Skip to content

clang AST crashes on invalid decl type.Assertion `getType(Base)->isPointerType() || getType(Base)->isArrayType()' failed #118073

@mainsea

Description

@mainsea

The provided test case contains compilation errors, and in clang/lib/AST/APValue.cpp, the method QualType APValue::LValueBase::getType() const is noted to handle ValueDecl in an inadequate way for similar situations.

// FIXME: It's unclear where we're supposed to take the type from, and
// this actually matters for arrays of unknown bound. Eg:
//
// extern int arr[]; void f() { extern int arr[3]; };
// constexpr int *p = &arr[1]; // valid?
//
// For now, we take the most complete type we can find.

The possible reason is that the obtained decl is an invalid decl, causing it to lose its int[] type attribute.

crash example like:

extern int error_names_array[total_error_count + 2];
extern int error_names_array[];
static int *sqlstate_map = &error_names_array[1];

Is this a common way of handling the situation? When Clang detects a compilation error, certain unhandled cases can cause the Clang frontend to crash.However, in my opinion, it should at least not result in a crash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"crashPrefer [crash-on-valid] or [crash-on-invalid]duplicateResolved as duplicate

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions