[llvm-bugs] [Bug 51105] New: wchar_t initializer causes an assert in isa

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 15 06:07:11 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51105

            Bug ID: 51105
           Summary: wchar_t initializer causes an assert in isa
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: erich.keane at intel.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Reproducer: 
wchar_t *p = (wchar_t [2]){ (L"p") };

Crash in godbolt:
https://godbolt.org/z/bedcxWjdv

Note it also happens with a non-wchar_t version of this same code:
char *p = (char [5]){ ("p") };
https://godbolt.org/z/rj5rs9E1z

Quick research shows it happens in MaybeElementDependentArrayFiller, which
doesn't seem to properly handle its 'FillerExpr' being nullptr, though it seems
like it is expected to in the caller.  

I'm not sure why this example doesn't have an 'array filler', is it supposed
to?
https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ExprConstant.cpp#L10452

Finally, here is the AST dump of the original problem:
`-VarDecl 0x13042440 <temp.cpp:1:1, col:36> col:10 p 'wchar_t *' cinit
  `-ImplicitCastExpr 0x130426d8 <col:14, col:36> 'wchar_t *'
<ArrayToPointerDecay>
    `-CompoundLiteralExpr 0x130426b0 <col:14, col:36> 'wchar_t [2]' lvalue
      `-InitListExpr 0x13042650 <col:27, col:36> 'wchar_t [2]'
        `-ConstantExpr 0x13042698 <col:29, col:34> 'wchar_t [2]'
          `-ParenExpr 0x130425e8 <col:29, col:34> 'wchar_t [2]'
            `-StringLiteral 0x130425c8 <col:30> 'wchar_t [2]' L"p"


IS this as simple as teaching MaybeElementDependentArrayFiller to know how to
handle its parameter?


Assertion:
bash-4.2$ ./bin/clang -cc1 temp.cpp -emit-llvm -o -
clang:
/iusers/ekeane1/workspaces/llvm-project/llvm/include/llvm/Support/Casting.h:104:
static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To =
clang::ImplicitValueInitExpr; From = clang::Expr]: Assertion `Val && "isa<>
used on a null pointer"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash
backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: ./bin/clang -cc1 temp.cpp -emit-llvm -o -
1.      <eof> parser at end of file
2.      temp.cpp:1:10: LLVM IR generation of declaration 'p'
3.      temp.cpp:1:10: Generating code for declaration 'p'
 #0 0x000000000551da55 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
/iusers/ekeane1/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:565:22
 #1 0x000000000551db0c PrintStackTraceSignalHandler(void*)
/iusers/ekeane1/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:632:1
 #2 0x000000000551bac9 llvm::sys::RunSignalHandlers()
/iusers/ekeane1/workspaces/llvm-project/llvm/lib/Support/Signals.cpp:76:20
 #3 0x000000000551d49d SignalHandler(int)
/iusers/ekeane1/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x00007ff24bf645e0 __restore_rt sigaction.c:0:0
 #5 0x00007ff24aadd1f7 raise (/lib64/libc.so.6+0x351f7)
 #6 0x00007ff24aade8e8 abort (/lib64/libc.so.6+0x368e8)
 #7 0x00007ff24aad6266 __assert_fail_base (/lib64/libc.so.6+0x2e266)
 #8 0x00007ff24aad6312 (/lib64/libc.so.6+0x2e312)
 #9 0x0000000005e30fe2 llvm::isa_impl_cl<clang::ImplicitValueInitExpr,
clang::Expr const*>::doit(clang::Expr const*)
/iusers/ekeane1/workspaces/llvm-project/llvm/include/llvm/Support/Casting.h:105:36
#10 0x0000000005e30c81 llvm::isa_impl_wrap<clang::ImplicitValueInitExpr,
clang::Expr const*, clang::Expr const*>::doit(clang::Expr const* const&)
/iusers/ekeane1/workspaces/llvm-project/llvm/include/llvm/Support/Casting.h:132:3
#11 0x0000000005e30b0b llvm::isa_impl_wrap<clang::ImplicitValueInitExpr,
clang::Expr const* const, clang::Expr const*>::doit(clang::Expr const* const&)
/iusers/ekeane1/workspaces/llvm-project/llvm/include/llvm/Support/Casting.h:123:77
#12 0x0000000005e306c7 bool llvm::isa<clang::ImplicitValueInitExpr, clang::Expr
const*>(clang::Expr const* const&)
/iusers/ekeane1/workspaces/llvm-project/llvm/include/llvm/Support/Casting.h:144:1
#13 0x0000000009b28a3a MaybeElementDependentArrayFiller(clang::Expr const*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/AST/ExprConstant.cpp:10452:3
#14 0x0000000009b28cfc (anonymous
namespace)::ArrayExprEvaluator::VisitInitListExpr(clang::InitListExpr const*,
clang::QualType)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/AST/ExprConstant.cpp:10496:32
#15 0x0000000009b56276 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous
namespace)::ArrayExprEvaluator, bool>::Visit(clang::Stmt const*)
/iusers/ekeane1/workspaces/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:1127:1
#16 0x0000000009b28867 EvaluateArray(clang::Expr const*, (anonymous
namespace)::LValue const&, clang::APValue&, (anonymous namespace)::EvalInfo&)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/AST/ExprConstant.cpp:10424:56
#17 0x0000000009b3a042 Evaluate(clang::APValue&, (anonymous
namespace)::EvalInfo&, clang::Expr const*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/AST/ExprConstant.cpp:14558:9
#18 0x0000000009b3a6fc EvaluateAsRValue((anonymous namespace)::EvalInfo&,
clang::Expr const*, clang::APValue&)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/AST/ExprConstant.cpp:14640:9
#19 0x0000000009b3aaf9 EvaluateAsRValue(clang::Expr const*,
clang::Expr::EvalResult&, clang::ASTContext const&, (anonymous
namespace)::EvalInfo&)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/AST/ExprConstant.cpp:14699:46
#20 0x0000000009b3ad83 clang::Expr::EvaluateAsRValue(clang::Expr::EvalResult&,
clang::ASTContext const&, bool) const
/iusers/ekeane1/workspaces/llvm-project/clang/lib/AST/ExprConstant.cpp:14747:28
#21 0x0000000005964135
clang::CodeGen::ConstantEmitter::tryEmitPrivate(clang::Expr const*,
clang::QualType)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CGExprConstant.cpp:1724:34
#22 0x0000000005963e31
clang::CodeGen::ConstantEmitter::tryEmitPrivateForMemory(clang::Expr const*,
clang::QualType)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CGExprConstant.cpp:1673:37
#23 0x0000000005962dd1
clang::CodeGen::ConstantEmitter::tryEmitForInitializer(clang::Expr const*,
clang::LangAS, clang::QualType)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CGExprConstant.cpp:1416:22
#24 0x0000000005961176 (anonymous
namespace)::tryEmitGlobalCompoundLiteral(clang::CodeGen::CodeGenModule&,
clang::CodeGen::CodeGenFunction*, clang::CompoundLiteralExpr const*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CGExprConstant.cpp:907:52
#25 0x0000000005964bbd (anonymous
namespace)::ConstantLValueEmitter::VisitCompoundLiteralExpr(clang::CompoundLiteralExpr
const*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CGExprConstant.cpp:1939:58
#26 0x000000000596b412 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous
namespace)::ConstantLValueEmitter, (anonymous
namespace)::ConstantLValue>::Visit(clang::Stmt const*)
/iusers/ekeane1/workspaces/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:985:1
#27 0x0000000005964b0d (anonymous
namespace)::ConstantLValueEmitter::tryEmitBase(clang::APValue::LValueBase
const&)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CGExprConstant.cpp:1928:1
#28 0x0000000005964531 (anonymous namespace)::ConstantLValueEmitter::tryEmit()
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CGExprConstant.cpp:1838:43
#29 0x000000000596537d
clang::CodeGen::ConstantEmitter::tryEmitPrivate(clang::APValue const&,
clang::QualType)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CGExprConstant.cpp:2042:65
#30 0x0000000005963ea1
clang::CodeGen::ConstantEmitter::tryEmitPrivateForMemory(clang::APValue const&,
clang::QualType)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CGExprConstant.cpp:1680:26
#31 0x0000000005963c39
clang::CodeGen::ConstantEmitter::tryEmitPrivateForVarInit(clang::VarDecl
const&)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CGExprConstant.cpp:1634:52
#32 0x0000000005962d7d
clang::CodeGen::ConstantEmitter::tryEmitForInitializer(clang::VarDecl const&)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CGExprConstant.cpp:1409:22
#33 0x0000000005a65b9e
clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*,
bool)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:4342:65
#34 0x0000000005a60a90
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3218:60
#35 0x0000000005a5fad0
clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:2967:5
#36 0x0000000005a6b4ee
clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:5696:47
#37 0x0000000006b324d8 (anonymous
namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:169:7
#38 0x0000000006b2bbfc
clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:217:11
#39 0x0000000008495260 clang::ParseAST(clang::Sema&, bool, bool)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Parse/ParseAST.cpp:162:20
#40 0x00000000061cbb5b clang::ASTFrontendAction::ExecuteAction()
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1058:11
#41 0x0000000006b2950b clang::CodeGenAction::ExecuteAction()
/iusers/ekeane1/workspaces/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1045:5
#42 0x00000000061cb487 clang::FrontendAction::Execute()
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Frontend/FrontendAction.cpp:955:38
#43 0x0000000006115733
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:974:42
#44 0x000000000634b394
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:278:38
#45 0x00000000025c0829 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*)
/iusers/ekeane1/workspaces/llvm-project/clang/tools/driver/cc1_main.cpp:246:40
#46 0x00000000025b58a5 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
/iusers/ekeane1/workspaces/llvm-project/clang/tools/driver/driver.cpp:338:20
#47 0x00000000025b5f73 main
/iusers/ekeane1/workspaces/llvm-project/clang/tools/driver/driver.cpp:415:26
#48 0x00007ff24aac9c05 __libc_start_main (/lib64/libc.so.6+0x21c05)
#49 0x00000000025b4119 _start (./bin/clang+0x25b4119)
Aborted (core dumped)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210715/40431c0b/attachment-0001.html>


More information about the llvm-bugs mailing list