diff options
author | Hans Wennborg <hans@hanshq.net> | 2014-10-16 20:52:46 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2014-10-16 20:52:46 +0000 |
commit | 899ded9cdf53b3d84c8d0e771851cc256296bfd2 (patch) | |
tree | 05e0f0f099bab9d80d79172a08299e85c89d306f /clang/test/CodeGen/sections.c | |
parent | 933bead97d1cd46e29d347329442a3c6f7259ce7 (diff) | |
download | bcm5719-llvm-899ded9cdf53b3d84c8d0e771851cc256296bfd2.tar.gz bcm5719-llvm-899ded9cdf53b3d84c8d0e771851cc256296bfd2.zip |
MS Compat: mark globals emitted in read-only sections const
They cannot be written to, so marking them const makes sense and may improve
optimisation.
As a side-effect, SectionInfos has to be moved from Sema to ASTContext.
It also fixes this problem, that occurs when compiling ATL:
warning LNK4254: section 'ATL' (C0000040) merged into '.rdata' (40000040) with different attributes
The ATL headers are putting variables in a special section that's marked
read-only. However, Clang currently can't model that read-onlyness in the IR.
But, by making the variables const, the section does become read-only, and
the linker warning is avoided.
Differential Revision: http://reviews.llvm.org/D5812
llvm-svn: 219960
Diffstat (limited to 'clang/test/CodeGen/sections.c')
-rw-r--r-- | clang/test/CodeGen/sections.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/test/CodeGen/sections.c b/clang/test/CodeGen/sections.c index 8d93fed480e..4c59881b73b 100644 --- a/clang/test/CodeGen/sections.c +++ b/clang/test/CodeGen/sections.c @@ -31,6 +31,14 @@ int i; int TEST1; #pragma bss_seg(pop) int TEST2; + +#pragma section("read_flag_section", read) +// Even though they are not declared const, these become constant since they are +// in a read-only section. +__declspec(allocate("read_flag_section")) int unreferenced = 0; +extern __declspec(allocate("read_flag_section")) int referenced = 42; +int *user() { return &referenced; } + #ifdef __cplusplus } #endif @@ -47,5 +55,7 @@ int TEST2; //CHECK: @i = global i32 0 //CHECK: @TEST1 = global i32 0 //CHECK: @TEST2 = global i32 0, section ".bss1" +//CHECK: @unreferenced = constant i32 0, section "read_flag_section" +//CHECK: @referenced = constant i32 42, section "read_flag_section" //CHECK: define void @g() //CHECK: define void @h() {{.*}} section ".my_code" |