Skip to content

clang::CompoundLiteralExpr::Init can be NULL, consequently getInitializer() must use cast_or_null. #3641

@llvmbot

Description

@llvmbot
Bugzilla Link 3269
Resolution FIXED
Resolved on Mar 12, 2010 00:59
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor
CC @efriedma-quic

Extended Description

To see a case where CompoundLiteralExpr::Init is null:

  • modify getSourceRange() adding `assert(Init && "Init CAN be null.");' as first line of the function body.
  • compile clang
  • exec the new clang with this code:
    ---->
    struct S {
    char a[2]; int b; };
    int f() {
    return __builtin_offsetof(struct S, b); }
    ----<

The assertion will fail, and since the compound literal do not actually have an init expression it is correct.
Yet, the getInitializer() functions use cast() that crashes in case of null pointers. It must be changed to cast_or_null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions