Bug Patch for MSVC

Hi,

   There is a small bug in the actual clang code when compiling with visual studio 8.0 . For VS, the enum are signed so when an enum is used in a bit field just the right size, it get sign exteded when you read it and this cause problems (here it perturb isa<> so clang can't compile a function definition...)

here is the patch (not a true patch since I don't have svn acces from where I am)

file: /include/clang/AST/Type.h
lines: 199 to 216

  class Type {
  public:
- enum TypeClass {
+ enum TypeClass : unsigned int {
      Builtin, Complex, Pointer, Reference,
      ConstantArray, VariableArray,
      Vector, OCUVector,
      FunctionNoProto, FunctionProto,
      TypeName, Tagged,
      ObjcInterface,
      TypeOfExp, TypeOfTyp // GNU typeof extension.
    };
  private:
    QualType CanonicalType;

   /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
   /// Note that this should stay at the end of the ivars for Type so that
   /// subclasses can pack their bitfields into the same word.
   TypeClass TC : 4;

another alternative is to make the TC bit field 5 bits wide. This is the choice llvm made in one of is class.

best regards,

      Hi,

   There is a small bug in the actual clang code when compiling with
visual studio 8.0 . For VS, the enum are signed so when an enum is
used in a bit field just the right size, it get sign exteded when you
read it and this cause problems (here it perturb isa<> so clang can't
compile a function definition...)

Ok.

here is the patch (not a true patch since I don't have svn acces from
where I am)

file: /include/clang/AST/Type.h
lines: 199 to 216

  class Type {
  public:
- enum TypeClass {
+ enum TypeClass : unsigned int {

This isn't valid C++ Syntax.

    QualType CanonicalType;

   /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
   /// Note that this should stay at the end of the ivars for Type so that
   /// subclasses can pack their bitfields into the same word.
   TypeClass TC : 4;

another alternative is to make the TC bit field 5 bits wide. This is
the choice llvm made in one of is class.

I'd suggest changing getTypeClass() to do the appropriate masking.

-Chris

Chris,

> QualType CanonicalType;
>
> /// TypeClass bitfield - Enum that specifies what subclass this
> belongs to.
> /// Note that this should stay at the end of the ivars
for Type so
> that
> /// subclasses can pack their bitfields into the same word.
> TypeClass TC : 4;
>
> another alternative is to make the TC bit field 5 bits
wide. This is
> the choice llvm made in one of is class.

I'd suggest changing getTypeClass() to do the appropriate masking.

FWIW, that's exactly what I did a couple of days ago.
Are there other places in clang where bitmasks are used?

Regards Hartmut

The specific sticking issue seems to be enum bitfields. The other solution would be to declare TC as:

  unsigned TC : 4;

and then return (TypeClass)TC; in getTypeClass(). This is probably the cleanest solution.

-Chris

Done.

Regards Hartmut