Index: include/clang/Driver/CC1Options.td =================================================================== --- include/clang/Driver/CC1Options.td +++ include/clang/Driver/CC1Options.td @@ -170,6 +170,8 @@ HelpText<"Emit an error if a C++ static local initializer would need a guard variable">; def no_implicit_float : Flag<["-"], "no-implicit-float">, HelpText<"Don't generate implicit floating point instructions">; +def force_align_stack : Flag<["-"], "force-align-stack">, + HelpText<"Force realign the stack at entry to every function">; def fdump_vtable_layouts : Flag<["-"], "fdump-vtable-layouts">, HelpText<"Dump the layouts of all vtables that will be emitted in a translation unit">; def fmerge_functions : Flag<["-"], "fmerge-functions">, Index: include/clang/Frontend/CodeGenOptions.def =================================================================== --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -152,6 +152,8 @@ CODEGENOPT(StackRealignment , 1, 0) ///< Control whether to permit stack ///< realignment. +CODEGENOPT(ForceAlignStack , 1, 0) ///< Control whether to force stack + ///< realignment. CODEGENOPT(UseInitArray , 1, 0) ///< Control whether to use .init_array or ///< .ctors. VALUE_CODEGENOPT(StackAlignment , 32, 0) ///< Overrides default stack Index: lib/CodeGen/CGCall.cpp =================================================================== --- lib/CodeGen/CGCall.cpp +++ lib/CodeGen/CGCall.cpp @@ -1491,6 +1491,8 @@ if (!CodeGenOpts.StackRealignment) FuncAttrs.addAttribute("no-realign-stack"); + else if (CodeGenOpts.ForceAlignStack) + FuncAttrs.addAttribute("force-align-stack"); // Add target-cpu and target-features attributes to functions. If // we have a decl for the function and it has a target attribute then Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -4228,10 +4228,9 @@ // Translate -mstackrealign if (Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign, - false)) { - CmdArgs.push_back("-backend-option"); - CmdArgs.push_back("-force-align-stack"); - } + false)) + CmdArgs.push_back(Args.MakeArgString("-force-align-stack")); + if (!Args.hasFlag(options::OPT_mno_stackrealign, options::OPT_mstackrealign, false)) { CmdArgs.push_back(Args.MakeArgString("-mstackrealign")); Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -569,6 +569,8 @@ Opts.SSPBufferSize = getLastArgIntValue(Args, OPT_stack_protector_buffer_size, 8, Diags); Opts.StackRealignment = Args.hasArg(OPT_mstackrealign); + Opts.ForceAlignStack = Args.hasArg(OPT_force_align_stack); + if (Arg *A = Args.getLastArg(OPT_mstack_alignment)) { StringRef Val = A->getValue(); unsigned StackAlignment = Opts.StackAlignment;