diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index c4bda1f..5de7f71 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -1239,12 +1239,14 @@ const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const {
   }
 }
 
-/// getDeclAlign - Return a conservative estimate of the alignment of the
-/// specified decl.  Note that bitfields do not have a valid alignment, so
-/// this method will assert on them.
-/// If @p RefAsPointee, references are treated like their underlying type
-/// (for alignof), else they're treated like pointers (for CodeGen).
-CharUnits ASTContext::getDeclAlign(const Decl *D, bool RefAsPointee) const {
+/// Return a conservative estimate of the alignment of the specified decl.
+/// Note that bitfields do not have a valid alignment, so this method will
+/// assert on them.
+/// If @p ForAlignof is true, we compute the value exposed by alignof:
+/// References are treated like their underlying type and large arrays don't
+/// get any special treatment. If @p ForAlignof is false, we comput the value
+/// to be used by CodeGen.
+CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const {
   unsigned Align = Target->getCharWidth();
 
   bool UseAlignAttrOnly = false;
@@ -1277,7 +1279,7 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool RefAsPointee) const {
   } else if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
     QualType T = VD->getType();
     if (const ReferenceType* RT = T->getAs<ReferenceType>()) {
-      if (RefAsPointee)
+      if (ForAlignof)
         T = RT->getPointeeType();
       else
         T = getPointerType(RT->getPointeeType());
@@ -1285,9 +1287,9 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool RefAsPointee) const {
     if (!T->isIncompleteType() && !T->isFunctionType()) {
       // Adjust alignments of declarations with array type by the
       // large-array alignment on the target.
-      unsigned MinWidth = Target->getLargeArrayMinWidth();
       if (const ArrayType *arrayType = getAsArrayType(T)) {
-        if (MinWidth) {
+        unsigned MinWidth = Target->getLargeArrayMinWidth();
+        if (!ForAlignof && MinWidth) {
           if (isa<VariableArrayType>(arrayType))
             Align = std::max(Align, Target->getLargeArrayAlign());
           else if (isa<ConstantArrayType>(arrayType) &&
diff --git a/test/CodeGen/align-x68_64.c b/test/CodeGen/align-x68_64.c
new file mode 100644
index 0000000..cf128b4
--- /dev/null
+++ b/test/CodeGen/align-x68_64.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// PR5599
+
+void test1_f(void *);
+
+void test1_g(void) {
+  float x[4];
+  test1_f(x);
+}
+// CHECK: @test1_g
+// CHECK: alloca [4 x float], align 16
diff --git a/test/Sema/align-x86-64.c b/test/Sema/align-x86-64.c
index 09bf633..b34d859 100644
--- a/test/Sema/align-x86-64.c
+++ b/test/Sema/align-x86-64.c
@@ -1,16 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -verify %s
 // expected-no-diagnostics
 
-// PR5599
-
-void frob(void *);
-
-void foo(void) {
-  float x[4];
-  char y[__alignof__(x) == 16 ? 1 : -1];
-  frob(y);
-}
-
 // PR5637
 
 typedef __attribute__((aligned(16))) struct {
diff --git a/test/SemaCXX/alignof.cpp b/test/SemaCXX/alignof.cpp
index ca673c4..f0b89ee 100644
--- a/test/SemaCXX/alignof.cpp
+++ b/test/SemaCXX/alignof.cpp
@@ -58,3 +58,7 @@ struct S5 {
   int x;
 };
 const int test8 = __alignof__(S5::x);
+
+long long int test14[2];
+
+static_assert(alignof(test14) == 8, "foo"); // expected-warning {{'alignof' applied to an expression is a GNU extension}}
