diff options
author | Joey Gouly <joey.gouly@arm.com> | 2012-11-23 10:39:49 +0000 |
---|---|---|
committer | Joey Gouly <joey.gouly@arm.com> | 2012-11-23 10:39:49 +0000 |
commit | 85489080807b47b70d26611ba543801e16bec4cd (patch) | |
tree | 56667df8f6d4774ce20329cee27463000aa89836 | |
parent | 66b8a6671bb5df540dd7200a5286f7ed7a72c1cc (diff) |
PR14306: Move -fbounds-checking to -fsanitize=bounds.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168510 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/Sanitizers.def | 3 | ||||
-rw-r--r-- | include/clang/Frontend/CodeGenOptions.def | 3 | ||||
-rw-r--r-- | lib/CodeGen/BackendUtil.cpp | 6 | ||||
-rw-r--r-- | lib/Driver/SanitizerArgs.h | 2 | ||||
-rw-r--r-- | lib/Driver/Tools.cpp | 12 | ||||
-rw-r--r-- | lib/Frontend/CompilerInvocation.cpp | 2 | ||||
-rw-r--r-- | test/CodeGen/bounds-checking.c | 2 | ||||
-rw-r--r-- | test/Driver/bounds-checking.c | 16 | ||||
-rw-r--r-- | test/Driver/darwin-sanitizer-ld.c | 15 | ||||
-rw-r--r-- | test/Driver/fsanitize.c | 7 | ||||
-rw-r--r-- | test/Driver/ubsan-ld.c | 10 |
11 files changed, 48 insertions, 30 deletions
diff --git a/include/clang/Basic/Sanitizers.def b/include/clang/Basic/Sanitizers.def index 085ca16eae..135832de91 100644 --- a/include/clang/Basic/Sanitizers.def +++ b/include/clang/Basic/Sanitizers.def @@ -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 diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 3c9490e287..d3f29f1b58 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -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) diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index c698102278..076b27960f 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -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, diff --git a/lib/Driver/SanitizerArgs.h b/lib/Driver/SanitizerArgs.h index ecb396ea06..85f81f4bd9 100644 --- a/lib/Driver/SanitizerArgs.h +++ b/lib/Driver/SanitizerArgs.h @@ -30,7 +30,7 @@ class SanitizerArgs { #include "clang/Basic/Sanitizers.def" NeedsAsanRt = Address, NeedsTsanRt = Thread, - NeedsUbsanRt = Undefined + NeedsUbsanRt = Undefined ^ Bounds }; unsigned Kind; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index fcf9d6b390..eb79c2fb88 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -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"); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 2e8ae63831..9a80b1f3b3 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -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); diff --git a/test/CodeGen/bounds-checking.c b/test/CodeGen/bounds-checking.c index e2786203e6..fa7541f814 100644 --- a/test/CodeGen/bounds-checking.c +++ b/test/CodeGen/bounds-checking.c @@ -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) { diff --git a/test/Driver/bounds-checking.c b/test/Driver/bounds-checking.c index 95bb8afd0d..a4f97e820b 100644 --- a/test/Driver/bounds-checking.c +++ b/test/Driver/bounds-checking.c @@ -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" diff --git a/test/Driver/darwin-sanitizer-ld.c b/test/Driver/darwin-sanitizer-ld.c index ec275415c7..cc6ab7784c 100644 --- a/test/Driver/darwin-sanitizer-ld.c +++ b/test/Driver/darwin-sanitizer-ld.c @@ -29,6 +29,14 @@ // 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 @@ -38,3 +46,10 @@ // 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 diff --git a/test/Driver/fsanitize.c b/test/Driver/fsanitize.c index 9f7cd46c6c..9812c25f77 100644 --- a/test/Driver/fsanitize.c +++ b/test/Driver/fsanitize.c @@ -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 @@ -15,9 +15,10 @@ // 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 diff --git a/test/Driver/ubsan-ld.c b/test/Driver/ubsan-ld.c index 775e669944..4a17e7c72f 100644 --- a/test/Driver/ubsan-ld.c +++ b/test/Driver/ubsan-ld.c @@ -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" |