diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -237,8 +237,8 @@ } Expr::EvalResult AlignResult; unsigned MaxAlignmentBits = S.Context.getIntWidth(SrcTy) - 1; - // We can't check validity of alignment if it is type dependent. - if (!AlignOp->isInstantiationDependent() && + // We can't check validity of alignment if it is value dependent. + if (!AlignOp->isValueDependent() && AlignOp->EvaluateAsInt(AlignResult, S.Context, Expr::SE_AllowSideEffects)) { llvm::APSInt AlignValue = AlignResult.Val.getInt(); diff --git a/clang/test/SemaCXX/builtin-align-cxx.cpp b/clang/test/SemaCXX/builtin-align-cxx.cpp --- a/clang/test/SemaCXX/builtin-align-cxx.cpp +++ b/clang/test/SemaCXX/builtin-align-cxx.cpp @@ -52,6 +52,9 @@ __builtin_align_up(array, 31); // expected-error{{requested alignment is not a power of 2}} __builtin_align_up(value, 31); // This shouldn't want since the type is dependent __builtin_align_up(value); // Same here + + __builtin_align_up(array, sizeof(sizeof(value)) - 1); // expected-error{{requested alignment is not a power of 2}} + __builtin_align_up(array, value); // no diagnostic as the alignment is value dependent. } // The original fix for the issue above broke some legitimate code.