Skip to content

Commit 336d735

Browse files
committed
[clang][bytecode] Fix lookup in source locations in implicit ctors
Implicit functions may still have a body. The !hasBody() check is enough.
1 parent 761bf33 commit 336d735

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

clang/lib/AST/ByteCode/InterpFrame.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,28 +210,28 @@ Pointer InterpFrame::getParamPointer(unsigned Off) {
210210
SourceInfo InterpFrame::getSource(CodePtr PC) const {
211211
// Implicitly created functions don't have any code we could point at,
212212
// so return the call site.
213-
if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
213+
if (Func && !Func->hasBody() && Caller)
214214
return Caller->getSource(RetPC);
215215

216216
return S.getSource(Func, PC);
217217
}
218218

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

223223
return S.getExpr(Func, PC);
224224
}
225225

226226
SourceLocation InterpFrame::getLocation(CodePtr PC) const {
227-
if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
227+
if (Func && !Func->hasBody() && Caller)
228228
return Caller->getLocation(RetPC);
229229

230230
return S.getLocation(Func, PC);
231231
}
232232

233233
SourceRange InterpFrame::getRange(CodePtr PC) const {
234-
if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
234+
if (Func && !Func->hasBody() && Caller)
235235
return Caller->getRange(RetPC);
236236

237237
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)