[PATCH] D122336: [InstrProfiling] No runtime hook for unused funcs

2022-03-24 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp:569-573
+if (!CoverageNamesVar) {
+  return MadeChange;
+} else if (!NeedsRuntimeHook) {
+  return MadeChange;
+}

This could be combined into a single statement.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122336

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


[clang] 1c13bbd - [NFCI] Fix set-but-unused warning in UnwrappedLineParser.cpp

2022-03-24 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-24T08:13:29+01:00
New Revision: 1c13bbdde630b8716f817989a33ccc77a588642c

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

LOG: [NFCI] Fix set-but-unused warning in UnwrappedLineParser.cpp

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 8052eb932141d..b8cffcd471e91 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -600,10 +600,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   do {
 // Get next non-comment token.
 FormatToken *NextTok;
-unsigned ReadTokens = 0;
 do {
   NextTok = Tokens->getNextToken();
-  ++ReadTokens;
 } while (NextTok->is(tok::comment));
 
 switch (Tok->Tok.getKind()) {
@@ -643,7 +641,6 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
 ScopedMacroState MacroState(*Line, Tokens, NextTok);
 do {
   NextTok = Tokens->getNextToken();
-  ++ReadTokens;
 } while (NextTok->isNot(tok::eof));
   }
 
@@ -696,7 +693,6 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
 // We can have an array subscript after a braced init
 // list, but C++11 attributes are expected after blocks.
 NextTok = Tokens->getNextToken();
-++ReadTokens;
 ProbablyBracedList = NextTok->isNot(tok::l_square);
   }
 }



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


[PATCH] D121201: [clang] Merge the SourceRange into ParsedAttributes

2022-03-24 Thread Timm Bäder 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 rG711e3a569167: [clang][parse] Move source range into 
ParsedAttibutesView (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121201

Files:
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaOpenCL/address-spaces.cl

Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -258,7 +258,7 @@
 
 void func_multiple_addr2(void) {
   typedef __private int private_int_t;
-  __private __attribute__((opencl_global)) int var1;   // expected-error {{multiple address spaces specified for type}} \
+  __attribute__((opencl_global)) __private int var1;   // expected-error {{multiple address spaces specified for type}} \
// expected-error {{function scope variable cannot be declared in global address space}}
   __private __attribute__((opencl_global)) int *var2;  // expected-error {{multiple address spaces specified for type}}
   __attribute__((opencl_global)) private_int_t var3;   // expected-error {{multiple address spaces specified for type}}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -368,7 +368,8 @@
 };
 
 static void processTypeAttrs(TypeProcessingState &state, QualType &type,
- TypeAttrLocation TAL, ParsedAttributesView &attrs);
+ TypeAttrLocation TAL,
+ const ParsedAttributesView &attrs);
 
 static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
QualType &type);
@@ -8149,7 +8150,12 @@
 
 static void processTypeAttrs(TypeProcessingState &state, QualType &type,
  TypeAttrLocation TAL,
- ParsedAttributesView &attrs) {
+ const ParsedAttributesView &attrs) {
+
+  state.setParsedNoDeref(false);
+  if (attrs.empty())
+return;
+
   // Scan through and apply attributes to this type where it makes sense.  Some
   // attributes (such as __address_space__, __vector_size__, etc) apply to the
   // type, but others can be present in the type specifiers even though they
@@ -8159,9 +8165,6 @@
   // sure we visit every element once. Copy the attributes list, and iterate
   // over that.
   ParsedAttributesView AttrsCopy{attrs};
-
-  state.setParsedNoDeref(false);
-
   for (ParsedAttr &attr : AttrsCopy) {
 
 // Skip attributes that were marked to be invalid.
Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -495,8 +495,7 @@
   }
 }
 
-void Sema::ProcessStmtAttributes(Stmt *S,
- const ParsedAttributesWithRange &InAttrs,
+void Sema::ProcessStmtAttributes(Stmt *S, const ParsedAttributes &InAttrs,
  SmallVectorImpl &OutAttrs) {
   for (const ParsedAttr &AL : InAttrs) {
 if (const Attr *A = ProcessStmtAttribute(*this, S, AL, InAttrs.Range))
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -587,7 +587,7 @@
   return AttributedStmt::Create(Context, AttrsLoc, Attrs, SubStmt);
 }
 
-StmtResult Sema::ActOnAttributedStmt(const ParsedAttributesWithRange &Attrs,
+StmtResult Sema::ActOnAttributedStmt(const ParsedAttributes &Attrs,
  Stmt *SubStmt) {
   SmallVector SemanticAttrs;
   ProcessStmtAttributes(SubStmt, Attrs, SemanticAttrs);
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -2641,12 +2641,11 @@
 /// example:
 ///class foo : public bar, virtual private baz {
 /// 'public bar' and 'virtual private baz' are each

[clang] 711e3a5 - [clang][parse] Move source range into ParsedAttibutesView

2022-03-24 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-03-24T08:11:57+01:00
New Revision: 711e3a569167ee6f3fbccf983933d92cd03a469b

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

LOG: [clang][parse] Move source range into ParsedAttibutesView

Move the SourceRange from the old ParsedAttributesWithRange into
ParsedAttributesView, so we have source range information available
everywhere we use attributes.

This also removes ParsedAttributesWithRange (replaced by simply using
ParsedAttributes) and ParsedAttributesVieWithRange (replaced by using
ParsedAttributesView).

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

Added: 


Modified: 
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/DeclSpec.h
clang/include/clang/Sema/ParsedAttr.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Parse/ParseObjc.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Parse/ParsePragma.cpp
clang/lib/Parse/ParseStmt.cpp
clang/lib/Parse/ParseTemplate.cpp
clang/lib/Parse/ParseTentative.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaStmtAttr.cpp
clang/lib/Sema/SemaType.cpp
clang/test/SemaOpenCL/address-spaces.cl

Removed: 




diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index a3c1a15d333ce..1af53a151f8c9 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1544,7 +1544,7 @@ class Parser : public CodeCompletionHandler {
   };
 
   NamedDecl *ParseCXXInlineMethodDef(AccessSpecifier AS,
- ParsedAttributes &AccessAttrs,
+ const ParsedAttributesView &AccessAttrs,
  ParsingDeclarator &D,
  const ParsedTemplateInfo &TemplateInfo,
  const VirtSpecifiers &VS,
@@ -1580,15 +1580,15 @@ class Parser : public CodeCompletionHandler {
 
   
//======//
   // C99 6.9: External Definitions.
-  DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
+  DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributes &Attrs,
   ParsingDeclSpec *DS = nullptr);
   bool isDeclarationAfterDeclarator();
   bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator);
-  DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(
-  ParsedAttributesWithRange 
&attrs,
-  ParsingDeclSpec *DS = 
nullptr,
-  AccessSpecifier AS = 
AS_none);
-  DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange 
&attrs,
+  DeclGroupPtrTy
+  ParseDeclarationOrFunctionDefinition(ParsedAttributes &Attrs,
+   ParsingDeclSpec *DS = nullptr,
+   AccessSpecifier AS = AS_none);
+  DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributes &Attrs,
 ParsingDeclSpec &DS,
 AccessSpecifier AS);
 
@@ -1603,7 +1603,7 @@ class Parser : public CodeCompletionHandler {
 
   // Objective-C External Declarations
   void MaybeSkipAttributes(tok::ObjCKeywordKind Kind);
-  DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributesWithRange &Attrs);
+  DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &Attrs);
   DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
   Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
 ParsedAttributes &prefixAttrs);
@@ -1984,9 +1984,8 @@ class Parser : public CodeCompletionHandler {
   bool MissingOK,
   ForRangeInfo *FRI = nullptr,
   bool EnterForConditionScope = false);
-  DeclGroupPtrTy
-  ParseAliasDeclarationInInitStatement(DeclaratorContext Context,
-   ParsedAttributesWithRange &Attrs);
+  DeclGroupPtrTy ParseAliasDeclarationInInitStatement(DeclaratorContext 
Context,
+  ParsedAttributes &Attrs);
 
   
//======//
   // C++ Coroutines
@@ -2066,12 +2065,10 @@ class Parser : public CodeCompletionHandler {
   StmtVe

[clang] 48285c2 - [NFCI] Fix set-but-unused warning in ClangAttrEmitter.cpp

2022-03-24 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-24T08:13:28+01:00
New Revision: 48285c20eb5f5ed4f7b539fbd7f882c997a08f46

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

LOG: [NFCI] Fix set-but-unused warning in ClangAttrEmitter.cpp

Added: 


Modified: 
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 47c06cdd147cb..b77554cbb6d39 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1522,12 +1522,10 @@ writePrettyPrintFunction(const Record &R,
   // To avoid printing parentheses around an empty argument list or
   // printing spurious commas at the end of an argument list, we need to
   // determine where the last provided non-fake argument is.
-  unsigned NonFakeArgs = 0;
   bool FoundNonOptArg = false;
   for (const auto &arg : llvm::reverse(Args)) {
 if (arg->isFake())
   continue;
-++NonFakeArgs;
 if (FoundNonOptArg)
   continue;
 // FIXME: arg->getIsOmitted() == "false" means we haven't implemented



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


[PATCH] D121584: [clang-format] Correctly recognize arrays in template parameter list.

2022-03-24 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

> It appears that this regressed some ObjC patterns:

@curdeius any progress on this? If not, could we revert this for now? 
Internally we've got enough of these regressing ObjC patterns that we can't 
release clang-format with this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121584

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


[PATCH] D121584: [clang-format] Correctly recognize arrays in template parameter list.

2022-03-24 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

Yes, let's revert this. I should have a fix soon though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121584

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


[clang] 67d9276 - [clang-cl] Ignore /Wv and /Wv:17 flags

2022-03-24 Thread Tobias Hieta via cfe-commits

Author: Tobias Hieta
Date: 2022-03-24T09:42:34+01:00
New Revision: 67d9276b16024bae66dfc2fcb739d947637b8c52

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

LOG: [clang-cl] Ignore /Wv and /Wv:17 flags

MSVC supports passing /Wv and /Wv:17 to ignore warnings added
since that version. Clang doesn't have a option like this - but
we can ignore this flag instead of error.

MSVC documentation: 
https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level

Reviewed By: hans, mstorsjo

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/cl-options.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b5bd2d6c3e1bd..114b230b39e8f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6530,6 +6530,7 @@ def _SLASH_sdl_ : CLIgnoredFlag<"sdl-">;
 def _SLASH_utf8 : CLIgnoredFlag<"utf-8">,
   HelpText<"Set source and runtime encoding to UTF-8 (default)">;
 def _SLASH_w : CLIgnoredJoined<"w">;
+def _SLASH_Wv_ : CLIgnoredJoined<"Wv">;
 def _SLASH_Zc___cplusplus : CLIgnoredFlag<"Zc:__cplusplus">;
 def _SLASH_Zc_auto : CLIgnoredFlag<"Zc:auto">;
 def _SLASH_Zc_forScope : CLIgnoredFlag<"Zc:forScope">;

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index f332cd83b26e4..244b4430dd0dc 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -396,6 +396,8 @@
 // RUN:/volatile:iso \
 // RUN:/w12345 \
 // RUN:/wd1234 \
+// RUN:/Wv \
+// RUN:/Wv:17 \
 // RUN:/Zc:__cplusplus \
 // RUN:/Zc:auto \
 // RUN:/Zc:forScope \



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


[PATCH] D122298: [clang-cl] Ignore /Wv and /Wv:17 flags

2022-03-24 Thread Tobias Hieta via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG67d9276b1602: [clang-cl] Ignore /Wv and /Wv:17 flags 
(authored by thieta).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122298

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/cl-options.c


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -396,6 +396,8 @@
 // RUN:/volatile:iso \
 // RUN:/w12345 \
 // RUN:/wd1234 \
+// RUN:/Wv \
+// RUN:/Wv:17 \
 // RUN:/Zc:__cplusplus \
 // RUN:/Zc:auto \
 // RUN:/Zc:forScope \
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -6530,6 +6530,7 @@
 def _SLASH_utf8 : CLIgnoredFlag<"utf-8">,
   HelpText<"Set source and runtime encoding to UTF-8 (default)">;
 def _SLASH_w : CLIgnoredJoined<"w">;
+def _SLASH_Wv_ : CLIgnoredJoined<"Wv">;
 def _SLASH_Zc___cplusplus : CLIgnoredFlag<"Zc:__cplusplus">;
 def _SLASH_Zc_auto : CLIgnoredFlag<"Zc:auto">;
 def _SLASH_Zc_forScope : CLIgnoredFlag<"Zc:forScope">;


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -396,6 +396,8 @@
 // RUN:/volatile:iso \
 // RUN:/w12345 \
 // RUN:/wd1234 \
+// RUN:/Wv \
+// RUN:/Wv:17 \
 // RUN:/Zc:__cplusplus \
 // RUN:/Zc:auto \
 // RUN:/Zc:forScope \
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -6530,6 +6530,7 @@
 def _SLASH_utf8 : CLIgnoredFlag<"utf-8">,
   HelpText<"Set source and runtime encoding to UTF-8 (default)">;
 def _SLASH_w : CLIgnoredJoined<"w">;
+def _SLASH_Wv_ : CLIgnoredJoined<"Wv">;
 def _SLASH_Zc___cplusplus : CLIgnoredFlag<"Zc:__cplusplus">;
 def _SLASH_Zc_auto : CLIgnoredFlag<"Zc:auto">;
 def _SLASH_Zc_forScope : CLIgnoredFlag<"Zc:forScope">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121368: [pseudo][WIP] Build Ambiguous forest node in the GLR Parser.

2022-03-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Some notes before our meeting.

It does appear that it's possible to generate duplicate forest nodes in this 
way, and AFAIK any method other that explicitly deduplicating creating using a 
map<(rule, rhsnodes), sequencenode> is going to have this problem.
The good news is:

- the cache lifetime is local to the family (outer batch), collisions 
necessarily happen within a family (outer batch). (We can make it a member and 
clear it, to reuse storage)
- I think we can form the forest nodes at the bottom of the 
enumerateReducePaths() call, and use them + base GSS node in place of the 
reduce path. (we never actually used internal gss path nodes, just the forest 
nodes + GSS base).
- Now reductions found by enumerateReducePaths() is identified by (base, 
sequence node, new state) which are cheap to compare/group in various ways

I feel like this should simplify subsequent steps, but need to think more


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121368

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


[PATCH] D122244: [analyzer] Turn missing tablegen doc entry of a checker into fatal error

2022-03-24 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

LGTM! You did check whether a missing doc field will actually trigger this 
error, right?




Comment at: clang/utils/TableGen/ClangSACheckersEmitter.cpp:82
+PrintFatalError(R.getLoc(),
+"missing Documentation for " + getCheckerFullName(&R));
+

We might as well give an extra hand, and state that a `Documentation<> field` 
is missing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122244

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


[clang] d00e840 - [Clang] Add option to set alternative toolchain path

2022-03-24 Thread Qiu Chaofan via cfe-commits

Author: Qiu Chaofan
Date: 2022-03-24T17:01:35+08:00
New Revision: d00e8400e2e3a602fdf40cd7348ed113952261d3

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

LOG: [Clang] Add option to set alternative toolchain path

In some cases, we need to set alternative toolchain path other than the
default with system (headers, libraries, dynamic linker prefix, ld path,
etc.), e.g., to pick up newer components, but keep sysroot at the same
time (to pick up extra packages).

This change introduces a new option --overlay-platform-toolchain to set
up such alternative toolchain path.

Reviewed By: hubert.reinterpretcast

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

Added: 
clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0/include/.keep
clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0/lib64/.keep
clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-8.3.0/include/.keep

clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-8.3.0/lib/gcc/powerpc64le-linux-gnu/8.3.0/.keep
clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-8.3.0/lib64/.keep
clang/test/Driver/overlay-toolchain.cpp

Modified: 
clang/docs/ClangCommandLineReference.rst
clang/include/clang/Driver/Driver.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Linux.cpp

Removed: 




diff  --git a/clang/docs/ClangCommandLineReference.rst 
b/clang/docs/ClangCommandLineReference.rst
index 9d097ccae6aab..d226ab75b3288 100644
--- a/clang/docs/ClangCommandLineReference.rst
+++ b/clang/docs/ClangCommandLineReference.rst
@@ -515,6 +515,10 @@ CUDA offloading device architecture (e.g. sm\_35), or HIP 
offloading target ID i
 
 Specify comma-separated list of offloading target triples (CUDA and HIP only)
 
+.. option:: --overlay-platform-toolchain=
+
+Specify a toolchain with higher priority than sysroot in search paths.
+
 .. option:: -p, --profile
 
 .. option:: -pagezero\_size

diff  --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 6f24f649ea544..50aa7bea8f6d5 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -149,6 +149,9 @@ class Driver {
   typedef SmallVector prefix_list;
   prefix_list PrefixDirs;
 
+  /// Alternative toolchain path used prior to sysroot.
+  std::string OverlayToolChainPath;
+
   /// sysroot, if present
   std::string SysRoot;
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 114b230b39e8f..c63c02bb8941a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4180,6 +4180,8 @@ def _output_class_directory_EQ : Joined<["--"], 
"output-class-directory=">, Alia
 def _output_class_directory : Separate<["--"], "output-class-directory">, 
Alias;
 def _output_EQ : Joined<["--"], "output=">, Alias;
 def _output : Separate<["--"], "output">, Alias;
+def _overlay_platform_toolchain_EQ : Joined<["--"], 
"overlay-platform-toolchain=">;
+def _overlay_platform_toolchain : Separate<["--"], 
"overlay-platform-toolchain">, Alias<_overlay_platform_toolchain_EQ>;
 def _param : Separate<["--"], "param">, Group;
 def _param_EQ : Joined<["--"], "param=">, Alias<_param>;
 def _precompile : Flag<["--"], "precompile">, Flags<[NoXarchOption]>,

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 44a89e9e26ee1..31ef07cd5acc6 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1208,6 +1208,11 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   CompilerPath = Split.second;
 }
   }
+  if (const Arg *A =
+  Args.getLastArg(options::OPT__overlay_platform_toolchain_EQ)) {
+OverlayToolChainPath = A->getValue();
+DyldPrefix = A->getValue();
+  }
   if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ))
 SysRoot = A->getValue();
   if (const Arg *A = Args.getLastArg(options::OPT__dyld_prefix_EQ))

diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index bb3cba6dc4f77..7164f42170a8c 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1867,6 +1867,10 @@ static llvm::StringRef getGCCToolchainDir(const ArgList 
&Args,
   if (A)
 return A->getValue();
 
+  if (const Arg *X = Args.getLastArg(
+  clang::driver::options::OPT__overlay_platform_toolchain_EQ))
+return X->getValue();
+
   // If we have a SysRoot, ignore GCC_INSTALL_PREFIX.
   // GCC_INSTALL_PREFIX specifies the gcc installation for the default
   // sysroot and is likely not valid with a 
diff erent sysroot.

diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/

[PATCH] D121992: [Clang] [Driver] Add option to set alternative toolchain path

2022-03-24 Thread Qiu Chaofan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd00e8400e2e3: [Clang] Add option to set alternative 
toolchain path (authored by qiucf).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121992

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Driver/Driver.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0/include/.keep
  clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0/lib64/.keep
  clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-8.3.0/include/.keep
  
clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-8.3.0/lib/gcc/powerpc64le-linux-gnu/8.3.0/.keep
  clang/test/Driver/Inputs/powerpc64le-linux-gnu-tree/gcc-8.3.0/lib64/.keep
  clang/test/Driver/overlay-toolchain.cpp

Index: clang/test/Driver/overlay-toolchain.cpp
===
--- /dev/null
+++ clang/test/Driver/overlay-toolchain.cpp
@@ -0,0 +1,18 @@
+// RUN: %clangxx %s -### --target=powerpc64le-linux-gnu \
+// RUN:   --overlay-platform-toolchain=%S/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0 \
+// RUN:   2>&1 | FileCheck %s --check-prefix=OVERLAY
+// RUN: %clangxx %s -### --target=powerpc64le-linux-gnu \
+// RUN:   --sysroot=%S/Inputs/powerpc64le-linux-gnu-tree/gcc-8.3.0 \
+// RUN:   --overlay-platform-toolchain=%S/Inputs/powerpc64le-linux-gnu-tree/gcc-11.2.0 \
+// RUN:   2>&1 | FileCheck %s --check-prefixes=OVERLAY,ROOT
+
+// OVERLAY: "-internal-externc-isystem"
+// OVERLAY: "[[TOOLCHAIN:[^"]+]]/powerpc64le-linux-gnu-tree/gcc-11.2.0/include"
+// ROOT: "-internal-externc-isystem"
+// ROOT: "[[TOOLCHAIN]]/powerpc64le-linux-gnu-tree/gcc-8.3.0/include"
+// OVERLAY: "-dynamic-linker"
+// OVERLAY: "[[TOOLCHAIN]]/powerpc64le-linux-gnu-tree/gcc-11.2.0/lib64/ld64.so.2"
+// OVERLAY: "-L[[TOOLCHAIN]]/powerpc64le-linux-gnu-tree/gcc-11.2.0/lib/../lib64"
+// ROOT: "-L[[TOOLCHAIN]]/powerpc64le-linux-gnu-tree/gcc-8.3.0/lib/../lib64"
+// OVERLAY: "-L[[TOOLCHAIN]]/powerpc64le-linux-gnu-tree/gcc-11.2.0/lib"
+// ROOT: "-L[[TOOLCHAIN]]/powerpc64le-linux-gnu-tree/gcc-8.3.0/lib"
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -260,6 +260,14 @@
 
   const std::string OSLibDir = std::string(getOSLibDir(Triple, Args));
   const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot);
+  const std::string &ExtraPath = D.OverlayToolChainPath;
+
+  if (!D.OverlayToolChainPath.empty()) {
+addPathIfExists(D, ExtraPath + "/lib/" + MultiarchTriple, Paths);
+addPathIfExists(D, ExtraPath + "/lib/../" + OSLibDir, Paths);
+addPathIfExists(D, ExtraPath + "/usr/lib/" + MultiarchTriple, Paths);
+addPathIfExists(D, ExtraPath + "/usr/lib/../" + OSLibDir, Paths);
+  }
 
   // mips32: Debian multilib, we use /libo32, while in other case, /lib is
   // used. We need add both libo32 and /lib.
@@ -314,6 +322,11 @@
   addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
   }
 
+  if (!D.OverlayToolChainPath.empty()) {
+addPathIfExists(D, ExtraPath + "/lib", Paths);
+addPathIfExists(D, ExtraPath + "/usr/lib", Paths);
+  }
+
   addPathIfExists(D, SysRoot + "/lib", Paths);
   addPathIfExists(D, SysRoot + "/usr/lib", Paths);
 }
@@ -567,6 +580,10 @@
   if (DriverArgs.hasArg(options::OPT_nostdlibinc))
 return;
 
+  if (!D.OverlayToolChainPath.empty())
+addExternCSystemInclude(DriverArgs, CC1Args,
+D.OverlayToolChainPath + "/include");
+
   // LOCAL_INCLUDE_DIR
   addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include");
   // TOOL_INCLUDE_DIR
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1867,6 +1867,10 @@
   if (A)
 return A->getValue();
 
+  if (const Arg *X = Args.getLastArg(
+  clang::driver::options::OPT__overlay_platform_toolchain_EQ))
+return X->getValue();
+
   // If we have a SysRoot, ignore GCC_INSTALL_PREFIX.
   // GCC_INSTALL_PREFIX specifies the gcc installation for the default
   // sysroot and is likely not valid with a different sysroot.
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1208,6 +1208,11 @@
   CompilerPath = Split.second;
 }
   }
+  if (const Arg *A =
+  Args.getLastArg(options::OPT__overlay_platform_toolchain_EQ)) {
+OverlayToolChainPath = A->getValue();
+DyldPrefix = A->getValue();
+  }
   if (const Arg *A = Args.getLastArg(options::OPT__sys

[PATCH] D122335: [clang] Emit crash reproduction as a single tar file

2022-03-24 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.

In D122335#3404358 , @jrtc27 wrote:

> As a developer who often deals with crashes locally this is more annoying; 
> currently I can just point tools at the shell script and C file in /tmp and 
> let them go to work reducing, but now I have to also extract the files

+1.

I can see this being helpful for end-users who now just have to provide 
developers with a single file, but it does make things more awkward for me as a 
developer. How about an environment variable and/or a CMake option to skip 
archiving that can be used locally.


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

https://reviews.llvm.org/D122335

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


[clang] be5c3ca - Revert "[clang-format] Correctly recognize arrays in template parameter list."

2022-03-24 Thread Krasimir Georgiev via cfe-commits

Author: Krasimir Georgiev
Date: 2022-03-24T10:14:13+01:00
New Revision: be5c3ca7fbaec90fff004af54d3cd5f6c30a9664

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

LOG: Revert "[clang-format] Correctly recognize arrays in template parameter 
list."

This reverts commit 126b37a713dc1c67cbc7dc8b5288b2f907c906a9.

Regressed some ObjC patterns, see comments on https://reviews.llvm.org/D121584.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index b8cffcd471e91..c5594a6d66484 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1940,11 +1940,6 @@ bool UnwrappedLineParser::tryToParseLambda() {
   if (!tryToParseLambdaIntroducer())
 return false;
 
-  // `[something] >` is not a lambda, but an array type in a template parameter
-  // list.
-  if (FormatTok->is(tok::greater))
-return false;
-
   bool SeenArrow = false;
   bool InTemplateParameterList = false;
 
@@ -3534,7 +3529,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   // Don't try parsing a lambda if we had a closing parenthesis before,
   // it was probably a pointer to an array: int (*)[].
   if (!tryToParseLambda())
-continue;
+break;
 } else {
   parseSquare();
   continue;

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index ac0802f837173..380ec90330f12 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -98,20 +98,6 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
   auto Tokens = annotate("struct S {};");
   EXPECT_EQ(Tokens.size(), 6u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_StructLBrace);
-
-  Tokens = annotate("template  struct S {};");
-  EXPECT_EQ(Tokens.size(), 18u) << Tokens;
-  EXPECT_TOKEN(Tokens[7], tok::less, TT_TemplateOpener);
-  EXPECT_TOKEN(Tokens[10], tok::l_square, TT_ArraySubscriptLSquare);
-  EXPECT_TOKEN(Tokens[13], tok::greater, TT_TemplateCloser);
-  EXPECT_TOKEN(Tokens[14], tok::l_brace, TT_StructLBrace);
-
-  Tokens = annotate("template  struct S {};");
-  EXPECT_EQ(Tokens.size(), 18u) << Tokens;
-  EXPECT_TOKEN(Tokens[7], tok::less, TT_TemplateOpener);
-  EXPECT_TOKEN(Tokens[10], tok::l_square, TT_ArraySubscriptLSquare);
-  EXPECT_TOKEN(Tokens[13], tok::greater, TT_TemplateCloser);
-  EXPECT_TOKEN(Tokens[14], tok::l_brace, TT_StructLBrace);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUnions) {



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


[PATCH] D100581: [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable

2022-03-24 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

In D100581#3404624 , @xbolva00 wrote:

> @mbenfield found false positive
>
>   void test(void) {
> static int counter = 0;
> counter += 5;
>   }

posted https://reviews.llvm.org/D122374


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100581

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


[clang] f854434 - [NVPTX] Enhance vectorization of ld.param & st.param

2022-03-24 Thread Daniil Kovalev via cfe-commits

Author: Daniil Kovalev
Date: 2022-03-24T12:25:36+03:00
New Revision: f854434f0f2a01027bdaad8e6fdac5a782fce291

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

LOG: [NVPTX] Enhance vectorization of ld.param & st.param

Since function parameters and return values are passed via param space, we
can force special alignment for values hold in it which will add vectorization
options. This change may be done if the function has private or internal
linkage. Special alignment is forced during 2 phases.

1) Instruction selection lowering. Here we use special alignment for function
   prototypes (changing both own return value and parameters alignment), call
   lowering (changing both callee's return value and parameters alignment).

2) IR pass nvptx-lower-args. Here we change alignment of byval parameters that
   belong to param space (or are casted to it). We only handle cases when all
   uses of such parameters are loads from it. For such loads, we can change the
   alignment according to special type alignment and the load offset. Then,
   load-store-vectorizer IR pass will perform vectorization where alignment
   allows it.

Special alignment calculated as maximum from default ABI type alignment and
alignment 16. Alignment 16 is chosen because it's the maximum size of
vectorized ld.param & st.param.

Before specifying such special alignment, we should check if it is a multiple
of the alignment that the type already has. For example, if a value has an
enforced alignment of 64, default ABI alignment of 4 and special alignment
of 16, we should preserve 64.

This patch will be followed by a refactoring patch that removes duplicating
code in handling byval and non-byval arguments.

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

Added: 
llvm/test/CodeGen/NVPTX/param-vectorize-device.ll
llvm/test/CodeGen/NVPTX/param-vectorize-kernel.ll

Modified: 
clang/test/CodeGenCUDA/device-fun-linkage.cu
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
llvm/lib/Target/NVPTX/NVPTXISelLowering.h
llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp

Removed: 




diff  --git a/clang/test/CodeGenCUDA/device-fun-linkage.cu 
b/clang/test/CodeGenCUDA/device-fun-linkage.cu
index d1b9db261151b..d8ad6d438be9c 100644
--- a/clang/test/CodeGenCUDA/device-fun-linkage.cu
+++ b/clang/test/CodeGenCUDA/device-fun-linkage.cu
@@ -1,19 +1,32 @@
-// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
-// RUN:   -emit-llvm -o - %s \
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -emit-llvm -o - %s \
 // RUN:   | FileCheck -check-prefix=NORDC %s
-// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
-// RUN:   -fgpu-rdc -emit-llvm -o - %s \
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -emit-llvm -o - %s \
+// RUN:   | FileCheck -check-prefix=NORDC-NEG %s
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -fgpu-rdc -emit-llvm -o - %s 
\
 // RUN:   | FileCheck -check-prefix=RDC %s
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -fgpu-rdc -emit-llvm -o - %s 
\
+// RUN:   | FileCheck -check-prefix=RDC-NEG %s
 
 #include "Inputs/cuda.h"
 
-// NORDC: define internal void @_Z4funcIiEvv()
-// NORDC: define{{.*}} void @_Z6kernelIiEvv()
-// RDC: define weak_odr void @_Z4funcIiEvv()
-// RDC: define weak_odr void @_Z6kernelIiEvv()
-
 template  __device__ void func() {}
 template  __global__ void kernel() {}
 
 template __device__ void func();
+// NORDC: define internal void @_Z4funcIiEvv()
+// RDC:   define weak_odr void @_Z4funcIiEvv()
+
 template __global__ void kernel();
+// NORDC: define void @_Z6kernelIiEvv()
+// RDC:   define weak_odr void @_Z6kernelIiEvv()
+
+// Ensure that unused static device function is eliminated
+static __device__ void static_func() {}
+// NORDC-NEG-NOT: define{{.*}} void @_ZL13static_funcv()
+// RDC-NEG-NOT:   define{{.*}} void @_ZL13static_funcv()
+
+// Ensure that kernel function has external or weak_odr
+// linkage regardless static specifier
+static __global__ void static_kernel() {}
+// NORDC: define void @_ZL13static_kernelv()
+// RDC:   define weak_odr void @_ZL13static_kernelv()

diff  --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp 
b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index 2516dff52efdf..e8322a0a8425b 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -329,7 +329,7 @@ MCOperand NVPTXAsmPrinter::GetSymbolRef(const MCSymbol 
*Symbol) {
 void NVPTXAsmPrinter::printReturnValStr(const Function *F, raw_ostream &O) {
   const DataLayout &DL = getDataLayout();
   const NVPTXSubtarget &STI = TM.getSubtarget(*F);
-  const TargetLowering *TLI = STI.getTargetLowering();
+  const auto *TLI = cast(STI.getTargetLowering());
 
   Type *Ty = F->getReturnType();
 
@@

[PATCH] D121549: Define ABI breaking class members correctly

2022-03-24 Thread Daniil Kovalev 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 rGf854434f0f2a: [NVPTX] Enhance vectorization of ld.param 
& st.param (authored by kovdan01).
Herald added subscribers: asavonic, StephenFan, jholewinski.
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D121549?vs=415049&id=417855#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121549

Files:
  clang/test/CodeGenCUDA/device-fun-linkage.cu
  llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
  llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
  llvm/lib/Target/NVPTX/NVPTXISelLowering.h
  llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
  llvm/test/CodeGen/NVPTX/param-vectorize-device.ll
  llvm/test/CodeGen/NVPTX/param-vectorize-kernel.ll

Index: llvm/test/CodeGen/NVPTX/param-vectorize-kernel.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/param-vectorize-kernel.ll
@@ -0,0 +1,456 @@
+; RUN: llc < %s -mtriple=nvptx-unknown-unknown | FileCheck %s
+;
+; Check that parameters of a __global__ (kernel) function do not get increased
+; alignment, and no additional vectorization is performed on loads/stores with
+; that parameters.
+;
+; Test IR is a minimized version of IR generated with the following command
+; from the source code below:
+; $ clang++ -O3 --cuda-gpu-arch=sm_35 -S -emit-llvm src.cu
+;
+; 
+; #include 
+;
+; struct St4x1 { uint32_t field[1]; };
+; struct St4x2 { uint32_t field[2]; };
+; struct St4x3 { uint32_t field[3]; };
+; struct St4x4 { uint32_t field[4]; };
+; struct St4x5 { uint32_t field[5]; };
+; struct St4x6 { uint32_t field[6]; };
+; struct St4x7 { uint32_t field[7]; };
+; struct St4x8 { uint32_t field[8]; };
+; struct St8x1 { uint64_t field[1]; };
+; struct St8x2 { uint64_t field[2]; };
+; struct St8x3 { uint64_t field[3]; };
+; struct St8x4 { uint64_t field[4]; };
+;
+; #define DECLARE_FUNCTION(StName)\
+; static __global__  __attribute__((noinline))\
+; void foo_##StName(struct StName in, struct StName* ret) {   \
+;   const unsigned size = sizeof(ret->field) / sizeof(*ret->field);   \
+;   for (unsigned i = 0; i != size; ++i)  \
+; ret->field[i] = in.field[i];\
+; }   \
+;
+; DECLARE_FUNCTION(St4x1)
+; DECLARE_FUNCTION(St4x2)
+; DECLARE_FUNCTION(St4x3)
+; DECLARE_FUNCTION(St4x4)
+; DECLARE_FUNCTION(St4x5)
+; DECLARE_FUNCTION(St4x6)
+; DECLARE_FUNCTION(St4x7)
+; DECLARE_FUNCTION(St4x8)
+; DECLARE_FUNCTION(St8x1)
+; DECLARE_FUNCTION(St8x2)
+; DECLARE_FUNCTION(St8x3)
+; DECLARE_FUNCTION(St8x4)
+; 
+
+%struct.St4x1 = type { [1 x i32] }
+%struct.St4x2 = type { [2 x i32] }
+%struct.St4x3 = type { [3 x i32] }
+%struct.St4x4 = type { [4 x i32] }
+%struct.St4x5 = type { [5 x i32] }
+%struct.St4x6 = type { [6 x i32] }
+%struct.St4x7 = type { [7 x i32] }
+%struct.St4x8 = type { [8 x i32] }
+%struct.St8x1 = type { [1 x i64] }
+%struct.St8x2 = type { [2 x i64] }
+%struct.St8x3 = type { [3 x i64] }
+%struct.St8x4 = type { [4 x i64] }
+
+define dso_local void @foo_St4x1(%struct.St4x1* nocapture noundef readonly byval(%struct.St4x1) align 4 %in, %struct.St4x1* nocapture noundef writeonly %ret) {
+  ; CHECK-LABEL: .visible .func foo_St4x1(
+  ; CHECK:   .param .align 4 .b8 foo_St4x1_param_0[4],
+  ; CHECK:   .param .b32 foo_St4x1_param_1
+  ; CHECK:   )
+  ; CHECK:   ld.param.u32 [[R1:%r[0-9]+]], [foo_St4x1_param_1];
+  ; CHECK:   ld.param.u32 [[R2:%r[0-9]+]], [foo_St4x1_param_0];
+  ; CHECK:   st.u32  [[[R1]]], [[R2]];
+  ; CHECK:   ret;
+  %arrayidx = getelementptr inbounds %struct.St4x1, %struct.St4x1* %in, i64 0, i32 0, i64 0
+  %1 = load i32, i32* %arrayidx, align 4
+  %arrayidx3 = getelementptr inbounds %struct.St4x1, %struct.St4x1* %ret, i64 0, i32 0, i64 0
+  store i32 %1, i32* %arrayidx3, align 4
+  ret void
+}
+
+define dso_local void @foo_St4x2(%struct.St4x2* nocapture noundef readonly byval(%struct.St4x2) align 4 %in, %struct.St4x2* nocapture noundef writeonly %ret) {
+  ; CHECK-LABEL: .visible .func foo_St4x2(
+  ; CHECK:   .param .align 4 .b8 foo_St4x2_param_0[8],
+  ; CHECK:   .param .b32 foo_St4x2_param_1
+  ; CHECK:   )
+  ; CHECK:   ld.param.u32 [[R1:%r[0-9]+]], [foo_St4x2_param_1];
+  ; CHECK:   ld.param.u32 [[R2:%r[0-9]+]], [foo_St4x2_param_0];
+  ; CHECK:   st.u32  [[[R1]]], [[R2]];
+  ; CHECK:   ld.param.u32 [[R3:%r[0-9]+]], [foo_St4x2_param_0+4];
+  ; CHECK:   st.u32  [[[R1]]+4], [[R3]];
+  ; CHECK:   ret;
+  %arrayidx = getelementp

[clang] a034878 - Revert "[NVPTX] Enhance vectorization of ld.param & st.param"

2022-03-24 Thread Daniil Kovalev via cfe-commits

Author: Daniil Kovalev
Date: 2022-03-24T12:32:06+03:00
New Revision: a0348785649271e8c63a42bd4a83a2fefa96efe0

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

LOG: Revert "[NVPTX] Enhance vectorization of ld.param & st.param"

This reverts commit f854434f0f2a01027bdaad8e6fdac5a782fce291.

Placed URL to wrong differential revision in commit message.

Added: 


Modified: 
clang/test/CodeGenCUDA/device-fun-linkage.cu
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
llvm/lib/Target/NVPTX/NVPTXISelLowering.h
llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp

Removed: 
llvm/test/CodeGen/NVPTX/param-vectorize-device.ll
llvm/test/CodeGen/NVPTX/param-vectorize-kernel.ll



diff  --git a/clang/test/CodeGenCUDA/device-fun-linkage.cu 
b/clang/test/CodeGenCUDA/device-fun-linkage.cu
index d8ad6d438be9c..d1b9db261151b 100644
--- a/clang/test/CodeGenCUDA/device-fun-linkage.cu
+++ b/clang/test/CodeGenCUDA/device-fun-linkage.cu
@@ -1,32 +1,19 @@
-// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -emit-llvm -o - %s \
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
+// RUN:   -emit-llvm -o - %s \
 // RUN:   | FileCheck -check-prefix=NORDC %s
-// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -emit-llvm -o - %s \
-// RUN:   | FileCheck -check-prefix=NORDC-NEG %s
-// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -fgpu-rdc -emit-llvm -o - %s 
\
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
+// RUN:   -fgpu-rdc -emit-llvm -o - %s \
 // RUN:   | FileCheck -check-prefix=RDC %s
-// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -fgpu-rdc -emit-llvm -o - %s 
\
-// RUN:   | FileCheck -check-prefix=RDC-NEG %s
 
 #include "Inputs/cuda.h"
 
+// NORDC: define internal void @_Z4funcIiEvv()
+// NORDC: define{{.*}} void @_Z6kernelIiEvv()
+// RDC: define weak_odr void @_Z4funcIiEvv()
+// RDC: define weak_odr void @_Z6kernelIiEvv()
+
 template  __device__ void func() {}
 template  __global__ void kernel() {}
 
 template __device__ void func();
-// NORDC: define internal void @_Z4funcIiEvv()
-// RDC:   define weak_odr void @_Z4funcIiEvv()
-
 template __global__ void kernel();
-// NORDC: define void @_Z6kernelIiEvv()
-// RDC:   define weak_odr void @_Z6kernelIiEvv()
-
-// Ensure that unused static device function is eliminated
-static __device__ void static_func() {}
-// NORDC-NEG-NOT: define{{.*}} void @_ZL13static_funcv()
-// RDC-NEG-NOT:   define{{.*}} void @_ZL13static_funcv()
-
-// Ensure that kernel function has external or weak_odr
-// linkage regardless static specifier
-static __global__ void static_kernel() {}
-// NORDC: define void @_ZL13static_kernelv()
-// RDC:   define weak_odr void @_ZL13static_kernelv()

diff  --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp 
b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index e8322a0a8425b..2516dff52efdf 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -329,7 +329,7 @@ MCOperand NVPTXAsmPrinter::GetSymbolRef(const MCSymbol 
*Symbol) {
 void NVPTXAsmPrinter::printReturnValStr(const Function *F, raw_ostream &O) {
   const DataLayout &DL = getDataLayout();
   const NVPTXSubtarget &STI = TM.getSubtarget(*F);
-  const auto *TLI = cast(STI.getTargetLowering());
+  const TargetLowering *TLI = STI.getTargetLowering();
 
   Type *Ty = F->getReturnType();
 
@@ -363,7 +363,7 @@ void NVPTXAsmPrinter::printReturnValStr(const Function *F, 
raw_ostream &O) {
   unsigned totalsz = DL.getTypeAllocSize(Ty);
   unsigned retAlignment = 0;
   if (!getAlign(*F, 0, retAlignment))
-retAlignment = TLI->getFunctionParamOptimizedAlign(F, Ty, DL).value();
+retAlignment = DL.getABITypeAlignment(Ty);
   O << ".param .align " << retAlignment << " .b8 func_retval0[" << totalsz
 << "]";
 } else
@@ -1348,8 +1348,7 @@ void NVPTXAsmPrinter::emitFunctionParamList(const 
Function *F, raw_ostream &O) {
   const DataLayout &DL = getDataLayout();
   const AttributeList &PAL = F->getAttributes();
   const NVPTXSubtarget &STI = TM.getSubtarget(*F);
-  const auto *TLI = cast(STI.getTargetLowering());
-
+  const TargetLowering *TLI = STI.getTargetLowering();
   Function::const_arg_iterator I, E;
   unsigned paramIndex = 0;
   bool first = true;
@@ -1406,24 +1405,18 @@ void NVPTXAsmPrinter::emitFunctionParamList(const 
Function *F, raw_ostream &O) {
   }
 }
 
-auto getOptimalAlignForParam = [TLI, &DL, &PAL, F,
-paramIndex](Type *Ty) -> Align {
-  Align TypeAlign = TLI->getFunctionParamOptimizedAlign(F, Ty, DL);
-  MaybeAlign ParamAlign = PAL.getParamAlignment(paramIndex);
-  return max(TypeAlign, ParamAlign);
-};
-
 if (!PAL.hasParamAttr(paramIndex, Attribute::By

[clang] 2af845a - Relands "[Clang] -Wunused-but-set-variable warning - handle also pre/post unary operators"

2022-03-24 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-24T10:34:44+01:00
New Revision: 2af845a6519c9cde5c8f58db5554f8b1084ce1ed

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

LOG: Relands "[Clang] -Wunused-but-set-variable warning - handle also pre/post 
unary operators"

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp
clang/test/Sema/warn-unused-but-set-parameters.c
clang/test/Sema/warn-unused-but-set-variables.c
clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 8873731cd3d3e..f360dc6e1a236 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -7921,6 +7921,7 @@ static void MaybeDecrementCount(
 Expr *E, llvm::DenseMap &RefsMinusAssignments) {
   DeclRefExpr *LHS = nullptr;
   bool IsCompoundAssign = false;
+  bool isIncrementDecrementUnaryOp = false;
   if (BinaryOperator *BO = dyn_cast(E)) {
 if (BO->getLHS()->getType()->isDependentType() ||
 BO->getRHS()->getType()->isDependentType()) {
@@ -7935,6 +7936,11 @@ static void MaybeDecrementCount(
 if (COCE->getOperator() != OO_Equal)
   return;
 LHS = dyn_cast(COCE->getArg(0));
+  } else if (UnaryOperator *UO = dyn_cast(E)) {
+if (!UO->isIncrementDecrementOp())
+  return;
+isIncrementDecrementUnaryOp = true;
+LHS = dyn_cast(UO->getSubExpr());
   }
   if (!LHS)
 return;
@@ -7942,8 +7948,10 @@ static void MaybeDecrementCount(
   if (!VD)
 return;
   // Don't decrement RefsMinusAssignments if volatile variable with compound
-  // assignment (+=, ...) to avoid potential unused-but-set-variable warning.
-  if (IsCompoundAssign && VD->getType().isVolatileQualified())
+  // assignment (+=, ...) or increment/decrement unary operator to avoid
+  // potential unused-but-set-variable warning.
+  if ((IsCompoundAssign || isIncrementDecrementUnaryOp) &&
+  VD->getType().isVolatileQualified())
 return;
   auto iter = RefsMinusAssignments.find(VD);
   if (iter == RefsMinusAssignments.end())

diff  --git a/clang/test/Sema/warn-unused-but-set-parameters.c 
b/clang/test/Sema/warn-unused-but-set-parameters.c
index 4f000617cfcc4..f1563ab50c1fb 100644
--- a/clang/test/Sema/warn-unused-but-set-parameters.c
+++ b/clang/test/Sema/warn-unused-but-set-parameters.c
@@ -25,10 +25,10 @@ void f3(struct S s) { // expected-warning{{parameter 's' 
set but not used}}
   s = t;
 }
 
-void f4(int j) { //TODO: warn
+void f4(int j) { // expected-warning{{parameter 'j' set but not used}}
 j++;
 }
 
-void f5(int k) { //TODO: warn
+void f5(int k) { // expected-warning{{parameter 'k' set but not used}}
 --k;
 }

diff  --git a/clang/test/Sema/warn-unused-but-set-variables.c 
b/clang/test/Sema/warn-unused-but-set-variables.c
index 6e5b7d671711b..a390944815a9a 100644
--- a/clang/test/Sema/warn-unused-but-set-variables.c
+++ b/clang/test/Sema/warn-unused-but-set-variables.c
@@ -73,3 +73,23 @@ void f3(void) {
   __attribute__((__cleanup__(for_cleanup))) int x;
   x = 5;
 }
+
+void f4(void) {
+  int x1 = 0; // expected-warning{{variable 'x1' set but not used}}
+  x1++;
+  int x2 = 0; // expected-warning{{variable 'x2' set but not used}}
+  x2--;
+  int x3 = 0; // expected-warning{{variable 'x3' set but not used}}
+  ++x3;
+  int x4 = 0; // expected-warning{{variable 'x4' set but not used}}
+  --x4;
+
+  static int counter = 0; // expected-warning{{variable 'counter' set but not 
used}}
+  counter += 1;
+
+  volatile int v1 = 0;
+  ++v1;
+  typedef volatile int volint;
+  volint v2 = 0;
+  v2++;
+}

diff  --git a/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp 
b/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
index 400e9d7681b31..418baa78aa964 100644
--- a/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
+++ b/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
@@ -7,6 +7,7 @@ struct S {
 struct __attribute__((warn_unused)) SWarnUnused {
   int j;
   void operator +=(int);
+  void operator ++();
 };
 
 int f0() {
@@ -62,3 +63,9 @@ template void f4(T n) {
   SWarnUnused swu;
   swu += n;
 }
+
+template  void f5() {
+  // Don't warn for overloaded pre/post operators in template code.
+  SWarnUnused swu;
+  ++swu;
+}



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


[clang] 828b63c - [NVPTX] Enhance vectorization of ld.param & st.param

2022-03-24 Thread Daniil Kovalev via cfe-commits

Author: Daniil Kovalev
Date: 2022-03-24T12:36:52+03:00
New Revision: 828b63c309439d3b0915205f1e5a159c69cb36b8

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

LOG: [NVPTX] Enhance vectorization of ld.param & st.param

Since function parameters and return values are passed via param space, we
can force special alignment for values hold in it which will add vectorization
options. This change may be done if the function has private or internal
linkage. Special alignment is forced during 2 phases.

1) Instruction selection lowering. Here we use special alignment for function
   prototypes (changing both own return value and parameters alignment), call
   lowering (changing both callee's return value and parameters alignment).

2) IR pass nvptx-lower-args. Here we change alignment of byval parameters that
   belong to param space (or are casted to it). We only handle cases when all
   uses of such parameters are loads from it. For such loads, we can change the
   alignment according to special type alignment and the load offset. Then,
   load-store-vectorizer IR pass will perform vectorization where alignment
   allows it.

Special alignment calculated as maximum from default ABI type alignment and
alignment 16. Alignment 16 is chosen because it's the maximum size of
vectorized ld.param & st.param.

Before specifying such special alignment, we should check if it is a multiple
of the alignment that the type already has. For example, if a value has an
enforced alignment of 64, default ABI alignment of 4 and special alignment
of 16, we should preserve 64.

This patch will be followed by a refactoring patch that removes duplicating
code in handling byval and non-byval arguments.

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

Added: 
llvm/test/CodeGen/NVPTX/param-vectorize-device.ll
llvm/test/CodeGen/NVPTX/param-vectorize-kernel.ll

Modified: 
clang/test/CodeGenCUDA/device-fun-linkage.cu
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
llvm/lib/Target/NVPTX/NVPTXISelLowering.h
llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp

Removed: 




diff  --git a/clang/test/CodeGenCUDA/device-fun-linkage.cu 
b/clang/test/CodeGenCUDA/device-fun-linkage.cu
index d1b9db261151b..d8ad6d438be9c 100644
--- a/clang/test/CodeGenCUDA/device-fun-linkage.cu
+++ b/clang/test/CodeGenCUDA/device-fun-linkage.cu
@@ -1,19 +1,32 @@
-// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
-// RUN:   -emit-llvm -o - %s \
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -emit-llvm -o - %s \
 // RUN:   | FileCheck -check-prefix=NORDC %s
-// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
-// RUN:   -fgpu-rdc -emit-llvm -o - %s \
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -emit-llvm -o - %s \
+// RUN:   | FileCheck -check-prefix=NORDC-NEG %s
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -fgpu-rdc -emit-llvm -o - %s 
\
 // RUN:   | FileCheck -check-prefix=RDC %s
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -fgpu-rdc -emit-llvm -o - %s 
\
+// RUN:   | FileCheck -check-prefix=RDC-NEG %s
 
 #include "Inputs/cuda.h"
 
-// NORDC: define internal void @_Z4funcIiEvv()
-// NORDC: define{{.*}} void @_Z6kernelIiEvv()
-// RDC: define weak_odr void @_Z4funcIiEvv()
-// RDC: define weak_odr void @_Z6kernelIiEvv()
-
 template  __device__ void func() {}
 template  __global__ void kernel() {}
 
 template __device__ void func();
+// NORDC: define internal void @_Z4funcIiEvv()
+// RDC:   define weak_odr void @_Z4funcIiEvv()
+
 template __global__ void kernel();
+// NORDC: define void @_Z6kernelIiEvv()
+// RDC:   define weak_odr void @_Z6kernelIiEvv()
+
+// Ensure that unused static device function is eliminated
+static __device__ void static_func() {}
+// NORDC-NEG-NOT: define{{.*}} void @_ZL13static_funcv()
+// RDC-NEG-NOT:   define{{.*}} void @_ZL13static_funcv()
+
+// Ensure that kernel function has external or weak_odr
+// linkage regardless static specifier
+static __global__ void static_kernel() {}
+// NORDC: define void @_ZL13static_kernelv()
+// RDC:   define weak_odr void @_ZL13static_kernelv()

diff  --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp 
b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index 2516dff52efdf..e8322a0a8425b 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -329,7 +329,7 @@ MCOperand NVPTXAsmPrinter::GetSymbolRef(const MCSymbol 
*Symbol) {
 void NVPTXAsmPrinter::printReturnValStr(const Function *F, raw_ostream &O) {
   const DataLayout &DL = getDataLayout();
   const NVPTXSubtarget &STI = TM.getSubtarget(*F);
-  const TargetLowering *TLI = STI.getTargetLowering();
+  const auto *TLI = cast(STI.getTargetLowering());
 
   Type *Ty = F->getReturnType();
 
@@

[PATCH] D120129: [NVPTX] Enhance vectorization of ld.param & st.param

2022-03-24 Thread Daniil Kovalev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
kovdan01 marked 2 inline comments as done.
Closed by commit rG828b63c30943: [NVPTX] Enhance vectorization of ld.param 
& st.param (authored by kovdan01).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120129

Files:
  clang/test/CodeGenCUDA/device-fun-linkage.cu
  llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
  llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
  llvm/lib/Target/NVPTX/NVPTXISelLowering.h
  llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
  llvm/test/CodeGen/NVPTX/param-vectorize-device.ll
  llvm/test/CodeGen/NVPTX/param-vectorize-kernel.ll

Index: llvm/test/CodeGen/NVPTX/param-vectorize-kernel.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/param-vectorize-kernel.ll
@@ -0,0 +1,456 @@
+; RUN: llc < %s -mtriple=nvptx-unknown-unknown | FileCheck %s
+;
+; Check that parameters of a __global__ (kernel) function do not get increased
+; alignment, and no additional vectorization is performed on loads/stores with
+; that parameters.
+;
+; Test IR is a minimized version of IR generated with the following command
+; from the source code below:
+; $ clang++ -O3 --cuda-gpu-arch=sm_35 -S -emit-llvm src.cu
+;
+; 
+; #include 
+;
+; struct St4x1 { uint32_t field[1]; };
+; struct St4x2 { uint32_t field[2]; };
+; struct St4x3 { uint32_t field[3]; };
+; struct St4x4 { uint32_t field[4]; };
+; struct St4x5 { uint32_t field[5]; };
+; struct St4x6 { uint32_t field[6]; };
+; struct St4x7 { uint32_t field[7]; };
+; struct St4x8 { uint32_t field[8]; };
+; struct St8x1 { uint64_t field[1]; };
+; struct St8x2 { uint64_t field[2]; };
+; struct St8x3 { uint64_t field[3]; };
+; struct St8x4 { uint64_t field[4]; };
+;
+; #define DECLARE_FUNCTION(StName)\
+; static __global__  __attribute__((noinline))\
+; void foo_##StName(struct StName in, struct StName* ret) {   \
+;   const unsigned size = sizeof(ret->field) / sizeof(*ret->field);   \
+;   for (unsigned i = 0; i != size; ++i)  \
+; ret->field[i] = in.field[i];\
+; }   \
+;
+; DECLARE_FUNCTION(St4x1)
+; DECLARE_FUNCTION(St4x2)
+; DECLARE_FUNCTION(St4x3)
+; DECLARE_FUNCTION(St4x4)
+; DECLARE_FUNCTION(St4x5)
+; DECLARE_FUNCTION(St4x6)
+; DECLARE_FUNCTION(St4x7)
+; DECLARE_FUNCTION(St4x8)
+; DECLARE_FUNCTION(St8x1)
+; DECLARE_FUNCTION(St8x2)
+; DECLARE_FUNCTION(St8x3)
+; DECLARE_FUNCTION(St8x4)
+; 
+
+%struct.St4x1 = type { [1 x i32] }
+%struct.St4x2 = type { [2 x i32] }
+%struct.St4x3 = type { [3 x i32] }
+%struct.St4x4 = type { [4 x i32] }
+%struct.St4x5 = type { [5 x i32] }
+%struct.St4x6 = type { [6 x i32] }
+%struct.St4x7 = type { [7 x i32] }
+%struct.St4x8 = type { [8 x i32] }
+%struct.St8x1 = type { [1 x i64] }
+%struct.St8x2 = type { [2 x i64] }
+%struct.St8x3 = type { [3 x i64] }
+%struct.St8x4 = type { [4 x i64] }
+
+define dso_local void @foo_St4x1(%struct.St4x1* nocapture noundef readonly byval(%struct.St4x1) align 4 %in, %struct.St4x1* nocapture noundef writeonly %ret) {
+  ; CHECK-LABEL: .visible .func foo_St4x1(
+  ; CHECK:   .param .align 4 .b8 foo_St4x1_param_0[4],
+  ; CHECK:   .param .b32 foo_St4x1_param_1
+  ; CHECK:   )
+  ; CHECK:   ld.param.u32 [[R1:%r[0-9]+]], [foo_St4x1_param_1];
+  ; CHECK:   ld.param.u32 [[R2:%r[0-9]+]], [foo_St4x1_param_0];
+  ; CHECK:   st.u32  [[[R1]]], [[R2]];
+  ; CHECK:   ret;
+  %arrayidx = getelementptr inbounds %struct.St4x1, %struct.St4x1* %in, i64 0, i32 0, i64 0
+  %1 = load i32, i32* %arrayidx, align 4
+  %arrayidx3 = getelementptr inbounds %struct.St4x1, %struct.St4x1* %ret, i64 0, i32 0, i64 0
+  store i32 %1, i32* %arrayidx3, align 4
+  ret void
+}
+
+define dso_local void @foo_St4x2(%struct.St4x2* nocapture noundef readonly byval(%struct.St4x2) align 4 %in, %struct.St4x2* nocapture noundef writeonly %ret) {
+  ; CHECK-LABEL: .visible .func foo_St4x2(
+  ; CHECK:   .param .align 4 .b8 foo_St4x2_param_0[8],
+  ; CHECK:   .param .b32 foo_St4x2_param_1
+  ; CHECK:   )
+  ; CHECK:   ld.param.u32 [[R1:%r[0-9]+]], [foo_St4x2_param_1];
+  ; CHECK:   ld.param.u32 [[R2:%r[0-9]+]], [foo_St4x2_param_0];
+  ; CHECK:   st.u32  [[[R1]]], [[R2]];
+  ; CHECK:   ld.param.u32 [[R3:%r[0-9]+]], [foo_St4x2_param_0+4];
+  ; CHECK:   st.u32  [[[R1]]+4], [[R3]];
+  ; CHECK:   ret;
+  %arrayidx = getelementptr inbounds %struct.St4x2, %struct.St4x2* %in, i64 0, i32 0, i6

[PATCH] D122244: [analyzer] Turn missing tablegen doc entry of a checker into fatal error

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

In D122244#3404727 , @Szelethus wrote:

> LGTM! You did check whether a missing doc field will actually trigger this 
> error, right?

Yup, it works as expected!

  ninja: Entering directory `build/release'
  [1/375] Building Checkers.inc...
  FAILED: tools/clang/include/clang/StaticAnalyzer/Checkers/Checkers.inc 
/git/llvm-project/build/release/tools/clang/include/clang/StaticAnalyzer/Checkers/Checkers.inc
  cd /git/llvm-project/build/release && 
/git/llvm-project/build/release/bin/clang-tblgen -gen-clang-sa-checkers -I 
/git/llvm-project/clang/include/clang/StaticAnalyzer/Checkers 
-I/git/llvm-project/clang/include 
-I/git/llvm-project/build/release/tools/clang/include 
-I/git/llvm-project/build/release/include -I/git/llvm-project/llvm/include 
/git/llvm-project/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
--write-if-changed -o 
tools/clang/include/clang/StaticAnalyzer/Checkers/Checkers.inc -d 
tools/clang/include/clang/StaticAnalyzer/Checkers/Checkers.inc.d
  
/git/llvm-project/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td:585:1:
 error: missing Documentation for cplusplus.NewDelete
  def NewDeleteChecker : Checker<"NewDelete">,
  ^
  ninja: build stopped: subcommand failed.




Comment at: clang/utils/TableGen/ClangSACheckersEmitter.cpp:82
+PrintFatalError(R.getLoc(),
+"missing Documentation for " + getCheckerFullName(&R));
+

Szelethus wrote:
> We might as well give an extra hand, and state that a `Documentation<> field` 
> is missing.
Hmm, indeed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122244

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


[PATCH] D121549: [CodeGen] Define ABI breaking class members correctly

2022-03-24 Thread Daniil Kovalev via Phabricator via cfe-commits
kovdan01 updated this revision to Diff 417858.
kovdan01 added a comment.

Accidentally placed this revision ID in commit message related to other patch. 
Reverted that.


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

https://reviews.llvm.org/D121549

Files:
  llvm/include/llvm/CodeGen/GlobalISel/GISelWorkList.h
  llvm/include/llvm/CodeGen/MachineScheduler.h
  llvm/include/llvm/CodeGen/PBQP/ReductionRules.h
  llvm/include/llvm/CodeGen/RegAllocPBQP.h
  llvm/include/llvm/CodeGen/SelectionDAG.h
  llvm/lib/CodeGen/MachineScheduler.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp

Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
===
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
@@ -181,11 +181,11 @@
 /// clearGraphAttrs - Clear all previously defined node graph attributes.
 /// Intended to be used from a debugging tool (eg. gdb).
 void SelectionDAG::clearGraphAttrs() {
-#ifndef NDEBUG
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
   NodeGraphAttrs.clear();
 #else
-  errs() << "SelectionDAG::clearGraphAttrs is only available in debug builds"
- << " on systems with Graphviz or gv!\n";
+  errs() << "SelectionDAG::clearGraphAttrs is only available in builds with "
+ << "ABI breaking checks enabled on systems with Graphviz or gv!\n";
 #endif
 }
 
@@ -193,11 +193,11 @@
 /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".)
 ///
 void SelectionDAG::setGraphAttrs(const SDNode *N, const char *Attrs) {
-#ifndef NDEBUG
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
   NodeGraphAttrs[N] = Attrs;
 #else
-  errs() << "SelectionDAG::setGraphAttrs is only available in debug builds"
- << " on systems with Graphviz or gv!\n";
+  errs() << "SelectionDAG::setGraphAttrs is only available in builds with "
+ << "ABI breaking checks enabled on systems with Graphviz or gv!\n";
 #endif
 }
 
@@ -205,7 +205,7 @@
 /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".)
 /// Used from getNodeAttributes.
 std::string SelectionDAG::getGraphAttrs(const SDNode *N) const {
-#ifndef NDEBUG
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
   std::map::const_iterator I =
 NodeGraphAttrs.find(N);
 
@@ -214,8 +214,8 @@
   else
 return "";
 #else
-  errs() << "SelectionDAG::getGraphAttrs is only available in debug builds"
- << " on systems with Graphviz or gv!\n";
+  errs() << "SelectionDAG::getGraphAttrs is only available in builds with "
+ << "ABI breaking checks enabled on systems with Graphviz or gv!\n";
   return std::string();
 #endif
 }
@@ -223,11 +223,11 @@
 /// setGraphColor - Convenience for setting node color attribute.
 ///
 void SelectionDAG::setGraphColor(const SDNode *N, const char *Color) {
-#ifndef NDEBUG
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
   NodeGraphAttrs[N] = std::string("color=") + Color;
 #else
-  errs() << "SelectionDAG::setGraphColor is only available in debug builds"
- << " on systems with Graphviz or gv!\n";
+  errs() << "SelectionDAG::setGraphColor is only available in builds with "
+ << "ABI breaking checks enabled on systems with Graphviz or gv!\n";
 #endif
 }
 
Index: llvm/lib/CodeGen/MachineScheduler.cpp
===
--- llvm/lib/CodeGen/MachineScheduler.cpp
+++ llvm/lib/CodeGen/MachineScheduler.cpp
@@ -752,7 +752,7 @@
 }
 
 bool ScheduleDAGMI::checkSchedLimit() {
-#ifndef NDEBUG
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
   if (NumInstrsScheduled == MISchedCutoff && MISchedCutoff != ~0U) {
 CurrentTop = CurrentBottom;
 return false;
@@ -2006,7 +2006,7 @@
   ReservedCycles.clear();
   ReservedCyclesIndex.clear();
   ResourceGroupSubUnitMasks.clear();
-#ifndef NDEBUG
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
   // Track the maximum number of stall cycles that could arise either from the
   // latency of a DAG edge or the number of cycles that a processor resource is
   // reserved (SchedBoundary::ReservedCycles).
@@ -2194,7 +2194,7 @@
   unsigned NRCycle, InstanceIdx;
   std::tie(NRCycle, InstanceIdx) = getNextResourceCycle(SC, ResIdx, Cycles);
   if (NRCycle > CurrCycle) {
-#ifndef NDEBUG
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
 MaxObservedStall = std::max(Cycles, MaxObservedStall);
 #endif
 LLVM_DEBUG(dbgs() << "  SU(" << SU->NodeNum << ") "
@@ -2261,7 +2261,7 @@
 unsigned Idx) {
   assert(SU->getInstr() && "Scheduled SUnit must have instr");
 
-#ifndef NDEBUG
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
   // ReadyCycle was been bumped up to the CurrCycle when this node was
   // scheduled, but CurrCycle may have been eagerly advanced immediately after
   // scheduling, so may now be greater than ReadyCycle.
Index: llvm/include/llvm/CodeGen/SelectionDAG.h
===
--- llvm/include/llvm/CodeGen/SelectionDAG.h
+++ 

[PATCH] D122244: [analyzer] Turn missing tablegen doc entry of a checker into fatal error

2022-03-24 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 417862.
steakhal added a comment.

reword error message


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

https://reviews.llvm.org/D122244

Files:
  clang/utils/TableGen/ClangSACheckersEmitter.cpp


Index: clang/utils/TableGen/ClangSACheckersEmitter.cpp
===
--- clang/utils/TableGen/ClangSACheckersEmitter.cpp
+++ clang/utils/TableGen/ClangSACheckersEmitter.cpp
@@ -76,14 +76,17 @@
 
 static std::string getCheckerDocs(const Record &R) {
   StringRef LandingPage;
-  if (BitsInit *BI = R.getValueAsBitsInit("Documentation")) {
-uint64_t V = getValueFromBitsInit(BI, R);
-if (V == 1)
-  LandingPage = "available_checks.html";
-else if (V == 2)
-  LandingPage = "alpha_checks.html";
-  }
-  
+  const BitsInit *BI = R.getValueAsBitsInit("Documentation");
+  if (!BI)
+PrintFatalError(R.getLoc(), "missing Documentation<...> member for " +
+getCheckerFullName(&R));
+
+  uint64_t V = getValueFromBitsInit(BI, R);
+  if (V == 1)
+LandingPage = "available_checks.html";
+  else if (V == 2)
+LandingPage = "alpha_checks.html";
+
   if (LandingPage.empty())
 return "";
 


Index: clang/utils/TableGen/ClangSACheckersEmitter.cpp
===
--- clang/utils/TableGen/ClangSACheckersEmitter.cpp
+++ clang/utils/TableGen/ClangSACheckersEmitter.cpp
@@ -76,14 +76,17 @@
 
 static std::string getCheckerDocs(const Record &R) {
   StringRef LandingPage;
-  if (BitsInit *BI = R.getValueAsBitsInit("Documentation")) {
-uint64_t V = getValueFromBitsInit(BI, R);
-if (V == 1)
-  LandingPage = "available_checks.html";
-else if (V == 2)
-  LandingPage = "alpha_checks.html";
-  }
-  
+  const BitsInit *BI = R.getValueAsBitsInit("Documentation");
+  if (!BI)
+PrintFatalError(R.getLoc(), "missing Documentation<...> member for " +
+getCheckerFullName(&R));
+
+  uint64_t V = getValueFromBitsInit(BI, R);
+  if (V == 1)
+LandingPage = "available_checks.html";
+  else if (V == 2)
+LandingPage = "alpha_checks.html";
+
   if (LandingPage.empty())
 return "";
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122377: [PowerPC][Linux] Support 16-byte lock free atomics on pwr8 and up

2022-03-24 Thread Kai Luo via Phabricator via cfe-commits
lkail created this revision.
lkail added reviewers: hubert.reinterpretcast, jsji, xingxue, PowerPC.
Herald added subscribers: shchenz, kbarton, hiraditya, nemanjai.
Herald added a project: All.
lkail requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Enable clang of Linux on POWER supports 16-byte lock free atomics on power8 and 
up, so that clang can be consistent with GCC of Linux on POWER.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122377

Files:
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/test/CodeGen/PowerPC/atomic-alignment.c
  clang/test/CodeGen/PowerPC/quadword-atomics.c
  clang/test/Sema/atomic-ops.c
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -123,7 +123,7 @@
 
 static cl::opt EnableQuadwordAtomics(
 "ppc-quadword-atomics",
-cl::desc("enable quadword lock-free atomic operations"), cl::init(false),
+cl::desc("enable quadword lock-free atomic operations"), cl::init(true),
 cl::Hidden);
 
 static cl::opt
Index: clang/test/Sema/atomic-ops.c
===
--- clang/test/Sema/atomic-ops.c
+++ clang/test/Sema/atomic-ops.c
@@ -9,7 +9,7 @@
 // RUN:   -target-cpu pwr7
 // RUN: %clang_cc1 %s -verify -fgnuc-version=4.2.1 -ffreestanding \
 // RUN:   -fsyntax-only -triple=powerpc64le-linux-gnu -std=c11 \
-// RUN:   -target-cpu pwr8
+// RUN:   -target-cpu pwr8 -DPPC64_PWR8
 
 // Basic parsing/Sema tests for __c11_atomic_*
 
@@ -47,7 +47,11 @@
 _Static_assert(__c11_atomic_is_lock_free(3), ""); // expected-error {{not an integral constant expression}}
 _Static_assert(__c11_atomic_is_lock_free(4), "");
 _Static_assert(__c11_atomic_is_lock_free(8), "");
+#ifndef PPC64_PWR8
 _Static_assert(__c11_atomic_is_lock_free(16), ""); // expected-error {{not an integral constant expression}}
+#else
+_Static_assert(__c11_atomic_is_lock_free(16), ""); // expected-no-error
+#endif
 _Static_assert(__c11_atomic_is_lock_free(17), ""); // expected-error {{not an integral constant expression}}
 
 _Static_assert(__atomic_is_lock_free(1, 0), "");
@@ -55,15 +59,23 @@
 _Static_assert(__atomic_is_lock_free(3, 0), ""); // expected-error {{not an integral constant expression}}
 _Static_assert(__atomic_is_lock_free(4, 0), "");
 _Static_assert(__atomic_is_lock_free(8, 0), "");
+#ifndef PPC64_PWR8
 _Static_assert(__atomic_is_lock_free(16, 0), ""); // expected-error {{not an integral constant expression}}
+#else
+_Static_assert(__atomic_is_lock_free(16, 0), ""); // expected-no-error
+#endif
 _Static_assert(__atomic_is_lock_free(17, 0), ""); // expected-error {{not an integral constant expression}}
 
 _Static_assert(atomic_is_lock_free((atomic_char*)0), "");
 _Static_assert(atomic_is_lock_free((atomic_short*)0), "");
 _Static_assert(atomic_is_lock_free((atomic_int*)0), "");
 _Static_assert(atomic_is_lock_free((atomic_long*)0), "");
+#ifndef PPC64_PWR8
 // noi128-error@+1 {{__int128 is not supported on this target}}
 _Static_assert(atomic_is_lock_free((_Atomic(__int128)*)0), ""); // expected-error {{not an integral constant expression}}
+#else
+_Static_assert(atomic_is_lock_free((_Atomic(__int128)*)0), ""); // expected-no-error
+#endif
 _Static_assert(atomic_is_lock_free(0 + (atomic_char*)0), "");
 
 char i8;
@@ -88,7 +100,11 @@
 _Static_assert(!__atomic_always_lock_free(3, 0), "");
 _Static_assert(__atomic_always_lock_free(4, 0), "");
 _Static_assert(__atomic_always_lock_free(8, 0), "");
+#ifndef PPC64_PWR8
 _Static_assert(!__atomic_always_lock_free(16, 0), "");
+#else
+_Static_assert(__atomic_always_lock_free(16, 0), "");
+#endif
 _Static_assert(!__atomic_always_lock_free(17, 0), "");
 
 _Static_assert(__atomic_always_lock_free(1, incomplete), "");
Index: clang/test/CodeGen/PowerPC/quadword-atomics.c
===
--- /dev/null
+++ clang/test/CodeGen/PowerPC/quadword-atomics.c
@@ -0,0 +1,91 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -verify -Wno-atomic-alignment -triple powerpc64le-linux-gnu \
+// RUN:   -target-cpu pwr8 -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC64-PWR8
+// RUN: %clang_cc1 -verify -Wno-atomic-alignment -triple powerpc64le-linux-gnu \
+// RUN:   -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC64
+
+typedef struct {
+  char x[16];
+} Q;
+
+typedef _Atomic(Q) AtomicQ;
+
+typedef __int128_t int128_t;
+
+// PPC64-PWR8-LABEL: @test_load(
+// PPC64-PWR8:[[TMP3:%.*]] = load atomic i128, i128* [[TMP1:%.*]] acquire, align 16
+//
+// PPC64-LABEL: @test_load(
+// PPC64:call void @__atomic_load(i64 noundef 16, i8* noundef [[TMP3:%.*]], i8* noundef [[TMP4:%.*]], i32 noundef signext 2)
+//
+Q test_l

[PATCH] D122378: Be more explicit about -fvisibility= documentation

2022-03-24 Thread serge via Phabricator via cfe-commits
serge-sans-paille created this revision.
serge-sans-paille added a reviewer: aaron.ballman.
Herald added a project: All.
serge-sans-paille requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When in need, I had to look into gcc info page, then check clang source code. 
Having that info in the official doc looks useful :-)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122378

Files:
  clang/docs/ClangCommandLineReference.rst


Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -2613,9 +2613,9 @@
 
 The visibility for defintiions without an explicit DLL export class 
\[-fvisibility-from-dllstorageclass\]
 
-.. option:: -fvisibility=
+.. option:: -fvisibility=[default|hidden]
 
-Set the default symbol visibility for all global declarations
+Set the default symbol visibility for all global declarations.
 
 .. option:: -fwasm-exceptions
 


Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -2613,9 +2613,9 @@
 
 The visibility for defintiions without an explicit DLL export class \[-fvisibility-from-dllstorageclass\]
 
-.. option:: -fvisibility=
+.. option:: -fvisibility=[default|hidden]
 
-Set the default symbol visibility for all global declarations
+Set the default symbol visibility for all global declarations.
 
 .. option:: -fwasm-exceptions
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122377: [PowerPC][Linux] Support 16-byte lock free atomics on pwr8 and up

2022-03-24 Thread Kai Luo via Phabricator via cfe-commits
lkail updated this revision to Diff 417868.

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

https://reviews.llvm.org/D122377

Files:
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/test/CodeGen/PowerPC/atomic-alignment.c
  clang/test/CodeGen/PowerPC/quadword-atomics.c
  clang/test/Sema/atomic-ops.c
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -123,7 +123,7 @@
 
 static cl::opt EnableQuadwordAtomics(
 "ppc-quadword-atomics",
-cl::desc("enable quadword lock-free atomic operations"), cl::init(false),
+cl::desc("enable quadword lock-free atomic operations"), cl::init(true),
 cl::Hidden);
 
 static cl::opt
Index: clang/test/Sema/atomic-ops.c
===
--- clang/test/Sema/atomic-ops.c
+++ clang/test/Sema/atomic-ops.c
@@ -9,7 +9,7 @@
 // RUN:   -target-cpu pwr7
 // RUN: %clang_cc1 %s -verify -fgnuc-version=4.2.1 -ffreestanding \
 // RUN:   -fsyntax-only -triple=powerpc64le-linux-gnu -std=c11 \
-// RUN:   -target-cpu pwr8
+// RUN:   -target-cpu pwr8 -DPPC64_PWR8
 
 // Basic parsing/Sema tests for __c11_atomic_*
 
@@ -47,7 +47,11 @@
 _Static_assert(__c11_atomic_is_lock_free(3), ""); // expected-error {{not an integral constant expression}}
 _Static_assert(__c11_atomic_is_lock_free(4), "");
 _Static_assert(__c11_atomic_is_lock_free(8), "");
+#ifndef PPC64_PWR8
 _Static_assert(__c11_atomic_is_lock_free(16), ""); // expected-error {{not an integral constant expression}}
+#else
+_Static_assert(__c11_atomic_is_lock_free(16), ""); // expected-no-error
+#endif
 _Static_assert(__c11_atomic_is_lock_free(17), ""); // expected-error {{not an integral constant expression}}
 
 _Static_assert(__atomic_is_lock_free(1, 0), "");
@@ -55,15 +59,23 @@
 _Static_assert(__atomic_is_lock_free(3, 0), ""); // expected-error {{not an integral constant expression}}
 _Static_assert(__atomic_is_lock_free(4, 0), "");
 _Static_assert(__atomic_is_lock_free(8, 0), "");
+#ifndef PPC64_PWR8
 _Static_assert(__atomic_is_lock_free(16, 0), ""); // expected-error {{not an integral constant expression}}
+#else
+_Static_assert(__atomic_is_lock_free(16, 0), ""); // expected-no-error
+#endif
 _Static_assert(__atomic_is_lock_free(17, 0), ""); // expected-error {{not an integral constant expression}}
 
 _Static_assert(atomic_is_lock_free((atomic_char*)0), "");
 _Static_assert(atomic_is_lock_free((atomic_short*)0), "");
 _Static_assert(atomic_is_lock_free((atomic_int*)0), "");
 _Static_assert(atomic_is_lock_free((atomic_long*)0), "");
+#ifndef PPC64_PWR8
 // noi128-error@+1 {{__int128 is not supported on this target}}
 _Static_assert(atomic_is_lock_free((_Atomic(__int128)*)0), ""); // expected-error {{not an integral constant expression}}
+#else
+_Static_assert(atomic_is_lock_free((_Atomic(__int128)*)0), ""); // expected-no-error
+#endif
 _Static_assert(atomic_is_lock_free(0 + (atomic_char*)0), "");
 
 char i8;
@@ -88,7 +100,11 @@
 _Static_assert(!__atomic_always_lock_free(3, 0), "");
 _Static_assert(__atomic_always_lock_free(4, 0), "");
 _Static_assert(__atomic_always_lock_free(8, 0), "");
+#ifndef PPC64_PWR8
 _Static_assert(!__atomic_always_lock_free(16, 0), "");
+#else
+_Static_assert(__atomic_always_lock_free(16, 0), "");
+#endif
 _Static_assert(!__atomic_always_lock_free(17, 0), "");
 
 _Static_assert(__atomic_always_lock_free(1, incomplete), "");
Index: clang/test/CodeGen/PowerPC/quadword-atomics.c
===
--- /dev/null
+++ clang/test/CodeGen/PowerPC/quadword-atomics.c
@@ -0,0 +1,90 @@
+// RUN: %clang_cc1 -verify -Wno-atomic-alignment -triple powerpc64le-linux-gnu \
+// RUN:   -target-cpu pwr8 -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC64-PWR8
+// RUN: %clang_cc1 -verify -Wno-atomic-alignment -triple powerpc64le-linux-gnu \
+// RUN:   -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC64
+
+typedef struct {
+  char x[16];
+} Q;
+
+typedef _Atomic(Q) AtomicQ;
+
+typedef __int128_t int128_t;
+
+// PPC64-PWR8-LABEL: @test_load(
+// PPC64-PWR8:[[TMP3:%.*]] = load atomic i128, i128* [[TMP1:%.*]] acquire, align 16
+//
+// PPC64-LABEL: @test_load(
+// PPC64:call void @__atomic_load(i64 noundef 16, i8* noundef [[TMP3:%.*]], i8* noundef [[TMP4:%.*]], i32 noundef signext 2)
+//
+Q test_load(AtomicQ *ptr) {
+  // expected-no-diagnostics
+  return __c11_atomic_load(ptr, __ATOMIC_ACQUIRE);
+}
+
+// PPC64-PWR8-LABEL: @test_store(
+// PPC64-PWR8:store atomic i128 [[TMP6:%.*]], i128* [[TMP4:%.*]] release, align 16
+//
+// PPC64-LABEL: @test_store(
+// PPC64:call void @__atomic_store(i64 noundef 16, i8* noundef [[TMP6:%.*]], i8* noundef [[TMP7:%.*]], i32 noundef signext 3)
+//
+void test_store(Q val, AtomicQ *ptr) {
+  // expected-no-diagnostics
+  __c11_

[PATCH] D122315: [clangd] Retain main file fixes attached to diags from preamble

2022-03-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 417873.
kadircet marked 2 inline comments as done.
kadircet added a comment.

- Get rid of redundant local variable
- Update comment around assumptions about main file-ness inside toLSPDiag.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122315

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -22,6 +22,7 @@
 #include "support/Path.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticSema.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
@@ -1658,6 +1659,28 @@
   EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
 }
 
+TEST(DiagnosticsTest, FixItFromHeader) {
+  llvm::StringLiteral Header(R"cpp(
+void foo(int *);
+void foo(int *, int);)cpp");
+  Annotations Source(R"cpp(
+  /*error-ok*/
+void bar() {
+  int x;
+  $diag[[foo]]($fix[[]]x, 1);
+})cpp");
+  TestTU TU;
+  TU.Code = Source.code().str();
+  TU.HeaderCode = Header.str();
+  EXPECT_THAT(
+  *TU.build().getDiagnostics(),
+  UnorderedElementsAre(AllOf(
+  Diag(Source.range("diag"), "no matching function for call to 'foo'"),
+  withFix(Fix(Source.range("fix"), "&",
+  "candidate function not viable: no known conversion from 
"
+  "'int' to 'int *' for 1st argument; take the address of "
+  "the argument with &");
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -31,6 +31,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -463,7 +464,8 @@
 
   // Main diagnostic should always refer to a range inside main file. If a
   // diagnostic made it so for, it means either itself or one of its notes is
-  // inside main file.
+  // inside main file. It's also possible that there's a fix in the main file,
+  // but we preserve fixes iff primary diagnostic is in the main file.
   if (D.InsideMainFile) {
 Main.range = D.Range;
   } else {
@@ -701,13 +703,12 @@
 return;
   }
 
-  bool InsideMainFile = isInsideMainFile(Info);
   SourceManager &SM = Info.getSourceManager();
 
   auto FillDiagBase = [&](DiagBase &D) {
 fillNonLocationData(DiagLevel, Info, D);
 
-D.InsideMainFile = InsideMainFile;
+D.InsideMainFile = isInsideMainFile(Info);
 D.Range = diagnosticRange(Info, *LangOpts);
 D.File = std::string(SM.getFilename(Info.getLocation()));
 D.AbsFile = getCanonicalPath(
@@ -719,9 +720,9 @@
   auto AddFix = [&](bool SyntheticMessage) -> bool {
 assert(!Info.getFixItHints().empty() &&
"diagnostic does not have attached fix-its");
-if (!InsideMainFile)
+// No point in generating fixes, if the diagnostic is for a different file.
+if (!LastDiag->InsideMainFile)
   return false;
-
 // Copy as we may modify the ranges.
 auto FixIts = Info.getFixItHints().vec();
 llvm::SmallVector Edits;


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -22,6 +22,7 @@
 #include "support/Path.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticSema.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
@@ -1658,6 +1659,28 @@
   EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
 }
 
+TEST(DiagnosticsTest, FixItFromHeader) {
+  llvm::StringLiteral Header(R"cpp(
+void foo(int *);
+void foo(int *, int);)cpp");
+  Annotations Source(R"cpp(
+  /*error-ok*/
+void bar() {
+  int x;
+  $diag[[foo]]($fix[[]]x, 1);
+})cpp");
+  TestTU TU;
+  TU.Code = Source.code().str();
+  TU.HeaderCode = Header.str();
+  EXPECT_THAT(
+  *TU.build().getDiagnostics(),
+  UnorderedElementsAre(AllOf(
+  Diag(Source.range("diag"), "no matching function for call to 'foo'"),
+  withFix(Fix(Source.range("fix"), "&",
+  "candidate function not viable: no known conversion from "
+  "'int' to 'int *' for 1st argument; take the address of "
+  "the argument with &");
+}
 } // namespa

[PATCH] D122315: [clangd] Retain main file fixes attached to diags from preamble

2022-03-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:68
 return true;
   // Fixes are always in the main file.
   if (!D.Fixes.empty())

sammccall wrote:
> update comment: Fixes are only added if the fix or diagnostics is in the main 
> file.
as discussed offline, this is still the case and it isn't an `or` but an `and`, 
i.e. we preserve a fix if it's in the main file AND the primary diagnostic 
we'll attach it to is also inside the main file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122315

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


[PATCH] D122331: [clang][extract-api] Stop allocating APIRecords via BumpPtrAllocator

2022-03-24 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added a comment.

I have checked locally against San to make sure this doesn't reintroduce the 
memory leak issues we were seeing initially that lead to the addition of 
`APIRecordUniquePtr`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122331

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


[PATCH] D122315: [clangd] Retain main file fixes attached to diags from preamble

2022-03-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

LG, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122315

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


[PATCH] D120989: Support debug info for alias variable

2022-03-24 Thread Kavitha Natarajan via Phabricator via cfe-commits
kavitha-natarajan updated this revision to Diff 417878.
kavitha-natarajan added a comment.

@aprantl, thanks for your comments. Updated the patch with the fixes.

@dblaikie, haven't got any response from gdb reviewers about the gdb patch yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120989

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/debug-info-alias.c

Index: clang/test/CodeGen/debug-info-alias.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-alias.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+
+// CHECK-DAG: [[ENTITY1:![0-9]+]] = distinct !DIGlobalVariable(name: "aliased_global"
+// CHECK-DAG: [[ENTITY2:![0-9]+]] = distinct !DIGlobalVariable(name: "aliased_global_2"
+// CHECK-DAG: !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "__global_alias", scope: !2, entity: [[ENTITY1]]
+// CHECK-DAG: [[ENTITY3:![0-9]+]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "global_alias_2", scope: !2, entity: [[ENTITY2]]
+// CHECK-DAG: !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "__global_alias_2_alias", scope: !2, entity: [[ENTITY3]]
+
+int aliased_global = 1;
+extern int __attribute__((alias("aliased_global"))) __global_alias;
+
+// Recursive alias:
+int aliased_global_2 = 2;
+extern int __attribute__((alias("aliased_global_2"))) global_alias_2;
+extern int __attribute__((alias("global_alias_2"))) __global_alias_2_alias;
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1213,6 +1213,7 @@
 
   StringRef getMangledName(GlobalDecl GD);
   StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
+  const GlobalDecl getMangledNameDecl(StringRef);
 
   void EmitTentativeDefinition(const VarDecl *D);
 
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1498,6 +1498,16 @@
   return Result.first->first();
 }
 
+const GlobalDecl CodeGenModule::getMangledNameDecl(StringRef Name) {
+  auto it = MangledDeclNames.begin();
+  while (it != MangledDeclNames.end()) {
+if (it->second == Name)
+  return it->first;
+it++;
+  }
+  return GlobalDecl();
+}
+
 llvm::GlobalValue *CodeGenModule::GetGlobalValue(StringRef Name) {
   return getModule().getNamedValue(Name);
 }
@@ -5164,6 +5174,13 @@
   setTLSMode(GA, *VD);
 
   SetCommonAttributes(GD, GA);
+
+  // Emit global alias debug information.
+  if (const auto *VD = dyn_cast(D)) {
+if (CGDebugInfo *DI = getModuleDebugInfo()) {
+  DI->EmitGlobalAlias(cast(GA->getAliasee()), GD);
+}
+  }
 }
 
 void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -152,8 +152,10 @@
   llvm::DenseMap DIFileCache;
   llvm::DenseMap SPCache;
   /// Cache declarations relevant to DW_TAG_imported_declarations (C++
-  /// using declarations) that aren't covered by other more specific caches.
+  /// using declarations and global alias variables) that aren't covered
+  /// by other more specific caches.
   llvm::DenseMap DeclCache;
+  llvm::DenseMap ImportedDeclCache;
   llvm::DenseMap NamespaceCache;
   llvm::DenseMap
   NamespaceAliasCache;
@@ -512,6 +514,9 @@
   /// Emit information about an external variable.
   void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
 
+  /// Emit information about global variable alias.
+  void EmitGlobalAlias(const llvm::GlobalValue *GV, const GlobalDecl Decl);
+
   /// Emit C++ using directive.
   void EmitUsingDirective(const UsingDirectiveDecl &UD);
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3908,6 +3908,17 @@
 auto N = I->second;
 if (auto *GVE = dyn_cast_or_null(N))
   return GVE->getVariable();
+return cast(N);
+  }
+
+  // Search imported declaration cache if it is already defined
+  // as imported declaration.
+  auto IE = ImportedDeclCache.find(D->getCanonicalDecl());
+
+  if (IE != ImportedDeclCache.end()) {
+auto N = IE->second;
+if (auto *GVE = dyn_cast_or_null(N))
+  return cast(GVE);
 return dyn_cast_or_null(N);
   }
 
@@ -5467,6 +5478,47 @@
   Var->addDebugInfo(GVE);
 }
 
+void CGDebugInfo::EmitGlobalAlias(const llvm::GlobalValue *GV,
+  const GlobalDecl GD) {
+
+  a

[PATCH] D122341: Fix a crash with variably-modified parameter types in a naked function

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 417884.
aaron.ballman added a comment.

Updating based on review feedback


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

https://reviews.llvm.org/D122341

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/attr-naked.c


Index: clang/test/CodeGen/attr-naked.c
===
--- clang/test/CodeGen/attr-naked.c
+++ clang/test/CodeGen/attr-naked.c
@@ -23,5 +23,14 @@
 // CHECK: unreachable
 }
 
+// Make sure naked functions do not attempt to evaluate parameters with a
+// variably-modified type. Naked functions get no prolog, so this evaluation
+// should not take place.
+__attribute__((naked)) void t4(int len, char x[len]) {
+  // CHECK: define{{.*}} void @t4(i32 noundef %0, i8* noundef %1)
+  // CHECK-NEXT: entry:
+  // CHECK-NEXT: unreachable
+}
+
 // CHECK: attributes [[NAKED_OPTNONE]] = { naked noinline nounwind 
optnone{{.*}} }
 // CHECK: attributes [[NAKED]] = { naked noinline nounwind{{.*}} }
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1195,27 +1195,26 @@
   }
 
   // If any of the arguments have a variably modified type, make sure to
-  // emit the type size.
-  for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
-   i != e; ++i) {
-const VarDecl *VD = *i;
-
-// Dig out the type as written from ParmVarDecls; it's unclear whether
-// the standard (C99 6.9.1p10) requires this, but we're following the
-// precedent set by gcc.
-QualType Ty;
-if (const ParmVarDecl *PVD = dyn_cast(VD))
-  Ty = PVD->getOriginalType();
-else
-  Ty = VD->getType();
+  // emit the type size, but only if the function is not naked. Naked functions
+  // have no prolog to run this evaluation.
+  if (!FD || !FD->hasAttr()) {
+for (const VarDecl *VD : Args) {
+  // Dig out the type as written from ParmVarDecls; it's unclear whether
+  // the standard (C99 6.9.1p10) requires this, but we're following the
+  // precedent set by gcc.
+  QualType Ty;
+  if (const ParmVarDecl *PVD = dyn_cast(VD))
+Ty = PVD->getOriginalType();
+  else
+Ty = VD->getType();
 
-if (Ty->isVariablyModifiedType())
-  EmitVariablyModifiedType(Ty);
+  if (Ty->isVariablyModifiedType())
+EmitVariablyModifiedType(Ty);
+}
   }
   // Emit a location at the end of the prologue.
   if (CGDebugInfo *DI = getDebugInfo())
 DI->EmitLocation(Builder, StartLoc);
-
   // TODO: Do we need to handle this in two places like we do with
   // target-features/target-cpu?
   if (CurFuncDecl)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -72,10 +72,12 @@
 - Previously invalid member variables with template parameters would crash 
clang.
   Now fixed by setting identifiers for them.
   This fixes `Issue 28475 (PR28101) 
`_.
-
 - Now allow the `restrict` and `_Atomic` qualifiers to be used in conjunction
   with `__auto_type` to match the behavior in GCC. This fixes
   `Issue 53652 `_.
+- No longer crash when specifying a variably-modified parameter type in a
+  function with the ``naked`` attribute. This fixes
+  `Issue 50541 `_.
 
 
 Improvements to Clang's diagnostics


Index: clang/test/CodeGen/attr-naked.c
===
--- clang/test/CodeGen/attr-naked.c
+++ clang/test/CodeGen/attr-naked.c
@@ -23,5 +23,14 @@
 // CHECK: unreachable
 }
 
+// Make sure naked functions do not attempt to evaluate parameters with a
+// variably-modified type. Naked functions get no prolog, so this evaluation
+// should not take place.
+__attribute__((naked)) void t4(int len, char x[len]) {
+  // CHECK: define{{.*}} void @t4(i32 noundef %0, i8* noundef %1)
+  // CHECK-NEXT: entry:
+  // CHECK-NEXT: unreachable
+}
+
 // CHECK: attributes [[NAKED_OPTNONE]] = { naked noinline nounwind optnone{{.*}} }
 // CHECK: attributes [[NAKED]] = { naked noinline nounwind{{.*}} }
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1195,27 +1195,26 @@
   }
 
   // If any of the arguments have a variably modified type, make sure to
-  // emit the type size.
-  for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
-   i != e; ++i) {
-const VarDecl *VD = *i;
-
-// Dig out the type as written from ParmVarDecls; it's unclear whether
-// the standard (C99 6.9.1p10) requires thi

[PATCH] D122341: Fix a crash with variably-modified parameter types in a naked function

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D122341#3403587 , @erichkeane 
wrote:

> Other than this 1 thing, LGTM.  I DO find myself wondering how much of the 
> CXXMethodDecl bit in the branch above is valid for 'naked' as well.  If it 
> ISN'T we might consider  moving this loop AND that to EmitFunctionPrologue.

There's a different kind of bug there. MSVC disallows using the `naked` 
attribute on a member function. Clang doesn't enforce this: 
https://godbolt.org/z/6jKGbzYTq GCC has no such restriction, but GCC doesn't 
have many diagnostics in this area anyway. We may want to reconsider whether 
allowing the naked attribute on a non static member function is a good idea. We 
probably don't want to allow it in MS compatibility mode at the very least. But 
I think this can be a change for another day. WDYT?




Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:1200
+  if (!FD || !FD->hasAttr()) {
+for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
+ i != e; ++i) {

erichkeane wrote:
> Since you're touching it... this looks like a 'range-for' loop :D 
Sure, I can do that.


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

https://reviews.llvm.org/D122341

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


[PATCH] D122331: [clang][extract-api] Stop allocating APIRecords via BumpPtrAllocator

2022-03-24 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 417885.
dang marked 2 inline comments as done.
dang added a comment.

Address review feedback: Rename APISet::Allocator to APISet::StringAllocator


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122331

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/lib/ExtractAPI/API.cpp

Index: clang/lib/ExtractAPI/API.cpp
===
--- clang/lib/ExtractAPI/API.cpp
+++ clang/lib/ExtractAPI/API.cpp
@@ -17,7 +17,7 @@
 #include "clang/AST/CommentLexer.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/Index/USRGeneration.h"
-#include "llvm/Support/Allocator.h"
+#include 
 
 using namespace clang::extractapi;
 using namespace llvm;
@@ -32,9 +32,9 @@
   auto Result = Globals.insert({Name, nullptr});
   if (Result.second) {
 // Create the record if it does not already exist.
-auto Record = APIRecordUniquePtr(new (Allocator) GlobalRecord{
+auto Record = std::make_unique(
 Kind, Name, USR, Loc, Availability, Linkage, Comment, Fragments,
-SubHeading, Signature});
+SubHeading, Signature);
 Result.first->second = std::move(Record);
   }
   return Result.first->second.get();
@@ -63,9 +63,8 @@
 EnumRecord *Enum, StringRef Name, StringRef USR, PresumedLoc Loc,
 const AvailabilityInfo &Availability, const DocComment &Comment,
 DeclarationFragments Declaration, DeclarationFragments SubHeading) {
-  auto Record =
-  APIRecordUniquePtr(new (Allocator) EnumConstantRecord{
-  Name, USR, Loc, Availability, Comment, Declaration, SubHeading});
+  auto Record = std::make_unique(
+  Name, USR, Loc, Availability, Comment, Declaration, SubHeading);
   return Enum->Constants.emplace_back(std::move(Record)).get();
 }
 
@@ -77,8 +76,8 @@
   auto Result = Enums.insert({Name, nullptr});
   if (Result.second) {
 // Create the record if it does not already exist.
-auto Record = APIRecordUniquePtr(new (Allocator) EnumRecord{
-Name, USR, Loc, Availability, Comment, Declaration, SubHeading});
+auto Record = std::make_unique(
+Name, USR, Loc, Availability, Comment, Declaration, SubHeading);
 Result.first->second = std::move(Record);
   }
   return Result.first->second.get();
@@ -90,9 +89,8 @@
   const DocComment &Comment,
   DeclarationFragments Declaration,
   DeclarationFragments SubHeading) {
-  auto Record =
-  APIRecordUniquePtr(new (Allocator) StructFieldRecord{
-  Name, USR, Loc, Availability, Comment, Declaration, SubHeading});
+  auto Record = std::make_unique(
+  Name, USR, Loc, Availability, Comment, Declaration, SubHeading);
   return Struct->Fields.emplace_back(std::move(Record)).get();
 }
 
@@ -104,8 +102,8 @@
   auto Result = Structs.insert({Name, nullptr});
   if (Result.second) {
 // Create the record if it does not already exist.
-auto Record = APIRecordUniquePtr(new (Allocator) StructRecord{
-Name, USR, Loc, Availability, Comment, Declaration, SubHeading});
+auto Record = std::make_unique(
+Name, USR, Loc, Availability, Comment, Declaration, SubHeading);
 Result.first->second = std::move(Record);
   }
   return Result.first->second.get();
@@ -122,10 +120,10 @@
 return {};
 
   // No need to allocate memory and copy if the string has already been stored.
-  if (Allocator.identifyObject(String.data()))
+  if (StringAllocator.identifyObject(String.data()))
 return String;
 
-  void *Ptr = Allocator.Allocate(String.size(), 1);
+  void *Ptr = StringAllocator.Allocate(String.size(), 1);
   memcpy(Ptr, String.data(), String.size());
   return StringRef(reinterpret_cast(Ptr), String.size());
 }
Index: clang/include/clang/ExtractAPI/API.h
===
--- clang/include/clang/ExtractAPI/API.h
+++ clang/include/clang/ExtractAPI/API.h
@@ -30,25 +30,6 @@
 #include "llvm/Support/Casting.h"
 #include 
 
-namespace {
-
-/// \brief A custom deleter used for ``std::unique_ptr`` to APIRecords stored
-/// in the BumpPtrAllocator.
-///
-/// \tparam T the exact type of the APIRecord subclass.
-template  struct UniquePtrBumpPtrAllocatorDeleter {
-  void operator()(T *Instance) { Instance->~T(); }
-};
-
-/// A unique pointer to an APIRecord stored in the BumpPtrAllocator.
-///
-/// \tparam T the exact type of the APIRecord subclass.
-template 
-using APIRecordUniquePtr =
-std::unique_ptr>;
-
-} // anonymous namespace
-
 namespace clang {
 namespace extractapi {
 
@@ -165,7 +146,7 @@
 
 /// This holds information associated with enums.
 struct EnumRecord : APIRecord {
-  SmallVector> Constants;
+  SmallVector> Constants;
 
   EnumRecord(StringRef Name, StringRef USR, PresumedLoc Loc,
  const AvailabilityInfo &Availability, const DocC

[PATCH] D122331: [clang][extract-api] Stop allocating APIRecords via BumpPtrAllocator

2022-03-24 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/include/clang/ExtractAPI/API.h:326
+  /// Note: The main use for this is being able to deduplicate strings.
   llvm::BumpPtrAllocator Allocator;
 

zixuw wrote:
> zixuw wrote:
> > Should we just rename the allocator along the lines of `StringAllocator` or 
> > `StringPool` so that the code is self-explanatory?
> Also now that the allocator is used exclusively for strings, should we use 
> `SpecificBumpPtrAllocator`?
After thinking about it, we shouldn't because we are storing strings that 
shouldn't be modified as `const char *` so we shouldn't need to call 
destructors.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122331

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


[clang] 406bde9 - [PowerPC] [Clang] Add SSE4 and BMI intrinsics implementation

2022-03-24 Thread Qiu Chaofan via cfe-commits

Author: Qiu Chaofan
Date: 2022-03-24T20:03:08+08:00
New Revision: 406bde9a15136254f2b10d9ef3a42033b3cb1b16

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

LOG: [PowerPC] [Clang] Add SSE4 and BMI intrinsics implementation

Reviewed By: jsji

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

Added: 
clang/lib/Headers/ppc_wrappers/bmi2intrin.h
clang/lib/Headers/ppc_wrappers/bmiintrin.h
clang/lib/Headers/ppc_wrappers/immintrin.h
clang/lib/Headers/ppc_wrappers/nmmintrin.h
clang/lib/Headers/ppc_wrappers/x86gprintrin.h
clang/lib/Headers/ppc_wrappers/x86intrin.h
clang/test/CodeGen/PowerPC/ppc-x86gprintrin.c

Modified: 
clang/lib/Headers/CMakeLists.txt
clang/lib/Headers/ppc_wrappers/emmintrin.h
clang/lib/Headers/ppc_wrappers/pmmintrin.h
clang/lib/Headers/ppc_wrappers/smmintrin.h
clang/lib/Headers/ppc_wrappers/tmmintrin.h
clang/lib/Headers/ppc_wrappers/xmmintrin.h
clang/test/CodeGen/PowerPC/ppc-emmintrin.c
clang/test/CodeGen/PowerPC/ppc-smmintrin.c
clang/test/CodeGen/PowerPC/ppc-xmmintrin.c

Removed: 




diff  --git a/clang/lib/Headers/CMakeLists.txt 
b/clang/lib/Headers/CMakeLists.txt
index e218a6a46a147..f1106b97bb382 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -164,6 +164,12 @@ set(ppc_wrapper_files
   ppc_wrappers/pmmintrin.h
   ppc_wrappers/tmmintrin.h
   ppc_wrappers/smmintrin.h
+  ppc_wrappers/bmiintrin.h
+  ppc_wrappers/bmi2intrin.h
+  ppc_wrappers/immintrin.h
+  ppc_wrappers/tmmintrin.h
+  ppc_wrappers/x86intrin.h
+  ppc_wrappers/x86gprintrin.h
 )
 
 set(openmp_wrapper_files

diff  --git a/clang/lib/Headers/ppc_wrappers/bmi2intrin.h 
b/clang/lib/Headers/ppc_wrappers/bmi2intrin.h
new file mode 100644
index 0..433fe0887a071
--- /dev/null
+++ b/clang/lib/Headers/ppc_wrappers/bmi2intrin.h
@@ -0,0 +1,133 @@
+/*=== bmiintrin.h - Implementation of BMI2 intrinsics on PowerPC ---===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#if !defined X86GPRINTRIN_H_
+#error "Never use  directly; include  instead."
+#endif
+
+#ifndef BMI2INTRIN_H_
+#define BMI2INTRIN_H_
+
+extern __inline unsigned int
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+_bzhi_u32(unsigned int __X, unsigned int __Y) {
+  return ((__X << (32 - __Y)) >> (32 - __Y));
+}
+
+extern __inline unsigned int
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+_mulx_u32(unsigned int __X, unsigned int __Y, unsigned int *__P) {
+  unsigned long long __res = (unsigned long long)__X * __Y;
+  *__P = (unsigned int)(__res >> 32);
+  return (unsigned int)__res;
+}
+
+#ifdef __PPC64__
+extern __inline unsigned long long
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+_bzhi_u64(unsigned long long __X, unsigned long long __Y) {
+  return ((__X << (64 - __Y)) >> (64 - __Y));
+}
+
+/* __int128 requires base 64-bit.  */
+extern __inline unsigned long long
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+_mulx_u64(unsigned long long __X, unsigned long long __Y,
+  unsigned long long *__P) {
+  unsigned __int128 __res = (unsigned __int128)__X * __Y;
+  *__P = (unsigned long long)(__res >> 64);
+  return (unsigned long long)__res;
+}
+
+#ifdef _ARCH_PWR7
+/* popcount and bpermd require power7 minimum.  */
+extern __inline unsigned long long
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+_pdep_u64(unsigned long long __X, unsigned long long __M) {
+  unsigned long result = 0x0UL;
+  const unsigned long mask = 0x8000UL;
+  unsigned long m = __M;
+  unsigned long c, t;
+  unsigned long p;
+
+  /* The pop-count of the mask gives the number of the bits from
+   source to process.  This is also needed to shift bits from the
+   source into the correct position for the result.  */
+  p = 64 - __builtin_popcountl(__M);
+
+  /* The loop is for the number of '1' bits in the mask and clearing
+   each mask bit as it is processed.  */
+  while (m != 0) {
+c = __builtin_clzl(m);
+t = __X << (p - c);
+m ^= (mask >> c);
+result |= (t & (mask >> c));
+p++;
+  }
+  return (result);
+}
+
+extern __inline unsigned long long
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+_pext_u64(unsigned long long __X, unsigned long long __M) {
+  unsigned long p = 0x4040404040404040UL; // initial bit permute control
+  const unsigned long mask = 0x8000UL;
+  unsigned long m = __M;

[PATCH] D119407: [PowerPC] [Clang] Add SSE4 and BMI compatible intrinsics implementation for PowerPC

2022-03-24 Thread Qiu Chaofan 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 rG406bde9a1513: [PowerPC] [Clang] Add SSE4 and BMI intrinsics 
implementation (authored by qiucf).

Changed prior to commit:
  https://reviews.llvm.org/D119407?vs=413336&id=417887#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119407

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/ppc_wrappers/bmi2intrin.h
  clang/lib/Headers/ppc_wrappers/bmiintrin.h
  clang/lib/Headers/ppc_wrappers/emmintrin.h
  clang/lib/Headers/ppc_wrappers/immintrin.h
  clang/lib/Headers/ppc_wrappers/nmmintrin.h
  clang/lib/Headers/ppc_wrappers/pmmintrin.h
  clang/lib/Headers/ppc_wrappers/smmintrin.h
  clang/lib/Headers/ppc_wrappers/tmmintrin.h
  clang/lib/Headers/ppc_wrappers/x86gprintrin.h
  clang/lib/Headers/ppc_wrappers/x86intrin.h
  clang/lib/Headers/ppc_wrappers/xmmintrin.h
  clang/test/CodeGen/PowerPC/ppc-emmintrin.c
  clang/test/CodeGen/PowerPC/ppc-smmintrin.c
  clang/test/CodeGen/PowerPC/ppc-x86gprintrin.c
  clang/test/CodeGen/PowerPC/ppc-xmmintrin.c

Index: clang/test/CodeGen/PowerPC/ppc-xmmintrin.c
===
--- clang/test/CodeGen/PowerPC/ppc-xmmintrin.c
+++ clang/test/CodeGen/PowerPC/ppc-xmmintrin.c
@@ -9,6 +9,9 @@
 // RUN: %clang -x c++ -fsyntax-only -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
 
+// RUN: %clang -S -emit-llvm -target powerpc64le-unknown-linux-gnu -mcpu=pwr10 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
+// RUN:   -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-P10
+
 // RUN: %clang -S -emit-llvm -target powerpc64-unknown-freebsd13.0 -mcpu=pwr8 -ffreestanding -nostdlibinc -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
 // RUN: %clang -x c++ -fsyntax-only -target powerpc64-unknown-freebsd13.0 -mcpu=pwr8 -ffreestanding -nostdlibinc -DNO_WARN_X86_INTRINSICS %s \
@@ -383,12 +386,12 @@
 // CHECK: extractelement <4 x float> %{{[0-9a-zA-Z_.]+}}, i32 0
 
 // CHECK-LABEL: define available_externally signext i32 @_mm_cvtss_si32
-// CHECK-LE: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i64, double } asm "xxsldwi ${0:x},${0:x},${0:x},3;\0Axscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
-// CHECK-BE: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i64, double } asm "xscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
-// CHECK: extractvalue { <4 x float>, i64, double } %[[VEC]], 0
-// CHECK: extractvalue { <4 x float>, i64, double } %[[VEC]], 1
-// CHECK: extractvalue { <4 x float>, i64, double } %[[VEC]], 2
-// CHECK: trunc i64 %{{[0-9a-zA-Z_.]+}} to i32
+// CHECK-LE: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i32, double } asm "xxsldwi ${0:x},${0:x},${0:x},3;\0Axscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
+// CHECK-BE: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i32, double } asm "xscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
+// CHECK-P10: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i32, double } asm "xxsldwi ${0:x},${0:x},${0:x},3;\0Axscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
+// CHECK: extractvalue { <4 x float>, i32, double } %[[VEC]], 0
+// CHECK: extractvalue { <4 x float>, i32, double } %[[VEC]], 1
+// CHECK: extractvalue { <4 x float>, i32, double } %[[VEC]], 2
 
 // CHECK-LABEL: define available_externally i64 @_mm_cvtss_si64
 // CHECK-LE: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i64, double } asm "xxsldwi ${0:x},${0:x},${0:x},3;\0Axscvspdp ${2:x},${0:x};\0Afctid  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
@@ -681,9 +684,11 @@
 // CHECK-LABEL: define available_externally signext i32 @_mm_movemask_ps
 // CHECK-LE: call <2 x i64> @vec_vbpermq(unsigned char vector[16], unsigned char vector[16])(<16 x i8> noundef %{{[0-9a-zA-Z_.]+}}, <16 x i8> noundef bitcast (<4 x i32>  to <16 x i8>))
 // CHECK-LE: extractelement <2 x i64> %{{[0-9a-zA-Z_.]+}}, i32 1
+// CHECK-LE: trunc i64 %[[EXT]] to i32
 // CHECK-BE: call <2 x i64> @vec_vbpermq(unsigned char vector[16], unsigned char vector[16])(<16 x i8> noundef %{{[0-9a-zA-Z_.]+}}, <16 x i8> noundef bitcast (<4 x i32>  to <16 x i8>))
 // CHECK-BE: %[[EXT:[0-9a-zA-Z_.]+]] = extractelement <2 x i64> %{{[0-9a-zA-Z_.]+}}, i32 0
-// CHECK: trunc i64 %[[EXT]] to i32
+// CHECK-BE: trunc i64 %[[EXT]] to i32
+// CHECK-P10: call zeroext i32 @vec_extractm(unsigned int vector[4])(<4 x i32> noundef %{{[0-9a-zA-Z_.]+}})
 
 void __attribute__((noinline))
 test_alt_name_move() {
Index: cl

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

2022-03-24 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, saudi.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

One goal of the ad-hoc command line argument parsing in `clang-scan-deps` is to 
get the last output path value.

Currently, the algorithm walks the arguments in reverse and identifies 
potention output path arguments.

Interestingly, in `clang-cl` mode, the output path can be specified in multiple 
ways. For example `/o /opt/build` and `/o/opt/build` are equivalent. The parser 
currently fails to correctly parse the former. It considers the value 
(`/opt/build/`) to be a shorthand for `/o pt/build`. It doesn't look at the 
preceding `/o`.

This patch simplifies the algorithm by doing forward iteration and fixes the 
bug by correctly handling separate `/o` argument.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122385

Files:
  clang/test/ClangScanDeps/cl-output.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -470,27 +470,29 @@
   llvm::sys::path::stem(Args[0]).contains_insensitive("clang-cl") 
||
   llvm::is_contained(Args, "--driver-mode=cl");
 
-  // Reverse scan, starting at the end or at the element before "--".
-  auto R = std::make_reverse_iterator(FlagsEnd);
-  for (auto I = R, E = Args.rend(); I != E; ++I) {
+  for (auto I = Args.begin(); I != FlagsEnd; ++I) {
 StringRef Arg = *I;
 if (ClangCLMode) {
   // Ignore arguments that are preceded by "-Xclang".
-  if ((I + 1) != E && I[1] == "-Xclang")
-continue;
-  if (LastO.empty()) {
-// With clang-cl, the output obj file can be specified with
-// "/opath", "/o path", "/Fopath", and the dash counterparts.
-// Also, clang-cl adds ".obj" extension if none is found.
-if ((Arg == "-o" || Arg == "/o") && I != R)
-  LastO = I[-1]; // Next argument (reverse iterator)
-else if (Arg.startswith("/Fo") || Arg.startswith("-Fo"))
-  LastO = Arg.drop_front(3).str();
-else if (Arg.startswith("/o") || Arg.startswith("-o"))
-  LastO = Arg.drop_front(2).str();
-
-if (!LastO.empty() && !llvm::sys::path::has_extension(LastO))
-  LastO.append(".obj");
+  if (Arg == "-Xclang")
+++I;
+
+  // With clang-cl, the output obj file can be specified with
+  // "/opath", "/o path", "/Fopath", and the dash counterparts.
+  // Also, clang-cl adds ".obj" extension if none is found.
+  llvm::StringRef CurrentO;
+  if ((Arg == "/o" || Arg == "-o") && I != FlagsEnd)
+CurrentO = *++I;
+  else if (Arg.startswith("/Fo") || Arg.startswith("-Fo"))
+CurrentO = Arg.drop_front(3);
+  else if (Arg.startswith("/o") || Arg.startswith("-o"))
+CurrentO = Arg.drop_front(2);
+
+  if (!CurrentO.empty()) {
+if (!llvm::sys::path::has_extension(CurrentO))
+  LastO = (CurrentO + ".obj").str();
+else
+  LastO = CurrentO.str();
   }
 }
 if (Arg == "-resource-dir")
Index: clang/test/ClangScanDeps/cl-output.c
===
--- clang/test/ClangScanDeps/cl-output.c
+++ clang/test/ClangScanDeps/cl-output.c
@@ -46,6 +46,10 @@
   "file": "DIR/test.c",
   "directory": "DIR",
   "command": "clang-cl /c -o DIR/test.o -o DIR/last.o -- DIR/test.c"
+},{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang-cl /c /o /opt/test.o -- DIR/test.c"
 }]
 
 //--- test.c
@@ -81,7 +85,9 @@
 // Check that the last argument specifying the output path wins.
 //
 // RUN: sed -e "s|DIR|%/t|g" %t/last-arg-cdb.json.template > 
%t/last-arg-cdb.json
-// RUN: clang-scan-deps -compilation-database %t/last-arg-cdb.json > 
%t/last-arg-result.d
+// RUN: clang-scan-deps -compilation-database %t/last-arg-cdb.json -j 1 > 
%t/last-arg-result.d
 // RUN: cat %t/last-arg-result.d | sed 's:\?:/:g' | FileCheck %s 
-DPREFIX=%/t --check-prefix=CHECK-LAST
 // CHECK-LAST:  [[PREFIX]]/last.o:
 // CHECK-LAST-NEXT:   [[PREFIX]]/test.c
+// CHECK-LAST-NEXT: /opt/test.o:
+// CHECK-LAST-NEXT:   [[PREFIX]]/test.c


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -47

[PATCH] D122335: [clang] Emit crash reproduction as a single tar file

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D122335#3404754 , @arichardson 
wrote:

> In D122335#3404358 , @jrtc27 wrote:
>
>> As a developer who often deals with crashes locally this is more annoying; 
>> currently I can just point tools at the shell script and C file in /tmp and 
>> let them go to work reducing, but now I have to also extract the files
>
> +1.
>
> I can see this being helpful for end-users who now just have to provide 
> developers with a single file, but it does make things more awkward for me as 
> a developer. How about an environment variable and/or a CMake option to skip 
> archiving that can be used locally.

I think the idea of a cmake option makes a lot of sense. It may even be worth 
disabling the feature by default when configuring a debug build under the 
assumption those are primarily for compiler developers.


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

https://reviews.llvm.org/D122335

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


[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-24 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Sorry for the breakage and thanks for reporting this! This is a real bug 
uncovered by your build using `/opt`. I have a fix here: D122385 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121812

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


[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D122248#3403734 , @yihanaa wrote:

> What if we don't emit '=' for zero-width bitfield, like this:
>
>   struct Bar {
>   unsigned c : 1;
>   unsigned : 3;
>   unsigned : 0;
>   unsigned b;
>   };
>   
>   struct Bar {
>   unsigned int c : 1 = 0
>   unsigned int   : 3 = 0
>   unsigned int   : 0
>   unsigned int b = 0
>   }
>
> What do you all think?

I like this idea best of all!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

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


[PATCH] D122155: Add warning when eval-method is set in the presence of value unsafe floating-point calculations.

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticFrontendKinds.td:50-53
+def warn_eval_method_setting_via_option_in_value_unsafe_context : Warning<
+"setting the eval method via '-ffp-eval-method' has not effect when 
numeric "
+"results of floating-point calculations aren't value-safe.">,
+InGroup;

zahiraam wrote:
> aaron.ballman wrote:
> > andrew.w.kaylor wrote:
> > > zahiraam wrote:
> > > > aaron.ballman wrote:
> > > > > Unless you have a strong reason for this to be a warning, this seems 
> > > > > like a situation we should diagnose as an error with a much clearer 
> > > > > message.
> > > > May  be @andrew.w.kaylor would weigh in on this?
> > > I was going to say that for the command line option we could just issue a 
> > > warning saying that the later option overrides the earlier, but it's a 
> > > bit complicated to sort out what that would mean if the eval method 
> > > follows a fast-math option and it might not always be what the user 
> > > intended. So, I guess I'd agree that it should be an error.
> > > 
> > > For the case with pragmas, the model I'd follow is the mixing of #pragma 
> > > float_control(except, on) with a fast-math mode or #pragma 
> > > float_control(precise, off) with a non-ignore exception mode. In both 
> > > those cases we issue an error.
> > > For the case with pragmas, the model I'd follow is the mixing of #pragma 
> > > float_control(except, on) with a fast-math mode or #pragma 
> > > float_control(precise, off) with a non-ignore exception mode. In both 
> > > those cases we issue an error.
> > 
> > Good catch, I think that's a good approach as well.
> I think i  will have the issue with the order of appearance of the options on 
> the command line. 
> // RUN: -freciprocal-math -mreassociate   -ffp-eval-method=source 
> and
> // RUN: -mreassociate -ffp-eval-method=source 
> 
> will depend on which order I will test for 
> LangOpts.ApproxFunc/AllowFPReasson/AllowRecip being used or not?
> 
> The run lines above might give the same diagnostic. Unless I do something 
> really complicated to check the order of the options on the command line?
> I think i will have the issue with the order of appearance of the options on 
> the command line.

You shouldn't -- you should be able to test the language options after the 
command line was fully parsed. See `FixupInvocation()` in 
`CompilerInvocation.cpp`.


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

https://reviews.llvm.org/D122155

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


[PATCH] D122077: [InstCombine] Fold (ctpop(X) == 1) | (X == 0) into ctpop(X) < 2

2022-03-24 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

A few changes for tests suggested inline.

There might be some generalization of ctpop analysis that we can make as a 
follow-up patch.
For example, I was looking at a "wrong predicate" combination and noticed that 
we miss possible optimizations like this:
https://alive2.llvm.org/ce/z/RRk_d9




Comment at: llvm/test/Transforms/InstCombine/icmp-or.ll:412
+  %4 = icmp eq <2 x i32> %0, 
+  %5 = or <2 x i1> %4, %3
+  ret <2 x i1> %5

We can swap the operand order of the "or" for more coverage of the commuted 
pattern.



Comment at: llvm/test/Transforms/InstCombine/icmp-or.ll:444
+  %4 = icmp ne i32 %0, 0
+  %5 = and i1 %4, %3
+  ret i1 %5

We are testing the 'and' pattern too now, so it doesn't match the name of the 
file. I think it would be better to add the new tests next to the changed tests 
in `ispow2.ll`.



Comment at: llvm/test/Transforms/InstCombine/icmp-or.ll:478
+
+; negative test - wrong constants
+

Instead of checking the same wrong constant again, it would be better to change 
to a wrong predicate(s).



Comment at: llvm/test/Transforms/InstCombine/icmp-or.ll:382
+  ret i1 %5
+}
+

craig.topper wrote:
> RKSimon wrote:
> > What about if the ctpop has multi uses?
> The ctpop isn't being changed. Does it matter if it has more uses?
> 
> What is interesting is if the (icmp eq (ctpop(x)), 1) has another user other 
> than the or.
This transform only replaces the logic op with a cmp, so I think we want to do 
it even if all of the intermediate values have other uses.
Either way, we should have at least one test where there are other uses of the 
icmps.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122077

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


[PATCH] D120185: [ASTMatchers] Output currently processing match and nodes on crash

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D120185#3403676 , @njames93 wrote:

> In D120185#3403270 , @aaron.ballman 
> wrote:
>
>> I'd like to understand what's happening better rather than land with a 
>> disabled test. Not getting the crash dump in some circumstances could either 
>> be specific to the machine configuration (which would be pretty tricky for 
>> us to solve in a unit test) or it could be something functionally wrong with 
>> the changes (though I would be surprised, tbh).
>
> From what it looks like on the buildbot, the testing infrastructure wasn't 
> recieving any output from stderr.

@thakis -- is it possible your build bot is configured to disable generation of 
crash dumps?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120185

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


[PATCH] D117522: [clang-tidy] Add modernize-macro-to-enum check

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp:47
+CRLF,
+CRLFCR,
+  };

LegalizeAdulthood wrote:
> aaron.ballman wrote:
> > LegalizeAdulthood wrote:
> > > aaron.ballman wrote:
> > > > LegalizeAdulthood wrote:
> > > > > aaron.ballman wrote:
> > > > > > I'm a bit confused by this one as this is not a valid line ending 
> > > > > > (it's either three valid line endings or two valid line endings, 
> > > > > > depending on how you look at it). Can you explain why this is 
> > > > > > needed?
> > > > > It's a state machine, where the states are named for what we've seen 
> > > > > so far and we're looking for //two// consecutive line endings, not 
> > > > > just one.  Does it make sense now?
> > > > Thanks, I understood it was a state machine, but it's a confused one to 
> > > > me. `\r` was the line ending on Mac Classic, I've not seen it used 
> > > > outside of that platform (and I've not seen anyone write code for that 
> > > > platform in a long time). So, to me, the only valid combinations of 
> > > > line endings to worry about are: `LF LF`; `CRLF CRLF`; `CRLF LF`; `LF 
> > > > CRLF`.
> > > > 
> > > > `LF LF` returns false (Nothing -> LF -> return false)
> > > > `CRLF CRLF` returns false (Nothing -> CR -> CRLF -> CRLFCR -> return 
> > > > false)
> > > > `CRLF LF` returns true (Nothing -> CR -> CRLF -> LF -> finish loop)
> > > > `LF CRLF` returns true (Nothing -> LF -> CR -> CRLF -> finish loop)
> > > > 
> > > > (If you also intend to support Mac Classic line endings for some 
> > > > reason, this gets even more complicated.)
> > > I was trying to follow "be liberal in what you accept as input and 
> > > conservative in what you generate as output" maxim.  I can remove the 
> > > `CR` as a line ending case if you think it's too obscure.
> > If Clang supports it as a line ending, we probably should too, but... how 
> > do we handle CRLF vs "I mixed a CR with an LF by accident" kind of inputs? 
> > (Maybe we just treat that as CRLF and if the behavior is bad, the user 
> > shouldn't mix their line endings that way; I think that's defensible.) That 
> > seems to be similar to the scenario that's confusing me above where the 
> > user mixed an LF and CRLF by accident.
> Well, as far as Clang is concerned it's all just "whitespace" that gets eaten 
> up by the preprocessor.  Actually, that gives me a thought.  A preprocessing 
> directive is considered to end at the physical line ending, so I should look 
> to see what sort of characters it considers to "end the line".
> 
> For the accidental mix-up, I'm not going to worry about that here.  Your 
> input files are assumed to be "well formed".  The worst that happens in this 
> check is that two blocks of macros that //look// like they are separated by a 
> blank line are considered as a single clump by this check.
> 
> In other words, the worst that can happen is:
>   - Two clumps of macros are considered together.
>   - One clump of macros that is discarded because it doesn't follow the 
> constraints "taints" an adjacent clump of macros that do follow the 
> constraints.
> 
> Either way, nothing harmful happens to your code.  It will still compile and 
> be syntactically and semantically equivalent to what was there before.
> 
> Actually, that gives me a thought. A preprocessing directive is considered to 
> end at the physical line ending, so I should look to see what sort of 
> characters it considers to "end the line".

All of `\r`, `\n`, `\r\n` I believe (you can double-check in 
`Lexer::LexTokenInternal()`

> Either way, nothing harmful happens to your code. It will still compile and 
> be syntactically and semantically equivalent to what was there before.

Oh, that's a very good point, thank you. I think that's reasonable fallback 
behavior for these weird edge cases.


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

https://reviews.llvm.org/D117522

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


[PATCH] D122338: [OPENMP] Eliminate extra set of simd variant function attribute.

2022-03-24 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11988
 if (isa(E)) {
   Pos = ParamPositions[FD];
 } else {

I would also recommend to replace all `operator []` calls to something that 
does not modify the map, like `find`.


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

https://reviews.llvm.org/D122338

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


[PATCH] D122378: Be more explicit about -fvisibility= documentation

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks for the additional docs!




Comment at: clang/docs/ClangCommandLineReference.rst:2616
 
-.. option:: -fvisibility=
+.. option:: -fvisibility=[default|hidden]
 

From looking at Options.td, it seems there are more visibility values we 
support as synonyms: 
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td#L472

Should we list those and document their nature?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122378

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


[PATCH] D122378: Be more explicit about -fvisibility= documentation

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

Btw, you're changing a generated .rst file. You need to fix up the 
documentation in Options.td which is used to generate this .rst file. I don't 
know that you'll be able to change the option values the way you have, though; 
at least, not without adding some logic to the tabelgen code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122378

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


[clang] 4d20781 - Typo fix in the documentation; NFC

2022-03-24 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-03-24T08:56:14-04:00
New Revision: 4d20781b6935099879f8704fcf93d9cdb83cf3ef

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

LOG: Typo fix in the documentation; NFC

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c63c02bb8941a..d37d3a31fe07a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2827,7 +2827,7 @@ def fvisibility_dllexport_EQ : Joined<["-"], 
"fvisibility-dllexport=">, Group, 
"DefaultVisibility">,
   ShouldParseIf;
 def fvisibility_nodllstorageclass_EQ : Joined<["-"], 
"fvisibility-nodllstorageclass=">, Group, Flags<[CC1Option]>,
-  HelpText<"The visibility for defintiions without an explicit DLL export 
class [-fvisibility-from-dllstorageclass]">,
+  HelpText<"The visibility for definitions without an explicit DLL export 
class [-fvisibility-from-dllstorageclass]">,
   MarshallingInfoVisibility, 
"HiddenVisibility">,
   ShouldParseIf;
 def fvisibility_externs_dllimport_EQ : Joined<["-"], 
"fvisibility-externs-dllimport=">, Group, Flags<[CC1Option]>,



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


[clang] de867c6 - [clang] Reformat

2022-03-24 Thread Nathan Sidwell via cfe-commits

Author: Nathan Sidwell
Date: 2022-03-24T05:56:23-07:00
New Revision: de867c6d6ed86851dcd0f9de1154db3d42a0ad63

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

LOG: [clang] Reformat

Reformat some misindentation that is coincidentally close to a piece
being worked on.

Reviewed By: dblaikie

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

Added: 


Modified: 
clang/lib/Index/USRGeneration.cpp

Removed: 




diff  --git a/clang/lib/Index/USRGeneration.cpp 
b/clang/lib/Index/USRGeneration.cpp
index 41edd431dd5b8..129114ebfaedc 100644
--- a/clang/lib/Index/USRGeneration.cpp
+++ b/clang/lib/Index/USRGeneration.cpp
@@ -549,22 +549,22 @@ void USRGenerator::VisitTagDecl(const TagDecl *D) {
 if (const TypedefNameDecl *TD = D->getTypedefNameForAnonDecl()) {
   Buf[off] = 'A';
   Out << '@' << *TD;
-}
-  else {
-if (D->isEmbeddedInDeclarator() && !D->isFreeStanding()) {
-  printLoc(Out, D->getLocation(), Context->getSourceManager(), true);
 } else {
-  Buf[off] = 'a';
-  if (auto *ED = dyn_cast(D)) {
-// Distinguish USRs of anonymous enums by using their first enumerator.
-auto enum_range = ED->enumerators();
-if (enum_range.begin() != enum_range.end()) {
-  Out << '@' << **enum_range.begin();
+  if (D->isEmbeddedInDeclarator() && !D->isFreeStanding()) {
+printLoc(Out, D->getLocation(), Context->getSourceManager(), true);
+  } else {
+Buf[off] = 'a';
+if (auto *ED = dyn_cast(D)) {
+  // Distinguish USRs of anonymous enums by using their first
+  // enumerator.
+  auto enum_range = ED->enumerators();
+  if (enum_range.begin() != enum_range.end()) {
+Out << '@' << **enum_range.begin();
+  }
 }
   }
 }
   }
-  }
 
   // For a class template specialization, mangle the template arguments.
   if (const ClassTemplateSpecializationDecl *Spec



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


[PATCH] D122314: [clang] Reformat

2022-03-24 Thread Nathan Sidwell via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGde867c6d6ed8: [clang] Reformat (authored by urnathan).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122314

Files:
  clang/lib/Index/USRGeneration.cpp


Index: clang/lib/Index/USRGeneration.cpp
===
--- clang/lib/Index/USRGeneration.cpp
+++ clang/lib/Index/USRGeneration.cpp
@@ -549,22 +549,22 @@
 if (const TypedefNameDecl *TD = D->getTypedefNameForAnonDecl()) {
   Buf[off] = 'A';
   Out << '@' << *TD;
-}
-  else {
-if (D->isEmbeddedInDeclarator() && !D->isFreeStanding()) {
-  printLoc(Out, D->getLocation(), Context->getSourceManager(), true);
 } else {
-  Buf[off] = 'a';
-  if (auto *ED = dyn_cast(D)) {
-// Distinguish USRs of anonymous enums by using their first enumerator.
-auto enum_range = ED->enumerators();
-if (enum_range.begin() != enum_range.end()) {
-  Out << '@' << **enum_range.begin();
+  if (D->isEmbeddedInDeclarator() && !D->isFreeStanding()) {
+printLoc(Out, D->getLocation(), Context->getSourceManager(), true);
+  } else {
+Buf[off] = 'a';
+if (auto *ED = dyn_cast(D)) {
+  // Distinguish USRs of anonymous enums by using their first
+  // enumerator.
+  auto enum_range = ED->enumerators();
+  if (enum_range.begin() != enum_range.end()) {
+Out << '@' << **enum_range.begin();
+  }
 }
   }
 }
   }
-  }
 
   // For a class template specialization, mangle the template arguments.
   if (const ClassTemplateSpecializationDecl *Spec


Index: clang/lib/Index/USRGeneration.cpp
===
--- clang/lib/Index/USRGeneration.cpp
+++ clang/lib/Index/USRGeneration.cpp
@@ -549,22 +549,22 @@
 if (const TypedefNameDecl *TD = D->getTypedefNameForAnonDecl()) {
   Buf[off] = 'A';
   Out << '@' << *TD;
-}
-  else {
-if (D->isEmbeddedInDeclarator() && !D->isFreeStanding()) {
-  printLoc(Out, D->getLocation(), Context->getSourceManager(), true);
 } else {
-  Buf[off] = 'a';
-  if (auto *ED = dyn_cast(D)) {
-// Distinguish USRs of anonymous enums by using their first enumerator.
-auto enum_range = ED->enumerators();
-if (enum_range.begin() != enum_range.end()) {
-  Out << '@' << **enum_range.begin();
+  if (D->isEmbeddedInDeclarator() && !D->isFreeStanding()) {
+printLoc(Out, D->getLocation(), Context->getSourceManager(), true);
+  } else {
+Buf[off] = 'a';
+if (auto *ED = dyn_cast(D)) {
+  // Distinguish USRs of anonymous enums by using their first
+  // enumerator.
+  auto enum_range = ED->enumerators();
+  if (enum_range.begin() != enum_range.end()) {
+Out << '@' << **enum_range.begin();
+  }
 }
   }
 }
   }
-  }
 
   // For a class template specialization, mangle the template arguments.
   if (const ClassTemplateSpecializationDecl *Spec
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D122248#3405062 , @aaron.ballman 
wrote:

> In D122248#3403734 , @yihanaa wrote:
>
>> What if we don't emit '=' for zero-width bitfield, like this:
>>
>>   struct Bar {
>>   unsigned c : 1;
>>   unsigned : 3;
>>   unsigned : 0;
>>   unsigned b;
>>   };
>>   
>>   struct Bar {
>>   unsigned int c : 1 = 0
>>   unsigned int   : 3 = 0
>>   unsigned int   : 0
>>   unsigned int b = 0
>>   }
>>
>> What do you all think?
>
> I like this idea best of all!

Agreed!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

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


[PATCH] D122303: [pseudo] Sort nonterminals based on their reduction order.

2022-03-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 417902.
hokein marked 5 inline comments as done.
hokein added a comment.

address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122303

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
  clang-tools-extra/pseudo/lib/GrammarBNF.cpp
  clang-tools-extra/pseudo/test/lr-build-basic.test
  clang-tools-extra/pseudo/test/lr-build-conflicts.test
  clang-tools-extra/pseudo/unittests/GrammarTest.cpp

Index: clang-tools-extra/pseudo/unittests/GrammarTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GrammarTest.cpp
+++ clang-tools-extra/pseudo/unittests/GrammarTest.cpp
@@ -44,6 +44,16 @@
 return 0;
   }
 
+  RuleID ruleFor(llvm::StringRef NonterminalName) const {
+auto RuleRange = G->table().Nonterminals[id(NonterminalName)].RuleRange;
+if (RuleRange.End - RuleRange.Start == 1)
+  return G->table().Nonterminals[id(NonterminalName)].RuleRange.Start;
+ADD_FAILURE() << "Expected a single rule for " << NonterminalName
+  << ", but it has " << RuleRange.End - RuleRange.Start
+  << " rule!\n";
+return 0;
+  }
+
 protected:
   std::unique_ptr G;
   std::vector Diags;
@@ -74,6 +84,21 @@
Sequence(id("INT"), id(";";
 }
 
+TEST_F(GrammarTest, RuleIDSorted) {
+  build(R"bnf(
+_ := x
+
+x := y
+y := z
+z := IDENTIFIER
+  )bnf");
+  ASSERT_TRUE(Diags.empty());
+
+  EXPECT_LT(ruleFor("z"), ruleFor("y"));
+  EXPECT_LT(ruleFor("y"), ruleFor("x"));
+  EXPECT_LT(ruleFor("x"), ruleFor("_"));
+}
+
 TEST_F(GrammarTest, Diagnostics) {
   build(R"cpp(
 _ := ,_opt
@@ -82,6 +107,9 @@
 _ := IDENFIFIE # a typo of the terminal IDENFITIER
 
 invalid
+# cycle
+a := b
+b := a
   )cpp");
 
   EXPECT_EQ(G->startSymbol(), id("_"));
@@ -91,7 +119,8 @@
  "No rules for nonterminal: undefined-sym",
  "Failed to parse 'invalid': no separator :=",
  "Token-like name IDENFIFIE is used as a nonterminal",
- "No rules for nonterminal: IDENFIFIE"));
+ "No rules for nonterminal: IDENFIFIE",
+ "The grammar contains a cycle involving symbol a"));
 }
 
 TEST_F(GrammarTest, FirstAndFollowSets) {
Index: clang-tools-extra/pseudo/test/lr-build-conflicts.test
===
--- clang-tools-extra/pseudo/test/lr-build-conflicts.test
+++ clang-tools-extra/pseudo/test/lr-build-conflicts.test
@@ -5,8 +5,8 @@
 # RUN: clang-pseudo -grammar %s -print-graph | FileCheck %s --check-prefix=GRAPH
 #  GRAPH: States
 # GRAPH-NEXT: State 0
-# GRAPH-NEXT: _ :=  • expr
 # GRAPH-NEXT: expr :=  • expr - expr
+# GRAPH-NEXT: _ :=  • expr
 # GRAPH-NEXT: expr :=  • IDENTIFIER
 # GRAPH-NEXT: State 1
 # GRAPH-NEXT: _ := expr • 
@@ -42,6 +42,6 @@
 # TABLE-NEXT: 'IDENTIFIER': shift state 2
 # TABLE-NEXT: 'expr': go to state 4
 # TABLE-NEXT: State 4
-# TABLE-NEXT: 'EOF': reduce by rule 2 'expr := expr - expr'
+# TABLE-NEXT: 'EOF': reduce by rule 0 'expr := expr - expr'
 # TABLE-NEXT: '-': shift state 3
-# TABLE-NEXT: '-': reduce by rule 2 'expr := expr - expr'
+# TABLE-NEXT: '-': reduce by rule 0 'expr := expr - expr'
Index: clang-tools-extra/pseudo/test/lr-build-basic.test
===
--- clang-tools-extra/pseudo/test/lr-build-basic.test
+++ clang-tools-extra/pseudo/test/lr-build-basic.test
@@ -26,4 +26,4 @@
 # TABLE-NEXT: State 2
 # TABLE-NEXT: 'EOF': reduce by rule 1 'expr := id'
 # TABLE-NEXT: State 3
-# TABLE-NEXT: 'EOF': reduce by rule 2 'id := IDENTIFIER'
+# TABLE-NEXT: 'EOF': reduce by rule 0 'id := IDENTIFIER'
Index: clang-tools-extra/pseudo/lib/GrammarBNF.cpp
===
--- clang-tools-extra/pseudo/lib/GrammarBNF.cpp
+++ clang-tools-extra/pseudo/lib/GrammarBNF.cpp
@@ -9,9 +9,11 @@
 #include "clang-pseudo/Grammar.h"
 #include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/FormatVariadic.h"
 #include 
+#include 
 
 namespace clang {
 namespace pseudo {
@@ -87,23 +89,75 @@
 }
 assert(T->Rules.size() < (1 << RuleBits) &&
"Too many rules to fit in RuleID bits!");
-llvm::sort(T->Rules, [](const Rule &Left, const Rule &Right) {
-  // Sorted by the Target.
-  return std::tie(Left.Target, Left.Size) <
- std::tie(Right.Target, Right.Size);
-});
-RuleID RulePos = 0;
+const auto &SymbolOrder = getTopologicalOrder(T.get());
+llvm::stable_sort(
+T->Rules, [&SymbolOrder](const Rule &Left, const Rule &Right) {
+   

[PATCH] D122303: [pseudo] Sort nonterminals based on their reduction order.

2022-03-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/pseudo/lib/GrammarBNF.cpp:147
+  VisitStates[SID] = Visiting;
+  auto It = llvm::partition_point(
+  Dependencies, [&SID](const std::pair &D) {

sammccall wrote:
> this is more tersely `llvm::lower_bound(Dependencies, {SID, 0})`, making use 
> of the fact that `std::less` will do what we want
> 
> And with the inline lambda is gone, it seems more idiomatic as a for loop:
> ```
> for (auto It = llvm::lower_bound(...); It != Dependencies.end() && It->first 
> == SID; ++It)
>   DFS(It->second);
> ```
thanks, this is a nice suggestion.



Comment at: clang-tools-extra/pseudo/lib/GrammarBNF.cpp:156
+  VisitStates[SID] = Visited;
+  Order.push_back(SID);
+};

sammccall wrote:
> Instead of building up the permutation array and then inverting it 
> afterwards, maybe directly `Result[SID] = NextKey++;` here?
> 
> (Having pre-sized the vector)
this is a smart suggestion, but it seems too smart, I find the current way is 
easier to understand (we first build the top order, and revert it secondly).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122303

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


[PATCH] D122394: [C++20][Modules] Correct an assert for modules-ts.

2022-03-24 Thread Iain Sandoe via Phabricator via cfe-commits
iains created this revision.
Herald added a project: All.
iains added a reviewer: urnathan.
iains published this revision for review.
iains added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

somewhat on the trivial side.


When adding the support for modules partitions we added an assert that the
actual status of Global Module Fragments matches the state machine that is
driven by the module; keyword.

That does not apply to the modules-ts case, where there is an implicit GMF.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122394

Files:
  clang/lib/Sema/SemaModule.cpp


Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -173,7 +173,7 @@
   ModuleScopes.back().Module->Kind == Module::GlobalModuleFragment)
 GlobalModuleFragment = ModuleScopes.back().Module;
 
-  assert((!getLangOpts().CPlusPlusModules ||
+  assert((!getLangOpts().CPlusPlusModules || getLangOpts().ModulesTS ||
   SeenGMF == (bool)GlobalModuleFragment) &&
  "mismatched global module state");
 


Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -173,7 +173,7 @@
   ModuleScopes.back().Module->Kind == Module::GlobalModuleFragment)
 GlobalModuleFragment = ModuleScopes.back().Module;
 
-  assert((!getLangOpts().CPlusPlusModules ||
+  assert((!getLangOpts().CPlusPlusModules || getLangOpts().ModulesTS ||
   SeenGMF == (bool)GlobalModuleFragment) &&
  "mismatched global module state");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-03-24 Thread Sylvain Audi via Phabricator via cfe-commits
saudi added a comment.

Nice! It's much more straightforward now, the reverse iteration was pretty 
confusing.
Thanks!




Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:478
+  if (Arg == "-Xclang")
+++I;
+

A test for boundary (`I+1 != FlagsEnd`) will be needed here, to avoid an 
infinite loop in the case `-Xclang` is the last arg.

I think it would be worth doing `continue` here, both because `Arg`'s value is 
`-Xclang`, which won't be used in this iteration, and also it is a bit 
confusing as `Arg` has now represents `*(I-1)` instead of `*I`






Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:483
+  // Also, clang-cl adds ".obj" extension if none is found.
+  llvm::StringRef CurrentO;
+  if ((Arg == "/o" || Arg == "-o") && I != FlagsEnd)

`llvm::` is unnecessary here, as it's not used for other `StringRef` in this 
file



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:484
+  llvm::StringRef CurrentO;
+  if ((Arg == "/o" || Arg == "-o") && I != FlagsEnd)
+CurrentO = *++I;

The test for the end should be on `I+1`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122385

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


[PATCH] D122341: Fix a crash with variably-modified parameter types in a naked function

2022-03-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D122341#3405008 , @aaron.ballman 
wrote:

> In D122341#3403587 , @erichkeane 
> wrote:
>
>> Other than this 1 thing, LGTM.  I DO find myself wondering how much of the 
>> CXXMethodDecl bit in the branch above is valid for 'naked' as well.  If it 
>> ISN'T we might consider  moving this loop AND that to EmitFunctionPrologue.
>
> There's a different kind of bug there. MSVC disallows using the `naked` 
> attribute on a member function. Clang doesn't enforce this: 
> https://godbolt.org/z/6jKGbzYTq GCC has no such restriction, but GCC doesn't 
> have many diagnostics in this area anyway. We may want to reconsider whether 
> allowing the naked attribute on a non static member function is a good idea. 
> We probably don't want to allow it in MS compatibility mode at the very 
> least. But I think this can be a change for another day. WDYT?

Ah! I didn't know the bit about MSVC! I think that makes it even more 
interesting.  From what I can tell however, GCC actually DOES 'do the right 
thing' with member functions, though the motivation for them is somewhat 
suspicious.  I definitely agree we don't want to allow it in MS Compat mode 
(and agree that is a different patch).  As for in GCC mode, a part of me wants 
to just DO it and see what the fallout is.  The only value I can see for these 
as non-static member functions is in a template (or perhaps as a virtual 
function? *shudders*), and I don't see much overlap in the usage there.




Comment at: clang/test/CodeGen/attr-naked.c:31
+  // CHECK: define{{.*}} void @t4(i32 noundef %0, i8* noundef %1)
+  // CHECK-NEXT: entry:
+  // CHECK-NEXT: unreachable

so in the test, both 'entry' and '%0'/'%1' above are unstable names.  You might 
want to replace both with wildcards.  THOUGH, I see other parts of this test 
have the param names, so IDK?  Either way, 'entry' isn't necessarily a stable 
label.


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

https://reviews.llvm.org/D122341

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


[PATCH] D122303: [pseudo] Sort nonterminals based on their reduction order.

2022-03-24 Thread Haojian Wu 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 rGf383b88d8214: [pseudo] Sort nonterminals based on their 
reduction order. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122303

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
  clang-tools-extra/pseudo/lib/GrammarBNF.cpp
  clang-tools-extra/pseudo/test/lr-build-basic.test
  clang-tools-extra/pseudo/test/lr-build-conflicts.test
  clang-tools-extra/pseudo/unittests/GrammarTest.cpp

Index: clang-tools-extra/pseudo/unittests/GrammarTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GrammarTest.cpp
+++ clang-tools-extra/pseudo/unittests/GrammarTest.cpp
@@ -44,6 +44,16 @@
 return 0;
   }
 
+  RuleID ruleFor(llvm::StringRef NonterminalName) const {
+auto RuleRange = G->table().Nonterminals[id(NonterminalName)].RuleRange;
+if (RuleRange.End - RuleRange.Start == 1)
+  return G->table().Nonterminals[id(NonterminalName)].RuleRange.Start;
+ADD_FAILURE() << "Expected a single rule for " << NonterminalName
+  << ", but it has " << RuleRange.End - RuleRange.Start
+  << " rule!\n";
+return 0;
+  }
+
 protected:
   std::unique_ptr G;
   std::vector Diags;
@@ -74,6 +84,21 @@
Sequence(id("INT"), id(";";
 }
 
+TEST_F(GrammarTest, RuleIDSorted) {
+  build(R"bnf(
+_ := x
+
+x := y
+y := z
+z := IDENTIFIER
+  )bnf");
+  ASSERT_TRUE(Diags.empty());
+
+  EXPECT_LT(ruleFor("z"), ruleFor("y"));
+  EXPECT_LT(ruleFor("y"), ruleFor("x"));
+  EXPECT_LT(ruleFor("x"), ruleFor("_"));
+}
+
 TEST_F(GrammarTest, Diagnostics) {
   build(R"cpp(
 _ := ,_opt
@@ -82,6 +107,9 @@
 _ := IDENFIFIE # a typo of the terminal IDENFITIER
 
 invalid
+# cycle
+a := b
+b := a
   )cpp");
 
   EXPECT_EQ(G->startSymbol(), id("_"));
@@ -91,7 +119,8 @@
  "No rules for nonterminal: undefined-sym",
  "Failed to parse 'invalid': no separator :=",
  "Token-like name IDENFIFIE is used as a nonterminal",
- "No rules for nonterminal: IDENFIFIE"));
+ "No rules for nonterminal: IDENFIFIE",
+ "The grammar contains a cycle involving symbol a"));
 }
 
 TEST_F(GrammarTest, FirstAndFollowSets) {
Index: clang-tools-extra/pseudo/test/lr-build-conflicts.test
===
--- clang-tools-extra/pseudo/test/lr-build-conflicts.test
+++ clang-tools-extra/pseudo/test/lr-build-conflicts.test
@@ -5,8 +5,8 @@
 # RUN: clang-pseudo -grammar %s -print-graph | FileCheck %s --check-prefix=GRAPH
 #  GRAPH: States
 # GRAPH-NEXT: State 0
-# GRAPH-NEXT: _ :=  • expr
 # GRAPH-NEXT: expr :=  • expr - expr
+# GRAPH-NEXT: _ :=  • expr
 # GRAPH-NEXT: expr :=  • IDENTIFIER
 # GRAPH-NEXT: State 1
 # GRAPH-NEXT: _ := expr • 
@@ -42,6 +42,6 @@
 # TABLE-NEXT: 'IDENTIFIER': shift state 2
 # TABLE-NEXT: 'expr': go to state 4
 # TABLE-NEXT: State 4
-# TABLE-NEXT: 'EOF': reduce by rule 2 'expr := expr - expr'
+# TABLE-NEXT: 'EOF': reduce by rule 0 'expr := expr - expr'
 # TABLE-NEXT: '-': shift state 3
-# TABLE-NEXT: '-': reduce by rule 2 'expr := expr - expr'
+# TABLE-NEXT: '-': reduce by rule 0 'expr := expr - expr'
Index: clang-tools-extra/pseudo/test/lr-build-basic.test
===
--- clang-tools-extra/pseudo/test/lr-build-basic.test
+++ clang-tools-extra/pseudo/test/lr-build-basic.test
@@ -26,4 +26,4 @@
 # TABLE-NEXT: State 2
 # TABLE-NEXT: 'EOF': reduce by rule 1 'expr := id'
 # TABLE-NEXT: State 3
-# TABLE-NEXT: 'EOF': reduce by rule 2 'id := IDENTIFIER'
+# TABLE-NEXT: 'EOF': reduce by rule 0 'id := IDENTIFIER'
Index: clang-tools-extra/pseudo/lib/GrammarBNF.cpp
===
--- clang-tools-extra/pseudo/lib/GrammarBNF.cpp
+++ clang-tools-extra/pseudo/lib/GrammarBNF.cpp
@@ -9,9 +9,11 @@
 #include "clang-pseudo/Grammar.h"
 #include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/FormatVariadic.h"
 #include 
+#include 
 
 namespace clang {
 namespace pseudo {
@@ -87,23 +89,75 @@
 }
 assert(T->Rules.size() < (1 << RuleBits) &&
"Too many rules to fit in RuleID bits!");
-llvm::sort(T->Rules, [](const Rule &Left, const Rule &Right) {
-  // Sorted by the Target.
-  return std::tie(Left.Target, Left.Size) <
- std::tie(Right.Target, Right.Size);
-});
-RuleID RulePos = 0;
+const auto &SymbolOrder = getTopologicalOr

[clang-tools-extra] f383b88 - [pseudo] Sort nonterminals based on their reduction order.

2022-03-24 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-03-24T14:30:12+01:00
New Revision: f383b88d8214dc8f2d8bc9521c3ddd1c4454927f

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

LOG: [pseudo] Sort nonterminals based on their reduction order.

Reductions need to be performed in a careful order in GLR parser, to
make sure we gather all alternatives before creating an ambigous forest
node.

This patch encodes the nonterminal order into the rule id, so that we
can efficiently to determinal ordering of reductions in GLR parser.

This patch also abstracts to a TestGrammar, which is shared among tests.

This is a part of the GLR parser, https://reviews.llvm.org/D121368,
https://reviews.llvm.org/D121150

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

Added: 


Modified: 
clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
clang-tools-extra/pseudo/lib/GrammarBNF.cpp
clang-tools-extra/pseudo/test/lr-build-basic.test
clang-tools-extra/pseudo/test/lr-build-conflicts.test
clang-tools-extra/pseudo/unittests/GrammarTest.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
index 106734b1b022a..46e8fcbcafa2c 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
@@ -165,8 +165,15 @@ struct GrammarTable {
 } RuleRange;
   };
 
-  // The rules are sorted (and thus grouped) by target symbol.
-  // RuleID is the index of the vector.
+  // RuleID is an index into this table of rule definitions.
+  //
+  // Rules with the same target symbol (LHS) are grouped into a single range.
+  // The relative order of 
diff erent target symbols is *not* by SymbolID, but
+  // rather a topological sort: if S := T then the rules producing T have lower
+  // RuleIDs than rules producing S.
+  // (This strange order simplifies the GLR parser: for a given token range, if
+  // we reduce in increasing RuleID order then we need never backtrack --
+  // prerequisite reductions are reached before dependent ones).
   std::vector Rules;
   // A table of terminals (aka tokens). It corresponds to the clang::Token.
   // clang::tok::TokenKind is the index of the table.

diff  --git a/clang-tools-extra/pseudo/lib/GrammarBNF.cpp 
b/clang-tools-extra/pseudo/lib/GrammarBNF.cpp
index 57ed2ca7c8f0b..7ca5bc1a90221 100644
--- a/clang-tools-extra/pseudo/lib/GrammarBNF.cpp
+++ b/clang-tools-extra/pseudo/lib/GrammarBNF.cpp
@@ -9,9 +9,11 @@
 #include "clang-pseudo/Grammar.h"
 #include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/FormatVariadic.h"
 #include 
+#include 
 
 namespace clang {
 namespace pseudo {
@@ -87,23 +89,75 @@ class GrammarBuilder {
 }
 assert(T->Rules.size() < (1 << RuleBits) &&
"Too many rules to fit in RuleID bits!");
-llvm::sort(T->Rules, [](const Rule &Left, const Rule &Right) {
-  // Sorted by the Target.
-  return std::tie(Left.Target, Left.Size) <
- std::tie(Right.Target, Right.Size);
-});
-RuleID RulePos = 0;
+const auto &SymbolOrder = getTopologicalOrder(T.get());
+llvm::stable_sort(
+T->Rules, [&SymbolOrder](const Rule &Left, const Rule &Right) {
+  // Sorted by the topological order of the nonterminal Target.
+  return SymbolOrder[Left.Target] < SymbolOrder[Right.Target];
+});
 for (SymbolID SID = 0; SID < T->Nonterminals.size(); ++SID) {
-  RuleID Start = RulePos;
-  while (RulePos < T->Rules.size() && T->Rules[RulePos].Target == SID)
-++RulePos;
-  T->Nonterminals[SID].RuleRange = {Start, RulePos};
+  auto StartIt = llvm::partition_point(T->Rules, [&](const Rule &R) {
+return SymbolOrder[R.Target] < SymbolOrder[SID];
+  });
+  RuleID Start = StartIt - T->Rules.begin();
+  RuleID End = Start;
+  while (End < T->Rules.size() && T->Rules[End].Target == SID)
+++End;
+  T->Nonterminals[SID].RuleRange = {Start, End};
 }
 auto G = std::make_unique(std::move(T));
 diagnoseGrammar(*G);
 return G;
   }
 
+  // Gets topological order for nonterminal symbols.
+  //
+  // The topological order is defined as: if a *single* nonterminal A produces
+  // (or transitively) a nonterminal B (that said, there is a production rule
+  // B := A), then A is less than B.
+  //
+  // It returns the sort key for each symbol, the array is indexed by SymbolID.
+  std::vector getTopologicalOrder(GrammarTable *T) {
+std::vector> Dependencies;
+for (const auto &Rule : T->Rules) {
+  // if A := B, A depends on B.
+  if (Rule.Size == 1 && pseudo::isNonterminal(Rule.Seque

[PATCH] D104439: [analyzer][NFC] Demonstrate a move from the analyzer-configs `.def` file to a TableGen file

2022-03-24 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added reviewers: jansvoboda11, myhsu.
steakhal added subscribers: jansvoboda11, myhsu.
steakhal added a comment.
Herald added a project: All.

> We can put all the acceptable values in the help text AND generate the enum 
> class WITHOUT any redundancy.

+1

> While not demonstrated, it'd be easy to add help texts to the enum values as 
> well.

Ah yes! We should take it one step further. Generate user-facing documentation 
from the descriptions embedded in the `td file.
We should really have a doc page for analyzer configs as well, similarly to the 
one we have for checkers.
That being said, I would vote for generating the checker's user-facing docs as 
well, from the `Checkers.td` file. That way they would be always in sync and we 
could easily check if an option/checker is not documented.`

> Automatic initialization and validation of the user input can be done by 
> marshaling, but its so strongly tied to regular llvm/clang flags, I'd rather 
> use it as a source of inspiration.

I think we can introduce //marshaling// and `cl::opts` in a subsequent patch if 
we need to, but I cannot immediately foresee the impact of any of these.

Let me invite @myhsu for Tablegen and @jansvoboda11 for marshaling.




Comment at: clang/include/clang/StaticAnalyzer/AnalyzerFlagsBase.td:9
+
+/// Describes ain option type. This is important for validating user supplied
+/// inputs.

typo



Comment at: clang/utils/TableGen/ClangSAConfigsEmitter.cpp:19
+#include "llvm/TableGen/TableGenBackend.h"
+#include 
+#include 

Where do you use `std::map`?



Comment at: clang/utils/TableGen/ClangSAConfigsEmitter.cpp:35-38
+if (DefaultVal == "")
+  OS << "\"\"";
+else
+  OS << "\"" << DefaultVal << "\"";





Comment at: clang/utils/TableGen/ClangSAConfigsEmitter.cpp:43-49
+static SortedRecords getSortedDerivedDefinitions(RecordKeeper &Records,
+ StringRef ClassName) {
+  SortedRecords Ret;
+  for (const Record *R : Records.getAllDerivedDefinitions(ClassName))
+Ret[R->getValueAsString("Name")] = R;
+  return Ret;
+}

How does this return a sorted data structure? `SortedRecords` aliases 
`llvm::StringMap`.



Comment at: clang/utils/TableGen/ClangSAConfigsEmitter.cpp:114
+
+  // Emit enum options. These are string options can only take a select fe
+  // values, and are parsed into enums.

typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104439

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


[clang-tools-extra] 62d5f25 - [pseudo] Introduce parse forest.

2022-03-24 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-03-24T14:47:17+01:00
New Revision: 62d5f254ccd0fc745fceb15a80494ef892db367c

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

LOG: [pseudo] Introduce parse forest.

Parse forest is the output of the GLR parser, it is a tree-like DAG
which presents all possible parse trees without duplicating subparse structures.

This is a patch split from https://reviews.llvm.org/D121150.

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

Added: 
clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
clang-tools-extra/pseudo/lib/Forest.cpp
clang-tools-extra/pseudo/unittests/ForestTest.cpp

Modified: 
clang-tools-extra/pseudo/lib/CMakeLists.txt
clang-tools-extra/pseudo/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/Forest.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
new file mode 100644
index 0..650f9131bd2ea
--- /dev/null
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
@@ -0,0 +1,178 @@
+//===--- Forest.h - Parse forest, the output of the GLR parser ---*- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// A parse forest represents a set of possible parse trees efficiently, it is
+// produced by the GLR parser.
+//
+// Despite the name, its data structure is a tree-like DAG with a single root.
+// Multiple ways to parse the same tokens are presented as an ambiguous node
+// with all possible interpretations as children.
+// Common sub-parses are shared: if two interpretations both parse "1 + 1" as
+// "expr := expr + expr", they will share a Sequence node representing the 
expr.
+//
+//===--===//
+
+#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/Token.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Allocator.h"
+#include 
+
+namespace clang {
+namespace pseudo {
+
+// A node represents ways to parse a sequence of tokens, it interprets a fixed
+// range of tokens as a fixed grammar symbol.
+//
+// There are 
diff erent kinds of nodes, some nodes have "children" (stored in a
+// trailing array) and have pointers to them. "Children" has 
diff erent semantics
+// depending on the node kinds. For an Ambiguous node, it means all
+// possible interpretations; for a Sequence node, it means each symbol on the
+// right hand side of the production rule.
+//
+// Since this is a node in a DAG, a node may have multiple parents. And a node
+// doesn't have parent pointers.
+class alignas(class ForestNode *) ForestNode {
+public:
+  enum Kind : uint8_t {
+// A Terminal node is a single terminal symbol bound to a token.
+Terminal,
+// A Sequence node is a nonterminal symbol parsed from a grammar rule,
+// elements() are the parses of each symbol on the RHS of the rule.
+// If the rule is A := X Y Z, the node is for nonterminal A, and elements()
+// are [X, Y, Z].
+Sequence,
+// An Ambiguous node exposes multiple ways to interpret the code as the
+// same symbol, alternatives() are all possible parses.
+Ambiguous,
+// An Opaque node is a placeholder. It asserts that tokens match a symbol,
+// without saying how.
+// It is used for lazy-parsing (not parsed yet), or error-recovery (invalid
+// code).
+Opaque,
+  };
+  Kind kind() const { return K; }
+
+  SymbolID symbol() const { return Symbol; }
+
+  // The start of the token range, it is a poistion within a token stream.
+  Token::Index startTokenIndex() const { return StartIndex; }
+
+  // Returns the corresponding grammar rule.
+  // REQUIRES: this is a Sequence node.
+  RuleID rule() const {
+assert(kind() == Sequence);
+return Data & ((1 << RuleBits) - 1);
+  }
+  // Returns the parses of each element on the RHS of the rule.
+  // REQUIRES: this is a Sequence node;
+  llvm::ArrayRef elements() const {
+assert(kind() == Sequence);
+return children(Data >> RuleBits);
+  };
+
+  // Returns all possible interpretations of the code.
+  // REQUIRES: this is an Ambiguous node.
+  llvm::ArrayRef alternatives() const {
+assert(kind() == Ambiguous);
+return children(Data);
+  }
+
+  std::string dump(const Grammar &) const;
+  std::string dumpRecursive(const Grammar &, bool Abbreviated = false) const;
+
+private:
+  friend class ForestArena;
+
+  ForestNode(Kind K, SymbolID Symbol, Token::Index StartIndex, uint16_t Data)
+  : StartIndex(StartIndex), K(K), Symbol

[PATCH] D122139: [pseudo] Introduce parse forest.

2022-03-24 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG62d5f254ccd0: [pseudo] Introduce parse forest. (authored by 
hokein).

Changed prior to commit:
  https://reviews.llvm.org/D122139?vs=417225&id=417911#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122139

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
  clang-tools-extra/pseudo/lib/CMakeLists.txt
  clang-tools-extra/pseudo/lib/Forest.cpp
  clang-tools-extra/pseudo/unittests/CMakeLists.txt
  clang-tools-extra/pseudo/unittests/ForestTest.cpp

Index: clang-tools-extra/pseudo/unittests/ForestTest.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/unittests/ForestTest.cpp
@@ -0,0 +1,130 @@
+//===--- ForestTest.cpp - Test Forest dump --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang-pseudo/Forest.h"
+#include "clang-pseudo/Token.h"
+#include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/StringRef.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace clang {
+namespace pseudo {
+namespace {
+
+// FIXME: extract to a TestGrammar class to allow code sharing among tests.
+class ForestTest : public ::testing::Test {
+public:
+  void build(llvm::StringRef BNF) {
+Diags.clear();
+G = Grammar::parseBNF(BNF, Diags);
+  }
+
+  SymbolID symbol(llvm::StringRef Name) const {
+for (unsigned I = 0; I < NumTerminals; ++I)
+  if (G->table().Terminals[I] == Name)
+return tokenSymbol(static_cast(I));
+for (SymbolID ID = 0; ID < G->table().Nonterminals.size(); ++ID)
+  if (G->table().Nonterminals[ID].Name == Name)
+return ID;
+ADD_FAILURE() << "No such symbol found: " << Name;
+return 0;
+  }
+
+  RuleID ruleFor(llvm::StringRef NonterminalName) const {
+auto RuleRange = G->table().Nonterminals[symbol(NonterminalName)].RuleRange;
+if (RuleRange.End - RuleRange.Start == 1)
+  return G->table().Nonterminals[symbol(NonterminalName)].RuleRange.Start;
+ADD_FAILURE() << "Expected a single rule for " << NonterminalName
+  << ", but it has " << RuleRange.End - RuleRange.Start
+  << " rule!\n";
+return 0;
+  }
+
+protected:
+  std::unique_ptr G;
+  std::vector Diags;
+};
+
+TEST_F(ForestTest, DumpBasic) {
+  build(R"cpp(
+_ := add-expression
+add-expression := id-expression + id-expression
+id-expression := IDENTIFIER
+  )cpp");
+  ASSERT_TRUE(Diags.empty());
+  ForestArena Arena;
+  const auto &TS =
+  cook(lex("a + b", clang::LangOptions()), clang::LangOptions());
+
+  auto T = Arena.createTerminals(TS);
+  ASSERT_EQ(T.size(), 3u);
+  const auto *Left = &Arena.createSequence(
+  symbol("id-expression"), ruleFor("id-expression"), {&T.front()});
+  const auto *Right = &Arena.createSequence(symbol("id-expression"),
+ruleFor("id-expression"), {&T[2]});
+
+  const auto *Add =
+  &Arena.createSequence(symbol("add-expression"), ruleFor("add-expression"), {Left, &T[1], Right});
+  EXPECT_EQ(Add->dumpRecursive(*G, true),
+"[  0, end) add-expression := id-expression + id-expression\n"
+"[  0,   1)   id-expression~IDENTIFIER := tok[0]\n"
+"[  1,   2)   + := tok[1]\n"
+"[  2, end)   id-expression~IDENTIFIER := tok[2]\n");
+  EXPECT_EQ(Add->dumpRecursive(*G, false),
+"[  0, end) add-expression := id-expression + id-expression\n"
+"[  0,   1)   id-expression := IDENTIFIER\n"
+"[  0,   1) IDENTIFIER := tok[0]\n"
+"[  1,   2)   + := tok[1]\n"
+"[  2, end)   id-expression := IDENTIFIER\n"
+"[  2, end) IDENTIFIER := tok[2]\n");
+}
+
+TEST_F(ForestTest, DumpAmbiguousAndRefs) {
+  build(R"cpp(
+_ := type
+type := class-type # rule 1
+type := enum-type # rule 2
+class-type := shared-type
+enum-type := shared-type
+shared-type := IDENTIFIER)cpp");
+  ASSERT_TRUE(Diags.empty());
+  ForestArena Arena;
+  const auto &TS = cook(lex("abc", clang::LangOptions()), clang::LangOptions());
+
+  auto Terminals = Arena.createTerminals(TS);
+  ASSERT_EQ(Terminals.size(), 1u);
+
+  const auto *SharedType = &Arena.createSequence(
+  symbol("shared-type"), ruleFor("shared-type"), {Terminals.begin()});
+  const auto *ClassType = &Arena.createSequence(
+  symbol("class-type"), ruleFor("class-type"), {SharedType});
+  const auto *Enumtype = &Arena.createSequence(
+  symbol("enum-type"), ruleFor("enum-type"), {SharedType});
+  const auto *Alternative1 =
+  &Arena.create

[PATCH] D122394: [C++20][Modules] Correct an assert for modules-ts.

2022-03-24 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan added a comment.

Is this because of history that ModulesTS option != p1103 modules?  I thought 
we wanted to make the former become the latter (i.e. ModuleTS is the same as 
CPlusPlusModules)  This seems to be moving in the wrong direction.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122394

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


[PATCH] D122394: [C++20][Modules] Correct an assert for modules-ts.

2022-03-24 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D122394#3405338 , @urnathan wrote:

> Is this because of history that ModulesTS option != p1103 modules?  I thought 
> we wanted to make the former become the latter (i.e. ModuleTS is the same as 
> CPlusPlusModules)  This seems to be moving in the wrong direction.

This is because we are not removing the fmodules-ts flag (nor. at this point, 
the code that it changes) - as I understand things.  So I have now to fix (next 
patch) the problem that we currently generate wrong code for static vars and 
lambdas in modules since the linkage is defaulting to the modules-ts "module 
internal" model.

So, unless we shift priorities such that we take a detour to remove the 
modules-ts support, I need to make this change to avoid the assert firing for 
-fmodules-ts (it seems we have limited testing - since nothing fired until I 
tried to make other changes form my patchset).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122394

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


[clang-tools-extra] 50f4f32 - [clangd] Retain main file fixes attached to diags from preamble

2022-03-24 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-03-24T15:19:25+01:00
New Revision: 50f4f32b56688d8cdeff5cda0982f19863093cd5

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

LOG: [clangd] Retain main file fixes attached to diags from preamble

Clangd ignores fixits if the diagnsotics is outside the main file (e.g.
a note on a declaration from a header), but the fix might still be inside the
main file (e.g. change the function call).

This patch changes the logic to retain fixes that touch main file, if the
diagnostic owning them is still inside main file, even if they are attached to a
note outside the main file.

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

Added: 


Modified: 
clang-tools-extra/clangd/Diagnostics.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index da9167462d685..762906615f323 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -31,6 +31,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -463,7 +464,8 @@ void toLSPDiags(
 
   // Main diagnostic should always refer to a range inside main file. If a
   // diagnostic made it so for, it means either itself or one of its notes is
-  // inside main file.
+  // inside main file. It's also possible that there's a fix in the main file,
+  // but we preserve fixes iff primary diagnostic is in the main file.
   if (D.InsideMainFile) {
 Main.range = D.Range;
   } else {
@@ -701,13 +703,12 @@ void 
StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
 return;
   }
 
-  bool InsideMainFile = isInsideMainFile(Info);
   SourceManager &SM = Info.getSourceManager();
 
   auto FillDiagBase = [&](DiagBase &D) {
 fillNonLocationData(DiagLevel, Info, D);
 
-D.InsideMainFile = InsideMainFile;
+D.InsideMainFile = isInsideMainFile(Info);
 D.Range = diagnosticRange(Info, *LangOpts);
 D.File = std::string(SM.getFilename(Info.getLocation()));
 D.AbsFile = getCanonicalPath(
@@ -719,9 +720,9 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level 
DiagLevel,
   auto AddFix = [&](bool SyntheticMessage) -> bool {
 assert(!Info.getFixItHints().empty() &&
"diagnostic does not have attached fix-its");
-if (!InsideMainFile)
+// No point in generating fixes, if the diagnostic is for a 
diff erent file.
+if (!LastDiag->InsideMainFile)
   return false;
-
 // Copy as we may modify the ranges.
 auto FixIts = Info.getFixItHints().vec();
 llvm::SmallVector Edits;

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp 
b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 97e36dd828b21..097ada51b2e9a 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -22,6 +22,7 @@
 #include "support/Path.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticSema.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
@@ -1680,6 +1681,28 @@ TEST(DiagnosticsTest, IncludeCleaner) {
   EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
 }
 
+TEST(DiagnosticsTest, FixItFromHeader) {
+  llvm::StringLiteral Header(R"cpp(
+void foo(int *);
+void foo(int *, int);)cpp");
+  Annotations Source(R"cpp(
+  /*error-ok*/
+void bar() {
+  int x;
+  $diag[[foo]]($fix[[]]x, 1);
+})cpp");
+  TestTU TU;
+  TU.Code = Source.code().str();
+  TU.HeaderCode = Header.str();
+  EXPECT_THAT(
+  *TU.build().getDiagnostics(),
+  UnorderedElementsAre(AllOf(
+  Diag(Source.range("diag"), "no matching function for call to 'foo'"),
+  withFix(Fix(Source.range("fix"), "&",
+  "candidate function not viable: no known conversion from 
"
+  "'int' to 'int *' for 1st argument; take the address of "
+  "the argument with &");
+}
 } // namespace
 } // namespace clangd
 } // namespace clang



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


[PATCH] D122315: [clangd] Retain main file fixes attached to diags from preamble

2022-03-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG50f4f32b5668: [clangd] Retain main file fixes attached to 
diags from preamble (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122315

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -22,6 +22,7 @@
 #include "support/Path.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticSema.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
@@ -1680,6 +1681,28 @@
   EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
 }
 
+TEST(DiagnosticsTest, FixItFromHeader) {
+  llvm::StringLiteral Header(R"cpp(
+void foo(int *);
+void foo(int *, int);)cpp");
+  Annotations Source(R"cpp(
+  /*error-ok*/
+void bar() {
+  int x;
+  $diag[[foo]]($fix[[]]x, 1);
+})cpp");
+  TestTU TU;
+  TU.Code = Source.code().str();
+  TU.HeaderCode = Header.str();
+  EXPECT_THAT(
+  *TU.build().getDiagnostics(),
+  UnorderedElementsAre(AllOf(
+  Diag(Source.range("diag"), "no matching function for call to 'foo'"),
+  withFix(Fix(Source.range("fix"), "&",
+  "candidate function not viable: no known conversion from 
"
+  "'int' to 'int *' for 1st argument; take the address of "
+  "the argument with &");
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -31,6 +31,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -463,7 +464,8 @@
 
   // Main diagnostic should always refer to a range inside main file. If a
   // diagnostic made it so for, it means either itself or one of its notes is
-  // inside main file.
+  // inside main file. It's also possible that there's a fix in the main file,
+  // but we preserve fixes iff primary diagnostic is in the main file.
   if (D.InsideMainFile) {
 Main.range = D.Range;
   } else {
@@ -701,13 +703,12 @@
 return;
   }
 
-  bool InsideMainFile = isInsideMainFile(Info);
   SourceManager &SM = Info.getSourceManager();
 
   auto FillDiagBase = [&](DiagBase &D) {
 fillNonLocationData(DiagLevel, Info, D);
 
-D.InsideMainFile = InsideMainFile;
+D.InsideMainFile = isInsideMainFile(Info);
 D.Range = diagnosticRange(Info, *LangOpts);
 D.File = std::string(SM.getFilename(Info.getLocation()));
 D.AbsFile = getCanonicalPath(
@@ -719,9 +720,9 @@
   auto AddFix = [&](bool SyntheticMessage) -> bool {
 assert(!Info.getFixItHints().empty() &&
"diagnostic does not have attached fix-its");
-if (!InsideMainFile)
+// No point in generating fixes, if the diagnostic is for a different file.
+if (!LastDiag->InsideMainFile)
   return false;
-
 // Copy as we may modify the ranges.
 auto FixIts = Info.getFixItHints().vec();
 llvm::SmallVector Edits;


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -22,6 +22,7 @@
 #include "support/Path.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticSema.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
@@ -1680,6 +1681,28 @@
   EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
 }
 
+TEST(DiagnosticsTest, FixItFromHeader) {
+  llvm::StringLiteral Header(R"cpp(
+void foo(int *);
+void foo(int *, int);)cpp");
+  Annotations Source(R"cpp(
+  /*error-ok*/
+void bar() {
+  int x;
+  $diag[[foo]]($fix[[]]x, 1);
+})cpp");
+  TestTU TU;
+  TU.Code = Source.code().str();
+  TU.HeaderCode = Header.str();
+  EXPECT_THAT(
+  *TU.build().getDiagnostics(),
+  UnorderedElementsAre(AllOf(
+  Diag(Source.range("diag"), "no matching function for call to 'foo'"),
+  withFix(Fix(Source.range("fix"), "&",
+  "candidate function not viable: no known conversion from "
+  "'int' to 'int *' for 1st argument; take the address of "
+  "the argument with &");
+}
 } // namespace
 } // namespace clangd
 } // nam

[PATCH] D122104: [X86][regcall] Support passing / returning structures

2022-03-24 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

Ping? We have internal request for this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122104

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


[PATCH] D122401: [AVR] Add more devices

2022-03-24 Thread Ben Shi via Phabricator via cfe-commits
benshi001 created this revision.
benshi001 added reviewers: aykevl, dylanmckay.
Herald added subscribers: Jim, hiraditya.
Herald added a project: All.
benshi001 requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, jacquesguan.
Herald added projects: clang, LLVM.

Synchronize device list with avr-gcc 7.3.0 and avrlibc 2.0.0.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122401

Files:
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/test/Driver/avr-link-mcu-family-unimplemented.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/lib/Target/AVR/AVRDevices.td

Index: llvm/lib/Target/AVR/AVRDevices.td
===
--- llvm/lib/Target/AVR/AVRDevices.td
+++ llvm/lib/Target/AVR/AVRDevices.td
@@ -191,6 +191,12 @@
  [FamilyAVR0, FeatureBREAK, FeatureSRAM, FeatureTinyEncoding,
   FeatureSmallStack]>;
 
+def FamilyXMEGA3 : Family<"xmega3",
+  [FamilyAVR0, FeatureLPM, FeatureIJMPCALL,
+   FeatureADDSUBIW, FeatureSRAM, FeatureJMPCALL,
+   FeatureMultiplication, FeatureMOVW, FeatureLPMX,
+   FeatureBREAK]>;
+
 def FamilyXMEGA : Family<"xmega",
  [FamilyAVR0, FeatureLPM, FeatureIJMPCALL,
   FeatureADDSUBIW, FeatureSRAM, FeatureJMPCALL,
@@ -236,7 +242,7 @@
 def : Device<"avr6", FamilyAVR6, ELFArchAVR6>;
 def : Device<"avrxmega1", FamilyXMEGA, ELFArchXMEGA1>;
 def : Device<"avrxmega2", FamilyXMEGA, ELFArchXMEGA2>;
-def : Device<"avrxmega3", FamilyXMEGA, ELFArchXMEGA3>;
+def : Device<"avrxmega3", FamilyXMEGA3, ELFArchXMEGA3>;
 def : Device<"avrxmega4", FamilyXMEGA, ELFArchXMEGA4>;
 def : Device<"avrxmega5", FamilyXMEGA, ELFArchXMEGA5>;
 def : Device<"avrxmega6", FamilyXMEGA, ELFArchXMEGA6>;
@@ -265,6 +271,7 @@
 def : Device<"at90c8534", FamilyAVR2, ELFArchAVR2>;
 def : Device<"at90s8535", FamilyAVR2, ELFArchAVR2>;
 def : Device<"ata5272", FamilyAVR25, ELFArchAVR25>;
+def : Device<"ata6616c", FamilyAVR25, ELFArchAVR25>;
 def : Device<"attiny13", FamilyAVR25, ELFArchAVR25, [FeatureSmallStack]>;
 def : Device<"attiny13a", FamilyAVR25, ELFArchAVR25, [FeatureSmallStack]>;
 def : Device<"attiny2313", FamilyAVR25, ELFArchAVR25, [FeatureSmallStack]>;
@@ -473,7 +480,6 @@
 def : Device<"atxmega32e5", FamilyXMEGAU, ELFArchXMEGA2>;
 def : Device<"atxmega16e5", FamilyXMEGAU, ELFArchXMEGA2>;
 def : Device<"atxmega8e5", FamilyXMEGAU, ELFArchXMEGA2>;
-def : Device<"atxmega32x1", FamilyXMEGA, ELFArchXMEGA2>;
 def : Device<"atxmega64a3", FamilyXMEGA, ELFArchXMEGA4>;
 def : Device<"atxmega64a3u", FamilyXMEGAU, ELFArchXMEGA4>;
 def : Device<"atxmega64a4u", FamilyXMEGAU, ELFArchXMEGA4>;
@@ -514,28 +520,39 @@
 def : Device<"attiny40", FamilyTiny, ELFArchTiny>;
 def : Device<"attiny102", FamilyTiny, ELFArchTiny>;
 def : Device<"attiny104", FamilyTiny, ELFArchTiny>;
-def : Device<"attiny202", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny402", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny204", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny404", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny804", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny1604", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny406", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny806", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny1606", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny807", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny1607", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny212", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny412", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny214", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny414", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny814", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny1614", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny416", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny816", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny1616", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny3216", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny417", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny817", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny1617", FamilyXMEGA, ELFArchXMEGA3>;
-def : Device<"attiny3217", FamilyXMEGA, ELFArchXMEGA3>;
+def : Device<"attiny202", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny402", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny204", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny404", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny804", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny1604", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny406", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny806", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny1606", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny807", FamilyXMEGA3, ELFArchXMEGA3>;
+def : Device<"attiny1607", FamilyX

[PATCH] D122341: Fix a crash with variably-modified parameter types in a naked function

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 417928.
aaron.ballman added a comment.

Updated the tests


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

https://reviews.llvm.org/D122341

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/attr-naked.c


Index: clang/test/CodeGen/attr-naked.c
===
--- clang/test/CodeGen/attr-naked.c
+++ clang/test/CodeGen/attr-naked.c
@@ -23,5 +23,13 @@
 // CHECK: unreachable
 }
 
+// Make sure naked functions do not attempt to evaluate parameters with a
+// variably-modified type. Naked functions get no prolog, so this evaluation
+// should not take place.
+__attribute__((naked)) void t4(int len, char x[len]) {
+  // CHECK: define{{.*}} void @t4(i32 noundef{{.*}}, i8* noundef{{.*}})
+  // CHECK: unreachable
+}
+
 // CHECK: attributes [[NAKED_OPTNONE]] = { naked noinline nounwind 
optnone{{.*}} }
 // CHECK: attributes [[NAKED]] = { naked noinline nounwind{{.*}} }
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1195,27 +1195,26 @@
   }
 
   // If any of the arguments have a variably modified type, make sure to
-  // emit the type size.
-  for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
-   i != e; ++i) {
-const VarDecl *VD = *i;
-
-// Dig out the type as written from ParmVarDecls; it's unclear whether
-// the standard (C99 6.9.1p10) requires this, but we're following the
-// precedent set by gcc.
-QualType Ty;
-if (const ParmVarDecl *PVD = dyn_cast(VD))
-  Ty = PVD->getOriginalType();
-else
-  Ty = VD->getType();
+  // emit the type size, but only if the function is not naked. Naked functions
+  // have no prolog to run this evaluation.
+  if (!FD || !FD->hasAttr()) {
+for (const VarDecl *VD : Args) {
+  // Dig out the type as written from ParmVarDecls; it's unclear whether
+  // the standard (C99 6.9.1p10) requires this, but we're following the
+  // precedent set by gcc.
+  QualType Ty;
+  if (const ParmVarDecl *PVD = dyn_cast(VD))
+Ty = PVD->getOriginalType();
+  else
+Ty = VD->getType();
 
-if (Ty->isVariablyModifiedType())
-  EmitVariablyModifiedType(Ty);
+  if (Ty->isVariablyModifiedType())
+EmitVariablyModifiedType(Ty);
+}
   }
   // Emit a location at the end of the prologue.
   if (CGDebugInfo *DI = getDebugInfo())
 DI->EmitLocation(Builder, StartLoc);
-
   // TODO: Do we need to handle this in two places like we do with
   // target-features/target-cpu?
   if (CurFuncDecl)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -72,10 +72,12 @@
 - Previously invalid member variables with template parameters would crash 
clang.
   Now fixed by setting identifiers for them.
   This fixes `Issue 28475 (PR28101) 
`_.
-
 - Now allow the `restrict` and `_Atomic` qualifiers to be used in conjunction
   with `__auto_type` to match the behavior in GCC. This fixes
   `Issue 53652 `_.
+- No longer crash when specifying a variably-modified parameter type in a
+  function with the ``naked`` attribute. This fixes
+  `Issue 50541 `_.
 
 
 Improvements to Clang's diagnostics


Index: clang/test/CodeGen/attr-naked.c
===
--- clang/test/CodeGen/attr-naked.c
+++ clang/test/CodeGen/attr-naked.c
@@ -23,5 +23,13 @@
 // CHECK: unreachable
 }
 
+// Make sure naked functions do not attempt to evaluate parameters with a
+// variably-modified type. Naked functions get no prolog, so this evaluation
+// should not take place.
+__attribute__((naked)) void t4(int len, char x[len]) {
+  // CHECK: define{{.*}} void @t4(i32 noundef{{.*}}, i8* noundef{{.*}})
+  // CHECK: unreachable
+}
+
 // CHECK: attributes [[NAKED_OPTNONE]] = { naked noinline nounwind optnone{{.*}} }
 // CHECK: attributes [[NAKED]] = { naked noinline nounwind{{.*}} }
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1195,27 +1195,26 @@
   }
 
   // If any of the arguments have a variably modified type, make sure to
-  // emit the type size.
-  for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
-   i != e; ++i) {
-const VarDecl *VD = *i;
-
-// Dig out the type as written from ParmVarDecls; it's unclear whether
-// the standard (C99 6.9.1p10) requires this, but we're following the
-// precedent set by gcc.
-Qu

[PATCH] D122341: Fix a crash with variably-modified parameter types in a naked function

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D122341#3405269 , @erichkeane 
wrote:

> In D122341#3405008 , @aaron.ballman 
> wrote:
>
>> In D122341#3403587 , @erichkeane 
>> wrote:
>>
>>> Other than this 1 thing, LGTM.  I DO find myself wondering how much of the 
>>> CXXMethodDecl bit in the branch above is valid for 'naked' as well.  If it 
>>> ISN'T we might consider  moving this loop AND that to EmitFunctionPrologue.
>>
>> There's a different kind of bug there. MSVC disallows using the `naked` 
>> attribute on a member function. Clang doesn't enforce this: 
>> https://godbolt.org/z/6jKGbzYTq GCC has no such restriction, but GCC doesn't 
>> have many diagnostics in this area anyway. We may want to reconsider whether 
>> allowing the naked attribute on a non static member function is a good idea. 
>> We probably don't want to allow it in MS compatibility mode at the very 
>> least. But I think this can be a change for another day. WDYT?
>
> Ah! I didn't know the bit about MSVC! I think that makes it even more 
> interesting.  From what I can tell however, GCC actually DOES 'do the right 
> thing' with member functions, though the motivation for them is somewhat 
> suspicious.  I definitely agree we don't want to allow it in MS Compat mode 
> (and agree that is a different patch).  As for in GCC mode, a part of me 
> wants to just DO it and see what the fallout is.  The only value I can see 
> for these as non-static member functions is in a template (or perhaps as a 
> virtual function? *shudders*), and I don't see much overlap in the usage 
> there.

I don't have very strong opinions on whether we restrict in non-Microsoft mode, 
but from what I can tell, the Itanium ABI does do some interesting things for 
some member functions (having to do with virtual table tables, also having to 
do with targets that mandate returning `this`, but otherwise don't seem to do 
any interesting things in the prolog. So it may be sensible to restrict some 
situations while still allowing it on member functions. I think for the moment, 
I'll just restrict on Microsoft mode under the assumption that Itanium is "okay 
enough" for the moment. But I'll do that in a follow-up patch.




Comment at: clang/test/CodeGen/attr-naked.c:31
+  // CHECK: define{{.*}} void @t4(i32 noundef %0, i8* noundef %1)
+  // CHECK-NEXT: entry:
+  // CHECK-NEXT: unreachable

erichkeane wrote:
> so in the test, both 'entry' and '%0'/'%1' above are unstable names.  You 
> might want to replace both with wildcards.  THOUGH, I see other parts of this 
> test have the param names, so IDK?  Either way, 'entry' isn't necessarily a 
> stable label.
Ah, good to know -- I'll correct that.


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

https://reviews.llvm.org/D122341

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


[clang] 488c772 - Fix a crash with variably-modified parameter types in a naked function

2022-03-24 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-03-24T10:39:14-04:00
New Revision: 488c772920566354075f7933eedbe4358c128bd2

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

LOG: Fix a crash with variably-modified parameter types in a naked function

Naked functions have no prolog, so it's not valid to emit prolog code
to evaluate the variably-modified type. This fixes Issue 50541.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/CodeGenFunction.cpp
clang/test/CodeGen/attr-naked.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 373d4156cd797..720fff759c4ec 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -72,10 +72,12 @@ Bug Fixes
 - Previously invalid member variables with template parameters would crash 
clang.
   Now fixed by setting identifiers for them.
   This fixes `Issue 28475 (PR28101) 
`_.
-
 - Now allow the `restrict` and `_Atomic` qualifiers to be used in conjunction
   with `__auto_type` to match the behavior in GCC. This fixes
   `Issue 53652 `_.
+- No longer crash when specifying a variably-modified parameter type in a
+  function with the ``naked`` attribute. This fixes
+  `Issue 50541 `_.
 
 
 Improvements to Clang's diagnostics

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index de717439918d7..15719d12eafeb 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1195,27 +1195,26 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   }
 
   // If any of the arguments have a variably modified type, make sure to
-  // emit the type size.
-  for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
-   i != e; ++i) {
-const VarDecl *VD = *i;
-
-// Dig out the type as written from ParmVarDecls; it's unclear whether
-// the standard (C99 6.9.1p10) requires this, but we're following the
-// precedent set by gcc.
-QualType Ty;
-if (const ParmVarDecl *PVD = dyn_cast(VD))
-  Ty = PVD->getOriginalType();
-else
-  Ty = VD->getType();
+  // emit the type size, but only if the function is not naked. Naked functions
+  // have no prolog to run this evaluation.
+  if (!FD || !FD->hasAttr()) {
+for (const VarDecl *VD : Args) {
+  // Dig out the type as written from ParmVarDecls; it's unclear whether
+  // the standard (C99 6.9.1p10) requires this, but we're following the
+  // precedent set by gcc.
+  QualType Ty;
+  if (const ParmVarDecl *PVD = dyn_cast(VD))
+Ty = PVD->getOriginalType();
+  else
+Ty = VD->getType();
 
-if (Ty->isVariablyModifiedType())
-  EmitVariablyModifiedType(Ty);
+  if (Ty->isVariablyModifiedType())
+EmitVariablyModifiedType(Ty);
+}
   }
   // Emit a location at the end of the prologue.
   if (CGDebugInfo *DI = getDebugInfo())
 DI->EmitLocation(Builder, StartLoc);
-
   // TODO: Do we need to handle this in two places like we do with
   // target-features/target-cpu?
   if (CurFuncDecl)

diff  --git a/clang/test/CodeGen/attr-naked.c b/clang/test/CodeGen/attr-naked.c
index 2bd9e4c77c025..b4da372247929 100644
--- a/clang/test/CodeGen/attr-naked.c
+++ b/clang/test/CodeGen/attr-naked.c
@@ -23,5 +23,13 @@ __attribute((naked)) void t3(int x) {
 // CHECK: unreachable
 }
 
+// Make sure naked functions do not attempt to evaluate parameters with a
+// variably-modified type. Naked functions get no prolog, so this evaluation
+// should not take place.
+__attribute__((naked)) void t4(int len, char x[len]) {
+  // CHECK: define{{.*}} void @t4(i32 noundef{{.*}}, i8* noundef{{.*}})
+  // CHECK: unreachable
+}
+
 // CHECK: attributes [[NAKED_OPTNONE]] = { naked noinline nounwind 
optnone{{.*}} }
 // CHECK: attributes [[NAKED]] = { naked noinline nounwind{{.*}} }



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


[PATCH] D122341: Fix a crash with variably-modified parameter types in a naked function

2022-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

Thanks for the reviews! I've commit in 488c772920566354075f7933eedbe4358c128bd2 
.


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

https://reviews.llvm.org/D122341

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


[PATCH] D122403: [OpenMP] Add a sematnic check for updating hidden or internal values

2022-03-24 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, JonChesterfield, ABataev.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

A previous patch removed the compiler from generting offloading entries
for variables that were declared on the device but were internal or
hidden. This allowed us to compile programs but turns any attempt to run
'#pragma omp target update' on one of those variables a silent failure.
This patch adds a check in the semantic analysis to check if the user is
attempting the update a variable on the device from the host that is not
externally visible.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122403

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_update_messages.cpp


Index: clang/test/OpenMP/target_update_messages.cpp
===
--- clang/test/OpenMP/target_update_messages.cpp
+++ clang/test/OpenMP/target_update_messages.cpp
@@ -8,12 +8,27 @@
 
 // RUN: %clang_cc1 -verify=expected,ge50,ge51,cxx2b -fopenmp -fopenmp-simd 
-fopenmp-version=51 -x c++ -std=c++2b %s -Wuninitialized
 
+
 void xxx(int argc) {
   int x; // expected-note {{initialize the variable 'x' to silence this 
warning}}
 #pragma omp target update to(x)
   argc = x; // expected-warning {{variable 'x' is uninitialized when used 
here}}
 }
 
+static int y;
+#pragma omp declare target(y)
+
+void yyy() {
+#pragma omp target update to(y) // expected-error {{the host cannot update a 
declare target variable that is not externally visible.}}
+}
+
+int __attribute__((visibility("hidden"))) z;
+#pragma omp declare target(z)
+
+void zzz() {
+#pragma omp target update from(z) // expected-error {{the host cannot update a 
declare target variable that is not externally visible.}}
+}
+
 void foo() {
 }
 
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -12619,6 +12619,26 @@
   return hasClauses(Clauses, K) || hasClauses(Clauses, ClauseTypes...);
 }
 
+/// Check if the variables in the mapping clause are externally visible.
+static bool isClauseMappable(ArrayRef Clauses) {
+  for (const OMPClause *C : Clauses) {
+if (auto *TC = dyn_cast(C))
+  return llvm::all_of(TC->all_decls(), [](ValueDecl *VD) {
+return !VD || !VD->hasAttr() ||
+   (VD->isExternallyVisible() &&
+VD->getVisibility() != HiddenVisibility);
+  });
+else if (auto *FC = dyn_cast(C))
+  return llvm::all_of(FC->all_decls(), [](ValueDecl *VD) {
+return !VD || !VD->hasAttr() ||
+   (VD->isExternallyVisible() &&
+VD->getVisibility() != HiddenVisibility);
+  });
+  }
+
+  return true;
+}
+
 StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef Clauses,
 Stmt *AStmt,
 SourceLocation StartLoc,
@@ -12752,6 +12772,12 @@
 Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required);
 return StmtError();
   }
+
+  if (!isClauseMappable(Clauses)) {
+Diag(StartLoc, diag::err_omp_cannot_update_with_internal_linkage);
+return StmtError();
+  }
+
   return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses,
   AStmt);
 }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10734,6 +10734,8 @@
   "expected a reference to an integer-typed parameter">;
 def err_omp_at_least_one_motion_clause_required : Error<
   "expected at least one 'to' clause or 'from' clause specified to '#pragma 
omp target update'">;
+def err_omp_cannot_update_with_internal_linkage : Error<
+  "the host cannot update a declare target variable that is not externally 
visible.">;
 def err_omp_usedeviceptr_not_a_pointer : Error<
   "expected pointer or reference to pointer in 'use_device_ptr' clause">;
 def err_omp_argument_type_isdeviceptr : Error <


Index: clang/test/OpenMP/target_update_messages.cpp
===
--- clang/test/OpenMP/target_update_messages.cpp
+++ clang/test/OpenMP/target_update_messages.cpp
@@ -8,12 +8,27 @@
 
 // RUN: %clang_cc1 -verify=expected,ge50,ge51,cxx2b -fopenmp -fopenmp-simd -fopenmp-version=51 -x c++ -std=c++2b %s -Wuninitialized
 
+
 void xxx(int argc) {
   int x; // expected-note {{initialize the variable 'x' to silence this warning}}
 #pragma omp target update to(x)
   argc = x; // expected-warning {{variable 'x' is uninitialized when use

[PATCH] D122404: [clang][AArc64][SVE] Add support for comparison operators on SVE types

2022-03-24 Thread David Truby via Phabricator via cfe-commits
DavidTruby created this revision.
Herald added subscribers: ctetreau, psnobl, tschuett.
Herald added a reviewer: efriedma.
Herald added a project: All.
DavidTruby requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Comparison operators on SVE types return a signed integer vector
of the same width as the incoming SVE type. This matches the existing
behaviour for NEON types.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122404

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/aarch64-sve-vector-compare-ops.c
  clang/test/Sema/aarch64-sve-vector-compare-ops.c
  clang/test/Sema/sizeless-1.c
  clang/test/SemaCXX/sizeless-1.cpp

Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -212,12 +212,6 @@
 
   local_int8 << init_int8; // expected-error {{invalid operands to binary expression}}
   local_int8 >> init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 < init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 <= init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 == init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 != init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 >= init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 > init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 &&init_int8;  // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
 
Index: clang/test/Sema/sizeless-1.c
===
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -200,12 +200,6 @@
 
   local_int8 << init_int8; // expected-error {{invalid operands to binary expression}}
   local_int8 >> init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 < init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 <= init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 == init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 != init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 >= init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 > init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 &&init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}}
 
Index: clang/test/Sema/aarch64-sve-vector-compare-ops.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-vector-compare-ops.c
@@ -0,0 +1,761 @@
+// RUN: %clang_cc1 -verify -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns -fsyntax-only %s
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+void eq(svint8_t i8, svint16_t i16, svint32_t i32, svint64_t i64,
+svuint8_t u8, svuint16_t u16, svuint32_t u32, svuint64_t u64,
+svfloat16_t f16, svfloat32_t f32, svfloat64_t f64,
+svbool_t b) {
+  (void)(i8 == b);   // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == i16); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == i32); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == i64); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == u16); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == u32); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == u64); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == f16); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == f32); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == f64); // expected-error{{invalid operands to binary expression}}
+
+  (void)(u8 == b);   // expected-error{{invalid operands to binary expression}}
+  (void)(u8 == i16); // expected-error{{invalid operands to binary expression}}
+  (void)(u8 == i32); // expected-error{{invalid operands to binary expression}}
+  (void)(u8 == i64); // expected-error{{invalid operands to binary expression}}
+  (void)(u8 == u16); // expected-error{{invalid operands to binary expression}}
+  (void)(u8 == u32); // expected-error{{invalid operands to binary expression}}
+  (void)(u8 == u64); // expected-

[PATCH] D121765: [CUDA][HIP] Fix hostness check with -fopenmp

2022-03-24 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:3325-3330
+  /// getCurFunctionDecl - If parsing a lambda, then return the lambda
+  /// declaration if \p AllowLambda is true, otherwise return the function
+  /// declaration enclosing the lambda. If in 'block' context, return the
+  /// enclosing function or lambda declaration if \p AllowLambda is true,
+  /// otherwise return the enclosing function declaration. For regular
+  /// functions, return the function declarations.

rsmith wrote:
> This comment would be clearer if it started with the common case and then 
> explains any special cases. We also prefer to not include the function name 
> at the start of the comment, so that should be removed when updating a 
> function comment. It's also possible for a (member) function to be nested 
> within a lambda, so I don't think it's correct that we will return the lambda 
> whenever we're parsing one. Also, talking about "parsing" isn't right during 
> template instantiation.
> 
> Maybe: "Returns a pointer to the innermost enclosing function, or `nullptr` 
> if the current context is not inside a function. If \p AllowLambda is true, 
> this can return the call operator of an enclosing lambda, otherwise lambdas 
> are skipped when looking for an enclosing function."
Thanks. Will fix when committing.


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

https://reviews.llvm.org/D121765

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


[PATCH] D120306: [clangd] IncludeCleaner: Add support for IWYU pragma private

2022-03-24 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 417940.
kbobyrev added a comment.
Herald added a project: All.

Switch to a different model of recording includes that differentiates between
user includes and public headers recored through IWYU pragmas.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120306

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -9,6 +9,7 @@
 #include "Annotations.h"
 #include "IncludeCleaner.h"
 #include "SourceCode.h"
+#include "TestFS.h"
 #include "TestTU.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Testing/Support/SupportHelpers.h"
@@ -266,8 +267,9 @@
 
 ReferencedLocations Locs = findReferencedLocations(AST);
 EXPECT_THAT(Locs.Stdlib, ElementsAreArray(WantSyms));
-ReferencedFiles Files = findReferencedFiles(Locs, AST.getIncludeStructure(),
-AST.getSourceManager());
+ReferencedFiles Files =
+findReferencedFiles(Locs, AST.getIncludeStructure(),
+AST.getCanonicalIncludes(), AST.getSourceManager());
 EXPECT_THAT(Files.Stdlib, ElementsAreArray(WantHeaders));
   }
 }
@@ -378,8 +380,8 @@
   auto &SM = AST.getSourceManager();
   auto &Includes = AST.getIncludeStructure();
 
-  auto ReferencedFiles =
-  findReferencedFiles(findReferencedLocations(AST), Includes, SM);
+  auto ReferencedFiles = findReferencedFiles(
+  findReferencedLocations(AST), Includes, AST.getCanonicalIncludes(), SM);
   llvm::StringSet<> ReferencedFileNames;
   for (FileID FID : ReferencedFiles.User)
 ReferencedFileNames.insert(
@@ -427,9 +429,9 @@
 
   ParsedAST AST = TU.build();
 
-  auto ReferencedFiles =
-  findReferencedFiles(findReferencedLocations(AST),
-  AST.getIncludeStructure(), AST.getSourceManager());
+  auto ReferencedFiles = findReferencedFiles(
+  findReferencedLocations(AST), AST.getIncludeStructure(),
+  AST.getCanonicalIncludes(), AST.getSourceManager());
   llvm::StringSet<> ReferencedFileNames;
   auto &SM = AST.getSourceManager();
   for (FileID FID : ReferencedFiles.User)
@@ -461,9 +463,9 @@
 
   ParsedAST AST = TU.build();
 
-  auto ReferencedFiles =
-  findReferencedFiles(findReferencedLocations(AST),
-  AST.getIncludeStructure(), AST.getSourceManager());
+  auto ReferencedFiles = findReferencedFiles(
+  findReferencedLocations(AST), AST.getIncludeStructure(),
+  AST.getCanonicalIncludes(), AST.getSourceManager());
   llvm::StringSet<> ReferencedFileNames;
   auto &SM = AST.getSourceManager();
   for (FileID FID : ReferencedFiles.User)
@@ -479,13 +481,23 @@
   TestTU TU;
   TU.Code = R"cpp(
 #include "behind_keep.h" // IWYU pragma: keep
+#include "public.h"
+
+void bar() { foo(); }
 )cpp";
   TU.AdditionalFiles["behind_keep.h"] = guard("");
+  TU.AdditionalFiles["public.h"] = guard("#include \"private.h\"");
+  TU.AdditionalFiles["private.h"] = guard(R"cpp(
+// IWYU pragma: private, include "public.h"
+void foo() {}
+  )cpp");
   ParsedAST AST = TU.build();
 
-  auto ReferencedFiles =
-  findReferencedFiles(findReferencedLocations(AST),
-  AST.getIncludeStructure(), AST.getSourceManager());
+  auto ReferencedFiles = findReferencedFiles(
+  findReferencedLocations(AST), AST.getIncludeStructure(),
+  AST.getCanonicalIncludes(), AST.getSourceManager());
+  EXPECT_EQ(ReferencedFiles.PublicHeaders.size(), 1u);
+  EXPECT_EQ(ReferencedFiles.PublicHeaders.begin()->getKey(), "\"public.h\"");
   EXPECT_TRUE(ReferencedFiles.User.empty());
   EXPECT_THAT(AST.getDiagnostics(), llvm::ValueIs(IsEmpty()));
 }
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -13,9 +13,6 @@
 /// to provide useful warnings in most popular scenarios but not 1:1 exact
 /// feature compatibility.
 ///
-/// FIXME(kirillbobyrev): Add support for IWYU pragmas.
-/// FIXME(kirillbobyrev): Add support for standard library headers.
-///
 //===--===//
 
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INCLUDECLEANER_H
@@ -23,10 +20,12 @@
 
 #include "Headers.h"
 #include "ParsedAST.h"
+#include "index/CanonicalIncludes.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
+#include "llvm/ADT/StringSet.h"
 #in

[PATCH] D103501: [clang][AIX] Enable inlined quadword atomic operations

2022-03-24 Thread Kai Luo via Phabricator via cfe-commits
lkail abandoned this revision.
lkail added a comment.
Herald added a project: All.

Most are covered by https://reviews.llvm.org/D122377 already.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103501

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


[PATCH] D122407: [ASan] Reland of D116182 to always link asan_static library.

2022-03-24 Thread Kirill Stoimenov via Phabricator via cfe-commits
kstoimenov created this revision.
Herald added a subscriber: mgorny.
Herald added a project: All.
kstoimenov requested review of this revision.
Herald added projects: clang, Sanitizers.
Herald added subscribers: Sanitizers, cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122407

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/lib/asan/CMakeLists.txt
  compiler-rt/lib/asan/asan_interface.inc
  compiler-rt/lib/asan/asan_rtl_x86_64.S

Index: compiler-rt/lib/asan/asan_rtl_x86_64.S
===
--- compiler-rt/lib/asan/asan_rtl_x86_64.S
+++ compiler-rt/lib/asan/asan_rtl_x86_64.S
@@ -16,6 +16,7 @@
 #define BEGINF(reg, op, s, i) \
 .section .text.FNAME(reg, op, s, i),"ax",@progbits ;\
 .globl  FNAME(reg, op, s, i) ;\
+.hidden  FNAME(reg, op, s, i) ;\
 ASM_TYPE_FUNCTION(FNAME(reg, op, s, i)) ;\
 .cfi_startproc ;\
 FNAME(reg, op, s, i): ;\
@@ -41,7 +42,7 @@
 pop%rcx ;\
 jl RLABEL(reg, op, 1, i);\
 mov%##reg,%rdi ;\
-jmp__asan_report_##op##1@PLT ;\
+jmp__asan_report_##op##1_asm ;\
 
 #define ASAN_MEMORY_ACCESS_EXTRA_CHECK_2(reg, op, i) \
 CLABEL(reg, op, 2, i): ;\
@@ -53,7 +54,7 @@
 pop%rcx ;\
 jl RLABEL(reg, op, 2, i);\
 mov%##reg,%rdi ;\
-jmp__asan_report_##op##2@PLT ;\
+jmp__asan_report_##op##2_asm ;\
 
 #define ASAN_MEMORY_ACCESS_EXTRA_CHECK_4(reg, op, i) \
 CLABEL(reg, op, 4, i): ;\
@@ -65,7 +66,7 @@
 pop%rcx ;\
 jl RLABEL(reg, op, 4, i);\
 mov%##reg,%rdi ;\
-jmp__asan_report_##op##4@PLT ;\
+jmp__asan_report_##op##4_asm ;\
 
 #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_1(reg, op) \
 BEGINF(reg, op, 1, add) ;\
@@ -96,7 +97,7 @@
 #define ASAN_MEMORY_ACCESS_FAIL(reg, op, s, i) \
 FLABEL(reg, op, s, i): ;\
 mov%##reg,%rdi ;\
-jmp__asan_report_##op##s@PLT;\
+jmp__asan_report_##op##s##_asm;\
 
 #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_8(reg, op) \
 BEGINF(reg, op, 8, add) ;\
Index: compiler-rt/lib/asan/asan_interface.inc
===
--- compiler-rt/lib/asan/asan_interface.inc
+++ compiler-rt/lib/asan/asan_interface.inc
@@ -180,37 +180,3 @@
 INTERFACE_WEAK_FUNCTION(__asan_default_options)
 INTERFACE_WEAK_FUNCTION(__asan_default_suppressions)
 INTERFACE_WEAK_FUNCTION(__asan_on_error)
-
-#if defined(__x86_64__) && !defined(__APPLE__) && !defined(_WIN32)
-
-#  define ASAN_MEMORY_ACCESS_CALLBACK_ADD(s, reg, op) \
-INTERFACE_FUNCTION(__asan_check_##op##_add_##s##_##reg)
-
-#  define ASAN_MEMORY_ACCESS_CALLBACKS_ADD(reg)\
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(1, reg, load)  \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(1, reg, store) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(2, reg, load)  \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(2, reg, store) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(4, reg, load)  \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(4, reg, store) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(8, reg, load)  \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(8, reg, store) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(16, reg, load) \
-ASAN_MEMORY_ACCESS_CALLBACK_ADD(16, reg, store)
-
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RAX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RBX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RCX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RDX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RSI)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RDI)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RBP)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R8)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R9)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R12)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R13)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R14)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R15)
-
-#endif  // defined(__x86_64__) && !defined(__APPLE__) && !defined(_WIN32)
-
Index: compiler-rt/lib/asan/CMakeLists.txt
===
--- compiler-rt/lib/asan/CMakeLists.txt
+++ compiler-rt/lib/asan/CMakeLists.txt
@@ -34,7 +34,6 @@
 
 if (NOT WIN32 AND NOT APPLE)
   list(APPEND ASAN_SOURCES
-asan_rtl_x86_64.S
 asan_interceptors_vfork.S
 )
 endif()
@@ -49,6 +48,7 @@
 
 if (NOT WIN32 AND NOT APPLE)
   list(APPEND ASAN_STATIC_SOURCES
+asan_rtl_x86_64.S
   )
 endif()
 
Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -30,6 +30,7 @@
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-EXECUTABLE-LINUX %s
 //
+// CHECK-ASAN-EXECUTABLE-LINUX: libclang_rt.asan_static-x86_64
 // CHECK-ASAN-EXECUTABLE-LINUX: libclang_rt.asan-x86_64
 
 // RUN: %clang -fsanitize=address -shared %s -### -o %t.o 2>&1  \
@@ -38,6 +39,7 @@
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-SHARED-LINUX %s
 

[PATCH] D122377: [PowerPC][Linux] Support 16-byte lock free atomics on pwr8 and up

2022-03-24 Thread Jinsong Ji via Phabricator via cfe-commits
jsji added inline comments.



Comment at: clang/test/CodeGen/PowerPC/atomic-alignment.c:7
+// RUN:   -emit-llvm -o - %s | FileCheck %s --check-prefixes=PPC,PPC64-PWR8
 // RUN: %clang_cc1 -verify -triple powerpc64-unknown-aix -emit-llvm -o - %s | \
 // RUN:   FileCheck %s --check-prefixes=PPC,PPC64

How about AIX pwr8?



Comment at: llvm/lib/Target/PowerPC/PPCISelLowering.cpp:126
 "ppc-quadword-atomics",
-cl::desc("enable quadword lock-free atomic operations"), cl::init(false),
+cl::desc("enable quadword lock-free atomic operations"), cl::init(true),
 cl::Hidden);

So we enable it by default , *EVEN* on AIX?


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

https://reviews.llvm.org/D122377

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


[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-24 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem added a comment.

In D121812#3405060 , @jansvoboda11 
wrote:

> Sorry for the breakage and thanks for reporting this! This is a real bug 
> uncovered by your build using `/opt`. I have a fix here: D122385 
> .

Thanks for the fix.  Could it be possible to land the fix asap?
If not, could you please revert this patch, and reland with the fix?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121812

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


[clang] 5b164a3 - Diagnose use of a naked attribute on a member function in ms-mode

2022-03-24 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-03-24T11:52:43-04:00
New Revision: 5b164a3a9b8c52e45641203de9c4c73fa7402570

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

LOG: Diagnose use of a naked attribute on a member function in ms-mode

This matches the behavior of cl.exe.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Sema/attr-naked.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 720fff759c4ec..b2f0ed185e0b5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -131,6 +131,9 @@ Attribute Changes in Clang
 
 - ``#pragma clang attribute push`` now supports multiple attributes within a 
single directive.
 
+- The ``__declspec(naked)`` attribute can no longer be written on a member
+  function in Microsoft compatibility mode, matching the behavior of cl.exe.
+
 Windows Support
 ---
 

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 4ac45145e6e8a..b99a970061c0c 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2158,6 +2158,14 @@ static void handleNakedAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   << AL << Triple.getArchName();
   return;
 }
+
+// This form is not allowed to be written on a member function (static or
+// nonstatic) when in Microsoft compatibility mode.
+if (S.getLangOpts().MSVCCompat && isa(D)) {
+  S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type_str)
+  << AL << "non-member functions";
+  return;
+}
   }
 
   D->addAttr(::new (S.Context) NakedAttr(S.Context, AL));

diff  --git a/clang/test/Sema/attr-naked.cpp b/clang/test/Sema/attr-naked.cpp
index eaa8e223b83e1..a9c0fed4b99fc 100644
--- a/clang/test/Sema/attr-naked.cpp
+++ b/clang/test/Sema/attr-naked.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 %s -verify -fsyntax-only -triple arm-none-linux
+// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -DDECLSPEC 
-triple i686-pc-win32
+
 class Foo {
   void bar();
   static void bar2();
@@ -13,3 +15,12 @@ void __attribute__((naked)) Foo::bar() { // 
expected-note{{attribute is here}}
 void __attribute__((naked)) Foo::bar2() {
   asm("mov r2, %0" : : "r"(s)); // static member reference is OK
 }
+
+struct Bar {
+#ifdef DECLSPEC
+  __declspec(naked) void func1(); // expected-error {{'naked' attribute only 
applies to non-member functions}}
+  __declspec(naked) static void func2(); // expected-error {{'naked' attribute 
only applies to non-member functions}}
+#endif
+  __attribute__((naked)) void func3(); // OK
+  __attribute__((naked)) static void func4(); // OK
+};



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


[PATCH] D122336: [InstrProfiling] No runtime hook for unused funcs

2022-03-24 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem updated this revision to Diff 417945.
gulfem added a comment.

Addressed phosek's comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122336

Files:
  clang/test/CoverageMapping/unused_function_no_runtime_hook.cpp
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp


Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===
--- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -558,16 +558,18 @@
   TT = Triple(M.getTargetTriple());
 
   bool MadeChange = false;
-
-  // Emit the runtime hook even if no counters are present.
-  if (needsRuntimeHookUnconditionally(TT))
+  bool NeedsRuntimeHook = needsRuntimeHookUnconditionally(TT);
+  if (NeedsRuntimeHook)
 MadeChange = emitRuntimeHook();
 
   // Improve compile time by avoiding linear scans when there is no work.
   GlobalVariable *CoverageNamesVar =
   M.getNamedGlobal(getCoverageUnusedNamesVarName());
-  if (!containsProfilingIntrinsics(M) && !CoverageNamesVar)
-return MadeChange;
+  if (!containsProfilingIntrinsics(M)) {
+if (!CoverageNamesVar || !NeedsRuntimeHook) {
+  return MadeChange;
+}
+  }
 
   // We did not know how many value sites there would be inside
   // the instrumented function. This is counting the number of instrumented
Index: clang/test/CoverageMapping/unused_function_no_runtime_hook.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/unused_function_no_runtime_hook.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-unknown-fuchsia -fprofile-instr-generate 
-fcoverage-mapping -emit-llvm -S %s -o - | FileCheck %s
+
+// CHECK-NOT: @__llvm_profile_runtime
+static int f0() {
+  return 100;
+}


Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===
--- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -558,16 +558,18 @@
   TT = Triple(M.getTargetTriple());
 
   bool MadeChange = false;
-
-  // Emit the runtime hook even if no counters are present.
-  if (needsRuntimeHookUnconditionally(TT))
+  bool NeedsRuntimeHook = needsRuntimeHookUnconditionally(TT);
+  if (NeedsRuntimeHook)
 MadeChange = emitRuntimeHook();
 
   // Improve compile time by avoiding linear scans when there is no work.
   GlobalVariable *CoverageNamesVar =
   M.getNamedGlobal(getCoverageUnusedNamesVarName());
-  if (!containsProfilingIntrinsics(M) && !CoverageNamesVar)
-return MadeChange;
+  if (!containsProfilingIntrinsics(M)) {
+if (!CoverageNamesVar || !NeedsRuntimeHook) {
+  return MadeChange;
+}
+  }
 
   // We did not know how many value sites there would be inside
   // the instrumented function. This is counting the number of instrumented
Index: clang/test/CoverageMapping/unused_function_no_runtime_hook.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/unused_function_no_runtime_hook.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-unknown-fuchsia -fprofile-instr-generate -fcoverage-mapping -emit-llvm -S %s -o - | FileCheck %s
+
+// CHECK-NOT: @__llvm_profile_runtime
+static int f0() {
+  return 100;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122338: [OPENMP] Eliminate extra set of simd variant function attribute.

2022-03-24 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 417944.
jyu2 added a comment.

Address Alexey's comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122338

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_simd_codegen.cpp


Index: clang/test/OpenMP/declare_simd_codegen.cpp
===
--- clang/test/OpenMP/declare_simd_codegen.cpp
+++ clang/test/OpenMP/declare_simd_codegen.cpp
@@ -153,6 +153,23 @@
 // CHECK-DAG: "_ZGVdN4v__Z5add_1Pf"
 // CHECK-DAG: "_ZGVeN8v__Z5add_1Pf"
 
+// CHECK-NOT: _ZGVbN2vv__Z5add_1Pf
+// CHECK-NOT: _ZGVcN4vv__Z5add_1Pf
+// CHECK-NOT: _ZGVdN4vv__Z5add_1Pf
+// CHECK-NOT: _ZGVeN8vv__Z5add_1Pf
+// CHECK-NOT: _ZGVbM32vv__Z5add_1Pf
+// CHECK-NOT: _ZGVcM32vv__Z5add_1Pf
+// CHECK-NOT: _ZGVdM32vv__Z5add_1Pf
+// CHECK-NOT: _ZGVeM32vv__Z5add_1Pf
+// CHECK-NOT: _ZGVbN4l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVcN8l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVdN8l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVeN16l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVbM4l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVcM8l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVdM8l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVeM16l32v__Z5add_1Pf
+
 // CHECK-DAG: "_ZGVbM2va16va16vv__Z1hIiEvPT_S1_S1_S1_"
 // CHECK-DAG: "_ZGVbN2va16va16vv__Z1hIiEvPT_S1_S1_S1_"
 // CHECK-DAG: "_ZGVcM4va16va16vv__Z1hIiEvPT_S1_S1_S1_"
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11968,16 +11968,16 @@
   llvm::Function *Fn) {
   ASTContext &C = CGM.getContext();
   FD = FD->getMostRecentDecl();
-  // Map params to their positions in function decl.
-  llvm::DenseMap ParamPositions;
-  if (isa(FD))
-ParamPositions.try_emplace(FD, 0);
-  unsigned ParamPos = ParamPositions.size();
-  for (const ParmVarDecl *P : FD->parameters()) {
-ParamPositions.try_emplace(P->getCanonicalDecl(), ParamPos);
-++ParamPos;
-  }
   while (FD) {
+// Map params to their positions in function decl.
+llvm::DenseMap ParamPositions;
+if (isa(FD))
+  ParamPositions.try_emplace(FD, 0);
+unsigned ParamPos = ParamPositions.size();
+for (const ParmVarDecl *P : FD->parameters()) {
+  ParamPositions.try_emplace(P->getCanonicalDecl(), ParamPos);
+  ++ParamPos;
+}
 for (const auto *Attr : FD->specific_attrs()) {
   llvm::SmallVector ParamAttrs(ParamPositions.size());
   // Mark uniform parameters.
@@ -11989,6 +11989,7 @@
 } else {
   const auto *PVD = cast(cast(E)->getDecl())
 ->getCanonicalDecl();
+  assert(ParamPositions.find(PVD) != ParamPositions.end());
   Pos = ParamPositions[PVD];
 }
 ParamAttrs[Pos].Kind = Uniform;
@@ -12005,6 +12006,7 @@
 } else {
   const auto *PVD = cast(cast(E)->getDecl())
 ->getCanonicalDecl();
+  assert(ParamPositions.find(PVD) != ParamPositions.end());
   Pos = ParamPositions[PVD];
   ParmTy = PVD->getType();
 }
@@ -12030,6 +12032,7 @@
 } else {
   const auto *PVD = cast(cast(E)->getDecl())
 ->getCanonicalDecl();
+  assert(ParamPositions.find(PVD) != ParamPositions.end());
   Pos = ParamPositions[PVD];
   if (auto *P = dyn_cast(PVD->getType()))
 PtrRescalingFactor = CGM.getContext()
@@ -12048,6 +12051,8 @@
   if (const auto *StridePVD =
   dyn_cast(DRE->getDecl())) {
 ParamAttr.Kind = LinearWithVarStride;
+assert(ParamPositions.find(StridePVD->getCanonicalDecl()) !=
+   ParamPositions.end());
 ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned(
 ParamPositions[StridePVD->getCanonicalDecl()]);
   }


Index: clang/test/OpenMP/declare_simd_codegen.cpp
===
--- clang/test/OpenMP/declare_simd_codegen.cpp
+++ clang/test/OpenMP/declare_simd_codegen.cpp
@@ -153,6 +153,23 @@
 // CHECK-DAG: "_ZGVdN4v__Z5add_1Pf"
 // CHECK-DAG: "_ZGVeN8v__Z5add_1Pf"
 
+// CHECK-NOT: _ZGVbN2vv__Z5add_1Pf
+// CHECK-NOT: _ZGVcN4vv__Z5add_1Pf
+// CHECK-NOT: _ZGVdN4vv__Z5add_1Pf
+// CHECK-NOT: _ZGVeN8vv__Z5add_1Pf
+// CHECK-NOT: _ZGVbM32vv__Z5add_1Pf
+// CHECK-NOT: _ZGVcM32vv__Z5add_1Pf
+// CHECK-NOT: _ZGVdM32vv__Z5add_1Pf
+// CHECK-NOT: _ZGVeM32vv__Z5add_1Pf
+// CHECK-NOT: _ZGVbN4l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVcN8l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVdN8l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVeN16l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVbM4l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVcM8l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVdM8l32v__Z5add_1Pf
+// CHECK-NOT: _ZGVeM16l32v__Z5add_1Pf
+
 // CHECK-DAG: "_ZGVbM2va16va16vv__Z1hIiEvPT_S1_S1_S1_

[PATCH] D122338: [OPENMP] Eliminate extra set of simd variant function attribute.

2022-03-24 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11992
 ->getCanonicalDecl();
+  assert(ParamPositions.find(PVD) != ParamPositions.end());
   Pos = ParamPositions[PVD];

Better to use `count()` or `contain()` (do not remember which one is defined 
for DenseMap), also add messages to asserts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122338

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


[PATCH] D121328: Disable -Wmissing-prototypes for internal linkage functions that aren't explicitly marked "static"""

2022-03-24 Thread Dean Sturtevant via Phabricator via cfe-commits
deansturtevant requested changes to this revision.
deansturtevant added a comment.
This revision now requires changes to proceed.

Aha! (I think).
If the code to test "isExternalVisible" is executed *after* the code to test 
whether it's a C++ member function (the very next test), then the problem 
wouldn't arise.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121328

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


[PATCH] D122338: [OPENMP] Eliminate extra set of simd variant function attribute.

2022-03-24 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:11992-11993
 ->getCanonicalDecl();
+  assert(ParamPositions.find(PVD) != ParamPositions.end());
   Pos = ParamPositions[PVD];
 }

ABataev wrote:
> Better to use `count()` or `contain()` (do not remember which one is defined 
> for DenseMap), also add messages to asserts.
Or, if you already using `find`, better to do something like:
```
auto It = ParamPositions.find(PVD);
assert(It != ParamPositions.end() && "...");
Pos = It->second;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122338

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


[PATCH] D122403: [OpenMP] Add a sematnic check for updating hidden or internal values

2022-03-24 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122403

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


[PATCH] D119544: Deferred Concept Instantiation Implementation

2022-03-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 417948.
erichkeane added reviewers: clang-language-wg, aaron.ballman, saar.raz.
erichkeane added a subscriber: cfe-commits.
erichkeane added a comment.

Added release notes.

I tossed every ranges-based example I could find on google at this and I saw 
only improvements (that is, no regressions).  I don't think there is anything 
else I can do on this, so hoping to get this reviewed and committed, hopefully 
soon enough for folks to mess with this enough for more-clever folks to break 
it.


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

https://reviews.llvm.org/D119544

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Template.h
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CXX/temp/temp.constr/temp.constr.constr/non-function-templates.cpp
  clang/test/SemaTemplate/deferred-concept-inst.cpp
  clang/test/SemaTemplate/instantiate-requires-clause.cpp
  clang/test/SemaTemplate/trailing-return-short-circuit.cpp

Index: clang/test/SemaTemplate/trailing-return-short-circuit.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/trailing-return-short-circuit.cpp
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+template 
+requires(sizeof(T) > 2) || T::value // #FOO_REQ
+void Foo(T){}; // #FOO
+
+template 
+void TrailingReturn(T) // #TRAILING
+requires(sizeof(T) > 2) || T::value // #TRAILING_REQ
+{};
+template
+struct HasValue {
+  static constexpr bool value = B;
+};
+static_assert(sizeof(HasValue) <= 2);
+
+template
+struct HasValueLarge {
+  static constexpr bool value = B;
+  int I;
+};
+static_assert(sizeof(HasValueLarge) > 2);
+
+void usage() {
+  // Passes the 1st check, short-circuit so the 2nd ::value is not evaluated.
+  Foo(1.0);
+  TrailingReturn(1.0);
+
+  // Fails the 1st check, but has a ::value, so the check happens correctly.
+  Foo(HasValue{});
+  TrailingReturn(HasValue{});
+
+  // Passes the 1st check, but would have passed the 2nd one.
+  Foo(HasValueLarge{});
+  TrailingReturn(HasValueLarge{});
+
+  // Fails the 1st check, fails 2nd because there is no ::value.
+  Foo(true);
+  // expected-error@-1{{no matching function for call to 'Foo'}}
+  // expected-note@#FOO{{candidate template ignored: constraints not satisfied [with T = bool]}}
+  // expected-note@#FOO_REQ{{because 'sizeof(_Bool) > 2' (1 > 2) evaluated to false}}
+  // expected-note@#FOO_REQ{{because substituted constraint expression is ill-formed: type 'bool' cannot be used prior to '::' because it has no members}}
+
+  TrailingReturn(true);
+  // expected-error@-1{{no matching function for call to 'TrailingReturn'}}
+  // expected-note@#TRAILING{{candidate template ignored: constraints not satisfied [with T = bool]}}
+  // expected-note@#TRAILING_REQ{{because 'sizeof(_Bool) > 2' (1 > 2) evaluated to false}}
+  // expected-note@#TRAILING_REQ{{because substituted constraint expression is ill-formed: type 'bool' cannot be used prior to '::' because it has no members}}
+
+  // Fails the 1st check, fails 2nd because ::value is false.
+  Foo(HasValue{});
+  // expected-error@-1 {{no matching function for call to 'Foo'}}
+  // expected-note@#FOO{{candidate template ignored: constraints not satisfied [with T = HasValue]}}
+  // expected-note@#FOO_REQ{{because 'sizeof(HasValue) > 2' (1 > 2) evaluated to false}}
+  // expected-note@#FOO_REQ{{and 'HasValue::value' evaluated to false}}
+  TrailingReturn(HasValue{});
+  // expected-error@-1 {{no matching function for call to 'TrailingReturn'}}
+  // expected-note@#TRAILING{{candidate template ignored: constraints not satisfied [with T = HasValue]}}
+  // expected-note@#TRAILING_REQ{{because 'sizeof(HasValue) > 2' (1 > 2) evaluated to false}}
+  // expected-note@#TRAILING_REQ{{and 'HasValue::value' evaluated to false}}
+}
Index: clang/test/SemaTemplate/instantiate-requires-clause.cpp
===
--- clang/test/SemaTemplate/instantiate-requires-clause.cpp
+++ clang/test/SemaTemplate/instantiate-requires-clause.cpp
@@ -40,6 +40,18 @@
 
 static_assert(S::f(1));
 
+// Similar to the 'S' test, but tries to use 'U' in the requires clause.
+template
+struct S1 {
+  // expected-note@+3 {{candidate template ignored: constraints not satisfied [with U = int]}}
+  // expected-note@+2 {{because substituted constraint expression is ill-formed: type 'int' cannot be used prior to '::' because it has no members}}
+  template 
+  static constexpr auto f(U const index) requires(U::foo) { return true; }
+};
+
+// expected-error@+1 {{no matching function for call to 'f'}}
+static_assert(S1::f(1));
+
 constexpr auto value = 0;
 
 template
Index: clang/test/SemaTemplate/deferred-concept

[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-24 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa added a comment.

In D122248#3405166 , @erichkeane 
wrote:

> In D122248#3405062 , @aaron.ballman 
> wrote:
>
>> In D122248#3403734 , @yihanaa 
>> wrote:
>>
>>> What if we don't emit '=' for zero-width bitfield, like this:
>>>
>>>   struct Bar {
>>>   unsigned c : 1;
>>>   unsigned : 3;
>>>   unsigned : 0;
>>>   unsigned b;
>>>   };
>>>   
>>>   struct Bar {
>>>   unsigned int c : 1 = 0
>>>   unsigned int   : 3 = 0
>>>   unsigned int   : 0
>>>   unsigned int b = 0
>>>   }
>>>
>>> What do you all think?
>>
>> I like this idea best of all!
>
> Agreed!

@erichkeane @aaron.ballman


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

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


[PATCH] D122408: [pseudo] [WIP2] Implement GLR parser

2022-03-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
Herald added subscribers: mgrang, mgorny.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, alextsao1999.
Herald added a project: clang-tools-extra.

Derived from https://reviews.llvm.org/D121150, which I don't want to commandeer
at this point. Rebased against new directory structure.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122408

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
  clang-tools-extra/pseudo/include/clang-pseudo/GLRParser.h
  clang-tools-extra/pseudo/lib/CMakeLists.txt
  clang-tools-extra/pseudo/lib/GLRParser.cpp
  clang-tools-extra/pseudo/tool/ClangPseudo.cpp

Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang-pseudo/DirectiveMap.h"
+#include "clang-pseudo/GLRParser.h"
 #include "clang-pseudo/Grammar.h"
 #include "clang-pseudo/LRGraph.h"
 #include "clang-pseudo/LRTable.h"
@@ -29,6 +30,8 @@
 desc("Print the LR graph for the grammar"));
 static opt PrintTable("print-table",
 desc("Print the LR table for the grammar"));
+static opt ParseFile("parse", desc("Parse a C++ source file"),
+  init(""));
 static opt Source("source", desc("Source file"));
 static opt PrintSource("print-source", desc("Print token stream"));
 static opt PrintTokens("print-tokens", desc("Print detailed token info"));
@@ -67,6 +70,28 @@
   llvm::outs() << clang::pseudo::LRGraph::buildLR0(*G).dumpForTests(*G);
 if (PrintTable)
   llvm::outs() << clang::pseudo::LRTable::buildSLR(*G).dumpForTests(*G);
+
+if (ParseFile.getNumOccurrences()) {
+  std::string Code = readOrDie(ParseFile);
+  const auto &T = clang::pseudo::LRTable::buildSLR(*G);
+  clang::LangOptions Opts;
+  Opts.CPlusPlus = 1;
+
+  auto RawTokens = clang::pseudo::lex(Code, Opts);
+  auto Tokens = clang::pseudo::stripComments(cook(RawTokens, Opts));
+  clang::pseudo::ForestArena Arena;
+  clang::pseudo::GLRParser Parser(T, *G, Arena);
+  const auto *Root = Parser.parse(Tokens);
+  if (Root) {
+llvm::outs() << "parsed successfully!\n";
+llvm::outs() << "Forest bytes: " << Arena.bytes()
+ << " nodes: " << Arena.nodeCount() << "\n";
+llvm::outs() << "GSS bytes: " << Parser.getGSS().bytes()
+ << " nodes: " << Parser.getGSS().nodeCount() << "\n";
+llvm::outs() << Root->dumpRecursive(*G, true);
+  }
+}
+
 return 0;
   }
 
Index: clang-tools-extra/pseudo/lib/GLRParser.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/lib/GLRParser.cpp
@@ -0,0 +1,332 @@
+//===--- GLRParser.cpp   -*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang-pseudo/GLRParser.h"
+#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/LRTable.h"
+#include "clang-pseudo/Token.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormatVariadic.h"
+#include 
+#include 
+
+#define DEBUG_TYPE "GLRParser.cpp"
+
+namespace clang {
+namespace pseudo {
+
+using StateID = LRTable::StateID;
+
+const ForestNode *GLRParser::parse(const TokenStream &Code) {
+  Terminals = ParsedForest.createTerminals(Code);
+  const Token *Lookahead = &Code.tokens().front();
+  addActions(GSS.addNode(/*StartState*/ 0, nullptr, {}), *Lookahead);
+
+  while (!ShiftList.empty() || !ReduceList.empty()) {
+LLVM_DEBUG(llvm::dbgs() << llvm::formatv(
+   "Lookahead token {0} (id: {1} text: '{2}')\n",
+   G.symbolName(tokenSymbol(Lookahead->Kind)),
+   tokenSymbol(Lookahead->Kind), Lookahead->text()));
+
+performReduction(*Lookahead);
+auto NewHeads = performShift(Code.index(*Lookahead));
+
+if (Lookahead->Kind != tok::eof)
+  ++Lookahead;
+for (const auto &AS : NewHeads)
+  addActions(AS, *Lookahead);
+  }
+
+  if (!AcceptLists.empty()) {
+// FIXME: supporting multiple accepted symbols. It should be fine now, as we
+// only have one production for the start symbol `_`. This would become a
+// problem when we support parsing any code snippet rather than t

[clang] f82ec55 - [OpenMP] Initial parsing/sema for the 'omp target parallel loop' construct

2022-03-24 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-03-24T09:19:00-07:00
New Revision: f82ec5532b2f303732e547226816d7a668db3050

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

LOG: [OpenMP] Initial parsing/sema for the 'omp target parallel loop' construct

 Adds basic parsing/sema/serialization support for the
 #pragma omp target parallel loop directive.

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

Added: 
clang/test/OpenMP/target_parallel_generic_loop_ast_print.cpp
clang/test/OpenMP/target_parallel_generic_loop_messages.cpp

Modified: 
clang/include/clang-c/Index.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/AST/StmtOpenMP.h
clang/include/clang/Basic/StmtNodes.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/StmtOpenMP.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/test/Analysis/cfg-openmp.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 4783744359eec..f28601c37d8ef 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2612,7 +2612,11 @@ enum CXCursorKind {
*/
   CXCursor_OMPParallelGenericLoopDirective = 298,
 
-  CXCursor_LastStmt = CXCursor_OMPParallelGenericLoopDirective,
+  /** OpenMP target parallel loop directive.
+   */
+  CXCursor_OMPTargetParallelGenericLoopDirective = 299,
+
+  CXCursor_LastStmt = CXCursor_OMPTargetParallelGenericLoopDirective,
 
   /**
* Cursor that represents the translation unit itself.

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index ceb874598aded..5aed81d6c72ac 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3082,6 +3082,9 @@ DEF_TRAVERSE_STMT(OMPTargetTeamsGenericLoopDirective,
 
 DEF_TRAVERSE_STMT(OMPParallelGenericLoopDirective,
   { TRY_TO(TraverseOMPExecutableDirective(S)); })
+
+DEF_TRAVERSE_STMT(OMPTargetParallelGenericLoopDirective,
+  { TRY_TO(TraverseOMPExecutableDirective(S)); })
 // OpenMP clauses.
 template 
 bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) {

diff  --git a/clang/include/clang/AST/StmtOpenMP.h 
b/clang/include/clang/AST/StmtOpenMP.h
index 9178b47a0b5f4..28b3567b36556 100644
--- a/clang/include/clang/AST/StmtOpenMP.h
+++ b/clang/include/clang/AST/StmtOpenMP.h
@@ -1529,6 +1529,7 @@ class OMPLoopDirective : public OMPLoopBasedDirective {
T->getStmtClass() == OMPTeamsGenericLoopDirectiveClass ||
T->getStmtClass() == OMPTargetTeamsGenericLoopDirectiveClass ||
T->getStmtClass() == OMPParallelGenericLoopDirectiveClass ||
+   T->getStmtClass() == OMPTargetParallelGenericLoopDirectiveClass ||
T->getStmtClass() == OMPParallelMasterTaskLoopDirectiveClass ||
T->getStmtClass() == OMPParallelMasterTaskLoopSimdDirectiveClass ||
T->getStmtClass() == OMPDistributeDirectiveClass ||
@@ -5767,6 +5768,71 @@ class OMPParallelGenericLoopDirective final : public 
OMPLoopDirective {
 return T->getStmtClass() == OMPParallelGenericLoopDirectiveClass;
   }
 };
+
+/// This represents '#pragma omp target parallel loop' directive.
+///
+/// \code
+/// #pragma omp target parallel loop private(a,b) order(concurrent)
+/// \endcode
+/// In this example directive '#pragma omp target parallel loop' has
+/// clauses 'private' with the variables 'a' and 'b', and order(concurrent).
+///
+class OMPTargetParallelGenericLoopDirective final : public OMPLoopDirective {
+  friend class ASTStmtReader;
+  friend class OMPExecutableDirective;
+  /// Build directive with the given start and end location.
+  ///
+  /// \param StartLoc Starting location of the directive kind.
+  /// \param EndLoc Ending location of the directive.
+  /// \param CollapsedNum Number of collapsed nested loops.
+  ///
+  OMPTargetParallelGenericLoopDirective(SourceLocation StartLoc,
+SourceLocation EndLoc,
+unsigned CollapsedNum)
+  : OMPLoopDirective(OMPTargetParallelGenericLoopDirectiveClass,
+ llvm::omp::OMPD_target_parallel_loop, StartLoc, 
EndLoc,

[PATCH] D122359: [OpenMP] Initial parsing/sema for the 'omp target parallel loop' construct

2022-03-24 Thread Mike Rice 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 rGf82ec5532b2f: [OpenMP] Initial parsing/sema for the 
'omp target parallel loop' construct (authored by mikerice).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122359

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/Analysis/cfg-openmp.cpp
  clang/test/OpenMP/target_parallel_generic_loop_ast_print.cpp
  clang/test/OpenMP/target_parallel_generic_loop_messages.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -1828,6 +1828,33 @@
 VersionedClause,
   ];
 }
+def OMP_target_parallel_loop : Directive<"target parallel loop"> {
+  let allowedClauses = [
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+  ];
+  let allowedOnceClauses = [
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+VersionedClause,
+  ];
+}
 def OMP_Metadirective : Directive<"metadirective"> {
   let allowedClauses = [VersionedClause];
   let allowedOnceClauses = [VersionedClause];
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -835,6 +835,9 @@
   case Stmt::OMPParallelGenericLoopDirectiveClass:
 K = CXCursor_OMPParallelGenericLoopDirective;
 break;
+  case Stmt::OMPTargetParallelGenericLoopDirectiveClass:
+K = CXCursor_OMPTargetParallelGenericLoopDirective;
+break;
   case Stmt::BuiltinBitCastExprClass:
 K = CXCursor_BuiltinBitCastExpr;
   }
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5732,6 +5732,8 @@
 return cxstring::createRef("OMPTargetTeamsGenericLoopDirective");
   case CXCursor_OMPParallelGenericLoopDirective:
 return cxstring::createRef("OMPParallelGenericLoopDirective");
+  case CXCursor_OMPTargetParallelGenericLoopDirective:
+return cxstring::createRef("OMPTargetParallelGenericLoopDirective");
   case CXCursor_OverloadCandidate:
 return cxstring::createRef("OverloadCandidate");
   case CXCursor_TypeAliasTemplateDecl:
Index: clang/test/OpenMP/target_parallel_generic_loop_messages.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_parallel_generic_loop_messages.cpp
@@ -0,0 +1,165 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -verify -fopenmp \
+// RUN:  -fopenmp-version=51 -Wuninitialized %s
+
+void foo()
+{
+  int i,j,k;
+  int z;
+
+  // expected-error@+2 {{statement after '#pragma omp target parallel loop' must be a for loop}}
+  #pragma omp target parallel loop bind(thread)
+  i = 0;
+
+  // OpenMP 5.1 [2.22 Nesting of regions]
+  //
+  // A barrier region may not be closely nested inside a worksharing, loop,
+  // task, taskloop, critical, ordered, atomic, or masked region.
+
+  // expected-error@+3 {{region cannot be closely nested inside 'target parallel loop' region}}
+  #pragma omp target parallel loop bind(thread)
+  for (i=0; i<1000; ++i) {
+#pragma omp barrier
+  }
+
+  // A masked region may not be closely nested inside a worksharing, loop,
+  // atomic, task, or taskloop region.
+
+  // expected-error@+3 {{region cannot be closely nested inside 'target parallel loop' region}}
+  #pragma omp target parallel loop bind(thread)
+  for (i=0; i<1000; ++i) {
+#pragma omp masked filter(2)
+{ }
+  }
+
+  // An ordered region that corresponds to an ordered construct without any
+  // claus

[PATCH] D122409: [libclang] Add missing CursorKind enums defined in Index.h.

2022-03-24 Thread Tao He via Phabricator via cfe-commits
sighingnow created this revision.
Herald added a subscriber: arphaman.
Herald added a project: All.
sighingnow requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Signed-off-by: Tao He 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122409

Files:
  clang/bindings/python/clang/cindex.py
  clang/bindings/python/tests/cindex/test_cursor_kind.py

Index: clang/bindings/python/tests/cindex/test_cursor_kind.py
===
--- clang/bindings/python/tests/cindex/test_cursor_kind.py
+++ clang/bindings/python/tests/cindex/test_cursor_kind.py
@@ -23,6 +23,7 @@
 self.assertIn(CursorKind.MS_ASM_STMT, kinds)
 self.assertIn(CursorKind.MODULE_IMPORT_DECL, kinds)
 self.assertIn(CursorKind.TYPE_ALIAS_TEMPLATE_DECL, kinds)
+self.assertIn(CursorKind.BUILTIN_BIT_CAST_EXPR, kinds)
 
 def test_kind_groups(self):
 """Check that every kind classifies to exactly one group."""
Index: clang/bindings/python/clang/cindex.py
===
--- clang/bindings/python/clang/cindex.py
+++ clang/bindings/python/clang/cindex.py
@@ -1084,6 +1084,17 @@
 # Represents an @available(...) check.
 CursorKind.OBJC_AVAILABILITY_CHECK_EXPR = CursorKind(148)
 
+# Fixed point literal
+CursorKind.FIXED_POINT_LITERAL = 149
+
+# OpenMP 5.0 [2.1.4, Array Shaping].
+CursorKind.OMP_ARRAY_SHAPING_EXPR = 150
+
+# OpenMP 5.0 [2.1.6 Iterators]
+CursorKind.OMP_ITERATOR_EXPR = 151
+
+# OpenCL's addrspace_cast<> expression.
+CursorKind.CXX_ADDRSPACE_CAST_EXPR = 152
 
 # A statement whose specific kind is not exposed via this interface.
 #
@@ -1305,6 +1316,87 @@
 # OpenMP teams distribute directive.
 CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(271)
 
+# OpenMP teams distribute simd directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE = 272
+
+# OpenMP teams distribute parallel for simd directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE = 273
+
+# OpenMP teams distribute parallel for directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE = 274
+
+# OpenMP target teams directive.
+CursorKind.OMP_TARGET_TEAMS_DIRECTIVE = 275
+
+# OpenMP target teams distribute directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE = 276
+
+# OpenMP target teams distribute parallel for directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE = 277
+
+# OpenMP target teams distribute parallel for simd directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE = 278
+
+# OpenMP target teams distribute simd directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE = 279
+
+# C++2a std::bit_cast expression.
+CursorKind.BUILTIN_BIT_CAST_EXPR = 280
+
+# OpenMP master taskloop directive.
+CursorKind.OMP_MASTER_TASK_LOOP_DIRECTIVE = 281
+
+# OpenMP parallel master taskloop directive.
+CursorKind.OMP_PARALLEL_MASTER_TASK_LOOP_DIRECTIVE = 282
+
+# OpenMP master taskloop simd directive.
+CursorKind.OMP_MASTER_TASK_LOOP_SIMD_DIRECTIVE = 283
+
+# OpenMP parallel master taskloop simd directive.
+CursorKind.OMP_PARALLEL_MASTER_TASK_LOOP_SIMD_DIRECTIVE = 284
+
+# OpenMP parallel master directive.
+CursorKind.OMP_PARALLEL_MASTER_DIRECTIVE = 285
+
+# OpenMP depobj directive.
+CursorKind.OMP_DEPOBJ_DIRECTIVE = 286
+
+# OpenMP scan directive.
+CursorKind.OMP_SCAN_DIRECTIVE = 287
+
+# OpenMP tile directive.
+CursorKind.OMP_TILE_DIRECTIVE = 288
+
+# OpenMP canonical loop.
+CursorKind.OMP_CANONICAL_LOOP = 289
+
+# OpenMP interop directive.
+CursorKind.OMP_INTEROP_DIRECTIVE = 290
+
+# OpenMP dispatch directive.
+CursorKind.OMP_DISPATCH_DIRECTIVE = 291
+
+# OpenMP masked directive.
+CursorKind.OMP_MASKED_DIRECTIVE = 292
+
+# OpenMP unroll directive.
+CursorKind.OMP_UNROLL_DIRECTIVE = 293
+
+# OpenMP metadirective directive.
+CursorKind.OMP_META_DIRECTIVE = 294
+
+# OpenMP loop directive.
+CursorKind.OMP_GENERIC_LOOP_DIRECTIVE = 295
+
+# OpenMP teams loop directive.
+CursorKind.OMP_TEAMS_GENERIC_LOOP_DIRECTIVE = 296
+
+# OpenMP target teams loop directive.
+CursorKind.OMP_TARGET_TEAMS_GENERIC_LOOP_DIRECTIVE = 297
+
+# OpenMP parallel loop directive.
+CursorKind.OMP_PARALLEL_GENERIC_LOOP_DIRECTIVE = 298
+
 ###
 # Other Kinds
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122409: [libclang] Add missing CursorKind enums defined in Index.h.

2022-03-24 Thread Tao He via Phabricator via cfe-commits
sighingnow updated this revision to Diff 417955.
sighingnow edited the summary of this revision.
sighingnow added a comment.

Add summary of this diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122409

Files:
  clang/bindings/python/clang/cindex.py
  clang/bindings/python/tests/cindex/test_cursor_kind.py

Index: clang/bindings/python/tests/cindex/test_cursor_kind.py
===
--- clang/bindings/python/tests/cindex/test_cursor_kind.py
+++ clang/bindings/python/tests/cindex/test_cursor_kind.py
@@ -23,6 +23,7 @@
 self.assertIn(CursorKind.MS_ASM_STMT, kinds)
 self.assertIn(CursorKind.MODULE_IMPORT_DECL, kinds)
 self.assertIn(CursorKind.TYPE_ALIAS_TEMPLATE_DECL, kinds)
+self.assertIn(CursorKind.BUILTIN_BIT_CAST_EXPR, kinds)
 
 def test_kind_groups(self):
 """Check that every kind classifies to exactly one group."""
Index: clang/bindings/python/clang/cindex.py
===
--- clang/bindings/python/clang/cindex.py
+++ clang/bindings/python/clang/cindex.py
@@ -1084,6 +1084,17 @@
 # Represents an @available(...) check.
 CursorKind.OBJC_AVAILABILITY_CHECK_EXPR = CursorKind(148)
 
+# Fixed point literal
+CursorKind.FIXED_POINT_LITERAL = 149
+
+# OpenMP 5.0 [2.1.4, Array Shaping].
+CursorKind.OMP_ARRAY_SHAPING_EXPR = 150
+
+# OpenMP 5.0 [2.1.6 Iterators]
+CursorKind.OMP_ITERATOR_EXPR = 151
+
+# OpenCL's addrspace_cast<> expression.
+CursorKind.CXX_ADDRSPACE_CAST_EXPR = 152
 
 # A statement whose specific kind is not exposed via this interface.
 #
@@ -1305,6 +1316,87 @@
 # OpenMP teams distribute directive.
 CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(271)
 
+# OpenMP teams distribute simd directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE = 272
+
+# OpenMP teams distribute parallel for simd directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE = 273
+
+# OpenMP teams distribute parallel for directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE = 274
+
+# OpenMP target teams directive.
+CursorKind.OMP_TARGET_TEAMS_DIRECTIVE = 275
+
+# OpenMP target teams distribute directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE = 276
+
+# OpenMP target teams distribute parallel for directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE = 277
+
+# OpenMP target teams distribute parallel for simd directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE = 278
+
+# OpenMP target teams distribute simd directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE = 279
+
+# C++2a std::bit_cast expression.
+CursorKind.BUILTIN_BIT_CAST_EXPR = 280
+
+# OpenMP master taskloop directive.
+CursorKind.OMP_MASTER_TASK_LOOP_DIRECTIVE = 281
+
+# OpenMP parallel master taskloop directive.
+CursorKind.OMP_PARALLEL_MASTER_TASK_LOOP_DIRECTIVE = 282
+
+# OpenMP master taskloop simd directive.
+CursorKind.OMP_MASTER_TASK_LOOP_SIMD_DIRECTIVE = 283
+
+# OpenMP parallel master taskloop simd directive.
+CursorKind.OMP_PARALLEL_MASTER_TASK_LOOP_SIMD_DIRECTIVE = 284
+
+# OpenMP parallel master directive.
+CursorKind.OMP_PARALLEL_MASTER_DIRECTIVE = 285
+
+# OpenMP depobj directive.
+CursorKind.OMP_DEPOBJ_DIRECTIVE = 286
+
+# OpenMP scan directive.
+CursorKind.OMP_SCAN_DIRECTIVE = 287
+
+# OpenMP tile directive.
+CursorKind.OMP_TILE_DIRECTIVE = 288
+
+# OpenMP canonical loop.
+CursorKind.OMP_CANONICAL_LOOP = 289
+
+# OpenMP interop directive.
+CursorKind.OMP_INTEROP_DIRECTIVE = 290
+
+# OpenMP dispatch directive.
+CursorKind.OMP_DISPATCH_DIRECTIVE = 291
+
+# OpenMP masked directive.
+CursorKind.OMP_MASKED_DIRECTIVE = 292
+
+# OpenMP unroll directive.
+CursorKind.OMP_UNROLL_DIRECTIVE = 293
+
+# OpenMP metadirective directive.
+CursorKind.OMP_META_DIRECTIVE = 294
+
+# OpenMP loop directive.
+CursorKind.OMP_GENERIC_LOOP_DIRECTIVE = 295
+
+# OpenMP teams loop directive.
+CursorKind.OMP_TEAMS_GENERIC_LOOP_DIRECTIVE = 296
+
+# OpenMP target teams loop directive.
+CursorKind.OMP_TARGET_TEAMS_GENERIC_LOOP_DIRECTIVE = 297
+
+# OpenMP parallel loop directive.
+CursorKind.OMP_PARALLEL_GENERIC_LOOP_DIRECTIVE = 298
+
 ###
 # Other Kinds
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-03-24 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.
Herald added a subscriber: StephenFan.

@beanz Let me know if you need help, I'm happy to commandeer the change if 
you're too busy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

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


[PATCH] D122409: [libclang] Add missing CursorKind enums defined in Index.h.

2022-03-24 Thread Tao He via Phabricator via cfe-commits
sighingnow added a comment.

See also: 
https://github.com/llvm/llvm-project/blob/main/clang/include/clang-c/Index.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122409

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


[PATCH] D109977: LLVM Driver Multicall tool

2022-03-24 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

In D109977#3405687 , @phosek wrote:

> @beanz Let me know if you need help, I'm happy to commandeer the change if 
> you're too busy.

Please feel free to commandeer it. I'm really sorry I've held this up so long 
and I'm totally swamped right now :(.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

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


[PATCH] D119409: [C++20] [Modules] Remain dynamic initializing internal-linkage variables in module interface unit

2022-03-24 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

is this an issue for Clang Header Modules codegen too? (maybe the solution 
should be the same for both, then) 
& maybe we should do this regardless of the presence/absence/type of 
initializer, just for consistency?


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

https://reviews.llvm.org/D119409

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


  1   2   3   >