[cfe-commits] r42061 - /cfe/trunk/include/clang/AST/Type.h

Hartmut Kaiser hartmut.kaiser at gmail.com
Mon Sep 17 14:11:08 PDT 2007


Author: hkaiser
Date: Mon Sep 17 16:11:08 2007
New Revision: 42061

URL: http://llvm.org/viewvc/llvm-project?rev=42061&view=rev
Log:
Fixed a VC++ issue related to bitmasks. As it turns out the compiler fills the unused bits of the word a bitmask is stored in with '1' (or randomly, I can't tell, I've seen '1' so far only), which creates wrong results in certain cases.

Please review.

Modified:
    cfe/trunk/include/clang/AST/Type.h

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=42061&r1=42060&r2=42061&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Sep 17 16:11:08 2007
@@ -222,7 +222,10 @@
   virtual ~Type();
   friend class ASTContext;
 public:
-  TypeClass getTypeClass() const { return TC; }
+  // Masking the 4 bits from the bitfield above is necessary, since at least
+  // VC++ fills the unused bits of the word the bitfield is stored in with
+  // '1' resulting in invalid values returned from this function otherwise.
+  TypeClass getTypeClass() const { return static_cast<TypeClass>(TC & 0xf); }
   
   bool isCanonical() const { return CanonicalType.getTypePtr() == this; }
 





More information about the cfe-commits mailing list