[clang-tools-extra] [clang] [clang-tidy] fix match for binaryOperator in ExprMutationAnalyzer for misc-const-correctness (PR #70559)
jcsxky wrote: how about adding a function call like `f()`? will this can prevent clang to emit empty function body? https://github.com/llvm/llvm-project/pull/70559 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/74813 This patch aims to fix the [crash](https://github.com/llvm/llvm-project/issues/74774) >From 49ec0838ecef753d86562ce4c12b3d84000a859e Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 8 Dec 2023 15:26:01 +0800 Subject: [PATCH] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr --- clang/lib/AST/ASTImporter.cpp | 12 clang/unittests/AST/ASTImporterTest.cpp | 20 2 files changed, 32 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a..79ca48bf9ec0f 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -7820,6 +7820,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); } + case Stmt::BuiltinBitCastExprClass: { +auto *BBC = cast(E); +ExpectedSLoc ToLParenLocOrErr = import(BBC->getBeginLoc()); +if (!ToLParenLocOrErr) + return ToLParenLocOrErr.takeError(); +ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc()); +if (!ToRParenLocOrErr) + return ToRParenLocOrErr.takeError(); +return new (Importer.getToContext()) BuiltinBitCastExpr( +ToType, E->getValueKind(), E->getCastKind(), ToSubExpr, +ToTypeInfoAsWritten, *ToLParenLocOrErr, *ToRParenLocOrErr); + } default: llvm_unreachable("Cast expression of unsupported type!"); return make_error(ASTImportError::UnsupportedConstruct); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf..3d9c426e13895 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -10,6 +10,7 @@ // //===--===// +#include "clang/AST/ASTFwd.h" #include "clang/AST/RecordLayout.h" #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Testing/CommandLineArgs.h" @@ -19,6 +20,7 @@ #include "gtest/gtest.h" #include "ASTImporterFixtures.h" +#include "DeclMatcher.h" #include namespace clang { @@ -9284,6 +9286,24 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +const internal::VariadicDynCastAllOfMatcher +builtinBitCastExpr; + +TEST_P(ASTImporterOptionSpecificTestBase, ImportBuiltinBitCastExpr) { + const char *CodeFrom = + R"( + void foo(int T) { (void)__builtin_bit_cast(float, T); } + )"; + Decl *FromTU = getTuDecl(CodeFrom, Lang_CXX20); + auto *FromFoo = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("foo"))); + auto *ToFoo = Import(FromFoo, Lang_CXX20); + EXPECT_TRUE(ToFoo); + auto *ToBuiltinBitCastExpr = + FirstDeclMatcher().match(ToFoo, builtinBitCastExpr()); + EXPECT_TRUE(ToBuiltinBitCastExpr); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74813 >From 0cab02331a5f1eb85649ab381d73ddb71d354b5b Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 8 Dec 2023 15:26:01 +0800 Subject: [PATCH] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr --- clang/lib/AST/ASTImporter.cpp | 12 clang/unittests/AST/ASTImporterTest.cpp | 18 ++ 2 files changed, 30 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..79ca48bf9ec0f9 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -7820,6 +7820,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); } + case Stmt::BuiltinBitCastExprClass: { +auto *BBC = cast(E); +ExpectedSLoc ToLParenLocOrErr = import(BBC->getBeginLoc()); +if (!ToLParenLocOrErr) + return ToLParenLocOrErr.takeError(); +ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc()); +if (!ToRParenLocOrErr) + return ToRParenLocOrErr.takeError(); +return new (Importer.getToContext()) BuiltinBitCastExpr( +ToType, E->getValueKind(), E->getCastKind(), ToSubExpr, +ToTypeInfoAsWritten, *ToLParenLocOrErr, *ToRParenLocOrErr); + } default: llvm_unreachable("Cast expression of unsupported type!"); return make_error(ASTImportError::UnsupportedConstruct); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..27137c5b8ad06a 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9284,6 +9284,24 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +const internal::VariadicDynCastAllOfMatcher +builtinBitCastExpr; + +TEST_P(ASTImporterOptionSpecificTestBase, ImportBuiltinBitCastExpr) { + const char *CodeFrom = + R"( + void foo(int T) { (void)__builtin_bit_cast(float, T); } + )"; + Decl *FromTU = getTuDecl(CodeFrom, Lang_CXX20); + auto *FromFoo = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("foo"))); + auto *ToFoo = Import(FromFoo, Lang_CXX20); + EXPECT_TRUE(ToFoo); + auto *ToBuiltinBitCastExpr = + FirstDeclMatcher().match(ToFoo, builtinBitCastExpr()); + EXPECT_TRUE(ToBuiltinBitCastExpr); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl (PR #74919)
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/74919 Skip checking `TemplateTypeParmDecl ` in `VisitTypeAliasTemplateDecl`. [Fix this crash](https://github.com/llvm/llvm-project/issues/74765) >From b3c28d66efb98dff8b8f879bda92341bf62f45d3 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Sat, 9 Dec 2023 12:00:02 +0800 Subject: [PATCH] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl --- clang/lib/AST/ASTImporter.cpp | 3 ++- clang/unittests/AST/ASTImporterTest.cpp | 23 +++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..bfe9af648e603b 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -2769,7 +2769,8 @@ ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { unsigned IDNS = Decl::IDNS_Ordinary; auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); for (auto *FoundDecl : FoundDecls) { - if (!FoundDecl->isInIdentifierNamespace(IDNS)) + if (!FoundDecl->isInIdentifierNamespace(IDNS) || + isa_and_nonnull(FoundDecl)) continue; if (auto *FoundAlias = dyn_cast(FoundDecl)) return Importer.MapImported(D, FoundAlias); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..6f9aba2c867eea 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9284,6 +9284,29 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +TEST_P(ASTImporterOptionSpecificTestBase, XXX) { + const char *Code = + R"( + struct S; + template + using Callable = S; + template + int bindingFunctionVTable; + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + + auto *FromCallable1 = FirstDeclMatcher().match( + FromTU, typeAliasTemplateDecl(hasName("Callable"))); + + auto *FromCallable2 = FirstDeclMatcher().match( + FromTU, templateTypeParmDecl(hasName("Callable"))); + + auto *ToCallable2 = Import(FromCallable2, Lang_CXX17); + auto *ToCallable1 = Import(FromCallable1, Lang_CXX17); + EXPECT_TRUE(ToCallable1); + EXPECT_TRUE(ToCallable2); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74813 >From 53e0a0bb8061e5fbd49c58b30bc1217cbb669352 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 8 Dec 2023 15:26:01 +0800 Subject: [PATCH] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr --- clang/lib/AST/ASTImporter.cpp | 12 clang/unittests/AST/ASTImporterTest.cpp | 18 ++ 2 files changed, 30 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a..0edb6930ed0a0 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -7820,6 +7820,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); } + case Stmt::BuiltinBitCastExprClass: { +auto *BBC = cast(E); +ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc()); +if (!ToKWLocOrErr) + return ToKWLocOrErr.takeError(); +ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc()); +if (!ToRParenLocOrErr) + return ToRParenLocOrErr.takeError(); +return new (Importer.getToContext()) BuiltinBitCastExpr( +ToType, E->getValueKind(), E->getCastKind(), ToSubExpr, +ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr); + } default: llvm_unreachable("Cast expression of unsupported type!"); return make_error(ASTImportError::UnsupportedConstruct); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf..27137c5b8ad06 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9284,6 +9284,24 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +const internal::VariadicDynCastAllOfMatcher +builtinBitCastExpr; + +TEST_P(ASTImporterOptionSpecificTestBase, ImportBuiltinBitCastExpr) { + const char *CodeFrom = + R"( + void foo(int T) { (void)__builtin_bit_cast(float, T); } + )"; + Decl *FromTU = getTuDecl(CodeFrom, Lang_CXX20); + auto *FromFoo = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("foo"))); + auto *ToFoo = Import(FromFoo, Lang_CXX20); + EXPECT_TRUE(ToFoo); + auto *ToBuiltinBitCastExpr = + FirstDeclMatcher().match(ToFoo, builtinBitCastExpr()); + EXPECT_TRUE(ToBuiltinBitCastExpr); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
@@ -7820,6 +7820,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); } + case Stmt::BuiltinBitCastExprClass: { +auto *BBC = cast(E); +ExpectedSLoc ToLParenLocOrErr = import(BBC->getBeginLoc()); jcsxky wrote: Fixed according to your suggestion and description has been updated. https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] delay import funtion return type (PR #74991)
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/74991 Import return type of a function would lead infinite recursion when `getAssociatedDecl()` returns itself in `ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr`. Delay import the return type whether it is auto would make sense. This patch try to fix [this issue](https://github.com/llvm/llvm-project/issues/74839) >From 1527cc2046d4c9881ca536a2dbf59330d9291ba2 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Sun, 10 Dec 2023 21:01:49 +0800 Subject: [PATCH] [clang][ASTImporter] delay import funtion return type --- clang/lib/AST/ASTImporter.cpp | 8 ++-- clang/unittests/AST/ASTImporterTest.cpp | 20 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..335d10016f2060 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -3739,16 +3739,13 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { // do the same with TypeSourceInfo. bool UsedDifferentProtoType = false; if (const auto *FromFPT = FromTy->getAs()) { -QualType FromReturnTy = FromFPT->getReturnType(); // Functions with auto return type may define a struct inside their body // and the return type could refer to that struct. // E.g.: auto foo() { struct X{}; return X(); } // To avoid an infinite recursion when importing, create the FunctionDecl // with a simplified return type. -if (hasAutoReturnTypeDeclaredInside(D)) { - FromReturnTy = Importer.getFromContext().VoidTy; - UsedDifferentProtoType = true; -} +QualType FromReturnTy = Importer.getFromContext().VoidTy; +UsedDifferentProtoType = true; FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the // FunctionDecl that we are importing the FunctionProtoType for. @@ -3759,7 +3756,6 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { FromEPI.ExceptionSpec.NoexceptExpr) { FunctionProtoType::ExtProtoInfo DefaultEPI; FromEPI = DefaultEPI; - UsedDifferentProtoType = true; } FromTy = Importer.getFromContext().getFunctionType( FromReturnTy, FromFPT->getParamTypes(), FromEPI); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..7ab9db4251e80b 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9284,6 +9284,26 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +TEST_P(ASTImporterOptionSpecificTestBase, ImportFunctionAutoType) { + const char *Code = + R"( + template + struct array {}; + + template + auto foo() { return array(); } + + void bar() { foo<0>(); } + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + + auto *FromBar = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("bar"))); + + auto *ToBar = Import(FromBar, Lang_CXX17); + EXPECT_TRUE(ToBar); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl (PR #74919)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74919 >From e656aa2a3850f845987bb0ddc56b308d22d2dafd Mon Sep 17 00:00:00 2001 From: huqizhi Date: Sat, 9 Dec 2023 12:00:02 +0800 Subject: [PATCH] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl --- clang/lib/AST/ASTImporter.cpp | 3 ++- clang/unittests/AST/ASTImporterTest.cpp | 23 +++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a..bfe9af648e603 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -2769,7 +2769,8 @@ ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { unsigned IDNS = Decl::IDNS_Ordinary; auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); for (auto *FoundDecl : FoundDecls) { - if (!FoundDecl->isInIdentifierNamespace(IDNS)) + if (!FoundDecl->isInIdentifierNamespace(IDNS) || + isa_and_nonnull(FoundDecl)) continue; if (auto *FoundAlias = dyn_cast(FoundDecl)) return Importer.MapImported(D, FoundAlias); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf..b53cf11f315c8 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9284,6 +9284,29 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +TEST_P(ASTImporterOptionSpecificTestBase, ImportTypeAliasTemplateDecl) { + const char *Code = + R"( + struct S; + template + using Callable = S; + template + int bindingFunctionVTable; + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + + auto *FromCallable1 = FirstDeclMatcher().match( + FromTU, typeAliasTemplateDecl(hasName("Callable"))); + + auto *FromCallable2 = FirstDeclMatcher().match( + FromTU, templateTypeParmDecl(hasName("Callable"))); + + auto *ToCallable2 = Import(FromCallable2, Lang_CXX17); + auto *ToCallable1 = Import(FromCallable1, Lang_CXX17); + EXPECT_TRUE(ToCallable1); + EXPECT_TRUE(ToCallable2); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] delay import funtion return type (PR #74991)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74991 >From 8dc4955fad0147db16bddfe8fc7d227ae69b89a1 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Sun, 10 Dec 2023 21:01:49 +0800 Subject: [PATCH] [clang][ASTImporter] add processing of SubstNonTypeTemplateParmExpr in isAncestorDeclContextOf --- clang/lib/AST/ASTImporter.cpp | 15 ++- clang/unittests/AST/ASTImporterTest.cpp | 20 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..8f360e9443011f 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -3418,10 +3418,15 @@ static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) { while (!ToProcess.empty()) { const Stmt *CurrentS = ToProcess.pop_back_val(); ToProcess.append(CurrentS->child_begin(), CurrentS->child_end()); -if (const auto *DeclRef = dyn_cast(CurrentS)) +if (const auto *DeclRef = dyn_cast(CurrentS)) { if (const Decl *D = DeclRef->getDecl()) if (isAncestorDeclContextOf(DC, D)) return true; +} else if (const auto *E = + dyn_cast_or_null(CurrentS)) { + if (isAncestorDeclContextOf(DC, E->getAssociatedDecl())) +return true; +} } return false; } @@ -3745,15 +3750,15 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { // E.g.: auto foo() { struct X{}; return X(); } // To avoid an infinite recursion when importing, create the FunctionDecl // with a simplified return type. -if (hasAutoReturnTypeDeclaredInside(D)) { - FromReturnTy = Importer.getFromContext().VoidTy; - UsedDifferentProtoType = true; -} FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the // FunctionDecl that we are importing the FunctionProtoType for. // To avoid an infinite recursion when importing, create the FunctionDecl // with a simplified function type. +if (hasAutoReturnTypeDeclaredInside(D)) { + FromReturnTy = Importer.getFromContext().VoidTy; + UsedDifferentProtoType = true; +} if (FromEPI.ExceptionSpec.SourceDecl || FromEPI.ExceptionSpec.SourceTemplate || FromEPI.ExceptionSpec.NoexceptExpr) { diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..7ab9db4251e80b 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9284,6 +9284,26 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +TEST_P(ASTImporterOptionSpecificTestBase, ImportFunctionAutoType) { + const char *Code = + R"( + template + struct array {}; + + template + auto foo() { return array(); } + + void bar() { foo<0>(); } + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + + auto *FromBar = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("bar"))); + + auto *ToBar = Import(FromBar, Lang_CXX17); + EXPECT_TRUE(ToBar); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] delay import funtion return type (PR #74991)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74991 >From 07b7415da7af38c45f4d22ba4d42f435c6a9fe68 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Sun, 10 Dec 2023 21:01:49 +0800 Subject: [PATCH] [clang][ASTImporter] add processing of SubstNonTypeTemplateParmExpr in isAncestorDeclContextOf --- clang/lib/AST/ASTImporter.cpp | 7 ++- clang/unittests/AST/ASTImporterTest.cpp | 20 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..8c8be7c1d8b24b 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -3418,10 +3418,15 @@ static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) { while (!ToProcess.empty()) { const Stmt *CurrentS = ToProcess.pop_back_val(); ToProcess.append(CurrentS->child_begin(), CurrentS->child_end()); -if (const auto *DeclRef = dyn_cast(CurrentS)) +if (const auto *DeclRef = dyn_cast(CurrentS)) { if (const Decl *D = DeclRef->getDecl()) if (isAncestorDeclContextOf(DC, D)) return true; +} else if (const auto *E = + dyn_cast_or_null(CurrentS)) { + if (isAncestorDeclContextOf(DC, E->getAssociatedDecl())) +return true; +} } return false; } diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..7ab9db4251e80b 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9284,6 +9284,26 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +TEST_P(ASTImporterOptionSpecificTestBase, ImportFunctionAutoType) { + const char *Code = + R"( + template + struct array {}; + + template + auto foo() { return array(); } + + void bar() { foo<0>(); } + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + + auto *FromBar = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("bar"))); + + auto *ToBar = Import(FromBar, Lang_CXX17); + EXPECT_TRUE(ToBar); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] add processing of SubstNonTypeTemplateParmExpr in isAncestorDeclContextOf (PR #74991)
https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/74991 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] add processing of SubstNonTypeTemplateParmExpr in isAncestorDeclContextOf (PR #74991)
https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/74991 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] add processing of SubstNonTypeTemplateParmExpr in isAncestorDeclContextOf (PR #74991)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74991 >From e5a6b1423919ded1ae11b431b2afa7213d052c41 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Sun, 10 Dec 2023 21:01:49 +0800 Subject: [PATCH] [clang][ASTImporter] add processing of SubstNonTypeTemplateParmExpr in isAncestorDeclContextOf --- clang/lib/AST/ASTImporter.cpp | 8 +++- clang/unittests/AST/ASTImporterTest.cpp | 20 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..e0eed03ce22b51 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -3418,10 +3418,16 @@ static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) { while (!ToProcess.empty()) { const Stmt *CurrentS = ToProcess.pop_back_val(); ToProcess.append(CurrentS->child_begin(), CurrentS->child_end()); -if (const auto *DeclRef = dyn_cast(CurrentS)) +if (const auto *DeclRef = dyn_cast(CurrentS)) { if (const Decl *D = DeclRef->getDecl()) if (isAncestorDeclContextOf(DC, D)) return true; +} else if (const auto *E = + dyn_cast_or_null(CurrentS)) { + if (const Decl *D = E->getAssociatedDecl()) +if (isAncestorDeclContextOf(DC, D)) + return true; +} } return false; } diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..7ab9db4251e80b 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9284,6 +9284,26 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +TEST_P(ASTImporterOptionSpecificTestBase, ImportFunctionAutoType) { + const char *Code = + R"( + template + struct array {}; + + template + auto foo() { return array(); } + + void bar() { foo<0>(); } + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + + auto *FromBar = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("bar"))); + + auto *ToBar = Import(FromBar, Lang_CXX17); + EXPECT_TRUE(ToBar); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][AST][ASTMerge] prevent AST nodes from being deallocated early (PR #73096)
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/73096 This patch aims to fix [error in ast-merge to new ast file](https://github.com/llvm/llvm-project/issues/72783). `ASTUnit` is put in `for` body and AST nodes would be deallocated by allocator. Using these nodes later would lead to use after free bug. Debug the [issue](https://github.com/llvm/llvm-project/issues/72783) can prove it. Address interval (local from 0x3a9a00 to 0x3aaa00) allocated by allocator contains a `IdentifierInfo` variable (local address:0x3aa190) whose address is freed early. As system header like stdio.h or math.h can't be put into test, it's hard to add testcase. Could anyone give me some guidance? Thanks in advance! >From 0c3b47b351eb90495d635fd37845d5c7da869b6e Mon Sep 17 00:00:00 2001 From: huqizhi Date: Wed, 22 Nov 2023 16:41:42 +0800 Subject: [PATCH] [clang][AST][ASTMerge] prevent AST nodes from being deallocated early --- clang/lib/Frontend/ASTMerge.cpp | 13 - 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/clang/lib/Frontend/ASTMerge.cpp b/clang/lib/Frontend/ASTMerge.cpp index 057ea4fd5bb3518..94706ade4c876a2 100644 --- a/clang/lib/Frontend/ASTMerge.cpp +++ b/clang/lib/Frontend/ASTMerge.cpp @@ -5,14 +5,15 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===--===// -#include "clang/Frontend/ASTUnit.h" #include "clang/AST/ASTContext.h" #include "clang/AST/ASTDiagnostic.h" #include "clang/AST/ASTImporter.h" #include "clang/AST/ASTImporterSharedState.h" #include "clang/Basic/Diagnostic.h" +#include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendActions.h" +#include "llvm/ADT/SmallVector.h" using namespace clang; @@ -40,24 +41,26 @@ void ASTMergeAction::ExecuteAction() { DiagIDs(CI.getDiagnostics().getDiagnosticIDs()); auto SharedState = std::make_shared( *CI.getASTContext().getTranslationUnitDecl()); + llvm::SmallVector> Units(ASTFiles.size()); for (unsigned I = 0, N = ASTFiles.size(); I != N; ++I) { IntrusiveRefCntPtr Diags(new DiagnosticsEngine(DiagIDs, &CI.getDiagnosticOpts(), new ForwardingDiagnosticConsumer( *CI.getDiagnostics().getClient()), /*ShouldOwnClient=*/true)); -std::unique_ptr Unit = ASTUnit::LoadFromASTFile( +Units[I] = ASTUnit::LoadFromASTFile( ASTFiles[I], CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts(), CI.getHeaderSearchOptsPtr(), false); -if (!Unit) +if (!Units[I]) continue; ASTImporter Importer(CI.getASTContext(), CI.getFileManager(), - Unit->getASTContext(), Unit->getFileManager(), + Units[I]->getASTContext(), Units[I]->getFileManager(), /*MinimalImport=*/false, SharedState); -TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl(); +TranslationUnitDecl *TU = +Units[I]->getASTContext().getTranslationUnitDecl(); for (auto *D : TU->decls()) { // Don't re-import __va_list_tag, __builtin_va_list. if (const auto *ND = dyn_cast(D)) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][AST][ASTMerge] prevent AST nodes from being deallocated early (PR #73096)
jcsxky wrote: > > Debug the #72783 can prove it. Address interval (local from 0x3a9a00 to > > 0x3aaa00) allocated by allocator contains a IdentifierInfo variable (local > > address:0x3aa190) whose address is freed early. > > In this case, it looks better to extract the use-after-free variable only > instead of extracting the whole ASTUnit. - From my local debugging, it's a `IdentifierInfo` type variable which is freed by allocator. The variable is subnode of AST. Thanks to `ASTUnit` is out of scope, some related memory is freed (which is allocated by `SpecificBumpPtrAllocator`) as destructor called and we can't extract only `IdentifierInfo` type variable. > > > As system header like stdio.h or math.h can't be put into test, it's hard > > to add testcase. Could anyone give me some guidance? Thanks in advance! > > Generally, we need to reduce them in this case. e.g., we need to preprocess > them, and remove unncessary parts until we can't. It is time consuming but it > is worthy. - Small piece of code can't reproduce the crash. The crash is caused by growing of size of `OnDiskChainedHashTableGenerator` when add `IdentifierInfo` type variable. As mentioned in the [issue](https://github.com/llvm/llvm-project/issues/72783), when remove header file, it runs OK. Small-scale code wouldn't cause resize of `OnDiskChainedHashTableGenerator` https://github.com/llvm/llvm-project/pull/73096 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [clang-tidy] fix match for binaryOperator in ExprMutationAnalyzer for misc-const-correctness (PR #70559)
jcsxky wrote: > The top-level Linux and Windows tests work, but inside the `Trigger > Build`/`clang-ci` run, the windows test step fails. I'm not sure what the > difference is between these two Windows tests. This is interesting! Generally speaking, AST of the code in Windows and Linux platform is identical with clang compiled. Probably need debuging in Windows. https://github.com/llvm/llvm-project/pull/70559 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl (PR #74919)
jcsxky wrote: > The `VisitTypeAliasTemplateDecl` function should be re-designed to check for > structural equivalence at import. The following test does not pass because an > existing `TypeAliasTemplateDecl` declaration with the same name is always > found and returned, without check for structural equivalence. > > ``` > TEST_P(ASTImporterOptionSpecificTestBase, ImportTypeAliasTemplateDecl1) { > const char *ToCode = > R"( > struct S; > template > using Callable = S; > )"; > const char *Code = > R"( > struct S; > template > using Callable = S; > )"; > Decl *ToTU = getToTuDecl(ToCode, Lang_CXX17); > Decl *FromTU = getTuDecl(Code, Lang_CXX17); > > auto *FromCallable = FirstDeclMatcher().match( > FromTU, typeAliasTemplateDecl(hasName("Callable"))); > > auto *ToCallable = FirstDeclMatcher().match( > ToTU, typeAliasTemplateDecl(hasName("Callable"))); > > auto *ImportedCallable = Import(FromCallable, Lang_CXX17); > EXPECT_TRUE(ImportedCallable); > EXPECT_NE(ImportedCallable, ToCallable); > } > ``` > > Additionally I discovered that import of `ClassTemplateDecl` is not correct > too: If there is an object with the same name that is not a > `ClassTemplateDecl`, it is just ignored at import. This is not correct, the > existing object may cause name conflict (for example it can be a non-template > `RecordDecl`). (I found this when checking the questions in my last comment.) > This is an independent problem but should be fixed. I pulled the latest code of main branch and found it seems incorrect with the test case I have supplied. I will have a double check this pr and issues you mentioned here. Thank for your detail comments and guidance. https://github.com/llvm/llvm-project/pull/74919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl (PR #74919)
jcsxky wrote: > The problem may be related to the fact that template parameter declarations > can have the `TranslationUnitDecl` as parent until the template (with these > parameters) is finally created. In the temporary phase the object > (`TemplateTypeParmDecl`) is found with lookup if it has the same name as an > other imported object. Does the crash happen if in the test code the > `TypeAliasTemplateDecl` is replaced with a plain `ClassTemplateDecl` or > `FunctionTemplateDecl`? If yes the change is needed at these import functions > too. Replace `TypeAliasTemplateDecl` with `ClassTemplateDecl` or `FunctionTemplateDecl` has no problem and passed the test with following test code ```cpp struct S; template class Callable {}; template int bindingFunctionVTable; ``` and ```cpp struct S; template void Callable(){} template int bindingFunctionVTable; ``` Test code seems good to current issue and the two you mentioned above can't be fixed with this pr. Should I abandon this pr or fix current issue only first? https://github.com/llvm/llvm-project/pull/74919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl (PR #74919)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74919 >From e4e981ed4f545f3dd4cc709bab30468a8ceb3962 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Sat, 9 Dec 2023 12:00:02 +0800 Subject: [PATCH] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl --- clang/lib/AST/ASTImporter.cpp | 16 --- clang/lib/AST/ASTStructuralEquivalence.cpp | 16 +++ clang/unittests/AST/ASTImporterTest.cpp| 50 ++ 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..40e5ac6ecb13e4 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -2771,9 +2771,12 @@ ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { for (auto *FoundDecl : FoundDecls) { if (!FoundDecl->isInIdentifierNamespace(IDNS)) continue; - if (auto *FoundAlias = dyn_cast(FoundDecl)) -return Importer.MapImported(D, FoundAlias); - ConflictingDecls.push_back(FoundDecl); + if (auto *FoundAlias = dyn_cast(FoundDecl)) { +// if (IsStructuralMatch(D,FoundAlias)) + return Importer.MapImported(D, FoundAlias); + +ConflictingDecls.push_back(FoundDecl); + } } if (!ConflictingDecls.empty()) { @@ -9073,7 +9076,6 @@ class AttrImporter { ToAttr = FromAttr->clone(Importer.getToContext()); ToAttr->setRange(ToRange); -ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName())); } // Get the result of the previous import attempt (can be used only once). @@ -9223,6 +9225,11 @@ Expected ASTImporter::Import(const Attr *FromAttr) { AI.castAttrAs()->setCountedByFieldLoc(SR.get()); break; } + case attr::AlignValue:{ +auto *From = cast(FromAttr); +AI.importAttr(From,AI.importArg(From->getAlignment()).value()); +break; + } default: { // The default branch works for attributes that have no arguments to import. @@ -9391,7 +9398,6 @@ Expected ASTImporter::Import(Decl *FromD) { setImportDeclError(FromD, *Error); return make_error(*Error); } - // Make sure that ImportImpl registered the imported decl. assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?"); if (auto Error = ImportAttrs(ToD, FromD)) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 6bb4bf14b873d7..5d6c3f35e50832 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -1977,6 +1977,22 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, D2->getTemplatedDecl()->getType()); } +// static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, +// TypeAliasTemplateDecl *D1, +// TypeAliasTemplateDecl *D2) { +// if (!IsStructurallyEquivalent(Context, D1->getDeclName(), D2->getDeclName())) +// return false; + +// // Check the templated declaration. +// if (!IsStructurallyEquivalent(Context, D1->getTemplatedDecl(), +// D2->getTemplatedDecl())) +// return false; + +// // Check template parameters. +// return IsStructurallyEquivalent(Context, D1->getTemplateParameters(), +// D2->getTemplateParameters()); +// } + static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, ConceptDecl *D1, ConceptDecl *D2) { diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..454a4d42d77520 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9284,6 +9284,56 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +// TEST_P(ASTImporterOptionSpecificTestBase, ImportTypeAliasTemplateDecl) { +// const char *Code = +// R"( +// struct S; +// template +// using Callable = S; +// template +// int bindingFunctionVTable; +// )"; +// Decl *FromTU = getTuDecl(Code, Lang_CXX17); + +// auto *FromCallable1 = FirstDeclMatcher().match( +// FromTU, typeAliasTemplateDecl(hasName("Callable"))); + +// auto *FromCallable2 = FirstDeclMatcher().match( +// FromTU, templateTypeParmDecl(hasName("Callable"))); + +// auto *ToCallable2 = Import(FromCallable2, Lang_CXX17); +// auto *ToCallable1 = Import(FromCallable1, Lang_CXX17); +// EXPECT_TRUE(ToCallable1); +// EXPECT_TRUE(ToCallable2); +// } + +// TEST_P(ASTImporterOptionSpecificTestBase, X) { +// const char *CodeFrom1 = +// R"( +// template +// bool A = A; +// )"; +// const char *CodeFrom2 = +// R"( +//
[clang] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl (PR #74919)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74919 >From a2dcc7f471237e78f374c204216c6574059aa950 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Sat, 9 Dec 2023 12:00:02 +0800 Subject: [PATCH] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl --- clang/lib/AST/ASTImporter.cpp | 9 +++-- clang/lib/AST/ASTStructuralEquivalence.cpp | 16 clang/unittests/AST/ASTImporterTest.cpp| 47 ++ 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..270574a7704505 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -2771,9 +2771,11 @@ ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { for (auto *FoundDecl : FoundDecls) { if (!FoundDecl->isInIdentifierNamespace(IDNS)) continue; - if (auto *FoundAlias = dyn_cast(FoundDecl)) -return Importer.MapImported(D, FoundAlias); - ConflictingDecls.push_back(FoundDecl); + if (auto *FoundAlias = dyn_cast(FoundDecl)) { +if (IsStructuralMatch(D, FoundAlias)) + return Importer.MapImported(D, FoundAlias); +ConflictingDecls.push_back(FoundDecl); + } } if (!ConflictingDecls.empty()) { @@ -9391,7 +9393,6 @@ Expected ASTImporter::Import(Decl *FromD) { setImportDeclError(FromD, *Error); return make_error(*Error); } - // Make sure that ImportImpl registered the imported decl. assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?"); if (auto Error = ImportAttrs(ToD, FromD)) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 6bb4bf14b873d7..ae55ff7811e794 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -1977,6 +1977,22 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, D2->getTemplatedDecl()->getType()); } +static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, + TypeAliasTemplateDecl *D1, + TypeAliasTemplateDecl *D2) { + if (!IsStructurallyEquivalent(Context, D1->getDeclName(), D2->getDeclName())) +return false; + + // Check the templated declaration. + if (!IsStructurallyEquivalent(Context, D1->getTemplatedDecl(), +D2->getTemplatedDecl())) +return false; + + // Check template parameters. + return IsStructurallyEquivalent(Context, D1->getTemplateParameters(), + D2->getTemplateParameters()); +} + static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, ConceptDecl *D1, ConceptDecl *D2) { diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..2328e98a663810 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9284,6 +9284,53 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +TEST_P(ASTImporterOptionSpecificTestBase, + ImportTypeAliasTemplateAfterSimilarCalledTemplateTypeParm) { + const char *Code = + R"( + struct S; + template + using Callable = S; + template + int bindingFunctionVTable; + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + + auto *FromCallable = FirstDeclMatcher().match( + FromTU, typeAliasTemplateDecl(hasName("Callable"))); + + auto *FromCallableParm = FirstDeclMatcher().match( + FromTU, templateTypeParmDecl(hasName("Callable"))); + + auto *ToFromCallableParm = Import(FromCallableParm, Lang_CXX17); + auto *ToCallable = Import(FromCallable, Lang_CXX17); + EXPECT_TRUE(ToFromCallableParm); + EXPECT_TRUE(ToCallable); +} + +TEST_P(ASTImporterOptionSpecificTestBase, ImportConflictTypeAliasTemplate) { + const char *ToCode = + R"( + struct S; + template + using Callable = S; + )"; + const char *Code = + R"( + struct S; + template + using Callable = S; + )"; + (void)getToTuDecl(ToCode, Lang_CXX17); + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + + auto *FromCallable = FirstDeclMatcher().match( + FromTU, typeAliasTemplateDecl(hasName("Callable"))); + + auto *ImportedCallable = Import(FromCallable, Lang_CXX17); + EXPECT_FALSE(ImportedCallable); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl (PR #74919)
jcsxky wrote: > The `VisitTypeAliasTemplateDecl` function should be re-designed to check for > structural equivalence at import. The following test does not pass because an > existing `TypeAliasTemplateDecl` declaration with the same name is always > found and returned, without check for structural equivalence. > > ``` > TEST_P(ASTImporterOptionSpecificTestBase, ImportTypeAliasTemplateDecl1) { > const char *ToCode = > R"( > struct S; > template > using Callable = S; > )"; > const char *Code = > R"( > struct S; > template > using Callable = S; > )"; > Decl *ToTU = getToTuDecl(ToCode, Lang_CXX17); > Decl *FromTU = getTuDecl(Code, Lang_CXX17); > > auto *FromCallable = FirstDeclMatcher().match( > FromTU, typeAliasTemplateDecl(hasName("Callable"))); > > auto *ToCallable = FirstDeclMatcher().match( > ToTU, typeAliasTemplateDecl(hasName("Callable"))); > > auto *ImportedCallable = Import(FromCallable, Lang_CXX17); > EXPECT_TRUE(ImportedCallable); > EXPECT_NE(ImportedCallable, ToCallable); > } > ``` > > Additionally I discovered that import of `ClassTemplateDecl` is not correct > too: If there is an object with the same name that is not a > `ClassTemplateDecl`, it is just ignored at import. This is not correct, the > existing object may cause name conflict (for example it can be a non-template > `RecordDecl`). (I found this when checking the questions in my last comment.) > This is an independent problem but should be fixed. Is import of `Callable` should be failed? I compiled this code ```cpp struct S; template using Callable = S; template using Callable = S; ``` and clang report an error. https://github.com/llvm/llvm-project/pull/74919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Fix import of variable template redeclarations. (PR #72841)
=?utf-8?q?Balázs_Kéri?= , =?utf-8?q?Balázs_Kéri?= Message-ID: In-Reply-To: @@ -5050,6 +5050,59 @@ TEST_P(ImportFriendClasses, RecordVarTemplateDecl) { EXPECT_EQ(ToTUX, ToX); } +TEST_P(ASTImporterOptionSpecificTestBase, VarTemplateDeclConflict) { + getToTuDecl( + R"( + template + constexpr int X = 1; + )", + Lang_CXX14); + + Decl *FromTU = getTuDecl( + R"( + template + constexpr int X = 2; + )", + Lang_CXX14, "input1.cc"); + auto *FromX = FirstDeclMatcher().match( + FromTU, varTemplateDecl(hasName("X"))); + auto *ToX = Import(FromX, Lang_CXX11); + // FIXME: This import should fail. + EXPECT_TRUE(ToX); jcsxky wrote: If import `X` should fail, What about this case in `ASTImporterGenericRedeclTest.cpp` ```cpp struct VariableTemplate { using DeclTy = VarTemplateDecl; static constexpr auto *Prototype = "template extern T X;"; static constexpr auto *Definition = R"( template T X; template <> int X; )"; // There is no matcher for varTemplateDecl so use a work-around. BindableMatcher getPattern() { return namedDecl(hasName("X"), unless(isImplicit()), has(templateTypeParmDecl())); } }; ``` Storage of `X` in `Prototype` and `Definition` is different, it should fail when imported. I added structural equivalence of `VarTemplateDecl` and makes this import failed in `VarTemplateDeclConflict`. is it also need to fix the testcase in `ASTImporterGenericRedeclTest.cpp`? ```cpp static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, VarTemplateDecl *D1, VarTemplateDecl *D2) { if (!IsStructurallyEquivalent(Context, D1->getDeclName(), D2->getDeclName())) return false; // Check the templated declaration. if (!IsStructurallyEquivalent(Context, D1->getTemplatedDecl(), D2->getTemplatedDecl())) return false; // Check template parameters. return IsStructurallyEquivalent(Context, D1->getTemplateParameters(), D2->getTemplateParameters()); } ``` https://github.com/llvm/llvm-project/pull/72841 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74813 >From 4e2ac40eece61343b5947ae906e5a4be8a82c823 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 8 Dec 2023 15:26:01 +0800 Subject: [PATCH] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr --- clang/lib/AST/ASTImporter.cpp | 12 clang/unittests/AST/ASTImporterTest.cpp | 24 2 files changed, 36 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..0edb6930ed0a00 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -7820,6 +7820,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); } + case Stmt::BuiltinBitCastExprClass: { +auto *BBC = cast(E); +ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc()); +if (!ToKWLocOrErr) + return ToKWLocOrErr.takeError(); +ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc()); +if (!ToRParenLocOrErr) + return ToRParenLocOrErr.takeError(); +return new (Importer.getToContext()) BuiltinBitCastExpr( +ToType, E->getValueKind(), E->getCastKind(), ToSubExpr, +ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr); + } default: llvm_unreachable("Cast expression of unsupported type!"); return make_error(ASTImportError::UnsupportedConstruct); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..82174ddc07de22 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -3220,6 +3220,12 @@ TEST_P(ImportExpr, UnresolvedMemberExpr) { compoundStmt(has(callExpr(has(unresolvedMemberExpr()); } +TEST_P(ImportExpr, BuiltinBitCastExpr) { + MatchVerifier Verifier; + testImport("void declToImport(int T) { (void)__builtin_bit_cast(float, T); }", + Lang_CXX20, "", Lang_CXX20, Verifier, functionDecl()); +} + class ImportImplicitMethods : public ASTImporterOptionSpecificTestBase { public: static constexpr auto DefaultCode = R"( @@ -9284,6 +9290,24 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +const internal::VariadicDynCastAllOfMatcher +builtinBitCastExpr; + +TEST_P(ASTImporterOptionSpecificTestBase, ImportBuiltinBitCastExpr) { + const char *CodeFrom = + R"( + void foo(int T) { (void)__builtin_bit_cast(float, T); } + )"; + Decl *FromTU = getTuDecl(CodeFrom, Lang_CXX20); + auto *FromFoo = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("foo"))); + auto *ToFoo = Import(FromFoo, Lang_CXX20); + EXPECT_TRUE(ToFoo); + auto *ToBuiltinBitCastExpr = + FirstDeclMatcher().match(ToFoo, builtinBitCastExpr()); + EXPECT_TRUE(ToBuiltinBitCastExpr); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
@@ -9284,6 +9284,24 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +const internal::VariadicDynCastAllOfMatcher +builtinBitCastExpr; + +TEST_P(ASTImporterOptionSpecificTestBase, ImportBuiltinBitCastExpr) { + const char *CodeFrom = + R"( + void foo(int T) { (void)__builtin_bit_cast(float, T); } + )"; + Decl *FromTU = getTuDecl(CodeFrom, Lang_CXX20); + auto *FromFoo = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("foo"))); + auto *ToFoo = Import(FromFoo, Lang_CXX20); + EXPECT_TRUE(ToFoo); + auto *ToBuiltinBitCastExpr = + FirstDeclMatcher().match(ToFoo, builtinBitCastExpr()); + EXPECT_TRUE(ToBuiltinBitCastExpr); +} jcsxky wrote: Another testcase has been added to `ImportExpr` https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] add processing of SubstNonTypeTemplateParmExpr in isAncestorDeclContextOf (PR #74991)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74991 >From 6bb37862cb6b09fd252d991d5f3ce0d2208bedac Mon Sep 17 00:00:00 2001 From: huqizhi Date: Sun, 10 Dec 2023 21:01:49 +0800 Subject: [PATCH] [clang][ASTImporter] add processing of SubstNonTypeTemplateParmExpr in isAncestorDeclContextOf --- clang/lib/AST/ASTImporter.cpp | 8 +++- clang/unittests/AST/ASTImporterTest.cpp | 20 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..e0eed03ce22b51 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -3418,10 +3418,16 @@ static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) { while (!ToProcess.empty()) { const Stmt *CurrentS = ToProcess.pop_back_val(); ToProcess.append(CurrentS->child_begin(), CurrentS->child_end()); -if (const auto *DeclRef = dyn_cast(CurrentS)) +if (const auto *DeclRef = dyn_cast(CurrentS)) { if (const Decl *D = DeclRef->getDecl()) if (isAncestorDeclContextOf(DC, D)) return true; +} else if (const auto *E = + dyn_cast_or_null(CurrentS)) { + if (const Decl *D = E->getAssociatedDecl()) +if (isAncestorDeclContextOf(DC, D)) + return true; +} } return false; } diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..4c06152d3eb563 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -7250,6 +7250,26 @@ TEST_P(ImportAutoFunctions, ReturnWithAutoTemplateType) { Lang_CXX14, /*FindLast=*/true); } +TEST_P(ImportAutoFunctions, ReturnWithSubstNonTypeTemplateParmExpr) { + const char *Code = + R"( + template + struct array {}; + + template + auto foo() { return array(); } + + void bar() { foo<0>(); } + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + + auto *FromBar = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("bar"))); + + auto *ToBar = Import(FromBar, Lang_CXX17); + EXPECT_TRUE(ToBar); +} + struct ImportSourceLocations : ASTImporterOptionSpecificTestBase {}; TEST_P(ImportSourceLocations, PreserveFileIDTreeStructure) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] add processing of SubstNonTypeTemplateParmExpr in isAncestorDeclContextOf (PR #74991)
@@ -9284,6 +9284,26 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +TEST_P(ASTImporterOptionSpecificTestBase, ImportFunctionAutoType) { jcsxky wrote: Code has been fixed. https://github.com/llvm/llvm-project/pull/74991 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl (PR #74919)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74919 >From 583cbd47533ff1aa71874c502affc44ce5b5c107 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Sat, 9 Dec 2023 12:00:02 +0800 Subject: [PATCH] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl --- clang/lib/AST/ASTImporter.cpp | 9 +++-- clang/lib/AST/ASTStructuralEquivalence.cpp | 12 ++ clang/unittests/AST/ASTImporterTest.cpp| 47 ++ 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..270574a7704505 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -2771,9 +2771,11 @@ ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { for (auto *FoundDecl : FoundDecls) { if (!FoundDecl->isInIdentifierNamespace(IDNS)) continue; - if (auto *FoundAlias = dyn_cast(FoundDecl)) -return Importer.MapImported(D, FoundAlias); - ConflictingDecls.push_back(FoundDecl); + if (auto *FoundAlias = dyn_cast(FoundDecl)) { +if (IsStructuralMatch(D, FoundAlias)) + return Importer.MapImported(D, FoundAlias); +ConflictingDecls.push_back(FoundDecl); + } } if (!ConflictingDecls.empty()) { @@ -9391,7 +9393,6 @@ Expected ASTImporter::Import(Decl *FromD) { setImportDeclError(FromD, *Error); return make_error(*Error); } - // Make sure that ImportImpl registered the imported decl. assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?"); if (auto Error = ImportAttrs(ToD, FromD)) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 6bb4bf14b873d7..1f492b051e0341 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -1977,6 +1977,18 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, D2->getTemplatedDecl()->getType()); } +static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, + TypeAliasTemplateDecl *D1, + TypeAliasTemplateDecl *D2) { + // Check template parameters. + if (!IsTemplateDeclCommonStructurallyEquivalent(Context, D1, D2)) +return false; + + // Check the templated declaration. + return IsStructurallyEquivalent(Context, D1->getTemplatedDecl(), + D2->getTemplatedDecl()); +} + static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, ConceptDecl *D1, ConceptDecl *D2) { diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..2328e98a663810 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9284,6 +9284,53 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +TEST_P(ASTImporterOptionSpecificTestBase, + ImportTypeAliasTemplateAfterSimilarCalledTemplateTypeParm) { + const char *Code = + R"( + struct S; + template + using Callable = S; + template + int bindingFunctionVTable; + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + + auto *FromCallable = FirstDeclMatcher().match( + FromTU, typeAliasTemplateDecl(hasName("Callable"))); + + auto *FromCallableParm = FirstDeclMatcher().match( + FromTU, templateTypeParmDecl(hasName("Callable"))); + + auto *ToFromCallableParm = Import(FromCallableParm, Lang_CXX17); + auto *ToCallable = Import(FromCallable, Lang_CXX17); + EXPECT_TRUE(ToFromCallableParm); + EXPECT_TRUE(ToCallable); +} + +TEST_P(ASTImporterOptionSpecificTestBase, ImportConflictTypeAliasTemplate) { + const char *ToCode = + R"( + struct S; + template + using Callable = S; + )"; + const char *Code = + R"( + struct S; + template + using Callable = S; + )"; + (void)getToTuDecl(ToCode, Lang_CXX17); + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + + auto *FromCallable = FirstDeclMatcher().match( + FromTU, typeAliasTemplateDecl(hasName("Callable"))); + + auto *ImportedCallable = Import(FromCallable, Lang_CXX17); + EXPECT_FALSE(ImportedCallable); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74813 >From d1f48502c1ec7a58ca18a19dc3631265e5c1b137 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 8 Dec 2023 15:26:01 +0800 Subject: [PATCH] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr --- clang/lib/AST/ASTImporter.cpp | 12 clang/unittests/AST/ASTImporterTest.cpp | 12 2 files changed, 24 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..0edb6930ed0a00 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -7820,6 +7820,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); } + case Stmt::BuiltinBitCastExprClass: { +auto *BBC = cast(E); +ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc()); +if (!ToKWLocOrErr) + return ToKWLocOrErr.takeError(); +ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc()); +if (!ToRParenLocOrErr) + return ToRParenLocOrErr.takeError(); +return new (Importer.getToContext()) BuiltinBitCastExpr( +ToType, E->getValueKind(), E->getCastKind(), ToSubExpr, +ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr); + } default: llvm_unreachable("Cast expression of unsupported type!"); return make_error(ASTImportError::UnsupportedConstruct); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..0941417bd3cfb4 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -561,6 +561,18 @@ TEST_P(ImportExpr, ImportVAArgExpr) { cStyleCastExpr(hasSourceExpression(vaArgExpr()); } +const internal::VariadicDynCastAllOfMatcher +builtinBitCastExpr; + +TEST_P(ImportExpr, ImportBuiltinBitCastExpr) { + MatchVerifier Verifier; + testImport("void declToImport(int X) {" + " (void)__builtin_bit_cast(float, X); }", + Lang_CXX20, "", Lang_CXX20, Verifier, + functionDecl(hasDescendant( + cStyleCastExpr(hasSourceExpression(builtinBitCastExpr()); +} + TEST_P(ImportExpr, CXXTemporaryObjectExpr) { MatchVerifier Verifier; testImport( ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
@@ -3220,6 +3220,12 @@ TEST_P(ImportExpr, UnresolvedMemberExpr) { compoundStmt(has(callExpr(has(unresolvedMemberExpr()); } +TEST_P(ImportExpr, BuiltinBitCastExpr) { + MatchVerifier Verifier; + testImport("void declToImport(int T) { (void)__builtin_bit_cast(float, T); }", + Lang_CXX20, "", Lang_CXX20, Verifier, functionDecl()); +} + jcsxky wrote: Oh, I see. The code has been fixed. https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][AST][ASTMerge] prevent AST nodes from being deallocated early (PR #73096)
jcsxky wrote: > You have found that reason for the crash is that references to > `IdentifierInfo` are remaining in `OnDiskChainedHashTableGenerator` and > previously deallocated by `ASTUnit` destruction? In this case why is the > `ASTUnit` (or something in it, probably `ASTContext`) the owner of the data, > and not `OnDiskChainedHashTableGenerator`? By using `ASTImporter` it is > possible that it moves data from the "old" AST to the "new" without copy (if > yes this is a bug) and such a situation can cause memory errors. Thanks for your remind! Indeed, root cause of the issue is ASTImporter and I have checked the code. IdentifierInfo of attribute should set with `ToASTContext` instead of copying from `FromASTContext`. https://github.com/llvm/llvm-project/pull/73096 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][AST][ASTMerge] prevent AST nodes from being deallocated early (PR #73096)
https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/73096 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/73290 None >From cc883836b0c24368a7a438873cec2229776323da Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 24 Nov 2023 13:55:45 +0800 Subject: [PATCH] [clang][ASTImporter] IdentifierInfo of Attribute should be set using ToASTContext --- clang/include/clang/Basic/AttributeCommonInfo.h | 1 + clang/lib/AST/ASTImporter.cpp | 7 +-- clang/unittests/AST/ASTImporterTest.cpp | 13 +++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h b/clang/include/clang/Basic/AttributeCommonInfo.h index 3140d1a838afcec..f84f51b1cd25022 100644 --- a/clang/include/clang/Basic/AttributeCommonInfo.h +++ b/clang/include/clang/Basic/AttributeCommonInfo.h @@ -177,6 +177,7 @@ class AttributeCommonInfo { IsRegularKeywordAttribute); } const IdentifierInfo *getAttrName() const { return AttrName; } + void setAttrName(const IdentifierInfo *A) { AttrName = A; } SourceLocation getLoc() const { return AttrRange.getBegin(); } SourceRange getRange() const { return AttrRange; } void setRange(SourceRange R) { AttrRange = R; } diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index c4e931e220f69b5..19e3e94c70c82d5 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -9241,9 +9241,12 @@ Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) { return Error::success(); for (const Attr *FromAttr : FromD->getAttrs()) { auto ToAttrOrErr = Import(FromAttr); -if (ToAttrOrErr) +if (ToAttrOrErr) { + if (auto *FromAttrNameII = FromAttr->getAttrName()) +(*ToAttrOrErr) +->setAttrName(&ToContext.Idents.get(FromAttrNameII->getName())); ToD->addAttr(*ToAttrOrErr); -else +} else return ToAttrOrErr.takeError(); } return Error::success(); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 5f4d8d040772cb1..2df92ad9d5985a4 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -12,6 +12,7 @@ #include "clang/AST/RecordLayout.h" #include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Testing/CommandLineArgs.h" #include "llvm/Support/SmallVectorMemoryBuffer.h" #include "clang/AST/DeclContextInternals.h" @@ -7362,11 +7363,12 @@ struct ImportAttributes : public ASTImporterOptionSpecificTestBase { } template - void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr) { + void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr, + TestLanguage Lang = Lang_CXX11) { static_assert(std::is_base_of::value, "AT should be an Attr"); static_assert(std::is_base_of::value, "DT should be a Decl"); -Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc"); +Decl *FromTU = getTuDecl(Code, Lang, "input.cc"); DT *FromD = FirstDeclMatcher().match(FromTU, namedDecl(hasName("test"))); ASSERT_TRUE(FromD); @@ -7652,6 +7654,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) { checkImportVariadicArg(FromAttr->args(), ToAttr->args()); } +TEST_P(ImportAttributes, ImportC99NoThrowAttr) { + NoThrowAttr *FromAttr, *ToAttr; + importAttr("void test () __attribute__ ((__nothrow__));", + FromAttr, ToAttr, Lang_C99); + checkImported(FromAttr->getAttrName(), ToAttr->getAttrName()); +} + template auto ExtendWithOptions(const T &Values, const std::vector &Args) { auto Copy = Values; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/73290 >From 150993c21943203d3fd116c3a0456eaea81008de Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 24 Nov 2023 13:55:45 +0800 Subject: [PATCH] [clang][ASTImporter] IdentifierInfo of Attribute should be set using ToASTContext --- clang/lib/AST/ASTImporter.cpp | 7 +-- clang/unittests/AST/ASTImporterTest.cpp | 13 +++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index c4e931e220f69b5..19e3e94c70c82d5 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -9241,9 +9241,12 @@ Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) { return Error::success(); for (const Attr *FromAttr : FromD->getAttrs()) { auto ToAttrOrErr = Import(FromAttr); -if (ToAttrOrErr) +if (ToAttrOrErr) { + if (auto *FromAttrNameII = FromAttr->getAttrName()) +(*ToAttrOrErr) +->setAttrName(&ToContext.Idents.get(FromAttrNameII->getName())); ToD->addAttr(*ToAttrOrErr); -else +} else return ToAttrOrErr.takeError(); } return Error::success(); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 5f4d8d040772cb1..2df92ad9d5985a4 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -12,6 +12,7 @@ #include "clang/AST/RecordLayout.h" #include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Testing/CommandLineArgs.h" #include "llvm/Support/SmallVectorMemoryBuffer.h" #include "clang/AST/DeclContextInternals.h" @@ -7362,11 +7363,12 @@ struct ImportAttributes : public ASTImporterOptionSpecificTestBase { } template - void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr) { + void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr, + TestLanguage Lang = Lang_CXX11) { static_assert(std::is_base_of::value, "AT should be an Attr"); static_assert(std::is_base_of::value, "DT should be a Decl"); -Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc"); +Decl *FromTU = getTuDecl(Code, Lang, "input.cc"); DT *FromD = FirstDeclMatcher().match(FromTU, namedDecl(hasName("test"))); ASSERT_TRUE(FromD); @@ -7652,6 +7654,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) { checkImportVariadicArg(FromAttr->args(), ToAttr->args()); } +TEST_P(ImportAttributes, ImportC99NoThrowAttr) { + NoThrowAttr *FromAttr, *ToAttr; + importAttr("void test () __attribute__ ((__nothrow__));", + FromAttr, ToAttr, Lang_C99); + checkImported(FromAttr->getAttrName(), ToAttr->getAttrName()); +} + template auto ExtendWithOptions(const T &Values, const std::vector &Args) { auto Copy = Values; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/73290 >From 52b972fd84877793fa8099cfb0b5d934c39e5925 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 24 Nov 2023 13:55:45 +0800 Subject: [PATCH] [clang][ASTImporter] IdentifierInfo of Attribute should be set using ToASTContext --- clang/include/clang/Basic/AttributeCommonInfo.h | 1 + clang/lib/AST/ASTImporter.cpp | 7 +-- clang/unittests/AST/ASTImporterTest.cpp | 13 +++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h b/clang/include/clang/Basic/AttributeCommonInfo.h index 3140d1a838afcec..f84f51b1cd25022 100644 --- a/clang/include/clang/Basic/AttributeCommonInfo.h +++ b/clang/include/clang/Basic/AttributeCommonInfo.h @@ -177,6 +177,7 @@ class AttributeCommonInfo { IsRegularKeywordAttribute); } const IdentifierInfo *getAttrName() const { return AttrName; } + void setAttrName(const IdentifierInfo *A) { AttrName = A; } SourceLocation getLoc() const { return AttrRange.getBegin(); } SourceRange getRange() const { return AttrRange; } void setRange(SourceRange R) { AttrRange = R; } diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index c4e931e220f69b5..19e3e94c70c82d5 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -9241,9 +9241,12 @@ Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) { return Error::success(); for (const Attr *FromAttr : FromD->getAttrs()) { auto ToAttrOrErr = Import(FromAttr); -if (ToAttrOrErr) +if (ToAttrOrErr) { + if (auto *FromAttrNameII = FromAttr->getAttrName()) +(*ToAttrOrErr) +->setAttrName(&ToContext.Idents.get(FromAttrNameII->getName())); ToD->addAttr(*ToAttrOrErr); -else +} else return ToAttrOrErr.takeError(); } return Error::success(); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 5f4d8d040772cb1..2df92ad9d5985a4 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -12,6 +12,7 @@ #include "clang/AST/RecordLayout.h" #include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Testing/CommandLineArgs.h" #include "llvm/Support/SmallVectorMemoryBuffer.h" #include "clang/AST/DeclContextInternals.h" @@ -7362,11 +7363,12 @@ struct ImportAttributes : public ASTImporterOptionSpecificTestBase { } template - void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr) { + void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr, + TestLanguage Lang = Lang_CXX11) { static_assert(std::is_base_of::value, "AT should be an Attr"); static_assert(std::is_base_of::value, "DT should be a Decl"); -Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc"); +Decl *FromTU = getTuDecl(Code, Lang, "input.cc"); DT *FromD = FirstDeclMatcher().match(FromTU, namedDecl(hasName("test"))); ASSERT_TRUE(FromD); @@ -7652,6 +7654,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) { checkImportVariadicArg(FromAttr->args(), ToAttr->args()); } +TEST_P(ImportAttributes, ImportC99NoThrowAttr) { + NoThrowAttr *FromAttr, *ToAttr; + importAttr("void test () __attribute__ ((__nothrow__));", + FromAttr, ToAttr, Lang_C99); + checkImported(FromAttr->getAttrName(), ToAttr->getAttrName()); +} + template auto ExtendWithOptions(const T &Values, const std::vector &Args) { auto Copy = Values; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/73290 >From a29523ed19ccb36554ea7ad2597631da26d8baaa Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 24 Nov 2023 13:55:45 +0800 Subject: [PATCH] [clang][ASTImporter] IdentifierInfo of Attribute should be set using ToASTContext --- clang/include/clang/Basic/AttributeCommonInfo.h | 1 + clang/lib/AST/ASTImporter.cpp | 7 +-- clang/unittests/AST/ASTImporterTest.cpp | 13 +++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h b/clang/include/clang/Basic/AttributeCommonInfo.h index 3140d1a838afcec..018b92fdc11f559 100644 --- a/clang/include/clang/Basic/AttributeCommonInfo.h +++ b/clang/include/clang/Basic/AttributeCommonInfo.h @@ -177,6 +177,7 @@ class AttributeCommonInfo { IsRegularKeywordAttribute); } const IdentifierInfo *getAttrName() const { return AttrName; } + void setAttrName(const IdentifierInfo *AttrNameII) { AttrName = AttrNameII; } SourceLocation getLoc() const { return AttrRange.getBegin(); } SourceRange getRange() const { return AttrRange; } void setRange(SourceRange R) { AttrRange = R; } diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index c4e931e220f69b5..19e3e94c70c82d5 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -9241,9 +9241,12 @@ Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) { return Error::success(); for (const Attr *FromAttr : FromD->getAttrs()) { auto ToAttrOrErr = Import(FromAttr); -if (ToAttrOrErr) +if (ToAttrOrErr) { + if (auto *FromAttrNameII = FromAttr->getAttrName()) +(*ToAttrOrErr) +->setAttrName(&ToContext.Idents.get(FromAttrNameII->getName())); ToD->addAttr(*ToAttrOrErr); -else +} else return ToAttrOrErr.takeError(); } return Error::success(); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 5f4d8d040772cb1..2df92ad9d5985a4 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -12,6 +12,7 @@ #include "clang/AST/RecordLayout.h" #include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Testing/CommandLineArgs.h" #include "llvm/Support/SmallVectorMemoryBuffer.h" #include "clang/AST/DeclContextInternals.h" @@ -7362,11 +7363,12 @@ struct ImportAttributes : public ASTImporterOptionSpecificTestBase { } template - void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr) { + void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr, + TestLanguage Lang = Lang_CXX11) { static_assert(std::is_base_of::value, "AT should be an Attr"); static_assert(std::is_base_of::value, "DT should be a Decl"); -Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc"); +Decl *FromTU = getTuDecl(Code, Lang, "input.cc"); DT *FromD = FirstDeclMatcher().match(FromTU, namedDecl(hasName("test"))); ASSERT_TRUE(FromD); @@ -7652,6 +7654,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) { checkImportVariadicArg(FromAttr->args(), ToAttr->args()); } +TEST_P(ImportAttributes, ImportC99NoThrowAttr) { + NoThrowAttr *FromAttr, *ToAttr; + importAttr("void test () __attribute__ ((__nothrow__));", + FromAttr, ToAttr, Lang_C99); + checkImported(FromAttr->getAttrName(), ToAttr->getAttrName()); +} + template auto ExtendWithOptions(const T &Values, const std::vector &Args) { auto Copy = Values; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/73290 >From 20aab6095691f3de5568bc61c83427f380e28350 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 24 Nov 2023 13:55:45 +0800 Subject: [PATCH] [clang][ASTImporter] IdentifierInfo of Attribute should be set using ToASTContext --- clang/include/clang/Basic/AttributeCommonInfo.h | 1 + clang/lib/AST/ASTImporter.cpp | 1 + clang/unittests/AST/ASTImporterTest.cpp | 13 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h b/clang/include/clang/Basic/AttributeCommonInfo.h index 3140d1a838afcec..018b92fdc11f559 100644 --- a/clang/include/clang/Basic/AttributeCommonInfo.h +++ b/clang/include/clang/Basic/AttributeCommonInfo.h @@ -177,6 +177,7 @@ class AttributeCommonInfo { IsRegularKeywordAttribute); } const IdentifierInfo *getAttrName() const { return AttrName; } + void setAttrName(const IdentifierInfo *AttrNameII) { AttrName = AttrNameII; } SourceLocation getLoc() const { return AttrRange.getBegin(); } SourceRange getRange() const { return AttrRange; } void setRange(SourceRange R) { AttrRange = R; } diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index c4e931e220f69b5..4bc18d7b54dbc5a 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -9063,6 +9063,7 @@ class AttrImporter { ToAttr = FromAttr->clone(Importer.getToContext()); ToAttr->setRange(ToRange); +ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName())); } // Get the result of the previous import attempt (can be used only once). diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 5f4d8d040772cb1..2df92ad9d5985a4 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -12,6 +12,7 @@ #include "clang/AST/RecordLayout.h" #include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Testing/CommandLineArgs.h" #include "llvm/Support/SmallVectorMemoryBuffer.h" #include "clang/AST/DeclContextInternals.h" @@ -7362,11 +7363,12 @@ struct ImportAttributes : public ASTImporterOptionSpecificTestBase { } template - void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr) { + void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr, + TestLanguage Lang = Lang_CXX11) { static_assert(std::is_base_of::value, "AT should be an Attr"); static_assert(std::is_base_of::value, "DT should be a Decl"); -Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc"); +Decl *FromTU = getTuDecl(Code, Lang, "input.cc"); DT *FromD = FirstDeclMatcher().match(FromTU, namedDecl(hasName("test"))); ASSERT_TRUE(FromD); @@ -7652,6 +7654,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) { checkImportVariadicArg(FromAttr->args(), ToAttr->args()); } +TEST_P(ImportAttributes, ImportC99NoThrowAttr) { + NoThrowAttr *FromAttr, *ToAttr; + importAttr("void test () __attribute__ ((__nothrow__));", + FromAttr, ToAttr, Lang_C99); + checkImported(FromAttr->getAttrName(), ToAttr->getAttrName()); +} + template auto ExtendWithOptions(const T &Values, const std::vector &Args) { auto Copy = Values; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)
jcsxky wrote: > I think it is better to add the import of AttrName to the attribute import > code (function `Import(const Attr *FromAttr)` and what is called from it). > Probably it works to add it to `AttrImporter::cloneAttr` and do it like > `const IdentifierInfo *ToAttrName = > Importer.Import(FromAttr->getAttrName());`. Fixed according to your guidance. https://github.com/llvm/llvm-project/pull/73290 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)
https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/73290 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] add processing of SubstNonTypeTemplateParmExpr in isAncestorDeclContextOf (PR #74991)
https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/74991 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/76226 Types comparison in `StructuralEquivalence` ignores its `DeclContext` when they are generated by template specialization implicitly and this will produce incorrect result. Add comparison of `DeclContext` of ClassTemplateSpecializationDecl to improve result. >From 8d57b196a90fe8454d815617924b6b363aa4cb87 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 22 Dec 2023 17:56:32 +0800 Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType --- clang/lib/AST/ASTStructuralEquivalence.cpp| 15 ++--- .../AST/StructuralEquivalenceTest.cpp | 22 +++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 6bb4bf14b873d7..7c04c09bb80874 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -1107,11 +1107,20 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, } case Type::Record: - case Type::Enum: -if (!IsStructurallyEquivalent(Context, cast(T1)->getDecl(), - cast(T2)->getDecl())) + case Type::Enum: { +auto *D1 = cast(T1)->getDecl(); +auto *D2 = cast(T2)->getDecl(); +if (!IsStructurallyEquivalent(Context, D1, D2)) + return false; +auto *D1Spec = + dyn_cast_or_null(D1->getDeclContext()); +auto *D2Spec = + dyn_cast_or_null(D2->getDeclContext()); +if (nullptr != D1Spec && nullptr != D2Spec && +!IsStructurallyEquivalent(Context, D1Spec, D2Spec)) return false; break; + } case Type::TemplateTypeParm: { const auto *Parm1 = cast(T1); diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 44d950cfe758f1..b54d149152e105 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -1024,6 +1024,28 @@ TEST_F(StructuralEquivalenceRecordContextTest, TransparentContextInNamespace) { EXPECT_TRUE(testStructuralMatch(Decls)); } +TEST_F(StructuralEquivalenceRecordContextTest, RecordWithinTemplateClass) { + std::string Code = + R"( + template struct O { +struct M {}; + }; + )"; + auto t = makeDecls(Code + R"( + typedef O::M MT1; + MT1 A; + )", + Code + R"( + namespace { +struct I {}; + } // namespace + typedef O::M MT2; + MT2 A; + )", + Lang_CXX11, varDecl(hasName("A"))); + EXPECT_FALSE(testStructuralMatch(t)); +} + TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) { auto Decls = makeNamedDecls( R"( ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)
https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/76226 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/76226 >From 08a2bb64e19fe244361cb58a1e8eed64a2c1f0cd Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 22 Dec 2023 17:56:32 +0800 Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType --- clang/lib/AST/ASTStructuralEquivalence.cpp| 15 ++--- .../AST/StructuralEquivalenceTest.cpp | 22 +++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 6bb4bf14b873d7..7c04c09bb80874 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -1107,11 +1107,20 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, } case Type::Record: - case Type::Enum: -if (!IsStructurallyEquivalent(Context, cast(T1)->getDecl(), - cast(T2)->getDecl())) + case Type::Enum: { +auto *D1 = cast(T1)->getDecl(); +auto *D2 = cast(T2)->getDecl(); +if (!IsStructurallyEquivalent(Context, D1, D2)) + return false; +auto *D1Spec = + dyn_cast_or_null(D1->getDeclContext()); +auto *D2Spec = + dyn_cast_or_null(D2->getDeclContext()); +if (nullptr != D1Spec && nullptr != D2Spec && +!IsStructurallyEquivalent(Context, D1Spec, D2Spec)) return false; break; + } case Type::TemplateTypeParm: { const auto *Parm1 = cast(T1); diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 44d950cfe758f1..b54d149152e105 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -1024,6 +1024,28 @@ TEST_F(StructuralEquivalenceRecordContextTest, TransparentContextInNamespace) { EXPECT_TRUE(testStructuralMatch(Decls)); } +TEST_F(StructuralEquivalenceRecordContextTest, RecordWithinTemplateClass) { + std::string Code = + R"( + template struct O { +struct M {}; + }; + )"; + auto t = makeDecls(Code + R"( + typedef O::M MT1; + MT1 A; + )", + Code + R"( + namespace { +struct I {}; + } // namespace + typedef O::M MT2; + MT2 A; + )", + Lang_CXX11, varDecl(hasName("A"))); + EXPECT_FALSE(testStructuralMatch(t)); +} + TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) { auto Decls = makeNamedDecls( R"( ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/76226 >From 9a8cea81eba77eef914089e3cffd96e863aac36f Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 22 Dec 2023 17:56:32 +0800 Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType --- clang/lib/AST/ASTStructuralEquivalence.cpp| 15 ++--- .../AST/StructuralEquivalenceTest.cpp | 22 +++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 6bb4bf14b873d7..7c04c09bb80874 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -1107,11 +1107,20 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, } case Type::Record: - case Type::Enum: -if (!IsStructurallyEquivalent(Context, cast(T1)->getDecl(), - cast(T2)->getDecl())) + case Type::Enum: { +auto *D1 = cast(T1)->getDecl(); +auto *D2 = cast(T2)->getDecl(); +if (!IsStructurallyEquivalent(Context, D1, D2)) + return false; +auto *D1Spec = + dyn_cast_or_null(D1->getDeclContext()); +auto *D2Spec = + dyn_cast_or_null(D2->getDeclContext()); +if (nullptr != D1Spec && nullptr != D2Spec && +!IsStructurallyEquivalent(Context, D1Spec, D2Spec)) return false; break; + } case Type::TemplateTypeParm: { const auto *Parm1 = cast(T1); diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 44d950cfe758f1..b54d149152e105 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -1024,6 +1024,28 @@ TEST_F(StructuralEquivalenceRecordContextTest, TransparentContextInNamespace) { EXPECT_TRUE(testStructuralMatch(Decls)); } +TEST_F(StructuralEquivalenceRecordContextTest, RecordWithinTemplateClass) { + std::string Code = + R"( + template struct O { +struct M {}; + }; + )"; + auto t = makeDecls(Code + R"( + typedef O::M MT1; + MT1 A; + )", + Code + R"( + namespace { +struct I {}; + } // namespace + typedef O::M MT2; + MT2 A; + )", + Lang_CXX11, varDecl(hasName("A"))); + EXPECT_FALSE(testStructuralMatch(t)); +} + TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) { auto Decls = makeNamedDecls( R"( ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/76226 >From be62fb62934052db668eea57a9ff241fcd06cd2c Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 22 Dec 2023 17:56:32 +0800 Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType --- clang/lib/AST/ASTStructuralEquivalence.cpp| 15 ++--- .../AST/StructuralEquivalenceTest.cpp | 22 +++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 6bb4bf14b873d7..7c04c09bb80874 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -1107,11 +1107,20 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, } case Type::Record: - case Type::Enum: -if (!IsStructurallyEquivalent(Context, cast(T1)->getDecl(), - cast(T2)->getDecl())) + case Type::Enum: { +auto *D1 = cast(T1)->getDecl(); +auto *D2 = cast(T2)->getDecl(); +if (!IsStructurallyEquivalent(Context, D1, D2)) + return false; +auto *D1Spec = + dyn_cast_or_null(D1->getDeclContext()); +auto *D2Spec = + dyn_cast_or_null(D2->getDeclContext()); +if (nullptr != D1Spec && nullptr != D2Spec && +!IsStructurallyEquivalent(Context, D1Spec, D2Spec)) return false; break; + } case Type::TemplateTypeParm: { const auto *Parm1 = cast(T1); diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 44d950cfe758f1..b54d149152e105 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -1024,6 +1024,28 @@ TEST_F(StructuralEquivalenceRecordContextTest, TransparentContextInNamespace) { EXPECT_TRUE(testStructuralMatch(Decls)); } +TEST_F(StructuralEquivalenceRecordContextTest, RecordWithinTemplateClass) { + std::string Code = + R"( + template struct O { +struct M {}; + }; + )"; + auto t = makeDecls(Code + R"( + typedef O::M MT1; + MT1 A; + )", + Code + R"( + namespace { +struct I {}; + } // namespace + typedef O::M MT2; + MT2 A; + )", + Lang_CXX11, varDecl(hasName("A"))); + EXPECT_FALSE(testStructuralMatch(t)); +} + TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) { auto Decls = makeNamedDecls( R"( ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/76226 >From 574fa37117614fc4e23c12a7ecd297304d5eb337 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 22 Dec 2023 17:56:32 +0800 Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType --- clang/lib/AST/ASTStructuralEquivalence.cpp| 15 ++--- .../AST/StructuralEquivalenceTest.cpp | 22 +++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 6bb4bf14b873d7..7c04c09bb80874 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -1107,11 +1107,20 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, } case Type::Record: - case Type::Enum: -if (!IsStructurallyEquivalent(Context, cast(T1)->getDecl(), - cast(T2)->getDecl())) + case Type::Enum: { +auto *D1 = cast(T1)->getDecl(); +auto *D2 = cast(T2)->getDecl(); +if (!IsStructurallyEquivalent(Context, D1, D2)) + return false; +auto *D1Spec = + dyn_cast_or_null(D1->getDeclContext()); +auto *D2Spec = + dyn_cast_or_null(D2->getDeclContext()); +if (nullptr != D1Spec && nullptr != D2Spec && +!IsStructurallyEquivalent(Context, D1Spec, D2Spec)) return false; break; + } case Type::TemplateTypeParm: { const auto *Parm1 = cast(T1); diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 44d950cfe758f1..b54d149152e105 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -1024,6 +1024,28 @@ TEST_F(StructuralEquivalenceRecordContextTest, TransparentContextInNamespace) { EXPECT_TRUE(testStructuralMatch(Decls)); } +TEST_F(StructuralEquivalenceRecordContextTest, RecordWithinTemplateClass) { + std::string Code = + R"( + template struct O { +struct M {}; + }; + )"; + auto t = makeDecls(Code + R"( + typedef O::M MT1; + MT1 A; + )", + Code + R"( + namespace { +struct I {}; + } // namespace + typedef O::M MT2; + MT2 A; + )", + Lang_CXX11, varDecl(hasName("A"))); + EXPECT_FALSE(testStructuralMatch(t)); +} + TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) { auto Decls = makeNamedDecls( R"( ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/76226 >From 27005dba5f7530143657c514250a362670e3d67d Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 22 Dec 2023 17:56:32 +0800 Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType --- clang/lib/AST/ASTStructuralEquivalence.cpp| 13 --- .../AST/StructuralEquivalenceTest.cpp | 22 +++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 6bb4bf14b873d7..277532696305e3 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -1463,8 +1463,9 @@ IsStructurallyEquivalentLambdas(StructuralEquivalenceContext &Context, } /// Determine if context of a class is equivalent. -static bool IsRecordContextStructurallyEquivalent(RecordDecl *D1, - RecordDecl *D2) { +static bool +IsRecordContextStructurallyEquivalent(StructuralEquivalenceContext &Context, + RecordDecl *D1, RecordDecl *D2) { // The context should be completely equal, including anonymous and inline // namespaces. // We compare objects as part of full translation units, not subtrees of @@ -1491,6 +1492,12 @@ static bool IsRecordContextStructurallyEquivalent(RecordDecl *D1, return false; } +if (auto *D1Spec = dyn_cast(DC1)) { + auto *D2Spec = dyn_cast(DC2); + if (!IsStructurallyEquivalent(Context, D1Spec, D2Spec)) +return false; +} + DC1 = DC1->getParent()->getNonTransparentContext(); DC2 = DC2->getParent()->getNonTransparentContext(); } @@ -1544,7 +1551,7 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, // If the records occur in different context (namespace), these should be // different. This is specially important if the definition of one or both // records is missing. - if (!IsRecordContextStructurallyEquivalent(D1, D2)) + if (!IsRecordContextStructurallyEquivalent(Context, D1, D2)) return false; // If both declarations are class template specializations, we know diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 44d950cfe758f1..b54d149152e105 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -1024,6 +1024,28 @@ TEST_F(StructuralEquivalenceRecordContextTest, TransparentContextInNamespace) { EXPECT_TRUE(testStructuralMatch(Decls)); } +TEST_F(StructuralEquivalenceRecordContextTest, RecordWithinTemplateClass) { + std::string Code = + R"( + template struct O { +struct M {}; + }; + )"; + auto t = makeDecls(Code + R"( + typedef O::M MT1; + MT1 A; + )", + Code + R"( + namespace { +struct I {}; + } // namespace + typedef O::M MT2; + MT2 A; + )", + Lang_CXX11, varDecl(hasName("A"))); + EXPECT_FALSE(testStructuralMatch(t)); +} + TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) { auto Decls = makeNamedDecls( R"( ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/76226 >From 77976022454865df8bee1e4a09682a16658ed035 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 22 Dec 2023 17:56:32 +0800 Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType --- clang/lib/AST/ASTStructuralEquivalence.cpp| 13 --- .../AST/StructuralEquivalenceTest.cpp | 23 +++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 6bb4bf14b873d7..277532696305e3 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -1463,8 +1463,9 @@ IsStructurallyEquivalentLambdas(StructuralEquivalenceContext &Context, } /// Determine if context of a class is equivalent. -static bool IsRecordContextStructurallyEquivalent(RecordDecl *D1, - RecordDecl *D2) { +static bool +IsRecordContextStructurallyEquivalent(StructuralEquivalenceContext &Context, + RecordDecl *D1, RecordDecl *D2) { // The context should be completely equal, including anonymous and inline // namespaces. // We compare objects as part of full translation units, not subtrees of @@ -1491,6 +1492,12 @@ static bool IsRecordContextStructurallyEquivalent(RecordDecl *D1, return false; } +if (auto *D1Spec = dyn_cast(DC1)) { + auto *D2Spec = dyn_cast(DC2); + if (!IsStructurallyEquivalent(Context, D1Spec, D2Spec)) +return false; +} + DC1 = DC1->getParent()->getNonTransparentContext(); DC2 = DC2->getParent()->getNonTransparentContext(); } @@ -1544,7 +1551,7 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, // If the records occur in different context (namespace), these should be // different. This is specially important if the definition of one or both // records is missing. - if (!IsRecordContextStructurallyEquivalent(D1, D2)) + if (!IsRecordContextStructurallyEquivalent(Context, D1, D2)) return false; // If both declarations are class template specializations, we know diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 44d950cfe758f1..22c7b82460f0a0 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -1024,6 +1024,29 @@ TEST_F(StructuralEquivalenceRecordContextTest, TransparentContextInNamespace) { EXPECT_TRUE(testStructuralMatch(Decls)); } +TEST_F(StructuralEquivalenceRecordContextTest, + ClassTemplateSpecializationContext) { + std::string Code = + R"( + template struct O { +struct M {}; + }; + )"; + auto t = makeDecls(Code + R"( + typedef O::M MT1; + MT1 A; + )", + Code + R"( + namespace { +struct I {}; + } // namespace + typedef O::M MT2; + MT2 A; + )", + Lang_CXX11, varDecl(hasName("A"))); + EXPECT_FALSE(testStructuralMatch(t)); +} + TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) { auto Decls = makeNamedDecls( R"( ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl (PR #74919)
https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/74919 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (PR #76493)
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/76493 import of `ClassTemplateSpecializationDecl` didn't set `InstantiatedFromMember` and this makes ast-dump crash. import and set `InstantiatedFromMember`. fix [issue](https://github.com/llvm/llvm-project/issues/76469) >From fa5ec63aa713a4a902e535cb89f836a7757c2ba9 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Thu, 28 Dec 2023 15:51:32 +0800 Subject: [PATCH] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl --- clang/lib/AST/ASTImporter.cpp | 5 clang/unittests/AST/ASTImporterTest.cpp | 32 + 2 files changed, 37 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index b61180c4f3491d..9ffae72346f2af 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -6141,6 +6141,11 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( InsertPos)) // Add this partial specialization to the class template. ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos); +if (Expected ToInstOrErr = +import(PartialSpec->getInstantiatedFromMember())) + PartSpec2->setInstantiatedFromMember(*ToInstOrErr); +else + return ToInstOrErr.takeError(); updateLookupTableForTemplateParameters(*ToTPList); } else { // Not a partial specialization. diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index ed8ecb080e268d..1221174326b90f 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9342,6 +9342,38 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportConflictTypeAliasTemplate) { EXPECT_FALSE(ImportedCallable); } +AST_MATCHER(ClassTemplateSpecializationDecl, hasInstantiatedFromMember) { + if (auto Instantiate = Node.getInstantiatedFrom()) { +if (auto *FromPartialSpecialization = +Instantiate.get()) { + return nullptr != FromPartialSpecialization->getInstantiatedFromMember(); +} + } + return false; +} + +TEST_P(ASTImporterOptionSpecificTestBase, ImportInstantiatedFromMember) { + const char *Code = + R"( + template struct B { +template union D; +template union D {}; +D d; + }; + B b; + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + auto *FromA = FirstDeclMatcher().match( + FromTU, classTemplateSpecializationDecl(hasName("D"), + hasInstantiatedFromMember())); + auto *FromPartialSpecialization = + cast( + FromA->getInstantiatedFrom()); + auto *ImportedPartialSpecialization = + Import(FromPartialSpecialization, Lang_CXX17); + EXPECT_TRUE(ImportedPartialSpecialization->getInstantiatedFromMember()); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (PR #76493)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/76493 >From 057f9324bb83141ea07c69beb3afe5158fb3f194 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Thu, 28 Dec 2023 15:51:32 +0800 Subject: [PATCH] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl --- clang/lib/AST/ASTImporter.cpp | 5 clang/unittests/AST/ASTImporterTest.cpp | 32 + 2 files changed, 37 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index b61180c4f3491d..9ffae72346f2af 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -6141,6 +6141,11 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( InsertPos)) // Add this partial specialization to the class template. ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos); +if (Expected ToInstOrErr = +import(PartialSpec->getInstantiatedFromMember())) + PartSpec2->setInstantiatedFromMember(*ToInstOrErr); +else + return ToInstOrErr.takeError(); updateLookupTableForTemplateParameters(*ToTPList); } else { // Not a partial specialization. diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index ed8ecb080e268d..1221174326b90f 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9342,6 +9342,38 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportConflictTypeAliasTemplate) { EXPECT_FALSE(ImportedCallable); } +AST_MATCHER(ClassTemplateSpecializationDecl, hasInstantiatedFromMember) { + if (auto Instantiate = Node.getInstantiatedFrom()) { +if (auto *FromPartialSpecialization = +Instantiate.get()) { + return nullptr != FromPartialSpecialization->getInstantiatedFromMember(); +} + } + return false; +} + +TEST_P(ASTImporterOptionSpecificTestBase, ImportInstantiatedFromMember) { + const char *Code = + R"( + template struct B { +template union D; +template union D {}; +D d; + }; + B b; + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + auto *FromA = FirstDeclMatcher().match( + FromTU, classTemplateSpecializationDecl(hasName("D"), + hasInstantiatedFromMember())); + auto *FromPartialSpecialization = + cast( + FromA->getInstantiatedFrom()); + auto *ImportedPartialSpecialization = + Import(FromPartialSpecialization, Lang_CXX17); + EXPECT_TRUE(ImportedPartialSpecialization->getInstantiatedFromMember()); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (PR #76493)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/76493 >From 9a9a203bbea079a033a14e610a3c00dff5ec408a Mon Sep 17 00:00:00 2001 From: huqizhi Date: Thu, 28 Dec 2023 15:51:32 +0800 Subject: [PATCH] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl --- clang/lib/AST/ASTImporter.cpp | 5 clang/unittests/AST/ASTImporterTest.cpp | 32 + 2 files changed, 37 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index b61180c4f3491d..9ffae72346f2af 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -6141,6 +6141,11 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( InsertPos)) // Add this partial specialization to the class template. ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos); +if (Expected ToInstOrErr = +import(PartialSpec->getInstantiatedFromMember())) + PartSpec2->setInstantiatedFromMember(*ToInstOrErr); +else + return ToInstOrErr.takeError(); updateLookupTableForTemplateParameters(*ToTPList); } else { // Not a partial specialization. diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index ed8ecb080e268d..3c228d0e5ecd5f 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9342,6 +9342,38 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportConflictTypeAliasTemplate) { EXPECT_FALSE(ImportedCallable); } +AST_MATCHER(ClassTemplateSpecializationDecl, hasInstantiatedFromMember) { + if (auto Instantiate = Node.getInstantiatedFrom()) { +if (auto *FromPartialSpecialization = +Instantiate.get()) { + return nullptr != FromPartialSpecialization->getInstantiatedFromMember(); +} + } + return false; +} + +TEST_P(ASTImporterOptionSpecificTestBase, ImportInstantiatedFromMember) { + const char *Code = + R"( + template struct B { +template union D; +template union D {}; +D d; + }; + B b; + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + auto *FromA = FirstDeclMatcher().match( + FromTU, classTemplateSpecializationDecl(hasName("D"), + hasInstantiatedFromMember())); + auto *FromPartialSpecialization = + cast( + FromA->getInstantiatedFrom()); + auto *ImportedPartialSpecialization = + Import(FromPartialSpecialization, Lang_CXX11); + EXPECT_TRUE(ImportedPartialSpecialization->getInstantiatedFromMember()); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (PR #76493)
@@ -9342,6 +9342,38 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportConflictTypeAliasTemplate) { EXPECT_FALSE(ImportedCallable); } +AST_MATCHER(ClassTemplateSpecializationDecl, hasInstantiatedFromMember) { + if (auto Instantiate = Node.getInstantiatedFrom()) { +if (auto *FromPartialSpecialization = +Instantiate.get()) { + return nullptr != FromPartialSpecialization->getInstantiatedFromMember(); +} + } + return false; +} + +TEST_P(ASTImporterOptionSpecificTestBase, ImportInstantiatedFromMember) { + const char *Code = + R"( + template struct B { +template union D; +template union D {}; +D d; + }; + B b; + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX17); jcsxky wrote: fixed, use C++11 instead. https://github.com/llvm/llvm-project/pull/76493 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (PR #76493)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/76493 >From a891331098d34724495798650e4a6e7ad9ebefcb Mon Sep 17 00:00:00 2001 From: huqizhi Date: Thu, 28 Dec 2023 15:51:32 +0800 Subject: [PATCH] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl --- clang/lib/AST/ASTImporter.cpp | 5 clang/unittests/AST/ASTImporterTest.cpp | 32 + 2 files changed, 37 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index b61180c4f3491d..9ffae72346f2af 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -6141,6 +6141,11 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( InsertPos)) // Add this partial specialization to the class template. ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos); +if (Expected ToInstOrErr = +import(PartialSpec->getInstantiatedFromMember())) + PartSpec2->setInstantiatedFromMember(*ToInstOrErr); +else + return ToInstOrErr.takeError(); updateLookupTableForTemplateParameters(*ToTPList); } else { // Not a partial specialization. diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index ed8ecb080e268d..b4a853952f00a3 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9342,6 +9342,38 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportConflictTypeAliasTemplate) { EXPECT_FALSE(ImportedCallable); } +AST_MATCHER(ClassTemplateSpecializationDecl, hasInstantiatedFromMember) { + if (auto Instantiate = Node.getInstantiatedFrom()) { +if (auto *FromPartialSpecialization = +Instantiate.get()) { + return nullptr != FromPartialSpecialization->getInstantiatedFromMember(); +} + } + return false; +} + +TEST_P(ASTImporterOptionSpecificTestBase, ImportInstantiatedFromMember) { + const char *Code = + R"( + template struct B { +template union D; +template union D {}; +D d; + }; + B b; + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX11); + auto *FromA = FirstDeclMatcher().match( + FromTU, classTemplateSpecializationDecl(hasName("D"), + hasInstantiatedFromMember())); + auto *FromPartialSpecialization = + cast( + FromA->getInstantiatedFrom()); + auto *ImportedPartialSpecialization = + Import(FromPartialSpecialization, Lang_CXX11); + EXPECT_TRUE(ImportedPartialSpecialization->getInstantiatedFromMember()); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/76226 >From ab1ace9573588153f1e8caf992a6abda3322c6a7 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 22 Dec 2023 17:56:32 +0800 Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType --- clang/lib/AST/ASTStructuralEquivalence.cpp| 13 --- .../AST/StructuralEquivalenceTest.cpp | 23 +++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 6bb4bf14b873d7..73b3b2a9524a7b 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -1463,8 +1463,9 @@ IsStructurallyEquivalentLambdas(StructuralEquivalenceContext &Context, } /// Determine if context of a class is equivalent. -static bool IsRecordContextStructurallyEquivalent(RecordDecl *D1, - RecordDecl *D2) { +static bool +IsRecordContextStructurallyEquivalent(StructuralEquivalenceContext &Context, + RecordDecl *D1, RecordDecl *D2) { // The context should be completely equal, including anonymous and inline // namespaces. // We compare objects as part of full translation units, not subtrees of @@ -1491,6 +1492,12 @@ static bool IsRecordContextStructurallyEquivalent(RecordDecl *D1, return false; } +auto *D1Spec = dyn_cast(DC1); +auto *D2Spec = dyn_cast(DC2); +if (nullptr != D1Spec && nullptr != D2Spec && +!IsStructurallyEquivalent(Context, D1Spec, D2Spec)) + return false; + DC1 = DC1->getParent()->getNonTransparentContext(); DC2 = DC2->getParent()->getNonTransparentContext(); } @@ -1544,7 +1551,7 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, // If the records occur in different context (namespace), these should be // different. This is specially important if the definition of one or both // records is missing. - if (!IsRecordContextStructurallyEquivalent(D1, D2)) + if (!IsRecordContextStructurallyEquivalent(Context, D1, D2)) return false; // If both declarations are class template specializations, we know diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 44d950cfe758f1..22c7b82460f0a0 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -1024,6 +1024,29 @@ TEST_F(StructuralEquivalenceRecordContextTest, TransparentContextInNamespace) { EXPECT_TRUE(testStructuralMatch(Decls)); } +TEST_F(StructuralEquivalenceRecordContextTest, + ClassTemplateSpecializationContext) { + std::string Code = + R"( + template struct O { +struct M {}; + }; + )"; + auto t = makeDecls(Code + R"( + typedef O::M MT1; + MT1 A; + )", + Code + R"( + namespace { +struct I {}; + } // namespace + typedef O::M MT2; + MT2 A; + )", + Lang_CXX11, varDecl(hasName("A"))); + EXPECT_FALSE(testStructuralMatch(t)); +} + TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) { auto Decls = makeNamedDecls( R"( ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)
@@ -1491,6 +1492,12 @@ static bool IsRecordContextStructurallyEquivalent(RecordDecl *D1, return false; } +if (auto *D1Spec = dyn_cast(DC1)) { + auto *D2Spec = dyn_cast(DC2); jcsxky wrote: Done. https://github.com/llvm/llvm-project/pull/76226 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/76226 >From 77976022454865df8bee1e4a09682a16658ed035 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 22 Dec 2023 17:56:32 +0800 Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType --- clang/lib/AST/ASTStructuralEquivalence.cpp| 13 --- .../AST/StructuralEquivalenceTest.cpp | 23 +++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 6bb4bf14b873d7..277532696305e3 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -1463,8 +1463,9 @@ IsStructurallyEquivalentLambdas(StructuralEquivalenceContext &Context, } /// Determine if context of a class is equivalent. -static bool IsRecordContextStructurallyEquivalent(RecordDecl *D1, - RecordDecl *D2) { +static bool +IsRecordContextStructurallyEquivalent(StructuralEquivalenceContext &Context, + RecordDecl *D1, RecordDecl *D2) { // The context should be completely equal, including anonymous and inline // namespaces. // We compare objects as part of full translation units, not subtrees of @@ -1491,6 +1492,12 @@ static bool IsRecordContextStructurallyEquivalent(RecordDecl *D1, return false; } +if (auto *D1Spec = dyn_cast(DC1)) { + auto *D2Spec = dyn_cast(DC2); + if (!IsStructurallyEquivalent(Context, D1Spec, D2Spec)) +return false; +} + DC1 = DC1->getParent()->getNonTransparentContext(); DC2 = DC2->getParent()->getNonTransparentContext(); } @@ -1544,7 +1551,7 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, // If the records occur in different context (namespace), these should be // different. This is specially important if the definition of one or both // records is missing. - if (!IsRecordContextStructurallyEquivalent(D1, D2)) + if (!IsRecordContextStructurallyEquivalent(Context, D1, D2)) return false; // If both declarations are class template specializations, we know diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 44d950cfe758f1..22c7b82460f0a0 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -1024,6 +1024,29 @@ TEST_F(StructuralEquivalenceRecordContextTest, TransparentContextInNamespace) { EXPECT_TRUE(testStructuralMatch(Decls)); } +TEST_F(StructuralEquivalenceRecordContextTest, + ClassTemplateSpecializationContext) { + std::string Code = + R"( + template struct O { +struct M {}; + }; + )"; + auto t = makeDecls(Code + R"( + typedef O::M MT1; + MT1 A; + )", + Code + R"( + namespace { +struct I {}; + } // namespace + typedef O::M MT2; + MT2 A; + )", + Lang_CXX11, varDecl(hasName("A"))); + EXPECT_FALSE(testStructuralMatch(t)); +} + TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) { auto Decls = makeNamedDecls( R"( ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)
@@ -1491,6 +1492,12 @@ static bool IsRecordContextStructurallyEquivalent(RecordDecl *D1, return false; } +if (auto *D1Spec = dyn_cast(DC1)) { + auto *D2Spec = dyn_cast(DC2); jcsxky wrote: revert https://github.com/llvm/llvm-project/pull/76226 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (PR #76493)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/76493 >From ef18bd2237ebb045033001076a14d2b7c1e926db Mon Sep 17 00:00:00 2001 From: huqizhi Date: Thu, 28 Dec 2023 15:51:32 +0800 Subject: [PATCH] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl --- clang/lib/AST/ASTImporter.cpp | 5 clang/unittests/AST/ASTImporterTest.cpp | 33 + 2 files changed, 38 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index b61180c4f3491d..9ffae72346f2af 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -6141,6 +6141,11 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( InsertPos)) // Add this partial specialization to the class template. ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos); +if (Expected ToInstOrErr = +import(PartialSpec->getInstantiatedFromMember())) + PartSpec2->setInstantiatedFromMember(*ToInstOrErr); +else + return ToInstOrErr.takeError(); updateLookupTableForTemplateParameters(*ToTPList); } else { // Not a partial specialization. diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index ed8ecb080e268d..e4bd0d646cc9db 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9342,6 +9342,39 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportConflictTypeAliasTemplate) { EXPECT_FALSE(ImportedCallable); } +AST_MATCHER(ClassTemplateSpecializationDecl, hasInstantiatedFromMember) { + if (auto Instantiate = Node.getInstantiatedFrom()) { +if (auto *FromPartialSpecialization = +Instantiate.get()) { + return nullptr != FromPartialSpecialization->getInstantiatedFromMember(); +} + } + return false; +} + +TEST_P(ASTImporterOptionSpecificTestBase, ImportInstantiatedFromMember) { + const char *Code = + R"( + template struct B { +template union D; +template union D {}; +D d; + }; + B b; + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX11); + auto *FromD = FirstDeclMatcher().match( + FromTU, classTemplateSpecializationDecl(hasName("D"), + hasInstantiatedFromMember())); + auto *FromPartialSpecialization = + cast( + FromD->getInstantiatedFrom()); + ASSERT_TRUE(FromPartialSpecialization->getInstantiatedFromMember()); + auto *ImportedPartialSpecialization = + Import(FromPartialSpecialization, Lang_CXX11); + EXPECT_TRUE(ImportedPartialSpecialization->getInstantiatedFromMember()); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (PR #76493)
@@ -9342,6 +9342,38 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportConflictTypeAliasTemplate) { EXPECT_FALSE(ImportedCallable); } +AST_MATCHER(ClassTemplateSpecializationDecl, hasInstantiatedFromMember) { + if (auto Instantiate = Node.getInstantiatedFrom()) { +if (auto *FromPartialSpecialization = +Instantiate.get()) { + return nullptr != FromPartialSpecialization->getInstantiatedFromMember(); +} + } + return false; +} + +TEST_P(ASTImporterOptionSpecificTestBase, ImportInstantiatedFromMember) { + const char *Code = + R"( + template struct B { +template union D; +template union D {}; +D d; + }; + B b; + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX11); + auto *FromA = FirstDeclMatcher().match( + FromTU, classTemplateSpecializationDecl(hasName("D"), + hasInstantiatedFromMember())); + auto *FromPartialSpecialization = + cast( + FromA->getInstantiatedFrom()); + auto *ImportedPartialSpecialization = jcsxky wrote: All has been fixed. https://github.com/llvm/llvm-project/pull/76493 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (PR #76493)
https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/76493 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/77056 Parameter variable which is forwarded in lambda capture list or in body by reference is reasonable and current version of this check produces false positive on these cases. This patch try to fix the [issue](https://github.com/llvm/llvm-project/issues/68105) >From 799efba6c8fd3acfc96db8b5b2185bcd93aecb84 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Wed, 3 Jan 2024 09:44:26 +0800 Subject: [PATCH] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward --- .../MissingStdForwardCheck.cpp| 73 +-- .../cppcoreguidelines/missing-std-forward.cpp | 26 ++- 2 files changed, 89 insertions(+), 10 deletions(-) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp index 0b85ea19735eef..f0e021039f094d 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp @@ -53,18 +53,76 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) { FuncTemplate->getTemplateParameters()->getDepth(); } +AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) { + const auto &Name = Node.getNameAsString(); + + return Builder->removeBindings( + [this, Name](const ast_matchers::internal::BoundNodesMap &Nodes) { +const auto &BN = Nodes.getNode(this->BindingID); +if (const auto *ND = BN.get()) { + if (!isa(ND)) +return true; + return ND->getName() != Name; +} +return true; + }); +} + +AST_MATCHER_P(LambdaCapture, hasCaptureKind, LambdaCaptureKind, Kind) { + return Node.getCaptureKind() == Kind; +} + +AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) { + return Node.getCaptureDefault() == Kind; +} + +AST_MATCHER(LambdaExpr, hasCaptureToParm) { + auto RefToParm = capturesVar(varDecl(hasSameNameAsBoundNode("param"))); + auto HasRefToParm = hasAnyCapture(RefToParm); + + auto CaptureInRef = + allOf(hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByRef), +unless(HasRefToParm)); + auto CaptureInCopy = allOf( + hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByCopy), HasRefToParm); + auto CaptureByRefExplicit = hasAnyCapture( + allOf(hasCaptureKind(LambdaCaptureKind::LCK_ByRef), RefToParm)); + + auto Captured = + lambdaExpr(anyOf(CaptureInRef, CaptureInCopy, CaptureByRefExplicit)); + if (Captured.matches(Node, Finder, Builder)) +return true; + + return false; +} + +AST_MATCHER(CallExpr, forCallableNode) { + auto InvokeInCaptureList = hasAnyCapture(capturesVar( + varDecl(hasInitializer(ignoringParenImpCasts(equalsNode(&Node)); + auto InvokeInLambda = hasDeclContext(cxxRecordDecl( + isLambda(), + hasParent(lambdaExpr(forCallable(equalsBoundNode("func")), + anyOf(InvokeInCaptureList, hasCaptureToParm()); + + if (forCallable(anyOf(equalsBoundNode("func"), InvokeInLambda)) + .matches(Node, Finder, Builder)) +return true; + + return false; +} + } // namespace void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) { auto ToParam = hasAnyParameter(parmVarDecl(equalsBoundNode("param"))); - auto ForwardCallMatcher = callExpr( - forCallable(equalsBoundNode("func")), argumentCountIs(1), - callee(unresolvedLookupExpr(hasAnyDeclaration( - namedDecl(hasUnderlyingDecl(hasName("::std::forward")), - hasArgument(0, declRefExpr(to(equalsBoundNode("param"))).bind("ref")), - unless(anyOf(hasAncestor(typeLoc()), - hasAncestor(expr(hasUnevaluatedContext()); + auto ForwardCallMatcher = + callExpr(forCallableNode(), argumentCountIs(1), + callee(unresolvedLookupExpr(hasAnyDeclaration( + namedDecl(hasUnderlyingDecl(hasName("::std::forward")), + hasArgument(0, declRefExpr(to(equalsBoundNode("param", + unless(anyOf(hasAncestor(typeLoc()), +hasAncestor(expr(hasUnevaluatedContext()); Finder->addMatcher( parmVarDecl(parmVarDecl().bind("param"), isTemplateTypeParameter(), @@ -76,6 +134,7 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) { } void MissingStdForwardCheck::check(const MatchFinder::MatchResult &Result) { + const auto *Param = Result.Nodes.getNodeAs("param"); if (!Param) diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp index b9720db272e406..55d6be743c22ab 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/m
[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/77056 >From 043fc62485293f5cdc41ed8e4afd056671b0ea06 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Wed, 3 Jan 2024 09:44:26 +0800 Subject: [PATCH] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward --- .../MissingStdForwardCheck.cpp| 72 +-- .../cppcoreguidelines/missing-std-forward.cpp | 26 ++- 2 files changed, 88 insertions(+), 10 deletions(-) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp index 0b85ea19735eef..ae31ce13f8def9 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp @@ -53,18 +53,76 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) { FuncTemplate->getTemplateParameters()->getDepth(); } +AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) { + const auto &Name = Node.getNameAsString(); + + return Builder->removeBindings( + [this, Name](const ast_matchers::internal::BoundNodesMap &Nodes) { +const auto &BN = Nodes.getNode(this->BindingID); +if (const auto *ND = BN.get()) { + if (!isa(ND)) +return true; + return ND->getName() != Name; +} +return true; + }); +} + +AST_MATCHER_P(LambdaCapture, hasCaptureKind, LambdaCaptureKind, Kind) { + return Node.getCaptureKind() == Kind; +} + +AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) { + return Node.getCaptureDefault() == Kind; +} + +AST_MATCHER(LambdaExpr, hasCaptureToParm) { + auto RefToParm = capturesVar(varDecl(hasSameNameAsBoundNode("param"))); + auto HasRefToParm = hasAnyCapture(RefToParm); + + auto CaptureInRef = + allOf(hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByRef), +unless(HasRefToParm)); + auto CaptureInCopy = allOf( + hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByCopy), HasRefToParm); + auto CaptureByRefExplicit = hasAnyCapture( + allOf(hasCaptureKind(LambdaCaptureKind::LCK_ByRef), RefToParm)); + + auto Captured = + lambdaExpr(anyOf(CaptureInRef, CaptureInCopy, CaptureByRefExplicit)); + if (Captured.matches(Node, Finder, Builder)) +return true; + + return false; +} + +AST_MATCHER(CallExpr, forCallableNode) { + auto InvokeInCaptureList = hasAnyCapture(capturesVar( + varDecl(hasInitializer(ignoringParenImpCasts(equalsNode(&Node)); + auto InvokeInLambda = hasDeclContext(cxxRecordDecl( + isLambda(), + hasParent(lambdaExpr(forCallable(equalsBoundNode("func")), + anyOf(InvokeInCaptureList, hasCaptureToParm()); + + if (forCallable(anyOf(equalsBoundNode("func"), InvokeInLambda)) + .matches(Node, Finder, Builder)) +return true; + + return false; +} + } // namespace void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) { auto ToParam = hasAnyParameter(parmVarDecl(equalsBoundNode("param"))); - auto ForwardCallMatcher = callExpr( - forCallable(equalsBoundNode("func")), argumentCountIs(1), - callee(unresolvedLookupExpr(hasAnyDeclaration( - namedDecl(hasUnderlyingDecl(hasName("::std::forward")), - hasArgument(0, declRefExpr(to(equalsBoundNode("param"))).bind("ref")), - unless(anyOf(hasAncestor(typeLoc()), - hasAncestor(expr(hasUnevaluatedContext()); + auto ForwardCallMatcher = + callExpr(forCallableNode(), argumentCountIs(1), + callee(unresolvedLookupExpr(hasAnyDeclaration( + namedDecl(hasUnderlyingDecl(hasName("::std::forward")), + hasArgument(0, declRefExpr(to(equalsBoundNode("param", + unless(anyOf(hasAncestor(typeLoc()), +hasAncestor(expr(hasUnevaluatedContext()); Finder->addMatcher( parmVarDecl(parmVarDecl().bind("param"), isTemplateTypeParameter(), diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp index b9720db272e406..55d6be743c22ab 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp @@ -90,9 +90,9 @@ void lambda_value_capture(T&& t) { } template -void lambda_value_reference(T&& t) { - // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: forwarding reference parameter 't' is never forwarded inside the function body [cppcoreguidelines-missing-std-forward] - [&]() { T other = std::forward(t); }; +void lambda_value_capture_copy(T&& t) { + // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: forwarding reference parameter 't' is never forwarded inside the function body
[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)
https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/76226 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/77056 >From 4b8438f448010d8a805549d8c0fa902266c643e0 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Wed, 3 Jan 2024 09:44:26 +0800 Subject: [PATCH] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward --- .../MissingStdForwardCheck.cpp| 60 ++- .../cppcoreguidelines/missing-std-forward.cpp | 31 +- 2 files changed, 86 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp index 0b85ea19735eef..370de12999aceb 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp @@ -53,16 +53,72 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) { FuncTemplate->getTemplateParameters()->getDepth(); } +AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) { + IdentifierInfo *II = Node.getIdentifier(); + if (nullptr == II) +return false; + StringRef Name = II->getName(); + + return Builder->removeBindings( + [this, Name](const ast_matchers::internal::BoundNodesMap &Nodes) { +const DynTypedNode &BN = Nodes.getNode(this->BindingID); +if (const auto *ND = BN.get()) { + if (!isa(ND)) +return true; + return ND->getName() != Name; +} +return true; + }); +} + +AST_MATCHER_P(LambdaCapture, hasCaptureKind, LambdaCaptureKind, Kind) { + return Node.getCaptureKind() == Kind; +} + +AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) { + return Node.getCaptureDefault() == Kind; +} + } // namespace void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) { + auto RefToParmImplicit = allOf( + equalsBoundNode("var"), hasInitializer(ignoringParenImpCasts( + declRefExpr(to(equalsBoundNode("param")); + auto RefToParm = capturesVar( + varDecl(anyOf(hasSameNameAsBoundNode("param"), RefToParmImplicit))); + auto HasRefToParm = hasAnyCapture(RefToParm); + + auto CaptureInRef = + allOf(hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByRef), +unless(hasAnyCapture( +capturesVar(varDecl(hasSameNameAsBoundNode("param")); + auto CaptureInCopy = allOf( + hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByCopy), HasRefToParm); + auto CaptureByRefExplicit = hasAnyCapture( + allOf(hasCaptureKind(LambdaCaptureKind::LCK_ByRef), RefToParm)); + + auto CapturedInBody = + lambdaExpr(anyOf(CaptureInRef, CaptureInCopy, CaptureByRefExplicit)); + auto CapturedInCaptureList = hasAnyCapture(capturesVar( + varDecl(hasInitializer(ignoringParenImpCasts(equalsBoundNode("call")); + + auto CapturedInLambda = hasDeclContext(cxxRecordDecl( + isLambda(), + hasParent(lambdaExpr(forCallable(equalsBoundNode("func")), + anyOf(CapturedInCaptureList, CapturedInBody); + auto ToParam = hasAnyParameter(parmVarDecl(equalsBoundNode("param"))); auto ForwardCallMatcher = callExpr( - forCallable(equalsBoundNode("func")), argumentCountIs(1), + callExpr().bind("call"), argumentCountIs(1), + hasArgument( + 0, declRefExpr(to( + varDecl(optionally(equalsBoundNode("param"))).bind("var", + forCallable(anyOf(equalsBoundNode("func"), CapturedInLambda)), callee(unresolvedLookupExpr(hasAnyDeclaration( namedDecl(hasUnderlyingDecl(hasName("::std::forward")), - hasArgument(0, declRefExpr(to(equalsBoundNode("param"))).bind("ref")), + unless(anyOf(hasAncestor(typeLoc()), hasAncestor(expr(hasUnevaluatedContext()); diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp index b9720db272e406..443f338ba2046a 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp @@ -90,9 +90,9 @@ void lambda_value_capture(T&& t) { } template -void lambda_value_reference(T&& t) { - // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: forwarding reference parameter 't' is never forwarded inside the function body [cppcoreguidelines-missing-std-forward] - [&]() { T other = std::forward(t); }; +void lambda_value_capture_copy(T&& t) { + // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: forwarding reference parameter 't' is never forwarded inside the function body [cppcoreguidelines-missing-std-forward] + [&,t]() { T other = std::forward(t); }; } } // namespace positive_cases @@ -147,4 +147,29 @@ class AClass { T data; }; +template +void lambda_value_refere
[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/77056 >From 0f1e72b143d360c1f005f4bd63a378c5277d4480 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Wed, 3 Jan 2024 09:44:26 +0800 Subject: [PATCH] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward --- .../MissingStdForwardCheck.cpp| 60 ++- clang-tools-extra/docs/ReleaseNotes.rst | 5 ++ .../cppcoreguidelines/missing-std-forward.cpp | 31 +- 3 files changed, 91 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp index 0b85ea19735eef..370de12999aceb 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp @@ -53,16 +53,72 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) { FuncTemplate->getTemplateParameters()->getDepth(); } +AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) { + IdentifierInfo *II = Node.getIdentifier(); + if (nullptr == II) +return false; + StringRef Name = II->getName(); + + return Builder->removeBindings( + [this, Name](const ast_matchers::internal::BoundNodesMap &Nodes) { +const DynTypedNode &BN = Nodes.getNode(this->BindingID); +if (const auto *ND = BN.get()) { + if (!isa(ND)) +return true; + return ND->getName() != Name; +} +return true; + }); +} + +AST_MATCHER_P(LambdaCapture, hasCaptureKind, LambdaCaptureKind, Kind) { + return Node.getCaptureKind() == Kind; +} + +AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) { + return Node.getCaptureDefault() == Kind; +} + } // namespace void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) { + auto RefToParmImplicit = allOf( + equalsBoundNode("var"), hasInitializer(ignoringParenImpCasts( + declRefExpr(to(equalsBoundNode("param")); + auto RefToParm = capturesVar( + varDecl(anyOf(hasSameNameAsBoundNode("param"), RefToParmImplicit))); + auto HasRefToParm = hasAnyCapture(RefToParm); + + auto CaptureInRef = + allOf(hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByRef), +unless(hasAnyCapture( +capturesVar(varDecl(hasSameNameAsBoundNode("param")); + auto CaptureInCopy = allOf( + hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByCopy), HasRefToParm); + auto CaptureByRefExplicit = hasAnyCapture( + allOf(hasCaptureKind(LambdaCaptureKind::LCK_ByRef), RefToParm)); + + auto CapturedInBody = + lambdaExpr(anyOf(CaptureInRef, CaptureInCopy, CaptureByRefExplicit)); + auto CapturedInCaptureList = hasAnyCapture(capturesVar( + varDecl(hasInitializer(ignoringParenImpCasts(equalsBoundNode("call")); + + auto CapturedInLambda = hasDeclContext(cxxRecordDecl( + isLambda(), + hasParent(lambdaExpr(forCallable(equalsBoundNode("func")), + anyOf(CapturedInCaptureList, CapturedInBody); + auto ToParam = hasAnyParameter(parmVarDecl(equalsBoundNode("param"))); auto ForwardCallMatcher = callExpr( - forCallable(equalsBoundNode("func")), argumentCountIs(1), + callExpr().bind("call"), argumentCountIs(1), + hasArgument( + 0, declRefExpr(to( + varDecl(optionally(equalsBoundNode("param"))).bind("var", + forCallable(anyOf(equalsBoundNode("func"), CapturedInLambda)), callee(unresolvedLookupExpr(hasAnyDeclaration( namedDecl(hasUnderlyingDecl(hasName("::std::forward")), - hasArgument(0, declRefExpr(to(equalsBoundNode("param"))).bind("ref")), + unless(anyOf(hasAncestor(typeLoc()), hasAncestor(expr(hasUnevaluatedContext()); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 4d25e2ebe85f5f..b55599cac3dd06 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -295,6 +295,11 @@ Changes in existing checks coroutine functions and increase issue detection for cases involving type aliases with references. +- Improved :doc:`cppcoreguidelines-missing-std-forward + ` check to + provide fixes of false positive that forwarded in capture list and body of + lambda. + - Improved :doc:`cppcoreguidelines-narrowing-conversions ` check by extending the `IgnoreConversionFromTypes` option to include types without a diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp index b9720db272e406..443f338ba2046a 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp +++ b/clang-tools-extra/test/cla
[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)
@@ -53,18 +53,76 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) { FuncTemplate->getTemplateParameters()->getDepth(); } +AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) { + const auto &Name = Node.getNameAsString(); jcsxky wrote: Add release notes and fix code as your suggestion. https://github.com/llvm/llvm-project/pull/77056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)
@@ -147,4 +147,24 @@ class AClass { T data; }; +template +void lambda_value_reference(T&& t) { + [&]() { T other = std::forward(t); }; +} + +template +void lambda_value_reference_capture_list_ref_1(T&& t) { +[=, &t] { T other = std::forward(t); }; +} + +template +void lambda_value_reference_capture_list_ref_2(T&& t) { +[&t] { T other = std::forward(t); }; +} + +template +void lambda_value_reference_capture_list(T&& t) { +[t = std::forward(t)] { t(); }; +} + jcsxky wrote: Fixed. https://github.com/llvm/llvm-project/pull/77056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)
@@ -53,18 +53,76 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) { FuncTemplate->getTemplateParameters()->getDepth(); } +AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) { + const auto &Name = Node.getNameAsString(); + + return Builder->removeBindings( + [this, Name](const ast_matchers::internal::BoundNodesMap &Nodes) { +const auto &BN = Nodes.getNode(this->BindingID); jcsxky wrote: Add explicit type instead of `auto`. https://github.com/llvm/llvm-project/pull/77056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)
@@ -53,18 +53,76 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) { FuncTemplate->getTemplateParameters()->getDepth(); } +AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) { + const auto &Name = Node.getNameAsString(); + + return Builder->removeBindings( + [this, Name](const ast_matchers::internal::BoundNodesMap &Nodes) { +const auto &BN = Nodes.getNode(this->BindingID); +if (const auto *ND = BN.get()) { + if (!isa(ND)) +return true; + return ND->getName() != Name; +} +return true; + }); +} + +AST_MATCHER_P(LambdaCapture, hasCaptureKind, LambdaCaptureKind, Kind) { + return Node.getCaptureKind() == Kind; +} + +AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) { + return Node.getCaptureDefault() == Kind; +} + +AST_MATCHER(LambdaExpr, hasCaptureToParm) { + auto RefToParm = capturesVar(varDecl(hasSameNameAsBoundNode("param"))); + auto HasRefToParm = hasAnyCapture(RefToParm); + + auto CaptureInRef = + allOf(hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByRef), +unless(HasRefToParm)); + auto CaptureInCopy = allOf( + hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByCopy), HasRefToParm); + auto CaptureByRefExplicit = hasAnyCapture( + allOf(hasCaptureKind(LambdaCaptureKind::LCK_ByRef), RefToParm)); + + auto Captured = + lambdaExpr(anyOf(CaptureInRef, CaptureInCopy, CaptureByRefExplicit)); + if (Captured.matches(Node, Finder, Builder)) +return true; + + return false; +} + +AST_MATCHER(CallExpr, forCallableNode) { jcsxky wrote: Use original matchers instead. https://github.com/llvm/llvm-project/pull/77056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/77056 >From 880554dc7a73fbfad8229e15f8398097611e326d Mon Sep 17 00:00:00 2001 From: huqizhi Date: Wed, 3 Jan 2024 09:44:26 +0800 Subject: [PATCH] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward --- .../MissingStdForwardCheck.cpp| 60 ++- clang-tools-extra/docs/ReleaseNotes.rst | 4 ++ .../cppcoreguidelines/missing-std-forward.cpp | 31 +- 3 files changed, 90 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp index 0b85ea19735eef..370de12999aceb 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp @@ -53,16 +53,72 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) { FuncTemplate->getTemplateParameters()->getDepth(); } +AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) { + IdentifierInfo *II = Node.getIdentifier(); + if (nullptr == II) +return false; + StringRef Name = II->getName(); + + return Builder->removeBindings( + [this, Name](const ast_matchers::internal::BoundNodesMap &Nodes) { +const DynTypedNode &BN = Nodes.getNode(this->BindingID); +if (const auto *ND = BN.get()) { + if (!isa(ND)) +return true; + return ND->getName() != Name; +} +return true; + }); +} + +AST_MATCHER_P(LambdaCapture, hasCaptureKind, LambdaCaptureKind, Kind) { + return Node.getCaptureKind() == Kind; +} + +AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) { + return Node.getCaptureDefault() == Kind; +} + } // namespace void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) { + auto RefToParmImplicit = allOf( + equalsBoundNode("var"), hasInitializer(ignoringParenImpCasts( + declRefExpr(to(equalsBoundNode("param")); + auto RefToParm = capturesVar( + varDecl(anyOf(hasSameNameAsBoundNode("param"), RefToParmImplicit))); + auto HasRefToParm = hasAnyCapture(RefToParm); + + auto CaptureInRef = + allOf(hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByRef), +unless(hasAnyCapture( +capturesVar(varDecl(hasSameNameAsBoundNode("param")); + auto CaptureInCopy = allOf( + hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByCopy), HasRefToParm); + auto CaptureByRefExplicit = hasAnyCapture( + allOf(hasCaptureKind(LambdaCaptureKind::LCK_ByRef), RefToParm)); + + auto CapturedInBody = + lambdaExpr(anyOf(CaptureInRef, CaptureInCopy, CaptureByRefExplicit)); + auto CapturedInCaptureList = hasAnyCapture(capturesVar( + varDecl(hasInitializer(ignoringParenImpCasts(equalsBoundNode("call")); + + auto CapturedInLambda = hasDeclContext(cxxRecordDecl( + isLambda(), + hasParent(lambdaExpr(forCallable(equalsBoundNode("func")), + anyOf(CapturedInCaptureList, CapturedInBody); + auto ToParam = hasAnyParameter(parmVarDecl(equalsBoundNode("param"))); auto ForwardCallMatcher = callExpr( - forCallable(equalsBoundNode("func")), argumentCountIs(1), + callExpr().bind("call"), argumentCountIs(1), + hasArgument( + 0, declRefExpr(to( + varDecl(optionally(equalsBoundNode("param"))).bind("var", + forCallable(anyOf(equalsBoundNode("func"), CapturedInLambda)), callee(unresolvedLookupExpr(hasAnyDeclaration( namedDecl(hasUnderlyingDecl(hasName("::std::forward")), - hasArgument(0, declRefExpr(to(equalsBoundNode("param"))).bind("ref")), + unless(anyOf(hasAncestor(typeLoc()), hasAncestor(expr(hasUnevaluatedContext()); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 4d25e2ebe85f5f..49ac70d9998512 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -295,6 +295,10 @@ Changes in existing checks coroutine functions and increase issue detection for cases involving type aliases with references. +- Improved :doc:`cppcoreguidelines-missing-std-forward + ` check to + address false positives in the capture list and body of lambdas. + - Improved :doc:`cppcoreguidelines-narrowing-conversions ` check by extending the `IgnoreConversionFromTypes` option to include types without a diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp index b9720db272e406..443f338ba2046a 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppc
[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)
@@ -295,6 +295,11 @@ Changes in existing checks coroutine functions and increase issue detection for cases involving type aliases with references. +- Improved :doc:`cppcoreguidelines-missing-std-forward + ` check to + provide fixes of false positive that forwarded in capture list and body of + lambda. + jcsxky wrote: Done. https://github.com/llvm/llvm-project/pull/77056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)
https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/77056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] pop explicit to keep context stack balance (PR #77312)
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/77312 None >From d0a51d88d54420570bfa351e8ca70777ea15e4b7 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Mon, 8 Jan 2024 22:15:09 +0800 Subject: [PATCH] [clang] pop explicit to keep context stack balance --- clang/lib/Parse/ParseDecl.cpp | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index b60ae293ef8c20..9418ee305171c8 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2637,7 +2637,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( T.consumeOpen(); ExprVector Exprs; - +bool ValidBefore = !ThisDecl->isInvalidDecl(); InitializerScopeRAII InitScope(*this, D, ThisDecl); auto ThisVarDecl = dyn_cast_or_null(ThisDecl); @@ -2670,6 +2670,11 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( CalledSignatureHelp = true; } Actions.ActOnInitializerError(ThisDecl); + if (ValidBefore && ThisDecl->isInvalidDecl()) { +ThisDecl->setInvalidDecl(false); +InitScope.pop(); +ThisDecl->setInvalidDecl(); + } SkipUntil(tok::r_paren, StopAtSemi); } else { // Match the ')'. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] pop explicit to keep context stack balance (PR #77312)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/77312 >From e31bf72dfadd4f4b9a316917cc0919fdef203498 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Mon, 8 Jan 2024 22:15:09 +0800 Subject: [PATCH] [clang] pop explicit to keep context stack balance --- clang/lib/Parse/ParseDecl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index b60ae293ef8c20..ed75609d0a538b 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2637,7 +2637,6 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( T.consumeOpen(); ExprVector Exprs; - InitializerScopeRAII InitScope(*this, D, ThisDecl); auto ThisVarDecl = dyn_cast_or_null(ThisDecl); @@ -2669,6 +2668,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( /*Braced=*/false); CalledSignatureHelp = true; } + InitScope.pop(); Actions.ActOnInitializerError(ThisDecl); SkipUntil(tok::r_paren, StopAtSemi); } else { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] pop explicit to keep context stack balance (PR #77312)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/77312 >From f5813ab00fb26148b79f8a419436abf14ad9ee34 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Mon, 8 Jan 2024 22:15:09 +0800 Subject: [PATCH] [clang] pop explicit to keep context stack balance --- clang/lib/Parse/ParseDecl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index b60ae293ef8c20..6b16320f86721b 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2669,6 +2669,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( /*Braced=*/false); CalledSignatureHelp = true; } + InitScope.pop(); Actions.ActOnInitializerError(ThisDecl); SkipUntil(tok::r_paren, StopAtSemi); } else { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] pop explicit to keep context stack balance (PR #77312)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/77312 >From f3671079bb27100dd77f9572a20445285c6850dd Mon Sep 17 00:00:00 2001 From: huqizhi Date: Mon, 8 Jan 2024 22:15:09 +0800 Subject: [PATCH] [clang] pop explicit to keep context stack balance --- clang/lib/Parse/ParseDecl.cpp | 1 + .../cxx-static-member-init-no-crash.cpp | 19 +++ 2 files changed, 20 insertions(+) create mode 100644 clang/test/Parser/cxx-static-member-init-no-crash.cpp diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index b60ae293ef8c20..6b16320f86721b 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2669,6 +2669,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( /*Braced=*/false); CalledSignatureHelp = true; } + InitScope.pop(); Actions.ActOnInitializerError(ThisDecl); SkipUntil(tok::r_paren, StopAtSemi); } else { diff --git a/clang/test/Parser/cxx-static-member-init-no-crash.cpp b/clang/test/Parser/cxx-static-member-init-no-crash.cpp new file mode 100644 index 00..304f2ce7550e4b --- /dev/null +++ b/clang/test/Parser/cxx-static-member-init-no-crash.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +template class EngineClassTypeInfo; +template struct _ConcreteClassBase {}; + +struct _GLOBALSCOPE {}; +template struct _SCOPE {}; + +class Zone { +private: + typedef _ConcreteClassBase _ClassBase; + static EngineClassTypeInfo _smTypeInfo; + static EngineExportScope &__engineExportScope(); +}; + +EngineClassTypeInfo +Zone::_smTypeInfo("Zone", &_SCOPE<__DeclScope>()(), 0); +EngineExportScope &Zone::__engineExportScope() { return Zone::_smTypeInfo; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] pop explicit to keep context stack balance (PR #77312)
https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/77312 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] pop explicit to keep context stack balance (PR #77312)
jcsxky wrote: > Reference in new issue > Edit > Hide > Delete > Report conte Test case has been added and update description. https://github.com/llvm/llvm-project/pull/77312 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] pop explicit to keep context stack balance (PR #77312)
jcsxky wrote: > Can you explain why this change is needed, and provide a test case? (in > `clang/test/Parser`) Thanks Test case has been added and update description. https://github.com/llvm/llvm-project/pull/77312 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] pop explicit to keep context stack balance (PR #77312)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/77312 >From 1579c73d40a285caad1c51a74a1324d6476d633c Mon Sep 17 00:00:00 2001 From: huqizhi Date: Mon, 8 Jan 2024 22:15:09 +0800 Subject: [PATCH] [clang] pop explicit to keep context stack balance --- clang/lib/Parse/ParseDecl.cpp | 1 + .../cxx-static-member-init-no-crash.cpp | 20 +++ 2 files changed, 21 insertions(+) create mode 100644 clang/test/Parser/cxx-static-member-init-no-crash.cpp diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index b60ae293ef8c20..6b16320f86721b 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2669,6 +2669,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( /*Braced=*/false); CalledSignatureHelp = true; } + InitScope.pop(); Actions.ActOnInitializerError(ThisDecl); SkipUntil(tok::r_paren, StopAtSemi); } else { diff --git a/clang/test/Parser/cxx-static-member-init-no-crash.cpp b/clang/test/Parser/cxx-static-member-init-no-crash.cpp new file mode 100644 index 00..a1956500c55c2d --- /dev/null +++ b/clang/test/Parser/cxx-static-member-init-no-crash.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +template class EngineClassTypeInfo; // expected-note {{template is declared here}} +template struct _ConcreteClassBase {}; + +struct _GLOBALSCOPE {}; +template struct _SCOPE {}; + +class Zone { +private: + typedef _ConcreteClassBase _ClassBase; + static EngineClassTypeInfo _smTypeInfo; + static EngineExportScope &__engineExportScope(); // expected-error {{unknown type name 'EngineExportScope'}} +}; + +EngineClassTypeInfo +Zone::_smTypeInfo("Zone", &_SCOPE<__DeclScope>()(), 0); /* expected-error {{use of undeclared identifier '__DeclScope'}} \ + expected-error {{implicit instantiation of undefined template 'EngineClassTypeInfo>'}} */ +EngineExportScope &Zone::__engineExportScope() { return Zone::_smTypeInfo; } // expected-error {{unknown type name 'EngineExportScope'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] pop explicitly to keep context stack balance (PR #77312)
https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/77312 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Parser] pop explicitly to keep context stack balance (PR #77312)
https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/77312 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Parser] pop explicitly to keep context stack balance (PR #77312)
jcsxky wrote: > This looks like a duplicate of #77312 @danix800 The opposite is true. I will close this pr. https://github.com/llvm/llvm-project/pull/77312 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Parser] pop explicitly to keep context stack balance (PR #77312)
https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/77312 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][SemaCXX] improve sema check of clang::musttail attribute (PR #77727)
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/77727 Call function with no-return attribute generate code with unreachable instruction instead of return and if the call statement has `clang::musttail` attribute, it would crash in Verify. Check this condition in Sema. >From 0a340a46a69f04555bfeaeb14f214f57ebd6b9cd Mon Sep 17 00:00:00 2001 From: huqizhi Date: Thu, 11 Jan 2024 13:02:21 +0800 Subject: [PATCH] [Clang][SemaCXX] improve sema check of clang::musttail attribute --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaStmt.cpp | 6 ++ clang/test/SemaCXX/PR76631.cpp | 7 +++ 3 files changed, 15 insertions(+) create mode 100644 clang/test/SemaCXX/PR76631.cpp diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 3884dca59e2f3b..b40befc5c1cfb5 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3113,6 +3113,8 @@ def err_musttail_scope : Error< "cannot perform a tail call from this return statement">; def err_musttail_no_variadic : Error< "%0 attribute may not be used with variadic functions">; +def err_musttail_no_return : Error< + "%0 attribute may not be used with no-return-attribute functions">; def err_nsobject_attribute : Error< "'NSObject' attribute is for pointer types only">; diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 21efe25ed84a3d..9e7c8c7e4e8c12 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -786,6 +786,12 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr &MTA) { return false; } + const auto *CalleeDecl = CE->getCalleeDecl(); + if (CalleeDecl && CalleeDecl->hasAttr()) { +Diag(St->getBeginLoc(), diag::err_musttail_no_return) << &MTA; +return false; + } + // Caller and callee must match in whether they have a "this" parameter. if (CallerType.This.isNull() != CalleeType.This.isNull()) { if (const auto *ND = dyn_cast_or_null(CE->getCalleeDecl())) { diff --git a/clang/test/SemaCXX/PR76631.cpp b/clang/test/SemaCXX/PR76631.cpp new file mode 100644 index 00..df89753bd12580 --- /dev/null +++ b/clang/test/SemaCXX/PR76631.cpp @@ -0,0 +1,7 @@ +[[noreturn]] void throw_int() { + throw int(); +} + +void throw_int_wrapper() { + [[clang::musttail]] return throw_int(); // expected-error {{'musttail' attribute may not be used with no-return-attribute functions}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][SemaCXX] improve sema check of clang::musttail attribute (PR #77727)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/77727 >From c554108eeb950c9885291962018ce31233589e8e Mon Sep 17 00:00:00 2001 From: huqizhi Date: Thu, 11 Jan 2024 13:02:21 +0800 Subject: [PATCH] [Clang][SemaCXX] improve sema check of clang::musttail attribute --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaStmt.cpp | 6 ++ clang/test/SemaCXX/PR76631.cpp | 9 + 3 files changed, 17 insertions(+) create mode 100644 clang/test/SemaCXX/PR76631.cpp diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 3884dca59e2f3b..b40befc5c1cfb5 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3113,6 +3113,8 @@ def err_musttail_scope : Error< "cannot perform a tail call from this return statement">; def err_musttail_no_variadic : Error< "%0 attribute may not be used with variadic functions">; +def err_musttail_no_return : Error< + "%0 attribute may not be used with no-return-attribute functions">; def err_nsobject_attribute : Error< "'NSObject' attribute is for pointer types only">; diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 21efe25ed84a3d..9e7c8c7e4e8c12 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -786,6 +786,12 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr &MTA) { return false; } + const auto *CalleeDecl = CE->getCalleeDecl(); + if (CalleeDecl && CalleeDecl->hasAttr()) { +Diag(St->getBeginLoc(), diag::err_musttail_no_return) << &MTA; +return false; + } + // Caller and callee must match in whether they have a "this" parameter. if (CallerType.This.isNull() != CalleeType.This.isNull()) { if (const auto *ND = dyn_cast_or_null(CE->getCalleeDecl())) { diff --git a/clang/test/SemaCXX/PR76631.cpp b/clang/test/SemaCXX/PR76631.cpp new file mode 100644 index 00..ceacf22c76574a --- /dev/null +++ b/clang/test/SemaCXX/PR76631.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -verify -std=c++11 -fsyntax-only %s + +[[noreturn]] void throw_int() { + throw int(); +} + +void throw_int_wrapper() { + [[clang::musttail]] return throw_int(); // expected-error {{'musttail' attribute may not be used with no-return-attribute functions}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][SemaCXX] improve sema check of clang::musttail attribute (PR #77727)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/77727 >From 74fa4ef52b07df154d7b6682323d2da7ff2b12ef Mon Sep 17 00:00:00 2001 From: huqizhi Date: Thu, 11 Jan 2024 13:02:21 +0800 Subject: [PATCH] [Clang][SemaCXX] improve sema check of clang::musttail attribute --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaStmt.cpp | 6 ++ clang/test/SemaCXX/PR76631.cpp | 9 + 3 files changed, 17 insertions(+) create mode 100644 clang/test/SemaCXX/PR76631.cpp diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 3884dca59e2f3b..b40befc5c1cfb5 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3113,6 +3113,8 @@ def err_musttail_scope : Error< "cannot perform a tail call from this return statement">; def err_musttail_no_variadic : Error< "%0 attribute may not be used with variadic functions">; +def err_musttail_no_return : Error< + "%0 attribute may not be used with no-return-attribute functions">; def err_nsobject_attribute : Error< "'NSObject' attribute is for pointer types only">; diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 21efe25ed84a3d..9e7c8c7e4e8c12 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -786,6 +786,12 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr &MTA) { return false; } + const auto *CalleeDecl = CE->getCalleeDecl(); + if (CalleeDecl && CalleeDecl->hasAttr()) { +Diag(St->getBeginLoc(), diag::err_musttail_no_return) << &MTA; +return false; + } + // Caller and callee must match in whether they have a "this" parameter. if (CallerType.This.isNull() != CalleeType.This.isNull()) { if (const auto *ND = dyn_cast_or_null(CE->getCalleeDecl())) { diff --git a/clang/test/SemaCXX/PR76631.cpp b/clang/test/SemaCXX/PR76631.cpp new file mode 100644 index 00..947fa3fc2635e6 --- /dev/null +++ b/clang/test/SemaCXX/PR76631.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -verify -std=c++11 -fsyntax-only %s + +[[noreturn]] void throw_int() { + throw int(); // expected-error {{cannot use 'throw' with exceptions disabled}} +} + +void throw_int_wrapper() { + [[clang::musttail]] return throw_int(); // expected-error {{'musttail' attribute may not be used with no-return-attribute functions}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][SemaCXX] improve sema check of clang::musttail attribute (PR #77727)
https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/77727 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][SemaCXX] improve sema check of clang::musttail attribute (PR #77727)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/77727 >From cdc04d0b5b934c4dc4c8294dd000539275bf4222 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Thu, 11 Jan 2024 13:02:21 +0800 Subject: [PATCH] [Clang][SemaCXX] improve sema check of clang::musttail attribute --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaStmt.cpp | 6 ++ clang/test/SemaCXX/PR76631.cpp | 9 + 3 files changed, 17 insertions(+) create mode 100644 clang/test/SemaCXX/PR76631.cpp diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 1a79892e40030a..1006e7d65dd868 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3113,6 +3113,8 @@ def err_musttail_scope : Error< "cannot perform a tail call from this return statement">; def err_musttail_no_variadic : Error< "%0 attribute may not be used with variadic functions">; +def err_musttail_no_return : Error< + "%0 attribute may not be used with no-return-attribute functions">; def err_nsobject_attribute : Error< "'NSObject' attribute is for pointer types only">; diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 21efe25ed84a3d..9e7c8c7e4e8c12 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -786,6 +786,12 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr &MTA) { return false; } + const auto *CalleeDecl = CE->getCalleeDecl(); + if (CalleeDecl && CalleeDecl->hasAttr()) { +Diag(St->getBeginLoc(), diag::err_musttail_no_return) << &MTA; +return false; + } + // Caller and callee must match in whether they have a "this" parameter. if (CallerType.This.isNull() != CalleeType.This.isNull()) { if (const auto *ND = dyn_cast_or_null(CE->getCalleeDecl())) { diff --git a/clang/test/SemaCXX/PR76631.cpp b/clang/test/SemaCXX/PR76631.cpp new file mode 100644 index 00..947fa3fc2635e6 --- /dev/null +++ b/clang/test/SemaCXX/PR76631.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -verify -std=c++11 -fsyntax-only %s + +[[noreturn]] void throw_int() { + throw int(); // expected-error {{cannot use 'throw' with exceptions disabled}} +} + +void throw_int_wrapper() { + [[clang::musttail]] return throw_int(); // expected-error {{'musttail' attribute may not be used with no-return-attribute functions}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][SemaCXX] improve sema check of clang::musttail attribute (PR #77727)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/77727 >From 75e9a81a5aa4042197201450fa676b8036a3d2cd Mon Sep 17 00:00:00 2001 From: huqizhi Date: Thu, 11 Jan 2024 13:02:21 +0800 Subject: [PATCH] [Clang][SemaCXX] improve sema check of clang::musttail attribute --- clang/docs/HLSL/FunctionCalls.rst| 2 +- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaStmt.cpp | 6 ++ clang/test/SemaCXX/PR76631.cpp | 9 + 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/PR76631.cpp diff --git a/clang/docs/HLSL/FunctionCalls.rst b/clang/docs/HLSL/FunctionCalls.rst index 996ddd6944b1ce..7317de2163f897 100644 --- a/clang/docs/HLSL/FunctionCalls.rst +++ b/clang/docs/HLSL/FunctionCalls.rst @@ -144,7 +144,7 @@ undefined behavior in HLSL, and any use of the argument after the call is a use of an undefined value which may be illegal in the target (DXIL programs with used or potentially used ``undef`` or ``poison`` values fail validation). -Clang Implementation +Clang Implementation .. note:: diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 1a79892e40030a..1006e7d65dd868 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3113,6 +3113,8 @@ def err_musttail_scope : Error< "cannot perform a tail call from this return statement">; def err_musttail_no_variadic : Error< "%0 attribute may not be used with variadic functions">; +def err_musttail_no_return : Error< + "%0 attribute may not be used with no-return-attribute functions">; def err_nsobject_attribute : Error< "'NSObject' attribute is for pointer types only">; diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 21efe25ed84a3d..9e7c8c7e4e8c12 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -786,6 +786,12 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr &MTA) { return false; } + const auto *CalleeDecl = CE->getCalleeDecl(); + if (CalleeDecl && CalleeDecl->hasAttr()) { +Diag(St->getBeginLoc(), diag::err_musttail_no_return) << &MTA; +return false; + } + // Caller and callee must match in whether they have a "this" parameter. if (CallerType.This.isNull() != CalleeType.This.isNull()) { if (const auto *ND = dyn_cast_or_null(CE->getCalleeDecl())) { diff --git a/clang/test/SemaCXX/PR76631.cpp b/clang/test/SemaCXX/PR76631.cpp new file mode 100644 index 00..947fa3fc2635e6 --- /dev/null +++ b/clang/test/SemaCXX/PR76631.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -verify -std=c++11 -fsyntax-only %s + +[[noreturn]] void throw_int() { + throw int(); // expected-error {{cannot use 'throw' with exceptions disabled}} +} + +void throw_int_wrapper() { + [[clang::musttail]] return throw_int(); // expected-error {{'musttail' attribute may not be used with no-return-attribute functions}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] improve sema check of clang::musttail attribute (PR #77727)
https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/77727 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] improve sema check of clang::musttail attribute (PR #77727)
https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/77727 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix a bug on type constraint checking (PR #84671)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/84671 >From 849db0cede4d0fe108ec7cf530974606a426b9db Mon Sep 17 00:00:00 2001 From: huqizhi Date: Sun, 10 Mar 2024 16:11:18 +0800 Subject: [PATCH] [Clang][Sema] Fix a bug on type constraint checking --- clang/docs/ReleaseNotes.rst| 2 ++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 1 + clang/test/Sema/PR84368.cpp| 16 3 files changed, 19 insertions(+) create mode 100644 clang/test/Sema/PR84368.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 5fe3fd066df235..cede0deb179d5c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -376,6 +376,8 @@ Bug Fixes to C++ Support - Fixed a crash in constant evaluation when trying to access a captured ``this`` pointer in a lambda with an explicit object parameter. Fixes (#GH80997) +- Fix an issue where missing set friend declaration in template class instantiation. + Fixes (#GH84368). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 8ef8bfdf2a7b56..dc972018e7b281 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1727,6 +1727,7 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) { assert(!Owner->isDependentContext()); Inst->setLexicalDeclContext(Owner); RecordInst->setLexicalDeclContext(Owner); +Inst->setObjectOfFriendDecl(); if (PrevClassTemplate) { Inst->setCommonPtr(PrevClassTemplate->getCommonPtr()); diff --git a/clang/test/Sema/PR84368.cpp b/clang/test/Sema/PR84368.cpp new file mode 100644 index 00..6551df29358920 --- /dev/null +++ b/clang/test/Sema/PR84368.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -std=c++20 -verify %s +// RUN: %clang_cc1 -std=c++23 -verify %s +// expected-no-diagnostics + +template concept IsOk = requires() { typename T::Float; }; + +template struct Thing; + +template struct Foobar { + template struct Inner { +template friend struct Thing; + }; +}; + +struct MyType { using Float=float; }; +Foobar::Inner<0> foobar; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix a bug on type constraint checking (PR #84671)
https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/84671 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix issue on requires expression with templated base class member function (PR #85198)
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/85198 None >From 8925332a806b171bf2e12a7beb257ea85bd0a668 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Thu, 14 Mar 2024 16:32:36 +0800 Subject: [PATCH] [Clang][Sema] Fix issue on requires expression with templated base class member function --- clang/lib/Sema/SemaExpr.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 8725b09f8546cf..31df62d06f1c05 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -7729,7 +7729,8 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, } if (CXXMethodDecl *Method = dyn_cast_or_null(FDecl)) -if (Method->isImplicitObjectMemberFunction()) +if (!isa(CurContext) && +Method->isImplicitObjectMemberFunction()) return ExprError(Diag(LParenLoc, diag::err_member_call_without_object) << Fn->getSourceRange() << 0); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix issue on requires expression with templated base class member function (PR #85198)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/85198 >From 23a344395180cbdcd47618e3170e72260139d4b7 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Thu, 14 Mar 2024 16:32:36 +0800 Subject: [PATCH] [Clang][Sema] Fix issue on requires expression with templated base class member function --- clang/lib/Sema/SemaExpr.cpp| 3 ++- clang/test/SemaCXX/PR84020.cpp | 23 +++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/PR84020.cpp diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 8725b09f8546cf..31df62d06f1c05 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -7729,7 +7729,8 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, } if (CXXMethodDecl *Method = dyn_cast_or_null(FDecl)) -if (Method->isImplicitObjectMemberFunction()) +if (!isa(CurContext) && +Method->isImplicitObjectMemberFunction()) return ExprError(Diag(LParenLoc, diag::err_member_call_without_object) << Fn->getSourceRange() << 0); diff --git a/clang/test/SemaCXX/PR84020.cpp b/clang/test/SemaCXX/PR84020.cpp new file mode 100644 index 00..8ea5dcc4527ae7 --- /dev/null +++ b/clang/test/SemaCXX/PR84020.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -std=c++20 -verify %s +// RUN: %clang_cc1 -std=c++23 -verify %s +// expected-no-diagnostics + +struct B { +template +void foo(); + +void bar(); +}; + +template +struct A : T { +auto foo() { +static_assert(requires { T::template foo(); }); +static_assert(requires { T::bar(); }); +} +}; + +int main() { +A a; +a.foo(); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix issue on requires expression with templated base class member function (PR #85198)
jcsxky wrote: > Please add a more useful PR description, since that's useful for reviewers > and ends up in the git log. Thanks for your remind! I am waiting for CI to finish and after that I will add the description. Maybe mark it with draft would be better. https://github.com/llvm/llvm-project/pull/85198 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix issue on requires expression with templated base class member function (PR #85198)
https://github.com/jcsxky converted_to_draft https://github.com/llvm/llvm-project/pull/85198 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits