[llvm-bugs] [Bug 47143] New: char * const initialized with new char[strlen]() causes assertion failure for 32-bit targets

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 12 11:22:52 PDT 2020


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

            Bug ID: 47143
           Summary: char * const initialized with new char[strlen]()
                    causes assertion failure for 32-bit targets
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: john.brawn at arm.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

When the following example is compiled for a 32-bit target (I see it happening
with --target=arm or i686 but not --target=aarch64 or x86_64)

  extern "C" {
    unsigned int strlen(const char * s);
  }
  char *fn() {
    char * const ptr = new char[strlen("bla")]();
    return ptr;
  }

then it causes the assertion failure

  clang/lib/AST/ExprConstant.cpp:9089: bool (anonymous
namespace)::PointerExprEvaluator::VisitCXXNewExpr(const clang::CXXNewExpr *):
Assertion `CAT && "unexpected type for array initializer"' failed.

Doesn't happen if ptr isn't const, or if the function in the new char[] isn't
strlen, or if we have just new char[strlen("bla")] with no () after it.

-- 
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/20200812/2a13dc1f/attachment.html>


More information about the llvm-bugs mailing list