[PATCH] D138901: [clang] Propely handle tests for open DRs in make_cxx_dr_status

2022-11-29 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill created this revision.
Endill added reviewers: erichkeane, ychen, clang-language-wg.
Herald added a project: All.
Endill requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

A follow-up to D136133 . It was mentioned in 
#58382 
 
that there is a need to test for DRs that have not been officially resolved 
yet. This patch aims to replace original "hackery" with proper handling for 
such cases. Highlights:

- Availability can be suffixed (further) with "open", "drafting", or "review", 
e.g. `// dr2565: 16 open`, `// dr: 16 c++17 drafting`
- Checks are implemented to ensure that this suffix corresponds to actual issue 
status
- Non-resolved DRs are counted (stdout of make_cxx_dr_status)
- No changes made to cxx_dr_status.html
- 'c++20' availability suffix added
- Remove 'concurrency' status since it's no longer on the list of statuses in 
CWG Active Issues


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138901

Files:
  clang/test/CXX/drs/dr25xx.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/www/make_cxx_dr_status

Index: clang/www/make_cxx_dr_status
===
--- clang/www/make_cxx_dr_status
+++ clang/www/make_cxx_dr_status
@@ -95,6 +95,18 @@
 
 def availability(issue):
   status = status_map.get(issue, 'unknown')
+  
+  unresolved_status = ''
+  if status.endswith(' open'):
+status = status[:-5]
+unresolved_status = 'open'
+  elif status.endswith(' drafting'):
+status = status[:-9]
+unresolved_status = 'drafting'
+  elif status.endswith(' review'):
+status = status[:-7]
+unresolved_status = 'review'
+
   avail_suffix = ''
   if status.endswith(' c++11'):
 status = status[:-6]
@@ -105,6 +117,9 @@
   elif status.endswith(' c++17'):
 status = status[:-6]
 avail_suffix = ' (C++17 onwards)'
+  elif status.endswith(' c++20'):
+status = status[:-6]
+avail_suffix = ' (C++20 onwards)'
   if status == 'unknown':
 avail = 'Unknown'
 avail_style = ' class="none"'
@@ -140,17 +155,17 @@
 else:
   avail = 'Superseded by %s' % (dup, dup)
   try:
-_, avail_style = availability(int(dup))
+_, avail_style, _ = availability(int(dup))
   except:
 print("issue %s marked as sup %s" % (issue, dup), file=sys.stderr)
 avail_style = ' class="none"'
   elif status.startswith('dup '):
 dup = int(status.split(' ', 1)[1])
 avail = 'Duplicate of %s' % (dup, dup)
-_, avail_style = availability(dup)
+_, avail_style, _ = availability(dup)
   else:
 assert False, 'unknown status %s for issue %s' % (status, dr.issue)
-  return (avail + avail_suffix, avail_style)
+  return (avail + avail_suffix, avail_style, unresolved_status)
 
 count = {}
 for dr in drs:
@@ -158,21 +173,28 @@
 # This refers to the old ("C++0x") concepts feature, which was not part
 # of any C++ International Standard or Technical Specification.
 continue
-  if dr.issue in (2565, 2628):
+  elif dr.status == 'extension':
 row_style = ' class="open"'
-avail, avail_style = availability(dr.issue)
-  elif dr.status in ('open', 'concurrency', 'drafting', 'review', 'extension'):
-# We may have to deal with these some day, but not yet.
+avail = 'Extension'
+avail_style = ''
+  elif dr.status in ('open', 'drafting', 'review'):
 row_style = ' class="open"'
-if dr.status == 'extension':
-  avail = 'Extension'
-else:
+avail, avail_style, unresolved_status = availability(dr.issue)
+if avail == 'Unknown':
   avail = 'Not resolved'
-avail_style = ''
-assert dr.issue not in status_map, "have status for not-ready dr %s" % dr.issue
+  avail_style = ''
+else:
+  assert unresolved_status == dr.status, \
+ "Issue %s is marked '%s', which differs from CWG index status '%s'" \
+ % (dr.issue, unresolved_status, dr.status)
+if not avail.startswith('Sup') and not avail.startswith('Dup'):
+  count[avail] = count.get(avail, 0) + 1
   else:
 row_style = ''
-avail, avail_style = availability(dr.issue)
+avail, avail_style, unresolved_status = availability(dr.issue)
+assert not unresolved_status, \
+   "Issue %s is marked '%s', even though it is resolved in CWG index" \
+   % (dr.issue, unresolved_status)
 if not avail.startswith('Sup') and not avail.startswith('Dup'):
   count[avail] = count.get(avail, 0) + 1
 
Index: clang/test/CXX/drs/dr26xx.cpp
===
--- clang/test/CXX/drs/dr26xx.cpp
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -14,7 +14,7 @@
 }
 }
 
-namespace dr2628 { // dr2628: yes
+namespace dr2628 { // dr2628: yes open
 
 template 
 struct foo {
Index: clang/test/CXX/drs/dr25xx.cpp

[PATCH] D138727: [clang] Skip defaulted functions in zero-as-null-pointer-constant.

2022-11-29 Thread Jens Massberg via Phabricator via cfe-commits
massberg updated this revision to Diff 478477.
massberg added a comment.

Fixed comments and removed unnecessary includes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138727

Files:
  clang/lib/Sema/Sema.cpp
  clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp


Index: clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wzero-as-null-pointer-constant 
-std=c++20
+
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct A {
+  int a;
+  constexpr auto operator<=>(const A &other) const = default;
+};
+
+void test_cxx_rewritten_binary_ops() {
+  A a1, a2;
+  bool result;
+  result = (a1 < a2);
+  result = (a1 >= a2);
+  int *ptr = 0; // expected-warning{{zero as null pointer constant}}
+  result = (a1 > (ptr == 0 ? a1 : a2)); // expected-warning{{zero as null 
pointer constant}}
+  result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2)); // 
expected-warning{{zero as null pointer constant}}
+}
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -597,6 +597,12 @@
   CodeSynthesisContext::RewritingOperatorAsSpaceship)
 return;
 
+  // Ignore null pointers in defaulted comparison operators.
+  FunctionDecl *FD = getCurFunctionDecl();
+  if (FD && FD->isDefaulted()) {
+return;
+  }
+
   // If it is a macro from system header, and if the macro name is not "NULL",
   // do not warn.
   SourceLocation MaybeMacroLoc = E->getBeginLoc();


Index: clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wzero-as-null-pointer-constant -std=c++20
+
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct A {
+  int a;
+  constexpr auto operator<=>(const A &other) const = default;
+};
+
+void test_cxx_rewritten_binary_ops() {
+  A a1, a2;
+  bool result;
+  result = (a1 < a2);
+  result = (a1 >= a2);
+  int *ptr = 0; // expected-warning{{zero as null pointer constant}}
+  result = (a1 > (ptr == 0 ? a1 : a2)); // expected-warning{{zero as null pointer constant}}
+  result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2)); // expected-warning{{zero as null pointer constant}}
+}
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -597,6 +597,12 @@
   CodeSynthesisContext::RewritingOper

[PATCH] D136811: [-Wunsafe-buffer-usage] WIP: RFC: NFC: User documentation.

2022-11-29 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/docs/SafeBuffers.rst:31
+convert large amounts of old code to conform to the warning;
+  - Attribute ``[[unsafe_buffer_usage]]`` lets you annotate custom functions as
+unsafe, while providing a safe alternative that can often be suggested by




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

https://reviews.llvm.org/D136811

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


[PATCH] D138270: [clang][Sema] Skip checking int expressions for overflow in constexpr functions

2022-11-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Output for that test case is:

  ./array.cpp:1:16: error: constexpr function never produces a constant 
expression [-Winvalid-constexpr]
  constexpr void f() {
 ^
  ./array.cpp:3:23: note: value 1292785156096 is outside the range of 
representable values of type 'int'
  arr[1024*1024*1024*1204];
^
  ./array.cpp:3:28: warning: expression result unused [-Wunused-value]
  arr[1024*1024*1024*1204];
  ~~~ ~~~^
  1 warning and 1 error generated.

The first overflow warning is missing. That seems to be new though, I don't get 
that warning with clang 14 either.


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

https://reviews.llvm.org/D138270

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


[PATCH] D137415: [clang][Interp] Implement switch statements

2022-11-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeStmtGen.cpp:423
+  // Create labels and comparison ops for all case statements.
+  for (const SwitchCase *SC = S->getSwitchCaseList(); SC;
+   SC = SC->getNextSwitchCase()) {

aaron.ballman wrote:
> How well does this handle large switch statements? Generated code sometimes 
> winds up with thousands of cases, so I'm wondering if we need to have a jump 
> table implementation for numerous cases and use the simple comparison 
> implementation when there's only a small number of labels (and we can test to 
> see what constitutes a good value for "small number of labels").
> 
> Also, one thing to be aware of (that hopefully won't matter TOO much in this 
> case): the switch case list does not have a stable iteration order IIRC.
With 10'000 case labels, it seems to be slightly slower if all case labels need 
to be iterated through and slightly faster if the first iteration already hits. 
I'm not too concerned about the performance here tbh.



Comment at: clang/test/AST/Interp/switch.cpp:16-18
+  case 11:
+  case 13:
+  case 15:

aaron.ballman wrote:
> lol, you should probably fix this so it's not so confusing to casual readers.
What exactly is the confusing part? :D That the case labels are out of order?


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

https://reviews.llvm.org/D137415

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


[PATCH] D138797: [include-cleaner] Implement IWYU begin_keep/end_keep pragma support.

2022-11-29 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 478483.
VitaNuo added a comment.

Fix formatting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138797

Files:
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -308,38 +308,87 @@
 for (llvm::StringRef File : FileNames)
   Inputs.ExtraFiles[File] = "";
   }
+
+  size_t offsetToLineNum(llvm::Annotations MainFile, size_t Offset) {
+int Count = MainFile.code().substr(0, Offset).count('\n');
+return Count + 1;
+  }
 };
 
 TEST_F(PragmaIncludeTest, IWYUKeep) {
-  Inputs.Code = R"cpp(// Line 1
-#include "keep1.h" // IWYU pragma: keep
-#include "keep2.h" /* IWYU pragma: keep */
+  llvm::Annotations MainFile(R"cpp(
+$keep1^#include "keep1.h" // IWYU pragma: keep
+$keep2^#include "keep2.h" /* IWYU pragma: keep */
 
-#include "export1.h" // IWYU pragma: export // line 5
+$export1^#include "export1.h" // IWYU pragma: export
 // IWYU pragma: begin_exports
-#include "export2.h" // Line 7
-#include "export3.h"
+$export2^#include "export2.h"
+$export3^#include "export3.h"
 // IWYU pragma: end_exports
 
-#include "normal.h" // Line 11
-  )cpp";
-  createEmptyFiles({"keep1.h", "keep2.h", "export1.h", "export2.h", "export3.h",
-"normal.h"});
+$normal^#include "normal.h"
+
+// IWYU pragma: begin_keep // Line 13
+$keep3^#include "keep3.h"
+$keep4^#include "keep4.h"
+// IWYU pragma: end_keep
+
+// IWYU pragma: begin_keep // Line 18
+$keep5^#include "keep5.h"
+// IWYU pragma: begin_keep
+$keep6^#include "keep6.h"
+$keep7^#include "keep7.h"
+// IWYU pragma: end_keep
+$keep8^#include "keep8.h"
+// IWYU pragma: end_keep
+  )cpp");
+
+  Inputs.Code = MainFile.code();
+  createEmptyFiles({"keep1.h", "keep2.h", "keep3.h", "keep4.h", "keep5.h",
+"keep6.h", "keep7.h", "keep8.h", "export1.h", "export2.h",
+"export3.h", "normal.h"});
 
   TestAST Processed = build();
   EXPECT_FALSE(PI.shouldKeep(1));
+
   // Keep
-  EXPECT_TRUE(PI.shouldKeep(2));
-  EXPECT_TRUE(PI.shouldKeep(3));
+  EXPECT_TRUE(
+  PI.shouldKeep(offsetToLineNum(MainFile, MainFile.point("keep1";
+  EXPECT_TRUE(
+  PI.shouldKeep(offsetToLineNum(MainFile, MainFile.point("keep2";
+
+  EXPECT_FALSE(PI.shouldKeep(13)); // line with "begin_keep" pragma
+  EXPECT_TRUE(
+  PI.shouldKeep(offsetToLineNum(MainFile, MainFile.point("keep3";
+  EXPECT_TRUE(
+  PI.shouldKeep(offsetToLineNum(MainFile, MainFile.point("keep4";
+  EXPECT_FALSE(PI.shouldKeep(16)); // line with "end_keep" pragma
+
+  EXPECT_FALSE(PI.shouldKeep(18)); // line with "begin_keep" pragma
+  EXPECT_TRUE(
+  PI.shouldKeep(offsetToLineNum(MainFile, MainFile.point("keep5";
+  EXPECT_FALSE(PI.shouldKeep(20)); // line with "begin_keep" pragma
+  EXPECT_TRUE(
+  PI.shouldKeep(offsetToLineNum(MainFile, MainFile.point("keep6";
+  EXPECT_TRUE(
+  PI.shouldKeep(offsetToLineNum(MainFile, MainFile.point("keep7";
+  EXPECT_FALSE(PI.shouldKeep(23)); // line with "end_keep" pragma
+  EXPECT_TRUE(
+  PI.shouldKeep(offsetToLineNum(MainFile, MainFile.point("keep8";
+  EXPECT_FALSE(PI.shouldKeep(25)); // line with "end_keep" pragma
 
   // Exports
-  EXPECT_TRUE(PI.shouldKeep(5));
-  EXPECT_TRUE(PI.shouldKeep(7));
-  EXPECT_TRUE(PI.shouldKeep(8));
+  EXPECT_TRUE(
+  PI.shouldKeep(offsetToLineNum(MainFile, MainFile.point("export1";
+  EXPECT_TRUE(
+  PI.shouldKeep(offsetToLineNum(MainFile, MainFile.point("export2";
+  EXPECT_TRUE(
+  PI.shouldKeep(offsetToLineNum(MainFile, MainFile.point("export3";
   EXPECT_FALSE(PI.shouldKeep(6)); // no # directive
   EXPECT_FALSE(PI.shouldKeep(9)); // no # directive
 
-  EXPECT_FALSE(PI.shouldKeep(11));
+  EXPECT_FALSE(
+  PI.shouldKeep(offsetToLineNum(MainFile, MainFile.point("normal";
 }
 
 TEST_F(PragmaIncludeTest, IWYUPrivate) {
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -186,9 +186,7 @@
 FileID HashFID = SM.getFileID(HashLoc);
 int HashLine = SM.getLineNumber(HashFID, SM.getFileOffset(HashLoc));
 checkForExport(HashFID, HashLine, File ? &File->getFileEntry() : nullptr);
-
-if (InMainFile && LastPragmaKeepInMainFileLine == HashLine)
-  Out->ShouldKeep.insert(HashLine);
+checkForKeep(HashLine);
   }
 
   void checkForExport(FileID IncludingFile, int HashLine,
@@ -212,6 +2

[PATCH] D138727: [clang] Skip defaulted functions in zero-as-null-pointer-constant.

2022-11-29 Thread Jens Massberg via Phabricator via cfe-commits
massberg marked 2 inline comments as done.
massberg added a comment.

Thanks for the comments!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138727

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-11-29 Thread Daniel Kiss via Phabricator via cfe-commits
danielkiss added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7305
 
+  if (Args.hasArg(options::OPT_mno_fmv)) {
+CmdArgs.push_back("-target-feature");

maybe we need to add a check here for compiler-rt as rt-lib because today 
libgcc is not yet has the __aarch64_cpu_features.



Comment at: compiler-rt/lib/builtins/cpu_model.c:1311
+  // CPU features already initialized.
+  if (__aarch64_cpu_features.features)
+return;

I'd add a init value for the declaration to be sure it is properly initialised. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D138900: [X86] include cmpccxaddintrin.h from immintrin.h to x86gprintrin.h

2022-11-29 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei accepted this revision.
pengfei added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138900

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


[PATCH] D138727: [clang] Skip defaulted functions in zero-as-null-pointer-constant.

2022-11-29 Thread Jens Massberg via Phabricator via cfe-commits
massberg added a comment.

Note: The build failures are in parts of the code that isn't effected by this 
change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138727

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


[clang] 3faf1f1 - [Clang] Implement static operator[]

2022-11-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-11-29T12:39:52+02:00
New Revision: 3faf1f17a5c30a3ff1181898f2d2c7649066323d

URL: 
https://github.com/llvm/llvm-project/commit/3faf1f17a5c30a3ff1181898f2d2c7649066323d
DIFF: 
https://github.com/llvm/llvm-project/commit/3faf1f17a5c30a3ff1181898f2d2c7649066323d.diff

LOG: [Clang] Implement static operator[]

After accepted in Kona, update the code to accept static operator[] as well.

No big code changes: accept this operator as static in SemaDeclCXX, update AST 
call generation in SemaOverload and update feature macros + tests accordingly.

Reviewed By: cor3ntin, erichkeane, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D138387

Added: 
clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/CXX/over/over.oper/p7.cpp
clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
clang/test/Lexer/cxx-features.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 86911bd3b1a1e..ffce71f8c38a2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -661,7 +661,7 @@ C++2b Feature Support
 ^
 
 - Support label at end of compound statement (`P2324 
`_).
-- Implemented `P1169R4: static operator() `_.
+- Implemented `P1169R4: static operator() `_ and 
`P2589R1: static operator[] `_.
 - Implemented "char8_t Compatibility and Portability Fix" (`P2513R3 
`_).
   This change was applied to C++20 as a Defect Report.
 - Implemented "Permitting static constexpr variables in constexpr functions" 
(`P2647R1 _`).

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 71093da21b0d5..84ce58c69848c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9110,10 +9110,10 @@ def err_operator_overload_needs_class_or_enum : Error<
   "or enumeration type">;
 
 def err_operator_overload_variadic : Error<"overloaded %0 cannot be variadic">;
+def warn_cxx20_compat_operator_overload_static : Warning<
+  "declaring overloaded %0 as 'static' is incompatible with C++ standards "
+  "before C++2b">, InGroup, DefaultIgnore;
 def ext_operator_overload_static : ExtWarn<
-  "declaring overloaded %0 as 'static' is a C++2b extension">,
-  InGroup, DefaultIgnore;
-def err_call_operator_overload_static : ExtWarn<
   "declaring overloaded %0 as 'static' is a C++2b extension">, InGroup;
 def err_operator_overload_static : Error<
   "overloaded %0 cannot be a static member function">;

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 53a5f13e24afe..69480c9469262 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -695,7 +695,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
 Builder.defineMacro("__cpp_implicit_move", "202011L");
 Builder.defineMacro("__cpp_size_t_suffix", "202011L");
 Builder.defineMacro("__cpp_if_consteval", "202106L");
-Builder.defineMacro("__cpp_multidimensional_subscript", "202110L");
+Builder.defineMacro("__cpp_multidimensional_subscript", "202211L");
   }
 
   // We provide those C++2b features as extensions in earlier language modes, 
so

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 174fe43a2cd51..194298ab5f7bf 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -16015,10 +16015,11 @@ bool 
Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) {
   //   function allowed to be static is the call operator function.
   if (CXXMethodDecl *MethodDecl = dyn_cast(FnDecl)) {
 if (MethodDecl->isStatic()) {
-  if (Op == OO_Call)
+  if (Op == OO_Call || Op == OO_Subscript)
 Diag(FnDecl->getLocation(),
- (LangOpts.CPlusPlus2b ? diag::ext_operator_overload_static
-   : diag::err_call_operator_overload_static))
+ (LangOpts.CPlusPlus2b
+  ? diag::warn_cxx20_compat_operator_overload_static
+  : diag::ext_operator_overload_static))
 << FnDecl;
   else
 return Diag(FnDecl->getLocation(), diag::err_operator_overload_static)

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index f2c897dbe882f..a20d7dda79300 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.

[PATCH] D138387: [Clang] Implement static operator[]

2022-11-29 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3faf1f17a5c3: [Clang] Implement static operator[] (authored 
by royjacobson).

Changed prior to commit:
  https://reviews.llvm.org/D138387?vs=477550&id=478493#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138387

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/over/over.oper/p7.cpp
  clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
  clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1518,7 +1518,7 @@
 
   static operator[]
   https://wg21.link/P2589R1";>P2589R1
-  No
+  16
 
 
   Permitting static constexpr variables in constexpr functions (DR)
Index: clang/test/Lexer/cxx-features.cpp
===
--- clang/test/Lexer/cxx-features.cpp
+++ clang/test/Lexer/cxx-features.cpp
@@ -43,7 +43,7 @@
 #error "wrong value for __cpp_if_consteval"
 #endif
 
-#if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202110)
+#if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202211)
 #error "wrong value for __cpp_multidimensional_subscript"
 #endif
 
Index: clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -triple x86_64-linux -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -triple x86_64-windows-msvc -o - | FileCheck %s
+
+struct Functor {
+  static int operator[](int x, int y) {
+return x + y;
+  }
+};
+
+void call_static_subscript_operator() {
+  Functor f;
+  f[101, 102];
+  f.operator[](201, 202);
+  Functor{}[301, 302];
+  Functor::operator[](401, 402);
+}
+
+// CHECK:  define {{.*}}call_static_subscript_operator{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:{{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 401, i32 noundef 402)
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
+
+struct FunctorConsteval {
+  consteval static int operator[](int x, int y) {
+  return x + y;
+  }
+};
+
+struct FunctorConstexpr {
+  constexpr static int operator[](int x, int y) {
+  return x + y;
+  }
+};
+
+void test_consteval_constexpr() {
+  int x = 0;
+  int y = FunctorConstexpr{}[x, 2];
+  constexpr int z1 = FunctorConsteval{}[2, 2];
+  constexpr int z2 = FunctorConstexpr{}[2, 2];
+  
+  static_assert(z1 == 4);
+  static_assert(z2 == 4);
+}
+
+template 
+struct DepFunctor {
+  static int operator[](T t) {
+return int(t);
+  }
+};
+
+void test_dep_functors() {
+  int x = DepFunctor{}[1.0f];
+  int y = DepFunctor{}[true];
+}
+
+// CHECK:  define {{.*}}test_dep_functors{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:%call = call noundef i32 {{.*}}DepFunctor{{.*}}(float noundef 1.00e+00)
+// CHECK:%call1 = call noundef i32 {{.*}}DepFunctor{{.*}}(i1 noundef zeroext true)
+// CHECK:ret void
+// CHECK-NEXT: }
Index: clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
===
--- clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
+++ clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
@@ -28,6 +28,7 @@
   f(101, 102);
   f.operator()(201, 202);
   Functor{}(301, 302);
+  Functor::operator()(401, 402);
 }
 
 // CHECK:  define {{.*}}call_static_call_operator{{.*}}
@@ -35,6 +36,7 @@
 // CHECK:{{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
 // CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
 // CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 401, i32 noundef 402)
 // CHECK-NEXT:   ret void
 // CHECK-NEXT: }
 
Index: clang/test/CXX/over/over.oper/p7.cpp
===
--- clang/test/CXX/over/over.oper/p7.cpp
+++ clang/test/CXX/over/over.oper/p7.cpp
@@ -5,14 +5,19 @@
 
 struct Functor {
   static int operator()(int a, int b);
-  // cxx11-warning@-1 {{is a C++2b extension}}
-  // precxx2b-warning

[PATCH] D138603: [Clang] Implement LWG3823 for __is_aggregate

2022-11-29 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 478495.
royjacobson edited the summary of this revision.
royjacobson added a comment.

rebase to retry CI


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138603

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -533,13 +533,15 @@
   constexpr bool TrueAfterCpp14 = __cplusplus > 201402L;
 
   __is_aggregate(AnIncompleteType); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[1]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeAr); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArNB); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArMB); // expected-error {{incomplete type}}
   __is_aggregate(IncompleteUnion); // expected-error {{incomplete type}}
 
+  // Valid since LWG3823
+  static_assert(__is_aggregate(AnIncompleteType[]), "");
+  static_assert(__is_aggregate(AnIncompleteType[1]), "");
+  static_assert(__is_aggregate(AnIncompleteTypeAr), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArNB), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArMB), "");
+
   static_assert(!__is_aggregate(NonPOD), "");
   static_assert(__is_aggregate(NonPODAr), "");
   static_assert(__is_aggregate(NonPODArNB), "");
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4874,9 +4874,16 @@
   Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
 return true;
 
+  // LWG3823: T shall be an array type, a complete type, or cv void.
+  case UTT_IsAggregate:
+if (ArgTy->isArrayType() || ArgTy->isVoidType())
+  return true;
+
+return !S.RequireCompleteType(
+Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
+
   // C++1z [meta.unary.prop]:
   //   remove_all_extents_t shall be a complete type or cv void.
-  case UTT_IsAggregate:
   case UTT_IsTrivial:
   case UTT_IsTriviallyCopyable:
   case UTT_IsStandardLayout:
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -304,6 +304,8 @@
 - GNU attributes being applied prior to standard attributes would be handled
   improperly, which was corrected to match the behaviour exhibited by GCC.
   `Issue 58229 `_
+- The builtin type trait ``__is_aggregate`` now returns ``true`` for arrays of 
incomplete
+  types in accordance with the suggested fix for `LWG3823 
https://cplusplus.github.io/LWG/issue3823`_
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -533,13 +533,15 @@
   constexpr bool TrueAfterCpp14 = __cplusplus > 201402L;
 
   __is_aggregate(AnIncompleteType); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[1]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeAr); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArNB); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArMB); // expected-error {{incomplete type}}
   __is_aggregate(IncompleteUnion); // expected-error {{incomplete type}}
 
+  // Valid since LWG3823
+  static_assert(__is_aggregate(AnIncompleteType[]), "");
+  static_assert(__is_aggregate(AnIncompleteType[1]), "");
+  static_assert(__is_aggregate(AnIncompleteTypeAr), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArNB), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArMB), "");
+
   static_assert(!__is_aggregate(NonPOD), "");
   static_assert(__is_aggregate(NonPODAr), "");
   static_assert(__is_aggregate(NonPODArNB), "");
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4874,9 +4874,16 @@
   Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
 return true;
 
+  // LWG3823: T shall be an array type, a complete type, or cv void.
+  case UTT_IsAggregate:
+if (ArgTy->isArrayType() || ArgTy->isVoidType())
+  return true;
+
+return !S.RequireCompleteType(
+Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);

[PATCH] D138788: [SVE] Change some bfloat lane intrinsics to use i32 immediates

2022-11-29 Thread David Sherwood via Phabricator via cfe-commits
david-arm updated this revision to Diff 478494.
david-arm edited the summary of this revision.
david-arm added a comment.

- Changed patch to use autoupgrade mechanism.


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

https://reviews.llvm.org/D138788

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfdot.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmlalb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmlalt.c
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
  llvm/lib/Target/AArch64/SVEInstrFormats.td
  llvm/test/CodeGen/AArch64/sve-intrinsics-bfloat.ll

Index: llvm/test/CodeGen/AArch64/sve-intrinsics-bfloat.ll
===
--- llvm/test/CodeGen/AArch64/sve-intrinsics-bfloat.ll
+++ llvm/test/CodeGen/AArch64/sve-intrinsics-bfloat.ll
@@ -19,7 +19,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfdot z0.s, z1.h, z2.h[0]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfdot.lane( %a,  %b,  %c, i64 0)
+  %out = call  @llvm.aarch64.sve.bfdot.lane.i32( %a,  %b,  %c, i32 0)
   ret  %out
 }
 
@@ -28,7 +28,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfdot z0.s, z1.h, z2.h[1]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfdot.lane( %a,  %b,  %c, i64 1)
+  %out = call  @llvm.aarch64.sve.bfdot.lane.i32( %a,  %b,  %c, i32 1)
   ret  %out
 }
 
@@ -37,7 +37,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfdot z0.s, z1.h, z2.h[2]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfdot.lane( %a,  %b,  %c, i64 2)
+  %out = call  @llvm.aarch64.sve.bfdot.lane.i32( %a,  %b,  %c, i32 2)
   ret  %out
 }
 
@@ -46,7 +46,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfdot z0.s, z1.h, z2.h[3]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfdot.lane( %a,  %b,  %c, i64 3)
+  %out = call  @llvm.aarch64.sve.bfdot.lane.i32( %a,  %b,  %c, i32 3)
   ret  %out
 }
 
@@ -68,7 +68,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[0]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 0)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.i32( %a,  %b,  %c, i32 0)
   ret  %out
 }
 
@@ -77,7 +77,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[1]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 1)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.i32( %a,  %b,  %c, i32 1)
   ret  %out
 }
 
@@ -86,7 +86,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[2]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 2)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.i32( %a,  %b,  %c, i32 2)
   ret  %out
 }
 
@@ -95,7 +95,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[3]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 3)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.i32( %a,  %b,  %c, i32 3)
   ret  %out
 }
 
@@ -104,7 +104,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[4]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 4)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.i32( %a,  %b,  %c, i32 4)
   ret  %out
 }
 
@@ -113,7 +113,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[5]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 5)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.i32( %a,  %b,  %c, i32 5)
   ret  %out
 }
 
@@ -122,7 +122,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[6]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 6)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.i32( %a,  %b,  %c, i32 6)
   ret  %out
 }
 
@@ -131,7 +131,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[7]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 7)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.i32( %a,  %b,  %c, i32 7)
   ret  %out
 }
 
@@ -153,7 +153,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalt z0.s, z1.h, z2.h[0]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalt.lane( %a,  %b,  %c, i64 0)
+  %out = call  @llvm.aarch64.sve.bfmlalt.lane.i32( %a,  %b,  %c, i32 0)
   ret  %out
 }
 
@@ -162,7 +162,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalt z0.s, z1.h, z2.h[1]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalt.lane( %a,  %b,  %c, i64 1)
+  %out = call  @llvm.aarch64.sve.bfmlalt.lane.i32( %a,  %b,  %c, i32 1)
   ret  %out
 }
 
@@ -171,7 +171,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalt z0.s, z1.h, z2.h[2]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalt.lane( %a,  %b,  %c, i64 2)
+  %out = call  @llvm.aarch64.sve.bfmlalt.lane.i32( %a,  

[clang] 849b650 - [clang] Skip defaulted functions in zero-as-null-pointer-constant.

2022-11-29 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2022-11-29T11:56:10+01:00
New Revision: 849b650cf3b60e60f5e3a6457fe52e9c63e76e4c

URL: 
https://github.com/llvm/llvm-project/commit/849b650cf3b60e60f5e3a6457fe52e9c63e76e4c
DIFF: 
https://github.com/llvm/llvm-project/commit/849b650cf3b60e60f5e3a6457fe52e9c63e76e4c.diff

LOG: [clang] Skip defaulted functions in zero-as-null-pointer-constant.

The zero-as-null-pointer-constant check should not fire if it is inside
a defaulted function, e.g. defaulted spaceship operators.
Add C++20 tests with spaceship operators.

Fixes #50221

Differential Revision: https://reviews.llvm.org/D138727

Added: 
clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp

Modified: 
clang/lib/Sema/Sema.cpp

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index c229a77ff0b8d..ad53e874e9d32 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -597,6 +597,12 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, 
const Expr *E) {
   CodeSynthesisContext::RewritingOperatorAsSpaceship)
 return;
 
+  // Ignore null pointers in defaulted comparison operators.
+  FunctionDecl *FD = getCurFunctionDecl();
+  if (FD && FD->isDefaulted()) {
+return;
+  }
+
   // If it is a macro from system header, and if the macro name is not "NULL",
   // do not warn.
   SourceLocation MaybeMacroLoc = E->getBeginLoc();

diff  --git a/clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp 
b/clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
new file mode 100644
index 0..32b259d00aee2
--- /dev/null
+++ b/clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wzero-as-null-pointer-constant 
-std=c++20
+
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct A {
+  int a;
+  constexpr auto operator<=>(const A &other) const = default;
+};
+
+void test_cxx_rewritten_binary_ops() {
+  A a1, a2;
+  bool result;
+  result = (a1 < a2);
+  result = (a1 >= a2);
+  int *ptr = 0; // expected-warning{{zero as null pointer constant}}
+  result = (a1 > (ptr == 0 ? a1 : a2)); // expected-warning{{zero as null 
pointer constant}}
+  result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2)); // 
expected-warning{{zero as null pointer constant}}
+}



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


[PATCH] D138727: [clang] Skip defaulted functions in zero-as-null-pointer-constant.

2022-11-29 Thread Jens Massberg 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 rG849b650cf3b6: [clang] Skip defaulted functions in 
zero-as-null-pointer-constant. (authored by massberg).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138727

Files:
  clang/lib/Sema/Sema.cpp
  clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp


Index: clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wzero-as-null-pointer-constant 
-std=c++20
+
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct A {
+  int a;
+  constexpr auto operator<=>(const A &other) const = default;
+};
+
+void test_cxx_rewritten_binary_ops() {
+  A a1, a2;
+  bool result;
+  result = (a1 < a2);
+  result = (a1 >= a2);
+  int *ptr = 0; // expected-warning{{zero as null pointer constant}}
+  result = (a1 > (ptr == 0 ? a1 : a2)); // expected-warning{{zero as null 
pointer constant}}
+  result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2)); // 
expected-warning{{zero as null pointer constant}}
+}
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -597,6 +597,12 @@
   CodeSynthesisContext::RewritingOperatorAsSpaceship)
 return;
 
+  // Ignore null pointers in defaulted comparison operators.
+  FunctionDecl *FD = getCurFunctionDecl();
+  if (FD && FD->isDefaulted()) {
+return;
+  }
+
   // If it is a macro from system header, and if the macro name is not "NULL",
   // do not warn.
   SourceLocation MaybeMacroLoc = E->getBeginLoc();


Index: clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wzero-as-null-pointer-constant -std=c++20
+
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct A {
+  int a;
+  constexpr auto operator<=>(const A &other) const = default;
+};
+
+void test_cxx_rewritten_binary_ops() {
+  A a1, a2;
+  bool result;
+  result = (a1 < a2);
+  result = (a1 >= a2);
+  int *ptr = 0; // expected-warning{{zero as null pointer constant}}
+  result = (a1 > (ptr == 0 ? a1 : a2)); // expected-warning{{zero as null pointer constant}}
+  result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2)); // expected-warning{{zero as null pointer constant}}
+}
Index: clang/lib/Sema/Sema.cpp

[PATCH] D138777: [clang-tidy] Add check bugprone-multiple-new-in-one-expression.

2022-11-29 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

CppCoreGuidelines rule 
r13-perform-at-most-one-explicit-resource-allocation-in-a-single-expression-statement
 

 is applicable for this problem. The current check is more restricted. If the 
check is moved to cppcoreguidelines it should check for any multiple `new` in a 
single expression and probably for other "resource allocation" that is not 
`new` (if there is such case at all that can not be changed to a safe function 
call or is not deprecated by other rules). Probably we can have an option to 
switch the behavior (any 2 `new` or the current way) and move the check to 
cppcoreguidelines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138777

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


[PATCH] D138749: [clang] Compare constraints before diagnosing mismatched ref qualifiers (GH58962)

2022-11-29 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 478502.
royjacobson added a comment.

Remove redundant comments, use Sema::AreConstraintExpressionsEqual instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138749

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/over/over.load/p2-0x.cpp

Index: clang/test/CXX/over/over.load/p2-0x.cpp
===
--- clang/test/CXX/over/over.load/p2-0x.cpp
+++ clang/test/CXX/over/over.load/p2-0x.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 // Member function declarations with the same name and the same
 // parameter-type-list as well as mem- ber function template
@@ -22,3 +23,31 @@
   void k(); // expected-note{{previous declaration}}
   void k() &&; // expected-error{{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}}
 };
+
+
+#if __cplusplus >= 202002L
+namespace GH58962 {
+
+template
+__add_rvalue_reference(T) declval();
+
+template
+struct type
+{
+void func() requires (R == 0);
+void func() & requires (R == 1);
+void func() && requires (R == 2);
+};
+
+template
+concept test = requires { declval().func(); };
+
+static_assert(test&>);
+static_assert(test&&>);
+static_assert(test&>);
+static_assert(not test&&>);
+static_assert(not test&>);
+static_assert(test&&>);
+
+}
+#endif
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -1316,6 +1316,17 @@
 (!SameTemplateParameterList || !SameReturnType))
   return true;
   }
+
+  if (ConsiderRequiresClauses) {
+Expr *NewRC = New->getTrailingRequiresClause(),
+ *OldRC = Old->getTrailingRequiresClause();
+if ((NewRC != nullptr) != (OldRC != nullptr))
+  return true;
+
+if (NewRC && !AreConstraintExpressionsEqual(Old, OldRC, New, NewRC))
+return true;
+  }
+
   // If the function is a class member, its signature includes the
   // cv-qualifiers (if any) and ref-qualifier (if any) on the function itself.
   //
@@ -1332,14 +1343,15 @@
   if (!UseMemberUsingDeclRules &&
   (OldMethod->getRefQualifier() == RQ_None ||
NewMethod->getRefQualifier() == RQ_None)) {
-// C++0x [over.load]p2:
-//   - Member function declarations with the same name and the same
-// parameter-type-list as well as member function template
-// declarations with the same name, the same parameter-type-list, and
-// the same template parameter lists cannot be overloaded if any of
-// them, but not all, have a ref-qualifier (8.3.5).
+// C++20 [over.load]p2:
+//   - Member function declarations with the same name, the same
+// parameter-type-list, and the same trailing requires-clause (if
+// any), as well as member function template declarations with the
+// same name, the same parameter-type-list, the same trailing
+// requires-clause (if any), and the same template-head, cannot be
+// overloaded if any of them, but not all, have a ref-qualifier.
 Diag(NewMethod->getLocation(), diag::err_ref_qualifier_overload)
-  << NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
+<< NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
 Diag(OldMethod->getLocation(), diag::note_previous_declaration);
   }
   return true;
@@ -1403,23 +1415,6 @@
 }
   }
 
-  if (ConsiderRequiresClauses) {
-Expr *NewRC = New->getTrailingRequiresClause(),
- *OldRC = Old->getTrailingRequiresClause();
-if ((NewRC != nullptr) != (OldRC != nullptr))
-  // RC are most certainly different - these are overloads.
-  return true;
-
-if (NewRC) {
-  llvm::FoldingSetNodeID NewID, OldID;
-  NewRC->Profile(NewID, Context, /*Canonical=*/true);
-  OldRC->Profile(OldID, Context, /*Canonical=*/true);
-  if (NewID != OldID)
-// RCs are not equivalent - these are overloads.
-return true;
-}
-  }
-
   // The signatures match; this is not an overload.
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138749: [clang] Compare constraints before diagnosing mismatched ref qualifiers (GH58962)

2022-11-29 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked 3 inline comments as done.
royjacobson added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:1324
+if ((NewRC != nullptr) != (OldRC != nullptr))
+  // RC are most certainly different - these are overloads.
+  return true;

erichkeane wrote:
> cor3ntin wrote:
> > I know it's preexisting but, I'm not sure that comment adds anything.
> > If we want to keep it, "requires clauses are different, - these are 
> > overloads."
> The comment is definitely low quality here, I would probably prefer a little 
> more elaboration if we're going to keep it.
removed it.



Comment at: clang/lib/Sema/SemaOverload.cpp:1327
+
+if (NewRC) {
+  llvm::FoldingSetNodeID NewID, OldID;

erichkeane wrote:
> I did some work that extracted these at one point, and it matters because we 
> have to 'fix' the depths sometimes.  I suspect it wont' really come up here, 
> since we have already checked that these are both the same 'type' of template 
> parameter by now?  But at some point (perhaps not in this patch?) we might 
> find calling ` Sema::AreConstraintExpressionsEqual` necessary.
Went for `Sema::AreConstraintExpressionsEqual` to reduce code duplication. Only 
drawback is calling `CalculateTemplateDepthForConstraints` unnecessarily which 
seems reasonable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138749

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


[PATCH] D135508: [clangd] Heuristic to avoid desync if editors are confused about newline-at-eof

2022-11-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

as discussed, this is a rather contained fix that are likely to help with other 
editors that might get confused with new-lines at EOF. so LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135508

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


[PATCH] D138908: [clangd] Highlight "miscellaneous" types as `type` as a fallback.

2022-11-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This allows them to carry modifiers like `deduced`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138908

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -114,7 +114,7 @@
 $Primitive_deduced_defaultLibrary[[auto]] 
$LocalVariable_def[[VeryLongVariableName]] = 12312;
 $Class[[AS]] $LocalVariable_def[[AA]];
 $Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_def[[L]] = 
$LocalVariable[[AA]].$Field[[SomeMember]] + $Parameter[[A]];
-auto $LocalVariable_def[[FN]] = [ $LocalVariable[[AA]]](int 
$Parameter_def[[A]]) -> void {};
+$Type_deduced[[auto]] $LocalVariable_def[[FN]] = [ 
$LocalVariable[[AA]]](int $Parameter_def[[A]]) -> void {};
 $LocalVariable[[FN]](12312);
   }
 )cpp",
@@ -122,7 +122,7 @@
   void $Function_decl[[foo]](int);
   void $Function_decl[[Gah]]();
   void $Function_def[[foo]]() {
-auto $LocalVariable_def[[Bou]] = $Function[[Gah]];
+$Type_deduced[[auto]] $LocalVariable_def[[Bou]] = $Function[[Gah]];
   }
   struct $Class_def[[A]] {
 void $Method_decl[[abc]]();
@@ -331,7 +331,7 @@
   $Enum_deduced[[auto]] &$Variable_def[[AER]] = $Variable[[AE]];
   $Primitive_deduced_defaultLibrary[[auto]] $Variable_def[[Form]] = 10.2 + 
2 * 4;
   $Primitive_deduced_defaultLibrary[[decltype]]($Variable[[Form]]) 
$Variable_def[[F]] = 10;
-  auto $Variable_def[[Fun]] = []()->void{};
+  $Type_deduced[[auto]] $Variable_def[[Fun]] = []()->void{};
 )cpp",
   R"cpp(
   class $Class_def[[G]] {};
@@ -901,7 +901,7 @@
 };
 
 void $Function_def[[s]]($Class[[Foo]] $Parameter_def[[f]]) {
-  auto $LocalVariable_def[[k]] = &$Class[[Foo]]::$Method[[foo]];
+  $Type_deduced[[auto]] $LocalVariable_def[[k]] = 
&$Class[[Foo]]::$Method[[foo]];
   ($Parameter[[f]].*$LocalVariable[[k]])(); // no crash on 
VisitCXXMemberCallExpr
 }
   )cpp"};
@@ -972,7 +972,7 @@
   )cpp",
   R"cpp(
 // Lambdas are considered functions, not classes.
-auto $Variable_fileScope[[x]] = 
[$LocalVariable_functionScope[[m]](42)] {
+$Type_fileScope[[auto]] $Variable_fileScope[[x]] = 
[$LocalVariable_functionScope[[m]](42)] {
   return $LocalVariable_functionScope[[m]];
 };
   )cpp",
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -99,7 +99,8 @@
 // We try to highlight typedefs as their underlying type.
 if (auto K =
 kindForType(TD->getUnderlyingType().getTypePtrOrNull(), Resolver))
-  return K;
+  if (*K != HighlightingKind::Type)
+return K;
 // And fallback to a generic kind if this fails.
 return HighlightingKind::Typedef;
   }
@@ -171,12 +172,14 @@
   if (TP->isBuiltinType()) // Builtins are special, they do not have decls.
 return HighlightingKind::Primitive;
   if (auto *TD = dyn_cast(TP))
-return kindForDecl(TD->getDecl(), Resolver);
+if (auto Kind = kindForDecl(TD->getDecl(), Resolver))
+  return Kind;
   if (isa(TP))
 return HighlightingKind::Class;
   if (auto *TD = TP->getAsTagDecl())
-return kindForDecl(TD, Resolver);
-  return llvm::None;
+if (auto K = kindForDecl(TD, Resolver))
+  return K;
+  return HighlightingKind::Type;
 }
 
 // Whether T is const in a loose sense - is a variable with this type readonly?


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -114,7 +114,7 @@
 $Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_def[[VeryLongVariableName]] = 12312;
 $Class[[AS]] $LocalVariable_def[[AA]];
 $Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_def[[L]] = $LocalVariable[[AA]].$Field[[SomeMember]] + $Parameter[[A]];
-auto $LocalVariable_def[[FN]] = [ $LocalVariable[[AA]]](int $Parameter_def[[A]]) -> void {};
+$Type_deduced[[auto]] $LocalVariable_def[[FN]] = [ $LocalVariable[[AA]]](int $Parameter

[PATCH] D138797: [include-cleaner] Implement IWYU begin_keep/end_keep pragma support.

2022-11-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:312
+
+  size_t offsetToLineNum(llvm::Annotations MainFile, size_t Offset) {
+int Count = MainFile.code().substr(0, Offset).count('\n');

this is only used in `IWYUKeep` test, I'd make it as a local lambda (with 
MainFile captured) in the test:

```
auto OffsetToLineNum = [&MainFile](size_t Offset) { ... };
``` 



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:331
+
+// IWYU pragma: begin_keep // Line 13
+$keep3^#include "keep3.h"

I think we can also do similar thing on `$begin_keep_pragma^// IWYU pragma...`




Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:333
+$keep3^#include "keep3.h"
+$keep4^#include "keep4.h"
+// IWYU pragma: end_keep

keep4.h can be removed to simplify the testcode.



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:340
+$keep6^#include "keep6.h"
+$keep7^#include "keep7.h"
+// IWYU pragma: end_keep

keep7.h can be removed.



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:367
+
+  EXPECT_FALSE(PI.shouldKeep(18)); // line with "begin_keep" pragma
+  EXPECT_TRUE(

no need to repeatly test the begin_keep and end_keep pragmas.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138797

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


[clang-tools-extra] a53f895 - [clangd] Heuristic to avoid desync if editors are confused about newline-at-eof

2022-11-29 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-11-29T13:15:20+01:00
New Revision: a53f89522f46dd10f87f163d8501738182729b8d

URL: 
https://github.com/llvm/llvm-project/commit/a53f89522f46dd10f87f163d8501738182729b8d
DIFF: 
https://github.com/llvm/llvm-project/commit/a53f89522f46dd10f87f163d8501738182729b8d.diff

LOG: [clangd] Heuristic to avoid desync if editors are confused about 
newline-at-eof

As strange as it seems to our files-are-strings view of the world, some editors
that treat files as arrays of lines can get confused about whether the last line
has a newline or not.

The consequences of failing to handle a bad incremental update are catastrophic.
If an update would be valid except for a missing newline at end of file, pretend
one exists.

This fixes problems still present in neovim where deleting all text often leads
to a desync shortly afterwards: https://github.com/neovim/neovim/issues/17085

Differential Revision: https://reviews.llvm.org/D135508

Added: 


Modified: 
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/clangd/unittests/SourceCodeTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/SourceCode.cpp 
b/clang-tools-extra/clangd/SourceCode.cpp
index 5913db5405a34..d51bb997b5305 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -1063,6 +1063,40 @@ llvm::Error reformatEdit(Edit &E, const 
format::FormatStyle &Style) {
   return llvm::Error::success();
 }
 
+// Workaround for editors that have buggy handling of newlines at end of file.
+//
+// The editor is supposed to expose document contents over LSP as an exact
+// string, with whitespace and newlines well-defined. But internally many
+// editors treat text as an array of lines, and there can be ambiguity over
+// whether the last line ends with a newline or not.
+//
+// This confusion can lead to incorrect edits being sent. Failing to apply them
+// is catastrophic: we're desynced, LSP has no mechanism to get back in sync.
+// We apply a heuristic to avoid this state.
+//
+// If our current view of an N-line file does *not* end in a newline, but the
+// editor refers to the start of the next line (an impossible location), then
+// we silently add a newline to make this valid.
+// We will still validate that the rangeLength is correct, *including* the
+// inferred newline.
+//
+// See https://github.com/neovim/neovim/issues/17085
+static void inferFinalNewline(llvm::Expected &Err,
+  std::string &Contents, const Position &Pos) {
+  if (Err)
+return;
+  if (!Contents.empty() && Contents.back() == '\n')
+return;
+  if (Pos.character != 0)
+return;
+  if (Pos.line != llvm::count(Contents, '\n') + 1)
+return;
+  log("Editor sent invalid change coordinates, inferring newline at EOF");
+  Contents.push_back('\n');
+  consumeError(Err.takeError());
+  Err = Contents.size();
+}
+
 llvm::Error applyChange(std::string &Contents,
 const TextDocumentContentChangeEvent &Change) {
   if (!Change.range) {
@@ -1072,11 +1106,13 @@ llvm::Error applyChange(std::string &Contents,
 
   const Position &Start = Change.range->start;
   llvm::Expected StartIndex = positionToOffset(Contents, Start, false);
+  inferFinalNewline(StartIndex, Contents, Start);
   if (!StartIndex)
 return StartIndex.takeError();
 
   const Position &End = Change.range->end;
   llvm::Expected EndIndex = positionToOffset(Contents, End, false);
+  inferFinalNewline(EndIndex, Contents, End);
   if (!EndIndex)
 return EndIndex.takeError();
 

diff  --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp 
b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
index d7fd1a09e85d3..ce22062ab4d5e 100644
--- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -954,6 +954,44 @@ TEST(ApplyEditsTest, WrongRangeLength) {
   "the computed range length (2)."));
 }
 
+// Test that we correct observed buggy edits from Neovim.
+TEST(ApplyEditsTets, BuggyNeovimEdits) {
+  TextDocumentContentChangeEvent Change;
+  Change.range.emplace();
+
+  // https://github.com/neovim/neovim/issues/17085
+  // Adding a blank line after a (missing) newline
+  std::string Code = "a";
+  Change.range->start.line = 1;
+  Change.range->start.character = 0;
+  Change.range->end.line = 1;
+  Change.range->start.character = 0;
+  Change.rangeLength = 0;
+  Change.text = "\n";
+  EXPECT_THAT_ERROR(applyChange(Code, Change), llvm::Succeeded());
+  EXPECT_EQ(Code, "a\n\n");
+
+  // https://github.com/neovim/neovim/issues/17085#issuecomment-1269162264
+  // Replacing the (missing) newline with \n\n in an empty file.
+  Code = "";
+  Change.range->start.line = 0;
+  Change.range->start.character = 0;
+  Change.range->end.line = 1;
+  Change.range->end.character = 0;
+  Change.rangeLength = 1;
+

[PATCH] D135508: [clangd] Heuristic to avoid desync if editors are confused about newline-at-eof

2022-11-29 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa53f89522f46: [clangd] Heuristic to avoid desync if editors 
are confused about newline-at-eof (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135508

Files:
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/unittests/SourceCodeTests.cpp

Index: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
===
--- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -954,6 +954,44 @@
   "the computed range length (2)."));
 }
 
+// Test that we correct observed buggy edits from Neovim.
+TEST(ApplyEditsTets, BuggyNeovimEdits) {
+  TextDocumentContentChangeEvent Change;
+  Change.range.emplace();
+
+  // https://github.com/neovim/neovim/issues/17085
+  // Adding a blank line after a (missing) newline
+  std::string Code = "a";
+  Change.range->start.line = 1;
+  Change.range->start.character = 0;
+  Change.range->end.line = 1;
+  Change.range->start.character = 0;
+  Change.rangeLength = 0;
+  Change.text = "\n";
+  EXPECT_THAT_ERROR(applyChange(Code, Change), llvm::Succeeded());
+  EXPECT_EQ(Code, "a\n\n");
+
+  // https://github.com/neovim/neovim/issues/17085#issuecomment-1269162264
+  // Replacing the (missing) newline with \n\n in an empty file.
+  Code = "";
+  Change.range->start.line = 0;
+  Change.range->start.character = 0;
+  Change.range->end.line = 1;
+  Change.range->end.character = 0;
+  Change.rangeLength = 1;
+  Change.text = "\n\n";
+
+  EXPECT_THAT_ERROR(applyChange(Code, Change), llvm::Succeeded());
+  EXPECT_EQ(Code, "\n\n");
+
+  // We do not apply the heuristic fixes if the rangeLength doesn't match.
+  Code = "";
+  Change.rangeLength = 0;
+  EXPECT_THAT_ERROR(applyChange(Code, Change),
+FailedWithMessage("Change's rangeLength (0) doesn't match "
+  "the computed range length (1)."));
+}
+
 TEST(ApplyEditsTest, EndBeforeStart) {
   std::string Code = "int main() {}\n";
 
Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -1063,6 +1063,40 @@
   return llvm::Error::success();
 }
 
+// Workaround for editors that have buggy handling of newlines at end of file.
+//
+// The editor is supposed to expose document contents over LSP as an exact
+// string, with whitespace and newlines well-defined. But internally many
+// editors treat text as an array of lines, and there can be ambiguity over
+// whether the last line ends with a newline or not.
+//
+// This confusion can lead to incorrect edits being sent. Failing to apply them
+// is catastrophic: we're desynced, LSP has no mechanism to get back in sync.
+// We apply a heuristic to avoid this state.
+//
+// If our current view of an N-line file does *not* end in a newline, but the
+// editor refers to the start of the next line (an impossible location), then
+// we silently add a newline to make this valid.
+// We will still validate that the rangeLength is correct, *including* the
+// inferred newline.
+//
+// See https://github.com/neovim/neovim/issues/17085
+static void inferFinalNewline(llvm::Expected &Err,
+  std::string &Contents, const Position &Pos) {
+  if (Err)
+return;
+  if (!Contents.empty() && Contents.back() == '\n')
+return;
+  if (Pos.character != 0)
+return;
+  if (Pos.line != llvm::count(Contents, '\n') + 1)
+return;
+  log("Editor sent invalid change coordinates, inferring newline at EOF");
+  Contents.push_back('\n');
+  consumeError(Err.takeError());
+  Err = Contents.size();
+}
+
 llvm::Error applyChange(std::string &Contents,
 const TextDocumentContentChangeEvent &Change) {
   if (!Change.range) {
@@ -1072,11 +1106,13 @@
 
   const Position &Start = Change.range->start;
   llvm::Expected StartIndex = positionToOffset(Contents, Start, false);
+  inferFinalNewline(StartIndex, Contents, Start);
   if (!StartIndex)
 return StartIndex.takeError();
 
   const Position &End = Change.range->end;
   llvm::Expected EndIndex = positionToOffset(Contents, End, false);
+  inferFinalNewline(EndIndex, Contents, End);
   if (!EndIndex)
 return EndIndex.takeError();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136078: Use-after-return sanitizer binary metadata

2022-11-29 Thread Marco Elver via Phabricator via cfe-commits
melver added inline comments.



Comment at: llvm/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp:1
+// We run the compiled binary + sizes of stack arguments depend on the arch.
+// REQUIRES: native && target-x86_64

For LLVM IR tests, consider if utils/update_test_checks.py and for MIR 
utils/update_mir_test_checks.py could help.

Ideally, there'd be no .cpp runtime test, but I also think writing the .ll and 
.mir tests manually is impossible.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136078

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


[PATCH] D136554: Implement CWG2631

2022-11-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:9654-9655
+return true;
+  if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() ||
+  Ctx.isUnevaluated())
+return false;

cor3ntin wrote:
> aaron.ballman wrote:
> > We repeat this pattern four times in this patch; perhaps we should make a 
> > helper function for this predicate? Not certain of the best name for it, 
> > but removing the duplication might not be a bad idea.
> `isNotPotentiallyEvaluatedContext`? Something like that
Actually, Maybe we should leave it as is in this patch, 
and clean it up as part of 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2564r0.html
IE, I'm not sure i can come up with a completely correct name now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

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


[PATCH] D135171: FreeBSD: enable __float128 on x86

2022-11-29 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.

@brooks do you want me to commit this for you or do you have commit access?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135171

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


[PATCH] D138655: [clang-tidy] Fix `cppcoreguidelines-init-variables` for invalid vardecl

2022-11-29 Thread gehry via Phabricator via cfe-commits
Sockke updated this revision to Diff 478529.
Sockke added a comment.

Added test in existing `init-variables.cpp` file.


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

https://reviews.llvm.org/D138655

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
@@ -1,6 +1,15 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t -- -- 
-fno-delayed-template-parsing -fexceptions
+// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables -fix-errors %t 
-- -- -fno-delayed-template-parsing -fexceptions
 // CHECK-FIXES: {{^}}#include 
 
+#include "unknown.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:10: error: 'unknown.h' file not found 
[clang-diagnostic-error]
+
+namespace std {
+template 
+struct vector {
+  vector();
+};
+
 // Ensure that function declarations are not changed.
 void some_func(int x, double d, bool b, const char *p);
 
@@ -124,3 +133,10 @@
   Fruit fruit;
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'fruit' is not 
initialized [cppcoreguidelines-init-variables]
 }
+
+void test_clang_diagnostic_error() {
+  int a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'a' is not initialized 
[cppcoreguidelines-init-variables]
+  // CHECK-FIXES: {{^}}  int a = 0;{{$}}
+  std::vector arr;
+}
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
@@ -60,6 +60,8 @@
   const ASTContext &Context = *Result.Context;
   const SourceManager &Source = Context.getSourceManager();
 
+  if (MatchedDecl->isInvalidDecl())
+return;
   // We want to warn about cases where the type name
   // comes from a macro like this:
   //


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
@@ -1,6 +1,15 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t -- -- -fno-delayed-template-parsing -fexceptions
+// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables -fix-errors %t -- -- -fno-delayed-template-parsing -fexceptions
 // CHECK-FIXES: {{^}}#include 
 
+#include "unknown.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:10: error: 'unknown.h' file not found [clang-diagnostic-error]
+
+namespace std {
+template 
+struct vector {
+  vector();
+};
+
 // Ensure that function declarations are not changed.
 void some_func(int x, double d, bool b, const char *p);
 
@@ -124,3 +133,10 @@
   Fruit fruit;
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'fruit' is not initialized [cppcoreguidelines-init-variables]
 }
+
+void test_clang_diagnostic_error() {
+  int a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'a' is not initialized [cppcoreguidelines-init-variables]
+  // CHECK-FIXES: {{^}}  int a = 0;{{$}}
+  std::vector arr;
+}
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
@@ -60,6 +60,8 @@
   const ASTContext &Context = *Result.Context;
   const SourceManager &Source = Context.getSourceManager();
 
+  if (MatchedDecl->isInvalidDecl())
+return;
   // We want to warn about cases where the type name
   // comes from a macro like this:
   //
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137415: [clang][Interp] Implement switch statements

2022-11-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeStmtGen.cpp:423
+  // Create labels and comparison ops for all case statements.
+  for (const SwitchCase *SC = S->getSwitchCaseList(); SC;
+   SC = SC->getNextSwitchCase()) {

tbaeder wrote:
> aaron.ballman wrote:
> > How well does this handle large switch statements? Generated code sometimes 
> > winds up with thousands of cases, so I'm wondering if we need to have a 
> > jump table implementation for numerous cases and use the simple comparison 
> > implementation when there's only a small number of labels (and we can test 
> > to see what constitutes a good value for "small number of labels").
> > 
> > Also, one thing to be aware of (that hopefully won't matter TOO much in 
> > this case): the switch case list does not have a stable iteration order 
> > IIRC.
> With 10'000 case labels, it seems to be slightly slower if all case labels 
> need to be iterated through and slightly faster if the first iteration 
> already hits. I'm not too concerned about the performance here tbh.
Okay, we can address performance concerns later, if they arise. Thanks!



Comment at: clang/test/AST/Interp/switch.cpp:16-18
+  case 11:
+  case 13:
+  case 15:

tbaeder wrote:
> aaron.ballman wrote:
> > lol, you should probably fix this so it's not so confusing to casual 
> > readers.
> What exactly is the confusing part? :D That the case labels are out of order?
The function is called `isEven` and 11, 13, 15 all return true due to 
fallthrough.


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

https://reviews.llvm.org/D137415

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


[clang] 3c75fea - [clang] Compare constraints before diagnosing mismatched ref qualifiers (GH58962)

2022-11-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-11-29T14:57:26+02:00
New Revision: 3c75feab3bbda563374f08e46a7c052c0c6f1c36

URL: 
https://github.com/llvm/llvm-project/commit/3c75feab3bbda563374f08e46a7c052c0c6f1c36
DIFF: 
https://github.com/llvm/llvm-project/commit/3c75feab3bbda563374f08e46a7c052c0c6f1c36.diff

LOG: [clang] Compare constraints before diagnosing mismatched ref qualifiers 
(GH58962)

As noticed in GH58962, we should only diagnose illegal overloads of member 
functions
when the ref qualifiers don't match if the trailing constraints are the same.

The fix is to move the existing constraints check earlier in Sema::IsOverload.

Closes https://github.com/llvm/llvm-project/issues/58962

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D138749

Added: 


Modified: 
clang/lib/Sema/SemaOverload.cpp
clang/test/CXX/over/over.load/p2-0x.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index a20d7dda79300..1eb68090a8fdb 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1316,6 +1316,17 @@ bool Sema::IsOverload(FunctionDecl *New, FunctionDecl 
*Old,
 (!SameTemplateParameterList || !SameReturnType))
   return true;
   }
+
+  if (ConsiderRequiresClauses) {
+Expr *NewRC = New->getTrailingRequiresClause(),
+ *OldRC = Old->getTrailingRequiresClause();
+if ((NewRC != nullptr) != (OldRC != nullptr))
+  return true;
+
+if (NewRC && !AreConstraintExpressionsEqual(Old, OldRC, New, NewRC))
+return true;
+  }
+
   // If the function is a class member, its signature includes the
   // cv-qualifiers (if any) and ref-qualifier (if any) on the function itself.
   //
@@ -1332,14 +1343,15 @@ bool Sema::IsOverload(FunctionDecl *New, FunctionDecl 
*Old,
   if (!UseMemberUsingDeclRules &&
   (OldMethod->getRefQualifier() == RQ_None ||
NewMethod->getRefQualifier() == RQ_None)) {
-// C++0x [over.load]p2:
-//   - Member function declarations with the same name and the same
-// parameter-type-list as well as member function template
-// declarations with the same name, the same parameter-type-list, 
and
-// the same template parameter lists cannot be overloaded if any of
-// them, but not all, have a ref-qualifier (8.3.5).
+// C++20 [over.load]p2:
+//   - Member function declarations with the same name, the same
+// parameter-type-list, and the same trailing requires-clause (if
+// any), as well as member function template declarations with the
+// same name, the same parameter-type-list, the same trailing
+// requires-clause (if any), and the same template-head, cannot be
+// overloaded if any of them, but not all, have a ref-qualifier.
 Diag(NewMethod->getLocation(), diag::err_ref_qualifier_overload)
-  << NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
+<< NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
 Diag(OldMethod->getLocation(), diag::note_previous_declaration);
   }
   return true;
@@ -1403,23 +1415,6 @@ bool Sema::IsOverload(FunctionDecl *New, FunctionDecl 
*Old,
 }
   }
 
-  if (ConsiderRequiresClauses) {
-Expr *NewRC = New->getTrailingRequiresClause(),
- *OldRC = Old->getTrailingRequiresClause();
-if ((NewRC != nullptr) != (OldRC != nullptr))
-  // RC are most certainly 
diff erent - these are overloads.
-  return true;
-
-if (NewRC) {
-  llvm::FoldingSetNodeID NewID, OldID;
-  NewRC->Profile(NewID, Context, /*Canonical=*/true);
-  OldRC->Profile(OldID, Context, /*Canonical=*/true);
-  if (NewID != OldID)
-// RCs are not equivalent - these are overloads.
-return true;
-}
-  }
-
   // The signatures match; this is not an overload.
   return false;
 }

diff  --git a/clang/test/CXX/over/over.load/p2-0x.cpp 
b/clang/test/CXX/over/over.load/p2-0x.cpp
index cf38741056aba..183f3cb322af7 100644
--- a/clang/test/CXX/over/over.load/p2-0x.cpp
+++ b/clang/test/CXX/over/over.load/p2-0x.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 // Member function declarations with the same name and the same
 // parameter-type-list as well as mem- ber function template
@@ -22,3 +23,31 @@ class Y {
   void k(); // expected-note{{previous declaration}}
   void k() &&; // expected-error{{cannot overload a member function with 
ref-qualifier '&&' with a member function without a ref-qualifier}}
 };
+
+
+#if __cplusplus >= 202002L
+namespace GH58962 {
+
+template
+__add_rvalue_reference(T) declval();
+
+template
+struct type
+{
+void func() requires (R == 0);
+void func() & requires (R == 1);
+void func() && requires (R 

[PATCH] D138749: [clang] Compare constraints before diagnosing mismatched ref qualifiers (GH58962)

2022-11-29 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
royjacobson marked 2 inline comments as done.
Closed by commit rG3c75feab3bbd: [clang] Compare constraints before diagnosing 
mismatched ref qualifiers… (authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138749

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/over/over.load/p2-0x.cpp

Index: clang/test/CXX/over/over.load/p2-0x.cpp
===
--- clang/test/CXX/over/over.load/p2-0x.cpp
+++ clang/test/CXX/over/over.load/p2-0x.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 // Member function declarations with the same name and the same
 // parameter-type-list as well as mem- ber function template
@@ -22,3 +23,31 @@
   void k(); // expected-note{{previous declaration}}
   void k() &&; // expected-error{{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}}
 };
+
+
+#if __cplusplus >= 202002L
+namespace GH58962 {
+
+template
+__add_rvalue_reference(T) declval();
+
+template
+struct type
+{
+void func() requires (R == 0);
+void func() & requires (R == 1);
+void func() && requires (R == 2);
+};
+
+template
+concept test = requires { declval().func(); };
+
+static_assert(test&>);
+static_assert(test&&>);
+static_assert(test&>);
+static_assert(not test&&>);
+static_assert(not test&>);
+static_assert(test&&>);
+
+}
+#endif
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -1316,6 +1316,17 @@
 (!SameTemplateParameterList || !SameReturnType))
   return true;
   }
+
+  if (ConsiderRequiresClauses) {
+Expr *NewRC = New->getTrailingRequiresClause(),
+ *OldRC = Old->getTrailingRequiresClause();
+if ((NewRC != nullptr) != (OldRC != nullptr))
+  return true;
+
+if (NewRC && !AreConstraintExpressionsEqual(Old, OldRC, New, NewRC))
+return true;
+  }
+
   // If the function is a class member, its signature includes the
   // cv-qualifiers (if any) and ref-qualifier (if any) on the function itself.
   //
@@ -1332,14 +1343,15 @@
   if (!UseMemberUsingDeclRules &&
   (OldMethod->getRefQualifier() == RQ_None ||
NewMethod->getRefQualifier() == RQ_None)) {
-// C++0x [over.load]p2:
-//   - Member function declarations with the same name and the same
-// parameter-type-list as well as member function template
-// declarations with the same name, the same parameter-type-list, and
-// the same template parameter lists cannot be overloaded if any of
-// them, but not all, have a ref-qualifier (8.3.5).
+// C++20 [over.load]p2:
+//   - Member function declarations with the same name, the same
+// parameter-type-list, and the same trailing requires-clause (if
+// any), as well as member function template declarations with the
+// same name, the same parameter-type-list, the same trailing
+// requires-clause (if any), and the same template-head, cannot be
+// overloaded if any of them, but not all, have a ref-qualifier.
 Diag(NewMethod->getLocation(), diag::err_ref_qualifier_overload)
-  << NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
+<< NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
 Diag(OldMethod->getLocation(), diag::note_previous_declaration);
   }
   return true;
@@ -1403,23 +1415,6 @@
 }
   }
 
-  if (ConsiderRequiresClauses) {
-Expr *NewRC = New->getTrailingRequiresClause(),
- *OldRC = Old->getTrailingRequiresClause();
-if ((NewRC != nullptr) != (OldRC != nullptr))
-  // RC are most certainly different - these are overloads.
-  return true;
-
-if (NewRC) {
-  llvm::FoldingSetNodeID NewID, OldID;
-  NewRC->Profile(NewID, Context, /*Canonical=*/true);
-  OldRC->Profile(OldID, Context, /*Canonical=*/true);
-  if (NewID != OldID)
-// RCs are not equivalent - these are overloads.
-return true;
-}
-  }
-
   // The signatures match; this is not an overload.
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 13c3228 - [Clang] Implement LWG3823 for __is_aggregate

2022-11-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-11-29T14:57:47+02:00
New Revision: 13c32288354b6175527f4fdece623157d3637da3

URL: 
https://github.com/llvm/llvm-project/commit/13c32288354b6175527f4fdece623157d3637da3
DIFF: 
https://github.com/llvm/llvm-project/commit/13c32288354b6175527f4fdece623157d3637da3.diff

LOG: [Clang] Implement LWG3823 for __is_aggregate

LWG3823 says that arrays of incomplete types are aggregates. Fix the clang 
builtin to match that.

Closes https://github.com/llvm/llvm-project/issues/59002

Reviewed By: cjdb

Differential Revision: https://reviews.llvm.org/D138603

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ffce71f8c38a..551070b27b2d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -304,6 +304,8 @@ Bug Fixes
 - GNU attributes being applied prior to standard attributes would be handled
   improperly, which was corrected to match the behaviour exhibited by GCC.
   `Issue 58229 `_
+- The builtin type trait ``__is_aggregate`` now returns ``true`` for arrays of 
incomplete
+  types in accordance with the suggested fix for `LWG3823 
https://cplusplus.github.io/LWG/issue3823`_
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 8b3cd4211f88..0980f507426c 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4874,9 +4874,16 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, 
TypeTrait UTT,
   Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
 return true;
 
+  // LWG3823: T shall be an array type, a complete type, or cv void.
+  case UTT_IsAggregate:
+if (ArgTy->isArrayType() || ArgTy->isVoidType())
+  return true;
+
+return !S.RequireCompleteType(
+Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
+
   // C++1z [meta.unary.prop]:
   //   remove_all_extents_t shall be a complete type or cv void.
-  case UTT_IsAggregate:
   case UTT_IsTrivial:
   case UTT_IsTriviallyCopyable:
   case UTT_IsStandardLayout:

diff  --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 4369ed0c4672..76a67252c941 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -533,13 +533,15 @@ void is_aggregate()
   constexpr bool TrueAfterCpp14 = __cplusplus > 201402L;
 
   __is_aggregate(AnIncompleteType); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[1]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeAr); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArNB); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArMB); // expected-error {{incomplete type}}
   __is_aggregate(IncompleteUnion); // expected-error {{incomplete type}}
 
+  // Valid since LWG3823
+  static_assert(__is_aggregate(AnIncompleteType[]), "");
+  static_assert(__is_aggregate(AnIncompleteType[1]), "");
+  static_assert(__is_aggregate(AnIncompleteTypeAr), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArNB), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArMB), "");
+
   static_assert(!__is_aggregate(NonPOD), "");
   static_assert(__is_aggregate(NonPODAr), "");
   static_assert(__is_aggregate(NonPODArNB), "");



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


[PATCH] D138603: [Clang] Implement LWG3823 for __is_aggregate

2022-11-29 Thread Roy Jacobson 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 rG13c32288354b: [Clang] Implement LWG3823 for __is_aggregate 
(authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138603

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -533,13 +533,15 @@
   constexpr bool TrueAfterCpp14 = __cplusplus > 201402L;
 
   __is_aggregate(AnIncompleteType); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[1]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeAr); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArNB); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArMB); // expected-error {{incomplete type}}
   __is_aggregate(IncompleteUnion); // expected-error {{incomplete type}}
 
+  // Valid since LWG3823
+  static_assert(__is_aggregate(AnIncompleteType[]), "");
+  static_assert(__is_aggregate(AnIncompleteType[1]), "");
+  static_assert(__is_aggregate(AnIncompleteTypeAr), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArNB), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArMB), "");
+
   static_assert(!__is_aggregate(NonPOD), "");
   static_assert(__is_aggregate(NonPODAr), "");
   static_assert(__is_aggregate(NonPODArNB), "");
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4874,9 +4874,16 @@
   Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
 return true;
 
+  // LWG3823: T shall be an array type, a complete type, or cv void.
+  case UTT_IsAggregate:
+if (ArgTy->isArrayType() || ArgTy->isVoidType())
+  return true;
+
+return !S.RequireCompleteType(
+Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
+
   // C++1z [meta.unary.prop]:
   //   remove_all_extents_t shall be a complete type or cv void.
-  case UTT_IsAggregate:
   case UTT_IsTrivial:
   case UTT_IsTriviallyCopyable:
   case UTT_IsStandardLayout:
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -304,6 +304,8 @@
 - GNU attributes being applied prior to standard attributes would be handled
   improperly, which was corrected to match the behaviour exhibited by GCC.
   `Issue 58229 `_
+- The builtin type trait ``__is_aggregate`` now returns ``true`` for arrays of 
incomplete
+  types in accordance with the suggested fix for `LWG3823 
https://cplusplus.github.io/LWG/issue3823`_
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -533,13 +533,15 @@
   constexpr bool TrueAfterCpp14 = __cplusplus > 201402L;
 
   __is_aggregate(AnIncompleteType); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[1]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeAr); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArNB); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArMB); // expected-error {{incomplete type}}
   __is_aggregate(IncompleteUnion); // expected-error {{incomplete type}}
 
+  // Valid since LWG3823
+  static_assert(__is_aggregate(AnIncompleteType[]), "");
+  static_assert(__is_aggregate(AnIncompleteType[1]), "");
+  static_assert(__is_aggregate(AnIncompleteTypeAr), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArNB), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArMB), "");
+
   static_assert(!__is_aggregate(NonPOD), "");
   static_assert(__is_aggregate(NonPODAr), "");
   static_assert(__is_aggregate(NonPODArNB), "");
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -4874,9 +4874,16 @@
   Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
 return true;
 
+  // LWG3823: T shall be an array type, a complete type, or cv void.
+  case UTT_IsAggregate:
+if (ArgTy->isArrayType() || ArgTy->isVoidType())
+  return true;
+
+return !S.Requir

[clang] c64359e - [NFC] fix doc inconsistency in cxx_status

2022-11-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-11-29T15:00:40+02:00
New Revision: c64359ea4c8ee9830dc828ed26d862a763f4535d

URL: 
https://github.com/llvm/llvm-project/commit/c64359ea4c8ee9830dc828ed26d862a763f4535d
DIFF: 
https://github.com/llvm/llvm-project/commit/c64359ea4c8ee9830dc828ed26d862a763f4535d.diff

LOG: [NFC] fix doc inconsistency in cxx_status

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 9559c562bdec..ab4eabb542f5 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -1518,7 +1518,7 @@ C++2b implementation status
 
   static operator[]
   https://wg21.link/P2589R1";>P2589R1
-  16
+  Clang 16
 
 
   Permitting static constexpr variables in constexpr functions 
(DR)



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


[PATCH] D138679: [clang][CodeGen] Add default attributes to __clang_call_terminate

2022-11-29 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki added a comment.

The CI failures look related to this change: 
https://buildkite.com/llvm-project/premerge-checks/builds/123301#0184aa94-1b82-44a9-9c25-4074e026d266


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138679

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


[clang] 6b8900f - [clang][CodeGen] Add default attributes to __clang_call_terminate

2022-11-29 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2022-11-29T13:09:52Z
New Revision: 6b8900f7f91de489302886c7e48033407d13f8c1

URL: 
https://github.com/llvm/llvm-project/commit/6b8900f7f91de489302886c7e48033407d13f8c1
DIFF: 
https://github.com/llvm/llvm-project/commit/6b8900f7f91de489302886c7e48033407d13f8c1.diff

LOG: [clang][CodeGen] Add default attributes to __clang_call_terminate

When generating __clang_call_terminate use SetLLVMFunctionAttributes
to set the default function attributes, like we do for all the other
functions generated by clang. This fixes a problem where target
features from the command line weren't being applied to this function.

Differential Revision: https://reviews.llvm.org/D138679

Added: 
clang/test/CodeGenCXX/arm-generated-fn-attr.cpp

Modified: 
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/test/CodeGenCXX/dllimport-runtime-fns.cpp
clang/test/CodeGenCXX/exceptions.cpp
clang/test/CodeGenCXX/runtime-dllstorage.cpp
clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp
clang/test/OpenMP/parallel_codegen.cpp
clang/test/OpenMP/parallel_for_codegen.cpp
clang/test/OpenMP/parallel_master_codegen.cpp
clang/test/OpenMP/parallel_sections_codegen.cpp
clang/test/OpenMP/single_codegen.cpp
clang/test/OpenMP/taskgroup_codegen.cpp
clang/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp
clang/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 224a019d2fd3..66bfbd79595e 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -4675,13 +4675,16 @@ void ItaniumCXXABI::emitBeginCatch(CodeGenFunction &CGF,
 ///   void @__clang_call_terminate(i8* %exn) nounwind noreturn
 /// This code is used only in C++.
 static llvm::FunctionCallee getClangCallTerminateFn(CodeGenModule &CGM) {
-  llvm::FunctionType *fnTy =
-llvm::FunctionType::get(CGM.VoidTy, CGM.Int8PtrTy, /*isVarArg=*/false);
+  ASTContext &C = CGM.getContext();
+  const CGFunctionInfo &FI = CGM.getTypes().arrangeBuiltinFunctionDeclaration(
+  C.VoidTy, {C.getPointerType(C.CharTy)});
+  llvm::FunctionType *fnTy = CGM.getTypes().GetFunctionType(FI);
   llvm::FunctionCallee fnRef = CGM.CreateRuntimeFunction(
   fnTy, "__clang_call_terminate", llvm::AttributeList(), /*Local=*/true);
   llvm::Function *fn =
   cast(fnRef.getCallee()->stripPointerCasts());
   if (fn->empty()) {
+CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, fn, /*IsThunk=*/false);
 fn->setDoesNotThrow();
 fn->setDoesNotReturn();
 

diff  --git a/clang/test/CodeGenCXX/arm-generated-fn-attr.cpp 
b/clang/test/CodeGenCXX/arm-generated-fn-attr.cpp
new file mode 100644
index ..4908e8366d02
--- /dev/null
+++ b/clang/test/CodeGenCXX/arm-generated-fn-attr.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -triple thumbv8.1m.main-none-eabi -target-feature +pacbti 
-fcxx-exceptions -fexceptions -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-PACBTI
+// RUN: %clang_cc1 -triple thumbv8.1m.main-none-eabi -target-feature -pacbti 
-fcxx-exceptions -fexceptions -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-NOPACBTI
+
+// Check that functions generated by clang have the correct attributes
+
+class Example {
+public:
+  Example();
+  int fn();
+};
+
+// Initialization of var1 causes __cxx_global_var_init and __tls_init to be 
generated
+thread_local Example var1;
+extern thread_local Example var2;
+extern void fn();
+
+int testfn() noexcept {
+  // Calling fn in a noexcept function causes __clang_call_terminate to be 
generated
+  fn();
+  // Use of var1 and var2 causes TLS wrapper functions to be generated
+  return var1.fn() + var2.fn();
+}
+
+// CHECK: define {{.*}} @__cxx_global_var_init() [[ATTR1:#[0-9]+]]
+// CHECK: define {{.*}} @__clang_call_terminate({{.*}}) [[ATTR2:#[0-9]+]]
+// CHECK: define {{.*}} @_ZTW4var1() [[ATTR3:#[0-9]+]]
+// CHECK: define {{.*}} @_ZTW4var2() [[ATTR3]]
+// CHECK: define {{.*}} @__tls_init() [[ATTR1]]
+
+// CHECK-PACBTI: attributes [[ATTR1]] = { 
{{.*}}"target-features"="+armv8.1-m.main,+pacbti,+thumb-mode"{{.*}} }
+// CHECK-PACBTI: attributes [[ATTR2]] = { 
{{.*}}"target-features"="+armv8.1-m.main,+pacbti,+thumb-mode"{{.*}} }
+// CHECK-PACBTI: attributes [[ATTR3]] = { 
{{.*}}"target-features"="+armv8.1-m.main,+pacbti,+thumb-mode"{{.*}} }
+
+// CHECK-NOPACBTI: attributes [[ATTR1]] = { 
{{.*}}"target-features"="+armv8.1-m.main,+thumb-mode,-pacbti"{{.*}} }
+// CHECK-NOPACBTI: attributes [[ATTR2]] = { 
{{.*}}"target-features"="+armv8.1-m.main,+thumb-mode,-pacbti"{{.*}} }
+// CHECK-NOPACBTI: attributes [[ATTR3]] = { 
{{.*}}"target-features"="+armv8.1-m.main,+thumb-mode,-pacbti"{{.*}} }

diff  --git a/clang/test/CodeGenCXX/dllimport-runtime-fns.cpp 
b/clang/test/CodeGenCXX/dllimport-runtime-fns.cpp
index d589

[PATCH] D138679: [clang][CodeGen] Add default attributes to __clang_call_terminate

2022-11-29 Thread John Brawn 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 rG6b8900f7f91d: [clang][CodeGen] Add default attributes to 
__clang_call_terminate (authored by john.brawn).

Changed prior to commit:
  https://reviews.llvm.org/D138679?vs=477799&id=478536#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138679

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/arm-generated-fn-attr.cpp
  clang/test/CodeGenCXX/dllimport-runtime-fns.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/runtime-dllstorage.cpp
  clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp
  clang/test/OpenMP/parallel_codegen.cpp
  clang/test/OpenMP/parallel_for_codegen.cpp
  clang/test/OpenMP/parallel_master_codegen.cpp
  clang/test/OpenMP/parallel_sections_codegen.cpp
  clang/test/OpenMP/single_codegen.cpp
  clang/test/OpenMP/taskgroup_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp

Index: clang/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp
===
--- clang/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp
+++ clang/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp
@@ -381,7 +381,7 @@
 //
 //
 // CHECK1-LABEL: define {{[^@]+}}@__clang_call_terminate
-// CHECK1-SAME: (ptr [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
+// CHECK1-SAME: (ptr noundef [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
 // CHECK1-NEXT:[[TMP2:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP0]]) #[[ATTR6]]
 // CHECK1-NEXT:call void @_ZSt9terminatev() #[[ATTR9]]
 // CHECK1-NEXT:unreachable
@@ -1549,7 +1549,7 @@
 //
 //
 // CHECK3-LABEL: define {{[^@]+}}@__clang_call_terminate
-// CHECK3-SAME: (ptr [[TMP0:%.*]]) #[[ATTR4:[0-9]+]] comdat {
+// CHECK3-SAME: (ptr noundef [[TMP0:%.*]]) #[[ATTR4:[0-9]+]] comdat {
 // CHECK3-NEXT:[[TMP2:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP0]]) #[[ATTR6]]
 // CHECK3-NEXT:call void @_ZSt9terminatev() #[[ATTR7]]
 // CHECK3-NEXT:unreachable
@@ -2058,7 +2058,7 @@
 //
 //
 // CHECK5-LABEL: define {{[^@]+}}@__clang_call_terminate
-// CHECK5-SAME: (ptr [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
+// CHECK5-SAME: (ptr noundef [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
 // CHECK5-NEXT:[[TMP2:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP0]]) #[[ATTR6]]
 // CHECK5-NEXT:call void @_ZSt9terminatev() #[[ATTR9]]
 // CHECK5-NEXT:unreachable
Index: clang/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp
===
--- clang/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp
+++ clang/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp
@@ -365,7 +365,7 @@
 //
 //
 // CHECK1-LABEL: define {{[^@]+}}@__clang_call_terminate
-// CHECK1-SAME: (ptr [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
+// CHECK1-SAME: (ptr noundef [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
 // CHECK1-NEXT:[[TMP2:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP0]]) #[[ATTR6]]
 // CHECK1-NEXT:call void @_ZSt9terminatev() #[[ATTR9]]
 // CHECK1-NEXT:unreachable
@@ -1609,7 +1609,7 @@
 //
 //
 // CHECK5-LABEL: define {{[^@]+}}@__clang_call_terminate
-// CHECK5-SAME: (ptr [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
+// CHECK5-SAME: (ptr noundef [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
 // CHECK5-NEXT:[[TMP2:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP0]]) #[[ATTR6]]
 // CHECK5-NEXT:call void @_ZSt9terminatev() #[[ATTR9]]
 // CHECK5-NEXT:unreachable
Index: clang/test/OpenMP/taskgroup_codegen.cpp
===
--- clang/test/OpenMP/taskgroup_codegen.cpp
+++ clang/test/OpenMP/taskgroup_codegen.cpp
@@ -66,7 +66,7 @@
 //
 //
 // CHECK1-LABEL: define {{[^@]+}}@__clang_call_terminate
-// CHECK1-SAME: (ptr [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
+// CHECK1-SAME: (ptr noundef [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] comdat {
 // CHECK1-NEXT:[[TMP2:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP0]]) #[[ATTR3:[0-9]+]]
 // CHECK1-NEXT:call void @_ZSt9terminatev() #[[ATTR8]]
 // CHECK1-NEXT:unreachable
@@ -136,7 +136,7 @@
 //
 //
 // DEBUG1-LABEL: define {{[^@]+}}@__clang_call_terminate
-// DEBUG1-SAME: (ptr [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] {
+// DEBUG1-SAME: (ptr noundef [[TMP0:%.*]]) #[[ATTR5:[0-9]+]] {
 // DEBUG1-NEXT:[[TMP2:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP0]]) #[[ATTR3:[0-9]+]]
 // DEBUG1-NEXT:call void @_ZSt9terminatev() #[[ATTR8]]
 // DEBUG1-NEXT:unreachable
Index: clang/test/OpenMP/single_codegen.cpp
===
--- clang/test/OpenMP/single_codegen.cpp
+++ clang/test/OpenMP/sing

[clang-tools-extra] 3c97f6c - [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-29 Thread Archibald Elliott via cfe-commits

Author: Archibald Elliott
Date: 2022-11-29T13:14:13Z
New Revision: 3c97f6cab92fb3511d72996ac7ca8a8b459ebc88

URL: 
https://github.com/llvm/llvm-project/commit/3c97f6cab92fb3511d72996ac7ca8a8b459ebc88
DIFF: 
https://github.com/llvm/llvm-project/commit/3c97f6cab92fb3511d72996ac7ca8a8b459ebc88.diff

LOG: [Support] Move getHostNumPhysicalCores to Threading.h

This change is focussed on simplifying `Support/Host.h` to only do
target detection. In this case, this function is close in usage to
existing functions in `Support/Threading.h`, so I moved it into there.
The function is also renamed to `llvm::get_physical_cores()` to match
the style of threading's functions.

The big change here is that now if you have threading disabled,
`llvm::get_physical_cores()` will return -1, as if it had not been able
to work out the right info. This is due to how Threading.cpp includes
OS-specific code/headers. This seems ok, as if threading is disabled,
LLVM should not need to know the number of physical cores.

Differential Revision: https://reviews.llvm.org/D137836

Added: 


Modified: 
clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
llvm/include/llvm/Support/Host.h
llvm/include/llvm/Support/Threading.h
llvm/lib/Support/Host.cpp
llvm/lib/Support/Threading.cpp
llvm/lib/Support/Unix/Threading.inc
llvm/lib/Support/Windows/Threading.inc
llvm/unittests/Support/Host.cpp
llvm/unittests/Support/Threading.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h 
b/clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
index 3b7620adafb1..bf760e367ff7 100644
--- a/clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
+++ b/clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
@@ -7,11 +7,7 @@ class Dex;
 } // namespace clang
 
 namespace llvm {
-namespace sys {
-
-int getHostNumPhysicalCores();
-
-} // namespace sys
+int get_physical_cores();
 } // namespace llvm
 
 namespace {

diff  --git a/llvm/include/llvm/Support/Host.h 
b/llvm/include/llvm/Support/Host.h
index 369d6745db5a..dcebebdca6cb 100644
--- a/llvm/include/llvm/Support/Host.h
+++ b/llvm/include/llvm/Support/Host.h
@@ -54,11 +54,6 @@ namespace sys {
   /// \return - True on success.
   bool getHostCPUFeatures(StringMap &Features);
 
-  /// Get the number of physical cores (as opposed to logical cores returned
-  /// from thread::hardware_concurrency(), which includes hyperthreads).
-  /// Returns -1 if unknown for the current host system.
-  int getHostNumPhysicalCores();
-
   namespace detail {
   /// Helper functions to extract HostCPUName from /proc/cpuinfo on linux.
   StringRef getHostCPUNameForPowerPC(StringRef ProcCpuinfoContent);

diff  --git a/llvm/include/llvm/Support/Threading.h 
b/llvm/include/llvm/Support/Threading.h
index 7f2708ddbb46..f3f7c44bd439 100644
--- a/llvm/include/llvm/Support/Threading.h
+++ b/llvm/include/llvm/Support/Threading.h
@@ -231,6 +231,11 @@ constexpr bool llvm_is_multithreaded() { return 
LLVM_ENABLE_THREADS; }
   /// Returns how many physical CPUs or NUMA groups the system has.
   unsigned get_cpus();
 
+  /// Returns how many physical cores (as opposed to logical cores returned 
from
+  /// thread::hardware_concurrency(), which includes hyperthreads).
+  /// Returns -1 if unknown for the current host system.
+  int get_physical_cores();
+
   enum class ThreadPriority {
 /// Lower the current thread's priority as much as possible. Can be used
 /// for long-running tasks that are not time critical; more energy-

diff  --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp
index 713227c4b088..c87d9644d097 100644
--- a/llvm/lib/Support/Host.cpp
+++ b/llvm/lib/Support/Host.cpp
@@ -1576,128 +1576,6 @@ VendorSignatures getVendorSignature(unsigned *MaxLeaf) {
 } // namespace llvm
 #endif
 
-#if defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
-// On Linux, the number of physical cores can be computed from /proc/cpuinfo,
-// using the number of unique physical/core id pairs. The following
-// implementation reads the /proc/cpuinfo format on an x86_64 system.
-static int computeHostNumPhysicalCores() {
-  // Enabled represents the number of physical id/core id pairs with at least
-  // one processor id enabled by the CPU affinity mask.
-  cpu_set_t Affinity, Enabled;
-  if (sched_getaffinity(0, sizeof(Affinity), &Affinity) != 0)
-return -1;
-  CPU_ZERO(&Enabled);
-
-  // Read /proc/cpuinfo as a stream (until EOF reached). It cannot be
-  // mmapped because it appears to have 0 size.
-  llvm::ErrorOr> Text =
-  llvm::MemoryBuffer::getFileAsStream("/proc/cpuinfo");
-  if (std::error_code EC = Text.getError()) {
-llvm::errs() << "Can't read "
- << "/proc/cpuinfo: " << EC.message() << "\n";
-return -1;
-  }
-  SmallVector strs;
-  (*Text)->getBuffer().split(strs, "\n", /*MaxSplit=*/-1,
- /*KeepEmpty=

[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-29 Thread Sam Elliott via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
lenary marked an inline comment as done.
Closed by commit rG3c97f6cab92f: [Support] Move getHostNumPhysicalCores to 
Threading.h (authored by lenary).

Changed prior to commit:
  https://reviews.llvm.org/D137836?vs=477975&id=478537#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137836

Files:
  clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
  llvm/include/llvm/Support/Host.h
  llvm/include/llvm/Support/Threading.h
  llvm/lib/Support/Host.cpp
  llvm/lib/Support/Threading.cpp
  llvm/lib/Support/Unix/Threading.inc
  llvm/lib/Support/Windows/Threading.inc
  llvm/unittests/Support/Host.cpp
  llvm/unittests/Support/Threading.cpp

Index: llvm/unittests/Support/Threading.cpp
===
--- llvm/unittests/Support/Threading.cpp
+++ llvm/unittests/Support/Threading.cpp
@@ -7,6 +7,8 @@
 //===--===//
 
 #include "llvm/Support/Threading.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/thread.h"
 #include "gtest/gtest.h"
 
@@ -17,6 +19,18 @@
 
 namespace {
 
+static bool isThreadingSupportedArchAndOS() {
+  Triple Host(Triple::normalize(sys::getProcessTriple()));
+
+  // Initially this is only testing detection of the number of
+  // physical cores, which is currently only supported/tested on
+  // some systems.
+  return (Host.isOSWindows() && llvm_is_multithreaded()) || Host.isOSDarwin() ||
+ (Host.isX86() && Host.isOSLinux()) ||
+ (Host.isOSLinux() && !Host.isAndroid()) ||
+ (Host.isSystemZ() && Host.isOSzOS());
+}
+
 TEST(Threading, PhysicalConcurrency) {
   auto Num = heavyweight_hardware_concurrency();
   // Since Num is unsigned this will also catch us trying to
@@ -25,6 +39,20 @@
 hardware_concurrency().compute_thread_count());
 }
 
+TEST(Threading, NumPhysicalCoresSupported) {
+  if (!isThreadingSupportedArchAndOS())
+GTEST_SKIP();
+  int Num = get_physical_cores();
+  ASSERT_GT(Num, 0);
+}
+
+TEST(Threading, NumPhysicalCoresUnsupported) {
+  if (isThreadingSupportedArchAndOS())
+GTEST_SKIP();
+  int Num = get_physical_cores();
+  ASSERT_EQ(Num, -1);
+}
+
 #if LLVM_ENABLE_THREADS
 
 class Notification {
@@ -91,4 +119,4 @@
 #endif
 #endif
 
-} // end anon namespace
+} // namespace
Index: llvm/unittests/Support/Host.cpp
===
--- llvm/unittests/Support/Host.cpp
+++ llvm/unittests/Support/Host.cpp
@@ -30,37 +30,6 @@
 
 using namespace llvm;
 
-class HostTest : public testing::Test {
-  Triple Host;
-
-protected:
-  bool isSupportedArchAndOS() {
-// Initially this is only testing detection of the number of
-// physical cores, which is currently only supported/tested on
-// some systems.
-return (Host.isOSWindows() && llvm_is_multithreaded()) ||
-   Host.isOSDarwin() || (Host.isX86() && Host.isOSLinux()) ||
-   (Host.isOSLinux() && !Host.isAndroid()) ||
-   (Host.isSystemZ() && Host.isOSzOS());
-  }
-
-  HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {}
-};
-
-TEST_F(HostTest, NumPhysicalCoresSupported) {
-  if (!isSupportedArchAndOS())
-GTEST_SKIP();
-  int Num = sys::getHostNumPhysicalCores();
-  ASSERT_GT(Num, 0);
-}
-
-TEST_F(HostTest, NumPhysicalCoresUnsupported) {
-  if (isSupportedArchAndOS())
-GTEST_SKIP();
-  int Num = sys::getHostNumPhysicalCores();
-  ASSERT_EQ(Num, -1);
-}
-
 TEST(getLinuxHostCPUName, ARM) {
   StringRef CortexA9ProcCpuinfo = R"(
 processor   : 0
@@ -439,13 +408,13 @@
   return Success;
 }
 
-TEST_F(HostTest, DummyRunAndGetCommandOutputUse) {
+TEST(HostTest, DummyRunAndGetCommandOutputUse) {
   // Suppress defined-but-not-used warnings when the tests using the helper are
   // disabled.
   (void)&runAndGetCommandOutput;
 }
 
-TEST_F(HostTest, getMacOSHostVersion) {
+TEST(HostTest, getMacOSHostVersion) {
   llvm::Triple HostTriple(llvm::sys::getProcessTriple());
   if (!HostTriple.isMacOSX())
 GTEST_SKIP();
@@ -491,7 +460,7 @@
   .getOSVersion();
 }
 
-TEST_F(HostTest, AIXHostVersionDetect) {
+TEST(HostTest, AIXHostVersionDetect) {
   llvm::Triple HostTriple(llvm::sys::getProcessTriple());
   if (HostTriple.getOS() != Triple::AIX)
 GTEST_SKIP();
@@ -517,7 +486,7 @@
   ASSERT_EQ(SysMinor, HostVersion.getMinor());
 }
 
-TEST_F(HostTest, AIXTargetVersionDetect) {
+TEST(HostTest, AIXTargetVersionDetect) {
   llvm::Triple TargetTriple(llvm::sys::getDefaultTargetTriple());
   if (TargetTriple.getOS() != Triple::AIX)
 GTEST_SKIP();
@@ -535,7 +504,7 @@
   ASSERT_EQ(SystemVersion.getMinor(), TargetVersion.getMinor());
 }
 
-TEST_F(HostTest, AIXHostCPUDetect) {
+TEST(HostTest, AIXHostCPUDetect) {
   llvm::Triple HostTriple(l

[PATCH] D138914: Make evaluation of nested requirement consistent with requires expr.

2022-11-29 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 created this revision.
Herald added a project: All.
usaxena95 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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

  template  concept True = true;
  
  template 
  concept C1 = requires (T) {
 requires True || True;
  };
  
  template 
  constexpr bool foo()
  requires True || True {
  return true;
  }
  static_assert(C1); // Previously failed due to SFINAE error
  static_assert(foo()); // but this works fine.

The issue here is the discrepancy between how a nested requirement is evaluated 

 Vs how a non-nested requirement is evaluated 
.

This patch makes constraint checking consistent for nested requirement
and trailing requires expressions by reusing the same evaluator.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138914

Files:
  clang/include/clang/AST/ExprConcepts.h
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/SemaTemplate/instantiate-requires-expr.cpp

Index: clang/test/SemaTemplate/instantiate-requires-expr.cpp
===
--- clang/test/SemaTemplate/instantiate-requires-expr.cpp
+++ clang/test/SemaTemplate/instantiate-requires-expr.cpp
@@ -24,8 +24,8 @@
 
 template requires
 false_v; }>
-// expected-note@-1 {{because 'false_v; }>' evaluated to false}}
-// expected-note@-2 {{because 'false_v; }>' evaluated to false}}
+// expected-note@-1 {{because 'false_v; }>' evaluated to false}}
+// expected-note@-2 {{because 'false_v; }>' evaluated to false}}
 struct r1 {};
 
 using r1i1 = r1; // expected-error {{constraints not satisfied for class template 'r1' [with T = int]}}
@@ -35,8 +35,8 @@
 
 template requires
 false_v
-// expected-note@-1 {{because 'false_v'}}
-// expected-note@-2 {{because 'false_v' evaluated to false}}
+// expected-note@-1 {{because 'false_v; }>' evaluated to false}}
+// expected-note@-2 {{because 'false_v; }>' evaluated to false}}
 struct r2 {};
 
 using r2i1 = r2; // expected-error {{constraints not satisfied for class template 'r2' [with Ts = ]}}
@@ -44,8 +44,8 @@
 
 template requires
 false_v<(requires (Ts ts) {requires sizeof(ts) != 0;} && ...)>
-// expected-note@-1 {{because 'false_v' evaluated to false}}
-// expected-note@-2 {{because 'false_v' evaluated to false}}
+// expected-note@-1 {{because 'false_v; } && requires (unsigned short ts) { requires ; }>' evaluated to false}}
+// expected-note@-2 {{because 'false_v; }>' evaluated to false}}
 struct r3 {};
 
 using r3i1 = r3; // expected-error {{constraints not satisfied for class template 'r3' [with Ts = ]}}
@@ -181,7 +181,7 @@
 
 namespace nested_requirement {
   // check that constraint expression is instantiated correctly
-  template requires false_v // expected-note{{because 'false_v' evaluated to false}}
+  template requires false_v // expected-note{{because 'false_v; }>' evaluated to false}}
   struct r1 {};
 
   using r1i = r1; // expected-error{{constraints not satisfied for class template 'r1' [with T = int]}}
@@ -190,7 +190,7 @@
   template
   struct a {
   template requires
-  (requires { requires sizeof(T::a) == 0; }, false) // expected-note{{because 'requires { requires <>; } , false' evaluated to false}}
+  (requires { requires sizeof(T::a) == 0; }, false) // expected-note{{because 'requires { requires ; } , false' evaluated to false}}
   struct r {};
   };
 
@@ -199,7 +199,7 @@
   // Parameter pack inside expr
   template requires
   false_v<(requires { requires sizeof(Ts) == 0; } && ...)>
-  // expected-note@-1 {{because 'false_v' evaluated to false}}
+  // expected-note@-1 {{because 'false_v; } && requires { requires ; }>' evaluated to false}}
   struct r2 {};
 
   using r2i = r2; // expected-error{{constraints not satisfied for class template 'r2' [with Ts = ]}}
@@ -208,14 +208,14 @@
 // Parameter pack inside multiple requirements
 template requires
 false_v<(requires { requires sizeof(Ts) == 0; sizeof(Ts); } && ...)>
-// expected-note@-1 {{because 'false_v' evaluated to false}}
+// expected-note@-1 {{because 'false_v; sizeof(Ts); } && requires { requires ; sizeof(Ts); }>' evaluated to false}}
 struct r4 {};
 
 using r4i = r4; // expected-error{{constraints not satisfied for class template 'r4' [with Ts = ]}}
 
 template requires
 false_v<(requires(Ts t) { requires sizeof(t) == 0; t++; } && ...)>
-// expected-note@-1 {{because 'false_v' evaluated to false}}
+// expected-note@-1 {{because 'false_v; t++; } && requires (short t) { requires ; t++; }>' evaluated to false}}
 struct r5 {};
 
 using r5i = r5; // expected-error{{constraints not satisfied for class template 'r5' [with Ts = ]}}
Index: cl

[PATCH] D137712: Correctly handle Substitution failure in concept specialization.

2022-11-29 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 abandoned this revision.
usaxena95 added a comment.

Second attempt along the lines of the last comment: 
https://reviews.llvm.org/D138914
PTAL.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137712

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


[clang] b0e4897 - [OpenCL] Remove arm-integer-dot-product extension pragmas

2022-11-29 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-11-29T13:26:50Z
New Revision: b0e4897a1bd2ea5eeeb8c104e32df1402a397ac1

URL: 
https://github.com/llvm/llvm-project/commit/b0e4897a1bd2ea5eeeb8c104e32df1402a397ac1
DIFF: 
https://github.com/llvm/llvm-project/commit/b0e4897a1bd2ea5eeeb8c104e32df1402a397ac1.diff

LOG: [OpenCL] Remove arm-integer-dot-product extension pragmas

This extension only adds builtin functions and thus doesn't need to be
included as an extension.  Instead of a pragma, the builtin functions
of the extension can be exposed through enabling preprocessor defines.

Added: 


Modified: 
clang/include/clang/Basic/OpenCLExtensions.def
clang/test/CodeGenOpenCL/arm-integer-dot-product.cl

Removed: 




diff  --git a/clang/include/clang/Basic/OpenCLExtensions.def 
b/clang/include/clang/Basic/OpenCLExtensions.def
index a053a0e9adb5..70b4f15a95a7 100644
--- a/clang/include/clang/Basic/OpenCLExtensions.def
+++ b/clang/include/clang/Basic/OpenCLExtensions.def
@@ -94,12 +94,6 @@ OPENCL_EXTENSION(__cl_clang_bitfields, true, 100)
 OPENCL_EXTENSION(cl_amd_media_ops, true, 100)
 OPENCL_EXTENSION(cl_amd_media_ops2, true, 100)
 
-// ARM OpenCL extensions
-OPENCL_EXTENSION(cl_arm_integer_dot_product_int8, true, 120)
-OPENCL_EXTENSION(cl_arm_integer_dot_product_accumulate_int8, true, 120)
-OPENCL_EXTENSION(cl_arm_integer_dot_product_accumulate_int16, true, 120)
-OPENCL_EXTENSION(cl_arm_integer_dot_product_accumulate_saturate_int8, true, 
120)
-
 // Intel OpenCL extensions
 OPENCL_EXTENSION(cl_intel_subgroups, true, 120)
 OPENCL_EXTENSION(cl_intel_subgroups_short, true, 120)

diff  --git a/clang/test/CodeGenOpenCL/arm-integer-dot-product.cl 
b/clang/test/CodeGenOpenCL/arm-integer-dot-product.cl
index c98615c5dd98..e3172f28afd7 100644
--- a/clang/test/CodeGenOpenCL/arm-integer-dot-product.cl
+++ b/clang/test/CodeGenOpenCL/arm-integer-dot-product.cl
@@ -1,6 +1,12 @@
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -finclude-default-header 
-fdeclare-opencl-builtins -cl-std=CL1.2 -emit-llvm -o - -O0 | FileCheck %s
 
 // Pragmas are only accepted for backward compatibility.
+// The builtins are made available with the following defines.
+
+#define cl_arm_integer_dot_product_int8 1
+#define cl_arm_integer_dot_product_accumulate_int8 1
+#define cl_arm_integer_dot_product_accumulate_int16 1
+#define cl_arm_integer_dot_product_accumulate_saturate_int8 1
 
 #pragma OPENCL EXTENSION cl_arm_integer_dot_product_int8 : enable
 #pragma OPENCL EXTENSION cl_arm_integer_dot_product_int8 : disable



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


[PATCH] D138821: [include-cleaner] Remove filtering from UsingDecl visit.

2022-11-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:86
   report(UD->getLocation(), TD,
  IsUsed ? RefType::Explicit : RefType::Ambiguous);
 }

we should report all references as explicit.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:87
-  // headers might still be used by the dependents of the header.
-  if (!IsUsed && !IsHeader)
-continue;

The member field `IsHeader` is no longer used anywhere, we can remove it, which 
will simplify a few places, @kadircet any thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138821

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


[PATCH] D138753: [AArch64TargetParser] getArchFeatures -> getArchFeature

2022-11-29 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson updated this revision to Diff 478540.
tmatheson added a comment.

Reinstate unit test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138753

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1684,14 +1684,23 @@
 }
 
 TEST(TargetParserTest, AArch64ArchFeatures) {
-  std::vector Features;
-
-  for (auto AK : AArch64::ArchKinds) {
-if (AK == AArch64::ArchKind::INVALID)
-  EXPECT_FALSE(AArch64::getArchFeatures(AK, Features));
-else
-  EXPECT_TRUE(AArch64::getArchFeatures(AK, Features));
-  }
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::INVALID), "+");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8A), "+v8a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_1A), "+v8.1a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_2A), "+v8.2a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_3A), "+v8.3a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_4A), "+v8.4a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_5A), "+v8.5a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_6A), "+v8.6a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_7A), "+v8.7a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_8A), "+v8.8a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_9A), "+v8.9a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9A), "+v9a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9_1A), "+v9.1a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9_2A), "+v9.2a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9_3A), "+v9.3a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9_4A), "+v9.4a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8R), "+v8r");
 }
 
 TEST(TargetParserTest, AArch64ArchV9toV8Conversion) {
Index: llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
===
--- llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -6764,7 +6764,7 @@
 
   // Get the architecture and extension features.
   std::vector AArch64Features;
-  AArch64::getArchFeatures(ID, AArch64Features);
+  AArch64Features.push_back(AArch64::getArchFeature(ID));
   AArch64::getExtensionFeatures(AArch64::getDefaultExtensions("generic", ID),
 AArch64Features);
 
Index: llvm/lib/Support/AArch64TargetParser.cpp
===
--- llvm/lib/Support/AArch64TargetParser.cpp
+++ llvm/lib/Support/AArch64TargetParser.cpp
@@ -81,12 +81,8 @@
   .Default(CPU);
 }
 
-bool AArch64::getArchFeatures(AArch64::ArchKind AK,
-  std::vector &Features) {
-  if (AK == ArchKind::INVALID)
-return false;
-  Features.push_back(AArch64ARCHNames[static_cast(AK)].ArchFeature);
-  return true;
+StringRef AArch64::getArchFeature(AArch64::ArchKind AK) {
+  return AArch64ARCHNames[static_cast(AK)].ArchFeature;
 }
 
 StringRef AArch64::getArchName(AArch64::ArchKind AK) {
Index: llvm/include/llvm/Support/AArch64TargetParser.h
===
--- llvm/include/llvm/Support/AArch64TargetParser.h
+++ llvm/include/llvm/Support/AArch64TargetParser.h
@@ -158,7 +158,7 @@
 
 bool getExtensionFeatures(uint64_t Extensions,
   std::vector &Features);
-bool getArchFeatures(ArchKind AK, std::vector &Features);
+StringRef getArchFeature(ArchKind AK);
 
 StringRef getArchName(ArchKind AK);
 StringRef getSubArch(ArchKind AK);
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -135,8 +135,9 @@
 Features.push_back("+neon");
   } else {
 ArchKind = llvm::AArch64::parseCPUArch(CPU);
-if (!llvm::AArch64::getArchFeatures(ArchKind, Features))
+if (ArchKind == llvm::AArch64::ArchKind::INVALID)
   return false;
+Features.push_back(llvm::AArch64::getArchFeature(ArchKind));
 
 uint64_t Extension = llvm::AArch64::getDefaultExtensions(CPU, ArchKind);
 if (!llvm::AArch64::getExtensionFeatures(Extension, Features))
@@ -160,9 +161,9 @@
   llvm::AArch64::ArchKind ArchKind = llvm::AArch64::parseArch(Split.fir

[PATCH] D138797: [include-cleaner] Implement IWYU begin_keep/end_keep pragma support.

2022-11-29 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 478545.
VitaNuo marked 6 inline comments as done.
VitaNuo added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138797

Files:
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -308,38 +308,76 @@
 for (llvm::StringRef File : FileNames)
   Inputs.ExtraFiles[File] = "";
   }
+
+  size_t offsetToLineNum(llvm::Annotations MainFile, size_t Offset) {
+int Count = MainFile.code().substr(0, Offset).count('\n');
+return Count + 1;
+  }
 };
 
 TEST_F(PragmaIncludeTest, IWYUKeep) {
-  Inputs.Code = R"cpp(// Line 1
-#include "keep1.h" // IWYU pragma: keep
-#include "keep2.h" /* IWYU pragma: keep */
+  llvm::Annotations MainFile(R"cpp(
+$keep1^#include "keep1.h" // IWYU pragma: keep
+$keep2^#include "keep2.h" /* IWYU pragma: keep */
+
+$export1^#include "export1.h" // IWYU pragma: export
+$begin_exports^// IWYU pragma: begin_exports
+$export2^#include "export2.h"
+$export3^#include "export3.h"
+$end_exports^// IWYU pragma: end_exports
+
+$normal^#include "normal.h"
+
+$begin_keep^// IWYU pragma: begin_keep 
+$keep3^#include "keep3.h"
+$end_keep^// IWYU pragma: end_keep
+
+// IWYU pragma: begin_keep 
+$keep4^#include "keep4.h"
+// IWYU pragma: begin_keep
+$keep5^#include "keep5.h"
+// IWYU pragma: end_keep
+$keep6^#include "keep6.h"
+// IWYU pragma: end_keep
+  )cpp");
 
-#include "export1.h" // IWYU pragma: export // line 5
-// IWYU pragma: begin_exports
-#include "export2.h" // Line 7
-#include "export3.h"
-// IWYU pragma: end_exports
+  auto OffsetToLineNum = [&MainFile](size_t Offset) {
+int Count = MainFile.code().substr(0, Offset).count('\n');
+return Count + 1;
+  };
 
-#include "normal.h" // Line 11
-  )cpp";
-  createEmptyFiles({"keep1.h", "keep2.h", "export1.h", "export2.h", "export3.h",
+  Inputs.Code = MainFile.code();
+  createEmptyFiles({"keep1.h", "keep2.h", "keep3.h", "keep4.h", "keep5.h",
+"keep6.h", "export1.h", "export2.h", "export3.h",
 "normal.h"});
 
   TestAST Processed = build();
   EXPECT_FALSE(PI.shouldKeep(1));
+
   // Keep
-  EXPECT_TRUE(PI.shouldKeep(2));
-  EXPECT_TRUE(PI.shouldKeep(3));
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep1";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep2";
 
-  // Exports
-  EXPECT_TRUE(PI.shouldKeep(5));
-  EXPECT_TRUE(PI.shouldKeep(7));
-  EXPECT_TRUE(PI.shouldKeep(8));
-  EXPECT_FALSE(PI.shouldKeep(6)); // no # directive
-  EXPECT_FALSE(PI.shouldKeep(9)); // no # directive
+  EXPECT_FALSE(PI.shouldKeep(
+  OffsetToLineNum(MainFile.point("begin_keep"; // no # directive
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep3";
+  EXPECT_FALSE(PI.shouldKeep(
+  OffsetToLineNum(MainFile.point("end_keep"; // no # directive
+
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep4";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep5";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep6";
 
-  EXPECT_FALSE(PI.shouldKeep(11));
+  // Exports
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("export1";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("export2";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("export3";
+  EXPECT_FALSE(PI.shouldKeep(
+  OffsetToLineNum(MainFile.point("begin_exports"; // no # directive
+  EXPECT_FALSE(PI.shouldKeep(
+  OffsetToLineNum(MainFile.point("end_exports"; // no # directive
+
+  EXPECT_FALSE(PI.shouldKeep(OffsetToLineNum(MainFile.point("normal";
 }
 
 TEST_F(PragmaIncludeTest, IWYUPrivate) {
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -186,9 +186,7 @@
 FileID HashFID = SM.getFileID(HashLoc);
 int HashLine = SM.getLineNumber(HashFID, SM.getFileOffset(HashLoc));
 checkForExport(HashFID, HashLine, File ? &File->getFileEntry() : nullptr);
-
-if (InMainFile && LastPragmaKeepInMainFileLine == HashLine)
-  Out->ShouldKeep.insert(HashLine);
+checkForKeep(HashLine);
   }
 
   void checkForExport(FileID IncludingFile, int HashLine,
@@ -212,6 +210,18 @@
   ExportStack.pop_back();
   }
 
+  void checkForKeep(int HashLine) {
+if (!InMainFile || KeepStack.empty())
+  return;
+KeepPra

[PATCH] D138797: [include-cleaner] Implement IWYU begin_keep/end_keep pragma support.

2022-11-29 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added inline comments.



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:312
+
+  size_t offsetToLineNum(llvm::Annotations MainFile, size_t Offset) {
+int Count = MainFile.code().substr(0, Offset).count('\n');

hokein wrote:
> this is only used in `IWYUKeep` test, I'd make it as a local lambda (with 
> MainFile captured) in the test:
> 
> ```
> auto OffsetToLineNum = [&MainFile](size_t Offset) { ... };
> ``` 
Nice idea, thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138797

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


[PATCH] D136811: [-Wunsafe-buffer-usage] WIP: RFC: NFC: User documentation.

2022-11-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/docs/SafeBuffers.rst:92
+
+However, no automatic code modernizer for plain C is not provided,
+and the hardened C++ standard library cannot benefit C code, which limits





Comment at: clang/docs/SafeBuffers.rst:40-41
+  - Finally, in order to avoid bugs in newly converted code, the
+Clang static analyzer provides a checker to find misconstructed
+``std::span`` objects.
+

NoQ wrote:
> aaron.ballman wrote:
> > xazax.hun wrote:
> > > jkorous wrote:
> > > > NoQ wrote:
> > > > > xazax.hun wrote:
> > > > > > Isn't this overly specific? What about `string_view`s? 
> > > > > Yeah I think we can cover string views as well!
> > > > This is based on our current plans for near future.
> > > > While we are positive we will use `std::span` in the FixIts it is very 
> > > > unlikely we'd use `string_view`. That's why having a checker for 
> > > > `std::span` is more important for us now.
> > > Does this mean you'd recommend using a `span` over `string_view` in 
> > > all cases? I think that might surprise some users, so I wonder if it is 
> > > worth documenting. 
> > Oh, I was sort of assuming we'd be suggesting `string_view` over 
> > `span` when appropriate. So agreed that we should clearly document 
> > this as it may surprise folks.
> > 
> > Out of curiosity, why the strong preference for `span`?
> `string_view` is a bit harder to recommend automatically because whether a 
> certain sequence of bytes constitutes a "string" is often a matter of opinion 
> / user's point of view. `string_view`'s methods such as `find` will not 
> necessarily make sense over original data, or may turn out to have 
> counter-intuitive behavior when users try to modify the code further.
> 
> Additionally, `string_view` doesn't offer write access, so at best we'll be 
> able to recommend it for `const` pointers.
> 
> So I think we should gather more data before considering it.
> string_view is a bit harder to recommend automatically because whether a 
> certain sequence of bytes constitutes a "string" is often a matter of opinion 
> / user's point of view.

But why does that matter for `string_view`? It's not a null-terminated 
interface, so it explicitly encodes a pointer/length interface, same as `span`.



Comment at: clang/docs/SafeBuffers.rst:128
+  ``+``, ``-``, ``+=``, ``-=``,
+  - unless that number is a compile time constant ``0``;
+  - subtraction between two pointers is also fine;

NoQ wrote:
> jkorous wrote:
> > aaron.ballman wrote:
> > > One case I think this is going to trip up is: `this + 1` (which is not 
> > > uncommon in practice: 
> > > https://sourcegraph.com/search?q=context:global+-file:.*test.*+file:.*%5C.cpp+this+%2B+1&patternType=standard).
> > >  How do users fix up that pointer arithmetic and do they ever get any 
> > > safety or security benefits from it? (Note, this doesn't apply to `+=`, 
> > > just `+`.)
> > That's a fair point and if we don't find a good solution we should ignore 
> > arithmetic with `this` and a constant.
> I'll leave this unaddressed for now. It looks like these constructs typically 
> *do* indicate that the remaining part of the object is a buffer. C++ doesn't 
> seem to provide a good "safe" way to represent such objects. So, yeah, we 
> need more data.
Fair enough -- it's worth documenting explicitly as an open question. FWIW, I 
agree that the construct is mostly used for accessing trailing objects as a 
buffer. The closest thing I've seen to a safe way to handle this is how LLVM 
does it with the `TrailingObjects` mixin.



Comment at: clang/docs/SafeBuffers.rst:132
+attribute ``[[unsafe_buffer_usage]]``,
+  - unless the pointer is a compile time constant ``0`` or ``nullptr``;
+  - a number of C/C++ standard library buffer manipulation functions

NoQ wrote:
> aaron.ballman wrote:
> > NoQ wrote:
> > > aaron.ballman wrote:
> > > > `NULL` as well, I presume? (This matters for C where `NULL` often 
> > > > expands to `(void *)0`.)
> > > Hmm, I was thinking that `((void *)0)` is a compile-time constant `0`. 
> > > Like, I didn't say it's a *literal*. Is there a better term?
> > Are you okay with constant expressions? e.g.,
> > ```
> > consteval int foo() { return 0; }
> > 
> > void func(char *ptr) {
> >   char *offset_ptr = ptr + foo(); // Is this fine?
> > }
> > ```
> Yes sure, why not? If it ever becomes unsafe, we'll immediately warn.
Ah, C terminology is biting me here -- we use the term "constant" the same way 
C++ uses the term "literal", so when I read "constant 0" my brain interpreted 
that as literally just `0`.



Comment at: clang/docs/SafeBuffers.rst:213
+
+The attribute is NOT warranted when the function has runtime protection against
+overflows, assuming hardened libc++, assuming that containers constructed

NoQ wrote:
> aaron.bal

[PATCH] D138895: [clang] Update CWG2635 status

2022-11-29 Thread Erich Keane 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 rGde36be740455: [clang] Update CWG2635 status (authored by 
Endill, committed by erichkeane).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138895

Files:
  clang/test/CXX/drs/dr26xx.cpp


Index: clang/test/CXX/drs/dr26xx.cpp
===
--- clang/test/CXX/drs/dr26xx.cpp
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -29,7 +29,7 @@
 
 }
 
-namespace dr2635 { // dr2635: yes
+namespace dr2635 { // dr2635: 16
 template
 concept UnaryC = true;
 template


Index: clang/test/CXX/drs/dr26xx.cpp
===
--- clang/test/CXX/drs/dr26xx.cpp
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -29,7 +29,7 @@
 
 }
 
-namespace dr2635 { // dr2635: yes
+namespace dr2635 { // dr2635: 16
 template
 concept UnaryC = true;
 template
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138895: [clang] Update CWG2635 status

2022-11-29 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

woops, thanks!   Committed


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

https://reviews.llvm.org/D138895

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


[clang] de36be7 - [clang] Update CWG2635 status

2022-11-29 Thread Erich Keane via cfe-commits

Author: Vlad Serebrennikov
Date: 2022-11-29T05:54:34-08:00
New Revision: de36be74045533f6db0077c3f6cebaf258b63aaa

URL: 
https://github.com/llvm/llvm-project/commit/de36be74045533f6db0077c3f6cebaf258b63aaa
DIFF: 
https://github.com/llvm/llvm-project/commit/de36be74045533f6db0077c3f6cebaf258b63aaa.diff

LOG: [clang] Update CWG2635 status

A follow-up to D138852. Apparently cxx_dr_status.html was changed
manually there, since make_cxx_dr_status script doesn't generate the
same HTML after that patch landed.

Differential Revision: https://reviews.llvm.org/D138895

Added: 


Modified: 
clang/test/CXX/drs/dr26xx.cpp

Removed: 




diff  --git a/clang/test/CXX/drs/dr26xx.cpp b/clang/test/CXX/drs/dr26xx.cpp
index 7e8866045a7cd..3ec1aa279dfc9 100644
--- a/clang/test/CXX/drs/dr26xx.cpp
+++ b/clang/test/CXX/drs/dr26xx.cpp
@@ -29,7 +29,7 @@ void f() {
 
 }
 
-namespace dr2635 { // dr2635: yes
+namespace dr2635 { // dr2635: 16
 template
 concept UnaryC = true;
 template



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


[PATCH] D138117: [clang][docs] Correct floating point option explanations

2022-11-29 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added inline comments.



Comment at: clang/docs/UsersManual.rst:1435
* ``-fno-honor-nans``
-
+   * ``-fapprox-func``
* ``-fno-math-errno``

Leave a blank line before and after the bullet. Same below.



Comment at: clang/docs/UsersManual.rst:1612
* ``-freciprocal-math``
* ``-fno-signed-zeroes``
+   * ``-fno-trapping-math``

-fno-signed-zeros. Same below.



Comment at: clang/docs/UsersManual.rst:1628
+   ``-funsafe-math-optimizations``, and ``-fno-unsafe-math-optimizations``
+   behave in combination. Explanation in :option:`-fno-fast-math` also applies
+   to these options.

behave when combined.



Comment at: clang/docs/UsersManual.rst:1638
+   ``__FINITE_MATH_ONLY__`` preprocessor macro.
+   ``-ffinite-math-only`` also implies:
 

 ``-ffinite-math-only`` implies:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138117

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


[clang-tools-extra] 454a34d - [include-cleaner] Fix -Woverloaded-virtual warning, NFC.

2022-11-29 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-11-29T15:09:56+01:00
New Revision: 454a34d2c04f68f3d7b907d78f3071710b93cf34

URL: 
https://github.com/llvm/llvm-project/commit/454a34d2c04f68f3d7b907d78f3071710b93cf34
DIFF: 
https://github.com/llvm/llvm-project/commit/454a34d2c04f68f3d7b907d78f3071710b93cf34.diff

LOG: [include-cleaner] Fix -Woverloaded-virtual warning, NFC.

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/Record.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/Record.cpp 
b/clang-tools-extra/include-cleaner/lib/Record.cpp
index a0aa1ad6845d2..ac3315abb882c 100644
--- a/clang-tools-extra/include-cleaner/lib/Record.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -99,6 +99,8 @@ class PPRecorder : public PPCallbacks {
   recordMacroRef(MacroNameTok, *MI, RefType::Ambiguous);
   }
 
+  using PPCallbacks::Elifdef;
+  using PPCallbacks::Elifndef;
   void Elifdef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDefinition &MD) override {
 if (!Active)
@@ -106,7 +108,6 @@ class PPRecorder : public PPCallbacks {
 if (const auto *MI = MD.getMacroInfo())
   recordMacroRef(MacroNameTok, *MI, RefType::Ambiguous);
   }
-
   void Elifndef(SourceLocation Loc, const Token &MacroNameTok,
 const MacroDefinition &MD) override {
 if (!Active)



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


[PATCH] D138797: [include-cleaner] Implement IWYU begin_keep/end_keep pragma support.

2022-11-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks, looks good.




Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:312
+
+  size_t offsetToLineNum(llvm::Annotations MainFile, size_t Offset) {
+int Count = MainFile.code().substr(0, Offset).count('\n');

this method can be removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138797

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


[PATCH] D138821: [include-cleaner] Remove filtering from UsingDecl visit.

2022-11-29 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 478556.
VitaNuo added a comment.

Address review comments: turn all references into explicit, remove the 
"isHeader" field.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138821

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -88,12 +88,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -129,19 +127,39 @@
 }
 
 TEST(WalkAST, Using) {
-  // Make sure we ignore unused overloads.
+  // We should report unused overloads as ambiguous.
   testWalk(R"cpp(
 namespace ns {
-  void $explicit^x(); void x(int); void x(char);
+  void $explicit^x(); void $explicit^x(int); void $explicit^x(char);
 })cpp",
"using ns::^x; void foo() { x(); }");
-  // We should report unused overloads if main file is a header.
   testWalk(R"cpp(
 namespace ns {
-  void $ambiguous^x(); void $ambiguous^x(int); void $ambiguous^x(char);
+  void $explicit^x(); void $explicit^x(int); void $explicit^x(char);
 })cpp",
"// c++-header\n using ns::^x;");
+  testWalk(R"cpp(
+namespace ns {
+  void $explicit^x(); void $explicit^x(int); void $explicit^x(char);
+})cpp",
+   "using ns::^x;");
   testWalk("namespace ns { struct S; } using ns::$explicit^S;", "^S *s;");
+
+  // We should report references to templates as ambiguous.
+  testWalk(R"cpp(
+namespace ns {
+  template
+  class $explicit^Y {};
+}
+)cpp",
+   "using ns::^Y; Y x;");
+  testWalk(R"cpp(
+namespace ns {
+  template
+  class $explicit^Y {};
+}
+)cpp",
+   "using ns::^Y;");
 }
 
 TEST(WalkAST, Namespaces) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -16,7 +16,6 @@
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 
@@ -27,10 +26,6 @@
 
 class ASTWalker : public RecursiveASTVisitor {
   DeclCallback Callback;
-  // Whether we're traversing declarations coming from a header file.
-  // This helps figure out whether certain symbols can be assumed as unused
-  // (e.g. overloads brought into an implementation file, but not used).
-  bool IsHeader = false;
 
   bool handleTemplateName(SourceLocation Loc, TemplateName TN) {
 // For using-templates, only mark the alias.
@@ -50,8 +45,7 @@
   }
 
 public:
-  ASTWalker(DeclCallback Callback, bool IsHeader)
-  : Callback(Callback), IsHeader(IsHeader) {}
+  ASTWalker(DeclCallback Callback) : Callback(Callback) {}
 
   bool VisitDeclRefExpr(DeclRefExpr *DRE) {
 report(DRE->getLocation(), DRE->getFoundDecl());
@@ -81,13 +75,7 @@
   bool VisitUsingDecl(UsingDecl *UD) {
 for (const auto *Shadow : UD->shadows()) {
   auto *TD = Shadow->getTargetDecl();
-  auto IsUsed = TD->isUsed() || TD->isReferenced();
-  // We ignore unused overloads inside implementation files, as the ones in
-  // headers might still be used by the dependents of the header.
-  if (!IsUsed && !IsHeader)
-continue;
-  report(UD->getLocation(), TD,
- IsUsed ? RefType::Explicit : RefType::Ambiguous);
+  report(UD->getLocation(), TD, RefType::Explicit);
 }
 return true;
   }
@@ -151,14 +139,7 @@
 } // namespace
 
 void walkAST(Decl &Root, DeclCallback Callback) {
-  auto &AST = Root.getASTContext();
-  auto &SM = AST.getSourceManager();
-  // If decl isn't written in main file, assume it's coming from an include,
-  // hence written in a header.
-  bool IsRootedAtHeader =
-  AST.getLangOpts().IsHeaderFile ||
-  !SM.isWrittenInMainFile(SM.getSpellingLoc(Root.getLocation()));
-  ASTWalker(Callback, IsRootedAtHeader).Tr

[PATCH] D138901: [clang] Propely handle tests for open DRs in make_cxx_dr_status

2022-11-29 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I like the change, thank you!  I don't see anything to be concerned about, but 
my python is awful, so I'd like at least a 2nd set of eyes to take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138901

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


[PATCH] D138821: [include-cleaner] Remove filtering from UsingDecl visit.

2022-11-29 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo marked an inline comment as done.
VitaNuo added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:87
-  // headers might still be used by the dependents of the header.
-  if (!IsUsed && !IsHeader)
-continue;

hokein wrote:
> The member field `IsHeader` is no longer used anywhere, we can remove it, 
> which will simplify a few places, @kadircet any thoughts?
Ok, removed. Let me know if I should undo that eventually.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138821

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


[PATCH] D138914: Make evaluation of nested requirement consistent with requires expr.

2022-11-29 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/include/clang/AST/ExprConcepts.h:428
+  : Requirement(RK_Nested,
+Constraint && Constraint->isInstantiationDependent(),
+Constraint && 
Constraint->containsUnexpandedParameterPack(),

I'm a little concerned that we're changing to a situation where the constraint 
in a nested-requirement can be null like this.  The other cases it can be null 
we consider it a 'substitution failure' (see the 1st constructor).

It seems to me that we perhaps need a different state here for that.



Comment at: clang/test/SemaTemplate/instantiate-requires-expr.cpp:27
 false_v; }>
-// expected-note@-1 {{because 'false_v; }>' evaluated to false}}
-// expected-note@-2 {{because 'false_v; }>' evaluated to false}}
+// expected-note@-1 {{because 'false_v; }>' evaluated to false}}
+// expected-note@-2 {{because 'false_v; }>' evaluated to false}}

This is wrong here, we shouldn't be making our diagnostics incorrect like this. 
 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138914

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


[PATCH] D138901: [clang] Propely handle tests for open DRs in make_cxx_dr_status

2022-11-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision as: aaron.ballman.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM though my Python skills are lacking, so additional eyeballs on that would 
be appreciated.




Comment at: clang/www/make_cxx_dr_status:187-189
+  assert unresolved_status == dr.status, \
+ "Issue %s is marked '%s', which differs from CWG index status 
'%s'" \
+ % (dr.issue, unresolved_status, dr.status)

Thank you for this! It resolves the biggest concern I had with our markings 
getting out of sync with the issues list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138901

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


[PATCH] D138797: [include-cleaner] Implement IWYU begin_keep/end_keep pragma support.

2022-11-29 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 478561.
VitaNuo added a comment.

Remove excessive method.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138797

Files:
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -311,35 +311,68 @@
 };
 
 TEST_F(PragmaIncludeTest, IWYUKeep) {
-  Inputs.Code = R"cpp(// Line 1
-#include "keep1.h" // IWYU pragma: keep
-#include "keep2.h" /* IWYU pragma: keep */
+  llvm::Annotations MainFile(R"cpp(
+$keep1^#include "keep1.h" // IWYU pragma: keep
+$keep2^#include "keep2.h" /* IWYU pragma: keep */
+
+$export1^#include "export1.h" // IWYU pragma: export
+$begin_exports^// IWYU pragma: begin_exports
+$export2^#include "export2.h"
+$export3^#include "export3.h"
+$end_exports^// IWYU pragma: end_exports
+
+$normal^#include "normal.h"
+
+$begin_keep^// IWYU pragma: begin_keep 
+$keep3^#include "keep3.h"
+$end_keep^// IWYU pragma: end_keep
+
+// IWYU pragma: begin_keep 
+$keep4^#include "keep4.h"
+// IWYU pragma: begin_keep
+$keep5^#include "keep5.h"
+// IWYU pragma: end_keep
+$keep6^#include "keep6.h"
+// IWYU pragma: end_keep
+  )cpp");
 
-#include "export1.h" // IWYU pragma: export // line 5
-// IWYU pragma: begin_exports
-#include "export2.h" // Line 7
-#include "export3.h"
-// IWYU pragma: end_exports
+  auto OffsetToLineNum = [&MainFile](size_t Offset) {
+int Count = MainFile.code().substr(0, Offset).count('\n');
+return Count + 1;
+  };
 
-#include "normal.h" // Line 11
-  )cpp";
-  createEmptyFiles({"keep1.h", "keep2.h", "export1.h", "export2.h", "export3.h",
+  Inputs.Code = MainFile.code();
+  createEmptyFiles({"keep1.h", "keep2.h", "keep3.h", "keep4.h", "keep5.h",
+"keep6.h", "export1.h", "export2.h", "export3.h",
 "normal.h"});
 
   TestAST Processed = build();
   EXPECT_FALSE(PI.shouldKeep(1));
+
   // Keep
-  EXPECT_TRUE(PI.shouldKeep(2));
-  EXPECT_TRUE(PI.shouldKeep(3));
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep1";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep2";
 
-  // Exports
-  EXPECT_TRUE(PI.shouldKeep(5));
-  EXPECT_TRUE(PI.shouldKeep(7));
-  EXPECT_TRUE(PI.shouldKeep(8));
-  EXPECT_FALSE(PI.shouldKeep(6)); // no # directive
-  EXPECT_FALSE(PI.shouldKeep(9)); // no # directive
+  EXPECT_FALSE(PI.shouldKeep(
+  OffsetToLineNum(MainFile.point("begin_keep"; // no # directive
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep3";
+  EXPECT_FALSE(PI.shouldKeep(
+  OffsetToLineNum(MainFile.point("end_keep"; // no # directive
+
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep4";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep5";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep6";
 
-  EXPECT_FALSE(PI.shouldKeep(11));
+  // Exports
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("export1";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("export2";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("export3";
+  EXPECT_FALSE(PI.shouldKeep(
+  OffsetToLineNum(MainFile.point("begin_exports"; // no # directive
+  EXPECT_FALSE(PI.shouldKeep(
+  OffsetToLineNum(MainFile.point("end_exports"; // no # directive
+
+  EXPECT_FALSE(PI.shouldKeep(OffsetToLineNum(MainFile.point("normal";
 }
 
 TEST_F(PragmaIncludeTest, IWYUPrivate) {
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -186,9 +186,7 @@
 FileID HashFID = SM.getFileID(HashLoc);
 int HashLine = SM.getLineNumber(HashFID, SM.getFileOffset(HashLoc));
 checkForExport(HashFID, HashLine, File ? &File->getFileEntry() : nullptr);
-
-if (InMainFile && LastPragmaKeepInMainFileLine == HashLine)
-  Out->ShouldKeep.insert(HashLine);
+checkForKeep(HashLine);
   }
 
   void checkForExport(FileID IncludingFile, int HashLine,
@@ -212,6 +210,18 @@
   ExportStack.pop_back();
   }
 
+  void checkForKeep(int HashLine) {
+if (!InMainFile || KeepStack.empty())
+  return;
+KeepPragma &Top = KeepStack.back();
+// Check if the current include is covered by a keep pragma.
+if ((Top.Block && HashLine > Top.SeenAtLine) || Top.SeenAtLine == HashLine)
+  Out->ShouldKeep.insert(HashLine);
+
+if (!Top.Block)
+  KeepStack.pop_back(); // Pop immediately for s

[PATCH] D138797: [include-cleaner] Implement IWYU begin_keep/end_keep pragma support.

2022-11-29 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo marked an inline comment as done.
VitaNuo added inline comments.



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:312
+
+  size_t offsetToLineNum(llvm::Annotations MainFile, size_t Offset) {
+int Count = MainFile.code().substr(0, Offset).count('\n');

hokein wrote:
> this method can be removed.
Oops, sorry.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138797

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


[PATCH] D138901: [clang] Propely handle tests for open DRs in make_cxx_dr_status

2022-11-29 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

Can I kindly ask you to commit this?
I guess I can ask for commit access after this patch, and not bother you any 
further.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138901

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


[PATCH] D138918: [Clang] Implement CWG2654: Un-deprecation of compound volatile assignments

2022-11-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138918

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/SemaCXX/deprecated.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15732,7 +15732,7 @@
 https://wg21.link/cwg2654";>2654
 DR
 Un-deprecation of compound volatile assignments
-Unknown
+Clang 16
   
 
 
Index: clang/test/SemaCXX/deprecated.cpp
===
--- clang/test/SemaCXX/deprecated.cpp
+++ clang/test/SemaCXX/deprecated.cpp
@@ -186,10 +186,10 @@
 --n; // cxx20-warning {{decrement of object of volatile-qualified type 'volatile int' is deprecated}}
 n++; // cxx20-warning {{increment of object of volatile-qualified type 'volatile int' is deprecated}}
 n--; // cxx20-warning {{decrement of object of volatile-qualified type 'volatile int' is deprecated}}
-n += 5; // cxx20-warning {{compound assignment to object of volatile-qualified type 'volatile int' is deprecated}}
-n *= 3; // cxx20-warning {{compound assignment to object of volatile-qualified type 'volatile int' is deprecated}}
-n /= 2; // cxx20-warning {{compound assignment to object of volatile-qualified type 'volatile int' is deprecated}}
-n %= 42; // cxx20-warning {{compound assignment to object of volatile-qualified type 'volatile int' is deprecated}}
+n += 5; // undeprecated as a DR in C++23
+n *= 3; // undeprecated as a DR in C++23
+n /= 2; // undeprecated as a DR in C++23
+n %= 42; // undeprecated as a DR in C++23
 n &= 2; // undeprecated as a DR in C++23
 n |= 2; // undeprecated as a DR in C++23
 n ^= 2; // undeprecated as a DR in C++23
Index: clang/test/CXX/drs/dr26xx.cpp
===
--- clang/test/CXX/drs/dr26xx.cpp
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -50,3 +50,13 @@
 };
 int i0 = f(0);   //expected-error {{no matching function for call to 'f'}}
 }
+
+namespace dr2654 { // dr2654: 16
+void f() {
+int neck, tail;
+volatile int brachiosaur;
+brachiosaur += neck;// OK
+brachiosaur -= neck;// OK
+brachiosaur |= neck;// OK
+}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -13982,19 +13982,6 @@
   //   type is deprecated unless the assignment is either a discarded-value
   //   expression or an unevaluated operand
   ExprEvalContexts.back().VolatileAssignmentLHSs.push_back(LHSExpr);
-} else {
-  // C++20 [expr.ass]p6:
-  //   [Compound-assignment] expressions are deprecated if E1 has
-  //   volatile-qualified type and op is not one of the bitwise
-  //   operators |, &, ˆ.
-  switch (Opc) {
-  case BO_OrAssign:
-  case BO_AndAssign:
-  case BO_XorAssign:
-break;
-  default:
-Diag(Loc, diag::warn_deprecated_compound_assign_volatile) << LHSType;
-  }
 }
   }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7625,9 +7625,6 @@
 def warn_deprecated_simple_assign_volatile : Warning<
   "use of result of assignment to object of volatile-qualified type %0 "
   "is deprecated">, InGroup;
-def warn_deprecated_compound_assign_volatile : Warning<
-  "compound assignment to object of volatile-qualified type %0 is deprecated">,
-  InGroup;
 def warn_deprecated_volatile_return : Warning<
   "volatile-qualified return type %0 is deprecated">,
   InGroup;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -605,6 +605,8 @@
   conforming GNU extensions. Projects incompatible with C++17 can add
   ``-std=gnu++14`` to their build settings to restore the previous behaviour.
 - Implemented DR2358 allowing init captures in lambdas in default arguments.
+- implemented `DR2654 `_ which undeprecates
+  all compound assignements operations on volatile qualified variables.
 
 C++20 Feature Support
 ^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136078: Use-after-return sanitizer binary metadata

2022-11-29 Thread Dmitry Vyukov via Phabricator via cfe-commits
dvyukov updated this revision to Diff 478569.
dvyukov marked 4 inline comments as done.
dvyukov added a comment.

addressed comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136078

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
  llvm/include/llvm/CodeGen/MachinePassRegistry.def
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Transforms/Instrumentation.h
  llvm/include/llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/CodeGen.cpp
  llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
  llvm/test/Instrumentation/SanitizerBinaryMetadata/common.h
  llvm/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp
  llvm/test/Instrumentation/SanitizerBinaryMetadata/lit.local.cfg
  llvm/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp

Index: llvm/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp
===
--- /dev/null
+++ llvm/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp
@@ -0,0 +1,61 @@
+// We run the compiled binary + sizes of stack arguments depend on the arch.
+// REQUIRES: native && target-x86_64
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered,uar && %t | tee /dev/stderr | FileCheck %s
+
+// CHECK: metadata add version 1
+
+// CHECK: empty: features=0 stack_args=0
+void empty() {
+}
+
+// CHECK: ellipsis: features=0 stack_args=0
+void ellipsis(const char* fmt, ...) {
+  volatile int x;
+  x = 1;
+}
+
+// CHECK: non_empty_function: features=2 stack_args=0
+void non_empty_function() {
+  // Completely empty functions don't get uar metadata.
+  volatile int x;
+  x = 1;
+}
+
+// CHECK: no_stack_args: features=2 stack_args=0
+void no_stack_args(long a0, long a1, long a2, long a3, long a4, long a5) {
+  volatile int x;
+  x = 1;
+}
+
+// CHECK: stack_args: features=2 stack_args=16
+void stack_args(long a0, long a1, long a2, long a3, long a4, long a5, long a6) {
+  volatile int x;
+  x = 1;
+}
+
+// CHECK: more_stack_args: features=2 stack_args=32
+void more_stack_args(long a0, long a1, long a2, long a3, long a4, long a5, long a6, long a7, long a8) {
+  volatile int x;
+  x = 1;
+}
+
+// CHECK: struct_stack_args: features=2 stack_args=144
+struct large { char x[131]; };
+void struct_stack_args(large a) {
+  volatile int x;
+  x = 1;
+}
+
+// CHECK: metadata del version 1
+
+#define FUNCTIONS \
+  FN(empty); \
+  FN(ellipsis); \
+  FN(non_empty_function); \
+  FN(no_stack_args); \
+  FN(stack_args); \
+  FN(more_stack_args); \
+  FN(struct_stack_args); \
+/**/
+
+#include "common.h"
Index: llvm/test/Instrumentation/SanitizerBinaryMetadata/lit.local.cfg
===
--- /dev/null
+++ llvm/test/Instrumentation/SanitizerBinaryMetadata/lit.local.cfg
@@ -0,0 +1 @@
+config.suffixes = ['.ll', '.cpp']
Index: llvm/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp
===
--- /dev/null
+++ llvm/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp
@@ -0,0 +1,79 @@
+// REQUIRES: native && target-x86_64
+// RUN: clang++ %s -o %t && %t | FileCheck %s
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered && %t | FileCheck -check-prefix=CHECK-C %s
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=atomics && %t | FileCheck -check-prefix=CHECK-A %s
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=uar && %t | FileCheck -check-prefix=CHECK-U %s
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered,atomics && %t | FileCheck -check-prefix=CHECK-CA %s
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered,uar && %t | FileCheck -check-prefix=CHECK-CU %s
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=atomics,uar && %t | FileCheck -check-prefix=CHECK-AU %s
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered,atomics,uar && %t | FileCheck -check-prefix=CHECK-CAU %s
+
+// CHECK-NOT: metadata add
+// CHECK: main
+// CHECK-NOT: metadata del
+
+// CHECK-C:  empty: features=0
+// CHECK-A-NOT:  empty:
+// CHECK-U-NOT:  empty:
+// CHECK-CA: empty: features=1
+// CHECK-CU: empty: features=0
+// CHECK-AU-NOT: empty:
+// CHECK-CAU:empty: features=1
+void empty() {
+}
+
+// CHECK-C:  normal: features=0
+// CHECK-A:  normal: features=1
+// CHECK-U:  normal: features=2
+// CHECK-CA: normal: features=1
+// CHECK-CU: normal: features=2
+// CHECK-AU: normal: features=3
+// CHECK-CAU:normal: features=3
+void normal() {
+  volatile int x;
+  x

[PATCH] D138901: [clang] Propely handle tests for open DRs in make_cxx_dr_status

2022-11-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

I don't see anything wrong with the python either. There are probably clever 
ways to deal with the successions of if statements but i don't think it would 
be worth it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138901

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


[PATCH] D138901: [clang] Propely handle tests for open DRs in make_cxx_dr_status

2022-11-29 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Thanks @cor3ntin , I'll commit this then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138901

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


[PATCH] D136078: Use-after-return sanitizer binary metadata

2022-11-29 Thread Dmitry Vyukov via Phabricator via cfe-commits
dvyukov marked an inline comment as done.
dvyukov added a comment.

PTAL




Comment at: llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp:254
+  if (F.isVarArg())
+PerInstrFeatureMask &= ~kSanitizerBinaryMetadataUAR;
+  if (PerInstrFeatureMask & kSanitizerBinaryMetadataUAR)

melver wrote:
> What if Options.Covered==true?
> 
> Will it still emit some UAR metadata or will it emit something it shouldn't?
> 
> 
> Should the F.isVarArg() check be done above in `if (PerInstrFeatureMask || 
> (Options.UAR && !F.isVarArg())` ? Then you wouldn't need the 
> `PerInstrFeatureMask && RequiresCovered` change below and it could still just 
> check `RequiresCovered` as before.
> What if Options.Covered==true?
> Will it still emit some UAR metadata or will it emit something it shouldn't?

If Options.Covered==true && F.isVarArg(),  we emit covered metadata with 
features=0. This looks WAI.

> Should the F.isVarArg() check be done above in if (PerInstrFeatureMask || 
> (Options.UAR && !F.isVarArg()) ? Then you wouldn't need the 
> PerInstrFeatureMask && RequiresCovered change below and it could still just 
> check RequiresCovered as before.

It's tricky.
I forgot why I structured the code this way, but I added a new test for all 
permutations of covered/atomics/uar and it shows the following breakage with 
your proposed change:

```
  - CHECK-AU: ellipsis: features=1 stack_args=0
  + CHECK-AU: ellipsis: features=3 stack_args=0
```



Comment at: llvm/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp:1
+// REQUIRES: native && target-x86_64
+// RUN: clang++ %s -o %t && %t | FileCheck %s

This is the new test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136078

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


[clang] 3d280b0 - [clang] Propely handle tests for open DRs in make_cxx_dr_status

2022-11-29 Thread Erich Keane via cfe-commits

Author: Vlad Serebrennikov
Date: 2022-11-29T06:47:50-08:00
New Revision: 3d280b03753073960de9225f87780f5d6a4a2cb7

URL: 
https://github.com/llvm/llvm-project/commit/3d280b03753073960de9225f87780f5d6a4a2cb7
DIFF: 
https://github.com/llvm/llvm-project/commit/3d280b03753073960de9225f87780f5d6a4a2cb7.diff

LOG: [clang] Propely handle tests for open DRs in make_cxx_dr_status

A follow-up to D136133. It was mentioned in #58382 that there is a need
to test for DRs that have not been officially resolved yet. This patch
aims to replace original "hackery" with proper handling for such cases.
Highlights:

- Availability can be suffixed (further) with "open", "drafting", or
  "review", e.g. // dr2565: 16 open, // dr: 16 c++17 drafting
- Checks are implemented to ensure that this suffix corresponds to
  actual issue status
- Non-resolved DRs are counted (stdout of make_cxx_dr_status)
- No changes made to cxx_dr_status.html
- 'c++20' availability suffix added
- Remove 'concurrency' status since it's no longer
  on the list of statuses in CWG Active Issues

Differential Revision: https://reviews.llvm.org/D138901

Added: 


Modified: 
clang/test/CXX/drs/dr25xx.cpp
clang/test/CXX/drs/dr26xx.cpp
clang/www/make_cxx_dr_status

Removed: 




diff  --git a/clang/test/CXX/drs/dr25xx.cpp b/clang/test/CXX/drs/dr25xx.cpp
index a0b947b8d58ed..ee68b4ad45d11 100644
--- a/clang/test/CXX/drs/dr25xx.cpp
+++ b/clang/test/CXX/drs/dr25xx.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
 
-namespace dr2565 { // dr2565: 16
+namespace dr2565 { // dr2565: 16 open
   template
 concept C = requires (typename T::type x) {
   x + 1;

diff  --git a/clang/test/CXX/drs/dr26xx.cpp b/clang/test/CXX/drs/dr26xx.cpp
index 3ec1aa279dfc9..46d81e544b5c2 100644
--- a/clang/test/CXX/drs/dr26xx.cpp
+++ b/clang/test/CXX/drs/dr26xx.cpp
@@ -14,7 +14,7 @@ using enum E; // expected-error {{unknown type name E}}
 }
 }
 
-namespace dr2628 { // dr2628: yes
+namespace dr2628 { // dr2628: yes open
 
 template 
 struct foo {

diff  --git a/clang/www/make_cxx_dr_status b/clang/www/make_cxx_dr_status
index bdd08832844c8..922a3810ec9a2 100755
--- a/clang/www/make_cxx_dr_status
+++ b/clang/www/make_cxx_dr_status
@@ -95,6 +95,18 @@ latest_release = 15
 
 def availability(issue):
   status = status_map.get(issue, 'unknown')
+  
+  unresolved_status = ''
+  if status.endswith(' open'):
+status = status[:-5]
+unresolved_status = 'open'
+  elif status.endswith(' drafting'):
+status = status[:-9]
+unresolved_status = 'drafting'
+  elif status.endswith(' review'):
+status = status[:-7]
+unresolved_status = 'review'
+
   avail_suffix = ''
   if status.endswith(' c++11'):
 status = status[:-6]
@@ -105,6 +117,9 @@ def availability(issue):
   elif status.endswith(' c++17'):
 status = status[:-6]
 avail_suffix = ' (C++17 onwards)'
+  elif status.endswith(' c++20'):
+status = status[:-6]
+avail_suffix = ' (C++20 onwards)'
   if status == 'unknown':
 avail = 'Unknown'
 avail_style = ' class="none"'
@@ -140,17 +155,17 @@ def availability(issue):
 else:
   avail = 'Superseded by %s' % (dup, dup)
   try:
-_, avail_style = availability(int(dup))
+_, avail_style, _ = availability(int(dup))
   except:
 print("issue %s marked as sup %s" % (issue, dup), file=sys.stderr)
 avail_style = ' class="none"'
   elif status.startswith('dup '):
 dup = int(status.split(' ', 1)[1])
 avail = 'Duplicate of %s' % (dup, dup)
-_, avail_style = availability(dup)
+_, avail_style, _ = availability(dup)
   else:
 assert False, 'unknown status %s for issue %s' % (status, dr.issue)
-  return (avail + avail_suffix, avail_style)
+  return (avail + avail_suffix, avail_style, unresolved_status)
 
 count = {}
 for dr in drs:
@@ -158,21 +173,28 @@ for dr in drs:
 # This refers to the old ("C++0x") concepts feature, which was not part
 # of any C++ International Standard or Technical Specification.
 continue
-  if dr.issue in (2565, 2628):
+  elif dr.status == 'extension':
 row_style = ' class="open"'
-avail, avail_style = availability(dr.issue)
-  elif dr.status in ('open', 'concurrency', 'drafting', 'review', 'extension'):
-# We may have to deal with these some day, but not yet.
+avail = 'Extension'
+avail_style = ''
+  elif dr.status in ('open', 'drafting', 'review'):
 row_style = ' class="open"'
-if dr.status == 'extension':
-  avail = 'Extension'
-else:
+avail, avail_style, unresolved_status = availability(dr.issue)
+if avail == 'Unknown':
   avail = 'Not resolved'
-avail_style = ''
-assert dr.issue not in status_map, "have status for not-ready dr %s" % 
dr.issue
+  avail_style = ''
+else:
+  assert unresolved_status == dr.status, \
+ "Issue %s is marked '%s', 

[PATCH] D138901: [clang] Propely handle tests for open DRs in make_cxx_dr_status

2022-11-29 Thread Erich Keane 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 rG3d280b037530: [clang] Propely handle tests for open DRs in 
make_cxx_dr_status (authored by Endill, committed by erichkeane).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138901

Files:
  clang/test/CXX/drs/dr25xx.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/www/make_cxx_dr_status

Index: clang/www/make_cxx_dr_status
===
--- clang/www/make_cxx_dr_status
+++ clang/www/make_cxx_dr_status
@@ -95,6 +95,18 @@
 
 def availability(issue):
   status = status_map.get(issue, 'unknown')
+  
+  unresolved_status = ''
+  if status.endswith(' open'):
+status = status[:-5]
+unresolved_status = 'open'
+  elif status.endswith(' drafting'):
+status = status[:-9]
+unresolved_status = 'drafting'
+  elif status.endswith(' review'):
+status = status[:-7]
+unresolved_status = 'review'
+
   avail_suffix = ''
   if status.endswith(' c++11'):
 status = status[:-6]
@@ -105,6 +117,9 @@
   elif status.endswith(' c++17'):
 status = status[:-6]
 avail_suffix = ' (C++17 onwards)'
+  elif status.endswith(' c++20'):
+status = status[:-6]
+avail_suffix = ' (C++20 onwards)'
   if status == 'unknown':
 avail = 'Unknown'
 avail_style = ' class="none"'
@@ -140,17 +155,17 @@
 else:
   avail = 'Superseded by %s' % (dup, dup)
   try:
-_, avail_style = availability(int(dup))
+_, avail_style, _ = availability(int(dup))
   except:
 print("issue %s marked as sup %s" % (issue, dup), file=sys.stderr)
 avail_style = ' class="none"'
   elif status.startswith('dup '):
 dup = int(status.split(' ', 1)[1])
 avail = 'Duplicate of %s' % (dup, dup)
-_, avail_style = availability(dup)
+_, avail_style, _ = availability(dup)
   else:
 assert False, 'unknown status %s for issue %s' % (status, dr.issue)
-  return (avail + avail_suffix, avail_style)
+  return (avail + avail_suffix, avail_style, unresolved_status)
 
 count = {}
 for dr in drs:
@@ -158,21 +173,28 @@
 # This refers to the old ("C++0x") concepts feature, which was not part
 # of any C++ International Standard or Technical Specification.
 continue
-  if dr.issue in (2565, 2628):
+  elif dr.status == 'extension':
 row_style = ' class="open"'
-avail, avail_style = availability(dr.issue)
-  elif dr.status in ('open', 'concurrency', 'drafting', 'review', 'extension'):
-# We may have to deal with these some day, but not yet.
+avail = 'Extension'
+avail_style = ''
+  elif dr.status in ('open', 'drafting', 'review'):
 row_style = ' class="open"'
-if dr.status == 'extension':
-  avail = 'Extension'
-else:
+avail, avail_style, unresolved_status = availability(dr.issue)
+if avail == 'Unknown':
   avail = 'Not resolved'
-avail_style = ''
-assert dr.issue not in status_map, "have status for not-ready dr %s" % dr.issue
+  avail_style = ''
+else:
+  assert unresolved_status == dr.status, \
+ "Issue %s is marked '%s', which differs from CWG index status '%s'" \
+ % (dr.issue, unresolved_status, dr.status)
+if not avail.startswith('Sup') and not avail.startswith('Dup'):
+  count[avail] = count.get(avail, 0) + 1
   else:
 row_style = ''
-avail, avail_style = availability(dr.issue)
+avail, avail_style, unresolved_status = availability(dr.issue)
+assert not unresolved_status, \
+   "Issue %s is marked '%s', even though it is resolved in CWG index" \
+   % (dr.issue, unresolved_status)
 if not avail.startswith('Sup') and not avail.startswith('Dup'):
   count[avail] = count.get(avail, 0) + 1
 
Index: clang/test/CXX/drs/dr26xx.cpp
===
--- clang/test/CXX/drs/dr26xx.cpp
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -14,7 +14,7 @@
 }
 }
 
-namespace dr2628 { // dr2628: yes
+namespace dr2628 { // dr2628: yes open
 
 template 
 struct foo {
Index: clang/test/CXX/drs/dr25xx.cpp
===
--- clang/test/CXX/drs/dr25xx.cpp
+++ clang/test/CXX/drs/dr25xx.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
 
-namespace dr2565 { // dr2565: 16
+namespace dr2565 { // dr2565: 16 open
   template
 concept C = requires (typename T::type x) {
   x + 1;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138797: [include-cleaner] Implement IWYU begin_keep/end_keep pragma support.

2022-11-29 Thread Viktoriia Bakalova via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
VitaNuo marked an inline comment as done.
Closed by commit rG7452e053e592: [include-cleaner] Implement IWYU 
begin_keep/end_keep pragma support. (authored by VitaNuo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138797

Files:
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -311,35 +311,68 @@
 };
 
 TEST_F(PragmaIncludeTest, IWYUKeep) {
-  Inputs.Code = R"cpp(// Line 1
-#include "keep1.h" // IWYU pragma: keep
-#include "keep2.h" /* IWYU pragma: keep */
+  llvm::Annotations MainFile(R"cpp(
+$keep1^#include "keep1.h" // IWYU pragma: keep
+$keep2^#include "keep2.h" /* IWYU pragma: keep */
+
+$export1^#include "export1.h" // IWYU pragma: export
+$begin_exports^// IWYU pragma: begin_exports
+$export2^#include "export2.h"
+$export3^#include "export3.h"
+$end_exports^// IWYU pragma: end_exports
+
+$normal^#include "normal.h"
+
+$begin_keep^// IWYU pragma: begin_keep 
+$keep3^#include "keep3.h"
+$end_keep^// IWYU pragma: end_keep
+
+// IWYU pragma: begin_keep 
+$keep4^#include "keep4.h"
+// IWYU pragma: begin_keep
+$keep5^#include "keep5.h"
+// IWYU pragma: end_keep
+$keep6^#include "keep6.h"
+// IWYU pragma: end_keep
+  )cpp");
 
-#include "export1.h" // IWYU pragma: export // line 5
-// IWYU pragma: begin_exports
-#include "export2.h" // Line 7
-#include "export3.h"
-// IWYU pragma: end_exports
+  auto OffsetToLineNum = [&MainFile](size_t Offset) {
+int Count = MainFile.code().substr(0, Offset).count('\n');
+return Count + 1;
+  };
 
-#include "normal.h" // Line 11
-  )cpp";
-  createEmptyFiles({"keep1.h", "keep2.h", "export1.h", "export2.h", "export3.h",
+  Inputs.Code = MainFile.code();
+  createEmptyFiles({"keep1.h", "keep2.h", "keep3.h", "keep4.h", "keep5.h",
+"keep6.h", "export1.h", "export2.h", "export3.h",
 "normal.h"});
 
   TestAST Processed = build();
   EXPECT_FALSE(PI.shouldKeep(1));
+
   // Keep
-  EXPECT_TRUE(PI.shouldKeep(2));
-  EXPECT_TRUE(PI.shouldKeep(3));
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep1";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep2";
 
-  // Exports
-  EXPECT_TRUE(PI.shouldKeep(5));
-  EXPECT_TRUE(PI.shouldKeep(7));
-  EXPECT_TRUE(PI.shouldKeep(8));
-  EXPECT_FALSE(PI.shouldKeep(6)); // no # directive
-  EXPECT_FALSE(PI.shouldKeep(9)); // no # directive
+  EXPECT_FALSE(PI.shouldKeep(
+  OffsetToLineNum(MainFile.point("begin_keep"; // no # directive
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep3";
+  EXPECT_FALSE(PI.shouldKeep(
+  OffsetToLineNum(MainFile.point("end_keep"; // no # directive
+
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep4";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep5";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("keep6";
 
-  EXPECT_FALSE(PI.shouldKeep(11));
+  // Exports
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("export1";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("export2";
+  EXPECT_TRUE(PI.shouldKeep(OffsetToLineNum(MainFile.point("export3";
+  EXPECT_FALSE(PI.shouldKeep(
+  OffsetToLineNum(MainFile.point("begin_exports"; // no # directive
+  EXPECT_FALSE(PI.shouldKeep(
+  OffsetToLineNum(MainFile.point("end_exports"; // no # directive
+
+  EXPECT_FALSE(PI.shouldKeep(OffsetToLineNum(MainFile.point("normal";
 }
 
 TEST_F(PragmaIncludeTest, IWYUPrivate) {
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -187,9 +187,7 @@
 FileID HashFID = SM.getFileID(HashLoc);
 int HashLine = SM.getLineNumber(HashFID, SM.getFileOffset(HashLoc));
 checkForExport(HashFID, HashLine, File ? &File->getFileEntry() : nullptr);
-
-if (InMainFile && LastPragmaKeepInMainFileLine == HashLine)
-  Out->ShouldKeep.insert(HashLine);
+checkForKeep(HashLine);
   }
 
   void checkForExport(FileID IncludingFile, int HashLine,
@@ -213,6 +211,18 @@
   ExportStack.pop_back();
   }
 
+  void checkForKeep(int HashLine) {
+if (!InMainFile || KeepStack.empty())
+  return;
+KeepPragma &Top = KeepStack.back();
+// Check if the current include is covered by a keep pragma

[clang-tools-extra] 7452e05 - [include-cleaner] Implement IWYU begin_keep/end_keep pragma support.

2022-11-29 Thread Viktoriia Bakalova via cfe-commits

Author: Viktoriia Bakalova
Date: 2022-11-29T14:51:20Z
New Revision: 7452e053e5921113ef59ccab04acc0999bf2ecc2

URL: 
https://github.com/llvm/llvm-project/commit/7452e053e5921113ef59ccab04acc0999bf2ecc2
DIFF: 
https://github.com/llvm/llvm-project/commit/7452e053e5921113ef59ccab04acc0999bf2ecc2.diff

LOG: [include-cleaner] Implement IWYU begin_keep/end_keep pragma support.

Implement support for begin_keep/end_keep pragmas.

Differential Revision: https://reviews.llvm.org/D138797

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/Record.cpp
clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/Record.cpp 
b/clang-tools-extra/include-cleaner/lib/Record.cpp
index ac3315abb882c..5a9ec6d0aadcf 100644
--- a/clang-tools-extra/include-cleaner/lib/Record.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -187,9 +187,7 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
 FileID HashFID = SM.getFileID(HashLoc);
 int HashLine = SM.getLineNumber(HashFID, SM.getFileOffset(HashLoc));
 checkForExport(HashFID, HashLine, File ? &File->getFileEntry() : nullptr);
-
-if (InMainFile && LastPragmaKeepInMainFileLine == HashLine)
-  Out->ShouldKeep.insert(HashLine);
+checkForKeep(HashLine);
   }
 
   void checkForExport(FileID IncludingFile, int HashLine,
@@ -213,6 +211,18 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   ExportStack.pop_back();
   }
 
+  void checkForKeep(int HashLine) {
+if (!InMainFile || KeepStack.empty())
+  return;
+KeepPragma &Top = KeepStack.back();
+// Check if the current include is covered by a keep pragma.
+if ((Top.Block && HashLine > Top.SeenAtLine) || Top.SeenAtLine == HashLine)
+  Out->ShouldKeep.insert(HashLine);
+
+if (!Top.Block)
+  KeepStack.pop_back(); // Pop immediately for single-line keep pragma.
+  }
+
   bool HandleComment(Preprocessor &PP, SourceRange Range) override {
 auto &SM = PP.getSourceManager();
 auto Pragma =
@@ -257,23 +267,14 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
 }
 
 if (InMainFile) {
-  if (!Pragma->startswith("keep"))
-return false;
-  // Given:
-  //
-  // #include "foo.h"
-  // #include "bar.h" // IWYU pragma: keep
-  //
-  // The order in which the callbacks will be triggered:
-  //
-  // 1. InclusionDirective("foo.h")
-  // 2. handleCommentInMainFile("// IWYU pragma: keep")
-  // 3. InclusionDirective("bar.h")
-  //
-  // This code stores the last location of "IWYU pragma: keep" comment in
-  // the main file, so that when next InclusionDirective is called, it will
-  // know that the next inclusion is behind the IWYU pragma.
-  LastPragmaKeepInMainFileLine = CommentLine;
+  if (Pragma->startswith("keep")) {
+KeepStack.push_back({CommentLine, false});
+  } else if (Pragma->starts_with("begin_keep")) {
+KeepStack.push_back({CommentLine, true});
+  } else if (Pragma->starts_with("end_keep") && !KeepStack.empty()) {
+assert(KeepStack.back().Block);
+KeepStack.pop_back();
+  }
 }
 return false;
   }
@@ -288,8 +289,7 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   llvm::BumpPtrAllocator Arena;
   /// Intern table for strings. Contents are on the arena.
   llvm::StringSaver UniqueStrings;
-  // Track the last line "IWYU pragma: keep" was seen in the main file, 
1-based.
-  int LastPragmaKeepInMainFileLine = -1;
+
   struct ExportPragma {
 // The line number where we saw the begin_exports or export pragma.
 int SeenAtLine = 0; // 1-based line number.
@@ -303,6 +303,16 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   };
   // A stack for tracking all open begin_exports or single-line export.
   std::vector ExportStack;
+
+  struct KeepPragma {
+// The line number where we saw the begin_keep or keep pragma.
+int SeenAtLine = 0; // 1-based line number.
+// true if it is a block begin/end_keep pragma; false if it is a
+// single-line keep pragma.
+bool Block = false;
+  };
+  // A stack for tracking all open begin_keep pragmas or single-line keeps.
+  std::vector KeepStack;
 };
 
 void PragmaIncludes::record(const CompilerInstance &CI) {

diff  --git a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
index 0cc163751fd70..1076891473431 100644
--- a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -311,35 +311,68 @@ class PragmaIncludeTest : public ::testing::Test {
 };
 
 TEST_F(PragmaIncludeTest, IWYUKeep) {
-  Inputs.Code = R"c

[PATCH] D136078: Use-after-return sanitizer binary metadata

2022-11-29 Thread Marco Elver via Phabricator via cfe-commits
melver accepted this revision.
melver added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: llvm/include/llvm/CodeGen/MachinePassRegistry.def:205
 DUMMY_MACHINE_FUNCTION_PASS("print-machine-cycles", 
MachineCycleInfoPrinterPass, ())
+DUMMY_MACHINE_FUNCTION_PASS("machine-san-binary-md", 
MachineSanitizerBinaryMetadata, ())
 #undef DUMMY_MACHINE_FUNCTION_PASS

I called the LLVM IR pass just "sanmd-module".
So this could just be "machine-sanmd".



Comment at: llvm/test/Instrumentation/SanitizerBinaryMetadata/common.h:54
+
+void __sanitizer_metadata_atomics_add() {}
+void __sanitizer_metadata_atomics_del() {}

Could make this have its real signature, i.e. add version,start,end args. Then 
could also check in del that start,end matches, like above.



Comment at: llvm/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp:1
+// REQUIRES: native && target-x86_64
+// RUN: clang++ %s -o %t && %t | FileCheck %s

dvyukov wrote:
> This is the new test.
Nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136078

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


[PATCH] D136078: Use-after-return sanitizer binary metadata

2022-11-29 Thread Marco Elver via Phabricator via cfe-commits
melver added inline comments.



Comment at: llvm/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp:19
+void non_empty_function() {
+  // Completely empty functions don't get uar metadata.
+  volatile int x;

Is this comment out of place?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136078

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


[PATCH] D137652: Remove mandatory define of optional features macros for OpenCL C 3.0

2022-11-29 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

Are these features affecting the frontend functionality in any way? If not we 
should implement those in the headers and if headers are not flexible enough to 
condition out the addition of the new macros we should extend them (potentially 
by extending behaviour of `-cl-ext` or introducing `undef` macros, see 
https://github.com/llvm/llvm-project/issues/55674). Please review the 
guidelines here: 
https://clang.llvm.org/docs/OpenCLSupport.html#opencl-extensions-and-features. 
The most relevant part here is:

> If an extension adds functionality that does not modify standard language 
> parsing it should not require modifying anything other than header files and 
> OpenCLBuiltins.td detailed in OpenCL builtins. Most commonly such extensions 
> add functionality via libraries (by adding non-native types or functions) 
> parsed regularly. Similar to other languages this is the most common way to 
> add new functionality.

Overall, the idea is to avoiding modifying frontend changes if we can implement 
features via the headers instead. This is needed to address the scalability 
problems.




Comment at: clang/include/clang/Basic/OpenCLExtensions.def:123
+OPENCL_OPTIONALCOREFEATURE(__opencl_c_work_group_collective_functions, false, 
300, OCL_C_30)
+OPENCL_OPTIONALCOREFEATURE(__opencl_c_int64, false, 300, OCL_C_30)
 

svenvh wrote:
> I am wondering why those features weren't added together with the other 
> OpenCL 3.0 features; there wasn't any discussion around that in D95776.  
> Perhaps it's because these don't affect the compiler behaviour directly? (but 
> then neither does e.g. `__opencl_c_atomic_order_acq_rel`)  Wondering if 
> @Anastasia has any insights here.
Correct, I think Anton wanted to implement some diagnostics affecting 
`__opencl_c_atomic_order_acq_rel`, but it hasn't happened and I am not 
convinced it is doable. So potentially we can remove those from here in the 
future and migrate into the internal headers too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137652

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


[clang] 0fae851 - [AIX][pg] Add Correct Search Paths for Profiled Libraries

2022-11-29 Thread Chris Bowler via cfe-commits

Author: Michael Francis
Date: 2022-11-29T10:16:27-05:00
New Revision: 0fae851824bc1b64a727aeb331b7a0787599bd1f

URL: 
https://github.com/llvm/llvm-project/commit/0fae851824bc1b64a727aeb331b7a0787599bd1f
DIFF: 
https://github.com/llvm/llvm-project/commit/0fae851824bc1b64a727aeb331b7a0787599bd1f.diff

LOG: [AIX][pg] Add Correct Search Paths for Profiled Libraries

On AIX, profiled system libraries are stored at `/lib/profiled` and
`/usr/lib/profiled`. When compiling with `-pg`, we want to link against
libraries in those directories. This PR modifies the AIX toolchain to
add those directories to the linker search paths.

Differential Review: https://reviews.llvm.org/D137375

Added: 


Modified: 
clang/lib/Driver/ToolChains/AIX.cpp
clang/test/Driver/aix-ld.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index 1e72f1e761e8b..3bf97eec04a1a 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -250,6 +250,13 @@ void aix::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back("-lm");
 
 CmdArgs.push_back("-lc");
+
+if (Args.hasArg(options::OPT_pg)) {
+  CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
+   "/lib/profiled"));
+  CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
+   "/usr/lib/profiled"));
+}
   }
 
   const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());

diff  --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c
index 8aae6b086cbff..42631f4c59eee 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -189,6 +189,8 @@
 // CHECK-LD32-GPROF-NOT: "--no-as-needed"
 // CHECK-LD32-GPROF-NOT: "-lm"
 // CHECK-LD32-GPROF: "-lc"
+// CHECK-LD32-GPROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD32-GPROF: "-L[[SYSROOT]]/usr/lib/profiled"
 
 // Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable g-profiling.
 // RUN: %clang %s -### 2>&1 \
@@ -216,6 +218,8 @@
 // CHECK-LD64-GPROF-NOT: "--no-as-needed"
 // CHECK-LD64-GPROF-NOT: "-lm"
 // CHECK-LD64-GPROF: "-lc"
+// CHECK-LD64-GPROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD64-GPROF: "-L[[SYSROOT]]/usr/lib/profiled"
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. Static linking.
 // RUN: %clang %s -### 2>&1 \



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


[PATCH] D137213: [clang][modules] NFCI: Pragma diagnostic mappings: write/read FileID instead of SourceLocation

2022-11-29 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a subscriber: jgorbe.
alexfh added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:6343
  "Invalid data, missing pragma diagnostic states");
-  SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]);
-  auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc);
-  assert(IDAndOffset.first.isValid() && "invalid FileID for transition");
-  assert(IDAndOffset.second == 0 && "not a start location for a FileID");
+  FileID FID = ReadFileID(F, Record, Idx);
+  assert(FID.isValid() && "invalid FileID for transition");

jansvoboda11 wrote:
> alexfh wrote:
> > dexonsmith wrote:
> > > eaeltsin wrote:
> > > > This doesn't work as before, likely because ReadFileID doesn't do 
> > > > TranslateSourceLocation.
> > > > 
> > > > Our tests fail.
> > > > 
> > > > I tried calling TranslateSourceLocation here and the tests passed:
> > > > ```
> > > >   SourceLocation Loc = Diag.SourceMgr->getComposedLoc(FID, 0);
> > > >   SourceLocation Loc2 = TranslateSourceLocation(F, Loc);
> > > >   auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc2);
> > > > 
> > > >   // Note that we don't need to set up Parent/ParentOffset here, 
> > > > because
> > > >   // we won't be changing the diagnostic state within imported 
> > > > FileIDs
> > > >   // (other than perhaps appending to the main source file, which 
> > > > has no
> > > >   // parent).
> > > >   auto &F = Diag.DiagStatesByLoc.Files[IDAndOffset.first];
> > > > ```
> > > > 
> > > > Sorry I don't know the codebase, so this fix is definitely ugly :) But 
> > > > it shows the problem.
> > > > 
> > > I don't think that's the issue, since `ReadFileID()` calls 
> > > `TranslateFileID`, which should seems like it should be equivalent.
> > > 
> > > However, I notice that the post-increment for `Idx` got dropped! Can you 
> > > try replacing the line of code with the following and see if that fixes 
> > > your tests (without any extra TranslateSourceLocation logic)?
> > > ```
> > > lang=c++
> > > FileID FID = ReadFileID(F, Record, Idx++);
> > > ```
> > > 
> > > If so, maybe you can contribute that fix with a reduced testcase? I 
> > > suggest adding me, @vsapsai, @Bigcheese, and @jansvoboda11 as reviewers.
> > > 
> > > @alexfh, maybe you can check if this fixes your tests as well?
> > > 
> > > (If this is the issue, it's a bit surprising we don't have existing tests 
> > > covering this case... and embarrassing I missed it when reviewing 
> > > initially!)
> > I've noticed the dropped `Idx` post-increment as well, but I went a step 
> > further and looked at the `ReadFileID` implementation, which is actually 
> > doing a post-increment itself, and accepts `Idx` by reference:
> > ```
> >   FileID ReadFileID(ModuleFile &F, const RecordDataImpl &Record,
> > unsigned &Idx) const {
> > return TranslateFileID(F, FileID::get(Record[Idx++]));
> >   }
> > ```
> > 
> > Thus, it seems to be correct. But what @eaeltsin  has found is actually a 
> > problem for us.  I'm currently trying to make an isolated test case, but 
> > it's quite tricky (as header modules are =\). It may be the case that our 
> > build setup relies on something clang doesn't explicitly promises, but the 
> > fact is that the behavior (as observed by our build setup) has changed. 
> > I'll try to revert the commit for now to get us unblocked and provide a 
> > test case as soon as I can.
> Thanks for helping out @dexonsmith, we did have the week off.
> 
> @eaeltsin @alexfhDone, are you able to provide the failing test case? I'm 
> happy to look into it and re-land this with a fix.
I've spent multiple hours trying to extract an observable test case. It turned 
out to be too hairy of a yaq to shave: for each compilation a separate 
sandboxed environment is created with a separate symlink tree with just the 
inputs necessary for that action. Some of the inputs are prebuilt module files 
(e.g. for libc++) that are version-locked with the compiler. So far @jgorbe and 
I could reduce this to four compilation steps with their own symlink trees with 
inputs. While I could figure out some of the factors that affect 
reproducibility (for example, symlinks are important, since making a deep copy 
of the input directories makes the issue disappear), it will take a few more 
hours of concentrated yak shaving to bring this to a shareable state. I'm not 
sure I have much more time to sink into investigating this. 

It seems like examining code based on @eaeltsin's finding may be a more 
fruitful path to synthesizing a regression test. Could you try following that 
path?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137213

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


[PATCH] D138028: [clangd] Fix action `RemoveUsingNamespace` for inline namespace

2022-11-29 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry added a comment.

A gentle ping? Sorry if it bothers you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138028

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


[PATCH] D137213: [clang][modules] NFCI: Pragma diagnostic mappings: write/read FileID instead of SourceLocation

2022-11-29 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:6343
  "Invalid data, missing pragma diagnostic states");
-  SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]);
-  auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc);
-  assert(IDAndOffset.first.isValid() && "invalid FileID for transition");
-  assert(IDAndOffset.second == 0 && "not a start location for a FileID");
+  FileID FID = ReadFileID(F, Record, Idx);
+  assert(FID.isValid() && "invalid FileID for transition");

alexfh wrote:
> jansvoboda11 wrote:
> > alexfh wrote:
> > > dexonsmith wrote:
> > > > eaeltsin wrote:
> > > > > This doesn't work as before, likely because ReadFileID doesn't do 
> > > > > TranslateSourceLocation.
> > > > > 
> > > > > Our tests fail.
> > > > > 
> > > > > I tried calling TranslateSourceLocation here and the tests passed:
> > > > > ```
> > > > >   SourceLocation Loc = Diag.SourceMgr->getComposedLoc(FID, 0);
> > > > >   SourceLocation Loc2 = TranslateSourceLocation(F, Loc);
> > > > >   auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc2);
> > > > > 
> > > > >   // Note that we don't need to set up Parent/ParentOffset here, 
> > > > > because
> > > > >   // we won't be changing the diagnostic state within imported 
> > > > > FileIDs
> > > > >   // (other than perhaps appending to the main source file, which 
> > > > > has no
> > > > >   // parent).
> > > > >   auto &F = Diag.DiagStatesByLoc.Files[IDAndOffset.first];
> > > > > ```
> > > > > 
> > > > > Sorry I don't know the codebase, so this fix is definitely ugly :) 
> > > > > But it shows the problem.
> > > > > 
> > > > I don't think that's the issue, since `ReadFileID()` calls 
> > > > `TranslateFileID`, which should seems like it should be equivalent.
> > > > 
> > > > However, I notice that the post-increment for `Idx` got dropped! Can 
> > > > you try replacing the line of code with the following and see if that 
> > > > fixes your tests (without any extra TranslateSourceLocation logic)?
> > > > ```
> > > > lang=c++
> > > > FileID FID = ReadFileID(F, Record, Idx++);
> > > > ```
> > > > 
> > > > If so, maybe you can contribute that fix with a reduced testcase? I 
> > > > suggest adding me, @vsapsai, @Bigcheese, and @jansvoboda11 as reviewers.
> > > > 
> > > > @alexfh, maybe you can check if this fixes your tests as well?
> > > > 
> > > > (If this is the issue, it's a bit surprising we don't have existing 
> > > > tests covering this case... and embarrassing I missed it when reviewing 
> > > > initially!)
> > > I've noticed the dropped `Idx` post-increment as well, but I went a step 
> > > further and looked at the `ReadFileID` implementation, which is actually 
> > > doing a post-increment itself, and accepts `Idx` by reference:
> > > ```
> > >   FileID ReadFileID(ModuleFile &F, const RecordDataImpl &Record,
> > > unsigned &Idx) const {
> > > return TranslateFileID(F, FileID::get(Record[Idx++]));
> > >   }
> > > ```
> > > 
> > > Thus, it seems to be correct. But what @eaeltsin  has found is actually a 
> > > problem for us.  I'm currently trying to make an isolated test case, but 
> > > it's quite tricky (as header modules are =\). It may be the case that our 
> > > build setup relies on something clang doesn't explicitly promises, but 
> > > the fact is that the behavior (as observed by our build setup) has 
> > > changed. I'll try to revert the commit for now to get us unblocked and 
> > > provide a test case as soon as I can.
> > Thanks for helping out @dexonsmith, we did have the week off.
> > 
> > @eaeltsin @alexfhDone, are you able to provide the failing test case? I'm 
> > happy to look into it and re-land this with a fix.
> I've spent multiple hours trying to extract an observable test case. It 
> turned out to be too hairy of a yaq to shave: for each compilation a separate 
> sandboxed environment is created with a separate symlink tree with just the 
> inputs necessary for that action. Some of the inputs are prebuilt module 
> files (e.g. for libc++) that are version-locked with the compiler. So far 
> @jgorbe and I could reduce this to four compilation steps with their own 
> symlink trees with inputs. While I could figure out some of the factors that 
> affect reproducibility (for example, symlinks are important, since making a 
> deep copy of the input directories makes the issue disappear), it will take a 
> few more hours of concentrated yak shaving to bring this to a shareable 
> state. I'm not sure I have much more time to sink into investigating this. 
> 
> It seems like examining code based on @eaeltsin's finding may be a more 
> fruitful path to synthesizing a regression test. Could you try following that 
> path?
One more observation: `-fmodules-embed-all-files` and `-Wno-mismatched-tags` 
compiler options turned out to be important.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST AC

[PATCH] D138854: [AIX][LTO] Enabling Context Sensitive PGO Options

2022-11-29 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 updated this revision to Diff 478592.
qiongsiwu1 added a comment.

Address review comment. Thanks for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138854

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/lto-aix.c
  llvm/lib/LTO/LTOCodeGenerator.cpp

Index: llvm/lib/LTO/LTOCodeGenerator.cpp
===
--- llvm/lib/LTO/LTOCodeGenerator.cpp
+++ llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -118,7 +118,15 @@
 "lto-aix-system-assembler",
 cl::desc("Path to a system assembler, picked up on AIX only"),
 cl::value_desc("path"));
-}
+
+cl::opt
+LTORunCSIRInstr("cs-profile-generate",
+cl::desc("Perform context sensitive PGO instrumentation"));
+
+cl::opt
+LTOCSIRProfile("cs-profile-path",
+   cl::desc("Context sensitive profile file path"));
+} // namespace llvm
 
 LTOCodeGenerator::LTOCodeGenerator(LLVMContext &Context)
 : Context(Context), MergedModule(new Module("ld-temp.o", Context)),
@@ -131,6 +139,9 @@
   Config.PreCodeGenPassesHook = [](legacy::PassManager &PM) {
 PM.add(createObjCARCContractPass());
   };
+
+  Config.RunCSIRInstr = LTORunCSIRInstr;
+  Config.CSIRProfile = LTOCSIRProfile;
 }
 
 LTOCodeGenerator::~LTOCodeGenerator() = default;
Index: clang/test/Driver/lto-aix.c
===
--- clang/test/Driver/lto-aix.c
+++ clang/test/Driver/lto-aix.c
@@ -67,3 +67,9 @@
 //
 // STRICT:   "-bplugin_opt:-strict-dwarf=true"
 // NOSTRICT-NOT: "-bplugin_opt:-strict-dwarf=true"
+//
+// Test cspgo options
+// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld \
+// RUN:   -fcs-profile-generate 2>&1 | FileCheck -check-prefix=CSPGO %s
+//
+// CSPGO: "-bplugin_opt:-cs-profile-generate" "-bplugin_opt:-cs-profile-path=default_%m.profraw"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -519,8 +519,7 @@
   }
 
   const char *PluginOptPrefix = IsOSAIX ? "-bplugin_opt:" : "-plugin-opt=";
-  const char *mcpuOptPrefix = IsOSAIX ? "-mcpu=" : "mcpu=";
-  const char *OptLevelPrefix = IsOSAIX ? "-O" : "O";
+  const char *ExtraDash = IsOSAIX? "-" : "";
 
   // Note, this solution is far from perfect, better to encode it into IR
   // metadata, but this may not be worth it, since it looks like aranges is on
@@ -537,7 +536,7 @@
   std::string CPU = getCPUName(D, Args, ToolChain.getTriple());
   if (!CPU.empty())
 CmdArgs.push_back(
-Args.MakeArgString(Twine(PluginOptPrefix) + mcpuOptPrefix + CPU));
+Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + "mcpu=" + CPU));
 
   if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
 // The optimization level matches
@@ -556,7 +555,7 @@
   OOpt = "0";
 if (!OOpt.empty())
   CmdArgs.push_back(
-  Args.MakeArgString(Twine(PluginOptPrefix) + OptLevelPrefix + OOpt));
+  Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + "O" + OOpt));
   }
 
   if (Args.hasArg(options::OPT_gsplit_dwarf))
@@ -650,24 +649,25 @@
   auto *ProfileUseArg = getLastProfileUseArg(Args);
 
   if (CSPGOGenerateArg) {
-CmdArgs.push_back(
-Args.MakeArgString(Twine(PluginOptPrefix) + "cs-profile-generate"));
+CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
+ "cs-profile-generate"));
 if (CSPGOGenerateArg->getOption().matches(
 options::OPT_fcs_profile_generate_EQ)) {
   SmallString<128> Path(CSPGOGenerateArg->getValue());
   llvm::sys::path::append(Path, "default_%m.profraw");
-  CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
+  CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
"cs-profile-path=" + Path));
 } else
-  CmdArgs.push_back(Args.MakeArgString(
-  Twine(PluginOptPrefix) + "cs-profile-path=default_%m.profraw"));
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
+ "cs-profile-path=default_%m.profraw"));
   } else if (ProfileUseArg) {
 SmallString<128> Path(
 ProfileUseArg->getNumValues() == 0 ? "" : ProfileUseArg->getValue());
 if (Path.empty() || llvm::sys::fs::is_directory(Path))
   llvm::sys::path::append(Path, "default.profdata");
-CmdArgs.push_back(
-Args.MakeArgString(Twine(PluginOptPrefix) + "cs-profile-path=" + Path));
+CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
+ "cs-profile-path=" + Path));
   }
 
   // This controls whether or not we perform JustMyCode instrumentation.
___

[PATCH] D136176: Implement support for option 'fexcess-precision'.

2022-11-29 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

@rjmccall Would you mind looking at this please? Thanks.


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

https://reviews.llvm.org/D136176

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


[PATCH] D138920: [AArch64] Assembly support for VMSA

2022-11-29 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a comment.

Two nits. One below, the other: Please include everyone who contributed to this 
patch in the patch description.




Comment at: llvm/lib/Target/AArch64/AArch64.td:519
+def FeatureTHE : SubtargetFeature<"the", "HasTHE",
+"true", "Enable Translation Hardening Extension">;
+

Please can you include the feature name?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138920

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


[clang] bfd69ad - [LinkerWrapper] Ignore OFK_None kinds for building registration code

2022-11-29 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-11-29T09:46:51-06:00
New Revision: bfd69ad59672e67d60e71d66df7ef878c18a7bb8

URL: 
https://github.com/llvm/llvm-project/commit/bfd69ad59672e67d60e71d66df7ef878c18a7bb8
DIFF: 
https://github.com/llvm/llvm-project/commit/bfd69ad59672e67d60e71d66df7ef878c18a7bb8.diff

LOG: [LinkerWrapper] Ignore OFK_None kinds for building registration code

Summary:
The linker wrapper uses this metadata to determine which registration
code to emit, e.g. CUDA, HIP or OpenMP. If we encounter an OFK_None we
should just ignore it.

Added: 


Modified: 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 5e0c0f92e6f53..554527c314ea7 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -1153,7 +1153,8 @@ linkAndWrapDeviceFiles(SmallVectorImpl 
&LinkerInputFiles,
 
 DenseSet ActiveOffloadKinds;
 for (const auto &File : Input)
-  ActiveOffloadKinds.insert(File.getBinary()->getOffloadKind());
+  if (File.getBinary()->getOffloadKind() != OFK_None)
+ActiveOffloadKinds.insert(File.getBinary()->getOffloadKind());
 
 // First link and remove all the input files containing bitcode.
 SmallVector InputFiles;



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


[PATCH] D138920: [AArch64] Assembly support for VMSA

2022-11-29 Thread Sam Elliott via Phabricator via cfe-commits
lenary added inline comments.



Comment at: llvm/include/llvm/Support/AArch64TargetParser.h:82
+  AEK_THE = 1ULL << 50, // FEAT_THE
+  AEK_D128 =1ULL << 51, // FEAT_LSE128
+  AEK_LSE128 =  1ULL << 52, // FEAT_D128

Comments don't correspond to names :( 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138920

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


[PATCH] D138275: [clang][Interp] Avoid leaking init maps of local primitive arrays

2022-11-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 478598.

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

https://reviews.llvm.org/D138275

Files:
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/lib/AST/Interp/InterpFrame.h
  clang/lib/AST/Interp/InterpState.cpp
  clang/lib/AST/Interp/InterpState.h
  clang/test/AST/Interp/cxx20.cpp

Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -304,3 +304,15 @@
   }
   static_assert(testInc2() == 1, "");
 };
+
+constexpr int NoLeakHere() {
+  int abc[2];
+
+  abc[0] = 1;
+  return abc[1]; // expected-note {{read of object outside its lifetime}} \
+ // ref-note {{read of uninitialized object}}
+}
+static_assert(NoLeakHere() == 3); // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to}} \
+  // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to}}
Index: clang/lib/AST/Interp/InterpState.h
===
--- clang/lib/AST/Interp/InterpState.h
+++ clang/lib/AST/Interp/InterpState.h
@@ -78,9 +78,12 @@
   /// Reports overflow and return true if evaluation should continue.
   bool reportOverflow(const Expr *E, const llvm::APSInt &Value);
 
-  /// Deallocates a pointer.
+  /// Deallocates a block.
   void deallocate(Block *B);
 
+  /// Destroys a block, used during tear down.
+  void destroy(Block *B);
+
   /// Delegates source mapping to the mapper.
   SourceInfo getSource(const Function *F, CodePtr PC) const override {
 return M ? M->getSource(F, PC) : F->getSource(PC);
Index: clang/lib/AST/Interp/InterpState.cpp
===
--- clang/lib/AST/Interp/InterpState.cpp
+++ clang/lib/AST/Interp/InterpState.cpp
@@ -54,6 +54,15 @@
   return noteUndefinedBehavior();
 }
 
+void InterpState::destroy(Block *B) {
+  assert(B);
+  Descriptor *Desc = B->getDescriptor();
+  assert(Desc);
+  // Free storage, if necessary.
+  if (Desc->DtorFn)
+Desc->DtorFn(B, B->data(), Desc);
+}
+
 void InterpState::deallocate(Block *B) {
   Descriptor *Desc = B->getDescriptor();
   if (B->hasPointers()) {
@@ -68,7 +77,6 @@
   Desc->MoveFn(B, B->data(), D->data(), Desc);
   } else {
 // Free storage, if necessary.
-if (Desc->DtorFn)
-  Desc->DtorFn(B, B->data(), Desc);
+destroy(B);
   }
 }
Index: clang/lib/AST/Interp/InterpFrame.h
===
--- clang/lib/AST/Interp/InterpFrame.h
+++ clang/lib/AST/Interp/InterpFrame.h
@@ -47,6 +47,11 @@
   /// Invokes the destructors for a scope.
   void destroy(unsigned Idx);
 
+  /// Invokes the destructors for all scopes. This is used in the
+  /// InterpFrame destructor to avoid memory leaks in case the
+  /// interpretation was not successful.
+  void destroyAll();
+
   /// Pops the arguments off the stack.
   void popArgs();
 
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -64,6 +64,7 @@
 }
 
 InterpFrame::~InterpFrame() {
+  destroyAll();
   for (auto &Param : Params)
 S.deallocate(reinterpret_cast(Param.second.get()));
 }
@@ -74,6 +75,16 @@
   }
 }
 
+void InterpFrame::destroyAll() {
+  if (!Func)
+return;
+  for (const Scope &Sc : Func->scopes()) {
+for (auto &Local : Sc.locals()) {
+  S.destroy(reinterpret_cast(localBlock(Local.Offset)));
+}
+  }
+}
+
 void InterpFrame::popArgs() {
   for (PrimType Ty : Func->args_reverse())
 TYPE_SWITCH(Ty, S.Stk.discard());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137652: Remove mandatory define of optional features macros for OpenCL C 3.0

2022-11-29 Thread Finlay Marno via Phabricator via cfe-commits
FMarno added a comment.

@Anastasia I feel like I am following the guidance you quoted here. The defines 
I've deleted in `opencl-c-base.h` are blocking the possibility of `-cl-ext` 
working and would also get in the way of undefine preprocessor symbols working. 
If there is a problem with the additions to `OpenCLExtensions.def` then we'll 
need to rework how `InitializeOpenCLFeatureTestMacros` in 
`initPreprocessor.cpp` works.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137652

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


[PATCH] D138275: [clang][Interp] Avoid leaking init maps of local primitive arrays

2022-11-29 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

This is REALLY making me concerned again about ownership semantics in the 
interpreter.  I don't have any real concerns with this patch-as-is, but I DO 
have concerns with the architecture that makes something like this necessary.


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

https://reviews.llvm.org/D138275

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


[PATCH] D137051: [Clang] Allow additional mathematical symbols in identifiers.

2022-11-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@tahonermann gentle ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137051

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


[PATCH] D137340: [clang-tidy] Add misc-use-anonymous-namespace check

2022-11-29 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 478603.
carlosgalvezp added a comment.

Replace "the" anonymous namespace with "an" anonymous namespace
Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137340

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
@@ -0,0 +1,59 @@
+// RUN: %check_clang_tidy %s misc-use-anonymous-namespace %t
+
+static void f1();
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'f1' declared 'static', move to anonymous namespace instead [misc-use-anonymous-namespace]
+static int v1;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'v1' declared 'static', move to anonymous namespace instead
+
+namespace {
+  static void f2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f2' declared 'static' in anonymous namespace, remove 'static'
+  static int v2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v2' declared 'static' in anonymous namespace, remove 'static'
+}
+
+namespace a {
+  static void f3();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f3' declared 'static', move to anonymous namespace instead
+  static int v3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v3' declared 'static', move to anonymous namespace instead
+}
+
+namespace a {
+namespace {
+  static void f4();
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'f4' declared 'static' in anonymous namespace, remove 'static'
+  static int v4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'v4' declared 'static' in anonymous namespace, remove 'static'
+}
+}
+
+// OK
+void f5();
+int v5;
+
+// OK
+namespace {
+  void f6();
+  int v6;
+}
+
+// OK
+namespace a {
+namespace {
+  void f7();
+  int v7;
+}
+}
+
+// OK
+struct Foo {
+  static void f();
+  static int x;
+};
+
+// OK
+void foo()
+{
+  static int x;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
@@ -0,0 +1,44 @@
+.. title:: clang-tidy - misc-use-anonymous-namespace
+
+misc-use-anonymous-namespace
+
+
+Finds instances of ``static`` functions or variables declared at global scope
+that could instead be moved into an anonymous namespace. It also detects
+instances moved to an anonymous namespace that still keep the redundant
+``static``.
+
+Anonymous namespaces are the "superior alternative" according to the C++
+Standard. ``static`` was proposed for deprecation, but later un-deprecated to
+keep C compatibility [1]. ``static`` is an overloaded term with different meanings in
+different contexts, so it can create confusion.
+
+Examples:
+
+.. code-block:: c++
+
+  // Bad
+  static void foo();
+  static int x;
+
+  // Good
+  namespace {
+void foo();
+int x;
+  } // namespace
+
+.. code-block:: c++
+
+  // Bad
+  namespace {
+static void foo();
+static int x;
+  }
+
+  // Good
+  namespace {
+void foo();
+int x;
+  }  // namespace
+
+[1] `Undeprecating static `_
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -259,6 +259,7 @@
`misc-unused-alias-decls `_, "Yes"
`misc-unused-parameters `_, "Yes"
`misc-unused-using-decls `_, "Yes"
+   `misc-use-anonymous-namespace `_,
`modernize-avoid-bind `_, "Yes"
`modernize-avoid-c-arrays `_,
`modernize-concat-nested-namespaces `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -115,6 +115,12 @@
 
   Warns when using ``do-while`` loops.
 
+- New :doc:`misc-use-anonymous-namespace
+  ` check.
+
+  Warns when using ``static`` function or variables at global scope, and suggests
+  moving them into an anonymous namespace.
+
 New check aliases
 ^
 
Index: clang-tools-extra/clang-tidy/misc/UseAnonymousNamespace

[PATCH] D138091: [Clang] Fix Sema::ClassifyName so that it classifies EnumConstantDecl as NonType when they are brought into scope via using enum

2022-11-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM! Please add a release note when landing since this fixes open issues.


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

https://reviews.llvm.org/D138091

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


[PATCH] D136078: Use-after-return sanitizer binary metadata

2022-11-29 Thread Dmitry Vyukov via Phabricator via cfe-commits
dvyukov updated this revision to Diff 478609.
dvyukov marked 2 inline comments as done.
dvyukov added a comment.

addressed comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136078

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
  llvm/include/llvm/CodeGen/MachinePassRegistry.def
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Transforms/Instrumentation.h
  llvm/include/llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/CodeGen.cpp
  llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
  llvm/test/Instrumentation/SanitizerBinaryMetadata/common.h
  llvm/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp
  llvm/test/Instrumentation/SanitizerBinaryMetadata/lit.local.cfg
  llvm/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp

Index: llvm/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp
===
--- /dev/null
+++ llvm/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp
@@ -0,0 +1,59 @@
+// We run the compiled binary + sizes of stack arguments depend on the arch.
+// REQUIRES: native && target-x86_64
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered,uar && %t | tee /dev/stderr | FileCheck %s
+
+// CHECK: metadata add version 1
+
+// CHECK: empty: features=0 stack_args=0
+void empty() {
+}
+
+// CHECK: ellipsis: features=0 stack_args=0
+void ellipsis(const char* fmt, ...) {
+  volatile int x;
+  x = 1;
+}
+
+// CHECK: non_empty_function: features=2 stack_args=0
+void non_empty_function() {
+  // Completely empty functions don't get uar metadata.
+  volatile int x;
+  x = 1;
+}
+
+// CHECK: no_stack_args: features=2 stack_args=0
+void no_stack_args(long a0, long a1, long a2, long a3, long a4, long a5) {
+  volatile int x;
+  x = 1;
+}
+
+// CHECK: stack_args: features=2 stack_args=16
+void stack_args(long a0, long a1, long a2, long a3, long a4, long a5, long a6) {
+  volatile int x;
+  x = 1;
+}
+
+// CHECK: more_stack_args: features=2 stack_args=32
+void more_stack_args(long a0, long a1, long a2, long a3, long a4, long a5, long a6, long a7, long a8) {
+  volatile int x;
+  x = 1;
+}
+
+// CHECK: struct_stack_args: features=2 stack_args=144
+struct large { char x[131]; };
+void struct_stack_args(large a) {
+  volatile int x;
+  x = 1;
+}
+
+#define FUNCTIONS \
+  FN(empty); \
+  FN(ellipsis); \
+  FN(non_empty_function); \
+  FN(no_stack_args); \
+  FN(stack_args); \
+  FN(more_stack_args); \
+  FN(struct_stack_args); \
+/**/
+
+#include "common.h"
Index: llvm/test/Instrumentation/SanitizerBinaryMetadata/lit.local.cfg
===
--- /dev/null
+++ llvm/test/Instrumentation/SanitizerBinaryMetadata/lit.local.cfg
@@ -0,0 +1 @@
+config.suffixes = ['.ll', '.cpp']
Index: llvm/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp
===
--- /dev/null
+++ llvm/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp
@@ -0,0 +1,79 @@
+// REQUIRES: native && target-x86_64
+// RUN: clang++ %s -o %t && %t | FileCheck %s
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered && %t | FileCheck -check-prefix=CHECK-C %s
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=atomics && %t | FileCheck -check-prefix=CHECK-A %s
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=uar && %t | FileCheck -check-prefix=CHECK-U %s
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered,atomics && %t | FileCheck -check-prefix=CHECK-CA %s
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered,uar && %t | FileCheck -check-prefix=CHECK-CU %s
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=atomics,uar && %t | FileCheck -check-prefix=CHECK-AU %s
+// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered,atomics,uar && %t | FileCheck -check-prefix=CHECK-CAU %s
+
+// CHECK-NOT: metadata add
+// CHECK: main
+// CHECK-NOT: metadata del
+
+// CHECK-C:  empty: features=0
+// CHECK-A-NOT:  empty:
+// CHECK-U-NOT:  empty:
+// CHECK-CA: empty: features=1
+// CHECK-CU: empty: features=0
+// CHECK-AU-NOT: empty:
+// CHECK-CAU:empty: features=1
+void empty() {
+}
+
+// CHECK-C:  normal: features=0
+// CHECK-A:  normal: features=1
+// CHECK-U:  normal: features=2
+// CHECK-CA: normal: features=1
+// CHECK-CU: normal: features=2
+// CHECK-AU: normal: features=3
+// CHECK-CAU:normal: features=3
+void normal() {
+  volatile int x;
+  x = 0;
+}
+
+// CHECK-C:   with_atomi

[PATCH] D136078: Use-after-return sanitizer binary metadata

2022-11-29 Thread Dmitry Vyukov via Phabricator via cfe-commits
dvyukov marked an inline comment as done.
dvyukov added inline comments.



Comment at: llvm/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp:19
+void non_empty_function() {
+  // Completely empty functions don't get uar metadata.
+  volatile int x;

melver wrote:
> Is this comment out of place?
If a function is completely empty, it won't be marked with UAR feature metadata.
This is super-primitive approximation of the actual analysis we should do (the 
function has addr-taken/escaped locals/arguments).
So I needed at least somebody for the function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136078

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


[PATCH] D136078: Use-after-return sanitizer binary metadata

2022-11-29 Thread Marco Elver via Phabricator via cfe-commits
melver accepted this revision.
melver added inline comments.



Comment at: llvm/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp:19
+void non_empty_function() {
+  // Completely empty functions don't get uar metadata.
+  volatile int x;

dvyukov wrote:
> melver wrote:
> > Is this comment out of place?
> If a function is completely empty, it won't be marked with UAR feature 
> metadata.
> This is super-primitive approximation of the actual analysis we should do 
> (the function has addr-taken/escaped locals/arguments).
> So I needed at least somebody for the function.
Ack


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136078

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


[clang] b12aea6 - [Clang] Implement CWG2654: Un-deprecation of compound volatile assignments

2022-11-29 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-11-29T17:15:39+01:00
New Revision: b12aea6659e1170ecbc773a4a363dd0def93daa9

URL: 
https://github.com/llvm/llvm-project/commit/b12aea6659e1170ecbc773a4a363dd0def93daa9
DIFF: 
https://github.com/llvm/llvm-project/commit/b12aea6659e1170ecbc773a4a363dd0def93daa9.diff

LOG: [Clang] Implement CWG2654: Un-deprecation of compound volatile assignments

Reviewed By: #clang-language-wg, erichkeane

Differential Revision: https://reviews.llvm.org/D138918

Added: 


Modified: 
clang-tools-extra/clangd/Diagnostics.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/test/CXX/drs/dr26xx.cpp
clang/test/SemaCXX/deprecated.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 031192f763e6e..c0951edcf5258 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -331,7 +331,6 @@ void setTags(clangd::Diag &D) {
   diag::warn_deprecated,
   diag::warn_deprecated_altivec_src_compat,
   diag::warn_deprecated_comma_subscript,
-  diag::warn_deprecated_compound_assign_volatile,
   diag::warn_deprecated_copy,
   diag::warn_deprecated_copy_with_dtor,
   diag::warn_deprecated_copy_with_user_provided_copy,

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 551070b27b2da..0e57feb6e085b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -607,6 +607,8 @@ C++ Language Changes in Clang
   conforming GNU extensions. Projects incompatible with C++17 can add
   ``-std=gnu++14`` to their build settings to restore the previous behaviour.
 - Implemented DR2358 allowing init captures in lambdas in default arguments.
+- implemented `DR2654 `_ which undeprecates
+  all compound assignements operations on volatile qualified variables.
 
 C++20 Feature Support
 ^

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 84ce58c69848c..15f85b778ccc6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7627,9 +7627,6 @@ def warn_deprecated_increment_decrement_volatile : 
Warning<
 def warn_deprecated_simple_assign_volatile : Warning<
   "use of result of assignment to object of volatile-qualified type %0 "
   "is deprecated">, InGroup;
-def warn_deprecated_compound_assign_volatile : Warning<
-  "compound assignment to object of volatile-qualified type %0 is deprecated">,
-  InGroup;
 def warn_deprecated_volatile_return : Warning<
   "volatile-qualified return type %0 is deprecated">,
   InGroup;

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 1ba88ad6cc2a6..06c70fbba6ffa 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13982,19 +13982,6 @@ QualType Sema::CheckAssignmentOperands(Expr *LHSExpr, 
ExprResult &RHS,
   //   type is deprecated unless the assignment is either a discarded-value
   //   expression or an unevaluated operand
   ExprEvalContexts.back().VolatileAssignmentLHSs.push_back(LHSExpr);
-} else {
-  // C++20 [expr.ass]p6:
-  //   [Compound-assignment] expressions are deprecated if E1 has
-  //   volatile-qualified type and op is not one of the bitwise
-  //   operators |, &, ˆ.
-  switch (Opc) {
-  case BO_OrAssign:
-  case BO_AndAssign:
-  case BO_XorAssign:
-break;
-  default:
-Diag(Loc, diag::warn_deprecated_compound_assign_volatile) << LHSType;
-  }
 }
   }
 

diff  --git a/clang/test/CXX/drs/dr26xx.cpp b/clang/test/CXX/drs/dr26xx.cpp
index 46d81e544b5c2..6aa0e5053bc9a 100644
--- a/clang/test/CXX/drs/dr26xx.cpp
+++ b/clang/test/CXX/drs/dr26xx.cpp
@@ -78,3 +78,13 @@ class X {
 };
 int i0 = f(0);   //expected-error {{no matching function for call to 'f'}}
 }
+
+namespace dr2654 { // dr2654: 16
+void f() {
+int neck, tail;
+volatile int brachiosaur;
+brachiosaur += neck;// OK
+brachiosaur -= neck;// OK
+brachiosaur |= neck;// OK
+}
+}

diff  --git a/clang/test/SemaCXX/deprecated.cpp 
b/clang/test/SemaCXX/deprecated.cpp
index 0c2eaaa53ca64..a93331023f7e2 100644
--- a/clang/test/SemaCXX/deprecated.cpp
+++ b/clang/test/SemaCXX/deprecated.cpp
@@ -186,10 +186,10 @@ namespace DeprecatedVolatile {
 --n; // cxx20-warning {{decrement of object of volatile-qualified type 
'volatile int' is deprecated}}
 n++; // cxx20-warning {{increment of object of volatile-qualified type 
'volatile int' is deprecated}}
 n--; // cxx20-warning {{decrement of object of volatile-qualified type 
'volatile int' is deprecated}}
-n += 5; // cxx20-

[PATCH] D138918: [Clang] Implement CWG2654: Un-deprecation of compound volatile assignments

2022-11-29 Thread Corentin Jabot 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 rGb12aea6659e1: [Clang] Implement CWG2654: Un-deprecation of 
compound volatile assignments (authored by cor3ntin).
Herald added subscribers: kadircet, arphaman.
Herald added a project: clang-tools-extra.

Changed prior to commit:
  https://reviews.llvm.org/D138918?vs=478562&id=478610#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138918

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/SemaCXX/deprecated.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15732,7 +15732,7 @@
 https://wg21.link/cwg2654";>2654
 DR
 Un-deprecation of compound volatile assignments
-Unknown
+Clang 16
   
 
 
Index: clang/test/SemaCXX/deprecated.cpp
===
--- clang/test/SemaCXX/deprecated.cpp
+++ clang/test/SemaCXX/deprecated.cpp
@@ -186,10 +186,10 @@
 --n; // cxx20-warning {{decrement of object of volatile-qualified type 'volatile int' is deprecated}}
 n++; // cxx20-warning {{increment of object of volatile-qualified type 'volatile int' is deprecated}}
 n--; // cxx20-warning {{decrement of object of volatile-qualified type 'volatile int' is deprecated}}
-n += 5; // cxx20-warning {{compound assignment to object of volatile-qualified type 'volatile int' is deprecated}}
-n *= 3; // cxx20-warning {{compound assignment to object of volatile-qualified type 'volatile int' is deprecated}}
-n /= 2; // cxx20-warning {{compound assignment to object of volatile-qualified type 'volatile int' is deprecated}}
-n %= 42; // cxx20-warning {{compound assignment to object of volatile-qualified type 'volatile int' is deprecated}}
+n += 5; // undeprecated as a DR in C++23
+n *= 3; // undeprecated as a DR in C++23
+n /= 2; // undeprecated as a DR in C++23
+n %= 42; // undeprecated as a DR in C++23
 n &= 2; // undeprecated as a DR in C++23
 n |= 2; // undeprecated as a DR in C++23
 n ^= 2; // undeprecated as a DR in C++23
Index: clang/test/CXX/drs/dr26xx.cpp
===
--- clang/test/CXX/drs/dr26xx.cpp
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -78,3 +78,13 @@
 };
 int i0 = f(0);   //expected-error {{no matching function for call to 'f'}}
 }
+
+namespace dr2654 { // dr2654: 16
+void f() {
+int neck, tail;
+volatile int brachiosaur;
+brachiosaur += neck;// OK
+brachiosaur -= neck;// OK
+brachiosaur |= neck;// OK
+}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -13982,19 +13982,6 @@
   //   type is deprecated unless the assignment is either a discarded-value
   //   expression or an unevaluated operand
   ExprEvalContexts.back().VolatileAssignmentLHSs.push_back(LHSExpr);
-} else {
-  // C++20 [expr.ass]p6:
-  //   [Compound-assignment] expressions are deprecated if E1 has
-  //   volatile-qualified type and op is not one of the bitwise
-  //   operators |, &, ˆ.
-  switch (Opc) {
-  case BO_OrAssign:
-  case BO_AndAssign:
-  case BO_XorAssign:
-break;
-  default:
-Diag(Loc, diag::warn_deprecated_compound_assign_volatile) << LHSType;
-  }
 }
   }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7627,9 +7627,6 @@
 def warn_deprecated_simple_assign_volatile : Warning<
   "use of result of assignment to object of volatile-qualified type %0 "
   "is deprecated">, InGroup;
-def warn_deprecated_compound_assign_volatile : Warning<
-  "compound assignment to object of volatile-qualified type %0 is deprecated">,
-  InGroup;
 def warn_deprecated_volatile_return : Warning<
   "volatile-qualified return type %0 is deprecated">,
   InGroup;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -607,6 +607,8 @@
   conforming GNU extensions. Projects incompatible with C++17 can add
   ``-std=gnu++14`` to their build settings to restore the previous behaviour.
 - Implemented DR2358 allowing init captures in lambdas in default arguments.
+- implemented `DR2654 

[PATCH] D138918: [Clang] Implement CWG2654: Un-deprecation of compound volatile assignments

2022-11-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Thanks Erich!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138918

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


[PATCH] D135953: [IncludeCleaner] Introduce decl to location mapping

2022-11-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 478611.
kadircet marked 6 inline comments as done.
kadircet added a comment.

- Leaving out all the pieces around signals as discussed.
- Update tests to use a LocateExample helper, have a test for macros.
- Get rid of residues in other test files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135953

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
  clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
@@ -0,0 +1,131 @@
+//===--- LocateSymbolTest.cpp -- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "AnalysisInternal.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace clang::include_cleaner {
+namespace {
+using testing::ElementsAre;
+using testing::ElementsAreArray;
+using testing::Pair;
+using testing::UnorderedElementsAre;
+
+// A helper for building ASTs and getting decls out of it by name. Example usage
+// looks like:
+//   LocateExample X("void ^foo();");
+//   Decl &Foo = X.findDecl("foo");
+//   X.points(); // returns all the points in annotated test input.
+struct LocateExample {
+private:
+  llvm::Annotations Target;
+  TestAST AST;
+
+public:
+  LocateExample(llvm::StringRef AnnotatedCode)
+  : Target(AnnotatedCode), AST([this] {
+  TestInputs Inputs(Target.code());
+  Inputs.ExtraArgs.push_back("-std=c++17");
+  return TestAST(Inputs);
+}()) {}
+
+  const Decl &findDecl(llvm::StringRef SymbolName) {
+const NamedDecl *DeclToLocate;
+struct MatchCB : public ast_matchers::MatchFinder::MatchCallback {
+  MatchCB(const NamedDecl *&Out) : Out(Out) {}
+  void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
+Out = Result.Nodes.getNodeAs("id");
+assert(Out);
+Out = llvm::cast(Out->getCanonicalDecl());
+  }
+  const NamedDecl *&Out;
+} CB(DeclToLocate);
+ast_matchers::MatchFinder Finder;
+Finder.addMatcher(ast_matchers::namedDecl(
+  ast_matchers::unless(ast_matchers::isImplicit()),
+  ast_matchers::hasName(SymbolName))
+  .bind("id"),
+  &CB);
+Finder.matchAST(AST.context());
+if (!DeclToLocate)
+  ADD_FAILURE() << "Couldn't find any decls with name: " << SymbolName;
+assert(DeclToLocate);
+return *DeclToLocate;
+  }
+
+  Macro findMacro(llvm::StringRef Name) {
+auto &PP = AST.preprocessor();
+auto *II = PP.getIdentifierInfo(Name);
+if (!II || !II->hasMacroDefinition()) {
+  ADD_FAILURE() << "Couldn't find any macros with name: " << Name;
+  return {};
+}
+auto MD = PP.getMacroDefinition(II);
+return {II, MD.getMacroInfo()->getDefinitionLoc()};
+  }
+
+  std::vector points() {
+auto &SM = AST.sourceManager();
+auto FID = SM.getMainFileID();
+auto Offsets = Target.points();
+std::vector Results;
+for (auto &Offset : Offsets)
+  Results.emplace_back(SM.getComposedLoc(FID, Offset));
+return Results;
+  }
+};
+
+TEST(LocateSymbol, Decl) {
+  // Looks for decl with name 'foo' and performs locateSymbol on it.
+  // Expects all the locations in the case to be returned as a location.
+  const llvm::StringLiteral Cases[] = {
+  "struct ^foo; struct ^foo {};",
+  "namespace ns { void ^foo(); void ^foo() {} }",
+  "enum class ^foo; enum class ^foo {};",
+  };
+
+  for (auto &Case : Cases) {
+LocateExample Test(Case);
+EXPECT_THAT(locateSymbol(Test.findDecl("foo")),
+ElementsAreArray(Test.points()));
+  }
+}
+
+TEST(LocateSymbol, Stdlib) {
+  LocateExample Test("namespace std { struct

[PATCH] D137213: [clang][modules] NFCI: Pragma diagnostic mappings: write/read FileID instead of SourceLocation

2022-11-29 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:6343
  "Invalid data, missing pragma diagnostic states");
-  SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]);
-  auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc);
-  assert(IDAndOffset.first.isValid() && "invalid FileID for transition");
-  assert(IDAndOffset.second == 0 && "not a start location for a FileID");
+  FileID FID = ReadFileID(F, Record, Idx);
+  assert(FID.isValid() && "invalid FileID for transition");

alexfh wrote:
> alexfh wrote:
> > jansvoboda11 wrote:
> > > alexfh wrote:
> > > > dexonsmith wrote:
> > > > > eaeltsin wrote:
> > > > > > This doesn't work as before, likely because ReadFileID doesn't do 
> > > > > > TranslateSourceLocation.
> > > > > > 
> > > > > > Our tests fail.
> > > > > > 
> > > > > > I tried calling TranslateSourceLocation here and the tests passed:
> > > > > > ```
> > > > > >   SourceLocation Loc = Diag.SourceMgr->getComposedLoc(FID, 0);
> > > > > >   SourceLocation Loc2 = TranslateSourceLocation(F, Loc);
> > > > > >   auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc2);
> > > > > > 
> > > > > >   // Note that we don't need to set up Parent/ParentOffset 
> > > > > > here, because
> > > > > >   // we won't be changing the diagnostic state within imported 
> > > > > > FileIDs
> > > > > >   // (other than perhaps appending to the main source file, 
> > > > > > which has no
> > > > > >   // parent).
> > > > > >   auto &F = Diag.DiagStatesByLoc.Files[IDAndOffset.first];
> > > > > > ```
> > > > > > 
> > > > > > Sorry I don't know the codebase, so this fix is definitely ugly :) 
> > > > > > But it shows the problem.
> > > > > > 
> > > > > I don't think that's the issue, since `ReadFileID()` calls 
> > > > > `TranslateFileID`, which should seems like it should be equivalent.
> > > > > 
> > > > > However, I notice that the post-increment for `Idx` got dropped! Can 
> > > > > you try replacing the line of code with the following and see if that 
> > > > > fixes your tests (without any extra TranslateSourceLocation logic)?
> > > > > ```
> > > > > lang=c++
> > > > > FileID FID = ReadFileID(F, Record, Idx++);
> > > > > ```
> > > > > 
> > > > > If so, maybe you can contribute that fix with a reduced testcase? I 
> > > > > suggest adding me, @vsapsai, @Bigcheese, and @jansvoboda11 as 
> > > > > reviewers.
> > > > > 
> > > > > @alexfh, maybe you can check if this fixes your tests as well?
> > > > > 
> > > > > (If this is the issue, it's a bit surprising we don't have existing 
> > > > > tests covering this case... and embarrassing I missed it when 
> > > > > reviewing initially!)
> > > > I've noticed the dropped `Idx` post-increment as well, but I went a 
> > > > step further and looked at the `ReadFileID` implementation, which is 
> > > > actually doing a post-increment itself, and accepts `Idx` by reference:
> > > > ```
> > > >   FileID ReadFileID(ModuleFile &F, const RecordDataImpl &Record,
> > > > unsigned &Idx) const {
> > > > return TranslateFileID(F, FileID::get(Record[Idx++]));
> > > >   }
> > > > ```
> > > > 
> > > > Thus, it seems to be correct. But what @eaeltsin  has found is actually 
> > > > a problem for us.  I'm currently trying to make an isolated test case, 
> > > > but it's quite tricky (as header modules are =\). It may be the case 
> > > > that our build setup relies on something clang doesn't explicitly 
> > > > promises, but the fact is that the behavior (as observed by our build 
> > > > setup) has changed. I'll try to revert the commit for now to get us 
> > > > unblocked and provide a test case as soon as I can.
> > > Thanks for helping out @dexonsmith, we did have the week off.
> > > 
> > > @eaeltsin @alexfhDone, are you able to provide the failing test case? I'm 
> > > happy to look into it and re-land this with a fix.
> > I've spent multiple hours trying to extract an observable test case. It 
> > turned out to be too hairy of a yaq to shave: for each compilation a 
> > separate sandboxed environment is created with a separate symlink tree with 
> > just the inputs necessary for that action. Some of the inputs are prebuilt 
> > module files (e.g. for libc++) that are version-locked with the compiler. 
> > So far @jgorbe and I could reduce this to four compilation steps with their 
> > own symlink trees with inputs. While I could figure out some of the factors 
> > that affect reproducibility (for example, symlinks are important, since 
> > making a deep copy of the input directories makes the issue disappear), it 
> > will take a few more hours of concentrated yak shaving to bring this to a 
> > shareable state. I'm not sure I have much more time to sink into 
> > investigating this. 
> > 
> > It seems like examining code based on @eaeltsin's finding may be a more 
> > fruitful path to synthesizing a regression test. Could you try following

[PATCH] D136554: Implement CWG2631

2022-11-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM!




Comment at: clang/include/clang/Sema/Sema.h:9654-9655
+return true;
+  if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() ||
+  Ctx.isUnevaluated())
+return false;

cor3ntin wrote:
> cor3ntin wrote:
> > aaron.ballman wrote:
> > > We repeat this pattern four times in this patch; perhaps we should make a 
> > > helper function for this predicate? Not certain of the best name for it, 
> > > but removing the duplication might not be a bad idea.
> > `isNotPotentiallyEvaluatedContext`? Something like that
> Actually, Maybe we should leave it as is in this patch, 
> and clean it up as part of 
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2564r0.html
> IE, I'm not sure i can come up with a completely correct name now.
That's fine by me; naming is hard.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

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


[PATCH] D138597: DebugInfo: Add/support new DW_LANG codes for recent C and C++ versions

2022-11-29 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D138597#3954269 , @probinson wrote:

> Hmmm I might be inclined to emit 17 and 20 only under not-strict-DWARF for 
> v5, although it makes the logic more complicated.  The codes have been 
> allocated but AFAICT the website doesn't have the new codes listed (I looked 
> at http://wiki.dwarfstd.org/index.php/DWARF_Language_Support which doesn't 
> even have all the v5 codes yet).

I think they're up here: https://dwarfstd.org/Languages.php (linked from the 
dwarfstd.org front page "DWARF V5 Language Codes and Requests")

> @aprantl do you have an opinion on this?  I tend to lean to the pedantic side 
> on this kind of thing, but I'm persuadable.

Yeah, I've certainly got mixed feelings - maybe we don't pick up these 
after-release language codes, and instead produce the new language encoding 
(which separates language from version) as an extension, alongside the 
old/in-the-dwarfv5-spec-document codes? So that a DWARFv5 consumer that 
contains only the DWARFv5-spec-document functionality and not the new codes, 
and a newer consumer can read the new parts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138597

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


[PATCH] D137348: [-Wunsafe-buffer-usage] Introduce an abstraction for fixable code patterns.

2022-11-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:63
+
+  Gadget(Kind K) : K(K) {}
+

NoQ wrote:
> aaron.ballman wrote:
> > Should this be an explicit constructor? (Same question applies below to 
> > derived classes as well.)
> What's the value of making it `explicit` given that it's an abstract class 
> that can't be constructed directly anyway?
None, I had missed that this was an abstract class and forgot to delete the 
comment here on the base class. It does apply to the (non-abstract) derived 
classes though.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:113
+  : UnsafeGadget(Kind::Increment),
+Op(Result.Nodes.getNodeAs("op")) {}
+

NoQ wrote:
> aaron.ballman wrote:
> > Should we make a `static constexpr const char *` for these strings so we 
> > can give it a name and ensure it's used consistently?
> I think it makes perfect sense to have different bind-names in different 
> classes. They don't all correspond to the same role the bound expression 
> plays.
Sorry, I was unclear. I meant a private data member of `IncrementGadget` so 
that the constructor and the `matcher()` functions use a named constant rather 
than a string literal.


Repository:
  rC Clang

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

https://reviews.llvm.org/D137348

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


[PATCH] D138200: [include-cleaner] Make use of locateSymbol in WalkUsed

2022-11-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 478614.
kadircet added a comment.

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138200

Files:
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/test/Inputs/foo2.h
  clang-tools-extra/include-cleaner/test/html.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -25,6 +25,7 @@
 
 namespace clang::include_cleaner {
 namespace {
+using testing::Contains;
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
@@ -32,8 +33,45 @@
   return "#pragma once\n" + Code.str();
 }
 
-TEST(WalkUsed, Basic) {
-  // FIXME: Have a fixture for setting up tests.
+class WalkUsedTest : public testing::Test {
+protected:
+  TestInputs Inputs;
+  PragmaIncludes PI;
+  WalkUsedTest() {
+Inputs.MakeAction = [this] {
+  struct Hook : public SyntaxOnlyAction {
+  public:
+Hook(PragmaIncludes *Out) : Out(Out) {}
+bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
+  Out->record(CI);
+  return true;
+}
+
+PragmaIncludes *Out;
+  };
+  return std::make_unique(&PI);
+};
+  }
+
+  llvm::DenseMap>
+  offsetToProviders(TestAST &AST, SourceManager &SM) {
+llvm::SmallVector TopLevelDecls;
+for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
+  TopLevelDecls.emplace_back(D);
+}
+llvm::DenseMap> OffsetToProviders;
+walkUsed(TopLevelDecls, /*MacroRefs=*/{}, &PI, SM,
+ [&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
+   auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
+   if (FID != SM.getMainFileID())
+ ADD_FAILURE() << "Reference outside of the main file!";
+   OffsetToProviders.try_emplace(Offset, Providers.vec());
+ });
+return OffsetToProviders;
+  }
+};
+
+TEST_F(WalkUsedTest, Basic) {
   llvm::Annotations Code(R"cpp(
   #include "header.h"
   #include "private.h"
@@ -43,7 +81,7 @@
 std::$vector^vector $vconstructor^v;
   }
   )cpp");
-  TestInputs Inputs(Code.code());
+  Inputs.Code = Code.code();
   Inputs.ExtraFiles["header.h"] = guard(R"cpp(
   void foo();
   namespace std { class vector {}; }
@@ -53,51 +91,53 @@
 class Private {};
   )cpp");
 
-  PragmaIncludes PI;
-  Inputs.MakeAction = [&PI] {
-struct Hook : public SyntaxOnlyAction {
-public:
-  Hook(PragmaIncludes *Out) : Out(Out) {}
-  bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
-Out->record(CI);
-return true;
-  }
-
-  PragmaIncludes *Out;
-};
-return std::make_unique(&PI);
-  };
   TestAST AST(Inputs);
-
-  llvm::SmallVector TopLevelDecls;
-  for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
-TopLevelDecls.emplace_back(D);
-  }
-
   auto &SM = AST.sourceManager();
-  llvm::DenseMap> OffsetToProviders;
-  walkUsed(TopLevelDecls, /*MacroRefs=*/{}, &PI, SM,
-   [&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
- auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
- EXPECT_EQ(FID, SM.getMainFileID());
- OffsetToProviders.try_emplace(Offset, Providers.vec());
-   });
-  auto &FM = AST.fileManager();
-  auto HeaderFile = Header(FM.getFile("header.h").get());
+  auto HeaderFile = Header(AST.fileManager().getFile("header.h").get());
+  auto PrivateFile = Header(AST.fileManager().getFile("private.h").get());
+  auto PublicFile = Header("\"path/public.h\"");
   auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID()));
   auto VectorSTL = Header(tooling::stdlib::Header::named("").value());
   EXPECT_THAT(
-  OffsetToProviders,
+  offsetToProviders(AST, SM),
   UnorderedElementsAre(
   Pair(Code.point("bar"), UnorderedElementsAre(MainFile)),
   Pair(Code.point("private"),
-   UnorderedElementsAre(Header("\"path/public.h\""),
-Header(FM.getFile("private.h").get(,
+   UnorderedElementsAre(PublicFile, PrivateFile)),
   Pair(Code.point("foo"), UnorderedElementsAre(HeaderFile)),
   Pair(Code.point("vector"), UnorderedElementsAre(VectorSTL)),
   Pair(Code.point("vconstructor"), UnorderedElementsAre(VectorSTL;
 }
 
+TEST_F(WalkUsedTest, MultipleProviders) {
+  llvm::Annotations Code(R"cpp(
+  #include "header1.h"
+  #include "header2.h"
+  void foo();
+
+  void bar() {
+$foo^foo();
+  }
+  )cpp");
+  Inputs.Code = Code.code();
+  Inputs.ExtraFiles["header1.h"] = guard

  1   2   3   >