diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-05-23 19:16:56 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-05-23 19:16:56 +0000 |
| commit | a5bb2f61cfb8a707cf20b61bc13bf3f3d60c50f5 (patch) | |
| tree | 3aed1affc220cd72906bd67ba29f70b2195d3b7b /llvm/lib/Target/TargetMachine.cpp | |
| parent | ffd8a3364c700f560b5d37e32364b5e53041f1cb (diff) | |
| download | bcm5719-llvm-a5bb2f61cfb8a707cf20b61bc13bf3f3d60c50f5.tar.gz bcm5719-llvm-a5bb2f61cfb8a707cf20b61bc13bf3f3d60c50f5.zip | |
Use alias linkage and visibility to decide tls access mode.
This matches both what we do for the non-thread case and what gcc does.
With this patch clang would match gcc's behaviour in
static __thread int a = 42;
extern __thread int b __attribute__((alias("a")));
int *f(void) { return &a; }
int *g(void) { return &b; }
if not for pr19843. Manually writing the IL does produce the same access modes.
It is also a step in the direction of fixing pr19844.
llvm-svn: 209543
Diffstat (limited to 'llvm/lib/Target/TargetMachine.cpp')
| -rw-r--r-- | llvm/lib/Target/TargetMachine.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp index dbd433d5240..8365f64dc54 100644 --- a/llvm/lib/Target/TargetMachine.cpp +++ b/llvm/lib/Target/TargetMachine.cpp @@ -106,19 +106,13 @@ static TLSModel::Model getSelectedTLSModel(const GlobalVariable *Var) { } TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const { - // If GV is an alias then use the aliasee for determining - // thread-localness. - if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) - GV = GA->getAliasee(); - const GlobalVariable *Var = cast<GlobalVariable>(GV); - - bool isLocal = Var->hasLocalLinkage(); - bool isDeclaration = Var->isDeclaration(); + bool isLocal = GV->hasLocalLinkage(); + bool isDeclaration = GV->isDeclaration(); bool isPIC = getRelocationModel() == Reloc::PIC_; bool isPIE = Options.PositionIndependentExecutable; // FIXME: what should we do for protected and internal visibility? // For variables, is internal different from hidden? - bool isHidden = Var->hasHiddenVisibility(); + bool isHidden = GV->hasHiddenVisibility(); TLSModel::Model Model; if (isPIC && !isPIE) { @@ -133,10 +127,13 @@ TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const { Model = TLSModel::InitialExec; } - // If the user specified a more specific model, use that. - TLSModel::Model SelectedModel = getSelectedTLSModel(Var); - if (SelectedModel > Model) - return SelectedModel; + const GlobalVariable *Var = dyn_cast<GlobalVariable>(GV); + if (Var) { + // If the user specified a more specific model, use that. + TLSModel::Model SelectedModel = getSelectedTLSModel(Var); + if (SelectedModel > Model) + return SelectedModel; + } return Model; } |

