Index: docs/UsersManual.rst =================================================================== --- docs/UsersManual.rst +++ docs/UsersManual.rst @@ -3152,6 +3152,32 @@ .. _c: +Mark TOC Data / Not TOC Data (AIX-specific) +------------------------------------------- + +The user may specify which global variables they wish to be treated as TOC +data and which they don't. The options only take effect on AIX and are +on all other targets. + +.. option:: -mtocdata= + + Mark the specified global variables as "toc-data" if valid, or emit + diagnostics otherwise. + +.. option:: -mno-tocdata= + + Specifies which variables are execptions to the toc-data trasformation. + +.. option:: -mtocdata + + Mark all global variables not explicitly specified with -mno-tocdata as + toc-data. + +.. option:: -mno-tocdata + + Only explicitly specified variables will be treated as toc-data. + This is the default behaviour. + C Language Features =================== Index: include/clang/Basic/CodeGenOptions.h =================================================================== --- include/clang/Basic/CodeGenOptions.h +++ include/clang/Basic/CodeGenOptions.h @@ -399,6 +399,15 @@ /// List of dynamic shared object files to be loaded as pass plugins. std::vector PassPlugins; + /// List of global variables explicitly specified by the user as toc-data. + std::vector TocDataVarsUserSpecified; + + /// List of global variables that over-ride the toc-data default. + std::vector NoTocDataVars; + + /// Flag for all global variables to be treated as toc-data. + bool AllTocData; + /// Path to allowlist file specifying which objects /// (files, functions) should exclusively be instrumented /// by sanitizer coverage pass. Index: include/clang/Basic/DiagnosticFrontendKinds.td =================================================================== --- include/clang/Basic/DiagnosticFrontendKinds.td +++ include/clang/Basic/DiagnosticFrontendKinds.td @@ -93,6 +93,8 @@ def warn_fe_backend_warning_attr : Warning<"call to '%0' declared with 'warning' attribute: %1">, BackendInfo, InGroup; +def warn_toc_unsupported_type : Warning<"The -mtocdata option is ignored " + "for %0 because %1.">, InGroup; def err_fe_invalid_code_complete_file : Error< "cannot locate code-completion file %0">, DefaultFatal; Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -2920,6 +2920,19 @@ Group, Flags<[CC1Option,FlangOption,FC1Option]>, MetaVarName<"">, HelpText<"Load pass plugin from a dynamic shared object file (only with new pass manager).">, MarshallingInfoStringVector>; +def mtocdata_EQ : CommaJoined<["-"], "mtocdata=">, + Flags<[CC1Option,TargetSpecific]>, + HelpText<"Specifies which variables can be treated as toc-data">, + MarshallingInfoStringVector>; +def mtocdata : Flag<["-"], "mtocdata">, Flags<[CC1Option,TargetSpecific]>, + HelpText<"All variables can be treated as toc-data">, + MarshallingInfoFlag>; +def mno_tocdata_EQ : CommaJoined<["-"], "mno-tocdata=">, + Flags<[CC1Option,TargetSpecific]>, + HelpText<"Specifies which variables are exempt from the toc-data trasformation">, + MarshallingInfoStringVector>; +def mno_tocdata : Flag<["-"], "mno-tocdata">, Flags<[CC1Option,TargetSpecific]>, + HelpText<"Only explicitly specified variables will be treated as toc-data">; defm preserve_as_comments : BoolFOption<"preserve-as-comments", CodeGenOpts<"PreserveAsmComments">, DefaultTrue, NegFlag, Index: include/llvm/ADT/STLExtras.h =================================================================== --- include/llvm/ADT/STLExtras.h +++ include/llvm/ADT/STLExtras.h @@ -2034,6 +2034,19 @@ return std::partition(adl_begin(Range), adl_end(Range), P); } +/// Provide wrappers to std::binary_search which take ranges instead of having to +/// pass begin/end explicitly. +template auto binary_search(R &&Range, T &&Value) { + return std::binary_search(adl_begin(Range), adl_end(Range), + std::forward(Value)); +} + +template +auto binary_search(R &&Range, T &&Value, Compare C) { + return std::binary_search(adl_begin(Range), adl_end(Range), + std::forward(Value), C); +} + /// Provide wrappers to std::lower_bound which take ranges instead of having to /// pass begin/end explicitly. template auto lower_bound(R &&Range, T &&Value) { Index: lib/CodeGen/Targets/PPC.cpp =================================================================== --- lib/CodeGen/Targets/PPC.cpp +++ lib/CodeGen/Targets/PPC.cpp @@ -145,6 +145,9 @@ bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, llvm::Value *Address) const override; + + void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, + CodeGen::CodeGenModule &M) const override; }; } // namespace @@ -265,6 +268,58 @@ return PPC_initDwarfEHRegSizeTable(CGF, Address, Is64Bit, /*IsAIX*/ true); } +void AIXTargetCodeGenInfo::setTargetAttributes( + const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const { + if (auto *GVar = dyn_cast(GV)) { + auto GVId = GVar->getGlobalIdentifier(); + + // Is this a global variable specified by the user as toc-data? + bool UserSpecifiedTOC = + llvm::binary_search(M.getCodeGenOpts().TocDataVarsUserSpecified, GVId); + // Is this a global variable specified by the user as imported? + bool UserSpecifiedNotTOC = + llvm::binary_search(M.getCodeGenOpts().NoTocDataVars, GVId); + assert( + (!UserSpecifiedTOC || !UserSpecifiedNotTOC) && + "The same variable cannot be marked as both TocData and NotTocData."); + if (UserSpecifiedTOC || + ((M.getCodeGenOpts().AllTocData) && !UserSpecifiedNotTOC)) { + const unsigned long PointerSize = + GV->getParent()->getDataLayout().getPointerSizeInBits() / 8; + ASTContext &Context = D->getASTContext(); + auto *VarD = dyn_cast(D); + assert(VarD && "Invalid declaration of global variable."); + + unsigned Alignment = Context.toBits(Context.getDeclAlign(D)) / 8; + const auto *Ty = VarD->getType().getTypePtr(); + + if (!Ty || Ty->isIncompleteType()) { + if (UserSpecifiedTOC) + M.getDiags().Report(D->getLocation(), diag::warn_toc_unsupported_type) + << GVId << "of incomplete type"; + } else if (VarD->getTLSKind() != VarDecl::TLS_None) { + if (UserSpecifiedTOC) + M.getDiags().Report(D->getLocation(), diag::warn_toc_unsupported_type) + << GVId << "of thread local storage model"; + } else if (PointerSize < Context.getTypeInfo(VarD->getType()).Width / 8) { + if (UserSpecifiedTOC) + M.getDiags().Report(D->getLocation(), diag::warn_toc_unsupported_type) + << GVId << "variable is larger than a pointer"; + } else if (PointerSize < Alignment) { + if (UserSpecifiedTOC) + M.getDiags().Report(D->getLocation(), diag::warn_toc_unsupported_type) + << GVId << "variable is aligned wider than a pointer"; + } else if (D->hasAttr()) { + if (UserSpecifiedTOC) + M.getDiags().Report(D->getLocation(), diag::warn_toc_unsupported_type) + << GVId << "of a section attribute"; + } else { + GVar->addAttribute("toc-data"); + } + } + } +} + // PowerPC-32 namespace { /// PPC32_SVR4_ABIInfo - The 32-bit PowerPC ELF (SVR4) ABI information. Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -7039,6 +7039,90 @@ A->claim(); } + // Forward last mtocdata/mno_tocdata options to -cc1 + if (Args.hasArg(options::OPT_mtocdata_EQ, options::OPT_mno_tocdata_EQ, + options::OPT_mtocdata, options::OPT_mno_tocdata)) { + // Claim all arguments. + Args.ClaimAllArgs(options::OPT_mtocdata_EQ); + Args.ClaimAllArgs(options::OPT_mno_tocdata_EQ); + Args.ClaimAllArgs(options::OPT_mtocdata); + Args.ClaimAllArgs(options::OPT_mno_tocdata); + + // Diagnose option on unsupported platforms. + if (!Triple.isOSAIX()) { + const std::string &TripleString = Triple.str(); + for (const auto &Arg : + Args.filtered(options::OPT_mtocdata_EQ, options::OPT_mno_tocdata_EQ, + options::OPT_mtocdata, options::OPT_mno_tocdata)) { + D.Diag(diag::err_drv_unsupported_opt_for_target) + << Arg->getSpelling() << TripleString; + } + } else { + // The default behavior is -mno-tocdata. We need an explicit + // -mtocdata to enable toc-data attribute, and it must be last to take + // effect. + const bool TocDataInEffect = [&Args]() { + if (!Args.hasArg(options::OPT_mtocdata)) + return false; + + const Arg *LastArg = + Args.getLastArg(options::OPT_mtocdata, options::OPT_mno_tocdata); + return LastArg->getOption().matches(options::OPT_mtocdata); + }(); + + enum TOCDataOptionVal { + AddressInTOC = 0, // Address of the symbol stored in the TOC. + DataInTOC = 1 // Symbol defined in the TOC. + }; + + const TOCDataOptionVal ExplicitOptionDefaultOverride = + TocDataInEffect ? AddressInTOC : DataInTOC; + + llvm::StringSet<> ExplicitlySpecifiedGlobals; + for (const auto Arg : Args.filtered(options::OPT_mtocdata_EQ, + options::OPT_mno_tocdata_EQ)) { + TOCDataOptionVal OptionType = + Arg->getOption().matches(options::OPT_mtocdata_EQ) ? DataInTOC + : AddressInTOC; + if (OptionType == ExplicitOptionDefaultOverride) { + for (const char *Val : Arg->getValues()) + ExplicitlySpecifiedGlobals.insert(Val); + } else { + for (const char *Val : Arg->getValues()) + ExplicitlySpecifiedGlobals.erase(Val); + } + } + + const bool HasExplicitValues = !ExplicitlySpecifiedGlobals.empty(); + + auto buildExceptionList = [](const llvm::StringSet<> &ExplicitValues, + const char *OptionSpelling) -> std::string { + std::string Option(OptionSpelling); + bool IsFirst = true; + for (const auto &E : ExplicitValues) { + if (!IsFirst) + Option += ","; + + IsFirst = false; + Option += E.first(); + } + return Option; + }; + + if (TocDataInEffect) { + CmdArgs.push_back("-mtocdata"); + if (HasExplicitValues) + CmdArgs.push_back(Args.MakeArgString(Twine(buildExceptionList( + ExplicitlySpecifiedGlobals, "-mno-tocdata=")))); + } else { + CmdArgs.push_back("-mno-tocdata"); + if (HasExplicitValues) + CmdArgs.push_back(Args.MakeArgString(Twine( + buildExceptionList(ExplicitlySpecifiedGlobals, "-mtocdata=")))); + } + } + } + // Forward --vfsoverlay to -cc1. for (const Arg *A : Args.filtered(options::OPT_vfsoverlay)) { CmdArgs.push_back("--vfsoverlay"); Index: lib/Frontend/CompilerInstance.cpp =================================================================== --- lib/Frontend/CompilerInstance.cpp +++ lib/Frontend/CompilerInstance.cpp @@ -1039,6 +1039,11 @@ if (getFrontendOpts().ShowStats || !getFrontendOpts().StatsFile.empty()) llvm::EnableStatistics(false); + // Sort vectors containing toc data and no toc data variables to facilitate + // binary search later. + llvm::sort(getCodeGenOpts().TocDataVarsUserSpecified); + llvm::sort(getCodeGenOpts().NoTocDataVars); + for (const FrontendInputFile &FIF : getFrontendOpts().Inputs) { // Reset the ID tables if we are reusing the SourceManager and parsing // regular files. Index: test/CodeGen/PowerPC/toc-data-attribute.c =================================================================== --- /dev/null +++ test/CodeGen/PowerPC/toc-data-attribute.c @@ -0,0 +1,65 @@ +// REQUIRES: powerpc-registered-target +// RUN: %clang %s -target powerpc-ibm-aix-xcoff -S -mtocdata=f,g,h,i,j,k,l,m,n,o,p -emit-llvm -o - 2>&1 | FileCheck %s -check-prefixes=CHECK32 --match-full-lines +// RUN: %clang %s -target powerpc-ibm-aix-xcoff -S -mtocdata -emit-llvm -o - 2>&1 | FileCheck %s -check-prefixes=CHECK32 --match-full-lines + +// RUN: %clang %s -target powerpc64-ibm-aix-xcoff -S -mtocdata=f,g,h,i,j,k,l,m,n,o,p -emit-llvm -o - 2>&1 | FileCheck %s -check-prefixes=CHECK64 --match-full-lines +// RUN: %clang %s -target powerpc64-ibm-aix-xcoff -S -mtocdata -emit-llvm -o - 2>&1 | FileCheck %s -check-prefixes=CHECK64 --match-full-lines + +extern int f; +long long g = 5; +const char *h = "h"; +int *i; +int __attribute__((aligned(128))) j = 0; +float k = 100.00; +double l = 2.5; +int m __attribute__((section("foo"))) = 10; +__thread int n; + +extern int p[]; + +struct SomeStruct; +extern struct SomeStruct o; + +static int func_a() { + return g+(int)h[0]+*i+j+k+l+m+n+p[0]; +} + +int func_b() { + f = 1; + return func_a(); +} + +struct SomeStruct* getAddress(void) { + return &o; +} + +// CHECK32: @h = global {{...*}} #0 +// CHECK32: @k = global float 1.000000e+02, align 4 #0 +// CHECK32: @f = external global i32, align 4 #0 +// CHECK32: @i = global ptr null, align 4 #0 +// CHECK32: attributes #0 = { "toc-data" } + +// CHECK32-NOT: {{.*}} = private unnamed_addr constant [2 x i8] c"h\00", align 1 #0 +// CHECK32-NOT: @g = global i64 5, align 8 #0 +// CHECK32-NOT: @j = global i32 0, align 128 #0 +// CHECK32-NOT: @l = global double 2.500000e+00, align 8 #0 +// CHECK32-NOT: @m = global i32 10, section "foo", align 4 #0 +// CHECK32-NOT: @o = external global %struct.SomeStruct, align 1 #0 +// CHECK32-NOT: @n = thread_local global i32 0, align 4 #0 +// CHECK32-NOT: @p = external global [0 x i32], align 4 #0 + + +// CHECK64: @g = global i64 5, align 8 #0 +// CHECK64: @h = global {{...*}} #0 +// CHECK64: @k = global float 1.000000e+02, align 4 #0 +// CHECK64: @l = global double 2.500000e+00, align 8 #0 +// CHECK64: @f = external global i32, align 4 #0 +// CHECK64: @i = global ptr null, align 8 #0 +// CHECK64: attributes #0 = { "toc-data" } + +// CHECK64-NOT: {{.*}} = private unnamed_addr constant [2 x i8] c"h\00", align 1 #0 +// CHECK64-NOT: @j = global i32 0, align 128 #0 +// CHECK64-NOT: @m = global i32 10, section "foo", align 4 #0 +// CHECK64-NOT: @o = external global %struct.SomeStruct, align 1 #0 +// CHECK64-NOT: @n = thread_local global i32 0, align 4 #0 +// CHECK64-NOT: @p = external global [0 x i32], align 4 #0 Index: test/CodeGen/PowerPC/toc-data-diagnostics.c =================================================================== --- /dev/null +++ test/CodeGen/PowerPC/toc-data-diagnostics.c @@ -0,0 +1,42 @@ +// REQUIRES: powerpc-registered-target +// RUN: %clang_cc1 %s -triple=powerpc-ibm-aix-xcoff -S -mtocdata=h,g,f,e,d,c,b,a -verify -emit-llvm -o - | FileCheck %s -check-prefix=CHECK --match-full-lines +// RUN: %clang_cc1 %s -triple=powerpc-ibm-aix-xcoff -S -mtocdata -verify=none -emit-llvm -o - | FileCheck %s -check-prefix=CHECK --match-full-lines + +// none-no-diagnostics + +struct large_struct { + int x; + short y; + short z; + char c; +}; + +struct large_struct a; // expected-warning {{The -mtocdata option is ignored for a because variable is larger than a pointer.}} +long long b = 5; // expected-warning {{The -mtocdata option is ignored for b because variable is larger than a pointer.}} +int __attribute__((aligned(128))) c = 0; // expected-warning {{The -mtocdata option is ignored for c because variable is aligned wider than a pointer.}} +double d = 2.5; // expected-warning {{The -mtocdata option is ignored for d because variable is larger than a pointer.}} +int e __attribute__((section("foo"))) = 10; // expected-warning {{The -mtocdata option is ignored for e because of a section attribute.}} +__thread int f; // expected-warning {{The -mtocdata option is ignored for f because of thread local storage model.}} + +struct SomeStruct; +extern struct SomeStruct g; // expected-warning {{The -mtocdata option is ignored for g because of incomplete type.}} + +extern int h[]; // expected-warning {{The -mtocdata option is ignored for h because of incomplete type.}} + +int func() { + return a.x+b+c+d+e+f+h[0]; +} + +struct SomeStruct* getAddress(void) { + return &g; +} + +// CHECK: @b = global i64 5, align 8 +// CHECK: @c = global i32 0, align 128 +// CHECK: @d = global double 2.500000e+00, align 8 +// CHECK: @e = global i32 10, section "foo", align 4 +// CHECK: @a = global %struct.large_struct zeroinitializer, align 4 +// CHECK: @f = thread_local global i32 0, align 4 +// CHECK: @h = external global [0 x i32], align 4 +// CHECK: @g = external global %struct.SomeStruct, align 1 +// CHECK-NOT: attributes #0 = { "toc-data" } Index: test/CodeGen/PowerPC/toc-data-structs-arrays.cpp =================================================================== --- /dev/null +++ test/CodeGen/PowerPC/toc-data-structs-arrays.cpp @@ -0,0 +1,71 @@ +// REQUIRES: powerpc-registered-target +// RUN: %clang++ %s -target powerpc-ibm-aix-xcoff -S -mtocdata=a4,a5,a8,a9,b,c,d,e,v -emit-llvm -o - 2>&1 \ +// RUN: | FileCheck %s -check-prefixes=CHECK32 --match-full-lines +// RUN: %clang++ %s -target powerpc-ibm-aix-xcoff -S -mtocdata -emit-llvm -o - 2>&1 \ +// RUN: | FileCheck %s -check-prefixes=CHECK32 --match-full-lines + +// RUN: %clang++ %s -target powerpc64-ibm-aix-xcoff -S -mtocdata=a4,a5,a8,a9,b,c,d,e,v -emit-llvm -o - 2>&1 \ +// RUN: | FileCheck %s -check-prefixes=CHECK64 --match-full-lines +// RUN: %clang++ %s -target powerpc64-ibm-aix-xcoff -S -mtocdata -emit-llvm -o - 2>&1 \ +// RUN: | FileCheck %s -check-prefixes=CHECK64 --match-full-lines + +#include + +struct size4_struct { + int x; +}; + +struct size5_struct { + int x; + char c; +}; + +struct size8_struct { + int x; + short y; + short z; +}; + +struct size9_struct { + int x; + short y; + short z; + char c; +}; + +struct size4_struct a4; +struct size5_struct a5; +struct size8_struct a8; +struct size9_struct a9; + +short b[2]; +short c[3]; +short d[4]; +short e[5]; + +std::vector v = {0}; + +int func_a() { + return a4.x+a5.x+a8.x+a9.x+b[0]+c[0]+d[0]+e[0]+(int)v[0]; +} + +// CHECK32: @a4 = global %struct.size4_struct zeroinitializer, align 4 #0 +// CHECK32: @b = global [2 x i16] zeroinitializer, align 2 #0 +// CHECK32: attributes #0 = { "toc-data" } +// CHECK32-NOT: @a5 = global %struct.size5_struct zeroinitializer, align 4 #0 +// CHECK32-NOT: @a8 = global %struct.size8_struct zeroinitializer, align 4 #0 +// CHECK32-NOT: @a9 = global %struct.size9_struct zeroinitializer, align 4 #0 +// CHECK32-NOT: @c = global [3 x i16] zeroinitializer, align 2 #0 +// CHECK32-NOT: @d = global [4 x i16] zeroinitializer, align 2 #0 +// CHECK32-NOT: @e = global [5 x i16] zeroinitializer, align 2 #0 +// CHECK32-NOT: @v = global %"class.std::__1::vector" zeroinitializer, align 4 #0 + +// CHECK64: @a4 = global %struct.size4_struct zeroinitializer, align 4 #0 +// CHECK64: @a5 = global %struct.size5_struct zeroinitializer, align 4 #0 +// CHECK64: @a8 = global %struct.size8_struct zeroinitializer, align 4 #0 +// CHECK64: @b = global [2 x i16] zeroinitializer, align 2 #0 +// CHECK64: @c = global [3 x i16] zeroinitializer, align 2 #0 +// CHECK64: @d = global [4 x i16] zeroinitializer, align 2 #0 +// CHECK64: attributes #0 = { "toc-data" } +// CHECK64-NOT: @a9 = global %struct.size9_struct zeroinitializer, align 4 #0 +// CHECK64-NOT: @v = global %"class.std::__1::vector" zeroinitializer, align 4 #0 Index: test/CodeGen/toc-data.c =================================================================== --- /dev/null +++ test/CodeGen/toc-data.c @@ -0,0 +1,31 @@ +// RUN: %clang %s -target powerpc-unknown-aix -S -mtocdata=g1,g2,g3 -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-MIX --match-full-lines +// RUN: %clang %s -target powerpc64-unkown-aix -S -mtocdata -mno-tocdata=g4,g5 -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-MIX --match-full-lines + +// RUN: %clang %s -target powerpc-unknown-aix -S -mno-tocdata -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-NOTOCDATA +// RUN: %clang %s -target powerpc64-unknown-aix -S -mno-tocdata -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-NOTOCDATA + +// RUN: %clang %s -target powerpc-unknown-aix -S -mtocdata -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-TOCDATA --match-full-lines +// RUN: %clang %s -target powerpc64-unknown-aix -S -mtocdata -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-TOCDATA --match-full-lines + +int g1, g4; +extern int g2; +int g3 = 0, g5 = 123; +void func() { + g2 = 0; +} + +// CHECK-MIX-DAG: @g3 = global i32 0, align 4 #0 +// CHECK-MIX-DAG: @g2 = external global i32, align 4 #0 +// CHECK-MIX-DAG: @g1 = global i32 0, align 4 #0 +// CHECK-MIX-DAG: @g4 = global i32 0, align 4 +// CHECK-MIX-DAG: @g5 = global i32 123, align 4 +// CHECK-MIX: attributes #0 = { "toc-data" } + +// CHECK-NOTOCDATA-NOT: "toc-data" + +// CHECK-TOCDATA-DAG: @g3 = global i32 0, align 4 #0 +// CHECK-TOCDATA-DAG: @g2 = external global i32, align 4 #0 +// CHECK-TOCDATA-DAG: @g1 = global i32 0, align 4 #0 +// CHECK-TOCDATA-DAG: @g4 = global i32 0, align 4 #0 +// CHECK-TOCDATA-DAG: @g5 = global i32 123, align 4 #0 +// CHECK-TOCDATA: attributes #0 = { "toc-data" } Index: test/Driver/toc-conf.c =================================================================== --- /dev/null +++ test/Driver/toc-conf.c @@ -0,0 +1,30 @@ +// RUN: %clang %s -target powerpc-unknown-aix -S -mno-tocdata -mtocdata -mno-tocdata -### 2>&1 | FileCheck %s -check-prefix=CHECK-FLAG1 +// RUN: %clang %s -target powerpc-unknown-aix -S -mno-tocdata -mtocdata -mno-tocdata -mtocdata -### 2>&1 | FileCheck %s -check-prefix=CHECK-FLAG2 +// RUN: %clang %s -target powerpc-unknown-aix -S -mtocdata=g1,g2 -mno-tocdata=g2 -mtocdata=g3,g4 -mno-tocdata=g5,g1 -### 2>&1 | FileCheck %s -check-prefix=CHECK-EQCONF +// RUN: %clang %s -target powerpc-unknown-aix -S -mtocdata=g1 -mtocdata -mno-tocdata -mtocdata=g2,g3 -mno-tocdata=g4,g5,g3 -### 2>&1 | FileCheck %s -check-prefix=CHECK-CONF1 +// RUN: %clang %s -target powerpc-unknown-aix -S -mno-tocdata=g1 -mno-tocdata -mtocdata -### 2>&1 | FileCheck %s -check-prefix=CHECK-CONF2 + +int g1, g4, g5; +extern int g2; +int g3 = 0; +void func() { + g2 = 0; +} + +// CHECK-EQCONF-NOT: warning: +// CHECK-EQCONF: "-mno-tocdata" +// CHECK-EQCONF: "-mtocdata=g3,g4" + +// CHECK-FLAG1-NOT: warning: +// CHECK-FLAG1: "-mno-tocdata" + +// CHECK-FLAG2-NOT: warning: +// CHECK-FLAG2: "-mtocdata" + +// CHECK-CONF1-NOT: warning: +// CHECK-CONF1: "-mno-tocdata" +// CHECK-CONF1: "-mtocdata=g1,g2" + +// CHECK-CONF2-NOT: warning: +// CHECK-CONF2: "-mtocdata" +// CHECK-CONF2: "-mno-tocdata=g1"