From 881d150cc7c49bff7885ac9c4ae67353103bb672 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 14 Mar 2013 12:13:27 +0000 Subject: [PATCH] [ASan] Make -fsanitize=address imply -fsanitize=init-order (if the latter is not explicitly disabled). llvm-svn: 177061 --- clang/lib/Driver/Tools.cpp | 8 ++++++++ clang/test/Driver/fsanitize.c | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 065ee7d719b9..d8c4415a7a5d 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -1483,6 +1483,8 @@ SanitizerArgs::SanitizerArgs(const Driver &D, const ArgList &Args) AsanZeroBaseShadow(false) { unsigned AllKinds = 0; // All kinds of sanitizers that were turned on // at least once (possibly, disabled further). + unsigned AllRemovedKinds = 0; // All kinds of sanitizers that were explicitly + // removed at least once. for (ArgList::const_iterator I = Args.begin(), E = Args.end(); I != E; ++I) { unsigned Add, Remove; if (!parse(D, Args, *I, Add, Remove, true)) @@ -1491,6 +1493,12 @@ SanitizerArgs::SanitizerArgs(const Driver &D, const ArgList &Args) Kind |= Add; Kind &= ~Remove; AllKinds |= Add; + AllRemovedKinds |= Remove; + } + // Assume -fsanitize=address implies -fsanitize=init-order, if the latter is + // not disabled explicitly. + if ((Kind & Address) != 0 && (AllRemovedKinds & InitOrder) == 0) { + Kind |= InitOrder; } UbsanTrapOnError = diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c index efb289f6a705..b5cc3a4aa43f 100644 --- a/clang/test/Driver/fsanitize.c +++ b/clang/test/Driver/fsanitize.c @@ -16,6 +16,12 @@ // RUN: %clang -target x86_64-linux-gnu -fsanitize=address-full %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-FULL // CHECK-ASAN-FULL: "-fsanitize={{((address|init-order|use-after-return|use-after-scope),?){4}"}} +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-IMPLIED-INIT-ORDER +// CHECK-ASAN-IMPLIED-INIT-ORDER: "-fsanitize={{((address|init-order),?){2}"}} + +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fno-sanitize=init-order %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-NO-IMPLIED-INIT-ORDER +// CHECK-ASAN-NO-IMPLIED-INIT-ORDER-NOT: init-order + // RUN: %clang -target x86_64-linux-gnu -fcatch-undefined-behavior -fno-sanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-NO-TRAP-ERROR // CHECK-UNDEFINED-NO-TRAP-ERROR: '-fcatch-undefined-behavior' not allowed with '-fno-sanitize-undefined-trap-on-error'