[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-10-04 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 557588.
chaitanyav added a comment.

Rebase with upstream


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxx/test/std/containers/unord/unord.map/eq.different_hash.pass.cpp
  libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
  libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
  libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1250,10 +1247,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
+++ libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
@@ -40,7 +40,7 @@
 }
 template 
 std::size_t hash_even(T val) {
-  return val & 1 ? 1 : 0;
+  return (val & 1) ? 1 : 0;
 }
 template 
 std::size_t hash_same(T /*val*/) {
@@ -61,7 +61,7 @@
 }
 template 
 size_t hash_even(T* val) {
-  return *val & 1 ? 1 : 0;
+  return (*val & 1) ? 1 : 0;
 }
 
 template 
Index: libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
+++ libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
@@ -40,7 +40,7 @@
 }
 template 
 std::size_t hash_even(T val) {
-  return val & 1 ? 1 : 0;
+  return (val & 1) ? 1 : 0;
 }
 template 
 std::size_t hash_same(T /*val*/) {
@@ -61,7 +61,7 @@
 }
 template 
 std::size_t hash_even(T* val) {
-  return *val & 1 ? 1 : 0;
+  return (*val & 1) ? 1 : 0;
 }
 
 template 
Index: libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
+++ libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
@@ -41,7 +41,7 @@
 }
 template 
 std::size_t 

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-09-30 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav marked an inline comment as done.
chaitanyav added a comment.

Ran llvm with the boolean and operator change. attaching the log file with 
errors .F29524460: llvm.txt 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-09-30 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 557513.
chaitanyav added a comment.

rebase upstream changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxx/test/std/containers/unord/unord.map/eq.different_hash.pass.cpp
  libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
  libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
  libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1250,10 +1247,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
+++ libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
@@ -40,7 +40,7 @@
 }
 template 
 std::size_t hash_even(T val) {
-  return val & 1 ? 1 : 0;
+  return (val & 1) ? 1 : 0;
 }
 template 
 std::size_t hash_same(T /*val*/) {
@@ -61,7 +61,7 @@
 }
 template 
 size_t hash_even(T* val) {
-  return *val & 1 ? 1 : 0;
+  return (*val & 1) ? 1 : 0;
 }
 
 template 
Index: libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
+++ libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
@@ -40,7 +40,7 @@
 }
 template 
 std::size_t hash_even(T val) {
-  return val & 1 ? 1 : 0;
+  return (val & 1) ? 1 : 0;
 }
 template 
 std::size_t hash_same(T /*val*/) {
@@ -61,7 +61,7 @@
 }
 template 
 std::size_t hash_even(T* val) {
-  return *val & 1 ? 1 : 0;
+  return (*val & 1) ? 1 : 0;
 }
 
 template 
Index: libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
+++ libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
@@ -41,7 +41,7 @@
 }
 template 
 std::size_t 

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-09-27 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 557427.
chaitanyav added a comment.

Add parentheses to the conditional expression


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxx/test/std/containers/unord/unord.map/eq.different_hash.pass.cpp
  libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
  libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
  libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1250,10 +1247,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
+++ libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
@@ -40,7 +40,7 @@
 }
 template 
 std::size_t hash_even(T val) {
-  return val & 1 ? 1 : 0;
+  return (val & 1) ? 1 : 0;
 }
 template 
 std::size_t hash_same(T /*val*/) {
@@ -61,7 +61,7 @@
 }
 template 
 size_t hash_even(T* val) {
-  return *val & 1 ? 1 : 0;
+  return (*val & 1) ? 1 : 0;
 }
 
 template 
Index: libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
+++ libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
@@ -40,7 +40,7 @@
 }
 template 
 std::size_t hash_even(T val) {
-  return val & 1 ? 1 : 0;
+  return (val & 1) ? 1 : 0;
 }
 template 
 std::size_t hash_same(T /*val*/) {
@@ -61,7 +61,7 @@
 }
 template 
 std::size_t hash_even(T* val) {
-  return *val & 1 ? 1 : 0;
+  return (*val & 1) ? 1 : 0;
 }
 
 template 
Index: libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
+++ libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
@@ -41,7 +41,7 @@
 }
 

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-09-27 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 557417.
chaitanyav added a comment.

Add parentheses to the conditional expression


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1250,10 +1247,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
+++ libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
@@ -40,7 +40,7 @@
 }
 template 
 std::size_t hash_even(T val) {
-  return val & 1 ? 1 : 0;
+  return (val & 1) ? 1 : 0;
 }
 template 
 std::size_t hash_same(T /*val*/) {
@@ -61,7 +61,7 @@
 }
 template 
 std::size_t hash_even(T* val) {
-  return *val & 1 ? 1 : 0;
+  return (*val & 1) ? 1 : 0;
 }
 
 template 
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-09-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

Bootstrapping build failed due to -werror flag 
(https://buildkite.com/llvm-project/libcxx-ci/builds/30031)

   | 
/home/libcxx-builder/.buildkite-agent/builds/google-libcxx-builder-4613821dc47f-1/llvm-project/libcxx-ci/libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp:43:18:
 error: operator '?:' has lower precedence than '&'; '&' will be evaluated 
first [-Werror,-Wbitwise-conditional-parentheses]
  # |43 |   return val & 1 ? 1 : 0;
  # |   |  ~~~ ^
  
  
  # | 
/home/libcxx-builder/.buildkite-agent/builds/google-libcxx-builder-4613821dc47f-1/llvm-project/libcxx-ci/libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp:64:19:
 error: operator '?:' has lower precedence than '&'; '&' will be evaluated 
first [-Werror,-Wbitwise-conditional-parentheses]
  # |64 |   return *val & 1 ? 1 : 0;
  # |   |   ^


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-09-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 557373.
chaitanyav added a comment.

Rebase with upstream


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1250,10 +1247,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto deterministic_v = deterministic();
   

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-09-25 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 557346.
chaitanyav added a comment.

Rebase with upstream and update code as per comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1250,10 +1247,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto 

[PATCH] D151383: [clang-tidy] Check for specific return types on all functions

2023-05-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG785b30b8a33a: [clang-tidy] Check for specific return types 
on all functions (authored by chaitanyav).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
@@ -52,6 +52,9 @@
   bool empty() const noexcept;
 };
 
+class error_code {
+};
+
 // the check should be able to match std lib calls even if the functions are
 // declared inside inline namespaces
 inline namespace v1 {
@@ -72,6 +75,10 @@
 
 void useFuture(const std::future );
 
+std::error_code errorFunc() {
+return std::error_code();
+}
+
 void warning() {
   std::async(increment, 42);
   // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function should be used
@@ -185,6 +192,10 @@
 // CHECK-NOTES: [[@LINE-1]]:5: warning: the value {{.*}} should be used
 // CHECK-NOTES: [[@LINE-2]]:5: note: cast {{.*}} this warning
   }
+
+  errorFunc();
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 }
 
 void noWarning() {
@@ -209,6 +220,8 @@
   std::vector VecNoWarning;
   auto VecEmptyRetval = VecNoWarning.empty();
 
+  (void) errorFunc();
+
   // test using the return value in different kinds of expressions
   useFuture(std::async(increment, 42));
   std::launder()->f();
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -46,5 +46,11 @@
  return value often indicates that the programmer confused the function with
  ``clear()``.
 
+.. option:: CheckedReturnTypes
+
+   Semicolon-separated list of function return types to check.
+   By default the following function return types are checked:
+   `::std::error_code`, `::std::expected`, `::boost::system::error_code`, `::abseil::Status`
+
 `cert-err33-c <../cert/err33-c.html>`_ is an alias of this check that checks a
 fixed and large set of standard library functions.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -248,6 +248,10 @@
   constructor initializers. Correctly handle constructor arguments as being
   sequenced when constructor call is written as list-initialization.
 
+- Extend :doc:`bugprone-unused-return-value
+  ` check to check for all functions
+  with specified return types using the ``CheckedReturnTypes`` option.
+
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
@@ -27,6 +27,7 @@
 
 private:
   std::string CheckedFunctions;
+  const std::vector CheckedReturnTypes;
 };
 
 } // namespace clang::tidy::bugprone
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "UnusedReturnValueCheck.h"
+#include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -27,7 +28,6 @@
   return InnerMatcher.matches(InstantiatedFrom ? *InstantiatedFrom : Node,
   Finder, Builder);
 }
-
 } // namespace
 
 UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
@@ -124,19 +124,30 @@
"::sigismember;"
"::strcasecmp;"
"::strsignal;"
-   "::ttyname")) {}
+   "::ttyname")),
+  

[PATCH] D151383: [clang-tidy] Check for specific return types on all functions

2023-05-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

In D151383#4377043 , @PiotrZSL wrote:

> LGTM, you may consider reducing commit message (aka review description by 
> removing example and error from it, and leaving just plain description of a 
> change).

got it, will make sure to remove them from the arc generated commit message.




Comment at: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp:159
+   anyOf(isInstantiatedFrom(hasAnyName(FunVec)),
+ hasAnyReturnType(RetTypeVec)
   .bind("match";

PiotrZSL wrote:
> Consider:
> 
> hasAnyReturnType -> 
> `returns(hasCanonicalType(hasDeclaration(namedDecl(matchers::matchesAnyListedName(RetTypeVec`
> Note that to use matchesAnyListedName, you should save RetTypeVec  as class 
> member, just to be safe.
I followed the code in ForRangeCopyCheck.cpp and made the changes accordingly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151383: [clang-tidy] Check for specific return types on all functions

2023-05-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 526173.
chaitanyav marked an inline comment as done.
chaitanyav added a comment.

use fully qualified name in code and documentation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
@@ -52,6 +52,9 @@
   bool empty() const noexcept;
 };
 
+class error_code {
+};
+
 // the check should be able to match std lib calls even if the functions are
 // declared inside inline namespaces
 inline namespace v1 {
@@ -72,6 +75,10 @@
 
 void useFuture(const std::future );
 
+std::error_code errorFunc() {
+return std::error_code();
+}
+
 void warning() {
   std::async(increment, 42);
   // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function should be used
@@ -185,6 +192,10 @@
 // CHECK-NOTES: [[@LINE-1]]:5: warning: the value {{.*}} should be used
 // CHECK-NOTES: [[@LINE-2]]:5: note: cast {{.*}} this warning
   }
+
+  errorFunc();
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 }
 
 void noWarning() {
@@ -209,6 +220,8 @@
   std::vector VecNoWarning;
   auto VecEmptyRetval = VecNoWarning.empty();
 
+  (void) errorFunc();
+
   // test using the return value in different kinds of expressions
   useFuture(std::async(increment, 42));
   std::launder()->f();
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -46,5 +46,11 @@
  return value often indicates that the programmer confused the function with
  ``clear()``.
 
+.. option:: CheckedReturnTypes
+
+   Semicolon-separated list of function return types to check.
+   By default the following function return types are checked:
+   `::std::error_code`, `::std::expected`, `::boost::system::error_code`, `::abseil::Status`
+
 `cert-err33-c <../cert/err33-c.html>`_ is an alias of this check that checks a
 fixed and large set of standard library functions.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -248,6 +248,10 @@
   constructor initializers. Correctly handle constructor arguments as being
   sequenced when constructor call is written as list-initialization.
 
+- Extend :doc:`bugprone-unused-return-value
+  ` check to check for all functions
+  with specified return types using the ``CheckedReturnTypes`` option.
+
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
@@ -27,6 +27,7 @@
 
 private:
   std::string CheckedFunctions;
+  const std::vector CheckedReturnTypes;
 };
 
 } // namespace clang::tidy::bugprone
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "UnusedReturnValueCheck.h"
+#include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -27,7 +28,6 @@
   return InnerMatcher.matches(InstantiatedFrom ? *InstantiatedFrom : Node,
   Finder, Builder);
 }
-
 } // namespace
 
 UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
@@ -124,19 +124,30 @@
"::sigismember;"
"::strcasecmp;"
"::strsignal;"
-   "::ttyname")) {}
+   "::ttyname")),
+  

[PATCH] D151383: [clang-tidy] Check for specific return types on all functions

2023-05-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 526159.
chaitanyav marked 4 inline comments as done.
chaitanyav added a comment.

Make changes as per comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
@@ -52,6 +52,9 @@
   bool empty() const noexcept;
 };
 
+class error_code {
+};
+
 // the check should be able to match std lib calls even if the functions are
 // declared inside inline namespaces
 inline namespace v1 {
@@ -72,6 +75,10 @@
 
 void useFuture(const std::future );
 
+std::error_code errorFunc() {
+return std::error_code();
+}
+
 void warning() {
   std::async(increment, 42);
   // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function should be used
@@ -185,6 +192,10 @@
 // CHECK-NOTES: [[@LINE-1]]:5: warning: the value {{.*}} should be used
 // CHECK-NOTES: [[@LINE-2]]:5: note: cast {{.*}} this warning
   }
+
+  errorFunc();
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 }
 
 void noWarning() {
@@ -209,6 +220,8 @@
   std::vector VecNoWarning;
   auto VecEmptyRetval = VecNoWarning.empty();
 
+  (void) errorFunc();
+
   // test using the return value in different kinds of expressions
   useFuture(std::async(increment, 42));
   std::launder()->f();
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -46,5 +46,11 @@
  return value often indicates that the programmer confused the function with
  ``clear()``.
 
+.. option:: CheckedReturnTypes
+
+   Semicolon-separated list of function return types to check.
+   By default the following function return types are checked:
+   `std::error_code, std::expected, boost::system::error_code, abseil::Status`
+
 `cert-err33-c <../cert/err33-c.html>`_ is an alias of this check that checks a
 fixed and large set of standard library functions.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -248,6 +248,10 @@
   constructor initializers. Correctly handle constructor arguments as being
   sequenced when constructor call is written as list-initialization.
 
+- Extend :doc:`bugprone-unused-return-value
+  ` check to check for all functions
+  with specified return types using the ``CheckedReturnTypes`` option.
+
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
@@ -27,6 +27,7 @@
 
 private:
   std::string CheckedFunctions;
+  const std::vector CheckedReturnTypes;
 };
 
 } // namespace clang::tidy::bugprone
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "UnusedReturnValueCheck.h"
+#include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -27,7 +28,6 @@
   return InnerMatcher.matches(InstantiatedFrom ? *InstantiatedFrom : Node,
   Finder, Builder);
 }
-
 } // namespace
 
 UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
@@ -124,19 +124,30 @@
"::sigismember;"
"::strcasecmp;"
"::strsignal;"
-   "::ttyname")) {}
+   "::ttyname")),
+  CheckedReturnTypes(utils::options::parseStringList(
+  

[PATCH] D151383: [clang-tidy] Check for specific return types on all functions

2023-05-25 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 525926.
chaitanyav marked an inline comment as done.
chaitanyav added a comment.

Use single backticks for options


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
@@ -52,6 +52,9 @@
   bool empty() const noexcept;
 };
 
+class error_code {
+};
+
 // the check should be able to match std lib calls even if the functions are
 // declared inside inline namespaces
 inline namespace v1 {
@@ -72,6 +75,10 @@
 
 void useFuture(const std::future );
 
+std::error_code errorFunc() {
+return std::error_code();
+}
+
 void warning() {
   std::async(increment, 42);
   // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function should be used
@@ -185,6 +192,10 @@
 // CHECK-NOTES: [[@LINE-1]]:5: warning: the value {{.*}} should be used
 // CHECK-NOTES: [[@LINE-2]]:5: note: cast {{.*}} this warning
   }
+
+  errorFunc();
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 }
 
 void noWarning() {
@@ -209,6 +220,8 @@
   std::vector VecNoWarning;
   auto VecEmptyRetval = VecNoWarning.empty();
 
+  (void) errorFunc();
+
   // test using the return value in different kinds of expressions
   useFuture(std::async(increment, 42));
   std::launder()->f();
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -46,5 +46,11 @@
  return value often indicates that the programmer confused the function with
  ``clear()``.
 
+.. option:: CheckedReturnTypes
+
+   Semicolon-separated list of function return types to check.
+   By default the following function return types are checked:
+   `std::error_code, std::expected, boost::system::error_code, abseil::Status`
+
 `cert-err33-c <../cert/err33-c.html>`_ is an alias of this check that checks a
 fixed and large set of standard library functions.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -248,6 +248,10 @@
   constructor initializers. Correctly handle constructor arguments as being
   sequenced when constructor call is written as list-initialization.
 
+- Extend :doc:`bugprone-unused-return-value
+  ` check to check for all functions
+  with specified return types using the ``CheckedReturnTypes`` option.
+
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 
@@ -391,6 +395,7 @@
   `: warn on ``const &&``
   constructors.
 
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
@@ -27,6 +27,7 @@
 
 private:
   std::string CheckedFunctions;
+  std::string CheckedReturnTypes;
 };
 
 } // namespace clang::tidy::bugprone
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -28,6 +28,17 @@
   Finder, Builder);
 }
 
+// Checks if the function return type is in CheckedReturnedTypes
+AST_MATCHER_P(FunctionDecl, hasAnyReturnType, std::vector,
+  RetTypes) {
+  auto FuncRetType = Node.getReturnType().getAsString();
+  for (const auto RetType : RetTypes) {
+if (RetType == FuncRetType) {
+  return true;
+}
+  }
+  return false;
+}
 } // namespace
 
 UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
@@ -124,19 +135,28 @@
"::sigismember;"
"::strcasecmp;"
"::strsignal;"
-   "::ttyname")) {}
+   

[PATCH] D151383: [clang-tidy] Check for specific return types on all functions

2023-05-25 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

please let me know if there is better way to do the matching 
`hasAnyReturnType`.  We could also sort then do binarysearch instead of looping 
through the list of ret types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151383: [clang-tidy] Check for specific return types on all functions

2023-05-25 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 525855.
chaitanyav added a comment.

Add tests, update docs and extend matchcallexpr


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
@@ -52,6 +52,9 @@
   bool empty() const noexcept;
 };
 
+class error_code {
+};
+
 // the check should be able to match std lib calls even if the functions are
 // declared inside inline namespaces
 inline namespace v1 {
@@ -72,6 +75,10 @@
 
 void useFuture(const std::future );
 
+std::error_code errorFunc() {
+return std::error_code();
+}
+
 void warning() {
   std::async(increment, 42);
   // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function should be used
@@ -185,6 +192,10 @@
 // CHECK-NOTES: [[@LINE-1]]:5: warning: the value {{.*}} should be used
 // CHECK-NOTES: [[@LINE-2]]:5: note: cast {{.*}} this warning
   }
+
+  errorFunc();
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 }
 
 void noWarning() {
@@ -209,6 +220,8 @@
   std::vector VecNoWarning;
   auto VecEmptyRetval = VecNoWarning.empty();
 
+  (void) errorFunc();
+
   // test using the return value in different kinds of expressions
   useFuture(std::async(increment, 42));
   std::launder()->f();
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -46,5 +46,11 @@
  return value often indicates that the programmer confused the function with
  ``clear()``.
 
+.. option:: CheckedReturnTypes
+
+   Semicolon-separated list of function return types to check.
+   By default the following function return types are checked:
+   ``std::error_code std::expected boost::system::error_code abseil::Status``
+
 `cert-err33-c <../cert/err33-c.html>`_ is an alias of this check that checks a
 fixed and large set of standard library functions.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -391,6 +391,9 @@
   `: warn on ``const &&``
   constructors.
 
+- Extend ``bugprone-unused-return-value`` check to check for all functions
+  with specified return types using the ``CheckedReturnTypes`` option.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
@@ -27,6 +27,7 @@
 
 private:
   std::string CheckedFunctions;
+  std::string CheckedReturnTypes;
 };
 
 } // namespace clang::tidy::bugprone
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -28,6 +28,17 @@
   Finder, Builder);
 }
 
+// Checks if the function return type is in CheckedReturnedTypes
+AST_MATCHER_P(FunctionDecl, hasAnyReturnType, std::vector,
+  RetTypes) {
+  auto FuncRetType = Node.getReturnType().getAsString();
+  for (const auto RetType : RetTypes) {
+if (RetType == FuncRetType) {
+  return true;
+}
+  }
+  return false;
+}
 } // namespace
 
 UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
@@ -124,19 +135,28 @@
"::sigismember;"
"::strcasecmp;"
"::strsignal;"
-   "::ttyname")) {}
+   "::ttyname")),
+  CheckedReturnTypes(Options.get("CheckedReturnTypes",
+ "std::error_code;"
+ "std::expected;"
+ "boost::system::error_code;"
+

[PATCH] D151383: [clang-tidy] Check for specific return types on all functions

2023-05-24 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 525359.
chaitanyav added a comment.

Reuse diag code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp


Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -156,6 +156,15 @@
   auto UnusedInRangeForStmt = cxxForRangeStmt(hasBody(MatchedCallExpr));
   auto UnusedInCaseStmt = switchCase(forEach(MatchedCallExpr));
 
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(anyOf(
+   hasReturnTypeLoc(loc(asString("std::error_code"))),
+   hasReturnTypeLoc(loc(asString("std::expected"))),
+   
hasReturnTypeLoc(loc(asString("boost::system::error_code"))),
+   hasReturnTypeLoc(loc(asString("abseil::Status")))
+  .bind("return-types"),
+  this);
+
   Finder->addMatcher(
   stmt(anyOf(UnusedInCompoundStmt, UnusedInIfStmt, UnusedInWhileStmt,
  UnusedInDoStmt, UnusedInForStmt, UnusedInRangeForStmt,
@@ -164,13 +173,17 @@
 }
 
 void UnusedReturnValueCheck::check(const MatchFinder::MatchResult ) {
-  if (const auto *Matched = Result.Nodes.getNodeAs("match")) {
-diag(Matched->getBeginLoc(),
- "the value returned by this function should be used")
-<< Matched->getSourceRange();
-diag(Matched->getBeginLoc(),
- "cast the expression to void to silence this warning",
- DiagnosticIDs::Note);
+  const char *callExprBindingNames[] = {"return-types", "match"};
+  for (const char *callExprBindingName : callExprBindingNames) {
+if (const auto *Matched =
+Result.Nodes.getNodeAs(callExprBindingName)) {
+  diag(Matched->getBeginLoc(),
+   "the value returned by this function should be used")
+  << Matched->getSourceRange();
+  diag(Matched->getBeginLoc(),
+   "cast the expression to void to silence this warning",
+   DiagnosticIDs::Note);
+};
   }
 }
 


Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -156,6 +156,15 @@
   auto UnusedInRangeForStmt = cxxForRangeStmt(hasBody(MatchedCallExpr));
   auto UnusedInCaseStmt = switchCase(forEach(MatchedCallExpr));
 
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(anyOf(
+   hasReturnTypeLoc(loc(asString("std::error_code"))),
+   hasReturnTypeLoc(loc(asString("std::expected"))),
+   hasReturnTypeLoc(loc(asString("boost::system::error_code"))),
+   hasReturnTypeLoc(loc(asString("abseil::Status")))
+  .bind("return-types"),
+  this);
+
   Finder->addMatcher(
   stmt(anyOf(UnusedInCompoundStmt, UnusedInIfStmt, UnusedInWhileStmt,
  UnusedInDoStmt, UnusedInForStmt, UnusedInRangeForStmt,
@@ -164,13 +173,17 @@
 }
 
 void UnusedReturnValueCheck::check(const MatchFinder::MatchResult ) {
-  if (const auto *Matched = Result.Nodes.getNodeAs("match")) {
-diag(Matched->getBeginLoc(),
- "the value returned by this function should be used")
-<< Matched->getSourceRange();
-diag(Matched->getBeginLoc(),
- "cast the expression to void to silence this warning",
- DiagnosticIDs::Note);
+  const char *callExprBindingNames[] = {"return-types", "match"};
+  for (const char *callExprBindingName : callExprBindingNames) {
+if (const auto *Matched =
+Result.Nodes.getNodeAs(callExprBindingName)) {
+  diag(Matched->getBeginLoc(),
+   "the value returned by this function should be used")
+  << Matched->getSourceRange();
+  diag(Matched->getBeginLoc(),
+   "cast the expression to void to silence this warning",
+   DiagnosticIDs::Note);
+};
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151383: Check for specific return types on all functions

2023-05-24 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

@royjacobson Please list other types that must be included here. The tests are 
coming...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151383

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151383: Check for specific return types on all functions

2023-05-24 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav created this revision.
chaitanyav added a reviewer: royjacobson.
Herald added subscribers: PiotrZSL, carlosgalvezp.
Herald added a reviewer: njames93.
Herald added a project: All.
chaitanyav requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Extend the check to all functions with return types like

  std::error_code, std::expected, boost::system::error_code, abseil::Status...
  
  Resolves issue https://github.com/llvm/llvm-project/issues/62884


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151383

Files:
  clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp


Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -156,6 +156,15 @@
   auto UnusedInRangeForStmt = cxxForRangeStmt(hasBody(MatchedCallExpr));
   auto UnusedInCaseStmt = switchCase(forEach(MatchedCallExpr));
 
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(anyOf(
+   hasReturnTypeLoc(loc(asString("std::error_code"))),
+   hasReturnTypeLoc(loc(asString("std::expected"))),
+   
hasReturnTypeLoc(loc(asString("boost::system::error_code"))),
+   hasReturnTypeLoc(loc(asString("abseil::Status")))
+  .bind("return-types"),
+  this);
+
   Finder->addMatcher(
   stmt(anyOf(UnusedInCompoundStmt, UnusedInIfStmt, UnusedInWhileStmt,
  UnusedInDoStmt, UnusedInForStmt, UnusedInRangeForStmt,
@@ -164,6 +173,16 @@
 }
 
 void UnusedReturnValueCheck::check(const MatchFinder::MatchResult ) {
+
+  if (const auto *Matched = Result.Nodes.getNodeAs("return-types")) {
+diag(Matched->getBeginLoc(),
+ "the value returned by this function should be used")
+<< Matched->getSourceRange();
+diag(Matched->getBeginLoc(),
+ "cast the expression to void to silence this warning",
+ DiagnosticIDs::Note);
+  };
+
   if (const auto *Matched = Result.Nodes.getNodeAs("match")) {
 diag(Matched->getBeginLoc(),
  "the value returned by this function should be used")


Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -156,6 +156,15 @@
   auto UnusedInRangeForStmt = cxxForRangeStmt(hasBody(MatchedCallExpr));
   auto UnusedInCaseStmt = switchCase(forEach(MatchedCallExpr));
 
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(anyOf(
+   hasReturnTypeLoc(loc(asString("std::error_code"))),
+   hasReturnTypeLoc(loc(asString("std::expected"))),
+   hasReturnTypeLoc(loc(asString("boost::system::error_code"))),
+   hasReturnTypeLoc(loc(asString("abseil::Status")))
+  .bind("return-types"),
+  this);
+
   Finder->addMatcher(
   stmt(anyOf(UnusedInCompoundStmt, UnusedInIfStmt, UnusedInWhileStmt,
  UnusedInDoStmt, UnusedInForStmt, UnusedInRangeForStmt,
@@ -164,6 +173,16 @@
 }
 
 void UnusedReturnValueCheck::check(const MatchFinder::MatchResult ) {
+
+  if (const auto *Matched = Result.Nodes.getNodeAs("return-types")) {
+diag(Matched->getBeginLoc(),
+ "the value returned by this function should be used")
+<< Matched->getSourceRange();
+diag(Matched->getBeginLoc(),
+ "cast the expression to void to silence this warning",
+ DiagnosticIDs::Note);
+  };
+
   if (const auto *Matched = Result.Nodes.getNodeAs("match")) {
 diag(Matched->getBeginLoc(),
  "the value returned by this function should be used")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-23 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

I used the patch to compile LLVM, apache/arrow, apache/trafficserver, folly, 
tensorstore, protobuf. I did not see any cases with pointer arithmetic in these 
repos.  I see there is some value for the patch in terms of readability (will 
be helpful to someone who is new to a codebase). I have uploaded the make logs 
for the projects. I will attach the LLVM log in a bit since am building it from 
scratch. It's taking a while.
F27618552: apache_arrow_cpp_out.txt 

F27618556: apache_trafficserver_out.txt 

F27618559: protobuf_out.txt 

F27618563: folly_out.txt 

F27618565: tensorstore_out.txt 

Some examples

  
/home/nvellanki/scratch/temp_llvm/llvm-project/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp:3721:49:
 warning: operator '?:' has lower precedence than '%'; '%' will be evaluated 
first [-Wparentheses]
unsigned NumLeftovers = OrigNumElts % NumElts ? 1 : 0;
~ ^
  
/home/nvellanki/scratch/temp_llvm/llvm-project/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp:3721:49:
 note: place parentheses around the '%' expression to silence this warning
unsigned NumLeftovers = OrigNumElts % NumElts ? 1 : 0;
  ^
()
  
/home/nvellanki/scratch/temp_llvm/llvm-project/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp:3721:49:
 note: place parentheses around the '?:' expression to evaluate it first
unsigned NumLeftovers = OrigNumElts % NumElts ? 1 : 0;
  ^
  (  )
  
/home/nvellanki/scratch/temp_llvm/llvm-project/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp:3775:49:
 warning: operator '?:' has lower precedence than '%'; '%' will be evaluated 
first [-Wparentheses]
unsigned NumLeftovers = OrigNumElts % NumElts ? 1 : 0;
~ ^



  /home/nvellanki/scratch/tensorstore/build/_deps/zlib-src/crc32.c:572:19: 
warning: operator '?:' has lower precedence than '&'; '&' will be evaluated 
first [-Wbitwise-conditional-parentheses]
  b = b & 1 ? (b >> 1) ^ POLY : b >> 1;
  ~ ^
  /home/nvellanki/scratch/tensorstore/build/_deps/zlib-src/crc32.c:572:19: 
note: place parentheses around the '&' expression to silence this warning
  b = b & 1 ? (b >> 1) ^ POLY : b >> 1;
^
  ()
  /home/nvellanki/scratch/tensorstore/build/_deps/zlib-src/crc32.c:572:19: 
note: place parentheses around the '?:' expression to evaluate it first
  b = b & 1 ? (b >> 1) ^ POLY : b >> 1;
^
  (   )



  
/home/nvellanki/scratch/arrow/cpp/src/arrow/vendored/datetime/date.h:3941:61:
 warning: operator '?:' has lower precedence than '%'; '%' 
will be evaluated first [-Wparentheses]
  static CONSTDATA std::uint64_t value = h * h * (exp % 2 ? 10 : 1);
  ~~~ ^
  
/home/nvellanki/scratch/arrow/cpp/src/arrow/vendored/datetime/date.h:3941:61:
 note: place parentheses around the '%' expression to silence 
this warning
  static CONSTDATA std::uint64_t value = h * h * (exp % 2 ? 10 : 1);
  ^
  (  )
  
/home/nvellanki/scratch/arrow/cpp/src/arrow/vendored/datetime/date.h:3941:61:
 note: place parentheses around the '?:' expression to 
evaluate it first
  static CONSTDATA std::uint64_t value = h * h * (exp % 2 ? 10 : 1);
  ^
    (
 )



  
/home/nvellanki/scratch/trafficserver/include/tscore/SimpleTokenizer.h:145:47: 
warning: operator '?:' has lower precedence than '&'; '&' will be evaluated 
first [-Wbitwise-conditional-parentheses]
  _data   = (_mode & OVERWRITE_INPUT_STRING ? const_cast(s) : 
ats_strdup(s));
 ~~ ^
  
/home/nvellanki/scratch/trafficserver/include/tscore/SimpleTokenizer.h:145:47: 
note: place parentheses around the '&' expression to silence this warning
  _data   = (_mode & OVERWRITE_INPUT_STRING ? const_cast(s) : 
ats_strdup(s));
^
 ( )
  
/home/nvellanki/scratch/trafficserver/include/tscore/SimpleTokenizer.h:145:47: 
note: place parentheses around the '?:' expression to evaluate it first
  _data   = (_mode & OVERWRITE_INPUT_STRING ? 

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-23 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

In D147844#4361956 , @aaron.ballman 
wrote:

> In D147844#4335598 , @dblaikie 
> wrote:
>
>> In D147844#4329497 , 
>> @aaron.ballman wrote:
>>
>>> In general, I think this is incremental progress on the diagnostic 
>>> behavior. However, it's clear that there is room for interpretation on what 
>>> is or is not a false positive diagnostic for this,
>>
>> I hope we can agree on what a false positive is here - when the warning 
>> fires but the code is what the developer intended (ie: the existing code 
>> with the existing language semantics produce the desired result, the "fix" 
>> is to add parentheses that explicitly encode the language's existing 
>> rules/behavior anyway).
>
> I agree with that definition -- that's a useful way to approach this, thank 
> you!
>
>> Not that we don't have warnings that do this - that encourage parens to 
>> reinforce what the language already does to be more explicit/intentional 
>> about it, and in some cases it's not that uncommon that the user will be 
>> adding parens that reinforce the precedence rules anyway.
>
> Yup, which is largely what this patch is about.
>
>> Like, I think all the fixes in libc++, llvm, etc, are false positives? (none 
>> of them found bugs/unintended behavior)
>
> Yes, they all are false positives by the above definition.
>
>> Are there any examples of bugs being found by this warning in a codebase? (& 
>> how many false positives in such a codebase did it also flag?)
>
> This would be good to know, but a bit of a heavy lift to require of 
> @chaitanyav because they were working on this issue 
> (https://github.com/llvm/llvm-project/issues/61943) with a "good first issue" 
> label that is starting to look a bit like it was misleading (sorry about 
> that!). However, if you're able to try compiling some larger projects with 
> your patch applied to see if it spots any bugs in real world code, that would 
> be very helpful!

@aaron.ballman will try this patch on some projects and post the results here

>>> so we should pay close attention to user feedback during the 17.x release 
>>> cycle. If it seems we're getting significant push back, we may need to come 
>>> back and rethink.
>>>
>>> Specifically, I think we've improved the situation for code like this:
>>>
>>>   // `p` is a pointer, `x` is an `int`, and `b` is a `bool`
>>>   p + x ? 1 : 2; // previously didn't warn, now warns
>>>   p + b ? 1 : 2; // always warned
>>>
>>> Does anyone feel we should not move forward with accepting the patch in its 
>>> current form?
>>
>> *goes to look*
>>
>> Mixed feelings - you're right, incremental improvement/adding missed cases 
>> to an existing warning (especially if that warning's already stylistic in 
>> nature) is a lower bar/doesn't necessarily need the false positive 
>> assessment. But it looks like this case might've been intentionally 
>> suppressed in the initial warning implementation? (anyone linked to the 
>> original warning implementation/review/design to check if this was 
>> intentional?)
>
> I tried to chase down where this got added to see what review comments there 
> were, but it seems to predate my involvement (I'm seeing mentions of this in 
> 2011).
>
>> But, yeah, seems marginal enough I don't have strong feelings either way.
>
> Thank you for the opinion! I think pointer + int is a far more common code 
> pattern than pointer + bool, so it makes some sense to me that we would 
> silence the first case while diagnosing the second case. Given the general 
> lack of enthusiasm for the new diagnostics, it may boil down to answering 
> whether this finds any true positives or not.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-22 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 524376.
chaitanyav added a comment.

Rebase with upstream


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto deterministic_v = deterministic();
   

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-22 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 524321.
chaitanyav added a comment.

Rebase with upstream


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto deterministic_v = deterministic();
   

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-20 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 524072.
chaitanyav added a comment.

Rebase with upstream


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto deterministic_v = deterministic();
   

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-11 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 521330.
chaitanyav added a comment.

Rebase with upstream


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto deterministic_v = deterministic();
   

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-10 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 521203.
chaitanyav added a comment.

Remove extra parens


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto deterministic_v = deterministic();
   

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-09 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 520725.
chaitanyav added a comment.

Rebase with upstream and remove duplicate line from ReleaseNotes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = ((actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND);
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
 

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-08 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 520491.
chaitanyav added a comment.

Rebase with upstream


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = ((actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND);
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto deterministic_v = deterministic();
  

[PATCH] D149737: [clang][ExtractAPI] Add semicolon to function declaration fragments

2023-05-04 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG14805dcb0d8a: [clang][ExtractAPI] Add semicolon to function 
declaration fragments (authored by chaitanyav).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149737

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/availability.c
  clang/test/ExtractAPI/global_record.c
  clang/test/ExtractAPI/global_record_multifile.c
  clang/test/ExtractAPI/macro_undefined.c

Index: clang/test/ExtractAPI/macro_undefined.c
===
--- clang/test/ExtractAPI/macro_undefined.c
+++ clang/test/ExtractAPI/macro_undefined.c
@@ -67,7 +67,7 @@
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -173,7 +173,7 @@
 },
 {
   "kind": "text",
-  "spelling": ")"
+  "spelling": ");"
 }
   ],
   "functionSignature": {
Index: clang/test/ExtractAPI/global_record_multifile.c
===
--- clang/test/ExtractAPI/global_record_multifile.c
+++ clang/test/ExtractAPI/global_record_multifile.c
@@ -191,7 +191,7 @@
 },
 {
   "kind": "text",
-  "spelling": ")"
+  "spelling": ");"
 }
   ],
   "docComment": {
Index: clang/test/ExtractAPI/global_record.c
===
--- clang/test/ExtractAPI/global_record.c
+++ clang/test/ExtractAPI/global_record.c
@@ -189,7 +189,7 @@
 },
 {
   "kind": "text",
-  "spelling": ")"
+  "spelling": ");"
 }
   ],
   "docComment": {
Index: clang/test/ExtractAPI/availability.c
===
--- clang/test/ExtractAPI/availability.c
+++ clang/test/ExtractAPI/availability.c
@@ -76,7 +76,7 @@
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -150,7 +150,7 @@
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -234,7 +234,7 @@
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -334,7 +334,7 @@
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -416,7 +416,7 @@
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
Index: clang/lib/ExtractAPI/DeclarationFragments.cpp
===
--- clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -457,7 +457,7 @@
   Fragments.append(")", DeclarationFragments::FragmentKind::Text);
 
   // FIXME: Handle exception specifiers: throw, noexcept
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForEnumConstant(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146090: [Clang] Updating handling of defaulted comparison operators to reflect changes from P2448R2

2023-05-04 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

@shafik @aaron.ballman I see some errors

  [1/2496] Building DiagnosticAnalysisKinds.inc...
  FAILED: tools/clang/include/clang/Basic/DiagnosticAnalysisKinds.inc 
/home/nvellanki/scratch/llvm-project/tools/clang/include/clang/Basic/DiagnosticAnalysisKinds.inc
 
  cd /home/nvellanki/scratch/llvm-project && 
/home/nvellanki/scratch/llvm-project/bin/clang-tblgen -gen-clang-diags-defs 
-clang-component=Analysis -I 
/home/nvellanki/scratch/llvm-project/clang/include/clang/Basic 
-I/home/nvellanki/scratch/llvm-project/clang/include 
-I/home/nvellanki/scratch/llvm-project/tools/clang/include 
-I/home/nvellanki/scratch/llvm-project/include 
-I/home/nvellanki/scratch/llvm-project/llvm/include 
/home/nvellanki/scratch/llvm-project/clang/include/clang/Basic/Diagnostic.td 
--write-if-changed -o 
tools/clang/include/clang/Basic/DiagnosticAnalysisKinds.inc -d 
tools/clang/include/clang/Basic/DiagnosticAnalysisKinds.inc.d
  Included from 
/home/nvellanki/scratch/llvm-project/clang/include/clang/Basic/Diagnostic.td:168:
  
/home/nvellanki/scratch/llvm-project/clang/include/clang/Basic/DiagnosticSemaKinds.td:9443:11:
 error: Variable not defined: 'CXXPre2bCompat'
InGroup, DefaultIgnore;
^


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146090

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-03 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 519259.
chaitanyav added a comment.

Rebase with upstream


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = ((actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND);
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto deterministic_v = deterministic();
  

[PATCH] D149737: [clang][ExtractAPI] Add semicolon to function declaration fragments

2023-05-03 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

@dang @ributzka I missed adding semicolons to function declaration fragments in 
this commit 
https://github.com/llvm/llvm-project/commit/afce10c5b60fada1db369d3770f4389da7ef30ef
 . Please review this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149737: [clang][ExtractAPI] Add semicolon to function declaration fragments

2023-05-03 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav created this revision.
chaitanyav added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
chaitanyav requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add missing semicolon at the end of function declarations to fragments


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149737

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/availability.c
  clang/test/ExtractAPI/global_record.c
  clang/test/ExtractAPI/global_record_multifile.c
  clang/test/ExtractAPI/macro_undefined.c

Index: clang/test/ExtractAPI/macro_undefined.c
===
--- clang/test/ExtractAPI/macro_undefined.c
+++ clang/test/ExtractAPI/macro_undefined.c
@@ -67,7 +67,7 @@
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -173,7 +173,7 @@
 },
 {
   "kind": "text",
-  "spelling": ")"
+  "spelling": ");"
 }
   ],
   "functionSignature": {
Index: clang/test/ExtractAPI/global_record_multifile.c
===
--- clang/test/ExtractAPI/global_record_multifile.c
+++ clang/test/ExtractAPI/global_record_multifile.c
@@ -191,7 +191,7 @@
 },
 {
   "kind": "text",
-  "spelling": ")"
+  "spelling": ");"
 }
   ],
   "docComment": {
Index: clang/test/ExtractAPI/global_record.c
===
--- clang/test/ExtractAPI/global_record.c
+++ clang/test/ExtractAPI/global_record.c
@@ -189,7 +189,7 @@
 },
 {
   "kind": "text",
-  "spelling": ")"
+  "spelling": ");"
 }
   ],
   "docComment": {
Index: clang/test/ExtractAPI/availability.c
===
--- clang/test/ExtractAPI/availability.c
+++ clang/test/ExtractAPI/availability.c
@@ -76,7 +76,7 @@
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -150,7 +150,7 @@
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -234,7 +234,7 @@
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -334,7 +334,7 @@
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -416,7 +416,7 @@
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
Index: clang/lib/ExtractAPI/DeclarationFragments.cpp
===
--- clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -457,7 +457,7 @@
   Fragments.append(")", DeclarationFragments::FragmentKind::Text);
 
   // FIXME: Handle exception specifiers: throw, noexcept
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForEnumConstant(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-04-28 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 518118.
chaitanyav added a comment.

Rebase with upstream


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto deterministic_v = deterministic();
   

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-04-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 517429.
chaitanyav added a comment.

Revert libcxx libcxxabi files unrelated to the issue


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto 

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-04-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 517372.
chaitanyav added a comment.

Add parentheses around integer expressions in libcxx tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/src/filesystem/operations.cpp
  libcxx/src/locale.cpp
  libcxx/src/memory_resource.cpp
  libcxx/src/ryu/d2fixed.cpp
  libcxx/src/ryu/f2s.cpp
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_default_handlers.cpp
  libcxxabi/src/cxa_demangle.cpp
  libcxxabi/src/cxa_exception.cpp
  libcxxabi/src/cxa_personality.cpp
  libcxxabi/src/demangle/ItaniumDemangle.h

Index: libcxxabi/src/demangle/ItaniumDemangle.h
===
--- libcxxabi/src/demangle/ItaniumDemangle.h
+++ libcxxabi/src/demangle/ItaniumDemangle.h
@@ -1306,7 +1306,7 @@
   const Node *getSyntaxNode(OutputBuffer ) const override {
 initializePackExpansion(OB);
 size_t Idx = OB.CurrentPackIndex;
-return Idx < Data.size() ? Data[Idx]->getSyntaxNode(OB) : this;
+return (Idx < Data.size()) ? Data[Idx]->getSyntaxNode(OB) : this;
   }
 
   void printLeft(OutputBuffer ) const override {
@@ -2499,7 +2499,7 @@
 return false;
   }
 
-  char consume() { return First != Last ? *First++ : '\0'; }
+  char consume() { return (First != Last) ? *First++ : '\0'; }
 
   char look(unsigned Lookahead = 0) const {
 if (static_cast(Last - First) <= Lookahead)
Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxxabi/src/cxa_exception.cpp
===
--- libcxxabi/src/cxa_exception.cpp
+++ libcxxabi/src/cxa_exception.cpp
@@ -455,8 +455,8 @@
 if (native_exception)
 {
 // Increment the handler count, removing the flag about being rethrown
-exception_header->handlerCount = exception_header->handlerCount < 0 ?
--exception_header->handlerCount + 1 : exception_header->handlerCount + 1;
+exception_header->handlerCount = (exception_header->handlerCount < 0) ? -exception_header->handlerCount + 1
+  : 

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-04-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 517300.
chaitanyav added a comment.

Revert to earliest patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/src/filesystem/operations.cpp
  libcxx/src/locale.cpp
  libcxx/src/memory_resource.cpp
  libcxx/src/ryu/d2fixed.cpp
  libcxx/src/ryu/f2s.cpp
  libcxxabi/src/cxa_default_handlers.cpp
  libcxxabi/src/cxa_demangle.cpp
  libcxxabi/src/cxa_exception.cpp
  libcxxabi/src/cxa_personality.cpp
  libcxxabi/src/demangle/ItaniumDemangle.h

Index: libcxxabi/src/demangle/ItaniumDemangle.h
===
--- libcxxabi/src/demangle/ItaniumDemangle.h
+++ libcxxabi/src/demangle/ItaniumDemangle.h
@@ -1306,7 +1306,7 @@
   const Node *getSyntaxNode(OutputBuffer ) const override {
 initializePackExpansion(OB);
 size_t Idx = OB.CurrentPackIndex;
-return Idx < Data.size() ? Data[Idx]->getSyntaxNode(OB) : this;
+return (Idx < Data.size()) ? Data[Idx]->getSyntaxNode(OB) : this;
   }
 
   void printLeft(OutputBuffer ) const override {
@@ -2499,7 +2499,7 @@
 return false;
   }
 
-  char consume() { return First != Last ? *First++ : '\0'; }
+  char consume() { return (First != Last) ? *First++ : '\0'; }
 
   char look(unsigned Lookahead = 0) const {
 if (static_cast(Last - First) <= Lookahead)
Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxxabi/src/cxa_exception.cpp
===
--- libcxxabi/src/cxa_exception.cpp
+++ libcxxabi/src/cxa_exception.cpp
@@ -455,8 +455,8 @@
 if (native_exception)
 {
 // Increment the handler count, removing the flag about being rethrown
-exception_header->handlerCount = exception_header->handlerCount < 0 ?
--exception_header->handlerCount + 1 : exception_header->handlerCount + 1;
+exception_header->handlerCount = (exception_header->handlerCount < 0) ? -exception_header->handlerCount + 1
+  : exception_header->handlerCount + 1;
 //  place the exception on the top of the stack if it's not already
 //there by a previous rethrow
 if (exception_header != globals->caughtExceptions)
Index: 

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-04-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

In D147844#4299874 , @aaron.ballman 
wrote:

> In D147844#4299856 , @chaitanyav 
> wrote:
>
>> Disable precedence conditional warning by default; Revert changes to test 
>> files
>
> I'm sorry, I think there was a miscommunication. We were saying that we don't 
> typically want off-by-default diagnostics at all, not asking to turn this one 
> off by default. We've found that when a diagnostic is off by default, it very 
> rarely gets enabled by enough projects to be worth having the diagnostic. So 
> we instead expect diagnostics to have a very low false positive rate so that 
> they can be on by default without worrying that a lot of users will have to 
> disable it due to chattiness.
>
> So instead of making this diagnostic be `DefaultIgnore`, I think you should 
> back out most of the recent changes so we're back to only the small number of 
> additional diagnostics in the earlier patches.

@aaron.ballman am reverting to the earliest patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-04-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 517268.
chaitanyav added a comment.

Disable precedence conditional warning by default; Revert changes to test files


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/Sema/sizeless-1.c
  clang/test/Sema/zvector.c
  clang/test/Sema/zvector2.c
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/src/filesystem/operations.cpp
  libcxx/src/locale.cpp
  libcxx/src/memory_resource.cpp
  libcxx/src/ryu/d2fixed.cpp
  libcxx/src/ryu/f2s.cpp
  libcxxabi/src/cxa_default_handlers.cpp
  libcxxabi/src/cxa_demangle.cpp
  libcxxabi/src/cxa_exception.cpp
  libcxxabi/src/cxa_personality.cpp
  libcxxabi/src/demangle/ItaniumDemangle.h

Index: libcxxabi/src/demangle/ItaniumDemangle.h
===
--- libcxxabi/src/demangle/ItaniumDemangle.h
+++ libcxxabi/src/demangle/ItaniumDemangle.h
@@ -1306,7 +1306,7 @@
   const Node *getSyntaxNode(OutputBuffer ) const override {
 initializePackExpansion(OB);
 size_t Idx = OB.CurrentPackIndex;
-return Idx < Data.size() ? Data[Idx]->getSyntaxNode(OB) : this;
+return (Idx < Data.size()) ? Data[Idx]->getSyntaxNode(OB) : this;
   }
 
   void printLeft(OutputBuffer ) const override {
@@ -2499,7 +2499,7 @@
 return false;
   }
 
-  char consume() { return First != Last ? *First++ : '\0'; }
+  char consume() { return (First != Last) ? *First++ : '\0'; }
 
   char look(unsigned Lookahead = 0) const {
 if (static_cast(Last - First) <= Lookahead)
Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxxabi/src/cxa_exception.cpp
===
--- libcxxabi/src/cxa_exception.cpp
+++ libcxxabi/src/cxa_exception.cpp
@@ -455,8 +455,8 @@
 if (native_exception)
 {
 // Increment the handler count, removing the flag about being rethrown
-exception_header->handlerCount = exception_header->handlerCount < 0 ?
--exception_header->handlerCount + 1 : exception_header->handlerCount + 1;
+exception_header->handlerCount = (exception_header->handlerCount < 0) ? -exception_header->handlerCount + 1
+  : exception_header->handlerCount + 1;
 //  place the exception on the top of the stack if it's not already
 //there by a previous rethrow
 if (exception_header != 

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-04-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

@aaron.ballman just for learning, can you point me to the code where a warning 
is selectively enabled/disabled based on a flag. For e.g. -Wunused-comparison


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-04-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 517070.
chaitanyav added a comment.
Herald added a subscriber: arphaman.

Fix more failing tests due to missing parentheses in conditional operator 
expression


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/Interp/constexpr-nqueens.cpp
  clang/test/AST/Interp/literals.cpp
  clang/test/Analysis/copypaste/macro-complexity.cpp
  clang/test/Analysis/cxx-uninitialized-object-unguarded-access.cpp
  clang/test/Analysis/malloc-overflow.c
  clang/test/Analysis/misc-ps.m
  clang/test/Analysis/nullability.mm
  clang/test/Analysis/runtime-regression.c
  clang/test/Analysis/uninit-vals.c
  clang/test/Analysis/use-after-move.cpp
  clang/test/CXX/class.access/class.access.dcl/p1.cpp
  clang/test/CXX/drs/dr1xx.cpp
  clang/test/CXX/drs/dr4xx.cpp
  clang/test/CXX/drs/dr5xx.cpp
  clang/test/CXX/drs/dr6xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/partial-ordering.cpp
  clang/test/Frontend/macros.c
  clang/test/Headers/limits.cpp
  clang/test/Index/recursive-cxx-member-calls.cpp
  clang/test/Lexer/char-escapes.c
  clang/test/Lexer/utf8-char-literal.cpp
  clang/test/Misc/no-warn-in-system-macro.c.inc
  clang/test/Modules/module-private.cpp
  clang/test/OpenMP/atomic_messages.c
  clang/test/OpenMP/cancel_if_messages.cpp
  clang/test/OpenMP/distribute_collapse_messages.cpp
  clang/test/OpenMP/distribute_dist_schedule_messages.cpp
  clang/test/OpenMP/distribute_firstprivate_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_collapse_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_copyin_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_dist_schedule_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_firstprivate_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_if_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_lastprivate_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_num_threads_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_private_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_reduction_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_schedule_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_shared_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_collapse_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_copyin_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_dist_schedule_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_if_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_linear_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_num_threads_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_private_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_reduction_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_safelen_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_schedule_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_shared_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_simdlen_messages.cpp
  clang/test/OpenMP/distribute_private_messages.cpp
  clang/test/OpenMP/distribute_simd_aligned_messages.cpp
  clang/test/OpenMP/distribute_simd_collapse_messages.cpp
  clang/test/OpenMP/distribute_simd_dist_schedule_messages.cpp
  clang/test/OpenMP/distribute_simd_firstprivate_messages.cpp
  clang/test/OpenMP/distribute_simd_if_messages.cpp
  clang/test/OpenMP/distribute_simd_lastprivate_messages.cpp
  clang/test/OpenMP/distribute_simd_linear_messages.cpp
  clang/test/OpenMP/distribute_simd_private_messages.cpp
  clang/test/OpenMP/distribute_simd_reduction_messages.cpp
  clang/test/OpenMP/distribute_simd_safelen_messages.cpp
  clang/test/OpenMP/distribute_simd_simdlen_messages.cpp
  clang/test/OpenMP/for_collapse_messages.cpp
  clang/test/OpenMP/for_firstprivate_messages.cpp
  clang/test/OpenMP/for_lastprivate_messages.cpp
  clang/test/OpenMP/for_linear_messages.cpp
  clang/test/OpenMP/for_ordered_clause.cpp
  clang/test/OpenMP/for_private_messages.cpp
  clang/test/OpenMP/for_reduction_messages.cpp
  clang/test/OpenMP/for_schedule_messages.cpp
  clang/test/OpenMP/for_simd_aligned_messages.cpp
  clang/test/OpenMP/for_simd_collapse_messages.cpp
  clang/test/OpenMP/for_simd_firstprivate_messages.cpp
  clang/test/OpenMP/for_simd_if_messages.cpp
  clang/test/OpenMP/for_simd_lastprivate_messages.cpp
  clang/test/OpenMP/for_simd_linear_messages.cpp
  clang/test/OpenMP/for_simd_private_messages.cpp
  clang/test/OpenMP/for_simd_reduction_messages.cpp
  clang/test/OpenMP/for_simd_safelen_messages.cpp
  clang/test/OpenMP/for_simd_schedule_messages.cpp
  

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-04-25 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

Added parentheses to lots of files to fix the precedence warning. Still a lot 
to change in OpenMP.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-04-25 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 517042.
chaitanyav added a comment.
Herald added subscribers: jplehr, kosarev, jdoerfert, sstefan1, kerbowa, 
jvesely.
Herald added a reviewer: jdoerfert.

Fix tests/code by adding parentheses around the conditional operator expression


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/Interp/constexpr-nqueens.cpp
  clang/test/AST/Interp/literals.cpp
  clang/test/Analysis/copypaste/macro-complexity.cpp
  clang/test/Analysis/cxx-uninitialized-object-unguarded-access.cpp
  clang/test/Analysis/malloc-overflow.c
  clang/test/Analysis/misc-ps.m
  clang/test/Analysis/nullability.mm
  clang/test/Analysis/runtime-regression.c
  clang/test/Analysis/uninit-vals.c
  clang/test/Analysis/use-after-move.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/partial-ordering.cpp
  clang/test/Frontend/macros.c
  clang/test/OpenMP/cancel_if_messages.cpp
  clang/test/OpenMP/distribute_collapse_messages.cpp
  clang/test/OpenMP/distribute_dist_schedule_messages.cpp
  clang/test/OpenMP/distribute_firstprivate_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_collapse_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_copyin_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_dist_schedule_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_firstprivate_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_if_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_lastprivate_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_num_threads_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_private_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_reduction_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_schedule_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_shared_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_collapse_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_copyin_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_dist_schedule_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_if_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_linear_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_num_threads_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_private_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_reduction_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_safelen_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_schedule_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_shared_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_simdlen_messages.cpp
  clang/test/OpenMP/distribute_private_messages.cpp
  clang/test/OpenMP/distribute_simd_aligned_messages.cpp
  clang/test/OpenMP/distribute_simd_collapse_messages.cpp
  clang/test/OpenMP/distribute_simd_dist_schedule_messages.cpp
  clang/test/OpenMP/distribute_simd_firstprivate_messages.cpp
  clang/test/OpenMP/distribute_simd_if_messages.cpp
  clang/test/OpenMP/distribute_simd_lastprivate_messages.cpp
  clang/test/OpenMP/distribute_simd_linear_messages.cpp
  clang/test/OpenMP/distribute_simd_private_messages.cpp
  clang/test/OpenMP/distribute_simd_reduction_messages.cpp
  clang/test/OpenMP/distribute_simd_safelen_messages.cpp
  clang/test/OpenMP/distribute_simd_simdlen_messages.cpp
  clang/test/OpenMP/for_collapse_messages.cpp
  clang/test/OpenMP/for_firstprivate_messages.cpp
  clang/test/OpenMP/for_lastprivate_messages.cpp
  clang/test/OpenMP/for_linear_messages.cpp
  clang/test/OpenMP/for_ordered_clause.cpp
  clang/test/OpenMP/for_private_messages.cpp
  clang/test/OpenMP/for_reduction_messages.cpp
  clang/test/OpenMP/for_schedule_messages.cpp
  clang/test/OpenMP/for_simd_aligned_messages.cpp
  clang/test/OpenMP/for_simd_collapse_messages.cpp
  clang/test/OpenMP/for_simd_firstprivate_messages.cpp
  clang/test/OpenMP/for_simd_if_messages.cpp
  clang/test/OpenMP/for_simd_lastprivate_messages.cpp
  clang/test/OpenMP/for_simd_linear_messages.cpp
  clang/test/OpenMP/for_simd_private_messages.cpp
  clang/test/OpenMP/for_simd_reduction_messages.cpp
  clang/test/OpenMP/for_simd_safelen_messages.cpp
  clang/test/OpenMP/for_simd_schedule_messages.cpp
  clang/test/OpenMP/for_simd_simdlen_messages.cpp
  clang/test/OpenMP/masked_taskloop_collapse_messages.cpp
  clang/test/OpenMP/masked_taskloop_final_messages.cpp
  clang/test/OpenMP/masked_taskloop_firstprivate_messages.cpp
  clang/test/OpenMP/masked_taskloop_grainsize_messages.cpp
  clang/test/OpenMP/masked_taskloop_in_reduction_messages.cpp
  

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-04-25 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

In D147844#4293299 , @cjdb wrote:

> I think this is a good diagnostic to add: it improves readability and 
> eliminates ambiguities. My only request is that if there isn't already a 
> FixIt hint, one be added, please.

@cjb quick question, should we restrict to

  >, <, >=, <= 

I am finding lots of files in the project with ` ==` and `?:` precedence 
warnings.




Comment at: clang/test/Sema/parentheses.c:94
 
   (void)(x + y > 0 ? 1 : 2); // no warning
   (void)(x + (y > 0) ? 1 : 2); // expected-warning {{operator '?:' has lower 
precedence than '+'}} expected-note 2{{place parentheses}}

cjdb wrote:
> I think this should also warn.
@cjdb am looking into this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: [clang][Sema]Print diagnostic warning when implicit cast from int to bool happens in an conditional operator expression

2023-04-21 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 515978.
chaitanyav added a comment.

Revise commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto deterministic_v = deterministic();
   

[PATCH] D147844: Emit warning when implicit cast from int to bool happens in an conditional operator expression

2023-04-21 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 515974.
chaitanyav marked an inline comment as done.
chaitanyav added a comment.

Modify the commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
  

[PATCH] D147844: Emit warning when implicit cast from int to bool happens in an conditional operator expression

2023-04-21 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 515687.
chaitanyav added a comment.

Fix indentation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto deterministic_v = deterministic();
   

[PATCH] D147844: Emit warning when implicit cast from int to bool happens in an conditional operator expression

2023-04-21 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

@aaron.ballman please take a look.

I filed a issue that premerge checks are not working on AIX
https://github.com/google/llvm-premerge-checks/issues/441

Not sure why the TSAN, MSAN and ASAN checks are failing on libcxx


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: Emit warning when implicit cast from int to bool happens in an conditional operator expression

2023-04-20 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 515591.
chaitanyav added a comment.

Place parentheses around conditional expression to prevent precedence warnings 
since -Werror is enabled on build


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   std::less comp;
   std::__sort_dispatch(v.begin(), v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto deterministic_v = deterministic();
   std::sort(v.begin(), v.end());
@@ -62,7 +62,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = kSize / 2 - i * (i % 2 ? -1 : 1);
+v[i].value = kSize / 2 - i * ((i % 2) ? -1 : 1);
   }
   auto snapshot_v = v;
   auto snapshot_custom_v = v;
Index: libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
===
--- libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
+++ libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
@@ -32,7 +32,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+v[i].value = ((i % 2) ? 1 : kSize / 2 + i);
   }
   auto comp = std::less();
   std::__partial_sort_impl(v.begin(), v.begin() + kSize / 2, v.end(), comp);
@@ -44,7 +44,7 @@
   std::vector v;
   v.resize(kSize);
   for (int i = 0; i < kSize; ++i) {
-v[i].value = (i % 2 ? 1 : kSize / 2 + i);
+

[PATCH] D147844: Emit warning when implicit cast from int to bool happens in an conditional operator expression

2023-04-20 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 515513.
chaitanyav added a comment.

clang-format the changes to the file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1243,10 +1240,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/include/__chrono/duration.h
===
--- libcxx/include/__chrono/duration.h
+++ libcxx/include/__chrono/duration.h
@@ -194,7 +194,7 @@
 return __lower;
 if (__lower_diff > __upper_diff)
 return __upper;
-return __lower.count() & 1 ? __upper : __lower;
+return (__lower.count() & 1) ? __upper : __lower;
 }
 #endif
 
Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -41,7 +41,7 @@
   uint64_t not_overflow2 = (1ULL * ((uint64_t)(4608) * (1024 * 1024)) + 2ULL);
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
-  overflow = 4608 * 1024 * 1024 ?  4608 * 1024 * 1024 : 0;
+  overflow = (4608 * 1024 * 1024) ?  4608 * 1024 * 1024 : 0;
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
   overflow =  0 ? 0 : 4608 * 1024 * 1024;
Index: clang/test/SemaCXX/array-bounds.cpp
===
--- clang/test/SemaCXX/array-bounds.cpp
+++ clang/test/SemaCXX/array-bounds.cpp
@@ -87,7 +87,7 @@
 }
 
 #define SIZE 10
-#define ARR_IN_MACRO(flag, arr, idx) flag ? arr[idx] : 1
+#define ARR_IN_MACRO(flag, arr, idx) (flag ? arr[idx] : 1)
 
 int test_no_warn_macro_unreachable() {
   int arr[SIZE]; // expected-note {{array 'arr' declared here}}
Index: clang/test/Sema/parentheses.cpp
===
--- clang/test/Sema/parentheses.cpp
+++ clang/test/Sema/parentheses.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only 

[PATCH] D147844: Emit warning when implicit cast from int to bool happens in an conditional operator expression

2023-04-20 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 515492.
chaitanyav added a comment.
Herald added a project: libc++abi.
Herald added a reviewer: libc++abi.

Place parentheses around conditional expression to prevent precedence warnings 
since -Werror is enabled on build


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,7 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
+  results.reason = (actions & _UA_SEARCH_PHASE)
  ? _URC_CONTINUE_UNWIND
  : _URC_HANDLER_FOUND;
 return;
@@ -832,7 +832,7 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
+  results.reason = (hasCleanup && (actions & _UA_CLEANUP_PHASE))
  ? _URC_HANDLER_FOUND
  : _URC_CONTINUE_UNWIND;
 return;
@@ -1244,7 +1244,7 @@
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
 adjustedPtr =
-__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass ?
+  (__getExceptionClass(_exception_header->unwindHeader) == kOurDependentExceptionClass) ?
 ((__cxa_dependent_exception*)new_exception_header)->primaryException :
 new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
Index: libcxx/include/__chrono/duration.h
===
--- libcxx/include/__chrono/duration.h
+++ libcxx/include/__chrono/duration.h
@@ -194,7 +194,7 @@
 return __lower;
 if (__lower_diff > __upper_diff)
 return __upper;
-return __lower.count() & 1 ? __upper : __lower;
+return (__lower.count() & 1) ? __upper : __lower;
 }
 #endif
 
Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -41,7 +41,7 @@
   uint64_t not_overflow2 = (1ULL * ((uint64_t)(4608) * (1024 * 1024)) + 2ULL);
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
-  overflow = 4608 * 1024 * 1024 ?  4608 * 1024 * 1024 : 0;
+  overflow = (4608 * 1024 * 1024) ?  4608 * 1024 * 1024 : 0;
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
   overflow =  0 ? 0 : 4608 * 1024 * 1024;
Index: clang/test/SemaCXX/array-bounds.cpp
===
--- clang/test/SemaCXX/array-bounds.cpp
+++ clang/test/SemaCXX/array-bounds.cpp
@@ -87,7 +87,7 @@
 }
 
 #define SIZE 10
-#define ARR_IN_MACRO(flag, arr, idx) flag ? arr[idx] : 1
+#define ARR_IN_MACRO(flag, arr, idx) (flag ? arr[idx] : 1)
 
 int test_no_warn_macro_unreachable() {
   int arr[SIZE]; // expected-note {{array 'arr' declared here}}
Index: clang/test/Sema/parentheses.cpp
===
--- clang/test/Sema/parentheses.cpp
+++ clang/test/Sema/parentheses.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 bool someConditionFunc();
 
@@ -38,7 +38,7 @@
   Stream >>(const char*);
 };
 
-void f(Stream& s, bool b) {
+void f(Stream& s, bool b, int x) {
   (void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '<<'}} \
   // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
   

[PATCH] D147844: Emit warning when implicit cast to bool happens in an conditional operator expression when used inside an overloaded shift operator expression

2023-04-20 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 515445.
chaitanyav added a comment.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Place parentheses around conditional operator since & has higher precedence


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h

Index: libcxx/include/__chrono/duration.h
===
--- libcxx/include/__chrono/duration.h
+++ libcxx/include/__chrono/duration.h
@@ -194,7 +194,7 @@
 return __lower;
 if (__lower_diff > __upper_diff)
 return __upper;
-return __lower.count() & 1 ? __upper : __lower;
+return (__lower.count() & 1) ? __upper : __lower;
 }
 #endif
 
Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -41,7 +41,7 @@
   uint64_t not_overflow2 = (1ULL * ((uint64_t)(4608) * (1024 * 1024)) + 2ULL);
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
-  overflow = 4608 * 1024 * 1024 ?  4608 * 1024 * 1024 : 0;
+  overflow = (4608 * 1024 * 1024) ?  4608 * 1024 * 1024 : 0;
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
   overflow =  0 ? 0 : 4608 * 1024 * 1024;
Index: clang/test/SemaCXX/array-bounds.cpp
===
--- clang/test/SemaCXX/array-bounds.cpp
+++ clang/test/SemaCXX/array-bounds.cpp
@@ -87,7 +87,7 @@
 }
 
 #define SIZE 10
-#define ARR_IN_MACRO(flag, arr, idx) flag ? arr[idx] : 1
+#define ARR_IN_MACRO(flag, arr, idx) (flag ? arr[idx] : 1)
 
 int test_no_warn_macro_unreachable() {
   int arr[SIZE]; // expected-note {{array 'arr' declared here}}
Index: clang/test/Sema/parentheses.cpp
===
--- clang/test/Sema/parentheses.cpp
+++ clang/test/Sema/parentheses.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 bool someConditionFunc();
 
@@ -38,7 +38,7 @@
   Stream >>(const char*);
 };
 
-void f(Stream& s, bool b) {
+void f(Stream& s, bool b, int x) {
   (void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '<<'}} \
   // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
   // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
@@ -62,6 +62,30 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:16-[[@LINE-4]]:16}:")"
   // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
   // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:21-[[@LINE-6]]:21}:")"
+
+  void(s << "Test" << x ? "foo" : "bar"); //expected-warning {{operator '?:' has lower precedence than '<<'}} \
+ // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+// expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:24-[[@LINE-4]]:24}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:23-[[@LINE-5]]:23}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:40-[[@LINE-6]]:40}:")"
+
+  void(s << x == 1 ? "foo": "bar"); //expected-warning {{overloaded operator << has higher precedence than comparison operator}} \
+   //expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+  // expected-note {{place parentheses around comparison expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:14-[[@LINE-4]]:14}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:19-[[@LINE-6]]:19}:")"
+
+  void(s << static_cast(x) ? "foo" : "bar"); //expected-warning {{operator '?:' has lower precedence than '<<'}} \
+  

[PATCH] D147844: Emit warning when implicit cast to bool happens in an conditional operator expression when used inside an overloaded shift operator expression

2023-04-20 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 515394.
chaitanyav added a comment.

Update test to use parentheses around conditional operator


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp

Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -41,7 +41,7 @@
   uint64_t not_overflow2 = (1ULL * ((uint64_t)(4608) * (1024 * 1024)) + 2ULL);
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
-  overflow = 4608 * 1024 * 1024 ?  4608 * 1024 * 1024 : 0;
+  overflow = (4608 * 1024 * 1024) ?  4608 * 1024 * 1024 : 0;
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
   overflow =  0 ? 0 : 4608 * 1024 * 1024;
Index: clang/test/SemaCXX/array-bounds.cpp
===
--- clang/test/SemaCXX/array-bounds.cpp
+++ clang/test/SemaCXX/array-bounds.cpp
@@ -87,7 +87,7 @@
 }
 
 #define SIZE 10
-#define ARR_IN_MACRO(flag, arr, idx) flag ? arr[idx] : 1
+#define ARR_IN_MACRO(flag, arr, idx) (flag ? arr[idx] : 1)
 
 int test_no_warn_macro_unreachable() {
   int arr[SIZE]; // expected-note {{array 'arr' declared here}}
Index: clang/test/Sema/parentheses.cpp
===
--- clang/test/Sema/parentheses.cpp
+++ clang/test/Sema/parentheses.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 bool someConditionFunc();
 
@@ -38,7 +38,7 @@
   Stream >>(const char*);
 };
 
-void f(Stream& s, bool b) {
+void f(Stream& s, bool b, int x) {
   (void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '<<'}} \
   // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
   // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
@@ -62,6 +62,30 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:16-[[@LINE-4]]:16}:")"
   // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
   // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:21-[[@LINE-6]]:21}:")"
+
+  void(s << "Test" << x ? "foo" : "bar"); //expected-warning {{operator '?:' has lower precedence than '<<'}} \
+ // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+// expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:24-[[@LINE-4]]:24}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:23-[[@LINE-5]]:23}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:40-[[@LINE-6]]:40}:")"
+
+  void(s << x == 1 ? "foo": "bar"); //expected-warning {{overloaded operator << has higher precedence than comparison operator}} \
+   //expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+  // expected-note {{place parentheses around comparison expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:14-[[@LINE-4]]:14}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:19-[[@LINE-6]]:19}:")"
+
+  void(s << static_cast(x) ? "foo" : "bar"); //expected-warning {{operator '?:' has lower precedence than '<<'}} \
+  //expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+ //expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:33-[[@LINE-4]]:33}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:49-[[@LINE-6]]:49}:")"
 }
 
 struct S {
Index: clang/test/Sema/parentheses.c

[PATCH] D147844: Emit warning when implicit cast to bool happens in an conditional operator expression when used inside an overloaded shift operator expression

2023-04-20 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 515367.
chaitanyav added a comment.

Update SemaCXX tests to use parentheses around conditional operator


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp

Index: clang/test/SemaCXX/integer-overflow.cpp
===
--- clang/test/SemaCXX/integer-overflow.cpp
+++ clang/test/SemaCXX/integer-overflow.cpp
@@ -41,7 +41,7 @@
   uint64_t not_overflow2 = (1ULL * ((uint64_t)(4608) * (1024 * 1024)) + 2ULL);
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
-  overflow = 4608 * 1024 * 1024 ?  4608 * 1024 * 1024 : 0;
+  overflow = (4608 * 1024 * 1024) ?  4608 * 1024 * 1024 : 0;
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
   overflow =  0 ? 0 : 4608 * 1024 * 1024;
Index: clang/test/SemaCXX/array-bounds.cpp
===
--- clang/test/SemaCXX/array-bounds.cpp
+++ clang/test/SemaCXX/array-bounds.cpp
@@ -87,7 +87,7 @@
 }
 
 #define SIZE 10
-#define ARR_IN_MACRO(flag, arr, idx) flag ? arr[idx] : 1
+#define ARR_IN_MACRO(flag, arr, idx) (flag ? arr[idx] : 1)
 
 int test_no_warn_macro_unreachable() {
   int arr[SIZE]; // expected-note {{array 'arr' declared here}}
Index: clang/test/Sema/parentheses.cpp
===
--- clang/test/Sema/parentheses.cpp
+++ clang/test/Sema/parentheses.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 bool someConditionFunc();
 
@@ -38,7 +38,7 @@
   Stream >>(const char*);
 };
 
-void f(Stream& s, bool b) {
+void f(Stream& s, bool b, int x) {
   (void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '<<'}} \
   // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
   // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
@@ -62,6 +62,30 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:16-[[@LINE-4]]:16}:")"
   // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
   // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:21-[[@LINE-6]]:21}:")"
+
+  void(s << "Test" << x ? "foo" : "bar"); //expected-warning {{operator '?:' has lower precedence than '<<'}} \
+ // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+// expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:24-[[@LINE-4]]:24}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:23-[[@LINE-5]]:23}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:40-[[@LINE-6]]:40}:")"
+
+  void(s << x == 1 ? "foo": "bar"); //expected-warning {{overloaded operator << has higher precedence than comparison operator}} \
+   //expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+  // expected-note {{place parentheses around comparison expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:14-[[@LINE-4]]:14}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:19-[[@LINE-6]]:19}:")"
+
+  void(s << static_cast(x) ? "foo" : "bar"); //expected-warning {{operator '?:' has lower precedence than '<<'}} \
+  //expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+ //expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:33-[[@LINE-4]]:33}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:49-[[@LINE-6]]:49}:")"
 }
 
 struct S {
Index: clang/test/Sema/parentheses.c
===

[PATCH] D147844: Emit warning when implicit cast to bool happens in an conditional operator expression when used inside an overloaded shift operator expression

2023-04-19 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav marked 2 inline comments as done.
chaitanyav added a comment.

@aaron.ballman I have made more changes so that the warning is emitted on other 
integer expressions where the opertors has higher precedence than conditional 
operator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: Emit warning when implicit cast to bool happens in an conditional operator expression when used inside an overloaded shift operator expression

2023-04-19 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 515130.
chaitanyav added a comment.

Emit warning when implicit cast from int to bool in an conditional operator 
expression


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp

Index: clang/test/Sema/parentheses.cpp
===
--- clang/test/Sema/parentheses.cpp
+++ clang/test/Sema/parentheses.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 bool someConditionFunc();
 
@@ -38,7 +38,7 @@
   Stream >>(const char*);
 };
 
-void f(Stream& s, bool b) {
+void f(Stream& s, bool b, int x) {
   (void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '<<'}} \
   // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
   // expected-note {{place parentheses around the '?:' expression to evaluate it first}}
@@ -62,6 +62,30 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:16-[[@LINE-4]]:16}:")"
   // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
   // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:21-[[@LINE-6]]:21}:")"
+
+  void(s << "Test" << x ? "foo" : "bar"); //expected-warning {{operator '?:' has lower precedence than '<<'}} \
+ // expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+// expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:24-[[@LINE-4]]:24}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:23-[[@LINE-5]]:23}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:40-[[@LINE-6]]:40}:")"
+
+  void(s << x == 1 ? "foo": "bar"); //expected-warning {{overloaded operator << has higher precedence than comparison operator}} \
+   //expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+  // expected-note {{place parentheses around comparison expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:14-[[@LINE-4]]:14}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:19-[[@LINE-6]]:19}:")"
+
+  void(s << static_cast(x) ? "foo" : "bar"); //expected-warning {{operator '?:' has lower precedence than '<<'}} \
+  //expected-note {{place parentheses around the '<<' expression to silence this warning}} \
+ //expected-note {{place parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:33-[[@LINE-4]]:33}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:49-[[@LINE-6]]:49}:")"
 }
 
 struct S {
Index: clang/test/Sema/parentheses.c
===
--- clang/test/Sema/parentheses.c
+++ clang/test/Sema/parentheses.c
@@ -84,10 +84,10 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
   // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:24-[[@LINE-6]]:24}:")"
 
-  (void)(x % 2 ? 1 : 2); // no warning
+  (void)(x % 2 ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '%'}} expected-note 2{{place parenthese}}
 
   (void)(x + p ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} expected-note 2{{place parentheses}}
-  (void)(p + x ? 1 : 2); // no warning
+  (void)(p + x ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} expected-note 2{{place parentheses}}
 
   (void)(p + b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} expected-note 2{{place parentheses}}
 
Index: clang/test/Sema/integer-overflow.c
===
--- clang/test/Sema/integer-overflow.c
+++ clang/test/Sema/integer-overflow.c
@@ -34,7 +34,7 @@
   uint64_t not_overflow2 = (1ULL * ((uint64_t)(4608) * (1024 * 1024)) + 2ULL);
 
 // expected-warning@+1 2{{overflow in 

[PATCH] D147844: Emit warning when implicit cast to bool happens in an conditional operator expression when used inside an overloaded shift operator expression

2023-04-19 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

In D147844#4281288 , @aaron.ballman 
wrote:

> In D147844#4278384 , @chaitanyav 
> wrote:
>
>> @aaron.ballman am looking into this. If i change it back to
>>  `operation int();`
>> and add
>> `Stream& operator<<(bool)`
>> i get 
>> `
>> error: 'warning' diagnostics expected but not seen:
>>
>>   File 
>> /usr/home/nvellanki/explore/llvm-project/clang/test/Sema/parentheses.cpp 
>> Line 68: operator '?:' has lower precedence than '<<'
>>
>> error: 'note' diagnostics expected but not seen:
>>
>>   File 
>> /usr/home/nvellanki/explore/llvm-project/clang/test/Sema/parentheses.cpp 
>> Line 68: place parentheses around the '<<' expression to silence this warning
>>   File 
>> /usr/home/nvellanki/explore/llvm-project/clang/test/Sema/parentheses.cpp 
>> Line 68: place parentheses around the '?:' expression to evaluate it first
>>
>> 3 errors generated.
>> `
>> But it works correctly with std::cout
>>
>> `
>> test.cpp:7:30: warning: operator '?:' has lower precedence than '<<'; '<<' 
>> will be evaluated first [-Wparentheses]
>>
>>   std::cout << "Test" << a ? 1 : 0;
>>    ^
>>
>> test.cpp:7:30: note: place parentheses around the '<<' expression to silence 
>> this warning
>>
>>   std::cout << "Test" << a ? 1 : 0;
>>^
>>   (   )
>>
>> test.cpp:7:30: note: place parentheses around the '?:' expression to 
>> evaluate it first
>>
>>   std::cout << "Test" << a ? 1 : 0;
>>^
>>  ()
>
> I would expect to get the same diagnostic with either `operator int()` or 
> `operator bool()` as the precedence is the same either way. I think what 
> might be happening here is that `ExprLooksBoolean` is getting tricked into 
> thinking the expression isn't boolean when it actually is (I think this might 
> be the `FIXME` comment in that function needing to be addressed).

Thanks @aaron.ballman, will look into the FIXME.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: Emit warning when implicit cast to bool happens in an conditional operator expression when used inside an overloaded shift operator expression

2023-04-18 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

@aaron.ballman am looking into this. If i change it back to
 `operation int();`
and add
`Stream& operator<<(bool)`

I get

`
-

error: 'warning' diagnostics expected but not seen:

  File /usr/home/nvellanki/explore/llvm-project/clang/test/Sema/parentheses.cpp 
Line 68: operator '?:' has lower precedence than '<<'

error: 'note' diagnostics expected but not seen:

  File /usr/home/nvellanki/explore/llvm-project/clang/test/Sema/parentheses.cpp 
Line 68: place parentheses around the '<<' expression to silence this warning
  File /usr/home/nvellanki/explore/llvm-project/clang/test/Sema/parentheses.cpp 
Line 68: place parentheses around the '?:' expression to evaluate it first

3 errors generated.

-

`

But it works correctly with std::cout

`
test.cpp:7:30: warning: operator '?:' has lower precedence than '<<'; '<<' will 
be evaluated first [-Wparentheses]

  std::cout << "Test" << a ? 1 : 0;
   ^

test.cpp:7:30: note: place parentheses around the '<<' expression to silence 
this warning

  std::cout << "Test" << a ? 1 : 0;
   ^
  (   )

test.cpp:7:30: note: place parentheses around the '?:' expression to evaluate 
it first

  std::cout << "Test" << a ? 1 : 0;
   ^
 ()

`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: Emit warning when implicit cast to bool happens in an conditional operator expression when used inside an overloaded shift operator expression

2023-04-18 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 514702.
chaitanyav added a comment.

Update release notes about the fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/parentheses.cpp


Index: clang/test/Sema/parentheses.cpp
===
--- clang/test/Sema/parentheses.cpp
+++ clang/test/Sema/parentheses.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits 
%s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses 
-fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses 
-fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 bool someConditionFunc();
 
@@ -31,14 +31,14 @@
 
 class Stream {
 public:
-  operator int();
+  operator bool();
   Stream <<(int);
   Stream <<(const char*);
   Stream >>(int);
   Stream >>(const char*);
 };
 
-void f(Stream& s, bool b) {
+void f(Stream& s, bool b, int x) {
   (void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has 
lower precedence than '<<'}} \
   // expected-note {{place parentheses around 
the '<<' expression to silence this warning}} \
   // expected-note {{place parentheses around 
the '?:' expression to evaluate it first}}
@@ -62,6 +62,30 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:16-[[@LINE-4]]:16}:")"
   // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
   // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:21-[[@LINE-6]]:21}:")"
+
+  void(s << "Test" << x ? "foo" : "bar"); //expected-warning {{operator '?:' 
has lower precedence than '<<'}} \
+ // expected-note {{place parentheses 
around the '<<' expression to silence this warning}} \
+// expected-note {{place parentheses 
around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:24-[[@LINE-4]]:24}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:23-[[@LINE-5]]:23}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:40-[[@LINE-6]]:40}:")"
+
+  void(s << x == 1 ? "foo": "bar"); //expected-warning {{overloaded operator 
<< has higher precedence than comparison operator}} \
+   //expected-note {{place parentheses around 
the '<<' expression to silence this warning}} \
+  // expected-note {{place parentheses around 
comparison expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:14-[[@LINE-4]]:14}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:19-[[@LINE-6]]:19}:")"
+
+  void(s << static_cast(x) ? "foo" : "bar"); //expected-warning 
{{operator '?:' has lower precedence than '<<'}} \
+  //expected-note {{place 
parentheses around the '<<' expression to silence this warning}} \
+ //expected-note {{place 
parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:33-[[@LINE-4]]:33}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:49-[[@LINE-6]]:49}:")"
 }
 
 struct S {
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -9304,7 +9304,7 @@
 
   if (!IsArithmeticBinaryExpr(Condition, , ))
 return;
-  if (!ExprLooksBoolean(CondRHS))
+  if (!ExprLooksBoolean(CondRHS) && !ExprLooksBoolean(Condition))
 return;
 
   // The condition is an arithmetic binary expression, with a right-
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -314,6 +314,9 @@
   (`#61885 `_)
 - Clang constexpr evaluator now treats comparison of [[gnu::weak]]-attributed
   member pointer as an invalid expression.
+- Emit warning when implicit cast to bool happens in an conditional
+  operator expression when used inside an overloaded shift operator expression
+  (`#61943 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/Sema/parentheses.cpp
===
--- clang/test/Sema/parentheses.cpp

[PATCH] D147844: Emit warning when implicit cast to bool happens in an conditional operator expression when used inside an overloaded shift operator expression

2023-04-17 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav reclaimed this revision.
chaitanyav added a comment.

re-opening the revision to make further updates as per comments on the github 
issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: Emit warning when implicit cast to bool happens in an conditional operator expression when used inside an overloaded shift operator expression

2023-04-10 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

@aaron.ballman Please review this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: Emit warning when implicit cast to bool happens in an conditional operator expression when used inside an overloaded shift operator expression

2023-04-08 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

output for testcases mentioned in 
https://github.com/llvm/llvm-project/issues/61943

  test.cpp:6:30: warning: overloaded operator << has higher precedence than 
comparison operator [-Woverloaded-shift-op-parentheses]
  std::cout << "Test" << a == 5 ? 1 : 0;
   ^  ~
  test.cpp:6:25: note: place parentheses around the '<<' expression to silence 
this warning
  std::cout << "Test" << a == 5 ? 1 : 0;
  ^
  (   )
  test.cpp:6:30: note: place parentheses around comparison expression to 
evaluate it first
  std::cout << "Test" << a == 5 ? 1 : 0;
   ^
 ( )
  test.cpp:6:30: error: invalid operands to binary expression ('ostream' and 
'int')
  std::cout << "Test" << a == 5 ? 1 : 0;
   ^  ~
  test.cpp:7:30: warning: operator '?:' has lower precedence than '<<'; '<<' 
will be evaluated first [-Wparentheses]
  std::cout << "Test" << a ? 1 : 0;
   ^
  test.cpp:7:30: note: place parentheses around the '<<' expression to silence 
this warning
  std::cout << "Test" << a ? 1 : 0;
   ^
  (   )
  test.cpp:7:30: note: place parentheses around the '?:' expression to evaluate 
it first
  std::cout << "Test" << a ? 1 : 0;
   ^
 ()
  test.cpp:8:49: warning: operator '?:' has lower precedence than '<<'; '<<' 
will be evaluated first [-Wparentheses]
  std::cout << "Test" << static_cast(a) ? 1 : 0;
  ~~~ ^
  test.cpp:8:49: note: place parentheses around the '<<' expression to silence 
this warning
  std::cout << "Test" << static_cast(a) ? 1 : 0;
  ^
  (  )
  test.cpp:8:49: note: place parentheses around the '?:' expression to evaluate 
it first
  std::cout << "Test" << static_cast(a) ? 1 : 0;
  ^

@aaron.ballman Please review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147844: Emit warning when implicit cast to bool happens in an conditional operator expression when used inside an overloaded shift operator expression

2023-04-08 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav created this revision.
Herald added a project: All.
chaitanyav requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes issue https://github.com/llvm/llvm-project/issues/61943


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147844

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/parentheses.cpp


Index: clang/test/Sema/parentheses.cpp
===
--- clang/test/Sema/parentheses.cpp
+++ clang/test/Sema/parentheses.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits 
%s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses 
-fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses 
-fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 bool someConditionFunc();
 
@@ -31,14 +31,14 @@
 
 class Stream {
 public:
-  operator int();
+  operator bool();
   Stream <<(int);
   Stream <<(const char*);
   Stream >>(int);
   Stream >>(const char*);
 };
 
-void f(Stream& s, bool b) {
+void f(Stream& s, bool b, int x) {
   (void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has 
lower precedence than '<<'}} \
   // expected-note {{place parentheses around 
the '<<' expression to silence this warning}} \
   // expected-note {{place parentheses around 
the '?:' expression to evaluate it first}}
@@ -62,6 +62,30 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:16-[[@LINE-4]]:16}:")"
   // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
   // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:21-[[@LINE-6]]:21}:")"
+
+  void(s << "Test" << x ? "foo" : "bar"); //expected-warning {{operator '?:' 
has lower precedence than '<<'}} \
+ // expected-note {{place parentheses 
around the '<<' expression to silence this warning}} \
+// expected-note {{place parentheses 
around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:24-[[@LINE-4]]:24}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:23-[[@LINE-5]]:23}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:40-[[@LINE-6]]:40}:")"
+
+  void(s << x == 1 ? "foo": "bar"); //expected-warning {{overloaded operator 
<< has higher precedence than comparison operator}} \
+   //expected-note {{place parentheses around 
the '<<' expression to silence this warning}} \
+  // expected-note {{place parentheses around 
comparison expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:14-[[@LINE-4]]:14}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:19-[[@LINE-6]]:19}:")"
+
+  void(s << static_cast(x) ? "foo" : "bar"); //expected-warning 
{{operator '?:' has lower precedence than '<<'}} \
+  //expected-note {{place 
parentheses around the '<<' expression to silence this warning}} \
+ //expected-note {{place 
parentheses around the '?:' expression to evaluate it first}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:8-[[@LINE-3]]:8}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:33-[[@LINE-4]]:33}:")"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:49-[[@LINE-6]]:49}:")"
 }
 
 struct S {
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -9304,7 +9304,7 @@
 
   if (!IsArithmeticBinaryExpr(Condition, , ))
 return;
-  if (!ExprLooksBoolean(CondRHS))
+  if (!ExprLooksBoolean(CondRHS) && !ExprLooksBoolean(Condition))
 return;
 
   // The condition is an arithmetic binary expression, with a right-


Index: clang/test/Sema/parentheses.cpp
===
--- clang/test/Sema/parentheses.cpp
+++ clang/test/Sema/parentheses.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
-// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -Woverloaded-shift-op-parentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 bool someConditionFunc();
 
@@ -31,14 +31,14 @@
 
 class Stream {
 public:
-  operator int();
+  operator bool();
   Stream <<(int);
   Stream <<(const char*);
   Stream >>(int);
   

[PATCH] D146866: [clang][ExtractAPI] Remove extra pointer indirection from declaration fragments for Obj-C lightweight generics on id

2023-03-30 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa590d8634308: [clang][ExtractAPI] Remove extra pointer 
indirection from declaration fragments… (authored by chaitanyav).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146866

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/objc_id_protocol.m

Index: clang/test/ExtractAPI/objc_id_protocol.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_id_protocol.m
@@ -0,0 +1,341 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang -extract-api -x objective-c-header -target arm64-apple-macosx \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+@protocol MyProtocol
+@end
+
+@interface MyInterface
+@property(copy, readwrite) id obj1;
+@property(readwrite) id *obj2;
+@end
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)MyInterface(py)obj1",
+  "target": "c:objc(cs)MyInterface",
+  "targetFallback": "MyInterface"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)MyInterface(py)obj2",
+  "target": "c:objc(cs)MyInterface",
+  "targetFallback": "MyInterface"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyInterface"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyInterface"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"position": {
+  "character": 12,
+  "line": 4
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "MyInterface"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "MyInterface"
+  }
+],
+"title": "MyInterface"
+  },
+  "pathComponents": [
+"MyInterface"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@property"
+},
+{
+  "kind": "text",
+  "spelling": " ("
+},
+{
+  "kind": "keyword",
+  "spelling": "atomic"
+},
+{
+  "kind": "text",
+  "spelling": ", "
+},
+{
+  "kind": "keyword",
+  "spelling": "copy"
+},
+{
+  "kind": "text",
+  "spelling": ", "
+},
+{
+  "kind": "keyword",
+  "spelling": "readwrite"
+},
+{
+  "kind": "text",
+  "spelling": ") "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:Qoobjc(pl)MyProtocol",
+  "spelling": "id"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "obj1"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyInterface(py)obj1"
+  },
+  "kind": {
+"displayName": "Instance Property",
+"identifier": "objective-c.property"
+  },
+  "location": {
+"position": {
+  "character": 43,
+  "line": 5
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "obj1"
+  }
+],
+

[PATCH] D146866: [clang][ExtractAPI] Remove extra pointer indirection from declaration fragments for Obj-C lightweight generics on id

2023-03-29 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

@dang Please review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146866

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146866: [clang][ExtractAPI] Remove extra pointer indirection from declaration fragments for Obj-C lightweight generics on id

2023-03-29 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 509429.
chaitanyav added a comment.

Add comment to indicate that id* is not an qualified id type


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146866

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/objc_id_protocol.m

Index: clang/test/ExtractAPI/objc_id_protocol.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_id_protocol.m
@@ -0,0 +1,341 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang -extract-api -x objective-c-header -target arm64-apple-macosx \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+@protocol MyProtocol
+@end
+
+@interface MyInterface
+@property(copy, readwrite) id obj1;
+@property(readwrite) id *obj2;
+@end
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)MyInterface(py)obj1",
+  "target": "c:objc(cs)MyInterface",
+  "targetFallback": "MyInterface"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)MyInterface(py)obj2",
+  "target": "c:objc(cs)MyInterface",
+  "targetFallback": "MyInterface"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyInterface"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyInterface"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"position": {
+  "character": 12,
+  "line": 4
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "MyInterface"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "MyInterface"
+  }
+],
+"title": "MyInterface"
+  },
+  "pathComponents": [
+"MyInterface"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@property"
+},
+{
+  "kind": "text",
+  "spelling": " ("
+},
+{
+  "kind": "keyword",
+  "spelling": "atomic"
+},
+{
+  "kind": "text",
+  "spelling": ", "
+},
+{
+  "kind": "keyword",
+  "spelling": "copy"
+},
+{
+  "kind": "text",
+  "spelling": ", "
+},
+{
+  "kind": "keyword",
+  "spelling": "readwrite"
+},
+{
+  "kind": "text",
+  "spelling": ") "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:Qoobjc(pl)MyProtocol",
+  "spelling": "id"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "obj1"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyInterface(py)obj1"
+  },
+  "kind": {
+"displayName": "Instance Property",
+"identifier": "objective-c.property"
+  },
+  "location": {
+"position": {
+  "character": 43,
+  "line": 5
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "obj1"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+   

[PATCH] D146866: [clang][ExtractAPI] Remove extra pointer indirection from declaration fragments for Obj-C lightweight generics on id

2023-03-27 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

looks like its waiting on libcxx 
build(https://buildkite.com/llvm-project/premerge-checks/builds/143382#job-01872209-2788-44ef-930c-11e741ff906e)
  and it is actively being debugged as per comments on other differential.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146866

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146866: [clang][ExtractAPI] Remove extra pointer indirection from declaration fragments for Obj-C lightweight generics on id

2023-03-27 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

@dang @ributzka Please review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146866

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146866: [clang][ExtractAPI] Remove extra pointer indirection from declaration fragments for Obj-C lightweight generics on id

2023-03-25 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav created this revision.
chaitanyav added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
chaitanyav requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/61479


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146866

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/objc_id_protocol.m

Index: clang/test/ExtractAPI/objc_id_protocol.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_id_protocol.m
@@ -0,0 +1,341 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang -extract-api -x objective-c-header -target arm64-apple-macosx \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+@protocol MyProtocol
+@end
+
+@interface MyInterface
+@property(copy, readwrite) id obj1;
+@property(readwrite) id *obj2;
+@end
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)MyInterface(py)obj1",
+  "target": "c:objc(cs)MyInterface",
+  "targetFallback": "MyInterface"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)MyInterface(py)obj2",
+  "target": "c:objc(cs)MyInterface",
+  "targetFallback": "MyInterface"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyInterface"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyInterface"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"position": {
+  "character": 12,
+  "line": 4
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "MyInterface"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "MyInterface"
+  }
+],
+"title": "MyInterface"
+  },
+  "pathComponents": [
+"MyInterface"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@property"
+},
+{
+  "kind": "text",
+  "spelling": " ("
+},
+{
+  "kind": "keyword",
+  "spelling": "atomic"
+},
+{
+  "kind": "text",
+  "spelling": ", "
+},
+{
+  "kind": "keyword",
+  "spelling": "copy"
+},
+{
+  "kind": "text",
+  "spelling": ", "
+},
+{
+  "kind": "keyword",
+  "spelling": "readwrite"
+},
+{
+  "kind": "text",
+  "spelling": ") "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:Qoobjc(pl)MyProtocol",
+  "spelling": "id"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "obj1"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyInterface(py)obj1"
+  },
+  "kind": {
+"displayName": "Instance Property",
+"identifier": "objective-c.property"
+  },
+  "location": {
+"position": {
+  "character": 43,
+  "line": 5
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "obj1"
+

[PATCH] D146671: [clang][ExtractAPI]Fix Declaration fragments for instancetype in the type position degrade to id

2023-03-23 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc13ccf1fbabe: [clang][ExtractAPI]Fix Declaration fragments 
for instancetype in the type… (authored by chaitanyav).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146671

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/objc_instancetype.m

Index: clang/test/ExtractAPI/objc_instancetype.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_instancetype.m
@@ -0,0 +1,254 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+ // RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx -x objective-c-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+ // RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+
+//--- input.h
+@interface Foo
+- (instancetype) init;
+- (id) reset;
+@end
+// expected-no-diagnostics
+
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)Foo(im)init",
+  "target": "c:objc(cs)Foo",
+  "targetFallback": "Foo"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)Foo(im)reset",
+  "target": "c:objc(cs)Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"position": {
+  "character": 12,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "text",
+  "spelling": "- ("
+},
+{
+  "kind": "keyword",
+  "spelling": "instancetype"
+},
+{
+  "kind": "text",
+  "spelling": ") "
+},
+{
+  "kind": "identifier",
+  "spelling": "init"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "functionSignature": {
+"returns": [
+  {
+"kind": "keyword",
+"spelling": "instancetype"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)Foo(im)init"
+  },
+  "kind": {
+"displayName": "Instance Method",
+"identifier": "objective-c.method"
+  },
+  "location": {
+"position": {
+  "character": 1,
+  "line": 2
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "init"
+  }
+],
+"subHeading": [
+  {
+"kind": "text",
+"spelling": "- "
+  },
+  {
+"kind": "identifier",
+"spelling": "init"
+  }
+],
+"title": "init"
+  },
+  "pathComponents": [
+"Foo",
+"init"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "text",
+  "spelling": "- ("
+},
+{
+  "kind": "keyword",
+  

[PATCH] D146503: Fix highlighting issue with _complex and initialization list with more than 2 items

2023-03-23 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1c9173365a93: Fix highlighting issue with _complex and 
initialization list with more than 2… (authored by chaitanyav).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146503

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/caret-diags-complex-init.cpp
  clang/test/Sema/complex-init-list.c

Index: clang/test/Sema/complex-init-list.c
===
--- clang/test/Sema/complex-init-list.c
+++ clang/test/Sema/complex-init-list.c
@@ -25,17 +25,21 @@
 
 
 // Random other valid stuff
-_Complex int valid2 = { 1, 2 }; // expected-warning {{complex integer}} expected-warning {{specifying real and imaginary components is an extension}}
+_Complex int valid2 = { 1, 2 }; // expected-warning {{complex integer}} \
+   //  expected-warning {{specifying real and imaginary components is an extension}}
 struct teststruct valid3 = { { 1.0f, 2.0f} }; // expected-warning {{specifying real and imaginary components is an extension}}
 _Complex float valid4[2] = { {1.0f, 1.0f}, {1.0f, 1.0f} }; // expected-warning 2 {{specifying real and imaginary components is an extension}}
 // FIXME: We need some sort of warning for valid5
-_Complex float valid5 = {1.0f, 1.0fi}; // expected-warning {{imaginary constants}} expected-warning {{specifying real and imaginary components is an extension}}
+_Complex float valid5 = {1.0f, 1.0fi}; // expected-warning {{imaginary constants}} \
+   // expected-warning {{specifying real and imaginary components is an extension}}
 
 
 // Random invalid stuff
 struct teststruct invalid1 = { 1, 2 }; // expected-warning {{excess elements}}
-_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{excess elements}}
-_Complex float invalid3 = {}; // expected-error {{scalar initializer cannot be empty}} expected-warning {{GNU empty initializer}}
+_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{specifying real and imaginary components is an extension}} \
+   // expected-warning {{excess elements in scalar initializer}}
+_Complex float invalid3 = {}; // expected-error {{scalar initializer cannot be empty}} \
+ //  expected-warning {{GNU empty initializer}}
 
 
 // Check incomplete array sizing
@@ -46,3 +50,9 @@
 
 // Constant-folding with init list.
 _Complex float x = 2 + (_Complex float) { 1, 2 };  // expected-warning {{specifying real and imaginary components is an extension}}
+
+// initialization list
+_Complex double cd = {1.0, 2.0, 3.0}; // expected-warning {{specifying real and imaginary components is an extension}} \
+ //  expected-warning {{excess elements in scalar initializer}}
+_Complex float cf = {1.1f, 2.2f, 3.3f, 4.4f}; // expected-warning {{specifying real and imaginary components is an extension}} \
+ //  expected-warning {{excess elements in scalar initializer}}
Index: clang/test/Sema/caret-diags-complex-init.cpp
===
--- /dev/null
+++ clang/test/Sema/caret-diags-complex-init.cpp
@@ -0,0 +1,39 @@
+// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fcaret-diagnostics-max-lines 5 %s 2>&1 | FileCheck %s -strict-whitespace
+
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex double gz1 = {1, 2, 3};
+//CHECK-NEXT: {{^}} ^{{$}}
+_Complex double gz1 = {1, 2, 3}; 
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex double dd = {1.0, 2.0, 3.0};
+//CHECK-NEXT: {{^}}^~~{{$}}
+_Complex double dd = {1.0, 2.0, 3.0};
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex float fd = {1.0, 2.0, 3.0, 4.0, 5.0};
+//CHECK-NEXT: {{^}}   ^~~{{$}}
+_Complex float fd = {1.0, 2.0, 3.0, 4.0, 5.0};
+
+//CHECK: {{.*}}: error: no viable conversion from 'foo' to 'double'
+//CHECK-NEXT: {{^}}_Complex double ds = {f, 1.0, b};
+//CHECK-NEXT: {{^}}  ^{{$}}
+struct foo{};
+struct bar{};
+
+foo f;
+bar b;
+_Complex double ds = {f, 1.0, b};
+
+//CHECK: {{.*}}: error: no viable conversion from 'foo' to 'double'
+//CHECK-NEXT: {{^}}_Complex double fg = {1.0, f};
+//CHECK-NEXT: {{^}}   ^{{$}}
+_Complex double fg = {1.0, f};
+
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex double gg = {1.0, 2.0, f};
+//CHECK-NEXT: {{^}}^{{$}}
+//CHECK-NEXT: {{^}}6 errors generated.
+_Complex double gg = {1.0, 2.0, f};
Index: 

[PATCH] D146503: Fix highlighting issue with _complex and initialization list with more than 2 items

2023-03-23 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav marked 3 inline comments as done.
chaitanyav added a comment.

Thank you, I will commit myself. Should i wait for the build to finish?. this 
will be my first direct commit to repo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146503

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146503: Fix highlighting issue with _complex and initialization list with more than 2 items

2023-03-23 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 507750.
chaitanyav marked an inline comment as not done.
chaitanyav added a comment.

one diagnostic per line when there are multiple diagnostics expected


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146503

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/caret-diags-complex-init.cpp
  clang/test/Sema/complex-init-list.c

Index: clang/test/Sema/complex-init-list.c
===
--- clang/test/Sema/complex-init-list.c
+++ clang/test/Sema/complex-init-list.c
@@ -25,17 +25,21 @@
 
 
 // Random other valid stuff
-_Complex int valid2 = { 1, 2 }; // expected-warning {{complex integer}} expected-warning {{specifying real and imaginary components is an extension}}
+_Complex int valid2 = { 1, 2 }; // expected-warning {{complex integer}} \
+   //  expected-warning {{specifying real and imaginary components is an extension}}
 struct teststruct valid3 = { { 1.0f, 2.0f} }; // expected-warning {{specifying real and imaginary components is an extension}}
 _Complex float valid4[2] = { {1.0f, 1.0f}, {1.0f, 1.0f} }; // expected-warning 2 {{specifying real and imaginary components is an extension}}
 // FIXME: We need some sort of warning for valid5
-_Complex float valid5 = {1.0f, 1.0fi}; // expected-warning {{imaginary constants}} expected-warning {{specifying real and imaginary components is an extension}}
+_Complex float valid5 = {1.0f, 1.0fi}; // expected-warning {{imaginary constants}} \
+   // expected-warning {{specifying real and imaginary components is an extension}}
 
 
 // Random invalid stuff
 struct teststruct invalid1 = { 1, 2 }; // expected-warning {{excess elements}}
-_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{excess elements}}
-_Complex float invalid3 = {}; // expected-error {{scalar initializer cannot be empty}} expected-warning {{GNU empty initializer}}
+_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{specifying real and imaginary components is an extension}} \
+   // expected-warning {{excess elements in scalar initializer}}
+_Complex float invalid3 = {}; // expected-error {{scalar initializer cannot be empty}} \
+ //  expected-warning {{GNU empty initializer}}
 
 
 // Check incomplete array sizing
@@ -46,3 +50,9 @@
 
 // Constant-folding with init list.
 _Complex float x = 2 + (_Complex float) { 1, 2 };  // expected-warning {{specifying real and imaginary components is an extension}}
+
+// initialization list
+_Complex double cd = {1.0, 2.0, 3.0}; // expected-warning {{specifying real and imaginary components is an extension}} \
+ //  expected-warning {{excess elements in scalar initializer}}
+_Complex float cf = {1.1f, 2.2f, 3.3f, 4.4f}; // expected-warning {{specifying real and imaginary components is an extension}} \
+ //  expected-warning {{excess elements in scalar initializer}}
Index: clang/test/Sema/caret-diags-complex-init.cpp
===
--- /dev/null
+++ clang/test/Sema/caret-diags-complex-init.cpp
@@ -0,0 +1,39 @@
+// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fcaret-diagnostics-max-lines 5 %s 2>&1 | FileCheck %s -strict-whitespace
+
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex double gz1 = {1, 2, 3};
+//CHECK-NEXT: {{^}} ^{{$}}
+_Complex double gz1 = {1, 2, 3}; 
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex double dd = {1.0, 2.0, 3.0};
+//CHECK-NEXT: {{^}}^~~{{$}}
+_Complex double dd = {1.0, 2.0, 3.0};
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex float fd = {1.0, 2.0, 3.0, 4.0, 5.0};
+//CHECK-NEXT: {{^}}   ^~~{{$}}
+_Complex float fd = {1.0, 2.0, 3.0, 4.0, 5.0};
+
+//CHECK: {{.*}}: error: no viable conversion from 'foo' to 'double'
+//CHECK-NEXT: {{^}}_Complex double ds = {f, 1.0, b};
+//CHECK-NEXT: {{^}}  ^{{$}}
+struct foo{};
+struct bar{};
+
+foo f;
+bar b;
+_Complex double ds = {f, 1.0, b};
+
+//CHECK: {{.*}}: error: no viable conversion from 'foo' to 'double'
+//CHECK-NEXT: {{^}}_Complex double fg = {1.0, f};
+//CHECK-NEXT: {{^}}   ^{{$}}
+_Complex double fg = {1.0, f};
+
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex double gg = {1.0, 2.0, f};
+//CHECK-NEXT: {{^}}^{{$}}
+//CHECK-NEXT: {{^}}6 errors generated.
+_Complex double gg = {1.0, 2.0, f};
Index: clang/lib/Sema/SemaInit.cpp

[PATCH] D146671: [clang][ExtractAPI]Fix Declaration fragments for instancetype in the type position degrade to id

2023-03-23 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

@dang Please review the test/output.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146671

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146671: [clang][ExtractAPI]Fix Declaration fragments for instancetype in the type position degrade to id

2023-03-23 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 507725.
chaitanyav added a comment.

update test to check for id type


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146671

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/objc_instancetype.m

Index: clang/test/ExtractAPI/objc_instancetype.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_instancetype.m
@@ -0,0 +1,254 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+ // RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx -x objective-c-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+ // RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+
+//--- input.h
+@interface Foo
+- (instancetype) init;
+- (id) reset;
+@end
+// expected-no-diagnostics
+
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)Foo(im)init",
+  "target": "c:objc(cs)Foo",
+  "targetFallback": "Foo"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)Foo(im)reset",
+  "target": "c:objc(cs)Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"position": {
+  "character": 12,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "text",
+  "spelling": "- ("
+},
+{
+  "kind": "keyword",
+  "spelling": "instancetype"
+},
+{
+  "kind": "text",
+  "spelling": ") "
+},
+{
+  "kind": "identifier",
+  "spelling": "init"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "functionSignature": {
+"returns": [
+  {
+"kind": "keyword",
+"spelling": "instancetype"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)Foo(im)init"
+  },
+  "kind": {
+"displayName": "Instance Method",
+"identifier": "objective-c.method"
+  },
+  "location": {
+"position": {
+  "character": 1,
+  "line": 2
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "init"
+  }
+],
+"subHeading": [
+  {
+"kind": "text",
+"spelling": "- "
+  },
+  {
+"kind": "identifier",
+"spelling": "init"
+  }
+],
+"title": "init"
+  },
+  "pathComponents": [
+"Foo",
+"init"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "text",
+  "spelling": "- ("
+},
+{
+  "kind": "keyword",
+  "spelling": "id"
+},
+{
+  "kind": "text",
+  "spelling": ") "
+},
+{
+  "kind": "identifier",
+  

[PATCH] D146671: [clang][ExtractAPI]Fix Declaration fragments for instancetype in the type position degrade to id

2023-03-23 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

Will update the test to also include a Id instance method.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146671

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146503: Fix highlighting issue with _complex and initialization list with more than 2 items

2023-03-22 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav marked an inline comment as done.
chaitanyav added a comment.

I reported the flang failures https://github.com/llvm/llvm-project/issues/61634 
and it was reverted. How can i  trigger a new build with TOT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146503

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146671: Fix Declaration fragments for instancetype in the type position degrade to id

2023-03-22 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav created this revision.
chaitanyav added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
chaitanyav requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/61481


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146671

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/objc_instancetype.m

Index: clang/test/ExtractAPI/objc_instancetype.m
===
--- /dev/null
+++ clang/test/ExtractAPI/objc_instancetype.m
@@ -0,0 +1,176 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+ // RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx -x objective-c-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+ // RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+
+//--- input.h
+@interface Foo
+- (instancetype) init;
+@end
+// expected-no-diagnostics
+
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)Foo(im)init",
+  "target": "c:objc(cs)Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"position": {
+  "character": 12,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "text",
+  "spelling": "- ("
+},
+{
+  "kind": "keyword",
+  "spelling": "instancetype"
+},
+{
+  "kind": "text",
+  "spelling": ") "
+},
+{
+  "kind": "identifier",
+  "spelling": "init"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "functionSignature": {
+"returns": [
+  {
+"kind": "keyword",
+"spelling": "instancetype"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)Foo(im)init"
+  },
+  "kind": {
+"displayName": "Instance Method",
+"identifier": "objective-c.method"
+  },
+  "location": {
+"position": {
+  "character": 1,
+  "line": 2
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "init"
+  }
+],
+"subHeading": [
+  {
+"kind": "text",
+"spelling": "- "
+  },
+  {
+"kind": "identifier",
+"spelling": "init"
+  }
+],
+"title": "init"
+  },
+  "pathComponents": [
+"Foo",
+"init"
+  ]
+}
+  ]
+}
Index: clang/lib/ExtractAPI/DeclarationFragments.cpp
===
--- clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -243,26 +243,30 @@
 return Fragments.append(getFragmentsForType(ET->desugar(), Context, After));
   }
 
-  // Everything we care about has been handled now, 

[PATCH] D146503: Fix highlighting issue with _complex and initialization list with more than 2 items

2023-03-22 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav marked an inline comment as done.
chaitanyav added a comment.

@aaron.ballman  Please review.




Comment at: clang/test/Sema/complex-init-list.c:37
 struct teststruct invalid1 = { 1, 2 }; // expected-warning {{excess elements}}
-_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{excess elements}}
+_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{specifying real 
and imaginary components is an extension}} expected-warning {{excess elements 
in scalar initializer}}
 _Complex float invalid3 = {}; // expected-error {{scalar initializer cannot be 
empty}} expected-warning {{GNU empty initializer}}

aaron.ballman wrote:
> This makes it a bit easier to see that there are two diagnostics being fired 
> (even though we're not consistently doing that in this test file).
Yeah, one because its an extension and other because it has excess elements. 
Checked this file added that on lines its applicable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146503

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146503: Fix highlighting issue with _complex and initialization list with more than 2 items

2023-03-22 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 507479.
chaitanyav added a comment.

Added tests to check for the right diagnostic messages and highlighting at 
correct place
Update the release docs about the fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146503

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/caret-diags-complex-init.cpp
  clang/test/Sema/complex-init-list.c


Index: clang/test/Sema/complex-init-list.c
===
--- clang/test/Sema/complex-init-list.c
+++ clang/test/Sema/complex-init-list.c
@@ -34,7 +34,7 @@
 
 // Random invalid stuff
 struct teststruct invalid1 = { 1, 2 }; // expected-warning {{excess elements}}
-_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{excess elements}}
+_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{specifying real 
and imaginary components is an extension}} expected-warning {{excess elements 
in scalar initializer}}
 _Complex float invalid3 = {}; // expected-error {{scalar initializer cannot be 
empty}} expected-warning {{GNU empty initializer}}
 
 
@@ -46,3 +46,7 @@
 
 // Constant-folding with init list.
 _Complex float x = 2 + (_Complex float) { 1, 2 };  // expected-warning 
{{specifying real and imaginary components is an extension}}
+
+// initialization list
+_Complex double cd = {1.0, 2.0, 3.0}; // expected-warning {{specifying real 
and imaginary components is an extension}} expected-warning {{excess elements 
in scalar initializer}}
+_Complex float cf = {1.1f, 2.2f, 3.3f, 4.4f}; // expected-warning {{specifying 
real and imaginary components is an extension}} expected-warning {{excess 
elements in scalar initializer}}
Index: clang/test/Sema/caret-diags-complex-init.cpp
===
--- /dev/null
+++ clang/test/Sema/caret-diags-complex-init.cpp
@@ -0,0 +1,39 @@
+// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fcaret-diagnostics-max-lines 
5 %s 2>&1 | FileCheck %s -strict-whitespace
+
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex double gz1 = {1, 2, 3};
+//CHECK-NEXT: {{^}} ^{{$}}
+_Complex double gz1 = {1, 2, 3}; 
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex double dd = {1.0, 2.0, 3.0};
+//CHECK-NEXT: {{^}}^~~{{$}}
+_Complex double dd = {1.0, 2.0, 3.0};
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex float fd = {1.0, 2.0, 3.0, 4.0, 5.0};
+//CHECK-NEXT: {{^}}   ^~~{{$}}
+_Complex float fd = {1.0, 2.0, 3.0, 4.0, 5.0};
+
+//CHECK: {{.*}}: error: no viable conversion from 'foo' to 'double'
+//CHECK-NEXT: {{^}}_Complex double ds = {f, 1.0, b};
+//CHECK-NEXT: {{^}}  ^{{$}}
+struct foo{};
+struct bar{};
+
+foo f;
+bar b;
+_Complex double ds = {f, 1.0, b};
+
+//CHECK: {{.*}}: error: no viable conversion from 'foo' to 'double'
+//CHECK-NEXT: {{^}}_Complex double fg = {1.0, f};
+//CHECK-NEXT: {{^}}   ^{{$}}
+_Complex double fg = {1.0, f};
+
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex double gg = {1.0, 2.0, f};
+//CHECK-NEXT: {{^}}^{{$}}
+//CHECK-NEXT: {{^}}6 errors generated.
+_Complex double gg = {1.0, 2.0, f};
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -1536,7 +1536,7 @@
   // the element type of the complex type. The first element initializes
   // the real part, and the second element intitializes the imaginary part.
 
-  if (IList->getNumInits() != 2)
+  if (IList->getNumInits() < 2)
 return CheckScalarType(Entity, IList, DeclType, Index, StructuredList,
StructuredIndex);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@
   enabling short-circuiting coroutines use cases. This fixes
   (`#56532 `_) in
   antecipation of `CWG2563 
_`.
+- Fix highlighting issue with ``_Complex`` and initialization list with more 
than
+  2 items. (`#61518 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/Sema/complex-init-list.c
===
--- clang/test/Sema/complex-init-list.c
+++ clang/test/Sema/complex-init-list.c
@@ -34,7 +34,7 @@
 
 // Random invalid stuff
 struct teststruct invalid1 = { 1, 2 }; // expected-warning {{excess 

[PATCH] D146503: Fix highlighting issue with _complex and initialization list with more than 2 items

2023-03-21 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

Please review this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146503

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146503: Fix highlighting issue with _complex and initialization list with more than 2 items

2023-03-21 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

test outputs for C, C++

  _Complex float invalid2 = { 1, 2, 3 };
^
  test.cpp:2:34: error: excess elements in scalar initializer
  _Complex double dd = {1.0, 2.0 , 3.0};
   ^~~
  test.cpp:3:32: error: excess elements in scalar initializer
  _Complex float fd = {1.0, 2.0, 3.0, 4.0, 5.0};
 ^~~
  test.cpp:4:42: error: excess elements in scalar initializer
  constexpr _Complex double d = {1.0, 2.0, 3.0, 45};
   ^~~
  test.cpp:11:23: error: no viable conversion from 'foo' to 'double'
  _Complex double ds = {f, 1.0, b};
^
  test.cpp:13:28: error: no viable conversion from 'foo' to 'double'
  _Complex double fg = {1.0, f};
 ^
  test.cpp:15:33: error: excess elements in scalar initializer
  _Complex double gg = {1.0, 2.0, f};
  ^
  7 errors generated.   



  test.c:1:35: warning: excess elements in scalar initializer 
[-Wexcess-initializers]
  _Complex float invalid2 = { 1, 2, 3 };
^
  test.c:2:34: warning: excess elements in scalar initializer 
[-Wexcess-initializers]
  _Complex double dd = {1.0, 2.0 , 3.0};
   ^~~
  test.c:3:32: warning: excess elements in scalar initializer 
[-Wexcess-initializers]
  _Complex float fd = {1.0, 2.0, 3.0, 4.0, 5.0};
 ^~~
  test.c:4:38: warning: excess elements in scalar initializer 
[-Wexcess-initializers]
  const _Complex double d = {1.0, 2.0, 3.0, 45};
   ^~~
  test.c:11:23: error: initializing 'double' with an expression of incompatible 
type 'struct foo'
  _Complex double ds = {f, 1.0, b};
^
  test.c:13:28: error: initializing 'double' with an expression of incompatible 
type 'struct foo'
  _Complex double fg = {1.0, f};
 ^
  test.c:15:33: warning: excess elements in scalar initializer 
[-Wexcess-initializers]
  _Complex double gg = {1.0, 2.0, f};
  ^
  test.c:19:22: error: scalar initializer cannot be empty
  _Complex double dx = {};


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146503

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146503: Fix highlighting issue with _complex and initialization list with more than 2 items

2023-03-21 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 507090.
chaitanyav added a comment.

Only proceed with scalar initialization if number of elements is less than 2


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146503

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/complex-init-list.c


Index: clang/test/Sema/complex-init-list.c
===
--- clang/test/Sema/complex-init-list.c
+++ clang/test/Sema/complex-init-list.c
@@ -34,7 +34,7 @@
 
 // Random invalid stuff
 struct teststruct invalid1 = { 1, 2 }; // expected-warning {{excess elements}}
-_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{excess elements}}
+_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{specifying real 
and imaginary components is an extension}} expected-warning {{excess elements 
in scalar initializer}}
 _Complex float invalid3 = {}; // expected-error {{scalar initializer cannot be 
empty}} expected-warning {{GNU empty initializer}}
 
 
@@ -46,3 +46,7 @@
 
 // Constant-folding with init list.
 _Complex float x = 2 + (_Complex float) { 1, 2 };  // expected-warning 
{{specifying real and imaginary components is an extension}}
+
+// initialization list
+_Complex double cd = {1.0, 2.0, 3.0}; // expected-warning {{specifying real 
and imaginary components is an extension}} expected-warning {{excess elements 
in scalar initializer}}
+_Complex float cf = {1.1f, 2.2f, 3.3f, 4.4f}; // expected-warning {{specifying 
real and imaginary components is an extension}} expected-warning {{excess 
elements in scalar initializer}}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -1536,7 +1536,7 @@
   // the element type of the complex type. The first element initializes
   // the real part, and the second element intitializes the imaginary part.
 
-  if (IList->getNumInits() != 2)
+  if (IList->getNumInits() < 2)
 return CheckScalarType(Entity, IList, DeclType, Index, StructuredList,
StructuredIndex);
 


Index: clang/test/Sema/complex-init-list.c
===
--- clang/test/Sema/complex-init-list.c
+++ clang/test/Sema/complex-init-list.c
@@ -34,7 +34,7 @@
 
 // Random invalid stuff
 struct teststruct invalid1 = { 1, 2 }; // expected-warning {{excess elements}}
-_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{excess elements}}
+_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{specifying real and imaginary components is an extension}} expected-warning {{excess elements in scalar initializer}}
 _Complex float invalid3 = {}; // expected-error {{scalar initializer cannot be empty}} expected-warning {{GNU empty initializer}}
 
 
@@ -46,3 +46,7 @@
 
 // Constant-folding with init list.
 _Complex float x = 2 + (_Complex float) { 1, 2 };  // expected-warning {{specifying real and imaginary components is an extension}}
+
+// initialization list
+_Complex double cd = {1.0, 2.0, 3.0}; // expected-warning {{specifying real and imaginary components is an extension}} expected-warning {{excess elements in scalar initializer}}
+_Complex float cf = {1.1f, 2.2f, 3.3f, 4.4f}; // expected-warning {{specifying real and imaginary components is an extension}} expected-warning {{excess elements in scalar initializer}}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -1536,7 +1536,7 @@
   // the element type of the complex type. The first element initializes
   // the real part, and the second element intitializes the imaginary part.
 
-  if (IList->getNumInits() != 2)
+  if (IList->getNumInits() < 2)
 return CheckScalarType(Entity, IList, DeclType, Index, StructuredList,
StructuredIndex);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146503: Fix highlighting issue with _complex and initialization list with more than 2 items

2023-03-21 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

It will fall through to scalar type to do field wise initialization

  _Complex double gx = {1.0};
  
  _Complex double dx = {};

I think i get what you are saying, we can directly say that it has excess 
elements without having to do the field wise initialization. Let me look into 
that


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146503

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146503: Fix highlighting issue with _complex and initialization list with more than 2 items

2023-03-21 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

  test.cpp:2:34: error: excess elements in scalar initializer
  _Complex double dd = {1.0, 2.0 , 3.0};
   ^~~
  test.cpp:3:32: error: excess elements in scalar initializer
  _Complex float fd = {1.0, 2.0, 3.0, 4.0, 5.0};
 ^~~
  test.cpp:4:42: error: excess elements in scalar initializer
  constexpr _Complex double d = {1.0, 2.0, 3.0, 45};
   ^~~
  test.cpp:11:23: error: no viable conversion from 'foo' to '_Complex double'
  _Complex double ds = {f, 1.0, b};
^
  test.cpp:13:28: error: no viable conversion from 'foo' to 'double'
  _Complex double fg = {1.0, f};
 ^
  test.cpp:15:33: error: excess elements in scalar initializer
  _Complex double gg = {1.0, 2.0, f};
  ^
  6 errors generated.  

Tested various scenarios to ensure the behavior is as expected. Please review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146503

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146503: Fix highlighting issue with _complex and initialization list with more than 2 items

2023-03-21 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav created this revision.
chaitanyav added a reviewer: tbaeder.
Herald added a project: All.
chaitanyav requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/61518


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146503

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/complex-init-list.c


Index: clang/test/Sema/complex-init-list.c
===
--- clang/test/Sema/complex-init-list.c
+++ clang/test/Sema/complex-init-list.c
@@ -19,6 +19,9 @@
 // Basic testcase
 _Complex float valid1 = { 1.0f, 2.0f }; // expected-warning {{specifying real 
and imaginary components is an extension}}
 
+// initialization list
+_Complex double cd = {1.0, 2.0, 3.0}; // expected-warning {{excess elements in 
scalar initializer}}
+_Complex float cf = {1.1f, 2.2f, 3.3f, 4.4f}; // expected-warning {{excess 
elements in scalar initializer}}
 
 // Struct for nesting tests
 struct teststruct { _Complex float x; };
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -1633,7 +1633,11 @@
 }
   }
   UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
-  ++Index;
+
+  if (DeclType->isAnyComplexType() && IList->getNumInits() > 2)
+Index = 2;
+  else
+++Index;
 }
 
 void InitListChecker::CheckReferenceType(const InitializedEntity ,


Index: clang/test/Sema/complex-init-list.c
===
--- clang/test/Sema/complex-init-list.c
+++ clang/test/Sema/complex-init-list.c
@@ -19,6 +19,9 @@
 // Basic testcase
 _Complex float valid1 = { 1.0f, 2.0f }; // expected-warning {{specifying real and imaginary components is an extension}}
 
+// initialization list
+_Complex double cd = {1.0, 2.0, 3.0}; // expected-warning {{excess elements in scalar initializer}}
+_Complex float cf = {1.1f, 2.2f, 3.3f, 4.4f}; // expected-warning {{excess elements in scalar initializer}}
 
 // Struct for nesting tests
 struct teststruct { _Complex float x; };
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -1633,7 +1633,11 @@
 }
   }
   UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
-  ++Index;
+
+  if (DeclType->isAnyComplexType() && IList->getNumInits() > 2)
+Index = 2;
+  else
+++Index;
 }
 
 void InitListChecker::CheckReferenceType(const InitializedEntity ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146354: [clang][ExtractAPI] Add semicolons for enum, typedef, struct declaration fragments

2023-03-20 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

Name: NagaChaitanya Vellanki
email: pnag...@protonmail.com


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146354

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146354: [clang][ExtractAPI] Add semicolons for enum, typedef, struct declaration fragments

2023-03-20 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

Thank you, Please go ahead and Commit the change. I don't have commit access, 
Will follow the instructions on the page to get access.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146354

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146354: [clang][ExtractAPI] Add semicolons for enum, typedef, struct declaration fragments

2023-03-19 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

The debian build is failing because of this 
https://github.com/google/llvm-premerge-checks/issues/436

The windows build is failing because of 
https://github.com/llvm/llvm-project/issues/61519, i see that the fix 
(https://reviews.llvm.org/rGd233c7b814071e8b9345b1c25411272ec7446c8d) for this 
is already on main but i cannot trigger a new build for my changes.

Please advice on how to trigger a new build that will run on latest main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146354

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146354: [clang][ExtractAPI] Add semicolons for enum, typedef, struct declaration fragments

2023-03-18 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 506309.
chaitanyav added a comment.

- Update reference output in underscored.c
- combine return and append semicolon fragment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146354

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/anonymous_record_no_typedef.c
  clang/test/ExtractAPI/enum.c
  clang/test/ExtractAPI/struct.c
  clang/test/ExtractAPI/typedef.c
  clang/test/ExtractAPI/typedef_anonymous_record.c
  clang/test/ExtractAPI/typedef_chain.c
  clang/test/ExtractAPI/underscored.c

Index: clang/test/ExtractAPI/underscored.c
===
--- clang/test/ExtractAPI/underscored.c
+++ clang/test/ExtractAPI/underscored.c
@@ -135,6 +135,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedRecord"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -296,6 +300,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedTypedef"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -356,6 +364,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedTypedefToHidden"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/typedef_chain.c
===
--- clang/test/ExtractAPI/typedef_chain.c
+++ clang/test/ExtractAPI/typedef_chain.c
@@ -68,6 +68,10 @@
 {
   "kind": "identifier",
   "spelling": "MyInt"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -128,6 +132,10 @@
 {
   "kind": "identifier",
   "spelling": "MyIntInt"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -188,6 +196,10 @@
 {
   "kind": "identifier",
   "spelling": "MyIntIntInt"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/typedef_anonymous_record.c
===
--- clang/test/ExtractAPI/typedef_anonymous_record.c
+++ clang/test/ExtractAPI/typedef_anonymous_record.c
@@ -75,6 +75,10 @@
 {
   "kind": "identifier",
   "spelling": "MyEnum"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -170,6 +174,10 @@
 {
   "kind": "identifier",
   "spelling": "MyStruct"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -223,6 +231,10 @@
 {
   "kind": "identifier",
   "spelling": "MyStructStruct"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -283,6 +295,10 @@
 {
   "kind": "identifier",
   "spelling": "MyStructStructStruct"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -343,6 +359,10 @@
 {
   "kind": "identifier",
   "spelling": "MyEnumEnum"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -403,6 +423,10 @@
 {
   "kind": "identifier",
   "spelling": "MyEnumEnumEnum"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/typedef.c
===
--- clang/test/ExtractAPI/typedef.c
+++ clang/test/ExtractAPI/typedef.c
@@ -66,6 +66,10 @@
 {
   "kind": "identifier",
   "spelling": "MyInt"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/struct.c
===
--- clang/test/ExtractAPI/struct.c
+++ clang/test/ExtractAPI/struct.c
@@ -89,6 +89,10 @@
 {
   "kind": "identifier",
   "spelling": "Color"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "docComment": {
Index: clang/test/ExtractAPI/enum.c
===
--- clang/test/ExtractAPI/enum.c
+++ clang/test/ExtractAPI/enum.c
@@ -153,6 +153,10 @@
   "kind": "typeIdentifier",
   "preciseIdentifier": 

[PATCH] D146354: [clang][ExtractAPI] Add semicolons for enum, typedef, struct declaration fragments

2023-03-18 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 506308.
chaitanyav added a comment.

- Update reference output in underscored.c
- combine return and append semicolon fragment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146354

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/underscored.c


Index: clang/test/ExtractAPI/underscored.c
===
--- clang/test/ExtractAPI/underscored.c
+++ clang/test/ExtractAPI/underscored.c
@@ -135,6 +135,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedRecord"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -296,6 +300,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedTypedef"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -356,6 +364,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedTypedefToHidden"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/lib/ExtractAPI/DeclarationFragments.cpp
===
--- clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -470,8 +470,7 @@
 getFragmentsForType(IntegerType, EnumDecl->getASTContext(), After))
 .append(std::move(After));
 
-  Fragments.append(";", DeclarationFragments::FragmentKind::Text);
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 DeclarationFragments
@@ -495,8 +494,7 @@
 Fragments.appendSpace().append(
 Record->getName(), DeclarationFragments::FragmentKind::Identifier);
 
-  Fragments.append(";", DeclarationFragments::FragmentKind::Text);
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 DeclarationFragments
@@ -746,8 +744,7 @@
   .appendSpace()
   .append(Decl->getName(), DeclarationFragments::FragmentKind::Identifier);
 
-  Fragments.append(";", DeclarationFragments::FragmentKind::Text);
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 template 


Index: clang/test/ExtractAPI/underscored.c
===
--- clang/test/ExtractAPI/underscored.c
+++ clang/test/ExtractAPI/underscored.c
@@ -135,6 +135,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedRecord"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -296,6 +300,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedTypedef"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -356,6 +364,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedTypedefToHidden"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/lib/ExtractAPI/DeclarationFragments.cpp
===
--- clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -470,8 +470,7 @@
 getFragmentsForType(IntegerType, EnumDecl->getASTContext(), After))
 .append(std::move(After));
 
-  Fragments.append(";", DeclarationFragments::FragmentKind::Text);
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 DeclarationFragments
@@ -495,8 +494,7 @@
 Fragments.appendSpace().append(
 Record->getName(), DeclarationFragments::FragmentKind::Identifier);
 
-  Fragments.append(";", DeclarationFragments::FragmentKind::Text);
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 DeclarationFragments
@@ -746,8 +744,7 @@
   .appendSpace()
   .append(Decl->getName(), DeclarationFragments::FragmentKind::Identifier);
 
-  Fragments.append(";", DeclarationFragments::FragmentKind::Text);
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146363: Update reference output in underscored.c

2023-03-18 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav created this revision.
Herald added a reviewer: ributzka.
Herald added a project: All.
chaitanyav requested review of this revision.
Herald added a reviewer: dang.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

update reference output in underscored.c, combine return and append semicolon 
fragment


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146363

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/underscored.c


Index: clang/test/ExtractAPI/underscored.c
===
--- clang/test/ExtractAPI/underscored.c
+++ clang/test/ExtractAPI/underscored.c
@@ -135,6 +135,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedRecord"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -296,6 +300,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedTypedef"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -356,6 +364,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedTypedefToHidden"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/lib/ExtractAPI/DeclarationFragments.cpp
===
--- clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -470,8 +470,7 @@
 getFragmentsForType(IntegerType, EnumDecl->getASTContext(), After))
 .append(std::move(After));
 
-  Fragments.append(";", DeclarationFragments::FragmentKind::Text);
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 DeclarationFragments
@@ -495,8 +494,7 @@
 Fragments.appendSpace().append(
 Record->getName(), DeclarationFragments::FragmentKind::Identifier);
 
-  Fragments.append(";", DeclarationFragments::FragmentKind::Text);
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 DeclarationFragments
@@ -746,8 +744,7 @@
   .appendSpace()
   .append(Decl->getName(), DeclarationFragments::FragmentKind::Identifier);
 
-  Fragments.append(";", DeclarationFragments::FragmentKind::Text);
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 template 


Index: clang/test/ExtractAPI/underscored.c
===
--- clang/test/ExtractAPI/underscored.c
+++ clang/test/ExtractAPI/underscored.c
@@ -135,6 +135,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedRecord"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -296,6 +300,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedTypedef"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -356,6 +364,10 @@
 {
   "kind": "identifier",
   "spelling": "ExposedTypedefToHidden"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/lib/ExtractAPI/DeclarationFragments.cpp
===
--- clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -470,8 +470,7 @@
 getFragmentsForType(IntegerType, EnumDecl->getASTContext(), After))
 .append(std::move(After));
 
-  Fragments.append(";", DeclarationFragments::FragmentKind::Text);
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 DeclarationFragments
@@ -495,8 +494,7 @@
 Fragments.appendSpace().append(
 Record->getName(), DeclarationFragments::FragmentKind::Identifier);
 
-  Fragments.append(";", DeclarationFragments::FragmentKind::Text);
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 DeclarationFragments
@@ -746,8 +744,7 @@
   .appendSpace()
   .append(Decl->getName(), DeclarationFragments::FragmentKind::Identifier);
 
-  Fragments.append(";", DeclarationFragments::FragmentKind::Text);
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146354: [clang][ExtractAPI] Add semicolons for enum, typedef, struct declaration fragments

2023-03-18 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav created this revision.
chaitanyav added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
chaitanyav requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/61480


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146354

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/anonymous_record_no_typedef.c
  clang/test/ExtractAPI/enum.c
  clang/test/ExtractAPI/struct.c
  clang/test/ExtractAPI/typedef.c
  clang/test/ExtractAPI/typedef_anonymous_record.c
  clang/test/ExtractAPI/typedef_chain.c

Index: clang/test/ExtractAPI/typedef_chain.c
===
--- clang/test/ExtractAPI/typedef_chain.c
+++ clang/test/ExtractAPI/typedef_chain.c
@@ -68,6 +68,10 @@
 {
   "kind": "identifier",
   "spelling": "MyInt"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -128,6 +132,10 @@
 {
   "kind": "identifier",
   "spelling": "MyIntInt"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -188,6 +196,10 @@
 {
   "kind": "identifier",
   "spelling": "MyIntIntInt"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/typedef_anonymous_record.c
===
--- clang/test/ExtractAPI/typedef_anonymous_record.c
+++ clang/test/ExtractAPI/typedef_anonymous_record.c
@@ -75,6 +75,10 @@
 {
   "kind": "identifier",
   "spelling": "MyEnum"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -170,6 +174,10 @@
 {
   "kind": "identifier",
   "spelling": "MyStruct"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -223,6 +231,10 @@
 {
   "kind": "identifier",
   "spelling": "MyStructStruct"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -283,6 +295,10 @@
 {
   "kind": "identifier",
   "spelling": "MyStructStructStruct"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -343,6 +359,10 @@
 {
   "kind": "identifier",
   "spelling": "MyEnumEnum"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -403,6 +423,10 @@
 {
   "kind": "identifier",
   "spelling": "MyEnumEnumEnum"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/typedef.c
===
--- clang/test/ExtractAPI/typedef.c
+++ clang/test/ExtractAPI/typedef.c
@@ -66,6 +66,10 @@
 {
   "kind": "identifier",
   "spelling": "MyInt"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
Index: clang/test/ExtractAPI/struct.c
===
--- clang/test/ExtractAPI/struct.c
+++ clang/test/ExtractAPI/struct.c
@@ -89,6 +89,10 @@
 {
   "kind": "identifier",
   "spelling": "Color"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "docComment": {
Index: clang/test/ExtractAPI/enum.c
===
--- clang/test/ExtractAPI/enum.c
+++ clang/test/ExtractAPI/enum.c
@@ -153,6 +153,10 @@
   "kind": "typeIdentifier",
   "preciseIdentifier": "c:i",
   "spelling": "unsigned int"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "docComment": {
@@ -461,6 +465,10 @@
   "kind": "typeIdentifier",
   "preciseIdentifier": "c:c",
   "spelling": "unsigned char"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -684,6 +692,10 @@
   "kind": "typeIdentifier",
   "preciseIdentifier": "c:i",
   "spelling": "unsigned int"
+},
+{
+  "kind": "text",
+  "spelling": ";"
 }
   ],
   "identifier": {
@@ -772,6 +784,10 @@
   "kind": "typeIdentifier",
   "preciseIdentifier": "c:i",
   "spelling": "unsigned int"
+},
+{
+