[PATCH] D12598: clang should emulate GCC's -fabi-version=<X>
Stefan Teleman via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 3 06:04:00 PDT 2015
steleman created this revision.
steleman added a subscriber: cfe-commits.
This changeset provides an implementation of GCC's -fabi-version=<X> flag.
-fabi-version is documented at GCC here:
https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html
GCC implements it here:
${top_srcdir}/gcc/c-family/c-cppbuiltin.c
http://reviews.llvm.org/D12598
Files:
tools/clang/include/clang/Basic/LangOptions.def
tools/clang/include/clang/Driver/Options.td
tools/clang/lib/Driver/Tools.cpp
tools/clang/lib/Frontend/CompilerInvocation.cpp
tools/clang/lib/Frontend/InitPreprocessor.cpp
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/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<f_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<f_Group>,
+ Flags<[CC1Option]>, HelpText<"Use specified GNU C++ ABI version">;
def ffor_scope : Flag<["-"], "ffor-scope">, Group<f_Group>;
def fno_for_scope : Flag<["-"], "fno-for-scope">, Group<f_Group>;
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
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")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12598.33938.patch
Type: text/x-patch
Size: 4049 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150903/a7cd5bf4/attachment-0001.bin>
More information about the cfe-commits
mailing list