[PATCH] D39069: CodeGen: Fix missing debug loc due to alloca

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 18 14:11:17 PDT 2017


yaxunl created this revision.

Builder save/restores insertion pointer when emitting addr space cast
for alloca, but does not save/restore debug loc, which causes verifier
failure for certain call instructions.

This patch fixes that.


https://reviews.llvm.org/D39069

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGenOpenCL/func-call-dbg-loc.cl


Index: test/CodeGenOpenCL/func-call-dbg-loc.cl
===================================================================
--- /dev/null
+++ test/CodeGenOpenCL/func-call-dbg-loc.cl
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple amdgcn---amdgizcl -debug-info-kind=limited -dwarf-version=2 -debugger-tuning=gdb -O0 -emit-llvm -o - %s | FileCheck %s
+// Checks the file compiles without verifier error: inlinable function call in a function with debug info must have a !dbg location.
+
+typedef struct
+{
+    float m_max;
+} Struct;
+
+typedef struct
+{
+    Struct m_volume;
+} Node;
+
+
+Struct buzz(Node node)
+{
+    return node.m_volume;
+}
+
+__attribute__((always_inline))
+float bar(Struct aabb)
+{
+    return 0.0f;
+}
+
+__attribute__((used))
+void foo()
+{
+    Node node;
+    // CHECK: store float 0.000000e+00, float addrspace(5)* %f, align 4, !dbg !{{[0-9]+}}
+    float f = bar(buzz(node));
+}
+
+
Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -75,11 +75,13 @@
   if (CastToDefaultAddrSpace && getASTAllocaAddressSpace() != LangAS::Default) {
     auto DestAddrSpace = getContext().getTargetAddressSpace(LangAS::Default);
     auto CurIP = Builder.saveIP();
+    auto DbgLoc = Builder.getCurrentDebugLocation();
     Builder.SetInsertPoint(AllocaInsertPt);
     V = getTargetHooks().performAddrSpaceCast(
         *this, V, getASTAllocaAddressSpace(), LangAS::Default,
         Ty->getPointerTo(DestAddrSpace), /*non-null*/ true);
     Builder.restoreIP(CurIP);
+    Builder.SetCurrentDebugLocation(DbgLoc);
   }
 
   return Address(V, Align);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39069.119521.patch
Type: text/x-patch
Size: 1657 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171018/1bcf9aa3/attachment.bin>


More information about the cfe-commits mailing list