42 lines · c
1// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s2 3// CHECK: @.str.3 = private unnamed_addr constant [28 x i8] c"GlobalValAnnotationWithArgs\00", section "llvm.metadata"4// CHECK-NEXT: @.args = private unnamed_addr constant { i32, %struct.TestStruct } { i32 42, %struct.TestStruct { i32 1, i32 2 } }, section "llvm.metadata"5 6// CHECK: llvm.global.annotations7 8// CHECK: llvm.var.annotation9// CHECK: llvm.var.annotation10// CHECK: llvm.var.annotation11 12/* Global variable with attribute */13int X __attribute__((annotate("GlobalValAnnotation")));14 15/* Function with attribute */16int foo(int y) __attribute__((annotate("GlobalValAnnotation")))17 __attribute__((noinline));18 19int foo(int y __attribute__((annotate("LocalValAnnotation")))) {20 int x __attribute__((annotate("LocalValAnnotation")));21 x = 34;22 return y + x;23}24 25/* Attribute with struct argument. */26struct TestStruct {27 int a;28 int b;29};30int Y __attribute__((annotate(31 "GlobalValAnnotationWithArgs",32 42,33 (struct TestStruct) { .a = 1, .b = 2 }34)));35 36 37int main(void) {38 static int a __attribute__((annotate("GlobalValAnnotation")));39 a = foo(2);40 return 0;41}42