r212138 - Driver: Handle /GR- in a compatible way with MSVC
Rafael EspĂndola
rafael.espindola at gmail.com
Wed Jul 2 06:57:46 PDT 2014
Cool, can we now use std::function? :-)
On 1 July 2014 18:24, David Majnemer <david.majnemer at gmail.com> wrote:
> Author: majnemer
> Date: Tue Jul 1 17:24:56 2014
> New Revision: 212138
>
> URL: http://llvm.org/viewvc/llvm-project?rev=212138&view=rev
> Log:
> Driver: Handle /GR- in a compatible way with MSVC
>
> There are slight differences between /GR- and -fno-rtti which made
> mapping one to the other inappropriate.
>
> -fno-rtti disables dynamic_cast, typeid, and does not emit RTTI related
> information for the v-table.
>
> /GR- does not generate complete object locators and thus will not
> reference them in vftables. However, constructs like dynamic_cast and
> typeid are permitted.
>
> This should bring our implementation of RTTI up to semantic parity with
> MSVC modulo bugs.
>
> Added:
> cfe/trunk/test/CodeGenCXX/microsoft-no-rtti-data.cpp
> Modified:
> cfe/trunk/include/clang/Basic/LangOptions.def
> cfe/trunk/include/clang/Driver/CC1Options.td
> cfe/trunk/include/clang/Driver/CLCompatOptions.td
> cfe/trunk/lib/AST/VTableBuilder.cpp
> cfe/trunk/lib/Basic/Targets.cpp
> cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
> cfe/trunk/lib/CodeGen/MicrosoftRTTI.cpp
> cfe/trunk/lib/Driver/Tools.cpp
> cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> cfe/trunk/test/Driver/cl-fallback.c
> cfe/trunk/test/Driver/cl-options.c
>
> Modified: cfe/trunk/include/clang/Basic/LangOptions.def
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=212138&r1=212137&r2=212138&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/LangOptions.def (original)
> +++ cfe/trunk/include/clang/Basic/LangOptions.def Tue Jul 1 17:24:56 2014
> @@ -84,6 +84,7 @@ LANGOPT(CXXExceptions , 1, 0, "C++ e
> LANGOPT(SjLjExceptions , 1, 0, "setjmp-longjump exception handling")
> LANGOPT(TraditionalCPP , 1, 0, "traditional CPP emulation")
> LANGOPT(RTTI , 1, 1, "run-time type information")
> +LANGOPT(RTTIData , 1, 1, "emit run-time type information data")
> LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout")
> LANGOPT(Freestanding, 1, 0, "freestanding implementation")
> LANGOPT(NoBuiltin , 1, 0, "disable builtin functions")
>
> Modified: cfe/trunk/include/clang/Driver/CC1Options.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=212138&r1=212137&r2=212138&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/CC1Options.td (original)
> +++ cfe/trunk/include/clang/Driver/CC1Options.td Tue Jul 1 17:24:56 2014
> @@ -484,6 +484,8 @@ def fobjc_subscripting_legacy_runtime :
> HelpText<"Allow Objective-C array and dictionary subscripting in legacy runtime">;
> def vtordisp_mode_EQ : Joined<["-"], "vtordisp-mode=">,
> HelpText<"Control vtordisp placement on win32 targets">;
> +def fno_rtti_data : Flag<["-"], "fno-rtti-data">,
> + HelpText<"Control emission of RTTI data">;
>
> //===----------------------------------------------------------------------===//
> // Header Search Options
>
> Modified: cfe/trunk/include/clang/Driver/CLCompatOptions.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CLCompatOptions.td?rev=212138&r1=212137&r2=212138&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/CLCompatOptions.td (original)
> +++ cfe/trunk/include/clang/Driver/CLCompatOptions.td Tue Jul 1 17:24:56 2014
> @@ -58,8 +58,8 @@ def _SLASH_c : CLFlag<"c">, HelpText<"Co
> def _SLASH_D : CLJoinedOrSeparate<"D">, HelpText<"Define macro">,
> MetaVarName<"<macro[=value]>">, Alias<D>;
> def _SLASH_E : CLFlag<"E">, HelpText<"Preprocess to stdout">, Alias<E>;
> -def _SLASH_GR : CLFlag<"GR">, HelpText<"Enable RTTI">, Alias<frtti>;
> -def _SLASH_GR_ : CLFlag<"GR-">, HelpText<"Disable RTTI">, Alias<fno_rtti>;
> +def _SLASH_GR : CLFlag<"GR">, HelpText<"Enable emission of RTTI data">;
> +def _SLASH_GR_ : CLFlag<"GR-">, HelpText<"Disable emission of RTTI data">;
> def _SLASH_GF_ : CLFlag<"GF-">, HelpText<"Disable string pooling">,
> Alias<fwritable_strings>;
> def _SLASH_Gy : CLFlag<"Gy">, HelpText<"Put each function in its own section">,
>
> Modified: cfe/trunk/lib/AST/VTableBuilder.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/VTableBuilder.cpp?rev=212138&r1=212137&r2=212138&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/VTableBuilder.cpp (original)
> +++ cfe/trunk/lib/AST/VTableBuilder.cpp Tue Jul 1 17:24:56 2014
> @@ -2579,7 +2579,7 @@ public:
> Overriders(MostDerivedClass, CharUnits(), MostDerivedClass) {
> // Only include the RTTI component if we know that we will provide a
> // definition of the vftable.
> - HasRTTIComponent = Context.getLangOpts().RTTI &&
> + HasRTTIComponent = Context.getLangOpts().RTTIData &&
> !MostDerivedClass->hasAttr<DLLImportAttr>();
> if (HasRTTIComponent)
> Components.push_back(VTableComponent::MakeRTTI(MostDerivedClass));
>
> Modified: cfe/trunk/lib/Basic/Targets.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=212138&r1=212137&r2=212138&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Basic/Targets.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets.cpp Tue Jul 1 17:24:56 2014
> @@ -572,7 +572,7 @@ protected:
> void getVisualStudioDefines(const LangOptions &Opts,
> MacroBuilder &Builder) const {
> if (Opts.CPlusPlus) {
> - if (Opts.RTTI)
> + if (Opts.RTTIData)
> Builder.defineMacro("_CPPRTTI");
>
> if (Opts.Exceptions)
>
> Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=212138&r1=212137&r2=212138&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
> +++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Tue Jul 1 17:24:56 2014
> @@ -1152,7 +1152,7 @@ llvm::GlobalVariable *MicrosoftCXXABI::g
> llvm::GlobalValue::ExternalLinkage;
> llvm::ArrayType *VTableType =
> llvm::ArrayType::get(CGM.Int8PtrTy, NumVTableSlots);
> - if (getContext().getLangOpts().RTTI) {
> + if (getContext().getLangOpts().RTTIData) {
> VTableLinkage = llvm::GlobalValue::PrivateLinkage;
> VTableName = "";
> }
> @@ -1163,7 +1163,8 @@ llvm::GlobalVariable *MicrosoftCXXABI::g
> CGM.getModule(), VTableType, /*isConstant=*/true, VTableLinkage,
> /*Initializer=*/nullptr, VTableName);
> VTable->setUnnamedAddr(true);
> - if (getContext().getLangOpts().RTTI && !RD->hasAttr<DLLImportAttr>()) {
> + if (getContext().getLangOpts().RTTIData &&
> + !RD->hasAttr<DLLImportAttr>()) {
> llvm::Value *GEPIndices[] = {llvm::ConstantInt::get(CGM.IntTy, 0),
> llvm::ConstantInt::get(CGM.IntTy, 1)};
> llvm::Constant *VTableGEP =
>
> Modified: cfe/trunk/lib/CodeGen/MicrosoftRTTI.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftRTTI.cpp?rev=212138&r1=212137&r2=212138&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/MicrosoftRTTI.cpp (original)
> +++ cfe/trunk/lib/CodeGen/MicrosoftRTTI.cpp Tue Jul 1 17:24:56 2014
> @@ -508,7 +508,7 @@ llvm::Constant *CodeGenModule::getMSType
> llvm::Constant *
> CodeGenModule::getMSCompleteObjectLocator(const CXXRecordDecl *RD,
> const VPtrInfo *Info) {
> - if (!getLangOpts().RTTI)
> + if (!getLangOpts().RTTIData)
> return llvm::Constant::getNullValue(Int8PtrTy);
> return MSRTTIBuilder(*this, RD).getCompleteObjectLocator(Info);
> }
>
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=212138&r1=212137&r2=212138&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Tue Jul 1 17:24:56 2014
> @@ -4193,15 +4193,7 @@ void Clang::ConstructJob(Compilation &C,
> (InputType == types::TY_C || InputType == types::TY_CXX)) {
> Command *CLCommand = getCLFallback()->GetCommand(C, JA, Output, Inputs,
> Args, LinkingOutput);
> - // RTTI support in clang-cl is a work in progress. Fall back to MSVC early
> - // if we are using 'clang-cl /fallback /GR'.
> - // FIXME: Remove this when RTTI is finished.
> - if (Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti, false)) {
> - D.Diag(diag::warn_drv_rtti_fallback) << CLCommand->getExecutable();
> - C.addCommand(CLCommand);
> - } else {
> - C.addCommand(new FallbackCommand(JA, *this, Exec, CmdArgs, CLCommand));
> - }
> + C.addCommand(new FallbackCommand(JA, *this, Exec, CmdArgs, CLCommand));
> } else {
> C.addCommand(new Command(JA, *this, Exec, CmdArgs));
> }
> @@ -4446,9 +4438,10 @@ void Clang::AddClangCLArgs(const ArgList
> if (Arg *A = Args.getLastArg(options::OPT_show_includes))
> A->render(Args, CmdArgs);
>
> - // RTTI is currently not supported, so disable it by default.
> - if (!Args.hasArg(options::OPT_frtti, options::OPT_fno_rtti))
> - CmdArgs.push_back("-fno-rtti");
> + // This controls whether or not we emit RTTI data for polymorphic types.
> + if (Args.hasFlag(options::OPT__SLASH_GR_, options::OPT__SLASH_GR,
> + /*default=*/false))
> + CmdArgs.push_back("-fno-rtti-data");
>
> const Driver &D = getToolChain().getDriver();
> EHFlags EH = parseClangCLEHFlags(D, Args);
> @@ -7709,9 +7702,9 @@ Command *visualstudio::Compile::GetComma
> // Flags for which clang-cl have an alias.
> // FIXME: How can we ensure this stays in sync with relevant clang-cl options?
>
> - if (Arg *A = Args.getLastArg(options::OPT_frtti, options::OPT_fno_rtti))
> - CmdArgs.push_back(A->getOption().getID() == options::OPT_frtti ? "/GR"
> - : "/GR-");
> + if (Args.hasFlag(options::OPT__SLASH_GR_, options::OPT__SLASH_GR,
> + /*default=*/false))
> + CmdArgs.push_back("/GR-");
> if (Arg *A = Args.getLastArg(options::OPT_ffunction_sections,
> options::OPT_fno_function_sections))
> CmdArgs.push_back(A->getOption().getID() == options::OPT_ffunction_sections
>
> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=212138&r1=212137&r2=212138&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Jul 1 17:24:56 2014
> @@ -1447,6 +1447,7 @@ static void ParseLangArgs(LangOptions &O
> Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp);
>
> Opts.RTTI = !Args.hasArg(OPT_fno_rtti);
> + Opts.RTTIData = Opts.RTTI && !Args.hasArg(OPT_fno_rtti_data);
> Opts.Blocks = Args.hasArg(OPT_fblocks);
> Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional);
> Opts.Modules = Args.hasArg(OPT_fmodules);
>
> Added: cfe/trunk/test/CodeGenCXX/microsoft-no-rtti-data.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-no-rtti-data.cpp?rev=212138&view=auto
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/microsoft-no-rtti-data.cpp (added)
> +++ cfe/trunk/test/CodeGenCXX/microsoft-no-rtti-data.cpp Tue Jul 1 17:24:56 2014
> @@ -0,0 +1,21 @@
> +// RUN: %clang_cc1 %s -fno-rtti-data -triple=i386-pc-win32 -o - -emit-llvm | FileCheck %s
> +
> +// vftable shouldn't have RTTI data in it.
> +// CHECK: @"\01??_7S@@6B@" = linkonce_odr unnamed_addr constant [1 x i8*] [i8* bitcast ({{.*}} @"\01??_GS@@UAEPAXI at Z" to i8*)]
> +
> +struct type_info;
> +namespace std { using ::type_info; }
> +
> +struct S {
> + virtual ~S();
> +} s;
> +
> +struct U : S {
> + virtual ~U();
> +};
> +
> +extern S *getS();
> +
> +const std::type_info &ti = typeid(*getS());
> +const U &u = dynamic_cast<U &>(*getS());
> +// CHECK: call i8* @__RTDynamicCast(i8* %0, i32 0, i8* bitcast ({{.*}} @"\01??_R0?AUS@@@8" to i8*), i8* bitcast ({{.*}} @"\01??_R0?AUU@@@8" to i8*), i32 1)
>
> Modified: cfe/trunk/test/Driver/cl-fallback.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-fallback.c?rev=212138&r1=212137&r2=212138&view=diff
> ==============================================================================
> --- cfe/trunk/test/Driver/cl-fallback.c (original)
> +++ cfe/trunk/test/Driver/cl-fallback.c Tue Jul 1 17:24:56 2014
> @@ -31,6 +31,10 @@
> // CHECK: "/Tc" "{{.*cl-fallback.c}}"
> // CHECK: "/Fo{{.*cl-fallback.*.obj}}"
>
> +// RUN: %clang_cl /fallback /GR- -### -- %s 2>&1 | FileCheck -check-prefix=GR %s
> +// GR: cl.exe
> +// GR: "/GR-"
> +
> // RUN: %clang_cl /fallback /Od -### -- %s 2>&1 | FileCheck -check-prefix=O0 %s
> // O0: cl.exe
> // O0: "/Od"
> @@ -56,15 +60,12 @@
> // RUN: FileCheck -check-prefix=ErrWarn %s
> // ErrWarn: warning: falling back to {{.*}}cl.exe
>
> -// Don't attempt to run clang -cc1 with /fallback and /GR. It isn't ready yet.
> -// RUN: %clang_cl /fallback /c /GR -### -- %s 2>&1 | \
> -// RUN: FileCheck -check-prefix=RTTI %s
> -// RTTI: warning: cannot compile RTTI yet, falling back to {{.*}}cl.exe
> // RUN: %clang_cl /fallback /c /GR /GR- -### -- %s 2>&1 | \
> // RUN: FileCheck -check-prefix=NO_RTTI %s
> // NO_RTTI: "-cc1"
> // NO_RTTI: ||
> // NO_RTTI: cl.exe
> +// NO_RTTI: "/GR-"
>
> // Don't fall back on non-C or C++ files.
> // RUN: %clang_cl /fallback -### -- %S/Inputs/file.ll 2>&1 | FileCheck -check-prefix=LL %s
>
> Modified: cfe/trunk/test/Driver/cl-options.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-options.c?rev=212138&r1=212137&r2=212138&view=diff
> ==============================================================================
> --- cfe/trunk/test/Driver/cl-options.c (original)
> +++ cfe/trunk/test/Driver/cl-options.c Tue Jul 1 17:24:56 2014
> @@ -289,10 +289,12 @@
> // RUN: %clang_cl /Zs /WX -m32 -m64 -### -- 2>&1 %s | FileCheck -check-prefix=MFLAGS %s
> // MFLAGS-NOT: argument unused during compilation
>
> -// Use -fno-rtti by default.
> -// RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=NoRTTI %s
> -// NoRTTI: "-fno-rtti"
> +// RTTI is on by default. /GR- controls -fno-rtti-data.
> +// RUN: %clang_cl /c /GR- -### -- %s 2>&1 | FileCheck -check-prefix=NoRTTI %s
> +// NoRTTI: "-fno-rtti-data"
> +// NoRTTI-NOT: "-fno-rtti"
> // RUN: %clang_cl /c /GR -### -- %s 2>&1 | FileCheck -check-prefix=RTTI %s
> +// RTTI-NOT: "-fno-rtti-data"
> // RTTI-NOT: "-fno-rtti"
>
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list