Skip to content

Commit

Permalink
Fix Bugzilla Issue 24504 - ImportC: Enum declarations with a mixture …
Browse files Browse the repository at this point in the history
…of int and uint literal values cause errors, when targeting Windows, when debug info generation is enabled.
  • Loading branch information
just-harry committed Apr 19, 2024
1 parent f1307d6 commit 81d4ded
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
15 changes: 13 additions & 2 deletions compiler/src/dmd/tocvdebug.d
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ enum CV8_NAMELENMAX = 0xffff; // length record is 16-bit only

uint cv4_Denum(EnumDeclaration e)
{
import dmd.expression : IntegerExp;

//dbg_printf("cv4_Denum(%s)\n", e.toChars());
const uint property = (!e.members || !e.memtype || !e.memtype.isintegral())
? 0x80 // enum is forward referenced or non-integer
Expand All @@ -159,7 +161,11 @@ uint cv4_Denum(EnumDeclaration e)
EnumMember sf = (*e.members)[i].isEnumMember();
if (!sf)
continue;
const value = sf.value().toInteger();

auto valueExp = sf.value();
if (auto castExp = valueExp.isCastExp())
valueExp = new IntegerExp(castExp.loc, castExp.e1.toInteger(), castExp.type);
const value = valueExp.toInteger();

// store only member's simple name
uint len = 4 + cv4_numericbytes(cast(uint)value) + cv_stringbytes(sf.toChars());
Expand Down Expand Up @@ -218,7 +224,12 @@ uint cv4_Denum(EnumDeclaration e)
continue;

ubyte* p = mc.writePtr();
dinteger_t value = sf.value().toInteger();

auto valueExp = sf.value();
if (auto castExp = valueExp.isCastExp())
valueExp = new IntegerExp(castExp.loc, castExp.e1.toInteger(), castExp.type);
dinteger_t value = valueExp.toInteger();

TOWORD(p, (config.fulltypes == CV8) ? LF_ENUMERATE_V3 : LF_ENUMERATE);
uint attribute = 0;
TOWORD(p + 2, attribute);
Expand Down
10 changes: 10 additions & 0 deletions compiler/test/compilable/test24504.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// REQUIRED_ARGS: -os=windows -g
// DISABLED: osx
// This is disabled on macOS because ld complains about _main being undefined
// when clang attempts to preprocess the C file.

typedef enum
{
HasIntAndUIntValuesInt = 0,
HasIntAndUIntValuesUInt = 0x80000000
} HasIntAndUIntValues;

0 comments on commit 81d4ded

Please sign in to comment.