Skip to content

Commit 4a6014c

Browse files
committed
staging
1 parent c73bcdc commit 4a6014c

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,9 @@ class Sema final : public SemaBase {
23092309
ActOnPragmaMSFunction(SourceLocation Loc,
23102310
const llvm::SmallVectorImpl<StringRef> &NoBuiltins);
23112311

2312+
NamedDecl *lookupExternCName(IdentifierInfo *IdentId, SourceLocation NameLoc,
2313+
Scope *curScope);
2314+
23122315
/// A label from a C++ #pragma export, for a symbol that we
23132316
/// haven't seen the declaration for yet.
23142317
struct SymbolLabel {
@@ -2319,7 +2322,8 @@ class Sema final : public SemaBase {
23192322
llvm::DenseMap<IdentifierInfo *, SymbolLabel> PendingExportedNames;
23202323

23212324
/// ActonPragmaExport - called on well-formed '\#pragma export'.
2322-
void ActOnPragmaExport(IdentifierInfo *IdentId, SourceLocation ExportNameLoc);
2325+
void ActOnPragmaExport(IdentifierInfo *IdentId, SourceLocation ExportNameLoc,
2326+
Scope *curScope);
23232327

23242328
/// Only called on function definitions; if there is a pragma in scope
23252329
/// with the effect of a range-based optnone, consider marking the function

clang/lib/Parse/ParsePragma.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,6 @@ bool Parser::zOSHandlePragmaHelper(tok::TokenKind PragmaKind) {
14221422
return false;
14231423
}
14241424

1425-
// C++ could have a nested name, or be qualified with ::.
14261425
PP.Lex(Tok);
14271426
if (Tok.isNot(tok::identifier)) {
14281427
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
@@ -1441,7 +1440,7 @@ bool Parser::zOSHandlePragmaHelper(tok::TokenKind PragmaKind) {
14411440
}
14421441

14431442
PP.Lex(Tok);
1444-
Actions.ActOnPragmaExport(IdentName, IdentNameLoc);
1443+
Actions.ActOnPragmaExport(IdentName, IdentNameLoc, getCurScope());
14451444

14461445
// Because export is also a C++ keyword, we also check for that.
14471446
if (Tok.is(tok::identifier) || Tok.is(tok::kw_export)) {

clang/lib/Sema/SemaAttr.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,23 +1327,35 @@ void Sema::AddImplicitMSFunctionNoBuiltinAttr(FunctionDecl *FD) {
13271327
FD->addAttr(NoBuiltinAttr::CreateImplicit(Context, V.data(), V.size()));
13281328
}
13291329

1330-
void Sema::ActOnPragmaExport(IdentifierInfo *IdentId, SourceLocation NameLoc) {
1330+
NamedDecl *Sema::lookupExternCName(IdentifierInfo *IdentId,
1331+
SourceLocation NameLoc, Scope *curScope) {
1332+
LookupResult Result(*this, IdentId, NameLoc, LookupOrdinaryName);
1333+
LookupName(Result, curScope);
1334+
if (!getLangOpts().CPlusPlus)
1335+
return Result.getAsSingle<NamedDecl>();
1336+
for (LookupResult::iterator I = Result.begin(); I != Result.end(); ++I) {
1337+
NamedDecl *D = (*I)->getUnderlyingDecl();
1338+
if (auto *FD = dyn_cast<FunctionDecl>(D->getCanonicalDecl()))
1339+
if (FD->isExternC())
1340+
return D;
1341+
if (isa<VarDecl>(D->getCanonicalDecl()))
1342+
return D;
1343+
}
1344+
return nullptr;
1345+
}
1346+
1347+
void Sema::ActOnPragmaExport(IdentifierInfo *IdentId, SourceLocation NameLoc, Scope *curScope) {
13311348
SymbolLabel Label;
13321349
Label.NameLoc = NameLoc;
13331350
Label.Used = false;
13341351

1335-
NamedDecl *PrevDecl =
1336-
LookupSingleName(TUScope, IdentId, NameLoc, LookupOrdinaryName);
1352+
NamedDecl *PrevDecl = lookupExternCName(IdentId, NameLoc, curScope);
13371353
if (!PrevDecl) {
13381354
PendingExportedNames[IdentId] = Label;
13391355
return;
13401356
}
13411357

13421358
if (auto *FD = dyn_cast<FunctionDecl>(PrevDecl->getCanonicalDecl())) {
1343-
if (getLangOpts().CPlusPlus && !FD->isExternC()) {
1344-
PendingExportedNames[IdentId] = Label;
1345-
return;
1346-
}
13471359
if (!FD->hasExternalFormalLinkage()) {
13481360
Diag(NameLoc, diag::warn_pragma_not_applied) << "export" << PrevDecl;
13491361
return;

0 commit comments

Comments
 (0)