Index: include/clang/Driver/CC1Options.td =================================================================== --- include/clang/Driver/CC1Options.td +++ include/clang/Driver/CC1Options.td @@ -244,6 +244,8 @@ HelpText<"Turn off Type Based Alias Analysis">; def no_struct_path_tbaa : Flag<["-"], "no-struct-path-tbaa">, HelpText<"Turn off struct-path aware Type Based Alias Analysis">; +def new_struct_path_tbaa : Flag<["-"], "new-struct-path-tbaa">, + HelpText<"Enable enhanced struct-path aware Type Based Alias Analysis">; def masm_verbose : Flag<["-"], "masm-verbose">, HelpText<"Generate verbose assembly output">; def mcode_model : Separate<["-"], "mcode-model">, Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1272,6 +1272,7 @@ def fno_strict_aliasing : Flag<["-"], "fno-strict-aliasing">, Group, Flags<[DriverOption, CoreOption]>; def fstruct_path_tbaa : Flag<["-"], "fstruct-path-tbaa">, Group; +def fnew_struct_path_tbaa : Flag<["-"], "fnew-struct-path-tbaa">, Group; def fno_struct_path_tbaa : Flag<["-"], "fno-struct-path-tbaa">, Group; def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group; def fno_strict_vtable_pointers: Flag<["-"], "fno-strict-vtable-pointers">, Index: include/clang/Frontend/CodeGenOptions.def =================================================================== --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -142,6 +142,7 @@ CODEGENOPT(RelaxAll , 1, 0) ///< Relax all machine code instructions. CODEGENOPT(RelaxedAliasing , 1, 0) ///< Set when -fno-strict-aliasing is enabled. CODEGENOPT(StructPathTBAA , 1, 0) ///< Whether or not to use struct-path TBAA. +CODEGENOPT(NewStructPathTBAA , 1, 0) ///< Whether or not to use new struct-path TBAA. CODEGENOPT(SaveTempLabels , 1, 0) ///< Save temporary labels. CODEGENOPT(SanitizeAddressUseAfterScope , 1, 0) ///< Enable use-after-scope detection ///< in AddressSanitizer Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3334,9 +3334,15 @@ if (!Args.hasFlag(options::OPT_fstrict_aliasing, StrictAliasingAliasOption, 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)) + bool StructPathTBAA = Args.hasFlag(options::OPT_fstruct_path_tbaa, + options::OPT_fno_struct_path_tbaa); + bool NewStructPathTBAA = Args.hasFlag(options::OPT_fnew_struct_path_tbaa, + options::OPT_fno_struct_path_tbaa, + false); + if (!StructPathTBAA && !NewStructPathTBAA) CmdArgs.push_back("-no-struct-path-tbaa"); + if (NewStructPathTBAA) + CmdArgs.push_back("-new-struct-path-tbaa"); if (Args.hasFlag(options::OPT_fstrict_enums, options::OPT_fno_strict_enums, false)) CmdArgs.push_back("-fstrict-enums"); Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -546,6 +546,8 @@ OPT_fuse_register_sized_bitfield_access); Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing); Opts.StructPathTBAA = !Args.hasArg(OPT_no_struct_path_tbaa); + Opts.NewStructPathTBAA = !Args.hasArg(OPT_no_struct_path_tbaa) && + Args.hasArg(OPT_new_struct_path_tbaa); Opts.FineGrainedBitfieldAccesses = Args.hasFlag(OPT_ffine_grained_bitfield_accesses, OPT_fno_fine_grained_bitfield_accesses, false); Index: test/Driver/tbaa.c =================================================================== --- test/Driver/tbaa.c +++ test/Driver/tbaa.c @@ -0,0 +1,30 @@ +// Test translation of TBAA-related clang options to cc1 options. + +// RUN: %clang -### -target x86_64-unknown-linux \ +// RUN: -fno-struct-path-tbaa %s 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-NO_PATH %s +// RUN: %clang -### -target x86_64-unknown-linux \ +// RUN: -fstruct-path-tbaa -fno-struct-path-tbaa %s 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-NO_PATH %s +// RUN: %clang -### -target x86_64-unknown-linux \ +// RUN: -fnew-struct-path-tbaa -fno-struct-path-tbaa %s 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-NO_PATH %s +// CHECK-NO_PATH: "-cc1" +// CHECK-NO_PATH-NOT: "-new-struct-path-tbaa" +// CHECK-NO_PATH-SAME: "-no-struct-path-tbaa" +// CHECK-NO_PATH-NOT: "-new-struct-path-tbaa" + +// RUN: %clang -### -target x86_64-unknown-linux \ +// RUN: -fstruct-path-tbaa %s 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-PATH %s +// CHECK-PATH: "-cc1" +// CHECK-PATH-NOT: "-no-struct-path-tbaa" +// CHECK-PATH-NOT: "-new-struct-path-tbaa" + +// RUN: %clang -### -target x86_64-unknown-linux \ +// RUN: -fnew-struct-path-tbaa %s 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-NEW_PATH %s +// CHECK-NEW_PATH: "-cc1" +// CHECK-NEW_PATH-NOT: "-no-struct-path-tbaa" +// CHECK-NEW_PATH: "-new-struct-path-tbaa" +// CHECK-NEW_PATH-NOT: "-no-struct-path-tbaa"