Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -795,6 +795,9 @@ def flookup_tables : Flag<["-"], "flookup-tables">, Group; def fno_lookup_tables : Flag<["-"], "fno-lookup-tables">, Group, Flags<[CC1Option]>, HelpText<"Do not use lookup tables for lowering switches">; +def fswitch_tables : Flag<["-"], "fswitch-tables">, Group; +def fno_switch_tables : Flag<["-"], "fno-switch-tables">, Group, Flags<[CC1Option]>, + HelpText<"Do not use jump tables and lookup tables for lowering switches">; // Begin sanitizer flags. These should all be core options exposed in all driver // modes. Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -2262,13 +2262,22 @@ A->claim(); } - if (!Args.hasFlag(options::OPT_fjump_tables, options::OPT_fno_jump_tables, - true)) - CmdArgs.push_back("-fno-jump-tables"); + // fno-switch-tables disables the generation of both lookup and jump tables. + if (Arg *A = Args.getLastArg( + options::OPT_fjump_tables, options::OPT_fno_jump_tables, + options::OPT_fswitch_tables, options::OPT_fno_switch_tables)) { + if (A->getOption().matches(options::OPT_fno_jump_tables) || + A->getOption().matches(options::OPT_fno_switch_tables)) + CmdArgs.push_back("-fno-jump-tables"); + } - if (!Args.hasFlag(options::OPT_flookup_tables, options::OPT_fno_lookup_tables, - true)) - CmdArgs.push_back("-fno-lookup-tables"); + if (Arg *A = Args.getLastArg( + options::OPT_flookup_tables, options::OPT_fno_lookup_tables, + options::OPT_fswitch_tables, options::OPT_fno_switch_tables)) { + if (A->getOption().matches(options::OPT_fno_lookup_tables) || + A->getOption().matches(options::OPT_fno_switch_tables)) + CmdArgs.push_back("-fno-lookup-tables"); + } if (!Args.hasFlag(options::OPT_fpreserve_as_comments, options::OPT_fno_preserve_as_comments, true)) Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -650,9 +650,11 @@ Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions); - Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables); + Opts.NoUseJumpTables = + (Args.hasArg(OPT_fno_jump_tables) || Args.hasArg(OPT_fno_switch_tables)); - Opts.NoUseLookupTables = Args.hasArg(OPT_fno_lookup_tables); + Opts.NoUseLookupTables = (Args.hasArg(OPT_fno_lookup_tables) || + Args.hasArg(OPT_fno_switch_tables)); Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ); Opts.EmitSummaryIndex = false; Index: test/CodeGen/nouseswitchtable.c =================================================================== --- /dev/null +++ test/CodeGen/nouseswitchtable.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -S -fno-switch-tables %s -emit-llvm -o - | FileCheck %s + +// CHECK-LABEL: main +// CHECK: attributes #0 = {{.*}}"no-jump-tables"="true"{{.*}}"no-lookup-tables"="true" + +int main() { + return 0; +}