From b1b0ab41e79f4f11ab21e6e56ded7147241f8615 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 5 Nov 2012 22:21:05 +0000 Subject: [PATCH] Use the individual -fsanitize=<...> arguments to control which of the UBSan checks to enable. Remove frontend support for -fcatch-undefined-behavior, -faddress-sanitizer and -fthread-sanitizer now that they don't do anything. llvm-svn: 167413 --- clang/include/clang/Basic/LangOptions.def | 1 - clang/include/clang/Driver/Options.td | 10 ++--- clang/lib/CodeGen/CGBuiltin.cpp | 2 +- clang/lib/CodeGen/CGExpr.cpp | 50 ++++++++++++---------- clang/lib/CodeGen/CGExprScalar.cpp | 26 +++++------ clang/lib/CodeGen/CodeGenFunction.cpp | 11 +++-- clang/lib/CodeGen/CodeGenFunction.h | 5 ++- clang/lib/Driver/Tools.cpp | 6 --- clang/lib/Frontend/CompilerInvocation.cpp | 3 -- clang/test/CodeGen/address-safety-attr.cpp | 2 +- clang/test/CodeGen/catch-undef-behavior.c | 13 +++++- clang/test/CodeGen/integer-overflow.c | 2 +- clang/test/CodeGen/tbaa-for-vptr.cpp | 4 +- clang/test/CodeGenCXX/catch-undef-behavior.cpp | 2 +- clang/test/CodeGenObjCXX/address-safety-attr.mm | 2 +- clang/test/Lexer/has_feature_address_sanitizer.cpp | 2 +- 16 files changed, 76 insertions(+), 65 deletions(-) diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index fab4a54..f4cba24 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -117,7 +117,6 @@ LANGOPT(CUDA , 1, 0, "CUDA") LANGOPT(AssumeSaneOperatorNew , 1, 1, "implicit __attribute__((malloc)) for C++'s new operators") BENIGN_LANGOPT(ElideConstructors , 1, 1, "C++ copy constructor elision") -BENIGN_LANGOPT(CatchUndefined , 1, 0, "catching undefined behavior at run time") BENIGN_LANGOPT(DumpRecordLayouts , 1, 0, "dumping the layout of IRgen'd records") BENIGN_LANGOPT(DumpRecordLayoutsSimple , 1, 0, "dumping the layout of IRgen'd records in a simple form") BENIGN_LANGOPT(DumpVTableLayouts , 1, 0, "dumping the layouts of emitted vtables") diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index ba609fa..2ace8f38 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -293,12 +293,12 @@ def fapple_kext : Flag<["-"], "fapple-kext">, Group, Flags<[CC1Option]> HelpText<"Use Apple's kernel extensions ABI">; def fapple_pragma_pack : Flag<["-"], "fapple-pragma-pack">, Group, Flags<[CC1Option]>, HelpText<"Enable Apple gcc-compatible #pragma pack handling">; -def faddress_sanitizer : Flag<["-"], "faddress-sanitizer">, Group, Flags<[CC1Option]>, +def faddress_sanitizer : Flag<["-"], "faddress-sanitizer">, Group, HelpText<"Enable AddressSanitizer instrumentation (memory error detection)">; -def fno_address_sanitizer : Flag<["-"], "fno-address-sanitizer">, Group, Flags<[CC1Option]>; -def fthread_sanitizer : Flag<["-"], "fthread-sanitizer">, Group, Flags<[CC1Option]>, +def fno_address_sanitizer : Flag<["-"], "fno-address-sanitizer">, Group; +def fthread_sanitizer : Flag<["-"], "fthread-sanitizer">, Group, HelpText<"Enable ThreadSanitizer instrumentation (race detection)">; -def fno_thread_sanitizer : Flag<["-"], "fno-thread-sanitizer">, Group, Flags<[CC1Option]>; +def fno_thread_sanitizer : Flag<["-"], "fno-thread-sanitizer">, Group; def fasm : Flag<["-"], "fasm">, Group; def fasm_blocks : Flag<["-"], "fasm-blocks">, Group; @@ -322,7 +322,7 @@ def fbuiltin_strcat : Flag<["-"], "fbuiltin-strcat">, Group; def fbuiltin_strcpy : Flag<["-"], "fbuiltin-strcpy">, Group; def fbuiltin : Flag<["-"], "fbuiltin">, Group; def fcaret_diagnostics : Flag<["-"], "fcaret-diagnostics">, Group; -def fcatch_undefined_behavior : Flag<["-"], "fcatch-undefined-behavior">, Flags<[CC1Option]>, +def fcatch_undefined_behavior : Flag<["-"], "fcatch-undefined-behavior">, Group, HelpText<"Generate runtime checks for undefined behavior.">; def fclasspath_EQ : Joined<["-"], "fclasspath=">, Group; def fcolor_diagnostics : Flag<["-"], "fcolor-diagnostics">, Group, Flags<[CC1Option]>, diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index b0ea2fa..e8c05d3 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -406,7 +406,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, return RValue::get(Builder.CreateCall(F)); } case Builtin::BI__builtin_unreachable: { - if (CatchUndefined) + if (getLangOpts().SanitizeUnreachable) EmitCheck(Builder.getFalse(), "builtin_unreachable", EmitCheckSourceLocation(E->getExprLoc()), llvm::ArrayRef()); diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 6255585..d1a2889 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -389,7 +389,7 @@ CodeGenFunction::EmitReferenceBindingToExpr(const Expr *E, ReferenceTemporaryDtor, ObjCARCReferenceLifetimeType, InitializedDecl); - if (CatchUndefined && !E->getType()->isFunctionType()) { + if (SanitizePerformTypeCheck && !E->getType()->isFunctionType()) { // C++11 [dcl.ref]p5 (as amended by core issue 453): // If a glvalue to which a reference is directly bound designates neither // an existing object or function of an appropriate type nor a region of @@ -476,7 +476,7 @@ static llvm::Value *emitHash16Bytes(CGBuilderTy &Builder, llvm::Value *Low, void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *Address, QualType Ty, CharUnits Alignment) { - if (!CatchUndefined) + if (!SanitizePerformTypeCheck) return; // Don't check pointers outside the default address space. The null check @@ -487,19 +487,17 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *Cond = 0; - // The glvalue must not be an empty glvalue. - Cond = Builder.CreateICmpNE( - Address, llvm::Constant::getNullValue(Address->getType())); - - uint64_t AlignVal = Alignment.getQuantity(); + if (getLangOpts().SanitizeNull) { + // The glvalue must not be an empty glvalue. + Cond = Builder.CreateICmpNE( + Address, llvm::Constant::getNullValue(Address->getType())); + } - if (!Ty->isIncompleteType()) { + if (getLangOpts().SanitizeObjectSize && !Ty->isIncompleteType()) { uint64_t Size = getContext().getTypeSizeInChars(Ty).getQuantity(); - if (!AlignVal) - AlignVal = getContext().getTypeAlignInChars(Ty).getQuantity(); // The glvalue must refer to a large enough storage region. - // FIXME: If -faddress-sanitizer is enabled, insert dynamic instrumentation + // FIXME: If Address Sanitizer is enabled, insert dynamic instrumentation // to check this. llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::objectsize, IntPtrTy); llvm::Value *Min = Builder.getFalse(); @@ -510,13 +508,22 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, Cond = Cond ? Builder.CreateAnd(Cond, LargeEnough) : LargeEnough; } - if (AlignVal) { + uint64_t AlignVal = 0; + + if (getLangOpts().SanitizeAlignment) { + AlignVal = Alignment.getQuantity(); + if (!Ty->isIncompleteType() && !AlignVal) + AlignVal = getContext().getTypeAlignInChars(Ty).getQuantity(); + // The glvalue must be suitably aligned. - llvm::Value *Align = - Builder.CreateAnd(Builder.CreatePtrToInt(Address, IntPtrTy), - llvm::ConstantInt::get(IntPtrTy, AlignVal - 1)); - Cond = Builder.CreateAnd(Cond, - Builder.CreateICmpEQ(Align, llvm::ConstantInt::get(IntPtrTy, 0))); + if (AlignVal) { + llvm::Value *Align = + Builder.CreateAnd(Builder.CreatePtrToInt(Address, IntPtrTy), + llvm::ConstantInt::get(IntPtrTy, AlignVal - 1)); + llvm::Value *Aligned = + Builder.CreateICmpEQ(Align, llvm::ConstantInt::get(IntPtrTy, 0)); + Cond = Cond ? Builder.CreateAnd(Cond, Aligned) : Aligned; + } } if (Cond) { @@ -529,14 +536,11 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, EmitCheck(Cond, "type_mismatch", StaticData, Address); } + // If possible, check that the vptr indicates that there is a subobject of + // type Ty at offset zero within this object. CXXRecordDecl *RD = Ty->getAsCXXRecordDecl(); - if (TCK != TCK_ConstructorCall && + if (getLangOpts().SanitizeVptr && TCK != TCK_ConstructorCall && RD && RD->hasDefinition() && RD->isDynamicClass()) { - // Check that the vptr indicates that there is a subobject of type Ty at - // offset zero within this object. - // FIXME: Produce a diagnostic if the user tries to combine this check with - // -fno-rtti. - // Compute a hash of the mangled name of the type. // // FIXME: This is not guaranteed to be deterministic! Move to a diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index b6ce22b..c21cbf6 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -406,14 +406,14 @@ public: case LangOptions::SOB_Defined: return Builder.CreateMul(Ops.LHS, Ops.RHS, "mul"); case LangOptions::SOB_Undefined: - if (!CGF.CatchUndefined) + if (!CGF.getLangOpts().SanitizeSignedIntegerOverflow) return Builder.CreateNSWMul(Ops.LHS, Ops.RHS, "mul"); // Fall through. case LangOptions::SOB_Trapping: return EmitOverflowCheckedBinOp(Ops); } } - + if (Ops.LHS->getType()->isFPOrFPVectorTy()) return Builder.CreateFMul(Ops.LHS, Ops.RHS, "mul"); return Builder.CreateMul(Ops.LHS, Ops.RHS, "mul"); @@ -731,7 +731,7 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType, // An overflowing conversion has undefined behavior if either the source type // or the destination type is a floating-point type. - if (CGF.CatchUndefined && + if (CGF.getLangOpts().SanitizeFloatCastOverflow && (OrigSrcType->isFloatingType() || DstType->isFloatingType())) EmitFloatConversionCheck(OrigSrc, OrigSrcType, Src, SrcType, DstType, DstTy); @@ -1417,7 +1417,7 @@ EmitAddConsiderOverflowBehavior(const UnaryOperator *E, case LangOptions::SOB_Defined: return Builder.CreateAdd(InVal, NextVal, IsInc ? "inc" : "dec"); case LangOptions::SOB_Undefined: - if (!CGF.CatchUndefined) + if (!CGF.getLangOpts().SanitizeSignedIntegerOverflow) return Builder.CreateNSWAdd(InVal, NextVal, IsInc ? "inc" : "dec"); // Fall through. case LangOptions::SOB_Trapping: @@ -1942,7 +1942,7 @@ void ScalarExprEmitter::EmitUndefinedBehaviorIntegerDivAndRemCheck( } Value *ScalarExprEmitter::EmitDiv(const BinOpInfo &Ops) { - if (CGF.CatchUndefined) { + if (CGF.getLangOpts().SanitizeDivideByZero) { llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty)); if (Ops.Ty->isIntegerType()) @@ -1970,7 +1970,7 @@ Value *ScalarExprEmitter::EmitDiv(const BinOpInfo &Ops) { Value *ScalarExprEmitter::EmitRem(const BinOpInfo &Ops) { // Rem in C can't be a floating point type: C99 6.5.5p2. - if (CGF.CatchUndefined) { + if (CGF.getLangOpts().SanitizeDivideByZero) { llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty)); if (Ops.Ty->isIntegerType()) @@ -2021,9 +2021,9 @@ Value *ScalarExprEmitter::EmitOverflowCheckedBinOp(const BinOpInfo &Ops) { const std::string *handlerName = &CGF.getLangOpts().OverflowHandler; if (handlerName->empty()) { - // If -fcatch-undefined-behavior is enabled, emit a call to its + // If the signed-integer-overflow sanitizer is enabled, emit a call to its // runtime. Otherwise, this is a -ftrapv check, so just emit a trap. - if (CGF.CatchUndefined) + if (CGF.getLangOpts().SanitizeSignedIntegerOverflow) EmitBinOpCheck(Builder.CreateNot(overflow), Ops); else CGF.EmitTrapvCheck(Builder.CreateNot(overflow)); @@ -2241,7 +2241,7 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &op) { case LangOptions::SOB_Defined: return Builder.CreateAdd(op.LHS, op.RHS, "add"); case LangOptions::SOB_Undefined: - if (!CGF.CatchUndefined) + if (!CGF.getLangOpts().SanitizeSignedIntegerOverflow) return Builder.CreateNSWAdd(op.LHS, op.RHS, "add"); // Fall through. case LangOptions::SOB_Trapping: @@ -2268,7 +2268,7 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &op) { case LangOptions::SOB_Defined: return Builder.CreateSub(op.LHS, op.RHS, "sub"); case LangOptions::SOB_Undefined: - if (!CGF.CatchUndefined) + if (!CGF.getLangOpts().SanitizeSignedIntegerOverflow) return Builder.CreateNSWSub(op.LHS, op.RHS, "sub"); // Fall through. case LangOptions::SOB_Trapping: @@ -2351,7 +2351,8 @@ Value *ScalarExprEmitter::EmitShl(const BinOpInfo &Ops) { if (Ops.LHS->getType() != RHS->getType()) RHS = Builder.CreateIntCast(RHS, Ops.LHS->getType(), false, "sh_prom"); - if (CGF.CatchUndefined && isa(Ops.LHS->getType())) { + if (CGF.getLangOpts().SanitizeShift && + isa(Ops.LHS->getType())) { unsigned Width = cast(Ops.LHS->getType())->getBitWidth(); llvm::Value *WidthMinusOne = llvm::ConstantInt::get(RHS->getType(), Width - 1); @@ -2390,7 +2391,8 @@ Value *ScalarExprEmitter::EmitShr(const BinOpInfo &Ops) { if (Ops.LHS->getType() != RHS->getType()) RHS = Builder.CreateIntCast(RHS, Ops.LHS->getType(), false, "sh_prom"); - if (CGF.CatchUndefined && isa(Ops.LHS->getType())) { + if (CGF.getLangOpts().SanitizeShift && + isa(Ops.LHS->getType())) { unsigned Width = cast(Ops.LHS->getType())->getBitWidth(); llvm::Value *WidthVal = llvm::ConstantInt::get(RHS->getType(), Width); EmitBinOpCheck(Builder.CreateICmpULT(RHS, WidthVal), Ops); diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 140f1cb..18f1623 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -32,6 +32,10 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext) : CodeGenTypeCache(cgm), CGM(cgm), Target(CGM.getContext().getTargetInfo()), Builder(cgm.getModule().getContext()), + SanitizePerformTypeCheck(CGM.getLangOpts().SanitizeNull | + CGM.getLangOpts().SanitizeAlignment | + CGM.getLangOpts().SanitizeObjectSize | + CGM.getLangOpts().SanitizeVptr), AutoreleaseResult(false), BlockInfo(0), BlockPointer(0), LambdaThisCaptureField(0), NormalCleanupDest(0), NextCleanupDestIndex(1), FirstBlockInfo(0), EHResumeBlock(0), ExceptionSlot(0), EHSelectorSlot(0), @@ -40,8 +44,6 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext) CXXABIThisDecl(0), CXXABIThisValue(0), CXXThisValue(0), CXXVTTDecl(0), CXXVTTValue(0), OutermostConditional(0), TerminateLandingPad(0), TerminateHandler(0), TrapBB(0) { - - CatchUndefined = getLangOpts().CatchUndefined; if (!suppressNewContext) CGM.getCXXABI().getMangleContext().startNewFunction(); } @@ -543,7 +545,7 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn, // function call is used by the caller, the behavior is undefined. if (getLangOpts().CPlusPlus && !FD->hasImplicitReturnZero() && !FD->getResultType()->isVoidType() && Builder.GetInsertBlock()) { - if (CatchUndefined) + if (getLangOpts().SanitizeReturn) EmitCheck(Builder.getFalse(), "missing_return", EmitCheckSourceLocation(FD->getLocation()), llvm::ArrayRef()); @@ -1128,7 +1130,8 @@ void CodeGenFunction::EmitVariablyModifiedType(QualType type) { // If the size is an expression that is not an integer constant // expression [...] each time it is evaluated it shall have a value // greater than zero. - if (CatchUndefined && size->getType()->isSignedIntegerType()) { + if (getLangOpts().SanitizeVLABound && + size->getType()->isSignedIntegerType()) { llvm::Value *Zero = llvm::Constant::getNullValue(Size->getType()); llvm::Constant *StaticArgs[] = { EmitCheckSourceLocation(size->getLocStart()), diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 1e9fd00..fadc391 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -594,8 +594,9 @@ public: /// potentially higher performance penalties. unsigned char BoundsChecking; - /// CatchUndefined - Emit run-time checks to catch undefined behaviors. - bool CatchUndefined; + /// \brief Whether any type-checking sanitizers are enabled. If \c false, + /// calls to EmitTypeCheck can be skipped. + bool SanitizePerformTypeCheck; /// In ARC, whether we should autorelease the return value. bool AutoreleaseResult; diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index d1109ff..6ae24da 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -1506,12 +1506,6 @@ struct SanitizerArgs { } void addArgs(const ArgList &Args, ArgStringList &CmdArgs) const { - if (Kind & Address) - CmdArgs.push_back("-faddress-sanitizer"); - if (Kind & Thread) - CmdArgs.push_back("-fthread-sanitizer"); - if (Kind & Undefined) - CmdArgs.push_back("-fcatch-undefined-behavior"); if (!Kind) return; llvm::SmallString<256> SanitizeOpt("-fsanitize="); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 8cce72c..62c08df 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1213,7 +1213,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Args.getLastArgValue(OPT_fconstant_string_class); Opts.ObjCDefaultSynthProperties = Args.hasArg(OPT_fobjc_default_synthesize_properties); - Opts.CatchUndefined = Args.hasArg(OPT_fcatch_undefined_behavior); Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls); Opts.PackStruct = Args.getLastArgIntValue(OPT_fpack_struct_EQ, 0, Diags); Opts.PICLevel = Args.getLastArgIntValue(OPT_pic_level, 0, Diags); @@ -1234,8 +1233,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Opts.DebuggerSupport = Args.hasArg(OPT_fdebugger_support); Opts.DebuggerCastResultToId = Args.hasArg(OPT_fdebugger_cast_result_to_id); Opts.DebuggerObjCLiteral = Args.hasArg(OPT_fdebugger_objc_literal); - Opts.SanitizeAddress = Args.hasArg(OPT_faddress_sanitizer); - Opts.SanitizeThread = Args.hasArg(OPT_fthread_sanitizer); Opts.ApplePragmaPack = Args.hasArg(OPT_fapple_pragma_pack); Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name); diff --git a/clang/test/CodeGen/address-safety-attr.cpp b/clang/test/CodeGen/address-safety-attr.cpp index da68b1d..5c9862d 100644 --- a/clang/test/CodeGen/address-safety-attr.cpp +++ b/clang/test/CodeGen/address-safety-attr.cpp @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s -// RUN: %clang_cc1 -emit-llvm -o - %s -faddress-sanitizer | FileCheck -check-prefix ASAN %s +// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=address | FileCheck -check-prefix ASAN %s // The address_safety attribute should be attached to functions // when AddressSanitizer is enabled, unless no_address_safety_analysis attribute diff --git a/clang/test/CodeGen/catch-undef-behavior.c b/clang/test/CodeGen/catch-undef-behavior.c index 5283b3b..bc5ec63 100644 --- a/clang/test/CodeGen/catch-undef-behavior.c +++ b/clang/test/CodeGen/catch-undef-behavior.c @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -fcatch-undefined-behavior -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s +// RUN: %clang_cc1 -fsanitize=alignment,null,object-size,shift,return,signed-integer-overflow,vla-bound,float-cast-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s +// RUN: %clang_cc1 -fsanitize=null -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefix=CHECK-NULL // CHECK: @[[INT:.*]] = private unnamed_addr constant { i16, i16, [6 x i8] } { i16 0, i16 11, [6 x i8] c"'int'\00" } @@ -17,8 +18,11 @@ // CHECK: @[[LINE_800:.*]] = {{.*}}, i32 800, i32 12 {{.*}} @{{.*}} } // CHECK: @[[LINE_900:.*]] = {{.*}}, i32 900, i32 11 {{.*}} @{{.*}} } +// CHECK-NULL: @[[LINE_100:.*]] = private unnamed_addr constant {{.*}}, i32 100, i32 5 {{.*}} + // PR6805 // CHECK: @foo +// CHECK-NULL: @foo void foo() { union { int i; } u; // CHECK: %[[CHECK0:.*]] = icmp ne {{.*}}* %[[PTR:.*]], null @@ -37,6 +41,11 @@ void foo() { // CHECK: %[[ARG:.*]] = ptrtoint {{.*}} %[[PTR]] to i64 // CHECK-NEXT: call void @__ubsan_handle_type_mismatch(i8* bitcast ({{.*}} @[[LINE_100]] to i8*), i64 %[[ARG]]) noreturn nounwind + + // With -fsanitize=null, only perform the null check. + // CHECK-NULL: %[[NULL:.*]] = icmp ne {{.*}}, null + // CHECK-NULL: br i1 %[[NULL]] + // CHECK-NULL: call void @__ubsan_handle_type_mismatch(i8* bitcast ({{.*}} @[[LINE_100]] to i8*), i64 %{{.*}}) noreturn nounwind #line 100 u.i=1; } @@ -137,6 +146,8 @@ int signed_overflow(int a, int b) { // CHECK: @no_return int no_return() { // Reaching the end of a noreturn function is fine in C. + // FIXME: If the user explicitly requests -fsanitize=return, we should catch + // that here even though it's not undefined behavior. // CHECK-NOT: call // CHECK-NOT: unreachable // CHECK: ret i32 diff --git a/clang/test/CodeGen/integer-overflow.c b/clang/test/CodeGen/integer-overflow.c index 176ee65..ed2dede 100644 --- a/clang/test/CodeGen/integer-overflow.c +++ b/clang/test/CodeGen/integer-overflow.c @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - | FileCheck %s --check-prefix=DEFAULT // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fwrapv | FileCheck %s --check-prefix=WRAPV // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -ftrapv | FileCheck %s --check-prefix=TRAPV -// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fcatch-undefined-behavior | FileCheck %s --check-prefix=CATCH_UB +// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fsanitize=signed-integer-overflow | FileCheck %s --check-prefix=CATCH_UB // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -ftrapv -ftrapv-handler foo | FileCheck %s --check-prefix=TRAPV_HANDLER diff --git a/clang/test/CodeGen/tbaa-for-vptr.cpp b/clang/test/CodeGen/tbaa-for-vptr.cpp index e879807..9369036 100644 --- a/clang/test/CodeGen/tbaa-for-vptr.cpp +++ b/clang/test/CodeGen/tbaa-for-vptr.cpp @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 -emit-llvm -o - -O0 -fthread-sanitizer %s | FileCheck %s +// RUN: %clang_cc1 -emit-llvm -o - -O0 -fsanitize=thread %s | FileCheck %s // RUN: %clang_cc1 -emit-llvm -o - -O1 %s | FileCheck %s -// RUN: %clang_cc1 -emit-llvm -o - -O1 -relaxed-aliasing -fthread-sanitizer %s | FileCheck %s +// RUN: %clang_cc1 -emit-llvm -o - -O1 -relaxed-aliasing -fsanitize=thread %s | FileCheck %s // // RUN: %clang_cc1 -emit-llvm -o - -O0 %s | FileCheck %s --check-prefix=NOTBAA // RUN: %clang_cc1 -emit-llvm -o - -O2 -relaxed-aliasing %s | FileCheck %s --check-prefix=NOTBAA diff --git a/clang/test/CodeGenCXX/catch-undef-behavior.cpp b/clang/test/CodeGenCXX/catch-undef-behavior.cpp index 6cebdd7..fd9e3d7 100644 --- a/clang/test/CodeGenCXX/catch-undef-behavior.cpp +++ b/clang/test/CodeGenCXX/catch-undef-behavior.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fcatch-undefined-behavior -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s +// RUN: %clang_cc1 -fsanitize=signed-integer-overflow,divide-by-zero,shift,unreachable,return,vla-bound,alignment,null,vptr,object-size,float-cast-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s // CHECK: @_Z17reference_binding void reference_binding(int *p) { diff --git a/clang/test/CodeGenObjCXX/address-safety-attr.mm b/clang/test/CodeGenObjCXX/address-safety-attr.mm index a54ca99..a3824b9 100644 --- a/clang/test/CodeGenObjCXX/address-safety-attr.mm +++ b/clang/test/CodeGenObjCXX/address-safety-attr.mm @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s -// RUN: %clang_cc1 -emit-llvm -o - %s -faddress-sanitizer | FileCheck -check-prefix ASAN %s +// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=address | FileCheck -check-prefix ASAN %s @interface MyClass + (int) addressSafety:(int*)a; diff --git a/clang/test/Lexer/has_feature_address_sanitizer.cpp b/clang/test/Lexer/has_feature_address_sanitizer.cpp index 69acc39..5c98116 100644 --- a/clang/test/Lexer/has_feature_address_sanitizer.cpp +++ b/clang/test/Lexer/has_feature_address_sanitizer.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -E -faddress-sanitizer %s -o - | FileCheck --check-prefix=CHECK-ASAN %s +// RUN: %clang_cc1 -E -fsanitize=address %s -o - | FileCheck --check-prefix=CHECK-ASAN %s // RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-ASAN %s #if __has_feature(address_sanitizer) -- 2.7.4