[clang] [clang][AST] Fix spaces in TypePrinter for some calling convs (PR #143160)
https://github.com/mizvekov approved this pull request. Thanks, LGTM! You might want to consider adding a change to the ReleaseNotes before merging this. https://github.com/llvm/llvm-project/pull/143160 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][AST] Fix spaces in TypePrinter for some calling convs (PR #143160)
@@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -triple aarch64 -ast-dump -ast-dump-filter foo %s \ +// RUN: | FileCheck --strict-whitespace %s + +// CHECK: {{foo1 'void \(\) __attribute__\(\(device_kernel\)\)'$}} mizvekov wrote: ```suggestion // CHECK: foo1 'void () __attribute__((device_kernel))'{{$}} ``` You don't need to apply the regex to the whole match, this makes it a little bit easier to read. https://github.com/llvm/llvm-project/pull/143160 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] add a JSON generator (PR #142483)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/142483 >From fa8b80f9bfe2b7faf765ed4cf60fb8cec30e1d48 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Mon, 2 Jun 2025 12:53:36 -0700 Subject: [PATCH 1/4] [clang-doc] add a JSON generator --- clang-tools-extra/clang-doc/CMakeLists.txt| 1 + clang-tools-extra/clang-doc/Generators.cpp| 2 + clang-tools-extra/clang-doc/Generators.h | 1 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 316 ++ .../clang-doc/tool/ClangDocMain.cpp | 8 +- .../test/clang-doc/json/class.cpp | 183 ++ 6 files changed, 509 insertions(+), 2 deletions(-) create mode 100644 clang-tools-extra/clang-doc/JSONGenerator.cpp create mode 100644 clang-tools-extra/test/clang-doc/json/class.cpp diff --git a/clang-tools-extra/clang-doc/CMakeLists.txt b/clang-tools-extra/clang-doc/CMakeLists.txt index 79563c41435eb..5989e5fe60cf3 100644 --- a/clang-tools-extra/clang-doc/CMakeLists.txt +++ b/clang-tools-extra/clang-doc/CMakeLists.txt @@ -17,6 +17,7 @@ add_clang_library(clangDoc STATIC Serialize.cpp YAMLGenerator.cpp HTMLMustacheGenerator.cpp + JSONGenerator.cpp DEPENDS omp_gen diff --git a/clang-tools-extra/clang-doc/Generators.cpp b/clang-tools-extra/clang-doc/Generators.cpp index a3c2773412cff..3fb5b63c403a7 100644 --- a/clang-tools-extra/clang-doc/Generators.cpp +++ b/clang-tools-extra/clang-doc/Generators.cpp @@ -105,5 +105,7 @@ static int LLVM_ATTRIBUTE_UNUSED HTMLGeneratorAnchorDest = HTMLGeneratorAnchorSource; static int LLVM_ATTRIBUTE_UNUSED MHTMLGeneratorAnchorDest = MHTMLGeneratorAnchorSource; +static int LLVM_ATTRIBUTE_UNUSED JSONGeneratorAnchorDest = +JSONGeneratorAnchorSource; } // namespace doc } // namespace clang diff --git a/clang-tools-extra/clang-doc/Generators.h b/clang-tools-extra/clang-doc/Generators.h index aee04b9d58d9d..92d3006e6002d 100644 --- a/clang-tools-extra/clang-doc/Generators.h +++ b/clang-tools-extra/clang-doc/Generators.h @@ -58,6 +58,7 @@ extern volatile int YAMLGeneratorAnchorSource; extern volatile int MDGeneratorAnchorSource; extern volatile int HTMLGeneratorAnchorSource; extern volatile int MHTMLGeneratorAnchorSource; +extern volatile int JSONGeneratorAnchorSource; } // namespace doc } // namespace clang diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp new file mode 100644 index 0..499ca4dd05e6e --- /dev/null +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -0,0 +1,316 @@ +#include "Generators.h" +#include "llvm/Support/JSON.h" + +using namespace llvm; +using namespace llvm::json; + +static llvm::ExitOnError ExitOnErr; + +namespace clang { +namespace doc { + +class JSONGenerator : public Generator { +public: + static const char *Format; + + Error generateDocs(StringRef RootDir, + llvm::StringMap> Infos, + const ClangDocContext &CDCtx) override; + Error createResources(ClangDocContext &CDCtx) override; + Error generateDocForInfo(Info *I, llvm::raw_ostream &OS, + const ClangDocContext &CDCtx) override; +}; + +const char *JSONGenerator::Format = "json"; + +static json::Object serializeLocation(const Location &Loc, + std::optional RepositoryUrl) { + Object LocationObj = Object(); + LocationObj["LineNumber"] = Loc.StartLineNumber; + LocationObj["Filename"] = Loc.Filename; + + if (!Loc.IsFileInRootDir || !RepositoryUrl) +return LocationObj; + SmallString<128> FileURL(*RepositoryUrl); + sys::path::append(FileURL, sys::path::Style::posix, Loc.Filename); + FileURL += "#" + std::to_string(Loc.StartLineNumber); + LocationObj["FileURL"] = FileURL; + return LocationObj; +} + +static json::Value serializeComment(const CommentInfo &Comment) { + assert((Comment.Kind == "BlockCommandComment" || + Comment.Kind == "FullComment" || Comment.Kind == "ParagraphComment" || + Comment.Kind == "TextComment") && + "Unknown Comment type in CommentInfo."); + + Object Obj = Object(); + json::Value Child = Object(); + + // TextComment has no children, so return it. + if (Comment.Kind == "TextComment") { +Obj["TextComment"] = Comment.Text; +return Obj; + } + + // BlockCommandComment needs to generate a Command key. + if (Comment.Kind == "BlockCommandComment") +Child.getAsObject()->insert({"Command", Comment.Name}); + + // Use the same handling for everything else. + // Only valid for: + // - BlockCommandComment + // - FullComment + // - ParagraphComment + json::Value ChildArr = Array(); + auto &CARef = *ChildArr.getAsArray(); + CARef.reserve(Comment.Children.size()); + for (const auto &C : Comment.Children) +CARef.emplace_back(serializeComment(*C)); + Child.getAsObject()->insert({"Children", ChildArr}); + Obj.insert({Comment.Kind, Child}); + return Obj; +} + +static void serializeCommonA
[clang] b84127b - [OpenACC][CIR] Lowering for 'deviceptr' for compute/combined constructs
Author: erichkeane Date: 2025-06-06T11:26:35-07:00 New Revision: b84127bb131cee3ed2400abede345d473bb6130b URL: https://github.com/llvm/llvm-project/commit/b84127bb131cee3ed2400abede345d473bb6130b DIFF: https://github.com/llvm/llvm-project/commit/b84127bb131cee3ed2400abede345d473bb6130b.diff LOG: [OpenACC][CIR] Lowering for 'deviceptr' for compute/combined constructs This ends up being a simple clause that only adds 'acc.deviceptr' to the dataOperands list on the compute construct operation. Added: Modified: clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp clang/test/CIR/CodeGenOpenACC/combined.cpp clang/test/CIR/CodeGenOpenACC/kernels.c clang/test/CIR/CodeGenOpenACC/parallel.c clang/test/CIR/CodeGenOpenACC/serial.c Removed: diff --git a/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp b/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp index e3657e9014121..9f283974d8c8f 100644 --- a/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp @@ -829,6 +829,22 @@ class OpenACCClauseCIREmitter final llvm_unreachable("Unknown construct kind in VisitUseDeviceClause"); } } + + void VisitDevicePtrClause(const OpenACCDevicePtrClause &clause) { +if constexpr (isOneOfTypes) { + for (auto var : clause.getVarList()) +addDataOperand( +var, mlir::acc::DataClause::acc_deviceptr, /*structured=*/true, +/*implicit=*/false); +} else if constexpr (isCombinedType) { + applyToComputeOp(clause); +} else { + // TODO: When we've implemented this for everything, switch this to an + // unreachable. data, declare remain. + return clauseNotImplemented(clause); +} + } }; template diff --git a/clang/test/CIR/CodeGenOpenACC/combined.cpp b/clang/test/CIR/CodeGenOpenACC/combined.cpp index 6124f38967285..fec6ec688a44d 100644 --- a/clang/test/CIR/CodeGenOpenACC/combined.cpp +++ b/clang/test/CIR/CodeGenOpenACC/combined.cpp @@ -1011,3 +1011,41 @@ extern "C" void acc_combined(int N, int cond) { // CHECK-NEXT: acc.terminator // CHECK-NEXT: } loc } +extern "C" void acc_combined_deviceptr(int *arg1, int *arg2) { + // CHECK: cir.func @acc_combined_deviceptr(%[[ARG1_PARAM:.*]]: !cir.ptr{{.*}}, %[[ARG2_PARAM:.*]]: !cir.ptr{{.*}}) { + // CHECK-NEXT: %[[ARG1:.*]] = cir.alloca !cir.ptr, !cir.ptr>, ["arg1", init] + // CHECK-NEXT: %[[ARG2:.*]] = cir.alloca !cir.ptr, !cir.ptr>, ["arg2", init] + // CHECK-NEXT: cir.store %[[ARG1_PARAM]], %[[ARG1]] : !cir.ptr, !cir.ptr> + // CHECK-NEXT: cir.store %[[ARG2_PARAM]], %[[ARG2]] : !cir.ptr, !cir.ptr> + +#pragma acc parallel loop deviceptr(arg1) + for(unsigned I = 0; I < 5; ++I); + // CHECK-NEXT: %[[DEVPTR1:.*]] = acc.deviceptr varPtr(%[[ARG1]] : !cir.ptr>) -> !cir.ptr> {name = "arg1"} + // CHECK-NEXT: acc.parallel combined(loop) dataOperands(%[[DEVPTR1]] : !cir.ptr>) { + // CHECK-NEXT: acc.loop combined(parallel) { + // CHECK: acc.yield + // CHECK-NEXT: } loc + // CHECK-NEXT: acc.yield + // CHECK-NEXT: } loc + +#pragma acc serial loop deviceptr(arg2) + for(unsigned I = 0; I < 5; ++I); + // CHECK-NEXT: %[[DEVPTR2:.*]] = acc.deviceptr varPtr(%[[ARG2]] : !cir.ptr>) -> !cir.ptr> {name = "arg2"} + // CHECK-NEXT: acc.serial combined(loop) dataOperands(%[[DEVPTR2]] : !cir.ptr>) { + // CHECK-NEXT: acc.loop combined(serial) { + // CHECK: acc.yield + // CHECK-NEXT: } loc + // CHECK-NEXT: acc.yield + // CHECK-NEXT: } loc + +#pragma acc kernels loop deviceptr(arg1, arg2) + for(unsigned I = 0; I < 5; ++I); + // CHECK-NEXT: %[[DEVPTR1:.*]] = acc.deviceptr varPtr(%[[ARG1]] : !cir.ptr>) -> !cir.ptr> {name = "arg1"} + // CHECK-NEXT: %[[DEVPTR2:.*]] = acc.deviceptr varPtr(%[[ARG2]] : !cir.ptr>) -> !cir.ptr> {name = "arg2"} + // CHECK-NEXT: acc.kernels combined(loop) dataOperands(%[[DEVPTR1]], %[[DEVPTR2]] : !cir.ptr>, !cir.ptr>) { + // CHECK-NEXT: acc.loop combined(kernels) { + // CHECK: acc.yield + // CHECK-NEXT: } loc + // CHECK-NEXT: acc.terminator + // CHECK-NEXT: } loc +} diff --git a/clang/test/CIR/CodeGenOpenACC/kernels.c b/clang/test/CIR/CodeGenOpenACC/kernels.c index 333669c8de7de..e940b84fb7461 100644 --- a/clang/test/CIR/CodeGenOpenACC/kernels.c +++ b/clang/test/CIR/CodeGenOpenACC/kernels.c @@ -416,3 +416,25 @@ void acc_kernels(int cond) { // CHECK-NEXT: cir.return } + +void acc_kernels_deviceptr(int *arg1, int *arg2) { + // CHECK: cir.func @acc_kernels_deviceptr(%[[ARG1_PARAM:.*]]: !cir.ptr{{.*}}, %[[ARG2_PARAM:.*]]: !cir.ptr{{.*}}) { + // CHECK-NEXT: %[[ARG1:.*]] = cir.alloca !cir.ptr, !cir.ptr>, ["arg1", init] + // CHECK-NEXT: %[[ARG2:.*]] = cir.alloca !cir.ptr, !cir.ptr>, ["arg2", init] + // CHECK-NEXT: cir.store %[[ARG1_PARAM]], %[[ARG1]] : !cir.ptr, !cir.ptr> + // CHECK-NEXT: cir.store %[[ARG2_PARAM]], %[[ARG2]] : !cir.ptr, !cir.ptr> + +#pragma acc kernels deviceptr(arg1) + ; + // CHECK-NEXT: %[[DE
[clang-tools-extra] [clang-tidy] Add performance-bool-bitwise-operation check (PR #142324)
vbvictor wrote: > Actually, another reason for not putting this in performance is that the > changes made by this check may lead to non-functional changes in the code. Off-by-default option `StrictMode` may exclude fix-its that involve function with side-effects, etc.. AFAIK, if the check does more than one thing (readability, performance) we should place it under `misc` category, so I weakly in favor of `misc` because it may benefit users in different ways. We shall wait for another opinion. https://github.com/llvm/llvm-project/pull/142324 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] Refactor AutoConvert.h to remove large MVS guard (PR #143174)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/143174 >From 4f8acb6898ca282321d688b960ca02f8e80bad26 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 6 Jun 2025 12:16:52 -0400 Subject: [PATCH] refactor AutoConvert.h to remove MVS guard --- clang/tools/c-index-test/c-index-test.c | 4 +-- llvm/include/llvm/Support/AutoConvert.h | 5 ++-- llvm/lib/Support/AutoConvert.cpp| 33 +++-- llvm/lib/Support/InitLLVM.cpp | 6 ++--- llvm/lib/Support/MemoryBuffer.cpp | 8 ++ llvm/lib/Support/raw_ostream.cpp| 10 +--- llvm/utils/count/count.c| 6 +++-- 7 files changed, 46 insertions(+), 26 deletions(-) diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 4a887cd0c1e2e..3922aa9c31386 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -5199,13 +5199,13 @@ static void flush_atexit(void) { int main(int argc, const char **argv) { thread_info client_data; -#ifdef __MVS__ + // On z/OS we need to enable auto conversion if (enablezOSAutoConversion(fileno(stdout)) == -1) fprintf(stderr, "Setting conversion on stdout failed\n"); + // On z/OS we need to enable auto conversion if (enablezOSAutoConversion(fileno(stderr)) == -1) fprintf(stderr, "Setting conversion on stderr failed\n"); -#endif atexit(flush_atexit); diff --git a/llvm/include/llvm/Support/AutoConvert.h b/llvm/include/llvm/Support/AutoConvert.h index 352493e9be25f..9501ae54927c0 100644 --- a/llvm/include/llvm/Support/AutoConvert.h +++ b/llvm/include/llvm/Support/AutoConvert.h @@ -16,6 +16,7 @@ #ifdef __MVS__ #include <_Ccsid.h> +#endif #ifdef __cplusplus #include "llvm/Support/ErrorOr.h" #include @@ -55,8 +56,10 @@ std::error_code restorezOSStdHandleAutoConversion(int FD); /** \brief Set the tag information for a file descriptor. */ std::error_code setzOSFileTag(int FD, int CCSID, bool Text); +#ifdef __MVS__ /** \brief Get the the tag ccsid for a file name or a file descriptor. */ ErrorOr<__ccsid_t> getzOSFileTag(const char *FileName, const int FD = -1); +#endif /** \brief Query the file tag to determine if it needs conversion to UTF-8 * codepage. @@ -66,6 +69,4 @@ ErrorOr needzOSConversion(const char *FileName, const int FD = -1); } /* namespace llvm */ #endif /* __cplusplus */ -#endif /* __MVS__ */ - #endif /* LLVM_SUPPORT_AUTOCONVERT_H */ diff --git a/llvm/lib/Support/AutoConvert.cpp b/llvm/lib/Support/AutoConvert.cpp index f7918548df1d0..296c0018ff41a 100644 --- a/llvm/lib/Support/AutoConvert.cpp +++ b/llvm/lib/Support/AutoConvert.cpp @@ -11,8 +11,6 @@ // //===--===// -#ifdef __MVS__ - #include "llvm/Support/AutoConvert.h" #include "llvm/Support/Error.h" #include @@ -25,6 +23,9 @@ using namespace llvm; static int savedStdHandleAutoConversionMode[3] = {-1, -1, -1}; int disablezOSAutoConversion(int FD) { +#ifndef __MVS__ + return 0; +#else static const struct f_cnvrt Convert = { SETCVTOFF, // cvtcmd 0, // pccsid @@ -32,9 +33,13 @@ int disablezOSAutoConversion(int FD) { }; return fcntl(FD, F_CONTROL_CVT, &Convert); +#endif } int restorezOSStdHandleAutoConversion(int FD) { +#ifndef __MVS__ + return 0; +#else assert(FD == STDIN_FILENO || FD == STDOUT_FILENO || FD == STDERR_FILENO); if (savedStdHandleAutoConversionMode[FD] == -1) return 0; @@ -44,9 +49,13 @@ int restorezOSStdHandleAutoConversion(int FD) { 0,// fccsid }; return (fcntl(FD, F_CONTROL_CVT, &Cvt)); +#endif } int enablezOSAutoConversion(int FD) { +#ifndef __MVS__ + return 0; +#else struct f_cnvrt Query = { QUERYCVT, // cvtcmd 0,// pccsid @@ -81,30 +90,35 @@ int enablezOSAutoConversion(int FD) { // Assume untagged files to be IBM-1047 encoded. Query.fccsid = (Query.fccsid == FT_UNTAGGED) ? CCSID_IBM_1047 : Query.fccsid; return fcntl(FD, F_CONTROL_CVT, &Query); +#endif } std::error_code llvm::disablezOSAutoConversion(int FD) { +#ifdef __MVS__ if (::disablezOSAutoConversion(FD) == -1) return errnoAsErrorCode(); - +#endif return std::error_code(); } std::error_code llvm::enablezOSAutoConversion(int FD) { +#ifdef __MVS__ if (::enablezOSAutoConversion(FD) == -1) return errnoAsErrorCode(); - +#endif return std::error_code(); } std::error_code llvm::restorezOSStdHandleAutoConversion(int FD) { +#ifdef __MVS__ if (::restorezOSStdHandleAutoConversion(FD) == -1) return errnoAsErrorCode(); - +#endif return std::error_code(); } std::error_code llvm::setzOSFileTag(int FD, int CCSID, bool Text) { +#ifdef __MVS__ assert((!Text || (CCSID != FT_UNTAGGED && CCSID != FT_BINARY)) && "FT_UNTAGGED and FT_BINARY are not allowed for text files"); struct file_tag Tag;
[clang] [clang][AST] Fix spaces in TypePrinter for some calling convs (PR #143160)
https://github.com/mizvekov edited https://github.com/llvm/llvm-project/pull/143160 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add performance-bool-bitwise-operation check (PR #142324)
carlosgalvezp wrote: > takes less time than evaluating both operands. Actually, another reason for *not* putting this in `performance` is that the changes made by this check may lead to non-functional changes in the code. If the RHS operand is a function that has side effects, this check will change the logic of the code, since the RHS may not be called due to short-circuiting, and maybe the caller actually intended to do so. Performance checks are expected to only provide performance gains, without changes to the functionality/logic of the code. > I think no place for this check in readability section Readability is not so much about "making the code shorter", it's also about making the code explicit, without surprises. One example of that slightly related to this particular case is `readability-implicit-bool-conversion`. But like I said, I don't have a strong opinion about `readability`, it could be `bugprone` or `misc` too. https://github.com/llvm/llvm-project/pull/142324 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] [NFC] Potential dereference of nullptr. (PR #143145)
https://github.com/carlosgalvezp approved this pull request. I think this is the correct thing to do. It's a programming error if these pointers are null, and so assertions are the correct tool for this. Other checks do `if (const auto* Found = ...)`, but that's not correct, since it silences programming errors. https://github.com/llvm/llvm-project/pull/143145 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Move `Sema` work out of `Parser::ParseMicrosoftRootSignatureAttributeArgs` (PR #143184)
https://github.com/inbelic created https://github.com/llvm/llvm-project/pull/143184 This separates semantic analysis from parsing by moving `RootSignatureDecl` creation, scope storage, and lookup logic into `Sema`. For more context see: https://github.com/llvm/llvm-project/issues/142834. - Define `ActOnStartRootSignatureDecl` and `ActOnFinishRootSignatureDecl` on `SemaDecl` - NFC so no test changes. Resolves: https://github.com/llvm/llvm-project/issues/142834 >From f8b165eecd613a4e9dc1576f5087e37ec74034e5 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Fri, 6 Jun 2025 17:37:12 + Subject: [PATCH 1/3] define ActOnStartRootSignatureDecl --- clang/include/clang/Sema/Sema.h | 3 +++ clang/lib/Parse/ParseDeclCXX.cpp | 17 ++--- clang/lib/Sema/SemaDecl.cpp | 13 + 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index f9a086b6966d9..240cde87703b8 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -3619,6 +3619,9 @@ class Sema final : public SemaBase { SourceLocation NameLoc, bool IsTemplateTypeArg); + std::pair + ActOnStartRootSignatureDecl(StringRef Signature); + class NameClassification { NameClassificationKind Kind; union { diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 2cf33a856c4f4..1775d14456316 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -4942,18 +4942,13 @@ void Parser::ParseMicrosoftRootSignatureAttributeArgs(ParsedAttributes &Attrs) { // Construct our identifier StringRef Signature = StrLiteral.value()->getString(); - auto Hash = llvm::hash_value(Signature); - std::string IdStr = "__hlsl_rootsig_decl_" + std::to_string(Hash); - IdentifierInfo *DeclIdent = &(Actions.getASTContext().Idents.get(IdStr)); - - LookupResult R(Actions, DeclIdent, SourceLocation(), - Sema::LookupOrdinaryName); - // Check if we have already found a decl of the same name, if we haven't - // then parse the root signature string and construct the in-memory elements - if (!Actions.LookupQualifiedName(R, Actions.CurContext)) { + auto [DeclIdent, Found] = Actions.ActOnStartRootSignatureDecl(Signature); + // If we haven't found an already defined DeclIdent then parse the root + // signature string and construct the in-memory elements + if (!Found) { +// Offset location 1 to account for '"' SourceLocation SignatureLoc = -StrLiteral.value()->getExprLoc().getLocWithOffset( -1); // offset 1 for '"' +StrLiteral.value()->getExprLoc().getLocWithOffset(1); // Invoke the root signature parser to construct the in-memory constructs hlsl::RootSignatureLexer Lexer(Signature, SignatureLoc); SmallVector RootElements; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 60e911b9fecc0..ba2329765182c 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -653,6 +653,19 @@ ParsedType Sema::ActOnMSVCUnknownTypeName(const IdentifierInfo &II, return CreateParsedType(T, Builder.getTypeSourceInfo(Context, T)); } +std::pair +Sema::ActOnStartRootSignatureDecl(StringRef Signature) { + auto Hash = llvm::hash_value(Signature); + std::string IdStr = "__hlsl_rootsig_decl_" + std::to_string(Hash); + IdentifierInfo *DeclIdent = &(getASTContext().Idents.get(IdStr)); + + // Check if we have already found a decl of the same name + LookupResult R(Actions, DeclIdent, SourceLocation(), + Sema::LookupOrdinaryName); + bool Found = LookupQualifiedName(R, Actions.CurContext); + return {DeclIdent, Found}; +} + DeclSpec::TST Sema::isTagName(IdentifierInfo &II, Scope *S) { // Do a tag name lookup in this scope. LookupResult R(*this, &II, SourceLocation(), LookupTagName); >From bc9bb267fc738c5ab537797d98507254eb0841b4 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Fri, 6 Jun 2025 17:57:12 + Subject: [PATCH 2/3] define ActOnFinishRootSignatureDecl --- clang/include/clang/Sema/Sema.h | 3 +++ clang/lib/Parse/ParseDeclCXX.cpp | 8 ++-- clang/lib/Sema/SemaDecl.cpp | 17 ++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 240cde87703b8..f27d769a576ea 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -3621,6 +3621,9 @@ class Sema final : public SemaBase { std::pair ActOnStartRootSignatureDecl(StringRef Signature); + void ActOnFinishRootSignatureDecl( + SourceLocation Loc, IdentifierInfo *DeclIdent, + SmallVector &Elements); class NameClassification { NameClassificationKind Kind; diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 1775d14456316..c84b0c8dfd480 10
[clang-tools-extra] [clang-tidy] Add performance-bool-bitwise-operation check (PR #142324)
denzor200 wrote: > Actually, another reason for not putting this in performance is that the > changes made by this check may lead to non-functional changes in the code. If > the RHS operand is a function that has side effects, this check will change > the logic of the code, since the RHS may not be called due to > short-circuiting, and maybe the caller actually intended to do so. Do you mean automatic changes made by this check? Don't worry about that, already under control. The check can recognize side effects. https://github.com/llvm/llvm-project/pull/142324 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add performance-bool-bitwise-operation check (PR #142324)
carlosgalvezp wrote: > The check can recognize side effects. Ok, that's great! Did you have a chance to run the test on a large codebase (e.g. the llvm-project) and see if we get any FPs in this regard? > if the check does more than one thing (readability, performance) we should > place it under misc category That's a good point, I agree. Is there be a strong reason _not_ to put it in `misc`? https://github.com/llvm/llvm-project/pull/142324 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Filter out configuration file from compile commands (PR #131099)
https://github.com/aaupov approved this pull request. https://github.com/llvm/llvm-project/pull/131099 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add performance-bool-bitwise-operation check (PR #142324)
denzor200 wrote: > Ok, that's great! Did you have a chance to run the test on a large codebase > (e.g. the llvm-project) and see if we get any FPs in this regard? Going to do it https://github.com/llvm/llvm-project/pull/142324 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
@@ -3167,3 +3167,29 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args, options::OPT_fno_loop_interchange, EnableInterchange)) CmdArgs.push_back("-floop-interchange"); } + +std::optional tools::ParseMPreferVectorWidthOption( +clang::DiagnosticsEngine &Diags, const llvm::opt::ArgList &Args, +ArgStringList &CmdArgs, bool isCompilerDriver) { + // If this was invoked by the Compiler Driver, we pass through the option + // as-is. Otherwise, if this is the Frontend Driver, we want just the value. + StringRef Out = (isCompilerDriver) ? "-mprefer-vector-width=" : ""; + + Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ); + if (!A) +return std::nullopt; + + StringRef Value = A->getValue(); + unsigned Width; shafik wrote: Agreed https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Use ExtVector for firstbit intrinsics (PR #142679)
https://github.com/s-perron approved this pull request. https://github.com/llvm/llvm-project/pull/142679 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64TargetParser]Fix reconstructFromParsedFeatures ignoring negative features (PR #142236)
@@ -1831,6 +1831,22 @@ TEST_P(AArch64ExtensionDependenciesBaseCPUTestFixture, } } +TEST(TargetParserTest, testAArch64ReconstructFromParsedFeatures) { + AArch64::ExtensionSet Extensions; + std::vector FeatureOptions = { + "-sve2", "-Baz", "+sve", "+FooBar", "+sve2", "+neon", "-sve", + }; + std::vector NonExtensions; + Extensions.reconstructFromParsedFeatures(FeatureOptions, NonExtensions); + + std::vector NonExtensionsExpected = {"-Baz", "+FooBar"}; + ASSERT_THAT(NonExtensions, testing::ContainerEq(NonExtensionsExpected)); + std::vector Features; + Extensions.toLLVMFeatureList(Features); + std::vector FeaturesExpected = {"+neon", "-sve", "+sve2"}; labrinea wrote: Reading the comment https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/TargetParser/AArch64TargetParser.h#L208 reminded me that it is intentional to not expand dependencies at this stage. https://github.com/llvm/llvm-project/pull/142236 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 39bb267 - [OpenACC][CIR][NFC] Add device_ptr async clause tests
Author: erichkeane Date: 2025-06-06T11:58:58-07:00 New Revision: 39bb267445ffee980c313285f09814ab12e3a847 URL: https://github.com/llvm/llvm-project/commit/39bb267445ffee980c313285f09814ab12e3a847 DIFF: https://github.com/llvm/llvm-project/commit/39bb267445ffee980c313285f09814ab12e3a847.diff LOG: [OpenACC][CIR][NFC] Add device_ptr async clause tests Add a test to ensure that device_ptr properly respects the 'async' functionality we added for copy/etc. Added: Modified: clang/test/CIR/CodeGenOpenACC/combined.cpp clang/test/CIR/CodeGenOpenACC/kernels.c clang/test/CIR/CodeGenOpenACC/parallel.c clang/test/CIR/CodeGenOpenACC/serial.c Removed: diff --git a/clang/test/CIR/CodeGenOpenACC/combined.cpp b/clang/test/CIR/CodeGenOpenACC/combined.cpp index fec6ec688a44d..5107ee56c568c 100644 --- a/clang/test/CIR/CodeGenOpenACC/combined.cpp +++ b/clang/test/CIR/CodeGenOpenACC/combined.cpp @@ -1048,4 +1048,35 @@ extern "C" void acc_combined_deviceptr(int *arg1, int *arg2) { // CHECK-NEXT: } loc // CHECK-NEXT: acc.terminator // CHECK-NEXT: } loc + +#pragma acc parallel loop deviceptr(arg1) async + for(unsigned I = 0; I < 5; ++I); + // CHECK-NEXT: %[[DEVPTR1:.*]] = acc.deviceptr varPtr(%[[ARG1]] : !cir.ptr>) async -> !cir.ptr> {name = "arg1"} + // CHECK-NEXT: acc.parallel combined(loop) dataOperands(%[[DEVPTR1]] : !cir.ptr>) async { + // CHECK-NEXT: acc.loop combined(parallel) { + // CHECK: acc.yield + // CHECK-NEXT: } loc + // CHECK-NEXT: acc.yield + // CHECK-NEXT: } loc + +#pragma acc serial loop deviceptr(arg2) async device_type(nvidia) + for(unsigned I = 0; I < 5; ++I); + // CHECK-NEXT: %[[DEVPTR2:.*]] = acc.deviceptr varPtr(%[[ARG2]] : !cir.ptr>) async -> !cir.ptr> {name = "arg2"} + // CHECK-NEXT: acc.serial combined(loop) dataOperands(%[[DEVPTR2]] : !cir.ptr>) async { + // CHECK-NEXT: acc.loop combined(serial) { + // CHECK: acc.yield + // CHECK-NEXT: } loc + // CHECK-NEXT: acc.yield + // CHECK-NEXT: } loc + +#pragma acc kernels loop deviceptr(arg1, arg2) device_type(nvidia) async + for(unsigned I = 0; I < 5; ++I); + // CHECK-NEXT: %[[DEVPTR1:.*]] = acc.deviceptr varPtr(%[[ARG1]] : !cir.ptr>) async([#acc.device_type]) -> !cir.ptr> {name = "arg1"} + // CHECK-NEXT: %[[DEVPTR2:.*]] = acc.deviceptr varPtr(%[[ARG2]] : !cir.ptr>) async([#acc.device_type]) -> !cir.ptr> {name = "arg2"} + // CHECK-NEXT: acc.kernels combined(loop) dataOperands(%[[DEVPTR1]], %[[DEVPTR2]] : !cir.ptr>, !cir.ptr>) async([#acc.device_type]) { + // CHECK-NEXT: acc.loop combined(kernels) { + // CHECK: acc.yield + // CHECK-NEXT: } loc + // CHECK-NEXT: acc.terminator + // CHECK-NEXT: } loc } diff --git a/clang/test/CIR/CodeGenOpenACC/kernels.c b/clang/test/CIR/CodeGenOpenACC/kernels.c index e940b84fb7461..d276c2c23fbed 100644 --- a/clang/test/CIR/CodeGenOpenACC/kernels.c +++ b/clang/test/CIR/CodeGenOpenACC/kernels.c @@ -437,4 +437,18 @@ void acc_kernels_deviceptr(int *arg1, int *arg2) { // CHECK-NEXT: acc.kernels dataOperands(%[[DEVPTR1]], %[[DEVPTR2]] : !cir.ptr>, !cir.ptr>) { // CHECK-NEXT: acc.terminator // CHECK-NEXT: } loc + +#pragma acc kernels deviceptr(arg1) async + ; + // CHECK-NEXT: %[[DEVPTR1:.*]] = acc.deviceptr varPtr(%[[ARG1]] : !cir.ptr>) async -> !cir.ptr> {name = "arg1"} + // CHECK-NEXT: acc.kernels dataOperands(%[[DEVPTR1]] : !cir.ptr>) async { + // CHECK-NEXT: acc.terminator + // CHECK-NEXT: } loc +#pragma acc kernels deviceptr(arg1, arg2) device_type(radeon) async + ; + // CHECK-NEXT: %[[DEVPTR1:.*]] = acc.deviceptr varPtr(%[[ARG1]] : !cir.ptr>) async([#acc.device_type]) -> !cir.ptr> {name = "arg1"} + // CHECK-NEXT: %[[DEVPTR2:.*]] = acc.deviceptr varPtr(%[[ARG2]] : !cir.ptr>) async([#acc.device_type]) -> !cir.ptr> {name = "arg2"} + // CHECK-NEXT: acc.kernels dataOperands(%[[DEVPTR1]], %[[DEVPTR2]] : !cir.ptr>, !cir.ptr>) async([#acc.device_type]) { + // CHECK-NEXT: acc.terminator + // CHECK-NEXT: } loc } diff --git a/clang/test/CIR/CodeGenOpenACC/parallel.c b/clang/test/CIR/CodeGenOpenACC/parallel.c index 282a0218054d5..df05a7aa53bb8 100644 --- a/clang/test/CIR/CodeGenOpenACC/parallel.c +++ b/clang/test/CIR/CodeGenOpenACC/parallel.c @@ -464,4 +464,18 @@ void acc_parallel_deviceptr(int *arg1, int *arg2) { // CHECK-NEXT: acc.parallel dataOperands(%[[DEVPTR1]], %[[DEVPTR2]] : !cir.ptr>, !cir.ptr>) { // CHECK-NEXT: acc.yield // CHECK-NEXT: } loc + +#pragma acc parallel deviceptr(arg1) async + ; + // CHECK-NEXT: %[[DEVPTR1:.*]] = acc.deviceptr varPtr(%[[ARG1]] : !cir.ptr>) async -> !cir.ptr> {name = "arg1"} + // CHECK-NEXT: acc.parallel dataOperands(%[[DEVPTR1]] : !cir.ptr>) async { + // CHECK-NEXT: acc.yield + // CHECK-NEXT: } loc +#pragma acc parallel deviceptr(arg1, arg2) device_type(radeon) async + ; + // CHECK-NEXT: %[[DEVPTR1:.*]] = acc.deviceptr varPtr(%[[ARG1]] : !cir.ptr>) async([#acc.device_type]) -> !cir.ptr
[clang] [llvm] [SystemZ][z/OS] Refactor AutoConvert.h to remove large MVS guard (PR #143174)
https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/143174 >From dd9f82c5f6f48f175e973b43cd6303e757e1907e Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 6 Jun 2025 12:16:52 -0400 Subject: [PATCH] refactor AutoConvert.h to remove MVS guard --- clang/tools/c-index-test/c-index-test.c | 4 +-- llvm/include/llvm/Support/AutoConvert.h | 5 ++-- llvm/lib/Support/AutoConvert.cpp| 33 +++-- llvm/lib/Support/InitLLVM.cpp | 2 ++ llvm/lib/Support/MemoryBuffer.cpp | 8 ++ llvm/lib/Support/raw_ostream.cpp| 10 +--- llvm/utils/count/count.c| 6 +++-- 7 files changed, 45 insertions(+), 23 deletions(-) diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 4a887cd0c1e2e..3922aa9c31386 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -5199,13 +5199,13 @@ static void flush_atexit(void) { int main(int argc, const char **argv) { thread_info client_data; -#ifdef __MVS__ + // On z/OS we need to enable auto conversion if (enablezOSAutoConversion(fileno(stdout)) == -1) fprintf(stderr, "Setting conversion on stdout failed\n"); + // On z/OS we need to enable auto conversion if (enablezOSAutoConversion(fileno(stderr)) == -1) fprintf(stderr, "Setting conversion on stderr failed\n"); -#endif atexit(flush_atexit); diff --git a/llvm/include/llvm/Support/AutoConvert.h b/llvm/include/llvm/Support/AutoConvert.h index 352493e9be25f..9501ae54927c0 100644 --- a/llvm/include/llvm/Support/AutoConvert.h +++ b/llvm/include/llvm/Support/AutoConvert.h @@ -16,6 +16,7 @@ #ifdef __MVS__ #include <_Ccsid.h> +#endif #ifdef __cplusplus #include "llvm/Support/ErrorOr.h" #include @@ -55,8 +56,10 @@ std::error_code restorezOSStdHandleAutoConversion(int FD); /** \brief Set the tag information for a file descriptor. */ std::error_code setzOSFileTag(int FD, int CCSID, bool Text); +#ifdef __MVS__ /** \brief Get the the tag ccsid for a file name or a file descriptor. */ ErrorOr<__ccsid_t> getzOSFileTag(const char *FileName, const int FD = -1); +#endif /** \brief Query the file tag to determine if it needs conversion to UTF-8 * codepage. @@ -66,6 +69,4 @@ ErrorOr needzOSConversion(const char *FileName, const int FD = -1); } /* namespace llvm */ #endif /* __cplusplus */ -#endif /* __MVS__ */ - #endif /* LLVM_SUPPORT_AUTOCONVERT_H */ diff --git a/llvm/lib/Support/AutoConvert.cpp b/llvm/lib/Support/AutoConvert.cpp index f7918548df1d0..296c0018ff41a 100644 --- a/llvm/lib/Support/AutoConvert.cpp +++ b/llvm/lib/Support/AutoConvert.cpp @@ -11,8 +11,6 @@ // //===--===// -#ifdef __MVS__ - #include "llvm/Support/AutoConvert.h" #include "llvm/Support/Error.h" #include @@ -25,6 +23,9 @@ using namespace llvm; static int savedStdHandleAutoConversionMode[3] = {-1, -1, -1}; int disablezOSAutoConversion(int FD) { +#ifndef __MVS__ + return 0; +#else static const struct f_cnvrt Convert = { SETCVTOFF, // cvtcmd 0, // pccsid @@ -32,9 +33,13 @@ int disablezOSAutoConversion(int FD) { }; return fcntl(FD, F_CONTROL_CVT, &Convert); +#endif } int restorezOSStdHandleAutoConversion(int FD) { +#ifndef __MVS__ + return 0; +#else assert(FD == STDIN_FILENO || FD == STDOUT_FILENO || FD == STDERR_FILENO); if (savedStdHandleAutoConversionMode[FD] == -1) return 0; @@ -44,9 +49,13 @@ int restorezOSStdHandleAutoConversion(int FD) { 0,// fccsid }; return (fcntl(FD, F_CONTROL_CVT, &Cvt)); +#endif } int enablezOSAutoConversion(int FD) { +#ifndef __MVS__ + return 0; +#else struct f_cnvrt Query = { QUERYCVT, // cvtcmd 0,// pccsid @@ -81,30 +90,35 @@ int enablezOSAutoConversion(int FD) { // Assume untagged files to be IBM-1047 encoded. Query.fccsid = (Query.fccsid == FT_UNTAGGED) ? CCSID_IBM_1047 : Query.fccsid; return fcntl(FD, F_CONTROL_CVT, &Query); +#endif } std::error_code llvm::disablezOSAutoConversion(int FD) { +#ifdef __MVS__ if (::disablezOSAutoConversion(FD) == -1) return errnoAsErrorCode(); - +#endif return std::error_code(); } std::error_code llvm::enablezOSAutoConversion(int FD) { +#ifdef __MVS__ if (::enablezOSAutoConversion(FD) == -1) return errnoAsErrorCode(); - +#endif return std::error_code(); } std::error_code llvm::restorezOSStdHandleAutoConversion(int FD) { +#ifdef __MVS__ if (::restorezOSStdHandleAutoConversion(FD) == -1) return errnoAsErrorCode(); - +#endif return std::error_code(); } std::error_code llvm::setzOSFileTag(int FD, int CCSID, bool Text) { +#ifdef __MVS__ assert((!Text || (CCSID != FT_UNTAGGED && CCSID != FT_BINARY)) && "FT_UNTAGGED and FT_BINARY are not allowed for text files"); struct file_tag Tag; @@
[clang] [llvm] Global string alignment (PR #142346)
https://github.com/efriedma-quic commented: I'm a little concerned we don't want to play whack-a-mole with this... but I guess optimizations generally won't explicitly request an alignment of "1", so this is probably good enough? Please write a test specifically for instcombine, not a clang test. https://github.com/llvm/llvm-project/pull/142346 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
mcinally wrote: > > I had 1 minor objection, see my concern on the `uninitialized` attribute > > removal. > > Would it be simpler just to initialize the variable before use? I assume that > the attribute is present to eliminate compiler warnings about uninitialized > variables being passed by reference. I don't see the use of this anywhere > else in the code base. Does adding that attribute really provide a great deal > of meaningful context? This is looking like a better option. Some CIs don't seem to pick up the macro. I'll do some investigating, but I'm not able to reproduce with my build. https://github.com/llvm/llvm-project/pull/142800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [CodeGen][COFF] Always emit CodeView compiler info on Windows targets (PR #142970)
@@ -560,11 +560,12 @@ bool AsmPrinter::doInitialization(Module &M) { } if (MAI->doesSupportDebugInformation()) { -bool EmitCodeView = M.getCodeViewFlag(); -if (EmitCodeView && -(TM.getTargetTriple().isOSWindows() || TM.getTargetTriple().isUEFI())) +// On Windows targets, emit minimal CodeView compiler info even when debug +// info is disabled. +if ((TM.getTargetTriple().isOSWindows() || TM.getTargetTriple().isUEFI()) && cjacek wrote: The new version keeps the existing UEFI condition unchanged. https://github.com/llvm/llvm-project/pull/142970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] add a JSON generator (PR #142483)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/142483 >From fa8b80f9bfe2b7faf765ed4cf60fb8cec30e1d48 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Mon, 2 Jun 2025 12:53:36 -0700 Subject: [PATCH 1/4] [clang-doc] add a JSON generator --- clang-tools-extra/clang-doc/CMakeLists.txt| 1 + clang-tools-extra/clang-doc/Generators.cpp| 2 + clang-tools-extra/clang-doc/Generators.h | 1 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 316 ++ .../clang-doc/tool/ClangDocMain.cpp | 8 +- .../test/clang-doc/json/class.cpp | 183 ++ 6 files changed, 509 insertions(+), 2 deletions(-) create mode 100644 clang-tools-extra/clang-doc/JSONGenerator.cpp create mode 100644 clang-tools-extra/test/clang-doc/json/class.cpp diff --git a/clang-tools-extra/clang-doc/CMakeLists.txt b/clang-tools-extra/clang-doc/CMakeLists.txt index 79563c41435eb..5989e5fe60cf3 100644 --- a/clang-tools-extra/clang-doc/CMakeLists.txt +++ b/clang-tools-extra/clang-doc/CMakeLists.txt @@ -17,6 +17,7 @@ add_clang_library(clangDoc STATIC Serialize.cpp YAMLGenerator.cpp HTMLMustacheGenerator.cpp + JSONGenerator.cpp DEPENDS omp_gen diff --git a/clang-tools-extra/clang-doc/Generators.cpp b/clang-tools-extra/clang-doc/Generators.cpp index a3c2773412cff..3fb5b63c403a7 100644 --- a/clang-tools-extra/clang-doc/Generators.cpp +++ b/clang-tools-extra/clang-doc/Generators.cpp @@ -105,5 +105,7 @@ static int LLVM_ATTRIBUTE_UNUSED HTMLGeneratorAnchorDest = HTMLGeneratorAnchorSource; static int LLVM_ATTRIBUTE_UNUSED MHTMLGeneratorAnchorDest = MHTMLGeneratorAnchorSource; +static int LLVM_ATTRIBUTE_UNUSED JSONGeneratorAnchorDest = +JSONGeneratorAnchorSource; } // namespace doc } // namespace clang diff --git a/clang-tools-extra/clang-doc/Generators.h b/clang-tools-extra/clang-doc/Generators.h index aee04b9d58d9d..92d3006e6002d 100644 --- a/clang-tools-extra/clang-doc/Generators.h +++ b/clang-tools-extra/clang-doc/Generators.h @@ -58,6 +58,7 @@ extern volatile int YAMLGeneratorAnchorSource; extern volatile int MDGeneratorAnchorSource; extern volatile int HTMLGeneratorAnchorSource; extern volatile int MHTMLGeneratorAnchorSource; +extern volatile int JSONGeneratorAnchorSource; } // namespace doc } // namespace clang diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp new file mode 100644 index 0..499ca4dd05e6e --- /dev/null +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -0,0 +1,316 @@ +#include "Generators.h" +#include "llvm/Support/JSON.h" + +using namespace llvm; +using namespace llvm::json; + +static llvm::ExitOnError ExitOnErr; + +namespace clang { +namespace doc { + +class JSONGenerator : public Generator { +public: + static const char *Format; + + Error generateDocs(StringRef RootDir, + llvm::StringMap> Infos, + const ClangDocContext &CDCtx) override; + Error createResources(ClangDocContext &CDCtx) override; + Error generateDocForInfo(Info *I, llvm::raw_ostream &OS, + const ClangDocContext &CDCtx) override; +}; + +const char *JSONGenerator::Format = "json"; + +static json::Object serializeLocation(const Location &Loc, + std::optional RepositoryUrl) { + Object LocationObj = Object(); + LocationObj["LineNumber"] = Loc.StartLineNumber; + LocationObj["Filename"] = Loc.Filename; + + if (!Loc.IsFileInRootDir || !RepositoryUrl) +return LocationObj; + SmallString<128> FileURL(*RepositoryUrl); + sys::path::append(FileURL, sys::path::Style::posix, Loc.Filename); + FileURL += "#" + std::to_string(Loc.StartLineNumber); + LocationObj["FileURL"] = FileURL; + return LocationObj; +} + +static json::Value serializeComment(const CommentInfo &Comment) { + assert((Comment.Kind == "BlockCommandComment" || + Comment.Kind == "FullComment" || Comment.Kind == "ParagraphComment" || + Comment.Kind == "TextComment") && + "Unknown Comment type in CommentInfo."); + + Object Obj = Object(); + json::Value Child = Object(); + + // TextComment has no children, so return it. + if (Comment.Kind == "TextComment") { +Obj["TextComment"] = Comment.Text; +return Obj; + } + + // BlockCommandComment needs to generate a Command key. + if (Comment.Kind == "BlockCommandComment") +Child.getAsObject()->insert({"Command", Comment.Name}); + + // Use the same handling for everything else. + // Only valid for: + // - BlockCommandComment + // - FullComment + // - ParagraphComment + json::Value ChildArr = Array(); + auto &CARef = *ChildArr.getAsArray(); + CARef.reserve(Comment.Children.size()); + for (const auto &C : Comment.Children) +CARef.emplace_back(serializeComment(*C)); + Child.getAsObject()->insert({"Children", ChildArr}); + Obj.insert({Comment.Kind, Child}); + return Obj; +} + +static void serializeCommonA
[clang] Filter out configuration file from compile commands (PR #131099)
https://github.com/kwk closed https://github.com/llvm/llvm-project/pull/131099 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ubsan] Remove -fsanitizer=vptr from -fsanitizer=undefined (PR #121115)
ojhunt wrote: This obviously cases https://github.com/llvm/llvm-project/issues/143065 @AaronBallman @erichkeane @zygoloid commented in the RFC - this change regresses the checks in ubsan for default compilation modes in order to make the use of sanitize=undefined easier in non-default scenarios. https://github.com/llvm/llvm-project/pull/121115 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 7db847d - Filter out configuration file from compile commands (#131099)
Author: Konrad Kleine Date: 2025-06-06T21:08:56+02:00 New Revision: 7db847df556f9c2670046f0d067b3aa80d6b9d39 URL: https://github.com/llvm/llvm-project/commit/7db847df556f9c2670046f0d067b3aa80d6b9d39 DIFF: https://github.com/llvm/llvm-project/commit/7db847df556f9c2670046f0d067b3aa80d6b9d39.diff LOG: Filter out configuration file from compile commands (#131099) The commands to run the compilation when printed with `-###` contain various irrelevant lines for the perf-training. Most of them are filtered out already but when configured with `CLANG_CONFIG_FILE_SYSTEM_DIR` a new line like the following is added and needs to be filtered out: `Configuration file: /etc/clang/x86_64-redhat-linux-gnu-clang.cfg` Added: Modified: clang/utils/perf-training/perf-helper.py Removed: diff --git a/clang/utils/perf-training/perf-helper.py b/clang/utils/perf-training/perf-helper.py index 80c6356d0497c..29904aded5ab0 100644 --- a/clang/utils/perf-training/perf-helper.py +++ b/clang/utils/perf-training/perf-helper.py @@ -237,6 +237,7 @@ def get_cc1_command_for_args(cmd, env): or ln.startswith("InstalledDir:") or ln.startswith("LLVM Profile Note") or ln.startswith(" (in-process)") +or ln.startswith("Configuration file:") or " version " in ln ): continue ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PowerPC] Support for Packed BCD conversion builtins (PR #142723)
@@ -0,0 +1,57 @@ +// Testfile that verifies positive cases (0 or 1 only) for BCD builtins national2packed, packed2zoned and zoned2packed. redstar wrote: I wonder if the `CHECK:` lines could be generated by `update_cc_test_checks.py`. https://github.com/llvm/llvm-project/pull/142723 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [CodeGen][COFF] Always emit CodeView compiler info on Windows targets (PR #142970)
https://github.com/cjacek updated https://github.com/llvm/llvm-project/pull/142970 >From 4b7ecac7f4efcd34bb280c49e8b85b5a36b594c1 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 4 Jun 2025 15:58:59 +0200 Subject: [PATCH 1/4] [CodeGen][COFF] Always emit CodeView compiler info on Windows targets MSVC always emits minimal CodeView metadata with compiler information, even when debug info is otherwise disabled. Other tools may rely on this metadata being present. For example, linkers use it to determine whether hotpatching is enabled for the object file. --- clang/lib/CodeGen/CodeGenModule.cpp | 5 +++ clang/test/CodeGenCXX/debug-info-coff.cpp | 37 ++ .../debug-info-hotpatch-aarch64.cpp | 7 +--- .../CodeGenCXX/debug-info-hotpatch-arm.cpp| 7 +--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp| 9 +++-- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 29 -- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h | 3 ++ llvm/test/DebugInfo/COFF/dwarf-headers.ll | 27 + .../COFF/emission-kind-no-codeview.ll | 38 +++ .../DebugInfo/COFF/emission-kind-no-debug.ll | 28 -- llvm/test/DebugInfo/COFF/fission-cu.ll| 10 ++--- llvm/test/DebugInfo/COFF/fission-sections.ll | 15 .../X86/dbg-value-regmask-clobber.ll | 2 +- 13 files changed, 183 insertions(+), 34 deletions(-) create mode 100644 clang/test/CodeGenCXX/debug-info-coff.cpp create mode 100644 llvm/test/DebugInfo/COFF/emission-kind-no-codeview.ll diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 468fc6e0e5c56..8b67a7f68cf6a 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -414,6 +414,11 @@ CodeGenModule::CodeGenModule(ASTContext &C, CodeGenOpts.CoverageNotesFile.size() || CodeGenOpts.CoverageDataFile.size()) DebugInfo.reset(new CGDebugInfo(*this)); + else if (getTriple().isOSWindows()) +// On Windows targets, we want to emit compiler info even if debug info is +// otherwise disabled. Use a temporary CGDebugInfo instance to emit only +// basic compiler metadata. +CGDebugInfo(*this); Block.GlobalUniqueCount = 0; diff --git a/clang/test/CodeGenCXX/debug-info-coff.cpp b/clang/test/CodeGenCXX/debug-info-coff.cpp new file mode 100644 index 0..87d853bfdeb09 --- /dev/null +++ b/clang/test/CodeGenCXX/debug-info-coff.cpp @@ -0,0 +1,37 @@ +// REQUIRES: x86-registered-target + +// Check that CodeView compiler version is emitted even when debug info is otherwise disabled. + +// RUN: %clang --target=i686-pc-windows-msvc -S -emit-llvm %s -o - | FileCheck --check-prefix=IR %s +// IR: !llvm.dbg.cu = !{!0} +// IR: !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version {{.*}}", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, splitDebugInlining: false, nameTableKind: None) + +// RUN: %clang --target=i686-pc-windows-msvc -c %s -o %t.o +// RUN: llvm-readobj --codeview %t.o | FileCheck %s +// CHECK: CodeViewDebugInfo [ +// CHECK-NEXT: Section: .debug$S (4) +// CHECK-NEXT: Magic: 0x4 +// CHECK-NEXT: Subsection [ +// CHECK-NEXT: SubSectionType: Symbols (0xF1) +// CHECK-NEXT: SubSectionSize: 0x40 +// CHECK-NEXT: ObjNameSym { +// CHECK-NEXT: Kind: S_OBJNAME (0x1101) +// CHECK-NEXT: Signature: 0x0 +// CHECK-NEXT: ObjectName: +// CHECK-NEXT: } +// CHECK-NEXT: Compile3Sym { +// CHECK-NEXT: Kind: S_COMPILE3 (0x113C) +// CHECK-NEXT: Language: Cpp (0x1) +// CHECK-NEXT: Flags [ (0x0) +// CHECK-NEXT: ] +// CHECK-NEXT: Machine: Pentium3 (0x7) +// CHECK-NEXT: FrontendVersion: +// CHECK-NEXT: BackendVersion: +// CHECK-NEXT: VersionName: clang version +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: ] + +int main() { + return 0; +} diff --git a/clang/test/CodeGenCXX/debug-info-hotpatch-aarch64.cpp b/clang/test/CodeGenCXX/debug-info-hotpatch-aarch64.cpp index 10fb1750f2c55..ff2dfc19961c0 100644 --- a/clang/test/CodeGenCXX/debug-info-hotpatch-aarch64.cpp +++ b/clang/test/CodeGenCXX/debug-info-hotpatch-aarch64.cpp @@ -11,12 +11,9 @@ // RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s --check-prefix=HOTPATCH // HOTPATCH: S_COMPILE3 [size = [[#]]] // HOTPATCH: flags = hot patchable -/// -/// Unfortunately we need /Z7, Clang does not systematically generate S_COMPILE3. -/// +// // RUN: %clang_cl --target=aarch64-pc-windows-msvc /c -o %t.obj -- %s -// RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s --check-prefix=NO-HOTPATCH -// NO-HOTPATCH-NOT: flags = hot patchable +// RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s --check-prefix=HOTPATCH int main() { return 0; diff --git a/clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp b/clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp index 48a61f7fb1977..e31c762b08872 100644 ---
[clang] [llvm] [PowerPC] Support for Packed BCD conversion builtins (PR #142723)
@@ -0,0 +1,96 @@ +; Testfile that verifies positive case (0 or 1 only) for BCD builtins national2packed, packed2zoned and zoned2packed. +; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc64le-unknown-unknown \ +; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s + +; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc64-unknown-unknown \ +; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s + +; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc-unknown-unknown \ +; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s + +; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc64-ibm-aix-xcoff \ +; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s + +; CHECK-LABEL: tBcd_National2packed_imm0 +; CHECK: bcdcfn. v2, v2, 0 +; CHECK-NEXT:blr + +; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(none) +declare <16 x i8> @llvm.ppc.national2packed(<16 x i8>, i32 immarg) + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) +define <16 x i8> @tBcd_National2packed_imm0(<16 x i8> noundef %a) { +entry: + %0 = tail call <16 x i8> @llvm.ppc.national2packed(<16 x i8> %a, i32 0) redstar wrote: Simplify the test by removing `tail`. This has no influence on the test. ```suggestion %0 = call <16 x i8> @llvm.ppc.national2packed(<16 x i8> %a, i32 0) ``` Applies to all calls in this test. https://github.com/llvm/llvm-project/pull/142723 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PowerPC] Support for Packed BCD conversion builtins (PR #142723)
@@ -0,0 +1,96 @@ +; Testfile that verifies positive case (0 or 1 only) for BCD builtins national2packed, packed2zoned and zoned2packed. +; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc64le-unknown-unknown \ +; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s + +; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc64-unknown-unknown \ +; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s + +; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc-unknown-unknown \ +; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s + +; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc64-ibm-aix-xcoff \ +; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s + +; CHECK-LABEL: tBcd_National2packed_imm0 +; CHECK: bcdcfn. v2, v2, 0 +; CHECK-NEXT:blr + +; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(none) +declare <16 x i8> @llvm.ppc.national2packed(<16 x i8>, i32 immarg) + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) +define <16 x i8> @tBcd_National2packed_imm0(<16 x i8> noundef %a) { +entry: + %0 = tail call <16 x i8> @llvm.ppc.national2packed(<16 x i8> %a, i32 0) + ret <16 x i8> %0 +} + +; CHECK-LABEL: tBcd_National2packed_imm1 +; CHECK: bcdcfn. v2, v2, 1 +; CHECK-NEXT:blr + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) +define <16 x i8> @tBcd_National2packed_imm1(<16 x i8> noundef %a) { +entry: + %0 = tail call <16 x i8> @llvm.ppc.national2packed(<16 x i8> %a, i32 1) + ret <16 x i8> %0 +} + +; CHECK-LABEL: tBcd_Packed2national +; CHECK: bcdctn. v2, v2 +; CHECK-NEXT:blr +; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(none) +declare <16 x i8> @llvm.ppc.packed2national(<16 x i8>) + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) +define <16 x i8> @tBcd_Packed2national(<16 x i8> noundef %a) { +entry: + %0 = tail call <16 x i8> @llvm.ppc.packed2national(<16 x i8> %a) + ret <16 x i8> %0 +} + +; CHECK-LABEL: tBcd_Packed2zoned_imm0 +; CHECK: bcdctz. v2, v2, 0 +; CHECK-NEXT:blr +; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(none) +declare <16 x i8> @llvm.ppc.packed2zoned(<16 x i8>, i32 immarg) + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable +define dso_local <16 x i8> @tBcd_Packed2zoned_imm0(<16 x i8> noundef %a) { redstar wrote: `dso_local` is not really required. Same with `noundef`. ```suggestion define <16 x i8> @tBcd_Packed2zoned_imm0(<16 x i8> %a) { ``` Applies to the other uses in this test, too. https://github.com/llvm/llvm-project/pull/142723 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PowerPC] Support for Packed BCD conversion builtins (PR #142723)
@@ -0,0 +1,96 @@ +; Testfile that verifies positive case (0 or 1 only) for BCD builtins national2packed, packed2zoned and zoned2packed. +; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc64le-unknown-unknown \ +; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s + +; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc64-unknown-unknown \ +; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s + +; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc-unknown-unknown \ +; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s + +; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc64-ibm-aix-xcoff \ +; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s + +; CHECK-LABEL: tBcd_National2packed_imm0 +; CHECK: bcdcfn. v2, v2, 0 +; CHECK-NEXT:blr + +; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(none) redstar wrote: This comment (and the other, similar comments) does not make sense because the function attributes were removed. Remove the comments, too. https://github.com/llvm/llvm-project/pull/142723 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PowerPC] Support for Packed BCD conversion builtins (PR #142723)
@@ -0,0 +1,96 @@ +; Testfile that verifies positive case (0 or 1 only) for BCD builtins national2packed, packed2zoned and zoned2packed. redstar wrote: Since this is a new test I think we should strive for using `update_llc_test_checks.py` to generate the `CHECK:` lines. https://github.com/llvm/llvm-project/pull/142723 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Upstream CreateOp for ComplexType with folder (PR #143192)
https://github.com/AmrDeveloper created https://github.com/llvm/llvm-project/pull/143192 This change adds support for the create op for ComplexType with folder and support for empty init list https://github.com/llvm/llvm-project/issues/141365 >From 0ee92db03198e2364ade53e5c0bbd0f844fe634f Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Fri, 6 Jun 2025 20:56:49 +0200 Subject: [PATCH] [CIR] Upstream CreateOp for ComplexType with folder --- clang/include/clang/CIR/Dialect/IR/CIROps.td | 32 .../include/clang/CIR/Dialect/IR/CIRTypes.td | 3 +- clang/include/clang/CIR/MissingFeatures.h | 1 - clang/lib/CIR/CodeGen/CIRGenBuilder.h | 6 ++ clang/lib/CIR/CodeGen/CIRGenDecl.cpp | 12 ++- clang/lib/CIR/CodeGen/CIRGenExpr.cpp | 11 +++ clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp | 81 +++ clang/lib/CIR/CodeGen/CIRGenFunction.h| 9 +++ clang/lib/CIR/CodeGen/CMakeLists.txt | 1 + clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 28 +++ .../Dialect/Transforms/CIRCanonicalize.cpp| 3 +- .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 48 ++- .../CIR/Lowering/DirectToLLVM/LowerToLLVM.h | 10 +++ clang/test/CIR/CodeGen/complex.cpp| 56 + .../CIR/Transforms/complex-create-fold.cir| 30 +++ 15 files changed, 322 insertions(+), 9 deletions(-) create mode 100644 clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp create mode 100644 clang/test/CIR/Transforms/complex-create-fold.cir diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index bd847731193ab..5f72545ea020d 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -2226,4 +2226,36 @@ def VecTernaryOp : CIR_Op<"vec.ternary", let hasVerifier = 1; } +//===--===// +// ComplexCreateOp +//===--===// + +def ComplexCreateOp : CIR_Op<"complex.create", [Pure, SameTypeOperands]> { + let summary = "Create a complex value from its real and imaginary parts"; + let description = [{ +The `cir.complex.create` operation takes two operands that represent the +real and imaginary part of a complex number, and yields the complex number. + +```mlir +%0 = cir.const #cir.fp<1.00e+00> : !cir.double +%1 = cir.const #cir.fp<2.00e+00> : !cir.double +%2 = cir.complex.create %0, %1 : !cir.complex +``` + }]; + + let results = (outs CIR_ComplexType:$result); + let arguments = (ins +CIR_AnyIntOrFloatType:$real, +CIR_AnyIntOrFloatType:$imag + ); + + let assemblyFormat = [{ +$real `,` $imag +`:` qualified(type($real)) `->` qualified(type($result)) attr-dict + }]; + + let hasVerifier = 1; + let hasFolder = 1; +} + #endif // CLANG_CIR_DIALECT_IR_CIROPS_TD diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td index fb96976075130..41d7d725a09e0 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td @@ -600,7 +600,8 @@ def CIRRecordType : Type< def CIR_AnyType : AnyTypeOf<[ CIR_VoidType, CIR_BoolType, CIR_ArrayType, CIR_VectorType, CIR_IntType, - CIR_AnyFloatType, CIR_PointerType, CIR_FuncType, CIR_RecordType + CIR_AnyFloatType, CIR_PointerType, CIR_FuncType, CIR_RecordType, + CIR_ComplexType ]>; #endif // MLIR_CIR_DIALECT_CIR_TYPES diff --git a/clang/include/clang/CIR/MissingFeatures.h b/clang/include/clang/CIR/MissingFeatures.h index f1e0c15d41f64..473e4dc7a81a4 100644 --- a/clang/include/clang/CIR/MissingFeatures.h +++ b/clang/include/clang/CIR/MissingFeatures.h @@ -233,7 +233,6 @@ struct MissingFeatures { // Future CIR operations static bool awaitOp() { return false; } static bool callOp() { return false; } - static bool complexCreateOp() { return false; } static bool complexImagOp() { return false; } static bool complexRealOp() { return false; } static bool ifOp() { return false; } diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h b/clang/lib/CIR/CodeGen/CIRGenBuilder.h index 5f33ae1af35ee..308b51be6c30b 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h +++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h @@ -323,6 +323,12 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { return CIRBaseBuilderTy::createStore(loc, val, dst.getPointer(), align); } + mlir::Value createComplexCreate(mlir::Location loc, mlir::Value real, + mlir::Value imag) { +auto resultComplexTy = cir::ComplexType::get(real.getType()); +return create(loc, resultComplexTy, real, imag); + } + /// Create a cir.ptr_stride operation to get access to an array element. /// \p idx is the index of the element to access, \p shouldDecay is true if /// the result should decay to a pointer to the element
[clang] [CIR] Upstream CreateOp for ComplexType with folder (PR #143192)
llvmbot wrote: @llvm/pr-subscribers-clangir Author: Amr Hesham (AmrDeveloper) Changes This change adds support for the create op for ComplexType with folder and support for empty init list https://github.com/llvm/llvm-project/issues/141365 --- Patch is 22.07 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/143192.diff 15 Files Affected: - (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+32) - (modified) clang/include/clang/CIR/Dialect/IR/CIRTypes.td (+2-1) - (modified) clang/include/clang/CIR/MissingFeatures.h (-1) - (modified) clang/lib/CIR/CodeGen/CIRGenBuilder.h (+6) - (modified) clang/lib/CIR/CodeGen/CIRGenDecl.cpp (+9-3) - (modified) clang/lib/CIR/CodeGen/CIRGenExpr.cpp (+11) - (added) clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp (+81) - (modified) clang/lib/CIR/CodeGen/CIRGenFunction.h (+9) - (modified) clang/lib/CIR/CodeGen/CMakeLists.txt (+1) - (modified) clang/lib/CIR/Dialect/IR/CIRDialect.cpp (+28) - (modified) clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp (+1-2) - (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+46-2) - (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h (+10) - (modified) clang/test/CIR/CodeGen/complex.cpp (+56) - (added) clang/test/CIR/Transforms/complex-create-fold.cir (+30) ``diff diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index bd847731193ab..5f72545ea020d 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -2226,4 +2226,36 @@ def VecTernaryOp : CIR_Op<"vec.ternary", let hasVerifier = 1; } +//===--===// +// ComplexCreateOp +//===--===// + +def ComplexCreateOp : CIR_Op<"complex.create", [Pure, SameTypeOperands]> { + let summary = "Create a complex value from its real and imaginary parts"; + let description = [{ +The `cir.complex.create` operation takes two operands that represent the +real and imaginary part of a complex number, and yields the complex number. + +```mlir +%0 = cir.const #cir.fp<1.00e+00> : !cir.double +%1 = cir.const #cir.fp<2.00e+00> : !cir.double +%2 = cir.complex.create %0, %1 : !cir.complex +``` + }]; + + let results = (outs CIR_ComplexType:$result); + let arguments = (ins +CIR_AnyIntOrFloatType:$real, +CIR_AnyIntOrFloatType:$imag + ); + + let assemblyFormat = [{ +$real `,` $imag +`:` qualified(type($real)) `->` qualified(type($result)) attr-dict + }]; + + let hasVerifier = 1; + let hasFolder = 1; +} + #endif // CLANG_CIR_DIALECT_IR_CIROPS_TD diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td index fb96976075130..41d7d725a09e0 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td @@ -600,7 +600,8 @@ def CIRRecordType : Type< def CIR_AnyType : AnyTypeOf<[ CIR_VoidType, CIR_BoolType, CIR_ArrayType, CIR_VectorType, CIR_IntType, - CIR_AnyFloatType, CIR_PointerType, CIR_FuncType, CIR_RecordType + CIR_AnyFloatType, CIR_PointerType, CIR_FuncType, CIR_RecordType, + CIR_ComplexType ]>; #endif // MLIR_CIR_DIALECT_CIR_TYPES diff --git a/clang/include/clang/CIR/MissingFeatures.h b/clang/include/clang/CIR/MissingFeatures.h index f1e0c15d41f64..473e4dc7a81a4 100644 --- a/clang/include/clang/CIR/MissingFeatures.h +++ b/clang/include/clang/CIR/MissingFeatures.h @@ -233,7 +233,6 @@ struct MissingFeatures { // Future CIR operations static bool awaitOp() { return false; } static bool callOp() { return false; } - static bool complexCreateOp() { return false; } static bool complexImagOp() { return false; } static bool complexRealOp() { return false; } static bool ifOp() { return false; } diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h b/clang/lib/CIR/CodeGen/CIRGenBuilder.h index 5f33ae1af35ee..308b51be6c30b 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h +++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h @@ -323,6 +323,12 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { return CIRBaseBuilderTy::createStore(loc, val, dst.getPointer(), align); } + mlir::Value createComplexCreate(mlir::Location loc, mlir::Value real, + mlir::Value imag) { +auto resultComplexTy = cir::ComplexType::get(real.getType()); +return create(loc, resultComplexTy, real, imag); + } + /// Create a cir.ptr_stride operation to get access to an array element. /// \p idx is the index of the element to access, \p shouldDecay is true if /// the result should decay to a pointer to the element type. diff --git a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp index 80b0172090aa3..3e2c96c5aaeaf 100644 --- a/clang/lib/CIR/CodeG
[clang] [alpha.webkit.NoUnretainedMemberChecker] Recognize NS_REQUIRES_PROPERTY_DEFINITIONS (PR #141293)
https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/141293 >From bcee06004f24f8488bcc8e84170bf3509daa5fd9 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Fri, 23 May 2025 13:53:36 -0700 Subject: [PATCH 1/2] [alpha.webkit.NoUnretainedMemberChecker] Recognize NS_REQUIRES_PROPERTY_DEFINITIONS Allow @property of a raw pointer when NS_REQUIRES_PROPERTY_DEFINITIONS is specified on the interface since such an interface does not automatically synthesize raw pointer ivars. Also emit a warning for @property(assign) and @property(unsafe_unretained) under ARC. --- .../Checkers/WebKit/PtrTypesSemantics.cpp | 1 + .../Checkers/WebKit/PtrTypesSemantics.h | 2 ++ .../WebKit/RawPtrRefMemberChecker.cpp | 21 + .../Checkers/WebKit/objc-mock-types.h | 1 + .../Checkers/WebKit/unretained-members-arc.mm | 30 +++ .../Checkers/WebKit/unretained-members.mm | 19 6 files changed, 68 insertions(+), 6 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 4ddd11495f534..f547f86f4782f 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -236,6 +236,7 @@ std::optional isUnchecked(const QualType T) { void RetainTypeChecker::visitTranslationUnitDecl( const TranslationUnitDecl *TUD) { IsARCEnabled = TUD->getLangOpts().ObjCAutoRefCount; + DefaultSynthProperties = TUD->getLangOpts().ObjCDefaultSynthProperties; } void RetainTypeChecker::visitTypedef(const TypedefDecl *TD) { diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h index f9fcfe9878d54..3c9560cb8059b 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h @@ -76,12 +76,14 @@ class RetainTypeChecker { llvm::DenseSet CFPointees; llvm::DenseSet RecordlessTypes; bool IsARCEnabled{false}; + bool DefaultSynthProperties{true}; public: void visitTranslationUnitDecl(const TranslationUnitDecl *); void visitTypedef(const TypedefDecl *); bool isUnretained(const QualType, bool ignoreARC = false); bool isARCEnabled() const { return IsARCEnabled; } + bool defaultSynthProperties() const { return DefaultSynthProperties; } }; /// \returns true if \p Class is NS or CF objects AND not retained, false if diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp index 4ea6158c4c410..aa707823beb5b 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp @@ -38,7 +38,8 @@ class RawPtrRefMemberChecker RawPtrRefMemberChecker(const char *description) : Bug(this, description, "WebKit coding guidelines") {} - virtual std::optional isUnsafePtr(QualType) const = 0; + virtual std::optional isUnsafePtr(QualType, + bool ignoreARC = false) const = 0; virtual const char *typeName() const = 0; virtual const char *invariant() const = 0; @@ -174,7 +175,15 @@ class RawPtrRefMemberChecker if (!PropType) return; -auto IsUnsafePtr = isUnsafePtr(QT); +if (const ObjCInterfaceDecl *ID = dyn_cast(CD)) { + if (!RTC || !RTC->defaultSynthProperties() || + ID->isObjCRequiresPropertyDefs()) +return; +} + +bool ignoreARC = +!PD->isReadOnly() && PD->getSetterKind() == ObjCPropertyDecl::Assign; +auto IsUnsafePtr = isUnsafePtr(QT, ignoreARC); if (!IsUnsafePtr || !*IsUnsafePtr) return; @@ -274,7 +283,7 @@ class NoUncountedMemberChecker final : public RawPtrRefMemberChecker { : RawPtrRefMemberChecker("Member variable is a raw-pointer/reference to " "reference-countable type") {} - std::optional isUnsafePtr(QualType QT) const final { + std::optional isUnsafePtr(QualType QT, bool) const final { return isUncountedPtr(QT.getCanonicalType()); } @@ -291,7 +300,7 @@ class NoUncheckedPtrMemberChecker final : public RawPtrRefMemberChecker { : RawPtrRefMemberChecker("Member variable is a raw-pointer/reference to " "checked-pointer capable type") {} - std::optional isUnsafePtr(QualType QT) const final { + std::optional isUnsafePtr(QualType QT, bool) const final { return isUncheckedPtr(QT.getCanonicalType()); } @@ -311,8 +320,8 @@ class NoUnretainedMemberChecker final : public RawPtrRefMemberChecker { RTC = RetainTypeChecker(); } - std::optional isUnsafePtr(QualType QT) const final { -return RTC->isUnretained(QT); + std::optional isUnsafePtr(QualType QT, bool ignoreARC) const final {
[clang-tools-extra] [clangd] added const and constexpr (PR #143193)
https://github.com/JohnFinn created https://github.com/llvm/llvm-project/pull/143193 None >From 7104f44426829e4262851afdbe0182dcfe8da812 Mon Sep 17 00:00:00 2001 From: JohnFinn Date: Fri, 6 Jun 2025 21:28:12 +0200 Subject: [PATCH] [clangd] added const and constexpr --- .../clangd/HeaderSourceSwitch.cpp | 26 ++- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp index d54c3668570eb..ee4bea1401490 100644 --- a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp +++ b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp @@ -20,22 +20,24 @@ namespace clangd { std::optional getCorrespondingHeaderOrSource( PathRef OriginalFile, llvm::IntrusiveRefCntPtr VFS) { - llvm::StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx", -".c++", ".m", ".mm"}; - llvm::StringRef HeaderExtensions[] = {".h",".hh", ".hpp", ".hxx", -".inc", ".cppm", ".ccm", ".cxxm", -".c++m", ".ixx"}; + static constexpr llvm::StringRef SourceExtensions[] = { + ".cpp", ".c", ".cc", ".cxx", ".c++", ".m", ".mm"}; + static constexpr llvm::StringRef HeaderExtensions[] = { + ".h",".hh", ".hpp", ".hxx", ".inc", + ".cppm", ".ccm", ".cxxm", ".c++m", ".ixx"}; llvm::StringRef PathExt = llvm::sys::path::extension(OriginalFile); // Lookup in a list of known extensions. - bool IsSource = llvm::any_of(SourceExtensions, [&PathExt](PathRef SourceExt) { -return SourceExt.equals_insensitive(PathExt); - }); + const bool IsSource = + llvm::any_of(SourceExtensions, [&PathExt](PathRef SourceExt) { +return SourceExt.equals_insensitive(PathExt); + }); - bool IsHeader = llvm::any_of(HeaderExtensions, [&PathExt](PathRef HeaderExt) { -return HeaderExt.equals_insensitive(PathExt); - }); + const bool IsHeader = + llvm::any_of(HeaderExtensions, [&PathExt](PathRef HeaderExt) { +return HeaderExt.equals_insensitive(PathExt); + }); // We can only switch between the known extensions. if (!IsSource && !IsHeader) @@ -94,7 +96,7 @@ std::optional getCorrespondingHeaderOrSource(PathRef OriginalFile, // // For each symbol in the original file, we get its target location (decl or // def) from the index, then award that target file. - bool IsHeader = isHeaderFile(OriginalFile, AST.getLangOpts()); + const bool IsHeader = isHeaderFile(OriginalFile, AST.getLangOpts()); Index->lookup(Request, [&](const Symbol &Sym) { if (IsHeader) AwardTarget(Sym.Definition.FileURI); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] added const and constexpr (PR #143193)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clangd Author: Jouni (JohnFinn) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/143193.diff 1 Files Affected: - (modified) clang-tools-extra/clangd/HeaderSourceSwitch.cpp (+14-12) ``diff diff --git a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp index d54c3668570eb..ee4bea1401490 100644 --- a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp +++ b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp @@ -20,22 +20,24 @@ namespace clangd { std::optional getCorrespondingHeaderOrSource( PathRef OriginalFile, llvm::IntrusiveRefCntPtr VFS) { - llvm::StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx", -".c++", ".m", ".mm"}; - llvm::StringRef HeaderExtensions[] = {".h",".hh", ".hpp", ".hxx", -".inc", ".cppm", ".ccm", ".cxxm", -".c++m", ".ixx"}; + static constexpr llvm::StringRef SourceExtensions[] = { + ".cpp", ".c", ".cc", ".cxx", ".c++", ".m", ".mm"}; + static constexpr llvm::StringRef HeaderExtensions[] = { + ".h",".hh", ".hpp", ".hxx", ".inc", + ".cppm", ".ccm", ".cxxm", ".c++m", ".ixx"}; llvm::StringRef PathExt = llvm::sys::path::extension(OriginalFile); // Lookup in a list of known extensions. - bool IsSource = llvm::any_of(SourceExtensions, [&PathExt](PathRef SourceExt) { -return SourceExt.equals_insensitive(PathExt); - }); + const bool IsSource = + llvm::any_of(SourceExtensions, [&PathExt](PathRef SourceExt) { +return SourceExt.equals_insensitive(PathExt); + }); - bool IsHeader = llvm::any_of(HeaderExtensions, [&PathExt](PathRef HeaderExt) { -return HeaderExt.equals_insensitive(PathExt); - }); + const bool IsHeader = + llvm::any_of(HeaderExtensions, [&PathExt](PathRef HeaderExt) { +return HeaderExt.equals_insensitive(PathExt); + }); // We can only switch between the known extensions. if (!IsSource && !IsHeader) @@ -94,7 +96,7 @@ std::optional getCorrespondingHeaderOrSource(PathRef OriginalFile, // // For each symbol in the original file, we get its target location (decl or // def) from the index, then award that target file. - bool IsHeader = isHeaderFile(OriginalFile, AST.getLangOpts()); + const bool IsHeader = isHeaderFile(OriginalFile, AST.getLangOpts()); Index->lookup(Request, [&](const Symbol &Sym) { if (IsHeader) AwardTarget(Sym.Definition.FileURI); `` https://github.com/llvm/llvm-project/pull/143193 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [alpha.webkit.NoUnretainedMemberChecker] Recognize NS_REQUIRES_PROPERTY_DEFINITIONS (PR #141293)
@@ -64,3 +64,33 @@ void forceTmplToInstantiate(FooTmpl) {} }; } // namespace ptr_to_ptr_to_retained + +@interface AnotherObject : NSObject { + NSString *ns_string; + CFStringRef cf_string; + // expected-warning@-1{{Instance variable 'cf_string' in 'AnotherObject' is a retainable type 'CFStringRef'; member variables must be a RetainPtr}} +} +@property(nonatomic, strong) NSString *prop_string1; +@property(nonatomic, assign) NSString *prop_string2; +// expected-warning@-1{{Property 'prop_string2' in 'AnotherObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}} +@property(nonatomic, unsafe_unretained) NSString *prop_string3; +// expected-warning@-1{{Property 'prop_string3' in 'AnotherObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}} +@property(nonatomic, readonly) NSString *prop_string4; +@end + +NS_REQUIRES_PROPERTY_DEFINITIONS +@interface NoSynthObject : NSObject { + NSString *ns_string; + CFStringRef cf_string; + // expected-warning@-1{{Instance variable 'cf_string' in 'NoSynthObject' is a retainable type 'CFStringRef'; member variables must be a RetainPtr}} +} +@property(nonatomic, readonly, strong) NSString *prop_string1; +@property(nonatomic, readonly, strong) NSString *prop_string2; rniwa wrote: Actually, writing a test for this made me realize we weren't handling `@synthenize` so fixing that now. https://github.com/llvm/llvm-project/pull/141293 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] added const and constexpr (PR #143193)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/143193 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle templates in qualified typenames (PR #143194)
https://github.com/bdunkin created https://github.com/llvm/llvm-project/pull/143194 This fixes the `SpaceBeforeParensOptions.AfterFunctionDeclarationName` and `SpaceBeforeParensOptions.AfterFunctionDefinitionName` options not adding spaces when a template type's constructor or destructor is forward declared or defined outside of the type definition. Attribution Note - I have been authorized to contribute this change on behalf of my company: ArenaNet LLC >From 2f262ca8d5060bf58ac23241917bad6d7347c8d3 Mon Sep 17 00:00:00 2001 From: Ben Dunkin Date: Fri, 6 Jun 2025 12:29:13 -0700 Subject: [PATCH] Fix identifiers not being marked as constructor/destructor names if they are qualified by a template type, or have template typename declarations in front of them. --- clang/lib/Format/TokenAnnotator.cpp | 68 +-- clang/unittests/Format/TokenAnnotatorTest.cpp | 42 2 files changed, 106 insertions(+), 4 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 37ab40ca97bff..479a8743c5a65 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3622,6 +3622,29 @@ static unsigned maxNestingDepth(const AnnotatedLine &Line) { return Result; } +static bool startsQualifiedName(const FormatToken *Tok) { + // Consider: A::B::B() + // Tok --^ + if (Tok->startsSequence(tok::identifier, tok::coloncolon)) +return true; + + // Consider: A::B::B() + // Tok --^ + if (Tok->startsSequence(tok::identifier, TT_TemplateOpener)) { +Tok = Tok->getNextNonComment(); +assert(Tok); +assert(Tok->is(TT_TemplateOpener)); + +if (!Tok->MatchingParen) + return false; + +return Tok->MatchingParen->startsSequence(TT_TemplateCloser, + tok::coloncolon); + } + + return false; +} + // Returns the name of a function with no return type, e.g. a constructor or // destructor. static FormatToken *getFunctionName(const AnnotatedLine &Line, @@ -3651,6 +3674,21 @@ static FormatToken *getFunctionName(const AnnotatedLine &Line, continue; } +// Skip past template typename declarations that may precede the +// constructor/destructor name +if (Tok->is(tok::kw_template)) { + Tok = Tok->getNextNonComment(); + if (!Tok) +return nullptr; + + assert(Tok->is(TT_TemplateOpener)); + Tok = Tok->MatchingParen; + if (!Tok) +return nullptr; + + continue; +} + // A qualified name may start from the global namespace. if (Tok->is(tok::coloncolon)) { Tok = Tok->Next; @@ -3659,9 +3697,23 @@ static FormatToken *getFunctionName(const AnnotatedLine &Line, } // Skip to the unqualified part of the name. -while (Tok->startsSequence(tok::identifier, tok::coloncolon)) { - assert(Tok->Next); - Tok = Tok->Next->Next; +while (startsQualifiedName(Tok)) { + Tok = Tok->getNextNonComment(); + if (!Tok) +return nullptr; + + // Skip template types if this is a templated type name + if (Tok->is(TT_TemplateOpener)) { +Tok = Tok->MatchingParen; +if (!Tok) + return nullptr; + +Tok = Tok->getNextNonComment(); +if (!Tok) + return nullptr; + } + + Tok = Tok->getNextNonComment(); if (!Tok) return nullptr; } @@ -3691,10 +3743,18 @@ static bool isCtorOrDtorName(const FormatToken *Tok) { if (Prev && Prev->is(tok::tilde)) Prev = Prev->Previous; - if (!Prev || !Prev->endsSequence(tok::coloncolon, tok::identifier)) + // Consider: A::A() and A::A() + if (!Prev || (!Prev->endsSequence(tok::coloncolon, tok::identifier) && +!Prev->endsSequence(tok::coloncolon, TT_TemplateCloser))) { return false; + } assert(Prev->Previous); + if (Prev->Previous->is(TT_TemplateCloser) && Prev->Previous->MatchingParen) { +Prev = Prev->Previous->MatchingParen; +assert(Prev->Previous); + } + return Prev->Previous->TokenText == Tok->TokenText; } diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 9d62ff8d39a77..7e9b9c24f6a3a 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -2346,6 +2346,48 @@ TEST_F(TokenAnnotatorTest, UnderstandsCtorAndDtorDeclNames) { EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_FunctionDeclarationLParen); EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_FunctionLBrace); + Tokens = annotate("Foo::Foo() {}"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[5], tok::identifier, TT_CtorDtorDeclName); + EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_FunctionDeclarationLParen); + EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_FunctionLBrace); + + Tokens = annotate("Foo::~Foo() {}"); + ASSERT_EQ(Tokens.size(), 12u) << Tokens; + EXPECT_TOKEN(Tokens
[clang] [alpha.webkit.NoUnretainedMemberChecker] Recognize NS_REQUIRES_PROPERTY_DEFINITIONS (PR #141293)
https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/141293 >From bcee06004f24f8488bcc8e84170bf3509daa5fd9 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Fri, 23 May 2025 13:53:36 -0700 Subject: [PATCH 1/3] [alpha.webkit.NoUnretainedMemberChecker] Recognize NS_REQUIRES_PROPERTY_DEFINITIONS Allow @property of a raw pointer when NS_REQUIRES_PROPERTY_DEFINITIONS is specified on the interface since such an interface does not automatically synthesize raw pointer ivars. Also emit a warning for @property(assign) and @property(unsafe_unretained) under ARC. --- .../Checkers/WebKit/PtrTypesSemantics.cpp | 1 + .../Checkers/WebKit/PtrTypesSemantics.h | 2 ++ .../WebKit/RawPtrRefMemberChecker.cpp | 21 + .../Checkers/WebKit/objc-mock-types.h | 1 + .../Checkers/WebKit/unretained-members-arc.mm | 30 +++ .../Checkers/WebKit/unretained-members.mm | 19 6 files changed, 68 insertions(+), 6 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 4ddd11495f534..f547f86f4782f 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -236,6 +236,7 @@ std::optional isUnchecked(const QualType T) { void RetainTypeChecker::visitTranslationUnitDecl( const TranslationUnitDecl *TUD) { IsARCEnabled = TUD->getLangOpts().ObjCAutoRefCount; + DefaultSynthProperties = TUD->getLangOpts().ObjCDefaultSynthProperties; } void RetainTypeChecker::visitTypedef(const TypedefDecl *TD) { diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h index f9fcfe9878d54..3c9560cb8059b 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h @@ -76,12 +76,14 @@ class RetainTypeChecker { llvm::DenseSet CFPointees; llvm::DenseSet RecordlessTypes; bool IsARCEnabled{false}; + bool DefaultSynthProperties{true}; public: void visitTranslationUnitDecl(const TranslationUnitDecl *); void visitTypedef(const TypedefDecl *); bool isUnretained(const QualType, bool ignoreARC = false); bool isARCEnabled() const { return IsARCEnabled; } + bool defaultSynthProperties() const { return DefaultSynthProperties; } }; /// \returns true if \p Class is NS or CF objects AND not retained, false if diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp index 4ea6158c4c410..aa707823beb5b 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp @@ -38,7 +38,8 @@ class RawPtrRefMemberChecker RawPtrRefMemberChecker(const char *description) : Bug(this, description, "WebKit coding guidelines") {} - virtual std::optional isUnsafePtr(QualType) const = 0; + virtual std::optional isUnsafePtr(QualType, + bool ignoreARC = false) const = 0; virtual const char *typeName() const = 0; virtual const char *invariant() const = 0; @@ -174,7 +175,15 @@ class RawPtrRefMemberChecker if (!PropType) return; -auto IsUnsafePtr = isUnsafePtr(QT); +if (const ObjCInterfaceDecl *ID = dyn_cast(CD)) { + if (!RTC || !RTC->defaultSynthProperties() || + ID->isObjCRequiresPropertyDefs()) +return; +} + +bool ignoreARC = +!PD->isReadOnly() && PD->getSetterKind() == ObjCPropertyDecl::Assign; +auto IsUnsafePtr = isUnsafePtr(QT, ignoreARC); if (!IsUnsafePtr || !*IsUnsafePtr) return; @@ -274,7 +283,7 @@ class NoUncountedMemberChecker final : public RawPtrRefMemberChecker { : RawPtrRefMemberChecker("Member variable is a raw-pointer/reference to " "reference-countable type") {} - std::optional isUnsafePtr(QualType QT) const final { + std::optional isUnsafePtr(QualType QT, bool) const final { return isUncountedPtr(QT.getCanonicalType()); } @@ -291,7 +300,7 @@ class NoUncheckedPtrMemberChecker final : public RawPtrRefMemberChecker { : RawPtrRefMemberChecker("Member variable is a raw-pointer/reference to " "checked-pointer capable type") {} - std::optional isUnsafePtr(QualType QT) const final { + std::optional isUnsafePtr(QualType QT, bool) const final { return isUncheckedPtr(QT.getCanonicalType()); } @@ -311,8 +320,8 @@ class NoUnretainedMemberChecker final : public RawPtrRefMemberChecker { RTC = RetainTypeChecker(); } - std::optional isUnsafePtr(QualType QT) const final { -return RTC->isUnretained(QT); + std::optional isUnsafePtr(QualType QT, bool ignoreARC) const final {
[clang] [clang-format] Handle templates in qualified typenames (PR #143194)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/143194 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle templates in qualified typenames (PR #143194)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Ben Dunkin (bdunkin) Changes This fixes the `SpaceBeforeParensOptions.AfterFunctionDeclarationName` and `SpaceBeforeParensOptions.AfterFunctionDefinitionName` options not adding spaces when a template type's constructor or destructor is forward declared or defined outside of the type definition. Attribution Note - I have been authorized to contribute this change on behalf of my company: ArenaNet LLC --- Full diff: https://github.com/llvm/llvm-project/pull/143194.diff 2 Files Affected: - (modified) clang/lib/Format/TokenAnnotator.cpp (+64-4) - (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+42) ``diff diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 37ab40ca97bff..479a8743c5a65 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3622,6 +3622,29 @@ static unsigned maxNestingDepth(const AnnotatedLine &Line) { return Result; } +static bool startsQualifiedName(const FormatToken *Tok) { + // Consider: A::B::B() + // Tok --^ + if (Tok->startsSequence(tok::identifier, tok::coloncolon)) +return true; + + // Consider: A::B::B() + // Tok --^ + if (Tok->startsSequence(tok::identifier, TT_TemplateOpener)) { +Tok = Tok->getNextNonComment(); +assert(Tok); +assert(Tok->is(TT_TemplateOpener)); + +if (!Tok->MatchingParen) + return false; + +return Tok->MatchingParen->startsSequence(TT_TemplateCloser, + tok::coloncolon); + } + + return false; +} + // Returns the name of a function with no return type, e.g. a constructor or // destructor. static FormatToken *getFunctionName(const AnnotatedLine &Line, @@ -3651,6 +3674,21 @@ static FormatToken *getFunctionName(const AnnotatedLine &Line, continue; } +// Skip past template typename declarations that may precede the +// constructor/destructor name +if (Tok->is(tok::kw_template)) { + Tok = Tok->getNextNonComment(); + if (!Tok) +return nullptr; + + assert(Tok->is(TT_TemplateOpener)); + Tok = Tok->MatchingParen; + if (!Tok) +return nullptr; + + continue; +} + // A qualified name may start from the global namespace. if (Tok->is(tok::coloncolon)) { Tok = Tok->Next; @@ -3659,9 +3697,23 @@ static FormatToken *getFunctionName(const AnnotatedLine &Line, } // Skip to the unqualified part of the name. -while (Tok->startsSequence(tok::identifier, tok::coloncolon)) { - assert(Tok->Next); - Tok = Tok->Next->Next; +while (startsQualifiedName(Tok)) { + Tok = Tok->getNextNonComment(); + if (!Tok) +return nullptr; + + // Skip template types if this is a templated type name + if (Tok->is(TT_TemplateOpener)) { +Tok = Tok->MatchingParen; +if (!Tok) + return nullptr; + +Tok = Tok->getNextNonComment(); +if (!Tok) + return nullptr; + } + + Tok = Tok->getNextNonComment(); if (!Tok) return nullptr; } @@ -3691,10 +3743,18 @@ static bool isCtorOrDtorName(const FormatToken *Tok) { if (Prev && Prev->is(tok::tilde)) Prev = Prev->Previous; - if (!Prev || !Prev->endsSequence(tok::coloncolon, tok::identifier)) + // Consider: A::A() and A::A() + if (!Prev || (!Prev->endsSequence(tok::coloncolon, tok::identifier) && +!Prev->endsSequence(tok::coloncolon, TT_TemplateCloser))) { return false; + } assert(Prev->Previous); + if (Prev->Previous->is(TT_TemplateCloser) && Prev->Previous->MatchingParen) { +Prev = Prev->Previous->MatchingParen; +assert(Prev->Previous); + } + return Prev->Previous->TokenText == Tok->TokenText; } diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 9d62ff8d39a77..7e9b9c24f6a3a 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -2346,6 +2346,48 @@ TEST_F(TokenAnnotatorTest, UnderstandsCtorAndDtorDeclNames) { EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_FunctionDeclarationLParen); EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_FunctionLBrace); + Tokens = annotate("Foo::Foo() {}"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[5], tok::identifier, TT_CtorDtorDeclName); + EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_FunctionDeclarationLParen); + EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_FunctionLBrace); + + Tokens = annotate("Foo::~Foo() {}"); + ASSERT_EQ(Tokens.size(), 12u) << Tokens; + EXPECT_TOKEN(Tokens[6], tok::identifier, TT_CtorDtorDeclName); + EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_FunctionDeclarationLParen); + EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_FunctionLBrace); + + Tokens = annotate("template Foo::Foo() {}"); + ASSERT_EQ(Tokens.size(), 16u) << To
[clang] [alpha.webkit.NoUnretainedMemberChecker] Recognize NS_REQUIRES_PROPERTY_DEFINITIONS (PR #141293)
@@ -99,3 +99,22 @@ @interface AnotherObject : NSObject { @property(nonatomic, strong) NSString *prop_string; // expected-warning@-1{{Property 'prop_string' in 'AnotherObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}} @end + +NS_REQUIRES_PROPERTY_DEFINITIONS +@interface NoSynthObject : NSObject { + NSString *ns_string; + // expected-warning@-1{{Instance variable 'ns_string' in 'NoSynthObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}} + CFStringRef cf_string; + // expected-warning@-1{{Instance variable 'cf_string' in 'NoSynthObject' is a retainable type 'CFStringRef'; member variables must be a RetainPtr}} +} +@property(nonatomic, readonly, strong) NSString *prop_string1; +@property(nonatomic, readonly, strong) NSString *prop_string2; ziqingluo-90 wrote: Similarly, would it make sense to also test for `@property(nonatomic, assign)` and `@property(nonatomic, unsafe_unretained)` https://github.com/llvm/llvm-project/pull/141293 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [alpha.webkit.NoUnretainedMemberChecker] Recognize NS_REQUIRES_PROPERTY_DEFINITIONS (PR #141293)
@@ -64,3 +64,33 @@ void forceTmplToInstantiate(FooTmpl) {} }; } // namespace ptr_to_ptr_to_retained + +@interface AnotherObject : NSObject { + NSString *ns_string; + CFStringRef cf_string; + // expected-warning@-1{{Instance variable 'cf_string' in 'AnotherObject' is a retainable type 'CFStringRef'; member variables must be a RetainPtr}} +} +@property(nonatomic, strong) NSString *prop_string1; +@property(nonatomic, assign) NSString *prop_string2; +// expected-warning@-1{{Property 'prop_string2' in 'AnotherObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}} +@property(nonatomic, unsafe_unretained) NSString *prop_string3; +// expected-warning@-1{{Property 'prop_string3' in 'AnotherObject' is a raw pointer to retainable type 'NSString'; member variables must be a RetainPtr}} +@property(nonatomic, readonly) NSString *prop_string4; +@end + +NS_REQUIRES_PROPERTY_DEFINITIONS +@interface NoSynthObject : NSObject { + NSString *ns_string; + CFStringRef cf_string; + // expected-warning@-1{{Instance variable 'cf_string' in 'NoSynthObject' is a retainable type 'CFStringRef'; member variables must be a RetainPtr}} +} +@property(nonatomic, readonly, strong) NSString *prop_string1; +@property(nonatomic, readonly, strong) NSString *prop_string2; ziqingluo-90 wrote: Would it make sense to also test for `@property(nonatomic, assign)` and `@property(nonatomic, unsafe_unretained)`, like what you did few lines the above? https://github.com/llvm/llvm-project/pull/141293 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [alpha.webkit.NoUnretainedMemberChecker] Recognize NS_REQUIRES_PROPERTY_DEFINITIONS (PR #141293)
ziqingluo-90 wrote: Overall, I think the change aligns with what you described. I've just left a few questions to clarify my understanding. https://github.com/llvm/llvm-project/pull/141293 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Reduce TemplateDeclInstantiator size. (PR #142983)
https://github.com/hokein updated https://github.com/llvm/llvm-project/pull/142983 >From 61be4bfea92d52cfc3e48a3cabb1bc80cbebb7fa Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 5 Jun 2025 15:38:58 +0200 Subject: [PATCH 1/2] [clang] Reduce TemplateDeclInstantiator size. --- clang/include/clang/Sema/Template.h| 4 ++-- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Sema/Template.h b/clang/include/clang/Sema/Template.h index af0c1e8506cf3..0c68ad9b9d90a 100644 --- a/clang/include/clang/Sema/Template.h +++ b/clang/include/clang/Sema/Template.h @@ -587,7 +587,7 @@ enum class TemplateSubstitutionKind : char { /// specializations that will need to be instantiated after the /// enclosing class's instantiation is complete. SmallVector, 4> +ClassTemplatePartialSpecializationDecl *>, 1> OutOfLinePartialSpecs; /// A list of out-of-line variable template partial @@ -595,7 +595,7 @@ enum class TemplateSubstitutionKind : char { /// enclosing variable's instantiation is complete. /// FIXME: Verify that this is needed. SmallVector< -std::pair, 4> +std::pair, 1> OutOfLineVarPartialSpecs; public: diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index bcad815e1587f..7da09b149446a 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2394,7 +2394,7 @@ Decl *TemplateDeclInstantiator::VisitVarTemplateDecl(VarTemplateDecl *D) { // Queue up any out-of-line partial specializations of this member // variable template; the client will force their instantiation once // the enclosing class has been instantiated. -SmallVector PartialSpecs; +SmallVector PartialSpecs; D->getPartialSpecializations(PartialSpecs); for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) if (PartialSpecs[I]->getFirstDecl()->isOutOfLine()) >From 77ecc3b6362ab9b844f4b4393b839e9b3e57175b Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 6 Jun 2025 09:10:08 +0200 Subject: [PATCH 2/2] clang-format --- clang/include/clang/Sema/Template.h | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Sema/Template.h b/clang/include/clang/Sema/Template.h index 0c68ad9b9d90a..fe907078af275 100644 --- a/clang/include/clang/Sema/Template.h +++ b/clang/include/clang/Sema/Template.h @@ -587,8 +587,9 @@ enum class TemplateSubstitutionKind : char { /// specializations that will need to be instantiated after the /// enclosing class's instantiation is complete. SmallVector, 1> - OutOfLinePartialSpecs; + ClassTemplatePartialSpecializationDecl *>, +1> +OutOfLinePartialSpecs; /// A list of out-of-line variable template partial /// specializations that will need to be instantiated after the @@ -596,7 +597,7 @@ enum class TemplateSubstitutionKind : char { /// FIXME: Verify that this is needed. SmallVector< std::pair, 1> -OutOfLineVarPartialSpecs; +OutOfLineVarPartialSpecs; public: TemplateDeclInstantiator(Sema &SemaRef, DeclContext *Owner, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CFG] Fix assertion failure in checkIncorrectLogicOperator (PR #142897)
@@ -1261,6 +1261,28 @@ class CFGBuilder { L2Result.Val.getKind() == APValue::Float) { llvm::APFloat L1 = L1Result.Val.getFloat(); llvm::APFloat L2 = L2Result.Val.getFloat(); + // Note that L1 and L2 do not necessarily have the same type. For example + // `x != 0 || x != 1.0`, if `x` is a float16, the two literals `0` and + // `1.0` are float16 and double respectively. In this case, we should do + // a conversion before comparing L1 and L2. Their types must be + // compatible since they are comparing with the same DRE. + int8_t Order = Context->getFloatingTypeOrder(NumExpr1->getType(), + NumExpr2->getType()); + bool convertLoseInfo = false; + + if (Order > 0) { +// type rank L1 > L2: +if (L2.convert(L1.getSemantics(), llvm::APFloat::rmNearestTiesToEven, + &convertLoseInfo)) + return {}; ziqingluo-90 wrote: This branch is for failed conversions, so it no longer matters whether it loses info. https://github.com/llvm/llvm-project/pull/142897 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][PAC] add support for options parameter to __ptrauth (PR #136828)
https://github.com/ojhunt updated https://github.com/llvm/llvm-project/pull/136828 >From 927380bdf377581e6e40507a12c374023352c613 Mon Sep 17 00:00:00 2001 From: Oliver Hunt Date: Wed, 30 Apr 2025 22:26:59 -0700 Subject: [PATCH 1/6] [clang][PAC] add support for options parameter to __ptrauth This PR adds support for an 'options' parameter for the __ptrauth qualifier. The initial version only exposes the authehntication modes: * "strip" * "sign-and-strip" * "sign-and-auth" We also support parsing the options but not yet the implementation * "isa-pointer" * "authenticates-null-values" The initial support for authentication mode controls exist to support ABI changes over time, and as a byproduct support basic initial tests for option parsing. --- clang/include/clang/Basic/Attr.td | 6 +- .../clang/Basic/DiagnosticParseKinds.td | 4 +- .../clang/Basic/DiagnosticSemaKinds.td| 13 +- clang/include/clang/Basic/LangOptions.h | 11 + clang/lib/CodeGen/CGExprConstant.cpp | 24 +- clang/lib/Parse/ParseDecl.cpp | 2 +- clang/lib/Sema/SemaType.cpp | 155 - clang/test/CodeGen/ptrauth-stripping.c| 327 ++ clang/test/Parser/ptrauth-qualifier.c | 2 +- clang/test/Sema/ptrauth-qualifier-options.c | 65 clang/test/Sema/ptrauth-qualifier.c | 39 ++- .../ptrauth-qualifier-constexpr-options.cpp | 65 12 files changed, 683 insertions(+), 30 deletions(-) create mode 100644 clang/test/CodeGen/ptrauth-stripping.c create mode 100644 clang/test/Sema/ptrauth-qualifier-options.c create mode 100644 clang/test/SemaCXX/ptrauth-qualifier-constexpr-options.cpp diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 06462b8a26bc0..ec4b869d50ba5 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3606,9 +3606,9 @@ def ObjCRequiresPropertyDefs : InheritableAttr { def PointerAuth : TypeAttr { let Spellings = [CustomKeyword<"__ptrauth">]; - let Args = [IntArgument<"Key">, - BoolArgument<"AddressDiscriminated", 1>, - IntArgument<"ExtraDiscriminator", 1>]; + let Args = [IntArgument<"Key">, BoolArgument<"AddressDiscriminated", 1>, + IntArgument<"ExtraDiscriminator", 1>, + StringArgument<"Options", 1>]; let Documentation = [PtrAuthDocs]; } diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index fd525140d0482..ca5155c70fee5 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -1736,8 +1736,8 @@ def warn_pragma_unroll_cuda_value_in_parens : Warning< "argument to '#pragma unroll' should not be in parentheses in CUDA C/C++">, InGroup; -def err_ptrauth_qualifier_bad_arg_count : Error< - "'__ptrauth' qualifier must take between 1 and 3 arguments">; +def err_ptrauth_qualifier_bad_arg_count +: Error<"'__ptrauth' qualifier must take between 1 and 4 arguments">; def warn_cuda_attr_lambda_position : Warning< "nvcc does not allow '__%0__' to appear after the parameter list in lambdas">, diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 78b36ceb88125..57a9b4cb6e148 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1047,6 +1047,18 @@ def err_ptrauth_extra_discriminator_invalid : Error< "invalid extra discriminator flag '%0'; '__ptrauth' requires a value between " "'0' and '%1'">; +// __ptrauth qualifier options string +def note_ptrauth_evaluating_options +: Note<"options parameter evaluated to '%0'">; +def err_ptrauth_invalid_option : Error<"'__ptrauth' options parameter %0">; +def err_ptrauth_unknown_authentication_option +: Error<"unknown '__ptrauth' authentication option '%0'">; +def err_ptrauth_repeated_authentication_option +: Error<"repeated '__ptrauth' authentication %select{mode|option}0%select{, prior " +"mode was '%2'| '%1'}0">; +def err_ptrauth_option_missing_comma +: Error<"missing comma after '%0' option in '__ptrauth' qualifier">; + /// main() // static main() is not an error in C, just in C++. def warn_static_main : Warning<"'main' should not be declared static">, @@ -1737,7 +1749,6 @@ def err_static_assert_requirement_failed : Error< def note_expr_evaluates_to : Note< "expression evaluates to '%0 %1 %2'">; - def subst_user_defined_msg : TextSubstitution< "%select{the message|the expression}0 in " "%select{a static assertion|this asm operand}0">; diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 491e8bee9fd5c..3944946374d30 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -65,6 +65,17 @@ enum class
[clang] Added TypeKind.FLOAT16 for 32 in cindex.py (PR #142634)
DeinAlptraum wrote: Great, thank you! > IMHO: I guess a relevant test case is to take some huge relevant project, > maybe LLVM itself and parse all their files and walk through all the nodes of > the ast through all the members/methods recursively The problem is that this depends on the functionality you're testing, e.g. in this case, just walking the entire Clang AST would not have been enough to detect the issue, you would have had to call `cursor.type.kind` for every node. And at that point, you might as well compare the possible to the mapped kinds directly. https://github.com/llvm/llvm-project/pull/142634 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fail the constraint substitution early after CWG2369 (PR #143096)
https://github.com/zyn0217 created https://github.com/llvm/llvm-project/pull/143096 CWG2369 revealed another case where we were SFINAE'ing out the invalid result of substitution, but the expression now makes into evaluation. We switch to the concept specialization's context before we check it. This ensures that we're able to realize the invalid expression earlier, so we can avoid evaluating invalid expression, which is a hard error. >From 020160fde7a3cc13b104a5f5577a8037cf412c66 Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Fri, 6 Jun 2025 17:09:08 +0800 Subject: [PATCH] [Clang] Fail the constraint substitution early after CWG2369 CWG2369 revealed another case where we were SFINAE'ing out the invalid result of substitution, but the expression now makes into evaluation. We switch to the concept specialization's context before we check it. This ensures that we're able to realize the invalid expression earlier, so we can avoid evaluating invalid expression, which is a hard error. --- clang/lib/Sema/SemaTemplate.cpp | 2 ++ clang/test/SemaTemplate/concepts.cpp | 31 2 files changed, 33 insertions(+) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 1d8fea1d72008..ccc532e1fd3de 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -4749,6 +4749,8 @@ Sema::CheckConceptTemplateId(const CXXScopeSpec &SS, EnterExpressionEvaluationContext EECtx{ *this, ExpressionEvaluationContext::Unevaluated, CSD}; + ContextRAII CurContext(*this, CSD->getDeclContext(), + /*NewThisContext=*/false); if (!AreArgsDependent && CheckConstraintSatisfaction( NamedConcept, AssociatedConstraint(NamedConcept->getConstraintExpr()), diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp index 3e50a8bce24af..abfc14de9bc75 100644 --- a/clang/test/SemaTemplate/concepts.cpp +++ b/clang/test/SemaTemplate/concepts.cpp @@ -1200,3 +1200,34 @@ bool test_val_types() { } } + +namespace CWG2369_Regression { + +enum class KindEnum { + Unknown = 0, + Foo = 1, +}; + +template +concept KnownKind = T::kind() != KindEnum::Unknown; + +template struct KnownType; + +struct Type { + KindEnum kind() const; + + static Type f(Type t); + + template static KnownType f(T t); + + static void g() { +Type t; +f(t); + } +}; + +template struct KnownType { + static constexpr KindEnum kind() { return KindEnum::Foo; } +}; + +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add AllowFalseEvaluated flag to clang-tidy noexcept-move-constructor check (PR #126897)
@@ -0,0 +1,46 @@ +// RUN: %check_clang_tidy -check-suffix=CONFIG %s performance-noexcept-move-constructor,performance-noexcept-destructor %t -- \ +// RUN: -config="{CheckOptions: {performance-noexcept-move-constructor.AllowFalseEvaluated: true}}" \ +// RUN: -- -fexceptions + +namespace std +{ + template + struct is_nothrow_move_constructible + { +static constexpr bool value = __is_nothrow_constructible(T, __add_rvalue_reference(T)); + }; +} // namespace std + +struct ThrowOnAnything { + ThrowOnAnything() noexcept(false); + ThrowOnAnything(ThrowOnAnything&&) noexcept(false); + ThrowOnAnything& operator=(ThrowOnAnything &&) noexcept(false); + ~ThrowOnAnything() noexcept(false); +}; + +struct C_1 { +static constexpr bool kFalse = false; +C_1(C_1&&) noexcept(kFalse) = default; +C_1 &operator=(C_1 &&) noexcept(kFalse); +}; + +struct C_2 { +static constexpr bool kEval = std::is_nothrow_move_constructible::value; +static_assert(!kEval); // kEval == false; + +C_2(C_2&&) noexcept(kEval) = default; +C_2 &operator=(C_2 &&) noexcept(kEval); + +ThrowOnAnything field; +}; + +struct C_3 { +static constexpr bool kEval = std::is_nothrow_move_constructible::value; +static_assert(!kEval); // kEval == false; + +C_3(C_3&&) noexcept(kEval) = default; +~C_3() noexcept(kEval) = default; +// CHECK-MESSAGES-CONFIG: :[[@LINE-1]]:21: warning: noexcept specifier on the destructor evaluates to 'false' + +ThrowOnAnything field; +}; Nechda wrote: I'm sorry, I don't quite understand what test case you are referring to. It looks like the default behavior of this check is already covered by another test case. https://github.com/llvm/llvm-project/blob/a663e78a6eb6bbd20c0c74b3e6a78e24ee423544/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp After the test simplification, only one line should be displayed in the output if the option in the config is enabled. https://github.com/llvm/llvm-project/pull/126897 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Control analysis-based diagnostics with #pragma (PR #136323)
@@ -16597,7 +16597,8 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, BD->setCaptures(Context, Captures, BSI->CXXThisCaptureIndex != 0); // Pop the block scope now but keep it alive to the end of this function. - AnalysisBasedWarnings::Policy WP = AnalysisWarnings.getDefaultPolicy(); + AnalysisBasedWarnings::Policy WP = + AnalysisWarnings.getPolicyInEffectAt(Body->getEndLoc()); steakhal wrote: I think the statement `BD->setBody(cast(Body));` dominates all checks to `Body`, consequently, I don't think `Body` can be null. I'd say, the checks for `Body` are redundant. https://github.com/llvm/llvm-project/pull/136323 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Reapply CWG2369 "Ordering between constraints and substitution" (PR #122423)
zyn0217 wrote: @rupprecht I sent out https://github.com/llvm/llvm-project/pull/143096 for the fix :) https://github.com/llvm/llvm-project/pull/122423 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add check for -mstack-alignment (PR #143124)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Feng Zou (fzou1) Changes An error message will be emitted if the wrong value is passed to -mstack-alignment option. --- Full diff: https://github.com/llvm/llvm-project/pull/143124.diff 2 Files Affected: - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+11-3) - (added) clang/test/Driver/stack-alignment.c (+11) ``diff diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 80dd72a23a673..290c10e5ea6cb 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7047,9 +7047,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.addOptInFlag(CmdArgs, options::OPT_mstackrealign, options::OPT_mno_stackrealign); - if (Args.hasArg(options::OPT_mstack_alignment)) { -StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment); -CmdArgs.push_back(Args.MakeArgString("-mstack-alignment=" + alignment)); + if (const Arg *A = Args.getLastArg(options::OPT_mstack_alignment)) { +StringRef Value = A->getValue(); +int64_t Alignment = 0; +if (Value.getAsInteger(10, Alignment) || Alignment < 0) + D.Diag(diag::err_drv_invalid_argument_to_option) + << Value << A->getOption().getName(); +else if (Alignment & (Alignment - 1)) + D.Diag(diag::err_drv_alignment_not_power_of_two) + << A->getAsString(Args) << Value; +else + CmdArgs.push_back(Args.MakeArgString("-mstack-alignment=" + Value)); } if (Args.hasArg(options::OPT_mstack_probe_size)) { diff --git a/clang/test/Driver/stack-alignment.c b/clang/test/Driver/stack-alignment.c new file mode 100644 index 0..e1e62c05c32ab --- /dev/null +++ b/clang/test/Driver/stack-alignment.c @@ -0,0 +1,11 @@ +// RUN: not %clang -### -mstack-alignment=-1 %s 2>&1 | FileCheck %s --check-prefix=CHECK_NEG_1 +// RUN: %clang -### -mstack-alignment=0 %s 2>&1 | FileCheck %s --check-prefix=CHECK_0 +// RUN: %clang -### -mstack-alignment=1 %s 2>&1 | FileCheck %s --check-prefix=CHECK_1 +// RUN: %clang -### -mstack-alignment=4 %s 2>&1 | FileCheck %s --check-prefix=CHECK_4 +// RUN: not %clang -### -mstack-alignment=5 %s 2>&1 | FileCheck %s --check-prefix=CHECK_5 + +// CHECK_NEG_1: error: invalid argument '-1' to -mstack-alignment= +// CHECK_0: -mstack-alignment=0 +// CHECK_1: -mstack-alignment=1 +// CHECK_4: -mstack-alignment=4 +// CHECK_5: error: alignment is not a power of 2 in '-mstack-alignment=5' `` https://github.com/llvm/llvm-project/pull/143124 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add check for -mstack-alignment (PR #143124)
https://github.com/fzou1 edited https://github.com/llvm/llvm-project/pull/143124 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add check for -mstack-alignment (PR #143124)
https://github.com/fzou1 created https://github.com/llvm/llvm-project/pull/143124 An error message will be emitted if the wrong value is passed to -mstack-alignment option. >From 688405f851d3685e588b4797314377a1d5d5c124 Mon Sep 17 00:00:00 2001 From: Feng Zou Date: Fri, 6 Jun 2025 18:21:30 +0800 Subject: [PATCH] [Driver] Add check for -mstack-alignment An error message will be emitted if the wrong value is passed to -mstack-alignment option. --- clang/lib/Driver/ToolChains/Clang.cpp | 14 +++--- clang/test/Driver/stack-alignment.c | 11 +++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 clang/test/Driver/stack-alignment.c diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 80dd72a23a673..290c10e5ea6cb 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7047,9 +7047,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.addOptInFlag(CmdArgs, options::OPT_mstackrealign, options::OPT_mno_stackrealign); - if (Args.hasArg(options::OPT_mstack_alignment)) { -StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment); -CmdArgs.push_back(Args.MakeArgString("-mstack-alignment=" + alignment)); + if (const Arg *A = Args.getLastArg(options::OPT_mstack_alignment)) { +StringRef Value = A->getValue(); +int64_t Alignment = 0; +if (Value.getAsInteger(10, Alignment) || Alignment < 0) + D.Diag(diag::err_drv_invalid_argument_to_option) + << Value << A->getOption().getName(); +else if (Alignment & (Alignment - 1)) + D.Diag(diag::err_drv_alignment_not_power_of_two) + << A->getAsString(Args) << Value; +else + CmdArgs.push_back(Args.MakeArgString("-mstack-alignment=" + Value)); } if (Args.hasArg(options::OPT_mstack_probe_size)) { diff --git a/clang/test/Driver/stack-alignment.c b/clang/test/Driver/stack-alignment.c new file mode 100644 index 0..e1e62c05c32ab --- /dev/null +++ b/clang/test/Driver/stack-alignment.c @@ -0,0 +1,11 @@ +// RUN: not %clang -### -mstack-alignment=-1 %s 2>&1 | FileCheck %s --check-prefix=CHECK_NEG_1 +// RUN: %clang -### -mstack-alignment=0 %s 2>&1 | FileCheck %s --check-prefix=CHECK_0 +// RUN: %clang -### -mstack-alignment=1 %s 2>&1 | FileCheck %s --check-prefix=CHECK_1 +// RUN: %clang -### -mstack-alignment=4 %s 2>&1 | FileCheck %s --check-prefix=CHECK_4 +// RUN: not %clang -### -mstack-alignment=5 %s 2>&1 | FileCheck %s --check-prefix=CHECK_5 + +// CHECK_NEG_1: error: invalid argument '-1' to -mstack-alignment= +// CHECK_0: -mstack-alignment=0 +// CHECK_1: -mstack-alignment=1 +// CHECK_4: -mstack-alignment=4 +// CHECK_5: error: alignment is not a power of 2 in '-mstack-alignment=5' ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in ExprCXX (PR #143125)
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/143125 None >From a2dc54aae78b395574e071f46dcc55dfbf6825cc Mon Sep 17 00:00:00 2001 From: Rahul Joshi Date: Mon, 19 May 2025 10:25:19 -0700 Subject: [PATCH] [NFC][Clang] Adopt simplified `getTrailingObjects` in ExprCXX --- clang/include/clang/AST/ExprCXX.h | 54 +-- clang/lib/AST/ExprCXX.cpp | 10 +++--- 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 4c9636f990db0..477373f07f25d 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -1290,7 +1290,7 @@ class CXXDefaultArgExpr final CXXDefaultArgExprBits.Loc = Loc; CXXDefaultArgExprBits.HasRewrittenInit = RewrittenExpr != nullptr; if (RewrittenExpr) - *getTrailingObjects() = RewrittenExpr; + *getTrailingObjects() = RewrittenExpr; setDependence(computeDependence(this)); } @@ -1323,7 +1323,7 @@ class CXXDefaultArgExpr final } Expr *getRewrittenExpr() { -return hasRewrittenInit() ? *getTrailingObjects() : nullptr; +return hasRewrittenInit() ? *getTrailingObjects() : nullptr; } const Expr *getRewrittenExpr() const { @@ -1421,14 +1421,14 @@ class CXXDefaultInitExpr final /// any. const Expr *getRewrittenExpr() const { assert(hasRewrittenInit() && "expected a rewritten init expression"); -return *getTrailingObjects(); +return *getTrailingObjects(); } /// Retrieve the initializing expression with evaluated immediate calls, if /// any. Expr *getRewrittenExpr() { assert(hasRewrittenInit() && "expected a rewritten init expression"); -return *getTrailingObjects(); +return *getTrailingObjects(); } const DeclContext *getUsedContext() const { return UsedContext; } @@ -1982,8 +1982,8 @@ class LambdaExpr final : public Expr, /// Construct an empty lambda expression. LambdaExpr(EmptyShell Empty, unsigned NumCaptures); - Stmt **getStoredStmts() { return getTrailingObjects(); } - Stmt *const *getStoredStmts() const { return getTrailingObjects(); } + Stmt **getStoredStmts() { return getTrailingObjects(); } + Stmt *const *getStoredStmts() const { return getTrailingObjects(); } void initBodyIfNeeded() const; @@ -3621,7 +3621,7 @@ class ExprWithCleanups final ArrayRef objects); ArrayRef getObjects() const { -return getTrailingObjects(getNumObjects()); +return getTrailingObjects(getNumObjects()); } unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } @@ -3742,14 +3742,14 @@ class CXXUnresolvedConstructExpr final using arg_iterator = Expr **; using arg_range = llvm::iterator_range; - arg_iterator arg_begin() { return getTrailingObjects(); } + arg_iterator arg_begin() { return getTrailingObjects(); } arg_iterator arg_end() { return arg_begin() + getNumArgs(); } arg_range arguments() { return arg_range(arg_begin(), arg_end()); } using const_arg_iterator = const Expr* const *; using const_arg_range = llvm::iterator_range; - const_arg_iterator arg_begin() const { return getTrailingObjects(); } + const_arg_iterator arg_begin() const { return getTrailingObjects(); } const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); } const_arg_range arguments() const { return const_arg_range(arg_begin(), arg_end()); @@ -3860,10 +3860,6 @@ class CXXDependentScopeMemberExpr final return getNumTemplateArgs(); } - unsigned numTrailingObjects(OverloadToken) const { -return hasFirstQualifierFoundInScope(); - } - CXXDependentScopeMemberExpr(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, @@ -4419,7 +4415,7 @@ class SizeOfPackExpr final Length(Length ? *Length : PartialArgs.size()), Pack(Pack) { assert((!Length || PartialArgs.empty()) && "have partial args for non-dependent sizeof... expression"); -auto *Args = getTrailingObjects(); +auto *Args = getTrailingObjects(); llvm::uninitialized_copy(PartialArgs, Args); setDependence(Length ? ExprDependence::None : ExprDependence::ValueInstantiation); @@ -4472,8 +4468,7 @@ class SizeOfPackExpr final /// Get ArrayRef getPartialArguments() const { assert(isPartiallySubstituted()); -const auto *Args = getTrailingObjects(); -return llvm::ArrayRef(Args, Args + Length); +return getTrailingObjects(Length); } SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; } @@ -4517,8 +4512,7 @@ class PackIndexingExpr final SubExprs{PackIdExpr, IndexExpr} { PackIndexingExprBits.TransformedExpressions = SubstitutedExprs.size(); PackIndexingExprBits.FullySubstituted = FullySubstituted; -auto *Exprs = getTrailingObj
[clang] [clang][python][test] Move python binding tests to lit framework (PR #142948)
@@ -0,0 +1,22 @@ +def is_libclang_loadable(): +try: +sys.path.append(os.path.join(config.clang_src_dir, "bindings/python")) +from clang.cindex import Config +conf = Config() +Config.set_library_path(config.clang_lib_dir) +conf.lib +return True +except Exception as e: +# Benign error modes. +if "wrong ELF class: ELFCLASS32" in str(e): +return False +elif "No such file or directory" in str(e): +return False +# Unknown error modes. +else: +return True rorth wrote: The intent (and it worked for me) is as follows: - If `libclang.so` cannot be loaded, this can be for two reasons so far: - In a 32-bit build on a 64-bit system, the resulting 32-bit `libclang.so` cannot be loaded into the system's 64-bit `python`. This is as expected, nothing to be done about that, thus the lib is truely considered unloadable. - If `libclang.so` is missing completely, this must be because building it has been disabled somehow (probably with `-DLLVM_ENABLE_PIC=OFF`. Again, this is intentional and nothing to be done. - However, in other cases there may well be a bug lurking here. Consider (just for the sake of argument) a `libclang.so` matching `python`'s ELF class, but built with missing dependencies so it's not self-contained and cannot be loaded. This is simply a bug that could/should be fixed. Therefore, I return `True` for unknown/unhandled errors, which lets the test to `FAIL`, forcing investigation. The failure may be benign yet not currently handled, or there may be a real bug that needs fixing. If I always return `False` on a failure to load `libclang.so`, such bugs would go unnoticed. https://github.com/llvm/llvm-project/pull/142948 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Non-polymorphic trivially relocatable types can have [[trivial_abi]] (PR #143111)
https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/143111 >From d4e5db938e4af98dda2dd4b518273fe339c64bfa Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Fri, 6 Jun 2025 13:09:40 +0200 Subject: [PATCH] [Clang] Non-polymorphic trivially relocatable types can have [[trivial_abi]] Use the definition of trivially relocatable types to short circuit some checks for trivial_abi. Note that this is mostly a no-op as there is a lot of overlap between trivial_abi and trivial relocatability (ie I can't envision a scenario in which there would be a trivially relocatable type that would not be eligible for trivial_abi based on its special member function... which is good!) Note that for bases and members we need to check CanPassInRegister rather than just relocation. So we do these checks first, which leads to better diagnostics. --- clang/include/clang/Sema/Sema.h | 1 + clang/lib/Sema/SemaDeclCXX.cpp| 49 --- clang/lib/Sema/SemaTypeTraits.cpp | 12 +++--- clang/test/SemaCXX/attr-trivial-abi.cpp | 16 +--- clang/test/SemaObjCXX/attr-trivial-abi.mm | 3 +- 5 files changed, 46 insertions(+), 35 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 65c84c0c40f60..88db3f5de7486 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -8680,6 +8680,7 @@ class Sema final : public SemaBase { // FIXME: This is in Sema because it requires // overload resolution, can we move to ASTContext? bool IsCXXTriviallyRelocatableType(QualType T); + bool IsCXXTriviallyRelocatableType(const CXXRecordDecl &RD); Determines if a type is replaceable /// according to the C++26 rules. diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 55e078f3180a2..190544e9e1cd3 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -10572,29 +10572,6 @@ void Sema::checkIllFormedTrivialABIStruct(CXXRecordDecl &RD) { RD.dropAttr(); }; - // Ill-formed if the copy and move constructors are deleted. - auto HasNonDeletedCopyOrMoveConstructor = [&]() { -// If the type is dependent, then assume it might have -// implicit copy or move ctor because we won't know yet at this point. -if (RD.isDependentType()) - return true; -if (RD.needsImplicitCopyConstructor() && -!RD.defaultedCopyConstructorIsDeleted()) - return true; -if (RD.needsImplicitMoveConstructor() && -!RD.defaultedMoveConstructorIsDeleted()) - return true; -for (const CXXConstructorDecl *CD : RD.ctors()) - if (CD->isCopyOrMoveConstructor() && !CD->isDeleted()) -return true; -return false; - }; - - if (!HasNonDeletedCopyOrMoveConstructor()) { -PrintDiagAndRemoveAttr(0); -return; - } - // Ill-formed if the struct has virtual functions. if (RD.isPolymorphic()) { PrintDiagAndRemoveAttr(1); @@ -10638,6 +10615,32 @@ void Sema::checkIllFormedTrivialABIStruct(CXXRecordDecl &RD) { return; } } + + if (IsCXXTriviallyRelocatableType(RD)) +return; + + // Ill-formed if the copy and move constructors are deleted. + auto HasNonDeletedCopyOrMoveConstructor = [&]() { +// If the type is dependent, then assume it might have +// implicit copy or move ctor because we won't know yet at this point. +if (RD.isDependentType()) + return true; +if (RD.needsImplicitCopyConstructor() && +!RD.defaultedCopyConstructorIsDeleted()) + return true; +if (RD.needsImplicitMoveConstructor() && +!RD.defaultedMoveConstructorIsDeleted()) + return true; +for (const CXXConstructorDecl *CD : RD.ctors()) + if (CD->isCopyOrMoveConstructor() && !CD->isDeleted()) +return true; +return false; + }; + + if (!HasNonDeletedCopyOrMoveConstructor()) { +PrintDiagAndRemoveAttr(0); +return; + } } void Sema::checkIncorrectVTablePointerAuthenticationAttribute( diff --git a/clang/lib/Sema/SemaTypeTraits.cpp b/clang/lib/Sema/SemaTypeTraits.cpp index b849bbe94af62..865a460a97458 100644 --- a/clang/lib/Sema/SemaTypeTraits.cpp +++ b/clang/lib/Sema/SemaTypeTraits.cpp @@ -295,13 +295,13 @@ Sema::CheckCXX2CRelocatableAndReplaceable(const CXXRecordDecl *D) { return Info; } -static bool IsCXXTriviallyRelocatableType(Sema &S, const CXXRecordDecl *RD) { +bool Sema::IsCXXTriviallyRelocatableType(const CXXRecordDecl &RD) { if (std::optional Info = - S.getASTContext().getRelocationInfoForCXXRecord(RD)) + getASTContext().getRelocationInfoForCXXRecord(&RD)) return Info->IsRelocatable; ASTContext::CXXRecordDeclRelocationInfo Info = - S.CheckCXX2CRelocatableAndReplaceable(RD); - S.getASTContext().setRelocationInfoForCXXRecord(RD, Info); + CheckCXX2CRelocatableAndReplaceable(&RD); + getASTContext().setRelocationInfoForCXXRecord(&RD, Info); return Info.IsRelocatable; } @@
[clang] [analyzer][NFCI] Remove ad-hoc program point tagging (PR #142980)
NagyDonat wrote: The validation on our set of open source projects was successful, I'm merging this now. https://github.com/llvm/llvm-project/pull/142980 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] b80024e - [analyzer][NFCI] Remove ad-hoc program point tagging (#142980)
Author: Donát Nagy Date: 2025-06-06T14:34:47+02:00 New Revision: b80024e0f4bea449f5c1373436cd61096dd6613b URL: https://github.com/llvm/llvm-project/commit/b80024e0f4bea449f5c1373436cd61096dd6613b DIFF: https://github.com/llvm/llvm-project/commit/b80024e0f4bea449f5c1373436cd61096dd6613b.diff LOG: [analyzer][NFCI] Remove ad-hoc program point tagging (#142980) Previously some checkers attached explicitly created program point tags to some of the exploded graph nodes that they created. In most of the checkers this ad-hoc tagging only affected the debug dump of the exploded graph (and they weren't too relevant for debugging) so this commit removes them. There were two checkers where the tagging _did_ have a functional role: - In `RetainCountChecker` the presence of tags were checked by `RefCountReportVisitor`. - In `DynamicTypePropagation` the checker sometimes wanted to create two identical nodes and had to apply an explicit tag on the second one to avoid "caching out". In these two situations I preserved the tags but switched to using `SimpleProgramPointTag` instead of `CheckerProgramPointTag` because `CheckerProgramPointTag` didn't provide enough benefits to justify its existence. Note that this commit depends on the earlier commit "[analyzer] Fix tagging of PostAllocatorCall" ec96c0c072ef3f78813c378949c00e1c07aa44e5 and would introduce crashes when cherry-picked onto a branch that doesn't contain that commit. For more details about the background see the discourse thread https://discourse.llvm.org/t/role-of-programpointtag-in-the-static-analyzer/ As a tangentially related changes, this commit also adds some comments to document the surprising behavior of `CheckerContext::addTransition` and an assertion in the constructor of `PathSensitiveBugReport` to get a more readable crash dump in the case when the report is constructed with `nullptr` as the `ErrorNode`. (This can happen due to "caching out".) Added: Modified: clang/include/clang/StaticAnalyzer/Core/Checker.h clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h clang/lib/StaticAnalyzer/Core/BugReporter.cpp clang/lib/StaticAnalyzer/Core/Checker.cpp Removed: diff --git a/clang/include/clang/StaticAnalyzer/Core/Checker.h b/clang/include/clang/StaticAnalyzer/Core/Checker.h index c6866cb561551..31cc095c29bfe 100644 --- a/clang/include/clang/StaticAnalyzer/Core/Checker.h +++ b/clang/include/clang/StaticAnalyzer/Core/Checker.h @@ -608,20 +608,6 @@ class EventDispatcher { } }; -/// Tag that can use a checker name as a message provider -/// (see SimpleProgramPointTag). -/// FIXME: This is a cargo cult class which is copied into several checkers but -/// does not provide anything useful. -/// The only added functionality provided by this class (compared to -/// SimpleProgramPointTag) is that it composes the tag description string from -/// two arguments -- but tag descriptions only appear in debug output so there -/// is no reason to bother with this. -class CheckerProgramPointTag : public SimpleProgramPointTag { -public: - CheckerProgramPointTag(StringRef CheckerName, StringRef Msg); - CheckerProgramPointTag(const CheckerBase *Checker, StringRef Msg); -}; - /// We dereferenced a location that may be null. struct ImplicitNullDerefEvent { SVal Location; diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h index aad71299ccdc1..f20b0031c1528 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h @@ -171,6 +171,9 @@ class CheckerContext { ///tag is specified, a default tag, unique to the given checker, ///will be used. Tags are used to prevent states generated at /// diff erent sites from caching out. + /// NOTE: If the State is unchanged and the Tag is nullptr, this may return a + /// node which is not tagged (instead of using the default tag corresponding + /// to the active checker). This is arguably a bug and should be fixed. ExplodedNode *addTransition(ProgramStateRef State = nullptr,
[clang] [clang][python][test] Move python binding tests to lit framework (PR #142948)
rorth wrote: > @rorth have you tested that your `is_libclang_loadable` works as intended > w.r.t the "Benign error modes"? Do correct me if I made a mistake here, but I > just tried testing this by manually adding `raise Exception("wrong ELF class: > ELFCLASS32")` at the start of `get_cindex_library` and then running the tests > via `build/bin/llvm-lit clang/test/bindings/python`, and this just gives me a > regular `FAIL`. Adding some debugging statements into `is_libclang_loadable` > shows that the `except` block is never entered for some reason... As mentioned in the description, I've tested the patch in a variety of configurations: - Solaris/amd64 (where `libclang.so` matches `python`, causing the test to `PASS`) - Solaris/i386 (where the 32-bit `libclang.so` cannot be loaded into the system `python`, which causes the test to become `UNSUPPORTED`. - Similarly Solaris/sparcv9, Solaris/sparc, Linux/x86_64, Linux/i686 (and also, not mentioned above) Linux/sparc64 and Linux/sparc. Besides, I've manually moved `libclang.so` aside to test the `libclang` missing case. I've got no explanation why your explicit `raise` didn't come through (but then I known very little Python). https://github.com/llvm/llvm-project/pull/142948 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][SROA] Teach SROA how to "bitcast" between fixed and scalable vectors. (PR #130973)
https://github.com/nikic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/130973 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer][NFCI] Remove ad-hoc program point tagging (PR #142980)
https://github.com/NagyDonat closed https://github.com/llvm/llvm-project/pull/142980 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add check for -mstack-alignment (PR #143124)
https://github.com/fzou1 edited https://github.com/llvm/llvm-project/pull/143124 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Add WaveGetLaneCount() intrinsic to FE (PR #143127)
https://github.com/Keenuts created https://github.com/llvm/llvm-project/pull/143127 This commit adds code to lower WaveGetLaneCount() into the SPV or DXIL intrinsic. The backends will then need to lower the intrinsic into proper SPIR-V/DXIL. Related to #99159 From d47adb2f82940abcab87428f7ef09b326bfb42e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= Date: Fri, 6 Jun 2025 14:00:49 +0200 Subject: [PATCH] [HLSL] Add WaveGetLaneCount() intrinsic to FE This commit adds code to lower WaveGetLaneCount() into the SPV or DXIL intrinsic. The backends will then need to lower the intrinsic into proper SPIR-V/DXIL. Related to #99159 --- clang/include/clang/Basic/Builtins.td | 6 clang/lib/CodeGen/CGHLSLBuiltins.cpp | 5 +++ clang/lib/CodeGen/CGHLSLRuntime.h | 1 + .../lib/Headers/hlsl/hlsl_alias_intrinsics.h | 4 +++ .../builtins/wave_get_lane_count.hlsl | 32 +++ llvm/include/llvm/IR/IntrinsicsDirectX.td | 2 ++ llvm/include/llvm/IR/IntrinsicsSPIRV.td | 2 ++ 7 files changed, 52 insertions(+) create mode 100644 clang/test/CodeGenHLSL/builtins/wave_get_lane_count.hlsl diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index b15cde05410ab..68cd3d790e78a 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4909,6 +4909,12 @@ def HLSLWaveReadLaneAt : LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLWaveGetLaneCount : LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_wave_get_lane_count"]; + let Attributes = [NoThrow, Const]; + let Prototype = "unsigned int()"; +} + def HLSLClamp : LangBuiltin<"HLSL_LANG"> { let Spellings = ["__builtin_hlsl_elementwise_clamp"]; let Attributes = [NoThrow, Const, CustomTypeChecking]; diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp b/clang/lib/CodeGen/CGHLSLBuiltins.cpp index 10dd9fd04eb9e..abebc201808b0 100644 --- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp +++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp @@ -691,6 +691,11 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, return EmitRuntimeCall( Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID)); } + case Builtin::BI__builtin_hlsl_wave_get_lane_count: { +Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveGetLaneCountIntrinsic(); +return EmitRuntimeCall( +Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID)); + } case Builtin::BI__builtin_hlsl_wave_read_lane_at: { // Due to the use of variadic arguments we must explicitly retreive them and // create our function type. diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index f7ca2077a576b..bb2b82fa1f5aa 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -107,6 +107,7 @@ class CGHLSLRuntime { GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveAnyTrue, wave_any) GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveCountBits, wave_active_countbits) GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane) + GENERATE_HLSL_INTRINSIC_FUNCTION(WaveGetLaneCount, wave_get_lane_count) GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_readlane) GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitUHigh, firstbituhigh) GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitSHigh, firstbitshigh) diff --git a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h index 3835eb78cec50..74aabbdaad266 100644 --- a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h @@ -2350,6 +2350,10 @@ _HLSL_AVAILABILITY(shadermodel, 6.0) _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_is_first_lane) __attribute__((convergent)) bool WaveIsFirstLane(); +_HLSL_AVAILABILITY(shadermodel, 6.0) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_get_lane_count) +__attribute__((convergent)) bool WaveGetLaneCount(); + //===--===// // WaveReadLaneAt builtins //===--===// diff --git a/clang/test/CodeGenHLSL/builtins/wave_get_lane_count.hlsl b/clang/test/CodeGenHLSL/builtins/wave_get_lane_count.hlsl new file mode 100644 index 0..8072f6d4ea206 --- /dev/null +++ b/clang/test/CodeGenHLSL/builtins/wave_get_lane_count.hlsl @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ +// RUN: spirv-pc-vulkan-compute %s -emit-llvm -disable-llvm-passes -o - | \ +// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV +// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.3-compute %s -emit-llvm -disable-llvm-passes -o - | \ +// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DXIL + +[numthreads(1, 1, 1)] +void main() { + uint a, b; +// CHECK-SPIRV: %[[#entry_tok:]]
[clang] [llvm] [HLSL] Add WaveGetLaneCount() intrinsic to FE (PR #143127)
llvmbot wrote: @llvm/pr-subscribers-backend-x86 Author: Nathan Gauër (Keenuts) Changes This commit adds code to lower WaveGetLaneCount() into the SPV or DXIL intrinsic. The backends will then need to lower the intrinsic into proper SPIR-V/DXIL. Related to #99159 --- Full diff: https://github.com/llvm/llvm-project/pull/143127.diff 7 Files Affected: - (modified) clang/include/clang/Basic/Builtins.td (+6) - (modified) clang/lib/CodeGen/CGHLSLBuiltins.cpp (+5) - (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+1) - (modified) clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h (+4) - (added) clang/test/CodeGenHLSL/builtins/wave_get_lane_count.hlsl (+32) - (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+2) - (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (+2) ``diff diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index b15cde05410ab..68cd3d790e78a 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4909,6 +4909,12 @@ def HLSLWaveReadLaneAt : LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLWaveGetLaneCount : LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_wave_get_lane_count"]; + let Attributes = [NoThrow, Const]; + let Prototype = "unsigned int()"; +} + def HLSLClamp : LangBuiltin<"HLSL_LANG"> { let Spellings = ["__builtin_hlsl_elementwise_clamp"]; let Attributes = [NoThrow, Const, CustomTypeChecking]; diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp b/clang/lib/CodeGen/CGHLSLBuiltins.cpp index 10dd9fd04eb9e..abebc201808b0 100644 --- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp +++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp @@ -691,6 +691,11 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, return EmitRuntimeCall( Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID)); } + case Builtin::BI__builtin_hlsl_wave_get_lane_count: { +Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveGetLaneCountIntrinsic(); +return EmitRuntimeCall( +Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID)); + } case Builtin::BI__builtin_hlsl_wave_read_lane_at: { // Due to the use of variadic arguments we must explicitly retreive them and // create our function type. diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index f7ca2077a576b..bb2b82fa1f5aa 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -107,6 +107,7 @@ class CGHLSLRuntime { GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveAnyTrue, wave_any) GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveCountBits, wave_active_countbits) GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane) + GENERATE_HLSL_INTRINSIC_FUNCTION(WaveGetLaneCount, wave_get_lane_count) GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_readlane) GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitUHigh, firstbituhigh) GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitSHigh, firstbitshigh) diff --git a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h index 3835eb78cec50..74aabbdaad266 100644 --- a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h @@ -2350,6 +2350,10 @@ _HLSL_AVAILABILITY(shadermodel, 6.0) _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_is_first_lane) __attribute__((convergent)) bool WaveIsFirstLane(); +_HLSL_AVAILABILITY(shadermodel, 6.0) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_get_lane_count) +__attribute__((convergent)) bool WaveGetLaneCount(); + //===--===// // WaveReadLaneAt builtins //===--===// diff --git a/clang/test/CodeGenHLSL/builtins/wave_get_lane_count.hlsl b/clang/test/CodeGenHLSL/builtins/wave_get_lane_count.hlsl new file mode 100644 index 0..8072f6d4ea206 --- /dev/null +++ b/clang/test/CodeGenHLSL/builtins/wave_get_lane_count.hlsl @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ +// RUN: spirv-pc-vulkan-compute %s -emit-llvm -disable-llvm-passes -o - | \ +// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV +// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.3-compute %s -emit-llvm -disable-llvm-passes -o - | \ +// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DXIL + +[numthreads(1, 1, 1)] +void main() { + uint a, b; +// CHECK-SPIRV: %[[#entry_tok:]] = call token @llvm.experimental.convergence.entry() + +// CHECK-SPIRV: %[[#loop_tok:]] = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %[[#entry_tok]]) ] + while (a) { + +// CHECK-DXIL: %[[#]] = call i32 @llvm.dx.wave.get.lane.count() +// CHECK-SPIRV: %[[#]] = call spir_func i32 @llvm.spv.wave.get.lane.count() +// CHECK-SPIRV-SAME:
[clang] [llvm] [HLSL] Add WaveGetLaneCount() intrinsic to FE (PR #143127)
llvmbot wrote: @llvm/pr-subscribers-backend-directx Author: Nathan Gauër (Keenuts) Changes This commit adds code to lower WaveGetLaneCount() into the SPV or DXIL intrinsic. The backends will then need to lower the intrinsic into proper SPIR-V/DXIL. Related to #99159 --- Full diff: https://github.com/llvm/llvm-project/pull/143127.diff 7 Files Affected: - (modified) clang/include/clang/Basic/Builtins.td (+6) - (modified) clang/lib/CodeGen/CGHLSLBuiltins.cpp (+5) - (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+1) - (modified) clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h (+4) - (added) clang/test/CodeGenHLSL/builtins/wave_get_lane_count.hlsl (+32) - (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+2) - (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (+2) ``diff diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index b15cde05410ab..68cd3d790e78a 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4909,6 +4909,12 @@ def HLSLWaveReadLaneAt : LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLWaveGetLaneCount : LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_wave_get_lane_count"]; + let Attributes = [NoThrow, Const]; + let Prototype = "unsigned int()"; +} + def HLSLClamp : LangBuiltin<"HLSL_LANG"> { let Spellings = ["__builtin_hlsl_elementwise_clamp"]; let Attributes = [NoThrow, Const, CustomTypeChecking]; diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp b/clang/lib/CodeGen/CGHLSLBuiltins.cpp index 10dd9fd04eb9e..abebc201808b0 100644 --- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp +++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp @@ -691,6 +691,11 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, return EmitRuntimeCall( Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID)); } + case Builtin::BI__builtin_hlsl_wave_get_lane_count: { +Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveGetLaneCountIntrinsic(); +return EmitRuntimeCall( +Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID)); + } case Builtin::BI__builtin_hlsl_wave_read_lane_at: { // Due to the use of variadic arguments we must explicitly retreive them and // create our function type. diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index f7ca2077a576b..bb2b82fa1f5aa 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -107,6 +107,7 @@ class CGHLSLRuntime { GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveAnyTrue, wave_any) GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveCountBits, wave_active_countbits) GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane) + GENERATE_HLSL_INTRINSIC_FUNCTION(WaveGetLaneCount, wave_get_lane_count) GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_readlane) GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitUHigh, firstbituhigh) GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitSHigh, firstbitshigh) diff --git a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h index 3835eb78cec50..74aabbdaad266 100644 --- a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h @@ -2350,6 +2350,10 @@ _HLSL_AVAILABILITY(shadermodel, 6.0) _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_is_first_lane) __attribute__((convergent)) bool WaveIsFirstLane(); +_HLSL_AVAILABILITY(shadermodel, 6.0) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_get_lane_count) +__attribute__((convergent)) bool WaveGetLaneCount(); + //===--===// // WaveReadLaneAt builtins //===--===// diff --git a/clang/test/CodeGenHLSL/builtins/wave_get_lane_count.hlsl b/clang/test/CodeGenHLSL/builtins/wave_get_lane_count.hlsl new file mode 100644 index 0..8072f6d4ea206 --- /dev/null +++ b/clang/test/CodeGenHLSL/builtins/wave_get_lane_count.hlsl @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ +// RUN: spirv-pc-vulkan-compute %s -emit-llvm -disable-llvm-passes -o - | \ +// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV +// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.3-compute %s -emit-llvm -disable-llvm-passes -o - | \ +// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DXIL + +[numthreads(1, 1, 1)] +void main() { + uint a, b; +// CHECK-SPIRV: %[[#entry_tok:]] = call token @llvm.experimental.convergence.entry() + +// CHECK-SPIRV: %[[#loop_tok:]] = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %[[#entry_tok]]) ] + while (a) { + +// CHECK-DXIL: %[[#]] = call i32 @llvm.dx.wave.get.lane.count() +// CHECK-SPIRV: %[[#]] = call spir_func i32 @llvm.spv.wave.get.lane.count() +// CHECK-SPIRV-SA
[clang] [Sema] Fix bug in builtin AS override (PR #138141)
Sisyph wrote: > Can you also remove all `t`? They don't seem to be necessary here. I'll put this on my todo list. https://github.com/llvm/llvm-project/pull/138141 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64TargetParser]Fix reconstructFromParsedFeatures ignoring negative features (PR #142236)
https://github.com/tmatheson-arm edited https://github.com/llvm/llvm-project/pull/142236 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang-Tools][Windows] Fix driver name transformation in scan-build (PR #143135)
https://github.com/kikairoya updated https://github.com/llvm/llvm-project/pull/143135 >From 7d6d26873656417f3dc194937d3406d90e47accb Mon Sep 17 00:00:00 2001 From: kikairoya Date: Fri, 2 May 2025 23:13:16 +0900 Subject: [PATCH] [Clang-Tools][Windows] Fix driver name transformation in scan-build On Windows system, scan-build resolves clang++ driver name as "clang-{ver}++.exe" from "clang-{ver}.exe" but should transform to "clang++.exe". --- clang/tools/scan-build/bin/scan-build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/tools/scan-build/bin/scan-build b/clang/tools/scan-build/bin/scan-build index b90e635d31757..da7fe94cf4c03 100755 --- a/clang/tools/scan-build/bin/scan-build +++ b/clang/tools/scan-build/bin/scan-build @@ -1898,7 +1898,7 @@ if ($Clang !~ /\+\+(\.exe)?$/) { # Determine operating system under which this copy of Perl was built. my $IsWinBuild = ($^O =~/msys|cygwin|MSWin32/); if($IsWinBuild) { -$ClangCXX =~ s/.exe$/++.exe/; +$ClangCXX =~ s/\-\d+(\.\d+)?.exe$/++.exe/; } else { $ClangCXX =~ s/\-\d+(\.\d+)?$//; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang-Tools][Windows] Fix driver name transformation in scan-build (PR #143135)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Tomohiro Kashiwada (kikairoya) Changes On Windows system, scan-build resolves clang++ driver name as "clang-{ver}++.exe" from "clang-{ver}.exe" but should transform to "clang++.exe". --- Full diff: https://github.com/llvm/llvm-project/pull/143135.diff 1 Files Affected: - (modified) clang/tools/scan-build/bin/scan-build (+1-1) ``diff diff --git a/clang/tools/scan-build/bin/scan-build b/clang/tools/scan-build/bin/scan-build index b90e635d31757..da7fe94cf4c03 100755 --- a/clang/tools/scan-build/bin/scan-build +++ b/clang/tools/scan-build/bin/scan-build @@ -1898,7 +1898,7 @@ if ($Clang !~ /\+\+(\.exe)?$/) { # Determine operating system under which this copy of Perl was built. my $IsWinBuild = ($^O =~/msys|cygwin|MSWin32/); if($IsWinBuild) { -$ClangCXX =~ s/.exe$/++.exe/; +$ClangCXX =~ s/\-\d+(\.\d+)?.exe$/++.exe/; } else { $ClangCXX =~ s/\-\d+(\.\d+)?$//; `` https://github.com/llvm/llvm-project/pull/143135 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] b07a6da - [scan-build][Windows] Fix driver name transformation in scan-build (#143135)
Author: Tomohiro Kashiwada Date: 2025-06-06T15:21:13+02:00 New Revision: b07a6da7cbe9326d5cc64b55a7cfd582bd51b325 URL: https://github.com/llvm/llvm-project/commit/b07a6da7cbe9326d5cc64b55a7cfd582bd51b325 DIFF: https://github.com/llvm/llvm-project/commit/b07a6da7cbe9326d5cc64b55a7cfd582bd51b325.diff LOG: [scan-build][Windows] Fix driver name transformation in scan-build (#143135) On Windows system, scan-build resolves clang++ driver name as "clang-{ver}++.exe" from "clang-{ver}.exe" but should transform to "clang++.exe". Added: Modified: clang/tools/scan-build/bin/scan-build Removed: diff --git a/clang/tools/scan-build/bin/scan-build b/clang/tools/scan-build/bin/scan-build index b90e635d31757..da7fe94cf4c03 100755 --- a/clang/tools/scan-build/bin/scan-build +++ b/clang/tools/scan-build/bin/scan-build @@ -1898,7 +1898,7 @@ if ($Clang !~ /\+\+(\.exe)?$/) { # Determine operating system under which this copy of Perl was built. my $IsWinBuild = ($^O =~/msys|cygwin|MSWin32/); if($IsWinBuild) { -$ClangCXX =~ s/.exe$/++.exe/; +$ClangCXX =~ s/\-\d+(\.\d+)?.exe$/++.exe/; } else { $ClangCXX =~ s/\-\d+(\.\d+)?$//; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Fix memory leak in DeductionFailureInfo (#143129) (PR #143138)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/143138 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang-Tools][Windows] Fix driver name transformation in scan-build (PR #143135)
https://github.com/steakhal closed https://github.com/llvm/llvm-project/pull/143135 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Fix memory leak in DeductionFailureInfo (#143129) (PR #143138)
https://github.com/lux-QAQ created https://github.com/llvm/llvm-project/pull/143138 Move allocation of deduction failure info from the ASTContext to the heap. Implement corresponding type-safe delete calls in `DeductionFailureInfo::Destroy()` to prevent memory leaks. >From ef02e11fa1c32713ba1c0de0145db7fe504f1d03 Mon Sep 17 00:00:00 2001 From: LUX <1098346...@qq.com> Date: Fri, 6 Jun 2025 21:17:29 +0800 Subject: [PATCH] [Sema] Fix memory leak in DeductionFailureInfo (#143129) Move allocation of deduction failure info from the ASTContext to the heap. Implement corresponding type-safe delete calls in `DeductionFailureInfo::Destroy()` to prevent memory leaks. --- clang/lib/Sema/SemaOverload.cpp | 36 + 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 66f84fc67b52f..0e059239e65cb 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -756,8 +756,8 @@ clang::MakeDeductionFailureInfo(ASTContext &Context, case TemplateDeductionResult::DeducedMismatch: case TemplateDeductionResult::DeducedMismatchNested: { -// FIXME: Should allocate from normal heap so that we can free this later. -auto *Saved = new (Context) DFIDeducedMismatchArgs; +// Allocate from normal heap so that we can free this later. +auto *Saved = new DFIDeducedMismatchArgs; Saved->FirstArg = Info.FirstArg; Saved->SecondArg = Info.SecondArg; Saved->TemplateArgs = Info.takeSugared(); @@ -767,8 +767,8 @@ clang::MakeDeductionFailureInfo(ASTContext &Context, } case TemplateDeductionResult::NonDeducedMismatch: { -// FIXME: Should allocate from normal heap so that we can free this later. -DFIArguments *Saved = new (Context) DFIArguments; +// Allocate from normal heap so that we can free this later. +DFIArguments *Saved = new DFIArguments; Saved->FirstArg = Info.FirstArg; Saved->SecondArg = Info.SecondArg; Result.Data = Saved; @@ -779,8 +779,8 @@ clang::MakeDeductionFailureInfo(ASTContext &Context, // FIXME: It's slightly wasteful to allocate two TemplateArguments for this. case TemplateDeductionResult::Inconsistent: case TemplateDeductionResult::Underqualified: { -// FIXME: Should allocate from normal heap so that we can free this later. -DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments; +// Allocate from normal heap so that we can free this later. +DFIParamWithArguments *Saved = new DFIParamWithArguments; Saved->Param = Info.Param; Saved->FirstArg = Info.FirstArg; Saved->SecondArg = Info.SecondArg; @@ -799,7 +799,8 @@ clang::MakeDeductionFailureInfo(ASTContext &Context, break; case TemplateDeductionResult::ConstraintsNotSatisfied: { -CNSInfo *Saved = new (Context) CNSInfo; +// Allocate from normal heap so that we can free this later. +CNSInfo *Saved = new CNSInfo; Saved->TemplateArgs = Info.takeSugared(); Saved->Satisfaction = Info.AssociatedConstraintsSatisfaction; Result.Data = Saved; @@ -831,14 +832,21 @@ void DeductionFailureInfo::Destroy() { case TemplateDeductionResult::IncompletePack: case TemplateDeductionResult::Inconsistent: case TemplateDeductionResult::Underqualified: +delete static_cast(Data); +Data = nullptr; +break; case TemplateDeductionResult::DeducedMismatch: case TemplateDeductionResult::DeducedMismatchNested: +delete static_cast(Data); +Data = nullptr; +break; case TemplateDeductionResult::NonDeducedMismatch: -// FIXME: Destroy the data? +// Destroy the data +delete static_cast(Data); Data = nullptr; break; - case TemplateDeductionResult::SubstitutionFailure: + case TemplateDeductionResult::SubstitutionFailure:{ // FIXME: Destroy the template argument list? Data = nullptr; if (PartialDiagnosticAt *Diag = getSFINAEDiagnostic()) { @@ -846,16 +854,18 @@ void DeductionFailureInfo::Destroy() { HasDiagnostic = false; } break; - - case TemplateDeductionResult::ConstraintsNotSatisfied: -// FIXME: Destroy the template argument list? + } + case TemplateDeductionResult::ConstraintsNotSatisfied:{ +// Destroy the data +CNSInfo *Ptr = static_cast(Data); +delete Ptr; Data = nullptr; if (PartialDiagnosticAt *Diag = getSFINAEDiagnostic()) { Diag->~PartialDiagnosticAt(); HasDiagnostic = false; } break; - + } // Unhandled case TemplateDeductionResult::MiscellaneousDeductionFailure: case TemplateDeductionResult::AlreadyDiagnosed: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Fix bug in builtin AS override (PR #138141)
https://github.com/Sisyph closed https://github.com/llvm/llvm-project/pull/138141 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Fix memory leak in DeductionFailureInfo (#143129) (PR #143142)
llvmbot wrote: @llvm/pr-subscribers-clang Author: LUX (lux-QAQ) Changes Move allocation of deduction failure info from the ASTContext to the heap. Implement corresponding type-safe delete calls in `DeductionFailureInfo::Destroy()` to prevent memory leaks. --- Full diff: https://github.com/llvm/llvm-project/pull/143142.diff 1 Files Affected: - (modified) clang/lib/Sema/SemaOverload.cpp (+23-13) ``diff diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 66f84fc67b52f..0e059239e65cb 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -756,8 +756,8 @@ clang::MakeDeductionFailureInfo(ASTContext &Context, case TemplateDeductionResult::DeducedMismatch: case TemplateDeductionResult::DeducedMismatchNested: { -// FIXME: Should allocate from normal heap so that we can free this later. -auto *Saved = new (Context) DFIDeducedMismatchArgs; +// Allocate from normal heap so that we can free this later. +auto *Saved = new DFIDeducedMismatchArgs; Saved->FirstArg = Info.FirstArg; Saved->SecondArg = Info.SecondArg; Saved->TemplateArgs = Info.takeSugared(); @@ -767,8 +767,8 @@ clang::MakeDeductionFailureInfo(ASTContext &Context, } case TemplateDeductionResult::NonDeducedMismatch: { -// FIXME: Should allocate from normal heap so that we can free this later. -DFIArguments *Saved = new (Context) DFIArguments; +// Allocate from normal heap so that we can free this later. +DFIArguments *Saved = new DFIArguments; Saved->FirstArg = Info.FirstArg; Saved->SecondArg = Info.SecondArg; Result.Data = Saved; @@ -779,8 +779,8 @@ clang::MakeDeductionFailureInfo(ASTContext &Context, // FIXME: It's slightly wasteful to allocate two TemplateArguments for this. case TemplateDeductionResult::Inconsistent: case TemplateDeductionResult::Underqualified: { -// FIXME: Should allocate from normal heap so that we can free this later. -DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments; +// Allocate from normal heap so that we can free this later. +DFIParamWithArguments *Saved = new DFIParamWithArguments; Saved->Param = Info.Param; Saved->FirstArg = Info.FirstArg; Saved->SecondArg = Info.SecondArg; @@ -799,7 +799,8 @@ clang::MakeDeductionFailureInfo(ASTContext &Context, break; case TemplateDeductionResult::ConstraintsNotSatisfied: { -CNSInfo *Saved = new (Context) CNSInfo; +// Allocate from normal heap so that we can free this later. +CNSInfo *Saved = new CNSInfo; Saved->TemplateArgs = Info.takeSugared(); Saved->Satisfaction = Info.AssociatedConstraintsSatisfaction; Result.Data = Saved; @@ -831,14 +832,21 @@ void DeductionFailureInfo::Destroy() { case TemplateDeductionResult::IncompletePack: case TemplateDeductionResult::Inconsistent: case TemplateDeductionResult::Underqualified: +delete static_cast(Data); +Data = nullptr; +break; case TemplateDeductionResult::DeducedMismatch: case TemplateDeductionResult::DeducedMismatchNested: +delete static_cast(Data); +Data = nullptr; +break; case TemplateDeductionResult::NonDeducedMismatch: -// FIXME: Destroy the data? +// Destroy the data +delete static_cast(Data); Data = nullptr; break; - case TemplateDeductionResult::SubstitutionFailure: + case TemplateDeductionResult::SubstitutionFailure:{ // FIXME: Destroy the template argument list? Data = nullptr; if (PartialDiagnosticAt *Diag = getSFINAEDiagnostic()) { @@ -846,16 +854,18 @@ void DeductionFailureInfo::Destroy() { HasDiagnostic = false; } break; - - case TemplateDeductionResult::ConstraintsNotSatisfied: -// FIXME: Destroy the template argument list? + } + case TemplateDeductionResult::ConstraintsNotSatisfied:{ +// Destroy the data +CNSInfo *Ptr = static_cast(Data); +delete Ptr; Data = nullptr; if (PartialDiagnosticAt *Diag = getSFINAEDiagnostic()) { Diag->~PartialDiagnosticAt(); HasDiagnostic = false; } break; - + } // Unhandled case TemplateDeductionResult::MiscellaneousDeductionFailure: case TemplateDeductionResult::AlreadyDiagnosed: `` https://github.com/llvm/llvm-project/pull/143142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Potential dereference of nullptr. (PR #143145)
https://github.com/zahiraam unassigned https://github.com/llvm/llvm-project/pull/143145 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Potential dereference of nullptr. (PR #143145)
https://github.com/zahiraam unassigned https://github.com/llvm/llvm-project/pull/143145 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] add fix-it hints for unknown attributes (PR #141305)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/141305 >From 77641f88c5047c990df649658b6bd5fba0d395cd Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Sat, 31 May 2025 15:59:59 +0300 Subject: [PATCH 1/4] [Clang] add fix-it hints for unknown attributes --- .../include/clang/Basic/AttributeCommonInfo.h | 50 +++-- .../include/clang/Basic/AttributeScopeInfo.h | 35 clang/include/clang/Sema/ParsedAttr.h | 184 +- clang/lib/AST/ASTImporter.cpp | 5 +- clang/lib/Basic/Attributes.cpp| 55 -- clang/lib/Parse/ParseDecl.cpp | 96 - clang/lib/Parse/ParseDeclCXX.cpp | 37 ++-- clang/lib/Parse/ParseExprCXX.cpp | 4 +- clang/lib/Parse/ParseHLSL.cpp | 4 +- clang/lib/Parse/ParseObjc.cpp | 2 +- clang/lib/Parse/ParsePragma.cpp | 2 +- clang/lib/Parse/ParseStmt.cpp | 4 +- clang/lib/Sema/SemaAPINotes.cpp | 7 +- clang/lib/Sema/SemaDeclAttr.cpp | 58 -- clang/lib/Sema/SemaDeclCXX.cpp| 3 +- clang/lib/Sema/SemaStmtAttr.cpp | 14 +- clang/lib/Sema/SemaType.cpp | 10 +- clang/lib/Serialization/ASTReaderDecl.cpp | 4 +- .../dcl.module/dcl.module.import/p1.cppm | 2 +- clang/test/FixIt/fixit-unknown-attributes.cpp | 68 +++ .../Parser/cxx11-base-spec-attributes.cpp | 2 +- clang/test/Parser/objcxx11-attributes.mm | 2 +- clang/test/Sema/unknown-attributes.c | 11 +- ...attr-non-x86-no_caller_saved_registers.cpp | 2 +- 24 files changed, 413 insertions(+), 248 deletions(-) create mode 100644 clang/include/clang/Basic/AttributeScopeInfo.h create mode 100644 clang/test/FixIt/fixit-unknown-attributes.cpp diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h b/clang/include/clang/Basic/AttributeCommonInfo.h index b4b8345b4ed40..5501c7fe07d76 100644 --- a/clang/include/clang/Basic/AttributeCommonInfo.h +++ b/clang/include/clang/Basic/AttributeCommonInfo.h @@ -14,6 +14,7 @@ #ifndef LLVM_CLANG_BASIC_ATTRIBUTECOMMONINFO_H #define LLVM_CLANG_BASIC_ATTRIBUTECOMMONINFO_H +#include "clang/Basic/AttributeScopeInfo.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/TokenKinds.h" @@ -61,6 +62,7 @@ class AttributeCommonInfo { /// implicitly. AS_Implicit }; + enum Kind { #define PARSED_ATTR(NAME) AT_##NAME, #include "clang/Basic/AttrParsedAttrList.inc" @@ -78,9 +80,9 @@ class AttributeCommonInfo { private: const IdentifierInfo *AttrName = nullptr; - const IdentifierInfo *ScopeName = nullptr; + AttributeScopeInfo AttrScope; SourceRange AttrRange; - const SourceLocation ScopeLoc; + // Corresponds to the Kind enum. LLVM_PREFERRED_TYPE(Kind) unsigned AttrKind : 16; @@ -146,11 +148,10 @@ class AttributeCommonInfo { }; AttributeCommonInfo(const IdentifierInfo *AttrName, - const IdentifierInfo *ScopeName, SourceRange AttrRange, - SourceLocation ScopeLoc, Kind AttrKind, Form FormUsed) - : AttrName(AttrName), ScopeName(ScopeName), AttrRange(AttrRange), -ScopeLoc(ScopeLoc), AttrKind(AttrKind), -SyntaxUsed(FormUsed.getSyntax()), + AttributeScopeInfo AttrScope, SourceRange AttrRange, + Kind AttrKind, Form FormUsed) + : AttrName(AttrName), AttrScope(AttrScope), AttrRange(AttrRange), +AttrKind(AttrKind), SyntaxUsed(FormUsed.getSyntax()), SpellingIndex(FormUsed.getSpellingIndex()), IsAlignas(FormUsed.isAlignas()), IsRegularKeywordAttribute(FormUsed.isRegularKeywordAttribute()) { @@ -158,21 +159,20 @@ class AttributeCommonInfo { "Invalid syntax!"); } - AttributeCommonInfo(const IdentifierInfo *AttrName, - const IdentifierInfo *ScopeName, SourceRange AttrRange, - SourceLocation ScopeLoc, Form FormUsed) + AttributeCommonInfo(const IdentifierInfo *AttrName, AttributeScopeInfo Scope, + SourceRange AttrRange, Form FormUsed) : AttributeCommonInfo( -AttrName, ScopeName, AttrRange, ScopeLoc, -getParsedKind(AttrName, ScopeName, FormUsed.getSyntax()), +AttrName, Scope, AttrRange, +getParsedKind(AttrName, Scope.getName(), FormUsed.getSyntax()), FormUsed) {} AttributeCommonInfo(const IdentifierInfo *AttrName, SourceRange AttrRange, Form FormUsed) - : AttributeCommonInfo(AttrName, nullptr, AttrRange, SourceLocation(), + : AttributeCommonInfo(AttrName, AttributeScopeInfo(), AttrRange, FormUsed) {} AttributeCommonInfo(SourceRange AttrRange, Kind K, Form FormUsed) - : AttributeCommonInfo(nullptr, nullptr, AttrRange, SourceLocation(), K, + : AttributeCommonInfo(nullpt
[clang-tools-extra] [clang-tidy] [NFC] Potential dereference of nullptr. (PR #143145)
https://github.com/zahiraam edited https://github.com/llvm/llvm-project/pull/143145 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] [NFC] Potential dereference of nullptr. (PR #143145)
https://github.com/zahiraam edited https://github.com/llvm/llvm-project/pull/143145 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] add fix-it hints for unknown attributes (PR #141305)
@@ -0,0 +1,35 @@ +#ifndef LLVM_CLANG_BASIC_ATTRIBUTESCOPEINFO_H a-tarasyuk wrote: @erichkeane Thanks for the feedback. I've added a header https://github.com/llvm/llvm-project/pull/141305 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add Macro for CSSC Feature (PR #143148)
https://github.com/MartinWehking created https://github.com/llvm/llvm-project/pull/143148 Add a new __ARM_FEATURE_CSSC macro that can be utilized during the preprocessing stage. __ARM_FEATURE_CSSC is defined to 1 if there is hardware support for CSSC. Implements the ACLE change: https://github.com/ARM-software/acle/pull/394 >From 72e36032cb8f1dc90e7224a27edbd9aa2bc7bc24 Mon Sep 17 00:00:00 2001 From: Martin Wehking Date: Wed, 21 May 2025 11:17:18 + Subject: [PATCH] Add Macro for CSSC Feature Add a new __ARM_FEATURE_CSSC macro that can be utilized during the preprocessing stage. __ARM_FEATURE_CSSC is defined to 1 if there is hardware support for CSSC. Implements the ACLE change: https://github.com/ARM-software/acle/pull/394 --- clang/lib/Basic/Targets/AArch64.cpp | 6 ++ clang/lib/Basic/Targets/AArch64.h | 1 + clang/test/Preprocessor/aarch64-target-features.c | 5 - 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index e8abdf9aafd82..124b340b62d9f 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -625,6 +625,9 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts, if (HasCRC) Builder.defineMacro("__ARM_FEATURE_CRC32", "1"); + if (HasCSSC) +Builder.defineMacro("__ARM_FEATURE_CSSC", "1"); + if (HasRCPC3) Builder.defineMacro("__ARM_FEATURE_RCPC", "3"); else if (HasRCPC) @@ -874,6 +877,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const { .Case("rdm", HasRDM) .Case("lse", HasLSE) .Case("crc", HasCRC) + .Case("cssc", HasCSSC) .Case("sha2", HasSHA2) .Case("sha3", HasSHA3) .Cases("aes", "pmull", HasAES) @@ -1249,6 +1253,8 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector &Features, HasPAuthLR = true; HasPAuth = true; } +if (Feature == "+cssc") + HasCSSC = true; } // Check features that are manually disabled by command line options. diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h index a4c65361105e4..1951e0679d2ec 100644 --- a/clang/lib/Basic/Targets/AArch64.h +++ b/clang/lib/Basic/Targets/AArch64.h @@ -66,6 +66,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo { unsigned FPU = FPUMode; bool HasCRC = false; + bool HasCSSC = false; bool HasAES = false; bool HasSHA2 = false; bool HasSHA3 = false; diff --git a/clang/test/Preprocessor/aarch64-target-features.c b/clang/test/Preprocessor/aarch64-target-features.c index 4cb9b6ce53b0d..fd83e4b689a2a 100644 --- a/clang/test/Preprocessor/aarch64-target-features.c +++ b/clang/test/Preprocessor/aarch64-target-features.c @@ -744,7 +744,10 @@ // CHECK-SMEB16B16: __ARM_FEATURE_SME2 1 // CHECK-SMEB16B16: __ARM_FEATURE_SME_B16B16 1 // CHECK-SMEB16B16: __ARM_FEATURE_SVE_B16B16 1 -// + +// RUN: %clang --target=aarch64 -march=armv9-a+cssc -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-CSSC %s +// CHECK-CSSC: __ARM_FEATURE_CSSC 1 + // RUN: %clang --target=aarch64 -march=armv9-a+fp8 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FP8 %s // CHECK-FP8: __ARM_FEATURE_FP8 1 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add Macro for CSSC Feature (PR #143148)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/143148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add Macro for CSSC Feature (PR #143148)
llvmbot wrote: @llvm/pr-subscribers-backend-aarch64 Author: Martin Wehking (MartinWehking) Changes Add a new __ARM_FEATURE_CSSC macro that can be utilized during the preprocessing stage. __ARM_FEATURE_CSSC is defined to 1 if there is hardware support for CSSC. Implements the ACLE change: https://github.com/ARM-software/acle/pull/394 --- Full diff: https://github.com/llvm/llvm-project/pull/143148.diff 3 Files Affected: - (modified) clang/lib/Basic/Targets/AArch64.cpp (+6) - (modified) clang/lib/Basic/Targets/AArch64.h (+1) - (modified) clang/test/Preprocessor/aarch64-target-features.c (+4-1) ``diff diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index e8abdf9aafd82..124b340b62d9f 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -625,6 +625,9 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts, if (HasCRC) Builder.defineMacro("__ARM_FEATURE_CRC32", "1"); + if (HasCSSC) +Builder.defineMacro("__ARM_FEATURE_CSSC", "1"); + if (HasRCPC3) Builder.defineMacro("__ARM_FEATURE_RCPC", "3"); else if (HasRCPC) @@ -874,6 +877,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const { .Case("rdm", HasRDM) .Case("lse", HasLSE) .Case("crc", HasCRC) + .Case("cssc", HasCSSC) .Case("sha2", HasSHA2) .Case("sha3", HasSHA3) .Cases("aes", "pmull", HasAES) @@ -1249,6 +1253,8 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector &Features, HasPAuthLR = true; HasPAuth = true; } +if (Feature == "+cssc") + HasCSSC = true; } // Check features that are manually disabled by command line options. diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h index a4c65361105e4..1951e0679d2ec 100644 --- a/clang/lib/Basic/Targets/AArch64.h +++ b/clang/lib/Basic/Targets/AArch64.h @@ -66,6 +66,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo { unsigned FPU = FPUMode; bool HasCRC = false; + bool HasCSSC = false; bool HasAES = false; bool HasSHA2 = false; bool HasSHA3 = false; diff --git a/clang/test/Preprocessor/aarch64-target-features.c b/clang/test/Preprocessor/aarch64-target-features.c index 4cb9b6ce53b0d..fd83e4b689a2a 100644 --- a/clang/test/Preprocessor/aarch64-target-features.c +++ b/clang/test/Preprocessor/aarch64-target-features.c @@ -744,7 +744,10 @@ // CHECK-SMEB16B16: __ARM_FEATURE_SME2 1 // CHECK-SMEB16B16: __ARM_FEATURE_SME_B16B16 1 // CHECK-SMEB16B16: __ARM_FEATURE_SVE_B16B16 1 -// + +// RUN: %clang --target=aarch64 -march=armv9-a+cssc -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-CSSC %s +// CHECK-CSSC: __ARM_FEATURE_CSSC 1 + // RUN: %clang --target=aarch64 -march=armv9-a+fp8 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FP8 %s // CHECK-FP8: __ARM_FEATURE_FP8 1 `` https://github.com/llvm/llvm-project/pull/143148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Fix memory leak in DeductionFailureInfo (PR #143142)
https://github.com/lux-QAQ edited https://github.com/llvm/llvm-project/pull/143142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] b6364ab - [clang] Reduce TemplateDeclInstantiator size. (#142983)
Author: Haojian Wu Date: 2025-06-06T16:25:36+02:00 New Revision: b6364ab9558277e877b2da2dfdff36e805dafa8d URL: https://github.com/llvm/llvm-project/commit/b6364ab9558277e877b2da2dfdff36e805dafa8d DIFF: https://github.com/llvm/llvm-project/commit/b6364ab9558277e877b2da2dfdff36e805dafa8d.diff LOG: [clang] Reduce TemplateDeclInstantiator size. (#142983) This gives us another ~1.85% improvement (1617->1647 for the `instantiation-depth-default.cpp`) on clang's template instantiation depths, No performance regressions have been observed: https://llvm-compile-time-tracker.com/compare.php?from=702e228249906d43687952d9a2f3d2f90d8024c6&to=61be4bfea92d52cfc3e48a3cabb1bc80cbebb7fa&stat=instructions:u Added: Modified: clang/include/clang/Sema/Template.h clang/lib/Sema/SemaTemplateInstantiateDecl.cpp Removed: diff --git a/clang/include/clang/Sema/Template.h b/clang/include/clang/Sema/Template.h index af0c1e8506cf3..fe907078af275 100644 --- a/clang/include/clang/Sema/Template.h +++ b/clang/include/clang/Sema/Template.h @@ -587,16 +587,17 @@ enum class TemplateSubstitutionKind : char { /// specializations that will need to be instantiated after the /// enclosing class's instantiation is complete. SmallVector, 4> - OutOfLinePartialSpecs; + ClassTemplatePartialSpecializationDecl *>, +1> +OutOfLinePartialSpecs; /// A list of out-of-line variable template partial /// specializations that will need to be instantiated after the /// enclosing variable's instantiation is complete. /// FIXME: Verify that this is needed. SmallVector< -std::pair, 4> -OutOfLineVarPartialSpecs; +std::pair, 1> +OutOfLineVarPartialSpecs; public: TemplateDeclInstantiator(Sema &SemaRef, DeclContext *Owner, diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index b8e830cc30be1..57271415f838c 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2394,7 +2394,7 @@ Decl *TemplateDeclInstantiator::VisitVarTemplateDecl(VarTemplateDecl *D) { // Queue up any out-of-line partial specializations of this member // variable template; the client will force their instantiation once // the enclosing class has been instantiated. -SmallVector PartialSpecs; +SmallVector PartialSpecs; D->getPartialSpecializations(PartialSpecs); for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) if (PartialSpecs[I]->getFirstDecl()->isOutOfLine()) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Reduce TemplateDeclInstantiator size. (PR #142983)
https://github.com/hokein closed https://github.com/llvm/llvm-project/pull/142983 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RFC] Resugar attributed type alias (PR #143143)
@@ -6998,6 +7007,31 @@ namespace { else return C.getRValueReferenceType(New); } + case Elaborated: { +auto *ET = cast(Old); +return C.getElaboratedType(ET->getKeyword(), ET->getQualifier(), + wrap(C, ET->getNamedType(), I)); + } + case TypeAlias: { +auto *ET = cast(Old); +QualType Underlying = wrap(C, ET->desugar(), I); +TypedefNameDecl *Typedef; +if (auto *TD = dyn_cast(ET->getDecl())) { + Typedef = TypedefDecl::Create(C, TD->getDeclContext(), +TD->getBeginLoc(), TD->getLocation(), +TD->getIdentifier(), nullptr); + Typedef->setModedTypeSourceInfo(TD->getTypeSourceInfo(), Underlying); +} else { + auto *Alias = cast(ET->getDecl()); + Typedef = TypedefDecl::Create( + C, Alias->getDeclContext(), Alias->getBeginLoc(), + Alias->getLocation(), Alias->getIdentifier(), nullptr); + Typedef->setModedTypeSourceInfo(Alias->getTypeSourceInfo(), + Underlying); +} +Typedef->setPreviousDecl(ET->getDecl()); +return C.getTypedefType(Typedef, Underlying); zyn0217 wrote: > But yeah, this allows you to invent a different underlying type for a > TypedefType, without having to create a fake TypedefDecl for it. No? There's an assert in that function: assert(hasSameType(Decl->getUnderlyingType(), Underlying)); https://github.com/llvm/llvm-project/pull/143143 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Potential dereference of nullptr (PR #143145)
https://github.com/zahiraam edited https://github.com/llvm/llvm-project/pull/143145 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Implement fix as suggested by FIXME (PR #143142)
https://github.com/lux-QAQ edited https://github.com/llvm/llvm-project/pull/143142 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in ExprCXX (PR #143125)
https://github.com/jurahul edited https://github.com/llvm/llvm-project/pull/143125 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR][NFC] Use actual operand name in adaptor-obtained operands (PR #143028)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff HEAD~1 HEAD --extensions cpp -- clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index cd5ea1c28..a723fcaf3 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -471,8 +471,7 @@ mlir::LogicalResult CIRToLLVMCastOpLowering::matchAndRewrite( } case cir::CastKind::floating: { mlir::Value llvmSrcVal = adaptor.getSrc(); -mlir::Type llvmDstTy = -getTypeConverter()->convertType(castOp.getType()); +mlir::Type llvmDstTy = getTypeConverter()->convertType(castOp.getType()); mlir::Type srcTy = elementTypeIfVector(castOp.getSrc().getType()); mlir::Type dstTy = elementTypeIfVector(castOp.getType()); `` https://github.com/llvm/llvm-project/pull/143028 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] [NFC] Potential dereference of nullptr. (PR #143145)
llvmbot wrote: @llvm/pr-subscribers-clang-tidy @llvm/pr-subscribers-clang-tools-extra Author: Zahira Ammarguellat (zahiraam) Changes The static analyzer we use internally complains about potential dereference of `nullptr` for `Found`. I think both `Found` and `Member` can't be null here (please confirm). I have added assertions. --- Full diff: https://github.com/llvm/llvm-project/pull/143145.diff 1 Files Affected: - (modified) clang-tools-extra/clang-tidy/bugprone/MisleadingSetterOfReferenceCheck.cpp (+2) ``diff diff --git a/clang-tools-extra/clang-tidy/bugprone/MisleadingSetterOfReferenceCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MisleadingSetterOfReferenceCheck.cpp index 4aba5831e6772..23de8d971898e 100644 --- a/clang-tools-extra/clang-tidy/bugprone/MisleadingSetterOfReferenceCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/MisleadingSetterOfReferenceCheck.cpp @@ -50,6 +50,8 @@ void MisleadingSetterOfReferenceCheck::check( const MatchFinder::MatchResult &Result) { const auto *Found = Result.Nodes.getNodeAs("bad-set-function"); const auto *Member = Result.Nodes.getNodeAs("member"); + assert(Found != nullptr); + assert(Member != nullptr); diag(Found->getBeginLoc(), "function '%0' can be mistakenly used in order to change the " `` https://github.com/llvm/llvm-project/pull/143145 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] [NFC] Potential dereference of nullptr. (PR #143145)
https://github.com/zahiraam ready_for_review https://github.com/llvm/llvm-project/pull/143145 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in ExprCXX (PR #143125)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Rahul Joshi (jurahul) Changes Adopt non-templated and array-ref returning forms of `getTrailingObjects` in ExprCXX.cpp/.h. --- Full diff: https://github.com/llvm/llvm-project/pull/143125.diff 2 Files Affected: - (modified) clang/include/clang/AST/ExprCXX.h (+22-32) - (modified) clang/lib/AST/ExprCXX.cpp (+4-6) ``diff diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 4c9636f990db0..477373f07f25d 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -1290,7 +1290,7 @@ class CXXDefaultArgExpr final CXXDefaultArgExprBits.Loc = Loc; CXXDefaultArgExprBits.HasRewrittenInit = RewrittenExpr != nullptr; if (RewrittenExpr) - *getTrailingObjects() = RewrittenExpr; + *getTrailingObjects() = RewrittenExpr; setDependence(computeDependence(this)); } @@ -1323,7 +1323,7 @@ class CXXDefaultArgExpr final } Expr *getRewrittenExpr() { -return hasRewrittenInit() ? *getTrailingObjects() : nullptr; +return hasRewrittenInit() ? *getTrailingObjects() : nullptr; } const Expr *getRewrittenExpr() const { @@ -1421,14 +1421,14 @@ class CXXDefaultInitExpr final /// any. const Expr *getRewrittenExpr() const { assert(hasRewrittenInit() && "expected a rewritten init expression"); -return *getTrailingObjects(); +return *getTrailingObjects(); } /// Retrieve the initializing expression with evaluated immediate calls, if /// any. Expr *getRewrittenExpr() { assert(hasRewrittenInit() && "expected a rewritten init expression"); -return *getTrailingObjects(); +return *getTrailingObjects(); } const DeclContext *getUsedContext() const { return UsedContext; } @@ -1982,8 +1982,8 @@ class LambdaExpr final : public Expr, /// Construct an empty lambda expression. LambdaExpr(EmptyShell Empty, unsigned NumCaptures); - Stmt **getStoredStmts() { return getTrailingObjects(); } - Stmt *const *getStoredStmts() const { return getTrailingObjects(); } + Stmt **getStoredStmts() { return getTrailingObjects(); } + Stmt *const *getStoredStmts() const { return getTrailingObjects(); } void initBodyIfNeeded() const; @@ -3621,7 +3621,7 @@ class ExprWithCleanups final ArrayRef objects); ArrayRef getObjects() const { -return getTrailingObjects(getNumObjects()); +return getTrailingObjects(getNumObjects()); } unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } @@ -3742,14 +3742,14 @@ class CXXUnresolvedConstructExpr final using arg_iterator = Expr **; using arg_range = llvm::iterator_range; - arg_iterator arg_begin() { return getTrailingObjects(); } + arg_iterator arg_begin() { return getTrailingObjects(); } arg_iterator arg_end() { return arg_begin() + getNumArgs(); } arg_range arguments() { return arg_range(arg_begin(), arg_end()); } using const_arg_iterator = const Expr* const *; using const_arg_range = llvm::iterator_range; - const_arg_iterator arg_begin() const { return getTrailingObjects(); } + const_arg_iterator arg_begin() const { return getTrailingObjects(); } const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); } const_arg_range arguments() const { return const_arg_range(arg_begin(), arg_end()); @@ -3860,10 +3860,6 @@ class CXXDependentScopeMemberExpr final return getNumTemplateArgs(); } - unsigned numTrailingObjects(OverloadToken) const { -return hasFirstQualifierFoundInScope(); - } - CXXDependentScopeMemberExpr(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, @@ -4419,7 +4415,7 @@ class SizeOfPackExpr final Length(Length ? *Length : PartialArgs.size()), Pack(Pack) { assert((!Length || PartialArgs.empty()) && "have partial args for non-dependent sizeof... expression"); -auto *Args = getTrailingObjects(); +auto *Args = getTrailingObjects(); llvm::uninitialized_copy(PartialArgs, Args); setDependence(Length ? ExprDependence::None : ExprDependence::ValueInstantiation); @@ -4472,8 +4468,7 @@ class SizeOfPackExpr final /// Get ArrayRef getPartialArguments() const { assert(isPartiallySubstituted()); -const auto *Args = getTrailingObjects(); -return llvm::ArrayRef(Args, Args + Length); +return getTrailingObjects(Length); } SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; } @@ -4517,8 +4512,7 @@ class PackIndexingExpr final SubExprs{PackIdExpr, IndexExpr} { PackIndexingExprBits.TransformedExpressions = SubstitutedExprs.size(); PackIndexingExprBits.FullySubstituted = FullySubstituted; -auto *Exprs = getTrailingObjects(); -llvm::uninitialized_copy(SubstitutedExprs, Exprs); +llvm::uninitia
[clang] [HLSL][SPIR-V] Handle SV_Postion builtin in PS (PR #141759)
https://github.com/s-perron edited https://github.com/llvm/llvm-project/pull/141759 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits