From: Ted Kremenek Date: Sat, 18 Oct 2008 22:20:20 +0000 (+0000) Subject: Add support in GRExprEngine for UnaryOperator::AlignOf. This fixes one crash report... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6dfe2f544a5e601bd5ac1a7e31af17ec3bf1fe01;p=clang Add support in GRExprEngine for UnaryOperator::AlignOf. This fixes one crash report in PR 2796. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57777 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index d122dca019..98fa58f5dd 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -1780,6 +1780,23 @@ void GRExprEngine::VisitUnaryOperator(UnaryOperator* U, NodeTy* Pred, return; } + + case UnaryOperator::AlignOf: { + + QualType T = U->getSubExpr()->getType(); + + // FIXME: Add support for VLAs. + + if (!T.getTypePtr()->isConstantSizeType()) + return; + + uint64_t size = getContext().getTypeAlign(T) / 8; + const GRState* St = GetState(Pred); + St = SetSVal(St, U, NonLoc::MakeVal(getBasicVals(), size, U->getType())); + + MakeNode(Dst, U, Pred, St); + return; + } case UnaryOperator::SizeOf: { diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m index f96b1a22c7..ab00bd8c34 100644 --- a/test/Analysis/misc-ps.m +++ b/test/Analysis/misc-ps.m @@ -9,3 +9,7 @@ } @end +// Reduced test case from crash in PR 2796; +// http://llvm.org/bugs/show_bug.cgi?id=2796 + +unsigned foo(unsigned x) { return __alignof__((x)) + sizeof(x); }