Skip to content

Commit

Permalink
Added masking to clang_getConstantIntegerValue.
Browse files Browse the repository at this point in the history
  • Loading branch information
vsajip committed Sep 26, 2011
1 parent cdb67c7 commit 0c5d826
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3280,11 +3280,13 @@ long long clang_getConstantIntegerValue(CXCursor C) {

if (isa<EnumConstantDecl> (D)) { // this check may not be needed
llvm::APSInt Value = static_cast<EnumConstantDecl *> (D)->getInitVal();
long long mask = Value.getAllOnesValue(Value.getBitWidth()).getZExtValue();

if (Value.isSigned())
result = Value.getSExtValue();
else
result = Value.getZExtValue();
result &= mask;
}
} else if (C.kind == CXCursor_UnexposedAttr) {
Attr * A = getCursorAttr(C);
Expand All @@ -3295,11 +3297,13 @@ long long clang_getConstantIntegerValue(CXCursor C) {
CXTranslationUnit tu = getCursorTU(C);
ASTUnit *CXXUnit = static_cast<ASTUnit*> (tu->TUData);
llvm::APSInt Value = E->EvaluateAsInt(CXXUnit->getASTContext());
long long mask = Value.getAllOnesValue(Value.getBitWidth()).getZExtValue();

if (Value.isSigned())
result = Value.getSExtValue();
else
result = Value.getZExtValue();
result &= mask;
}
return result;
}
Expand Down

0 comments on commit 0c5d826

Please sign in to comment.