Skip to content

Commit d03822d

Browse files
authored
[clang][bytecode] Fix lookup of source locations in implicit ctors (#107992)
Implicit functions may still have a body. The !hasBody() check is enough.
1 parent 6bbf7f0 commit d03822d

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

clang/lib/AST/ByteCode/InterpFrame.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,31 +207,40 @@ Pointer InterpFrame::getParamPointer(unsigned Off) {
207207
return Pointer(B);
208208
}
209209

210+
static bool funcHasUsableBody(const Function *F) {
211+
assert(F);
212+
213+
if (F->isConstructor() || F->isDestructor())
214+
return true;
215+
216+
return !F->getDecl()->isImplicit();
217+
}
218+
210219
SourceInfo InterpFrame::getSource(CodePtr PC) const {
211220
// Implicitly created functions don't have any code we could point at,
212221
// so return the call site.
213-
if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
222+
if (Func && !funcHasUsableBody(Func) && Caller)
214223
return Caller->getSource(RetPC);
215224

216225
return S.getSource(Func, PC);
217226
}
218227

219228
const Expr *InterpFrame::getExpr(CodePtr PC) const {
220-
if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
221-
return Caller->getExpr(RetPC);
229+
if (Func && !funcHasUsableBody(Func) && Caller)
230+
return Caller->getExpr(PC);
222231

223232
return S.getExpr(Func, PC);
224233
}
225234

226235
SourceLocation InterpFrame::getLocation(CodePtr PC) const {
227-
if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
236+
if (Func && !funcHasUsableBody(Func) && Caller)
228237
return Caller->getLocation(RetPC);
229238

230239
return S.getLocation(Func, PC);
231240
}
232241

233242
SourceRange InterpFrame::getRange(CodePtr PC) const {
234-
if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
243+
if (Func && !funcHasUsableBody(Func) && Caller)
235244
return Caller->getRange(RetPC);
236245

237246
return S.getRange(Func, PC);

clang/test/AST/ByteCode/builtin-functions.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,3 +968,10 @@ namespace FunctionStart {
968968
static_assert(__builtin_function_start(a) == a, ""); // both-error {{not an integral constant expression}} \
969969
// both-note {{comparison of addresses of literals has unspecified value}}
970970
}
971+
972+
namespace BuiltinInImplicitCtor {
973+
constexpr struct {
974+
int a = __builtin_isnan(1.0);
975+
} Foo;
976+
static_assert(Foo.a == 0, "");
977+
}

0 commit comments

Comments
 (0)