From: Hartmut Kaiser Date: Mon, 17 Sep 2007 21:11:08 +0000 (+0000) Subject: Fixed a VC++ issue related to bitmasks. As it turns out the compiler fills the unused... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0bcccc763bef79171015c3b270e505b9c864ea8b;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42061 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 9c853e321b..d99babb4c1 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -222,7 +222,10 @@ protected: 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(TC & 0xf); } bool isCanonical() const { return CanonicalType.getTypePtr() == this; }