<div dir="ltr">What John said, but also a narrower test would be good - checking that the appropriate call instruction gets a debug location, rather than checking that a bunch of inlining doesn't cause the assertion/verifier failure, would be good. (Clang tests should, as much as possible, not rely on or run the LLVM optimization passes - but check the IR coming directly from Clang before any of that)<br><br><div class="gmail_quote"><div dir="ltr">On Wed, Oct 18, 2017 at 2:15 PM Yaxun Liu via Phabricator via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">yaxunl created this revision.<br>
<br>
Builder save/restores insertion pointer when emitting addr space cast<br>
for alloca, but does not save/restore debug loc, which causes verifier<br>
failure for certain call instructions.<br>
<br>
This patch fixes that.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D39069" rel="noreferrer" target="_blank">https://reviews.llvm.org/D39069</a><br>
<br>
Files:<br>
  lib/CodeGen/CGExpr.cpp<br>
  test/CodeGenOpenCL/<a href="http://func-call-dbg-loc.cl" rel="noreferrer" target="_blank">func-call-dbg-loc.cl</a><br>
<br>
<br>
Index: test/CodeGenOpenCL/<a href="http://func-call-dbg-loc.cl" rel="noreferrer" target="_blank">func-call-dbg-loc.cl</a><br>
===================================================================<br>
--- /dev/null<br>
+++ test/CodeGenOpenCL/<a href="http://func-call-dbg-loc.cl" rel="noreferrer" target="_blank">func-call-dbg-loc.cl</a><br>
@@ -0,0 +1,34 @@<br>
+// RUN: %clang_cc1 -triple amdgcn---amdgizcl -debug-info-kind=limited -dwarf-version=2 -debugger-tuning=gdb -O0 -emit-llvm -o - %s | FileCheck %s<br>
+// Checks the file compiles without verifier error: inlinable function call in a function with debug info must have a !dbg location.<br>
+<br>
+typedef struct<br>
+{<br>
+    float m_max;<br>
+} Struct;<br>
+<br>
+typedef struct<br>
+{<br>
+    Struct m_volume;<br>
+} Node;<br>
+<br>
+<br>
+Struct buzz(Node node)<br>
+{<br>
+    return node.m_volume;<br>
+}<br>
+<br>
+__attribute__((always_inline))<br>
+float bar(Struct aabb)<br>
+{<br>
+    return 0.0f;<br>
+}<br>
+<br>
+__attribute__((used))<br>
+void foo()<br>
+{<br>
+    Node node;<br>
+    // CHECK: store float 0.000000e+00, float addrspace(5)* %f, align 4, !dbg !{{[0-9]+}}<br>
+    float f = bar(buzz(node));<br>
+}<br>
+<br>
+<br>
Index: lib/CodeGen/CGExpr.cpp<br>
===================================================================<br>
--- lib/CodeGen/CGExpr.cpp<br>
+++ lib/CodeGen/CGExpr.cpp<br>
@@ -75,11 +75,13 @@<br>
   if (CastToDefaultAddrSpace && getASTAllocaAddressSpace() != LangAS::Default) {<br>
     auto DestAddrSpace = getContext().getTargetAddressSpace(LangAS::Default);<br>
     auto CurIP = Builder.saveIP();<br>
+    auto DbgLoc = Builder.getCurrentDebugLocation();<br>
     Builder.SetInsertPoint(AllocaInsertPt);<br>
     V = getTargetHooks().performAddrSpaceCast(<br>
         *this, V, getASTAllocaAddressSpace(), LangAS::Default,<br>
         Ty->getPointerTo(DestAddrSpace), /*non-null*/ true);<br>
     Builder.restoreIP(CurIP);<br>
+    Builder.SetCurrentDebugLocation(DbgLoc);<br>
   }<br>
<br>
   return Address(V, Align);<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div>