[PATCH] D156711: [clang][ExprConstant] Fix assertion failure in constant expression folding

antoine moynault via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 18 08:29:40 PDT 2023


antmo updated this revision to Diff 551525.
antmo added a comment.

rebase & ping ; )


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156711

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constexpr-string.cpp


Index: clang/test/SemaCXX/constexpr-string.cpp
===================================================================
--- clang/test/SemaCXX/constexpr-string.cpp
+++ clang/test/SemaCXX/constexpr-string.cpp
@@ -93,6 +93,7 @@
 
   static_assert(__builtin_strncmp(kFoobar, kFoobazfoobar, 6) == -1);
   static_assert(__builtin_strncmp(kFoobar, kFoobazfoobar, 7) == -1); // FIXME: Should we reject this?
+  static_assert(__builtin_strncmp(kFoobar, kFoobazfoobar, (size_t)-1) == -1); // Check that this does not assert
   static_assert(__builtin_strncmp(kFoobar, kFoobazfoobar + 6, 6) == 0);
   static_assert(__builtin_strncmp(kFoobar, kFoobazfoobar + 6, 7) == 0); // expected-error {{not an integral constant}} expected-note {{dereferenced one-past-the-end}}
 
@@ -377,6 +378,7 @@
 
   static_assert(__builtin_memchr(kStr, 'a', 0) == nullptr);
   static_assert(__builtin_memchr(kStr, 'a', 1) == kStr);
+  static_assert(__builtin_memchr(kStr, 'a', (size_t)-1) == kStr); // Check that this does not assert
   static_assert(__builtin_memchr(kStr, '\0', 5) == nullptr);
   static_assert(__builtin_memchr(kStr, '\0', 6) == kStr + 5);
   static_assert(__builtin_memchr(kStr, '\xff', 8) == kStr + 4);
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -9357,7 +9357,7 @@
       APSInt N;
       if (!EvaluateInteger(E->getArg(2), N, Info))
         return false;
-      MaxLength = N.getExtValue();
+      MaxLength = N.getZExtValue();
     }
     // We cannot find the value if there are no candidates to match against.
     if (MaxLength == 0u)
@@ -12381,7 +12381,7 @@
       APSInt N;
       if (!EvaluateInteger(E->getArg(2), N, Info))
         return false;
-      MaxLength = N.getExtValue();
+      MaxLength = N.getZExtValue();
     }
 
     // Empty substrings compare equal by definition.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156711.551525.patch
Type: text/x-patch
Size: 1912 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230818/1154b3f6/attachment.bin>


More information about the cfe-commits mailing list