Skip to content

Commit 5f0a685

Browse files
committed
Improve locations in messages
1 parent c6eb30f commit 5f0a685

File tree

11 files changed

+57
-70
lines changed

11 files changed

+57
-70
lines changed

clang/include/clang/Parse/Parser.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,11 +859,10 @@ class Parser : public CodeCompletionHandler {
859859

860860
/// Helper functions for handling zOS pragmas.
861861
NestedNameSpecifier *zOSParseIdentifier(StringRef PragmaName,
862-
const IdentifierInfo *IdentName,
863-
SourceLocation &);
862+
const IdentifierInfo *IdentName);
864863
bool zOSParseParameterList(StringRef PragmaName,
865864
std::optional<SmallVector<QualType, 4>> &TypeList,
866-
Qualifiers &CVQual, SourceLocation &);
865+
Qualifiers &CVQual);
867866
bool zOSHandlePragmaHelper(tok::TokenKind);
868867

869868
/// Handle the annotation token produced for

clang/include/clang/Sema/DeclSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ class Declarator {
21342134
/// Whether this declarator is marked as _Export.
21352135
bool IsExport() const { return ExportSpecified; }
21362136

2137-
/// Get the location of the _Export keyword
2137+
/// Get the location of the _Export keyword.
21382138
SourceLocation getExportLoc() const { return ExportLoc; }
21392139

21402140
/// Reset the contents of this Declarator.

clang/lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6779,7 +6779,7 @@ void Parser::ParseDeclaratorInternal(Declarator &D,
67796779

67806780
tok::TokenKind Kind = Tok.getKind();
67816781

6782-
// If this variable or function is marked as _Export, set the bit
6782+
// If this variable or function is marked as _Export, set the bit.
67836783
if (Kind == tok::kw__Export) {
67846784
SourceLocation loc = ConsumeToken();
67856785
D.SetExport(loc);

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,6 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
17521752
// If attributes exist after tag, parse them.
17531753
for (;;) {
17541754
MaybeParseAttributes(PAKM_CXX11 | PAKM_Declspec | PAKM_GNU, attrs);
1755-
// If the token is _Export, set the bits
17561755
if (Tok.is(tok::kw__Export)) {
17571756
SourceLocation loc = ConsumeToken();
17581757
DS.setExportSpec(loc);

clang/lib/Parse/ParsePragma.cpp

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,53 +1417,47 @@ bool Parser::HandlePragmaMSAllocText(StringRef PragmaName,
14171417
return true;
14181418
}
14191419

1420-
NestedNameSpecifier *Parser::zOSParseIdentifier(StringRef PragmaName,
1421-
const IdentifierInfo *IdentName,
1422-
SourceLocation &PrevLoc) {
1420+
NestedNameSpecifier *
1421+
Parser::zOSParseIdentifier(StringRef PragmaName,
1422+
const IdentifierInfo *IdentName) {
14231423
NestedNameSpecifier *NestedId = nullptr;
14241424
if (PP.getLangOpts().CPlusPlus) {
14251425
if (Tok.is(tok::coloncolon)) {
1426+
// Nothing to do.
14261427
} else if (Actions.CurContext->isNamespace()) {
14271428
auto *NS = cast<NamespaceDecl>(Actions.CurContext);
14281429
NestedId =
14291430
NestedNameSpecifier::Create(Actions.Context, NS->getIdentifier());
14301431
NestedId =
14311432
NestedNameSpecifier::Create(Actions.Context, NestedId, IdentName);
1432-
PrevLoc = Tok.getLocation();
14331433
PP.Lex(Tok);
14341434
} else {
14351435
NestedId = NestedNameSpecifier::Create(Actions.Context, IdentName);
1436-
PrevLoc = Tok.getLocation();
14371436
PP.Lex(Tok);
14381437
}
14391438
while (Tok.is(tok::coloncolon)) {
1440-
PrevLoc = Tok.getLocation();
14411439
PP.Lex(Tok);
14421440
if (Tok.isNot(tok::identifier)) {
1443-
PP.Diag(Tok.getLocation().isValid() ? Tok.getLocation() : PrevLoc,
1444-
diag::warn_pragma_expected_identifier)
1441+
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
14451442
<< PragmaName;
14461443
return nullptr;
14471444
}
14481445
IdentifierInfo *II = Tok.getIdentifierInfo();
14491446
NestedId = NestedNameSpecifier::Create(Actions.Context, NestedId, II);
1450-
PrevLoc = Tok.getLocation();
14511447
PP.Lex(Tok);
14521448
}
14531449
} else {
14541450
NestedId = NestedNameSpecifier::Create(Actions.Context, IdentName);
1455-
PrevLoc = Tok.getLocation();
14561451
PP.Lex(Tok);
14571452
}
14581453
return NestedId;
14591454
}
14601455

14611456
bool Parser::zOSParseParameterList(
14621457
StringRef PragmaName, std::optional<SmallVector<QualType, 4>> &TypeList,
1463-
Qualifiers &CVQual, SourceLocation &PrevLoc) {
1458+
Qualifiers &CVQual) {
14641459
if (Tok.is(tok::l_paren)) {
14651460
TypeList = SmallVector<QualType, 4>();
1466-
PrevLoc = Tok.getLocation();
14671461
PP.Lex(Tok);
14681462
while (Tok.isNot(tok::eof) && !Tok.is(tok::r_paren)) {
14691463
TypeResult TResult = ParseTypeName(nullptr);
@@ -1473,18 +1467,16 @@ bool Parser::zOSParseParameterList(
14731467
TypeList->push_back(QT);
14741468
}
14751469
}
1476-
if (Tok.is(tok::comma) || Tok.is(tok::identifier)) {
1477-
PrevLoc = Tok.getLocation();
1470+
if (Tok.is(tok::comma) || Tok.is(tok::identifier))
14781471
PP.Lex(Tok);
1479-
}
14801472
}
1481-
if (Tok.is(tok::r_paren)) {
1482-
PrevLoc = Tok.getLocation();
1473+
if (Tok.is(tok::r_paren))
14831474
PP.Lex(Tok);
1484-
} else {
1475+
else {
14851476
// We ate the whole line trying to find the right paren of the parameter
1486-
// list
1487-
PP.Diag(PrevLoc, diag::warn_pragma_expected_identifier) << PragmaName;
1477+
// list.
1478+
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
1479+
<< PragmaName;
14881480
return false;
14891481
}
14901482

@@ -1496,7 +1488,6 @@ bool Parser::zOSParseParameterList(
14961488
assert(Tok.is(tok::kw_volatile));
14971489
CVQual.addVolatile();
14981490
}
1499-
PrevLoc = Tok.getLocation();
15001491
PP.Lex(Tok);
15011492
}
15021493
}
@@ -1515,34 +1506,28 @@ bool Parser::zOSHandlePragmaHelper(tok::TokenKind PragmaKind) {
15151506
(std::pair<std::unique_ptr<Token[]>, size_t> *)Tok.getAnnotationValue();
15161507
PP.EnterTokenStream(std::move(TheTokens->first), TheTokens->second, true,
15171508
false);
1518-
ConsumeAnnotationToken(); // The annotation token.
1509+
ConsumeAnnotationToken();
15191510

15201511
do {
1521-
SourceLocation PrevTokLocation = Tok.getLocation();
1522-
15231512
PP.Lex(Tok);
15241513
if (Tok.isNot(tok::l_paren)) {
1525-
PP.Diag(Tok.getLocation().isValid() ? Tok.getLocation() : PrevTokLocation,
1526-
diag::warn_pragma_expected_lparen)
1514+
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen)
15271515
<< PragmaName;
15281516
return false;
15291517
}
15301518

15311519
// C++ could have a nested name, or be qualified with ::.
1532-
PrevTokLocation = Tok.getLocation();
15331520
PP.Lex(Tok);
15341521
if (Tok.isNot(tok::identifier) &&
15351522
!(PP.getLangOpts().CPlusPlus && Tok.is(tok::coloncolon))) {
1536-
PP.Diag(Tok.getLocation().isValid() ? Tok.getLocation() : PrevTokLocation,
1537-
diag::warn_pragma_expected_identifier)
1523+
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
15381524
<< PragmaName;
15391525
return false;
15401526
}
15411527

15421528
IdentifierInfo *IdentName = Tok.getIdentifierInfo();
15431529
SourceLocation IdentNameLoc = Tok.getLocation();
1544-
NestedNameSpecifier *NestedId =
1545-
zOSParseIdentifier(PragmaName, IdentName, PrevTokLocation);
1530+
NestedNameSpecifier *NestedId = zOSParseIdentifier(PragmaName, IdentName);
15461531
if (!NestedId)
15471532
return false;
15481533

@@ -1552,13 +1537,12 @@ bool Parser::zOSHandlePragmaHelper(tok::TokenKind PragmaKind) {
15521537
Qualifiers CVQual;
15531538

15541539
if (PP.getLangOpts().CPlusPlus && Tok.is(tok::l_paren)) {
1555-
if (!zOSParseParameterList(PragmaName, TypeList, CVQual, PrevTokLocation))
1540+
if (!zOSParseParameterList(PragmaName, TypeList, CVQual))
15561541
return false;
15571542
}
15581543

15591544
if (Tok.isNot(tok::r_paren)) {
1560-
PP.Diag(Tok.getLocation().isValid() ? Tok.getLocation() : PrevTokLocation,
1561-
diag::warn_pragma_expected_rparen)
1545+
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_rparen)
15621546
<< PragmaName;
15631547
return false;
15641548
}
@@ -1567,7 +1551,7 @@ bool Parser::zOSHandlePragmaHelper(tok::TokenKind PragmaKind) {
15671551
Actions.ActOnPragmaExport(NestedId, IdentNameLoc, std::move(TypeList),
15681552
CVQual);
15691553

1570-
// Because export is also a C++ keyword, we also check for that
1554+
// Because export is also a C++ keyword, we also check for that.
15711555
if (Tok.is(tok::identifier) || Tok.is(tok::kw_export)) {
15721556
IsPragmaExport = false;
15731557
PragmaName = Tok.getIdentifierInfo()->getName();
@@ -4363,6 +4347,7 @@ static void zOSPragmaHandlerHelper(Preprocessor &PP, Token &Tok,
43634347
AnnotTok.setAnnotationEndLoc(Tok.getLocation());
43644348
}
43654349
// Add a sentinel EoF token to the end of the list.
4350+
EoF.setLocation(Tok.getLocation());
43664351
TokenVector.push_back(EoF);
43674352
// We must allocate this array with new because EnterTokenStream is going to
43684353
// delete it later.

clang/lib/Sema/Sema.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ void Sema::ActOnEndOfTranslationUnit() {
14221422
Consumer.CompleteExternalDeclaration(D);
14231423
}
14241424

1425-
// Visit all pending #pragma export
1425+
// Visit all pending #pragma export.
14261426
for (auto &Iter : PendingExportNames) {
14271427
NestedNameSpecifier *Name = Iter.first;
14281428
PendingSymbolOverloads &Overloads = Iter.second;
@@ -1436,8 +1436,7 @@ void Sema::ActOnEndOfTranslationUnit() {
14361436
} else
14371437
Consumer.CompletePragmaExport(D);
14381438
} else
1439-
Diag(D->getLocation(), diag::warn_pragma_not_applied)
1440-
<< "export" << D;
1439+
Diag(I.NameLoc, diag::warn_pragma_not_applied) << "export" << D;
14411440
} else
14421441
Diag(I.NameLoc, diag::warn_failed_to_resolve_pragma) << "export";
14431442
}

clang/lib/Sema/SemaAttr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ FunctionDecl *Sema::tryFunctionLookUpInPragma(NestedNameSpecifier *NestedName,
13851385
}
13861386
F.done();
13871387
// Loop over all the found decls and see if the arguments match
1388-
// any of the results
1388+
// any of the results.
13891389
for (LookupResult::iterator I = Result.begin(); I != Result.end(); ++I) {
13901390
NamedDecl *ND = (*I)->getUnderlyingDecl();
13911391
FunctionDecl *FD = dyn_cast<FunctionDecl>(ND);
@@ -1438,14 +1438,14 @@ Sema::trySymbolLookUpInPragma(NestedNameSpecifier *NestedName,
14381438
return nullptr;
14391439
};
14401440

1441-
// global variable or function in a namespace
1441+
// global variable or function in a namespace.
14421442
if (NamespaceDecl *ND = Result.getAsSingle<NamespaceDecl>()) {
14431443
if (ND->getIdentifierNamespace() == Decl::IDNS_Namespace) {
14441444
return MatchDecl(ND);
14451445
}
14461446
}
14471447

1448-
// data or function member
1448+
// data or function member.
14491449
if (CXXRecordDecl *RD = Result.getAsSingle<CXXRecordDecl>()) {
14501450
return MatchDecl(RD);
14511451
}
@@ -1467,7 +1467,7 @@ Sema::trySymbolLookUpInPragma(NestedNameSpecifier *NestedName,
14671467
}
14681468

14691469
// Loop over all the found decls and see if the arguments match
1470-
// any of the results
1470+
// any of the results.
14711471
for (LookupResult::iterator I = Result.begin(); I != Result.end(); ++I) {
14721472
NamedDecl *ND = (*I)->getUnderlyingDecl();
14731473
FunctionDecl *FD = dyn_cast<FunctionDecl>(ND);

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6506,7 +6506,7 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
65066506
if (existingValue != VisibilityAttr::Default)
65076507
Diag(D.getExportLoc(), diag::err_mismatched_visibility);
65086508
} else
6509-
// Add VisibilityAttr::Default since the default could be hidden, etc
6509+
// Add VisibilityAttr::Default since the default could be hidden, etc.
65106510
New->addAttr(
65116511
VisibilityAttr::CreateImplicit(Context, VisibilityAttr::Default));
65126512
}

clang/test/Sema/attr-export-failing.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,3 @@
22
// RUN: %clang_cc1 -triple s390x-none-zos -fzos-extensions %s -fsyntax-only -verify
33
__attribute__((visibility("hidden"))) int _Export i; // expected-error {{visibility does not match previous declaration}}
44
class __attribute__((visibility("hidden"))) _Export C; // expected-error {{visibility does not match previous declaration}}
5-
6-
#pragma export(sf1)
7-
#pragma export(s1)
8-
static void sf1(void) {} // expected-warning{{#pragma export is applicable to symbols with external linkage only; not applied to 'sf1'}}
9-
static int s1; // expected-warning{{#pragma export is applicable to symbols with external linkage only; not applied to 's1'}}
10-
11-
static void sf0(void) {} // expected-warning{{#pragma export is applicable to symbols with external linkage only; not applied to 'sf0'}}
12-
int v0;
13-
static int s0; // expected-warning{{#pragma export is applicable to symbols with external linkage only; not applied to 's0'}}
14-
#pragma export(sf0)
15-
#pragma export(s0)

clang/test/Sema/pragma-export-failing.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33

44
#pragma export(d0) // expected-warning{{failed to resolve '#pragma export' to a declaration}}
55
#pragma export(f9) // expected-warning{{failed to resolve '#pragma export' to a declaration}}
6-
#pragma export(f0(int)) // expected-warning{{failed to resolve '#pragma export' to a declaration}}
7-
#pragma export(f3(double, double, double)) // expected-warning{{failed to resolve '#pragma export' to a declaration}}
86

9-
#pragma export(sf1)
10-
#pragma export(s1)
11-
static void sf1(void) {} // expected-warning{{#pragma export is applicable to symbols with external linkage only; not applied to 'sf1'}}
12-
static int s1; // expected-warning{{#pragma export is applicable to symbols with external linkage only; not applied to 's1'}}
7+
#pragma export(sf1) // expected-warning{{#pragma export is applicable to symbols with external linkage only; not applied to 'sf1'}}
8+
#pragma export(s1) // expected-warning{{#pragma export is applicable to symbols with external linkage only; not applied to 's1'}}
9+
static void sf1(void) {}
10+
static int s1;
1311

14-
static void sf0(void) {} // expected-warning{{#pragma export is applicable to symbols with external linkage only; not applied to 'sf0'}}
12+
static void sf0(void) {}
1513
int v0;
16-
static int s0; // expected-warning{{#pragma export is applicable to symbols with external linkage only; not applied to 's0'}}
17-
#pragma export(sf0)
18-
#pragma export(s0)
14+
static int s0;
15+
#pragma export(sf0) // expected-warning{{#pragma export is applicable to symbols with external linkage only; not applied to 'sf0'}}
16+
#pragma export(s0) // expected-warning{{#pragma export is applicable to symbols with external linkage only; not applied to 's0'}}

0 commit comments

Comments
 (0)