https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/107992
Implicit functions may still have a body. The !hasBody() check is enough. >From 336d735f9c40987b3c31d3422747d403dd6d6165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Tue, 10 Sep 2024 11:39:38 +0200 Subject: [PATCH] [clang][bytecode] Fix lookup in source locations in implicit ctors Implicit functions may still have a body. The !hasBody() check is enough. --- clang/lib/AST/ByteCode/InterpFrame.cpp | 10 +++++----- clang/test/AST/ByteCode/builtin-functions.cpp | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp index 6830a7b37f1da5..6c1e446458dc57 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.cpp +++ b/clang/lib/AST/ByteCode/InterpFrame.cpp @@ -210,28 +210,28 @@ Pointer InterpFrame::getParamPointer(unsigned Off) { SourceInfo InterpFrame::getSource(CodePtr PC) const { // Implicitly created functions don't have any code we could point at, // so return the call site. - if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller) + if (Func && !Func->hasBody() && Caller) return Caller->getSource(RetPC); return S.getSource(Func, PC); } const Expr *InterpFrame::getExpr(CodePtr PC) const { - if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller) - return Caller->getExpr(RetPC); + if (Func && !Func->hasBody() && Caller) + return Caller->getExpr(PC); return S.getExpr(Func, PC); } SourceLocation InterpFrame::getLocation(CodePtr PC) const { - if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller) + if (Func && !Func->hasBody() && Caller) return Caller->getLocation(RetPC); return S.getLocation(Func, PC); } SourceRange InterpFrame::getRange(CodePtr PC) const { - if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller) + if (Func && !Func->hasBody() && Caller) return Caller->getRange(RetPC); return S.getRange(Func, PC); diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp index 9c9ca23e0a6a69..9fd5eae67a21f6 100644 --- a/clang/test/AST/ByteCode/builtin-functions.cpp +++ b/clang/test/AST/ByteCode/builtin-functions.cpp @@ -968,3 +968,10 @@ namespace FunctionStart { static_assert(__builtin_function_start(a) == a, ""); // both-error {{not an integral constant expression}} \ // both-note {{comparison of addresses of literals has unspecified value}} } + +namespace BuiltinInImplicitCtor { + constexpr struct { + int a = __builtin_isnan(1.0); + } Foo; + static_assert(Foo.a == 0, ""); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits