mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
Redo "Make global aliases have symbol size equal to their type"
r242520 was reverted in r244313 as the expected behaviour of the alias attribute in C is that the alias has the same size as the aliasee. However we can re-introduce adding the size on the alias when the aliasee does not, from a source code or object perspective, exist as a discrete entity. This happens when the aliasee is not a symbol, or when that symbol is private. Differential Revision: http://reviews.llvm.org/D11943 llvm-svn: 244752
This commit is contained in:
parent
8a59b4f141
commit
dcf7a81cdd
@ -1184,6 +1184,20 @@ bool AsmPrinter::doFinalization(Module &M) {
|
|||||||
|
|
||||||
// Emit the directives as assignments aka .set:
|
// Emit the directives as assignments aka .set:
|
||||||
OutStreamer->EmitAssignment(Name, lowerConstant(Alias.getAliasee()));
|
OutStreamer->EmitAssignment(Name, lowerConstant(Alias.getAliasee()));
|
||||||
|
|
||||||
|
// If the aliasee does not correspond to a symbol in the output, i.e. the
|
||||||
|
// alias is not of an object or the aliased object is private, then set the
|
||||||
|
// size of the alias symbol from the type of the alias. We don't do this in
|
||||||
|
// other situations as the alias and aliasee having differing types but same
|
||||||
|
// size may be intentional.
|
||||||
|
const GlobalObject *BaseObject = Alias.getBaseObject();
|
||||||
|
if (MAI->hasDotTypeDotSizeDirective() && Alias.getValueType()->isSized() &&
|
||||||
|
(!BaseObject || BaseObject->hasPrivateLinkage())) {
|
||||||
|
const DataLayout &DL = M.getDataLayout();
|
||||||
|
uint64_t Size = DL.getTypeAllocSize(Alias.getValueType());
|
||||||
|
OutStreamer->emitELFSize(cast<MCSymbolELF>(Name),
|
||||||
|
MCConstantExpr::create(Size, OutContext));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
|
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
|
||||||
|
@ -33,10 +33,13 @@ define void @g1(i32 %a1, i32 %a2) {
|
|||||||
|
|
||||||
;CHECK: .globl x
|
;CHECK: .globl x
|
||||||
;CHECK: x = .L_MergedGlobals
|
;CHECK: x = .L_MergedGlobals
|
||||||
|
;CHECK: .size x, 4
|
||||||
;CHECK: .globl y
|
;CHECK: .globl y
|
||||||
;CHECK: y = .L_MergedGlobals+4
|
;CHECK: y = .L_MergedGlobals+4
|
||||||
|
;CHECK: .size y, 4
|
||||||
;CHECK: .globl z
|
;CHECK: .globl z
|
||||||
;CHECK: z = .L_MergedGlobals+8
|
;CHECK: z = .L_MergedGlobals+8
|
||||||
|
;CHECK: .size z, 4
|
||||||
|
|
||||||
;CHECK-APPLE-IOS: .zerofill __DATA,__bss,l__MergedGlobals,12,3
|
;CHECK-APPLE-IOS: .zerofill __DATA,__bss,l__MergedGlobals,12,3
|
||||||
|
|
||||||
|
@ -39,8 +39,10 @@ define void @f1(i32 %a1, i32 %a2, i32 %a3) {
|
|||||||
;CHECK: z = .L_MergedGlobals
|
;CHECK: z = .L_MergedGlobals
|
||||||
;CHECK: .globl x
|
;CHECK: .globl x
|
||||||
;CHECK: x = .L_MergedGlobals+4
|
;CHECK: x = .L_MergedGlobals+4
|
||||||
|
;CHECK: .size x, 4000
|
||||||
;CHECK: .globl y
|
;CHECK: .globl y
|
||||||
;CHECK: y = .L_MergedGlobals.1
|
;CHECK: y = .L_MergedGlobals.1
|
||||||
|
;CHECK: .size y, 4000
|
||||||
|
|
||||||
;CHECK-APPLE-IOS-NOT: _z = l__MergedGlobals
|
;CHECK-APPLE-IOS-NOT: _z = l__MergedGlobals
|
||||||
;CHECK-APPLE-IOS:.globl _x
|
;CHECK-APPLE-IOS:.globl _x
|
||||||
|
@ -2,19 +2,35 @@
|
|||||||
|
|
||||||
; CHECK: .globl test
|
; CHECK: .globl test
|
||||||
|
|
||||||
|
; CHECK: .Lstructvar:
|
||||||
|
; CHECK: .size .Lstructvar, 8
|
||||||
|
|
||||||
; CHECK: .globl foo1
|
; CHECK: .globl foo1
|
||||||
; CHECK: foo1 = bar
|
; CHECK: foo1 = bar
|
||||||
|
; CHECK-NOT: .size foo1
|
||||||
|
|
||||||
; CHECK: .globl foo2
|
; CHECK: .globl foo2
|
||||||
; CHECK: foo2 = bar
|
; CHECK: foo2 = bar
|
||||||
|
; CHECK-NOT: .size foo2
|
||||||
|
|
||||||
; CHECK: .weak bar_f
|
; CHECK: .weak bar_f
|
||||||
; CHECK: bar_f = foo_f
|
; CHECK: bar_f = foo_f
|
||||||
|
; CHECK-NOT: .size bar_f
|
||||||
|
|
||||||
; CHECK: bar_i = bar
|
; CHECK: bar_i = bar
|
||||||
|
; CHECK-NOT: .size bar_i
|
||||||
|
|
||||||
; CHECK: .globl A
|
; CHECK: .globl A
|
||||||
; CHECK: A = bar
|
; CHECK: A = bar
|
||||||
|
; CHECK-NOT: .size A
|
||||||
|
|
||||||
|
; CHECK: .globl elem0
|
||||||
|
; CHECK: elem0 = .Lstructvar
|
||||||
|
; CHECK: .size elem0, 4
|
||||||
|
|
||||||
|
; CHECK: .globl elem1
|
||||||
|
; CHECK: elem1 = .Lstructvar+4
|
||||||
|
; CHECK: .size elem1, 4
|
||||||
|
|
||||||
@bar = global i32 42
|
@bar = global i32 42
|
||||||
@foo1 = alias i32* @bar
|
@foo1 = alias i32* @bar
|
||||||
@ -31,6 +47,10 @@ define i32 @foo_f() {
|
|||||||
|
|
||||||
@A = alias bitcast (i32* @bar to i64*)
|
@A = alias bitcast (i32* @bar to i64*)
|
||||||
|
|
||||||
|
@structvar = private global {i32, i32} {i32 1, i32 2}
|
||||||
|
@elem0 = alias getelementptr({i32, i32}, {i32, i32}* @structvar, i32 0, i32 0)
|
||||||
|
@elem1 = alias getelementptr({i32, i32}, {i32, i32}* @structvar, i32 0, i32 1)
|
||||||
|
|
||||||
define i32 @test() {
|
define i32 @test() {
|
||||||
entry:
|
entry:
|
||||||
%tmp = load i32, i32* @foo1
|
%tmp = load i32, i32* @foo1
|
||||||
|
@ -37,7 +37,10 @@ define void @g1(i32 %a1, i32 %a2) {
|
|||||||
|
|
||||||
;CHECK-MERGE: .globl x
|
;CHECK-MERGE: .globl x
|
||||||
;CHECK-MERGE: x = .L_MergedGlobals
|
;CHECK-MERGE: x = .L_MergedGlobals
|
||||||
|
;CHECK-MERGE: .size x, 4
|
||||||
;CHECK-MERGE: .globl y
|
;CHECK-MERGE: .globl y
|
||||||
;CHECK-MERGE: y = .L_MergedGlobals+4
|
;CHECK-MERGE: y = .L_MergedGlobals+4
|
||||||
|
;CHECK-MERGE: .size y, 4
|
||||||
;CHECK-MERGE: .globl z
|
;CHECK-MERGE: .globl z
|
||||||
;CHECK-MERGE: z = .L_MergedGlobals+8
|
;CHECK-MERGE: z = .L_MergedGlobals+8
|
||||||
|
;CHECK-MERGE: .size z, 4
|
||||||
|
Loading…
Reference in New Issue
Block a user