<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - wchar_t initializer causes an assert in isa"
   href="https://bugs.llvm.org/show_bug.cgi?id=51105">51105</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>wchar_t initializer causes an assert in isa
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>erich.keane@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Reproducer: 
wchar_t *p = (wchar_t [2]){ (L"p") };

Crash in godbolt:
<a href="https://godbolt.org/z/bedcxWjdv">https://godbolt.org/z/bedcxWjdv</a>

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

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?
<a href="https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ExprConstant.cpp#L10452">https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ExprConstant.cpp#L10452</a>

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 <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> 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)</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>