[PATCH] D102547: [clang][AVR] Redefine [u]int16_t to be compatible with avr-gcc

2021-05-15 Thread Ben Shi via Phabricator via cfe-commits
benshi001 updated this revision to Diff 345611.

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

https://reviews.llvm.org/D102547

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/AVR.h
  clang/lib/Frontend/InitPreprocessor.cpp


Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -216,6 +216,11 @@
   if (TypeWidth == 64)
 Ty = IsSigned ? TI.getInt64Type() : TI.getUInt64Type();
 
+  // Use the target specified int16 type when appropriate. Some MCU targets
+  // (such as AVR) have definition of [u]int16_t to [un]signed int.
+  if (TypeWidth == 16)
+Ty = IsSigned ? TI.getInt16Type() : TI.getUInt16Type();
+
   const char *Prefix = IsSigned ? "__INT" : "__UINT";
 
   DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
Index: clang/lib/Basic/Targets/AVR.h
===
--- clang/lib/Basic/Targets/AVR.h
+++ clang/lib/Basic/Targets/AVR.h
@@ -52,6 +52,7 @@
 IntPtrType = SignedInt;
 Char16Type = UnsignedInt;
 WIntType = SignedInt;
+Int16Type = SignedInt;
 Char32Type = UnsignedLong;
 SigAtomicType = SignedChar;
 resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
Index: clang/lib/Basic/Targets/AVR.cpp
===
--- clang/lib/Basic/Targets/AVR.cpp
+++ clang/lib/Basic/Targets/AVR.cpp
@@ -309,8 +309,6 @@
   Builder.defineMacro("__AVR__");
   Builder.defineMacro("__ELF__");
   Builder.defineMacro("__flash", "__attribute__((address_space(1)))");
-  Builder.defineMacro("__UINT16_TYPE__", "unsigned int");
-  Builder.defineMacro("__INT16_TYPE__", "int");
 
   if (!this->CPU.empty()) {
 auto It = llvm::find_if(
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -98,6 +98,7 @@
   Char16Type = UnsignedShort;
   Char32Type = UnsignedInt;
   Int64Type = SignedLongLong;
+  Int16Type = SignedShort;
   SigAtomicType = SignedInt;
   ProcessIDType = SignedInt;
   UseSignedCharForObjCBool = true;
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -129,9 +129,9 @@
 Float128
   };
 protected:
-  IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType,
-  WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
-  ProcessIDType;
+  IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType, WIntType,
+  Char16Type, Char32Type, Int64Type, Int16Type, SigAtomicType,
+  ProcessIDType;
 
   /// Whether Objective-C's built-in boolean type should be signed char.
   ///
@@ -351,6 +351,10 @@
   IntType getUInt64Type() const {
 return getCorrespondingUnsignedType(Int64Type);
   }
+  IntType getInt16Type() const { return Int16Type; }
+  IntType getUInt16Type() const {
+return getCorrespondingUnsignedType(Int16Type);
+  }
   IntType getSigAtomicType() const { return SigAtomicType; }
   IntType getProcessIDType() const { return ProcessIDType; }
 


Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -216,6 +216,11 @@
   if (TypeWidth == 64)
 Ty = IsSigned ? TI.getInt64Type() : TI.getUInt64Type();
 
+  // Use the target specified int16 type when appropriate. Some MCU targets
+  // (such as AVR) have definition of [u]int16_t to [un]signed int.
+  if (TypeWidth == 16)
+Ty = IsSigned ? TI.getInt16Type() : TI.getUInt16Type();
+
   const char *Prefix = IsSigned ? "__INT" : "__UINT";
 
   DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
Index: clang/lib/Basic/Targets/AVR.h
===
--- clang/lib/Basic/Targets/AVR.h
+++ clang/lib/Basic/Targets/AVR.h
@@ -52,6 +52,7 @@
 IntPtrType = SignedInt;
 Char16Type = UnsignedInt;
 WIntType = SignedInt;
+Int16Type = SignedInt;
 Char32Type = UnsignedLong;
 SigAtomicType = SignedChar;
 resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
Index: clang/lib/Basic/Targets/AVR.cpp
===
--- clang/lib/Basic/Targets/AVR.cpp
+++ clang/lib/Basic/Targets/AVR.cpp
@@ -309,8 +309,6 @@
   Builder.defineMacro("__AVR__");
   Builder.defineMacro("__ELF__");
   Builder.defineMacro("__flash", "__attribute__((address_space(1)))");
-  Builder.defineMacro("__UINT16_TYPE__", "unsigned int");
-  Builder.defineMacro("__INT16_TYPE__", "in

[PATCH] D102392: [clang-format] PR50326 AlignAfterOpenBracket AlwaysBreak does not keep to the ColumnLimit

2021-05-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 345619.
MyDeveloperDay added a comment.

Add a test that shows it no longer impacts function ptrs


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

https://reviews.llvm.org/D102392

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13298,6 +13298,13 @@
   verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+  Spaces.ColumnLimit = 80;
+  verifyFormat(
+  "size_t foo = (*(function))(F, Bar, F, Ba, "
+  "FoLong,\n"
+  "   BaLong, FoLong);",
+  Spaces);
   Spaces.SpaceAfterCStyleCast = false;
   verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces);
   verifyFormat("size_t idx = (size_t)a;", Spaces);
@@ -13305,6 +13312,13 @@
   verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+
+  verifyFormat(
+  "size_t foo = (*(function))(F, Bar, F, Ba, "
+  "FoLong,\n"
+  "   BaLong, FoLong);",
+  Spaces);
 }
 
 TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1907,12 +1907,12 @@
 if (Tok.Next->isOneOf(tok::identifier, tok::kw_this))
   return true;
 
-if (Tok.Next->is(tok::l_paren) &&
-!(Tok.Previous && Tok.Previous->is(tok::identifier) &&
-  Tok.Previous->Previous &&
-  Tok.Previous->Previous->isOneOf(tok::arrowstar, tok::arrow,
-  tok::star)))
-  return true;
+// Look for a cast `( x ) (`.
+if (Tok.Next->is(tok::l_paren) && Tok.Previous && Tok.Previous->Previous) {
+  if (Tok.Previous->is(tok::identifier) &&
+  Tok.Previous->Previous->is(tok::l_paren))
+return true;
+}
 
 if (!Tok.Next->Next)
   return false;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13298,6 +13298,13 @@
   verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+  Spaces.ColumnLimit = 80;
+  verifyFormat(
+  "size_t foo = (*(function))(F, Bar, F, Ba, "
+  "FoLong,\n"
+  "   BaLong, FoLong);",
+  Spaces);
   Spaces.SpaceAfterCStyleCast = false;
   verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces);
   verifyFormat("size_t idx = (size_t)a;", Spaces);
@@ -13305,6 +13312,13 @@
   verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+
+  verifyFormat(
+  "size_t foo = (*(function))(F, Bar, F, Ba, "
+  "FoLong,\n"
+  "   BaLong, FoLong);",
+  Spaces);
 }
 
 TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1907,12 +1907,12 @@
 if (Tok.Next->isOneOf(tok::identifier, tok::kw_this))
   return true;
 
-if (Tok.Next->is(tok::l_paren) &&
-!(Tok.Previous && Tok.Previous->is(tok::identifier) &&
-  Tok.Previous->Previous &&
-  Tok.Previous->Previous->isOneOf(tok::arrowstar, tok::arrow,
-  tok::star)))
-  return true;
+// Look for a cast `( x ) (`.
+if (Tok.Next->is(tok::l_paren) && Tok.Previous && Tok.Previous->Previous) {
+  if (Tok.Previous->is(tok::identifier) &&
+  Tok.Previous->Previous->is(tok::l_paren))
+return true;
+}
 
 if (!Tok.Next->Next)
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mai

[PATCH] D102392: [clang-format] PR50326 AlignAfterOpenBracket AlwaysBreak does not keep to the ColumnLimit

2021-05-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 345620.
MyDeveloperDay added a comment.

slightly closer test to the original failure


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

https://reviews.llvm.org/D102392

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13298,6 +13298,17 @@
   verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+  Spaces.ColumnLimit = 80;
+  Spaces.IndentWidth = 4;
+  Spaces.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  verifyFormat("void foo( ) {\n"
+   "size_t foo = (*(function))(\n"
+   "F, Bar, F, Ba, FoLong, "
+   "BaLong,\n"
+   "FoLong);\n"
+   "}",
+   Spaces);
   Spaces.SpaceAfterCStyleCast = false;
   verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces);
   verifyFormat("size_t idx = (size_t)a;", Spaces);
@@ -13305,6 +13316,15 @@
   verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+
+  verifyFormat("void foo( ) {\n"
+   "size_t foo = (*(function))(\n"
+   "F, Bar, F, Ba, FoLong, "
+   "BaLong,\n"
+   "FoLong);\n"
+   "}",
+   Spaces);
 }
 
 TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1907,12 +1907,12 @@
 if (Tok.Next->isOneOf(tok::identifier, tok::kw_this))
   return true;
 
-if (Tok.Next->is(tok::l_paren) &&
-!(Tok.Previous && Tok.Previous->is(tok::identifier) &&
-  Tok.Previous->Previous &&
-  Tok.Previous->Previous->isOneOf(tok::arrowstar, tok::arrow,
-  tok::star)))
-  return true;
+// Look for a cast `( x ) (`.
+if (Tok.Next->is(tok::l_paren) && Tok.Previous && Tok.Previous->Previous) {
+  if (Tok.Previous->is(tok::identifier) &&
+  Tok.Previous->Previous->is(tok::l_paren))
+return true;
+}
 
 if (!Tok.Next->Next)
   return false;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13298,6 +13298,17 @@
   verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+  Spaces.ColumnLimit = 80;
+  Spaces.IndentWidth = 4;
+  Spaces.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  verifyFormat("void foo( ) {\n"
+   "size_t foo = (*(function))(\n"
+   "F, Bar, F, Ba, FoLong, "
+   "BaLong,\n"
+   "FoLong);\n"
+   "}",
+   Spaces);
   Spaces.SpaceAfterCStyleCast = false;
   verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces);
   verifyFormat("size_t idx = (size_t)a;", Spaces);
@@ -13305,6 +13316,15 @@
   verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+
+  verifyFormat("void foo( ) {\n"
+   "size_t foo = (*(function))(\n"
+   "F, Bar, F, Ba, FoLong, "
+   "BaLong,\n"
+   "FoLong);\n"
+   "}",
+   Spaces);
 }
 
 TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1907,12 +1907,12 @@
 if (Tok.Next->isOneOf(tok::identifier, tok::kw_this))
   return true;
 
-if (Tok.Next->is(tok::l_paren) &&
-!(Tok.Previous && Tok.Previous->is(tok::identifier) &&
-  Tok.Previous->Previous &&
-  Tok.Previous->Previous->isOneOf(tok::ar

[clang] eae445f - [clang-format] PR50326 AlignAfterOpenBracket AlwaysBreak does not keep to the ColumnLimit

2021-05-15 Thread via cfe-commits

Author: mydeveloperday
Date: 2021-05-15T11:29:56+01:00
New Revision: eae445f65d077304703e3290ddb4ff28f6d65ff4

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

LOG: [clang-format]  PR50326 AlignAfterOpenBracket AlwaysBreak does not keep to 
the ColumnLimit

https://bugs.llvm.org/show_bug.cgi?id=50326

{D93626} caused a regression in terms of formatting a function ptr, incorrectly 
thinking it was a C-Style cast.

This cased a formatter regression between clang-format-11 and clang-format-12

```
void bar()
{
size_t foo = function(F, Bar, F, Ba, FoLong);

size_t foo = function(
F, Bar, F, Ba, FoLong, BaLong,
FoLong);

size_t foo = (*(function))(F, Bar, F, FoLong);

size_t foo = (*(
function))(F, Bar, F, Ba, FoLong,
BaLong, FoLong);
}
```

became

```
void bar()
{
size_t foo1 = function(F, Bar, F, Ba, FoLong);

size_t foo2 = function(
F, Bar, F, Ba, FoLong, BaLong,
FoLong);

size_t foo3 = (*(function))(F, Bar, F, FoLong);

size_t foo4 = (*(
function))(F, Bar, F, Ba, FoLong, 
BaLong, FoLong);
}
```

This fixes this issue by simplify the clause to be specific about what is 
wanted rather than what is not.

Reviewed By: curdeius, HazardyKnusperkeks

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index a996ae8198ca9..d1aa3e422b5a8 100755
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1907,12 +1907,12 @@ class AnnotatingParser {
 if (Tok.Next->isOneOf(tok::identifier, tok::kw_this))
   return true;
 
-if (Tok.Next->is(tok::l_paren) &&
-!(Tok.Previous && Tok.Previous->is(tok::identifier) &&
-  Tok.Previous->Previous &&
-  Tok.Previous->Previous->isOneOf(tok::arrowstar, tok::arrow,
-  tok::star)))
-  return true;
+// Look for a cast `( x ) (`.
+if (Tok.Next->is(tok::l_paren) && Tok.Previous && Tok.Previous->Previous) {
+  if (Tok.Previous->is(tok::identifier) &&
+  Tok.Previous->Previous->is(tok::l_paren))
+return true;
+}
 
 if (!Tok.Next->Next)
   return false;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 2e7b28cc1568a..cf3e7b1df3900 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -13298,6 +13298,17 @@ TEST_F(FormatTest, ConfigurableSpacesInParentheses) {
   verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+  Spaces.ColumnLimit = 80;
+  Spaces.IndentWidth = 4;
+  Spaces.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  verifyFormat("void foo( ) {\n"
+   "size_t foo = (*(function))(\n"
+   "F, Bar, F, Ba, FoLong, "
+   "BaLong,\n"
+   "FoLong);\n"
+   "}",
+   Spaces);
   Spaces.SpaceAfterCStyleCast = false;
   verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces);
   verifyFormat("size_t idx = (size_t)a;", Spaces);
@@ -13305,6 +13316,15 @@ TEST_F(FormatTest, ConfigurableSpacesInParentheses) {
   verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+
+  verifyFormat("void foo( ) {\n"
+   "size_t foo = (*(function))(\n"
+   "F, Bar, F, Ba, FoLong, "
+   "BaLong,\n"
+   "FoLong);\n"
+   "}",
+   Spaces);
 }
 
 TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {



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


[PATCH] D102392: [clang-format] PR50326 AlignAfterOpenBracket AlwaysBreak does not keep to the ColumnLimit

2021-05-15 Thread MyDeveloperDay 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 rGeae445f65d07: [clang-format]  PR50326 AlignAfterOpenBracket 
AlwaysBreak does not keep to the… (authored by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102392

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13298,6 +13298,17 @@
   verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+  Spaces.ColumnLimit = 80;
+  Spaces.IndentWidth = 4;
+  Spaces.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  verifyFormat("void foo( ) {\n"
+   "size_t foo = (*(function))(\n"
+   "F, Bar, F, Ba, FoLong, "
+   "BaLong,\n"
+   "FoLong);\n"
+   "}",
+   Spaces);
   Spaces.SpaceAfterCStyleCast = false;
   verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces);
   verifyFormat("size_t idx = (size_t)a;", Spaces);
@@ -13305,6 +13316,15 @@
   verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+
+  verifyFormat("void foo( ) {\n"
+   "size_t foo = (*(function))(\n"
+   "F, Bar, F, Ba, FoLong, "
+   "BaLong,\n"
+   "FoLong);\n"
+   "}",
+   Spaces);
 }
 
 TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1907,12 +1907,12 @@
 if (Tok.Next->isOneOf(tok::identifier, tok::kw_this))
   return true;
 
-if (Tok.Next->is(tok::l_paren) &&
-!(Tok.Previous && Tok.Previous->is(tok::identifier) &&
-  Tok.Previous->Previous &&
-  Tok.Previous->Previous->isOneOf(tok::arrowstar, tok::arrow,
-  tok::star)))
-  return true;
+// Look for a cast `( x ) (`.
+if (Tok.Next->is(tok::l_paren) && Tok.Previous && Tok.Previous->Previous) {
+  if (Tok.Previous->is(tok::identifier) &&
+  Tok.Previous->Previous->is(tok::l_paren))
+return true;
+}
 
 if (!Tok.Next->Next)
   return false;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13298,6 +13298,17 @@
   verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+  Spaces.ColumnLimit = 80;
+  Spaces.IndentWidth = 4;
+  Spaces.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  verifyFormat("void foo( ) {\n"
+   "size_t foo = (*(function))(\n"
+   "F, Bar, F, Ba, FoLong, "
+   "BaLong,\n"
+   "FoLong);\n"
+   "}",
+   Spaces);
   Spaces.SpaceAfterCStyleCast = false;
   verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces);
   verifyFormat("size_t idx = (size_t)a;", Spaces);
@@ -13305,6 +13316,15 @@
   verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
   verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+
+  verifyFormat("void foo( ) {\n"
+   "size_t foo = (*(function))(\n"
+   "F, Bar, F, Ba, FoLong, "
+   "BaLong,\n"
+   "FoLong);\n"
+   "}",
+   Spaces);
 }
 
 TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1907,12 +1907,12 @@
 if (Tok.Next->isOneOf(tok::identifier, tok::kw_this))
   return true;
 
-if (

[PATCH] D102489: [Clang,Driver] Add -fveclib=Darwin_libsystem_m support.

2021-05-15 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

(Failed on our bots too -- the new test probably just needs a ` REQUIRES: 
aarch64-registered-target`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102489

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


[PATCH] D96033: [clang-repl] Land initial infrastructure for incremental parsing

2021-05-15 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

In D96033#2760067 , 
@hubert.reinterpretcast wrote:

> In D96033#2759808 , @v.g.vassilev 
> wrote:
>
>> Hi @hubert.reinterpretcast,
>>
>> Would you mind testing this patch:
>
> Does the test try to generate native object files in some way? There is 
> functionality (with some limitations) for that under 32-bit AIX; however, 
> we're running a 64-bit build and we don't have integrated-as capability for 
> that at this time. This is what I'm seeing:
>
>    TEST 'Clang :: Interpreter/execute.cpp' FAILED 
> 
>   Script:
>   --
>   : 'RUN: at line 1';   cat 
> /home/hstong/.Liodine/llvmproj/clang/test/Interpreter/execute.cpp | 
> /home/hstong/.Nrtphome/.Liodine/llcrossbld/dev/build/bin/clang-repl | 
> /home/hstong/.Nrtphome/.Liodine/llcrossbld/dev/build/bin/FileCheck 
> /home/hstong/.Liodine/llvmproj/clang/test/Interpreter/execute.cpp
>   --
>   Exit Code: 2
>   
>   Command Output (stderr):
>   --
>   clang-repl: Driver initialization failed. Incremental mode for action is 
> not supported
>   FileCheck error: '' is empty.
>   FileCheck command line:  
> /home/hstong/.Nrtphome/.Liodine/llcrossbld/dev/build/bin/FileCheck 
> /home/hstong/.Liodine/llvmproj/clang/test/Interpreter/execute.cpp
>   
>   --
>   
>   

That looks like progress! Thanks a lot for investing the time to do that. I 
tried to get access to such a machine but we don't have them off the shelf.

The test is supposed to create an incremental Clang and create a JIT. 
clang-repl will take the original `ProgramAction` was and try to turn it into 
an incremental action using the `WrappedFrontendAction` and add 
`EmitLLVMOnlyAction`. That is done here 
.

The diagnostics tells us that we cannot turn some `ProgramAction` into an 
incremental one. I am wondering what that action is. `clang-repl -Xcc -v` 
should be able to tell us.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96033

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


[PATCH] D102325: [clang-tidy] cppcoreguidelines-virtual-base-class-destructor: a new check

2021-05-15 Thread Marco Gartmann via Phabricator via cfe-commits
mgartmann marked 17 inline comments as done.
mgartmann added a comment.

In D102325#2754241 , @njames93 wrote:

> Whats the intended behaviour for derived classes and their destructors? Can 
> test be added to demonstrate that behaviour?

If a derived class inherits a `virtual` method from a base class, according to 
guideline C.35, it is a potential base class as well.
Therefore, such a derived class gets flagged by the check if its destructor is 
not specified correctly.

In order to flag derived classes that only inherit a `virtual` method but do 
not override it, the following matcher had to be added:

  ast_matchers::internal::Matcher inheritsVirtualMethod =
  hasAnyBase(hasType(cxxRecordDecl(has(cxxMethodDecl(isVirtual());

Test cases were added to demonstrate this behaviour.




Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualBaseClassDestructorCheck.cpp:129
+
+AccessSpecDecl *VirtualBaseClassDestructorCheck::getPublicASDecl(
+const CXXRecordDecl &StructOrClass) const {

njames93 wrote:
> Can be made static again. Also should probably return a `const AccessSpecDecl 
> *`
@njames93 If I get this correctly, only `check` and `addMatcher` should be 
member functions of a check's class. All the other aid methods should be static 
and not part of the class. 

Did I get this right?



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-virtual-base-class-destructor.rst:55
+
+.. option:: IndentationWidth
+

Eugene.Zelenko wrote:
> Shouldn't `Clang-format` take care about such things?
As @njames93 also suggested leaving the indentation to `clang-format`, I 
removed this option and the indentation functionality.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102325

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


[PATCH] D102392: [clang-format] PR50326 AlignAfterOpenBracket AlwaysBreak does not keep to the ColumnLimit

2021-05-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

This is also the cause of https://bugs.llvm.org/show_bug.cgi?id=49995, we might 
want to ask for this to be put into any 12.0.1 patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102392

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


[PATCH] D102325: [clang-tidy] cppcoreguidelines-virtual-base-class-destructor: a new check

2021-05-15 Thread Marco Gartmann via Phabricator via cfe-commits
mgartmann updated this revision to Diff 345623.
mgartmann marked 2 inline comments as done.
mgartmann added a comment.

Incorporated Phabricator review feedback:

- added matchers and tests for subclasses with inherited virtual methods
- made aid methods static and not part of the check's class
- replaced `auto` with types where it was suggested
- adjusted diagnostic messages

Included new commits of upstream `main` branch to resolve build failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102325

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualBaseClassDestructorCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualBaseClassDestructorCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-virtual-base-class-destructor.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-base-class-destructor.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-base-class-destructor.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-base-class-destructor.cpp
@@ -0,0 +1,173 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-virtual-base-class-destructor %t
+
+// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: destructor of 'PrivateVirtualBaseStruct' is private and prevents using the type. Consider making it public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+struct PrivateVirtualBaseStruct {
+  virtual void f();
+
+private:
+  virtual ~PrivateVirtualBaseStruct(){};
+};
+
+struct PublicVirtualBaseStruct { // OK
+  virtual void f();
+  virtual ~PublicVirtualBaseStruct(){};
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: destructor of 'ProtectedVirtualBaseStruct' is protected and virtual. It should either be public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+struct ProtectedVirtualBaseStruct {
+  virtual void f();
+
+protected:
+  virtual ~ProtectedVirtualBaseStruct(){};
+  // CHECK-FIXES: ~ProtectedVirtualBaseStruct(){};
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: destructor of 'PrivateNonVirtualBaseStruct' is private and prevents using the type. Consider making it public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+struct PrivateNonVirtualBaseStruct {
+  virtual void f();
+
+private:
+  ~PrivateNonVirtualBaseStruct(){};
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: destructor of 'PublicNonVirtualBaseStruct' is public and non-virtual. It should either be public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+struct PublicNonVirtualBaseStruct {
+  virtual void f();
+  ~PublicNonVirtualBaseStruct(){};
+  // CHECK-FIXES: virtual ~PublicNonVirtualBaseStruct(){};
+};
+
+struct PublicNonVirtualNonBaseStruct { // OK according to C.35, since this struct does not have any virtual methods.
+  void f();
+  ~PublicNonVirtualNonBaseStruct(){};
+};
+
+// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: destructor of 'PublicImplicitNonVirtualBaseStruct' is public and non-virtual. It should either be public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+// CHECK-FIXES: struct PublicImplicitNonVirtualBaseStruct {
+// CHECK-FIXES-NEXT: virtual ~PublicImplicitNonVirtualBaseStruct() = default;
+struct PublicImplicitNonVirtualBaseStruct {
+  virtual void f();
+};
+
+// CHECK-MESSAGES: :[[@LINE+4]]:8: warning: destructor of 'PublicASImplicitNonVirtualBaseStruct' is public and non-virtual. It should either be public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+// CHECK-FIXES: struct PublicASImplicitNonVirtualBaseStruct {
+// CHECK-FIXES-NEXT: virtual ~PublicASImplicitNonVirtualBaseStruct() = default;
+// CHECK-FIXES-NEXT: private:
+struct PublicASImplicitNonVirtualBaseStruct {
+private:
+  virtual void f();
+};
+
+struct ProtectedNonVirtualBaseStruct { // OK
+  virtual void f();
+
+protected:
+  ~ProtectedNonVirtualBaseStruct(){};
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:7: warning: destructor of 'PrivateVirtualBaseClass' is private and prevents using the type. Consider making it public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+class PrivateVirtualBaseClass {
+  virtual void f();
+  virtual ~PrivateVirtualBaseClass(){};
+};
+
+class PublicVirtualBaseClass { // OK
+  virtual void f();
+
+public:
+  virtual ~PublicVirtualBaseClass(){};
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:7: warning: destructor of 'Protect

[PATCH] D89425: [Format/ObjC] Add NS_SWIFT_NAME() and CF_SWIFT_NAME() to WhitespaceSensitiveMacros

2021-05-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

After this change, this

  FOUNDATION_EXPORT NSString *const kFIRInstanceIDScopeFirebaseMessaging
  NS_SWIFT_NAME(InstanceIDScopeFirebaseMessaging) DEPRECATED_ATTRIBUTE;
  
  typedef NS_ENUM(NSInteger, FIRHTTPMethod) {
/** HTTP Method GET */
FIRHTTPMethodGET NS_SWIFT_NAME(get),
/** HTTP Method PUT */
FIRHTTPMethodPUT NS_SWIFT_NAME(put),
/** HTTP Method POST */
FIRHTTPMethodPOST NS_SWIFT_NAME(post),
/** HTTP Method DELETE */
FIRHTTPMethodDELETE NS_SWIFT_NAME(delete),
/** HTTP Method HEAD */
FIRHTTPMethodHEAD NS_SWIFT_NAME(head),
/** HTTP Method PATCH */
FIRHTTPMethodPATCH NS_SWIFT_NAME(patch),
/** HTTP Method OPTIONS */
FIRHTTPMethodOPTIONS NS_SWIFT_NAME(options),
/** HTTP Method TRACE */
FIRHTTPMethodTRACE NS_SWIFT_NAME(trace),
/** HTTP Method CONNECT */
FIRHTTPMethodCONNECT NS_SWIFT_NAME(connect)
  } NS_SWIFT_NAME(HTTPMethod);

is formatted as

  FOUNDATION_EXPORT NSString *const
  kFIRInstanceIDScopeFirebaseMessaging 
NS_SWIFT_NAME(InstanceIDScopeFirebaseMe
  ssaging) DEPRECATED_ATTRIBUTE;
  
  typedef NS_ENUM(NSInteger, FIRHTTPMethod) {
/** HTTP Method GET */
FIRHTTPMethodGET NS_SWIFT_NAME(get),
/** HTTP Method PUT */
FIRHTTPMethodPUT NS_SWIFT_NAME(put),
/** HTTP Method POST */
FIRHTTPMethodPOST NS_SWIFT_NAME(post),
/** HTTP Method DELETE */
FIRHTTPMethodDELETE NS_SWIFT_NAME(delete),
/** HTTP Method HEAD */
FIRHTTPMethodHEAD NS_SWIFT_NAME(head),
/** HTTP Method PATCH */
FIRHTTPMethodPATCH NS_SWIFT_NAME(patch),
/** HTTP Method OPTIONS */
FIRHTTPMethodOPTIONS NS_SWIFT_NAME(options),
/** HTTP Method TRACE */
FIRHTTPMethodTRACE NS_SWIFT_NAME(trace),
/** HTTP Method CONNECT */
FIRHTTPMethodCONNECT NS_SWIFT_NAME(connect)
} NS_SWIFT_NAME(HTTPMethod);

This is logged as  https://bugs.llvm.org/show_bug.cgi?id=49995


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89425

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


[PATCH] D100630: [Debug-Info][DBX] DW_TAG_rvalue_reference_type should not be generated when dwarf version is smaller than 4

2021-05-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

This isn't the sort of thing I'd like to leave to a FIXME later - seems like 
the sort of thing we shouldn't create now to fix later.

@aprantl mind having a second look at this to consider the situation further?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100630

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


[PATCH] D102325: [clang-tidy] cppcoreguidelines-virtual-base-class-destructor: a new check

2021-05-15 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualBaseClassDestructorCheck.cpp:22
+void VirtualBaseClassDestructorCheck::registerMatchers(MatchFinder *Finder) {
+  ast_matchers::internal::Matcher inheritsVirtualMethod =
+  hasAnyBase(hasType(cxxRecordDecl(has(cxxMethodDecl(isVirtual());

Please fix `readability-identifier-naming` warning.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-virtual-base-class-destructor.rst:16
+
+This check implements `C.35 
`_
 from the CppCoreGuidelines.
+

Links to documentation usually placed at the end. See other checks 
documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102325

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


[PATCH] D102280: [analyzer] Engine: fix crash with SEH __leave keyword

2021-05-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D102280#2760402 , @AbbasSabra 
wrote:

> Is it a requirement for you to build them on Linux? Maybe you can try to 
> build them on windows with !!clang-cl!!?

It is a hard requirement. I'm gonna think more about this in the far future I 
guess. Thanks for the insight though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102280

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


[PATCH] D99646: [clang-tidy] misc-avoid-std-io-outside-main: a new check

2021-05-15 Thread Marco Gartmann via Phabricator via cfe-commits
mgartmann updated this revision to Diff 345634.
mgartmann added a comment.

Fetched new commits from upstream `main` branch and resolved merge conflicts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99646

Files:
  clang-tools-extra/clang-tidy/misc/AvoidStdIoOutsideMainCheck.cpp
  clang-tools-extra/clang-tidy/misc/AvoidStdIoOutsideMainCheck.h
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-avoid-std-io-outside-main.rst

Index: clang-tools-extra/docs/clang-tidy/checks/misc-avoid-std-io-outside-main.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc-avoid-std-io-outside-main.rst
@@ -0,0 +1,52 @@
+.. title:: clang-tidy - misc-avoid-std-io-outside-main
+
+misc-avoid-std-io-outside-main
+=
+
+Finds predefined standard stream objects like ``cin``, ``wcin``, ``cout``,
+``wcout``, ``cerr`` or ``wcerr``, that are used outside the ``main``
+function. It also finds uses of ``cstdio`` and ``stdio.h`` functions like
+``printf()`` outside the ``main`` function.
+
+For instance, in the following code, the use of ``std::cout`` and ``printf()``
+outside of ``main()`` would get flagged whereas the use of them inside
+``main()`` is not flagged:
+
+.. code-block:: c++
+
+  #include 
+  #include 
+
+  void some_function() {
+std::cout << "This triggers the check."; // NOK
+std::printf("This triggers the check."); // NOK
+  }
+
+  int main() {
+std::cout << "This does not trigger the check."; // OK
+std::printf("This does not trigger the check."); // OK
+  }
+
+Since the predefined standard stream objects are global objects, their use
+outside of ``main()`` worsens a program's testability and is thus discouraged.
+Instead, those objects should only be used inside ``main()``. They can then be
+passed as arguments to other functions like so:
+
+.. code-block:: c++
+
+  #include 
+
+  void some_function(std::istream & in, std::ostream & out) {
+out << "This does not trigger the check.";
+
+int i{0};
+in >> i;
+  }
+
+  int main() {
+some_function(std::cin, std::cout);
+  }
+
+In contrast to using ``std::cin`` and ``std::cout`` directly, in the above
+example, it is possible to inject mocked stream objects into
+``some_function()`` during testing.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -205,6 +205,7 @@
`llvmlibc-callee-namespace `_,
`llvmlibc-implementation-in-namespace `_,
`llvmlibc-restrict-system-libc-headers `_, "Yes"
+   `misc-misc-avoid-std-io-outside-main `_,
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
`misc-new-delete-overloads `_,
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -119,6 +119,14 @@
 
   Finds calls to ``new`` with missing exception handler for ``std::bad_alloc``.
 
+- New :doc:`misc-avoid-std-io-outside-main
+  ` check.
+
+  Finds predefined standard stream objects like ``cin``, ``wcin``, ``cout``,
+  ``wcout``, ``cerr`` or ``wcerr``, that are used outside the ``main``
+  function. It also finds uses of ``cstdio`` and ``stdio.h`` functions like
+  ``printf()`` outside the ``main`` function.
+
 New check aliases
 ^
 
Index: clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
+++ clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
@@ -9,6 +9,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidStdIoOutsideMainCheck.h"
 #include "DefinitionsInHeadersCheck.h"
 #include "MisplacedConstCheck.h"
 #include "NewDeleteOverloadsCheck.h"
@@ -31,6 +32,8 @@
 class MiscModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"misc-avoid-std-io-outside-main");
 CheckFactories.registerCheck(
 "misc-definitions-in-headers");
 CheckFactories.registerCheck("misc-misplaced-const");
Index: clang-tools-extra/clang-tidy/misc/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -4,6 +4,7 @@
   )
 
 add_clang_library(clangTidyMiscModule
+  AvoidStdIoOutsideMainCheck.c

[PATCH] D96033: [clang-repl] Land initial infrastructure for incremental parsing

2021-05-15 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

@v.g.vassilev, thanks for working with me on this. I understand it is difficult 
to handle issues that appear on platforms and build configurations one does not 
have set up.

I've added `-Xcc -v` and the output is below. It seems it has to do with the 
implicit `-fno-integrated-as` currently used with AIX. I'll paste the result 
with `-Xcc -fintegrated-as` in my next comment.

  $ cat /home/hstong/.Liodine/llvmproj/clang/test/Interpreter/execute.cpp | 
/home/hstong/.Nrtphome/.Liodine/llcrossbld/dev/build/bin/clang-repl -Xcc -v
  clang version 13.0.0
  Target: powerpc64-ibm-aix7.2.0.0
  Thread model: posix
  InstalledDir:
   "" -cc1 -triple powerpc64-ibm-aix7.2.0.0 -S -disable-free -main-file-name 
"<<< inputs >>>" -mrelocation-model pic -pic-level 2 -mframe-pointer=all 
-fmath-errno -fno-rounding-math -fno-verbose-asm -no-integrated-as -target-cpu 
pwr7 -mfloat-abi hard -mllvm -treat-scalable-fixed-error-as-warning 
-gstrict-dwarf -gno-column-info -debugger-tuning=dbx -v -fdata-sections 
-fcoverage-compilation-dir=/home/hstong/.Nrtphome/.Liodine/llcrossbld/dev/build 
-resource-dir lib/clang/13.0.0 -internal-isystem lib/clang/13.0.0/include 
-internal-isystem /usr/include -fdeprecated-macro -fno-dwarf-directory-asm 
-fdebug-compilation-dir=/home/hstong/.Nrtphome/.Liodine/llcrossbld/dev/build 
-ferror-limit 19 -fno-signed-char -fno-use-cxa-atexit -fgnuc-version=4.2.1 
-fcxx-exceptions -fexceptions -fcolor-diagnostics -fxl-pragma-pack -o 
"/tmp/hstong/auto.2021W19/<<< inputs >>>-e534ce.s" -x c++ "<<< inputs >>>"
   "/usr/bin/as" -a64 -many -o "<<< inputs >>>.o" "/tmp/hstong/auto.2021W19/<<< 
inputs >>>-e534ce.s"
  clang-repl: Driver initialization failed. Incremental mode for action is not 
supported


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96033

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


[PATCH] D102325: [clang-tidy] cppcoreguidelines-virtual-base-class-destructor: a new check

2021-05-15 Thread Marco Gartmann via Phabricator via cfe-commits
mgartmann updated this revision to Diff 345635.
mgartmann added a comment.

Resolved readability-identifier-naming warning, adjusted check's documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102325

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualBaseClassDestructorCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualBaseClassDestructorCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-virtual-base-class-destructor.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-base-class-destructor.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-base-class-destructor.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-base-class-destructor.cpp
@@ -0,0 +1,173 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-virtual-base-class-destructor %t
+
+// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: destructor of 'PrivateVirtualBaseStruct' is private and prevents using the type. Consider making it public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+struct PrivateVirtualBaseStruct {
+  virtual void f();
+
+private:
+  virtual ~PrivateVirtualBaseStruct(){};
+};
+
+struct PublicVirtualBaseStruct { // OK
+  virtual void f();
+  virtual ~PublicVirtualBaseStruct(){};
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: destructor of 'ProtectedVirtualBaseStruct' is protected and virtual. It should either be public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+struct ProtectedVirtualBaseStruct {
+  virtual void f();
+
+protected:
+  virtual ~ProtectedVirtualBaseStruct(){};
+  // CHECK-FIXES: ~ProtectedVirtualBaseStruct(){};
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: destructor of 'PrivateNonVirtualBaseStruct' is private and prevents using the type. Consider making it public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+struct PrivateNonVirtualBaseStruct {
+  virtual void f();
+
+private:
+  ~PrivateNonVirtualBaseStruct(){};
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: destructor of 'PublicNonVirtualBaseStruct' is public and non-virtual. It should either be public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+struct PublicNonVirtualBaseStruct {
+  virtual void f();
+  ~PublicNonVirtualBaseStruct(){};
+  // CHECK-FIXES: virtual ~PublicNonVirtualBaseStruct(){};
+};
+
+struct PublicNonVirtualNonBaseStruct { // OK according to C.35, since this struct does not have any virtual methods.
+  void f();
+  ~PublicNonVirtualNonBaseStruct(){};
+};
+
+// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: destructor of 'PublicImplicitNonVirtualBaseStruct' is public and non-virtual. It should either be public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+// CHECK-FIXES: struct PublicImplicitNonVirtualBaseStruct {
+// CHECK-FIXES-NEXT: virtual ~PublicImplicitNonVirtualBaseStruct() = default;
+struct PublicImplicitNonVirtualBaseStruct {
+  virtual void f();
+};
+
+// CHECK-MESSAGES: :[[@LINE+4]]:8: warning: destructor of 'PublicASImplicitNonVirtualBaseStruct' is public and non-virtual. It should either be public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+// CHECK-FIXES: struct PublicASImplicitNonVirtualBaseStruct {
+// CHECK-FIXES-NEXT: virtual ~PublicASImplicitNonVirtualBaseStruct() = default;
+// CHECK-FIXES-NEXT: private:
+struct PublicASImplicitNonVirtualBaseStruct {
+private:
+  virtual void f();
+};
+
+struct ProtectedNonVirtualBaseStruct { // OK
+  virtual void f();
+
+protected:
+  ~ProtectedNonVirtualBaseStruct(){};
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:7: warning: destructor of 'PrivateVirtualBaseClass' is private and prevents using the type. Consider making it public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+class PrivateVirtualBaseClass {
+  virtual void f();
+  virtual ~PrivateVirtualBaseClass(){};
+};
+
+class PublicVirtualBaseClass { // OK
+  virtual void f();
+
+public:
+  virtual ~PublicVirtualBaseClass(){};
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:7: warning: destructor of 'ProtectedVirtualBaseClass' is protected and virtual. It should either be public and virtual or protected and non-virtual [cppcoreguidelines-virtual-base-class-destructor]
+class ProtectedVirtualBaseClass {
+  virtual void f();
+
+protected:
+  virtual ~ProtectedVirtualBaseClass(){};
+  // CHECK-FIXES: ~

[PATCH] D102325: [clang-tidy] cppcoreguidelines-virtual-base-class-destructor: a new check

2021-05-15 Thread Marco Gartmann via Phabricator via cfe-commits
mgartmann marked 2 inline comments as done.
mgartmann added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-virtual-base-class-destructor.rst:16
+
+This check implements `C.35 
`_
 from the CppCoreGuidelines.
+

Eugene.Zelenko wrote:
> Links to documentation usually placed at the end. See other checks 
> documentation.
Thanks for pointing this out to me! 
I previously followed the style of other `cppcoreguideline` checks which did 
not have this line at the end of the file (e.g., [[ 
https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-prefer-member-initializer.html
 | cppcoreguidelines-prefer-member-initializer ]] or [[ 
https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-avoid-non-const-global-variables.html
 | cppcoreguidelines-avoid-non-const-global-variables]].

I adjusted the documentation according to your suggestion and now placed this 
line at the end.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102325

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


[PATCH] D96033: [clang-repl] Land initial infrastructure for incremental parsing

2021-05-15 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

Once I add `-Xcc -fintegrated-as`, we get:

  $ cat /home/hstong/.Liodine/llvmproj/clang/test/Interpreter/execute.cpp | 
/home/hstong/.Nrtphome/.Liodine/llcrossbld/dev/build/bin/clang-repl -Xcc 
-fintegrated-as
  fatal error: error in backend: 64-bit XCOFF object files are not supported 
yet.
  clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 

I am not sure if there's something to avoid this other than to XFAIL the test 
somehow while the 64-bit XCOFF integrated-as capability is still pending.
If you have some ideas, please let me know. Meanwhile, I am trying out 
`system-aix` as the "feature" to XFAIL on.

I still think the switch to the use the process triple in 
https://reviews.llvm.org/D96033#2759808 is perhaps correct (so even if it does 
not help currently for the configuration we have running, it could be 
worthwhile to commit).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96033

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


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-15 Thread Kostya Kortchinsky via Phabricator via cfe-commits
cryptoad added a comment.

Thanks a lot Mitch! Couple of comments from a first look, I'll give it another 
go later.




Comment at: compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp:42
+  if (Allocator.canReturnNull()) { 
\
+errno = EINVAL;
\
+return nullptr;
\

I don't think errno carry over to  C++, there seems to be no sign of it in 
https://en.cppreference.com/w/cpp/memory/new/operator_new



Comment at: compiler-rt/test/scudo/standalone/lit.cfg.py:21
 c_flags = ([config.target_cflags] +
-   ["-pthread",
-   "-fPIE",
-   "-pie",
-   "-O0",
-   "-UNDEBUG",
-   "-ldl",
-   "-Wl,--gc-sections"])
+   ["-pthread", "-fPIE", "-pie", "-O0", "-UNDEBUG", "-ldl",
+"-Wl,--gc-sections"])

-ldl might not be necessary anymore without the sanitizer dependencies?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

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


[PATCH] D102555: [libclang] Enhance support for source-to-source rewriting

2021-05-15 Thread Sam Vervaeck via Phabricator via cfe-commits
samvv created this revision.
samvv added reviewers: rsmith, jkorous.
Herald added a subscriber: arphaman.
samvv requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Hi! This is my first time submitting a patch to LLVM/Clang, so apologies if I'm 
doing anything wrong. Eager to learn.

This patch exposes some additional Rewriter methods in libclang and the Python 
bindings, making it possible to write simple transformations in Python. **This 
patch modifies the ABI signature of clang_CXRewriter_insertTextBefore.** I do 
not know what the policy is regarding the modification of an existing API 
function in libclang, so you have been warned.

- Added clang_CXRewriter_getMainFileContents
- Added clang_CXRewriter_insertTextAfter
- Added a parameter to clang_CXRewriter_insertTextBefore to control indentation
- Modified clang_CXRewriter_insertTextBefore to accept an additional 
`InsertIndent` argument
- Added a Rewriter class in the Python bindings
- Added `test_rewriter.py` with some unit tests for the new Python bindings
- Applied clang-format@HEAD to the modified C++ files, which caused some of the 
existing lines to change

I did not discuss this change over at cfe-dev because I thought the change is 
fairly trivial. If all changes are required to go through cfe-dev first do let 
me know.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102555

Files:
  clang/bindings/python/clang/cindex.py
  clang/bindings/python/tests/cindex/test_rewriter.py
  clang/include/clang-c/Rewrite.h
  clang/tools/libclang/Rewrite.cpp
  clang/tools/libclang/libclang.exports

Index: clang/tools/libclang/libclang.exports
===
--- clang/tools/libclang/libclang.exports
+++ clang/tools/libclang/libclang.exports
@@ -386,7 +386,9 @@
 clang_Cursor_hasVarDeclGlobalStorage
 clang_Cursor_hasVarDeclExternalStorage
 clang_CXRewriter_create
+clang_CXRewriter_getMainFileContents
 clang_CXRewriter_insertTextBefore
+clang_CXRewriter_insertTextAfter
 clang_CXRewriter_replaceText
 clang_CXRewriter_removeText
 clang_CXRewriter_overwriteChangedFiles
Index: clang/tools/libclang/Rewrite.cpp
===
--- clang/tools/libclang/Rewrite.cpp
+++ clang/tools/libclang/Rewrite.cpp
@@ -25,14 +25,24 @@
 }
 
 void clang_CXRewriter_insertTextBefore(CXRewriter Rew, CXSourceLocation Loc,
-const char *Insert) {
+   const char *Insert,
+   bool IndentNewLines) {
   assert(Rew);
   clang::Rewriter &R = *reinterpret_cast(Rew);
-  R.InsertTextBefore(clang::cxloc::translateSourceLocation(Loc), Insert);
+  R.InsertText(clang::cxloc::translateSourceLocation(Loc), Insert, false,
+   IndentNewLines);
+}
+
+void clang_CXRewriter_insertTextAfter(CXRewriter Rew, CXSourceLocation Loc,
+  const char *Insert, bool IndentNewLines) {
+  assert(Rew);
+  clang::Rewriter &R = *reinterpret_cast(Rew);
+  R.InsertText(clang::cxloc::translateSourceLocation(Loc), Insert, true,
+   IndentNewLines);
 }
 
 void clang_CXRewriter_replaceText(CXRewriter Rew, CXSourceRange ToBeReplaced,
-   const char *Replacement) {
+  const char *Replacement) {
   assert(Rew);
   clang::Rewriter &R = *reinterpret_cast(Rew);
   R.ReplaceText(clang::cxloc::translateCXRangeToCharRange(ToBeReplaced),
@@ -51,6 +61,15 @@
   return R.overwriteChangedFiles();
 }
 
+CXString clang_CXRewriter_getMainFileContents(CXRewriter Rew) {
+  assert(Rew);
+  clang::Rewriter &R = *reinterpret_cast(Rew);
+  std::string Res;
+  llvm::raw_string_ostream Out(Res);
+  R.getEditBuffer(R.getSourceMgr().getMainFileID()).write(Out);
+  return clang::cxstring::createDup(Res);
+}
+
 void clang_CXRewriter_writeMainFileToStdOut(CXRewriter Rew) {
   assert(Rew);
   clang::Rewriter &R = *reinterpret_cast(Rew);
Index: clang/include/clang-c/Rewrite.h
===
--- clang/include/clang-c/Rewrite.h
+++ clang/include/clang-c/Rewrite.h
@@ -25,22 +25,40 @@
 CINDEX_LINKAGE CXRewriter clang_CXRewriter_create(CXTranslationUnit TU);
 
 /**
- * Insert the specified string at the specified location in the original buffer.
+ * Get the contents of the main file as a string.
  */
-CINDEX_LINKAGE void clang_CXRewriter_insertTextBefore(CXRewriter Rew, CXSourceLocation Loc,
-   const char *Insert);
+CXString clang_CXRewriter_getMainFileContents(CXRewriter Rew);
+
+/**
+ * Insert the given string at the specified location in the original buffer.
+ */
+CINDEX_LINKAGE void clang_CXRewriter_insertTextBefore(CXRewriter Rew,
+  CXSourceLocation Loc,
+  const char *Insert,
+ 

[PATCH] D102555: [libclang] Enhance support for source-to-source rewriting

2021-05-15 Thread Sam Vervaeck via Phabricator via cfe-commits
samvv updated this revision to Diff 345641.
samvv added a comment.

Attempt at re-running clang-format-13.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102555

Files:
  clang/bindings/python/clang/cindex.py
  clang/bindings/python/tests/cindex/test_rewriter.py
  clang/include/clang-c/Rewrite.h
  clang/tools/libclang/Rewrite.cpp
  clang/tools/libclang/libclang.exports

Index: clang/tools/libclang/libclang.exports
===
--- clang/tools/libclang/libclang.exports
+++ clang/tools/libclang/libclang.exports
@@ -386,6 +386,8 @@
 clang_Cursor_hasVarDeclGlobalStorage
 clang_Cursor_hasVarDeclExternalStorage
 clang_CXRewriter_create
+clang_CXRewriter_getMainFileContents
+clang_CXRewriter_insertTextAfter
 clang_CXRewriter_insertTextBefore
 clang_CXRewriter_replaceText
 clang_CXRewriter_removeText
Index: clang/tools/libclang/Rewrite.cpp
===
--- clang/tools/libclang/Rewrite.cpp
+++ clang/tools/libclang/Rewrite.cpp
@@ -25,14 +25,24 @@
 }
 
 void clang_CXRewriter_insertTextBefore(CXRewriter Rew, CXSourceLocation Loc,
-const char *Insert) {
+   const char *Insert,
+   bool IndentNewLines) {
   assert(Rew);
   clang::Rewriter &R = *reinterpret_cast(Rew);
-  R.InsertTextBefore(clang::cxloc::translateSourceLocation(Loc), Insert);
+  R.InsertText(clang::cxloc::translateSourceLocation(Loc), Insert, false,
+   IndentNewLines);
+}
+
+void clang_CXRewriter_insertTextAfter(CXRewriter Rew, CXSourceLocation Loc,
+  const char *Insert, bool IndentNewLines) {
+  assert(Rew);
+  clang::Rewriter &R = *reinterpret_cast(Rew);
+  R.InsertText(clang::cxloc::translateSourceLocation(Loc), Insert, true,
+   IndentNewLines);
 }
 
 void clang_CXRewriter_replaceText(CXRewriter Rew, CXSourceRange ToBeReplaced,
-   const char *Replacement) {
+  const char *Replacement) {
   assert(Rew);
   clang::Rewriter &R = *reinterpret_cast(Rew);
   R.ReplaceText(clang::cxloc::translateCXRangeToCharRange(ToBeReplaced),
@@ -51,6 +61,15 @@
   return R.overwriteChangedFiles();
 }
 
+CXString clang_CXRewriter_getMainFileContents(CXRewriter Rew) {
+  assert(Rew);
+  clang::Rewriter &R = *reinterpret_cast(Rew);
+  std::string Res;
+  llvm::raw_string_ostream Out(Res);
+  R.getEditBuffer(R.getSourceMgr().getMainFileID()).write(Out);
+  return clang::cxstring::createDup(Res);
+}
+
 void clang_CXRewriter_writeMainFileToStdOut(CXRewriter Rew) {
   assert(Rew);
   clang::Rewriter &R = *reinterpret_cast(Rew);
Index: clang/include/clang-c/Rewrite.h
===
--- clang/include/clang-c/Rewrite.h
+++ clang/include/clang-c/Rewrite.h
@@ -25,22 +25,40 @@
 CINDEX_LINKAGE CXRewriter clang_CXRewriter_create(CXTranslationUnit TU);
 
 /**
- * Insert the specified string at the specified location in the original buffer.
+ * Get the contents of the main file as a string.
  */
-CINDEX_LINKAGE void clang_CXRewriter_insertTextBefore(CXRewriter Rew, CXSourceLocation Loc,
-   const char *Insert);
+CXString clang_CXRewriter_getMainFileContents(CXRewriter Rew);
+
+/**
+ * Insert the given string at the specified location in the original buffer.
+ */
+CINDEX_LINKAGE void clang_CXRewriter_insertTextBefore(CXRewriter Rew,
+  CXSourceLocation Loc,
+  const char *Insert,
+  bool IndentNewLines);
+
+/**
+ * Insert the given string right after the specified location in the original
+ * buffer.
+ */
+CINDEX_LINKAGE void clang_CXRewriter_insertTextAfter(CXRewriter Rew,
+ CXSourceLocation Loc,
+ const char *Insert,
+ bool IndentNewLines);
 
 /**
  * Replace the specified range of characters in the input with the specified
  * replacement.
  */
-CINDEX_LINKAGE void clang_CXRewriter_replaceText(CXRewriter Rew, CXSourceRange ToBeReplaced,
-  const char *Replacement);
+CINDEX_LINKAGE void clang_CXRewriter_replaceText(CXRewriter Rew,
+ CXSourceRange ToBeReplaced,
+ const char *Replacement);
 
 /**
  * Remove the specified range.
  */
-CINDEX_LINKAGE void clang_CXRewriter_removeText(CXRewriter Rew, CXSourceRange ToBeRemoved);
+CINDEX_LINKAGE void clang_CXRewriter_removeText(CXRewriter Rew,
+CXSourceRange ToBeRemov

[PATCH] D102118: [BPF] add support for 32 bit registers in inline asm

2021-05-15 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song accepted this revision.
yonghong-song added a comment.
This revision is now accepted and ready to land.

LGTM except one minor issue. Please do address the nit before merging. Thanks!




Comment at: clang/test/CodeGen/bpf-inline-asm.c:5
+
+long var;
+

The `var` is not used and can be removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102118

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


[PATCH] D102556: [HIP] Fix spack detection

2021-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added subscribers: kerbowa, nhaehnle, jvesely.
yaxunl requested review of this revision.

Missing or duplicate spack package should not cause error, since
users may only installed llvm/clang package, or users may installed
duplicate HIP package but will use environment variable or compiler
option to choose HIP path.

The message about missing or duplicate spack package is for informational
and will be emitted only when -v is specified.


https://reviews.llvm.org/D102556

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/ROCm.h
  clang/test/Driver/rocm-detect.hip


Index: clang/test/Driver/rocm-detect.hip
===
--- clang/test/Driver/rocm-detect.hip
+++ clang/test/Driver/rocm-detect.hip
@@ -61,12 +61,15 @@
 // RUN:%s 2>&1 | FileCheck -check-prefixes=SPACK-SET %s
 
 // Test invalid SPACK ROCm installation missing hip and rocm-device-libs 
packages.
+// The message about SPACK is emitted only if -v is specified.
 
 // RUN: rm -rf %T/rocm-spack/hip-*
 // RUN: rm -rf %T/rocm-spack/rocm-device-libs-*
 // RUN: 
%T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### 
-v \
 // RUN:   -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 %s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=SPACK-MISS %s
+// RUN: 
%T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang 
--version 2>&1 \
+// RUN:   | FileCheck -check-prefixes=SPACK-MISS-SILENT %s
 
 // GFX902-DEFAULTLIBS: error: cannot find ROCm device library for gfx902. 
Provide its path via --rocm-path or --rocm-device-lib-path, or pass -nogpulib 
to build without ROCm device library
 
@@ -90,8 +93,8 @@
 // SPACK-SAME: "-internal-isystem" 
"[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
 
 // SPACK-MULT: InstalledDir: 
[[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
-// SPACK-MULT-DAG: Expecting one SPACK package hip-4.0.0 at [[DIR]] but found 
more
-// SPACK-MULT-DAG: Expecting one SPACK package rocm-device-libs-4.0.0 at 
[[DIR]] but found more
+// SPACK-MULT-DAG: Cannot use SPACK package hip-4.0.0 at [[DIR]] due to 
multiple installations for the same version
+// SPACK-MULT-DAG: Cannot use SPACK package rocm-device-libs-4.0.0 at [[DIR]] 
due to multiple installations for the same version
 // SPACK-MULT-NOT: Found HIP installation: 
[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
 // SPACK-MULT-NOT: "-mlink-builtin-bitcode" 
"[[DIR]]/rocm-device-libs-4.0.0-6wnyzz4hgl3hr7uswasnagt7j2adctbs/amdgcn/bitcode/hip.bc"
 // SPACK-MULT-NOT: "-internal-isystem" 
"[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
@@ -103,8 +106,12 @@
 // SPACK-SET-SAME: "-internal-isystem" "[[DIR]]/hip-4.0.0-abcd/include"
 
 // SPACK-MISS: InstalledDir: 
[[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
-// SPACK-MISS-DAG: Expecting SPACK package hip-4.0.0 at [[DIR]] but not found
-// SPACK-MISS-DAG: Expecting SPACK package rocm-device-libs-4.0.0 at [[DIR]] 
but not found
+// SPACK-MISS-DAG: SPACK package hip-4.0.0 not found at [[DIR]]
+// SPACK-MISS-DAG: SPACK package rocm-device-libs-4.0.0 not found at [[DIR]]
 // SPACK-MISS-NOT: Found HIP installation: 
[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
 // SPACK-MISS-NOT: "-mlink-builtin-bitcode" 
"[[DIR]]/rocm-device-libs-4.0.0-6wnyzz4hgl3hr7uswasnagt7j2adctbs/amdgcn/bitcode/hip.bc"
 // SPACK-MISS-NOT: "-internal-isystem" 
"[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
+
+// SPACK-MISS-SILENT-NOT: SPACK package hip-4.0.0 not found at
+// SPACK-MISS-SILENT-NOT: SPACK package rocm-device-libs-4.0.0 not found at
+// SPACK-MISS-SILENT-NOT: Found HIP installation
Index: clang/lib/Driver/ToolChains/ROCm.h
===
--- clang/lib/Driver/ToolChains/ROCm.h
+++ clang/lib/Driver/ToolChains/ROCm.h
@@ -110,6 +110,7 @@
   // Cache ROCm installation search paths.
   SmallVector ROCmSearchDirs;
   bool PrintROCmSearchDirs;
+  bool Verbose;
 
   bool allGenericLibsValid() const {
 return !OCML.empty() && !OCKL.empty() && !OpenCL.empty() && !HIP.empty() &&
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -58,19 +58,16 @@
 llvm::sys::path::append(PackagePath, SubDirs[0]);
 return PackagePath;
   }
-  if (SubDirs.size() == 0) {
-unsigned DiagID = D.getDiags().getCustomDiagID(
-DiagnosticsEngine::Error,
-"Expecting SPACK package %0 at %1 but not found");
-D.Diag(DiagID) << Prefix << Cand.Path;
+  if (SubDirs.size() == 0 && Verbose) {
+llvm::errs() << "SPACK package " << Prefix << " not found at " << Cand.Path
+ << '\n';
 return {};
   }
 
-  assert(SubDirs.size() > 1);
-  uns

[clang] c9b36a0 - Support GCC's -fstack-usage flag

2021-05-15 Thread Pengxuan Zheng via cfe-commits

Author: Pengxuan Zheng
Date: 2021-05-15T10:22:49-07:00
New Revision: c9b36a041fd70de0617ea7e241f520b345e12cac

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

LOG: Support GCC's -fstack-usage flag

This patch adds support for GCC's -fstack-usage flag. With this flag, a stack
usage file (i.e., .su file) is generated for each input source file. The format
of the stack usage file is also similar to what is used by GCC. For each
function defined in the source file, a line with the following information is
produced in the .su file.

::  

"Static" means that the function's frame size is static and the size info is an
accurate reflection of the frame size. While "dynamic" means the function's
frame size can only be determined at run-time because the function manipulates
the stack dynamically (e.g., due to variable size objects). The size info only
reflects the size of the fixed size frame objects in this case and therefore is
not a reliable measure of the total frame size.

Reviewed By: MaskRay

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

Added: 
clang/test/CodeGen/stack-usage.c
clang/test/Driver/stack-usage.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
llvm/include/llvm/CodeGen/AsmPrinter.h
llvm/include/llvm/Target/TargetOptions.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 17351278974df..f3f7fb4eabc3c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -70,6 +70,10 @@ New Compiler Flags
 - ``-Wreserved-identifier`` emits warning when user code uses reserved
   identifiers.
 
+- ``-fstack-usage`` generates an extra .su file per input source file. The .su
+  file contains frame size information for each function defined in the source
+  file.
+
 Deprecated Compiler Flags
 -
 

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 3f06dd3a3f821..90388b169f5e0 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -372,6 +372,11 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// coverage pass should actually not be instrumented.
   std::vector SanitizeCoverageIgnorelistFiles;
 
+  /// Name of the stack usage file (i.e., .su file) if user passes
+  /// -fstack-usage. If empty, it can be implied that -fstack-usage is not
+  /// passed on the command line.
+  std::string StackUsageOutput;
+
   /// Executable and command-line used to create a given CompilerInvocation.
   /// Most of the time this will be the full -cc1 command.
   const char *Argv0 = nullptr;

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a7adab50657af..c1d096f358d9e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2709,6 +2709,12 @@ defm stack_size_section : 
BoolFOption<"stack-size-section",
   CodeGenOpts<"StackSizeSection">, DefaultFalse,
   PosFlag,
   NegFlag>;
+def fstack_usage : Flag<["-"], "fstack-usage">, Group,
+  HelpText<"Emit .su file containing information on function stack sizes">;
+def stack_usage_file : Separate<["-"], "stack-usage-file">,
+  Flags<[CC1Option, NoDriverOption]>,
+  HelpText<"Filename (or -) to write stack usage output to">,
+  MarshallingInfoString>;
 
 defm unique_basic_block_section_names : 
BoolFOption<"unique-basic-block-section-names",
   CodeGenOpts<"UniqueBasicBlockSectionNames">, DefaultFalse,

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index e2799f6aba4ca..e5a2a089563ef 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -567,6 +567,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   Options.ExplicitEmulatedTLS = CodeGenOpts.ExplicitEmulatedTLS;
   Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
   Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
+  Options.StackUsageOutput = CodeGenOpts.StackUsageOutput;
   Options.EmitAddrsig = CodeGenOpts.Addrsig;
   Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
   Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 061b578cc6ff7..fe0f57d4c4791 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5492,6 +5492,18 @@ void Clang::ConstructJob(Compilation &C, const JobAction

[PATCH] D100509: Support GCC's -fstack-usage flag

2021-05-15 Thread Pengxuan Zheng via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc9b36a041fd7: Support GCC's -fstack-usage flag 
(authored by pzheng).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100509

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/stack-usage.c
  clang/test/Driver/stack-usage.c
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1185,6 +1185,37 @@
   OutStreamer->PopSection();
 }
 
+void AsmPrinter::emitStackUsage(const MachineFunction &MF) {
+  const std::string &OutputFilename = MF.getTarget().Options.StackUsageOutput;
+
+  // OutputFilename empty implies -fstack-usage is not passed.
+  if (OutputFilename.empty())
+return;
+
+  const MachineFrameInfo &FrameInfo = MF.getFrameInfo();
+  uint64_t StackSize = FrameInfo.getStackSize();
+
+  if (StackUsageStream == nullptr) {
+std::error_code EC;
+StackUsageStream =
+std::make_unique(OutputFilename, EC, sys::fs::OF_Text);
+if (EC) {
+  errs() << "Could not open file: " << EC.message();
+  return;
+}
+  }
+
+  *StackUsageStream << MF.getFunction().getParent()->getName();
+  if (const DISubprogram *DSP = MF.getFunction().getSubprogram())
+*StackUsageStream << ':' << DSP->getLine();
+
+  *StackUsageStream << ':' << MF.getName() << '\t' << StackSize << '\t';
+  if (FrameInfo.hasVarSizedObjects())
+*StackUsageStream << "dynamic\n";
+  else
+*StackUsageStream << "static\n";
+}
+
 static bool needFuncLabelsForEHOrDebugInfo(const MachineFunction &MF) {
   MachineModuleInfo &MMI = MF.getMMI();
   if (!MF.getLandingPads().empty() || MF.hasEHFunclets() || MMI.hasDebugInfo())
@@ -1469,6 +1500,9 @@
   // Emit section containing stack size metadata.
   emitStackSizeSection(*MF);
 
+  // Emit .su file containing function stack size information.
+  emitStackUsage(*MF);
+
   emitPatchableFunctionEntries();
 
   if (isVerbose())
Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -342,6 +342,11 @@
 /// Stack protector guard reg to use, e.g. usually fs or gs in X86.
 std::string StackProtectorGuardReg = "None";
 
+/// Name of the stack usage file (i.e., .su file) if user passes
+/// -fstack-usage. If empty, it can be implied that -fstack-usage is not
+/// passed on the command line.
+std::string StackUsageOutput;
+
 /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
 /// on the command line. This setting may either be Default, Soft, or Hard.
 /// Default selects the target's default behavior. Soft selects the ABI for
Index: llvm/include/llvm/CodeGen/AsmPrinter.h
===
--- llvm/include/llvm/CodeGen/AsmPrinter.h
+++ llvm/include/llvm/CodeGen/AsmPrinter.h
@@ -182,6 +182,9 @@
   /// Emit comments in assembly output if this is true.
   bool VerboseAsm;
 
+  /// Output stream for the stack usage file (i.e., .su file).
+  std::unique_ptr StackUsageStream;
+
   static char ID;
 
 protected:
@@ -358,6 +361,8 @@
 
   void emitStackSizeSection(const MachineFunction &MF);
 
+  void emitStackUsage(const MachineFunction &MF);
+
   void emitBBAddrMapSection(const MachineFunction &MF);
 
   void emitPseudoProbe(const MachineInstr &MI);
Index: clang/test/Driver/stack-usage.c
===
--- /dev/null
+++ clang/test/Driver/stack-usage.c
@@ -0,0 +1,7 @@
+// RUN: %clang -target aarch64-unknown %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ABSENT
+// CHECK-ABSENT-NOT: "-stack-usage-file"
+
+// RUN: %clang -target aarch64-unknown -fstack-usage %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-PRESENT
+// CHECK-PRESENT: "-stack-usage-file"
+
+int foo() { return 42; }
Index: clang/test/CodeGen/stack-usage.c
===
--- /dev/null
+++ clang/test/CodeGen/stack-usage.c
@@ -0,0 +1,19 @@
+// REQUIRES: aarch64-registered-target
+
+// RUN: rm -rf %t && mkdir %t && cd %t
+// RUN: %clang_cc1 -triple aarch64-unknown -stack-usage-file b.su -emit-obj %s -o b.o
+// RUN: FileCheck %s < b.su
+
+// CHECK: stack-usage.c:[[#@LINE+1]]:foo	{{[0-9]+}}	static
+int foo() {
+  char a[8];
+
+  return 0;
+}
+
+// CHECK: stack-usage.c:[[#@LINE+1]]:bar	{{[0-9]+}}	dynamic
+int

[PATCH] D87029: [AIX] Implement AIX special bitfield related alignment rules

2021-05-15 Thread Sean Fertile via Phabricator via cfe-commits
sfertile accepted this revision.
sfertile added a comment.
This revision is now accepted and ready to land.

LGTM.


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

https://reviews.llvm.org/D87029

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


[PATCH] D102558: [Utils] Check for generated functions inline if possible

2021-05-15 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert created this revision.
jdoerfert added reviewers: greened, arichardson, ggeorgakoudis.
Herald added a subscriber: bollu.
jdoerfert requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

With D83004  we allowed to check for generated 
functions. However, since
those might be generated in various places we did simply check for all
functions in the end. Furthermore, this prevented us from reusing check
prefixes across run lines. For every run line we checked for all functions
regardless if the functions were equal across prefixes.

To reduce the number of check lines we now allow to reuse them across
run lines. That is, we can have prefixes that span multiple run lines
even when we check for generated functions. This will only reduce the
run lines if we can find a total order of the generated functions
though. The check lines for generated functions are placed in-between
check lines of existing functions or at the end, as necessary.

The IR update script needs adjusts similar to the CC one.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102558

Files:
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
  
clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.expected
  clang/test/utils/update_cc_test_checks/Inputs/lots-of-generated-funcs.c
  
clang/test/utils/update_cc_test_checks/Inputs/lots-of-generated-funcs.c.lots-of-generated.expected
  
clang/test/utils/update_cc_test_checks/Inputs/lots-of-generated-funcs.c.no-lots-of-generated.expected
  clang/test/utils/update_cc_test_checks/lots-of-generated-funcs.test
  llvm/utils/UpdateTestChecks/common.py
  llvm/utils/update_cc_test_checks.py
  llvm/utils/update_test_checks.py

Index: llvm/utils/update_test_checks.py
===
--- llvm/utils/update_test_checks.py
+++ llvm/utils/update_test_checks.py
@@ -138,6 +138,9 @@
   '--include-generated-funcs',
   True)
 
+# TODO: use common.get_total_function_order to avoid adding new functions at the end but
+#   instead place them in order between existing ones. See the CC script.
+
 if include_generated_funcs:
   # Generate the appropriate checks for each function.  We need to emit
   # these in the order according to the generated output so that CHECK-LABEL
Index: llvm/utils/update_cc_test_checks.py
===
--- llvm/utils/update_cc_test_checks.py
+++ llvm/utils/update_cc_test_checks.py
@@ -305,8 +305,9 @@
   lambda args: ti.args.include_generated_funcs,
   '--include-generated-funcs',
   True)
+total_function_order = common.get_total_function_order(filecheck_run_list, builder.func_order())
 
-if include_generated_funcs:
+if include_generated_funcs and not total_function_order:
   # Generate the appropriate checks for each function.  We need to emit
   # these in the order according to the generated output so that CHECK-LABEL
   # works properly.  func_order provides that.
@@ -337,6 +338,59 @@
check_generator(my_output_lines,
prefixes, func))
 else:
+  trailing_functions = []
+  # If we might have generated functions we need to place them in the right position now,
+  # trailing ones are kept separate though.
+  if include_generated_funcs:
+total_order_idx = 0
+for line in line2spell_and_mangled_list.keys():
+  to_be_added = []
+  for spell, mangled in line2spell_and_mangled_list[line]:
+if mangled not in total_function_order:
+  continue
+# Figure out where this existing function is in the total order. All functions we
+# skipped are inserted before this one.
+index = total_function_order.index(mangled)
+while total_order_idx < index:
+  to_be_added.append(total_function_order[total_order_idx])
+  total_order_idx += 1
+# Account for the function itself (spell, mangled)
+total_order_idx += 1
+  # Reverse the order to match total order again before we insert the functions
+  # in the current line.
+  to_be_added.reverse()
+  for tba in to_be_added:
+line2spell_and_mangled_list[line].insert(0, ('', tba))
+
+# All functions we have not handled yet are added to the end.
+while total_order_idx < len(total_function_order):
+  func = total_function_order[total_order_idx]
+  trailing_functions.append(func)
+   

[PATCH] D102560: [AIX][clang-repl][test] Mark unsupported pending XCOFF64 integrated-as

2021-05-15 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast created this revision.
hubert.reinterpretcast added reviewers: v.g.vassilev, lhames, daltenty, 
jasonliu, jsji.
Herald added a subscriber: steven.zhang.
hubert.reinterpretcast requested review of this revision.
Herald added a project: clang.

This patch replaces the `powerpc64` token with the `system-aix` one in the 
UNSUPPORTED line of a test. The `powerpc64` token was originally added 
temporarily in 71a0609a2b53 
.

If AIX uses integrated-as by default and it works both for 32-bit and 64-bit 
objects, then the issues encountered so far (see comments in D96033 
) would be mostly solved.

As it is, marking the test as expected-to-fail (as opposed to unsupported) on 
AIX might cause more trouble in the form of 32-bit versus 64-bit differences. I 
am not aware of other situations where LIT tests are dependent on whether the 
LLVM build is 64-bit or 32-bit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102560

Files:
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -1,6 +1,6 @@
 // RUN: cat %s | clang-repl | FileCheck %s
 // REQUIRES: host-supports-jit
-// UNSUPPORTED: powerpc64
+// UNSUPPORTED: system-aix
 
 extern "C" int printf(const char *, ...);
 int i = 42;


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -1,6 +1,6 @@
 // RUN: cat %s | clang-repl | FileCheck %s
 // REQUIRES: host-supports-jit
-// UNSUPPORTED: powerpc64
+// UNSUPPORTED: system-aix
 
 extern "C" int printf(const char *, ...);
 int i = 42;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96033: [clang-repl] Land initial infrastructure for incremental parsing

2021-05-15 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D96033#2761428 , 
@hubert.reinterpretcast wrote:

> If you have some ideas, please let me know. Meanwhile, I am trying out 
> `system-aix` as the "feature" to XFAIL on.

https://reviews.llvm.org/D102560 posted to use `system-aix` so other PPC 
configurations will run the test. Possible further changes is for the code to 
choose the process triple, for the test to possibly specify `-fintegrated-as`, 
and (alternatively) for the system assembler step to be integrated into this 
use scenario.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96033

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


[PATCH] D98799: [UniqueLinkageName] Use consistent checks when mangling symbo linkage name and debug linkage name.

2021-05-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added subscribers: JDevlieghere, rjmccall.
dblaikie added a comment.

OK - poked around a bit more to better understand this, so attempting to 
summarize my current understanding (excuse the repetition from previous parts 
of this thread) and results.

- `__attribute__((overloadable))` can/does mangle K&R C style declarations 

- with this patch (currently committed), `-funique-internal-linkage-names` does 
not mangle K&R C style declarations (see `bar` in the included test case, 
unmangled)
- I'd like to avoid that divergence if possible
- Changing the debug info code to be more generous with names it mangles (by 
using `FD->getType()->getAs()` rather than `hasPrototype()`) 
causes problems
  - Specifically: Objective C blocks (which have a `FunctionProtoType` type, 
but `!hasPrototype` it seems) are missing parameter info so this 

 call crashes
- There doesn't seem to be any way to test for this property of the 
`FunctionDecl` that I can see - where it has a type, but doesn't have parameter 
info

Trying to pull in some folks who might know what's going on here/be able to 
suggest a way to split these cases if needed, or fix the block `FunctionDecl`s 
to have param info. @rjmccall @JDevlieghere - I'd really appreciate some help 
here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98799

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


[PATCH] D102560: [AIX][clang-repl][test] Mark unsupported pending XCOFF64 integrated-as

2021-05-15 Thread Jinsong Ji via Phabricator via cfe-commits
jsji accepted this revision.
jsji added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102560

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


[clang] 9ae529d - [AIX][clang-repl][test] Mark unsupported pending XCOFF64 integrated-as

2021-05-15 Thread Hubert Tong via cfe-commits

Author: Hubert Tong
Date: 2021-05-15T22:41:45-04:00
New Revision: 9ae529d0db2d6841b3b2e49525e03b33e8445636

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

LOG: [AIX][clang-repl][test] Mark unsupported pending XCOFF64 integrated-as

This patch replaces the `powerpc64` token with the `system-aix` one in
the UNSUPPORTED line of a test. The `powerpc64` token was originally
added temporarily in 71a0609a2b53.

If AIX uses integrated-as by default and it works both for 32-bit and
64-bit objects, then the issues encountered so far (see comments in
D96033) would be mostly solved.

As it is, marking the test as expected-to-fail (as opposed to
unsupported) on AIX might cause more trouble in the form of 32-bit
versus 64-bit differences. I am not aware of other situations where LIT
tests are dependent on whether the LLVM build is 64-bit or 32-bit.

Reviewed By: jsji

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

Added: 


Modified: 
clang/test/Interpreter/execute.cpp

Removed: 




diff  --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index a9beed5714d0b..108b79b23a59d 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -1,6 +1,6 @@
 // RUN: cat %s | clang-repl | FileCheck %s
 // REQUIRES: host-supports-jit
-// UNSUPPORTED: powerpc64
+// UNSUPPORTED: system-aix
 
 extern "C" int printf(const char *, ...);
 int i = 42;



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


[PATCH] D102560: [AIX][clang-repl][test] Mark unsupported pending XCOFF64 integrated-as

2021-05-15 Thread Hubert Tong via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9ae529d0db2d: [AIX][clang-repl][test] Mark unsupported 
pending XCOFF64 integrated-as (authored by hubert.reinterpretcast).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102560

Files:
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -1,6 +1,6 @@
 // RUN: cat %s | clang-repl | FileCheck %s
 // REQUIRES: host-supports-jit
-// UNSUPPORTED: powerpc64
+// UNSUPPORTED: system-aix
 
 extern "C" int printf(const char *, ...);
 int i = 42;


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -1,6 +1,6 @@
 // RUN: cat %s | clang-repl | FileCheck %s
 // REQUIRES: host-supports-jit
-// UNSUPPORTED: powerpc64
+// UNSUPPORTED: system-aix
 
 extern "C" int printf(const char *, ...);
 int i = 42;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102568: [Driver] Delete -mimplicit-it=

2021-05-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: nickdesaulniers, ostannard, raj.khem.
Herald added subscribers: dang, kristof.beyls.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a GNU as and Clang cc1as option, not a GCC option.
Users should specify `-Wa,-mimplicit-it=` instead.

Note: mixing the -m option and the -Wa, option doesn't work
`-Wa,-mimplicit-it=never -mimplicit-it=always` =>
`clang (LLVM option parsing): for the --arm-implicit-it option: may only occur 
zero or one times!`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102568

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/arm-implicit-it.s
  clang/test/Driver/arm-target-as-mimplicit-it.s
  clang/test/Driver/as-options.s

Index: clang/test/Driver/as-options.s
===
--- clang/test/Driver/as-options.s
+++ clang/test/Driver/as-options.s
@@ -53,20 +53,6 @@
 // RUN:   -o /dev/null -x assembler-with-cpp %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=WARN --allow-empty %s
 
-// RUN: %clang -mimplicit-it=always -target armv7-linux-gnueabi -E \
-// RUN:   -fintegrated-as -o /dev/null -x c++ %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=NOWARN --allow-empty %s
-// RUN: %clang -mimplicit-it=always -target armv7-linux-gnueabi -E \
-// RUN:   -fno-integrated-as -o /dev/null -x c++ %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=WARN --allow-empty %s
-
-// RUN: %clang -mimplicit-it=always -target armv7-linux-gnueabi -E \
-// RUN:   -fintegrated-as -o /dev/null -x assembler-with-cpp %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=NOWARN --allow-empty %s
-// RUN: %clang -mimplicit-it=always -target armv7-linux-gnueabi -E \
-// RUN:   -fno-integrated-as -o /dev/null -x assembler-with-cpp %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=WARN --allow-empty %s
-
 // RUN: %clang -Wa,-mbig-obj -target i386-pc-windows -E -fintegrated-as \
 // RUN:   -o /dev/null -x c++ %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=NOWARN --allow-empty %s
Index: clang/test/Driver/arm-target-as-mimplicit-it.s
===
--- clang/test/Driver/arm-target-as-mimplicit-it.s
+++ clang/test/Driver/arm-target-as-mimplicit-it.s
@@ -20,13 +20,6 @@
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always,-mimplicit-it=arm %s 2>&1 | FileCheck %s --check-prefix=ARM
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always,-mimplicit-it=thumb %s 2>&1 | FileCheck %s --check-prefix=THUMB
 
-/// Mix -implicit-it= (compiler) with -Wa,-mimplicit-it= (assembler), assembler
-/// takes priority. -mllvm -arm-implicit-it= will be repeated, with the
-/// assembler flag appearing last (latter wins).
-// RUN: %clang -target arm-linux-gnueabi -### -mimplicit-it=never -Wa,-mimplicit-it=always %S/Inputs/wildcard1.c 2>&1 | FileCheck %s --check-prefix=NEVER_ALWAYS
-// RUN: %clang -target arm-linux-gnueabi -### -mimplicit-it=always -Wa,-mimplicit-it=never %S/Inputs/wildcard1.c 2>&1 | FileCheck %s --check-prefix=ALWAYS_NEVER
-// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=never -mimplicit-it=always %S/Inputs/wildcard1.c 2>&1 | FileCheck %s --check-prefix=ALWAYS_NEVER
-
 /// Test invalid input.
 // RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=foo %s 2>&1 | FileCheck %s --check-prefix=INVALID
 // RUN: %clang -target arm-linux-gnueabi -### -Xassembler -mimplicit-it=foo %s 2>&1 | FileCheck %s --check-prefix=XINVALID
@@ -38,7 +31,5 @@
 // NEVER: "-mllvm" "-arm-implicit-it=never"
 // ARM: "-mllvm" "-arm-implicit-it=arm"
 // THUMB: "-mllvm" "-arm-implicit-it=thumb"
-// NEVER_ALWAYS: "-mllvm" "-arm-implicit-it=never" "-mllvm" "-arm-implicit-it=always"
-// ALWAYS_NEVER: "-mllvm" "-arm-implicit-it=always" "-mllvm" "-arm-implicit-it=never"
 // INVALID: error: unsupported argument '-mimplicit-it=foo' to option 'Wa,'
 // XINVALID: error: unsupported argument '-mimplicit-it=foo' to option 'Xassembler'
Index: clang/test/Driver/arm-implicit-it.s
===
--- clang/test/Driver/arm-implicit-it.s
+++ /dev/null
@@ -1,24 +0,0 @@
-// RUN: %clang -target armv7--none-eabi -### %s 2>&1 \
-// RUN:| FileCheck %s -check-prefix CHECK-DEFAULT
-
-// RUN: %clang -target armv7--none-eabi -mimplicit-it=arm -### %s 2>&1 \
-// RUN:| FileCheck %s -check-prefix CHECK-ARM
-
-// RUN: %clang -target armv7--none-eabi -mimplicit-it=thumb -### %s 2>&1 \
-// RUN:| FileCheck %s -check-prefix CHECK-THUMB
-
-// RUN: %clang -target armv7--none-eabi -mimplicit-it=never -### %s 2>&1 \
-// RUN:| FileCheck %s -check-prefix CHECK-NEVER
-
-// RUN: %clang -target armv7--none-eabi -mimplicit-it=always -### %s 2>&1 \
-// RUN:| FileCheck %s -check-prefix CHECK-ALWAYS
-
-// RUN: %clang -target armv7--none-eabi -mimplicit-it=thisisnotavalidoption -### %s 

[PATCH] D102569: [clang-tidy] Fix altera-struct-pack-align crash for struct fields with incomplete type

2021-05-15 Thread Georgy Komarov via Phabricator via cfe-commits
jubnzv created this revision.
jubnzv added reviewers: aaron.ballman, njames93.
jubnzv added a project: clang-tools-extra.
Herald added a subscriber: xazax.hun.
jubnzv requested review of this revision.

We can only use `ASTContext::getTypeInfo` for complete types.

This fixes the following bugzilla issue: 
https://bugs.llvm.org/show_bug.cgi?id=50313.


https://reviews.llvm.org/D102569

Files:
  clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp
@@ -0,0 +1,7 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s altera-struct-pack-align 
%t -- -header-filter=.*
+
+struct A;
+struct B {
+  A a;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: error: field has incomplete type 'A' 
[clang-diagnostic-error]
+};
Index: clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
===
--- clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
+++ clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
@@ -58,9 +58,11 @@
 // For each StructField, record how big it is (in bits).
 // Would be good to use a pair of  to advise a better
 // packing order.
+QualType StructFieldTy = StructField->getType();
+if (StructFieldTy->isIncompleteType())
+  return;
 unsigned int StructFieldWidth =
-(unsigned int)Result.Context
-->getTypeInfo(StructField->getType().getTypePtr())
+(unsigned int)Result.Context->getTypeInfo(StructFieldTy.getTypePtr())
 .Width;
 FieldSizes.emplace_back(StructFieldWidth, StructField->getFieldIndex());
 // FIXME: Recommend a reorganization of the struct (sort by StructField


Index: clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp
@@ -0,0 +1,7 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s altera-struct-pack-align %t -- -header-filter=.*
+
+struct A;
+struct B {
+  A a;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: error: field has incomplete type 'A' [clang-diagnostic-error]
+};
Index: clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
===
--- clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
+++ clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
@@ -58,9 +58,11 @@
 // For each StructField, record how big it is (in bits).
 // Would be good to use a pair of  to advise a better
 // packing order.
+QualType StructFieldTy = StructField->getType();
+if (StructFieldTy->isIncompleteType())
+  return;
 unsigned int StructFieldWidth =
-(unsigned int)Result.Context
-->getTypeInfo(StructField->getType().getTypePtr())
+(unsigned int)Result.Context->getTypeInfo(StructFieldTy.getTypePtr())
 .Width;
 FieldSizes.emplace_back(StructFieldWidth, StructField->getFieldIndex());
 // FIXME: Recommend a reorganization of the struct (sort by StructField
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits