[PATCH] D137693: [NFC] [C++20] [Modules] [clangd] Add test for code completion for C++20 Named Modules

2022-11-09 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu created this revision.
ChuanqiXu added reviewers: nridge, sammccall.
ChuanqiXu added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
ChuanqiXu requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

For issue https://github.com/llvm/llvm-project/issues/58723. Although we can't 
say the current status is good (enough), it should be good to add some tests to 
prevent the current status become worse.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137693

Files:
  clang-tools-extra/clangd/test/completion-modules.test
  clang-tools-extra/clangd/test/completion-modules2.test
  clang-tools-extra/clangd/test/completion-modules3.test
  clang-tools-extra/clangd/test/completion-modules4.test

Index: clang-tools-extra/clangd/test/completion-modules4.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/completion-modules4.test
@@ -0,0 +1,76 @@
+# Tests that the importee can't find the entities in the global module fragment.
+# RUN: rm -fr %t
+# RUN: mkdir -p %t
+# RUN: split-file %s %t
+#
+# RUN: sed "s|DIR|%/t|g" %t/compile_commands.json.tmpl > %t/compile_commands.json
+# RUN: sed "s|DIR|%/t|g" %t/definition.jsonrpc.tmpl > %t/definition.jsonrpc
+# RUN: %clang++ -std=c++20 %t/A.cppm --precompile -o %t/A.pcm
+# RUN: clangd -lit-test < %t/definition.jsonrpc  | FileCheck %t/definition.jsonrpc
+
+#--- foo.h
+void printA() {}
+
+#--- A.cppm
+module;
+#include "foo.h"
+export module A;
+
+
+#--- Use.cpp
+import A;
+void foo() {
+print
+}
+
+#--- compile_commands.json.tmpl
+[
+{
+  "directory": "DIR",
+  "command": "clang++  -fprebuilt-module-path=DIR -std=c++20 -o DIR/main.cpp.o -c DIR/Use.cpp",
+  "file": "DIR/Use.cpp"
+}
+]
+
+#--- definition.jsonrpc.tmpl
+{
+  "jsonrpc": "2.0",
+  "id": 0,
+  "method": "initialize",
+  "params": {
+"processId": 123,
+"rootPath": "clangd",
+"capabilities": {
+  "textDocument": {
+"completion": {
+  "completionItem": {
+"snippetSupport": true
+  }
+}
+  }
+},
+"trace": "off"
+  }
+}
+---
+{
+  "jsonrpc": "2.0",
+  "method": "textDocument/didOpen",
+  "params": {
+"textDocument": {
+  "uri": "file://DIR/Use.cpp",
+  "languageId": "cpp",
+  "version": 1,
+  "text": "import A;\nvoid foo() {\nprint\n}\n"
+}
+  }
+}
+
+# CHECK-NOT: "filterText": "printA"
+
+---
+{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file://DIR/Use.cpp"},"context":{"triggerKind":1},"position":{"line":2,"character":6}}}
+---
+{"jsonrpc":"2.0","id":2,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: clang-tools-extra/clangd/test/completion-modules3.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/completion-modules3.test
@@ -0,0 +1,97 @@
+# Tests that the importee can find the exported entities.
+# RUN: rm -fr %t
+# RUN: mkdir -p %t
+# RUN: split-file %s %t
+#
+# RUN: sed "s|DIR|%/t|g" %t/compile_commands.json.tmpl > %t/compile_commands.json
+# RUN: sed "s|DIR|%/t|g" %t/definition.jsonrpc.tmpl > %t/definition.jsonrpc
+# RUN: %clang++ -std=c++20 %t/A.cppm --precompile -o %t/A.pcm
+# RUN: clangd -lit-test < %t/definition.jsonrpc  | FileCheck -strict-whitespace %t/definition.jsonrpc
+
+#--- A.cppm
+export module A;
+void printA() {}
+
+#--- Use.cpp
+export module A:part;
+import A;
+void foo() {
+print
+}
+
+#--- compile_commands.json.tmpl
+[
+{
+  "directory": "DIR",
+  "command": "clang++  -fprebuilt-module-path=DIR -std=c++20 -o DIR/main.cpp.o -c DIR/Use.cpp",
+  "file": "DIR/Use.cpp"
+}
+]
+
+#--- definition.jsonrpc.tmpl
+{
+  "jsonrpc": "2.0",
+  "id": 0,
+  "method": "initialize",
+  "params": {
+"processId": 123,
+"rootPath": "clangd",
+"capabilities": {
+  "textDocument": {
+"completion": {
+  "completionItem": {
+"snippetSupport": true
+  }
+}
+  }
+},
+"trace": "off"
+  }
+}
+---
+{
+  "jsonrpc": "2.0",
+  "method": "textDocument/didOpen",
+  "params": {
+"textDocument": {
+  "uri": "file://DIR/Use.cpp",
+  "languageId": "cpp",
+  "version": 1,
+  "text": "export module A:part;\nimport A;\nvoid foo() {\nprint\n}\n"
+}
+  }
+}
+
+# CHECK:  "id": 1,
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": {
+# CHECK-NEXT:"isIncomplete": false,
+# CHECK-NEXT:"items": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"detail": "void",
+# CHECK-NEXT:"filterText": "printA",
+# CHECK-NEXT:"insertText": "printA()",
+# CHECK-NEXT:"insertTextFormat": 2,
+# CHECK-NEXT:"kind": 3,
+# CHECK-NEXT:"label": " printA()",
+# CHECK-NEXT:"score":
+# CHECK-NEXT:"sortText": "409fc4f5printA",
+# CHECK-NEXT: 

[PATCH] D137693: [NFC] [C++20] [Modules] [clangd] Add test for code completion for C++20 Named Modules

2022-11-09 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang-tools-extra/clangd/test/completion-modules2.test:13
+export module A;
+void printA() {}
+

It looks redundant at the first sight. I know we can reduce the size by the 
following trick:

```
#ifdef USE_EXPORT
export
#endif
void printA()

...
```

But this style will become very complex soon as long as the the size increases. 
An example could be found at: 
https://github.com/llvm/llvm-project/blob/main/clang/test/CXX/module/module.interface/p2.cpp.
 It was pretty painful for me to understand and edit the test cases. So I don't 
like such styles. I prefer the psychology that the somebody's redundancy is 
another's clearness. And the redundant test cases looks not a problem to me. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137693

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


[PATCH] D137386: [clang][Interp] Reject invalid declarations and expressions

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

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

https://reviews.llvm.org/D137386

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/functions.cpp


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -84,3 +84,18 @@
   return 5;
 }
 static_assert(a() == 5, "");
+
+constexpr int invalid() {
+  // Invalid expression in visit().
+  while(huh) {} // expected-error {{use of undeclared identifier}} \
+// ref-error {{use of undeclared identifier}}
+
+  return 0;
+}
+
+constexpr void invalid2() {
+  int i = 0;
+  // Invalid expression in discard().
+  huh(); // expected-error {{use of undeclared identifier}} \
+ // ref-error {{use of undeclared identifier}}
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -653,12 +653,18 @@
 }
 
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
+  if (E->containsErrors())
+return false;
+
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
 }
 
 template 
 bool ByteCodeExprGen::visit(const Expr *E) {
+  if (E->containsErrors())
+return false;
+
   OptionScope Scope(this, /*NewDiscardResult=*/false);
   return this->Visit(E);
 }
@@ -1226,8 +1232,10 @@
 /// We need to evaluate the initializer and return its value.
 template 
 bool ByteCodeExprGen::visitDecl(const VarDecl *VD) {
-  Optional VarT = classify(VD->getType());
+  if (VD->isInvalidDecl())
+return false;
 
+  Optional VarT = classify(VD->getType());
   // Create and initialize the variable.
   if (!this->visitVarDecl(VD))
 return false;


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -84,3 +84,18 @@
   return 5;
 }
 static_assert(a() == 5, "");
+
+constexpr int invalid() {
+  // Invalid expression in visit().
+  while(huh) {} // expected-error {{use of undeclared identifier}} \
+// ref-error {{use of undeclared identifier}}
+
+  return 0;
+}
+
+constexpr void invalid2() {
+  int i = 0;
+  // Invalid expression in discard().
+  huh(); // expected-error {{use of undeclared identifier}} \
+ // ref-error {{use of undeclared identifier}}
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -653,12 +653,18 @@
 }
 
 template  bool ByteCodeExprGen::discard(const Expr *E) {
+  if (E->containsErrors())
+return false;
+
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
 }
 
 template 
 bool ByteCodeExprGen::visit(const Expr *E) {
+  if (E->containsErrors())
+return false;
+
   OptionScope Scope(this, /*NewDiscardResult=*/false);
   return this->Visit(E);
 }
@@ -1226,8 +1232,10 @@
 /// We need to evaluate the initializer and return its value.
 template 
 bool ByteCodeExprGen::visitDecl(const VarDecl *VD) {
-  Optional VarT = classify(VD->getType());
+  if (VD->isInvalidDecl())
+return false;
 
+  Optional VarT = classify(VD->getType());
   // Create and initialize the variable.
   if (!this->visitVarDecl(VD))
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137386: [clang][Interp] Reject invalid declarations and expressions

2022-11-09 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/test/AST/Interp/functions.cpp:88-97
+constexpr int invalid() {
+  // Invalid expression in visit().
+  while(huh) {}
+}
+
+constexpr void invalid2() {
+  int i = 0;

aaron.ballman wrote:
> There should definitely be diagnostics here, right? There's a use of an 
> undeclared identifier in each function, but also, `invalid()` doesn't have a 
> return statement despite returning an `int`.
Right, I forgot to update the tests, sorry!


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

https://reviews.llvm.org/D137386

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


[PATCH] D137669: clang/cmake: Require pre-built test dependencies for stand-alone builds

2022-11-09 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

Also FYI, OpenMP has a bit of prior art in this area - see e.g. 
https://github.com/llvm/llvm-project/blob/main/openmp/cmake/OpenMPTesting.cmake#L27-L36.
 There it prints a warning at cmake time, disabling tests, saying why, and 
giving hints about how to fix it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137669

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


[PATCH] D137488: [clang][Interp] Array initialization via string literal

2022-11-09 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 474177.
tbaeder marked 4 inline comments as done.

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

https://reviews.llvm.org/D137488

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/literals.cpp


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -350,6 +350,13 @@
 #endif
 
 #pragma clang diagnostic pop
+
+  constexpr char foo[12] = "abc";
+  static_assert(foo[0] == 'a', "");
+  static_assert(foo[1] == 'b', "");
+  static_assert(foo[2] == 'c', "");
+  static_assert(foo[3] == 0, "");
+  static_assert(foo[11] == 0, "");
 };
 
 #if __cplusplus > 201402L
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1072,6 +1072,46 @@
 return false;
 }
 return true;
+  } else if (const auto *SL = dyn_cast(Initializer)) {
+const ConstantArrayType *CAT = 
Ctx.getASTContext().getAsConstantArrayType(SL->getType());
+assert(CAT && "a string literal that's not a constant array?");
+size_t NumElems = CAT->getSize().getZExtValue();
+
+// FIXME: There is a certain code duplication between here
+//   and Program::createGlobalString().
+size_t CharWidth = SL->getCharByteWidth();
+PrimType CharType;
+switch (CharWidth) {
+case 1:
+  CharType = PT_Sint8;
+  break;
+case 2:
+  CharType = PT_Uint16;
+  break;
+case 4:
+  CharType = PT_Uint32;
+  break;
+default:
+  llvm_unreachable("unsupported character width");
+}
+
+unsigned N = SL->getLength();
+for (size_t I = 0; I != NumElems; ++I) {
+  uint32_t CodePoint = I < N ? SL->getCodeUnit(I) : 0;
+  // TODO(Perf): 0 is implicit; we can just stop iterating at that point.
+  if (CharWidth == 1)
+this->emitConstSint8(CodePoint, SL);
+  else if (CharWidth == 2)
+this->emitConstUint16(CodePoint, SL);
+  else if (CharWidth == 4)
+this->emitConstUint32(CodePoint, SL);
+  else
+return false;
+
+  if (!this->emitInitElem(CharType, I, SL))
+return false;
+}
+return true;
   }
 
   assert(false && "Unknown expression for array initialization");


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -350,6 +350,13 @@
 #endif
 
 #pragma clang diagnostic pop
+
+  constexpr char foo[12] = "abc";
+  static_assert(foo[0] == 'a', "");
+  static_assert(foo[1] == 'b', "");
+  static_assert(foo[2] == 'c', "");
+  static_assert(foo[3] == 0, "");
+  static_assert(foo[11] == 0, "");
 };
 
 #if __cplusplus > 201402L
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1072,6 +1072,46 @@
 return false;
 }
 return true;
+  } else if (const auto *SL = dyn_cast(Initializer)) {
+const ConstantArrayType *CAT = Ctx.getASTContext().getAsConstantArrayType(SL->getType());
+assert(CAT && "a string literal that's not a constant array?");
+size_t NumElems = CAT->getSize().getZExtValue();
+
+// FIXME: There is a certain code duplication between here
+//   and Program::createGlobalString().
+size_t CharWidth = SL->getCharByteWidth();
+PrimType CharType;
+switch (CharWidth) {
+case 1:
+  CharType = PT_Sint8;
+  break;
+case 2:
+  CharType = PT_Uint16;
+  break;
+case 4:
+  CharType = PT_Uint32;
+  break;
+default:
+  llvm_unreachable("unsupported character width");
+}
+
+unsigned N = SL->getLength();
+for (size_t I = 0; I != NumElems; ++I) {
+  uint32_t CodePoint = I < N ? SL->getCodeUnit(I) : 0;
+  // TODO(Perf): 0 is implicit; we can just stop iterating at that point.
+  if (CharWidth == 1)
+this->emitConstSint8(CodePoint, SL);
+  else if (CharWidth == 2)
+this->emitConstUint16(CodePoint, SL);
+  else if (CharWidth == 4)
+this->emitConstUint32(CodePoint, SL);
+  else
+return false;
+
+  if (!this->emitInitElem(CharType, I, SL))
+return false;
+}
+return true;
   }
 
   assert(false && "Unknown expression for array initialization");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137488: [clang][Interp] Array initialization via string literal

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



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1133-1134
+  } else if (const auto *SL = dyn_cast(Initializer)) {
+const ArrayType *AT = SL->getType()->getAsArrayTypeUnsafe();
+const auto *CAT = cast(AT);
+size_t NumElems = CAT->getSize().getZExtValue();

aaron.ballman wrote:
> 
I feel like every time I write the code to get the `ConstantArrayType` from 
some array expression, I use a different version. I've never used 
`getAsConstantArrayType()` before :)



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1143
+case 1:
+  CharType = PT_Sint8;
+  break;

aaron.ballman wrote:
> Should we be looking at the sign of `char` to decide whether to use a uint8 
> or an sint8?
I was wondering about that too, but this code is copy/paste from `Program.cpp` 
where we create global storage for string literals. That code works, so I 
assume it will work here, too. Getting rid of the duplication might be nice 
though.


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

https://reviews.llvm.org/D137488

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


[PATCH] D137650: [clangd] Implement hover for string literals

2022-11-09 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry updated this revision to Diff 474179.
v1nh1shungry added a comment.

Improve the patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137650

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1300,7 +1300,6 @@
   "auto x = ^42.0i;",
   "auto x = ^42;",
   "auto x = ^nullptr;",
-  "auto x = ^\"asdf\";",
   };
 
   for (const auto &Test : Tests) {
@@ -1326,6 +1325,11 @@
  HI.Type = "char";
  HI.Value = "65 (0x41)";
}},
+  {"auto s = ^[[\"Hello, world!\"]]; // string literal",
+   [](HoverInfo &HI) {
+ HI.Name = "String Literal";
+ HI.Type = "const char[14]";
+   }},
   {
   R"cpp(// Local variable
 int main() {
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -785,7 +785,7 @@
  llvm::isa(E) ||
  llvm::isa(E) || llvm::isa(E) ||
  llvm::isa(E) || llvm::isa(E) ||
- llvm::isa(E) || llvm::isa(E);
+ llvm::isa(E);
 }
 
 llvm::StringLiteral getNameForExpr(const Expr *E) {
@@ -810,6 +810,15 @@
 return llvm::None;
 
   HoverInfo HI;
+  // Generate hover info for string literals showing
+  // its character's type and length
+  if (llvm::isa(E)) {
+HoverInfo::PrintedType PT;
+PT.Type = E->getType().getAsString(PP);
+HI.Type = PT;
+HI.Name = "String Literal";
+return HI;
+  }
   // For `this` expr we currently generate hover with pointee type.
   if (const CXXThisExpr *CTE = dyn_cast(E))
 return getThisExprHoverContents(CTE, AST.getASTContext(), PP);


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1300,7 +1300,6 @@
   "auto x = ^42.0i;",
   "auto x = ^42;",
   "auto x = ^nullptr;",
-  "auto x = ^\"asdf\";",
   };
 
   for (const auto &Test : Tests) {
@@ -1326,6 +1325,11 @@
  HI.Type = "char";
  HI.Value = "65 (0x41)";
}},
+  {"auto s = ^[[\"Hello, world!\"]]; // string literal",
+   [](HoverInfo &HI) {
+ HI.Name = "String Literal";
+ HI.Type = "const char[14]";
+   }},
   {
   R"cpp(// Local variable
 int main() {
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -785,7 +785,7 @@
  llvm::isa(E) ||
  llvm::isa(E) || llvm::isa(E) ||
  llvm::isa(E) || llvm::isa(E) ||
- llvm::isa(E) || llvm::isa(E);
+ llvm::isa(E);
 }
 
 llvm::StringLiteral getNameForExpr(const Expr *E) {
@@ -810,6 +810,15 @@
 return llvm::None;
 
   HoverInfo HI;
+  // Generate hover info for string literals showing
+  // its character's type and length
+  if (llvm::isa(E)) {
+HoverInfo::PrintedType PT;
+PT.Type = E->getType().getAsString(PP);
+HI.Type = PT;
+HI.Name = "String Literal";
+return HI;
+  }
   // For `this` expr we currently generate hover with pointee type.
   if (const CXXThisExpr *CTE = dyn_cast(E))
 return getThisExprHoverContents(CTE, AST.getASTContext(), PP);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137071: [clang][Interp] Implement missing compound assign operators

2022-11-09 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 474181.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D137071

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -469,5 +469,152 @@
 return (a -= a);
   }
   static_assert(subAll(213) == 0, "");
+
+  constexpr bool BoolOr(bool b1, bool b2) {
+bool a;
+a = b1;
+a |= b2;
+return a;
+  }
+  static_assert(BoolOr(true, true), "");
+  static_assert(BoolOr(true, false), "");
+  static_assert(BoolOr(false, true), "");
+  static_assert(!BoolOr(false, false), "");
+
+  constexpr int IntOr(unsigned a, unsigned b) {
+unsigned r;
+r = a;
+r |= b;
+return r;
+  }
+  static_assert(IntOr(10, 1) == 11, "");
+  static_assert(IntOr(1337, -1) == -1, "");
+  static_assert(IntOr(0, 12) == 12, "");
+
+  constexpr bool BoolAnd(bool b1, bool b2) {
+bool a;
+a = b1;
+a &= b2;
+return a;
+  }
+  static_assert(BoolAnd(true, true), "");
+  static_assert(!BoolAnd(true, false), "");
+  static_assert(!BoolAnd(false, true), "");
+  static_assert(!BoolAnd(false, false), "");
+
+  constexpr int IntAnd(unsigned a, unsigned b) {
+unsigned r;
+r = a;
+r &= b;
+return r;
+  }
+  static_assert(IntAnd(10, 1) == 0, "");
+  static_assert(IntAnd(1337, -1) == 1337, "");
+  static_assert(IntAnd(0, 12) == 0, "");
+
+  constexpr bool BoolXor(bool b1, bool b2) {
+bool a;
+a = b1;
+a ^= b2;
+return a;
+  }
+  static_assert(!BoolXor(true, true), "");
+  static_assert(BoolXor(true, false), "");
+  static_assert(BoolXor(false, true), "");
+  static_assert(!BoolXor(false, false), "");
+
+  constexpr int IntXor(unsigned a, unsigned b) {
+unsigned r;
+r = a;
+r ^= b;
+return r;
+  }
+  static_assert(IntXor(10, 1) == 11, "");
+  static_assert(IntXor(10, 10) == 0, "");
+  static_assert(IntXor(12, true) == 13, "");
+
+  constexpr bool BoolRem(bool b1, bool b2) {
+bool a;
+a = b1;
+a %= b2;
+return a;
+  }
+  static_assert(!BoolRem(true, true), "");
+  static_assert(!BoolRem(false, true), "");
+
+  constexpr int IntRem(unsigned a, unsigned b) {
+unsigned r;
+r = a;
+r %= b; // expected-note {{division by zero}} \
+// ref-note {{division by zero}}
+return r;
+  }
+  static_assert(IntRem(2, 2) == 0, "");
+  static_assert(IntRem(2, 1) == 0, "");
+  static_assert(IntRem(9, 7) == 2, "");
+  static_assert(IntRem(5, 0) == 0, ""); // expected-error {{not an integral constant expression}} \
+// expected-note {{in call to 'IntRem(5, 0)'}} \
+// ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'IntRem(5, 0)'}}
+
+  static_assert(IntRem(INT_MIN, -1) == 0, ""); // expected-error {{assertion failed}} \
+   // expected-note {{evaluates to}} \
+   // ref-error {{assertion failed}} \
+   // ref-note {{evaluates to}}
+
+
+  constexpr bool BoolDiv(bool b1, bool b2) {
+bool a;
+a = b1;
+a /= b2;
+return a;
+  }
+  static_assert(BoolDiv(true, true), "");
+  static_assert(!BoolDiv(false, true), "");
+
+  constexpr int IntDiv(unsigned a, unsigned b) {
+unsigned r;
+r = a;
+r /= b; // expected-note {{division by zero}} \
+// ref-note {{division by zero}}
+return r;
+  }
+  static_assert(IntDiv(2, 2) == 1, "");
+  static_assert(IntDiv(12, 20) == 0, "");
+  static_assert(IntDiv(2, 1) == 2, "");
+  static_assert(IntDiv(9, 7) == 1, "");
+  static_assert(IntDiv(5, 0) == 0, ""); // expected-error {{not an integral constant expression}} \
+// expected-note {{in call to 'IntDiv(5, 0)'}} \
+// ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'IntDiv(5, 0)'}}
+
+  static_assert(IntDiv(INT_MIN, -1) == 0, "");
+
+  constexpr bool BoolMul(bool b1, bool b2) {
+bool a;
+a = b1;
+a *= b2;
+return a;
+  }
+  static_assert(BoolMul(true, true), "");
+  static_assert(!BoolMul(true, false), "");
+  static_assert(!BoolMul(false, true), "");
+  static_assert(!BoolMul(false, false), "");
+
+  constexpr int IntMul(int a, int b) {
+int r;
+r = a;
+r *= b; // expected-note {{is outside the range of representable values of type 'int'}} \
+// ref-note {{is outside the range of representable values of type 'int'}}
+return r;
+  }
+  static_assert(IntMul(2, 2) == 4, "");
+  static_assert(IntMul(12, 20) == 240, "");
+  st

[PATCH] D137232: [clang][Interp] Support inc/dec operators on pointers

2022-11-09 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 474182.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D137232

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/arrays.cpp

Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -215,9 +215,6 @@
 static_assert(b.a[1].a == 12, "");
 
 namespace IncDec {
-  // FIXME: Pointer arithmethic needs to be supported in inc/dec
-  //   unary operators
-#if 0
   constexpr int getNextElem(const int *A, int I) {
 const int *B = (A + I);
 ++B;
@@ -225,6 +222,59 @@
   }
   constexpr int E[] = {1,2,3,4};
 
-  static_assert(getNextElem(E, 1) == 3);
-#endif
+  static_assert(getNextElem(E, 1) == 3, "");
+
+  constexpr int getFirst() {
+const int *e = E;
+return *(e++);
+  }
+  static_assert(getFirst() == 1, "");
+
+  constexpr int getFirst2() {
+const int *e = E;
+e++;
+return *e;
+  }
+  static_assert(getFirst2() == 2, "");
+
+  constexpr int getSecond() {
+const int *e = E;
+return *(++e);
+  }
+  static_assert(getSecond() == 2, "");
+
+  constexpr int getSecond2() {
+const int *e = E;
+++e;
+return *e;
+  }
+  static_assert(getSecond2() == 2, "");
+
+  constexpr int getLast() {
+const int *e = E + 3;
+return *(e--);
+  }
+  static_assert(getLast() == 4, "");
+
+  constexpr int getLast2() {
+const int *e = E + 3;
+e--;
+return *e;
+  }
+  static_assert(getLast2() == 3, "");
+
+  constexpr int getSecondToLast() {
+const int *e = E + 3;
+return *(--e);
+  }
+  static_assert(getSecondToLast() == 3, "");
+
+  constexpr int getSecondToLast2() {
+const int *e = E + 3;
+--e;
+return *e;
+  }
+  static_assert(getSecondToLast2() == 3, "");
+
+
 };
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -395,12 +395,21 @@
 // [Pointer, Integral] -> [Pointer]
 def SubOffset : AluOpcode;
 
-// Pointer, Pointer] - [Integral]
+// [Pointer, Pointer] -> [Integral]
 def SubPtr : Opcode {
   let Types = [IntegerTypeClass];
   let HasGroup = 1;
 }
 
+// [Pointer] -> [Pointer]
+def IncPtr : Opcode {
+  let HasGroup = 0;
+}
+// [Pointer] -> [Pointer]
+def DecPtr : Opcode {
+  let HasGroup = 0;
+}
+
 //===--===//
 // Binary operators.
 //===--===//
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -105,6 +105,8 @@
 /// Interpreter entry point.
 bool Interpret(InterpState &S, APValue &Result);
 
+enum class ArithOp { Add, Sub };
+
 //===--===//
 // Add, Sub, Mul
 //===--===//
@@ -1084,6 +1086,34 @@
   return OffsetHelper(S, OpPC);
 }
 
+template 
+static inline bool IncDecPtrHelper(InterpState &S, CodePtr OpPC) {
+  using OneT = Integral<8, false>;
+  const Pointer &Ptr = S.Stk.pop();
+
+  // Get the current value on the stack.
+  S.Stk.push(Ptr.deref());
+
+  // Now the current Ptr again and a constant 1.
+  // FIXME: We shouldn't have to push these two on the stack.
+  S.Stk.push(Ptr.deref());
+  S.Stk.push(OneT::from(1));
+  if (!OffsetHelper(S, OpPC))
+return false;
+
+  // Store the new value.
+  Ptr.deref() = S.Stk.pop();
+  return true;
+}
+
+static inline bool IncPtr(InterpState &S, CodePtr OpPC) {
+  return IncDecPtrHelper(S, OpPC);
+}
+
+static inline bool DecPtr(InterpState &S, CodePtr OpPC) {
+  return IncDecPtrHelper(S, OpPC);
+}
+
 /// 1) Pops a Pointer from the stack.
 /// 2) Pops another Pointer from the stack.
 /// 3) Pushes the different of the indices of the two pointers on the stack.
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1352,24 +1352,44 @@
   const Expr *SubExpr = E->getSubExpr();
   Optional T = classify(SubExpr->getType());
 
-  // TODO: Support pointers for inc/dec operators.
   switch (E->getOpcode()) {
   case UO_PostInc: { // x++
 if (!this->visit(SubExpr))
   return false;
 
+if (T == PT_Ptr) {
+  if (!this->emitIncPtr(E))
+return false;
+
+  return DiscardResult ? this->emitPopPtr(E) : true;
+}
+
 return DiscardResult ? this->emitIncPop(*T, E) : this->emitInc(*T, E);
   }
   case UO_PostDec: { // x--
 if (!this->visit(SubExpr))
   return false;
 
+if (T ==

[PATCH] D137153: [X86] Support -march=sierraforest, grandridge, graniterapids.

2022-11-09 Thread Freddy, Ye 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 rG84a18a260e46: [X86] Support -march=sierraforest, grandridge, 
graniterapids. (authored by FreddyYe).

Changed prior to commit:
  https://reviews.llvm.org/D137153?vs=474155&id=474183#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137153

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGen/target-builtin-noerror.c
  clang/test/Driver/x86-march.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros.c
  compiler-rt/lib/builtins/cpu_model.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/X86TargetParser.def
  llvm/include/llvm/Support/X86TargetParser.h
  llvm/lib/Support/Host.cpp
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -19,6 +19,9 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=lakemont 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=raptorlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=meteorlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=sierraforest 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=nocona 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=core2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
@@ -56,6 +59,9 @@
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=knm 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=raptorlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=meteorlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=sierraforest 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 define void @foo() {
   ret void
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -943,6 +943,12 @@
   list SPRFeatures =
 !listconcat(ICXFeatures, SPRAdditionalFeatures);
 
+  // Graniterapids
+  list GNRAdditionalFeatures = [FeatureAMXFP16,
+  FeaturePREFETCHI];
+  list GNRFeatures =
+!listconcat(SPRFeatures, GNRAdditionalFeatures);
+
   // Atom
   list AtomFeatures = [FeatureX87,
  FeatureCX8,
@@ -1050,6 +1056,19 @@
   list ADLFeatures =
 !listconcat(TRMFeatures, ADLAdditionalFeatures);
 
+  // Sierraforest
+  list SRFAdditionalFeatures = [FeatureCMPCCXADD,
+  FeatureAVXIFMA,
+  FeatureAVXNECONVERT,
+  FeatureAVXVNNIINT8];
+  list SRFFeatures =
+!listconcat(ADLFeatures, SRFAdditionalFeatures);
+
+  // Grandridge
+  list GRRAdditionalFeatures = [FeatureRAOINT];
+  list GRRFeatures =
+!listconcat(SRFFeatures, GRRAdditionalFeatures);
+
   // Knights Landing
   list KNLFeatures = [FeatureX87,
 FeatureCX8,
@@ -1441,6 +1460,10 @@
 ProcessorFeatures.GLPTuning>;
 def : ProcModel<"tremont", SLMModel, ProcessorFeatures.TRMFeatures,
 ProcessorFeatures.TRMTuning>;
+def : ProcModel<"sierraforest", AlderlakePModel, ProcessorFeatures.SRFFeatures,
+ProcessorFeatures.TRMTuning>;
+def : ProcModel<"grandridge", AlderlakePModel, ProcessorFeatures.GRRFeatures,
+

[PATCH] D137697: Move the isSelfContained function from clangd to libtooling.

2022-11-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: kadircet, sammccall.
Herald added a subscriber: arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added projects: clang, clang-tools-extra.

We plan to reuse it in the include-cleaner library, this patch moves
this functionality from clangd to libtooling, so that this piece of code can be
shared among all clang tools.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137697

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang/include/clang/Tooling/Inclusions/Header.h
  clang/lib/Tooling/Inclusions/CMakeLists.txt
  clang/lib/Tooling/Inclusions/Header.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/HeaderTest.cpp

Index: clang/unittests/Tooling/HeaderTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/HeaderTest.cpp
@@ -0,0 +1,64 @@
+//===- unittest/Tooling/HeaderTest.cpp ===//
+//
+// 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 "clang/Tooling/Inclusions/Header.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace tooling {
+namespace {
+
+TEST(HeaderTest, IsSelfContained) {
+  TestInputs Inputs;
+  Inputs.Code = R"cpp(
+  #include "headerguard.h"
+  #include "pragmaonce.h"
+
+  #include "bad.h"
+  #include "unguarded.h"
+  )cpp";
+
+  Inputs.ExtraFiles["headerguard.h"] = R"cpp(
+  #ifndef HEADER_H
+  #define HEADER_H
+
+  #endif HEADER_H
+  )cpp";
+  Inputs.ExtraFiles["pragmaonce.h"] = R"cpp(
+  #pragma once
+  )cpp";
+  Inputs.ExtraFiles["unguarded.h"] = "";
+  Inputs.ExtraFiles["bad.h"] = R"cpp(
+  #pragma once
+
+  #if defined(INSIDE_H)
+  #error "Only ... can be included directly"
+  #endif
+  )cpp";
+
+  TestAST AST(Inputs);
+  const auto &SM = AST.sourceManager();
+  auto &FM = SM.getFileManager();
+  auto &HI = AST.preprocessor().getHeaderSearchInfo();
+
+  EXPECT_TRUE(tooling::isSelfContainedHeader(FM.getFile("headerguard.h").get(),
+ SM, HI));
+  EXPECT_TRUE(
+  tooling::isSelfContainedHeader(FM.getFile("pragmaonce.h").get(), SM, HI));
+
+  EXPECT_FALSE(
+  tooling::isSelfContainedHeader(FM.getFile("unguarded.h").get(), SM, HI));
+  EXPECT_FALSE(
+  tooling::isSelfContainedHeader(FM.getFile("bad.h").get(), SM, HI));
+}
+
+} // namespace
+} // namespace tooling
+} // namespace clang
Index: clang/unittests/Tooling/CMakeLists.txt
===
--- clang/unittests/Tooling/CMakeLists.txt
+++ clang/unittests/Tooling/CMakeLists.txt
@@ -16,6 +16,7 @@
   DiagnosticsYamlTest.cpp
   ExecutionTest.cpp
   FixItTest.cpp
+  HeaderTest.cpp
   HeaderIncludesTest.cpp
   StandardLibraryTest.cpp
   LexicallyOrderedRecursiveASTVisitorTest.cpp
Index: clang/lib/Tooling/Inclusions/Header.cpp
===
--- /dev/null
+++ clang/lib/Tooling/Inclusions/Header.cpp
@@ -0,0 +1,66 @@
+//===--- Header.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 "clang/Tooling/Inclusions/Header.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/HeaderSearch.h"
+
+namespace clang::tooling {
+namespace {
+
+// Is Line an #if or #ifdef directive?
+// FIXME: This makes headers with #ifdef LINUX/WINDOWS/MACOS marked as non
+// self-contained and is probably not what we want.
+bool isIf(llvm::StringRef Line) {
+  Line = Line.ltrim();
+  if (!Line.consume_front("#"))
+return false;
+  Line = Line.ltrim();
+  return Line.startswith("if");
+}
+
+// Is Line an #error directive mentioning includes?
+bool isErrorAboutInclude(llvm::StringRef Line) {
+  Line = Line.ltrim();
+  if (!Line.consume_front("#"))
+return false;
+  Line = Line.ltrim();
+  if (!Line.startswith("error"))
+return false;
+  return Line.contains_insensitive(
+  "includ"); // Matches "include" or "including".
+}
+
+// Heuristically headers that only want to be included via an umbrella.
+bool isDontIncludeMeHeader(llvm::StringRef Content) {
+  llvm::StringRef Line;
+  // Only sniff up to 100 lines or 10KB.
+  Content = Content.take_front(

[PATCH] D137698: [include-cleaner] Add self-contained file support for PragmaIncludes.

2022-11-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang-tools-extra.

Based on https://reviews.llvm.org/D137697


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137698

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/CMakeLists.txt
  clang-tools-extra/include-cleaner/lib/Record.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
@@ -68,6 +68,10 @@
   }
 };
 
+std::string guard(const llvm::StringRef Code) {
+  return "#pragma once\n" + Code.str();
+}
+
 TEST_F(WalkUsedTest, Basic) {
   llvm::Annotations Code(R"cpp(
   #include "header.h"
@@ -78,14 +82,14 @@
   }
   )cpp");
   Inputs.Code = Code.code();
-  Inputs.ExtraFiles["header.h"] = R"cpp(
+  Inputs.ExtraFiles["header.h"] = guard(R"cpp(
   void foo();
   namespace std { class vector {}; }
-  )cpp";
-  Inputs.ExtraFiles["private.h"] = R"cpp(
-// IWYU pragma: private, include "path/public.h"
-class Private {};
-  )cpp";
+  )cpp");
+  Inputs.ExtraFiles["private.h"] = guard(R"cpp(
+  // IWYU pragma: private, include "path/public.h"
+  class Private {};
+  )cpp");
   TestAST AST(Inputs);
 
   auto HeaderFile = Header(AST.fileManager().getFile("header.h").get());
@@ -123,21 +127,26 @@
   Inputs.Code = R"cpp(
 #include "header1.h"
 #include "header2.h"
+#include "header3.h"
   )cpp";
-  Inputs.ExtraFiles["header1.h"] = R"cpp(
-// IWYU pragma: private, include "path/public.h"
-  )cpp";
-  Inputs.ExtraFiles["header2.h"] = R"cpp(
-#include "detail1.h" // IWYU pragma: export
+  Inputs.ExtraFiles["header1.h"] = guard(R"cpp(
+  // IWYU pragma: private, include "path/public.h"
+  )cpp");
+  Inputs.ExtraFiles["header2.h"] = guard(R"cpp(
+  #include "detail1.h" // IWYU pragma: export
 
-// IWYU pragma: begin_exports
-#include "detail2.h"
-// IWYU pragma: end_exports
+  // IWYU pragma: begin_exports
+  #include "detail2.h"
+  // IWYU pragma: end_exports
 
-#include "normal.h"
-  )cpp";
+  #include "normal.h"
+  )cpp");
+  Inputs.ExtraFiles["header3.h"] = guard(R"cpp(
+  #include "imp.inc"
+  )cpp");
   Inputs.ExtraFiles["normal.h"] = Inputs.ExtraFiles["detail1.h"] =
-  Inputs.ExtraFiles["detail2.h"] = "";
+  Inputs.ExtraFiles["detail2.h"] = guard("");
+  Inputs.ExtraFiles["imp.inc"] = "";
   TestAST AST(Inputs);
   const auto &SM = AST.sourceManager();
   auto &FM = SM.getFileManager();
@@ -156,6 +165,9 @@
   EXPECT_THAT(findIncludeHeaders(SourceLocFromFile("detail2.h"), SM, PI),
   UnorderedElementsAre(Header(FM.getFile("header2.h").get()),
Header(FM.getFile("detail2.h").get(;
+  // header3.h is the first #includer for the  non self-contained header imp.inc
+  EXPECT_THAT(findIncludeHeaders(SourceLocFromFile("imp.inc"), SM, PI),
+  UnorderedElementsAre(Header(FM.getFile("header3.h").get(;
 
   EXPECT_THAT(findIncludeHeaders(SourceLocFromFile("normal.h"), SM, PI),
   UnorderedElementsAre(Header(FM.getFile("normal.h").get(;
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
@@ -14,6 +14,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Tooling/Inclusions/Header.h"
 
 namespace clang::include_cleaner {
 
@@ -35,12 +36,26 @@
 class PragmaIncludes::RecordPragma : public PPCallbacks, public CommentHandler {
 public:
   RecordPragma(const CompilerInstance &CI, PragmaIncludes *Out)
-  : SM(CI.getSourceManager()), Out(Out) {}
+  : SM(CI.getSourceManager()),
+HeaderInfo(CI.getPreprocessor().getHeaderSearchInfo()), Out(Out) {}
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override {
 InMainFile = SM.isWrittenInMainFile(Loc);
+
+if (Reason == PPCallbacks::ExitFile) {
+  // At file exit time HeaderSearchInfo is valid and can be used to
+  // determine whether the file was a self-contained header or not.
+  if (const FileEntry *FE = SM.getFileEntryForID(PrevFID)) {
+if (tooling::isSelfContainedHeader(FE, SM, HeaderInfo))
+  Out->NonSelfContainedFiles.erase(
+  SM.getFileEntryForID(PrevFID)->getUniqueID());
+else
+  Out->NonSelfContainedFiles.insert(
+  SM.

[PATCH] D124730: [RISCV][NFC] Refactor RISC-V vector intrinsic utils.

2022-11-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Hi @kito-cheng, can you please let us know if you're working on a fix here (and 
whether it seems to be close)? otherwise i am planning to revert this and 
consequent changes, as it's clearly introducing data races.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124730

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


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

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



Comment at: clang/lib/AST/Interp/Opcodes.td:502
+  let Types = [AluTypeClass];
+  let Args = [ArgFltSemantics];
+  let HasGroup = 1;

jcranmer-intel wrote:
> tbaeder wrote:
> > sepavloff wrote:
> > > tbaeder wrote:
> > > > jcranmer-intel wrote:
> > > > > Integer-to-floating point conversion is dependent on rounding 
> > > > > mode--consider `(float)UINT_MAX`.
> > > > This test succeeds here, whether I use `-frounding-math` or not:
> > > > 
> > > > ```
> > > > constexpr float f = (float)4294967295;
> > > > static_assert(f == (float)4.2949673E+9);
> > > > ```
> > > > How can I test this behavior?
> > > You can use `#pragma STDC FENV_ROUND`. See 
> > > `clang/test/AST/const-fpfeatures.c` as an example.
> > Why does it work here to compare both `f` and `f2` to the same value? 
> > https://godbolt.org/z/zdsf1sK7r
> `FENV_ROUND` is a new feature of C2x, so it doesn't look like it's properly 
> handled in gcc or clang yet. (It's for sure not handled in clang--the code to 
> convert a floating-point literal into an `APFloat` hardcodes default rounding 
> mode in its call.)
> 
> Dynamic rounding mode shows you the difference: 
> https://godbolt.org/z/856xM8KTh
So I can't test this at all because it first needs work in clang to do the 
float->APFloat conversion correctly?


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

https://reviews.llvm.org/D134859

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


[PATCH] D137677: [include-cleaner] add macro symbols and implicit refs to HTML report

2022-11-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/include-cleaner/lib/HTMLReport.cpp:243
+for (Header H : T.Providers) {
+  OS << "Candidate: ";
+  escapeString(llvm::to_string(H));

It seems noisy to print it even there is only one candidate, maybe exclude it 
if there is only one candidate?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137677

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


[PATCH] D137071: [clang][Interp] Implement missing compound assign operators

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

In D137071#3915565 , @aaron.ballman 
wrote:

> Precommit CI looks to have potentially found something interesting here.

There might be one of my local patches missing, but it looks like it's somehow 
not applying this patch, which is weird.




Comment at: clang/test/AST/Interp/literals.cpp:553
+  static_assert(IntRem(2, 1) == 0, "");
+  static_assert(IntRem(9, 7) == 2, "");
+

aaron.ballman wrote:
> aaron.ballman wrote:
> > ```
> > static_assert(IntRem(9, 0) == 12, ""); // Not constexpr
> > static_assert(IntRem(__INT_MIN__, -1) == 12, ""); // Not constexpr
> > ```
> Missed the test for __INT_MIN__ and -1?
for rem, clang doesn't diagnose anything: https://godbolt.org/z/rhe5ezc54


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

https://reviews.llvm.org/D137071

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


[clang] 4057998 - Fix D132221 rebase: Add flags to enable Assignment Tracking

2022-11-09 Thread via cfe-commits

Author: OCHyams
Date: 2022-11-09T09:28:41Z
New Revision: 40579983555c7ed510e47bf2a0354bc1c0ec4d47

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

LOG: Fix D132221 rebase: Add flags to enable Assignment Tracking

The flags were not set up properly after rebasing the patch, causing bot
failures for D132226, for example:

https://lab.llvm.org/buildbot/#/builders/109/builds/50251

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ca16bd9765598..70bad936346b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5634,13 +5634,13 @@ def fctor_dtor_return_this : Flag<["-"], 
"fctor-dtor-return-this">,
"and non-deleting destructors. (No effect on Microsoft ABI)">,
   MarshallingInfoFlag>;
 
-} // let Flags = [CC1Option, NoDriverOption]
-
 def fexperimental_assignment_tracking :
   Flag<["-"], "fexperimental-assignment-tracking">, Group,
   HelpText<"Enable assignment tracking debug info">,
   MarshallingInfoFlag>;
 
+} // let Flags = [CC1Option, NoDriverOption]
+
 
//===--===//
 // Dependency Output Options
 
//===--===//



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


[clang] 4b6b2b1 - Reapply: [Assignment Tracking][7/*] Add assignment tracking functionality to clang

2022-11-09 Thread via cfe-commits

Author: OCHyams
Date: 2022-11-09T09:28:41Z
New Revision: 4b6b2b1a425a2eabb3a4b995bb05f4f53e313afa

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

LOG: Reapply: [Assignment Tracking][7/*] Add assignment tracking functionality 
to clang

Reverted in 98fa95492f3bbd5befdeb36c88a3ac5ef2740b4e.

The Assignment Tracking debug-info feature is outlined in this RFC:

https://discourse.llvm.org/t/
rfc-assignment-tracking-a-better-way-of-specifying-variable-locations-in-ir

This patch plumbs the AssignmentTrackingPass (AKA declare-to-assign), added in
the previous patch in this set, into the optimisation pipeline from
clang. clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp is the
main test for this patch.

Note: while clang (with the help of the declare-to-assign pass) can now emit
Assignment Tracking metadata, the llvm middle and back ends don't yet
understand it.

Reviewed By: jmorse

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

Added: 
clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp
clang/test/CodeGen/assignment-tracking/flag.cpp
clang/test/CodeGen/assignment-tracking/memcpy-fragment.cpp
clang/test/CodeGen/assignment-tracking/nested-scope.cpp
clang/test/Driver/assignment-tracking-opts.c

Modified: 
clang/lib/CodeGen/BackendUtil.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index f5c125da10da6..eb444c829381f 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -30,6 +30,7 @@
 #include "llvm/CodeGen/SchedulerRegistry.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
 #include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DebugInfo.h"
 #include "llvm/IR/IRPrintingPasses.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/IR/Module.h"
@@ -830,6 +831,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   SI.registerCallbacks(PIC, &FAM);
   PassBuilder PB(TM.get(), PTO, PGOOpt, &PIC);
 
+  if (CodeGenOpts.EnableAssignmentTracking) {
+PB.registerPipelineStartEPCallback(
+[&](ModulePassManager &MPM, OptimizationLevel Level) {
+  MPM.addPass(AssignmentTrackingPass());
+});
+  }
+
   // Enable verify-debuginfo-preserve-each for new PM.
   DebugifyEachInstrumentation Debugify;
   DebugInfoPerPass DebugInfoBeforePass;

diff  --git a/clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp 
b/clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp
new file mode 100644
index 0..5cb4e9456a93f
--- /dev/null
+++ b/clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp
@@ -0,0 +1,96 @@
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone 
-O0 \
+// RUN: -emit-llvm  -fexperimental-assignment-tracking %s -o - 
  \
+// RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg"
+
+// Based on llvm/test/DebugInfo/Generic/track-assignments.ll - check that using
+// -Xclang -fexperimental-assignment-tracking results in emitting (or, as it is
+// set up currently, telling llvm to create) assignment tracking metadata.
+//
+// See the original test for more info.
+
+struct Inner { int A, B; };
+struct Outer { Inner A, B; };
+struct Large { int A[10]; };
+struct LCopyCtor { int A[4]; LCopyCtor(); LCopyCtor(LCopyCtor const &); };
+int Value, Index, Cond;
+Inner InnerA, InnerB;
+Large L;
+
+void zeroInit() { int Z[3] = {0, 0, 0}; }
+// CHECK-LABEL: define dso_local void @_Z8zeroInitv
+// CHECK:   %Z = alloca [3 x i32], align 4, !DIAssignID ![[ID_0:[0-9]+]]
+// CHECK-NEXT:  call void @llvm.dbg.assign(metadata i1 undef, metadata 
![[VAR_0:[0-9]+]], metadata !DIExpression(), metadata ![[ID_0]], metadata ptr 
%Z, metadata !DIExpression())
+// CHECK:@llvm.memset{{.*}}, !DIAssignID ![[ID_1:[0-9]+]]
+// CHECK-NEXT:   call void @llvm.dbg.assign(metadata i8 0, metadata 
![[VAR_0]], metadata !DIExpression(), metadata ![[ID_1]], metadata ptr %Z, 
metadata !DIExpression())
+
+void memcpyInit() { int A[4] = {0, 1, 2, 3}; }
+// CHECK-LABEL: define dso_local void @_Z10memcpyInitv
+// CHECK:   %A = alloca [4 x i32], align 16, !DIAssignID ![[ID_2:[0-9]+]]
+// CHECK-NEXT:  call void @llvm.dbg.assign(metadata i1 undef, metadata 
![[VAR_1:[0-9]+]], metadata !DIExpression(), metadata ![[ID_2]], metadata ptr 
%A, metadata !DIExpression())
+// CHECK:@llvm.memcpy{{.*}}, !DIAssignID ![[ID_3:[0-9]+]]
+// CHECK-NEXT:   call void @llvm.dbg.assign(metadata i1 undef, metadata 
![[VAR_1]], metadata !DIExpression(), metadata ![[ID_3]], metadata ptr %A, 
metadata !DIExpression())
+
+void setField() {
+  Outer O;
+  O.A.B = Value;
+}
+// CHECK-LABEL: define dso_local void @_Z8setFieldv
+// CHECK:   %O = alloca %struct.Outer, align 4, !DIAssignID 
![[ID_4:[0-9]+

[PATCH] D137269: [Clang][AArch64][Darwin] Enable GlobalISel by default for Darwin ARM64 platforms.

2022-11-09 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

It looks like GISel crashes when building `llvm-test-suite` with -O3 on ARM64. 
If it isn't trivial to fix we should probably revert the patch to bring things 
back to green.

Reproducer:

  ; llc  -global-isel -O3
  target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
  target triple = "arm64-apple-macosx"
  
  define void @widget(ptr %arg, i1 %arg1) {
  bb:
br i1 %arg1, label %bb2, label %bb3
  
  bb2:  ; preds = %bb
%tmp = icmp slt i32 0, 0
br i1 %tmp, label %bb3, label %bb9
  
  bb3:  ; preds = %bb2, %bb
%tmp4 = phi i32 [ 1, %bb ], [ 0, %bb2 ]
%tmp5 = zext i32 %tmp4 to i64
br label %bb6
  
  bb6:  ; preds = %bb6, %bb3
%tmp7 = getelementptr i32, ptr %arg, i64 %tmp5
%tmp8 = getelementptr i32, ptr %tmp7, i64 4
store <4 x i32> zeroinitializer, ptr %tmp8, align 4
br label %bb6
  
  bb9:  ; preds = %bb2
ret void
  }

https://llvm.godbolt.org/z/d5oTWxvaG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137269

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


[PATCH] D137269: [Clang][AArch64][Darwin] Enable GlobalISel by default for Darwin ARM64 platforms.

2022-11-09 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

I'd like to object to enabling this via the frontend. This means that non-clang 
frontends will now use a non-default configuration that is not extensively 
tested by upstream anymore.

If you don't want to change tests, you can adjust the RUN lines to explicitly 
disable globalisel.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137269

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


[PATCH] D80392: [mips][mc][clang] Use pc-relative relocations in .eh_frame

2022-11-09 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa added a comment.

In D80392#3876782 , @wzssyqa wrote:

> I don't think that we need that option: what we need to do is to update the 
> old tools.

the ld.bfd support R_MIPS_PC32 here.
I think that we can just switch the behavior without any condtions.

And I am working to fix GCC/GAS for it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80392

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


[clang] 9d1ff78 - [AArch64] Add support for the Cortex-X3 CPU

2022-11-09 Thread Victor Campos via cfe-commits

Author: Victor Campos
Date: 2022-11-09T11:33:48Z
New Revision: 9d1ff787e5c2b19e19e5475b9c36f4e5c2a07d23

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

LOG: [AArch64] Add support for the Cortex-X3 CPU

Cortex-X3 is an Armv9-A AArch64 CPU.

This patch introduces support for Cortex-X3.

Technical Reference Manual: 
https://developer.arm.com/documentation/101593/latest

Reviewed By: dmgreen

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/test/Driver/aarch64-mcpu.c
clang/test/Misc/target-invalid-cpu-note.c
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/lib/Support/Host.cpp
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64Subtarget.cpp
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0d464e9fb7d51..774b575b52609 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -744,11 +744,11 @@ Arm and AArch64 Support in Clang
 - ``-march`` values for targeting armv2, armv2A, armv3 and armv3M have been 
removed.
   Their presence gave the impression that Clang can correctly generate code for
   them, which it cannot.
-- Add driver and tuning support for Neoverse V2 via the flag 
``-mcpu=neoverse-v2``.
-  Native detection is also supported via ``-mcpu=native``.
 - Support has been added for the following processors (-mcpu identifiers in 
parenthesis):
 
   * Arm Cortex-A715 (cortex-a715).
+  * Arm Cortex-X3 (cortex-x3).
+  * Arm Neoverse V2 (neoverse-v2)
 
 Floating Point Support in Clang
 ---

diff  --git a/clang/test/Driver/aarch64-mcpu.c 
b/clang/test/Driver/aarch64-mcpu.c
index b40c579acdf00..d0f898357570a 100644
--- a/clang/test/Driver/aarch64-mcpu.c
+++ b/clang/test/Driver/aarch64-mcpu.c
@@ -41,6 +41,8 @@
 // CORTEXX1: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-x1"
 // RUN: %clang -target aarch64 -mcpu=cortex-x1c  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEXX1C %s
 // CORTEXX1C: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-x1c"
+// RUN: %clang -target aarch64 -mcpu=cortex-x3 -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEXX3 %s
+// CORTEXX3: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-x3"
 // RUN: %clang -target aarch64 -mcpu=cortex-a78  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEXA78 %s
 // CORTEXA78: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-a78"
 // RUN: %clang -target aarch64 -mcpu=cortex-a78c  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEX-A78C %s

diff  --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 1d7d89ebb1eb0..f48a54d452f68 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, 
cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, 
cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-r82, cortex-x1, 
cortex-x1c, cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, 
neoverse-v1, neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, 
apple-a11, apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-m1, 
apple-m2, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, 
kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, 
thunderxt83, tsv110, a64fx, carmel, ampere1, grace{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, 
cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, 
cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-r82, cortex-x1, 
cortex-x1c, cortex-x2, cortex-x3, neoverse-e1, neoverse-n1, neoverse-n2, 
neoverse-512tvb, neoverse-v1, neoverse-v2, cyclone, apple-a7, apple-a8, 
apple-a9, apple-a10, apple-a11, apple-a12, apple-a13, apple-a14, apple-a15, 
apple-a16, apple-m1, apple-m2, apple-s4, apple-s5, exynos-m3, exynos-m4, 
exynos-m5, falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, 
thunderxt88, thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, 
grace{{$}}
 
 // RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE_

[PATCH] D136589: [AArch64] Add support for the Cortex-X3 CPU

2022-11-09 Thread Victor Campos 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 rG9d1ff787e5c2: [AArch64] Add support for the Cortex-X3 CPU 
(authored by vhscampos).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136589

Files:
  clang/docs/ReleaseNotes.rst
  clang/test/Driver/aarch64-mcpu.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/lib/Support/Host.cpp
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1086,6 +1086,19 @@
  AArch64::AEK_SVE2BITPERM | AArch64::AEK_SSBS |
  AArch64::AEK_SB | AArch64::AEK_FP16FML,
  "9-A"),
+ARMCPUTestParams("cortex-x3", "armv9-a", "neon-fp-armv8",
+ AArch64::AEK_CRC | AArch64::AEK_FP | AArch64::AEK_BF16 |
+ AArch64::AEK_SIMD | AArch64::AEK_RAS |
+ AArch64::AEK_LSE | AArch64::AEK_RDM |
+ AArch64::AEK_RCPC | AArch64::AEK_DOTPROD |
+ AArch64::AEK_MTE | AArch64::AEK_PAUTH |
+ AArch64::AEK_SVE | AArch64::AEK_SVE2 |
+ AArch64::AEK_SVE2BITPERM | AArch64::AEK_SB |
+ AArch64::AEK_PROFILE | AArch64::AEK_PERFMON |
+ AArch64::AEK_I8MM | AArch64::AEK_FP16 |
+ AArch64::AEK_FP16FML | AArch64::AEK_PREDRES |
+ AArch64::AEK_FLAGM | AArch64::AEK_SSBS,
+ "9-A"),
 ARMCPUTestParams("cyclone", "armv8-a", "crypto-neon-fp-armv8",
  AArch64::AEK_NONE | AArch64::AEK_CRYPTO |
  AArch64::AEK_FP | AArch64::AEK_SIMD,
@@ -1309,7 +1322,7 @@
  "8.2-A")));
 
 // Note: number of CPUs includes aliases.
-static constexpr unsigned NumAArch64CPUArchs = 60;
+static constexpr unsigned NumAArch64CPUArchs = 61;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/lib/Target/AArch64/AArch64Subtarget.h
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.h
+++ llvm/lib/Target/AArch64/AArch64Subtarget.h
@@ -69,6 +69,7 @@
 CortexX1,
 CortexX1C,
 CortexX2,
+CortexX3,
 ExynosM3,
 Falkor,
 Kryo,
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -144,6 +144,7 @@
   case CortexA710:
   case CortexA715:
   case CortexX2:
+  case CortexX3:
 PrefFunctionLogAlignment = 4;
 VScaleForTuning = 1;
 PrefLoopLogAlignment = 5;
Index: llvm/lib/Target/AArch64/AArch64.td
===
--- llvm/lib/Target/AArch64/AArch64.td
+++ llvm/lib/Target/AArch64/AArch64.td
@@ -799,6 +799,13 @@
   FeatureLSLFast,
   FeaturePostRAScheduler]>;
 
+def TuneX3 : SubtargetFeature<"cortex-x3", "ARMProcFamily", "CortexX3",
+  "Cortex-X3 ARM processors", [
+   FeatureLSLFast,
+   FeatureFuseAdrpAdd,
+   FeatureFuseAES,
+   FeaturePostRAScheduler]>;
+
 def TuneA64FX : SubtargetFeature<"a64fx", "ARMProcFamily", "A64FX",
  "Fujitsu A64FX processors", [
  FeaturePostRAScheduler,
@@ -1127,6 +1134,11 @@
  FeatureMatMulInt8, FeatureBF16, FeatureAM,
  FeatureMTE, FeatureETE, FeatureSVE2BitPerm,
  FeatureFP16FML];
+  list X3 =   [HasV9_0aOps, FeatureSVE, FeatureNEON,
+ FeaturePerfMon, FeatureETE, FeatureTRBE,
+ FeatureSPE, FeatureBF16, FeatureMatMulInt8,
+ FeatureMTE, FeatureSVE2BitPerm, FeatureFullFP16,
+ FeatureFP16FML];
   list A64FX= [HasV8_2aOps, FeatureFPARMv8, FeatureNEON,
  FeatureSHA2, FeaturePerfMon, FeatureFullFP16,
  FeatureSVE, FeatureComplxNum];
@@ -1259,6 +1271,8 @@
 

[clang] 103bbdd - [ARM] Move Triple::getARMCPUForArch into ARMTargetParser

2022-11-09 Thread Tomas Matheson via cfe-commits

Author: Tomas Matheson
Date: 2022-11-09T11:52:35Z
New Revision: 103bbddde66f4157b52c2b6d7532c1dd0dfcaf94

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

LOG: [ARM] Move Triple::getARMCPUForArch into ARMTargetParser

This is very backend specific so either belongs in Toolchains/ARM or in
ARMTargetParser. Since it is used in lldb, ARMTargetParser made more sense.

This is part of an effort to move information about ARM/AArch64 architecture
versions, extensions and CPUs into their respective TargetParsers.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/ARM.cpp
lldb/source/Utility/ArchSpec.cpp
llvm/include/llvm/ADT/Triple.h
llvm/include/llvm/Support/ARMTargetParser.h
llvm/lib/Support/ARMTargetParser.cpp
llvm/lib/Support/Triple.cpp
llvm/unittests/ADT/TripleTest.cpp
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 67dec7cadada5..bbf466ba847de 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -938,7 +938,7 @@ StringRef arm::getARMCPUForMArch(StringRef Arch, const 
llvm::Triple &Triple) {
 
   // We need to return an empty string here on invalid MArch values as the
   // various places that call this function can't cope with a null result.
-  return Triple.getARMCPUForArch(MArch);
+  return llvm::ARM::getARMCPUForArch(Triple, MArch);
 }
 
 /// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targeting.
@@ -971,7 +971,8 @@ llvm::ARM::ArchKind arm::getLLVMArchKindForARM(StringRef 
CPU, StringRef Arch,
 if (ArchKind == llvm::ARM::ArchKind::INVALID)
   // In case of generic Arch, i.e. "arm",
   // extract arch from default cpu of the Triple
-  ArchKind = llvm::ARM::parseCPUArch(Triple.getARMCPUForArch(ARMArch));
+  ArchKind =
+  llvm::ARM::parseCPUArch(llvm::ARM::getARMCPUForArch(Triple, 
ARMArch));
   } else {
 // FIXME: horrible hack to get around the fact that Cortex-A7 is only an
 // armv7k triple if it's actually been specified via "-arch armv7k".

diff  --git a/lldb/source/Utility/ArchSpec.cpp 
b/lldb/source/Utility/ArchSpec.cpp
index 126bedc209232..e1d7ee3ee276d 100644
--- a/lldb/source/Utility/ArchSpec.cpp
+++ b/lldb/source/Utility/ArchSpec.cpp
@@ -16,6 +16,7 @@
 #include "llvm/BinaryFormat/COFF.h"
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/BinaryFormat/MachO.h"
+#include "llvm/Support/ARMTargetParser.h"
 #include "llvm/Support/Compiler.h"
 
 using namespace lldb;
@@ -638,7 +639,7 @@ std::string ArchSpec::GetClangTargetCPU() const {
   }
 
   if (GetTriple().isARM())
-cpu = GetTriple().getARMCPUForArch("").str();
+cpu = llvm::ARM::getARMCPUForArch(GetTriple(), "").str();
   return cpu;
 }
 

diff  --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h
index dc96398dba999..5aba2730c5a8b 100644
--- a/llvm/include/llvm/ADT/Triple.h
+++ b/llvm/include/llvm/ADT/Triple.h
@@ -1024,12 +1024,6 @@ class Triple {
   ///  architecture if no such variant can be found.
   llvm::Triple getLittleEndianArchVariant() const;
 
-  /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
-  ///
-  /// \param Arch the architecture name (e.g., "armv7s"). If it is an empty
-  /// string then the triple's arch name is used.
-  StringRef getARMCPUForArch(StringRef Arch = StringRef()) const;
-
   /// Tests whether the target triple is little endian.
   ///
   /// \returns true if the triple is little endian, false otherwise.

diff  --git a/llvm/include/llvm/Support/ARMTargetParser.h 
b/llvm/include/llvm/Support/ARMTargetParser.h
index 5fb4090395c07..32cc31db5936a 100644
--- a/llvm/include/llvm/Support/ARMTargetParser.h
+++ b/llvm/include/llvm/Support/ARMTargetParser.h
@@ -296,6 +296,12 @@ unsigned parseArchVersion(StringRef Arch);
 void fillValidCPUArchList(SmallVectorImpl &Values);
 StringRef computeDefaultTargetABI(const Triple &TT, StringRef CPU);
 
+/// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
+///
+/// \param Arch the architecture name (e.g., "armv7s"). If it is an empty
+/// string then the triple's arch name is used.
+StringRef getARMCPUForArch(const llvm::Triple &Triple, StringRef MArch = {});
+
 } // namespace ARM
 } // namespace llvm
 

diff  --git a/llvm/lib/Support/ARMTargetParser.cpp 
b/llvm/lib/Support/ARMTargetParser.cpp
index a68244a5e38af..43cbb409b0f04 100644
--- a/llvm/lib/Support/ARMTargetParser.cpp
+++ b/llvm/lib/Support/ARMTargetParser.cpp
@@ -643,3 +643,72 @@ StringRef ARM::computeDefaultTargetABI(const Triple &TT, 
StringRef CPU) {
 return "aapcs";
   }
 }
+
+StringRef ARM::getARMC

[PATCH] D137564: [ARM] Move Triple::getARMCPUForArch into ARMTargetParser

2022-11-09 Thread Tomas Matheson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG103bbddde66f: [ARM] Move Triple::getARMCPUForArch into 
ARMTargetParser (authored by tmatheson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137564

Files:
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  lldb/source/Utility/ArchSpec.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/Support/ARMTargetParser.h
  llvm/lib/Support/ARMTargetParser.cpp
  llvm/lib/Support/Triple.cpp
  llvm/unittests/ADT/TripleTest.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -6,12 +6,13 @@
 //
 //===--===//
 
+#include "llvm/Support/TargetParser.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Support/AArch64TargetParser.h"
 #include "llvm/Support/ARMBuildAttributes.h"
 #include "llvm/Support/FormatVariadic.h"
-#include "llvm/Support/TargetParser.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
@@ -871,6 +872,70 @@
   EXPECT_EQ(5u, ARM::parseArchVersion(ARMArch[i]));
 }
 
+TEST(TargetParserTest, getARMCPUForArch) {
+  // Platform specific defaults.
+  {
+llvm::Triple Triple("arm--nacl");
+EXPECT_EQ("cortex-a8", ARM::getARMCPUForArch(Triple));
+  }
+  {
+llvm::Triple Triple("arm--openbsd");
+EXPECT_EQ("cortex-a8", ARM::getARMCPUForArch(Triple));
+  }
+  {
+llvm::Triple Triple("armv6-unknown-freebsd");
+EXPECT_EQ("arm1176jzf-s", ARM::getARMCPUForArch(Triple));
+  }
+  {
+llvm::Triple Triple("thumbv6-unknown-freebsd");
+EXPECT_EQ("arm1176jzf-s", ARM::getARMCPUForArch(Triple));
+  }
+  {
+llvm::Triple Triple("armebv6-unknown-freebsd");
+EXPECT_EQ("arm1176jzf-s", ARM::getARMCPUForArch(Triple));
+  }
+  {
+llvm::Triple Triple("arm--win32");
+EXPECT_EQ("cortex-a9", ARM::getARMCPUForArch(Triple));
+EXPECT_EQ("generic", ARM::getARMCPUForArch(Triple, "armv8-a"));
+  }
+  // Some alternative architectures
+  {
+llvm::Triple Triple("armv7k-apple-ios9");
+EXPECT_EQ("cortex-a7", ARM::getARMCPUForArch(Triple));
+  }
+  {
+llvm::Triple Triple("armv7k-apple-watchos3");
+EXPECT_EQ("cortex-a7", ARM::getARMCPUForArch(Triple));
+  }
+  {
+llvm::Triple Triple("armv7k-apple-tvos9");
+EXPECT_EQ("cortex-a7", ARM::getARMCPUForArch(Triple));
+  }
+  // armeb is permitted, but armebeb is not
+  {
+llvm::Triple Triple("armeb-none-eabi");
+EXPECT_EQ("arm7tdmi", ARM::getARMCPUForArch(Triple));
+  }
+  {
+llvm::Triple Triple("armebeb-none-eabi");
+EXPECT_EQ("", ARM::getARMCPUForArch(Triple));
+  }
+  {
+llvm::Triple Triple("armebv6eb-none-eabi");
+EXPECT_EQ("", ARM::getARMCPUForArch(Triple));
+  }
+  // xscaleeb is permitted, but armebxscale is not
+  {
+llvm::Triple Triple("xscaleeb-none-eabi");
+EXPECT_EQ("xscale", ARM::getARMCPUForArch(Triple));
+  }
+  {
+llvm::Triple Triple("armebxscale-none-eabi");
+EXPECT_EQ("", ARM::getARMCPUForArch(Triple));
+  }
+}
+
 class AArch64CPUTestFixture
 : public ::testing::TestWithParam {};
 
Index: llvm/unittests/ADT/TripleTest.cpp
===
--- llvm/unittests/ADT/TripleTest.cpp
+++ llvm/unittests/ADT/TripleTest.cpp
@@ -1855,70 +1855,6 @@
 Triple::normalize("aarch64-linux-android21"));
 }
 
-TEST(TripleTest, getARMCPUForArch) {
-  // Platform specific defaults.
-  {
-llvm::Triple Triple("arm--nacl");
-EXPECT_EQ("cortex-a8", Triple.getARMCPUForArch());
-  }
-  {
-llvm::Triple Triple("arm--openbsd");
-EXPECT_EQ("cortex-a8", Triple.getARMCPUForArch());
-  }
-  {
-llvm::Triple Triple("armv6-unknown-freebsd");
-EXPECT_EQ("arm1176jzf-s", Triple.getARMCPUForArch());
-  }
-  {
-llvm::Triple Triple("thumbv6-unknown-freebsd");
-EXPECT_EQ("arm1176jzf-s", Triple.getARMCPUForArch());
-  }
-  {
-llvm::Triple Triple("armebv6-unknown-freebsd");
-EXPECT_EQ("arm1176jzf-s", Triple.getARMCPUForArch());
-  }
-  {
-llvm::Triple Triple("arm--win32");
-EXPECT_EQ("cortex-a9", Triple.getARMCPUForArch());
-EXPECT_EQ("generic", Triple.getARMCPUForArch("armv8-a"));
-  }
-  // Some alternative architectures
-  {
-llvm::Triple Triple("armv7k-apple-ios9");
-EXPECT_EQ("cortex-a7", Triple.getARMCPUForArch());
-  }
-  {
-llvm::Triple Triple("armv7k-apple-watchos3");
-EXPECT_EQ("cortex-a7", Triple.getARMCPUForArch());
-  }
-  {
-llvm::Triple Triple("armv7k-apple-tvos9");
-EXPECT_EQ("cortex-a7", Triple.getARMCPUForArch());
-  }
-  // armeb is permitted, but armebeb is not
-  {
-llvm::Triple Triple("armeb-none-eabi");
-EXPECT_EQ("arm7td

[PATCH] D137563: [clang][Interp] Check declarations for constexpr-ness in Load() instructions

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

This is wrong if the (constant) initializer is for a legitimate non-constexpr 
variable declaration. We do a load in `visitDecl()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137563

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


[PATCH] D137706: [clang][Interp] Implement IntegralToPointer casts

2022-11-09 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a subscriber: inglorion.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The pointers created through such a cast are not usable in a constant 
expression as far as I know, but we need to be able to express them. Do that 
via  a `Pointer` with a `nullptr` pointee and an `Offset` that is the given 
integer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137706

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/Pointer.cpp
  clang/lib/AST/Interp/Pointer.h
  clang/test/Sema/const-eval-64.c

Index: clang/test/Sema/const-eval-64.c
===
--- clang/test/Sema/const-eval-64.c
+++ clang/test/Sema/const-eval-64.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux -fexperimental-constant-interpreter %s
 
 #define EVAL_EXPR(testno, expr) int test##testno = sizeof(struct{char qq[expr];});
 
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -67,6 +67,7 @@
   Pointer() {}
   Pointer(Block *B);
   Pointer(Block *B, unsigned BaseAndOffset);
+  Pointer(unsigned Offset);
   Pointer(const Pointer &P);
   Pointer(Pointer &&P);
   ~Pointer();
@@ -79,6 +80,9 @@
 
   /// Offsets a pointer inside an array.
   Pointer atIndex(unsigned Idx) const {
+if (!Pointee)
+  return Pointer(nullptr, 0,
+ Offset + Idx); // Offset + Idx, 0);//Base + Idx);
 if (Base == RootPtrMark)
   return Pointer(Pointee, RootPtrMark, getDeclDesc()->getSize());
 unsigned Off = Idx * elemSize();
@@ -160,14 +164,17 @@
   }
 
   /// Checks if the pointer is null.
-  bool isZero() const { return Pointee == nullptr; }
+  bool isZero() const { return Pointee == nullptr && Offset == 0; }
   /// Checks if the pointer is live.
   bool isLive() const { return Pointee && !Pointee->IsDead; }
   /// Checks if the item is a field in an object.
   bool isField() const { return Base != 0 && Base != RootPtrMark; }
 
   /// Accessor for information about the declaration site.
-  Descriptor *getDeclDesc() const { return Pointee->Desc; }
+  Descriptor *getDeclDesc() const {
+assert(Pointee);
+return Pointee->Desc;
+  }
   SourceLocation getDeclLoc() const { return getDeclDesc()->getLocation(); }
 
   /// Returns a pointer to the object of which this pointer is a field.
@@ -232,12 +239,12 @@
   }
 
   /// Checks if the innermost field is an array.
-  bool inArray() const { return getFieldDesc()->IsArray; }
+  bool inArray() const { return Pointee ? getFieldDesc()->IsArray : false; }
   /// Checks if the structure is a primitive array.
   bool inPrimitiveArray() const { return getFieldDesc()->isPrimitiveArray(); }
   /// Checks if the structure is an array of unknown size.
   bool isUnknownSizeArray() const {
-return getFieldDesc()->isUnknownSizeArray();
+return Pointee ? getFieldDesc()->isUnknownSizeArray() : false;
   }
   /// Checks if the pointer points to an array.
   bool isArrayElement() const { return Base != Offset; }
@@ -288,12 +295,20 @@
   }
 
   /// Returns the number of elements.
-  unsigned getNumElems() const { return getSize() / elemSize(); }
+  unsigned getNumElems() const {
+if (Pointee)
+  return getSize() / elemSize();
+
+return std::numeric_limits::max();
+  }
 
   Block *block() const { return Pointee; }
 
   /// Returns the index into an array.
   int64_t getIndex() const {
+if (!Pointee)
+  return 0;
+
 if (isElementPastEnd())
   return 1;
 if (auto ElemSize = elemSize())
@@ -307,7 +322,7 @@
   }
 
   /// Checks if the pointer is an out-of-bounds element pointer.
-  bool isElementPastEnd() const { return Offset == PastEndMark; }
+  bool isElementPastEnd() const { return Pointee && Offset == PastEndMark; }
 
   /// Dereferences the pointer, if it's live.
   template  T &deref() const {
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -19,6 +19,8 @@
 Pointer::Pointer(Block *Pointee, unsigned BaseAndOffset)
 : Pointer(Pointee, BaseAndOffset, BaseAndOffset) {}
 
+Pointer::Pointer(unsigned Offset) : Pointer(nullptr, Offset, Offset) {}
+
 Pointer::Pointer(const Pointer &P) : Pointer(P.Pointee, P.Base, P.Offset) {}
 
 Pointer::Pointer(Pointer &&P)
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -522,6 +522,11 @@
 

[PATCH] D137706: [clang][Interp] Implement IntegralToPointer casts

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



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:188-192
+// == in C
+if (const auto *BOP = dyn_cast(SubExpr);
+BOP && BOP->isEqualityOp())
+  return this->visit(SubExpr);
+[[fallthrough]];

This is a tiny hack to get the C test working.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137706

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


[clang] 0f4f246 - [OpenCL] Guard read_write image3d with cl_khr_3d_image_writes

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

Author: Sven van Haastregt
Date: 2022-11-09T13:17:59Z
New Revision: 0f4f246783fa5866f6fa5db4043e898060cdf98d

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

LOG: [OpenCL] Guard read_write image3d with cl_khr_3d_image_writes

Not all `read_write image3d_t` occurrences in opencl-c.h were guarded
with `cl_khr_3d_image_writes`.  Align with `-fdeclare-opencl-builtins`.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 2afe0231cd74b..288bb18bc654e 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -15388,9 +15388,11 @@ float4 __ovld __purefn read_imagef(read_write 
image2d_array_t, int4);
 int4 __ovld __purefn read_imagei(read_write image2d_array_t, int4);
 uint4 __ovld __purefn read_imageui(read_write image2d_array_t, int4);
 
+#ifdef cl_khr_3d_image_writes
 float4 __ovld __purefn read_imagef(read_write image3d_t, int4);
 int4 __ovld __purefn read_imagei(read_write image3d_t, int4);
 uint4 __ovld __purefn read_imageui(read_write image3d_t, int4);
+#endif // cl_khr_3d_image_writes
 
 #ifdef cl_khr_depth_images
 float __ovld __purefn read_imagef(read_write image2d_depth_t, int2);
@@ -15431,9 +15433,11 @@ uint4 __ovld __purefn read_imageui(read_write 
image2d_array_t, sampler_t, float4
 
 float __ovld __purefn read_imagef(read_write image2d_array_depth_t, sampler_t, 
float4, float);
 
+#ifdef cl_khr_3d_image_writes
 float4 __ovld __purefn read_imagef(read_write image3d_t, sampler_t, float4, 
float);
 int4 __ovld __purefn read_imagei(read_write image3d_t, sampler_t, float4, 
float);
 uint4 __ovld __purefn read_imageui(read_write image3d_t, sampler_t, float4, 
float);
+#endif // cl_khr_3d_image_writes
 
 float4 __ovld __purefn read_imagef(read_write image1d_t, sampler_t, float, 
float, float);
 int4 __ovld __purefn read_imagei(read_write image1d_t, sampler_t, float, 
float, float);
@@ -15455,9 +15459,11 @@ uint4 __ovld __purefn read_imageui(read_write 
image2d_array_t, sampler_t, float4
 
 float __ovld __purefn read_imagef(read_write image2d_array_depth_t, sampler_t, 
float4, float2, float2);
 
+#ifdef cl_khr_3d_image_writes
 float4 __ovld __purefn read_imagef(read_write image3d_t, sampler_t, float4, 
float4, float4);
 int4 __ovld __purefn read_imagei(read_write image3d_t, sampler_t, float4, 
float4, float4);
 uint4 __ovld __purefn read_imageui(read_write image3d_t, sampler_t, float4, 
float4, float4);
+#endif // cl_khr_3d_image_writes
 
 #endif //cl_khr_mipmap_image
 
@@ -15465,7 +15471,9 @@ uint4 __ovld __purefn read_imageui(read_write 
image3d_t, sampler_t, float4, floa
 #ifdef cl_khr_fp16
 half4 __ovld __purefn read_imageh(read_write image1d_t, int);
 half4 __ovld __purefn read_imageh(read_write image2d_t, int2);
+#ifdef cl_khr_3d_image_writes
 half4 __ovld __purefn read_imageh(read_write image3d_t, int4);
+#endif // cl_khr_3d_image_writes
 half4 __ovld __purefn read_imageh(read_write image1d_array_t, int2);
 half4 __ovld __purefn read_imageh(read_write image2d_array_t, int4);
 half4 __ovld __purefn read_imageh(read_write image1d_buffer_t, int);
@@ -15735,7 +15743,9 @@ int __ovld __cnfn get_image_width(write_only 
image2d_array_msaa_depth_t);
 int __ovld __cnfn get_image_width(read_write image1d_t);
 int __ovld __cnfn get_image_width(read_write image1d_buffer_t);
 int __ovld __cnfn get_image_width(read_write image2d_t);
+#ifdef cl_khr_3d_image_writes
 int __ovld __cnfn get_image_width(read_write image3d_t);
+#endif // cl_khr_3d_image_writes
 int __ovld __cnfn get_image_width(read_write image1d_array_t);
 int __ovld __cnfn get_image_width(read_write image2d_array_t);
 #ifdef cl_khr_depth_images
@@ -15785,7 +15795,9 @@ int __ovld __cnfn get_image_height(write_only 
image2d_array_msaa_depth_t);
 
 #if defined(__opencl_c_read_write_images)
 int __ovld __cnfn get_image_height(read_write image2d_t);
+#ifdef cl_khr_3d_image_writes
 int __ovld __cnfn get_image_height(read_write image3d_t);
+#endif // cl_khr_3d_image_writes
 int __ovld __cnfn get_image_height(read_write image2d_array_t);
 #ifdef cl_khr_depth_images
 int __ovld __cnfn get_image_height(read_write image2d_depth_t);
@@ -15806,11 +15818,11 @@ int __ovld __cnfn get_image_depth(read_only 
image3d_t);
 
 #ifdef cl_khr_3d_image_writes
 int __ovld __cnfn get_image_depth(write_only image3d_t);
-#endif
 
 #if defined(__opencl_c_read_write_images)
 int __ovld __cnfn get_image_depth(read_write image3d_t);
 #endif //defined(__opencl_c_read_write_images)
+#endif // cl_khr_3d_image_writes
 
 // OpenCL Extension v2.0 s9.18 - Mipmaps
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
@@ -15832,7 +15844,9 @@ int __ovld get_image_num_mip_levels(write_only 
image3d_t);
 #if defined(__opencl_c_

[PATCH] D137337: Replace LLVM_LIBDIR_SUFFIX by CMAKE_INSTALL_LIBDIR

2022-11-09 Thread serge via Phabricator via cfe-commits
serge-sans-paille added inline comments.



Comment at: bolt/lib/RuntimeLibs/RuntimeLibrary.cpp:32
   SmallString<128> LibPath = llvm::sys::path::parent_path(Dir);
-  llvm::sys::path::append(LibPath, "lib" LLVM_LIBDIR_SUFFIX);
+  llvm::sys::path::append(LibPath, CMAKE_INSTALL_LIBDIR);
   if (!llvm::sys::fs::exists(LibPath)) {

Ericson2314 wrote:
> mgorny wrote:
> > Well, one thing I immediately notice is that technically 
> > `CMAKE_INSTALL_LIBDIR` can be an absolute path, while in many locations you 
> > are assuming it will always be relative. Not saying that's a blocker but I 
> > think you should add checks for that into `CMakeLists.txt`.
> Yes I was working on this, and I intend to use `CMAKE_INSTALL_LIBDIR` with an 
> absolute path.
> 
> OK if this isn't supported initially but we should ovoid regressing where 
> possible.
Turns out LLVM_LIBDIR_SUFFIX is used in several situations: (a) for the library 
install dir or (b) for the location where build artifact as stored in 
CMAKE_BINARY_DIR. (a) could accept a path but not (b), unless we derive it from 
(a) but I can see a lot of complication there for the testing step. Would that 
be ok to choke on CMAKE_INSTALL_LIBDIR being a path and not a directory 
component?



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

https://reviews.llvm.org/D137337

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


[clang] 2fb3bec - [analyzer] Fix crash for array-delete of UnknownVal values.

2022-11-09 Thread Tomasz Kamiński via cfe-commits

Author: Tomasz Kamiński
Date: 2022-11-09T15:06:46+01:00
New Revision: 2fb3bec932ede7704724abb71e8270e0b4c201f6

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

LOG: [analyzer] Fix crash for array-delete of UnknownVal values.

We now skip the destruction of array elements for `delete[] p`,
if the value of `p` is UnknownVal and does not have corresponding region.
This eliminate the crash in `getDynamicElementCount` on that
region and matches the behavior for deleting the array of
non-constant range.

Reviewed By: isuckatcs

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/test/Analysis/dtor-array.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp 
b/clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp
index db9698b4086e9..6a86536492cd3 100644
--- a/clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp
+++ b/clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp
@@ -44,6 +44,7 @@ DefinedOrUnknownSVal getDynamicElementCount(ProgramStateRef 
State,
 const MemRegion *MR,
 SValBuilder &SVB,
 QualType ElementTy) {
+  assert(MR != nullptr && "Not-null region expected");
   MR = MR->StripCasts();
 
   DefinedOrUnknownSVal Size = getDynamicExtent(State, MR, SVB);

diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index a90e17fc496d2..4528dbc0cc36f 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1241,6 +1241,7 @@ ExprEngine::prepareStateForArrayDestruction(const 
ProgramStateRef State,
 const QualType &ElementTy,
 const LocationContext *LCtx,
 SVal *ElementCountVal) {
+  assert(Region != nullptr && "Not-null region expected"); 
 
   QualType Ty = ElementTy.getDesugaredType(getContext());
   while (const auto *NTy = dyn_cast(Ty))
@@ -1420,31 +1421,32 @@ void ExprEngine::ProcessDeleteDtor(const CFGDeleteDtor 
Dtor,
   const MemRegion *ArgR = ArgVal.getAsRegion();
 
   if (DE->isArrayForm()) {
-SVal ElementCount;
-std::tie(State, Idx) =
-prepareStateForArrayDestruction(State, ArgR, DTy, LCtx, &ElementCount);
-
 CallOpts.IsArrayCtorOrDtor = true;
 // Yes, it may even be a multi-dimensional array.
 while (const auto *AT = getContext().getAsArrayType(DTy))
   DTy = AT->getElementType();
 
-// If we're about to destruct a 0 length array, don't run any of the
-// destructors.
-if (ElementCount.isConstant() &&
-ElementCount.getAsInteger()->getLimitedValue() == 0) {
+if (ArgR) {
+  SVal ElementCount;
+  std::tie(State, Idx) = prepareStateForArrayDestruction(
+  State, ArgR, DTy, LCtx, &ElementCount);
 
-  static SimpleProgramPointTag PT(
-  "ExprEngine", "Skipping 0 length array delete destruction");
-  PostImplicitCall PP(getDtorDecl(DTy), DE->getBeginLoc(), LCtx, &PT);
-  NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
-  Bldr.generateNode(PP, Pred->getState(), Pred);
-  return;
-}
+  // If we're about to destruct a 0 length array, don't run any of the
+  // destructors.
+  if (ElementCount.isConstant() &&
+  ElementCount.getAsInteger()->getLimitedValue() == 0) {
+
+static SimpleProgramPointTag PT(
+"ExprEngine", "Skipping 0 length array delete destruction");
+PostImplicitCall PP(getDtorDecl(DTy), DE->getBeginLoc(), LCtx, &PT);
+NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
+Bldr.generateNode(PP, Pred->getState(), Pred);
+return;
+  }
 
-if (ArgR)
   ArgR = State->getLValue(DTy, svalBuilder.makeArrayIndex(Idx), ArgVal)
  .getAsRegion();
+}
   }
 
   NodeBuilder Bldr(Pred, Dst, getBuilderContext());

diff  --git a/clang/test/Analysis/dtor-array.cpp 
b/clang/test/Analysis/dtor-array.cpp
index ab0a939232173..84a34af922516 100644
--- a/clang/test/Analysis/dtor-array.cpp
+++ b/clang/test/Analysis/dtor-array.cpp
@@ -344,3 +344,36 @@ void nonConstantRegionExtent(){
   // region to a conjured symbol.
   clang_analyzer_eval(InlineDtor::dtorCalled == 0); // expected-warning 
{{TRUE}} expected-warning {{FALSE}}
 }
+
+namespace crash6 {
+
+struct NonTrivialItem {
+  ~NonTrivialItem();
+};
+
+struct WeirdVec {
+  void clear() {
+delete[] data;
+size = 0;
+  }
+  NonTrivialItem *data;
+  unsigned size;
+};
+
+void top(int j) {
+  WeirdVec *p = new WeirdVec;
+
+  p[j].size = 0;
+

[PATCH] D136671: [analyzer] Fix crash for array-delete of UnknownVal values.

2022-11-09 Thread Tomasz Kamiński via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2fb3bec932ed: [analyzer] Fix crash for array-delete of 
UnknownVal values. (authored by tomasz-kaminski-sonarsource).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136671

Files:
  clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/Analysis/dtor-array.cpp

Index: clang/test/Analysis/dtor-array.cpp
===
--- clang/test/Analysis/dtor-array.cpp
+++ clang/test/Analysis/dtor-array.cpp
@@ -344,3 +344,36 @@
   // region to a conjured symbol.
   clang_analyzer_eval(InlineDtor::dtorCalled == 0); // expected-warning {{TRUE}} expected-warning {{FALSE}}
 }
+
+namespace crash6 {
+
+struct NonTrivialItem {
+  ~NonTrivialItem();
+};
+
+struct WeirdVec {
+  void clear() {
+delete[] data;
+size = 0;
+  }
+  NonTrivialItem *data;
+  unsigned size;
+};
+
+void top(int j) {
+  WeirdVec *p = new WeirdVec;
+
+  p[j].size = 0;
+  delete[] p->data; // no-crash
+}
+
+template 
+T make_unknown() {
+  return reinterpret_cast(static_cast(0.404));
+}
+
+void directUnknownSymbol() {
+  delete[] make_unknown(); // no-crash
+}
+
+}
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1241,6 +1241,7 @@
 const QualType &ElementTy,
 const LocationContext *LCtx,
 SVal *ElementCountVal) {
+  assert(Region != nullptr && "Not-null region expected");	
 
   QualType Ty = ElementTy.getDesugaredType(getContext());
   while (const auto *NTy = dyn_cast(Ty))
@@ -1420,31 +1421,32 @@
   const MemRegion *ArgR = ArgVal.getAsRegion();
 
   if (DE->isArrayForm()) {
-SVal ElementCount;
-std::tie(State, Idx) =
-prepareStateForArrayDestruction(State, ArgR, DTy, LCtx, &ElementCount);
-
 CallOpts.IsArrayCtorOrDtor = true;
 // Yes, it may even be a multi-dimensional array.
 while (const auto *AT = getContext().getAsArrayType(DTy))
   DTy = AT->getElementType();
 
-// If we're about to destruct a 0 length array, don't run any of the
-// destructors.
-if (ElementCount.isConstant() &&
-ElementCount.getAsInteger()->getLimitedValue() == 0) {
+if (ArgR) {
+  SVal ElementCount;
+  std::tie(State, Idx) = prepareStateForArrayDestruction(
+  State, ArgR, DTy, LCtx, &ElementCount);
 
-  static SimpleProgramPointTag PT(
-  "ExprEngine", "Skipping 0 length array delete destruction");
-  PostImplicitCall PP(getDtorDecl(DTy), DE->getBeginLoc(), LCtx, &PT);
-  NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
-  Bldr.generateNode(PP, Pred->getState(), Pred);
-  return;
-}
+  // If we're about to destruct a 0 length array, don't run any of the
+  // destructors.
+  if (ElementCount.isConstant() &&
+  ElementCount.getAsInteger()->getLimitedValue() == 0) {
+
+static SimpleProgramPointTag PT(
+"ExprEngine", "Skipping 0 length array delete destruction");
+PostImplicitCall PP(getDtorDecl(DTy), DE->getBeginLoc(), LCtx, &PT);
+NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
+Bldr.generateNode(PP, Pred->getState(), Pred);
+return;
+  }
 
-if (ArgR)
   ArgR = State->getLValue(DTy, svalBuilder.makeArrayIndex(Idx), ArgVal)
  .getAsRegion();
+}
   }
 
   NodeBuilder Bldr(Pred, Dst, getBuilderContext());
Index: clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp
===
--- clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp
+++ clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp
@@ -44,6 +44,7 @@
 const MemRegion *MR,
 SValBuilder &SVB,
 QualType ElementTy) {
+  assert(MR != nullptr && "Not-null region expected");
   MR = MR->StripCasts();
 
   DefinedOrUnknownSVal Size = getDynamicExtent(State, MR, SVB);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105584: [MLIR][OpenMP] Distribute Construct Operation

2022-11-09 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan requested changes to this revision.
kiranchandramohan added a comment.
This revision now requires changes to proceed.

Patch probably needs a rebase. A few more minor things to fix. Looks mostly 
ready.




Comment at: mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td:490
+
+The optional `dist_schedule_var` attribute specifies the  schedule for this
+loop, determining how the loop is distributed across the parallel threads.

Do you mean `static_dist_schedule` here?



Comment at: mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td:495-496
+
+The optional `collapse` attribute specifies the number of loops which
+are collapsed to form the distribute loop.
+  }];

We can remove `collapse` for now.



Comment at: mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td:513
+   ( $schedule_chunk^ `:` type($schedule_chunk))? `)`
+  |`collapse` `(` $collapse_val `)`
+  | `allocate` `(`

In https://reviews.llvm.org/D128338 we removed collapse from all constructs. 
Currently collapse is modelled by having multiple entries in the lowerBound, 
upperBound and step.



Comment at: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp:211
+//===-===//
+// Verifier for Dristribute Op
+//===-===//





Comment at: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp:220
+return emitOpError() << "empty upperbound for distribute loop operation";
+  
+  return success();

Nit: Check that their sizes are equal as well. And also if step is present then 
its size matches lowerbound/upperbound.



Comment at: mlir/test/Dialect/OpenMP/ops.mlir:124
 
+// CHECK-LABEL: omp_DistributeOp
+func.func @omp_DistributeOp(%lb : index, %ub : index, %step : index, %data_var 
: memref, %chunk_var : i32) -> () {

Add a pretty-print test as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105584

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


[clang] b710444 - Fix Clang sphinx build

2022-11-09 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-11-09T09:19:24-05:00
New Revision: b7104442ddcc90dd9aa22e08a2113a463b1ef4be

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

LOG: Fix Clang sphinx build

This addresses the issue found by:
https://lab.llvm.org/buildbot/#/builders/92/builds/35350

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 774b575b5260..b0c01dd283e5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -713,7 +713,7 @@ X86 Support in Clang
   * Support intrinsic of ``_mm(256)_cvtneoph_ps``.
   * Support intrinsic of ``_mm(256)_cvtneps_avx_pbh``.
 - ``-march=raptorlake`` and ``-march=meteorlake`` are now supported.
-* ``-march=sierraforest``, ``-march=graniterapids`` and ``-march=grandridge`` 
are now supported.
+- ``-march=sierraforest``, ``-march=graniterapids`` and ``-march=grandridge`` 
are now supported.
 
 WebAssembly Support in Clang
 



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


[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-09 Thread Fabian Keßler via Phabricator via cfe-commits
Febbe added a comment.

In D137205#3915526 , @Skylion007 
wrote:

> Okay, now I am getting what I believe to be segfaults:
>
>   #0 0x564383482be4 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
>   #1 0x564383480464 SignalHandler(int) Signals.cpp:0:0
>   #2 0x7f7c275c9420 __restore_rt 
> (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
>   #3 0x5643804b0ea5 
> clang::tidy::performance::UnnecessaryCopyOnLastUseCheck::check(clang::ast_matchers::MatchFinder::MatchResult
>  const&) (.cold) UnnecessaryCopyOnLastUseCheck.cpp:0:0
>   #4 0x56438262bba1 clang::ast_matchers::internal::(anonymous 
> namespace)::MatchASTVisitor::MatchVisitor::visitMatch(clang::ast_matchers::BoundNodes
>  const&) ASTMatchFinder.cpp:0:0
>   #5 0x5643826818df 
> clang::ast_matchers::internal::BoundNodesTreeBuilder::visitMatches(clang::ast_matchers::internal::BoundNodesTreeBuilder::Visitor*)
>  (/home/aaron/git/llvm-project/build/bin/clang-tidy+0x2d258df)
>
> It worked before this PR, now it just crashes on a lot of real world 
> codebases including just trying to run it for a few files on LLVM's own 
> codebase.

I thought I had fixed it with my newest diff. 
The reason for the segfaults are, that I removed the `llvm::Expected` and 
replaced it with asserts. But there are cases, where the asserts can be false 
with regular (currently unhandled code).

I also found issues:

- a fixup is proposed even when the copy-parameter is not mentioned in the 
code. This is the case for capturing lambdas `... = [=]{...};` -> `... = 
[std::move(=)]{...};`
- a fixup is proposed for trivial types like std::pair


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

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


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

2022-11-09 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.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137712

Files:
  clang/include/clang/AST/ExprConcepts.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/ExprConcepts.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaTemplate/concepts.cpp

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -764,3 +764,53 @@
   __iterator_traits_member_pointer_or_arrow_or_void> f;
 }
 }// namespace InheritedFromPartialSpec
+
+namespace nested_requirements {
+template  concept True = true;
+
+struct S { double value; };
+
+template 
+concept Pipes = requires (T x) {
+   requires True || True;
+   requires True || True;
+};
+template 
+concept Amps1 = requires (T x) {
+   requires True && True;
+   // expected-note@-1{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
+};
+template 
+concept Amps2 = requires (T x) {
+   requires True && True;
+};
+
+static_assert(Pipes);
+static_assert(Pipes);
+
+static_assert(Amps1);
+static_assert(!Amps1);
+
+static_assert(Amps2);
+static_assert(!Amps2);
+
+template
+void foo1() requires requires (T x) { // expected-note {{candidate template ignored: constraints not satisfied [with T = int]}}
+  requires 
+  True // expected-note {{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
+  && True;
+} {}
+template void fooPipes() requires Pipes {}
+template void fooAmps1() requires Amps1 {}
+// expected-note@-1 {{candidate template ignored: constraints not satisfied [with T = int]}} \
+// expected-note@-1 {{because 'int' does not satisfy 'Amps1'}}
+
+void foo() {
+  foo1();
+  foo1(); // expected-error {{no matching function for call to 'foo1'}}
+  fooPipes();
+  fooPipes();
+  fooAmps1();
+  fooAmps1(); // expected-error {{no matching function for call to 'fooAmps1'}}
+}
+}
\ No newline at end of file
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3477,6 +3477,22 @@
 return Result;
   }
 
+  ExprResult RebuildConceptSpecializationExprWithSFINAE(
+  ConceptSpecializationExpr *E, NestedNameSpecifierLoc NNS,
+  SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
+  NamedDecl *FoundDecl, ConceptDecl *NamedConcept) {
+ConstraintSatisfaction Satisfaction;
+Satisfaction.IsSatisfied = false;
+Satisfaction.ContainsErrors = true;
+CXXScopeSpec SS;
+SS.Adopt(NNS);
+return ConceptSpecializationExpr::CreateWithSFINAE(
+SemaRef.Context,
+SS.isSet() ? SS.getWithLocInContext(SemaRef.Context)
+   : NestedNameSpecifierLoc{},
+TemplateKWLoc, ConceptNameInfo, FoundDecl, NamedConcept, &Satisfaction);
+  }
+
   /// \brief Build a new requires expression.
   ///
   /// By default, performs semantic analysis to build the new expression.
@@ -12617,9 +12633,20 @@
  ConceptSpecializationExpr *E) {
   const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
   TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
-  if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
-  Old->NumTemplateArgs, TransArgs))
-return ExprError();
+  {
+Sema::SFINAETrap Trap(getSema());
+if (getDerived().TransformTemplateArguments(
+Old->getTemplateArgs(), Old->NumTemplateArgs, TransArgs) &&
+!Trap.hasErrorOccurred())
+  return ExprError();
+
+if (Trap.hasErrorOccurred()) {
+  // FIXME: Propogate detailed subtitution falilure diagnostics.
+  return getDerived().RebuildConceptSpecializationExprWithSFINAE(
+  E, E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
+  E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept());
+}
+  }
 
   return getDerived().RebuildConceptSpecializationExpr(
   E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
Index: clang/lib/AST/ExprConcepts.cpp
===
--- clang/lib/AST/ExprConcepts.cpp
+++ clang/lib/AST/ExprConcepts.cpp
@@ -103,6 +103,16 @@
 Dependent, ContainsUnexpandedParameterPack);
 }
 
+ConceptSpecializationExpr *ConceptSpecializationExpr::CreateWithSFINAE(
+const ASTContext &C, NestedNameSpecifierLoc NNS,
+SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
+NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
+const ConstraintSatisfaction *Satisfaction) {
+  return ConceptSp

[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-09 Thread Fabian Keßler via Phabricator via cfe-commits
Febbe updated this revision to Diff 474260.
Febbe added a comment.

Fixed segfaults due to asserts which were wrongly assumed to be always true


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst
  
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-on-last-use.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-on-last-use.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-on-last-use.cpp
@@ -0,0 +1,168 @@
+// RUN: %check_clang_tidy %s -std=c++17 performance-unnecessary-copy-on-last-use %t
+// RUN: %check_clang_tidy %s -std=c++11 performance-unnecessary-copy-on-last-use %t
+// CHECK-FIXES: #include 
+
+struct Movable {
+  Movable() = default;
+  Movable(Movable const &) = default;
+  Movable(Movable &&) = default;
+  Movable &operator=(Movable const &) = default;
+  Movable &operator=(Movable &&) = default;
+  ~Movable();
+
+  void memberUse() {}
+};
+// static_assert(!std::is_trivially_copyable_v, "Movable must not be trivially copyable");
+
+void valueReceiver(Movable Mov);
+void constRefReceiver(Movable const &Mov);
+
+void valueTester() {
+  Movable Mov{};
+  valueReceiver(Mov);
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+  Mov = Movable{};
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+}
+
+void testUsageInBranch(bool Splitter) {
+  Movable Mov{};
+
+  valueReceiver(Mov);
+  if(Splitter){
+Mov.memberUse();
+  } else {
+Mov = Movable{};
+  }
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+
+  if(Splitter){
+Mov = Movable{};
+  } else {
+Mov = Movable{};
+  }
+  valueReceiver(Mov);
+  Mov.memberUse();
+}
+
+void testExplicitCopy() {
+  Movable Mov{};
+  constRefReceiver(Movable{Mov});
+  // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: constRefReceiver(Movable{std::move(Mov)});
+}
+
+Movable testReturn() {
+  Movable Mov{};
+  return Mov; // no warning, copy elision
+}
+
+Movable testReturn2(Movable && Mov, bool F) {
+  return F? Mov: Movable{}; 
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use] 
+  // CHECK-FIXES: return F? std::move(Mov): Movable{};
+}
+
+void rValReferenceTester(Movable&& Mov) {
+  valueReceiver(Mov);
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+  Mov = Movable{};
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+}
+
+void referenceTester(Movable& Mov) {
+  valueReceiver(Mov);
+  valueReceiver(Mov);
+  Mov = Movable{};
+  valueReceiver(Mov);
+}
+
+void pointerTester(Movable* Mov) {
+  valueReceiver(*Mov);
+  valueReceiver(*Mov);
+  *Mov = Movable{};
+  valueReceiver(*Mov);
+}
+
+template 
+struct RemoveRef{
+  using type = T;
+};
+
+template 
+struct RemoveRef{
+  using type = T;
+};
+
+template 
+struct RemoveRef{
+  using type = T;
+};
+
+template
+using RemoveRefT = typename RemoveRef::type;
+
+template 
+void initSomething(Movable&& Mov) {
+  valueReceiver(Mov);
+  valueReceiver(Mov); // no warning: Todo(bug): Is this a bug? Fix or explain.
+  Mov = RemoveRefT{};
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' may be copied on last use, consider forwarding it instead. [performance-unnecessary-copy-on-last-use]
+}
+
+void initSomethingVal(Movable const& Mov) {
+  initSomething(Movable{Mov

[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-09 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst:40
+.. option:: BlockedFunctions
+   A semicolon-separated list of names of functions who's parameters do not
+   participate in the resolution.

Please separate with newline.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst:50
+
+   A string specifying which include-style is used, `llvm` or `google`. Default
+   is `llvm`.

Could such option be shared between different checks? Or even rely on 
`.clang-format`?



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst:71
+
+  This check is also unable to detect last usages for fields, if the parent 
+  class is destructed after the last usage. 

Please unindent. It's not a code.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst:73
+  class is destructed after the last usage. 
\ No newline at end of file


Please add.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

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


[PATCH] D137071: [clang][Interp] Implement missing compound assign operators

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



Comment at: clang/test/AST/Interp/literals.cpp:591
+
+  static_assert(IntDiv(INT_MIN, -1) == 0, "");
+

This one should fail for the same reason as `%`



Comment at: clang/test/AST/Interp/literals.cpp:553
+  static_assert(IntRem(2, 1) == 0, "");
+  static_assert(IntRem(9, 7) == 2, "");
+

tbaeder wrote:
> aaron.ballman wrote:
> > aaron.ballman wrote:
> > > ```
> > > static_assert(IntRem(9, 0) == 12, ""); // Not constexpr
> > > static_assert(IntRem(__INT_MIN__, -1) == 12, ""); // Not constexpr
> > > ```
> > Missed the test for __INT_MIN__ and -1?
> for rem, clang doesn't diagnose anything: https://godbolt.org/z/rhe5ezc54
That's a bug per https://eel.is/c++draft/expr.mul#4.sentence-3 because the 
resulting algebraic value is not representable in the type of the result.


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

https://reviews.llvm.org/D137071

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


[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-09 Thread Aaron Gokaslan via Phabricator via cfe-commits
Skylion007 added a comment.

Currently, this check also tries to move static values which is very 
undesirable and unlikely to be correct.

 static auto value = std::string("CONSTANT");
  -  return value;
  +  return std::move(value);


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

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


[PATCH] D136603: [analyzer] Model cast after LValueToRValueBitCasts

2022-11-09 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

This 'new' approach with the type auto-detection behaves the same way as the 
originally proposed patch.
Same results, still no crashes :)
I'll update the summary and the title according to the new approach.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136603

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


[PATCH] D137550: [clangd] Fix the code action `RemoveUsingNamespace`

2022-11-09 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry updated this revision to Diff 474262.
v1nh1shungry added a comment.

Format codes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137550

Files:
  clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
  clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -249,6 +249,21 @@
 ns::Foo foo;
 foo + 10;
   }
+)cpp"},
+  {// Does not qualify user-defined literals
+   R"cpp(
+  namespace ns {
+  long double operator "" _w(long double);
+  }
+  using namespace n^s;
+  int main() { 1.5_w; }
+)cpp",
+   R"cpp(
+  namespace ns {
+  long double operator "" _w(long double);
+  }
+  
+  int main() { 1.5_w; }
 )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,12 +155,23 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+auto Kind = T->getDeclName().getNameKind();
 // Avoid adding qualifiers before operators, e.g.
 //   using namespace std;
 //   cout << "foo"; // Must not changed to std::cout std:: << "foo"
-// FIXME: User-defined literals are not handled
-if (T->isInIdentifierNamespace(
-Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+if (Kind == DeclarationName::CXXOperatorName)
+  return;
+// Avoid adding qualifiers before user-defined literals, e.g.
+//   using namespace std;
+//   auto s = "foo"s; // Must not changed to auto s = "foo" std::s;
+// FIXME: Add a using-directive for user-defined literals
+// declared in an inline namespace, e.g.
+//   using namespace s^td;
+//   int main() { cout << "foo"s; }
+// change to
+//   using namespace std::literals;
+//   int main() { std::cout << "foo"s; }
+if (Kind == DeclarationName::NameKind::CXXLiteralOperatorName)
   return;
   }
   SourceLocation Loc = Ref.NameLoc;


Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -249,6 +249,21 @@
 ns::Foo foo;
 foo + 10;
   }
+)cpp"},
+  {// Does not qualify user-defined literals
+   R"cpp(
+  namespace ns {
+  long double operator "" _w(long double);
+  }
+  using namespace n^s;
+  int main() { 1.5_w; }
+)cpp",
+   R"cpp(
+  namespace ns {
+  long double operator "" _w(long double);
+  }
+  
+  int main() { 1.5_w; }
 )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,12 +155,23 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+auto Kind = T->getDeclName().getNameKind();
 // Avoid adding qualifiers before operators, e.g.
 //   using namespace std;
 //   cout << "foo"; // Must not changed to std::cout std:: << "foo"
-// FIXME: User-defined literals are not handled
-if (T->isInIdentifierNamespace(
-Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+if (Kind == DeclarationName::CXXOperatorName)
+  return;
+// Avoid adding qualifiers before user-defined literals, e.g.
+//   using namespace std;
+//   auto s = "foo"s; // Must not changed to auto s = "foo" std::s;
+// FIXME: Add a using-directive for user-defined literals
+// declared in an inline namespace, e.g.
+//   using namespace s^td;
+   

[PATCH] D137618: [Clang] Fix behavior of -ffp-model option when overriden

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



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:3034
   RoundingFPMath = false;
+  FPExceptionBehavior = "";
   // If fast-math is set then set the fp-contract mode to fast.

 FPExceptionBehavior should be set here and in case options::OPT_ffp_model_EQ:



Comment at: clang/test/Driver/fp-model.c:69
 
+// RUN: %clang -### -ffp-model=fast -ffp-model=strict -c %s 2>&1 | FileCheck \
+// RUN:   --check-prefix=WARN11 %s

Add a RUN command for '-ffast-math -ffp-model=strict'. I would expect the same 
warning.
Currently (without your patch) it is generating this non-sense warning:
https://godbolt.org/z/eW679Y7G3


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137618

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


[PATCH] D122385: [clang][deps] Fix clang-cl output argument parsing

2022-11-09 Thread Sylvain Audi via Phabricator via cfe-commits
saudi added inline comments.
Herald added a subscriber: ributzka.



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:487
+if (!llvm::sys::path::has_extension(CurrentO))
+  LastO = (CurrentO + ".obj").str();
+else

Before the patch `LastO` string allocation was done only once (because of the 
`!LastO.empty()` test).
It probably would be better to have it of type `StringRef` and allocate once at 
the end


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122385

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


[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-09 Thread Aaron Gokaslan via Phabricator via cfe-commits
Skylion007 added a comment.

Hmm, I still had a crash on this latest code (although it is crashing much more 
rarely now.

It crashes on scanning this file 
https://github.com/facebookresearch/habitat-sim/blob/5fb04078b0b8432dc4a88ec186a2b7af74163be1/src/esp/core/managedContainers/ManagedContainerBase.cpp

  Found compiler error(s).
  /home/aaron/git/llvm-project/build/bin/clang-tidy -checks=-*,*perf*last* 
-export-fixes /tmp/tmp38bqy_w9/tmpa_p4xe5f.yaml -p=build 
/home/aaron/git/habitat-sim/src/esp/core/managedContainers/ManagedContainerBase.cpp
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace.
  Stack dump:
  0.Program arguments: /home/aaron/git/llvm-project/build/bin/clang-tidy 
-checks=-*,*perf*last* -export-fixes /tmp/tmp38bqy_w9/tmpa_p4xe5f.yaml -p=build 
/home/aaron/git/habitat-sim/src/esp/core/managedContainers/ManagedContainerBase.cpp
  1. parser at end of file
  2.ASTMatcher: Processing 'performance-unnecessary-copy-on-last-use' 
against:
CXXConstructExpr : 

  --- Bound Nodes Begin ---
  constructExpr - { CXXConstructExpr : 

 }
  param - { DeclRefExpr : 

 }
  --- Bound Nodes End ---
   #0 0x55a33b1c14f4 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
   #1 0x55a33b1bed74 SignalHandler(int) Signals.cpp:0:0
   #2 0x7f80af664420 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
   #3 0x55a338761176 
clang::tidy::performance::UnnecessaryCopyOnLastUseCheck::check(clang::ast_matchers::MatchFinder::MatchResult
 const&) (/home/aaron/git/llvm-project/build/bin/clang-tidy+0x10c7176)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

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


[PATCH] D137071: [clang][Interp] Implement missing compound assign operators

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

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

https://reviews.llvm.org/D137071

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -469,5 +469,156 @@
 return (a -= a);
   }
   static_assert(subAll(213) == 0, "");
+
+  constexpr bool BoolOr(bool b1, bool b2) {
+bool a;
+a = b1;
+a |= b2;
+return a;
+  }
+  static_assert(BoolOr(true, true), "");
+  static_assert(BoolOr(true, false), "");
+  static_assert(BoolOr(false, true), "");
+  static_assert(!BoolOr(false, false), "");
+
+  constexpr int IntOr(unsigned a, unsigned b) {
+unsigned r;
+r = a;
+r |= b;
+return r;
+  }
+  static_assert(IntOr(10, 1) == 11, "");
+  static_assert(IntOr(1337, -1) == -1, "");
+  static_assert(IntOr(0, 12) == 12, "");
+
+  constexpr bool BoolAnd(bool b1, bool b2) {
+bool a;
+a = b1;
+a &= b2;
+return a;
+  }
+  static_assert(BoolAnd(true, true), "");
+  static_assert(!BoolAnd(true, false), "");
+  static_assert(!BoolAnd(false, true), "");
+  static_assert(!BoolAnd(false, false), "");
+
+  constexpr int IntAnd(unsigned a, unsigned b) {
+unsigned r;
+r = a;
+r &= b;
+return r;
+  }
+  static_assert(IntAnd(10, 1) == 0, "");
+  static_assert(IntAnd(1337, -1) == 1337, "");
+  static_assert(IntAnd(0, 12) == 0, "");
+
+  constexpr bool BoolXor(bool b1, bool b2) {
+bool a;
+a = b1;
+a ^= b2;
+return a;
+  }
+  static_assert(!BoolXor(true, true), "");
+  static_assert(BoolXor(true, false), "");
+  static_assert(BoolXor(false, true), "");
+  static_assert(!BoolXor(false, false), "");
+
+  constexpr int IntXor(unsigned a, unsigned b) {
+unsigned r;
+r = a;
+r ^= b;
+return r;
+  }
+  static_assert(IntXor(10, 1) == 11, "");
+  static_assert(IntXor(10, 10) == 0, "");
+  static_assert(IntXor(12, true) == 13, "");
+
+  constexpr bool BoolRem(bool b1, bool b2) {
+bool a;
+a = b1;
+a %= b2;
+return a;
+  }
+  static_assert(!BoolRem(true, true), "");
+  static_assert(!BoolRem(false, true), "");
+
+  constexpr int IntRem(int a, int b) {
+int r;
+r = a;
+r %= b; // expected-note {{division by zero}} \
+// ref-note {{division by zero}} \
+// expected-note {{outside the range of representable values}}
+return r;
+  }
+  static_assert(IntRem(2, 2) == 0, "");
+  static_assert(IntRem(2, 1) == 0, "");
+  static_assert(IntRem(9, 7) == 2, "");
+  static_assert(IntRem(5, 0) == 0, ""); // expected-error {{not an integral constant expression}} \
+// expected-note {{in call to 'IntRem(5, 0)'}} \
+// ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'IntRem(5, 0)'}}
+
+  static_assert(IntRem(INT_MIN, -1) == 0, ""); // expected-error {{not an integral constant expression}} \
+   // expected-note {{in call to 'IntRem}}
+
+
+  constexpr bool BoolDiv(bool b1, bool b2) {
+bool a;
+a = b1;
+a /= b2;
+return a;
+  }
+  static_assert(BoolDiv(true, true), "");
+  static_assert(!BoolDiv(false, true), "");
+
+  constexpr int IntDiv(int a, int b) {
+int r;
+r = a;
+r /= b; // expected-note {{division by zero}} \
+// ref-note {{division by zero}} \
+// expected-note {{outside the range of representable values}} \
+// ref-note {{outside the range of representable values}}
+return r;
+  }
+  static_assert(IntDiv(2, 2) == 1, "");
+  static_assert(IntDiv(12, 20) == 0, "");
+  static_assert(IntDiv(2, 1) == 2, "");
+  static_assert(IntDiv(9, 7) == 1, "");
+  static_assert(IntDiv(5, 0) == 0, ""); // expected-error {{not an integral constant expression}} \
+// expected-note {{in call to 'IntDiv(5, 0)'}} \
+// ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'IntDiv(5, 0)'}}
+
+  static_assert(IntDiv(INT_MIN, -1) == 0, ""); // expected-error {{not an integral constant expression}} \
+   // expected-note {{in call to 'IntDiv}} \
+   // ref-error {{not an integral constant expression}} \
+   // ref-note {{in call to 'IntDiv}}
+
+  constexpr bool BoolMul(bool b1, bool b2) {
+bool a;
+a = b1;
+a *= b2;
+return a;
+  }
+  static_assert(BoolMul(true, true), "");
+  static_assert(!BoolMul(true, false), "");
+  static_assert(!BoolMul(false, true), "");
+  static_assert(!BoolMul(false, false), "");
+
+  

[PATCH] D137071: [clang][Interp] Implement missing compound assign operators

2022-11-09 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/test/AST/Interp/literals.cpp:591
+
+  static_assert(IntDiv(INT_MIN, -1) == 0, "");
+

aaron.ballman wrote:
> This one should fail for the same reason as `%`
Works when replacing all the `unsigned`s with `int`s.


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

https://reviews.llvm.org/D137071

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


[PATCH] D137232: [clang][Interp] Support inc/dec operators on pointers

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



Comment at: clang/lib/AST/Interp/Opcodes.td:421-425
+// [Pointer] -> []
+def IncPtr : Opcode {
+  let HasGroup = 0;
+}
+// [Pointer] -> []

aaron.ballman wrote:
> Don't both of these result in a `Pointer`? And should they have a `Types` 
> field?
Ah yes, they do. They don't need a type field, we know we're operating on a 
pointer.


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

https://reviews.llvm.org/D137232

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


[PATCH] D137650: [clangd] Implement hover for string literals

2022-11-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:816
+  if (llvm::isa(E)) {
+HoverInfo::PrintedType PT;
+PT.Type = E->getType().getAsString(PP);

can you extract this into a function, similar to the cases below?



Comment at: clang-tools-extra/clangd/Hover.cpp:819
+HI.Type = PT;
+HI.Name = "String Literal";
+return HI;

i think it's a good idea to also include the size here (e.g. L"XYZ", would be 8 
bytes).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137650

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


[PATCH] D137719: [clang] Missed rounding mode use in constant evaluation

2022-11-09 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff created this revision.
sepavloff added reviewers: rjmccall, efriedma, aaron.ballman.
Herald added a project: All.
sepavloff requested review of this revision.
Herald added a project: clang.

Integer-to-float conversion was handled in constant evaluator with
default rounding mode. This change fixes the behavior and the conversion
is made using rounding mode stored in ImplicitCastExpr node.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137719

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/AST/const-fpfeatures.c


Index: clang/test/AST/const-fpfeatures.c
===
--- clang/test/AST/const-fpfeatures.c
+++ clang/test/AST/const-fpfeatures.c
@@ -13,6 +13,9 @@
 // CHECK: @F2u = {{.*}} float 0x3FF02000
 // CHECK: @F3u = {{.*}} float 0x3FF02000
 
+float FI1u = 0xU;
+// CHECK: @FI1u = {{.*}} float 0x41F0
+
 float _Complex C1u = C0;
 // CHECK: @C1u = {{.*}} { float, float } { float 0x3FF02000, float 
0x3FF02000 }
 
@@ -27,5 +30,8 @@
 // CHECK: @F2d = {{.*}} float 1.00e+00
 // CHECK: @F3d = {{.*}} float 1.00e+00
 
+float FI1d = 0xU;
+// CHECK: @FI1d = {{.*}} float 0x41EFE000
+
 float _Complex C1d = C0;
 // CHECK: @C1d = {{.*}} { float, float } { float 1.00e+00, float 
1.00e+00 }
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -2648,14 +2648,9 @@
  QualType SrcType, const APSInt &Value,
  QualType DestType, APFloat &Result) {
   Result = APFloat(Info.Ctx.getFloatTypeSemantics(DestType), 1);
-  APFloat::opStatus St = Result.convertFromAPInt(Value, Value.isSigned(),
-   APFloat::rmNearestTiesToEven);
-  if (!Info.InConstantContext && St != llvm::APFloatBase::opOK &&
-  FPO.isFPConstrained()) {
-Info.FFDiag(E, diag::note_constexpr_float_arithmetic_strict);
-return false;
-  }
-  return true;
+  llvm::RoundingMode RM = getActiveRoundingMode(Info, E);
+  APFloat::opStatus St = Result.convertFromAPInt(Value, Value.isSigned(), RM);
+  return checkFloatingPointResult(Info, E, St);
 }
 
 static bool truncateBitfieldValue(EvalInfo &Info, const Expr *E,


Index: clang/test/AST/const-fpfeatures.c
===
--- clang/test/AST/const-fpfeatures.c
+++ clang/test/AST/const-fpfeatures.c
@@ -13,6 +13,9 @@
 // CHECK: @F2u = {{.*}} float 0x3FF02000
 // CHECK: @F3u = {{.*}} float 0x3FF02000
 
+float FI1u = 0xU;
+// CHECK: @FI1u = {{.*}} float 0x41F0
+
 float _Complex C1u = C0;
 // CHECK: @C1u = {{.*}} { float, float } { float 0x3FF02000, float 0x3FF02000 }
 
@@ -27,5 +30,8 @@
 // CHECK: @F2d = {{.*}} float 1.00e+00
 // CHECK: @F3d = {{.*}} float 1.00e+00
 
+float FI1d = 0xU;
+// CHECK: @FI1d = {{.*}} float 0x41EFE000
+
 float _Complex C1d = C0;
 // CHECK: @C1d = {{.*}} { float, float } { float 1.00e+00, float 1.00e+00 }
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -2648,14 +2648,9 @@
  QualType SrcType, const APSInt &Value,
  QualType DestType, APFloat &Result) {
   Result = APFloat(Info.Ctx.getFloatTypeSemantics(DestType), 1);
-  APFloat::opStatus St = Result.convertFromAPInt(Value, Value.isSigned(),
-   APFloat::rmNearestTiesToEven);
-  if (!Info.InConstantContext && St != llvm::APFloatBase::opOK &&
-  FPO.isFPConstrained()) {
-Info.FFDiag(E, diag::note_constexpr_float_arithmetic_strict);
-return false;
-  }
-  return true;
+  llvm::RoundingMode RM = getActiveRoundingMode(Info, E);
+  APFloat::opStatus St = Result.convertFromAPInt(Value, Value.isSigned(), RM);
+  return checkFloatingPointResult(Info, E, St);
 }
 
 static bool truncateBitfieldValue(EvalInfo &Info, const Expr *E,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-11-09 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

Patch https://reviews.llvm.org/D137719 fixed int->float conversion.


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

https://reviews.llvm.org/D134859

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


[PATCH] D137719: [clang] Missed rounding mode use in constant evaluation

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



Comment at: clang/lib/AST/ExprConstant.cpp:2653
+  APFloat::opStatus St = Result.convertFromAPInt(Value, Value.isSigned(), RM);
+  return checkFloatingPointResult(Info, E, St);
 }

`SrcType` was already unused before, but not so is `FPO`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137719

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


[PATCH] D137720: Migrate getOrCreateInternalVariable from Clang to OMPIRBuilder.

2022-11-09 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis created this revision.
TIFitis added reviewers: jdoerfert, jsjodin.
Herald added a subscriber: hiraditya.
Herald added a project: All.
TIFitis requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

This patch removes getOrCreateInternalVariable from Clang OMP CodeGen and 
replaces it's uses with

 OMPBuilder::getOrCreateInternalVariable. Also refactors 
OMPBuilder::getOrCreateInternalVariable to change type of name
 from Twine to StringRef


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137720

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -3866,7 +3866,7 @@
   Value *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize);
   Value *ThreadId = getOrCreateThreadID(Ident);
   Constant *ThreadPrivateCache =
-  getOrCreateOMPInternalVariable(Int8PtrPtr, Name);
+  getOrCreateInternalVariable(Int8PtrPtr, Name.str());
   llvm::Value *Args[] = {Ident, ThreadId, Pointer, Size, ThreadPrivateCache};
 
   Function *Fn =
@@ -3963,18 +3963,10 @@
   return OS.str().str();
 }
 
-Constant *OpenMPIRBuilder::getOrCreateOMPInternalVariable(
-llvm::Type *Ty, const llvm::Twine &Name, unsigned AddressSpace) {
-  // TODO: Replace the twine arg with stringref to get rid of the conversion
-  // logic. However This is taken from current implementation in clang as is.
-  // Since this method is used in many places exclusively for OMP internal use
-  // we will keep it as is for temporarily until we move all users to the
-  // builder and then, if possible, fix it everywhere in one go.
-  SmallString<256> Buffer;
-  llvm::raw_svector_ostream Out(Buffer);
-  Out << Name;
-  StringRef RuntimeName = Out.str();
-  auto &Elem = *InternalVars.try_emplace(RuntimeName, nullptr).first;
+GlobalVariable *
+OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name,
+ unsigned AddressSpace) {
+  auto &Elem = *InternalVars.try_emplace(Name, nullptr).first;
   if (Elem.second) {
 assert(cast(Elem.second->getType())
->isOpaqueOrPointeeTypeMatches(Ty) &&
@@ -3984,20 +3976,19 @@
 // variable for possibly changing that to internal or private, or maybe
 // create different versions of the function for different OMP internal
 // variables.
-Elem.second = new llvm::GlobalVariable(
-M, Ty, /*IsConstant*/ false, llvm::GlobalValue::CommonLinkage,
-llvm::Constant::getNullValue(Ty), Elem.first(),
-/*InsertBefore=*/nullptr, llvm::GlobalValue::NotThreadLocal,
-AddressSpace);
+Elem.second = new GlobalVariable(
+M, Ty, /*IsConstant*/ false, GlobalValue::CommonLinkage,
+Constant::getNullValue(Ty), Elem.first(),
+/*InsertBefore=*/nullptr, GlobalValue::NotThreadLocal, AddressSpace);
   }
 
-  return Elem.second;
+  return cast(&*Elem.second);
 }
 
 Value *OpenMPIRBuilder::getOMPCriticalRegionLock(StringRef CriticalName) {
   std::string Prefix = Twine("gomp_critical_user_", CriticalName).str();
   std::string Name = getNameWithSeparators({Prefix, "var"}, ".", ".");
-  return getOrCreateOMPInternalVariable(KmpCriticalNameTy, Name);
+  return getOrCreateInternalVariable(KmpCriticalNameTy, Name);
 }
 
 GlobalVariable *
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1462,15 +1462,6 @@
StringRef FirstSeparator,
StringRef Separator);
 
-  /// Gets (if variable with the given name already exist) or creates
-  /// internal global variable with the specified Name. The created variable has
-  /// linkage CommonLinkage by default and is initialized by null value.
-  /// \param Ty Type of the global variable. If it is exist already the type
-  /// must be the same.
-  /// \param Name Name of the variable.
-  Constant *getOrCreateOMPInternalVariable(Type *Ty, const Twine &Name,
-   unsigned AddressSpace = 0);
-
   /// Returns corresponding lock object for the specified critical region
   /// name. If the lock object does not exist it is created, otherwise the
   /// reference to the existing copy is returned.
@@ -1726,6 +1717,16 @@
   void
   loadOffloadInfoMetadata(Module &M,
   OffloadEntriesInfoManager &OffloadEntriesInfoManager);
+
+  /// Gets (if variable with the given name already exist) or creates
+  /// internal gl

[PATCH] D137719: [clang] Missed rounding mode use in constant evaluation

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



Comment at: clang/lib/AST/ExprConstant.cpp:2653
+  APFloat::opStatus St = Result.convertFromAPInt(Value, Value.isSigned(), RM);
+  return checkFloatingPointResult(Info, E, St);
 }

tbaeder wrote:
> `SrcType` was already unused before, but not so is `FPO`.
//now// so is `FPO`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137719

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


[PATCH] D137720: Migrate getOrCreateInternalVariable from Clang to OMPIRBuilder.

2022-11-09 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 474284.
TIFitis added a comment.

Fix commit message indentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137720

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -3866,7 +3866,7 @@
   Value *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize);
   Value *ThreadId = getOrCreateThreadID(Ident);
   Constant *ThreadPrivateCache =
-  getOrCreateOMPInternalVariable(Int8PtrPtr, Name);
+  getOrCreateInternalVariable(Int8PtrPtr, Name.str());
   llvm::Value *Args[] = {Ident, ThreadId, Pointer, Size, ThreadPrivateCache};
 
   Function *Fn =
@@ -3963,18 +3963,10 @@
   return OS.str().str();
 }
 
-Constant *OpenMPIRBuilder::getOrCreateOMPInternalVariable(
-llvm::Type *Ty, const llvm::Twine &Name, unsigned AddressSpace) {
-  // TODO: Replace the twine arg with stringref to get rid of the conversion
-  // logic. However This is taken from current implementation in clang as is.
-  // Since this method is used in many places exclusively for OMP internal use
-  // we will keep it as is for temporarily until we move all users to the
-  // builder and then, if possible, fix it everywhere in one go.
-  SmallString<256> Buffer;
-  llvm::raw_svector_ostream Out(Buffer);
-  Out << Name;
-  StringRef RuntimeName = Out.str();
-  auto &Elem = *InternalVars.try_emplace(RuntimeName, nullptr).first;
+GlobalVariable *
+OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name,
+ unsigned AddressSpace) {
+  auto &Elem = *InternalVars.try_emplace(Name, nullptr).first;
   if (Elem.second) {
 assert(cast(Elem.second->getType())
->isOpaqueOrPointeeTypeMatches(Ty) &&
@@ -3984,20 +3976,19 @@
 // variable for possibly changing that to internal or private, or maybe
 // create different versions of the function for different OMP internal
 // variables.
-Elem.second = new llvm::GlobalVariable(
-M, Ty, /*IsConstant*/ false, llvm::GlobalValue::CommonLinkage,
-llvm::Constant::getNullValue(Ty), Elem.first(),
-/*InsertBefore=*/nullptr, llvm::GlobalValue::NotThreadLocal,
-AddressSpace);
+Elem.second = new GlobalVariable(
+M, Ty, /*IsConstant*/ false, GlobalValue::CommonLinkage,
+Constant::getNullValue(Ty), Elem.first(),
+/*InsertBefore=*/nullptr, GlobalValue::NotThreadLocal, AddressSpace);
   }
 
-  return Elem.second;
+  return cast(&*Elem.second);
 }
 
 Value *OpenMPIRBuilder::getOMPCriticalRegionLock(StringRef CriticalName) {
   std::string Prefix = Twine("gomp_critical_user_", CriticalName).str();
   std::string Name = getNameWithSeparators({Prefix, "var"}, ".", ".");
-  return getOrCreateOMPInternalVariable(KmpCriticalNameTy, Name);
+  return getOrCreateInternalVariable(KmpCriticalNameTy, Name);
 }
 
 GlobalVariable *
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1462,15 +1462,6 @@
StringRef FirstSeparator,
StringRef Separator);
 
-  /// Gets (if variable with the given name already exist) or creates
-  /// internal global variable with the specified Name. The created variable has
-  /// linkage CommonLinkage by default and is initialized by null value.
-  /// \param Ty Type of the global variable. If it is exist already the type
-  /// must be the same.
-  /// \param Name Name of the variable.
-  Constant *getOrCreateOMPInternalVariable(Type *Ty, const Twine &Name,
-   unsigned AddressSpace = 0);
-
   /// Returns corresponding lock object for the specified critical region
   /// name. If the lock object does not exist it is created, otherwise the
   /// reference to the existing copy is returned.
@@ -1726,6 +1717,16 @@
   void
   loadOffloadInfoMetadata(Module &M,
   OffloadEntriesInfoManager &OffloadEntriesInfoManager);
+
+  /// Gets (if variable with the given name already exist) or creates
+  /// internal global variable with the specified Name. The created variable has
+  /// linkage CommonLinkage by default and is initialized by null value.
+  /// \param Ty Type of the global variable. If it is exist already the type
+  /// must be the same.
+  /// \param Name Name of the variable.
+  GlobalVariable *getOrCreateInternalVariable(llvm::Type *Ty,
+   

[PATCH] D135859: [Includecleaner] Introduce RefType to ast walking

2022-11-09 Thread Maryam Moghadas via Phabricator via cfe-commits
maryammo added a comment.

@kadircet, this commit causes failure on 
https://lab.llvm.org/buildbot/#/builders/121 which is possible to reproduce 
locally, can you please take a look?

[

  35/111] Linking CXX executable 
tools/clang/tools/extra/include-cleaner/unittests/ClangIncludeCleanerTests
  FAILED: 
tools/clang/tools/extra/include-cleaner/unittests/ClangIncludeCleanerTests 
  : && /usr/lib64/ccache/c++  -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual 
-Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough 
-Wno-maybe-uninitialized -Wno-class-memaccess -Wno-noexcept-type 
-Wdelete-non-virtual-dtor -Wno-comment -Wno-misleading-indentation 
-fdiagnostics-color -ffunction-sections -fdata-sections -fno-common 
-Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG  -Wl,--gc-sections 
tools/clang/tools/extra/include-cleaner/unittests/CMakeFiles/ClangIncludeCleanerTests.dir/AnalysisTest.cpp.o
 
tools/clang/tools/extra/include-cleaner/unittests/CMakeFiles/ClangIncludeCleanerTests.dir/RecordTest.cpp.o
 
tools/clang/tools/extra/include-cleaner/unittests/CMakeFiles/ClangIncludeCleanerTests.dir/WalkASTTest.cpp.o
  -o tools/clang/tools/extra/include-cleaner/unittests/ClangIncludeCleanerTests 
 
-Wl,-rpath,/home/buildbots/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/lib
  -lpthread  lib/libllvm_gtest_main.so.16git  -lpthread  
lib/libclangIncludeCleaner.so.16git  lib/libclangTesting.so.16git  
lib/libLLVMTestingSupport.so.16git  
lib/libclangToolingInclusionsStdlib.so.16git  lib/libllvm_gtest.so.16git  
lib/libclangFrontend.so.16git  lib/libclangAST.so.16git  
lib/libclangBasic.so.16git  lib/libLLVMSupport.so.16git  
-Wl,-rpath-link,/home/buildbots/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/lib
 && :
  /usr/bin/ld: 
tools/clang/tools/extra/include-cleaner/unittests/CMakeFiles/ClangIncludeCleanerTests.dir/RecordTest.cpp.o:
 undefined reference to symbol '_ZTVN5clang18PPChainedCallbacksE'
  
/home/buildbots/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/lib/libclangLex.so.16git:
 error adding symbols: DSO missing from command line
  collect2: error: ld returned 1 exit status
  [79/111] cd 
/home/buildbots/ppc64le-clang-multistage-test/clang-ppc64le-multistage/llvm/clang/bindings/python
 && /usr/local/bin/cmake -E env 
CLANG_LIBRARY_PATH=/home/buildbots/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/lib
 /usr/bin/python3.6 -m unittest discover
  ..
  
  
  cmake -G Ninja ../llvm-project/llvm -DCMAKE_BUILD_TYPE=Release 
-DLLVM_ENABLE_ASSERTIONS=True '-DLLVM_LIT_ARGS='"'"'-v'"'"'' 
-DCMAKE_INSTALL_PREFIX=../stage1.install -DLLVM_ENABLE_ASSERTIONS=ON 
-DLLVM_ENABLE_RUNTIMES=compiler-rt -DBUILD_SHARED_LIBS=ON 
-DLLVM_CCACHE_BUILD=ON '-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra;llvm'
  
  ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135859

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


[PATCH] D137722: [clang][analyzer] No new nodes when bug is detected in StdLibraryFunctionsChecker.

2022-11-09 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, gamesh411, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a reviewer: NoQ.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If a constraint violation was found the already applied other constraints were 
already added
and analysis was continuing on this path even if bug is reported. After the fix 
the error node
is added as the last node on the current path.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137722

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c


Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -20,6 +20,7 @@
 // RUN:   -verify=bugpath
 
 void clang_analyzer_eval(int);
+void clang_analyzer_warnIfReached();
 
 int glob;
 
@@ -215,6 +216,20 @@
 // bugpath-note{{}} \
 // bugpath-note{{Function argument constraint is not satisfied}}
 }
+void test_no_node_after_bug(FILE *fp, size_t size, size_t n, void *buf) {
+  if (fp) // \
+  // bugpath-note{{Assuming 'fp' is null}} \
+  // bugpath-note{{Taking false branch}}
+return;
+  size_t ret = fread(buf, size, n, fp); // \
+  // report-warning{{Function argument constraint is not satisfied}} \
+  // report-note{{}} \
+  // bugpath-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-note{{}} \
+  // bugpath-note{{Function argument constraint is not satisfied}}
+  clang_analyzer_warnIfReached(); // not reachable
+}
+
 typedef __WCHAR_TYPE__ wchar_t;
 // This is one test case for the ARR38-C SEI-CERT rule.
 void ARR38_C_F(FILE *file) {
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -950,7 +950,7 @@
 Constraint->negate()->apply(NewState, Call, Summary, C);
 // The argument constraint is not satisfied.
 if (FailureSt && !SuccessSt) {
-  if (ExplodedNode *N = C.generateErrorNode(NewState))
+  if (ExplodedNode *N = C.generateErrorNode(NewState, NewNode))
 reportBug(Call, N, Constraint.get(), Summary, C);
   break;
 }
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
@@ -211,6 +211,22 @@
(Tag ? Tag : Location.getTag()));
   }
 
+  /// Generate a transition to a node that will be used to report
+  /// an error. This node will be a sink. That is, it will stop exploration of
+  /// the given path.
+  ///
+  /// @param State The state of the generated node.
+  /// @param Pred The transition will be generated from the specified Pred node
+  /// to the newly generated node.
+  /// @param Tag The tag to uniquely identify the creation site. If null,
+  ///the default tag for the checker will be used.
+  ExplodedNode *generateErrorNode(ProgramStateRef State,
+  ExplodedNode *Pred,
+  const ProgramPointTag *Tag = nullptr) {
+return generateSink(State, Pred,
+   (Tag ? Tag : Location.getTag()));
+  }
+
   /// Generate a transition to a node that will be used to report
   /// an error. This node will not be a sink. That is, exploration will
   /// continue along this path.


Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -20,6 +20,7 @@
 // RUN:   -verify=bugpath
 
 void clang_analyzer_eval(int);
+void clang_analyzer_warnIfReached();
 
 int glob;
 
@@ -215,6 +216,20 @@
 // bugpath-note{{}} \
 // bugpath-note{{Function argument constraint is not satisfied}}
 }
+void test_no_node_after_bug(FILE *fp, size_t size, size_t n, void *buf) {
+  if (fp) // \
+  // bugpath-note{{Assuming 'fp' is null}} \
+  // bugpath-note{{Taking false branch}}
+return;
+  size_t ret = fread(buf, size, n, fp); // \
+  // report-warning{{Function argument constraint is not satisfied}} \
+  // report-note{{}}

[PATCH] D137724: [CMake] Warn when the version is older than 3.20.0.

2022-11-09 Thread Mark de Wever via Phabricator via cfe-commits
Mordante created this revision.
Herald added a reviewer: bollu.
Herald added subscribers: Moerafaat, zero9178, Enna1, bzcheeseman, sdasgup3, 
wenzhicui, wrengr, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, 
Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, 
antiagainst, shauheen, rriddle, mehdi_amini.
Herald added projects: Flang, All.
Mordante edited the summary of this revision.
Mordante added reviewers: libc++ vendors, clang-vendors, tstellar, mehdi_amini, 
MaskRay, ChuanqiXu, to268, kparzysz, thieta, tschuett, mgorny, stellaraccident, 
mizvekov, ldionne.
Herald added subscribers: StephenFan, jdoerfert.
Mordante published this revision for review.
Herald added subscribers: llvm-commits, libcxx-commits, openmp-commits, 
lldb-commits, Sanitizers, cfe-commits, stephenneuendorffer, nicolasvasilache.
Herald added projects: clang, Sanitizers, LLDB, libc++, OpenMP, libc++abi, 
MLIR, LLVM.
Herald added a reviewer: libc++.
Herald added a reviewer: libc++abi.

This is a preparation to require CMake 3.20.0 after LLVM 16 has been
released.

This change has been discussed on discourse
https://discourse.llvm.org/t/rfc-upgrading-llvms-minimum-required-cmake-version/66193


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137724

Files:
  clang/CMakeLists.txt
  compiler-rt/CMakeLists.txt
  compiler-rt/lib/builtins/CMakeLists.txt
  compiler-rt/lib/crt/CMakeLists.txt
  flang/CMakeLists.txt
  flang/runtime/CMakeLists.txt
  lld/CMakeLists.txt
  lldb/CMakeLists.txt
  lldb/tools/debugserver/CMakeLists.txt
  llvm/CMakeLists.txt
  llvm/docs/ReleaseNotes.rst
  mlir/CMakeLists.txt
  openmp/CMakeLists.txt
  polly/CMakeLists.txt
  runtimes/CMakeLists.txt

Index: runtimes/CMakeLists.txt
===
--- runtimes/CMakeLists.txt
+++ runtimes/CMakeLists.txt
@@ -1,5 +1,12 @@
 # This file handles building LLVM runtime sub-projects.
 cmake_minimum_required(VERSION 3.13.4)
+if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
+  message(WARNING
+"Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
+"minimum version of CMake required to build LLVM will become 3.20.0, and "
+"using an older CMake will become an error. Please upgrade your CMake to "
+"at least 3.20.0 now to avoid issues in the future!")
+endif()
 project(Runtimes C CXX ASM)
 
 # Add path for custom and the LLVM build's modules to the CMake module path.
Index: polly/CMakeLists.txt
===
--- polly/CMakeLists.txt
+++ polly/CMakeLists.txt
@@ -2,6 +2,13 @@
 if (NOT DEFINED LLVM_MAIN_SRC_DIR)
   project(Polly)
   cmake_minimum_required(VERSION 3.13.4)
+  if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
+message(WARNING
+  "Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
+  "minimum version of CMake required to build LLVM will become 3.20.0, and "
+  "using an older CMake will become an error. Please upgrade your CMake to "
+  "at least 3.20.0 now to avoid issues in the future!")
+  endif()
   set(POLLY_STANDALONE_BUILD TRUE)
 endif()
 
Index: openmp/CMakeLists.txt
===
--- openmp/CMakeLists.txt
+++ openmp/CMakeLists.txt
@@ -12,6 +12,13 @@
 if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
   set(OPENMP_STANDALONE_BUILD TRUE)
   project(openmp C CXX)
+  if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
+message(WARNING
+  "Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
+  "minimum version of CMake required to build LLVM will become 3.20.0, and "
+  "using an older CMake will become an error. Please upgrade your CMake to "
+  "at least 3.20.0 now to avoid issues in the future!")
+  endif()
 endif()
 
 # Must go below project(..)
Index: mlir/CMakeLists.txt
===
--- mlir/CMakeLists.txt
+++ mlir/CMakeLists.txt
@@ -11,6 +11,13 @@
 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   project(mlir)
   set(MLIR_STANDALONE_BUILD TRUE)
+  if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
+message(WARNING
+  "Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
+  "minimum version of CMake required to build LLVM will become 3.20.0, and "
+  "using an older CMake will become an error. Please upgrade your CMake to "
+  "at least 3.20.0 now to avoid issues in the future!")
+  endif()
 endif()
 
 # Must go below project(..)
Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -64,6 +64,17 @@
 * Apple Clang >= 10.0
 * Visual Studio 2019 >= 16.7
 
+With LLVM 16.x we will raise the version requirement of CMake used to build
+LLVM. The new requirements are as follows:
+
+* CMake >= 3.20.0
+
+In LLVM 16.x t

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

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

I dont have a good hold as to why this is the solution, can you better explain 
the issue and the solution that you made?  I will take a look when I get a 
chance next week, as the ISO meeting is taking up my week.


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


[PATCH] D137724: [CMake] Warn when the version is older than 3.20.0.

2022-11-09 Thread Tobias Hieta via Phabricator via cfe-commits
thieta accepted this revision as: thieta.
thieta added a comment.
Herald added a reviewer: jdoerfert.
Herald added subscribers: sstefan1, JDevlieghere.

I think this is fine as we have discussed before. But I really dislike the code 
duplication for the check. We could put it in a include() I guess - but maybe 
it's not worth it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137724

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


[PATCH] D137724: [CMake] Warn when the version is older than 3.20.0.

2022-11-09 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

In D137724#3917616 , @thieta wrote:

> I think this is fine as we have discussed before. But I really dislike the 
> code duplication for the check. We could put it in a include() I guess - but 
> maybe it's not worth it.

I wanted to make sure it shows up in different build scenarios. The code is 
temporary, once we switch to CMake 3.20.0 we can just change the 
`cmake_minimum_required` and remove these verbose blocks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137724

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


[clang-tools-extra] 453c287 - [include-cleaner] Add dependency to fix build with shared libraries

2022-11-09 Thread Ilya Biryukov via cfe-commits

Author: Ilya Biryukov
Date: 2022-11-09T18:31:14+01:00
New Revision: 453c2879cb2ad6c46267ef8f39f0274aed69d9ee

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

LOG: [include-cleaner] Add dependency to fix build with shared libraries

Added: 


Modified: 
clang-tools-extra/include-cleaner/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt 
b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
index ba9fc6419f388..8fdd855c7a1a6 100644
--- a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -19,6 +19,7 @@ clang_target_link_libraries(ClangIncludeCleanerTests
   clangAST
   clangBasic
   clangFrontend
+  clangLex
   clangToolingInclusionsStdlib
   )
 



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


[PATCH] D135859: [Includecleaner] Introduce RefType to ast walking

2022-11-09 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Sent out rG453c2879cb2ad6c46267ef8f39f0274aed69d9ee 
 to fix 
this


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135859

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


[PATCH] D91950: [clang-format] Add BreakBeforeInlineASMColon configuration

2022-11-09 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I think this is them..

https://twitter.com/xen_org/status/1397581514318225412

https://xenproject.org/


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

https://reviews.llvm.org/D91950

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


[PATCH] D136146: [Clang][LoongArch] Handle -march/-m{single,double,soft}-float/-mfpu options

2022-11-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

In D136146#3911137 , @SixWeining 
wrote:

> Sorry for the late reply.
>
> Should we choose not to implement the `-mfpu=` option which is not mandatory?

OK, I accept the `-mfpu=` different from `-m*-float`. If the patch does not 
implement the required semantics, deferring `-mfpu=` implementation may be good.
We can also check how many pieces of software actually use `-mfpu=` and some 
unneeded uses may be removed?




Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:696
+def err_drv_loongarch_invalid_mfpu_EQ : Error<
+  "invalid argument '%0' to -mfpu=; must be one of: 64, 32, 0, none">;
 }

`0, none (alias for 0)` or `none, 0 (alias for none)`

Ideally only one spelling is retained... No need to implement an alias if 
-mfpu= itself is niche.



Comment at: llvm/lib/Support/LoongArchTargetParser.cpp:46
+if ((A.Features & F.Kind) == F.Kind && F.Kind != FK_INVALID) {
+  Features.push_back(F.Name);
+}

SixWeining wrote:
> MaskRay wrote:
> > delete braces
> OK.
`for (const auto A : AllArchs)` needs braces since the nested `if (A.Name == 
Arch) {` has braces.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136146

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


[PATCH] D137724: [CMake] Warn when the version is older than 3.20.0.

2022-11-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision as: MaskRay.
MaskRay added a comment.

I think `if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)` checks for 
standalone builds is not necessary. The check in `llvm/CMakeLists.txt` suffices.
It's unlikely the users will use different cmake versions to configure llvm and 
a subproject like clang.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137724

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


[PATCH] D137724: [CMake] Warn when the version is older than 3.20.0.

2022-11-09 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

In D137724#3917644 , @MaskRay wrote:

> I think `if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)` checks for 
> standalone builds is not necessary. The check in `llvm/CMakeLists.txt` 
> suffices.
> It's unlikely the users will use different cmake versions to configure llvm 
> and a subproject like clang.

I can remove the others, but we need to keep the one in 
`runtimes/CMakeLists.txt` too. The runtimes (libc++, libc++abi, and libunwind) 
can be build without building or configuring LLVM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137724

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


[PATCH] D137719: [clang] Missed rounding mode use in constant evaluation

2022-11-09 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 474303.
sepavloff added a comment.

Removed unused parateters from HandleIntToFloatCast


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137719

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/AST/const-fpfeatures.c
  clang/test/Sema/constant-conversion.c

Index: clang/test/Sema/constant-conversion.c
===
--- clang/test/Sema/constant-conversion.c
+++ clang/test/Sema/constant-conversion.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -ffreestanding -verify=expected,one-bit -triple x86_64-apple-darwin %s
-// RUN: %clang_cc1 -fsyntax-only -ffreestanding -Wno-single-bit-bitfield-constant-conversion -verify -triple x86_64-apple-darwin %s
+// RUN: %clang_cc1 -fsyntax-only -ffreestanding -Wno-unknown-pragmas -verify=expected,one-bit -triple x86_64-apple-darwin %s
+// RUN: %clang_cc1 -fsyntax-only -ffreestanding -Wno-unknown-pragmas -Wno-single-bit-bitfield-constant-conversion -verify -triple x86_64-apple-darwin %s
 
 #include 
 
Index: clang/test/AST/const-fpfeatures.c
===
--- clang/test/AST/const-fpfeatures.c
+++ clang/test/AST/const-fpfeatures.c
@@ -13,6 +13,9 @@
 // CHECK: @F2u = {{.*}} float 0x3FF02000
 // CHECK: @F3u = {{.*}} float 0x3FF02000
 
+float FI1u = 0xU;
+// CHECK: @FI1u = {{.*}} float 0x41F0
+
 float _Complex C1u = C0;
 // CHECK: @C1u = {{.*}} { float, float } { float 0x3FF02000, float 0x3FF02000 }
 
@@ -27,5 +30,8 @@
 // CHECK: @F2d = {{.*}} float 1.00e+00
 // CHECK: @F3d = {{.*}} float 1.00e+00
 
+float FI1d = 0xU;
+// CHECK: @FI1d = {{.*}} float 0x41EFE000
+
 float _Complex C1d = C0;
 // CHECK: @C1d = {{.*}} { float, float } { float 1.00e+00, float 1.00e+00 }
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -2644,18 +2644,12 @@
 }
 
 static bool HandleIntToFloatCast(EvalInfo &Info, const Expr *E,
- const FPOptions FPO,
- QualType SrcType, const APSInt &Value,
- QualType DestType, APFloat &Result) {
+ const APSInt &Value, QualType DestType,
+ APFloat &Result) {
   Result = APFloat(Info.Ctx.getFloatTypeSemantics(DestType), 1);
-  APFloat::opStatus St = Result.convertFromAPInt(Value, Value.isSigned(),
-   APFloat::rmNearestTiesToEven);
-  if (!Info.InConstantContext && St != llvm::APFloatBase::opOK &&
-  FPO.isFPConstrained()) {
-Info.FFDiag(E, diag::note_constexpr_float_arithmetic_strict);
-return false;
-  }
-  return true;
+  llvm::RoundingMode RM = getActiveRoundingMode(Info, E);
+  APFloat::opStatus St = Result.convertFromAPInt(Value, Value.isSigned(), RM);
+  return checkFloatingPointResult(Info, E, St);
 }
 
 static bool truncateBitfieldValue(EvalInfo &Info, const Expr *E,
@@ -4413,11 +4407,8 @@
   Value = HandleIntToIntCast(Info, E, SubobjType, PromotedLHSType, LHS);
   return true;
 } else if (RHS.isFloat()) {
-  const FPOptions FPO = E->getFPFeaturesInEffect(
-Info.Ctx.getLangOpts());
   APFloat FValue(0.0);
-  return HandleIntToFloatCast(Info, E, FPO, SubobjType, Value,
-  PromotedLHSType, FValue) &&
+  return HandleIntToFloatCast(Info, E, Value, PromotedLHSType, FValue) &&
  handleFloatFloatBinOp(Info, E, FValue, Opcode, RHS.getFloat()) &&
  HandleFloatToIntCast(Info, E, PromotedLHSType, FValue, SubobjType,
   Value);
@@ -14169,11 +14160,8 @@
 
   case CK_IntegralToFloating: {
 APSInt IntResult;
-const FPOptions FPO = E->getFPFeaturesInEffect(
-  Info.Ctx.getLangOpts());
 return EvaluateInteger(SubExpr, IntResult, Info) &&
-   HandleIntToFloatCast(Info, E, FPO, SubExpr->getType(),
-IntResult, E->getType(), Result);
+   HandleIntToFloatCast(Info, E, IntResult, E->getType(), Result);
   }
 
   case CK_FixedPointToFloating: {
@@ -14414,16 +14402,11 @@
 if (!Visit(E->getSubExpr()))
   return false;
 
-const FPOptions FPO = E->getFPFeaturesInEffect(
-  Info.Ctx.getLangOpts());
 QualType To = E->getType()->castAs()->getElementType();
-QualType From
-  = E->getSubExpr()->getType()->castAs()->getElementType();
 Result.makeComplexFloat();
-return HandleIntToFloatCast(Info, E, FPO, From, Result.IntReal,
-To, Result.FloatReal) &&
-   HandleIntToFloatCast(Info, E, FPO, From, Result.IntImag,
-   

[PATCH] D137719: [clang] Missed rounding mode use in constant evaluation

2022-11-09 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 474304.
sepavloff added a comment.

Remove accidentally added file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137719

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/AST/const-fpfeatures.c


Index: clang/test/AST/const-fpfeatures.c
===
--- clang/test/AST/const-fpfeatures.c
+++ clang/test/AST/const-fpfeatures.c
@@ -13,6 +13,9 @@
 // CHECK: @F2u = {{.*}} float 0x3FF02000
 // CHECK: @F3u = {{.*}} float 0x3FF02000
 
+float FI1u = 0xU;
+// CHECK: @FI1u = {{.*}} float 0x41F0
+
 float _Complex C1u = C0;
 // CHECK: @C1u = {{.*}} { float, float } { float 0x3FF02000, float 
0x3FF02000 }
 
@@ -27,5 +30,8 @@
 // CHECK: @F2d = {{.*}} float 1.00e+00
 // CHECK: @F3d = {{.*}} float 1.00e+00
 
+float FI1d = 0xU;
+// CHECK: @FI1d = {{.*}} float 0x41EFE000
+
 float _Complex C1d = C0;
 // CHECK: @C1d = {{.*}} { float, float } { float 1.00e+00, float 
1.00e+00 }
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -2644,18 +2644,12 @@
 }
 
 static bool HandleIntToFloatCast(EvalInfo &Info, const Expr *E,
- const FPOptions FPO,
- QualType SrcType, const APSInt &Value,
- QualType DestType, APFloat &Result) {
+ const APSInt &Value, QualType DestType,
+ APFloat &Result) {
   Result = APFloat(Info.Ctx.getFloatTypeSemantics(DestType), 1);
-  APFloat::opStatus St = Result.convertFromAPInt(Value, Value.isSigned(),
-   APFloat::rmNearestTiesToEven);
-  if (!Info.InConstantContext && St != llvm::APFloatBase::opOK &&
-  FPO.isFPConstrained()) {
-Info.FFDiag(E, diag::note_constexpr_float_arithmetic_strict);
-return false;
-  }
-  return true;
+  llvm::RoundingMode RM = getActiveRoundingMode(Info, E);
+  APFloat::opStatus St = Result.convertFromAPInt(Value, Value.isSigned(), RM);
+  return checkFloatingPointResult(Info, E, St);
 }
 
 static bool truncateBitfieldValue(EvalInfo &Info, const Expr *E,
@@ -4413,11 +4407,8 @@
   Value = HandleIntToIntCast(Info, E, SubobjType, PromotedLHSType, LHS);
   return true;
 } else if (RHS.isFloat()) {
-  const FPOptions FPO = E->getFPFeaturesInEffect(
-Info.Ctx.getLangOpts());
   APFloat FValue(0.0);
-  return HandleIntToFloatCast(Info, E, FPO, SubobjType, Value,
-  PromotedLHSType, FValue) &&
+  return HandleIntToFloatCast(Info, E, Value, PromotedLHSType, FValue) &&
  handleFloatFloatBinOp(Info, E, FValue, Opcode, RHS.getFloat()) &&
  HandleFloatToIntCast(Info, E, PromotedLHSType, FValue, SubobjType,
   Value);
@@ -14169,11 +14160,8 @@
 
   case CK_IntegralToFloating: {
 APSInt IntResult;
-const FPOptions FPO = E->getFPFeaturesInEffect(
-  Info.Ctx.getLangOpts());
 return EvaluateInteger(SubExpr, IntResult, Info) &&
-   HandleIntToFloatCast(Info, E, FPO, SubExpr->getType(),
-IntResult, E->getType(), Result);
+   HandleIntToFloatCast(Info, E, IntResult, E->getType(), Result);
   }
 
   case CK_FixedPointToFloating: {
@@ -14414,16 +14402,11 @@
 if (!Visit(E->getSubExpr()))
   return false;
 
-const FPOptions FPO = E->getFPFeaturesInEffect(
-  Info.Ctx.getLangOpts());
 QualType To = E->getType()->castAs()->getElementType();
-QualType From
-  = E->getSubExpr()->getType()->castAs()->getElementType();
 Result.makeComplexFloat();
-return HandleIntToFloatCast(Info, E, FPO, From, Result.IntReal,
-To, Result.FloatReal) &&
-   HandleIntToFloatCast(Info, E, FPO, From, Result.IntImag,
-To, Result.FloatImag);
+return HandleIntToFloatCast(Info, E, Result.IntReal, To,
+Result.FloatReal) &&
+   HandleIntToFloatCast(Info, E, Result.IntImag, To, Result.FloatImag);
   }
   }
 


Index: clang/test/AST/const-fpfeatures.c
===
--- clang/test/AST/const-fpfeatures.c
+++ clang/test/AST/const-fpfeatures.c
@@ -13,6 +13,9 @@
 // CHECK: @F2u = {{.*}} float 0x3FF02000
 // CHECK: @F3u = {{.*}} float 0x3FF02000
 
+float FI1u = 0xU;
+// CHECK: @FI1u = {{.*}} float 0x41F0
+
 float _Complex C1u = C0;
 // CHECK: @C1u = {{.*}} { float, float } { float 0x3FF02000, float 0x3FF02000 }
 
@@ -27,5 +30,8 @@
 // CHECK: @F2d = {{.*}} float 1.

[PATCH] D137154: Adding nvvm_reflect clang builtin

2022-11-09 Thread Hugh Delaney via Phabricator via cfe-commits
hdelan added a comment.

Thanks for feedback. Instead of adding `__nvvm_reflect` as a clang builtin, 
would it be acceptable if I modified the NVVMReflect pass so that it works with 
addrspace casting as well? This would allow us to use `__nvvm_reflect` in openCL


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137154

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


[PATCH] D137583: [lldb] Fix simple template names and template params with scope qualifiers

2022-11-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

> ...we expect template params to be fully qualified when comparing them for 
> simple template names

So lldb is not inspecting the AST, they're doing reflection (of a sort) on the 
pretty printed names? Or am I misunderstanding something?




Comment at: clang/include/clang/AST/PrettyPrinter.h:134
+  /// When SuppressScope is true, do not apply it to template parameters.
+  unsigned NoSuppressTemplateParamsScope : 1;
+

I think this should be expressed in the positive rather than in the negative 
(`SuppressTemplateParamScope`) so it's consistent with the rest of the options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137583

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


[clang-tools-extra] 82ca918 - [clangd] Fix the code action `RemoveUsingNamespace`

2022-11-09 Thread Tom Praschan via cfe-commits

Author: v1nh1shungry
Date: 2022-11-09T21:04:21+01:00
New Revision: 82ca918b5755f3c442e247563dc011f7b310e446

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

LOG: [clangd] Fix the code action `RemoveUsingNamespace`

Avoid adding qualifiers before user-defined literals

Reviewed By: tom-anders

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

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
index 93fdbb9486cc7..f4228ae0be1f8 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,12 +155,23 @@ Expected RemoveUsingNamespace::apply(const 
Selection &Inputs) {
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+auto Kind = T->getDeclName().getNameKind();
 // Avoid adding qualifiers before operators, e.g.
 //   using namespace std;
 //   cout << "foo"; // Must not changed to std::cout std:: << "foo"
-// FIXME: User-defined literals are not handled
-if (T->isInIdentifierNamespace(
-Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+if (Kind == DeclarationName::CXXOperatorName)
+  return;
+// Avoid adding qualifiers before user-defined literals, e.g.
+//   using namespace std;
+//   auto s = "foo"s; // Must not changed to auto s = "foo" std::s;
+// FIXME: Add a using-directive for user-defined literals
+// declared in an inline namespace, e.g.
+//   using namespace s^td;
+//   int main() { cout << "foo"s; }
+// change to
+//   using namespace std::literals;
+//   int main() { std::cout << "foo"s; }
+if (Kind == DeclarationName::NameKind::CXXLiteralOperatorName)
   return;
   }
   SourceLocation Loc = Ref.NameLoc;

diff  --git 
a/clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
index 3449c6475e3fc..03a46d954fcd4 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -249,6 +249,21 @@ TEST_F(RemoveUsingNamespaceTest, All) {
 ns::Foo foo;
 foo + 10;
   }
+)cpp"},
+  {// Does not qualify user-defined literals
+   R"cpp(
+  namespace ns {
+  long double operator "" _w(long double);
+  }
+  using namespace n^s;
+  int main() { 1.5_w; }
+)cpp",
+   R"cpp(
+  namespace ns {
+  long double operator "" _w(long double);
+  }
+  
+  int main() { 1.5_w; }
 )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;



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


[PATCH] D137550: [clangd] Fix the code action `RemoveUsingNamespace`

2022-11-09 Thread Tom Praschan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG82ca918b5755: [clangd] Fix the code action 
`RemoveUsingNamespace` (authored by v1nh1shungry, committed by tom-anders).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137550

Files:
  clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
  clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -249,6 +249,21 @@
 ns::Foo foo;
 foo + 10;
   }
+)cpp"},
+  {// Does not qualify user-defined literals
+   R"cpp(
+  namespace ns {
+  long double operator "" _w(long double);
+  }
+  using namespace n^s;
+  int main() { 1.5_w; }
+)cpp",
+   R"cpp(
+  namespace ns {
+  long double operator "" _w(long double);
+  }
+  
+  int main() { 1.5_w; }
 )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,12 +155,23 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+auto Kind = T->getDeclName().getNameKind();
 // Avoid adding qualifiers before operators, e.g.
 //   using namespace std;
 //   cout << "foo"; // Must not changed to std::cout std:: << "foo"
-// FIXME: User-defined literals are not handled
-if (T->isInIdentifierNamespace(
-Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+if (Kind == DeclarationName::CXXOperatorName)
+  return;
+// Avoid adding qualifiers before user-defined literals, e.g.
+//   using namespace std;
+//   auto s = "foo"s; // Must not changed to auto s = "foo" std::s;
+// FIXME: Add a using-directive for user-defined literals
+// declared in an inline namespace, e.g.
+//   using namespace s^td;
+//   int main() { cout << "foo"s; }
+// change to
+//   using namespace std::literals;
+//   int main() { std::cout << "foo"s; }
+if (Kind == DeclarationName::NameKind::CXXLiteralOperatorName)
   return;
   }
   SourceLocation Loc = Ref.NameLoc;


Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -249,6 +249,21 @@
 ns::Foo foo;
 foo + 10;
   }
+)cpp"},
+  {// Does not qualify user-defined literals
+   R"cpp(
+  namespace ns {
+  long double operator "" _w(long double);
+  }
+  using namespace n^s;
+  int main() { 1.5_w; }
+)cpp",
+   R"cpp(
+  namespace ns {
+  long double operator "" _w(long double);
+  }
+  
+  int main() { 1.5_w; }
 )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,12 +155,23 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+auto Kind = T->getDeclName().getNameKind();
 // Avoid adding qualifiers before operators, e.g.
 //   using namespace std;
 //   cout << "foo"; // Must not changed to std::cout std:: << "foo"
-// FIXME: User-defined literals are not handled
-if (T->isInIdentifierNamespace(
-Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+if (Kind == DeclarationName::CXXOperatorName)
+  return;
+// Avoid adding qualifiers before user-defined literals, e.g.
+//   using namespace std;
+//   auto s = "foo"s; // Must not changed to auto s = "foo" std::s;
+// FIXME: Add a using-directive for user-de

[PATCH] D137232: [clang][Interp] Support inc/dec operators on pointers

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



Comment at: clang/test/AST/Interp/arrays.cpp:216
 
-  static_assert(getNextElem(E, 1) == 3);
-#endif
+  static_assert(getNextElem(E, 1) == 3, "");
+

aaron.ballman wrote:
> I'd like test cases where the pointer arithmetic has run off the 
> beginning/end of the object (forming the invalid pointer is UB per 
> http://eel.is/c++draft/expr.add#4.3 even if you never dereference the 
> pointer).
```
constexpr int bad1() {
  const int *e =  E + 3;
  e++; // This is fine because it's a one-past-the-end pointer
  return *e; // This is UB
}

constexpr int bad2() {
  const int *e = E + 4;
  e++; // This is UB
  return *e; // This is UB as well
}

constexpr int bad3() {
  const int *e = E;
  --e; // This is UB
  return *e; // This is UB as well
}
```


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

https://reviews.llvm.org/D137232

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


[PATCH] D131919: Move googletest to the third-party directory

2022-11-09 Thread Tom Stellard 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 rG59052468c3e3: Move googletest to the third-party directory 
(authored by tstellar).

Changed prior to commit:
  https://reviews.llvm.org/D131919?vs=468784&id=474310#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131919

Files:
  clang/CMakeLists.txt
  compiler-rt/CMakeLists.txt
  lld/CMakeLists.txt
  lldb/cmake/modules/LLDBStandalone.cmake
  llvm/CMakeLists.txt
  llvm/cmake/modules/HandleLLVMOptions.cmake
  llvm/utils/unittest/CMakeLists.txt
  llvm/utils/unittest/UnitTestMain/CMakeLists.txt
  llvm/utils/unittest/UnitTestMain/TestMain.cpp
  llvm/utils/unittest/googlemock/LICENSE.txt
  llvm/utils/unittest/googlemock/README.LLVM
  llvm/utils/unittest/googlemock/include/gmock/gmock-actions.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-cardinalities.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-function-mocker.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-generated-actions.h
  
llvm/utils/unittest/googlemock/include/gmock/gmock-generated-function-mockers.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-generated-matchers.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-matchers.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-more-actions.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-more-matchers.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-nice-strict.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-spec-builders.h
  llvm/utils/unittest/googlemock/include/gmock/gmock.h
  
llvm/utils/unittest/googlemock/include/gmock/internal/custom/gmock-generated-actions.h
  llvm/utils/unittest/googlemock/include/gmock/internal/custom/gmock-matchers.h
  llvm/utils/unittest/googlemock/include/gmock/internal/custom/gmock-port.h
  llvm/utils/unittest/googlemock/include/gmock/internal/gmock-internal-utils.h
  llvm/utils/unittest/googlemock/include/gmock/internal/gmock-port.h
  llvm/utils/unittest/googlemock/include/gmock/internal/gmock-pp.h
  llvm/utils/unittest/googlemock/src/gmock-all.cc
  llvm/utils/unittest/googlemock/src/gmock-cardinalities.cc
  llvm/utils/unittest/googlemock/src/gmock-internal-utils.cc
  llvm/utils/unittest/googlemock/src/gmock-matchers.cc
  llvm/utils/unittest/googlemock/src/gmock-spec-builders.cc
  llvm/utils/unittest/googlemock/src/gmock.cc
  llvm/utils/unittest/googletest/LICENSE.TXT
  llvm/utils/unittest/googletest/README.LLVM
  llvm/utils/unittest/googletest/include/gtest/gtest-death-test.h
  llvm/utils/unittest/googletest/include/gtest/gtest-matchers.h
  llvm/utils/unittest/googletest/include/gtest/gtest-message.h
  llvm/utils/unittest/googletest/include/gtest/gtest-param-test.h
  llvm/utils/unittest/googletest/include/gtest/gtest-printers.h
  llvm/utils/unittest/googletest/include/gtest/gtest-spi.h
  llvm/utils/unittest/googletest/include/gtest/gtest-test-part.h
  llvm/utils/unittest/googletest/include/gtest/gtest-typed-test.h
  llvm/utils/unittest/googletest/include/gtest/gtest.h
  llvm/utils/unittest/googletest/include/gtest/gtest_pred_impl.h
  llvm/utils/unittest/googletest/include/gtest/gtest_prod.h
  llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest-port.h
  llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest-printers.h
  llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest.h
  llvm/utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h
  
llvm/utils/unittest/googletest/include/gtest/internal/gtest-death-test-internal.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-filepath.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-internal.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-param-util.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-port-arch.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-string.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-type-util.h
  llvm/utils/unittest/googletest/src/gtest-all.cc
  llvm/utils/unittest/googletest/src/gtest-death-test.cc
  llvm/utils/unittest/googletest/src/gtest-filepath.cc
  llvm/utils/unittest/googletest/src/gtest-internal-inl.h
  llvm/utils/unittest/googletest/src/gtest-matchers.cc
  llvm/utils/unittest/googletest/src/gtest-port.cc
  llvm/utils/unittest/googletest/src/gtest-printers.cc
  llvm/utils/unittest/googletest/src/gtest-test-part.cc
  llvm/utils/unittest/googletest/src/gtest-typed-test.cc
  llvm/utils/unittest/googletest/src/gtest.cc
  mlir/CMakeLists.txt
  polly/CMakeLists.txt
  third-party/unittest/CMakeLists.txt
  third-party/unittest/UnitTestMain/CMakeLists.txt
  third-party/unittest/UnitTestMain/TestMain.cpp
  third-party/unittest/googlemock/LICENSE.txt
  third-party/unittest/googlemock/README.LLVM
  third-part

[PATCH] D137386: [clang][Interp] Reject invalid declarations and expressions

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



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1235-1236
 bool ByteCodeExprGen::visitDecl(const VarDecl *VD) {
-  Optional VarT = classify(VD->getType());
+  if (VD->isInvalidDecl())
+return false;
 

Because we can't find a case where we hit this, I think we should try asserting 
instead.


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

https://reviews.llvm.org/D137386

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


[PATCH] D137372: [Test][[AIX][pg] Add 32-bit linker invocation tests

2022-11-09 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm accepted this revision.
cebowleratibm added a comment.
This revision is now accepted and ready to land.

LGTM.

Test only patch is safe to commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137372

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


[PATCH] D137583: [lldb] Fix simple template names and template params with scope qualifiers

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

In D137583#3917706 , @aaron.ballman 
wrote:

>> ...we expect template params to be fully qualified when comparing them for 
>> simple template names
>
> So lldb is not inspecting the AST, they're doing reflection (of a sort) on 
> the pretty printed names? Or am I misunderstanding something?

Not reflection as such - but building names for the user, but partly from the 
AST - basically LLDB wants to be able to produce the same name that CGDebugInfo 
produces - so, maybe it should produce it the same way as CGDebugInfo, which 
isn't to use the pretty printer from scratch.

@aeubanks would this work for lldb's use case? 
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGDebugInfo.cpp#L5229
 it'd be identical to the original debug info generation, and looks like it 
doesn't require a printing policy change/feature. Sorry I didn't think of that 
earlier. I guess since `Qualified` would be `false` for lldb's use case, you 
could go down into the implementation and just call the unqualified side 
directly: `NamedDecl::printName(OS, Policy);` should print it unqualified for 
this name, but respect the qualified printing policy flag for any nested names, 
parameters, etc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137583

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


[PATCH] D91950: [clang-format] Add BreakBeforeInlineASMColon configuration

2022-11-09 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D91950#3917635 , @MyDeveloperDay 
wrote:

> I think this is them..
>
> https://twitter.com/xen_org/status/1397581514318225412
> https://xenproject.org/
> https://xenproject.org/2021/09/22/clang-format-for-xen-coding-style-checking-scheduled/
> https://www.youtube.com/watch?v=3EVE0TTEztc
>
> https://github.com/NastyaVicodin

Yep, from that github account I got the mail.


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

https://reviews.llvm.org/D91950

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


[PATCH] D137154: Adding nvvm_reflect clang builtin

2022-11-09 Thread Artem Belevich via Phabricator via cfe-commits
tra added a subscriber: jhuber6.
tra added a comment.

In D137154#3917692 , @hdelan wrote:

> Thanks for feedback. Instead of adding `__nvvm_reflect` as a clang builtin, 
> would it be acceptable if I modified the NVVMReflect pass

That would be less problematic, but I'm still concerned that it would tacitly 
endorse the use of `__nvvm_reflect` by LLVM users.

> so that it works with addrspace casting as well? This would allow us to use 
> `__nvvm_reflect` in openCL

Relaxing argument type checks on `__nvvm_reflect` function would be fine with 
me.

That said,...

TBH, I still don't quite convinced that compiler changes is the right solution 
for making it possible for *one* library to rely on something that was never 
intended to be exposed to compiler users.

Perhaps we should take a step back, figure out the fundamental problem you need 
to solve (as opposed to figuring out how to make a tactical hack work) and then 
figure out a more principled solution.

> In DPC++ for CUDA we use libclc as a wrapper around CUDA SDK's libdevice. 
> Like libdevice we want to precompile libclc to bc for the CUDA backend 
> without specializing for a particular arch, so that we can call different 
> __nv funcs based on the arch. For this reason we use the __nvvm_reflect llvm 
> intrinsic.

For starters, libdevice by itself is something that's not quite intended for 
the end user. It was a rather poor stop-gap solution to address the fact that 
there used to be no linking phase for GPU binaries and no 'standard' math 
library the code could rely on. The library itself does not have anything 
particularly interesting in it. Its major advantage is that it exists, while we 
don't have our own GPU-side libm yet. We do want to get rid of libdevice and 
replace it with an open-source math library of our own. With the recent 
improvements in offloading support in clang driver we're getting closer to 
making it possible.

As for the code specialization, why not build for individual GPUs? To me it 
looks like this use case is a good match for the "new-driver" offloading that's 
been recently implemented in clang. It allows compiling/linking GPU side code 
and that should obviate the need for shipping bitcode and relying on 
`__nvvm_reflect` for specialization.
The downside is that it's a recent feature, so it would not be available in 
older clang versions. @jhuber6 : I'm also not sure if OpenCL is supported by 
the new driver.

With the new driver, you in theory should be able to compile the source with 
`--offload-arch=A --offload-arch=B` and it would produce an object file with 
GPU-specific bitcode or object file which can then be transparently linked into 
the final executable, where clang would also perform final linking of GPU 
binaries, as well.

I realize that it may be hard or not feasible for your project right now. I'm 
OK with allowing limited nvvm_reflect use for the time being, but please do 
consider making things work w/o it or libdevice, if possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137154

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


[clang] 0453857 - [clang] Mention vector in the description for -mno-implict-float.

2022-11-09 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2022-11-09T11:32:19-08:00
New Revision: 0453857d740248a8991ac28981784445dffa8dee

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

LOG: [clang] Mention vector in the description for -mno-implict-float.

As far as I understand, this disables all integer vectors too.

Reviewed By: efriedma

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 70bad936346b6..c096c58440045 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3851,7 +3851,7 @@ def moutline_atomics : Flag<["-"], "moutline-atomics">, 
Group, Fl
 def mno_outline_atomics : Flag<["-"], "mno-outline-atomics">, 
Group, Flags<[CC1Option]>,
   HelpText<"Don't generate local calls to out-of-line atomic operations">;
 def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group,
-  HelpText<"Don't generate implicit floating point instructions">;
+  HelpText<"Don't generate implicit floating point or vector instructions">;
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
 def mrecip : Flag<["-"], "mrecip">, Group;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, 
Flags<[CC1Option]>,
@@ -5408,7 +5408,7 @@ def fforbid_guard_variables : Flag<["-"], 
"fforbid-guard-variables">,
   HelpText<"Emit an error if a C++ static local initializer would need a guard 
variable">,
   MarshallingInfoFlag>;
 def no_implicit_float : Flag<["-"], "no-implicit-float">,
-  HelpText<"Don't generate implicit floating point instructions">,
+  HelpText<"Don't generate implicit floating point or vector instructions">,
   MarshallingInfoFlag>;
 def fdump_vtable_layouts : Flag<["-"], "fdump-vtable-layouts">,
   HelpText<"Dump the layouts of all vtables that will be emitted in a 
translation unit">,



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


[PATCH] D134089: [clang] Mention vector in the description for -mno-implict-float.

2022-11-09 Thread Craig Topper via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0453857d7402: [clang] Mention vector in the description for 
-mno-implict-float. (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134089

Files:
  clang/include/clang/Driver/Options.td


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3851,7 +3851,7 @@
 def mno_outline_atomics : Flag<["-"], "mno-outline-atomics">, 
Group, Flags<[CC1Option]>,
   HelpText<"Don't generate local calls to out-of-line atomic operations">;
 def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group,
-  HelpText<"Don't generate implicit floating point instructions">;
+  HelpText<"Don't generate implicit floating point or vector instructions">;
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
 def mrecip : Flag<["-"], "mrecip">, Group;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, 
Flags<[CC1Option]>,
@@ -5408,7 +5408,7 @@
   HelpText<"Emit an error if a C++ static local initializer would need a guard 
variable">,
   MarshallingInfoFlag>;
 def no_implicit_float : Flag<["-"], "no-implicit-float">,
-  HelpText<"Don't generate implicit floating point instructions">,
+  HelpText<"Don't generate implicit floating point or vector instructions">,
   MarshallingInfoFlag>;
 def fdump_vtable_layouts : Flag<["-"], "fdump-vtable-layouts">,
   HelpText<"Dump the layouts of all vtables that will be emitted in a 
translation unit">,


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3851,7 +3851,7 @@
 def mno_outline_atomics : Flag<["-"], "mno-outline-atomics">, Group, Flags<[CC1Option]>,
   HelpText<"Don't generate local calls to out-of-line atomic operations">;
 def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group,
-  HelpText<"Don't generate implicit floating point instructions">;
+  HelpText<"Don't generate implicit floating point or vector instructions">;
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
 def mrecip : Flag<["-"], "mrecip">, Group;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, Flags<[CC1Option]>,
@@ -5408,7 +5408,7 @@
   HelpText<"Emit an error if a C++ static local initializer would need a guard variable">,
   MarshallingInfoFlag>;
 def no_implicit_float : Flag<["-"], "no-implicit-float">,
-  HelpText<"Don't generate implicit floating point instructions">,
+  HelpText<"Don't generate implicit floating point or vector instructions">,
   MarshallingInfoFlag>;
 def fdump_vtable_layouts : Flag<["-"], "fdump-vtable-layouts">,
   HelpText<"Dump the layouts of all vtables that will be emitted in a translation unit">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8a084f6 - Revert "Move googletest to the third-party directory"

2022-11-09 Thread Tom Stellard via cfe-commits

Author: Tom Stellard
Date: 2022-11-09T11:34:59-08:00
New Revision: 8a084f68c8a1cac99d9fa0fbcf490b53ab3b6e0c

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

LOG: Revert "Move googletest to the third-party directory"

This reverts commit 59052468c3e38cab15582cefbb5133fd4c2ffce5.

It looks like this patch breaks the build when compiler-rt is passed to
LLVM_ENABLE_PROJECTS instead of LLVM_ENABLE_RUNTIMES.

Added: 
llvm/utils/unittest/CMakeLists.txt
llvm/utils/unittest/UnitTestMain/CMakeLists.txt
llvm/utils/unittest/UnitTestMain/TestMain.cpp
llvm/utils/unittest/googlemock/LICENSE.txt
llvm/utils/unittest/googlemock/README.LLVM
llvm/utils/unittest/googlemock/include/gmock/gmock-actions.h
llvm/utils/unittest/googlemock/include/gmock/gmock-cardinalities.h
llvm/utils/unittest/googlemock/include/gmock/gmock-function-mocker.h
llvm/utils/unittest/googlemock/include/gmock/gmock-generated-actions.h

llvm/utils/unittest/googlemock/include/gmock/gmock-generated-function-mockers.h
llvm/utils/unittest/googlemock/include/gmock/gmock-generated-matchers.h
llvm/utils/unittest/googlemock/include/gmock/gmock-matchers.h
llvm/utils/unittest/googlemock/include/gmock/gmock-more-actions.h
llvm/utils/unittest/googlemock/include/gmock/gmock-more-matchers.h
llvm/utils/unittest/googlemock/include/gmock/gmock-nice-strict.h
llvm/utils/unittest/googlemock/include/gmock/gmock-spec-builders.h
llvm/utils/unittest/googlemock/include/gmock/gmock.h

llvm/utils/unittest/googlemock/include/gmock/internal/custom/gmock-generated-actions.h

llvm/utils/unittest/googlemock/include/gmock/internal/custom/gmock-matchers.h
llvm/utils/unittest/googlemock/include/gmock/internal/custom/gmock-port.h
llvm/utils/unittest/googlemock/include/gmock/internal/gmock-internal-utils.h
llvm/utils/unittest/googlemock/include/gmock/internal/gmock-port.h
llvm/utils/unittest/googlemock/include/gmock/internal/gmock-pp.h
llvm/utils/unittest/googlemock/src/gmock-all.cc
llvm/utils/unittest/googlemock/src/gmock-cardinalities.cc
llvm/utils/unittest/googlemock/src/gmock-internal-utils.cc
llvm/utils/unittest/googlemock/src/gmock-matchers.cc
llvm/utils/unittest/googlemock/src/gmock-spec-builders.cc
llvm/utils/unittest/googlemock/src/gmock.cc
llvm/utils/unittest/googletest/LICENSE.TXT
llvm/utils/unittest/googletest/README.LLVM
llvm/utils/unittest/googletest/include/gtest/gtest-death-test.h
llvm/utils/unittest/googletest/include/gtest/gtest-matchers.h
llvm/utils/unittest/googletest/include/gtest/gtest-message.h
llvm/utils/unittest/googletest/include/gtest/gtest-param-test.h
llvm/utils/unittest/googletest/include/gtest/gtest-printers.h
llvm/utils/unittest/googletest/include/gtest/gtest-spi.h
llvm/utils/unittest/googletest/include/gtest/gtest-test-part.h
llvm/utils/unittest/googletest/include/gtest/gtest-typed-test.h
llvm/utils/unittest/googletest/include/gtest/gtest.h
llvm/utils/unittest/googletest/include/gtest/gtest_pred_impl.h
llvm/utils/unittest/googletest/include/gtest/gtest_prod.h
llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest-port.h

llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest-printers.h
llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest.h
llvm/utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h

llvm/utils/unittest/googletest/include/gtest/internal/gtest-death-test-internal.h
llvm/utils/unittest/googletest/include/gtest/internal/gtest-filepath.h
llvm/utils/unittest/googletest/include/gtest/internal/gtest-internal.h
llvm/utils/unittest/googletest/include/gtest/internal/gtest-param-util.h
llvm/utils/unittest/googletest/include/gtest/internal/gtest-port-arch.h
llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h
llvm/utils/unittest/googletest/include/gtest/internal/gtest-string.h
llvm/utils/unittest/googletest/include/gtest/internal/gtest-type-util.h
llvm/utils/unittest/googletest/src/gtest-all.cc
llvm/utils/unittest/googletest/src/gtest-death-test.cc
llvm/utils/unittest/googletest/src/gtest-filepath.cc
llvm/utils/unittest/googletest/src/gtest-internal-inl.h
llvm/utils/unittest/googletest/src/gtest-matchers.cc
llvm/utils/unittest/googletest/src/gtest-port.cc
llvm/utils/unittest/googletest/src/gtest-printers.cc
llvm/utils/unittest/googletest/src/gtest-test-part.cc
llvm/utils/unittest/googletest/src/gtest-typed-test.cc
llvm/utils/unittest/googletest/src/gtest.cc

Modified: 
clang/CMakeLists.txt
compiler-rt/CMakeLists.txt
lld/CMakeLists.txt
lldb/cmake/modules/LLDBStandalone.cmake
llvm/CMakeLists.txt
llvm/cmake/modules/HandleLLVMOptions.cmake
mlir/CMakeLists.txt
polly/CMakeLis

[PATCH] D135011: Add builtin_elementwise_sin and builtin_elementwise_cos

2022-11-09 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

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


[PATCH] D137373: [Test][[AIX][p] Add 64-bit linker invocation tests

2022-11-09 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm accepted this revision.
cebowleratibm added a comment.
This revision is now accepted and ready to land.

LGTM.

Test only patch is safe to commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137373

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


[clang] dc9846c - [Test][AIX][p] Add 64-bit linker invocation tests

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

Author: Michael Francis
Date: 2022-11-09T14:51:40-05:00
New Revision: dc9846ce988b9ddfcbc42cd462d5d94b634b3161

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

LOG: [Test][AIX][p] Add 64-bit linker invocation tests

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

Added: 


Modified: 
clang/test/Driver/aix-ld.c

Removed: 




diff  --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c
index 5684a1e6ac957..46da1ef207207 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -136,6 +136,33 @@
 // CHECK-LD32-PROF-NOT: "-lm"
 // CHECK-LD32-PROF: "-lc"
 
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable profiling.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-resource-dir=%S/Inputs/resource_dir \
+// RUN:-p \
+// RUN:--target=powerpc64-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-PROF %s
+// CHECK-LD64-PROF-NOT: warning:
+// CHECK-LD64-PROF: "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
+// CHECK-LD64-PROF: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-LD64-PROF: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD64-PROF: "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD64-PROF-NOT: "-bnso"
+// CHECK-LD64-PROF: "-b64"
+// CHECK-LD64-PROF: "-bpT:0x1" "-bpD:0x11000"
+// CHECK-LD64-PROF: "[[SYSROOT]]/usr/lib{{/|}}mcrt0_64.o"
+// CHECK-LD64-PROF: "[[SYSROOT]]/usr/lib{{/|}}crti_64.o"
+// CHECK-LD64-PROF-NOT: "-lc++"
+// CHECK-LD64-PROF-NOT: "-lc++abi"
+// CHECK-LD64-PROF: 
"[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc64.a"
+// CHECK-LD64-PROF-NOT: "--as-needed"
+// CHECK-LD64-PROF: "-lunwind"
+// CHECK-LD64-PROF-NOT: "--no-as-needed"
+// CHECK-LD64-PROF-NOT: "-lm"
+// CHECK-LD64-PROF: "-lc"
+
 // Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable g-profiling.
 // RUN: %clang %s -### 2>&1 \
 // RUN:-resource-dir=%S/Inputs/resource_dir \



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


[PATCH] D137071: [clang][Interp] Implement missing compound assign operators

2022-11-09 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


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

https://reviews.llvm.org/D137071

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


[clang] e07a704 - [Test][AIX][pg] Add 32-bit linker invocation tests

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

Author: Michael Francis
Date: 2022-11-09T15:02:45-05:00
New Revision: e07a7040d9c6dbdd71e55d1153bfe1357079e511

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

LOG: [Test][AIX][pg] Add 32-bit linker invocation tests

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

Added: 


Modified: 
clang/test/Driver/aix-ld.c

Removed: 




diff  --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c
index 46da1ef20720..8aae6b086cbf 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -163,6 +163,33 @@
 // CHECK-LD64-PROF-NOT: "-lm"
 // CHECK-LD64-PROF: "-lc"
 
+// Check powerpc-ibm-aix7.1.0.0, 32-bit. Enable g-profiling.
+// RUN: %clang %s -### 2>&1 \
+// RUN:-resource-dir=%S/Inputs/resource_dir \
+// RUN:-pg \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-GPROF %s
+// CHECK-LD32-GPROF-NOT: warning:
+// CHECK-LD32-GPROF: "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-LD32-GPROF: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-LD32-GPROF: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD32-GPROF: "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD32-GPROF-NOT: "-bnso"
+// CHECK-LD32-GPROF: "-b32"
+// CHECK-LD32-GPROF: "-bpT:0x1000" "-bpD:0x2000"
+// CHECK-LD32-GPROF: "[[SYSROOT]]/usr/lib{{/|}}gcrt0.o"
+// CHECK-LD32-GPROF: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
+// CHECK-LD32-GPROF-NOT: "-lc++"
+// CHECK-LD32-GPROF-NOT: "-lc++abi"
+// CHECK-LD32-GPROF: 
"[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc.a"
+// CHECK-LD32-GPROF-NOT: "--as-needed"
+// CHECK-LD32-GPROF: "-lunwind"
+// CHECK-LD32-GPROF-NOT: "--no-as-needed"
+// CHECK-LD32-GPROF-NOT: "-lm"
+// CHECK-LD32-GPROF: "-lc"
+
 // Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable g-profiling.
 // RUN: %clang %s -### 2>&1 \
 // RUN:-resource-dir=%S/Inputs/resource_dir \



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


[PATCH] D137724: [CMake] Warn when the version is older than 3.20.0.

2022-11-09 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

LGTM (sorry, it looks like I approved on behalf of all libc++ vendors but that 
wasn't my intention).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137724

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


[PATCH] D136701: [LinkerWrapper] Perform device linking steps in parallel

2022-11-09 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136701

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


[PATCH] D137609: [C++20] [Modules] Remove unmaintained header modules

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

> I'm not aware of anyone using this mode, but please wait for responses from 
> Google and Meta people to verify that.

Best understanding on the Google side is we aren't using this.


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

https://reviews.llvm.org/D137609

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


[PATCH] D137154: Adding nvvm_reflect clang builtin

2022-11-09 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D137154#3917752 , @tra wrote:

> As for the code specialization, why not build for individual GPUs? To me it 
> looks like this use case is a good match for the "new-driver" offloading 
> that's been recently implemented in clang. It allows compiling/linking GPU 
> side code and that should obviate the need for shipping bitcode and relying 
> on `__nvvm_reflect` for specialization.

Dealing with the relative compatibility of GPU targets is a never-ending 
endeavor so I'm a proponent of just compiling the source for every single 
architecture, this is what we do with the `libomptarget` device libraries and 
is how the future `libm` and `libc` libraries will work.

> The downside is that it's a recent feature, so it would not be available in 
> older clang versions. @jhuber6 : I'm also not sure if OpenCL is supported by 
> the new driver.

It's not currently, I could put some cycles into that if needed. Also I'm 
wondering if it might be time to start an RFC for moving CUDA to the new driver 
by default. The one downside would be losing compatibility with CUDA's method 
of RDC compilation but I don't think that was ever a goal.

> With the new driver, you in theory should be able to compile the source with 
> `--offload-arch=A --offload-arch=B` and it would produce an object file with 
> GPU-specific bitcode or object file which can then be transparently linked 
> into the final executable, where clang would also perform final linking of 
> GPU binaries, as well.

Part of me wonders if  we should supply `--offload-arch=all` if people start 
doing this a lot.

> I realize that it may be hard or not feasible for your project right now. I'm 
> OK with allowing limited nvvm_reflect use for the time being, but please do 
> consider making things work w/o it or libdevice, if possible.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137154

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


[PATCH] D137724: [CMake] Warn when the version is older than 3.20.0.

2022-11-09 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: clang/CMakeLists.txt:14
   set(CLANG_BUILT_STANDALONE TRUE)
+  if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
+message(WARNING

I wonder if we could move this to `CMakePolicy.cmake`, though admittedly you'd 
have to somehow avoid warning multiple times in in-tree builds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137724

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


[PATCH] D137740: [clang-tidy] Fix namespace comments in AvoidThrowingObjCExceptionCheck.cpp 🧹

2022-11-09 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
stephanemoore published this revision for review.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This commit fixes namespace comments as suggested by the linter.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137740

Files:
  clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp


Index: clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
+++ clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
@@ -41,7 +41,7 @@
"Objective-C errors");
 }
 
-}  // namespace objc
-}  // namespace google
-}  // namespace tidy
-}  // namespace clang
+} // namespace objc
+} // namespace google
+} // namespace tidy
+} // namespace clang


Index: clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
+++ clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
@@ -41,7 +41,7 @@
"Objective-C errors");
 }
 
-}  // namespace objc
-}  // namespace google
-}  // namespace tidy
-}  // namespace clang
+} // namespace objc
+} // namespace google
+} // namespace tidy
+} // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137738: [clang-tidy] Suppress google-objc-avoid-throwing-exception in system macros 🫢

2022-11-09 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
stephanemoore updated this revision to Diff 474350.
stephanemoore added a comment.
stephanemoore updated this revision to Diff 474356.
stephanemoore published this revision for review.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

[clang-tidy] Fix namespace comments in AvoidThrowingObjCExceptionCheck.cpp 🧹

This commit fixes namespace comments as suggested by the linter.


stephanemoore added a comment.

Restore original diff that was replaced by accident.


The google-objc-avoid-throwing-exception check enforces the Google
Objective-C Style Guide's prohibition on throwing exceptions in user
code but the check incorrectly triggers findings for code emitted from
system headers. This commit suppresses any findings that do not have
valid locations or are emitted from macros in system headers.

Avoid Throwing Exceptions, Google Objective-C Style Guide:
https://github.com/google/styleguide/blob/gh-pages/objcguide.md#avoid-throwing-exceptions

Test Notes:
Ran clang-tidy lit tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137738

Files:
  clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/google/Inputs/system-header-throw.h
  
clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-throwing-exception.m


Index: 
clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-throwing-exception.m
===
--- 
clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-throwing-exception.m
+++ 
clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-throwing-exception.m
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s google-objc-avoid-throwing-exception %t
+// RUN: %check_clang_tidy %s google-objc-avoid-throwing-exception %t -- -- -I 
%S/Inputs/
+
 @class NSString;
 
 @interface NSException
@@ -21,12 +22,29 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass in NSError ** instead of 
throwing exception to indicate Objective-C errors 
[google-objc-avoid-throwing-exception]
 }
 
+#include "system-header-throw.h"
+
+#define THROW(e) @throw e
+
+#define RAISE [NSException raise:@"example" format:@"fmt"]
+
 - (void)f2 {
 [NSException raise:@"TestException" format:@"Test"];
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: pass in NSError ** instead of 
throwing exception to indicate Objective-C errors 
[google-objc-avoid-throwing-exception]
 [NSException raise:@"TestException" format:@"Test %@" arguments:@"bar"];
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: pass in NSError ** instead of 
throwing exception to indicate Objective-C errors 
[google-objc-avoid-throwing-exception]
 [NotException raise:@"NotException" format:@"Test"];
+
+NSException *e;
+SYS_THROW(e);
+
+SYS_RAISE;
+
+THROW(e);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass in NSError ** instead of 
throwing exception to indicate Objective-C errors 
[google-objc-avoid-throwing-exception]
+
+RAISE;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass in NSError ** instead of 
throwing exception to indicate Objective-C errors 
[google-objc-avoid-throwing-exception]
 }
 @end
 
Index: 
clang-tools-extra/test/clang-tidy/checkers/google/Inputs/system-header-throw.h
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/google/Inputs/system-header-throw.h
@@ -0,0 +1,6 @@
+#pragma clang system_header
+
+#define SYS_THROW(e) @throw e
+
+#define SYS_RAISE [NSException raise:@"example" format:@"fmt"]
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -141,6 +141,10 @@
   would be emitted for uninitialized members of an anonymous union despite
   there being an initializer for one of the other members.
 
+- Fixed false positives in :doc:`google-objc-avoid-throwing-exception
+  ` check for 
exceptions
+  thrown by code emitted from macros in system headers.
+
 - Improved :doc:`modernize-use-emplace 
`
   check.
 
Index: clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
+++ clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
@@ -36,6 +36,22 @@
   Result.Nodes.getNodeAs("raiseException");
   auto SourceLoc = MatchedStmt == nullptr ? MatchedExpr->getSelectorStartLoc()
   : MatchedStmt->getThrowLoc();
+
+  // Early return on invalid locations.
+  if (SourceLoc.isInvalid())
+return;
+
+ 

[PATCH] D137040: [clangd] Add heuristic for dropping snippet when completing member function pointer

2022-11-09 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders updated this revision to Diff 474358.
tom-anders added a comment.

Add test to sema


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137040

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/unittests/Sema/CodeCompleteTest.cpp

Index: clang/unittests/Sema/CodeCompleteTest.cpp
===
--- clang/unittests/Sema/CodeCompleteTest.cpp
+++ clang/unittests/Sema/CodeCompleteTest.cpp
@@ -23,7 +23,10 @@
 
 using namespace clang;
 using namespace clang::tooling;
+using ::testing::AllOf;
+using ::testing::Contains;
 using ::testing::Each;
+using ::testing::Field;
 using ::testing::UnorderedElementsAre;
 
 const char TestCCName[] = "test.cc";
@@ -36,6 +39,48 @@
   std::string PtrDiffType;
 };
 
+struct CompletedFunctionDecl {
+  std::string Name;
+  bool IsStatic;
+  bool CanBeCall;
+};
+
+class SaveCompletedFunctions : public CodeCompleteConsumer {
+public:
+  SaveCompletedFunctions(std::vector &CompletedFuncDecls)
+  : CodeCompleteConsumer(/*CodeCompleteOpts=*/{}),
+CompletedFuncDecls(CompletedFuncDecls),
+CCTUInfo(std::make_shared()) {}
+
+  void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context,
+  CodeCompletionResult *Results,
+  unsigned NumResults) override {
+for (unsigned I = 0; I < NumResults; ++I) {
+  auto R = Results[I];
+  if (R.Kind == CodeCompletionResult::RK_Declaration) {
+if (const auto *FD = llvm::dyn_cast(R.getDeclaration())) {
+  CompletedFunctionDecl D;
+  D.Name = FD->getNameAsString();
+  D.CanBeCall = R.FunctionCanBeCall;
+  D.IsStatic = FD->isStatic();
+  CompletedFuncDecls.emplace_back(std::move(D));
+}
+  }
+}
+  }
+
+private:
+  CodeCompletionAllocator &getAllocator() override {
+return CCTUInfo.getAllocator();
+  }
+
+  CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return CCTUInfo; }
+
+  std::vector &CompletedFuncDecls;
+
+  CodeCompletionTUInfo CCTUInfo;
+};
+
 class VisitedContextFinder : public CodeCompleteConsumer {
 public:
   VisitedContextFinder(CompletionContext &ResultCtx)
@@ -74,12 +119,15 @@
 
 class CodeCompleteAction : public SyntaxOnlyAction {
 public:
-  CodeCompleteAction(ParsedSourceLocation P, CompletionContext &ResultCtx)
-  : CompletePosition(std::move(P)), ResultCtx(ResultCtx) {}
+  CodeCompleteAction(ParsedSourceLocation P, CompletionContext &ResultCtx,
+ CodeCompleteConsumer *Consumer = nullptr)
+  : CompletePosition(std::move(P)), ResultCtx(ResultCtx),
+Consumer(Consumer) {}
 
   bool BeginInvocation(CompilerInstance &CI) override {
 CI.getFrontendOpts().CodeCompletionAt = CompletePosition;
-CI.setCodeCompletionConsumer(new VisitedContextFinder(ResultCtx));
+CI.setCodeCompletionConsumer(
+Consumer ? Consumer : new VisitedContextFinder(ResultCtx));
 return true;
   }
 
@@ -87,6 +135,7 @@
   // 1-based code complete position ;
   ParsedSourceLocation CompletePosition;
   CompletionContext &ResultCtx;
+  CodeCompleteConsumer *Consumer;
 };
 
 ParsedSourceLocation offsetToPosition(llvm::StringRef Code, size_t Offset) {
@@ -129,6 +178,83 @@
   return Types;
 }
 
+std::vector
+CollectCompletedFunctions(StringRef Code, std::size_t Point) {
+  CompletionContext DummyContext;
+  std::vector Result;
+  clang::tooling::runToolOnCodeWithArgs(
+  std::make_unique(offsetToPosition(Code, Point),
+   DummyContext,
+   new SaveCompletedFunctions(Result)),
+  Code, {"-std=c++11"}, TestCCName);
+  return Result;
+}
+
+TEST(SemaCodeCompleteTest, FunctionCanBeCall) {
+  llvm::Annotations Code(R"cpp(
+struct Foo {
+  static int staticMethod();
+  int method() const;
+  Foo() {
+this->$canBeCall^
+$canBeCall^
+Foo::$canBeCall^
+  }
+};
+
+struct Derived : Foo {
+  Derived() {
+Foo::$canBeCall^
+  }
+};
+
+struct OtherClass {
+  OtherClass() {
+Foo f;
+f.$canBeCall^
+&Foo::$cannotBeCall^
+  }
+};
+
+int main() {
+  Foo f;
+  f.$canBeCall^
+  &Foo::$cannotBeCall^
+}
+)cpp");
+
+  for (const auto &P : Code.points("canBeCall")) {
+auto Results = CollectCompletedFunctions(Code.code(), P);
+EXPECT_THAT(
+Results,
+Contains(AllOf(
+Field("Name", &CompletedFunctionDecl::Name, "method"),
+Field("IsStatic", &CompletedFunctionDecl::IsStatic, false),
+Field("CanBeCall", &CompletedFunctionDecl::CanBeCall, true;
+  }
+
+  for (const auto &P : Code.points("keepSnip

[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros

2022-11-09 Thread Noah Goldstein via Phabricator via cfe-commits
goldstein.w.n updated this revision to Diff 474359.
goldstein.w.n added a comment.



1. Updating D137181 : [clang-format] Don't 
use 'PPIndentWidth' inside multi-line macros #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Remove many unnecessary `PPLevel` changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137181

Files:
  clang/lib/Format/TokenAnnotator.h
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5040,6 +5040,254 @@
"  int y = 0;\n"
"}",
style);
+
+  style.IndentPPDirectives = FormatStyle::PPDIS_None;
+  verifyFormat("#ifdef X\n"
+   "#define Y  \\\n"
+   "switch (Y) {   \\\n"
+   "case 0:\\\n"
+   "break; \\\n"
+   "case 1:\\\n"
+   "break; \\\n"
+   "}  \\\n"
+   "Z();\n"
+   "#endif",
+   style);
+  verifyFormat("#ifdef foo\n"
+   "#define bar() \\\n"
+   "if (A) {  \\\n"
+   "B();  \\\n"
+   "} \\\n"
+   "C();\n"
+   "#endif",
+   style);
+  verifyFormat("if (emacs) {\n"
+   "#ifdef is\n"
+   "#define lit   \\\n"
+   "if (af) { \\\n"
+   "return duh(); \\\n"
+   "}\n"
+   "#endif\n"
+   "}",
+   style);
+  verifyFormat("#if abc\n"
+   "#ifdef foo\n"
+   "#define bar()\\\n"
+   "if (A) { \\\n"
+   "if (B) { \\\n"
+   "C(); \\\n"
+   "}\\\n"
+   "}\\\n"
+   "D();\n"
+   "#endif\n"
+   "#endif",
+   style);
+  verifyFormat("#ifndef foo\n"
+   "#define foo\n"
+   "if (emacs) {\n"
+   "#ifdef is\n"
+   "#define lit   \\\n"
+   "if (af) { \\\n"
+   "return duh(); \\\n"
+   "}\n"
+   "#endif\n"
+   "}\n"
+   "#endif",
+   style);
+
+  style.PPIndentWidth = 2;
+  verifyFormat("#ifdef foo\n"
+   "#define bar() \\\n"
+   "if (A) {  \\\n"
+   "B();  \\\n"
+   "} \\\n"
+   "C();\n"
+   "#endif",
+   style);
+  style.IndentWidth = 8;
+  verifyFormat("#ifdef foo\n"
+   "#define bar()\\\n"
+   "if (A) { \\\n"
+   "B(); \\\n"
+   "}\\\n"
+   "C();\n"
+   "#endif",
+   style);
+
+  style.IndentWidth = 4;
+  style.PPIndentWidth = 1;
+
+  style.IndentPPDirectives = FormatStyle::PPDIS_AfterHash;
+  verifyFormat("#ifdef X\n"
+   "# define Y  \\\n"
+   " switch (Y) {   \\\n"
+   " case 0:\\\n"
+   " break; \\\n"
+   " case 1:\\\n"
+   " break; \\\n"
+   " }  \\\n"
+   " Z();\n"
+   "#endif",
+   style);
+  verifyFormat("#ifdef foo\n"
+   "# define bar() \\\n"
+   " if (A) {  \\\n"
+   " B();  \\\n"
+   " } \\\n"
+   " C();\n"
+   "#endif",
+   style);
+  verifyFormat("if (emacs) {\n"
+   "#ifdef is\n"
+   "# define lit   \\\n"
+   " if (af) { \\\n"
+   " return duh(); \\\n"
+   " }\n"
+   "#endif\n"
+   "}",
+   style);
+  verifyFormat("#if abc\n"
+   "# ifdef foo\n"
+   "#  define bar()\\\n"
+   "  if (A) { \\\n"
+   "  if (B) { \\\n"
+   "  C(); \\\n"
+   "  }\\\n"
+   "  }\\\n"
+   "  D();\n"
+   "# endif\n"
+

[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros

2022-11-09 Thread Noah Goldstein via Phabricator via cfe-commits
goldstein.w.n added a comment.

In D137181#3916605 , @owenpan wrote:

> In D137181#3916558 , @goldstein.w.n 
> wrote:
>
>> In D137181#3916547 , @owenpan 
>> wrote:
>>
>>> Yes, if there is a header guard. Otherwise, set `PPLevel` to `PPBranchLevel 
>>> + 1`.
>>
>> That fails alot of the tests for me.
>>
>> maybe you did something different?
>
> Here is what I did:
>
>   $ git diff UnwrappedLineParser.cpp
>   diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
> b/clang/lib/Format/UnwrappedLineParser.cpp
>   index 25d9018fa109..ab3b9c53ee54 100644
>   --- a/clang/lib/Format/UnwrappedLineParser.cpp
>   +++ b/clang/lib/Format/UnwrappedLineParser.cpp
>   @@ -197,6 +197,7 @@ public:
>PreBlockLine = std::move(Parser.Line);
>Parser.Line = std::make_unique();
>Parser.Line->Level = PreBlockLine->Level;
>   +Parser.Line->PPLevel = PreBlockLine->PPLevel;
>Parser.Line->InPPDirective = PreBlockLine->InPPDirective;
>Parser.Line->InMacroBody = PreBlockLine->InMacroBody;
>  }
>   @@ -1274,6 +1275,10 @@ void UnwrappedLineParser::parsePPDefine() {
>  addUnwrappedLine();
>  ++Line->Level;
>  Line->InMacroBody = true;
>   +  if (Style.IndentPPDirectives != FormatStyle::PPDIS_None) {
>   +Line->PPLevel =
>   +IncludeGuard == IG_Defined ? PPBranchLevel : PPBranchLevel + 1;
>   +  }
>
>  // Errors during a preprocessor directive can only affect the layout of 
> the
>  // preprocessor directive, and thus we ignore them. An alternative 
> approach

You're right this works (but off by one). Updated patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137181

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


[PATCH] D137040: [clangd] Add heuristic for dropping snippet when completing member function pointer

2022-11-09 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added a comment.

Hmm I added the test for the flag to Sema, but now we kinda have the same test 
case duplicated in sema and clangd tests - I guess for clangd we now actually 
only have to test that the SnippetSuffix is cleared when FunctionCanBeCall is 
true, but I don't see an easy way to somehow inject fake Sema results into 
CodeComplete.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137040

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


  1   2   >