[llvm-dev] Member Function Annotation Missing

Asit Dhal via llvm-dev llvm-dev at lists.llvm.org
Fri Jan 20 15:31:07 PST 2017


I have a set of global variable and member functions annotations in my code.

//test1.cpp
#define ANNOT1 __attribute__((annotate("annot1")))
#define ANNOT2 __attribute__((annotate("annot2")))

ANNOT1 int a;
ANNOT1 int b;


class A {

 public:

    ANNOT2
    void hook() {
        //does nothing;
    }

   void dummy() {
        a = 0;
   }

};


int main() {

        A ob;
        ob.dummy();

}

//test1.ll
; ModuleID = 'test1.cpp'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

%class.A = type { i8 }

@a = global i32 0, align 4
@.str = private unnamed_addr constant [7 x i8] c"annot1\00", section
"llvm.metadata"
@.str1 = private unnamed_addr constant [10 x i8] c"test1.cpp\00", section
"llvm.metadata"
@b = global i32 0, align 4
@llvm.global.annotations = appending global [2 x { i8*, i8*, i8*, i32 }] [{
i8*, i8*, i8*, i32 } { i8* bitcast (i32* @a to i8*), i8* getelementptr
inbounds ([7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x
i8]* @.str1, i32 0, i32 0), i32 4 }, { i8*, i8*, i8*, i32 } { i8* bitcast
(i32* @b to i8*), i8* getelementptr inbounds ([7 x i8]* @.str, i32 0, i32
0), i8* getelementptr inbounds ([10 x i8]* @.str1, i32 0, i32 0), i32 5 }],
section "llvm.metadata"

; Function Attrs: uwtable
define i32 @main() #0 {
  %ob = alloca %class.A, align 1
  call void @_ZN1A5dummyEv(%class.A* %ob)
  ret i32 0
}

; Function Attrs: nounwind uwtable
define linkonce_odr void @_ZN1A5dummyEv(%class.A* %this) #1 align 2 {
  %1 = alloca %class.A*, align 8
  store %class.A* %this, %class.A** %1, align 8
  %2 = load %class.A** %1
  store i32 0, i32* @a, align 4
  ret void
}

attributes #0 = { uwtable "less-precise-fpmad"="false"
"no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
"no-infs-fp-math"="false" "no-nans-fp-math"="false"
"stack-protector-buffer-size"="8" "unsafe-fp-math"="false"
"use-soft-float"="false" }
attributes #1 = { nounwind uwtable "less-precise-fpmad"="false"
"no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
"no-infs-fp-math"="false" "no-nans-fp-math"="false"
"stack-protector-buffer-size"="8" "unsafe-fp-math"="false"
"use-soft-float"="false" }

!llvm.ident = !{!0}

!0 = !{!"Ubuntu clang version 3.6.0-2ubuntu1~trusty1
(tags/RELEASE_360/final) (based on LLVM 3.6.0)"}


Out of @a and @b, only @a is used. But in @llvm.global.annotations, both of
them appear.
But in case of member function annotations, void A::hook() has completely
disappeared from the IR. Because, member function is not called.

Can someone explain me why is this so different ?
I need void A::hook()  to be available in IR. Is it possible or any other
better solution ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170121/a1686eb0/attachment.html>


More information about the llvm-dev mailing list