Skip to content

Commit 6ea0f3f

Browse files
committed
fixup! ignore implicit function call in IgnoreUnlessSpelledInSource
1 parent 6694000 commit 6ea0f3f

File tree

3 files changed

+53
-29
lines changed

3 files changed

+53
-29
lines changed

clang/lib/AST/Expr.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3159,10 +3159,24 @@ Expr *Expr::IgnoreUnlessSpelledInSource() {
31593159
}
31603160
return E;
31613161
};
3162+
3163+
auto IgnoreImplicitCallSingleStep = [](Expr *E) {
3164+
if (auto *C = dyn_cast<CallExpr>(E)) {
3165+
auto NumArgs = C->getNumArgs();
3166+
if (NumArgs == 1 ||
3167+
(NumArgs > 1 && isa<CXXDefaultArgExpr>(C->getArg(1)))) {
3168+
Expr *A = C->getArg(0);
3169+
if (A->getSourceRange() == E->getSourceRange())
3170+
return A;
3171+
}
3172+
}
3173+
return E;
3174+
};
3175+
31623176
return IgnoreExprNodes(
31633177
this, IgnoreImplicitSingleStep, IgnoreImplicitCastsExtraSingleStep,
31643178
IgnoreParensOnlySingleStep, IgnoreImplicitConstructorSingleStep,
3165-
IgnoreImplicitMemberCallSingleStep);
3179+
IgnoreImplicitMemberCallSingleStep, IgnoreImplicitCallSingleStep);
31663180
}
31673181

31683182
bool Expr::isDefaultArgument() const {

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,32 +87,6 @@ static bool IsDecomposedVarDecl(VarDecl const *VD) {
8787
if (!Init)
8888
return false;
8989

90-
Init = Init->IgnoreUnlessSpelledInSource();
91-
if (!Init)
92-
return false;
93-
94-
// For tuple-like decompositions, if the `get` function
95-
// is not a member of the decomposed type, but instead a
96-
// free function (e.g., how std::get is specialized for
97-
// std::pair), then the initializer is a `CallExpr` and
98-
// we need to dig into the argument before unwrapping it
99-
// with IgnoreUnlessSpelledInSource.
100-
if (auto const *CE = llvm::dyn_cast<CallExpr>(Init)) {
101-
if (CE->getNumArgs() == 0)
102-
return false;
103-
104-
// The first argument will be the type we're decomposing.
105-
// Technically the getter could have more than 1 argument
106-
// (e.g., if they're defaulted arguments), but we don't care
107-
// about them because we just need to check whether the
108-
// first argument is a DecompositionDecl.
109-
auto const *Arg = CE->getArg(0);
110-
if (!Arg)
111-
return false;
112-
113-
Init = Arg;
114-
}
115-
11690
auto const *RefExpr =
11791
llvm::dyn_cast_or_null<DeclRefExpr>(Init->IgnoreUnlessSpelledInSource());
11892
if (!RefExpr)

clang/test/DebugInfo/CXX/structured-binding.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -triple %itanium_abi_triple %s -o - | FileCheck %s --implicit-check-not="call void @llvm.dbg.declare"
1+
// RUN: %clang_cc1 -std=c++23 -emit-llvm -debug-info-kind=standalone -triple %itanium_abi_triple %s -o - | FileCheck %s --implicit-check-not="call void @llvm.dbg.declare"
22

33
// CHECK: define {{.*}} i32 @_Z1fv
44
// CHECK: #dbg_declare(ptr %{{[a-z]+}}, ![[VAR_0:[0-9]+]], !DIExpression(),
@@ -17,6 +17,10 @@
1717
// CHECK: #dbg_declare(ptr %k, ![[VAR_7:[0-9]+]], !DIExpression()
1818
// CHECK: #dbg_declare(ptr %v, ![[VAR_8:[0-9]+]], !DIExpression()
1919
// CHECK: #dbg_declare(ptr %w, ![[VAR_9:[0-9]+]], !DIExpression()
20+
// CHECK: #dbg_declare(ptr %m, ![[VAR_10:[0-9]+]], !DIExpression()
21+
// CHECK: #dbg_declare(ptr %n, ![[VAR_11:[0-9]+]], !DIExpression()
22+
// CHECK: #dbg_declare(ptr %s, ![[VAR_12:[0-9]+]], !DIExpression()
23+
// CHECK: #dbg_declare(ptr %p, ![[VAR_13:[0-9]+]], !DIExpression()
2024
// CHECK: ![[VAR_0]] = !DILocalVariable(name: "a"
2125
// CHECK: ![[VAR_1]] = !DILocalVariable(name: "x1", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
2226
// CHECK: ![[VAR_2]] = !DILocalVariable(name: "y1", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
@@ -27,6 +31,10 @@
2731
// CHECK: ![[VAR_7]] = !DILocalVariable(name: "k", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
2832
// CHECK: ![[VAR_8]] = !DILocalVariable(name: "v", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
2933
// CHECK: ![[VAR_9]] = !DILocalVariable(name: "w", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
34+
// CHECK: ![[VAR_10]] = !DILocalVariable(name: "m", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
35+
// CHECK: ![[VAR_11]] = !DILocalVariable(name: "n", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
36+
// CHECK: ![[VAR_12]] = !DILocalVariable(name: "s", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
37+
// CHECK: ![[VAR_13]] = !DILocalVariable(name: "p", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
3038

3139
struct A {
3240
int x;
@@ -41,6 +49,22 @@ struct B {
4149
template<> int get<1>() { return z; }
4250
};
4351

52+
struct C {
53+
int w;
54+
int z;
55+
template<int> int get(this C&& self);
56+
template<> int get<0>(this C&& self) { return self.w; }
57+
template<> int get<1>(this C&& self) { return self.z; }
58+
};
59+
60+
struct D {
61+
int w;
62+
int z;
63+
template<int> int get(int unused = 0);
64+
template<> int get<0>(int unused) { return w; }
65+
template<> int get<1>(int unused) { return z; }
66+
};
67+
4468
// Note: the following declarations are necessary for decomposition of tuple-like
4569
// structured bindings
4670
namespace std {
@@ -51,6 +75,16 @@ struct tuple_size<B> {
5175
static constexpr unsigned value = 2;
5276
};
5377

78+
template<>
79+
struct tuple_size<C> {
80+
static constexpr unsigned value = 2;
81+
};
82+
83+
template<>
84+
struct tuple_size<D> {
85+
static constexpr unsigned value = 2;
86+
};
87+
5488
template<unsigned, typename T> struct tuple_element { using type = int; };
5589

5690
// Decomposition of tuple-like bindings but where the `get` methods
@@ -115,5 +149,7 @@ int f() {
115149
v2 //
116150
;
117151
auto [k, v, w] = std::triple{3, 4, 5};
118-
return x1 + y1 + x2 + y2 + z1 + z2 + k + v + w;
152+
auto [m, n] = C{2, 3};
153+
auto [s, p] = D{2, 3};
154+
return x1 + y1 + x2 + y2 + z1 + z2 + k + v + w + m + n + s + p;
119155
}

0 commit comments

Comments
 (0)