Clang.jl icon indicating copy to clipboard operation
Clang.jl copied to clipboard

Conflicting `enum` and `#define` identifiers make a translated header cause `invalid redefinition of constant`

Open topolarity opened this issue 1 year ago • 2 comments

NgSpice has a habit of establishing most enum-like constants with #define: https://github.com/imr/ngspice/blob/902a62d2f442a1d8322ae4fcad35c143c7a14561/src/include/ngspice/noisedef.h#L72-L74

but then occasionally introducing an enum { ... } with the same names wrapped in an ifdef guard: https://github.com/imr/ngspice/blob/902a62d2f442a1d8322ae4fcad35c143c7a14561/src/include/ngspice/acdefs.h#L29-L35

Example:

// test1.h
#ifndef TEST_H_
#define TEST_H_
enum {
    DECADE = 1,
    OCTAVE,
    LINEAR,
};
#endif // TEST_H_
// test2.h
#ifndef TEST_H_
#define DECADE 1
#endif

result:

module TestModule

const __JL_Ctag_1 = UInt32
const DECADE = 1 % UInt32
const OCTAVE = 2 % UInt32
const LINEAR = 3 % UInt32

const DECADE = 1
# ...
end # module

It would be nice if Clang.jl either:

  • Applied the #define across header files so that the duplicate enum definition is not parsed, OR
  • Merged the enum and #define constants, since their definitions are compatible up to a difference of integer type

topolarity avatar Jan 31 '24 19:01 topolarity

As a workaround, it does work if I use a wrapper header:

// wrapper.h
#include "test1.h"
#include "test2.h"

and translate only that

topolarity avatar Jan 31 '24 19:01 topolarity

does it work if you pass a macro-define compiler flag to args?

Gnimuc avatar Feb 01 '24 10:02 Gnimuc