[llvm-dev] Translation of custom attribute (defined for variables) from clang to llvm

Naveed Ul Mustafa via llvm-dev llvm-dev at lists.llvm.org
Fri Nov 25 03:52:22 PST 2016


Hi All,

I need your guidance about a custom attribute. I have defined one for 
variables. It is accepted in the source code (without any warnings from 
clang), for example in following snippet.

#define NEWATTR __attribute__((moviAttr(1)))

int main()
{
	NEWATTR volatile unsigned int a = 5;
	volatile unsigned int *p;
	p = &a;
	return (a+*p);
}


and actually when I Dump the declaration, after adding the attribute in 
handleMoviAttr() function in SemaDeclAttr.cpp as shown in following 
snippet

D->addAttr(::new (S.Context)moviAttrAttr(Attr.getRange(), S.Context, 
Val, Attr.getAttributeSpellingListIndex()));
D->dump();

It is dumped by clang with following output

VarDecl 0x440c698 <file.c:6:17, line:10:32> col:32 a 'volatile unsigned 
int'
`-moviAttrAttr 0x440c6d0 <line:6:32, col:42> 1

HOWEVER, the attribute doesnt appear in IR of the program. IR is shown 
below.

*** IR Dump Before Pre-ISel Intrinsic Lowering ***; ModuleID = 'file.bc'
source_filename = "file.c"
target datalayout = 
"e-m:e-p:32:32-f64:64-i64:64-v128:64-v64:64-v32:32-v16:16-n8:16:32-S64"
target triple = "shave"

; Function Attrs: nounwind
define i32 @main() local_unnamed_addr #0 {
   %1 = alloca i32, align 4
   %2 = bitcast i32* %1 to i8*
   call void @llvm.lifetime.start(i64 4, i8* %2)
   store volatile i32 5, i32* %1, align 4
   %3 = load volatile i32, i32* %1, align 4
   %4 = load volatile i32, i32* %1, align 4
   %5 = add i32 %4, %3
   call void @llvm.lifetime.end(i64 4, i8* %2)
   ret i32 %5
}

; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.start(i64, i8* nocapture) #1

; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.end(i64, i8* nocapture) #1

attributes #0 = { nounwind "disable-tail-calls"="false" 
"less-precise-fpmad"="false" "no-frame-pointer-elim"="true" 
"no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" 
"no-jump-tables"="false" "no-nans-fp-math"="false" 
"no-signed-zeros-fp-math"="false" "stack-protector-buffer-size"="8" 
"target-cpu"="myriad2.2" "unsafe-fp-math"="false" 
"use-soft-float"="false" }
attributes #1 = { argmemonly nounwind "target-cpu"="myriad2.2" }

Can someone help me please to solve the problem so that custom attribute 
also appears in the IR.

Thanks in advance

-- 
Naveed Ul Mustafa


More information about the llvm-dev mailing list