Skip to content

Commit 1a6d00b

Browse files
author
Zaara Syeda
committed
Address review comments
1 parent dced11b commit 1a6d00b

File tree

7 files changed

+79
-85
lines changed

7 files changed

+79
-85
lines changed

clang/docs/UsersManual.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4046,6 +4046,7 @@ Suitable variables must:
40464046
- not have internal linkage
40474047
- not have aliases
40484048
- not have section attributes
4049+
- not be thread local storage
40494050

40504051
The TOC data transformation results in the variable, not its address,
40514052
being placed in the TOC. This eliminates the need to load the address of the

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def err_fe_backend_error_attr :
9393
def warn_fe_backend_warning_attr :
9494
Warning<"call to '%0' declared with 'warning' attribute: %1">, BackendInfo,
9595
InGroup<BackendWarningAttributes>;
96-
def warn_toc_unsupported_type : Warning<"The -mtocdata option is ignored "
97-
"for %0 because %1.">, InGroup<BackendWarningAttributes>;
96+
def warn_toc_unsupported_type : Warning<"-mtocdata option is ignored "
97+
"for %0 because %1">, InGroup<BackendWarningAttributes>;
9898

9999
def err_fe_invalid_code_complete_file : Error<
100100
"cannot locate code-completion file %0">, DefaultFatal;

clang/include/clang/Driver/Options.td

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3520,25 +3520,23 @@ def fpass_plugin_EQ : Joined<["-"], "fpass-plugin=">,
35203520
MetaVarName<"<dsopath>">,
35213521
HelpText<"Load pass plugin from a dynamic shared object file (only with new pass manager).">,
35223522
MarshallingInfoStringVector<CodeGenOpts<"PassPlugins">>;
3523-
def mtocdata : Flag<["-"], "mtocdata">,
3524-
Visibility<[ClangOption, CLOption, DXCOption, CC1Option]>,
3525-
Flags<[TargetSpecific]>,
3526-
HelpText<"All suitable variables will have the TOC data transformation applied.">,
3527-
MarshallingInfoFlag<CodeGenOpts<"AllTocData">>;
3528-
def mno_tocdata : Flag<["-"], "mno-tocdata">,
3529-
Visibility<[ClangOption, CLOption, DXCOption, CC1Option]>,
3530-
Flags<[TargetSpecific]>,
3531-
HelpText<"This is the default. TOC data transformation is not applied to any"
3532-
"variables. Only variables specified explicitly in -mtocdata= will"
3533-
"have the TOC data transformation.">;
3523+
defm tocdata : BoolOption<"m","tocdata",
3524+
CodeGenOpts<"AllTocData">, DefaultFalse,
3525+
PosFlag<SetTrue, [], [ClangOption, CC1Option],
3526+
"All suitable variables will have the TOC data transformation applied">,
3527+
NegFlag<SetFalse, [], [ClangOption, CC1Option],
3528+
"This is the default. TOC data transformation is not applied to any"
3529+
"variables. Only variables specified explicitly in -mtocdata= will"
3530+
"have the TOC data transformation.">,
3531+
BothFlags<[], [ClangOption, CLOption]>>, Group<m_Group>;
35343532
def mtocdata_EQ : CommaJoined<["-"], "mtocdata=">,
3535-
Visibility<[ClangOption, CLOption, DXCOption, CC1Option]>,
3533+
Visibility<[ClangOption, CC1Option]>,
35363534
Flags<[TargetSpecific]>,
35373535
HelpText<"Specifies a list of variables to which the TOC data transformation"
35383536
"will be applied.">,
35393537
MarshallingInfoStringVector<CodeGenOpts<"TocDataVarsUserSpecified">>;
35403538
def mno_tocdata_EQ : CommaJoined<["-"], "mno-tocdata=">,
3541-
Visibility<[ClangOption, CLOption, DXCOption, CC1Option]>,
3539+
Visibility<[ClangOption, CC1Option]>,
35423540
Flags<[TargetSpecific]>,
35433541
HelpText<"Specifies a list of variables to be exempt from the TOC data"
35443542
"transformation.">,

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,7 @@ static void checkAliasForTocData(llvm::GlobalVariable *GVar,
632632
if (GVar->hasAttribute("toc-data")) {
633633
auto GVId = GVar->getGlobalIdentifier();
634634
// Is this a global variable specified by the user as local?
635-
bool UserSpecifiedTOC =
636-
llvm::binary_search(CodeGenOpts.TocDataVarsUserSpecified, GVId);
637-
if (UserSpecifiedTOC) {
635+
if ((llvm::binary_search(CodeGenOpts.TocDataVarsUserSpecified, GVId))) {
638636
Diags.Report(Location, diag::warn_toc_unsupported_type)
639637
<< GVId << "the variable has an alias";
640638
}

clang/lib/CodeGen/Targets/PPC.cpp

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -271,57 +271,55 @@ bool AIXTargetCodeGenInfo::initDwarfEHRegSizeTable(
271271

272272
void AIXTargetCodeGenInfo::setTargetAttributes(
273273
const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
274-
if (auto *GVar = dyn_cast<llvm::GlobalVariable>(GV)) {
275-
auto GVId = M.getMangledName(dyn_cast<NamedDecl>(D));
276-
277-
// Is this a global variable specified by the user as toc-data?
278-
bool UserSpecifiedTOC =
279-
llvm::binary_search(M.getCodeGenOpts().TocDataVarsUserSpecified, GVId);
280-
// Assumes the same variable cannot be in both TocVarsUserSpecified and
281-
// NoTocVars.
282-
if (UserSpecifiedTOC ||
283-
((M.getCodeGenOpts().AllTocData) &&
284-
!llvm::binary_search(M.getCodeGenOpts().NoTocDataVars, GVId))) {
285-
const unsigned long PointerSize =
286-
GV->getParent()->getDataLayout().getPointerSizeInBits() / 8;
287-
ASTContext &Context = D->getASTContext();
288-
auto *VarD = dyn_cast<VarDecl>(D);
289-
assert(VarD && "Invalid declaration of global variable.");
290-
291-
unsigned Alignment = Context.toBits(Context.getDeclAlign(D)) / 8;
292-
const auto *Ty = VarD->getType().getTypePtr();
293-
const RecordDecl *RDecl =
294-
Ty->isRecordType() ? Ty->getAs<RecordType>()->getDecl() : nullptr;
295-
296-
bool EmitDiagnostic = UserSpecifiedTOC && GV->hasExternalLinkage();
297-
if (!Ty || Ty->isIncompleteType()) {
298-
if (EmitDiagnostic)
299-
M.getDiags().Report(D->getLocation(), diag::warn_toc_unsupported_type)
300-
<< GVId << "of incomplete type";
301-
} else if (RDecl && RDecl->hasFlexibleArrayMember()) {
302-
if (UserSpecifiedTOC)
303-
M.getDiags().Report(D->getLocation(), diag::warn_toc_unsupported_type)
304-
<< GVId << "it contains a flexible array member";
305-
} else if (VarD->getTLSKind() != VarDecl::TLS_None) {
306-
if (EmitDiagnostic)
307-
M.getDiags().Report(D->getLocation(), diag::warn_toc_unsupported_type)
308-
<< GVId << "of thread local storage model";
309-
} else if (PointerSize < Context.getTypeInfo(VarD->getType()).Width / 8) {
310-
if (EmitDiagnostic)
311-
M.getDiags().Report(D->getLocation(), diag::warn_toc_unsupported_type)
312-
<< GVId << "variable is larger than a pointer";
313-
} else if (PointerSize < Alignment) {
314-
if (EmitDiagnostic)
315-
M.getDiags().Report(D->getLocation(), diag::warn_toc_unsupported_type)
316-
<< GVId << "variable is aligned wider than a pointer";
317-
} else if (D->hasAttr<SectionAttr>()) {
318-
if (EmitDiagnostic)
319-
M.getDiags().Report(D->getLocation(), diag::warn_toc_unsupported_type)
320-
<< GVId << "of a section attribute";
321-
} else if ((GV->hasExternalLinkage() || M.getCodeGenOpts().AllTocData) &&
322-
!GV->hasInternalLinkage()) {
323-
GVar->addAttribute("toc-data");
324-
}
274+
if (!isa<llvm::GlobalVariable>(GV))
275+
return;
276+
277+
auto *GVar = dyn_cast<llvm::GlobalVariable>(GV);
278+
auto GVId = M.getMangledName(dyn_cast<NamedDecl>(D));
279+
280+
// Is this a global variable specified by the user as toc-data?
281+
bool UserSpecifiedTOC =
282+
llvm::binary_search(M.getCodeGenOpts().TocDataVarsUserSpecified, GVId);
283+
// Assumes the same variable cannot be in both TocVarsUserSpecified and
284+
// NoTocVars.
285+
if (UserSpecifiedTOC ||
286+
((M.getCodeGenOpts().AllTocData) &&
287+
!llvm::binary_search(M.getCodeGenOpts().NoTocDataVars, GVId))) {
288+
const unsigned long PointerSize =
289+
GV->getParent()->getDataLayout().getPointerSizeInBits() / 8;
290+
ASTContext &Context = D->getASTContext();
291+
auto *VarD = dyn_cast<VarDecl>(D);
292+
assert(VarD && "Invalid declaration of global variable.");
293+
294+
unsigned Alignment = Context.toBits(Context.getDeclAlign(D)) / 8;
295+
const auto *Ty = VarD->getType().getTypePtr();
296+
const RecordDecl *RDecl =
297+
Ty->isRecordType() ? Ty->getAs<RecordType>()->getDecl() : nullptr;
298+
299+
bool EmitDiagnostic = UserSpecifiedTOC && GV->hasExternalLinkage();
300+
auto reportUnsupportedWarning = [&](bool ShouldEmitWarning, StringRef Msg) {
301+
if (ShouldEmitWarning)
302+
M.getDiags().Report(D->getLocation(), diag::warn_toc_unsupported_type)
303+
<< GVId << Msg;
304+
};
305+
if (!Ty || Ty->isIncompleteType()) {
306+
reportUnsupportedWarning(EmitDiagnostic, "of incomplete type");
307+
} else if (RDecl && RDecl->hasFlexibleArrayMember()) {
308+
reportUnsupportedWarning(EmitDiagnostic,
309+
"it contains a flexible array member");
310+
} else if (VarD->getTLSKind() != VarDecl::TLS_None) {
311+
reportUnsupportedWarning(EmitDiagnostic, "of thread local storage");
312+
} else if (PointerSize < Context.getTypeInfo(VarD->getType()).Width / 8) {
313+
reportUnsupportedWarning(EmitDiagnostic,
314+
"variable is larger than a pointer");
315+
} else if (PointerSize < Alignment) {
316+
reportUnsupportedWarning(EmitDiagnostic,
317+
"variable is aligned wider than a pointer");
318+
} else if (D->hasAttr<SectionAttr>()) {
319+
reportUnsupportedWarning(EmitDiagnostic, "of a section attribute");
320+
} else if ((GV->hasExternalLinkage() || M.getCodeGenOpts().AllTocData) &&
321+
!GV->hasInternalLinkage()) {
322+
GVar->addAttribute("toc-data");
325323
}
326324
}
327325
}

clang/lib/Driver/ToolChains/AIX.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,8 @@ static void addTocDataOptions(const llvm::opt::ArgList &Args,
483483
ExplicitlySpecifiedGlobals.erase(Val);
484484
}
485485

486-
const bool HasExplicitValues = !ExplicitlySpecifiedGlobals.empty();
487-
488486
auto buildExceptionList = [](const llvm::StringSet<> &ExplicitValues,
489-
const char *OptionSpelling) -> std::string {
487+
const char *OptionSpelling) {
490488
std::string Option(OptionSpelling);
491489
bool IsFirst = true;
492490
for (const auto &E : ExplicitValues) {
@@ -505,10 +503,11 @@ static void addTocDataOptions(const llvm::opt::ArgList &Args,
505503
// variables which would be exceptions to the default setting.
506504
const char *TocDataGlobalOption =
507505
TOCDataGloballyinEffect ? "-mtocdata" : "-mno-tocdata";
506+
CC1Args.push_back(TocDataGlobalOption);
507+
508508
const char *TocDataListOption =
509509
TOCDataGloballyinEffect ? "-mno-tocdata=" : "-mtocdata=";
510-
CC1Args.push_back(TocDataGlobalOption);
511-
if (HasExplicitValues)
510+
if (const bool HasExplicitValues = !ExplicitlySpecifiedGlobals.empty())
512511
CC1Args.push_back(Args.MakeArgString(llvm::Twine(
513512
buildExceptionList(ExplicitlySpecifiedGlobals, TocDataListOption))));
514513
}

clang/test/CodeGen/PowerPC/toc-data-diagnostics.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ struct large_struct {
1111
char c;
1212
};
1313

14-
struct large_struct a; // expected-warning {{The -mtocdata option is ignored for a because variable is larger than a pointer.}}
15-
long long b = 5; // expected-warning {{The -mtocdata option is ignored for b because variable is larger than a pointer.}}
16-
int __attribute__((aligned(128))) c = 0; // expected-warning {{The -mtocdata option is ignored for c because variable is aligned wider than a pointer.}}
17-
double d = 2.5; // expected-warning {{The -mtocdata option is ignored for d because variable is larger than a pointer.}}
18-
int e __attribute__((section("foo"))) = 10; // expected-warning {{The -mtocdata option is ignored for e because of a section attribute.}}
19-
__thread int f; // expected-warning {{The -mtocdata option is ignored for f because of thread local storage model.}}
14+
struct large_struct a; // expected-warning {{-mtocdata option is ignored for a because variable is larger than a pointer}}
15+
long long b = 5; // expected-warning {{-mtocdata option is ignored for b because variable is larger than a pointer}}
16+
int __attribute__((aligned(128))) c = 0; // expected-warning {{-mtocdata option is ignored for c because variable is aligned wider than a pointer}}
17+
double d = 2.5; // expected-warning {{-mtocdata option is ignored for d because variable is larger than a pointer}}
18+
int e __attribute__((section("foo"))) = 10; // expected-warning {{-mtocdata option is ignored for e because of a section attribute}}
19+
__thread int f; // expected-warning {{-mtocdata option is ignored for f because of thread local storage}}
2020

2121
struct SomeStruct;
22-
extern struct SomeStruct g; // expected-warning {{The -mtocdata option is ignored for g because of incomplete type.}}
22+
extern struct SomeStruct g; // expected-warning {{-mtocdata option is ignored for g because of incomplete type}}
2323

24-
extern int h[]; // expected-warning {{The -mtocdata option is ignored for h because of incomplete type.}}
24+
extern int h[]; // expected-warning {{-mtocdata option is ignored for h because of incomplete type}}
2525

2626
struct ty3 {
2727
int A;
2828
char C[];
2929
};
30-
struct ty3 t3 = { 4, "fo" }; // expected-warning {{The -mtocdata option is ignored for t3 because it contains a flexible array member.}}
30+
struct ty3 t3 = { 4, "fo" }; // expected-warning {{-mtocdata option is ignored for t3 because it contains a flexible array member}}
3131

3232
int globalOneWithAlias = 10;
33-
__attribute__((__alias__("globalOneWithAlias"))) extern int aliasOne; // expected-warning {{The -mtocdata option is ignored for globalOneWithAlias because the variable has an alias.}}
34-
__attribute__((__alias__("globalTwoWithAlias"))) extern int aliasTwo; // expected-warning {{The -mtocdata option is ignored for globalTwoWithAlias because the variable has an alias.}}
33+
__attribute__((__alias__("globalOneWithAlias"))) extern int aliasOne; // expected-warning {{-mtocdata option is ignored for globalOneWithAlias because the variable has an alias}}
34+
__attribute__((__alias__("globalTwoWithAlias"))) extern int aliasTwo; // expected-warning {{-mtocdata option is ignored for globalTwoWithAlias because the variable has an alias}}
3535
int globalTwoWithAlias = 20;
3636

3737

0 commit comments

Comments
 (0)