From: Reid Kleckner Date: Wed, 9 Apr 2014 20:07:39 +0000 (+0000) Subject: clang-cl: Disable TBAA by default for MSVC compatibility X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c61cae9c891371b8ea3d99dd9be4e8c31cae6f07;p=clang clang-cl: Disable TBAA by default for MSVC compatibility MSVC doesn't have an option to enable TBAA, so make -fstrict-aliasing and -fno-strict-aliasing available in clang-cl. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205924 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 33e058fde6..dd7055690c 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -687,7 +687,8 @@ def fno_spell_checking : Flag<["-"], "fno-spell-checking">, Group, Flags<[CC1Option]>, HelpText<"Disable spell-checking">; def fno_stack_protector : Flag<["-"], "fno-stack-protector">, Group, HelpText<"Disable the use of stack protectors">; -def fno_strict_aliasing : Flag<["-"], "fno-strict-aliasing">, Group; +def fno_strict_aliasing : Flag<["-"], "fno-strict-aliasing">, Group, + Flags<[DriverOption, CoreOption]>; def fstruct_path_tbaa : Flag<["-"], "fstruct-path-tbaa">, Group; def fno_struct_path_tbaa : Flag<["-"], "fno-struct-path-tbaa">, Group; def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group; @@ -799,7 +800,8 @@ def fno_standalone_debug : Flag<["-"], "fno-standalone-debug">, Group, HelpText<"Limit debug information produced to reduce size of debug binary">; def flimit_debug_info : Flag<["-"], "flimit-debug-info">, Alias; def fno_limit_debug_info : Flag<["-"], "fno-limit-debug-info">, Alias; -def fstrict_aliasing : Flag<["-"], "fstrict-aliasing">, Group; +def fstrict_aliasing : Flag<["-"], "fstrict-aliasing">, Group, + Flags<[DriverOption, CoreOption]>; def fstrict_enums : Flag<["-"], "fstrict-enums">, Group, Flags<[CC1Option]>, HelpText<"Enable optimizations based on the strict definition of an enum's " "value range">; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index e65b6e1782..28702836de 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -2508,8 +2508,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // enabled. This alias option is being used to simplify the hasFlag logic. OptSpecifier StrictAliasingAliasOption = OFastEnabled ? options::OPT_Ofast : options::OPT_fstrict_aliasing; + // We turn strict aliasing off by default if we're in CL mode, since MSVC + // doesn't do any TBAA. + bool TBAAOnByDefault = !getToolChain().getDriver().IsCLMode(); if (!Args.hasFlag(options::OPT_fstrict_aliasing, StrictAliasingAliasOption, - options::OPT_fno_strict_aliasing, true)) + options::OPT_fno_strict_aliasing, TBAAOnByDefault)) CmdArgs.push_back("-relaxed-aliasing"); if (!Args.hasFlag(options::OPT_fstruct_path_tbaa, options::OPT_fno_struct_path_tbaa)) diff --git a/test/Driver/cl-options.c b/test/Driver/cl-options.c index a76626464a..48f1a9e4af 100644 --- a/test/Driver/cl-options.c +++ b/test/Driver/cl-options.c @@ -133,6 +133,14 @@ // WJoined: "-cc1" // WJoined: "-Wunused-pragmas" +// We recognize -f[no-]strict-aliasing. +// RUN: %clang_cl -c -### -- %s 2>&1 | FileCheck -check-prefix=DEFAULTSTRICT %s +// DEFAULTSTRICT: "-relaxed-aliasing" +// RUN: %clang_cl -c -fstrict-aliasing -### -- %s 2>&1 | FileCheck -check-prefix=STRICT %s +// STRICT-NOT: "-relaxed-aliasing" +// RUN: %clang_cl -c -fno-strict-aliasing -### -- %s 2>&1 | FileCheck -check-prefix=NOSTRICT %s +// NOSTRICT: "-relaxed-aliasing" + // For some warning ids, we can map from MSVC warning to Clang warning. // RUN: %clang_cl -wd4005 -### -- %s 2>&1 | FileCheck -check-prefix=wd4005 %s // wd4005: "-cc1"