brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.4 KiB · ea508a4 Raw
206 lines · c
1// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm %s -o - -verify | FileCheck %s2 3// CHECK: @weakvar = weak{{.*}} global4// CHECK: @__weakvar_alias ={{.*}} global5// CHECK: @correct_linkage = weak{{.*}} global6 7 8// CHECK-DAG: @both ={{.*}} alias void (), ptr @__both9// CHECK-DAG: @both2 ={{.*}} alias void (), ptr @__both210// CHECK-DAG: @weakvar_alias = weak{{.*}} alias i32, ptr @__weakvar_alias11// CHECK-DAG: @foo = weak{{.*}} alias void (), ptr @__foo12// CHECK-DAG: @foo2 = weak{{.*}} alias void (), ptr @__foo213// CHECK-DAG: @stutter = weak{{.*}} alias void (), ptr @__stutter14// CHECK-DAG: @stutter2 = weak{{.*}} alias void (), ptr @__stutter215// CHECK-DAG: @declfirst = weak{{.*}} alias void (), ptr @__declfirst16// CHECK-DAG: @declfirstattr = weak{{.*}} alias void (), ptr @__declfirstattr17// CHECK-DAG: @mix2 = weak{{.*}} alias void (), ptr @__mix218// CHECK-DAG: @a1 = weak{{.*}} alias void (), ptr @__a119// CHECK-DAG: @xxx = weak{{.*}} alias i32 (), ptr @__xxx20// CHECK-DAG: @undecfunc_alias1 = weak{{.*}} alias void (), ptr @undecfunc21// CHECK-DAG: @undecfunc_alias2 = weak{{.*}} alias void (), ptr @undecfunc22// CHECK-DAG: @undecfunc_alias3 = weak{{.*}} alias void (), ptr @undecfunc23// CHECK-DAG: @undecfunc_alias4 = weak{{.*}} alias void (), ptr @undecfunc24 25 26 27// CHECK-LABEL: define weak{{.*}} void @weakdef()28 29 30#pragma weak weakvar31int weakvar;32 33#pragma weak weakdef34void weakdef(void) {}35 36#pragma weak param // expected-warning {{weak identifier 'param' never declared}}37#pragma weak correct_linkage38void f(int param) {39  int correct_linkage;40}41 42#pragma weak weakvar_alias = __weakvar_alias43int __weakvar_alias;44 45#pragma weak foo = __foo46void __foo(void) {}47// CHECK-LABEL: define{{.*}} void @__foo()48 49 50void __foo2(void) {}51#pragma weak foo2 = __foo252// CHECK-LABEL: define{{.*}} void @__foo2()53 54 55///// test errors56 57#pragma weak unused // expected-warning {{weak identifier 'unused' never declared}}58#pragma weak unused_alias = __unused_alias  // expected-warning {{weak identifier '__unused_alias' never declared}}59 60#pragma weak td // expected-warning {{'weak' attribute only applies to variables and functions}}61typedef int td;62 63#pragma weak td2 = __td2 // expected-warning {{'weak' attribute only applies to variables and functions}}64typedef int __td2;65 66typedef int __td3;67#pragma weak td3 = __td3 // expected-warning {{'weak' attribute only applies to variables and functions}}68 69///// test weird cases70 71// test repeats72 73#pragma weak stutter = __stutter74#pragma weak stutter = __stutter75void __stutter(void) {}76// CHECK-LABEL: define{{.*}} void @__stutter()77 78void __stutter2(void) {}79#pragma weak stutter2 = __stutter280#pragma weak stutter2 = __stutter281// CHECK-LABEL: define{{.*}} void @__stutter2()82 83 84// test decl/pragma weak order85 86void __declfirst(void);87#pragma weak declfirst = __declfirst88void __declfirst(void) {}89// CHECK-LABEL: define{{.*}} void @__declfirst()90 91void __declfirstattr(void) __attribute((noinline));92#pragma weak declfirstattr = __declfirstattr93void __declfirstattr(void) {}94// CHECK-LABEL: define{{.*}} void @__declfirstattr()95 96//// test that other attributes are preserved97 98//// ensure that pragma weak/__attribute((weak)) play nice99 100void mix(void);101#pragma weak mix102__attribute((weak)) void mix(void) { }103// CHECK-LABEL: define weak{{.*}} void @mix()104 105// ensure following __attributes are preserved and that only a single106// alias is generated107#pragma weak mix2 = __mix2108void __mix2(void) __attribute((noinline));109void __mix2(void) __attribute((noinline));110void __mix2(void) {}111// CHECK-LABEL: define{{.*}} void @__mix2()112 113////////////// test #pragma weak/__attribute combinations114 115// if the SAME ALIAS is already declared then it overrides #pragma weak116// resulting in a non-weak alias in this case117void both(void) __attribute((alias("__both")));118#pragma weak both = __both119void __both(void) {}120// CHECK-LABEL: define{{.*}} void @__both()121 122// if the TARGET is previously declared then whichever aliasing method123// comes first applies and subsequent aliases are discarded.124// TODO: warn about this125 126void __both2(void);127void both2(void) __attribute((alias("__both2"))); // first, wins128#pragma weak both2 = __both2129void __both2(void) {}130// CHECK-LABEL: define{{.*}} void @__both2()131 132///////////// ensure that #pragma weak does not alter existing __attributes()133 134void __a1(void) __attribute((noinline));135#pragma weak a1 = __a1136void __a1(void) {}137// CHECK: define{{.*}} void @__a1() [[NI:#[0-9]+]]138 139#pragma weak xxx = __xxx140__attribute((noinline,const)) int __xxx(void) { return 0; }141// CHECK: i32 @__xxx() [[RN:#[0-9]+]]142 143///////////// PR28611: Try multiple aliases of same undeclared symbol or alias144#pragma weak undecfunc_alias1 = undecfunc145#pragma weak undecfunc_alias1 = undecfunc // Try specifying same alias/target pair a second time.146#pragma weak undecfunc_alias3 = undecfunc_alias2 // expected-warning {{alias will always resolve to undecfunc}}147#pragma weak undecfunc_alias4 = undecfunc_alias2 // expected-warning {{alias will always resolve to undecfunc}}148#pragma weak undecfunc_alias2 = undecfunc149void undecfunc_alias2(void);150void undecfunc(void) { }151 152///////////// PR10878: Make sure we can call a weak alias153void SHA512Pad(void *context) {}154#pragma weak SHA384Pad = SHA512Pad155void PR10878(void) { SHA384Pad(0); }156// CHECK: call void @SHA384Pad(ptr noundef null)157 158 159// PR14046: Parse #pragma weak in function-local context160extern int PR14046e(void);161void PR14046f(void) {162#pragma weak PR14046e163  PR14046e();164}165// CHECK: declare extern_weak i32 @PR14046e()166 167// Parse #pragma weak after a label or case statement168extern int PR16705a(void);169extern int PR16705b(void);170extern int PR16705c(void);171void PR16705f(int a) {172  switch(a) {173  case 1:174#pragma weak PR16705a175    PR16705a();176  default:177#pragma weak PR16705b178    PR16705b();179  }180label:181  #pragma weak PR16705c182  PR16705c();183}184 185// CHECK: declare extern_weak i32 @PR16705a()186// CHECK: declare extern_weak i32 @PR16705b()187// CHECK: declare extern_weak i32 @PR16705c()188 189 190///////////// TODO: stuff that still doesn't work191 192// due to the fact that disparate TopLevelDecls cannot affect each other193// (due to clang's Parser and ASTConsumer behavior, and quite reasonable)194// #pragma weak must appear before or within the same TopLevelDecl as it195// references.196void yyy(void){}197void zzz(void){}198#pragma weak yyy199// NOTE: weak doesn't apply, not before or in same TopLevelDec(!)200// CHECK-LABEL: define{{.*}} void @yyy()201 202int correct_linkage;203 204// CHECK: attributes [[NI]] = { noinline nounwind{{.*}} }205// CHECK: attributes [[RN]] = { noinline nounwind optnone willreturn memory(none){{.*}} }206