Index: tools/clang/include/clang/Basic/LangOptions.def =================================================================== --- tools/clang/include/clang/Basic/LangOptions.def +++ tools/clang/include/clang/Basic/LangOptions.def @@ -134,6 +134,8 @@ "default struct packing maximum alignment") VALUE_LANGOPT(MaxTypeAlign , 32, 0, "default maximum alignment for types") +VALUE_LANGOPT(GXXABIVersion , 32, 0, + "Use specified GNU C++ Standard Library ABI version") VALUE_LANGOPT(PICLevel , 2, 0, "__PIC__ level") VALUE_LANGOPT(PIELevel , 2, 0, "__PIE__ level") LANGOPT(GNUInline , 1, 0, "GNU inline semantics") Index: tools/clang/include/clang/Driver/Options.td =================================================================== --- tools/clang/include/clang/Driver/Options.td +++ tools/clang/include/clang/Driver/Options.td @@ -574,6 +574,8 @@ def ffp_contract : Joined<["-"], "ffp-contract=">, Group, Flags<[CC1Option]>, HelpText<"Form fused FP ops (e.g. FMAs): fast (everywhere)" " | on (according to FP_CONTRACT pragma, default) | off (never fuse)">; +def fabi_version_EQ : Joined<["-"], "fabi-version=">, Group, + Flags<[CC1Option]>, HelpText<"Use specified GNU C++ ABI version">; def ffor_scope : Flag<["-"], "ffor-scope">, Group; def fno_for_scope : Flag<["-"], "fno-for-scope">, Group; Index: tools/clang/lib/Driver/Tools.cpp =================================================================== --- tools/clang/lib/Driver/Tools.cpp +++ tools/clang/lib/Driver/Tools.cpp @@ -2812,6 +2812,12 @@ CmdArgs.push_back(A->getValue()); } + if (Arg *A = Args.getLastArg(options::OPT_fabi_version_EQ)) { + StringRef v = A->getValue(); + CmdArgs.push_back(Args.MakeArgString("-fabi-version=" + v)); + A->claim(); + } + if (Arg *A = Args.getLastArg(options::OPT_fpcc_struct_return, options::OPT_freg_struct_return)) { if (getToolChain().getArch() != llvm::Triple::x86) { Index: tools/clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- tools/clang/lib/Frontend/CompilerInvocation.cpp +++ tools/clang/lib/Frontend/CompilerInvocation.cpp @@ -1539,6 +1539,7 @@ Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls); Opts.PackStruct = getLastArgIntValue(Args, OPT_fpack_struct_EQ, 0, Diags); Opts.MaxTypeAlign = getLastArgIntValue(Args, OPT_fmax_type_align_EQ, 0, Diags); + Opts.GXXABIVersion = getLastArgIntValue(Args, OPT_fabi_version_EQ, 0, Diags); Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags); Opts.PIELevel = getLastArgIntValue(Args, OPT_pie_level, 0, Diags); Opts.Static = Args.hasArg(OPT_static_define); Index: tools/clang/lib/Frontend/InitPreprocessor.cpp =================================================================== --- tools/clang/lib/Frontend/InitPreprocessor.cpp +++ tools/clang/lib/Frontend/InitPreprocessor.cpp @@ -479,7 +479,31 @@ Builder.defineMacro("__GNUC_MINOR__", "2"); Builder.defineMacro("__GNUC_PATCHLEVEL__", "1"); Builder.defineMacro("__GNUC__", "4"); + // GCC provides a number of C++ ABI Versions in: + // ${top_srcdir}/gcc/c-family/c-cppbuiltin.c + // Currently valid GXX ABI Versions are documented here: + // https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html + // clang only supports a subset. + switch (LangOpts.GXXABIVersion) { + default: Builder.defineMacro("__GXX_ABI_VERSION", "1002"); + break; + case 4: + Builder.defineMacro("__GXX_ABI_VERSION", "1004"); + break; + case 5: + Builder.defineMacro("__GXX_ABI_VERSION", "1005"); + break; + case 6: + Builder.defineMacro("__GXX_ABI_VERSION", "1006"); + break; + case 7: + Builder.defineMacro("__GXX_ABI_VERSION", "1007"); + break; + case 8: + Builder.defineMacro("__GXX_ABI_VERSION", "1008"); + break; + } } // Define macros for the C11 / C++11 memory orderings