зеркало из https://github.com/microsoft/clang-1.git
Implement #pragma redefine_extname.
This fixes PR5172 and allows clang to compile C++ programs on Solaris using the system headers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150881 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
65005eb83b
Коммит
5f3c163b7b
|
@ -162,6 +162,7 @@ class Parser : public CodeCompletionHandler {
|
||||||
OwningPtr<PragmaHandler> MSStructHandler;
|
OwningPtr<PragmaHandler> MSStructHandler;
|
||||||
OwningPtr<PragmaHandler> UnusedHandler;
|
OwningPtr<PragmaHandler> UnusedHandler;
|
||||||
OwningPtr<PragmaHandler> WeakHandler;
|
OwningPtr<PragmaHandler> WeakHandler;
|
||||||
|
OwningPtr<PragmaHandler> RedefineExtnameHandler;
|
||||||
OwningPtr<PragmaHandler> FPContractHandler;
|
OwningPtr<PragmaHandler> FPContractHandler;
|
||||||
OwningPtr<PragmaHandler> OpenCLExtensionHandler;
|
OwningPtr<PragmaHandler> OpenCLExtensionHandler;
|
||||||
|
|
||||||
|
|
|
@ -469,6 +469,13 @@ public:
|
||||||
/// identifier, declared or undeclared
|
/// identifier, declared or undeclared
|
||||||
llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers;
|
llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers;
|
||||||
|
|
||||||
|
/// ExtnameUndeclaredIdentifiers - Identifiers contained in
|
||||||
|
/// #pragma redefine_extname before declared. Used in Solaris system headers
|
||||||
|
/// to define functions that occur in multiple standards to call the version
|
||||||
|
/// in the currently selected standard.
|
||||||
|
llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers;
|
||||||
|
|
||||||
|
|
||||||
/// \brief Load weak undeclared identifiers from the external source.
|
/// \brief Load weak undeclared identifiers from the external source.
|
||||||
void LoadExternalWeakUndeclaredIdentifiers();
|
void LoadExternalWeakUndeclaredIdentifiers();
|
||||||
|
|
||||||
|
@ -5719,6 +5726,14 @@ public:
|
||||||
SourceLocation PragmaLoc,
|
SourceLocation PragmaLoc,
|
||||||
SourceLocation WeakNameLoc);
|
SourceLocation WeakNameLoc);
|
||||||
|
|
||||||
|
/// ActOnPragmaRedefineExtname - Called on well formed
|
||||||
|
/// #pragma redefine_extname oldname newname.
|
||||||
|
void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName,
|
||||||
|
IdentifierInfo* AliasName,
|
||||||
|
SourceLocation PragmaLoc,
|
||||||
|
SourceLocation WeakNameLoc,
|
||||||
|
SourceLocation AliasNameLoc);
|
||||||
|
|
||||||
/// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
|
/// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
|
||||||
void ActOnPragmaWeakAlias(IdentifierInfo* WeakName,
|
void ActOnPragmaWeakAlias(IdentifierInfo* WeakName,
|
||||||
IdentifierInfo* AliasName,
|
IdentifierInfo* AliasName,
|
||||||
|
|
|
@ -333,6 +333,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
|
||||||
Builder.defineMacro("__ATOMIC_ACQ_REL", "4");
|
Builder.defineMacro("__ATOMIC_ACQ_REL", "4");
|
||||||
Builder.defineMacro("__ATOMIC_SEQ_CST", "5");
|
Builder.defineMacro("__ATOMIC_SEQ_CST", "5");
|
||||||
|
|
||||||
|
// Support for #pragma redefine_extname (Sun compatibility)
|
||||||
|
Builder.defineMacro("__PRAGMA_REDEFINE_EXTNAME", "1");
|
||||||
|
|
||||||
// As sad as it is, enough software depends on the __VERSION__ for version
|
// As sad as it is, enough software depends on the __VERSION__ for version
|
||||||
// checks that it is necessary to report 4.2.1 (the base GCC version we claim
|
// checks that it is necessary to report 4.2.1 (the base GCC version we claim
|
||||||
// compatibility with) first.
|
// compatibility with) first.
|
||||||
|
|
|
@ -426,6 +426,44 @@ void PragmaWeakHandler::HandlePragma(Preprocessor &PP,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #pragma redefine_extname identifier identifier
|
||||||
|
void PragmaRedefineExtnameHandler::HandlePragma(Preprocessor &PP,
|
||||||
|
PragmaIntroducerKind Introducer,
|
||||||
|
Token &RedefToken) {
|
||||||
|
SourceLocation RedefLoc = RedefToken.getLocation();
|
||||||
|
|
||||||
|
Token Tok;
|
||||||
|
PP.Lex(Tok);
|
||||||
|
if (Tok.isNot(tok::identifier)) {
|
||||||
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) <<
|
||||||
|
"redefine_extname";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
IdentifierInfo *RedefName = Tok.getIdentifierInfo(), *AliasName = 0;
|
||||||
|
SourceLocation RedefNameLoc = Tok.getLocation(), AliasNameLoc;
|
||||||
|
|
||||||
|
PP.Lex(Tok);
|
||||||
|
if (Tok.isNot(tok::identifier)) {
|
||||||
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
|
||||||
|
<< "redefine_extname";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AliasName = Tok.getIdentifierInfo();
|
||||||
|
AliasNameLoc = Tok.getLocation();
|
||||||
|
PP.Lex(Tok);
|
||||||
|
|
||||||
|
if (Tok.isNot(tok::eod)) {
|
||||||
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
|
||||||
|
"redefine_extname";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Actions.ActOnPragmaRedefineExtname(RedefName, AliasName, RedefLoc,
|
||||||
|
RedefNameLoc, AliasNameLoc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PragmaFPContractHandler::HandlePragma(Preprocessor &PP,
|
PragmaFPContractHandler::HandlePragma(Preprocessor &PP,
|
||||||
PragmaIntroducerKind Introducer,
|
PragmaIntroducerKind Introducer,
|
||||||
|
|
|
@ -90,6 +90,16 @@ public:
|
||||||
Token &FirstToken);
|
Token &FirstToken);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PragmaRedefineExtnameHandler : public PragmaHandler {
|
||||||
|
Sema &Actions;
|
||||||
|
public:
|
||||||
|
explicit PragmaRedefineExtnameHandler(Sema &A)
|
||||||
|
: PragmaHandler("redefine_extname"), Actions(A) {}
|
||||||
|
|
||||||
|
virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
||||||
|
Token &FirstToken);
|
||||||
|
};
|
||||||
|
|
||||||
class PragmaOpenCLExtensionHandler : public PragmaHandler {
|
class PragmaOpenCLExtensionHandler : public PragmaHandler {
|
||||||
Sema &Actions;
|
Sema &Actions;
|
||||||
Parser &parser;
|
Parser &parser;
|
||||||
|
|
|
@ -64,6 +64,9 @@ Parser::Parser(Preprocessor &pp, Sema &actions)
|
||||||
WeakHandler.reset(new PragmaWeakHandler(actions));
|
WeakHandler.reset(new PragmaWeakHandler(actions));
|
||||||
PP.AddPragmaHandler(WeakHandler.get());
|
PP.AddPragmaHandler(WeakHandler.get());
|
||||||
|
|
||||||
|
RedefineExtnameHandler.reset(new PragmaRedefineExtnameHandler(actions));
|
||||||
|
PP.AddPragmaHandler(RedefineExtnameHandler.get());
|
||||||
|
|
||||||
FPContractHandler.reset(new PragmaFPContractHandler(actions, *this));
|
FPContractHandler.reset(new PragmaFPContractHandler(actions, *this));
|
||||||
PP.AddPragmaHandler("STDC", FPContractHandler.get());
|
PP.AddPragmaHandler("STDC", FPContractHandler.get());
|
||||||
|
|
||||||
|
@ -382,6 +385,8 @@ Parser::~Parser() {
|
||||||
UnusedHandler.reset();
|
UnusedHandler.reset();
|
||||||
PP.RemovePragmaHandler(WeakHandler.get());
|
PP.RemovePragmaHandler(WeakHandler.get());
|
||||||
WeakHandler.reset();
|
WeakHandler.reset();
|
||||||
|
PP.RemovePragmaHandler(RedefineExtnameHandler.get());
|
||||||
|
RedefineExtnameHandler.reset();
|
||||||
|
|
||||||
if (getLang().OpenCL) {
|
if (getLang().OpenCL) {
|
||||||
PP.RemovePragmaHandler("OPENCL", OpenCLExtensionHandler.get());
|
PP.RemovePragmaHandler("OPENCL", OpenCLExtensionHandler.get());
|
||||||
|
|
|
@ -4059,6 +4059,13 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
|
||||||
|
|
||||||
NewVD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0),
|
NewVD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0),
|
||||||
Context, Label));
|
Context, Label));
|
||||||
|
} else if (!ExtnameUndeclaredIdentifiers.empty()) {
|
||||||
|
llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
|
||||||
|
ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier());
|
||||||
|
if (I != ExtnameUndeclaredIdentifiers.end()) {
|
||||||
|
NewVD->addAttr(I->second);
|
||||||
|
ExtnameUndeclaredIdentifiers.erase(I);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Diagnose shadowed variables before filtering for scope.
|
// Diagnose shadowed variables before filtering for scope.
|
||||||
|
@ -5157,6 +5164,13 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
|
||||||
StringLiteral *SE = cast<StringLiteral>(E);
|
StringLiteral *SE = cast<StringLiteral>(E);
|
||||||
NewFD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0), Context,
|
NewFD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0), Context,
|
||||||
SE->getString()));
|
SE->getString()));
|
||||||
|
} else if (!ExtnameUndeclaredIdentifiers.empty()) {
|
||||||
|
llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
|
||||||
|
ExtnameUndeclaredIdentifiers.find(NewFD->getIdentifier());
|
||||||
|
if (I != ExtnameUndeclaredIdentifiers.end()) {
|
||||||
|
NewFD->addAttr(I->second);
|
||||||
|
ExtnameUndeclaredIdentifiers.erase(I);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the parameter declarations from the declarator D to the function
|
// Copy the parameter declarations from the declarator D to the function
|
||||||
|
@ -10152,6 +10166,24 @@ DeclResult Sema::ActOnModuleImport(SourceLocation AtLoc,
|
||||||
return Import;
|
return Import;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sema::ActOnPragmaRedefineExtname(IdentifierInfo* Name,
|
||||||
|
IdentifierInfo* AliasName,
|
||||||
|
SourceLocation PragmaLoc,
|
||||||
|
SourceLocation NameLoc,
|
||||||
|
SourceLocation AliasNameLoc) {
|
||||||
|
Decl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc,
|
||||||
|
LookupOrdinaryName);
|
||||||
|
AsmLabelAttr *Attr =
|
||||||
|
::new (Context) AsmLabelAttr(AliasNameLoc, Context, AliasName->getName());
|
||||||
|
fprintf(stderr, "Alias name: %s\n", AliasName->getName().str().c_str());
|
||||||
|
|
||||||
|
if (PrevDecl)
|
||||||
|
PrevDecl->addAttr(Attr);
|
||||||
|
else
|
||||||
|
(void)ExtnameUndeclaredIdentifiers.insert(
|
||||||
|
std::pair<IdentifierInfo*,AsmLabelAttr*>(Name, Attr));
|
||||||
|
}
|
||||||
|
|
||||||
void Sema::ActOnPragmaWeakID(IdentifierInfo* Name,
|
void Sema::ActOnPragmaWeakID(IdentifierInfo* Name,
|
||||||
SourceLocation PragmaLoc,
|
SourceLocation PragmaLoc,
|
||||||
SourceLocation NameLoc) {
|
SourceLocation NameLoc) {
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
// RUN: %clang_cc1 -triple=i386-pc-solaris2.11 -w -emit-llvm %s -o - | FileCheck %s
|
||||||
|
|
||||||
|
#pragma redefine_extname fake real
|
||||||
|
#pragma redefine_extname name alias
|
||||||
|
|
||||||
|
extern int fake(void);
|
||||||
|
|
||||||
|
int name;
|
||||||
|
|
||||||
|
// __PRAGMA_REDEFINE_EXTNAME should be defined. This will fail if it isn't...
|
||||||
|
int fish() { return fake() + __PRAGMA_REDEFINE_EXTNAME + name; }
|
||||||
|
// Check that the call to fake() is emitted as a call to real()
|
||||||
|
// CHECK: call i32 @real()
|
||||||
|
// Check that this also works with variables names
|
||||||
|
// CHECK: load i32* @alias
|
Загрузка…
Ссылка в новой задаче