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 d122dca..98fa58f 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -1780,6 +1780,23 @@
       
       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 f96b1a2..ab00bd8 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); }