https://github.com/mizvekov created https://github.com/llvm/llvm-project/pull/153923
These are implicit vardecls which its type was never written in source code. Don't create a TypeLoc and give it a fake source location. The fake as-written type also didn't match the actual type, which after fixing this gives some unrelated test churn on a CFG dump, since statement printing prefers type source info if thats available. Fixes https://github.com/llvm/llvm-project/issues/153649 This regression was never released, so no release notes are added. >From 3c0d0fb4f7d4a14caa3625822018f358198bb28d Mon Sep 17 00:00:00 2001 From: Matheus Izvekov <mizve...@gmail.com> Date: Sat, 16 Aug 2025 01:02:25 -0300 Subject: [PATCH] [clang] don't create type source info for vardecl created for structured bindings These are implicit vardecls which its type was never written in source code. Don't create a TypeLoc and give it a fake source location. The fake as-written type also didn't match the actual type, which after fixing this gives some unrelated test churn on a CFG dump, since statement printing prefers type source info if thats available. Fixes https://github.com/llvm/llvm-project/issues/153649 This regression was never released, so no release notes are added. --- .../checkers/modernize/type-traits-GH153649.cpp | 15 +++++++++++++++ clang/lib/Sema/SemaDeclCXX.cpp | 5 ++++- clang/test/Analysis/anonymous-decls.cpp | 4 ++-- 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits-GH153649.cpp diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits-GH153649.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits-GH153649.cpp new file mode 100644 index 0000000000000..142eb5847ae10 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits-GH153649.cpp @@ -0,0 +1,15 @@ +// RUN: %check_clang_tidy -std=c++20 %s modernize-type-traits %t + +namespace std { +template <class> struct tuple_size { + static const int value = 1; +}; +template <int, class> struct tuple_element { + using type = int; +}; +} + +struct A {}; +template <int> int get(const A&); + +auto [a] = A(); diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index dd66a5f15a970..2ba4f062b61e9 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -1373,10 +1373,13 @@ static bool checkTupleLikeDecomposition(Sema &S, S.BuildReferenceType(T, E.get()->isLValue(), Loc, B->getDeclName()); if (RefType.isNull()) return true; + + // Don't give this VarDecl a TypeSourceInfo, since this is a synthesized + // entity and this type was never written in source code. auto *RefVD = VarDecl::Create( S.Context, Src->getDeclContext(), Loc, Loc, B->getDeclName().getAsIdentifierInfo(), RefType, - S.Context.getTrivialTypeSourceInfo(T, Loc), Src->getStorageClass()); + /*TInfo=*/nullptr, Src->getStorageClass()); RefVD->setLexicalDeclContext(Src->getLexicalDeclContext()); RefVD->setTSCSpec(Src->getTSCSpec()); RefVD->setImplicit(); diff --git a/clang/test/Analysis/anonymous-decls.cpp b/clang/test/Analysis/anonymous-decls.cpp index 3f972a33aa621..76e5155b61b67 100644 --- a/clang/test/Analysis/anonymous-decls.cpp +++ b/clang/test/Analysis/anonymous-decls.cpp @@ -78,12 +78,12 @@ int main() { // CHECK-NEXT: 8: decomposition-a-b // CHECK-NEXT: 9: [B3.7]([B3.8]) // CHECK-NEXT: 10: [B3.9] -// CHECK-NEXT: 11: std::tuple_element<0UL, std::pair<int, int>>::type a = get<0UL>(decomposition-a-b); +// CHECK-NEXT: 11: std::tuple_element<0UL, std::pair<int, int>>::type &&a = get<0UL>(decomposition-a-b); // CHECK-NEXT: 12: get<1UL> // CHECK-NEXT: 13: [B3.12] (ImplicitCastExpr, FunctionToPointerDecay, tuple_element<1L, pair<int, int> >::type (*)(pair<int, int> &)) // CHECK-NEXT: 14: decomposition-a-b // CHECK-NEXT: 15: [B3.13]([B3.14]) // CHECK-NEXT: 16: [B3.15] -// CHECK-NEXT: 17: std::tuple_element<1UL, std::pair<int, int>>::type b = get<1UL>(decomposition-a-b); +// CHECK-NEXT: 17: std::tuple_element<1UL, std::pair<int, int>>::type &&b = get<1UL>(decomposition-a-b); // CHECK-NEXT: Preds (1): B1 // CHECK-NEXT: Succs (1): B2 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits