Skip to content

Commit d24b9c6

Browse files
authored
Fix AttrKind attributes with --spirv-preserve-auxdata (#2107)
For AttrKind attributes, we need to convert them to the AttrKind enum before checking if it exists or adding it, otherwise it gets added as a string. Signed-off-by: Sarnie, Nick <[email protected]>
1 parent d498f48 commit d24b9c6

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4537,15 +4537,21 @@ void SPIRVToLLVM::transAuxDataInst(SPIRVExtInst *BC) {
45374537
case NonSemanticAuxData::FunctionAttribute: {
45384538
assert(Args.size() < 4 && "Unexpected FunctionAttribute Args");
45394539
// If this attr was specially handled and added elsewhere, skip it.
4540-
if (F->hasFnAttribute(AttrOrMDName))
4540+
Attribute::AttrKind AsKind = Attribute::getAttrKindFromName(AttrOrMDName);
4541+
if (AsKind != Attribute::None && F->hasFnAttribute(AsKind))
4542+
return;
4543+
if (AsKind == Attribute::None && F->hasFnAttribute(AttrOrMDName))
45414544
return;
45424545
// For attributes, arg 2 is the attribute value as a string, which may not
45434546
// exist.
45444547
if (Args.size() == 3) {
45454548
auto AttrValue = BC->getModule()->get<SPIRVString>(Args[2])->getStr();
45464549
F->addFnAttr(AttrOrMDName, AttrValue);
45474550
} else {
4548-
F->addFnAttr(AttrOrMDName);
4551+
if (AsKind != Attribute::None)
4552+
F->addFnAttr(AsKind);
4553+
else
4554+
F->addFnAttr(AttrOrMDName);
45494555
}
45504556
break;
45514557
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: llvm-as < %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -spirv-text --spirv-preserve-auxdata -o - | FileCheck %s --check-prefix=CHECK-SPIRV
3+
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-preserve-auxdata
4+
; RUN: llvm-spirv -r -emit-opaque-pointers --spirv-preserve-auxdata %t.spv -o %t.rev.bc
5+
; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-LLVM
6+
7+
; CHECK-SPIRV: Extension "SPV_KHR_non_semantic_info"
8+
; CHECK-SPIRV: ExtInstImport [[#Import:]] "NonSemantic.AuxData"
9+
10+
; CHECK-SPIRV: String [[#Attr0:]] "nounwind"
11+
12+
; CHECK-SPIRV: Name [[#Fcn0:]] "foo"
13+
14+
; CHECK-SPIRV: TypeVoid [[#VoidT:]]
15+
16+
; CHECK-SPIRV: ExtInst [[#VoidT]] [[#Attr0Inst:]] [[#Import]] NonSemanticAuxDataFunctionAttribute [[#Fcn0]] [[#Attr0]] {{$}}
17+
18+
target triple = "spir64-unknown-unknown"
19+
20+
; CHECK-LLVM: define spir_func void @foo() #[[#Fcn0IRAttr:]]
21+
define spir_func void @foo() #0 {
22+
entry:
23+
ret void
24+
}
25+
; CHECK-LLVM: attributes #[[#Fcn0IRAttr]] = { nounwind }
26+
attributes #0 = { nounwind }

0 commit comments

Comments
 (0)