Author: Timm Baeder Date: 2026-03-31T11:23:14+02:00 New Revision: ad0cd387c0e9458e54db7817b57f822cc4d14dec
URL: https://github.com/llvm/llvm-project/commit/ad0cd387c0e9458e54db7817b57f822cc4d14dec DIFF: https://github.com/llvm/llvm-project/commit/ad0cd387c0e9458e54db7817b57f822cc4d14dec.diff LOG: [clang][bytecode] Fix a crash with void declarations (#189334) The `chk` decl is erroneous, but we shouldn't crash. Added: Modified: clang/lib/AST/ByteCode/Compiler.cpp clang/test/AST/ByteCode/records.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index c7f074c9efc6a..75841c4378d21 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -5293,7 +5293,7 @@ Compiler<Emitter>::visitVarDecl(const VarDecl *VD, const Expr *Init, VD->getType().isVolatileQualified(), ScopeKind::Block, IsConstexprUnknown); - if (!Init) + if (!Init || Init->getType()->isVoidType()) return true; // If this is a toplevel declaration, create a scope for the diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp index a6aea0458e4ed..db02a7d23151e 100644 --- a/clang/test/AST/ByteCode/records.cpp +++ b/clang/test/AST/ByteCode/records.cpp @@ -1910,3 +1910,22 @@ namespace VirtCallNoRecord { int bar(int{((S *const)0)->foo()}); } +namespace ErroneousVoidDecl { +#if __cplusplus >= 201703L + struct S {}; + template <auto V> struct M; + template <typename C, int N1, int N2> auto f(const C &, M<N1> *, M<N1> *) {} // both-note {{couldn't infer template argument}} + + template <typename F, typename C, typename N1, typename N2> + constexpr bool check(const C &c, N1 *n1, N2 *n2) { + decltype(f(c, n1, n2)) *chk{}; // both-error {{no matching function}} \ + // ref-note {{destroying object 'chk' whose lifetime has already ended}} + return true; + } + + template <int N> constexpr M<N> *bar() { return nullptr; } + static_assert(check<S>([](int n) constexpr {}, bar<1u>(), bar<1u>())); // both-note {{in instantiation}} \ + // ref-error {{not an integral constant expression}} \ + // ref-note {{in call to}} +#endif +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
