[PATCH] D127641: [clang-cl][MSVC] Enable /Zc:alignedNew for C++17 and /Zc:sizedDealloc by default
Stephen Long via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 14 17:38:59 PDT 2022
steplong updated this revision to Diff 436985.
steplong added a comment.
- Change logic for /Zc:alignedNew and /Zc:sizedDealloc
- Add tests for different /std:c++
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127641/new/
https://reviews.llvm.org/D127641
Files:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-zc.cpp
Index: clang/test/Driver/cl-zc.cpp
===================================================================
--- clang/test/Driver/cl-zc.cpp
+++ clang/test/Driver/cl-zc.cpp
@@ -1,6 +1,17 @@
// 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 -### -- %s 2>&1 | FileCheck -check-prefix=SIZED-DEALLOC-DEFAULT %s
+// SIZED-DEALLOC-DEFAULT: "-fsized-deallocation"
+
+// RUN: %clang_cl /c /std:c++11 -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-BEFORE-CPP17-DEFAULT %s
+// RUN: %clang_cl /c /std:c++14 -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-BEFORE-CPP17-DEFAULT %s
+// RUN: %clang_cl /c /std:c++17 -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-CPP17ONWARDS-DEFAULT %s
+// RUN: %clang_cl /c /std:c++20 -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-CPP17ONWARDS-DEFAULT %s
+// RUN: %clang_cl /c /std:c++latest -### -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-CPP17ONWARDS-DEFAULT %s
+// ALIGNED-NEW-BEFORE-CPP17-DEFAULT-NOT: "-faligned-allocation"
+// ALIGNED-NEW-CPP17ONWARDS-DEFAULT: "-faligned-allocation"
+
// 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.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6483,6 +6483,7 @@
}
CmdArgs.push_back(LanguageStandard.data());
}
+ bool IsCPP17Onwards = false;
if (ImplyVCPPCXXVer) {
StringRef LanguageStandard;
if (const Arg *StdArg = Args.getLastArg(options::OPT__SLASH_std)) {
@@ -6506,6 +6507,9 @@
}
CmdArgs.push_back(LanguageStandard.data());
+
+ IsCPP17Onwards =
+ LanguageStandard != "-std=c++11" && LanguageStandard != "-std=c++14";
}
Args.addOptInFlag(CmdArgs, options::OPT_fborland_extensions,
@@ -6635,9 +6639,14 @@
options::OPT_fno_relaxed_template_template_args);
// -fsized-deallocation is off by default, as it is an ABI-breaking change for
- // most platforms.
- Args.addOptInFlag(CmdArgs, options::OPT_fsized_deallocation,
- options::OPT_fno_sized_deallocation);
+ // most platforms. MSVC turns on /Zc:sizedDealloc by default.
+ if (IsWindowsMSVC &&
+ !Args.getLastArg(options::OPT_fsized_deallocation,
+ options::OPT_fno_sized_deallocation))
+ CmdArgs.push_back("-fsized-deallocation");
+ else
+ Args.addOptInFlag(CmdArgs, options::OPT_fsized_deallocation,
+ options::OPT_fno_sized_deallocation);
// -faligned-allocation is on by default in C++17 onwards and otherwise off
// by default.
@@ -6648,6 +6657,8 @@
CmdArgs.push_back("-fno-aligned-allocation");
else
CmdArgs.push_back("-faligned-allocation");
+ } else if (IsCPP17Onwards) {
+ CmdArgs.push_back("-faligned-allocation");
}
// The default new alignment can be specified using a dedicated option or via
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127641.436985.patch
Type: text/x-patch
Size: 3166 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220615/5b2094ad/attachment.bin>
More information about the cfe-commits
mailing list