gollvm: update recipe for recording sret/byval arg attributes
Update the recipe for attaching "sret" (structure return) and "by
value" attributes to function parameters. Previously it was enough to
just apply these attributes as tags; now we need to also capture the
type of the return or param as well.
Also fixes a buglet in the unit test remastering machinery (incorrect
env variable name).
Fixes golang/go#42843.
Change-Id: I3fceff4868f714d97621bdca07b91513c2ba94c8
Reviewed-on: https://go-review.googlesource.com/c/gollvm/+/274833
Trust: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/bridge/go-llvm-bfunction.cpp b/bridge/go-llvm-bfunction.cpp
index 5d1f78d..fc80e99 100644
--- a/bridge/go-llvm-bfunction.cpp
+++ b/bridge/go-llvm-bfunction.cpp
@@ -106,7 +106,9 @@
if (abiOracle_->returnInfo().disp() == ParmIndirect) {
std::string sretname(namegen("sret.formal"));
arguments_[argIdx]->setName(sretname);
- arguments_[argIdx]->addAttr(llvm::Attribute::StructRet);
+ llvm::AttrBuilder SRETAttrs;
+ SRETAttrs.addStructRetAttr(fcnType_->resultType()->type());
+ arguments_[argIdx]->addAttrs(SRETAttrs);
rtnValueMem_ = arguments_[argIdx];
argIdx += 1;
}
@@ -137,8 +139,11 @@
case ParmIndirect: {
paramValues_.push_back(arguments_[argIdx]);
assert(paramInfo.numArgSlots() == 1);
- if (paramInfo.attr() == AttrByVal)
- arguments_[argIdx]->addAttr(llvm::Attribute::ByVal);
+ if (paramInfo.attr() == AttrByVal) {
+ llvm::AttrBuilder BVAttrs;
+ BVAttrs.addByValAttr(paramTypes[idx]->type());
+ arguments_[argIdx]->addAttrs(BVAttrs);
+ }
argIdx += 1;
break;
}
diff --git a/unittests/BackendCore/BackendDebugEmit.cpp b/unittests/BackendCore/BackendDebugEmit.cpp
index 622718d..38e98de 100644
--- a/unittests/BackendCore/BackendDebugEmit.cpp
+++ b/unittests/BackendCore/BackendDebugEmit.cpp
@@ -76,12 +76,11 @@
EXPECT_FALSE(broken && "Module failed to verify.");
DECLARE_EXPECTED_OUTPUT(exp, R"RAW_RESULT(
- define void @foo(i8* nest %nest.0, { i64, i64, i64 }* byval %p0) #0 {
- entry:
- call void @llvm.dbg.declare(metadata { i64, i64, i64 }* %p0, metadata !5,
- metadata !DIExpression()), !dbg !18
- ret void
- }
+ define void @foo(i8* nest %nest.0, { i64, i64, i64 }* byval({ i64, i64, i64 }) %p0) #0 {
+ entry:
+ call void @llvm.dbg.declare(metadata { i64, i64, i64 }* %p0, metadata !5, metadata !DIExpression()), !dbg !18
+ ret void
+ }
)RAW_RESULT");
bool isOK = h.expectValue(func->function(), exp);
diff --git a/unittests/BackendCore/BackendExprTests.cpp b/unittests/BackendCore/BackendExprTests.cpp
index 54b37da..5d7528f 100644
--- a/unittests/BackendCore/BackendExprTests.cpp
+++ b/unittests/BackendCore/BackendExprTests.cpp
@@ -1455,7 +1455,7 @@
h.mkLocal("a", s2t, cond);
DECLARE_EXPECTED_OUTPUT(exp, R"RAW_RESULT(
- define void @foo({ [16 x i32], i32 }* sret %sret.formal.0, i8* nest %nest.0, { [16 x i32], i32 }* byval %p0, i32 %p1) #0 {
+ define void @foo({ [16 x i32], i32 }* sret({ [16 x i32], i32 }) %sret.formal.0, i8* nest %nest.0, { [16 x i32], i32 }* byval({ [16 x i32], i32 }) %p0, i32 %p1) #0 {
entry:
%p1.addr = alloca i32, align 4
%a = alloca { [16 x i32], i32 }, align 4
@@ -1530,7 +1530,7 @@
h.mkLocal("a", s2t, cond);
DECLARE_EXPECTED_OUTPUT(exp, R"RAW_RESULT(
- define void @foo({ [16 x i32], i32 }* sret %sret.formal.0, i8* nest %nest.0, { [16 x i32], i32 }* %p0, i32 %p1) #0 {
+ define void @foo({ [16 x i32], i32 }* sret({ [16 x i32], i32 }) %sret.formal.0, i8* nest %nest.0, { [16 x i32], i32 }* %p0, i32 %p1) #0 {
entry:
%p1.addr = alloca i32, align 4
%a = alloca { [16 x i32], i32 }, align 4
diff --git a/unittests/TestUtils/DiffUtils.cpp b/unittests/TestUtils/DiffUtils.cpp
index b3295f4..98786d7 100644
--- a/unittests/TestUtils/DiffUtils.cpp
+++ b/unittests/TestUtils/DiffUtils.cpp
@@ -168,7 +168,7 @@
if (getenv("GOLLVM_UNITTESTS_BACKENDCORE_EMITDUMPFILES") != nullptr)
emitDumpFilesOnDiff = true;
- if (getenv("GOLLVM_UNITTESTS_BACKENDCORE_EMITDUMPFILES") != nullptr) {
+ if (getenv("GOLLVM_UNITTESTS_EMIT_REMASTER_SCRIPT") != nullptr) {
emitRemasterScript = true;
emitDumpFilesOnDiff = true;
}