[cfe-dev] clang-cc assert when compiling a simple program

Zheng, Bixia Bixia.Zheng at amd.com
Fri Apr 3 11:17:37 PDT 2009


Hi,

 

I hit this assertion when compiling a simple program (pasted to end of
msg).

 

    assert((PtrVal & ((1 << PtrTraits::NumLowBitsAvailable)-1)) == 0 &&

           "Pointer is not sufficiently aligned");

 

 

Call stack

--------------

>          clang-cc.exe!llvm::PointerIntPair<clang::ActionBase
*,1,bool,llvm::PointerLikeTypeTraits<clang::ActionBase *>
>::setPointer(clang::ActionBase * Ptr=0x025aefbc)  + 0x34 bytes  C++

            clang-cc.exe!llvm::PointerIntPair<clang::ActionBase
*,1,bool,llvm::PointerLikeTypeTraits<clang::ActionBase *>
>::PointerIntPair<clang::ActionBase
*,1,bool,llvm::PointerLikeTypeTraits<clang::ActionBase *>
>(clang::ActionBase * Ptr=0x025aefbc, bool Int=false)  + 0x54 bytes
C++

 
clang-cc.exe!clang::ASTOwningResult<&clang::ActionBase::`vcall'{8}'>::AS
TOwningResult<&clang::ActionBase::`vcall'{8}'>(clang::ActionBase &
actions={...}, bool invalid=false)  + 0x1f bytes      C++

            clang-cc.exe!clang::Parser::ParseCompoundStatementBody(bool
isStmtExpr=false)  + 0xe6 bytes  C++

 
clang-cc.exe!clang::Parser::ParseFunctionStatementBody(clang::OpaquePtr<
0> Decl={...})  + 0xc6 bytes    C++

 
clang-cc.exe!clang::Parser::ParseFunctionDefinition(clang::Declarator &
D={...})  + 0x214 bytes       C++

 
clang-cc.exe!clang::Parser::ParseDeclarationOrFunctionDefinition(llvm::S
mallVector<void *,4> * TemplateParams=0x00000000, clang::AccessSpecifier
AS=AS_none)  + 0x61c bytes        C++

 

 

The debugger shows PtrTraits::NumLowBitsAvailable == 3.

 

Adding this code block to the beginning of ownership.h make the problem
go away:

namespace clang {

  class ActionBase;

}

namespace llvm {

 

  template<>

  class PointerLikeTypeTraits<clang::ActionBase*> {

    typedef clang::ActionBase* PT;

public:

  static inline void *getAsVoidPointer(PT P) { return P; }

  static inline PT getFromVoidPointer(void *P) {

    return static_cast<PT>(P);

  }

  enum { NumLowBitsAvailable = 2 };

};

}

 

I used cmake generated visual studio projects and compiled it with
visual studio 9.0. 

Please let me know if you have more information on this, such as whether
the problem is specific to the compiler I used and whether my fix is
proper.

 

 

test program

------------------

float foo(float i)

{

    return sin(i);

}

 

Thanks!

 

bixia

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090403/720c9d4b/attachment.html>


More information about the cfe-dev mailing list