llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Samarth Narang (snarang181)

<details>
<summary>Changes</summary>

This patch continues the cleanup with respect to 
StreamingDiagnostic::operator&lt;&lt; overloads for APSInt and APInt.

Implements https://github.com/issues/assigned?issue=llvm%7Cllvm-project%7C161325

---
Full diff: https://github.com/llvm/llvm-project/pull/161474.diff


8 Files Affected:

- (modified) clang/lib/Sema/SemaChecking.cpp (+6-7) 
- (modified) clang/test/AST/ByteCode/const-eval.c (+1-1) 
- (modified) clang/test/Sema/const-eval.c (+1-1) 
- (modified) clang/test/Sema/integer-overflow.c (+1-1) 
- (modified) clang/test/Sema/unbounded-array-bounds.c (+23-23) 
- (modified) clang/test/SemaCXX/array-bounds.cpp (+2-2) 
- (modified) clang/test/SemaCXX/constant-expression-cxx14.cpp (+1-1) 
- (modified) clang/test/SemaCXX/integer-overflow.cpp (+1-1) 


``````````diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 39c3aa2243338..08e4a693bd556 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14882,7 +14882,7 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const 
Expr *IndexExpr,
       // dependent CharUnits)
       DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
                           PDiag(DiagID)
-                              << toString(index, 10, true) << AddrBits
+                              << index << AddrBits
                               << (unsigned)ASTC.toBits(*ElemCharUnits)
                               << toString(ElemBytes, 10, false)
                               << toString(MaxElems, 10, false)
@@ -14970,10 +14970,10 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, 
const Expr *IndexExpr,
     unsigned CastMsg = (!ASE || BaseType == EffectiveType) ? 0 : 1;
     QualType CastMsgTy = ASE ? ASE->getLHS()->getType() : QualType();
 
-    DiagRuntimeBehavior(
-        BaseExpr->getBeginLoc(), BaseExpr,
-        PDiag(DiagID) << toString(index, 10, true) << ArrayTy->desugar()
-                      << CastMsg << CastMsgTy << IndexExpr->getSourceRange());
+    DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
+                        PDiag(DiagID)
+                            << index << ArrayTy->desugar() << CastMsg
+                            << CastMsgTy << IndexExpr->getSourceRange());
   } else {
     unsigned DiagID = diag::warn_array_index_precedes_bounds;
     if (!ASE) {
@@ -14982,8 +14982,7 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const 
Expr *IndexExpr,
     }
 
     DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
-                        PDiag(DiagID) << toString(index, 10, true)
-                                      << IndexExpr->getSourceRange());
+                        PDiag(DiagID) << index << IndexExpr->getSourceRange());
   }
 
   const NamedDecl *ND = nullptr;
diff --git a/clang/test/AST/ByteCode/const-eval.c 
b/clang/test/AST/ByteCode/const-eval.c
index c6b51d16b811e..407e1f19ca756 100644
--- a/clang/test/AST/ByteCode/const-eval.c
+++ b/clang/test/AST/ByteCode/const-eval.c
@@ -144,7 +144,7 @@ EVAL_EXPR(52, &pr24622 == (void *)&PR24622);
 
 // We evaluate these by providing 2s' complement semantics in constant
 // expressions, like we do for integers.
-void *PR28739a = (__int128)(unsigned long)-1 + &PR28739a;                  // 
both-warning {{the pointer incremented by 18446744073709551615 refers past the 
last possible element for an array in 64-bit address space containing 64-bit 
(8-byte) elements (max possible 2305843009213693952 elements)}}
+void *PR28739a = (__int128)(unsigned long)-1 + &PR28739a;                  // 
both-warning {{the pointer incremented by 18'446'744'073'709'551'615 refers 
past the last possible element for an array in 64-bit address space containing 
64-bit (8-byte) elements (max possible 2305843009213693952 elements)}}
 
 void *PR28739b = &PR28739b + (__int128)(unsigned long)-1;                  // 
both-warning {{refers past the last possible element}}
 __int128 PR28739c = (&PR28739c + (__int128)(unsigned long)-1) - &PR28739c; // 
both-warning {{refers past the last possible element}}
diff --git a/clang/test/Sema/const-eval.c b/clang/test/Sema/const-eval.c
index 11cc7fbc0feb3..531bde9814438 100644
--- a/clang/test/Sema/const-eval.c
+++ b/clang/test/Sema/const-eval.c
@@ -138,7 +138,7 @@ EVAL_EXPR(52, &pr24622 == (void *)&PR24622);
 
 // We evaluate these by providing 2s' complement semantics in constant
 // expressions, like we do for integers.
-void *PR28739a = (__int128)(unsigned long)-1 + &PR28739a;                  // 
expected-warning {{the pointer incremented by 18446744073709551615 refers past 
the last possible element for an array in 64-bit address space containing 
64-bit (8-byte) elements (max possible 2305843009213693952 elements)}}
+void *PR28739a = (__int128)(unsigned long)-1 + &PR28739a;                  // 
expected-warning {{the pointer incremented by 18'446'744'073'709'551'615 refers 
past the last possible element for an array in 64-bit address space containing 
64-bit (8-byte) elements (max possible 2305843009213693952 elements)}}
 void *PR28739b = &PR28739b + (__int128)(unsigned long)-1;                  // 
expected-warning {{refers past the last possible element}}
 __int128 PR28739c = (&PR28739c + (__int128)(unsigned long)-1) - &PR28739c; // 
expected-warning {{refers past the last possible element}}
 void *PR28739d = &(&PR28739d)[(__int128)(unsigned long)-1];                // 
expected-warning {{refers past the last possible element}}
diff --git a/clang/test/Sema/integer-overflow.c 
b/clang/test/Sema/integer-overflow.c
index 30a47aa5f6ad6..ba943f0927a22 100644
--- a/clang/test/Sema/integer-overflow.c
+++ b/clang/test/Sema/integer-overflow.c
@@ -143,7 +143,7 @@ uint64_t check_integer_overflows(int i) {
   (__imag__ x) = 4608 * 1024 * 1024;
 
 // expected-warning@+4 {{overflow in expression; result is 536'870'912 with 
type 'int'}}
-// expected-warning@+3 {{array index 536870912 is past the end of the array 
(that has type 'uint64_t[10]' (aka 'unsigned long long[10]'))}}
+// expected-warning@+3 {{array index 536'870'912 is past the end of the array 
(that has type 'uint64_t[10]' (aka 'unsigned long long[10]'))}}
 // expected-note@+1 {{array 'a' declared here}}
   uint64_t a[10];
   a[4608 * 1024 * 1024] = 1i;
diff --git a/clang/test/Sema/unbounded-array-bounds.c 
b/clang/test/Sema/unbounded-array-bounds.c
index b22261a3eaeb5..2799610d1ca2a 100644
--- a/clang/test/Sema/unbounded-array-bounds.c
+++ b/clang/test/Sema/unbounded-array-bounds.c
@@ -14,11 +14,11 @@ struct S s[]; // expected-warning {{tentative array 
definition}} expected-note {
 void f1(void) {
   ++s[3].a;
   ++s[7073650413200313099].b;
-  // addr16-warning@-1 {{array index 7073650413200313099 refers past the last 
possible element for an array in 16-bit address space containing 152-bit 
(19-byte) elements (max possible 3449 elements)}}
-  // addr32-warning@-2 {{array index 7073650413200313099 refers past the last 
possible element for an array in 32-bit address space containing 192-bit 
(24-byte) elements (max possible 178956970 elements)}}
-  // addr64-warning@-3 {{array index 7073650413200313099 refers past the last 
possible element for an array in 64-bit address space containing 256-bit 
(32-byte) elements (max possible 576460752303423488 elements)}}
+  // addr16-warning@-1 {{array index 7'073'650'413'200'313'099 refers past the 
last possible element for an array in 16-bit address space containing 152-bit 
(19-byte) elements (max possible 3449 elements)}}
+  // addr32-warning@-2 {{array index 7'073'650'413'200'313'099 refers past the 
last possible element for an array in 32-bit address space containing 192-bit 
(24-byte) elements (max possible 178956970 elements)}}
+  // addr64-warning@-3 {{array index 7'073'650'413'200'313'099 refers past the 
last possible element for an array in 64-bit address space containing 256-bit 
(32-byte) elements (max possible 576460752303423488 elements)}}
   ++s[7073650].c;
-  // addr16-warning@-1 {{array index 7073650 refers past the last possible 
element for an array in 16-bit address space containing 152-bit (19-byte) 
elements (max possible 3449 elements)}}
+  // addr16-warning@-1 {{array index 7'073'650 refers past the last possible 
element for an array in 16-bit address space containing 152-bit (19-byte) 
elements (max possible 3449 elements)}}
 }
 
 long long ll[]; // expected-warning {{tentative array definition}} 
expected-note {{declared here}} addr16-note {{declared here}} addr32-note 
{{declared here}}
@@ -26,32 +26,32 @@ long long ll[]; // expected-warning {{tentative array 
definition}} expected-note
 void f2(void) {
   ++ll[3];
   ++ll[2705843009213693952];
-  // addr16-warning@-1 {{array index 2705843009213693952 refers past the last 
possible element for an array in 16-bit address space containing 64-bit 
(8-byte) elements (max possible 8192 elements)}}
-  // addr32-warning@-2 {{array index 2705843009213693952 refers past the last 
possible element for an array in 32-bit address space containing 64-bit 
(8-byte) elements (max possible 536870912 elements)}}
-  // addr64-warning@-3 {{array index 2705843009213693952 refers past the last 
possible element for an array in 64-bit address space containing 64-bit 
(8-byte) elements (max possible 2305843009213693952 elements)}}
+  // addr16-warning@-1 {{array index 2'705'843'009'213'693'952 refers past the 
last possible element for an array in 16-bit address space containing 64-bit 
(8-byte) elements (max possible 8192 elements)}}
+  // addr32-warning@-2 {{array index 2'705'843'009'213'693'952 refers past the 
last possible element for an array in 32-bit address space containing 64-bit 
(8-byte) elements (max possible 536870912 elements)}}
+  // addr64-warning@-3 {{array index 2'705'843'009'213'693'952 refers past the 
last possible element for an array in 64-bit address space containing 64-bit 
(8-byte) elements (max possible 2305843009213693952 elements)}}
   ++ll[847073650];
-  // addr16-warning@-1 {{array index 847073650 refers past the last possible 
element for an array in 16-bit address space containing 64-bit (8-byte) 
elements (max possible 8192 elements)}}
-  // addr32-warning@-2 {{array index 847073650 refers past the last possible 
element for an array in 32-bit address space containing 64-bit (8-byte) 
elements (max possible 536870912 elements)}}
+  // addr16-warning@-1 {{array index 847'073'650 refers past the last possible 
element for an array in 16-bit address space containing 64-bit (8-byte) 
elements (max possible 8192 elements)}}
+  // addr32-warning@-2 {{array index 847'073'650 refers past the last possible 
element for an array in 32-bit address space containing 64-bit (8-byte) 
elements (max possible 536870912 elements)}}
 }
 
 void f3(struct S p[]) { // expected-note {{declared here}} addr16-note 
{{declared here}}
   ++p[3].a;
   ++p[7073650413200313099].b;
-  // addr16-warning@-1 {{array index 7073650413200313099 refers past the last 
possible element for an array in 16-bit address space containing 152-bit 
(19-byte) elements (max possible 3449 elements)}}
-  // addr32-warning@-2 {{array index 7073650413200313099 refers past the last 
possible element for an array in 32-bit address space containing 192-bit 
(24-byte) elements (max possible 178956970 elements)}}
-  // addr64-warning@-3 {{array index 7073650413200313099 refers past the last 
possible element for an array in 64-bit address space containing 256-bit 
(32-byte) elements (max possible 576460752303423488 elements)}}
+  // addr16-warning@-1 {{array index 7'073'650'413'200'313'099 refers past the 
last possible element for an array in 16-bit address space containing 152-bit 
(19-byte) elements (max possible 3449 elements)}}
+  // addr32-warning@-2 {{array index 7'073'650'413'200'313'099 refers past the 
last possible element for an array in 32-bit address space containing 192-bit 
(24-byte) elements (max possible 178956970 elements)}}
+  // addr64-warning@-3 {{array index 7'073'650'413'200'313'099 refers past the 
last possible element for an array in 64-bit address space containing 256-bit 
(32-byte) elements (max possible 576460752303423488 elements)}}
   ++p[7073650].c;
-  // addr16-warning@-1 {{array index 7073650 refers past the last possible 
element for an array in 16-bit address space containing 152-bit (19-byte) 
elements (max possible 3449 elements)}}
+  // addr16-warning@-1 {{array index 7'073'650 refers past the last possible 
element for an array in 16-bit address space containing 152-bit (19-byte) 
elements (max possible 3449 elements)}}
 }
 
 void f4(struct S *p) { // expected-note {{declared here}} addr16-note 
{{declared here}}
   p += 3;
   p += 7073650413200313099;
-  // addr16-warning@-1 {{the pointer incremented by 7073650413200313099 refers 
past the last possible element for an array in 16-bit address space containing 
152-bit (19-byte) elements (max possible 3449 elements)}}
-  // addr32-warning@-2 {{the pointer incremented by 7073650413200313099 refers 
past the last possible element for an array in 32-bit address space containing 
192-bit (24-byte) elements (max possible 178956970 elements)}}
-  // addr64-warning@-3 {{the pointer incremented by 7073650413200313099 refers 
past the last possible element for an array in 64-bit address space containing 
256-bit (32-byte) elements (max possible 576460752303423488 elements)}}
+  // addr16-warning@-1 {{the pointer incremented by 7'073'650'413'200'313'099 
refers past the last possible element for an array in 16-bit address space 
containing 152-bit (19-byte) elements (max possible 3449 elements)}}
+  // addr32-warning@-2 {{the pointer incremented by 7'073'650'413'200'313'099 
refers past the last possible element for an array in 32-bit address space 
containing 192-bit (24-byte) elements (max possible 178956970 elements)}}
+  // addr64-warning@-3 {{the pointer incremented by 7'073'650'413'200'313'099 
refers past the last possible element for an array in 64-bit address space 
containing 256-bit (32-byte) elements (max possible 576460752303423488 
elements)}}
   p += 7073650;
-  // addr16-warning@-1 {{the pointer incremented by 7073650 refers past the 
last possible element for an array in 16-bit address space containing 152-bit 
(19-byte) elements (max possible 3449 elements)}}
+  // addr16-warning@-1 {{the pointer incremented by 7'073'650 refers past the 
last possible element for an array in 16-bit address space containing 152-bit 
(19-byte) elements (max possible 3449 elements)}}
 }
 
 struct BQ {
@@ -102,15 +102,15 @@ struct {
 
 void fam_ily() {
   ++fam.tail[7073650413200313099];
-  // addr16-warning@-1 {{array index 7073650413200313099 refers past the last 
possible element for an array in 16-bit address space containing 8-bit (1-byte) 
elements (max possible 65536 elements)}}
-  // addr32-warning@-2 {{array index 7073650413200313099 refers past the last 
possible element for an array in 32-bit address space containing 8-bit (1-byte) 
elements (max possible 4294967296 elements)}}
+  // addr16-warning@-1 {{array index 7'073'650'413'200'313'099 refers past the 
last possible element for an array in 16-bit address space containing 8-bit 
(1-byte) elements (max possible 65536 elements)}}
+  // addr32-warning@-2 {{array index 7'073'650'413'200'313'099 refers past the 
last possible element for an array in 32-bit address space containing 8-bit 
(1-byte) elements (max possible 4294967296 elements)}}
   // No warning for addr64 because the array index is inbound in that case.
   ++fam0.tail[7073650413200313099];
-  // addr16-warning@-1 {{array index 7073650413200313099 refers past the last 
possible element for an array in 16-bit address space containing 8-bit (1-byte) 
elements (max possible 65536 elements)}}
-  // addr32-warning@-2 {{array index 7073650413200313099 refers past the last 
possible element for an array in 32-bit address space containing 8-bit (1-byte) 
elements (max possible 4294967296 elements)}}
+  // addr16-warning@-1 {{array index 7'073'650'413'200'313'099 refers past the 
last possible element for an array in 16-bit address space containing 8-bit 
(1-byte) elements (max possible 65536 elements)}}
+  // addr32-warning@-2 {{array index 7'073'650'413'200'313'099 refers past the 
last possible element for an array in 32-bit address space containing 8-bit 
(1-byte) elements (max possible 4294967296 elements)}}
   // No warning for addr64 because the array index is inbound in that case.
   ++fam1.tail[7073650413200313099];
-  // addr16-warning@-1 {{array index 7073650413200313099 refers past the last 
possible element for an array in 16-bit address space containing 8-bit (1-byte) 
elements (max possible 65536 elements)}}
-  // addr32-warning@-2 {{array index 7073650413200313099 refers past the last 
possible element for an array in 32-bit address space containing 8-bit (1-byte) 
elements (max possible 4294967296 elements)}}
+  // addr16-warning@-1 {{array index 7'073'650'413'200'313'099 refers past the 
last possible element for an array in 16-bit address space containing 8-bit 
(1-byte) elements (max possible 65536 elements)}}
+  // addr32-warning@-2 {{array index 7'073'650'413'200'313'099 refers past the 
last possible element for an array in 32-bit address space containing 8-bit 
(1-byte) elements (max possible 4294967296 elements)}}
   // No warning for addr64 because the array index is inbound in that case.
 }
diff --git a/clang/test/SemaCXX/array-bounds.cpp 
b/clang/test/SemaCXX/array-bounds.cpp
index b584e1e7cd453..6a40d1db0a6fd 100644
--- a/clang/test/SemaCXX/array-bounds.cpp
+++ b/clang/test/SemaCXX/array-bounds.cpp
@@ -237,7 +237,7 @@ void test_pr10771() {
     ((char*)foo)[sizeof(foo) - 1] = '\0';  // no-warning
     *(((char*)foo) + sizeof(foo) - 1) = '\0';  // no-warning
 
-    ((char*)foo)[sizeof(foo)] = '\0';  // expected-warning {{array index 32768 
is past the end of the array (that has type 'double[4096]', cast to 'char *')}}
+    ((char*)foo)[sizeof(foo)] = '\0';  // expected-warning {{array index 
32'768 is past the end of the array (that has type 'double[4096]', cast to 
'char *')}}
 
     // TODO: This should probably warn, too.
     *(((char*)foo) + sizeof(foo)) = '\0';  // no-warning
@@ -248,7 +248,7 @@ int test_pr11007_aux(const char * restrict, ...);
 // Test checking with varargs.
 void test_pr11007() {
   double a[5]; // expected-note {{array 'a' declared here}}
-  test_pr11007_aux("foo", a[1000]); // expected-warning {{array index 1000 is 
past the end of the array (that has type 'double[5]')}}
+  test_pr11007_aux("foo", a[1000]); // expected-warning {{array index 1'000 is 
past the end of the array (that has type 'double[5]')}}
 }
 
 void test_rdar10916006(void)
diff --git a/clang/test/SemaCXX/constant-expression-cxx14.cpp 
b/clang/test/SemaCXX/constant-expression-cxx14.cpp
index 1743e0e3ac4b5..c6dd5d6c70513 100644
--- a/clang/test/SemaCXX/constant-expression-cxx14.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx14.cpp
@@ -1047,7 +1047,7 @@ constexpr int S = sum(Cs); // expected-error{{must be 
initialized by a constant
 constexpr void PR28739(int n) { // cxx14_20-error {{never produces a constant}}
   int *p = &n;                  // expected-note {{array 'p' declared here}}
   p += (__int128)(unsigned long)-1; // cxx14_20-note {{cannot refer to element 
18446744073709551615 of non-array object in a constant expression}}
-  // expected-warning@-1 {{the pointer incremented by 18446744073709551615 
refers past the last possible element for an array in 64-bit address space 
containing 32-bit (4-byte) elements (max possible 4611686018427387904 
elements)}}
+  // expected-warning@-1 {{the pointer incremented by 
18'446'744'073'709'551'615 refers past the last possible element for an array 
in 64-bit address space containing 32-bit (4-byte) elements (max possible 
4611686018427387904 elements)}}
 }
 
 constexpr void Void(int n) {
diff --git a/clang/test/SemaCXX/integer-overflow.cpp 
b/clang/test/SemaCXX/integer-overflow.cpp
index 73a4e88ee6c09..214dc11bf3ead 100644
--- a/clang/test/SemaCXX/integer-overflow.cpp
+++ b/clang/test/SemaCXX/integer-overflow.cpp
@@ -171,7 +171,7 @@ uint64_t check_integer_overflows(int i) { //expected-note 
0+{{declared here}}
   uint64_t a[10];
   a[4608 * 1024 * 1024] = 1;
 #if __cplusplus < 201103L
-// expected-warning@-2 {{array index 536870912 is past the end of the array 
(that has type 'uint64_t[10]' (aka 'unsigned long long[10]'))}}
+// expected-warning@-2 {{array index 536'870'912 is past the end of the array 
(that has type 'uint64_t[10]' (aka 'unsigned long long[10]'))}}
 // expected-note@-4 {{array 'a' declared here}}
 #endif
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/161474
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to