[clang] [Clang][CodeGen] Emit `llvm.ptrmask` for `align_up` and `align_down` (PR #71238)
@@ -19671,41 +19671,38 @@ RValue CodeGenFunction::EmitBuiltinIsAligned(const CallExpr *E) { /// TODO: actually use ptrmask once most optimization passes know about it. zero9178 wrote: Can this TODO be removed now? https://github.com/llvm/llvm-project/pull/71238 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 984554f - [clang][DR] Test and mark DR1479 as complete
Author: Markus Böck Date: 2022-03-29T09:28:32+02:00 New Revision: 984554f846c44d4017be5b6e3bd694cc233ce7bc URL: https://github.com/llvm/llvm-project/commit/984554f846c44d4017be5b6e3bd694cc233ce7bc DIFF: https://github.com/llvm/llvm-project/commit/984554f846c44d4017be5b6e3bd694cc233ce7bc.diff LOG: [clang][DR] Test and mark DR1479 as complete DR: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1479 Clang has implemented this DR as far back as I could go on compiler explorer (3.0). This patch simply adds a test case and needed comments for the update script to mark it as complete. Differential Revision: https://reviews.llvm.org/D122620 Added: Modified: clang/test/CXX/drs/dr14xx.cpp clang/www/cxx_dr_status.html Removed: diff --git a/clang/test/CXX/drs/dr14xx.cpp b/clang/test/CXX/drs/dr14xx.cpp index 4d64943e9eea0..06fcc190784d9 100644 --- a/clang/test/CXX/drs/dr14xx.cpp +++ b/clang/test/CXX/drs/dr14xx.cpp @@ -463,6 +463,10 @@ namespace dr1467 { // dr1467: 3.7 c++11 #endif } // dr1467 +namespace dr1479 { // dr1479: yes + int operator"" _a(const char*, std::size_t = 0); // expected-error {{literal operator cannot have a default argument}} +} + namespace dr1490 { // dr1490: 3.7 c++11 // List-initialization from a string literal diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index 4734e9fd89253..6f66e2262a565 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -8688,7 +8688,7 @@ C++ defect report implementation status https://wg21.link/cwg1479";>1479 CD3 Literal operators and default arguments -Unknown +Yes https://wg21.link/cwg1480";>1480 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c1e614c - [clang][DR] Test and mark DR1305 as complete
Author: Markus Böck Date: 2022-03-29T20:45:49+02:00 New Revision: c1e614c8eb5004582c4d8f153f30fbfd0fcbea94 URL: https://github.com/llvm/llvm-project/commit/c1e614c8eb5004582c4d8f153f30fbfd0fcbea94 DIFF: https://github.com/llvm/llvm-project/commit/c1e614c8eb5004582c4d8f153f30fbfd0fcbea94.diff LOG: [clang][DR] Test and mark DR1305 as complete DR: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1305 This DR has always been implemented in all clang versions as far back as I could go. This patch basically just adds a test with the needed comments to mark it as complete. Differential Revision: https://reviews.llvm.org/D122674 Added: Modified: clang/test/CXX/drs/dr13xx.cpp clang/www/cxx_dr_status.html Removed: diff --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp index cf7091a533b56..57d0f3cc97cc1 100644 --- a/clang/test/CXX/drs/dr13xx.cpp +++ b/clang/test/CXX/drs/dr13xx.cpp @@ -13,6 +13,16 @@ namespace std { }; } +#if __cplusplus >= 201103L +namespace dr1305 { // dr1305: yes +struct Incomplete; // expected-note {{forward declaration of 'dr1305::Incomplete'}} +struct Complete {}; + +int incomplete = alignof(Incomplete(&)[]); // expected-error {{invalid application of 'alignof' to an incomplete type 'dr1305::Incomplete'}} +int complete = alignof(Complete(&)[]); +} +#endif + namespace dr1310 { // dr1310: 5 struct S {} * sp = new S::S; // expected-error {{qualified reference to 'S' is a constructor name}} void f() { diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index 6f66e2262a565..e730d6088ebaf 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -7644,7 +7644,7 @@ C++ defect report implementation status https://wg21.link/cwg1305";>1305 CD3 alignof applied to array of unknown size -Unknown +Yes https://wg21.link/cwg1306";>1306 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] e59335e - [clang][DR] Add test for DR1227 and mark it as complete
Author: Markus Böck Date: 2022-03-30T09:25:52+02:00 New Revision: e59335e891105d75ece5f7f4c40b5eaff6ce2f63 URL: https://github.com/llvm/llvm-project/commit/e59335e891105d75ece5f7f4c40b5eaff6ce2f63 DIFF: https://github.com/llvm/llvm-project/commit/e59335e891105d75ece5f7f4c40b5eaff6ce2f63.diff LOG: [clang][DR] Add test for DR1227 and mark it as complete DR: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1227 This DR has been implemented in Clang as far back as I could check. This patch simply adds a test and comment to mark it as complete. Differential Revision: https://reviews.llvm.org/D122682 Added: Modified: clang/test/CXX/drs/dr12xx.cpp clang/www/cxx_dr_status.html Removed: diff --git a/clang/test/CXX/drs/dr12xx.cpp b/clang/test/CXX/drs/dr12xx.cpp index 1bc4c39734435..dcc131104e7bd 100644 --- a/clang/test/CXX/drs/dr12xx.cpp +++ b/clang/test/CXX/drs/dr12xx.cpp @@ -27,6 +27,21 @@ namespace dr1213 { // dr1213: 7 #endif } +#if __cplusplus >= 201103L +namespace dr1227 { // dr1227: yes +template struct A { using X = typename T::X; }; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}} +template typename T::X f(typename A::X); +template void f(...) { } +template auto g(typename A::X) -> typename T::X; // expected-note {{in instantiation of template class 'dr1227::A' requested here}} +template void g(...) { } + +void h() { + f(0); // OK, substituting return type causes deduction to fail + g(0); // expected-note {{while substituting explicitly-specified template arguments into function template 'g'}} +} +} +#endif + namespace dr1250 { // dr1250: 3.9 struct Incomplete; diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index e730d6088ebaf..ef131b9a71e67 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -7176,7 +7176,7 @@ C++ defect report implementation status https://wg21.link/cwg1227";>1227 CD3 Mixing immediate and non-immediate contexts in deduction failure -Unknown +Yes https://wg21.link/cwg1228";>1228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] [Modules] [Driver] Don't enable -fdelayed-template-parsing by default on windows with C++20 modules (PR #69431)
zero9178 wrote: According to the docs [0], MSVC actually defaults to `-fno-delayed-template-parsing` (`/Zc:twoPhase-` with MSVC CLI) if using C++20. This is due to `-std:c++20` implying `/permissive-` which implies `/Zc:twoPhase-`. We could therefore just disable it based on language version alone, not just based on whether we are using modules. I previously tried to make it the default everywhere in https://reviews.llvm.org/D103772. @rnk argued we could always make it the default. Given that MSVC is essentially phasing it out and making all their headers compatible with `/Zc:twoPhase-` for the sake of C++20 support, it should be more feasible than previously. [0] https://learn.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=msvc-170 https://github.com/llvm/llvm-project/pull/69431 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] [Modules] [Driver] Don't enable -fdelayed-template-parsing by default on windows with C++20 modules (PR #69431)
zero9178 wrote: > > According to the docs [0], MSVC actually defaults to > > `-fno-delayed-template-parsing` (`/Zc:twoPhase-` with MSVC CLI) if using > > C++20. This is due to `-std:c++20` implying `/permissive-` which implies > > `/Zc:twoPhase-`. We could therefore just disable it based on language > > version alone, not just based on whether we are using modules. > > I previously tried to make it the default everywhere in > > https://reviews.llvm.org/D103772. @rnk argued we could always make it the > > default. Given that MSVC is essentially phasing it out and making all their > > headers compatible with `/Zc:twoPhase-` for the sake of C++20 support, it > > should be more feasible than previously. > > [0] > > https://learn.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=msvc-170 > > Thanks for the info! It looks like your patch can cover this patch. And we > can be sure that this patch itself is correct. > > Would you like to send that patch itself soon? If not, I'd like to land the > patch soon to give better user experience. Then you can revert this. If you > plan to send that patch soon, I'd like to discard the patch itself. I sadly won't have the time to push this so feel free to proceed working on this PR. > > > I still support disabling delayed template parsing by default in all > > > configurations. Ultimately, this feature is a source of bugs, and we > > > should start the clock on its deprecation and removal. This, of course, > > > involves real work, and I haven't allocated any time (mine or others') to > > > it. > > > > > > So @ChuanqiXu9 's patch is at least a conservative step towards that > > (limiting the change to C++20 modules where we know there is a problem) - > > we could then extend that to C++20, in general (as per @zero9178 's comment > > above). As you say deprecation and removal is more work. > > Yeah, how about we at least match MSVC here - and. generalize it to C++20 > today, leaving the older deprecation work to others/another time? I would also support this approach as it can also be seen as matching MSVC behaviour https://github.com/llvm/llvm-project/pull/69431 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir][LLVM] Verify too many indices in GEP verifier (PR #70174)
https://github.com/zero9178 updated https://github.com/llvm/llvm-project/pull/70174 From 03fb7aceae81227c3a64cf4b9ba1e53a69e46511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20B=C3=B6ck?= Date: Wed, 25 Oct 2023 09:54:16 +0200 Subject: [PATCH 1/3] [mlir][LLVM] Verify too many indices in GEP verifier The current verifier stopped verification with a success value as soon as a type was encountered that cannot be indexed into. The correct behaviour in this case is to error out as there are too many indices for the element type. Not doing so leads to bad user-experience as an invalid GEP is likely to fail only later during LLVM IR translation. This PR implements the correct verification behaviour. Some tests upstream had to also be fixed as they were creating invalid GEPs. Fixes https://github.com/llvm/llvm-project/issues/70168 --- mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp| 69 --- mlir/test/Dialect/LLVMIR/invalid.mlir | 8 +++ mlir/test/Dialect/LLVMIR/mem2reg.mlir | 9 ++- .../LLVMIR/roundtrip-typed-pointers.mlir | 4 +- mlir/test/Dialect/LLVMIR/roundtrip.mlir | 4 +- 5 files changed, 60 insertions(+), 34 deletions(-) diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index 95c04098d05fc2f..70045d028cc3214 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -704,50 +704,72 @@ struct GEPStaticIndexError << "to be constant"; } }; + +/// llvm::Error for non-static GEP index indexing a struct. +struct GEPCannotIndexError +: public llvm::ErrorInfo { + static char ID; + + using ErrorInfo::ErrorInfo; + + void log(llvm::raw_ostream &os) const override { +os << "expected index " << indexPos << " indexing a struct " + << "to be constant"; + } +}; + } // end anonymous namespace char GEPIndexError::ID = 0; char GEPIndexOutOfBoundError::ID = 0; char GEPStaticIndexError::ID = 0; - -/// For the given `structIndices` and `indices`, check if they're complied -/// with `baseGEPType`, especially check against LLVMStructTypes nested within. -static llvm::Error verifyStructIndices(Type baseGEPType, unsigned indexPos, - GEPIndicesAdaptor indices) { +char GEPCannotIndexError::ID = 0; + +/// For the given `indices`, check if they comply with `baseGEPType`, +// especially check against LLVMStructTypes nested within. +static LogicalResult +verifyStructIndices(Type baseGEPType, unsigned indexPos, +GEPIndicesAdaptor indices, +function_ref emitOpError) { if (indexPos >= indices.size()) // Stop searching -return llvm::Error::success(); +return success(); - return llvm::TypeSwitch(baseGEPType) - .Case([&](LLVMStructType structType) -> llvm::Error { + return llvm::TypeSwitch(baseGEPType) + .Case([&](LLVMStructType structType) -> LogicalResult { if (!indices[indexPos].is()) - return llvm::make_error(indexPos); + return emitOpError() << "expected index " << indexPos + << " indexing a struct to be constant"; int32_t gepIndex = indices[indexPos].get().getInt(); ArrayRef elementTypes = structType.getBody(); if (gepIndex < 0 || static_cast(gepIndex) >= elementTypes.size()) - return llvm::make_error(indexPos); + return emitOpError() << "index " << indexPos + << " indexing a struct is out of bounds"; // Instead of recursively going into every children types, we only // dive into the one indexed by gepIndex. return verifyStructIndices(elementTypes[gepIndex], indexPos + 1, - indices); + indices, emitOpError); }) .Case([&](auto containerType) -> llvm::Error { +LLVMArrayType>([&](auto containerType) -> LogicalResult { return verifyStructIndices(containerType.getElementType(), indexPos + 1, - indices); + indices, emitOpError); }) - .Default( - [](auto otherType) -> llvm::Error { return llvm::Error::success(); }); + .Default([&](auto otherType) -> LogicalResult { +return emitOpError() + << "type " << otherType << " cannot be indexed (index #" + << indexPos << ")"; + }); } -/// Driver function around `recordStructIndices`. Note that we always check -/// from the second GEP index since the first one is always dynamic. -static llvm::Error verifyStructIndices(Type baseGEPType, - GEPIndicesAdaptor indices) { - return verifyStructIndices(baseGEPType, /*indexPos=*/1, indices); +/// Driver function around `verifyStructIndices`. +static LogicalResult +verifyStructIndices(Type baseGEPType, GEPIndicesAd
[clang] [mlir][LLVM] Verify too many indices in GEP verifier (PR #70174)
https://github.com/zero9178 closed https://github.com/llvm/llvm-project/pull/70174 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 0b61f43 - [CMake] Consistently use the LibXml2::LibXml2 target instead of LIBXML2_LIBRARIES
Author: Markus Böck Date: 2021-09-25T13:13:11+02:00 New Revision: 0b61f43b6096a9e98652991cba34e8ad44d35101 URL: https://github.com/llvm/llvm-project/commit/0b61f43b6096a9e98652991cba34e8ad44d35101 DIFF: https://github.com/llvm/llvm-project/commit/0b61f43b6096a9e98652991cba34e8ad44d35101.diff LOG: [CMake] Consistently use the LibXml2::LibXml2 target instead of LIBXML2_LIBRARIES Linking against the LibXml2::LibXml2 target has the advantage of not only importing the library, but also adding the include path as well as any definitions the library requires. In case of a static build of libxml2, eg. a define is set on Windows to remove any DLL imports and export. LLVM already makes use of the target, but c-index-test and lldb were still linking against the library only. The workaround for Mac OS-X that I removed seems to have also been made redundant since https://reviews.llvm.org/D84563 I believe Differential Revision: https://reviews.llvm.org/D109975 Added: Modified: clang/tools/c-index-test/CMakeLists.txt lldb/source/Host/CMakeLists.txt Removed: diff --git a/clang/tools/c-index-test/CMakeLists.txt b/clang/tools/c-index-test/CMakeLists.txt index ceef4b08637cc..99c6081db2d63 100644 --- a/clang/tools/c-index-test/CMakeLists.txt +++ b/clang/tools/c-index-test/CMakeLists.txt @@ -40,12 +40,7 @@ set_target_properties(c-index-test # If libxml2 is available, make it available for c-index-test. if (CLANG_HAVE_LIBXML) - if ((CMAKE_OSX_SYSROOT) AND (EXISTS ${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR})) -include_directories(SYSTEM ${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR}) - else() -include_directories(SYSTEM ${LIBXML2_INCLUDE_DIR}) - endif() - target_link_libraries(c-index-test PRIVATE ${LIBXML2_LIBRARIES}) + target_link_libraries(c-index-test PRIVATE LibXml2::LibXml2) endif() if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt index a018fd6c183dc..c18e8ce004b08 100644 --- a/lldb/source/Host/CMakeLists.txt +++ b/lldb/source/Host/CMakeLists.txt @@ -137,7 +137,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "NetBSD") list(APPEND EXTRA_LIBS kvm) endif() if (LLDB_ENABLE_LIBXML2) - list(APPEND EXTRA_LIBS ${LIBXML2_LIBRARIES}) + list(APPEND EXTRA_LIBS LibXml2::LibXml2) endif() if (HAVE_LIBDL) list(APPEND EXTRA_LIBS ${CMAKE_DL_LIBS}) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 9f1b832 - Reland "[Driver][Windows] Support per-target runtimes dir layout for profile instr generate"
Author: Markus Böck Date: 2021-02-24T23:40:20+01:00 New Revision: 9f1b832331e350426f7f2f8cc30ab8ba991f5884 URL: https://github.com/llvm/llvm-project/commit/9f1b832331e350426f7f2f8cc30ab8ba991f5884 DIFF: https://github.com/llvm/llvm-project/commit/9f1b832331e350426f7f2f8cc30ab8ba991f5884.diff LOG: Reland "[Driver][Windows] Support per-target runtimes dir layout for profile instr generate" This relands commit rG7f9d5d6e444c which was reverted in rGab5b00ada9e7 Differential Revision: https://reviews.llvm.org/D96638 Added: Modified: clang/include/clang/Driver/ToolChain.h clang/lib/Driver/ToolChain.cpp clang/lib/Driver/ToolChains/BareMetal.cpp clang/lib/Driver/ToolChains/BareMetal.h clang/test/Driver/cl-options.c clang/test/Driver/fsanitize.c clang/test/Driver/instrprof-ld.c clang/test/Driver/sanitizer-ld.c Removed: diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index df4848d9e1345..e7e5a1f7a6ad0 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -184,6 +184,11 @@ class ToolChain { virtual Tool *buildStaticLibTool() const; virtual Tool *getTool(Action::ActionClass AC) const; + virtual std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args, + StringRef Component, + FileType Type, + bool AddArch) const; + /// \name Utilities for implementing subclasses. ///@{ static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, @@ -432,10 +437,9 @@ class ToolChain { getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component, FileType Type = ToolChain::FT_Static) const; - virtual std::string - getCompilerRTBasename(const llvm::opt::ArgList &Args, StringRef Component, -FileType Type = ToolChain::FT_Static, -bool AddArch = true) const; + std::string getCompilerRTBasename(const llvm::opt::ArgList &Args, +StringRef Component, +FileType Type = ToolChain::FT_Static) const; // Returns target specific runtime path if it exists. virtual Optional getRuntimePath() const; diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 372be613b795c..3f500617d8434 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -414,8 +414,16 @@ std::string ToolChain::getCompilerRTPath() const { } std::string ToolChain::getCompilerRTBasename(const ArgList &Args, - StringRef Component, FileType Type, - bool AddArch) const { + StringRef Component, + FileType Type) const { + std::string CRTAbsolutePath = getCompilerRT(Args, Component, Type); + return llvm::sys::path::filename(CRTAbsolutePath).str(); +} + +std::string ToolChain::buildCompilerRTBasename(const llvm::opt::ArgList &Args, + StringRef Component, + FileType Type, + bool AddArch) const { const llvm::Triple &TT = getTriple(); bool IsITANMSVCWindows = TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment(); @@ -431,8 +439,8 @@ std::string ToolChain::getCompilerRTBasename(const ArgList &Args, Suffix = IsITANMSVCWindows ? ".lib" : ".a"; break; case ToolChain::FT_Shared: -Suffix = Triple.isOSWindows() - ? (Triple.isWindowsGNUEnvironment() ? ".dll.a" : ".lib") +Suffix = TT.isOSWindows() + ? (TT.isWindowsGNUEnvironment() ? ".dll.a" : ".lib") : ".so"; break; } @@ -450,7 +458,7 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component, FileType Type) const { // Check for runtime files in the new layout without the architecture first. std::string CRTBasename = - getCompilerRTBasename(Args, Component, Type, /*AddArch=*/false); + buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false); for (const auto &LibPath : getLibraryPaths()) { SmallString<128> P(LibPath); llvm::sys::path::append(P, CRTBasename); @@ -460,7 +468,8 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component, // Fall back to the old expected compiler-rt name if the new one does not // exist. - CRTBasename = getCompilerRTBasename(Args, Component, Type, /*AddArch=*/true); + CRTBasename = + buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/true); Sma
[clang] 9833b57 - [clang][driver] Add -foperator-names
Author: Markus Böck Date: 2021-06-10T17:01:35+02:00 New Revision: 9833b57981c4e9402a326b5acd805e074cd2c802 URL: https://github.com/llvm/llvm-project/commit/9833b57981c4e9402a326b5acd805e074cd2c802 DIFF: https://github.com/llvm/llvm-project/commit/9833b57981c4e9402a326b5acd805e074cd2c802.diff LOG: [clang][driver] Add -foperator-names This patch adds the command line option -foperator-names which acts as the opposite of -fno-operator-names. With this command line option it is possible to reenable C++ operator keywords on the command line if -fno-operator-names had previously been passed. Differential Revision: https://reviews.llvm.org/D103749 Added: clang/test/Driver/cxx-operator-names.cpp Modified: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Clang.cpp Removed: diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 7dcee76b4ed8..862cb32730a2 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2221,9 +2221,10 @@ def fno_ms_compatibility : Flag<["-"], "fno-ms-compatibility">, Group, def fno_objc_legacy_dispatch : Flag<["-"], "fno-objc-legacy-dispatch">, Group; def fno_objc_weak : Flag<["-"], "fno-objc-weak">, Group, Flags<[CC1Option]>; def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, Group; -def fno_operator_names : Flag<["-"], "fno-operator-names">, Group, - HelpText<"Do not treat C++ operator name keywords as synonyms for operators">, - Flags<[CC1Option]>, MarshallingInfoNegativeFlag, cplusplus.KeyPath>; +defm operator_names : BoolFOption<"operator-names", + LangOpts<"CXXOperatorNames">, Default, + NegFlag, + PosFlag>; def fdiagnostics_absolute_paths : Flag<["-"], "fdiagnostics-absolute-paths">, Group, Flags<[CC1Option, CoreOption]>, HelpText<"Print absolute paths in diagnostics">, MarshallingInfoFlag>; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 6eaa8938a8d2..3163c26e4472 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5654,11 +5654,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ); + if (Args.hasFlag(options::OPT_fno_operator_names, + options::OPT_foperator_names, false)) +CmdArgs.push_back("-fno-operator-names"); + // Forward -f (flag) options which we can pass directly. Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs); - Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names); Args.AddLastArg(CmdArgs, options::OPT_femulated_tls, options::OPT_fno_emulated_tls); diff --git a/clang/test/Driver/cxx-operator-names.cpp b/clang/test/Driver/cxx-operator-names.cpp new file mode 100644 index ..d8a7a01449bb --- /dev/null +++ b/clang/test/Driver/cxx-operator-names.cpp @@ -0,0 +1,7 @@ +// RUN: %clang -### -S -foperator-names -fno-operator-names %s 2>&1 | \ +// RUN: FileCheck -check-prefix=CHECK-1 %s +// CHECK-1: "-fno-operator-names" + +// RUN: %clang -### -S -fno-operator-names -foperator-names %s 2>&1 | \ +// RUN: FileCheck -check-prefix=CHECK-2 %s +// CHECK-2-NOT: "-fno-operator-names" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 936d675 - [clang][msvc] Define _HAS_STATIC_RTTI to 0, when compiling with -fno-rtti
Author: Markus Böck Date: 2021-06-10T17:02:44+02:00 New Revision: 936d6756ccfbe207a181b692b828f9fd8f1489f2 URL: https://github.com/llvm/llvm-project/commit/936d6756ccfbe207a181b692b828f9fd8f1489f2 DIFF: https://github.com/llvm/llvm-project/commit/936d6756ccfbe207a181b692b828f9fd8f1489f2.diff LOG: [clang][msvc] Define _HAS_STATIC_RTTI to 0, when compiling with -fno-rtti When using the -fno-rtti option of the GCC style clang++, using typeid results in an error. The MSVC STL however kindly provides a define flag called _HAS_STATIC_RTTI, which either enables or disables uses of typeid throughout the STL. By default, if undefined, it is set to 1, enabling the use of typeid. With this patch, _HAS_STATIC_RTTI is set to 0 when -fno-rtti is specified. This way various headers of the MSVC STL like functional can be consumed without compilation failures. Differential Revision: https://reviews.llvm.org/D103771 Added: clang/test/Driver/msvc-static-rtti.cpp Modified: clang/lib/Driver/ToolChains/MSVC.cpp clang/lib/Driver/ToolChains/MSVC.h Removed: diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp index dd7fa5ebf6ff..9b1c320755ed 100644 --- a/clang/lib/Driver/ToolChains/MSVC.cpp +++ b/clang/lib/Driver/ToolChains/MSVC.cpp @@ -1573,3 +1573,13 @@ MSVCToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args, return DAL; } + +void MSVCToolChain::addClangTargetOptions( +const ArgList &DriverArgs, ArgStringList &CC1Args, +Action::OffloadKind DeviceOffloadKind) const { + // MSVC STL kindly allows removing all usages of typeid by defining + // _HAS_STATIC_RTTI to 0. Do so, when compiling with -fno-rtti + if (DriverArgs.hasArg(options::OPT_fno_rtti, options::OPT_frtti, +/*Default=*/false)) +CC1Args.push_back("-D_HAS_STATIC_RTTI=0"); +} diff --git a/clang/lib/Driver/ToolChains/MSVC.h b/clang/lib/Driver/ToolChains/MSVC.h index 432d399e241e..19d94c5c606e 100644 --- a/clang/lib/Driver/ToolChains/MSVC.h +++ b/clang/lib/Driver/ToolChains/MSVC.h @@ -122,6 +122,11 @@ class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain { bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); } + void + addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, +llvm::opt::ArgStringList &CC1Args, +Action::OffloadKind DeviceOffloadKind) const override; + protected: void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, diff --git a/clang/test/Driver/msvc-static-rtti.cpp b/clang/test/Driver/msvc-static-rtti.cpp new file mode 100644 index ..b352f07bc6c1 --- /dev/null +++ b/clang/test/Driver/msvc-static-rtti.cpp @@ -0,0 +1,5 @@ +// RUN: %clang -target x86_64-pc-windows-msvc -fno-rtti -### %s 2>&1 | FileCheck %s -check-prefix STATIC-RTTI-DEF +// RUN: %clang -target x86_64-pc-windows-msvc -frtti -### %s 2>&1 | FileCheck %s -check-prefix STATIC-RTTI-DEF-NOT + +// STATIC-RTTI-DEF: -D_HAS_STATIC_RTTI=0 +// STATIC-RTTI-DEF-NOT: -D_HAS_STATIC_RTTI=0 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c70b0e8 - [clang-cl] Add /permissive and /permissive-
Author: Markus Böck Date: 2021-06-10T17:06:19+02:00 New Revision: c70b0e808da8e1650f3ee426698a8b87c94b8910 URL: https://github.com/llvm/llvm-project/commit/c70b0e808da8e1650f3ee426698a8b87c94b8910 DIFF: https://github.com/llvm/llvm-project/commit/c70b0e808da8e1650f3ee426698a8b87c94b8910.diff LOG: [clang-cl] Add /permissive and /permissive- This patch adds the command line options /permissive and /permissive- to clang-cl. These flags are used in MSVC to enable various /Zc language conformance options at once. In particular, /permissive is used to enable the various non standard behaviour of MSVC, while /permissive- is the opposite. When either of two command lines are specified they are simply expanded to the various underlying /Zc options. In particular when /permissive is passed it currently expands to: /Zc:twoPhase- (disable two phase lookup) -fno-operator-names (disable C++ operator keywords) /permissive- expands to the opposites of these flags + /Zc:strictStrings (/Zc:strictStrings- does not currently exist). In the future, if any more MSVC workarounds are ever added they can easily be added to the expansion. One is also able to override settings done by permissive. Specifying /permissive- /Zc:twoPhase- will apply the settings from permissive minus, but disables two phase lookup. Motivation for this patch was mainly parity with MSVC as well as compatibility with Windows SDK headers. The /permissive page from MSVC documents various workarounds that have to be done for the Windows SDK headers [1], when MSVC is used with /permissive-. In these, Microsoft often recommends simply compiling with /permissive for the specified source files. Since some of these also apply to clang-cl (which acts like /permissive- by default mostly), and some are currently implemented as "hacks" within clang that I'd like to remove, adding /permissive and /permissive- to be in full parity with MSVC and Microsofts documentation made sense to me. [1] https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=msvc-160#windows-header-issues Differential Revision: https://reviews.llvm.org/D103773 Added: clang/test/Driver/cl-permissive.c Modified: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/MSVC.cpp Removed: diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 862cb32730a2..1271a75ba67e 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6099,6 +6099,10 @@ def _SLASH_o : CLJoinedOrSeparate<"o">, HelpText<"Deprecated (set output file name); use /Fe or /Fe">, MetaVarName<"">; def _SLASH_P : CLFlag<"P">, HelpText<"Preprocess to file">; +def _SLASH_permissive : CLFlag<"permissive">, + HelpText<"Enable some non conforming code to compile">; +def _SLASH_permissive_ : CLFlag<"permissive-">, + HelpText<"Disable non conforming code from compiling (default)">; def _SLASH_Tc : CLCompileJoinedOrSeparate<"Tc">, HelpText<"Treat as C source file">, MetaVarName<"">; def _SLASH_TC : CLCompileFlag<"TC">, HelpText<"Treat all source files as C">; @@ -6180,7 +6184,6 @@ def _SLASH_FS : CLIgnoredFlag<"FS">; def _SLASH_JMC : CLIgnoredFlag<"JMC">; def _SLASH_kernel_ : CLIgnoredFlag<"kernel-">; def _SLASH_nologo : CLIgnoredFlag<"nologo">; -def _SLASH_permissive_ : CLIgnoredFlag<"permissive-">; def _SLASH_RTC : CLIgnoredJoined<"RTC">; def _SLASH_sdl : CLIgnoredFlag<"sdl">; def _SLASH_sdl_ : CLIgnoredFlag<"sdl-">; diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp index 9b1c320755ed..ea79c0ec9eb5 100644 --- a/clang/lib/Driver/ToolChains/MSVC.cpp +++ b/clang/lib/Driver/ToolChains/MSVC.cpp @@ -1523,6 +1523,20 @@ static void TranslateDArg(Arg *A, llvm::opt::DerivedArgList &DAL, DAL.AddJoinedArg(A, Opts.getOption(options::OPT_D), NewVal); } +static void TranslatePermissive(Arg *A, llvm::opt::DerivedArgList &DAL, +const OptTable &Opts) { + DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase_)); + DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_operator_names)); + // There is currently no /Zc:strictStrings- in clang-cl +} + +static void TranslatePermissiveMinus(Arg *A, llvm::opt::DerivedArgList &DAL, + const OptTable &Opts) { + DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase)); + DAL.AddFlagArg(A, Opts.getOption(options::OPT_foperator_names)); + DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_strictStrings)); +} + llvm::opt::DerivedArgList * MSVCToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch, @@ -1565,6 +1579,12 @@ MSVCToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args, } else if (A->getOption().matches(options::OPT_D)) {
[clang] 7ff3a89 - [clang][NFC] Add IsAnyDestructorNoReturn field to CXXRecord instead of calculating it on demand
Author: Markus Böck Date: 2021-06-13T14:48:27+02:00 New Revision: 7ff3a89a7b94193638cb13f8a0a1ef70094c8263 URL: https://github.com/llvm/llvm-project/commit/7ff3a89a7b94193638cb13f8a0a1ef70094c8263 DIFF: https://github.com/llvm/llvm-project/commit/7ff3a89a7b94193638cb13f8a0a1ef70094c8263.diff LOG: [clang][NFC] Add IsAnyDestructorNoReturn field to CXXRecord instead of calculating it on demand This patch addresses a performance issue I noticed when using clang-12 to compile projects of mine. Even though the files weren't too large (around 1k cpp), the compiler was taking more than a minute to compile the source file, much longer than either GCC or MSVC. Using a profiler it turned out the issue was the isAnyDestructorNoReturn function in CXXRecordDecl. In particular it being recursive, recalculating the property for every invocation, for every field and base class. This showed up in tracebacks in the profiler. This patch instead adds IsAnyDestructorNoReturn as a Field to the data inside of CXXRecord and updates when a new base class, destructor, or record field member is added. After this patch the problematic file of mine went from a compile time of 81s, down to 12s. The patch itself should not change any functionality, just improve performance. Differential Revision: https://reviews.llvm.org/D104182 Added: Modified: clang/include/clang/AST/CXXRecordDeclDefinitionBits.def clang/include/clang/AST/DeclCXX.h clang/lib/AST/DeclCXX.cpp Removed: diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def index d15d6698860f4..9b270682f8cf0 100644 --- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def +++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def @@ -242,4 +242,8 @@ FIELD(HasDeclaredCopyConstructorWithConstParam, 1, MERGE_OR) /// const-qualified reference parameter or a non-reference parameter. FIELD(HasDeclaredCopyAssignmentWithConstParam, 1, MERGE_OR) +/// Whether the destructor is no-return. Either explicitly, or if any +/// base classes or fields have a no-return destructor +FIELD(IsAnyDestructorNoReturn, 1, NO_MERGE) + #undef FIELD diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index e9f9da6bd4bc4..0d5ad40fc19e7 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -1480,7 +1480,7 @@ class CXXRecordDecl : public RecordDecl { /// Returns true if the class destructor, or any implicitly invoked /// destructors are marked noreturn. - bool isAnyDestructorNoReturn() const; + bool isAnyDestructorNoReturn() const { return data().IsAnyDestructorNoReturn; } /// If the class is a local class [class.local], returns /// the enclosing function declaration. diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index bcff72ccadeab..aeee35d9c74f6 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -108,7 +108,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) ImplicitCopyConstructorCanHaveConstParamForNonVBase(true), ImplicitCopyAssignmentHasConstParam(true), HasDeclaredCopyConstructorWithConstParam(false), - HasDeclaredCopyAssignmentWithConstParam(false), IsLambda(false), + HasDeclaredCopyAssignmentWithConstParam(false), + IsAnyDestructorNoReturn(false), IsLambda(false), IsParsingBaseSpecifiers(false), ComputedVisibleConversions(false), HasODRHash(false), Definition(D) {} @@ -424,6 +425,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, if (!BaseClassDecl->hasIrrelevantDestructor()) data().HasIrrelevantDestructor = false; +if (BaseClassDecl->isAnyDestructorNoReturn()) + data().IsAnyDestructorNoReturn = true; + // C++11 [class.copy]p18: // The implicitly-declared copy assignment operator for a class X will // have the form 'X& X::operator=(const X&)' if each direct base class B @@ -836,6 +840,9 @@ void CXXRecordDecl::addedMember(Decl *D) { data().HasTrivialSpecialMembers &= ~SMF_Destructor; data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor; } + +if (DD->isNoReturn()) + data().IsAnyDestructorNoReturn = true; } // Handle member functions. @@ -1233,6 +1240,8 @@ void CXXRecordDecl::addedMember(Decl *D) { data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor; if (!FieldRec->hasIrrelevantDestructor()) data().HasIrrelevantDestructor = false; +if (FieldRec->isAnyDestructorNoReturn()) + data().IsAnyDestructorNoReturn = true; if (FieldRec->hasObjectMember()) setHasObjectMember(true); if (FieldRec->hasVolatileMember()) @@ -1888,29 +1897,6 @@ CXXDestructorDecl *CXXRecordDecl::getDestructor() const { return R.empty() ? nullptr : dyn_c
[clang] c9889c4 - [clang-cl] Don't expand /permissive- to /ZC:strictStrings yet
Author: Markus Böck Date: 2021-06-19T13:28:32+02:00 New Revision: c9889c44ec5a4054833457c813e155f284703ef4 URL: https://github.com/llvm/llvm-project/commit/c9889c44ec5a4054833457c813e155f284703ef4 DIFF: https://github.com/llvm/llvm-project/commit/c9889c44ec5a4054833457c813e155f284703ef4.diff LOG: [clang-cl] Don't expand /permissive- to /ZC:strictStrings yet Follow up on rGc70b0e808da8 /Zc:strictStrings is an alias to an option part of the -W group. When the driver tries to render the option back to a string for the cc1 invocation, it sadly gets rendered with the original spelling instead of the alias, causing issues reported here: https://reviews.llvm.org/D103773#inline-989447 I am thinking it's the best to revert this part of the patch until I figured out how to correctly add the arg and until /Zc:strictStrings- exists/is needed. Added: Modified: clang/lib/Driver/ToolChains/MSVC.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp index bb17f73e1488..cf08c42965c8 100644 --- a/clang/lib/Driver/ToolChains/MSVC.cpp +++ b/clang/lib/Driver/ToolChains/MSVC.cpp @@ -1493,14 +1493,12 @@ static void TranslatePermissive(Arg *A, llvm::opt::DerivedArgList &DAL, const OptTable &Opts) { DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase_)); DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_operator_names)); - // There is currently no /Zc:strictStrings- in clang-cl } static void TranslatePermissiveMinus(Arg *A, llvm::opt::DerivedArgList &DAL, const OptTable &Opts) { DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase)); DAL.AddFlagArg(A, Opts.getOption(options::OPT_foperator_names)); - DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_strictStrings)); } llvm::opt::DerivedArgList * ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] af2796c - [test] Add ability to get error messages from CMake for errc substitution
Author: Markus Böck Date: 2021-03-15T20:56:08+01:00 New Revision: af2796c76d2ff4b73165ed47959afd35a769beee URL: https://github.com/llvm/llvm-project/commit/af2796c76d2ff4b73165ed47959afd35a769beee DIFF: https://github.com/llvm/llvm-project/commit/af2796c76d2ff4b73165ed47959afd35a769beee.diff LOG: [test] Add ability to get error messages from CMake for errc substitution Visual Studios implementation of the C++ Standard Library does not use strerror to produce a message for std::error_code unlike other standard libraries such as libstdc++ or libc++ that might be used. This patch adds a cmake script that through running a C++ program gets the error messages for the POSIX error codes and passes them onto lit through an optional config parameter. If the config parameter is not set, or getting the messages failed, due to say a cross compiling configuration without an emulator, it will fall back to using pythons strerror functions. Differential Revision: https://reviews.llvm.org/D98278 Added: llvm/cmake/modules/GetErrcMessages.cmake Modified: clang/CMakeLists.txt clang/test/lit.site.cfg.py.in lld/CMakeLists.txt lld/test/lit.site.cfg.py.in llvm/CMakeLists.txt llvm/test/lit.site.cfg.py.in llvm/utils/lit/lit/llvm/config.py Removed: diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index 9ecf4b9d2de8..7af05c331e94 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -113,6 +113,7 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) include(TableGen) include(HandleLLVMOptions) include(VersionFromVCS) + include(GetErrcMessages) include(LLVMDistributionSupport) set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") @@ -177,6 +178,8 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) endif() set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") + get_errc_messages(LLVM_LIT_ERRC_MESSAGES) + # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools. if( WIN32 AND NOT CYGWIN ) set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools") diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in index eb01720249af..c3382e2c1c42 100644 --- a/clang/test/lit.site.cfg.py.in +++ b/clang/test/lit.site.cfg.py.in @@ -9,6 +9,7 @@ config.llvm_libs_dir = path(r"@LLVM_LIBS_DIR@") config.llvm_shlib_dir = path(r"@SHLIBDIR@") config.llvm_plugin_ext = "@LLVM_PLUGIN_EXT@" config.lit_tools_dir = path(r"@LLVM_LIT_TOOLS_DIR@") +config.errc_messages = "@LLVM_LIT_ERRC_MESSAGES@" config.clang_obj_root = path(r"@CLANG_BINARY_DIR@") config.clang_src_dir = path(r"@CLANG_SOURCE_DIR@") config.clang_tools_dir = path(r"@CLANG_TOOLS_DIR@") diff --git a/lld/CMakeLists.txt b/lld/CMakeLists.txt index cbca979aaeb1..53e09f93 100644 --- a/lld/CMakeLists.txt +++ b/lld/CMakeLists.txt @@ -54,6 +54,7 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) include(AddLLVM) include(TableGen) include(HandleLLVMOptions) + include(GetErrcMessages) include(CheckAtomic) if(LLVM_INCLUDE_TESTS) @@ -98,6 +99,8 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) endif() set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") + get_errc_messages(LLVM_LIT_ERRC_MESSAGES) + # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools. if(WIN32 AND NOT CYGWIN) set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools") diff --git a/lld/test/lit.site.cfg.py.in b/lld/test/lit.site.cfg.py.in index a140284e0ded..57fa15e730b1 100644 --- a/lld/test/lit.site.cfg.py.in +++ b/lld/test/lit.site.cfg.py.in @@ -8,6 +8,7 @@ config.llvm_obj_root = "@LLVM_BINARY_DIR@" config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" config.llvm_libs_dir = "@LLVM_LIBS_DIR@" config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" +config.errc_messages = "@LLVM_LIT_ERRC_MESSAGES@" config.lld_obj_root = "@LLD_BINARY_DIR@" config.lld_libs_dir = "@LLD_LIBS_DIR@" config.lld_tools_dir = "@LLD_TOOLS_DIR@" diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 22c1a130f4a5..51ed113f58c5 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -507,6 +507,9 @@ if (MSVC_IDE OR XCODE) endif() set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") +include(GetErrcMessages) +get_errc_messages(LLVM_LIT_ERRC_MESSAGES) + # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools. if( WIN32 AND NOT CYGWIN ) set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools") diff --git a/llvm/cmake/modules/GetErrcMessages.cmake b/llvm/cmake/modules/GetErrcMessages.cmake new file mode 100644 index ..79aa6456cc7e --- /dev/null +++ b/llvm/cmake/modules/GetErrcMessages.cmake @@ -0,0 +1,39 @@ + +# This function returns the messages of various POSIX error
[clang] 7ba70d3 - [PR52549][clang-cl] Predefine _MSVC_EXECUTION_CHARACTER_SET
Author: Markus Böck Date: 2021-11-30T09:13:22+01:00 New Revision: 7ba70d32736aef0c640b9d0e7b9081fc208c81c2 URL: https://github.com/llvm/llvm-project/commit/7ba70d32736aef0c640b9d0e7b9081fc208c81c2 DIFF: https://github.com/llvm/llvm-project/commit/7ba70d32736aef0c640b9d0e7b9081fc208c81c2.diff LOG: [PR52549][clang-cl] Predefine _MSVC_EXECUTION_CHARACTER_SET Since VS 2022 17.1 MSVC predefines _MSVC_EXECUTION_CHARACTER_SET to inform the users of the execution character set defined at compile time. The value the macro expands to is a Windows Code Page Identifier which are documented here: https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers As clang currently only supports UTF-8 it is defined as 65001. If clang-cl were to support a different execution character set in the future we'd have to change the value. Fixes https://bugs.llvm.org/show_bug.cgi?id=52549 Differential Revision: https://reviews.llvm.org/D114576 Added: Modified: clang/lib/Basic/Targets/OSTargets.cpp clang/test/Preprocessor/init.c Removed: diff --git a/clang/lib/Basic/Targets/OSTargets.cpp b/clang/lib/Basic/Targets/OSTargets.cpp index 7cd4a51901205..4d9a462b51366 100644 --- a/clang/lib/Basic/Targets/OSTargets.cpp +++ b/clang/lib/Basic/Targets/OSTargets.cpp @@ -201,6 +201,14 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) { } Builder.defineMacro("_INTEGRAL_MAX_BITS", "64"); + + // Starting with VS 2022 17.1, MSVC predefines the below macro to inform + // users of the execution character set defined at compile time. + // The value given is the Windows Code Page Identifier: + // https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers + // + // Clang currently only supports UTF-8, so we'll use 65001 + Builder.defineMacro("_MSVC_EXECUTION_CHARACTER_SET", "65001"); } void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts, diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 8bbfe85b9ba74..52c33d9b8b7a5 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -194,6 +194,7 @@ // MSEXT:#define _INTEGRAL_MAX_BITS 64 // MSEXT-NOT:#define _NATIVE_WCHAR_T_DEFINED 1 // MSEXT-NOT:#define _WCHAR_T_DEFINED 1 +// MSEXT:#define _MSVC_EXECUTION_CHARACTER_SET 65001 // // // RUN: %clang_cc1 -x c++ -fms-extensions -triple i686-pc-win32 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix MSEXT-CXX %s ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 3637dc6 - [clang][CodeGen] Consistently return nullptr Values for void builtins and scalar initalization
Author: Markus Böck Date: 2022-10-24T21:41:13+02:00 New Revision: 3637dc601c4923721a69426187aa69dd6a71a053 URL: https://github.com/llvm/llvm-project/commit/3637dc601c4923721a69426187aa69dd6a71a053 DIFF: https://github.com/llvm/llvm-project/commit/3637dc601c4923721a69426187aa69dd6a71a053.diff LOG: [clang][CodeGen] Consistently return nullptr Values for void builtins and scalar initalization A common post condition of the various visitor functions in CodeGen is that instructions, that do not return any values, simply return a nullptr Value as a sentinel. This has not been the case however for calls to some builtins returning void, as well as for an initializer expression of the form `void()`. This would then lead to ICEs in CodeGen on code relying on nullptr being returned for void values, which is eg. the case for conditional expressions [0]. This patch fixes that by returning nullptr Values for intrinsics known not to return any values as well as for a scalar initializer returning void. Fixes https://github.com/llvm/llvm-project/issues/53127 [0] https://github.com/llvm/llvm-project/blob/266ec801fb23f9f5f1d61ca9466e0805fbdb78a7/clang/lib/CodeGen/CGExprScalar.cpp#L4849-L4892 Differential Revision: https://reviews.llvm.org/D136548 Added: clang/test/CodeGen/pr53127.cpp Modified: clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CGExprScalar.cpp Removed: diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index fbb6e85e37d6e..f69b1e80607f8 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2518,11 +2518,11 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_va_start: case Builtin::BI__va_start: case Builtin::BI__builtin_va_end: -return RValue::get( -EmitVAStartEnd(BuiltinID == Builtin::BI__va_start - ? EmitScalarExpr(E->getArg(0)) - : EmitVAListRef(E->getArg(0)).getPointer(), - BuiltinID != Builtin::BI__builtin_va_end)); +EmitVAStartEnd(BuiltinID == Builtin::BI__va_start + ? EmitScalarExpr(E->getArg(0)) + : EmitVAListRef(E->getArg(0)).getPointer(), + BuiltinID != Builtin::BI__builtin_va_end); +return RValue::get(nullptr); case Builtin::BI__builtin_va_copy: { Value *DstPtr = EmitVAListRef(E->getArg(0)).getPointer(); Value *SrcPtr = EmitVAListRef(E->getArg(1)).getPointer(); @@ -2531,8 +2531,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, DstPtr = Builder.CreateBitCast(DstPtr, Type); SrcPtr = Builder.CreateBitCast(SrcPtr, Type); -return RValue::get(Builder.CreateCall(CGM.getIntrinsic(Intrinsic::vacopy), - {DstPtr, SrcPtr})); +Builder.CreateCall(CGM.getIntrinsic(Intrinsic::vacopy), {DstPtr, SrcPtr}); +return RValue::get(nullptr); } case Builtin::BI__builtin_abs: case Builtin::BI__builtin_labs: @@ -2804,7 +2804,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, Value *ArgValue = EmitScalarExpr(E->getArg(0)); Function *FnAssume = CGM.getIntrinsic(Intrinsic::assume); -return RValue::get(Builder.CreateCall(FnAssume, ArgValue)); +Builder.CreateCall(FnAssume, ArgValue); +return RValue::get(nullptr); } case Builtin::BI__arithmetic_fence: { // Create the builtin call if FastMath is selected, and the target @@ -2925,7 +2926,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, llvm::ConstantInt::get(Int32Ty, 3); Value *Data = llvm::ConstantInt::get(Int32Ty, 1); Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType()); -return RValue::get(Builder.CreateCall(F, {Address, RW, Locality, Data})); +Builder.CreateCall(F, {Address, RW, Locality, Data}); +return RValue::get(nullptr); } case Builtin::BI__builtin_readcyclecounter: { Function *F = CGM.getIntrinsic(Intrinsic::readcyclecounter); @@ -2938,9 +2940,11 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, return RValue::get(Builder.CreateCall(F, {Begin, End})); } case Builtin::BI__builtin_trap: -return RValue::get(EmitTrapCall(Intrinsic::trap)); +EmitTrapCall(Intrinsic::trap); +return RValue::get(nullptr); case Builtin::BI__debugbreak: -return RValue::get(EmitTrapCall(Intrinsic::debugtrap)); +EmitTrapCall(Intrinsic::debugtrap); +return RValue::get(nullptr); case Builtin::BI__builtin_unreachable: { EmitUnreachable(E->getExprLoc()); @@ -3721,7 +3725,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, } case Builtin::BI__builtin_unwind_init: { Function *F = CGM.getIntrinsi
[clang] 7a8cb6c - [clang][NFC] Fix warning due to initializing a pointer with `false`
Author: Markus Böck Date: 2022-12-31T18:07:03+01:00 New Revision: 7a8cb6cd4e3ff8aaadebff2b9d3ee9e2a326d444 URL: https://github.com/llvm/llvm-project/commit/7a8cb6cd4e3ff8aaadebff2b9d3ee9e2a326d444 DIFF: https://github.com/llvm/llvm-project/commit/7a8cb6cd4e3ff8aaadebff2b9d3ee9e2a326d444.diff LOG: [clang][NFC] Fix warning due to initializing a pointer with `false` Added: Modified: clang/lib/Sema/SemaInit.cpp Removed: diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index efc3274ce7d3c..d6ca63745f171 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -9150,7 +9150,7 @@ ExprResult InitializationSequence::Perform(Sema &S, break; } case SK_ParenthesizedListInit: { - CurInit = false; + CurInit = nullptr; TryOrBuildParenListInitialization(S, Entity, Kind, Args, *this, /*VerifyOnly=*/false, &CurInit); if (CurInit.get() && ResultType) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir][llvm] Fix elem type passing into `getelementptr` (PR #68136)
zero9178 wrote: What are the use cases for allowing either of these two syntaxes? The LLVM Dialect tries to closely mirror LLVM proper as much as possible and this would deviate from LLVMs behaviour. While the transition is currently stalled, in the future typed pointers will be removed from the dialect entirely, further discouraging the use of typed-pointers such as shown here. https://github.com/llvm/llvm-project/pull/68136 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Support] Rename HashBuilderImpl to HashBuilder (NFC) (PR #68173)
https://github.com/zero9178 approved this pull request. https://github.com/llvm/llvm-project/pull/68173 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir][llvm] Fix elem type passing into `getelementptr` (PR #68136)
zero9178 wrote: Thank you for your elaboration! I am not sure whether the original commit is referring to also supporting both typed pointers and opaque pointers in the exact same IR. This behaviour deviates from LLVM entirely as LLVM only supported one or the other as well. Furthermore, your example of the alloca is not quite equivalent to the GEP. Your first example uses strictly typed pointers while the second uses strictly opaque pointers. The GEP `llvm.getelementptr %0[0] : (!llvm.ptr) -> !llvm.ptr` mixes both opaque pointers and typed pointers, which has so far not been supported. Note that: `llvm.getelementptr %0[0] : (!llvm.ptr) -> !llvm.ptr, !llvm.ptr` and `llvm.getelementptr %0[0] : (!llvm.ptr) -> !llvm.ptr` work without issues. Lastly, the PR also deviates from how GEPs works with typed pointers as it deduces the element type from the result pointer. If we really want to support a half-typed half-opaque GEP it'd make more sense to support `llvm.getelementptr %0[0] : (!llvm.ptr) -> !llvm.ptr`. This would also allow specifying more than one index, something the current solution doesn't. E.g. ``` `llvm.getelementptr %0[0, 1] : (!llvm.ptr>) -> !llvm.ptr` ``` With all that said, I see this more as a "potential missing feature" rather than a bug. That is why I am curious what the motivation here is. Is this to ease transition to opaque pointers? I am not sure how effective this would be and I am a bit afraid of the burden of having to maintain what is essentially a third GEP representation. https://github.com/llvm/llvm-project/pull/68136 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir][llvm] Fix elem type passing into `getelementptr` (PR #68136)
zero9178 wrote: > So before I spend more time on the code, shall I rewrite this PR to throw a > clear error from `GEPOp::verify` for the incorrect representation? Then we > can close #63832. I'd personally be in favour of that. There is a **lot** of room for improvements in the verifiers in the LLVM Dialect so any contributions there are definitely highly appreciated! That said, its probably best to wait a bit for others to comment as well as they may have different views than I do. https://github.com/llvm/llvm-project/pull/68136 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Support] Deprecate system_endianness (PR #68279)
https://github.com/zero9178 approved this pull request. https://github.com/llvm/llvm-project/pull/68279 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reland "[mlir][arith] Canonicalization patterns for `arith.select` (#67809)" (PR #68941)
https://github.com/zero9178 approved this pull request. https://github.com/llvm/llvm-project/pull/68941 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir][LLVM] Model side effects of volatile and atomic load-store (PR #65730)
https://github.com/zero9178 updated https://github.com/llvm/llvm-project/pull/65730: From d32d6c5faca4141120482b7346c75f6656a29299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20B=C3=B6ck?= Date: Fri, 8 Sep 2023 11:16:22 +0200 Subject: [PATCH 1/2] [mlir][LLVM] Model side effects of volatile and atomic load-store According to the LLVM language reference, both volatile memory operations and atomic operations (except unordered) do not simply read memory but also perform write operations on arbitrary memory[0][1]. In the case of volatile memory operations, this is the case due to the read possibly having target specific properties. A common real-world situation where this happens is reading memory mapped registers on an MCU for example. Atomic operations are more special. They form a kind of memory barrier which from the perspective of the optimizer/lang-ref makes writes from other threads visible in the current thread. Any kind of synchronization can therefore conservatively be modeled as a write-effect. This PR therefore adjusts the side effects of `llvm.load` and `llvm.store` to add unknown global read and write effects if they are either atomic or volatile. Regarding testing: I am not sure how to best test this change for `llvm.store` and the "globalness" of the effect that isn't just a unit test checking that the output matches exactly. For the time being, I added a test making sure that `llvm.load` does not get DCEd in aforementioned cases. Related logic in LLVM proper: https://github.com/llvm/llvm-project/blob/3398744a6106c83993611bd3c5e79ec6b94417dc/llvm/lib/IR/Instruction.cpp#L638-L676 https://github.com/llvm/llvm-project/blob/3398744a6106c83993611bd3c5e79ec6b94417dc/llvm/include/llvm/IR/Instructions.h#L258-L262 [0] https://llvm.org/docs/LangRef.html#volatile-memory-accesses [1] https://llvm.org/docs/Atomics.html#monotonic --- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 10 ++ mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 22 + mlir/test/Dialect/LLVMIR/canonicalize.mlir | 17 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td index 7ceec72144eb52c..e9ed7f1186ee58a 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -326,9 +326,10 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure, } def LLVM_LoadOp : LLVM_MemAccessOpBase<"load", -[DeclareOpInterfaceMethods, +[DeclareOpInterfaceMethods, + DeclareOpInterfaceMethods, DeclareOpInterfaceMethods]> { - dag args = (ins Arg, "", [MemRead]>:$addr, + dag args = (ins LLVM_PointerTo:$addr, OptionalAttr:$alignment, UnitAttr:$volatile_, UnitAttr:$nontemporal, @@ -399,10 +400,11 @@ def LLVM_LoadOp : LLVM_MemAccessOpBase<"load", } def LLVM_StoreOp : LLVM_MemAccessOpBase<"store", -[DeclareOpInterfaceMethods, +[DeclareOpInterfaceMethods, + DeclareOpInterfaceMethods, DeclareOpInterfaceMethods]> { dag args = (ins LLVM_LoadableType:$value, - Arg,"",[MemWrite]>:$addr, + LLVM_PointerTo:$addr, OptionalAttr:$alignment, UnitAttr:$volatile_, UnitAttr:$nontemporal, diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index ae01f7c4621522b..a4e5c25f3394e67 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -812,6 +812,17 @@ Type GEPOp::getResultPtrElementType() { // LoadOp //===--===// +void LoadOp::getEffects( +SmallVectorImpl> +&effects) { + effects.emplace_back(MemoryEffects::Read::get(), getAddr()); + if (getVolatile_() || (getOrdering() != AtomicOrdering::not_atomic && + getOrdering() != AtomicOrdering::unordered)) { +effects.emplace_back(MemoryEffects::Write::get()); +effects.emplace_back(MemoryEffects::Read::get()); + } +} + /// Returns true if the given type is supported by atomic operations. All /// integer and float types with limited bit width are supported. Additionally, /// depending on the operation pointers may be supported as well. @@ -932,6 +943,17 @@ static void printLoadType(OpAsmPrinter &printer, Operation *op, Type type, // StoreOp //===--===// +void StoreOp::getEffects( +SmallVectorImpl> +&effects) { + effects.emplace_back(MemoryEffects::Write::get(), getAddr()); + if (getVolatile_() || (getOrdering() != AtomicOrdering::not_atomic && + getOrdering() != AtomicOrdering::unordered)) { +effects.emplace_back(MemoryEffects::Write::get()); +effects.emplace_back(MemoryEffects::Read::get()); + } +} + LogicalResult StoreOp::verif
[clang] [mlir][LLVM] Model side effects of volatile and atomic load-store (PR #65730)
https://github.com/zero9178 resolved https://github.com/llvm/llvm-project/pull/65730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir][LLVM] Model side effects of volatile and atomic load-store (PR #65730)
https://github.com/zero9178 resolved https://github.com/llvm/llvm-project/pull/65730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir][LLVM] Model side effects of volatile and atomic load-store (PR #65730)
https://github.com/zero9178 closed https://github.com/llvm/llvm-project/pull/65730 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 64276ee - [clang][NFC] Fix typo in comment
Author: Ilyas Mustafazade Date: 2023-03-21T13:32:05+01:00 New Revision: 64276eec7ed07e762ef90c248a36cbafdcd7bd81 URL: https://github.com/llvm/llvm-project/commit/64276eec7ed07e762ef90c248a36cbafdcd7bd81 DIFF: https://github.com/llvm/llvm-project/commit/64276eec7ed07e762ef90c248a36cbafdcd7bd81.diff LOG: [clang][NFC] Fix typo in comment Differential Revision: https://reviews.llvm.org/D146422 Added: Modified: clang/lib/Sema/SemaInit.cpp Removed: diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index ddb2b5cf5cd16..17d8b6c98207b 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -5437,7 +5437,7 @@ static void TryOrBuildParenListInitialization( } // Not all of the args have been processed, so there must've been more args - // then were required to initialize the element. + // than were required to initialize the element. if (ArgIndexToProcess < Args.size()) { Sequence.SetFailed(InitializationSequence::FK_ParenthesizedListInitFailed); if (!VerifyOnly) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] e0b11c7 - [Support][NFC] Fix generic `ChildrenGetterTy` of `IDFCalculatorBase`
Author: Markus Böck Date: 2022-01-30T22:09:07+01:00 New Revision: e0b11c7659f81a382a3c76e26ed792308248f41c URL: https://github.com/llvm/llvm-project/commit/e0b11c7659f81a382a3c76e26ed792308248f41c DIFF: https://github.com/llvm/llvm-project/commit/e0b11c7659f81a382a3c76e26ed792308248f41c.diff LOG: [Support][NFC] Fix generic `ChildrenGetterTy` of `IDFCalculatorBase` Both IDFCalculatorBase and its accompanying DominatorTreeBase only supports pointer nodes. The template argument is the block type itself and any uses of GraphTraits is therefore done via a pointer to the node type. However, the ChildrenGetterTy type of IDFCalculatorBase has a use on just the node type instead of a pointer to the node type. Various parts of the monorepo has worked around this issue by providing specializations of GraphTraits for the node type directly, or not been affected by using specializations instead of the generic case. These are unnecessary however and instead the generic code should be fixed instead. An example from within Tree is eg. A use of IDFCalculatorBase in InstrRefBasedImpl.cpp. It basically instantiates a IDFCalculatorBase but due to the bug above then goes on to specialize GraphTraits although GraphTraits exists (and should be used instead). Similar dead code exists in clang which defines redundant GraphTraits to work around this bug. This patch fixes both the original issue and removes the dead code that was used to work around the issue. Differential Revision: https://reviews.llvm.org/D118386 Added: Modified: clang/include/clang/Analysis/Analyses/Dominators.h clang/include/clang/Analysis/CFG.h llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp Removed: diff --git a/clang/include/clang/Analysis/Analyses/Dominators.h b/clang/include/clang/Analysis/Analyses/Dominators.h index f588a5c7d1d7b..9ac9cbe7d3ec7 100644 --- a/clang/include/clang/Analysis/Analyses/Dominators.h +++ b/clang/include/clang/Analysis/Analyses/Dominators.h @@ -193,7 +193,7 @@ namespace IDFCalculatorDetail { /// Specialize ChildrenGetterTy to skip nullpointer successors. template struct ChildrenGetterTy { - using NodeRef = typename GraphTraits::NodeRef; + using NodeRef = typename GraphTraits::NodeRef; using ChildrenTy = SmallVector; ChildrenTy get(const NodeRef &N) { diff --git a/clang/include/clang/Analysis/CFG.h b/clang/include/clang/Analysis/CFG.h index c5512a7e14998..d8e7e1e43d815 100644 --- a/clang/include/clang/Analysis/CFG.h +++ b/clang/include/clang/Analysis/CFG.h @@ -1494,9 +1494,6 @@ template <> struct GraphTraits< ::clang::CFGBlock *> { static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); } }; -template <> struct GraphTraits -: GraphTraits {}; - template <> struct GraphTraits< const ::clang::CFGBlock *> { using NodeRef = const ::clang::CFGBlock *; using ChildIteratorType = ::clang::CFGBlock::const_succ_iterator; @@ -1506,9 +1503,6 @@ template <> struct GraphTraits< const ::clang::CFGBlock *> { static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); } }; -template <> struct GraphTraits -: GraphTraits {}; - template <> struct GraphTraits> { using NodeRef = ::clang::CFGBlock *; using ChildIteratorType = ::clang::CFGBlock::const_pred_iterator; @@ -1521,9 +1515,6 @@ template <> struct GraphTraits> { static ChildIteratorType child_end(NodeRef N) { return N->pred_end(); } }; -template <> struct GraphTraits> -: GraphTraits {}; - template <> struct GraphTraits> { using NodeRef = const ::clang::CFGBlock *; using ChildIteratorType = ::clang::CFGBlock::const_pred_iterator; @@ -1536,9 +1527,6 @@ template <> struct GraphTraits> { static ChildIteratorType child_end(NodeRef N) { return N->pred_end(); } }; -template <> struct GraphTraits> -: GraphTraits {}; - // Traits for: CFG template <> struct GraphTraits< ::clang::CFG* > diff --git a/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h b/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h index 3bafeb48f64a3..96105d6b4684b 100644 --- a/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h +++ b/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h @@ -37,7 +37,7 @@ namespace IDFCalculatorDetail { /// May be specialized if, for example, one wouldn't like to return nullpointer /// successors. template struct ChildrenGetterTy { - using NodeRef = typename GraphTraits::NodeRef; + using NodeRef = typename GraphTraits::NodeRef; using ChildrenTy = SmallVector; ChildrenTy get(const NodeRef &N); diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp index 8a190e7699414..ee3bc79ed8f75 100644 --- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp +++ b/llvm/lib/CodeGen/Live
[clang] dbeeb13 - [clang][MinGW] Explicitly ignore `-fPIC` & friends
Author: Markus Böck Date: 2022-01-02T12:06:54+01:00 New Revision: dbeeb136abcb03eaa85e2ee47a5169f5298e8944 URL: https://github.com/llvm/llvm-project/commit/dbeeb136abcb03eaa85e2ee47a5169f5298e8944 DIFF: https://github.com/llvm/llvm-project/commit/dbeeb136abcb03eaa85e2ee47a5169f5298e8944.diff LOG: [clang][MinGW] Explicitly ignore `-fPIC` & friends GCC on Windows ignores this flag completely [0] which some build systems sadly rely on when compiling for Windows using MinGW. The current behaviour of clang however is to error out as -fPIC & friends has no effect on Windows. This patch instead changes the behaviour for MinGW to ignore the option for the sake of compatibility Fixes https://github.com/llvm/llvm-project/issues/52947 [0] https://gcc.gnu.org/legacy-ml/gcc-patches/2015-08/msg00836.html Differential Revision: https://reviews.llvm.org/D116485 Added: Modified: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/MinGW.cpp clang/test/Driver/pic.c clang/test/Driver/windows-pic.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index ad50c66cb6c11..f25fe9ba34c46 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1186,10 +1186,9 @@ tools::ParsePICArgs(const ToolChain &ToolChain, const ArgList &Args) { options::OPT_fpic, options::OPT_fno_pic, options::OPT_fPIE, options::OPT_fno_PIE, options::OPT_fpie, options::OPT_fno_pie); - if (Triple.isOSWindows() && LastPICArg && - LastPICArg == - Args.getLastArg(options::OPT_fPIC, options::OPT_fpic, - options::OPT_fPIE, options::OPT_fpie)) { + if (Triple.isOSWindows() && !Triple.isOSCygMing() && LastPICArg && + LastPICArg == Args.getLastArg(options::OPT_fPIC, options::OPT_fpic, +options::OPT_fPIE, options::OPT_fpie)) { ToolChain.getDriver().Diag(diag::err_drv_unsupported_opt_for_target) << LastPICArg->getSpelling() << Triple.str(); if (Triple.getArch() == llvm::Triple::x86_64) diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp index ecce2f062bd79..6d8bfc358dd31 100644 --- a/clang/lib/Driver/ToolChains/MinGW.cpp +++ b/clang/lib/Driver/ToolChains/MinGW.cpp @@ -486,10 +486,7 @@ bool toolchains::MinGW::isPIEDefault(const llvm::opt::ArgList &Args) const { return false; } -bool toolchains::MinGW::isPICDefaultForced() const { - return getArch() == llvm::Triple::x86_64 || - getArch() == llvm::Triple::aarch64; -} +bool toolchains::MinGW::isPICDefaultForced() const { return true; } llvm::ExceptionHandling toolchains::MinGW::GetExceptionModel(const ArgList &Args) const { diff --git a/clang/test/Driver/pic.c b/clang/test/Driver/pic.c index acb0bad022f4c..2124bf1b277b6 100644 --- a/clang/test/Driver/pic.c +++ b/clang/test/Driver/pic.c @@ -301,3 +301,13 @@ // RUN: | FileCheck %s --check-prefix=CHECK-PIC2 // RUN: %clang -c %s -target aarch64-windows-gnu -### 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-PIC2 +// +// On MinGW, allow specifying -fPIC & friends but ignore them +// RUN: %clang -fno-PIC -c %s -target x86_64-pc-windows-gnu -### 2>&1 \ +// RUN: | FileCheck %s --check-prefix=CHECK-PIC2 +// RUN: %clang -fPIC -c %s -target i686-pc-windows-gnu -### 2>&1 \ +// RUN: | FileCheck %s --check-prefix=CHECK-NO-PIC +// RUN: %clang -fno-PIC -c %s -target aarch64-pc-windows-gnu -### 2>&1 \ +// RUN: | FileCheck %s --check-prefix=CHECK-PIC2 +// RUN: %clang -fPIC -c %s -target armv7-pc-windows-gnu -### 2>&1 \ +// RUN: | FileCheck %s --check-prefix=CHECK-NO-PIC diff --git a/clang/test/Driver/windows-pic.cpp b/clang/test/Driver/windows-pic.cpp index 3b77a7cc5a335..00807d663dffb 100644 --- a/clang/test/Driver/windows-pic.cpp +++ b/clang/test/Driver/windows-pic.cpp @@ -16,15 +16,6 @@ // RUN: %clang -### -target i686-windows-itanium -fPIE -fno-pie %s // RUN: %clang -### -target i686-windows-itanium -fpie -fno-pie %s -// RUN: %clang -### -target i686-windows-gnu -fPIC %s 2>&1 | FileCheck -check-prefix CHECK-PIC-ERROR %s -// RUN: %clang -### -target i686-windows-gnu -fpic %s 2>&1 | FileCheck -check-prefix CHECK-pic-ERROR %s -// RUN: %clang -### -target i686-windows-gnu -fPIE %s 2>&1 | FileCheck -check-prefix CHECK-PIE-ERROR %s -// RUN: %clang -### -target i686-windows-gnu -fpie %s 2>&1 | FileCheck -check-prefix CHECK-pie-ERROR %s -// RUN: %clang -### -target i686-windows-gnu -fPIC -fno-pic %s -// RUN: %clang -### -target i686-windows-gnu -Fpic -fno-pic %s -// RUN: %clang -### -target i686-windows-gnu -fPIE -fno-pie %s -// RUN: %clang -### -target i686-windows-gnu -fpie -fno-pie %s - // RUN: %clang -### -target x86_64-windows -fPIC %
[clang] 782791e - [clang][#52782] Bail on incomplete parameter type in stdcall name mangling
Author: Markus Böck Date: 2022-01-05T17:58:24+01:00 New Revision: 782791ee84d29db137f441c1e033582a7a78ad5e URL: https://github.com/llvm/llvm-project/commit/782791ee84d29db137f441c1e033582a7a78ad5e DIFF: https://github.com/llvm/llvm-project/commit/782791ee84d29db137f441c1e033582a7a78ad5e.diff LOG: [clang][#52782] Bail on incomplete parameter type in stdcall name mangling stdcall name mangling requires a suffix with the number equal to the sum of the byte count of all parameter types. In the case of a function prototype that has a parameter type of an incomplete type it is impossible to get the size of the type. While such a function is not callable or able to be defined in the TU, it may still be mangled when generating debug info, which would previously lead to a crash. This patch fixes that by simply bailing out of the loop and using the so far accumulated byte count. This matches GCCs behaviour as well: https://github.com/gcc-mirror/gcc/blob/bc8d6c60137f8bbf173b86ddf31b15d7ba2a33dd/gcc/config/i386/winnt.c#L203 Fixes https://github.com/llvm/llvm-project/issues/52782 Differential Revision: https://reviews.llvm.org/D116020 Added: clang/test/CodeGen/pr52782-stdcall-func-decl.cpp Modified: clang/lib/AST/Mangle.cpp Removed: diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp index 54dbf484f3771..984da9909ce23 100644 --- a/clang/lib/AST/Mangle.cpp +++ b/clang/lib/AST/Mangle.cpp @@ -225,11 +225,17 @@ void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out) { if (const CXXMethodDecl *MD = dyn_cast(FD)) if (!MD->isStatic()) ++ArgWords; - for (const auto &AT : Proto->param_types()) + for (const auto &AT : Proto->param_types()) { +// If an argument type is incomplete there is no way to get its size to +// correctly encode into the mangling scheme. +// Follow GCCs behaviour by simply breaking out of the loop. +if (AT->isIncompleteType()) + break; // Size should be aligned to pointer size. ArgWords += llvm::alignTo(ASTContext.getTypeSize(AT), TI.getPointerWidth(0)) / TI.getPointerWidth(0); + } Out << ((TI.getPointerWidth(0) / 8) * ArgWords); } diff --git a/clang/test/CodeGen/pr52782-stdcall-func-decl.cpp b/clang/test/CodeGen/pr52782-stdcall-func-decl.cpp new file mode 100644 index 0..c3c94ece24b2a --- /dev/null +++ b/clang/test/CodeGen/pr52782-stdcall-func-decl.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple i686-w64-windows-gnu -o - -emit-llvm -debug-info-kind=constructor %s | FileCheck %s + +enum nsresult {}; + +class NotNull; + +class nsICanvasRenderingContextInternal { + // CHECK: !DISubprogram(name: "InitializeWithDrawTarget", linkageName: "\01__ZN33nsICanvasRenderingContextInternal24InitializeWithDrawTargetE7NotNull@4" + nsresult __stdcall InitializeWithDrawTarget(NotNull); +} nsTBaseHashSet; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6479f03 - [clang][#47272] Avoid suggesting deprecated version of a declaration over another in typo correction
Author: Markus Böck Date: 2022-01-11T22:58:10+01:00 New Revision: 6479f03daec1786d1e45f9148bd9298caafba9d2 URL: https://github.com/llvm/llvm-project/commit/6479f03daec1786d1e45f9148bd9298caafba9d2 DIFF: https://github.com/llvm/llvm-project/commit/6479f03daec1786d1e45f9148bd9298caafba9d2.diff LOG: [clang][#47272] Avoid suggesting deprecated version of a declaration over another in typo correction Prior to this patch, clang might suggest a deprecated name of a declaration over another name as the only mechanism for resolving two typo corrections referring to the same underlying declaration has previously been an alphabetical sort. This patch adjusts this resolve by also taking into account whether one of two declarations are deprecated. If the new one is deprecated it may not replace a previous correction with a non-deprecated correction and a previous deprecated correction always gets replaced by a non-deprecated new correction. Fixes https://github.com/llvm/llvm-project/issues/47272 Differential Revision: https://reviews.llvm.org/D116775 Added: Modified: clang/lib/Sema/SemaLookup.cpp clang/test/SemaCXX/typo-correction.cpp Removed: diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 635e93ba84602..c905a10990d21 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -4307,18 +4307,35 @@ void TypoCorrectionConsumer::addCorrection(TypoCorrection Correction) { if (!CList.empty() && !CList.back().isResolved()) CList.pop_back(); if (NamedDecl *NewND = Correction.getCorrectionDecl()) { -std::string CorrectionStr = Correction.getAsString(SemaRef.getLangOpts()); -for (TypoResultList::iterator RI = CList.begin(), RIEnd = CList.end(); - RI != RIEnd; ++RI) { - // If the Correction refers to a decl already in the result list, - // replace the existing result if the string representation of Correction - // comes before the current result alphabetically, then stop as there is - // nothing more to be done to add Correction to the candidate set. - if (RI->getCorrectionDecl() == NewND) { -if (CorrectionStr < RI->getAsString(SemaRef.getLangOpts())) - *RI = Correction; -return; - } +auto RI = llvm::find_if(CList, [NewND](const TypoCorrection &TypoCorr) { + return TypoCorr.getCorrectionDecl() == NewND; +}); +if (RI != CList.end()) { + // The Correction refers to a decl already in the list. No insertion is + // necessary and all further cases will return. + + auto IsDeprecated = [](Decl *D) { +while (D) { + if (D->isDeprecated()) +return true; + D = llvm::dyn_cast_or_null(D->getDeclContext()); +} +return false; + }; + + // Prefer non deprecated Corrections over deprecated and only then + // sort using an alphabetical order. + std::pair NewKey = { + IsDeprecated(Correction.getFoundDecl()), + Correction.getAsString(SemaRef.getLangOpts())}; + + std::pair PrevKey = { + IsDeprecated(RI->getFoundDecl()), + RI->getAsString(SemaRef.getLangOpts())}; + + if (NewKey < PrevKey) +*RI = Correction; + return; } } if (CList.empty() || Correction.isResolved()) diff --git a/clang/test/SemaCXX/typo-correction.cpp b/clang/test/SemaCXX/typo-correction.cpp index 8b13e43661eeb..7eca5d80770da 100644 --- a/clang/test/SemaCXX/typo-correction.cpp +++ b/clang/test/SemaCXX/typo-correction.cpp @@ -757,3 +757,34 @@ namespace PR46487 { b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}} }; } + +namespace PR47272 +{ + +namespace Views { +int Take(); // expected-note{{'Views::Take' declared here}} +} + +namespace [[deprecated("use Views instead")]] View { +using Views::Take; +} + +namespace [[deprecated]] A { // expected-note{{'A' has been explicitly marked deprecated here}} +int pr47272; +} + +namespace B { +using A::pr47272; // expected-note{{'B::pr47272' declared here}} expected-warning{{'A' is deprecated}} +} + +namespace [[deprecated]] C { +using A::pr47272; +} + +void function() { + int x = ::Take(); // expected-error{{no member named 'Take' in the global namespace; did you mean 'Views::Take'?}} + int y = ::pr47272; // expected-error{{no member named 'pr47272' in the global namespace; did you mean 'B::pr47272'?}} +} +} + + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 118f966 - [clang][#51931] Enable `-Wdeclaration-after-statement` for all C versions
Author: Markus Böck Date: 2022-01-12T18:21:46+01:00 New Revision: 118f966b46cfb60897b56a9878e1c68fd0e2afa4 URL: https://github.com/llvm/llvm-project/commit/118f966b46cfb60897b56a9878e1c68fd0e2afa4 DIFF: https://github.com/llvm/llvm-project/commit/118f966b46cfb60897b56a9878e1c68fd0e2afa4.diff LOG: [clang][#51931] Enable `-Wdeclaration-after-statement` for all C versions -Wdeclaration-after-statement currently only outputs an diagnostic if the user is compiling in C versions older than C99, even if the warning was explicitly requested by the user. This patch makes the warning also available in later C versions. If the C version is C99 or later it is simply a normal warning that is disabled by default (as it is valid C99) and has to be enabled by users. In older versions it remains an extension warning, and therefore affected by -pedantic. The above behaviour also matches GCCs behaviour. Fixes https://bugs.llvm.org/show_bug.cgi?id=51931 Differential Revision: https://reviews.llvm.org/D114787 Added: clang/test/Sema/warn-mixed-decls.c Modified: clang/include/clang/Basic/DiagnosticGroups.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaStmt.cpp Removed: diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index c0642efaee4e..1bc879a68a8c 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -241,6 +241,7 @@ def Documentation : DiagGroup<"documentation", def EmptyBody : DiagGroup<"empty-body">; def Exceptions : DiagGroup<"exceptions">; +def DeclarationAfterStatement : DiagGroup<"declaration-after-statement">; def GNUEmptyInitializer : DiagGroup<"gnu-empty-initializer">; def GNUEmptyStruct : DiagGroup<"gnu-empty-struct">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index dfd1069096ea..19ce0ffcec51 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -9861,8 +9861,11 @@ def err_constant_integer_arg_type : Error< "argument to %0 must be a constant integer">; def ext_mixed_decls_code : Extension< - "ISO C90 forbids mixing declarations and code">, - InGroup>; + "mixing declarations and code is a C99 extension">, + InGroup; +def warn_mixed_decls_code : Warning< + "mixing declarations and code is incompatible with standards before C99">, + InGroup, DefaultIgnore; def err_non_local_variable_decl_in_for : Error< "declaration of non-local variable in 'for' loop">; diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 7fe92f492b5e..ef498f9a5228 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -410,9 +410,10 @@ StmtResult Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef Elts, bool isStmtExpr) { const unsigned NumElts = Elts.size(); - // If we're in C89 mode, check that we don't have any decls after stmts. If - // so, emit an extension diagnostic. - if (!getLangOpts().C99 && !getLangOpts().CPlusPlus) { + // If we're in C mode, check that we don't have any decls after stmts. If + // so, emit an extension diagnostic in C89 and potentially a warning in later + // versions. + if (!getLangOpts().CPlusPlus) { // Note that __extension__ can be around a decl. unsigned i = 0; // Skip over all declarations. @@ -425,7 +426,8 @@ StmtResult Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R, if (i != NumElts) { Decl *D = *cast(Elts[i])->decl_begin(); - Diag(D->getLocation(), diag::ext_mixed_decls_code); + Diag(D->getLocation(), !getLangOpts().C99 ? diag::ext_mixed_decls_code +: diag::warn_mixed_decls_code); } } diff --git a/clang/test/Sema/warn-mixed-decls.c b/clang/test/Sema/warn-mixed-decls.c new file mode 100644 index ..219d64472b58 --- /dev/null +++ b/clang/test/Sema/warn-mixed-decls.c @@ -0,0 +1,28 @@ +/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -pedantic %s + */ +/* RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -Wdeclaration-after-statement %s + */ + +/* Should not emit diagnostic when not pedantic, not enabled or in C++ Code*/ +/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c89 %s + */ +/* RUN: %clang_cc1 -fsyntax-only -verify=none -std=c99 %s + */ +/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ %s + */ +/* RUN: %clang_cc1 -fsyntax-only -verify=none -x c++ -Wdeclaration-after-statement %s + */ + +/* none-no-diagnostics */ + +int foo(int i) +{ + i += 1; + int f = i; +#if __STDC_VERSION__ < 199901L + /* expected-warning@-2 {{mixing declarations and code is a C99 extension}}*/ +#else + /* expected-warning@-4 {{mixing declarations and code is incompatib
[clang-tools-extra] b7d5577 - [clang-tidy][#51939] Exempt placement-new expressions from 'bugprone-throw-keyword-missing'
Author: Markus Böck Date: 2021-12-15T16:59:14+01:00 New Revision: b7d55771ce3ecc5c1768bd5877dbdd312f9ab0d7 URL: https://github.com/llvm/llvm-project/commit/b7d55771ce3ecc5c1768bd5877dbdd312f9ab0d7 DIFF: https://github.com/llvm/llvm-project/commit/b7d55771ce3ecc5c1768bd5877dbdd312f9ab0d7.diff LOG: [clang-tidy][#51939] Exempt placement-new expressions from 'bugprone-throw-keyword-missing' The purpose of this checker is to flag a missing throw keyword, and does so by checking for the construction of an exception class that is then unused. This works great except that placement new expressions are also flagged as those lead to the construction of an object as well, even though they are not temporary (as that is dependent on the storage). This patch fixes the issue by exempting the match if it is within a placement-new. Fixes https://github.com/llvm/llvm-project/issues/51939 Differential Revision: https://reviews.llvm.org/D115576 Added: Modified: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp Removed: diff --git a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp index 5327a0c8d4c6b..3f5d875f471dd 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp @@ -24,11 +24,13 @@ void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) { cxxConstructExpr( hasType(cxxRecordDecl( isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION", - unless(anyOf(hasAncestor(stmt( - anyOf(cxxThrowExpr(), callExpr(), returnStmt(, - hasAncestor(decl(anyOf(varDecl(), fieldDecl(, - allOf(hasAncestor(CtorInitializerList), - unless(hasAncestor(cxxCatchStmt())) + unless(anyOf( + hasAncestor( + stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt(, + hasAncestor(decl(anyOf(varDecl(), fieldDecl(, + hasAncestor(expr(cxxNewExpr(hasAnyPlacementArg(anything(), + allOf(hasAncestor(CtorInitializerList), +unless(hasAncestor(cxxCatchStmt())) .bind("temporary-exception-not-thrown"), this); } diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 341eb82a1e903..bcb9a0f40719c 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -148,6 +148,10 @@ Changes in existing checks - Fixed a false positive in :doc:`fuchsia-trailing-return ` for C++17 deduction guides. + +- Fixed a false positive in :doc:`bugprone-throw-keyword-missing + ` when creating an exception object + using placement new Removed checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp index dff600c947070..49233c0deefdf 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp @@ -175,3 +175,14 @@ struct ExceptionRAII { void exceptionRAIITest() { ExceptionRAII E; } + +namespace std { +typedef decltype(sizeof(void*)) size_t; +} + +void* operator new(std::size_t, void*); + +void placeMentNewTest() { + alignas(RegularException) unsigned char expr[sizeof(RegularException)]; + new (expr) RegularException{}; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] aafc3f7 - [Driver] Add -print-runtime-dir
Author: Markus Böck Date: 2021-03-19T17:48:03+01:00 New Revision: aafc3f7be804d117a632365489a18c3e484a3931 URL: https://github.com/llvm/llvm-project/commit/aafc3f7be804d117a632365489a18c3e484a3931 DIFF: https://github.com/llvm/llvm-project/commit/aafc3f7be804d117a632365489a18c3e484a3931.diff LOG: [Driver] Add -print-runtime-dir This patch adds a new command line option to clang which outputs the directory containing clangs runtime libraries to stdout. The primary use case for this command line flag is for build systems using clang-cl. Build systems when using clang-cl invoke the linker, that is either link or lld-link in this case, directly instead of invoking the compiler for the linking process as is common with the other drivers. This leads to issues when runtime libraries of clang, such as sanitizers or profiling, have to be linked in as the compiler cannot communicate the link directory to the linker. Using this flag, build systems would be capable of getting the directory containing all of clang's runtime libraries and add it to the linker path. Differential Revision: https://reviews.llvm.org/D98868 Added: clang/test/Driver/Inputs/resource_dir/lib/windows/clang_rt.builtins-x86_64.lib clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-pc-windows-msvc/clang_rt.builtins.lib Modified: clang/include/clang/Driver/Options.td clang/lib/Driver/Driver.cpp clang/test/Driver/immediate-options.c Removed: diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index a9b43a8fe620..b7efb7469a23 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3566,6 +3566,8 @@ def print_targets : Flag<["-", "--"], "print-targets">, HelpText<"Print the registered targets">; def print_rocm_search_dirs : Flag<["-", "--"], "print-rocm-search-dirs">, HelpText<"Print the paths used for finding ROCm installation">; +def print_runtime_dir : Flag<["-", "--"], "print-runtime-dir">, + HelpText<"Print the directory pathname containing clangs runtime libraries">; def private__bundle : Flag<["-"], "private_bundle">; def pthreads : Flag<["-"], "pthreads">; defm pthread : BoolOption<"", "pthread", diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index dbd365e7c9bc..e70263e6a295 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1824,6 +1824,15 @@ bool Driver::HandleImmediateArgs(const Compilation &C) { return false; } + if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) { +if (auto RuntimePath = TC.getRuntimePath()) { + llvm::outs() << *RuntimePath << '\n'; + return false; +} +llvm::outs() << TC.getCompilerRTPath() << '\n'; +return false; + } + // FIXME: The following handlers should use a callback mechanism, we don't // know what the client would like to do. if (Arg *A = C.getArgs().getLastArg(options::OPT_print_file_name_EQ)) { diff --git a/clang/test/Driver/Inputs/resource_dir/lib/windows/clang_rt.builtins-x86_64.lib b/clang/test/Driver/Inputs/resource_dir/lib/windows/clang_rt.builtins-x86_64.lib new file mode 100644 index ..e69de29bb2d1 diff --git a/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-pc-windows-msvc/clang_rt.builtins.lib b/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-pc-windows-msvc/clang_rt.builtins.lib new file mode 100644 index ..e69de29bb2d1 diff --git a/clang/test/Driver/immediate-options.c b/clang/test/Driver/immediate-options.c index 723a6fa302f8..c398e0d41c6e 100644 --- a/clang/test/Driver/immediate-options.c +++ b/clang/test/Driver/immediate-options.c @@ -17,3 +17,15 @@ // Allow unspecified output because the value of CLANG_RESOURCE_DIR is unknown. // RUN: %clang -print-resource-dir | FileCheck %s -check-prefix=PRINT-RESOURCE-DIR // PRINT-RESOURCE-DIR: {{.+}} + +// Default resource-dir layout +// RUN: %clang -print-runtime-dir --target=x86_64-pc-windows-msvc \ +// RUN:-resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s +// PRINT-RUNTIME-DIR: lib{{/|\\}}windows + +// Per target dir layout +// RUN: %clang -print-runtime-dir --target=x86_64-pc-windows-msvc \ +// RUN:-resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: | FileCheck --check-prefix=PRINT-RUNTIME-DIR-PER-TARGET %s +// PRINT-RUNTIME-DIR-PER-TARGET: lib{{/|\\}}x86_64-pc-windows-msvc ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits