[PATCH] D83074: [clang] Check ValueDependent instead of InstantiationDependent before executing the align expr for builtin align functions.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 2 23:57:34 PDT 2020


hokein updated this revision to Diff 275299.
hokein marked an inline comment as done.
hokein added a comment.

add more test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83074/new/

https://reviews.llvm.org/D83074

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/builtin-align-cxx.cpp


Index: clang/test/SemaCXX/builtin-align-cxx.cpp
===================================================================
--- clang/test/SemaCXX/builtin-align-cxx.cpp
+++ clang/test/SemaCXX/builtin-align-cxx.cpp
@@ -37,7 +37,7 @@
   // expected-note at -1{{in instantiation of function template specialization 'test_templated_arguments<int, 7, 16>'}}
 }
 
-template <typename T>
+template <typename T, long ArraySize = 16>
 void test_incorrect_alignment_without_instatiation(T value) {
   int array[32];
   static_assert(__is_same(decltype(__builtin_align_up(array, 31)), int *), // expected-error{{requested alignment is not a power of 2}}
@@ -52,6 +52,10 @@
   __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.
+  (void)__builtin_align_up(array, ArraySize); // The same above here
 }
 
 // The original fix for the issue above broke some legitimate code.
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ 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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83074.275299.patch
Type: text/x-patch
Size: 1935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200703/b5d9e302/attachment-0001.bin>


More information about the cfe-commits mailing list