diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6490,6 +6490,12 @@ } CmdArgs.push_back(LanguageStandard.data()); + + // MSVC enables /Zc:alignedNew by default for C++17 + if (!Args.getLastArg(options::OPT_faligned_allocation, + options::OPT_fno_aligned_allocation) && + LanguageStandard == "-std=c++17") + CmdArgs.push_back("-faligned-allocation"); } Args.addOptInFlag(CmdArgs, options::OPT_fborland_extensions, @@ -6618,6 +6624,13 @@ Args.addOptInFlag(CmdArgs, options::OPT_frelaxed_template_template_args, options::OPT_fno_relaxed_template_template_args); + // MSVC turns on /Zc:sizedDealloc by default. Honor whatever is passed + // on the cmdline. + if (IsWindowsMSVC && + !Args.getLastArg(options::OPT_fsized_deallocation, + options::OPT_fno_sized_deallocation)) + CmdArgs.push_back("-fsized-deallocation"); + // -fsized-deallocation is off by default, as it is an ABI-breaking change for // most platforms. Args.addOptInFlag(CmdArgs, options::OPT_fsized_deallocation, diff --git a/clang/test/Driver/cl-zc.cpp b/clang/test/Driver/cl-zc.cpp --- a/clang/test/Driver/cl-zc.cpp +++ b/clang/test/Driver/cl-zc.cpp @@ -1,6 +1,12 @@ // Note: %s must be preceded by --, otherwise it may be interpreted as a // command-line option, e.g. on Mac where %s is commonly under /Users. +// RUN: %clang_cl /c /std:c++17 -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-CPP17-DEFAULT %s +// ALIGNED-NEW-CPP17-DEFAULT: "-faligned-allocation" + +// RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=SIZED-DEALLOC-DEFAULT %s +// SIZED-DEALLOC-DEFAULT: "-fsized-deallocation" + // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=TRIGRAPHS-DEFAULT %s // cc1 will disable trigraphs for -fms-compatibility as long as -ftrigraphs // isn't explicitly passed.