]> granicus.if.org Git - clang/commitdiff
Enable -fsanitize=use-after-return by default under -fsanitize=address
authorKostya Serebryany <kcc@google.com>
Mon, 23 Sep 2013 09:52:37 +0000 (09:52 +0000)
committerKostya Serebryany <kcc@google.com>
Mon, 23 Sep 2013 09:52:37 +0000 (09:52 +0000)
Summary:
We enable ASAN's use-after-return instrumentation at compile-time,
but still keep it disabled at run-time.
This enables the users to flip the flag at run-time using environment variable
ASAN_OPTIONS=detect_stack_use_after_return=1 instead of using a separate build.
If UAR detection is disabled at run-time, this extra compile-time instrumentation
costs very small slowdown. On SPEC 2006 14 tests are not affected at all,
4 tests get ~ 1% slowdown and 453.povray gets 4%.

Reviewers: samsonov

Reviewed By: samsonov

CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1741

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191186 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/SanitizerArgs.cpp
test/Driver/fsanitize.c

index 30fb3fa9cee92772b9e813c225785566619f1c9b..6a919985765ffec2794eeb8746ea505a2e2e2d6d 100644 (file)
@@ -211,11 +211,11 @@ unsigned SanitizerArgs::parse(const char *Value) {
 #define SANITIZER_GROUP(NAME, ID, ALIAS) .Case(NAME, ID)
 #include "clang/Basic/Sanitizers.def"
     .Default(SanitizeKind());
-  // Assume -fsanitize=address implies -fsanitize=init-order.
+  // Assume -fsanitize=address implies -fsanitize=init-order,use-after-return.
   // FIXME: This should be either specified in Sanitizers.def, or go away when
-  // we get rid of "-fsanitize=init-order" flag at all.
+  // we get rid of "-fsanitize=init-order,use-after-return" flags at all.
   if (ParsedKind & Address)
-    ParsedKind |= InitOrder;
+    ParsedKind |= InitOrder | UseAfterReturn;
   return ParsedKind;
 }
 
index aaca33e40555c9ddbb72a67b19c0bd4c117c3d42..e56fc51ca0e18bf8e9403b7ab074c97c85c2e475 100644 (file)
 // 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 -fno-sanitize=init-order -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 -fno-sanitize=init-order,use-after-return -fsanitize=address %s -### 2>&1 |  FileCheck %s --check-prefix=CHECK-ASAN-IMPLIED-INIT-ORDER-UAR
+// CHECK-ASAN-IMPLIED-INIT-ORDER-UAR: "-fsanitize={{((address|init-order|use-after-return),?){3}"}}
 
 // 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 -fsanitize=address -fno-sanitize=use-after-return %s -### 2>&1 |  FileCheck %s --check-prefix=CHECK-ASAN-NO-IMPLIED-UAR
+// CHECK-ASAN-NO-IMPLIED-UAR-NOT: use-after-return
+
 // 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'