Skip to content

DeclRefExpr and EnumConstantDecl have different signedness #2464

@tkremenek

Description

@tkremenek
Bugzilla Link 2092
Resolution FIXED
Resolved on Nov 07, 2018 00:22
Version unspecified
OS All

Extended Description

Consider the following code:

enum prefixes { PPS_LREP, PPS_SEG, PPS_OSIZE, PPS_ASIZE, MAXPREFIX };

int assemble () {
int j = 0;
return j < MAXPREFIX;
}

In the return statement, the AST node for MAXPREFIX is a DeclRefExpr that references an EnumConstantDecl for MAXPREFIX. This DeclRefExpr has type 'int', which represents a signed integer. The EnumConstantDecl for MAXPREFIX constants an APSInt object that represents an integer constant; this APSInt object, however, is marked "unsigned" (i.e., the method APSINT::isUnsigned() returns true). Here is the AST dump:

int assemble()
(CompoundStmt 0x9065e0 <assemble.i:7:17, line:10:1>
(DeclStmt 0x906350 <:0:0>
0x906520 "int j =
(IntegerLiteral 0x906550 assemble.i:8:11 'int' 0)"
(ReturnStmt 0x9065d0 <line:9:3, col:14>
(BinaryOperator 0x9065b0 <col:10, col:14> 'int' '<'
(DeclRefExpr 0x906570 col:10 'int' BlockVar='j' 0x906520)
(DeclRefExpr 0x906590 col:14 'int' EnumConstant='MAXPREFIX' 0x9063f0))))

The bug is that either the DeclRefExpr that wraps the EnumConstant should have an unsigned type (and thus we should have an implicit cast somewhere) or that the internal APSInt value of the EnumConstant should be marked signed.

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