Re: r344915 - Ensure sanitizer check function calls have a !dbg location

2018-10-22 Thread Vlad Tsyrklevich via cfe-commits
This change causes build failures on the UBSan bot, like so

:

3.  
/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm/include/llvm/Support/Allocator.h:98:40:
Generating code for declaration 'llvm::MallocAllocator::Allocate'

#0 0x55c1695ee77a llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x265677a)
#1 0x55c1695ecc55 llvm::sys::RunSignalHandlers()
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x2654c55)
#2 0x55c1695ecd6c SignalHandler(int)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x2654d6c)
#3 0x7f1e75f880c0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x110c0)
#4 0x55c169018c69 llvm::DebugLoc::get(unsigned int, unsigned int,
llvm::MDNode const*, llvm::MDNode const*, bool)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x2080c69)
#5 0x55c1697ddb31
clang::CodeGen::CGDebugInfo::EmitLocation(clang::CodeGen::CGBuilderTy&,
clang::SourceLocation)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x2845b31)
#6 0x55c1697ddcd6
clang::CodeGen::ApplyDebugLocation::init(clang::SourceLocation, bool)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x2845cd6)
#7 0x55c1699defa6
emitCheckHandlerCall(clang::CodeGen::CodeGenFunction&,
llvm::FunctionType*, llvm::ArrayRef,
clang::CodeGen::SanitizerHandler, (anonymous
namespace)::CheckRecoverableKind, bool, llvm::BasicBlock*)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x2a46fa6)
#8 0x55c1699e155a
clang::CodeGen::CodeGenFunction::EmitCheck(llvm::ArrayRef >, clang::CodeGen::SanitizerHandler,
llvm::ArrayRef, llvm::ArrayRef)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x2a4955a)
#9 0x55c169991463
clang::CodeGen::CodeGenFunction::EmitReturnValueCheck(llvm::Value*)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x29f9463)
#10 0x55c16999f536
clang::CodeGen::CodeGenFunction::EmitFunctionEpilog(clang::CodeGen::CGFunctionInfo
const&, bool, clang::SourceLocation)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x2a07536)
#11 0x55c16985070a
clang::CodeGen::CodeGenFunction::FinishFunction(clang::SourceLocation)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x28b870a)
#12 0x55c16985959f
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x28c159f)
#13 0x55c169895ac5
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x28fdac5)
#14 0x55c169892c39
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x28fac39)
#15 0x55c169898992 clang::CodeGen::CodeGenModule::EmitDeferred()
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x2900992)
#16 0x55c1698989ac clang::CodeGen::CodeGenModule::EmitDeferred()
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x29009ac)
#17 0x55c1698989ac clang::CodeGen::CodeGenModule::EmitDeferred()
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x29009ac)
#18 0x55c1698989ac clang::CodeGen::CodeGenModule::EmitDeferred()
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x29009ac)
#19 0x55c1698989ac clang::CodeGen::CodeGenModule::EmitDeferred()
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x29009ac)
#20 0x55c169898af3 clang::CodeGen::CodeGenModule::Release()
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x2900af3)
#21 0x55c169fae527 (anonymous
namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x3016527)
#22 0x55c169fad156
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x3015156)
#23 0x55c16a7b9569 clang::ParseAST(clang::Sema&, bool, bool)
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x3821569)
#24 0x55c169fac339 clang::CodeGenAction::ExecuteAction()
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x3014339)
#25 0x55c169c2d25e clang::FrontendAction::Execute()
(/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build0/bin/clang-8+0x2c9525e)
#26 0x55c169bf7b0e
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/b/sanitizer-x86_64-

r344915 - Ensure sanitizer check function calls have a !dbg location

2018-10-22 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Mon Oct 22 09:27:41 2018
New Revision: 344915

URL: http://llvm.org/viewvc/llvm-project?rev=344915&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

Added:
cfe/trunk/test/CodeGenCXX/ubsan-check-debuglocs.cpp
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=344915&r1=344914&r2=344915&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Oct 22 09:27:41 2018
@@ -2867,6 +2867,9 @@ static void emitCheckHandlerCall(CodeGen
  CheckRecoverableKind RecoverKind, bool 
IsFatal,
  llvm::BasicBlock *ContBB) {
   assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
+  auto *DI = CGF.getDebugInfo();
+  SourceLocation Loc = DI ? DI->getLocation() : SourceLocation();
+  auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc);
   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=344915&view=auto
==
--- cfe/trunk/test/CodeGenCXX/ubsan-check-debuglocs.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/ubsan-check-debuglocs.cpp Mon Oct 22 09:27:41 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);
+}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits