[clang] [clang] fix P3310 overload resolution flag propagation (PR #125372)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Matheus Izvekov (mizvekov) Changes Class templates might be only instantiated when they are required to be complete, but checking the template args against the primary template is immediate. This result is cached so that later when the class is instantiated, checking against the primary template is not repeated. The 'MatchedPackOnParmToNonPackOnArg' flag is also produced upon checking against the primary template, so it needs to be cached in the specialziation as well. This fixes a bug which has not been in any release, so there are no release notes. Fixes #125290 --- Full diff: https://github.com/llvm/llvm-project/pull/125372.diff 12 Files Affected: - (modified) clang/include/clang/AST/DeclTemplate.h (+12-2) - (modified) clang/lib/AST/ASTImporter.cpp (+3-3) - (modified) clang/lib/AST/DeclTemplate.cpp (+24-23) - (modified) clang/lib/AST/TextNodeDumper.cpp (+4-1) - (modified) clang/lib/Sema/SemaTemplate.cpp (+5-3) - (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (-2) - (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+1-1) - (modified) clang/lib/Sema/SemaType.cpp (+2-1) - (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+1) - (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+1) - (modified) clang/test/AST/ast-dump-templates.cpp (+17-2) - (modified) clang/test/SemaTemplate/cwg2398.cpp (+17) ``diff diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 9ecff2c898acd5..aff299433ce721 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -1841,15 +1841,21 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, LLVM_PREFERRED_TYPE(TemplateSpecializationKind) unsigned SpecializationKind : 3; + /// When matching the primary template, have we matched any packs on the + /// parameter side, versus any non-packs on the argument side, in a context + /// where the opposite matching is also allowed? + bool MatchedPackOnParmToNonPackOnArg : 1; + protected: ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, ArrayRef Args, + bool MatchedPackOnParmToNonPackOnArg, ClassTemplateSpecializationDecl *PrevDecl); - explicit ClassTemplateSpecializationDecl(ASTContext &C, Kind DK); + ClassTemplateSpecializationDecl(ASTContext &C, Kind DK); public: friend class ASTDeclReader; @@ -1859,7 +1865,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, - ArrayRef Args, + ArrayRef Args, bool MatchedPackOnParmToNonPackOnArg, ClassTemplateSpecializationDecl *PrevDecl); static ClassTemplateSpecializationDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID); @@ -1930,6 +1936,10 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, SpecializationKind = TSK; } + bool hasMatchedPackOnParmToNonPackOnArg() const { +return MatchedPackOnParmToNonPackOnArg; + } + /// Get the point of instantiation (if any), or null if none. SourceLocation getPointOfInstantiation() const { return PointOfInstantiation; diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index c9f2f905d2134c..1057f09deda073 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -6321,9 +6321,9 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( updateLookupTableForTemplateParameters(*ToTPList); } else { // Not a partial specialization. if (GetImportedOrCreateDecl( -D2, D, Importer.getToContext(), D->getTagKind(), DC, -*BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, -PrevDecl)) +D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr, +*IdLocOrErr, ClassTemplate, TemplateArgs, +D->hasMatchedPackOnParmToNonPackOnArg(), PrevDecl)) return D2; // Update InsertPos, because preceding import calls may have invalidated diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 2e1ed9e10713a8..fe8734d262a961 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -957,18 +957,20 @@ FunctionTemplateSpecializationInfo *FunctionTemplateSpecializationInfo::Create( // ClassTemplateSpecializationDecl Implementation //===-
[clang] [clang] fix P3310 overload resolution flag propagation (PR #125372)
llvmbot wrote: @llvm/pr-subscribers-clang-modules Author: Matheus Izvekov (mizvekov) Changes Class templates might be only instantiated when they are required to be complete, but checking the template args against the primary template is immediate. This result is cached so that later when the class is instantiated, checking against the primary template is not repeated. The 'MatchedPackOnParmToNonPackOnArg' flag is also produced upon checking against the primary template, so it needs to be cached in the specialziation as well. This fixes a bug which has not been in any release, so there are no release notes. Fixes #125290 --- Full diff: https://github.com/llvm/llvm-project/pull/125372.diff 12 Files Affected: - (modified) clang/include/clang/AST/DeclTemplate.h (+12-2) - (modified) clang/lib/AST/ASTImporter.cpp (+3-3) - (modified) clang/lib/AST/DeclTemplate.cpp (+24-23) - (modified) clang/lib/AST/TextNodeDumper.cpp (+4-1) - (modified) clang/lib/Sema/SemaTemplate.cpp (+5-3) - (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (-2) - (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+1-1) - (modified) clang/lib/Sema/SemaType.cpp (+2-1) - (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+1) - (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+1) - (modified) clang/test/AST/ast-dump-templates.cpp (+17-2) - (modified) clang/test/SemaTemplate/cwg2398.cpp (+17) ``diff diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 9ecff2c898acd5f..aff299433ce7217 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -1841,15 +1841,21 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, LLVM_PREFERRED_TYPE(TemplateSpecializationKind) unsigned SpecializationKind : 3; + /// When matching the primary template, have we matched any packs on the + /// parameter side, versus any non-packs on the argument side, in a context + /// where the opposite matching is also allowed? + bool MatchedPackOnParmToNonPackOnArg : 1; + protected: ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, ArrayRef Args, + bool MatchedPackOnParmToNonPackOnArg, ClassTemplateSpecializationDecl *PrevDecl); - explicit ClassTemplateSpecializationDecl(ASTContext &C, Kind DK); + ClassTemplateSpecializationDecl(ASTContext &C, Kind DK); public: friend class ASTDeclReader; @@ -1859,7 +1865,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, - ArrayRef Args, + ArrayRef Args, bool MatchedPackOnParmToNonPackOnArg, ClassTemplateSpecializationDecl *PrevDecl); static ClassTemplateSpecializationDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID); @@ -1930,6 +1936,10 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, SpecializationKind = TSK; } + bool hasMatchedPackOnParmToNonPackOnArg() const { +return MatchedPackOnParmToNonPackOnArg; + } + /// Get the point of instantiation (if any), or null if none. SourceLocation getPointOfInstantiation() const { return PointOfInstantiation; diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index c9f2f905d2134c1..1057f09deda073e 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -6321,9 +6321,9 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( updateLookupTableForTemplateParameters(*ToTPList); } else { // Not a partial specialization. if (GetImportedOrCreateDecl( -D2, D, Importer.getToContext(), D->getTagKind(), DC, -*BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, -PrevDecl)) +D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr, +*IdLocOrErr, ClassTemplate, TemplateArgs, +D->hasMatchedPackOnParmToNonPackOnArg(), PrevDecl)) return D2; // Update InsertPos, because preceding import calls may have invalidated diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 2e1ed9e10713a8b..fe8734d262a961c 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -957,18 +957,20 @@ FunctionTemplateSpecializationInfo *FunctionTemplateSpecializationInfo::Create( // ClassTemplateSpecializationDecl Implementation //===---
[clang] Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)" (PR #125348)
vinay-deshmukh wrote: @steakhal You can use: `vinay_deshmukh` AT `outlook` DOT `com` Thank you for looking into the issue again! https://github.com/llvm/llvm-project/pull/125348 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AST] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125379)
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/125379 Note that PointerUnion::dyn_cast has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with //isa, cast and the llvm::dyn_cast This patch migrates the use of PointerUnion::dyn_cast to dyn_cast_if_present because the non-const variant of getInitializedFieldInUnion is known to encounter null in ArrayFillerOrUnionFieldInit. See: commit 563c7c5539f05e7f8cbb42565c1f24466019f38b Author: Kazu Hirata Date: Sat Jan 25 14:05:01 2025 -0800 FWIW, I am not aware of any test case in check-clang that triggers null here. >From 6eda70bfeacd2ac76227d8b06f6def48c7020eb4 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 1 Feb 2025 12:36:01 -0800 Subject: [PATCH] [AST] Migrate away from PointerUnion::dyn_cast (NFC) Note that PointerUnion::dyn_cast has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with //isa, cast and the llvm::dyn_cast This patch migrates the use of PointerUnion::dyn_cast to dyn_cast_if_present because the non-const variant of getInitializedFieldInUnion is known to encounter null in ArrayFillerOrUnionFieldInit. See: commit 563c7c5539f05e7f8cbb42565c1f24466019f38b Author: Kazu Hirata Date: Sat Jan 25 14:05:01 2025 -0800 FWIW, I am not aware of any test case in check-clang that triggers null here. --- clang/include/clang/AST/ExprCXX.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 0b6c8cfb163c958..98ba2bb41bb54d9 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -5040,7 +5040,7 @@ class CXXParenListInitExpr final } const FieldDecl *getInitializedFieldInUnion() const { -return ArrayFillerOrUnionFieldInit.dyn_cast(); +return dyn_cast_if_present(ArrayFillerOrUnionFieldInit); } child_range children() { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Lex] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125380)
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/125380 Note that PointerUnion::dyn_cast has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with //isa, cast and the llvm::dyn_cast This patch migrates the use of PointerUnion::dyn_cast to dyn_cast_if_present because State is not guaranteed to be nonnull elsewhere in this class. See: commit 563c7c5539f05e7f8cbb42565c1f24466019f38b Author: Kazu Hirata Date: Sat Jan 25 14:05:01 2025 -0800 FWIW, I am not aware of any test case in check-clang that triggers null here. >From 236ab9e6ddf0cb24e50f7a6d2b62eb984986079c Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 1 Feb 2025 12:54:02 -0800 Subject: [PATCH] [Lex] Migrate away from PointerUnion::dyn_cast (NFC) Note that PointerUnion::dyn_cast has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with //isa, cast and the llvm::dyn_cast This patch migrates the use of PointerUnion::dyn_cast to dyn_cast_if_present because State is not guaranteed to be nonnull elsewhere in this class. See: commit 563c7c5539f05e7f8cbb42565c1f24466019f38b Author: Kazu Hirata Date: Sat Jan 25 14:05:01 2025 -0800 FWIW, I am not aware of any test case in check-clang that triggers null here. --- clang/include/clang/Lex/Preprocessor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 416f403c298410c..2bf4d1a16699430 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -933,7 +933,7 @@ class Preprocessor { } ArrayRef getOverriddenMacros() const { - if (auto *Info = State.dyn_cast()) + if (auto *Info = dyn_cast_if_present(State)) return Info->OverriddenMacros; return {}; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Lex] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125380)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) Changes Note that PointerUnion::dyn_cast has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with //isa, cast and the llvm::dyn_cast This patch migrates the use of PointerUnion::dyn_cast to dyn_cast_if_present because State is not guaranteed to be nonnull elsewhere in this class. See: commit 563c7c5539f05e7f8cbb42565c1f24466019f38b Author: Kazu Hirata Date: Sat Jan 25 14:05:01 2025 -0800 FWIW, I am not aware of any test case in check-clang that triggers null here. --- Full diff: https://github.com/llvm/llvm-project/pull/125380.diff 1 Files Affected: - (modified) clang/include/clang/Lex/Preprocessor.h (+1-1) ``diff diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 416f403c298410..2bf4d1a1669943 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -933,7 +933,7 @@ class Preprocessor { } ArrayRef getOverriddenMacros() const { - if (auto *Info = State.dyn_cast()) + if (auto *Info = dyn_cast_if_present(State)) return Info->OverriddenMacros; return {}; } `` https://github.com/llvm/llvm-project/pull/125380 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125381)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) Changes Note that PointerUnion::dyn_cast has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with //isa, cast and the llvm::dyn_cast Literal migration would result in dyn_cast_if_present (see the definition of PointerUnion::dyn_cast), but this patch uses dyn_cast because we expect Storage to be nonnull. --- Full diff: https://github.com/llvm/llvm-project/pull/125381.diff 1 Files Affected: - (modified) clang/tools/libclang/CIndex.cpp (+4-4) ``diff diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 42f095fea2db26..bf7fdeec0cc51b 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -7415,11 +7415,11 @@ unsigned clang_getNumOverloadedDecls(CXCursor C) { return 0; OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(C).first; - if (const OverloadExpr *E = Storage.dyn_cast()) + if (const OverloadExpr *E = dyn_cast(Storage)) return E->getNumDecls(); if (OverloadedTemplateStorage *S = - Storage.dyn_cast()) + dyn_cast(Storage)) return S->size(); const Decl *D = cast(Storage); @@ -7438,11 +7438,11 @@ CXCursor clang_getOverloadedDecl(CXCursor cursor, unsigned index) { CXTranslationUnit TU = getCursorTU(cursor); OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(cursor).first; - if (const OverloadExpr *E = Storage.dyn_cast()) + if (const OverloadExpr *E = dyn_cast(Storage)) return MakeCXCursor(E->decls_begin()[index], TU); if (OverloadedTemplateStorage *S = - Storage.dyn_cast()) + dyn_cast(Storage)) return MakeCXCursor(S->begin()[index], TU); const Decl *D = cast(Storage); `` https://github.com/llvm/llvm-project/pull/125381 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125381)
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/125381 Note that PointerUnion::dyn_cast has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with //isa, cast and the llvm::dyn_cast Literal migration would result in dyn_cast_if_present (see the definition of PointerUnion::dyn_cast), but this patch uses dyn_cast because we expect Storage to be nonnull. >From 3e29632322b575eae8302d931a3dcc4d5bad9d08 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 1 Feb 2025 14:00:00 -0800 Subject: [PATCH] [libclang] Migrate away from PointerUnion::dyn_cast (NFC) Note that PointerUnion::dyn_cast has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with //isa, cast and the llvm::dyn_cast Literal migration would result in dyn_cast_if_present (see the definition of PointerUnion::dyn_cast), but this patch uses dyn_cast because we expect Storage to be nonnull. --- clang/tools/libclang/CIndex.cpp | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 42f095fea2db26..bf7fdeec0cc51b 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -7415,11 +7415,11 @@ unsigned clang_getNumOverloadedDecls(CXCursor C) { return 0; OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(C).first; - if (const OverloadExpr *E = Storage.dyn_cast()) + if (const OverloadExpr *E = dyn_cast(Storage)) return E->getNumDecls(); if (OverloadedTemplateStorage *S = - Storage.dyn_cast()) + dyn_cast(Storage)) return S->size(); const Decl *D = cast(Storage); @@ -7438,11 +7438,11 @@ CXCursor clang_getOverloadedDecl(CXCursor cursor, unsigned index) { CXTranslationUnit TU = getCursorTU(cursor); OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(cursor).first; - if (const OverloadExpr *E = Storage.dyn_cast()) + if (const OverloadExpr *E = dyn_cast(Storage)) return MakeCXCursor(E->decls_begin()[index], TU); if (OverloadedTemplateStorage *S = - Storage.dyn_cast()) + dyn_cast(Storage)) return MakeCXCursor(S->begin()[index], TU); const Decl *D = cast(Storage); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AST] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125379)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) Changes Note that PointerUnion::dyn_cast has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with //isa, cast and the llvm::dyn_cast This patch migrates the use of PointerUnion::dyn_cast to dyn_cast_if_present because the non-const variant of getInitializedFieldInUnion is known to encounter null in ArrayFillerOrUnionFieldInit. See: commit 563c7c5539f05e7f8cbb42565c1f24466019f38b Author: Kazu Hirata Date: Sat Jan 25 14:05:01 2025 -0800 FWIW, I am not aware of any test case in check-clang that triggers null here. --- Full diff: https://github.com/llvm/llvm-project/pull/125379.diff 1 Files Affected: - (modified) clang/include/clang/AST/ExprCXX.h (+1-1) ``diff diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 0b6c8cfb163c958..98ba2bb41bb54d9 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -5040,7 +5040,7 @@ class CXXParenListInitExpr final } const FieldDecl *getInitializedFieldInUnion() const { -return ArrayFillerOrUnionFieldInit.dyn_cast(); +return dyn_cast_if_present(ArrayFillerOrUnionFieldInit); } child_range children() { `` https://github.com/llvm/llvm-project/pull/125379 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AArch64] Enable vscale_range with +sme (PR #124466)
davemgreen wrote: /cherry-pick 9f1c825fb62319b94ac9604f733afd59e9eb461b https://github.com/llvm/llvm-project/pull/124466 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AArch64] Enable vscale_range with +sme (PR #124466)
https://github.com/davemgreen milestoned https://github.com/llvm/llvm-project/pull/124466 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AArch64] Enable vscale_range with +sme (PR #124466)
llvmbot wrote: /pull-request llvm/llvm-project#125386 https://github.com/llvm/llvm-project/pull/124466 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] e11e65f - [CodeGen] Migrate away from PointerUnion::dyn_cast (NFC) (#125336)
Author: Kazu Hirata Date: 2025-02-01T08:13:41-08:00 New Revision: e11e65f08b00a96916ce5ec21bf31d061158829d URL: https://github.com/llvm/llvm-project/commit/e11e65f08b00a96916ce5ec21bf31d061158829d DIFF: https://github.com/llvm/llvm-project/commit/e11e65f08b00a96916ce5ec21bf31d061158829d.diff LOG: [CodeGen] Migrate away from PointerUnion::dyn_cast (NFC) (#125336) Note that PointerUnion::dyn_cast has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with //isa, cast and the llvm::dyn_cast Literal migration would result in dyn_cast_if_present (see the definition of PointerUnion::dyn_cast), but this patch uses dyn_cast because we expect E to be nonnull. Added: Modified: clang/lib/CodeGen/MicrosoftCXXABI.cpp Removed: diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp index 0d53e8cb45fe77..4a2630e83b62db 100644 --- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -1996,8 +1996,8 @@ CGCallee MicrosoftCXXABI::getVirtualFunctionPointer(CodeGenFunction &CGF, llvm::Value *MicrosoftCXXABI::EmitVirtualDestructorCall( CodeGenFunction &CGF, const CXXDestructorDecl *Dtor, CXXDtorType DtorType, Address This, DeleteOrMemberCallExpr E, llvm::CallBase **CallOrInvoke) { - auto *CE = E.dyn_cast(); - auto *D = E.dyn_cast(); + auto *CE = dyn_cast(E); + auto *D = dyn_cast(E); assert((CE != nullptr) ^ (D != nullptr)); assert(CE == nullptr || CE->arg_begin() == CE->arg_end()); assert(DtorType == Dtor_Deleting || DtorType == Dtor_Complete); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CodeGen] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125336)
https://github.com/kazutakahirata closed https://github.com/llvm/llvm-project/pull/125336 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] b798679 - test: correct a typo in the check identifier (NFCI)
Author: Saleem Abdulrasool Date: 2025-02-01T14:49:29-08:00 New Revision: b798679c076af4acaa806e893b038372f5954298 URL: https://github.com/llvm/llvm-project/commit/b798679c076af4acaa806e893b038372f5954298 DIFF: https://github.com/llvm/llvm-project/commit/b798679c076af4acaa806e893b038372f5954298.diff LOG: test: correct a typo in the check identifier (NFCI) This corrects a swapped order of the spelling of blocks in the check. This enables the correct forward declarations which were previously disabled. Added: Modified: clang/test/CodeGen/blocks-windows.c Removed: diff --git a/clang/test/CodeGen/blocks-windows.c b/clang/test/CodeGen/blocks-windows.c index 4379cd2e6b63ac..3da5f3d99bd23d 100644 --- a/clang/test/CodeGen/blocks-windows.c +++ b/clang/test/CodeGen/blocks-windows.c @@ -2,43 +2,43 @@ // RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -DBLOCKS_IN_BLOCKS_DEFN -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-IN-BLOCKS-DEFN // RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS // RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -DBLOCKS_NOT_IN_BLOCKS_EXTERN -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-EXTERN -// RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -DBLCOKS_NOT_IN_BLOCKS_EXTERN_DLLIMPORT -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-EXTERN-DLLIMPORT -// RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -DBLCOKS_NOT_IN_BLOCKS_DLLIMPORT -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-DLLIMPORT +// RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -DBLOCKS_NOT_IN_BLOCKS_EXTERN_DLLIMPORT -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-EXTERN-DLLIMPORT +// RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -DBLOCKS_NOT_IN_BLOCKS_DLLIMPORT -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-DLLIMPORT // RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -DBLOCKS_IN_BLOCKS_DECL -Os -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-IN-BLOCKS-DECL // RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -DBLOCKS_IN_BLOCKS_DEFN -Os -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-IN-BLOCKS-DEFN // RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -Os -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS // RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -DBLOCKS_NOT_IN_BLOCKS_EXTERN -Os -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-EXTERN -// RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -DBLCOKS_NOT_IN_BLOCKS_EXTERN_DLLIMPORT -Os -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-EXTERN-DLLIMPORT -// RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -DBLCOKS_NOT_IN_BLOCKS_DLLIMPORT -Os -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-DLLIMPORT +// RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -DBLOCKS_NOT_IN_BLOCKS_EXTERN_DLLIMPORT -Os -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-EXTERN-DLLIMPORT +// RUN: %clang_cc1 -triple thumbv7-windows -fblocks -fdeclspec -DBLOCKS_NOT_IN_BLOCKS_DLLIMPORT -Os -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-DLLIMPORT // RUN: %clang_cc1 -triple i686-windows -fblocks -fdeclspec -DBLOCKS_IN_BLOCKS_DECL -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-IN-BLOCKS-DECL // RUN: %clang_cc1 -triple i686-windows -fblocks -fdeclspec -DBLOCKS_IN_BLOCKS_DEFN -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-IN-BLOCKS-DEFN // RUN: %clang_cc1 -triple i686-windows -fblocks -fdeclspec -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS // RUN: %clang_cc1 -triple i686-windows -fblocks -fdeclspec -DBLOCKS_NOT_IN_BLOCKS_EXTERN -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-EXTERN -// RUN: %clang_cc1 -triple i686-windows -fblocks -fdeclspec -DBLCOKS_NOT_IN_BLOCKS_EXTERN_DLLIMPORT -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-EXTERN-DLLIMPORT -// RUN: %clang_cc1 -triple i686-windows -fblocks -fdeclspec -DBLCOKS_NOT_IN_BLOCKS_DLLIMPORT -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-DLLIMPORT +// RUN: %clang_cc1 -triple i686-windows -fblocks -fdeclspec -DBLOCKS_NOT_IN_BLOCKS_EXTERN_DLLIMPORT -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-EXTERN-DLLIMPORT +// RUN: %clang_cc1 -triple i686-windows -fblocks -fdeclspec -DBLOCKS_NOT_IN_BLOCKS_DLLIMPORT -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-BLOCKS-NOT-IN-BLOCKS-DLLIMPORT
[clang] Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)" (PR #125348)
steakhal wrote: @vinay-deshmukh What email should I use for attribution in the "Co-authored-by"? https://github.com/llvm/llvm-project/pull/125348 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)" (PR #125348)
https://github.com/steakhal edited https://github.com/llvm/llvm-project/pull/125348 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)" (PR #125348)
https://github.com/steakhal edited https://github.com/llvm/llvm-project/pull/125348 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reapply "[clang][bytecode] Stack-allocate bottom function frame" (#12… (PR #125349)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/125349 …5325) Move the BottomFrame to InterpState instead. >From 1f491bfbf6dd0bf81c7d531920276c5f6ac2c04d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Feb 2025 06:55:55 +0100 Subject: [PATCH] Reapply "[clang][bytecode] Stack-allocate bottom function frame" (#125325) Move the BottomFrame to InterpState instead. --- clang/lib/AST/ByteCode/Context.cpp | 5 + clang/lib/AST/ByteCode/EvalEmitter.cpp | 6 +- clang/lib/AST/ByteCode/Interp.h| 8 clang/lib/AST/ByteCode/InterpFrame.cpp | 20 ++-- clang/lib/AST/ByteCode/InterpFrame.h | 12 clang/lib/AST/ByteCode/InterpState.cpp | 12 ++-- clang/lib/AST/ByteCode/InterpState.h | 4 7 files changed, 46 insertions(+), 21 deletions(-) diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index a322700fc0d229..aa434d5c85921f 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -212,14 +212,11 @@ const llvm::fltSemantics &Context::getFloatSemantics(QualType T) const { bool Context::Run(State &Parent, const Function *Func) { { -InterpState State(Parent, *P, Stk, *this); -State.Current = new InterpFrame(State, Func, /*Caller=*/nullptr, CodePtr(), -Func->getArgSize()); +InterpState State(Parent, *P, Stk, *this, Func); if (Interpret(State)) { assert(Stk.empty()); return true; } - // State gets destroyed here, so the Stk.clear() below doesn't accidentally // remove values the State's destructor might access. } diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp index 8134bbf270363e..95149efbea9921 100644 --- a/clang/lib/AST/ByteCode/EvalEmitter.cpp +++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp @@ -17,11 +17,7 @@ using namespace clang::interp; EvalEmitter::EvalEmitter(Context &Ctx, Program &P, State &Parent, InterpStack &Stk) -: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx) { - // Create a dummy frame for the interpreter which does not have locals. - S.Current = - new InterpFrame(S, /*Func=*/nullptr, /*Caller=*/nullptr, CodePtr(), 0); -} +: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx) {} EvalEmitter::~EvalEmitter() { for (auto &[K, V] : Locals) { diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 063970afec9e35..2a39e3932077f5 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -325,11 +325,11 @@ bool Ret(InterpState &S, CodePtr &PC) { if (InterpFrame *Caller = S.Current->Caller) { PC = S.Current->getRetPC(); -delete S.Current; +InterpFrame::free(S.Current); S.Current = Caller; S.Stk.push(Ret); } else { -delete S.Current; +InterpFrame::free(S.Current); S.Current = nullptr; // The topmost frame should come from an EvalEmitter, // which has its own implementation of the Ret<> instruction. @@ -345,10 +345,10 @@ inline bool RetVoid(InterpState &S, CodePtr &PC) { if (InterpFrame *Caller = S.Current->Caller) { PC = S.Current->getRetPC(); -delete S.Current; +InterpFrame::free(S.Current); S.Current = Caller; } else { -delete S.Current; +InterpFrame::free(S.Current); S.Current = nullptr; } return true; diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp index 48a3db055c6c9b..89fc7a4515d641 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.cpp +++ b/clang/lib/AST/ByteCode/InterpFrame.cpp @@ -23,11 +23,15 @@ using namespace clang; using namespace clang::interp; +InterpFrame::InterpFrame(InterpState &S) +: Caller(nullptr), S(S), Depth(0), Func(nullptr), RetPC(CodePtr()), + ArgSize(0), Args(nullptr), FrameOffset(0), IsBottom(true) {} + InterpFrame::InterpFrame(InterpState &S, const Function *Func, InterpFrame *Caller, CodePtr RetPC, unsigned ArgSize) : Caller(Caller), S(S), Depth(Caller ? Caller->Depth + 1 : 0), Func(Func), RetPC(RetPC), ArgSize(ArgSize), Args(static_cast(S.Stk.top())), - FrameOffset(S.Stk.size()) { + FrameOffset(S.Stk.size()), IsBottom(!Caller) { if (!Func) return; @@ -73,11 +77,15 @@ InterpFrame::~InterpFrame() { // When destroying the InterpFrame, call the Dtor for all block // that haven't been destroyed via a destroy() op yet. // This happens when the execution is interruped midway-through. - if (Func) { -for (auto &Scope : Func->scopes()) { - for (auto &Local : Scope.locals()) { -S.deallocate(localBlock(Local.Offset)); - } + destroyScopes(); +} + +void InterpFrame::destroyScopes() { + if (!Func) +return; + for (auto &Scope : Func->scopes()) { +for (auto &Local : Scope.locals()) {
[clang] [clang module] Current Working Directory Pruning (PR #124786)
https://github.com/qiongsiwu updated https://github.com/llvm/llvm-project/pull/124786 >From 7060564de1bb6062639f4b4839fa17958f212755 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Mon, 27 Jan 2025 16:44:30 -0800 Subject: [PATCH 1/4] Initial implementation of clang modules current working directory pruning. --- .../DependencyScanningService.h | 5 +- .../DependencyScanning/ModuleDepCollector.cpp | 92 - .../ClangScanDeps/modules-context-hash-cwd.c | 123 ++ clang/test/ClangScanDeps/working-dir.m| 2 +- clang/tools/clang-scan-deps/ClangScanDeps.cpp | 2 + 5 files changed, 219 insertions(+), 5 deletions(-) create mode 100644 clang/test/ClangScanDeps/modules-context-hash-cwd.c diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h index 4a343f2872d8d97..9ad8e68c33eb106 100644 --- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h +++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h @@ -63,7 +63,10 @@ enum class ScanningOptimizations { /// Canonicalize -D and -U options. Macros = 8, - DSS_LAST_BITMASK_ENUM(Macros), + /// Ignore the compiler's working directory if it is safe. + IgnoreCWD = 0x10, + + DSS_LAST_BITMASK_ENUM(IgnoreCWD), Default = All }; diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index 2e97cac0796ceea..714efb86fa37960 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -397,9 +397,92 @@ void ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) { } } +static bool isSafeToIgnoreCWD(const CowCompilerInvocation &CI) { + // Check if the command line input uses relative paths. + // It is not safe to ignore the current working directory if any of the + // command line inputs use relative paths. +#define IF_RELATIVE_RETURN_FALSE(PATH) \ + do { \ +if (!PATH.empty() && !llvm::sys::path::is_absolute(PATH)) \ + return false; \ + } while (0) + +#define IF_ANY_RELATIVE_RETURN_FALSE(PATHS) \ + do { \ +if (std::any_of(PATHS.begin(), PATHS.end(), [](const auto &P) { \ + return !P.empty() && !llvm::sys::path::is_absolute(P); \ +})) \ + return false; \ + } while (0) + + // Header search paths. + const auto &HeaderSearchOpts = CI.getHeaderSearchOpts(); + IF_RELATIVE_RETURN_FALSE(HeaderSearchOpts.Sysroot); + for (auto &Entry : HeaderSearchOpts.UserEntries) +if (Entry.IgnoreSysRoot) + IF_RELATIVE_RETURN_FALSE(Entry.Path); + IF_RELATIVE_RETURN_FALSE(HeaderSearchOpts.ResourceDir); + IF_RELATIVE_RETURN_FALSE(HeaderSearchOpts.ModuleCachePath); + IF_RELATIVE_RETURN_FALSE(HeaderSearchOpts.ModuleUserBuildPath); + for (auto I = HeaderSearchOpts.PrebuiltModuleFiles.begin(), +E = HeaderSearchOpts.PrebuiltModuleFiles.end(); + I != E;) { +auto Current = I++; +IF_RELATIVE_RETURN_FALSE(Current->second); + } + IF_ANY_RELATIVE_RETURN_FALSE(HeaderSearchOpts.PrebuiltModulePaths); + IF_ANY_RELATIVE_RETURN_FALSE(HeaderSearchOpts.VFSOverlayFiles); + + // Preprocessor options. + const auto &PPOpts = CI.getPreprocessorOpts(); + IF_ANY_RELATIVE_RETURN_FALSE(PPOpts.MacroIncludes); + IF_ANY_RELATIVE_RETURN_FALSE(PPOpts.Includes); + IF_RELATIVE_RETURN_FALSE(PPOpts.ImplicitPCHInclude); + + // Frontend options. + const auto &FrontendOpts = CI.getFrontendOpts(); + for (const FrontendInputFile &Input : FrontendOpts.Inputs) { +if (Input.isBuffer()) + continue; // FIXME: Can this happen when parsing command-line? + +IF_RELATIVE_RETURN_FALSE(Input.getFile()); + } + IF_RELATIVE_RETURN_FALSE(FrontendOpts.CodeCompletionAt.FileName); + IF_ANY_RELATIVE_RETURN_FALSE(FrontendOpts.ModuleMapFiles); + IF_ANY_RELATIVE_RETURN_FALSE(FrontendOpts.ModuleFiles); + IF_ANY_RELATIVE_RETURN_FALSE(FrontendOpts.ModulesEmbedFiles); + IF_ANY_RELATIVE_RETURN_FALSE(FrontendOpts.ASTMergeFiles); + IF_RELATIVE_RETURN_FALSE(FrontendOpts.OverrideRecordLayoutsFile); + IF_RELATIVE_RETURN_FALSE(FrontendOpts.StatsFile); + + // Filesystem options. + const auto &FileSystemOpts = CI.getFileSystemOpts(); + IF_RELATIVE_RETURN_FALSE(FileSystemOpts.WorkingDir); + + // Codegen options. + const auto &CodeGenOpts = CI.getCodeGenOpts(); + IF_RELATIVE_RETURN_FALSE(CodeGenOpts.Debug
[clang] Patch series to reapply #118734 and substantially improve it (PR #120534)
Andarwinux wrote: https://github.com/llvm/llvm-project/pull/125367 RC1 coming soon https://github.com/llvm/llvm-project/pull/120534 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Hanlde qualified type name for `QualifierAlignment` (PR #125327)
owenca wrote: Same reason we almost never handle them, just like we (almost?) never handle the possibility of templated qualified names of arbitrary nesting levels (e.g. `A1::A2 … An`) and of comments before _every_ token. We can always tweak the code if and when we need to handle these rare cases. https://github.com/llvm/llvm-project/pull/125327 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 657dc6d - [AST] Migrate away from PointerUnion::dyn_cast (NFC) (#125335)
Author: Kazu Hirata Date: 2025-02-01T08:13:20-08:00 New Revision: 657dc6d05e8e20d5c3b41161ace7fba5d2cb6e26 URL: https://github.com/llvm/llvm-project/commit/657dc6d05e8e20d5c3b41161ace7fba5d2cb6e26 DIFF: https://github.com/llvm/llvm-project/commit/657dc6d05e8e20d5c3b41161ace7fba5d2cb6e26.diff LOG: [AST] Migrate away from PointerUnion::dyn_cast (NFC) (#125335) Note that PointerUnion::dyn_cast has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with //isa, cast and the llvm::dyn_cast Literal migration would result in dyn_cast_if_present (see the definition of PointerUnion::dyn_cast), but this patch uses dyn_cast because we expect InVectors.front() and P to be nonnull. Added: Modified: clang/lib/AST/TemplateName.cpp Removed: diff --git a/clang/lib/AST/TemplateName.cpp b/clang/lib/AST/TemplateName.cpp index 3a1eb1ca12f453..9e0a7dc2b8cdcb 100644 --- a/clang/lib/AST/TemplateName.cpp +++ b/clang/lib/AST/TemplateName.cpp @@ -144,7 +144,7 @@ TemplateName::TemplateName(DeducedTemplateStorage *Deduced) bool TemplateName::isNull() const { return Storage.isNull(); } TemplateName::NameKind TemplateName::getKind() const { - if (auto *ND = Storage.dyn_cast()) { + if (auto *ND = dyn_cast(Storage)) { if (isa(ND)) return UsingTemplate; assert(isa(ND)); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AST] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125335)
https://github.com/kazutakahirata closed https://github.com/llvm/llvm-project/pull/125335 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AST] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125335)
kazutakahirata wrote: > Feel free to batch some of these changes together in a single PR! Thanks! It's becoming harder to find occurrences where I can migrate `PU.dyn_cast` to `dyn_cast(PU)` (not to be confused with `dyn_cast_if_present(PU)`) because I have to convince myself that `PU` is never null. Not every places does `!PU.isNull()` or a dereference of `cast(PU)`. https://github.com/llvm/llvm-project/pull/125335 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reapply "[clang][bytecode] Stack-allocate bottom function frame" (#12… (PR #125349)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes …5325) Move the BottomFrame to InterpState instead. --- Full diff: https://github.com/llvm/llvm-project/pull/125349.diff 7 Files Affected: - (modified) clang/lib/AST/ByteCode/Context.cpp (+1-4) - (modified) clang/lib/AST/ByteCode/EvalEmitter.cpp (+1-5) - (modified) clang/lib/AST/ByteCode/Interp.h (+4-4) - (modified) clang/lib/AST/ByteCode/InterpFrame.cpp (+14-6) - (modified) clang/lib/AST/ByteCode/InterpFrame.h (+12) - (modified) clang/lib/AST/ByteCode/InterpState.cpp (+10-2) - (modified) clang/lib/AST/ByteCode/InterpState.h (+4) ``diff diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index a322700fc0d229..aa434d5c85921f 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -212,14 +212,11 @@ const llvm::fltSemantics &Context::getFloatSemantics(QualType T) const { bool Context::Run(State &Parent, const Function *Func) { { -InterpState State(Parent, *P, Stk, *this); -State.Current = new InterpFrame(State, Func, /*Caller=*/nullptr, CodePtr(), -Func->getArgSize()); +InterpState State(Parent, *P, Stk, *this, Func); if (Interpret(State)) { assert(Stk.empty()); return true; } - // State gets destroyed here, so the Stk.clear() below doesn't accidentally // remove values the State's destructor might access. } diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp index 8134bbf270363e..95149efbea9921 100644 --- a/clang/lib/AST/ByteCode/EvalEmitter.cpp +++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp @@ -17,11 +17,7 @@ using namespace clang::interp; EvalEmitter::EvalEmitter(Context &Ctx, Program &P, State &Parent, InterpStack &Stk) -: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx) { - // Create a dummy frame for the interpreter which does not have locals. - S.Current = - new InterpFrame(S, /*Func=*/nullptr, /*Caller=*/nullptr, CodePtr(), 0); -} +: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx) {} EvalEmitter::~EvalEmitter() { for (auto &[K, V] : Locals) { diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 063970afec9e35..2a39e3932077f5 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -325,11 +325,11 @@ bool Ret(InterpState &S, CodePtr &PC) { if (InterpFrame *Caller = S.Current->Caller) { PC = S.Current->getRetPC(); -delete S.Current; +InterpFrame::free(S.Current); S.Current = Caller; S.Stk.push(Ret); } else { -delete S.Current; +InterpFrame::free(S.Current); S.Current = nullptr; // The topmost frame should come from an EvalEmitter, // which has its own implementation of the Ret<> instruction. @@ -345,10 +345,10 @@ inline bool RetVoid(InterpState &S, CodePtr &PC) { if (InterpFrame *Caller = S.Current->Caller) { PC = S.Current->getRetPC(); -delete S.Current; +InterpFrame::free(S.Current); S.Current = Caller; } else { -delete S.Current; +InterpFrame::free(S.Current); S.Current = nullptr; } return true; diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp index 48a3db055c6c9b..89fc7a4515d641 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.cpp +++ b/clang/lib/AST/ByteCode/InterpFrame.cpp @@ -23,11 +23,15 @@ using namespace clang; using namespace clang::interp; +InterpFrame::InterpFrame(InterpState &S) +: Caller(nullptr), S(S), Depth(0), Func(nullptr), RetPC(CodePtr()), + ArgSize(0), Args(nullptr), FrameOffset(0), IsBottom(true) {} + InterpFrame::InterpFrame(InterpState &S, const Function *Func, InterpFrame *Caller, CodePtr RetPC, unsigned ArgSize) : Caller(Caller), S(S), Depth(Caller ? Caller->Depth + 1 : 0), Func(Func), RetPC(RetPC), ArgSize(ArgSize), Args(static_cast(S.Stk.top())), - FrameOffset(S.Stk.size()) { + FrameOffset(S.Stk.size()), IsBottom(!Caller) { if (!Func) return; @@ -73,11 +77,15 @@ InterpFrame::~InterpFrame() { // When destroying the InterpFrame, call the Dtor for all block // that haven't been destroyed via a destroy() op yet. // This happens when the execution is interruped midway-through. - if (Func) { -for (auto &Scope : Func->scopes()) { - for (auto &Local : Scope.locals()) { -S.deallocate(localBlock(Local.Offset)); - } + destroyScopes(); +} + +void InterpFrame::destroyScopes() { + if (!Func) +return; + for (auto &Scope : Func->scopes()) { +for (auto &Local : Scope.locals()) { + S.deallocate(localBlock(Local.Offset)); } } } diff --git a/clang/lib/AST/ByteCode/InterpFrame.h b/clang/lib/AST/ByteCode/InterpFrame.h index 7cfc3ac68b4f3e..360e6bff12327a 100644 --- a/clang/lib/AST/B
[clang] Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)" (PR #125348)
https://github.com/steakhal created https://github.com/llvm/llvm-project/pull/125348 This is the second attempt to bring initial support for [[assume()]] in the Clang Static Analyzer. The first attempt (#116462) was reverted in 2b9abf0db2d106c7208b4372e662ef5df869e6f1 due to some weird failure in a libcxx test involving `#pragma clang loop vectorize(enable) interleave(enable)`. The failure could be reduced into: ```c++ template void transform(ExecutionPolicy) { #pragma clang loop vectorize(enable) interleave(enable) for (int i = 0; 0;) { // The DeclStmt of "i" would be added twice in the ThreadSafety analysis. // empty } } void entrypoint() { transform(1); } ``` As it turns out, the problem with the initial patch was this: ```c++ for (const auto *Attr : AS->getAttrs()) { if (const auto *AssumeAttr = dyn_cast(Attr)) { Expr *AssumeExpr = AssumeAttr->getAssumption(); if (!AssumeExpr->HasSideEffects(Ctx)) { childrenBuf.push_back(AssumeExpr); } } // Visit the actual children AST nodes. // For CXXAssumeAttrs, this is always a NullStmt. llvm::append_range(childrenBuf, AS->children()); // <--- This was not meant to be part of the "for" loop. children = childrenBuf; } return; ``` The solution was simple. Just hoist it from the loop. I also had a closer look at `CFGBuilder::VisitAttributedStmt`, where I also spotted another bug. We would have added the CFG blocks twice if the AttributedStmt would have both the `[[fallthrough]]` and the `[[assume()]]` attributes. With my fix, it will only once add the blocks. Added a regression test for this. >From 3eb338e0e4306bd961164045aef726b41fa225d7 Mon Sep 17 00:00:00 2001 From: Balazs Benics Date: Sat, 1 Feb 2025 10:03:27 +0100 Subject: [PATCH 1/2] Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond) (#116462)" This reverts commit 2b9abf0db2d106c7208b4372e662ef5df869e6f1. --- clang/include/clang/AST/AttrIterator.h| 12 .../Core/PathSensitive/ExprEngine.h | 4 ++ clang/lib/Analysis/CFG.cpp| 72 +-- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 8 ++- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp | 7 +- .../lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | 18 + .../test/Analysis/cxx23-assume-attribute.cpp | 58 +++ clang/test/Analysis/out-of-bounds-new.cpp | 64 - 8 files changed, 218 insertions(+), 25 deletions(-) create mode 100644 clang/test/Analysis/cxx23-assume-attribute.cpp diff --git a/clang/include/clang/AST/AttrIterator.h b/clang/include/clang/AST/AttrIterator.h index 7e2bb0381d4c8f0..2f39c144dc1608a 100644 --- a/clang/include/clang/AST/AttrIterator.h +++ b/clang/include/clang/AST/AttrIterator.h @@ -16,6 +16,7 @@ #include "clang/Basic/LLVM.h" #include "llvm/ADT/ADL.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/Support/Casting.h" #include #include @@ -124,6 +125,17 @@ inline auto *getSpecificAttr(const Container &container) { return It != specific_attr_end(container) ? *It : nullptr; } +template +inline auto getSpecificAttrs(const Container &container) { + using ValueTy = llvm::detail::ValueOfRange; + using ValuePointeeTy = std::remove_pointer_t; + using IterTy = std::conditional_t, +const SpecificAttr, SpecificAttr>; + auto Begin = specific_attr_begin(container); + auto End = specific_attr_end(container); + return llvm::make_range(Begin, End); +} + } // namespace clang #endif // LLVM_CLANG_AST_ATTRITERATOR_H diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h index 20c446e33ef9a5a..df26f9abe22a188 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h @@ -498,6 +498,10 @@ class ExprEngine { void VisitInitListExpr(const InitListExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst); + /// VisitAttributedStmt - Transfer function logic for AttributedStmt + void VisitAttributedStmt(const AttributedStmt *A, ExplodedNode *Pred, + ExplodedNodeSet &Dst); + /// VisitLogicalExpr - Transfer function logic for '&&', '||' void VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred, ExplodedNodeSet &Dst); diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 304bbb2b422c61d..65f915ef087afab 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -433,7 +433,7 @@ class reverse_children { ArrayRef children; public: - reverse_children(Stmt *S); + reverse_children(Stmt *S, ASTContext &Ctx); using iterator = ArrayRef::reverse_iterator; @@ -443,28 +443,47 @@ class reverse_children { } // namespace -reverse_children::reverse_children(Stmt *S) { - if (CallExpr *CE =
[clang] Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)" (PR #125348)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Balazs Benics (steakhal) Changes This is the second attempt to bring initial support for [[assume()]] in the Clang Static Analyzer. The first attempt (#116462) was reverted in 2b9abf0db2d106c7208b4372e662ef5df869e6f1 due to some weird failure in a libcxx test involving `#pragma clang loop vectorize(enable) interleave(enable)`. The failure could be reduced into: ```c++ templatevoid transform(ExecutionPolicy) { #pragma clang loop vectorize(enable) interleave(enable) for (int i = 0; 0;) { // The DeclStmt of "i" would be added twice in the ThreadSafety analysis. // empty } } void entrypoint() { transform(1); } ``` As it turns out, the problem with the initial patch was this: ```c++ for (const auto *Attr : AS->getAttrs()) { if (const auto *AssumeAttr = dyn_cast (Attr)) { Expr *AssumeExpr = AssumeAttr->getAssumption(); if (!AssumeExpr->HasSideEffects(Ctx)) { childrenBuf.push_back(AssumeExpr); } } // Visit the actual children AST nodes. // For CXXAssumeAttrs, this is always a NullStmt. llvm::append_range(childrenBuf, AS->children()); // <--- This was not meant to be part of the "for" loop. children = childrenBuf; } return; ``` The solution was simple. Just hoist it from the loop. I also had a closer look at `CFGBuilder::VisitAttributedStmt`, where I also spotted another bug. We would have added the CFG blocks twice if the AttributedStmt would have both the `[[fallthrough]]` and the `[[assume()]]` attributes. With my fix, it will only once add the blocks. Added a regression test for this. --- Full diff: https://github.com/llvm/llvm-project/pull/125348.diff 8 Files Affected: - (modified) clang/include/clang/AST/AttrIterator.h (+12) - (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h (+4) - (modified) clang/lib/Analysis/CFG.cpp (+48-16) - (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (+7-1) - (modified) clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp (+4-3) - (modified) clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (+18) - (added) clang/test/Analysis/cxx23-assume-attribute.cpp (+77) - (modified) clang/test/Analysis/out-of-bounds-new.cpp (+63-1) ``diff diff --git a/clang/include/clang/AST/AttrIterator.h b/clang/include/clang/AST/AttrIterator.h index 7e2bb0381d4c8f0..2f39c144dc1608a 100644 --- a/clang/include/clang/AST/AttrIterator.h +++ b/clang/include/clang/AST/AttrIterator.h @@ -16,6 +16,7 @@ #include "clang/Basic/LLVM.h" #include "llvm/ADT/ADL.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/Support/Casting.h" #include #include @@ -124,6 +125,17 @@ inline auto *getSpecificAttr(const Container &container) { return It != specific_attr_end(container) ? *It : nullptr; } +template +inline auto getSpecificAttrs(const Container &container) { + using ValueTy = llvm::detail::ValueOfRange; + using ValuePointeeTy = std::remove_pointer_t; + using IterTy = std::conditional_t, +const SpecificAttr, SpecificAttr>; + auto Begin = specific_attr_begin(container); + auto End = specific_attr_end(container); + return llvm::make_range(Begin, End); +} + } // namespace clang #endif // LLVM_CLANG_AST_ATTRITERATOR_H diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h index 20c446e33ef9a5a..df26f9abe22a188 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h @@ -498,6 +498,10 @@ class ExprEngine { void VisitInitListExpr(const InitListExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst); + /// VisitAttributedStmt - Transfer function logic for AttributedStmt + void VisitAttributedStmt(const AttributedStmt *A, ExplodedNode *Pred, + ExplodedNodeSet &Dst); + /// VisitLogicalExpr - Transfer function logic for '&&', '||' void VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred, ExplodedNodeSet &Dst); diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 304bbb2b422c61d..5b119f08e91dd8b 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -433,7 +433,7 @@ class reverse_children { ArrayRef children; public: - reverse_children(Stmt *S); + reverse_children(Stmt *S, ASTContext &Ctx); using iterator = ArrayRef::reverse_iterator; @@ -443,21 +443,44 @@ class reverse_children { } // namespace -reverse_children::reverse_children(Stmt *S) { - if (CallExpr *CE = dyn_cast(S)) { -children = CE->getRawSubExprs(); +reverse_children::reverse_children(Stmt *S, ASTContext &Ctx) { + switch (S->getStmtClass()) { + case Stmt::CallExprClass: { +children = cast(S)->getRawSubExprs(
[clang] Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)" (PR #125348)
steakhal wrote: @Xazax-hun Please have a thorough review of this one. https://github.com/llvm/llvm-project/pull/125348 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] allow restrict qualifier for array types with pointer types as element types (PR #120896)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/120896 >From 295df258043ef5a87ae603eedd308b863bad7b59 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sun, 22 Dec 2024 15:14:30 +0200 Subject: [PATCH 1/3] [Clang] allow restrict qualifier for array types with pointer types as element types --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaType.cpp | 4 +++- clang/test/Sema/types.c | 10 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6b9e1109f3906e..52daea9b8eb2b6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -332,6 +332,7 @@ C Language Changes -- - Extend clang's to define ``LONG_LONG_*`` macros for Android's bionic. +- Clang now allows ``restrict`` qualifier for array types with pointer elements (#GH92847). C2y Feature Support ^^^ diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 83464c50b4b238..e84daeee679a57 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1595,12 +1595,14 @@ QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc, QualType ProblemTy; if (T->isAnyPointerType() || T->isReferenceType() || -T->isMemberPointerType()) { +T->isMemberPointerType() || T->isArrayType()) { QualType EltTy; if (T->isObjCObjectPointerType()) EltTy = T; else if (const MemberPointerType *PTy = T->getAs()) EltTy = PTy->getPointeeType(); + else if (T->isArrayType()) +EltTy = Context.getBaseElementType(T); else EltTy = T->getPointeeType(); diff --git a/clang/test/Sema/types.c b/clang/test/Sema/types.c index e0a6ba4f0691b9..4c90634b7ce284 100644 --- a/clang/test/Sema/types.c +++ b/clang/test/Sema/types.c @@ -9,20 +9,20 @@ typedef int (*T)[2]; restrict T x; typedef int *S[2]; -restrict S y; // expected-error {{restrict requires a pointer or reference ('S' (aka 'int *[2]') is invalid)}} - - +restrict S y; // int128_t is available. int a(void) { __int128_t s; __uint128_t t; -} +} // expected-warning {{non-void function does not return a value}} + // but not a keyword int b(void) { int __int128_t; int __uint128_t; -} +} // expected-warning {{non-void function does not return a value}} + // __int128 is a keyword int c(void) { __int128 i; >From 9e8dcdb20a3dd1ea9b49d501c2593d1ac1c7e424 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 31 Jan 2025 23:54:03 +0200 Subject: [PATCH 2/3] add additional tests --- clang/lib/Sema/SemaType.cpp | 2 +- clang/test/Sema/restrict-qualifier.c | 20 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 clang/test/Sema/restrict-qualifier.c diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index e84daeee679a57..ab85d6f51d22f7 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1602,7 +1602,7 @@ QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc, else if (const MemberPointerType *PTy = T->getAs()) EltTy = PTy->getPointeeType(); else if (T->isArrayType()) -EltTy = Context.getBaseElementType(T); +EltTy = BuildQualifiedType(Context.getBaseElementType(T), Loc, Qs); else EltTy = T->getPointeeType(); diff --git a/clang/test/Sema/restrict-qualifier.c b/clang/test/Sema/restrict-qualifier.c new file mode 100644 index 00..a68e55b47b5808 --- /dev/null +++ b/clang/test/Sema/restrict-qualifier.c @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -std=c2y -fsyntax-only -verify -pedantic %s + +typedef int (*T1)[2]; +restrict T1 t1; +static_assert(_Generic(typeof (t1), int (*restrict)[2] : 1, default : 0)); + +typedef int *T2[2]; +restrict T2 t2; +static_assert(_Generic(typeof (t2), int *restrict[2] : 1, default : 0)); + +typedef int *T3[2][2]; +restrict T3 t3; +static_assert(_Generic(typeof (t3), int *restrict[2][2] : 1, default : 0)); + +typedef int (*t4)(); +typedef t4 t5[2]; +typedef t5 restrict t6; // expected-error {{pointer to function type 'int (void)' may not be 'restrict' qualified}} + +typedef int t7[2]; +typedef t7 restrict t8; // expected-error {{restrict requires a pointer or reference ('int' is invalid)}} >From 7c85906d8a35abfa84ae20f7af952e2a15b6fa0f Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 1 Feb 2025 15:00:19 +0200 Subject: [PATCH 3/3] adjust array handling for clearer inner type check --- clang/lib/Sema/SemaType.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index da635224823908..3dd4952a829e09 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1598,12 +1598,14 @@ QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc, if (T->isAnyPointerType() || T->isReferenceType() ||
[clang] [Sema] Add code completion for if constexpr (PR #124315)
https://github.com/Lancern requested changes to this pull request. Thanks for working on this! Please add a test for your patch. You can take tests under `clang/test/CodeCompletion` for reference. https://github.com/llvm/llvm-project/pull/124315 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reland: [clang] Track function template instantiation from definition (PR #125266)
@@ -2298,6 +2298,13 @@ class FunctionDecl : public DeclaratorDecl, FunctionDeclBits.IsLateTemplateParsed = ILT; } + bool isInstantiatedFromMemberTemplate() const { +return FunctionDeclBits.IsInstantiatedFromMemberTemplate; + } + void setInstantiatedFromMemberTemplate(bool Val = true) { +FunctionDeclBits.IsInstantiatedFromMemberTemplate = Val; + } + cor3ntin wrote: Is that even used? https://github.com/llvm/llvm-project/pull/125266 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reland: [clang] Track function template instantiation from definition (PR #125266)
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/125266 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Hanlde qualified type name for `QualifierAlignment` (PR #125327)
HazardyKnusperkeks wrote: > > Seems to also work for top-level types (`::int_64_t constexpr x{123};` > > works correctly) but breaks for fully qualified types (`::std::int64_t > > constexpr x{123};` becomes `::constexpr std::int64_t x{123};`) > > Yeah, I intentionally didn't want to use a loop for names like `A1::A2:: ... > ::An` and instead just wanted to handle single-level nested names like `A::B`. But why? https://github.com/llvm/llvm-project/pull/125327 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)
createyourpersonalaccount wrote: @owenca @mydeveloperday @HazardyKnusperkeks I'll ping now that it's the weekend, perhaps you have some time to look at this more; in particular now I got the `--null` option to work for `--staged`, but I'm not sure how you'd like it to work for other options. I've explained my concerns in https://github.com/llvm/llvm-project/pull/123926#issuecomment-2614296866 https://github.com/llvm/llvm-project/pull/123926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 06130ed - Reapply "[clang][bytecode] Stack-allocate bottom function frame" (#12… (#125349)
Author: Timm Baeder Date: 2025-02-01T18:12:35+01:00 New Revision: 06130ed341ddbf697045731300651fbbcb63f0ff URL: https://github.com/llvm/llvm-project/commit/06130ed341ddbf697045731300651fbbcb63f0ff DIFF: https://github.com/llvm/llvm-project/commit/06130ed341ddbf697045731300651fbbcb63f0ff.diff LOG: Reapply "[clang][bytecode] Stack-allocate bottom function frame" (#12… (#125349) …5325) Move the BottomFrame to InterpState instead. Added: Modified: clang/lib/AST/ByteCode/Context.cpp clang/lib/AST/ByteCode/EvalEmitter.cpp clang/lib/AST/ByteCode/Interp.h clang/lib/AST/ByteCode/InterpFrame.cpp clang/lib/AST/ByteCode/InterpFrame.h clang/lib/AST/ByteCode/InterpState.cpp clang/lib/AST/ByteCode/InterpState.h Removed: diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index a322700fc0d229..aa434d5c85921f 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -212,14 +212,11 @@ const llvm::fltSemantics &Context::getFloatSemantics(QualType T) const { bool Context::Run(State &Parent, const Function *Func) { { -InterpState State(Parent, *P, Stk, *this); -State.Current = new InterpFrame(State, Func, /*Caller=*/nullptr, CodePtr(), -Func->getArgSize()); +InterpState State(Parent, *P, Stk, *this, Func); if (Interpret(State)) { assert(Stk.empty()); return true; } - // State gets destroyed here, so the Stk.clear() below doesn't accidentally // remove values the State's destructor might access. } diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp index 8134bbf270363e..95149efbea9921 100644 --- a/clang/lib/AST/ByteCode/EvalEmitter.cpp +++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp @@ -17,11 +17,7 @@ using namespace clang::interp; EvalEmitter::EvalEmitter(Context &Ctx, Program &P, State &Parent, InterpStack &Stk) -: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx) { - // Create a dummy frame for the interpreter which does not have locals. - S.Current = - new InterpFrame(S, /*Func=*/nullptr, /*Caller=*/nullptr, CodePtr(), 0); -} +: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx) {} EvalEmitter::~EvalEmitter() { for (auto &[K, V] : Locals) { diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 063970afec9e35..2a39e3932077f5 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -325,11 +325,11 @@ bool Ret(InterpState &S, CodePtr &PC) { if (InterpFrame *Caller = S.Current->Caller) { PC = S.Current->getRetPC(); -delete S.Current; +InterpFrame::free(S.Current); S.Current = Caller; S.Stk.push(Ret); } else { -delete S.Current; +InterpFrame::free(S.Current); S.Current = nullptr; // The topmost frame should come from an EvalEmitter, // which has its own implementation of the Ret<> instruction. @@ -345,10 +345,10 @@ inline bool RetVoid(InterpState &S, CodePtr &PC) { if (InterpFrame *Caller = S.Current->Caller) { PC = S.Current->getRetPC(); -delete S.Current; +InterpFrame::free(S.Current); S.Current = Caller; } else { -delete S.Current; +InterpFrame::free(S.Current); S.Current = nullptr; } return true; diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp index 48a3db055c6c9b..89fc7a4515d641 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.cpp +++ b/clang/lib/AST/ByteCode/InterpFrame.cpp @@ -23,11 +23,15 @@ using namespace clang; using namespace clang::interp; +InterpFrame::InterpFrame(InterpState &S) +: Caller(nullptr), S(S), Depth(0), Func(nullptr), RetPC(CodePtr()), + ArgSize(0), Args(nullptr), FrameOffset(0), IsBottom(true) {} + InterpFrame::InterpFrame(InterpState &S, const Function *Func, InterpFrame *Caller, CodePtr RetPC, unsigned ArgSize) : Caller(Caller), S(S), Depth(Caller ? Caller->Depth + 1 : 0), Func(Func), RetPC(RetPC), ArgSize(ArgSize), Args(static_cast(S.Stk.top())), - FrameOffset(S.Stk.size()) { + FrameOffset(S.Stk.size()), IsBottom(!Caller) { if (!Func) return; @@ -73,11 +77,15 @@ InterpFrame::~InterpFrame() { // When destroying the InterpFrame, call the Dtor for all block // that haven't been destroyed via a destroy() op yet. // This happens when the execution is interruped midway-through. - if (Func) { -for (auto &Scope : Func->scopes()) { - for (auto &Local : Scope.locals()) { -S.deallocate(localBlock(Local.Offset)); - } + destroyScopes(); +} + +void InterpFrame::destroyScopes() { + if (!Func) +return; + for (auto &Scope : Func->scopes()) { +for (auto &Local : Scope.locals()) { + S.deallo
[clang] [clang-format] Fix a bug in annotating ClassHeadName (PR #125326)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/125326 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reapply "[clang][bytecode] Stack-allocate bottom function frame" (#12… (PR #125349)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/125349 ___ 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 readability-string-view-substr check (PR #120055)
hjanuschka wrote: @5chmidti may i ping you? could you help me out, it feels like its only inches away from being done. or could we go with the prev. commit as mentioned above? https://github.com/llvm/llvm-project/pull/120055 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [experimental] Detect return-stack-addr using CFG (PR #124133)
https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/124133 >From 22990789b61e9f9d22e88a6b008eb3166fd1cb56 Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena Date: Thu, 23 Jan 2025 15:47:39 + Subject: [PATCH 1/3] [experimental] Detect return-stack-addr using CFG --- .../Analysis/Analyses/DanglingReference.h | 14 + clang/include/clang/Basic/DiagnosticGroups.td | 3 + .../clang/Basic/DiagnosticSemaKinds.td| 8 + clang/lib/Analysis/CMakeLists.txt | 1 + clang/lib/Analysis/DanglingReference.cpp | 351 ++ clang/lib/Sema/AnalysisBasedWarnings.cpp | 8 + .../test/Sema/warn-lifetime-analysis-cfg.cpp | 136 +++ 7 files changed, 521 insertions(+) create mode 100644 clang/include/clang/Analysis/Analyses/DanglingReference.h create mode 100644 clang/lib/Analysis/DanglingReference.cpp create mode 100644 clang/test/Sema/warn-lifetime-analysis-cfg.cpp diff --git a/clang/include/clang/Analysis/Analyses/DanglingReference.h b/clang/include/clang/Analysis/Analyses/DanglingReference.h new file mode 100644 index 00..c9f5753eed070e --- /dev/null +++ b/clang/include/clang/Analysis/Analyses/DanglingReference.h @@ -0,0 +1,14 @@ +#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_DANGLING_REFERENCE_H +#define LLVM_CLANG_ANALYSIS_ANALYSES_DANGLING_REFERENCE_H +#include "clang/AST/DeclBase.h" +#include "clang/Analysis/AnalysisDeclContext.h" +#include "clang/Analysis/CFG.h" +#include "clang/Sema/Sema.h" + +namespace clang { +void runDanglingReferenceAnalysis(const DeclContext &dc, const CFG &cfg, + AnalysisDeclContext &ac, Sema &S); + +} // namespace clang + +#endif // LLVM_CLANG_ANALYSIS_ANALYSES_DANGLING_REFERENCE_H diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 594e99a19b64d6..eeddd6eb82a301 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -472,6 +472,9 @@ def Dangling : DiagGroup<"dangling", [DanglingAssignment, DanglingInitializerList, DanglingGsl, ReturnStackAddress]>; +def ReturnStackAddressCFG : DiagGroup<"return-stack-address-cfg">; +def DanglingCFG : DiagGroup<"dangling-cfg", [ReturnStackAddressCFG]>; + def DistributedObjectModifiers : DiagGroup<"distributed-object-modifiers">; def DllexportExplicitInstantiationDecl : DiagGroup<"dllexport-explicit-instantiation-decl">; def ExcessInitializers : DiagGroup<"excess-initializers">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 8be4f946dce1cc..846cf6b3d45f8a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10169,6 +10169,14 @@ def err_lifetimebound_implicit_object_parameter_void_return_type : Error< "parameter of a function that returns void; " "did you mean 'lifetime_capture_by(X)'">; +// CFG based lifetime analysis. +def warn_ret_stack_variable_ref_cfg : Warning< + "returning reference to a stack variable">, InGroup, DefaultIgnore; +def note_local_variable_declared_here : Note<"reference to this stack variable is returned">; + +def warn_ret_stack_temporary_ref_cfg : Warning< + "returning reference to a temporary object">, InGroup, DefaultIgnore; + // CHECK: returning address/reference of stack memory def warn_ret_stack_addr_ref : Warning< "%select{address of|reference to}0 stack memory associated with " diff --git a/clang/lib/Analysis/CMakeLists.txt b/clang/lib/Analysis/CMakeLists.txt index 7914c12d429ef9..d6ea1e907e7f09 100644 --- a/clang/lib/Analysis/CMakeLists.txt +++ b/clang/lib/Analysis/CMakeLists.txt @@ -16,6 +16,7 @@ add_clang_library(clangAnalysis ConstructionContext.cpp Consumed.cpp CodeInjector.cpp + DanglingReference.cpp Dominators.cpp ExprMutationAnalyzer.cpp IntervalPartition.cpp diff --git a/clang/lib/Analysis/DanglingReference.cpp b/clang/lib/Analysis/DanglingReference.cpp new file mode 100644 index 00..2602cc597a36b8 --- /dev/null +++ b/clang/lib/Analysis/DanglingReference.cpp @@ -0,0 +1,351 @@ +#include "clang/Analysis/Analyses/DanglingReference.h" +#include "clang/AST/Attrs.inc" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclVisitor.h" +#include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" +#include "clang/AST/Stmt.h" +#include "clang/AST/StmtVisitor.h" +#include "clang/AST/Type.h" +#include "clang/Analysis/CFG.h" +#include "clang/Basic/DiagnosticSema.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" +#include "llvm/Support/raw_ostream.h" +#include + +namespace clang { +namespace { + +template static bool isRecordWithAttr(QualType Type) { + auto *RD = Type->getAsCXXRecordDecl(); + if (!RD) +return false; + bool Result = RD->hasAttr(); + + if (auto *CTSD =
[clang] [experimental] Detect return-stack-addr using CFG (PR #124133)
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/124133 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Force AttributedStmtClass to not be scope parents (PR #125370)
https://github.com/YutongZhuu created https://github.com/llvm/llvm-project/pull/125370 This PR addresses https://github.com/llvm/llvm-project/issues/84072. >From 01497e746ae23ea5033b1c6cd6f9f9718d6dc3d6 Mon Sep 17 00:00:00 2001 From: Yutong Zhu Date: Sat, 1 Feb 2025 20:09:13 -0500 Subject: [PATCH 1/2] Force AttributedStmtClass to not be scope parents --- clang/lib/Sema/JumpDiagnostics.cpp | 22 ++ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/clang/lib/Sema/JumpDiagnostics.cpp b/clang/lib/Sema/JumpDiagnostics.cpp index d465599450e7ffc..68a7049185b32ff 100644 --- a/clang/lib/Sema/JumpDiagnostics.cpp +++ b/clang/lib/Sema/JumpDiagnostics.cpp @@ -310,8 +310,8 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned &ParentScope = ((isa(S) && !isa(S)) ? origParentScope : independentParentScope); - unsigned StmtsToSkip = 0u; - + unsigned StmtsToSkip = 0u; + // If we found a label, remember that it is in ParentScope scope. switch (S->getStmtClass()) { case Stmt::AddrLabelExprClass: @@ -597,15 +597,6 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, LabelAndGotoScopes[S] = ParentScope; break; - case Stmt::AttributedStmtClass: { -AttributedStmt *AS = cast(S); -if (GetMustTailAttr(AS)) { - LabelAndGotoScopes[AS] = ParentScope; - MustTailStmts.push_back(AS); -} -break; - } - case Stmt::OpenACCComputeConstructClass: { unsigned NewParentScope = Scopes.size(); OpenACCComputeConstruct *CC = cast(S); @@ -658,6 +649,13 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, Next = SC->getSubStmt(); else if (LabelStmt *LS = dyn_cast(SubStmt)) Next = LS->getSubStmt(); + else if (AttributedStmt *AS = dyn_cast(SubStmt)){ +if (GetMustTailAttr(AS)) { + LabelAndGotoScopes[AS] = ParentScope; + MustTailStmts.push_back(AS); +} +Next = AS->getSubStmt(); + } else break; @@ -945,7 +943,7 @@ void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc, unsigned FromScope = LabelAndGotoScopes[From]; unsigned ToScope = LabelAndGotoScopes[To]; - + // Common case: exactly the same scope, which is fine. if (FromScope == ToScope) return; >From e71018ffee1be8cd26ee2ac22f226152ea385998 Mon Sep 17 00:00:00 2001 From: Yutong Zhu Date: Sat, 1 Feb 2025 20:13:41 -0500 Subject: [PATCH 2/2] Clang-format --- clang/lib/Sema/JumpDiagnostics.cpp | 11 +-- 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/clang/lib/Sema/JumpDiagnostics.cpp b/clang/lib/Sema/JumpDiagnostics.cpp index 68a7049185b32ff..c5577e09a86a1c3 100644 --- a/clang/lib/Sema/JumpDiagnostics.cpp +++ b/clang/lib/Sema/JumpDiagnostics.cpp @@ -310,8 +310,8 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned &ParentScope = ((isa(S) && !isa(S)) ? origParentScope : independentParentScope); - unsigned StmtsToSkip = 0u; - + unsigned StmtsToSkip = 0u; + // If we found a label, remember that it is in ParentScope scope. switch (S->getStmtClass()) { case Stmt::AddrLabelExprClass: @@ -649,14 +649,13 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, Next = SC->getSubStmt(); else if (LabelStmt *LS = dyn_cast(SubStmt)) Next = LS->getSubStmt(); - else if (AttributedStmt *AS = dyn_cast(SubStmt)){ + else if (AttributedStmt *AS = dyn_cast(SubStmt)) { if (GetMustTailAttr(AS)) { LabelAndGotoScopes[AS] = ParentScope; MustTailStmts.push_back(AS); } Next = AS->getSubStmt(); - } - else + } else break; LabelAndGotoScopes[SubStmt] = ParentScope; @@ -943,7 +942,7 @@ void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc, unsigned FromScope = LabelAndGotoScopes[From]; unsigned ToScope = LabelAndGotoScopes[To]; - + // Common case: exactly the same scope, which is fine. if (FromScope == ToScope) return; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Force AttributedStmtClass to not be scope parents (PR #125370)
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/125370 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Force AttributedStmtClass to not be scope parents (PR #125370)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Yutong Zhu (YutongZhuu) Changes This PR addresses https://github.com/llvm/llvm-project/issues/84072. --- Full diff: https://github.com/llvm/llvm-project/pull/125370.diff 1 Files Affected: - (modified) clang/lib/Sema/JumpDiagnostics.cpp (+7-10) ``diff diff --git a/clang/lib/Sema/JumpDiagnostics.cpp b/clang/lib/Sema/JumpDiagnostics.cpp index d465599450e7ff..c5577e09a86a1c 100644 --- a/clang/lib/Sema/JumpDiagnostics.cpp +++ b/clang/lib/Sema/JumpDiagnostics.cpp @@ -597,15 +597,6 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, LabelAndGotoScopes[S] = ParentScope; break; - case Stmt::AttributedStmtClass: { -AttributedStmt *AS = cast(S); -if (GetMustTailAttr(AS)) { - LabelAndGotoScopes[AS] = ParentScope; - MustTailStmts.push_back(AS); -} -break; - } - case Stmt::OpenACCComputeConstructClass: { unsigned NewParentScope = Scopes.size(); OpenACCComputeConstruct *CC = cast(S); @@ -658,7 +649,13 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, Next = SC->getSubStmt(); else if (LabelStmt *LS = dyn_cast(SubStmt)) Next = LS->getSubStmt(); - else + else if (AttributedStmt *AS = dyn_cast(SubStmt)) { +if (GetMustTailAttr(AS)) { + LabelAndGotoScopes[AS] = ParentScope; + MustTailStmts.push_back(AS); +} +Next = AS->getSubStmt(); + } else break; LabelAndGotoScopes[SubStmt] = ParentScope; `` https://github.com/llvm/llvm-project/pull/125370 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reland: [clang] Track function template instantiation from definition (PR #125266)
@@ -2298,6 +2298,13 @@ class FunctionDecl : public DeclaratorDecl, FunctionDeclBits.IsLateTemplateParsed = ILT; } + bool isInstantiatedFromMemberTemplate() const { +return FunctionDeclBits.IsInstantiatedFromMemberTemplate; + } + void setInstantiatedFromMemberTemplate(bool Val = true) { +FunctionDeclBits.IsInstantiatedFromMemberTemplate = Val; + } + mizvekov wrote: Yes, from new methods in DeclTemplate.h, which themselves are used from SemaTemplateInstantiateDecl.cpp and from the ASTReader / Writer. https://github.com/llvm/llvm-project/pull/125266 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6980d97 - [clang-format] Fix a bug in annotating ClassHeadName (#125326)
Author: Owen Pan Date: 2025-02-01T20:20:43-08:00 New Revision: 6980d9794684908fa1835b87b560d20e5f295a73 URL: https://github.com/llvm/llvm-project/commit/6980d9794684908fa1835b87b560d20e5f295a73 DIFF: https://github.com/llvm/llvm-project/commit/6980d9794684908fa1835b87b560d20e5f295a73.diff LOG: [clang-format] Fix a bug in annotating ClassHeadName (#125326) Added: Modified: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 1411197e3255496..4e040183f2f0a3e 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -4106,7 +4106,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) { if (AngleNestingLevel == 0) { if (FormatTok->is(tok::colon)) { IsDerived = true; -} else if (FormatTok->is(tok::identifier) && +} else if (!IsDerived && FormatTok->is(tok::identifier) && FormatTok->Previous->is(tok::coloncolon)) { ClassName = FormatTok; } else if (FormatTok->is(tok::l_paren) && diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 9995f090d441f7a..1b09c4570345622 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -3406,6 +3406,13 @@ TEST_F(TokenAnnotatorTest, BraceKind) { EXPECT_BRACE_KIND(Tokens[7], BK_Block); EXPECT_BRACE_KIND(Tokens[8], BK_Block); + Tokens = annotate("struct Foo : Base::Bar {};"); + ASSERT_EQ(Tokens.size(), 13u) << Tokens; + EXPECT_TOKEN(Tokens[1], tok::identifier, TT_ClassHeadName); + EXPECT_TOKEN(Tokens[8], tok::identifier, TT_Unknown); // Not TT_ClassHeadName. + EXPECT_BRACE_KIND(Tokens[9], BK_Block); + EXPECT_BRACE_KIND(Tokens[10], BK_Block); + Tokens = annotate("struct Foo final {};"); ASSERT_EQ(Tokens.size(), 7u) << Tokens; EXPECT_TOKEN(Tokens[1], tok::identifier, TT_ClassHeadName); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a bug in annotating ClassHeadName (PR #125326)
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/125326 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix P3310 overload resolution flag propagation (PR #125372)
https://github.com/mizvekov created https://github.com/llvm/llvm-project/pull/125372 Class templates might be only instantiated when they are required to be complete, but checking the template args against the primary template is immediate. This result is cached so that later when the class is instantiated, checking against the primary template is not repeated. The 'MatchedPackOnParmToNonPackOnArg' flag is also produced upon checking against the primary template, so it needs to be cached in the specialziation as well. This fixes a bug which has not been in any release, so there are no release notes. Fixes #125290 >From c76e470d6f5acd0fdbd369b13cfdeb50bacb Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Fri, 31 Jan 2025 20:41:39 -0300 Subject: [PATCH] [clang] fix P3310 overload resolution flag propagation Class templates might be only instantiated when they are required to be complete, but checking the template args against the primary template is immediate. This result is cached so that later when the class is instantiated, checking against the primary template is not repeated. The 'MatchedPackOnParmToNonPackOnArg' flag is also produced upon checking against the primary template, so it needs to be cached in the specialziation as well. This fixes a bug which has not been in any release, so there are no release notes. Fixes #125290 --- clang/include/clang/AST/DeclTemplate.h| 14 +- clang/lib/AST/ASTImporter.cpp | 6 +-- clang/lib/AST/DeclTemplate.cpp| 47 ++- clang/lib/AST/TextNodeDumper.cpp | 5 +- clang/lib/Sema/SemaTemplate.cpp | 8 ++-- clang/lib/Sema/SemaTemplateDeduction.cpp | 2 - .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 +- clang/lib/Sema/SemaType.cpp | 3 +- clang/lib/Serialization/ASTReaderDecl.cpp | 1 + clang/lib/Serialization/ASTWriterDecl.cpp | 1 + clang/test/AST/ast-dump-templates.cpp | 19 +++- clang/test/SemaTemplate/cwg2398.cpp | 17 +++ 12 files changed, 87 insertions(+), 38 deletions(-) diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 9ecff2c898acd5..aff299433ce721 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -1841,15 +1841,21 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, LLVM_PREFERRED_TYPE(TemplateSpecializationKind) unsigned SpecializationKind : 3; + /// When matching the primary template, have we matched any packs on the + /// parameter side, versus any non-packs on the argument side, in a context + /// where the opposite matching is also allowed? + bool MatchedPackOnParmToNonPackOnArg : 1; + protected: ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, ArrayRef Args, + bool MatchedPackOnParmToNonPackOnArg, ClassTemplateSpecializationDecl *PrevDecl); - explicit ClassTemplateSpecializationDecl(ASTContext &C, Kind DK); + ClassTemplateSpecializationDecl(ASTContext &C, Kind DK); public: friend class ASTDeclReader; @@ -1859,7 +1865,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, - ArrayRef Args, + ArrayRef Args, bool MatchedPackOnParmToNonPackOnArg, ClassTemplateSpecializationDecl *PrevDecl); static ClassTemplateSpecializationDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID); @@ -1930,6 +1936,10 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, SpecializationKind = TSK; } + bool hasMatchedPackOnParmToNonPackOnArg() const { +return MatchedPackOnParmToNonPackOnArg; + } + /// Get the point of instantiation (if any), or null if none. SourceLocation getPointOfInstantiation() const { return PointOfInstantiation; diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index c9f2f905d2134c..1057f09deda073 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -6321,9 +6321,9 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( updateLookupTableForTemplateParameters(*ToTPList); } else { // Not a partial specialization. if (GetImportedOrCreateDecl( -D2, D, Importer.getToContext(), D->getTagKind(), DC, -*BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, -PrevDecl)) +D2, D, Importer
[clang] [clang] fix P3310 overload resolution flag propagation (PR #125372)
https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/125372 >From 9645f14d3b9aa016cb45ca27ad0425adbbc0e1c6 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Fri, 31 Jan 2025 20:41:39 -0300 Subject: [PATCH] [clang] fix P3310 overload resolution flag propagation Class templates might be only instantiated when they are required to be complete, but checking the template args against the primary template is immediate. This result is cached so that later when the class is instantiated, checking against the primary template is not repeated. The 'MatchedPackOnParmToNonPackOnArg' flag is also produced upon checking against the primary template, so it needs to be cached in the specialziation as well. This fixes a bug which has not been in any release, so there are no release notes. Fixes #125290 --- clang/include/clang/AST/DeclTemplate.h| 14 +- clang/include/clang/Sema/Sema.h | 4 +- clang/lib/AST/ASTImporter.cpp | 6 +-- clang/lib/AST/DeclTemplate.cpp| 47 ++- clang/lib/AST/TextNodeDumper.cpp | 5 +- clang/lib/Sema/SemaTemplate.cpp | 8 ++-- clang/lib/Sema/SemaTemplateDeduction.cpp | 2 - .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 +- clang/lib/Sema/SemaType.cpp | 3 +- clang/lib/Serialization/ASTReaderDecl.cpp | 1 + clang/lib/Serialization/ASTWriterDecl.cpp | 1 + clang/test/AST/ast-dump-templates.cpp | 19 +++- clang/test/SemaTemplate/cwg2398.cpp | 17 +++ 13 files changed, 89 insertions(+), 40 deletions(-) diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 9ecff2c898acd5..aff299433ce721 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -1841,15 +1841,21 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, LLVM_PREFERRED_TYPE(TemplateSpecializationKind) unsigned SpecializationKind : 3; + /// When matching the primary template, have we matched any packs on the + /// parameter side, versus any non-packs on the argument side, in a context + /// where the opposite matching is also allowed? + bool MatchedPackOnParmToNonPackOnArg : 1; + protected: ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, ArrayRef Args, + bool MatchedPackOnParmToNonPackOnArg, ClassTemplateSpecializationDecl *PrevDecl); - explicit ClassTemplateSpecializationDecl(ASTContext &C, Kind DK); + ClassTemplateSpecializationDecl(ASTContext &C, Kind DK); public: friend class ASTDeclReader; @@ -1859,7 +1865,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, - ArrayRef Args, + ArrayRef Args, bool MatchedPackOnParmToNonPackOnArg, ClassTemplateSpecializationDecl *PrevDecl); static ClassTemplateSpecializationDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID); @@ -1930,6 +1936,10 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, SpecializationKind = TSK; } + bool hasMatchedPackOnParmToNonPackOnArg() const { +return MatchedPackOnParmToNonPackOnArg; + } + /// Get the point of instantiation (if any), or null if none. SourceLocation getPointOfInstantiation() const { return PointOfInstantiation; diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 472a0e25adc975..79bf6c04ee4969 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -13493,8 +13493,8 @@ class Sema final : public SemaBase { bool InstantiateClassTemplateSpecialization( SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, - TemplateSpecializationKind TSK, bool Complain = true, - bool PrimaryHasMatchedPackOnParmToNonPackOnArg = false); + TemplateSpecializationKind TSK, bool Complain, + bool PrimaryHasMatchedPackOnParmToNonPackOnArg); /// Instantiates the definitions of all of the member /// of the given class, which is an instantiation of a class template diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index c9f2f905d2134c..1057f09deda073 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -6321,9 +6321,9 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( updateLookupTableForTemplateParam
[clang] CodeGen: support static linking for libclosure (PR #125384)
https://github.com/compnerd created https://github.com/llvm/llvm-project/pull/125384 When building on Windows, dealing with the BlocksRuntime is slightly more complicated. As we are not guaranteed a formward declaration for the blocks runtime ABI symbols, we may generate the declarations for them. In order to properly link against the well-known types, we always annotated them as `__declspec(dllimport)`. This would require the dynamic linking of the blocks runtime under all conditions. However, this is the only the only possible way to us the library. We may be building a fully sealed (static) executable. In such a case, the well known symbols should not be marked as `dllimport` as they are assumed to be statically available with the static linking to the BlocksRuntime. Introduce a new driver/cc1 option `-static-libclosure` which mirrors the myriad of similar options (`-static-libgcc`, `-static-libstdc++`, -static-libsan`, etc). >From 4e0eb2ce4b30c872ce846956196e1e0970c43d57 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 1 Feb 2025 15:04:04 -0800 Subject: [PATCH] CodeGen: support static linking for libclosure When building on Windows, dealing with the BlocksRuntime is slightly more complicated. As we are not guaranteed a formward declaration for the blocks runtime ABI symbols, we may generate the declarations for them. In order to properly link against the well-known types, we always annotated them as `__declspec(dllimport)`. This would require the dynamic linking of the blocks runtime under all conditions. However, this is the only the only possible way to us the library. We may be building a fully sealed (static) executable. In such a case, the well known symbols should not be marked as `dllimport` as they are assumed to be statically available with the static linking to the BlocksRuntime. Introduce a new driver/cc1 option `-static-libclosure` which mirrors the myriad of similar options (`-static-libgcc`, `-static-libstdc++`, -static-libsan`, etc). --- clang/include/clang/Basic/CodeGenOptions.def | 4 clang/include/clang/Driver/Options.td| 2 ++ clang/lib/CodeGen/CGBlocks.cpp | 4 ++-- clang/lib/Driver/ToolChains/Clang.cpp| 2 ++ clang/lib/Frontend/CompilerInvocation.cpp| 5 + clang/test/CodeGen/blocks-windows.c | 7 +++ 6 files changed, 22 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 386652d2efa9e1..9ca1fe6566d6ad 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -469,6 +469,10 @@ CODEGENOPT(CtorDtorReturnThis, 1, 0) /// by the Windows kernel to enable import call optimization. CODEGENOPT(ImportCallOptimization, 1, 0) +/// Controls whether we generate code for static linking of libclosure +/// (BlocksRuntime) on Windows. +CODEGENOPT(StaticClosure, 1, 0) + /// FIXME: Make DebugOptions its own top-level .def file. #include "DebugOptions.def" diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 0ab923fcdd5838..7f2b8b74bce79c 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5825,6 +5825,8 @@ def start_no_unused_arguments : Flag<["--"], "start-no-unused-arguments">, HelpText<"Don't emit warnings about unused arguments for the following arguments">; def static_libgcc : Flag<["-"], "static-libgcc">; def static_libstdcxx : Flag<["-"], "static-libstdc++">; +def static_libclosure : Flag<["-"], "static-libclosure">, +Visibility<[ClangOption, CC1Option]>; def static : Flag<["-", "--"], "static">, Group, Visibility<[ClangOption, FlangOption]>, Flags<[NoArgumentUnused]>; diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp index a7584a95c8ca7b..aaba354c08547d 100644 --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -2800,7 +2800,8 @@ static void configureBlocksRuntimeObject(CodeGenModule &CGM, llvm::Constant *C) { auto *GV = cast(C->stripPointerCasts()); - if (CGM.getTarget().getTriple().isOSBinFormatCOFF()) { + if (!CGM.getCodeGenOpts().StaticClosure && + CGM.getTarget().getTriple().isOSBinFormatCOFF()) { const IdentifierInfo &II = CGM.getContext().Idents.get(C->getName()); TranslationUnitDecl *TUDecl = CGM.getContext().getTranslationUnitDecl(); DeclContext *DC = TranslationUnitDecl::castToDeclContext(TUDecl); @@ -2815,7 +2816,6 @@ static void configureBlocksRuntimeObject(CodeGenModule &CGM, (ND = dyn_cast(Result))) break; -// TODO: support static blocks runtime if (GV->isDeclaration() && (!ND || !ND->hasAttr())) { GV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); GV->setLinkage(llvm::GlobalValue::ExternalLinkage); diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clan
[clang] Reland: [clang] Track function template instantiation from definition (PR #125266)
@@ -2298,6 +2298,13 @@ class FunctionDecl : public DeclaratorDecl, FunctionDeclBits.IsLateTemplateParsed = ILT; } + bool isInstantiatedFromMemberTemplate() const { +return FunctionDeclBits.IsInstantiatedFromMemberTemplate; + } + void setInstantiatedFromMemberTemplate(bool Val = true) { +FunctionDeclBits.IsInstantiatedFromMemberTemplate = Val; + } + cor3ntin wrote: `ASTReader / Writer.`, sure. However, I don't understand where `IsInstantiatedFromMemberTemplate` is initially set (and i don't understand why we would need it - we already store that information on the `FunctionTemplateDecl` - which is what you have in your changes to `InstantiateFunctionDefinition`. Go through the different calls to `setInstantiatedFromMemberTemplate` and see that this is _only_ used in ASTreader, and the new `FunctionTemplateDecl::setInstantiatedFromMemberTemplate` is not used - unless I am blind, which is always a possibility at 7am :) Note that `RedeclarableTemplateDecl::setInstantiatedFromMemberTemplate` is already called everywhere it needs to (hopefully) and `isCompatibleWithDefinition()` can just be `return `isInstantiatedFromMemberTemplate() || isThisDeclarationADefinition();` - unless I am missing something, but in that case the PR needs more explanation. >From a FunctionFecl, >`FunctionDecl::getInstantiatedFromDecl/FunctionDecl::getInstantiatedFromMemberFunction` > _should_ also have the information @erichkeane @AaronBallman https://github.com/llvm/llvm-project/pull/125266 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] CodeGen: support static linking for libclosure (PR #125384)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Saleem Abdulrasool (compnerd) Changes When building on Windows, dealing with the BlocksRuntime is slightly more complicated. As we are not guaranteed a formward declaration for the blocks runtime ABI symbols, we may generate the declarations for them. In order to properly link against the well-known types, we always annotated them as `__declspec(dllimport)`. This would require the dynamic linking of the blocks runtime under all conditions. However, this is the only the only possible way to us the library. We may be building a fully sealed (static) executable. In such a case, the well known symbols should not be marked as `dllimport` as they are assumed to be statically available with the static linking to the BlocksRuntime. Introduce a new driver/cc1 option `-static-libclosure` which mirrors the myriad of similar options (`-static-libgcc`, `-static-libstdc++`, -static-libsan`, etc). --- Full diff: https://github.com/llvm/llvm-project/pull/125384.diff 6 Files Affected: - (modified) clang/include/clang/Basic/CodeGenOptions.def (+4) - (modified) clang/include/clang/Driver/Options.td (+2) - (modified) clang/lib/CodeGen/CGBlocks.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+2) - (modified) clang/lib/Frontend/CompilerInvocation.cpp (+5) - (modified) clang/test/CodeGen/blocks-windows.c (+7) ``diff diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 386652d2efa9e1..9ca1fe6566d6ad 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -469,6 +469,10 @@ CODEGENOPT(CtorDtorReturnThis, 1, 0) /// by the Windows kernel to enable import call optimization. CODEGENOPT(ImportCallOptimization, 1, 0) +/// Controls whether we generate code for static linking of libclosure +/// (BlocksRuntime) on Windows. +CODEGENOPT(StaticClosure, 1, 0) + /// FIXME: Make DebugOptions its own top-level .def file. #include "DebugOptions.def" diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 0ab923fcdd5838..7f2b8b74bce79c 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5825,6 +5825,8 @@ def start_no_unused_arguments : Flag<["--"], "start-no-unused-arguments">, HelpText<"Don't emit warnings about unused arguments for the following arguments">; def static_libgcc : Flag<["-"], "static-libgcc">; def static_libstdcxx : Flag<["-"], "static-libstdc++">; +def static_libclosure : Flag<["-"], "static-libclosure">, +Visibility<[ClangOption, CC1Option]>; def static : Flag<["-", "--"], "static">, Group, Visibility<[ClangOption, FlangOption]>, Flags<[NoArgumentUnused]>; diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp index a7584a95c8ca7b..aaba354c08547d 100644 --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -2800,7 +2800,8 @@ static void configureBlocksRuntimeObject(CodeGenModule &CGM, llvm::Constant *C) { auto *GV = cast(C->stripPointerCasts()); - if (CGM.getTarget().getTriple().isOSBinFormatCOFF()) { + if (!CGM.getCodeGenOpts().StaticClosure && + CGM.getTarget().getTriple().isOSBinFormatCOFF()) { const IdentifierInfo &II = CGM.getContext().Idents.get(C->getName()); TranslationUnitDecl *TUDecl = CGM.getContext().getTranslationUnitDecl(); DeclContext *DC = TranslationUnitDecl::castToDeclContext(TUDecl); @@ -2815,7 +2816,6 @@ static void configureBlocksRuntimeObject(CodeGenModule &CGM, (ND = dyn_cast(Result))) break; -// TODO: support static blocks runtime if (GV->isDeclaration() && (!ND || !ND->hasAttr())) { GV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); GV->setLinkage(llvm::GlobalValue::ExternalLinkage); diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 9b5132c5625faa..ad73ac4dd8f73d 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5580,6 +5580,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Args.hasArg(options::OPT_static)) CmdArgs.push_back("-static-define"); + Args.AddLastArg(CmdArgs, options::OPT_static_libclosure); + if (Args.hasArg(options::OPT_municode)) CmdArgs.push_back("-DUNICODE"); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 11fd6ab7f52a79..de31c3c40fecf0 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1843,6 +1843,9 @@ void CompilerInvocationBase::GenerateCodeGenArgs(const CodeGenOptions &Opts, GenerateArg(Consumer, OPT_fno_finite_loops); break; } + + if (Opts.StaticClosure) +GenerateArg(Consumer, OPT_static_libclosure); } bo
[clang] [clang] fix P3310 overload resolution flag propagation (PR #125372)
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/125372 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix P3310 overload resolution flag propagation (PR #125372)
@@ -1841,15 +1841,21 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, LLVM_PREFERRED_TYPE(TemplateSpecializationKind) unsigned SpecializationKind : 3; + /// When matching the primary template, have we matched any packs on the + /// parameter side, versus any non-packs on the argument side, in a context + /// where the opposite matching is also allowed? + bool MatchedPackOnParmToNonPackOnArg : 1; cor3ntin wrote: I know this has the same name as the one in `CheckTemplateArgumentInfo` but we should rename all of them to `MatchedNonPackArgumentWithPackParameter` or something like that (ie remove the `On`s) https://github.com/llvm/llvm-project/pull/125372 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix P3310 overload resolution flag propagation (PR #125372)
@@ -1841,15 +1841,21 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, LLVM_PREFERRED_TYPE(TemplateSpecializationKind) unsigned SpecializationKind : 3; + /// When matching the primary template, have we matched any packs on the + /// parameter side, versus any non-packs on the argument side, in a context + /// where the opposite matching is also allowed? cor3ntin wrote: ```suggestion /// Indicate that we have matched a parameter pack with a non pack /// argument (strict matching) /// This needs to be cached as deduction is performed during declaration, /// and we need the information to be preserved so that it is consistent during instantiation ``` ``` (Ideally we would have a wording reference. Alas) https://github.com/llvm/llvm-project/pull/125372 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix P3310 overload resolution flag propagation (PR #125372)
@@ -2525,8 +2525,11 @@ void TextNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) { OS << " instantiated_from"; dumpPointer(Instance); } - if (const auto *CTSD = dyn_cast(D)) + if (const auto *CTSD = dyn_cast(D)) { dumpTemplateSpecializationKind(CTSD->getSpecializationKind()); +if (CTSD->hasMatchedPackOnParmToNonPackOnArg()) + OS << " strict_match"; + } cor3ntin wrote: I don't know if that's useful information in the ast dump - is that just for testing? I'd be inclined to removing it, the ast dump doesn't tell you _how_ it was formed https://github.com/llvm/llvm-project/pull/125372 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix P3310 overload resolution flag propagation (PR #125372)
https://github.com/cor3ntin commented: Thanks for fixing that quickly. LGTM, just a few nits/comments. (I assume that we will want to cherry-pick that to 20) https://github.com/llvm/llvm-project/pull/125372 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][StaticAnalyzer][NFC] Fix a typo in comments (PR #125339)
https://github.com/steakhal approved this pull request. https://github.com/llvm/llvm-project/pull/125339 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][StaticAnalyzer][NFC] Fix a typo in comments (PR #125339)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Ben Shi (benshi001) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/125339.diff 1 Files Affected: - (modified) clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h (+2-2) ``diff diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h index 8974342166fadd..7563d8bbd1d273 100644 --- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h +++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h @@ -748,8 +748,8 @@ class BugReporterContext { /// It can be valuable to produce tags with some bits of information and later /// reuse them for a better diagnostic. /// -/// Please make sure that derived class' constuctor is private and that the user -/// can only create objects using DataTag::Factory. This also means that +/// Please make sure that derived class' constructor is private and that the +/// user can only create objects using DataTag::Factory. This also means that /// DataTag::Factory should be friend for every derived class. class DataTag : public ProgramPointTag { public: `` https://github.com/llvm/llvm-project/pull/125339 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AST] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125335)
https://github.com/nikic approved this pull request. https://github.com/llvm/llvm-project/pull/125335 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CodeGen] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125336)
https://github.com/nikic approved this pull request. https://github.com/llvm/llvm-project/pull/125336 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][StaticAnalyzer][NFC] Fix a typo in comments (PR #125339)
https://github.com/benshi001 created https://github.com/llvm/llvm-project/pull/125339 None >From 1cfa014550c0a1c2a8bb22587afdc8b211481f95 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Sat, 1 Feb 2025 16:16:29 +0800 Subject: [PATCH] [clang][StaticAnalyzer][NFC] Fix a typo in comments --- .../clang/StaticAnalyzer/Core/BugReporter/BugReporter.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h index 8974342166fadd..7563d8bbd1d273 100644 --- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h +++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h @@ -748,8 +748,8 @@ class BugReporterContext { /// It can be valuable to produce tags with some bits of information and later /// reuse them for a better diagnostic. /// -/// Please make sure that derived class' constuctor is private and that the user -/// can only create objects using DataTag::Factory. This also means that +/// Please make sure that derived class' constructor is private and that the +/// user can only create objects using DataTag::Factory. This also means that /// DataTag::Factory should be friend for every derived class. class DataTag : public ProgramPointTag { public: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 44aa618 - [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (#117437)
Author: yronglin Date: 2025-02-01T16:58:05+08:00 New Revision: 44aa618ef67d302f5ab77cc591fb3434fe967a2e URL: https://github.com/llvm/llvm-project/commit/44aa618ef67d302f5ab77cc591fb3434fe967a2e DIFF: https://github.com/llvm/llvm-project/commit/44aa618ef67d302f5ab77cc591fb3434fe967a2e.diff LOG: [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (#117437) Clang currently support extending lifetime of object bound to reference members of aggregates, that are created from default member initializer. This PR address this change and updaye CFG and ExprEngine. This PR reapply https://github.com/llvm/llvm-project/pull/91879. Fixes https://github.com/llvm/llvm-project/issues/93725. - Signed-off-by: yronglin Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/AST/ParentMap.cpp clang/lib/Analysis/CFG.cpp clang/lib/Analysis/ReachableCode.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/StaticAnalyzer/Core/ExprEngine.cpp clang/test/AST/ast-dump-recovery.cpp clang/test/Analysis/lifetime-extended-regions.cpp clang/test/SemaCXX/cxx2c-placeholder-vars.cpp clang/test/SemaCXX/warn-unreachable.cpp Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index a220e57d0b3222..30364a747f9c19 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -219,6 +219,10 @@ Code Completion Static Analyzer --- +- Clang currently support extending lifetime of object bound to + reference members of aggregates in CFG and ExprEngine, that are + created from default member initializer. + New features diff --git a/clang/lib/AST/ParentMap.cpp b/clang/lib/AST/ParentMap.cpp index e62e71bf5a5145..580613b2618fb6 100644 --- a/clang/lib/AST/ParentMap.cpp +++ b/clang/lib/AST/ParentMap.cpp @@ -13,6 +13,7 @@ #include "clang/AST/ParentMap.h" #include "clang/AST/Decl.h" #include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" #include "clang/AST/StmtObjC.h" #include "llvm/ADT/DenseMap.h" @@ -103,6 +104,22 @@ static void BuildParentMap(MapTy& M, Stmt* S, BuildParentMap(M, SubStmt, OVMode); } break; + case Stmt::CXXDefaultArgExprClass: +if (auto *Arg = dyn_cast(S)) { + if (Arg->hasRewrittenInit()) { +M[Arg->getExpr()] = S; +BuildParentMap(M, Arg->getExpr(), OVMode); + } +} +break; + case Stmt::CXXDefaultInitExprClass: +if (auto *Init = dyn_cast(S)) { + if (Init->hasRewrittenInit()) { +M[Init->getExpr()] = S; +BuildParentMap(M, Init->getExpr(), OVMode); + } +} +break; default: for (Stmt *SubStmt : S->children()) { if (SubStmt) { diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 304bbb2b422c61..6bba0e38af630d 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -556,6 +556,10 @@ class CFGBuilder { private: // Visitors to walk an AST and construct the CFG. + CFGBlock *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Default, + AddStmtChoice asc); + CFGBlock *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Default, +AddStmtChoice asc); CFGBlock *VisitInitListExpr(InitListExpr *ILE, AddStmtChoice asc); CFGBlock *VisitAddrLabelExpr(AddrLabelExpr *A, AddStmtChoice asc); CFGBlock *VisitAttributedStmt(AttributedStmt *A, AddStmtChoice asc); @@ -2261,16 +2265,10 @@ CFGBlock *CFGBuilder::Visit(Stmt * S, AddStmtChoice asc, asc, ExternallyDestructed); case Stmt::CXXDefaultArgExprClass: + return VisitCXXDefaultArgExpr(cast(S), asc); + case Stmt::CXXDefaultInitExprClass: - // FIXME: The expression inside a CXXDefaultArgExpr is owned by the - // called function's declaration, not by the caller. If we simply add - // this expression to the CFG, we could end up with the same Expr - // appearing multiple times (PR13385). - // - // It's likewise possible for multiple CXXDefaultInitExprs for the same - // expression to be used in the same function (through aggregate - // initialization). - return VisitStmt(S, asc); + return VisitCXXDefaultInitExpr(cast(S), asc); case Stmt::CXXBindTemporaryExprClass: return VisitCXXBindTemporaryExpr(cast(S), asc); @@ -2440,6 +2438,40 @@ CFGBlock *CFGBuilder::VisitChildren(Stmt *S) { return B; } +CFGBlock *CFGBuilder::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Arg, + AddStmtChoice asc) { + if (Arg->hasRewrittenInit()) { +if (asc.alwaysAdd(*this, Arg)) { + autoCreateBlock(); + appendStmt(Block, Arg); +} +return VisitStmt(Arg->getExpr(), asc); + } + + // We can't add the default argument if it's not rewritten because the + // expression inside a CXXDefaultAr
[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #117437)
https://github.com/yronglin closed https://github.com/llvm/llvm-project/pull/117437 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AST] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125335)
https://github.com/cor3ntin approved this pull request. Feel free to batch some of these changes together in a single PR! https://github.com/llvm/llvm-project/pull/125335 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] bfa7edc - [clang][StaticAnalyzer][NFC] Fix a typo in comments (#125339)
Author: Ben Shi Date: 2025-02-01T09:21:47+01:00 New Revision: bfa7edcc6652bdb37d53e0cec64926aab3f280eb URL: https://github.com/llvm/llvm-project/commit/bfa7edcc6652bdb37d53e0cec64926aab3f280eb DIFF: https://github.com/llvm/llvm-project/commit/bfa7edcc6652bdb37d53e0cec64926aab3f280eb.diff LOG: [clang][StaticAnalyzer][NFC] Fix a typo in comments (#125339) Added: Modified: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h Removed: diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h index 8974342166fadda..7563d8bbd1d273f 100644 --- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h +++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h @@ -748,8 +748,8 @@ class BugReporterContext { /// It can be valuable to produce tags with some bits of information and later /// reuse them for a better diagnostic. /// -/// Please make sure that derived class' constuctor is private and that the user -/// can only create objects using DataTag::Factory. This also means that +/// Please make sure that derived class' constructor is private and that the +/// user can only create objects using DataTag::Factory. This also means that /// DataTag::Factory should be friend for every derived class. class DataTag : public ProgramPointTag { public: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][StaticAnalyzer][NFC] Fix a typo in comments (PR #125339)
https://github.com/steakhal closed https://github.com/llvm/llvm-project/pull/125339 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 7612dcc - [clang] NFC, add a "continue" bailout in the for-loop of
Author: Haojian Wu Date: 2025-02-01T10:07:40+01:00 New Revision: 7612dcc6e8d8e7f19b364084effbb01946294720 URL: https://github.com/llvm/llvm-project/commit/7612dcc6e8d8e7f19b364084effbb01946294720 DIFF: https://github.com/llvm/llvm-project/commit/7612dcc6e8d8e7f19b364084effbb01946294720.diff LOG: [clang] NFC, add a "continue" bailout in the for-loop of DeclareImplicitDeductionGuidesForTypeAlias. This improves the code readability. Added: Modified: clang/lib/Sema/SemaTemplateDeductionGuide.cpp Removed: diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp index 00c5dfd3d7a438..63592c335d211b 100644 --- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp +++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp @@ -1246,6 +1246,7 @@ void DeclareImplicitDeductionGuidesForTypeAlias( Constraint = Conjunction.getAs(); } Transformed->setTrailingRequiresClause(Constraint); + continue; } FunctionTemplateDecl *F = dyn_cast(G); if (!F) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ValueTracking] Handle flipped strictness cases in `matchSelectPattern` (PR #121958)
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/121958 >From c67349c8d79333d574a753d7afb10489cafb008d Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Tue, 7 Jan 2025 23:48:53 +0800 Subject: [PATCH 1/4] [InstCombine] Add pre-commit tests. NFC. --- llvm/test/Transforms/InstCombine/minmax-fp.ll | 38 +++ .../InstCombine/preserve-sminmax.ll | 13 +++ 2 files changed, 51 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/minmax-fp.ll b/llvm/test/Transforms/InstCombine/minmax-fp.ll index 4fe8cf374344e22..38e88529915d04b 100644 --- a/llvm/test/Transforms/InstCombine/minmax-fp.ll +++ b/llvm/test/Transforms/InstCombine/minmax-fp.ll @@ -265,6 +265,44 @@ define double @t17(i32 %x) { ret double %sel } +define double @t17_commuted1(i32 %x) { +; CHECK-LABEL: @t17_commuted1( +; CHECK-NEXT:[[CMP:%.*]] = icmp slt i32 [[X:%.*]], 3 +; CHECK-NEXT:[[CST:%.*]] = sitofp i32 [[X]] to double +; CHECK-NEXT:[[SEL:%.*]] = select i1 [[CMP]], double 2.00e+00, double [[CST]] +; CHECK-NEXT:ret double [[SEL]] +; + %cmp = icmp slt i32 %x, 3 + %cst = sitofp i32 %x to double + %sel = select i1 %cmp, double 2.0, double %cst + ret double %sel +} + +define double @t17_commuted2(i32 %x) { +; CHECK-LABEL: @t17_commuted2( +; CHECK-NEXT:[[SEL1:%.*]] = call i32 @llvm.smin.i32(i32 [[X:%.*]], i32 2) +; CHECK-NEXT:[[SEL:%.*]] = sitofp i32 [[SEL1]] to double +; CHECK-NEXT:ret double [[SEL]] +; + %cmp = icmp sgt i32 %x, 2 + %cst = sitofp i32 %x to double + %sel = select i1 %cmp, double 2.0, double %cst + ret double %sel +} + +define double @t17_commuted3(i32 %x) { +; CHECK-LABEL: @t17_commuted3( +; CHECK-NEXT:[[CMP:%.*]] = icmp slt i32 [[X:%.*]], 3 +; CHECK-NEXT:[[CST:%.*]] = sitofp i32 [[X]] to double +; CHECK-NEXT:[[SEL:%.*]] = select i1 [[CMP]], double [[CST]], double 2.00e+00 +; CHECK-NEXT:ret double [[SEL]] +; + %cmp = icmp slt i32 %x, 3 + %cst = sitofp i32 %x to double + %sel = select i1 %cmp, double %cst, double 2.0 + ret double %sel +} + define float @fneg_fmax(float %x, float %y) { ; CHECK-LABEL: @fneg_fmax( ; CHECK-NEXT:[[COND:%.*]] = fcmp nnan olt float [[X:%.*]], [[Y:%.*]] diff --git a/llvm/test/Transforms/InstCombine/preserve-sminmax.ll b/llvm/test/Transforms/InstCombine/preserve-sminmax.ll index f45cbe054d441e3..f2aa0ef54be270a 100644 --- a/llvm/test/Transforms/InstCombine/preserve-sminmax.ll +++ b/llvm/test/Transforms/InstCombine/preserve-sminmax.ll @@ -19,6 +19,19 @@ define i32 @foo(i32 %h) { ret i32 %r } +define i32 @foo_commuted(i32 %h) { +; CHECK-LABEL: @foo_commuted( +; CHECK-NEXT:[[SD:%.*]] = sdiv i32 [[H:%.*]], 2 +; CHECK-NEXT:[[T:%.*]] = icmp sgt i32 [[H]], 1 +; CHECK-NEXT:[[R:%.*]] = select i1 [[T]], i32 1, i32 [[SD]] +; CHECK-NEXT:ret i32 [[R]] +; + %sd = sdiv i32 %h, 2 + %t = icmp sgt i32 %sd, 0 + %r = select i1 %t, i32 1, i32 %sd + ret i32 %r +} + define i32 @bar(i32 %h) { ; CHECK-LABEL: @bar( ; CHECK-NEXT:[[SD:%.*]] = sdiv i32 [[H:%.*]], 2 >From 760dfbfc092131ba79f6fa43d65ad67ec4c7f114 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Wed, 8 Jan 2025 00:00:41 +0800 Subject: [PATCH 2/4] [ValueTracking] Handle filpped strictness cases in `matchSelectPattern` --- llvm/lib/Analysis/ValueTracking.cpp | 14 ++ .../CodeGen/RISCV/selectcc-to-shiftand.ll | 26 -- .../CorrelatedValuePropagation/switch.ll | 4 +- llvm/test/Transforms/InstCombine/minmax-fp.ll | 10 ++-- .../InstCombine/preserve-sminmax.ll | 3 +- .../PhaseOrdering/ARM/arm_mult_q15.ll | 50 +-- 6 files changed, 68 insertions(+), 39 deletions(-) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 45c3b85ea39fb46..94d3ea34f53df1d 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -8517,6 +8517,20 @@ static SelectPatternResult matchMinMax(CmpInst::Predicate Pred, LHS = TrueVal; RHS = FalseVal; + // Handle constant RHS cases like X < 3 ? 2 : X -> max(X, 2) + auto *CmpRHSC = dyn_cast(CmpRHS); + if (ICmpInst::isRelational(Pred) && CmpRHSC) { +if (auto Flipped = +getFlippedStrictnessPredicateAndConstant(Pred, CmpRHSC)) { + // icmp Pred X, C ? X : C + if (TrueVal == CmpLHS && Flipped->second == FalseVal) +return getSelectPattern(Flipped->first); + // icmp Pred X, C ? C : X --> icmp InversePred X, C ? X : C + if (FalseVal == CmpLHS && Flipped->second == TrueVal) +return getSelectPattern(ICmpInst::getInversePredicate(Flipped->first)); +} + } + SelectPatternResult SPR = matchClamp(Pred, CmpLHS, CmpRHS, TrueVal, FalseVal); if (SPR.Flavor != SelectPatternFlavor::SPF_UNKNOWN) return SPR; diff --git a/llvm/test/CodeGen/RISCV/selectcc-to-shiftand.ll b/llvm/test/CodeGen/RISCV/selectcc-to-shiftand.ll index 0d96fbfa81279f9..36abd8078829adc 100644 --- a/llvm/test/Code
[clang] [llvm] [mlir] [clang][CodeGen][AA] Add `!llvm.errno.tbaa` gathering int-compatible TBAA nodes (PR #125258)
nikic wrote: > so IIUC !llvm.errno.tbaa should just be a module-level list of int-compatible > TBAA nodes. Yes, exactly. It should be a module level MD node, not on individual instructions. https://github.com/llvm/llvm-project/pull/125258 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ExtractAPI,test] fix filecheck annotation (PR #92231)
https://github.com/klensy updated https://github.com/llvm/llvm-project/pull/92231 >From 6f904e5a6ea450f651fa6a1a6d8a57d63a7c07cb Mon Sep 17 00:00:00 2001 From: klensy Date: Wed, 15 May 2024 12:14:56 +0300 Subject: [PATCH] [ExtractAPI,test] fix filecheck annotation --- clang/test/ExtractAPI/availability.c | 2 +- clang/test/ExtractAPI/objc_property.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/test/ExtractAPI/availability.c b/clang/test/ExtractAPI/availability.c index 237b2ffa55d7dc..ca6007e12e255c 100644 --- a/clang/test/ExtractAPI/availability.c +++ b/clang/test/ExtractAPI/availability.c @@ -40,7 +40,7 @@ void b(void) __attribute__((availability(macos, introduced=11.0, deprecated=12.0 // B-NEXT: } // B-NEXT: ] -// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix E +// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix C void c(void) __attribute__((availability(macos, introduced=11.0, deprecated=12.0, obsoleted=20.0))) __attribute__((availability(ios, introduced=13.0))); // C-LABEL: "!testLabel": "c:@F@c" // C: "availability": [ diff --git a/clang/test/ExtractAPI/objc_property.m b/clang/test/ExtractAPI/objc_property.m index f05584c885d91f..0c0b17c9c000fd 100644 --- a/clang/test/ExtractAPI/objc_property.m +++ b/clang/test/ExtractAPI/objc_property.m @@ -11,7 +11,7 @@ @protocol Protocol @interface Interface @property(class) int myInterfaceTypeProp; -// CHECk-DAG: "!testRelLabel": "memberOf $ c:objc(cs)Interface(cpy)myInterfaceTypeProp $ c:objc(cs)Interface" +// CHECK-DAG: "!testRelLabel": "memberOf $ c:objc(cs)Interface(cpy)myInterfaceTypeProp $ c:objc(cs)Interface" @property int myInterfaceInstanceProp; // CHECK-DAG: "!testRelLabel": "memberOf $ c:objc(cs)Interface(py)myInterfaceInstanceProp $ c:objc(cs)Interface" @end @@ -20,7 +20,7 @@ @interface Interface (Category) @property(class) int myCategoryTypeProp; // CHECK-DAG: "!testRelLabel": "memberOf $ c:objc(cs)Interface(cpy)myCategoryTypeProp $ c:objc(cs)Interface" @property int myCategoryInstanceProp; -// CHECK-DAG "!testRelLabel": "memberOf $ c:objc(cs)Interface(py)myCategoryInstanceProp $ c:objc(cs)Interface" +// CHECK-DAG: "!testRelLabel": "memberOf $ c:objc(cs)Interface(py)myCategoryInstanceProp $ c:objc(cs)Interface" @end // expected-no-diagnostics ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Emit warnings on incorrect AVR interrupt/signal handlers (PR #125328)
https://github.com/Patryk27 approved this pull request. https://github.com/llvm/llvm-project/pull/125328 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ExtractAPI,test] fix filecheck annotation (PR #92231)
klensy wrote: Reviewed and ready to merge, please, commit someone. https://github.com/llvm/llvm-project/pull/92231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits