Author: adrian Date: Wed Nov 28 13:44:06 2018 New Revision: 347810 URL: http://llvm.org/viewvc/llvm-project?rev=347810&view=rev Log: Ensure sanitizer check function calls have a !dbg location
Function calls without a !dbg location inside a function that has a DISubprogram make it impossible to construct inline information and are rejected by the verifier. This patch ensures that sanitizer check function calls have a !dbg location, by carrying forward the location of the preceding instruction or by inserting an artificial location if necessary. This fixes a crash when compiling the attached testcase with -Os. rdar://problem/45311226 Differential Revision: https://reviews.llvm.org/D53459 Note: This reapllies r344915, modified to reuse the IRBuilder's DebugLoc if one exists instead of picking the one from CGDebugInfo since the latter may get reset when emitting thunks such as block helpers in the middle of emitting another function. Added: cfe/trunk/test/CodeGenCXX/ubsan-check-debuglocs.cpp cfe/trunk/test/CodeGenObjC/ubsan-check-debuglocs.m Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=347810&r1=347809&r2=347810&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Nov 28 13:44:06 2018 @@ -2879,6 +2879,11 @@ static void emitCheckHandlerCall(CodeGen CheckRecoverableKind RecoverKind, bool IsFatal, llvm::BasicBlock *ContBB) { assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable); + Optional<ApplyDebugLocation> DL; + if (!CGF.Builder.getCurrentDebugLocation()) { + // Ensure that the call has at least an artificial debug location. + DL.emplace(CGF, SourceLocation()); + } bool NeedsAbortSuffix = IsFatal && RecoverKind != CheckRecoverableKind::Unrecoverable; bool MinimalRuntime = CGF.CGM.getCodeGenOpts().SanitizeMinimalRuntime; Added: cfe/trunk/test/CodeGenCXX/ubsan-check-debuglocs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ubsan-check-debuglocs.cpp?rev=347810&view=auto ============================================================================== --- cfe/trunk/test/CodeGenCXX/ubsan-check-debuglocs.cpp (added) +++ cfe/trunk/test/CodeGenCXX/ubsan-check-debuglocs.cpp Wed Nov 28 13:44:06 2018 @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited \ +// RUN: -fsanitize=null %s -o - | FileCheck %s + +// Check that santizer check calls have a !dbg location. +// CHECK: define {{.*}}acquire{{.*}} !dbg +// CHECK-NOT: define +// CHECK: call void {{.*}}@__ubsan_handle_type_mismatch_v1 +// CHECK-SAME: !dbg + +struct SourceLocation { + SourceLocation acquire() {}; +}; +extern "C" void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc); +static void handleTypeMismatchImpl(SourceLocation *Loc) { Loc->acquire(); } +void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc) { + handleTypeMismatchImpl(Loc); +} Added: cfe/trunk/test/CodeGenObjC/ubsan-check-debuglocs.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/ubsan-check-debuglocs.m?rev=347810&view=auto ============================================================================== --- cfe/trunk/test/CodeGenObjC/ubsan-check-debuglocs.m (added) +++ cfe/trunk/test/CodeGenObjC/ubsan-check-debuglocs.m Wed Nov 28 13:44:06 2018 @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -emit-llvm -fblocks -debug-info-kind=limited \ +// RUN: -fsanitize=nullability-return %s -o - | FileCheck %s + +// Check that santizer check calls have a !dbg location. +// CHECK: call void {{.*}}@__ubsan_handle_nullability_return_v1_abort +// CHECK-SAME: !dbg + +@protocol NSObject +@end + +@interface NSObject<NSObject> {} +@end + +#pragma clang assume_nonnull begin +@interface NSString : NSObject ++ (instancetype)stringWithFormat:(NSString *)format, ...; +@end + +@interface NSIndexPath : NSObject {} +@end +#pragma clang assume_nonnull end + +@interface B : NSObject +@end +id foo(NSIndexPath *indexPath) { + return [B withBlock:^{ + return [NSString stringWithFormat:@"%ld", + (long)[indexPath indexAtPosition:1]]; + }]; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits