PR14306: Move -fbounds-checking to -fsanitize=bounds.
authorJoey Gouly <joey.gouly@arm.com>
Fri, 23 Nov 2012 10:39:49 +0000 (10:39 +0000)
committerJoey Gouly <joey.gouly@arm.com>
Fri, 23 Nov 2012 10:39:49 +0000 (10:39 +0000)
llvm-svn: 168510

clang/include/clang/Basic/Sanitizers.def
clang/include/clang/Frontend/CodeGenOptions.def
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/SanitizerArgs.h
clang/lib/Driver/Tools.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/bounds-checking.c
clang/test/Driver/bounds-checking.c
clang/test/Driver/darwin-sanitizer-ld.c
clang/test/Driver/fsanitize.c
clang/test/Driver/ubsan-ld.c

index 085ca16..135832d 100644 (file)
@@ -56,6 +56,7 @@ SANITIZER("null", Null)
 SANITIZER("vptr", Vptr)
 SANITIZER("object-size", ObjectSize)
 SANITIZER("float-cast-overflow", FloatCastOverflow)
+SANITIZER("bounds", Bounds)
 
 // -fsanitize=undefined (and its alias -fcatch-undefined-behavior). This should
 // include all the sanitizers which have low overhead, no ABI or address space
@@ -63,7 +64,7 @@ SANITIZER("float-cast-overflow", FloatCastOverflow)
 SANITIZER_GROUP("undefined", Undefined,
                 SignedIntegerOverflow | DivideByZero | Shift | Unreachable |
                 Return | VLABound | Alignment | Null | Vptr | ObjectSize |
-                FloatCastOverflow)
+                FloatCastOverflow | Bounds)
 
 #undef SANITIZER
 #undef SANITIZER_GROUP
index 3c9490e..d3f29f1 100644 (file)
@@ -113,9 +113,6 @@ CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
 /// or 0 if unspecified.
 VALUE_CODEGENOPT(NumRegisterParameters, 32, 0)
 
-/// The run-time penalty for bounds checking, or 0 to disable.
-VALUE_CODEGENOPT(BoundsChecking, 8, 0)
-
 /// The lower bound for a buffer to be considered for stack protection.
 VALUE_CODEGENOPT(SSPBufferSize, 32, 0)
 
index c698102..076b279 100644 (file)
@@ -152,10 +152,9 @@ static void addObjCARCOptPass(const PassManagerBuilder &Builder, PassManagerBase
     PM.add(createObjCARCOptPass());
 }
 
-static unsigned BoundsChecking;
 static void addBoundsCheckingPass(const PassManagerBuilder &Builder,
                                     PassManagerBase &PM) {
-  PM.add(createBoundsCheckingPass(BoundsChecking));
+  PM.add(createBoundsCheckingPass());
 }
 
 static void addAddressSanitizerPass(const PassManagerBuilder &Builder,
@@ -197,8 +196,7 @@ void EmitAssemblyHelper::CreatePasses(TargetMachine *TM) {
                            addObjCARCOptPass);
   }
 
-  if (CodeGenOpts.BoundsChecking > 0) {
-    BoundsChecking = CodeGenOpts.BoundsChecking;
+  if (LangOpts.SanitizeBounds) {
     PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
                            addBoundsCheckingPass);
     PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
index ecb396e..85f81f4 100644 (file)
@@ -30,7 +30,7 @@ class SanitizerArgs {
 #include "clang/Basic/Sanitizers.def"
     NeedsAsanRt = Address,
     NeedsTsanRt = Thread,
-    NeedsUbsanRt = Undefined
+    NeedsUbsanRt = Undefined ^ Bounds
   };
   unsigned Kind;
 
index fcf9d6b..eb79c2f 100644 (file)
@@ -1479,6 +1479,10 @@ SanitizerArgs::SanitizerArgs(const Driver &D, const ArgList &Args) {
       Add = parse(D, *I);
     } else if ((*I)->getOption().matches(options::OPT_fno_sanitize_EQ)) {
       Remove = parse(D, *I);
+    } else if ((*I)->getOption().matches(options::OPT_fbounds_checking) ||
+               (*I)->getOption().matches(options::OPT_fbounds_checking_EQ)) {
+      Add = Bounds;
+      DeprecatedReplacement = "-fsanitize=bounds";
     } else {
       continue;
     }
@@ -2372,14 +2376,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
       CmdArgs.push_back("-Wlarge-by-value-copy=64"); // default value
   }
 
-  if (Arg *A = Args.getLastArg(options::OPT_fbounds_checking,
-                               options::OPT_fbounds_checking_EQ)) {
-    if (A->getNumValues()) {
-      StringRef val = A->getValue();
-      CmdArgs.push_back(Args.MakeArgString("-fbounds-checking=" + val));
-    } else
-      CmdArgs.push_back("-fbounds-checking=1");
-  }
 
   if (Args.hasArg(options::OPT_relocatable_pch))
     CmdArgs.push_back("-relocatable-pch");
index 2e8ae63..9a80b1f 100644 (file)
@@ -386,8 +386,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
   Opts.UnwindTables = Args.hasArg(OPT_munwind_tables);
   Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic");
   Opts.TrapFuncName = Args.getLastArgValue(OPT_ftrap_function_EQ);
-  Opts.BoundsChecking = Args.getLastArgIntValue(OPT_fbounds_checking_EQ, 0,
-                                                Diags);
   Opts.UseInitArray = Args.hasArg(OPT_fuse_init_array);
 
   Opts.FunctionSections = Args.hasArg(OPT_ffunction_sections);
index e278620..fa7541f 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fbounds-checking=4 -emit-llvm -triple x86_64-apple-darwin10 < %s | FileCheck %s
+// RUN: %clang_cc1 -fsanitize=bounds -emit-llvm -triple x86_64-apple-darwin10 < %s | FileCheck %s
 
 // CHECK: @f
 double f(int b, int i) {
index 95bb8af..a4f97e8 100644 (file)
@@ -1,7 +1,11 @@
-// RUN: %clang -target x86_64-apple-darwin10 -fbounds-checking -### -fsyntax-only %s 2> %t
-// RUN: FileCheck < %t %s
-// RUN: %clang -target x86_64-apple-darwin10 -fbounds-checking=3 -### -fsyntax-only %s 2> %t
-// RUN: FileCheck -check-prefix=CHECK2 < %t %s
+// RUN: %clang -fsanitize=bounds -### -fsyntax-only %s 2> %t
+// RUN: FileCheck -check-prefix=CHECK < %t %s
+// CHECK: "-fsanitize=bounds"
 
-// CHECK: "-fbounds-checking=1"
-// CHECK2: "-fbounds-checking=3"
+// RUN: %clang -fbounds-checking -### -fsyntax-only %s 2> %t
+// RUN: FileCheck -check-prefix=CHECK-OLD < %t %s
+// CHECK-OLD: "-fsanitize=bounds"
+
+// RUN: %clang -fbounds-checking=3 -### -fsyntax-only %s 2> %t
+// RUN: FileCheck -check-prefix=CHECK-OLD2 < %t %s
+// CHECK-OLD2: "-fsanitize=bounds"
index ec27541..cc6ab77 100644 (file)
 // CHECK-UBSAN: "-lstdc++"
 
 // RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \
+// RUN:   -fsanitize=bounds %s -o %t.o 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-BOUNDS %s
+
+// CHECK-BOUNDS: "{{.*}}ld{{(.exe)?}}"
+// CHECK-BOUNDS-NOT: libclang_rt.ubsan_osx.a"
+// CHECK-BOUNDS-NOT: "-lstdc++"
+
+// RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \
 // RUN:   -fPIC -shared -fsanitize=undefined %s -o %t.so 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-DYN-UBSAN %s
 
 // CHECK-DYN-UBSAN: "-undefined"
 // CHECK-DYN-UBSAN: "dynamic_lookup"
 // CHECK-DYN-UBSAN-NOT: libclang_rt.ubsan_osx.a
+
+// RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \
+// RUN:   -fPIC -shared -fsanitize=bounds %s -o %t.so 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-DYN-BOUNDS %s
+
+// CHECK-DYN-BOUNDS: "{{.*}}ld{{(.exe)?}}"
+// CHECK-DYN-BOUNDS-NOT: libclang_rt.ubsan_osx.a
index 9f7cd46..9812c25 100644 (file)
@@ -1,9 +1,9 @@
 // RUN: %clang -target x86_64-linux-gnu -fcatch-undefined-behavior %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED
-// CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|divide-by-zero|shift|unreachable|return|vla-bound|alignment|null|vptr|object-size|float-cast-overflow),?){11}"}}
+// CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|divide-by-zero|shift|unreachable|return|vla-bound|alignment|null|vptr|object-size|float-cast-overflow|bounds),?){12}"}}
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=thread,undefined -fno-thread-sanitizer -fno-sanitize=float-cast-overflow,vptr %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-PARTIAL-UNDEFINED
-// CHECK-PARTIAL-UNDEFINED: "-fsanitize={{((signed-integer-overflow|divide-by-zero|shift|unreachable|return|vla-bound|alignment|null|object-size),?){9}"}}
+// CHECK-PARTIAL-UNDEFINED: "-fsanitize={{((signed-integer-overflow|divide-by-zero|shift|unreachable|return|vla-bound|alignment|null|object-size|bounds),?){10}"}}
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=vptr -fno-rtti %s -c -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-VPTR-NO-RTTI
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fno-rtti %s -c -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-VPTR-NO-RTTI
 // RUN: %clang -target x86_64-linux-gnu -faddress-sanitizer -fthread-sanitizer -fno-rtti %s -c -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-TSAN
 // CHECK-ASAN-TSAN: '-faddress-sanitizer' not allowed with '-fthread-sanitizer'
 
-// RUN: %clang -target x86_64-linux-gnu -fcatch-undefined-behavior -fthread-sanitizer -fno-thread-sanitizer -faddress-sanitizer -fno-address-sanitizer -c -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=CHECK-DEPRECATED
+// RUN: %clang -target x86_64-linux-gnu -fcatch-undefined-behavior -fthread-sanitizer -fno-thread-sanitizer -faddress-sanitizer -fno-address-sanitizer -fbounds-checking -c -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=CHECK-DEPRECATED
 // CHECK-DEPRECATED: argument '-fcatch-undefined-behavior' is deprecated, use '-fsanitize=undefined' instead
 // CHECK-DEPRECATED: argument '-fthread-sanitizer' is deprecated, use '-fsanitize=thread' instead
 // CHECK-DEPRECATED: argument '-fno-thread-sanitizer' is deprecated, use '-fno-sanitize=thread' instead
 // CHECK-DEPRECATED: argument '-faddress-sanitizer' is deprecated, use '-fsanitize=address' instead
 // CHECK-DEPRECATED: argument '-fno-address-sanitizer' is deprecated, use '-fno-sanitize=address' instead
+// CHECK-DEPRECATED: argument '-fbounds-checking' is deprecated, use '-fsanitize=bounds' instead
index 775e669..4a17e7c 100644 (file)
@@ -1,6 +1,6 @@
 // Test UndefinedBehaviorSanitizer ld flags.
 
-// RUN: %clang -fcatch-undefined-behavior %s -### -o %t.o 2>&1 \
+// RUN: %clang -fsanitize=undefined %s -### -o %t.o 2>&1 \
 // RUN:     -target i386-unknown-linux \
 // RUN:     --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX %s
@@ -8,3 +8,11 @@
 // CHECK-LINUX-NOT: "-lc"
 // CHECK-LINUX: libclang_rt.ubsan-i386.a"
 // CHECK-LINUX: "-lpthread"
+
+// RUN: %clang -fsanitize=bounds %s -### -o %t.o 2>&1 \
+// RUN:     -target i386-unknown-linux \
+// RUN:     --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LINUX1 %s
+// CHECK-LINUX1: "{{.*}}ld{{(.exe)?}}"
+// CHECK-LINUX1-NOT: libclang_rt.ubsan-i386.a"
+// CHECK-LINUX1-NOT: "-lpthread"