Skip to content

Commit 60cfb2c

Browse files
committed
fixup! ignore implicit function call in IgnoreUnlessSpelledInSource
1 parent ad5c1a9 commit 60cfb2c

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
@@ -3183,10 +3183,24 @@ Expr *Expr::IgnoreUnlessSpelledInSource() {
31833183
}
31843184
return E;
31853185
};
3186+
3187+
auto IgnoreImplicitCallSingleStep = [](Expr *E) {
3188+
if (auto *C = dyn_cast<CallExpr>(E)) {
3189+
auto NumArgs = C->getNumArgs();
3190+
if (NumArgs == 1 ||
3191+
(NumArgs > 1 && isa<CXXDefaultArgExpr>(C->getArg(1)))) {
3192+
Expr *A = C->getArg(0);
3193+
if (A->getSourceRange() == E->getSourceRange())
3194+
return A;
3195+
}
3196+
}
3197+
return E;
3198+
};
3199+
31863200
return IgnoreExprNodes(
31873201
this, IgnoreImplicitSingleStep, IgnoreImplicitCastsExtraSingleStep,
31883202
IgnoreParensOnlySingleStep, IgnoreImplicitConstructorSingleStep,
3189-
IgnoreImplicitMemberCallSingleStep);
3203+
IgnoreImplicitMemberCallSingleStep, IgnoreImplicitCallSingleStep);
31903204
}
31913205

31923206
bool Expr::isDefaultArgument() const {

clang/lib/CodeGen/CGDebugInfo.cpp

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

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

clang/test/CodeGenCXX/debug-info-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(),
@@ -11,6 +11,10 @@
1111
// CHECK: #dbg_declare(ptr %k, ![[VAR_7:[0-9]+]], !DIExpression()
1212
// CHECK: #dbg_declare(ptr %v, ![[VAR_8:[0-9]+]], !DIExpression()
1313
// CHECK: #dbg_declare(ptr %w, ![[VAR_9:[0-9]+]], !DIExpression()
14+
// CHECK: #dbg_declare(ptr %m, ![[VAR_10:[0-9]+]], !DIExpression()
15+
// CHECK: #dbg_declare(ptr %n, ![[VAR_11:[0-9]+]], !DIExpression()
16+
// CHECK: #dbg_declare(ptr %s, ![[VAR_12:[0-9]+]], !DIExpression()
17+
// CHECK: #dbg_declare(ptr %p, ![[VAR_13:[0-9]+]], !DIExpression()
1418
// CHECK: ![[VAR_0]] = !DILocalVariable(name: "a"
1519
// CHECK: ![[VAR_1]] = !DILocalVariable(name: "x1", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
1620
// CHECK: ![[VAR_2]] = !DILocalVariable(name: "y1", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
@@ -21,6 +25,10 @@
2125
// CHECK: ![[VAR_7]] = !DILocalVariable(name: "k", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
2226
// CHECK: ![[VAR_8]] = !DILocalVariable(name: "v", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
2327
// CHECK: ![[VAR_9]] = !DILocalVariable(name: "w", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
28+
// CHECK: ![[VAR_10]] = !DILocalVariable(name: "m", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
29+
// CHECK: ![[VAR_11]] = !DILocalVariable(name: "n", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
30+
// CHECK: ![[VAR_12]] = !DILocalVariable(name: "s", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
31+
// CHECK: ![[VAR_13]] = !DILocalVariable(name: "p", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
2432

2533
struct A {
2634
int x;
@@ -35,6 +43,22 @@ struct B {
3543
template<> int get<1>() { return z; }
3644
};
3745

46+
struct C {
47+
int w;
48+
int z;
49+
template<int> int get(this C&& self);
50+
template<> int get<0>(this C&& self) { return self.w; }
51+
template<> int get<1>(this C&& self) { return self.z; }
52+
};
53+
54+
struct D {
55+
int w;
56+
int z;
57+
template<int> int get(int unused = 0);
58+
template<> int get<0>(int unused) { return w; }
59+
template<> int get<1>(int unused) { return z; }
60+
};
61+
3862
// Note: the following declarations are necessary for decomposition of tuple-like
3963
// structured bindings
4064
namespace std {
@@ -45,6 +69,16 @@ struct tuple_size<B> {
4569
static constexpr unsigned value = 2;
4670
};
4771

72+
template<>
73+
struct tuple_size<C> {
74+
static constexpr unsigned value = 2;
75+
};
76+
77+
template<>
78+
struct tuple_size<D> {
79+
static constexpr unsigned value = 2;
80+
};
81+
4882
template<unsigned, typename T> struct tuple_element { using type = int; };
4983

5084
// Decomposition of tuple-like bindings but where the `get` methods
@@ -72,5 +106,7 @@ int f() {
72106
auto &[x2, y2] = a;
73107
auto [z1, z2] = B{1, 2};
74108
auto [k, v, w] = std::triple{3, 4, 5};
75-
return x1 + y1 + x2 + y2 + z1 + z2 + k + v + w;
109+
auto [m, n] = C{2, 3};
110+
auto [s, p] = D{2, 3};
111+
return x1 + y1 + x2 + y2 + z1 + z2 + k + v + w + m + n + s + p;
76112
}

0 commit comments

Comments
 (0)