From: Adrian Prantl Date: Fri, 9 Nov 2018 21:17:38 +0000 (+0000) Subject: Revert "Revert rL346454: Fix a use-after-free introduced by r344915." X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2af5dd707a7928dbb409d41875c4b1353ed501f8;p=clang Revert "Revert rL346454: Fix a use-after-free introduced by r344915." This un-reverts commit 346454 with a relaxed CHECK for Windows. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@346556 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 1d999e446c..81cc07dddd 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -3538,7 +3538,7 @@ void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc) { // Update our current location setLocation(Loc); - if (CurLoc.isInvalid() || CurLoc.isMacroID()) + if (CurLoc.isInvalid() || CurLoc.isMacroID() || LexicalBlockStack.empty()) return; llvm::MDNode *Scope = LexicalBlockStack.back(); diff --git a/test/CodeGen/ubsan-debuglog-return.c b/test/CodeGen/ubsan-debuglog-return.c new file mode 100644 index 0000000000..23a1326934 --- /dev/null +++ b/test/CodeGen/ubsan-debuglog-return.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -x c -debug-info-kind=line-tables-only -emit-llvm -fsanitize=returns-nonnull-attribute -o - %s | FileCheck %s +// The UBSAN function call in the epilogue needs to have a debug location. + +__attribute__((returns_nonnull)) void *allocate() {} + +// CHECK: define {{.*}}nonnull i8* @allocate(){{.*}} !dbg +// CHECK: call void @__ubsan_handle_nonnull_return_v1_abort +// CHECK-SAME: !dbg ![[LOC:[0-9]+]] +// CHECK: ret i8* +// CHECK-SAME: !dbg ![[LOC]]