[clang] [OpenMP][NFC] Remove executable cases from declaration switch (PR #106438)

2024-08-28 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/106438
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenMP][NFC] Remove executable cases from declaration switch (PR #106438)

2024-08-28 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/106438

The executable directives are handled earlier.

>From 3a7f341c33c0f91f2ca6f31762e71fcae6f1a69d Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Wed, 28 Aug 2024 11:38:12 -0700
Subject: [PATCH] [OpenMP][NFC] Remove executable cases from declaration switch

The executable directives are handled earlier.
---
 clang/lib/Parse/ParseOpenMP.cpp | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 61aa72c30a4654..64dfcd47296998 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2954,8 +2954,6 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
 }
 break;
   }
-  case OMPD_reverse:
-  case OMPD_interchange:
   case OMPD_declare_target: {
 SourceLocation DTLoc = ConsumeAnyToken();
 bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end);

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


[clang] [clang] Fix compile-time regression from attribute arg checking change (PR #101768)

2024-08-06 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/101768
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix compile-time regression from attribute arg checking change (PR #101768)

2024-08-06 Thread Mike Rice via cfe-commits

mikerice1969 wrote:

Thanks @nikic!

https://github.com/llvm/llvm-project/pull/101768
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Update argument checking tablegen code to use a 'full' name (PR #99993)

2024-08-03 Thread Mike Rice via cfe-commits

mikerice1969 wrote:

Proposed fix for compile-time regression 
https://github.com/llvm/llvm-project/pull/101768

https://github.com/llvm/llvm-project/pull/3
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix compile-time regression from attribute arg checking change (PR #101768)

2024-08-02 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/101768

In 2acf77f987331c05520c5bfd849326909ffce983 code was added to use the 'full' 
name including syntax and scope.

Instead of building up a large string for each name, add syntax and scope 
checks to the value expression in tablegen.

There is already code to generate expressions for target specific attributes. 
This change refactors and adds to that code to include syntax and scope checks.

The tablegen avoids generating the complicated expression unless there are two 
attributes using the same name, otherwise the case values will be as simple as 
before.

Removes the currently unused attributeHasStrictIdentifierArgAtIndex function 
and the related tablegen.

>From 4cc7055227ea8115c93c806c42270d7da8e6e89d Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Fri, 2 Aug 2024 14:34:02 -0700
Subject: [PATCH 1/2] [clang] Fix compile-time regression from attribute arg
 checking change

In 2acf77f987331c05520c5bfd849326909ffce983 code was added to use the
'full' name including syntax and scope.

Instead of building up a large string for each name, add syntax and
scope checks to the value expression in tablegen.

There is already code to generate expressions for target specific
attributes. This change refactors and adds to that code to include
syntax and scope checks.

The tablegen avoids generating the complicated expression unless there
are two attributes using the same name, otherwise the case values will
be as simple as before.

Removes the currently unused attributeHasStrictIdentifierArgAtIndex
function and the related tablegen.
---
 .../include/clang/Basic/AttributeCommonInfo.h |   6 -
 clang/lib/Basic/Attributes.cpp|  34 ---
 clang/lib/Parse/ParseDecl.cpp |  71 ++---
 .../TableGen/attrs-parser-string-switches.td  | 132 -
 clang/utils/TableGen/ClangAttrEmitter.cpp | 276 +++---
 5 files changed, 249 insertions(+), 270 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index cdf9dcaff7508..5f024b4b5fd78 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -191,12 +191,6 @@ class AttributeCommonInfo {
   /// __gnu__::__attr__ will be normalized to gnu::attr).
   std::string getNormalizedFullName() const;
 
-  /// Generate a normalized full name, with syntax, scope and name.
-  static std::string
-  normalizeFullNameWithSyntax(const IdentifierInfo *Name,
-  const IdentifierInfo *Scope,
-  AttributeCommonInfo::Syntax SyntaxUsed);
-
   bool isDeclspecAttribute() const { return SyntaxUsed == AS_Declspec; }
   bool isMicrosoftAttribute() const { return SyntaxUsed == AS_Microsoft; }
 
diff --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp
index a39eb85f7e8fa..867d241a2cf84 100644
--- a/clang/lib/Basic/Attributes.cpp
+++ b/clang/lib/Basic/Attributes.cpp
@@ -153,40 +153,6 @@ std::string AttributeCommonInfo::getNormalizedFullName() 
const {
   normalizeName(getAttrName(), getScopeName(), getSyntax()));
 }
 
-static StringRef getSyntaxName(AttributeCommonInfo::Syntax SyntaxUsed) {
-  switch (SyntaxUsed) {
-  case AttributeCommonInfo::AS_GNU:
-return "GNU";
-  case AttributeCommonInfo::AS_CXX11:
-return "CXX11";
-  case AttributeCommonInfo::AS_C23:
-return "C23";
-  case AttributeCommonInfo::AS_Declspec:
-return "Declspec";
-  case AttributeCommonInfo::AS_Microsoft:
-return "Microsoft";
-  case AttributeCommonInfo::AS_Keyword:
-return "Keyword";
-  case AttributeCommonInfo::AS_Pragma:
-return "Pragma";
-  case AttributeCommonInfo::AS_ContextSensitiveKeyword:
-return "ContextSensitiveKeyword";
-  case AttributeCommonInfo::AS_HLSLAnnotation:
-return "HLSLAnnotation";
-  case AttributeCommonInfo::AS_Implicit:
-return "Implicit";
-  }
-  llvm_unreachable("Invalid attribute syntax");
-}
-
-std::string AttributeCommonInfo::normalizeFullNameWithSyntax(
-const IdentifierInfo *Name, const IdentifierInfo *ScopeName,
-Syntax SyntaxUsed) {
-  return (Twine(getSyntaxName(SyntaxUsed)) +
-  "::" + normalizeName(Name, ScopeName, SyntaxUsed))
-  .str();
-}
-
 unsigned AttributeCommonInfo::calculateAttributeSpellingListIndex() const {
   // Both variables will be used in tablegen generated
   // attribute spell list index matching code.
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 4a2d9a650e20c..719dec1422b69 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -314,27 +314,24 @@ void Parser::ParseGNUAttributes(ParsedAttributes &Attrs,
 }
 
 /// Determine whether the given attribute has an identifier argument.
-static bool attributeHasIdentifierArg(const IdentifierInfo &II,
+static bool attributeHasIdentifierArg(const llvm::Triple &T,
+ 

[clang] [clang] Update argument checking tablegen code to use a 'full' name (PR #99993)

2024-07-30 Thread Mike Rice via cfe-commits

mikerice1969 wrote:

The old tablegen produced a single entry per name:

`.Case("unroll", true)`

The new tablegen can produce multiple entries:

```
.Case("Microsoft::unroll", true)
.Case("Pragma::unroll", true)
```

I think we can instead produce something like this, one per name:

```
.Case("unroll",
(Syntax==AttributeCommonInfo::AS_Microsoft && !Scope) || 
(Syntax==AttributeCommonInfo::AS_Pragma && Scope && Scope=="whatever") ||
...)
```
That should elimate the need for any new std::strings.  @AaronBallman does this 
sound reasonable?

https://github.com/llvm/llvm-project/pull/3
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Update argument checking tablegen code to use a 'full' name (PR #99993)

2024-07-30 Thread Mike Rice via cfe-commits

mikerice1969 wrote:

> You probably need to separately match the syntax and the name without 
> constructing a temporary `std::string`.

@nikic Thanks. I'll look into improving this. If anyone thinks this should be 
reverted until then let me know, or just go ahead and revert it.

https://github.com/llvm/llvm-project/pull/3
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Update argument checking tablegen code to use a 'full' name (PR #99993)

2024-07-30 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/3
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Update argument checking tablegen code to use a 'full' name (PR #99993)

2024-07-29 Thread Mike Rice via cfe-commits

mikerice1969 wrote:

> That code was added very recently by #94056 and seem to be specific to the 
> `ptrauth_vtable_pointer` attribute. Perhaps we're lacking test coverage if 
> nothing breaks without that code?

@AaronBallman The code is logically useless so there's no way to add tests that 
make it useful.

```
do {
  if (Tok.is(tok::identifier) && attributeHasStrictIdentifierArgAtIndex()) {
ArgExprs.push_back(ParseIdentifierLoc());   
continue;
  }
  if (Tok.is(tok::identifier)) { 
ArgExprs.push_back(ParseIdentifierLoc());
  } else {
// Do something if not an identifier
  }
} while (TryConsumeToken(tok::comma);
```
It doesn't matter what attributeHasStrictIdentifierArgAtIndex returns we will 
always just add identifiers to ArgExprs.
The only question is what was intended in the code.

Unless @ojhunt and/or @ahmedbougacha can clarify I think we should just remove 
it.


https://github.com/llvm/llvm-project/pull/3
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Default and Relaxed Availability Diagnostics (PR #92704)

2024-07-26 Thread Mike Rice via cfe-commits


@@ -290,3 +294,296 @@ void SemaHLSL::DiagnoseAttrStageMismatch(
   << A << HLSLShaderAttr::ConvertShaderTypeToStr(Stage)
   << (AllowedStages.size() != 1) << join(StageStrings, ", ");
 }
+
+namespace {
+
+/// This class implements HLSL availability diagnostics for default
+/// and relaxed mode
+///
+/// The goal of this diagnostic is to emit an error or warning when an
+/// unavailable API is found in code that is reachable from the shader
+/// entry function or from an exported function (when compiling a shader
+/// library).
+///
+/// This is done by traversing the AST of all shader entry point functions
+/// and of all exported functions, and any functions that are refrenced
+/// from this AST. In other words, any functions that are reachable from
+/// the entry points.
+class DiagnoseHLSLAvailability
+: public RecursiveASTVisitor {
+
+  Sema &SemaRef;
+
+  // Stack of functions to be scaned
+  llvm::SmallVector DeclsToScan;
+
+  // Tracks which environments functions have been scanned in.
+  //
+  // Maps FunctionDecl to an unsigned number that represents the set of shader
+  // environments the function has been scanned for.
+  // Since HLSLShaderAttr::ShaderType enum is generated from Attr.td and is
+  // defined without any assigned values, it is guaranteed to be numbered
+  // sequentially from 0 up and we can use it to 'index' individual bits
+  // in the set.
+  // The N'th bit in the set will be set if the function has been scanned
+  // in shader environment whose ShaderType integer value equals N.
+  // For example, if a function has been scanned in compute and pixel stage
+  // environment, the value will be 0x21 (11 binary) because
+  // (int)HLSLShaderAttr::ShaderType::Pixel == 1 and
+  // (int)HLSLShaderAttr::ShaderType::Compute == 5.
+  // A FunctionDecl is mapped to 0 (or not included in the map) if it has not
+  // been scanned in any environment.
+  llvm::DenseMap ScannedDecls;
+
+  // Do not access these directly, use the get/set methods below to make
+  // sure the values are in sync
+  llvm::Triple::EnvironmentType CurrentShaderEnvironment;
+  unsigned CurrentShaderStageBit;
+
+  // True if scanning a function that was already scanned in a different
+  // shader stage context, and therefore we should not report issues that
+  // depend only on shader model version because they would be duplicate.
+  bool ReportOnlyShaderStageIssues;

mikerice1969 wrote:

@hekota Thanks!

https://github.com/llvm/llvm-project/pull/92704
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema][NFC] remove unreachable return statement (PR #100642)

2024-07-26 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/100642
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Default and Relaxed Availability Diagnostics (PR #92704)

2024-07-25 Thread Mike Rice via cfe-commits


@@ -290,3 +294,296 @@ void SemaHLSL::DiagnoseAttrStageMismatch(
   << A << HLSLShaderAttr::ConvertShaderTypeToStr(Stage)
   << (AllowedStages.size() != 1) << join(StageStrings, ", ");
 }
+
+namespace {
+
+/// This class implements HLSL availability diagnostics for default
+/// and relaxed mode
+///
+/// The goal of this diagnostic is to emit an error or warning when an
+/// unavailable API is found in code that is reachable from the shader
+/// entry function or from an exported function (when compiling a shader
+/// library).
+///
+/// This is done by traversing the AST of all shader entry point functions
+/// and of all exported functions, and any functions that are refrenced
+/// from this AST. In other words, any functions that are reachable from
+/// the entry points.
+class DiagnoseHLSLAvailability
+: public RecursiveASTVisitor {
+
+  Sema &SemaRef;
+
+  // Stack of functions to be scaned
+  llvm::SmallVector DeclsToScan;
+
+  // Tracks which environments functions have been scanned in.
+  //
+  // Maps FunctionDecl to an unsigned number that represents the set of shader
+  // environments the function has been scanned for.
+  // Since HLSLShaderAttr::ShaderType enum is generated from Attr.td and is
+  // defined without any assigned values, it is guaranteed to be numbered
+  // sequentially from 0 up and we can use it to 'index' individual bits
+  // in the set.
+  // The N'th bit in the set will be set if the function has been scanned
+  // in shader environment whose ShaderType integer value equals N.
+  // For example, if a function has been scanned in compute and pixel stage
+  // environment, the value will be 0x21 (11 binary) because
+  // (int)HLSLShaderAttr::ShaderType::Pixel == 1 and
+  // (int)HLSLShaderAttr::ShaderType::Compute == 5.
+  // A FunctionDecl is mapped to 0 (or not included in the map) if it has not
+  // been scanned in any environment.
+  llvm::DenseMap ScannedDecls;
+
+  // Do not access these directly, use the get/set methods below to make
+  // sure the values are in sync
+  llvm::Triple::EnvironmentType CurrentShaderEnvironment;
+  unsigned CurrentShaderStageBit;
+
+  // True if scanning a function that was already scanned in a different
+  // shader stage context, and therefore we should not report issues that
+  // depend only on shader model version because they would be duplicate.
+  bool ReportOnlyShaderStageIssues;

mikerice1969 wrote:

Hi @hekota, just following up on some static verifier hits. These three members 
are reported as not initialized in the constructor. Is it possible to 
initialize these to a sane default? That would make it clear to random readers 
(and static verifier tools) that it wasn't overlooked.

https://github.com/llvm/llvm-project/pull/92704
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer][NFC] Factor out NoOwnershipChangeVisitor (PR #94357)

2024-07-25 Thread Mike Rice via cfe-commits
=?utf-8?q?Kristóf?= Umann 
Message-ID:
In-Reply-To: 



@@ -804,23 +751,21 @@ class NoOwnershipChangeVisitor final : public 
NoStateChangeFuncVisitor {
 return false;
   }
 
+  bool hasResourceStateChanged(ProgramStateRef CallEnterState,
+   ProgramStateRef CallExitEndState) final {
+return CallEnterState->get(Sym) !=
+   CallExitEndState->get(Sym);
+  }
+
   /// Heuristically guess whether the callee intended to free memory. This is
   /// done syntactically, because we are trying to argue about alternative
   /// paths of execution, and as a consequence we don't have path-sensitive
   /// information.
-  bool doesFnIntendToHandleOwnership(const Decl *Callee, ASTContext &ACtx) {
+  bool doesFnIntendToHandleOwnership(const Decl *Callee,
+ ASTContext &ACtx) final {
 using namespace clang::ast_matchers;
 const FunctionDecl *FD = dyn_cast(Callee);

mikerice1969 wrote:

Following up on static verifier hits. This dyn_cast result is now not checked 
before it is dereferenced below (FD->getBody()). Should this be a cast instead? 
Or should there be a check before the dereference?

https://github.com/llvm/llvm-project/pull/94357
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema][NFC] remove unreachable return statement (PR #100642)

2024-07-25 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/100642

The switch now returns in every case so the end return is unreachable.

>From 8804f18fcaf1a70bad10a8e66414f91556df23bd Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Thu, 25 Jul 2024 11:35:11 -0700
Subject: [PATCH] [clang][Sema][NFC] remove unreachable return statement

The switch now returns in every case so the end return is unreachable.
---
 clang/lib/Sema/SemaPPC.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaPPC.cpp b/clang/lib/Sema/SemaPPC.cpp
index 99f46b12e6968..5b764ed396ebc 100644
--- a/clang/lib/Sema/SemaPPC.cpp
+++ b/clang/lib/Sema/SemaPPC.cpp
@@ -93,7 +93,6 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo 
&TI,
   unsigned BuiltinID,
   CallExpr *TheCall) {
   ASTContext &Context = getASTContext();
-  unsigned i = 0, l = 0, u = 0;
   bool IsTarget64Bit = TI.getTypeWidth(TI.getIntPtrType()) == 64;
   llvm::APSInt Result;
 
@@ -248,7 +247,7 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo 
&TI,
 return BuiltinPPCMMACall(TheCall, BuiltinID, Types);
 #include "clang/Basic/BuiltinsPPC.def"
   }
-  return SemaRef.BuiltinConstantArgRange(TheCall, i, l, u);
+  llvm_unreachable("must return from switch");
 }
 
 // Check if the given type is a non-pointer PPC MMA type. This function is used

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


[clang] [Clang] Fix potential null pointer dereferences in Sema::AddInitializerToDecl (PR #94368)

2024-07-25 Thread Mike Rice via cfe-commits


@@ -13681,12 +13681,13 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
 }
 
 Init = Result.getAs();
+assert(Init && "Init must not be null");
+
 IsParenListInit = !InitSeq.steps().empty() &&
   InitSeq.step_begin()->Kind ==
   InitializationSequence::SK_ParenthesizedListInit;
 QualType VDeclType = VDecl->getType();
-if (Init && !Init->getType().isNull() &&
-!Init->getType()->isDependentType() && !VDeclType->isDependentType() &&
+if (!Init->getType()->isDependentType() && !VDeclType->isDependentType() &&

mikerice1969 wrote:

> Was the static analysis tool perhaps complaining about later uses of `Init`?

Yes. FWIW Here is the logic:

```
if (!VDecl->isInvalidDecl()) {

  ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Args, &DclT);
  if (Result.isInvalid()) {
return 
  }
  Init = Result.getAs();

  if (Init && !Init->getType().isNull() && // verifier expects Init can be null.
}

…

if (!VDecl->isInvalidDecl()) {
  
  .. Init->getBeginLoc()))  // Deref of Init without check
}
```


https://github.com/llvm/llvm-project/pull/94368
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Pick up input headers by directory traversal (PR #94508)

2024-07-25 Thread Mike Rice via cfe-commits


@@ -0,0 +1,300 @@
+//===- DirectoryScanner.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/InstallAPI/DirectoryScanner.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/TextAPI/DylibReader.h"
+
+using namespace llvm;
+using namespace llvm::MachO;
+
+namespace clang::installapi {
+
+HeaderSeq DirectoryScanner::getHeaders(ArrayRef Libraries) {
+  HeaderSeq Headers;
+  for (const Library &Lib : Libraries)
+llvm::append_range(Headers, Lib.Headers);
+  return Headers;
+}
+
+llvm::Error DirectoryScanner::scan(StringRef Directory) {
+  if (Mode == ScanMode::ScanFrameworks)
+return scanForFrameworks(Directory);
+
+  return scanForUnwrappedLibraries(Directory);
+}
+
+llvm::Error DirectoryScanner::scanForUnwrappedLibraries(StringRef Directory) {
+  // Check some known sub-directory locations.
+  auto GetDirectory = [&](const char *Sub) -> OptionalDirectoryEntryRef {
+SmallString Path(Directory);
+sys::path::append(Path, Sub);
+return FM.getOptionalDirectoryRef(Path);
+  };
+
+  auto DirPublic = GetDirectory("usr/include");
+  auto DirPrivate = GetDirectory("usr/local/include");
+  if (!DirPublic && !DirPrivate) {
+std::error_code ec = std::make_error_code(std::errc::not_a_directory);
+return createStringError(ec,
+ "cannot find any public (usr/include) or private "
+ "(usr/local/include) header directory");
+  }
+
+  Library &Lib = getOrCreateLibrary(Directory, Libraries);
+  Lib.IsUnwrappedDylib = true;
+
+  if (DirPublic)
+if (Error Err = scanHeaders(DirPublic->getName(), Lib, HeaderType::Public,
+Directory))
+  return Err;
+
+  if (DirPrivate)
+if (Error Err = scanHeaders(DirPrivate->getName(), Lib, 
HeaderType::Private,
+Directory))
+  return Err;
+
+  return Error::success();
+}
+
+static bool isFramework(StringRef Path) {
+  while (Path.back() == '/')
+Path = Path.slice(0, Path.size() - 1);
+
+  return llvm::StringSwitch(llvm::sys::path::extension(Path))
+  .Case(".framework", true)
+  .Default(false);
+}
+
+Library &
+DirectoryScanner::getOrCreateLibrary(StringRef Path,
+ std::vector &Libs) const {
+  if (Path.consume_front(RootPath) && Path.empty())
+Path = "/";
+
+  auto LibIt =
+  find_if(Libs, [Path](const Library &L) { return L.getPath() == Path; });
+  if (LibIt != Libs.end())
+return *LibIt;
+
+  Libs.emplace_back(Path);
+  return Libs.back();
+}
+
+Error DirectoryScanner::scanHeaders(StringRef Path, Library &Lib,
+HeaderType Type, StringRef BasePath,
+StringRef ParentPath) const {
+  std::error_code ec;
+  auto &FS = FM.getVirtualFileSystem();
+  PathSeq SubDirectories;
+  for (vfs::directory_iterator i = FS.dir_begin(Path, ec), ie; i != ie;
+   i.increment(ec)) {
+StringRef HeaderPath = i->path();
+if (ec)
+  return createStringError(ec, "unable to read: " + HeaderPath);
+
+if (sys::fs::is_symlink_file(HeaderPath))
+  continue;
+
+// Ignore tmp files from unifdef.
+const StringRef Filename = sys::path::filename(HeaderPath);
+if (Filename.starts_with("."))
+  continue;
+
+// If it is a directory, remember the subdirectory.
+if (FM.getOptionalDirectoryRef(HeaderPath))
+  SubDirectories.push_back(HeaderPath.str());
+
+if (!isHeaderFile(HeaderPath))
+  continue;
+
+// Skip files that do not exist. This usually happens for broken symlinks.
+if (FS.status(HeaderPath) == std::errc::no_such_file_or_directory)
+  continue;
+
+auto IncludeName = createIncludeHeaderName(HeaderPath);
+Lib.addHeaderFile(HeaderPath, Type,
+  IncludeName.has_value() ? IncludeName.value() : "");
+  }
+
+  // Go through the subdirectories.
+  // Sort the sub-directory first since different file systems might have
+  // different traverse order.
+  llvm::sort(SubDirectories);
+  if (ParentPath.empty())
+ParentPath = Path;
+  for (const StringRef Dir : SubDirectories)
+return scanHeaders(Dir, Lib, Type, BasePath, ParentPath);

mikerice1969 wrote:

Hi @cyndyishida Our static verification run reports that this loop always exits 
on the first iteration (so it is not really a loop). Is that really what you 
want here? If you only want to scan the first item maybe something other than a 
loop makes sense?

https://github.com/llvm/llvm-project/pull/94508
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http

[clang] [clang][NFC] remove unneeded nullptr checks after dereference (PR #100489)

2024-07-25 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/100489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][NFC] remove unneeded nullptr checks after dereference (PR #100489)

2024-07-24 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/100489

Fix static verifer concerns of null pointer checks after dereferencing  
the pointer. Update the assert to make it super clear it is not null and
remove the checks.  

>From e7d006169a195856eb55a910a162286eb5925cb1 Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Wed, 24 Jul 2024 17:03:39 -0700
Subject: [PATCH 1/2] [clang][NFC] remove unneeded nullptr checks after
 dereference

Fix static verifer concerns of null pointer checks after dereferencing
the pointer. Update the assert to make it super clear it is not null and
remove the checks.
---
 clang/lib/Sema/SemaDeclCXX.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 04b8d88cae217..a9e2495cf2cde 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -12248,16 +12248,16 @@ Decl *Sema::ActOnUsingEnumDeclaration(Scope *S, 
AccessSpecifier AS,
   SourceLocation EnumLoc, SourceRange 
TyLoc,
   const IdentifierInfo &II, ParsedType Ty,
   CXXScopeSpec *SS) {
-  assert(!SS->isInvalid() && "ScopeSpec is invalid");
+  assert(SS && !SS->isInvalid() && "ScopeSpec is invalid");
   TypeSourceInfo *TSI = nullptr;
   SourceLocation IdentLoc = TyLoc.getBegin();
   QualType EnumTy = GetTypeFromParser(Ty, &TSI);
   if (EnumTy.isNull()) {
-Diag(IdentLoc, SS && isDependentScopeSpecifier(*SS)
+Diag(IdentLoc, isDependentScopeSpecifier(*SS)
? diag::err_using_enum_is_dependent
: diag::err_unknown_typename)
 << II.getName()
-<< SourceRange(SS ? SS->getBeginLoc() : IdentLoc, TyLoc.getEnd());
+<< SourceRange(SS->getBeginLoc(), TyLoc.getEnd());
 return nullptr;
   }
 

>From b7aa05e8a35fc17ecb0dd5f3cdd32ec0a8821877 Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Wed, 24 Jul 2024 17:40:34 -0700
Subject: [PATCH 2/2] Fix format

---
 clang/lib/Sema/SemaDeclCXX.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a9e2495cf2cde..1cca8ac9b9343 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -12256,8 +12256,7 @@ Decl *Sema::ActOnUsingEnumDeclaration(Scope *S, 
AccessSpecifier AS,
 Diag(IdentLoc, isDependentScopeSpecifier(*SS)
? diag::err_using_enum_is_dependent
: diag::err_unknown_typename)
-<< II.getName()
-<< SourceRange(SS->getBeginLoc(), TyLoc.getEnd());
+<< II.getName() << SourceRange(SS->getBeginLoc(), TyLoc.getEnd());
 return nullptr;
   }
 

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


[clang] [clang] Update argument checking tablegen code to use a 'full' name (PR #99993)

2024-07-23 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 updated 
https://github.com/llvm/llvm-project/pull/3

>From 5f8b68d9dfd7680adeadbae1d761dc03a2455685 Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Mon, 22 Jul 2024 15:28:15 -0700
Subject: [PATCH 1/2] [clang] Update argument checking tablegen code to use a
 'full' name

In 92fc1eb0c1ae3813f2ac9208e2c74207aae9d23 the HLSLLoopHint attribute
was added with an 'unroll' spelling. There is an existing LoopHint
attribute with the same spelling. These attributes have different
arguments.

The tablegen used to produce checks on arguments uses only the attribute
name, making it impossible to return correct info for attribute with
different argument types but the same name.

Improve the situation by using a 'full' name that combines the syntax,
scope, and name. This allows, for example, #pragma unroll and
[[unroll(x)]] to coexist correctly even with different argument types.

Also fix a bug in the StrictEnumParameters tablegen. If will now
correctly specify each parameter instead of only the first.
---
 .../include/clang/Basic/AttributeCommonInfo.h |   6 +
 clang/lib/Basic/Attributes.cpp|  34 +++
 clang/lib/Parse/ParseDecl.cpp | 104 +---
 clang/lib/Sema/SemaStmtAttr.cpp   |   7 -
 clang/test/SemaHLSL/Loops/unroll.hlsl |   5 +-
 .../TableGen/attrs-parser-string-switches.td  | 232 ++
 clang/utils/TableGen/ClangAttrEmitter.cpp |  71 --
 7 files changed, 394 insertions(+), 65 deletions(-)
 create mode 100644 clang/test/TableGen/attrs-parser-string-switches.td

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 5f024b4b5fd78..2c5baaf921cdf 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -191,6 +191,12 @@ class AttributeCommonInfo {
   /// __gnu__::__attr__ will be normalized to gnu::attr).
   std::string getNormalizedFullName() const;
 
+  /// Gets a normalized full name, with syntax, scope and name.
+  static std::string
+  getNormalizedFullNameWithSyntax(const IdentifierInfo *Name,
+  const IdentifierInfo *Scope,
+  AttributeCommonInfo::Syntax SyntaxUsed);
+
   bool isDeclspecAttribute() const { return SyntaxUsed == AS_Declspec; }
   bool isMicrosoftAttribute() const { return SyntaxUsed == AS_Microsoft; }
 
diff --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp
index 867d241a2cf84..0625c7637c009 100644
--- a/clang/lib/Basic/Attributes.cpp
+++ b/clang/lib/Basic/Attributes.cpp
@@ -153,6 +153,40 @@ std::string AttributeCommonInfo::getNormalizedFullName() 
const {
   normalizeName(getAttrName(), getScopeName(), getSyntax()));
 }
 
+static StringRef getSyntaxName(AttributeCommonInfo::Syntax SyntaxUsed) {
+  switch (SyntaxUsed) {
+  case AttributeCommonInfo::AS_GNU:
+return "GNU";
+  case AttributeCommonInfo::AS_CXX11:
+return "CXX11";
+  case AttributeCommonInfo::AS_C23:
+return "C23";
+  case AttributeCommonInfo::AS_Declspec:
+return "Declspec";
+  case AttributeCommonInfo::AS_Microsoft:
+return "Microsoft";
+  case AttributeCommonInfo::AS_Keyword:
+return "Keyword";
+  case AttributeCommonInfo::AS_Pragma:
+return "Pragma";
+  case AttributeCommonInfo::AS_ContextSensitiveKeyword:
+return "ContextSensitiveKeyword";
+  case AttributeCommonInfo::AS_HLSLAnnotation:
+return "HLSLAnnotation";
+  case AttributeCommonInfo::AS_Implicit:
+return "Implicit";
+  }
+}
+
+std::string AttributeCommonInfo::getNormalizedFullNameWithSyntax(
+const IdentifierInfo *Name, const IdentifierInfo *ScopeName,
+Syntax SyntaxUsed) {
+  std::string FullName = getSyntaxName(SyntaxUsed).str();
+  FullName += "::";
+  return FullName +=
+ static_cast(normalizeName(Name, ScopeName, SyntaxUsed));
+}
+
 unsigned AttributeCommonInfo::calculateAttributeSpellingListIndex() const {
   // Both variables will be used in tablegen generated
   // attribute spell list index matching code.
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 7ce9a9cea1c7a..28c69f9981abd 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -314,9 +314,13 @@ void Parser::ParseGNUAttributes(ParsedAttributes &Attrs,
 }
 
 /// Determine whether the given attribute has an identifier argument.
-static bool attributeHasIdentifierArg(const IdentifierInfo &II) {
+static bool attributeHasIdentifierArg(const IdentifierInfo &II,
+  ParsedAttr::Syntax Syntax,
+  IdentifierInfo *ScopeName) {
+  std::string FullName = AttributeCommonInfo::getNormalizedFullNameWithSyntax(
+  &II, ScopeName, Syntax);
 #define CLANG_ATTR_IDENTIFIER_ARG_LIST
-  return llvm::StringSwitch(normalizeAttrName(II.getName()))
+  return llvm::StringSwitch(FullName)
 #include "clang/Parse/AttrParserStringS

[clang] [clang] Update argument checking tablegen code to use a 'full' name (PR #99993)

2024-07-23 Thread Mike Rice via cfe-commits


@@ -314,64 +314,92 @@ void Parser::ParseGNUAttributes(ParsedAttributes &Attrs,
 }
 
 /// Determine whether the given attribute has an identifier argument.
-static bool attributeHasIdentifierArg(const IdentifierInfo &II) {
+static bool attributeHasIdentifierArg(const IdentifierInfo &II,
+  ParsedAttr::Syntax Syntax,
+  IdentifierInfo *ScopeName) {
+  std::string FullName = AttributeCommonInfo::getNormalizedFullNameWithSyntax(
+  &II, ScopeName, Syntax);
 #define CLANG_ATTR_IDENTIFIER_ARG_LIST
-  return llvm::StringSwitch(normalizeAttrName(II.getName()))
+  return llvm::StringSwitch(FullName)

mikerice1969 wrote:

> Can we remove `normalizeAttrName` since this looks like it replaces all of 
> the uses?

There are still two uses of this function. I didn't change the tablegen for the 
'LateParsed' uses (CLANG_ATTR_LATE_PARSED_EXPERIMENTAL_EXT_LIST and 
CLANG_ATTR_LATE_PARSED_LIST) since these only use the GNU syntax so there isn't 
a problem just using the attribute name. 

We could add "GNU::" to the tablegen for these and then use the new function. 
Or leave it alone. I don't have a strong preference.

https://github.com/llvm/llvm-project/pull/3
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Update argument checking tablegen code to use a 'full' name (PR #99993)

2024-07-23 Thread Mike Rice via cfe-commits

mikerice1969 wrote:

> Does this impact anything user-facing? e.g., should there be an additional 
> test somewhere in clang/test/Sema/ for this change?

I don't think there is any user-visible issue with the one attribute that uses 
this. At least how the Parse code is written currently. The attribute has three 
EnumArguments followed by an IntArgument. The call to 
attributeHasStrictIdentifierArgAtIndex is only done if the token is an 
identifier and if the IntArgument is an identifier that same thing happens 
anyway.

Looking at this code now, I am not convinced the call to 
attributeHasStrictIdentifierArgAtIndex does anything useful. 

```
if (Tok.is(tok::identifier) && attributeHasStrictIdentifierArgAtIndex( 
   *AttrName, ArgExprs.size())) {  
  ArgExprs.push_back(ParseIdentifierLoc());
  continue;
}  
   
ExprResult ArgExpr;
if (Tok.is(tok::identifier)) { 
  ArgExprs.push_back(ParseIdentifierLoc());
} else {   
``` 

So I think we can remove the whole function 
attributeHasStrictIdentifierArgAtIndex and the related tablegen. No tests fail 
without it. 

The function attributeHasStrictIdentifierArgs still seems necessary but not the 
AtIndex.

What do you think? 

https://github.com/llvm/llvm-project/pull/3
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Update argument checking tablegen code to use a 'full' name (PR #99993)

2024-07-22 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/3

In 92fc1eb0c1ae3813f2ac9208e2c74207aae9d23 the HLSLLoopHint attribute was added 
with an 'unroll' spelling. There is an existing LoopHint attribute with the 
same spelling. These attributes have different arguments.

The tablegen used to produce checks on arguments uses only the attribute name, 
making it impossible to return correct info for attribute with different 
argument types but the same name.

Improve the situation by using a 'full' name that combines the syntax, scope, 
and name. This allows, for example, #pragma unroll and [[unroll(x)]] to coexist 
correctly even with different argument types.

Also fix a bug in the StrictEnumParameters tablegen. If will now correctly 
specify each parameter instead of only the first.

>From 5f8b68d9dfd7680adeadbae1d761dc03a2455685 Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Mon, 22 Jul 2024 15:28:15 -0700
Subject: [PATCH] [clang] Update argument checking tablegen code to use a
 'full' name

In 92fc1eb0c1ae3813f2ac9208e2c74207aae9d23 the HLSLLoopHint attribute
was added with an 'unroll' spelling. There is an existing LoopHint
attribute with the same spelling. These attributes have different
arguments.

The tablegen used to produce checks on arguments uses only the attribute
name, making it impossible to return correct info for attribute with
different argument types but the same name.

Improve the situation by using a 'full' name that combines the syntax,
scope, and name. This allows, for example, #pragma unroll and
[[unroll(x)]] to coexist correctly even with different argument types.

Also fix a bug in the StrictEnumParameters tablegen. If will now
correctly specify each parameter instead of only the first.
---
 .../include/clang/Basic/AttributeCommonInfo.h |   6 +
 clang/lib/Basic/Attributes.cpp|  34 +++
 clang/lib/Parse/ParseDecl.cpp | 104 +---
 clang/lib/Sema/SemaStmtAttr.cpp   |   7 -
 clang/test/SemaHLSL/Loops/unroll.hlsl |   5 +-
 .../TableGen/attrs-parser-string-switches.td  | 232 ++
 clang/utils/TableGen/ClangAttrEmitter.cpp |  71 --
 7 files changed, 394 insertions(+), 65 deletions(-)
 create mode 100644 clang/test/TableGen/attrs-parser-string-switches.td

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 5f024b4b5fd78..2c5baaf921cdf 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -191,6 +191,12 @@ class AttributeCommonInfo {
   /// __gnu__::__attr__ will be normalized to gnu::attr).
   std::string getNormalizedFullName() const;
 
+  /// Gets a normalized full name, with syntax, scope and name.
+  static std::string
+  getNormalizedFullNameWithSyntax(const IdentifierInfo *Name,
+  const IdentifierInfo *Scope,
+  AttributeCommonInfo::Syntax SyntaxUsed);
+
   bool isDeclspecAttribute() const { return SyntaxUsed == AS_Declspec; }
   bool isMicrosoftAttribute() const { return SyntaxUsed == AS_Microsoft; }
 
diff --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp
index 867d241a2cf84..0625c7637c009 100644
--- a/clang/lib/Basic/Attributes.cpp
+++ b/clang/lib/Basic/Attributes.cpp
@@ -153,6 +153,40 @@ std::string AttributeCommonInfo::getNormalizedFullName() 
const {
   normalizeName(getAttrName(), getScopeName(), getSyntax()));
 }
 
+static StringRef getSyntaxName(AttributeCommonInfo::Syntax SyntaxUsed) {
+  switch (SyntaxUsed) {
+  case AttributeCommonInfo::AS_GNU:
+return "GNU";
+  case AttributeCommonInfo::AS_CXX11:
+return "CXX11";
+  case AttributeCommonInfo::AS_C23:
+return "C23";
+  case AttributeCommonInfo::AS_Declspec:
+return "Declspec";
+  case AttributeCommonInfo::AS_Microsoft:
+return "Microsoft";
+  case AttributeCommonInfo::AS_Keyword:
+return "Keyword";
+  case AttributeCommonInfo::AS_Pragma:
+return "Pragma";
+  case AttributeCommonInfo::AS_ContextSensitiveKeyword:
+return "ContextSensitiveKeyword";
+  case AttributeCommonInfo::AS_HLSLAnnotation:
+return "HLSLAnnotation";
+  case AttributeCommonInfo::AS_Implicit:
+return "Implicit";
+  }
+}
+
+std::string AttributeCommonInfo::getNormalizedFullNameWithSyntax(
+const IdentifierInfo *Name, const IdentifierInfo *ScopeName,
+Syntax SyntaxUsed) {
+  std::string FullName = getSyntaxName(SyntaxUsed).str();
+  FullName += "::";
+  return FullName +=
+ static_cast(normalizeName(Name, ScopeName, SyntaxUsed));
+}
+
 unsigned AttributeCommonInfo::calculateAttributeSpellingListIndex() const {
   // Both variables will be used in tablegen generated
   // attribute spell list index matching code.
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 7ce9a9cea1c7a..28c69f9981abd 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/l

[clang] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-07-16 Thread Mike Rice via cfe-commits


@@ -14,10 +14,144 @@
 #ifndef LLVM_CLANG_BASIC_POINTERAUTHOPTIONS_H
 #define LLVM_CLANG_BASIC_POINTERAUTHOPTIONS_H
 
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/STLForwardCompat.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Target/TargetOptions.h"
+#include 
+
 namespace clang {
 
 constexpr unsigned PointerAuthKeyNone = -1;
 
+class PointerAuthSchema {
+public:
+  enum class Kind : unsigned {
+None,
+ARM8_3,
+  };
+
+  /// Hardware pointer-signing keys in ARM8.3.
+  ///
+  /// These values are the same used in ptrauth.h.
+  enum class ARM8_3Key : unsigned {
+ASIA = 0,
+ASIB = 1,
+ASDA = 2,
+ASDB = 3
+  };
+
+  /// Forms of extra discrimination.
+  enum class Discrimination : unsigned {
+/// No additional discrimination.
+None,
+
+/// Discriminate using a constant value.
+Constant,
+  };
+
+private:
+  Kind TheKind : 2;
+  unsigned IsAddressDiscriminated : 1;
+  unsigned IsIsaPointer : 1;
+  unsigned AuthenticatesNullValues : 1;
+  PointerAuthenticationMode SelectedAuthenticationMode : 2;
+  Discrimination DiscriminationKind : 2;
+  unsigned Key : 2;
+  unsigned ConstantDiscriminator : 16;
+
+public:
+  PointerAuthSchema() : TheKind(Kind::None) {}
+
+  PointerAuthSchema(
+  ARM8_3Key Key, bool IsAddressDiscriminated,
+  PointerAuthenticationMode AuthenticationMode,
+  Discrimination OtherDiscrimination,
+  std::optional ConstantDiscriminatorOrNone = std::nullopt,
+  bool IsIsaPointer = false, bool AuthenticatesNullValues = false)
+  : TheKind(Kind::ARM8_3), IsAddressDiscriminated(IsAddressDiscriminated),
+IsIsaPointer(IsIsaPointer),
+AuthenticatesNullValues(AuthenticatesNullValues),
+SelectedAuthenticationMode(AuthenticationMode),
+DiscriminationKind(OtherDiscrimination), Key(llvm::to_underlying(Key)) 
{
+assert((getOtherDiscrimination() != Discrimination::Constant ||
+ConstantDiscriminatorOrNone) &&
+   "constant discrimination requires a constant!");
+if (ConstantDiscriminatorOrNone)
+  ConstantDiscriminator = *ConstantDiscriminatorOrNone;

mikerice1969 wrote:

Hi @ahmedbougacha @ahatanak The static verifier is reporting that 
'ConstantDiscriminator' is not initialized when taking the false branch of that 
if. Is that possible? 

https://github.com/llvm/llvm-project/pull/93906
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][clang] Replace unchecked dyn_cast with cast (PR #98948)

2024-07-16 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/98948
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][clang] Replace unchecked dyn_cast with cast (PR #98948)

2024-07-15 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/98948

BI__builtin_hlsl_elementwise_rcp is only invoked with a FixedVectorType so use 
cast to make this clear and satisfy the static verifier.

>From 68b271a07bea190e515fb24e1ec0a833624078bc Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Mon, 15 Jul 2024 11:40:17 -0700
Subject: [PATCH] [NFC][clang] Replace unchecked dyn_cast with cast

BI__builtin_hlsl_elementwise_rcp is only invoked with a FixedVectorType
so use cast to make this clear and satisfy the static verifier.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a54fa7bf87aad..c0297476391d2 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18389,13 +18389,12 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
   llvm_unreachable("rcp operand must have a float representation");
 llvm::Type *Ty = Op0->getType();
 llvm::Type *EltTy = Ty->getScalarType();
-Constant *One =
-Ty->isVectorTy()
-? ConstantVector::getSplat(
-  ElementCount::getFixed(
-  dyn_cast(Ty)->getNumElements()),
-  ConstantFP::get(EltTy, 1.0))
-: ConstantFP::get(EltTy, 1.0);
+Constant *One = Ty->isVectorTy()
+? ConstantVector::getSplat(
+  ElementCount::getFixed(
+  cast(Ty)->getNumElements()),
+  ConstantFP::get(EltTy, 1.0))
+: ConstantFP::get(EltTy, 1.0);
 return Builder.CreateFDiv(One, Op0, "hlsl.rcp");
   }
   case Builtin::BI__builtin_hlsl_elementwise_rsqrt: {

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


[clang] [NFC][clang] Replace unreachable code in literal processing with assert (PR #96579)

2024-06-25 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/96579
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-06-24 Thread Mike Rice via cfe-commits


@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (DoubleUnderscore)
+break; // Cannot be repeated.

mikerice1969 wrote:

Thanks for the comments. Submitted 
https://github.com/llvm/llvm-project/pull/96579

https://github.com/llvm/llvm-project/pull/86586
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][OpenMP] Shorten directive classification in ParseOpenMP (PR #94691)

2024-06-24 Thread Mike Rice via cfe-commits


@@ -2374,86 +2374,209 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
   case OMPD_unknown:
 Diag(Tok, diag::err_omp_unknown_directive);
 break;
-  case OMPD_parallel:
-  case OMPD_simd:
-  case OMPD_tile:
-  case OMPD_unroll:
-  case OMPD_task:
-  case OMPD_taskyield:
+  default:
+switch (getDirectiveCategory(DKind)) {
+case Category::Executable:
+case Category::Meta:
+case Category::Subsidiary:
+case Category::Utility:
+  Diag(Tok, diag::err_omp_unexpected_directive)
+  << 1 << getOpenMPDirectiveName(DKind);
+  break;
+default:
+  break;

mikerice1969 wrote:

Can this be a fully covered switch instead?
For 'Declarative' I suspect there should be a case to handle it, if not it can 
assert here so we know we need to add code there.
And do whatever is needed for 'Informational' directives arriving here.
The idea is when someone adds a new directive it doesn't just fall through 
silently but alerts us to the missing code.

https://github.com/llvm/llvm-project/pull/94691
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][OpenMP] Shorten directive classification in ParseOpenMP (PR #94691)

2024-06-24 Thread Mike Rice via cfe-commits


@@ -2374,86 +2374,209 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
   case OMPD_unknown:
 Diag(Tok, diag::err_omp_unknown_directive);
 break;
-  case OMPD_parallel:
-  case OMPD_simd:
-  case OMPD_tile:
-  case OMPD_unroll:
-  case OMPD_task:
-  case OMPD_taskyield:
+  default:
+switch (getDirectiveCategory(DKind)) {
+case Category::Executable:
+case Category::Meta:
+case Category::Subsidiary:
+case Category::Utility:
+  Diag(Tok, diag::err_omp_unexpected_directive)
+  << 1 << getOpenMPDirectiveName(DKind);
+  break;
+default:
+  break;
+}
+  }
+  while (Tok.isNot(tok::annot_pragma_openmp_end))
+ConsumeAnyToken();
+  ConsumeAnyToken();
+  return nullptr;
+}
+
+StmtResult Parser::ParseOpenMPExecutableDirective(
+ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
+bool ReadDirectiveWithinMetadirective) {
+  bool HasAssociatedStatement = true;
+
+  switch (DKind) {

mikerice1969 wrote:

Is it possible to use the Association somehow here instead of the switch? 
So when a new directive is added we don't have to update this code?

https://github.com/llvm/llvm-project/pull/94691
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][OpenMP] Shorten directive classification in ParseOpenMP (PR #94691)

2024-06-24 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 commented:

I both like and hate the huge fully-covered switches we have. I like when I add 
new directives and know exactly where to add code. I hate having to read code 
like this though. Seems like this is going in the right direction.

https://github.com/llvm/llvm-project/pull/94691
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][OpenMP] Shorten directive classification in ParseOpenMP (PR #94691)

2024-06-24 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 edited 
https://github.com/llvm/llvm-project/pull/94691
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][OpenMP] Fix error handling of the adjust_args clause (PR #94696)

2024-06-24 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/94696
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][OpenMP] Fix teams nesting of region check (PR #94806)

2024-06-24 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/94806
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenMP][NFC] Fix argument order of SourceLocations for allocate clause (PR #94777)

2024-06-10 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/94777
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][OpenMP][NFC] Remove unnecessary nullptr check (PR #94680)

2024-06-10 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/94680
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-06-07 Thread Mike Rice via cfe-commits


@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (DoubleUnderscore)
+break; // Cannot be repeated.

mikerice1969 wrote:

Hi @js324. our static verifier is reporting this 'break' as dead code saying 
that it will always be false. I removed all references to DoubleUnderscore and 
ran the lit tests and there are no fails. Do you have a test case in mind that 
exercises this condition? If so we should add a test for it. If not we can 
simplify this code and remove DoubleUnderscore. What do you think?

https://github.com/llvm/llvm-project/pull/86586
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][OpenMP] Fix teams nesting of region check (PR #94806)

2024-06-07 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/94806

The static verifier flagged dead code in the check since the loop will only 
execute once and never reach the iterator increment.

The loop needs to iterate twice to correctly diagnose when a statement is after 
the teams.

Since there are two iterations again, reset the iterator to the first teams 
directive when the double teams case is seen so the diagnostic can report both 
locations.

>From 61ea96129753641f7528c0f29c78143a2281cde9 Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Fri, 7 Jun 2024 14:26:37 -0700
Subject: [PATCH] [clang][OpenMP] Fix teams nesting of region check

The static verifier flagged dead code in the check since the loop will
only execute once and never reach the iterator increment.

The loop needs to iterate twice to correctly diagnose when a statement
is after the teams.

Since there are two iterations again, reset the iterator to the first
teams directive when the double teams case is seen so the diagnostic
can report both locations.
---
 clang/lib/Sema/SemaOpenMP.cpp   | 10 +++---
 clang/test/OpenMP/Inputs/nesting_of_regions.cpp | 12 
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 6e6815328e913..0fe04094c5912 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -13434,10 +13434,14 @@ StmtResult 
SemaOpenMP::ActOnOpenMPTargetDirective(ArrayRef Clauses,
   auto I = CS->body_begin();
   while (I != CS->body_end()) {
 const auto *OED = dyn_cast(*I);
-if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind()) ||
-OMPTeamsFound) {
-
+bool IsTeams = OED && isOpenMPTeamsDirective(OED->getDirectiveKind());
+if (!IsTeams || I != CS->body_begin()) {
   OMPTeamsFound = false;
+  if (IsTeams && I != CS->body_begin()) {
+// This is the two teams case. Since the InnerTeamsRegionLoc will
+// point to this second one reset the iterator to the other teams.
+--I;
+  }
   break;
 }
 ++I;
diff --git a/clang/test/OpenMP/Inputs/nesting_of_regions.cpp 
b/clang/test/OpenMP/Inputs/nesting_of_regions.cpp
index e671f9b0cf412..969ddfcce4cb0 100644
--- a/clang/test/OpenMP/Inputs/nesting_of_regions.cpp
+++ b/clang/test/OpenMP/Inputs/nesting_of_regions.cpp
@@ -4880,6 +4880,12 @@ void foo() {
 #pragma omp teams  // expected-note {{nested teams construct here}}
 ++a;
   }
+#pragma omp target // expected-error {{target construct with nested teams 
region contains statements outside of the teams construct}}
+  {
+#pragma omp teams  // expected-note {{nested teams construct here}}
+++a;
+++a;   // expected-note {{statement outside teams construct here}}
+  }
 #pragma omp target // expected-error {{target construct with nested teams 
region contains statements outside of the teams construct}}
   {
 while (0)  // expected-note {{statement outside teams construct here}}
@@ -14133,6 +14139,12 @@ void foo() {
 #pragma omp teams // expected-note {{nested teams construct here}}
 ++a;
   }
+#pragma omp target // expected-error {{target construct with nested teams 
region contains statements outside of the teams construct}}
+  {
+#pragma omp teams // expected-note {{nested teams construct here}}
+++a;
+++a;  // expected-note {{statement outside teams construct here}}
+  }
 #pragma omp target
   {
 #pragma omp taskloop

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


[clang] [OpenMP][NFC] Fix argument order of SourceLocations for allocate clause (PR #94777)

2024-06-07 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/94777

Static verifier caught passing ColonLoc/LParenLoc in wrong order. Marked as NFC 
since these don't seem to be used for anything currently that I can think to 
test for.

>From ae0438eda2b5fcffc70b991d2c496bac9b89a5a2 Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Fri, 7 Jun 2024 10:47:55 -0700
Subject: [PATCH] [OpenMP][NFC] Fix argument order of SourceLocations for
 allocate clause

Static verifier caught passing ColonLoc/LParenLoc in wrong order.
Marked as NFC since these don't seem to be used for anything currently
that I can think to test for.
---
 clang/lib/Sema/SemaOpenMP.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 6e6815328e913..f1ebe9d3b9db7 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -24331,7 +24331,7 @@ 
SemaOpenMP::ActOnOpenMPHasDeviceAddrClause(ArrayRef VarList,
 
 OMPClause *SemaOpenMP::ActOnOpenMPAllocateClause(
 Expr *Allocator, ArrayRef VarList, SourceLocation StartLoc,
-SourceLocation ColonLoc, SourceLocation LParenLoc, SourceLocation EndLoc) {
+SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) {
   if (Allocator) {
 // OpenMP [2.11.4 allocate Clause, Description]
 // allocator is an expression of omp_allocator_handle_t type.

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


[clang] [llvm] [CodeGen][arm64e] Add methods and data members to Address, which are needed to authenticate signed pointers (PR #86923)

2024-06-06 Thread Mike Rice via cfe-commits


@@ -201,14 +211,26 @@ template <> struct DominatingValue {
   class saved_type {
 enum Kind { ScalarLiteral, ScalarAddress, AggregateLiteral,
 AggregateAddress, ComplexAddress };
-
-llvm::Value *Value;
-llvm::Type *ElementType;
+union {
+  struct {
+DominatingLLVMValue::saved_type first, second;
+  } Vals;
+  DominatingValue::saved_type AggregateAddr;
+};
 LLVM_PREFERRED_TYPE(Kind)
 unsigned K : 3;
-unsigned Align : 29;
-saved_type(llvm::Value *v, llvm::Type *e, Kind k, unsigned a = 0)
-  : Value(v), ElementType(e), K(k), Align(a) {}
+unsigned IsVolatile : 1;

mikerice1969 wrote:

Hi @ahatanak, static verifier is concerned that IsVolatile is not initialized 
in the constructor. Can we add an initializer here? Also one of the 
constructors below has a IsVolatile parameter but isn't using it to initialize 
the field. Do you know what we should be doing here?

https://github.com/llvm/llvm-project/pull/86923
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][OpenMP] Fix error handling of the adjust_args clause (PR #94696)

2024-06-06 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/94696

Static verifier noticed the current code has logically dead code parsing the 
clause where IsComma is assigned. Fix this and improve the error message 
received when a bad adjust-op is specified.

This will now be handled like 'map' where a nice diagnostic is given with the 
correct values, then parsing continues on the next clause reducing unhelpful 
diagnostics.

>From 26ece1d7f046e81d095b7da609d34d19eebfed89 Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Thu, 6 Jun 2024 15:57:27 -0700
Subject: [PATCH] [clang][OpenMP] Fix error handling of the adjust_args clause

Static verifier noticed the current code has logically dead code parsing
the clause where IsComma is assigned. Fix this and improve the error
message received when a bad adjust-op is specified.

This will now be handled like 'map' where a nice diagnostic is given
with the correct values, then parsing continues on the next clause
reducing unhelpful diagnostics.
---
 clang/include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Parse/ParseOpenMP.cpp|  6 +++---
 clang/test/OpenMP/declare_variant_clauses_messages.cpp | 10 ++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index d8c3fee7841f4..1160b0f7a7a5a 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1508,6 +1508,8 @@ def err_omp_unexpected_append_op : Error<
   "unexpected operation specified in 'append_args' clause, expected 
'interop'">;
 def err_omp_unexpected_execution_modifier : Error<
   "unexpected 'execution' modifier in non-executable context">;
+def err_omp_unknown_adjust_args_op : Error<
+  "incorrect adjust_args type, expected 'need_device_ptr' or 'nothing'">;
 def err_omp_declare_variant_wrong_clause : Error<
   "expected %select{'match'|'match', 'adjust_args', or 'append_args'}0 clause "
   "on 'omp declare variant' directive">;
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 50a872fedebf7..76d1854520382 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4785,8 +4785,8 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
 getLangOpts());
 Data.ExtraModifierLoc = Tok.getLocation();
 if (Data.ExtraModifier == OMPC_ADJUST_ARGS_unknown) {
-  SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
-StopBeforeMatch);
+  Diag(Tok, diag::err_omp_unknown_adjust_args_op);
+  SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch);
 } else {
   ConsumeToken();
   if (Tok.is(tok::colon))
@@ -4799,7 +4799,7 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
   bool IsComma =
   (Kind != OMPC_reduction && Kind != OMPC_task_reduction &&
Kind != OMPC_in_reduction && Kind != OMPC_depend &&
-   Kind != OMPC_doacross && Kind != OMPC_map) ||
+   Kind != OMPC_doacross && Kind != OMPC_map && Kind != OMPC_adjust_args) 
||
   (Kind == OMPC_reduction && !InvalidReductionId) ||
   (Kind == OMPC_map && Data.ExtraModifier != OMPC_MAP_unknown) ||
   (Kind == OMPC_depend && Data.ExtraModifier != OMPC_DEPEND_unknown) ||
diff --git a/clang/test/OpenMP/declare_variant_clauses_messages.cpp 
b/clang/test/OpenMP/declare_variant_clauses_messages.cpp
index 2a9e5385c9ca6..284e49bbd21b4 100644
--- a/clang/test/OpenMP/declare_variant_clauses_messages.cpp
+++ b/clang/test/OpenMP/declare_variant_clauses_messages.cpp
@@ -186,6 +186,16 @@ void vararg_bar2(const char *fmt) { return; }
 // expected-error@+1 {{variant in '#pragma omp declare variant' with type 
'void (float *, float *, int *, omp_interop_t)' (aka 'void (float *, float *, 
int *, void *)') is incompatible with type 'void (float *, float *, int *)'}}
 #pragma omp declare variant(foo_v4) match(construct={dispatch})
 
+// expected-error@+3 {{incorrect adjust_args type, expected 'need_device_ptr' 
or 'nothing'}}
+#pragma omp declare variant(foo_v1)\
+   match(construct={dispatch}, device={arch(arm)}) \
+   adjust_args(badaaop:AAA,BBB)
+
+// expected-error@+3 {{incorrect adjust_args type, expected 'need_device_ptr' 
or 'nothing'}}
+#pragma omp declare variant(foo_v1)\
+   match(construct={dispatch}, device={arch(arm)}) \
+   adjust_args(badaaop AAA,BBB)
+
 #endif // _OPENMP >= 202011
 #if _OPENMP < 202011  // OpenMP 5.0 or lower
 // expected-error@+2 {{expected 'match' clause on 'omp declare variant' 
directive}}

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


[clang] [clang][OpenMP][NFC] Remove unnecessary nullptr check (PR #94680)

2024-06-06 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/94680

Static verifier reports unchecked use of pointer after explicitly checking 
earlier in the function. It appears the pointer won't be a nullptr, so remove 
the unneeded check for consistency.

>From 476c5a8580c066cce91def36f8e8ed20626d3ab0 Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Thu, 6 Jun 2024 11:56:04 -0700
Subject: [PATCH] [OpenMP][NFC] Remove unnecessary nullptr check

Static verifier reports unchecked use of pointer after explicitly
checking earlier in the function. It appears the pointer won't be a
nullptr, so remove the unneeded check for consistency.
---
 clang/lib/Sema/SemaOpenMP.cpp | 23 +++
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 6e6815328e913..5af32cb3589d3 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -6198,18 +6198,17 @@ class TeamsLoopChecker final : public 
ConstStmtVisitor {
 // unless the assume-no-nested-parallelism flag has been specified.
 // OpenMP API runtime library calls do not inhibit parallel loop
 // translation, regardless of the assume-no-nested-parallelism.
-if (C) {
-  bool IsOpenMPAPI = false;
-  auto *FD = dyn_cast_or_null(C->getCalleeDecl());
-  if (FD) {
-std::string Name = FD->getNameInfo().getAsString();
-IsOpenMPAPI = Name.find("omp_") == 0;
-  }
-  TeamsLoopCanBeParallelFor =
-  IsOpenMPAPI || SemaRef.getLangOpts().OpenMPNoNestedParallelism;
-  if (!TeamsLoopCanBeParallelFor)
-return;
-}
+bool IsOpenMPAPI = false;
+auto *FD = dyn_cast_or_null(C->getCalleeDecl());
+if (FD) {
+  std::string Name = FD->getNameInfo().getAsString();
+  IsOpenMPAPI = Name.find("omp_") == 0;
+}
+TeamsLoopCanBeParallelFor =
+IsOpenMPAPI || SemaRef.getLangOpts().OpenMPNoNestedParallelism;
+if (!TeamsLoopCanBeParallelFor)
+  return;
+
 for (const Stmt *Child : C->children())
   if (Child)
 Visit(Child);

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


[clang] [OpenMP][CodeGen] Improved codegen for combined loop directives (PR #87278)

2024-05-09 Thread Mike Rice via cfe-commits


@@ -6135,6 +6137,79 @@ processImplicitMapsWithDefaultMappers(Sema &S, 
DSAStackTy *Stack,
   }
 }
 
+namespace {
+/// A 'teams loop' with a nested 'loop bind(parallel)' or generic function
+/// call in the associated loop-nest cannot be a 'parallel for'.
+class TeamsLoopChecker final : public ConstStmtVisitor {
+  Sema &SemaRef;
+
+public:
+  bool teamsLoopCanBeParallelFor() const { return TeamsLoopCanBeParallelFor; }
+
+  // Is there a nested OpenMP loop bind(parallel)
+  void VisitOMPExecutableDirective(const OMPExecutableDirective *D) {
+if (D->getDirectiveKind() == llvm::omp::Directive::OMPD_loop) {
+  if (const auto *C = D->getSingleClause())
+if (C->getBindKind() == OMPC_BIND_parallel) {
+  TeamsLoopCanBeParallelFor = false;
+  // No need to continue visiting any more
+  return;
+}
+}
+for (const Stmt *Child : D->children())
+  if (Child)
+Visit(Child);
+  }
+
+  void VisitCallExpr(const CallExpr *C) {
+// Function calls inhibit parallel loop translation of 'target teams loop'
+// unless the assume-no-nested-parallelism flag has been specified.
+// OpenMP API runtime library calls do not inhibit parallel loop
+// translation, regardless of the assume-no-nested-parallelism.
+if (C) {
+  bool IsOpenMPAPI = false;
+  auto *FD = dyn_cast_or_null(C->getCalleeDecl());
+  if (FD) {
+std::string Name = FD->getNameInfo().getAsString();
+IsOpenMPAPI = Name.find("omp_") == 0;
+  }
+  TeamsLoopCanBeParallelFor =
+  IsOpenMPAPI || SemaRef.getLangOpts().OpenMPNoNestedParallelism;
+  if (!TeamsLoopCanBeParallelFor)
+return;
+}
+for (const Stmt *Child : C->children())
+  if (Child)
+Visit(Child);
+  }

mikerice1969 wrote:

Hi @ddpagan, the static verifier complains about this code since you check that 
'C' is not a nullptr, but then do not check before the 'C->children() call. It 
seems 'C' won't be null since it is checked in 
ActOnOpenMPTargetTeamsGenericLoopDirective. Can we remove the if(C) check and 
use an assert instead if you think it helps? Or if 'C' really can be null 
somehow we need to ensure that for loop is excluded for that case.

https://github.com/llvm/llvm-project/pull/87278
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Ensure nullable variable is not accessed without validity test (PR #90173)

2024-04-26 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 approved this pull request.

LGTM. Thanks!

https://github.com/llvm/llvm-project/pull/90173
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add fix-its to `readability-avoid-return-with-void-value` check (PR #81420)

2024-04-25 Thread Mike Rice via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -42,10 +44,30 @@ void AvoidReturnWithVoidValueCheck::check(
   const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
   if (IgnoreMacros && VoidReturn->getBeginLoc().isMacroID())
 return;
-  if (!StrictMode && !Result.Nodes.getNodeAs("compound_parent"))
+  const auto *SurroundingBlock =
+  Result.Nodes.getNodeAs("compound_parent");
+  if (!StrictMode && !SurroundingBlock)
 return;
-  diag(VoidReturn->getBeginLoc(), "return statement within a void function "
-  "should not have a specified return value");
+  DiagnosticBuilder Diag = diag(VoidReturn->getBeginLoc(),
+"return statement within a void function "
+"should not have a specified return value");
+  const SourceLocation SemicolonPos = utils::lexer::findNextTerminator(
+  VoidReturn->getEndLoc(), *Result.SourceManager, getLangOpts());
+  if (SemicolonPos.isInvalid())
+return;
+  if (!SurroundingBlock) {
+const auto BraceInsertionHints = utils::getBraceInsertionsHints(
+VoidReturn, getLangOpts(), *Result.SourceManager,
+VoidReturn->getBeginLoc());
+if (BraceInsertionHints)
+  Diag << BraceInsertionHints.openingBraceFixIt()
+   << BraceInsertionHints.closingBraceFixIt();
+  }
+  Diag << FixItHint::CreateRemoval(VoidReturn->getReturnLoc());
+  if (!Result.Nodes.getNodeAs("function_parent") ||
+  SurroundingBlock->body_back() != VoidReturn)

mikerice1969 wrote:

Hi @SimplyDanny, we are getting a static verifier hit on this code now since 
there is a nullptr check of SurroundingBlock followed by a use of 
SurroundingBlock without a check. 

It seems when there is a function parent SurroundingBlock won't be a nullptr 
since it will be set to the function's CompoundStmt, but that's not completely 
obvious to the reader of the code.

You might consider adding an assert to make it clear for anyone modifying in 
the future. Maybe:

```
const auto *FunctionParent =   
Result.Nodes.getNodeAs("function_parent");   
assert((!FunctionParent || SurroundingBlock) &&
   "missing surrounding block when function parent");  
if (!FunctionParent || SurroundingBlock->body_back() != VoidReturn)
```

https://github.com/llvm/llvm-project/pull/81420
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][clang][analyzer] Initialize pointer field in StreamOperationEvaluator (PR #89837)

2024-04-24 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/89837
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][clang][analyzer] Initialize pointer field in StreamOperationEvaluator (PR #89837)

2024-04-24 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 edited 
https://github.com/llvm/llvm-project/pull/89837
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][analyzer] Initialize pointer field in StreamOperationEvaluator (PR #89837)

2024-04-23 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/89837

Add an initializer for StreamSym, which is a pointer. The pointers in this 
class are set in the Init function, but all should be initialized in the 
constructor to avoid confusion and static verifier hits.

>From 000ab376b0d853a417c5727b0e87edc11d7e66a2 Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Tue, 23 Apr 2024 14:27:56 -0700
Subject: [PATCH] [NFC][analyzer] Initialize pointer field in
 StreamOperationEvaluator

Add an initializer for StreamSym, which is a pointer. The pointers in
this class are set in the Init function, but all should be initialized
in the constructor to avoid confusion and static verifier hits.
---
 clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index bd495cd0f9710d..a0aa2316a7b45d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -600,7 +600,7 @@ struct StreamOperationEvaluator {
   SValBuilder &SVB;
   const ASTContext &ACtx;
 
-  SymbolRef StreamSym;
+  SymbolRef StreamSym = nullptr;
   const StreamState *SS = nullptr;
   const CallExpr *CE = nullptr;
   StreamErrorState NewES;

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


[clang] [clang] Refactor `IdentifierInfo::ObjcOrBuiltinID` (PR #71709)

2024-04-23 Thread Mike Rice via cfe-commits


@@ -3597,8 +3597,13 @@ class ASTIdentifierTableTrait {
   /// doesn't check whether the name has macros defined; use 
PublicMacroIterator
   /// to check that.
   bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) 
{
-if (MacroOffset || II->isPoisoned() ||
-(!IsModule && II->getObjCOrBuiltinID()) ||
+II->getObjCOrBuiltinID();

mikerice1969 wrote:

Hi @Endilll, Does this call to getObjCOrBuiltinID do anything? Static verifiers 
report it 'useless' since it only returns a value and the value is not used.

https://github.com/llvm/llvm-project/pull/71709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen][OpenMP] Fix casting of atomic update of ptr types (PR #88215)

2024-04-12 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/88215
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen][OpenMP] Fix casting of atomic update of ptr types (PR #88215)

2024-04-12 Thread Mike Rice via cfe-commits

mikerice1969 wrote:

> We should really fix using cmpxchg here. Can you open an IR issue for it?

Sure, I'll look into it and follow-up. Thanks for the review!

https://github.com/llvm/llvm-project/pull/88215
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen][OpenMP] Fix casting of atomic update of ptr types (PR #88215)

2024-04-09 Thread Mike Rice via cfe-commits

mikerice1969 wrote:

See: https://godbolt.org/z/av7axb9as

https://github.com/llvm/llvm-project/pull/88215
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen][OpenMP] Fix casting of atomic update of ptr types (PR #88215)

2024-04-09 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/88215

In 4d5e834c5b7f0d90a6d543e182df602f6bc8, casts were removed for pointers 
but one case was missed. Add missing check.

>From b1eaa2f5b13db4d63390a0358ad0f9b13cbe927f Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Tue, 9 Apr 2024 16:11:30 -0700
Subject: [PATCH] [clang][CodeGen][OpenMP] Fix casting of atomic update of ptr
 types

In 4d5e834c5b7f0d90a6d543e182df602f6bc8, casts were removed for
pointers but one case was missed. Add missing check.
---
 clang/lib/CodeGen/CGAtomic.cpp  |  6 +-
 clang/test/OpenMP/atomic_update_codegen.cpp | 11 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index d35ce0409d7232..07452b18a85ea4 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -1806,7 +1806,11 @@ void AtomicInfo::EmitAtomicUpdateOp(
  /*NumReservedValues=*/2);
   PHI->addIncoming(OldVal, CurBB);
   Address NewAtomicAddr = CreateTempAlloca();
-  Address NewAtomicIntAddr = castToAtomicIntPointer(NewAtomicAddr);
+  Address NewAtomicIntAddr =
+  shouldCastToInt(NewAtomicAddr.getElementType(), /*CmpXchg=*/true)
+  ? castToAtomicIntPointer(NewAtomicAddr)
+  : NewAtomicAddr;
+
   if ((LVal.isBitField() && BFI.Size != ValueSizeInBits) ||
   requiresMemSetZero(getAtomicAddress().getElementType())) {
 CGF.Builder.CreateStore(PHI, NewAtomicIntAddr);
diff --git a/clang/test/OpenMP/atomic_update_codegen.cpp 
b/clang/test/OpenMP/atomic_update_codegen.cpp
index ce0765118922a1..fe745590a9f919 100644
--- a/clang/test/OpenMP/atomic_update_codegen.cpp
+++ b/clang/test/OpenMP/atomic_update_codegen.cpp
@@ -27,6 +27,7 @@ long double ldv, ldx;
 _Complex int civ, cix;
 _Complex float cfv, cfx;
 _Complex double cdv, cdx;
+char *cpx;
 
 typedef int int4 __attribute__((__vector_size__(16)));
 int4 int4x;
@@ -851,6 +852,16 @@ int main(void) {
 // CHECK: call{{.*}} @__kmpc_flush(
 #pragma omp atomic seq_cst
   rix = dv / rix;
+
+// CHECK: [[LD_CPX:%.+]] = load atomic ptr, ptr @cpx monotonic
+// CHECK: br label %[[CONT:.+]]
+// CHECK: [[CONT]]
+// CHECK: [[PHI:%.+]] = phi ptr
+// CHECK: [[RES:%.+]] = cmpxchg ptr @cpx,
+// CHECK: br i1 %{{.+}}, label %[[EXIT:.+]], label %[[CONT]]
+  #pragma omp atomic update
+  cpx += 1;
+
   return 0;
 }
 

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


[clang] [NFC][OpenMP] Split nesting_of_regions test (PR #87842)

2024-04-08 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/87842
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][OpenMP] Split nesting_of_regions test (PR #87842)

2024-04-05 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 ready_for_review 
https://github.com/llvm/llvm-project/pull/87842
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][OpenMP] Split nesting_of_regions test (PR #87842)

2024-04-05 Thread Mike Rice via cfe-commits

mikerice1969 wrote:

This is one way to improve the overall test time. Open for other suggestions.

```
Before change:

Slowest Tests:
--
144.09s: Clang :: OpenMP/nesting_of_regions.cpp
60.81s: Clang :: OpenMP/target_defaultmap_codegen_01.cpp
56.93s: Clang :: 
OpenMP/target_teams_distribute_parallel_for_simd_codegen_registration.cpp
51.11s: Clang :: OpenMP/target_update_codegen.cpp
50.76s: Clang :: OpenMP/target_parallel_for_simd_codegen_registration.cpp
49.79s: Clang :: OpenMP/target_parallel_for_codegen_registration.cpp
47.64s: Clang :: OpenMP/target_teams_distribute_codegen_registration.cpp
46.50s: Clang :: OpenMP/task_depend_messages.cpp
46.20s: Clang :: OpenMP/target_teams_distribute_simd_codegen_registration.cpp
43.90s: Clang :: OpenMP/target_parallel_codegen_registration.cpp
43.56s: Clang :: OpenMP/target_simd_codegen_registration.cpp
41.28s: Clang :: OpenMP/target_teams_codegen_registration.cpp
34.68s: Clang :: OpenMP/distribute_parallel_for_simd_reduction_messages.cpp
34.51s: Clang :: OpenMP/distribute_parallel_for_reduction_messages.cpp
31.47s: Clang :: OpenMP/target_parallel_for_simd_codegen.cpp
31.03s: Clang :: OpenMP/target_parallel_generic_loop_codegen-1.cpp
30.75s: Clang :: OpenMP/atomic_compare_codegen.cpp
29.19s: Clang :: OpenMP/target_parallel_for_codegen.cpp
28.99s: Clang :: OpenMP/distribute_simd_reduction_messages.cpp
28.32s: Clang :: 
OpenMP/target_teams_distribute_parallel_for_reduction_messages.cpp

Tests Times:
--
[   Range   ] :: [   Percentage   ] :: [  Count  ]
--
[140s,150s) :: [] :: [   1/1401]
[130s,140s) :: [] :: [   0/1401]
[120s,130s) :: [] :: [   0/1401]
[110s,120s) :: [] :: [   0/1401]
[100s,110s) :: [] :: [   0/1401]
[ 90s,100s) :: [] :: [   0/1401]
[ 80s, 90s) :: [] :: [   0/1401]
[ 70s, 80s) :: [] :: [   0/1401]
[ 60s, 70s) :: [] :: [   1/1401]
[ 50s, 60s) :: [] :: [   4/1401]
[ 40s, 50s) :: [] :: [   6/1401]
[ 30s, 40s) :: [] :: [   7/1401]
[ 20s, 30s) :: [*   ] :: [  46/1401]
[ 10s, 20s) :: [**  ] :: [  83/1401]
[  0s, 10s) :: [*** ] :: [1253/1401]
--

Testing Time: 152.87s

After split:

Slowest Tests:
--
74.79s: Clang :: 
OpenMP/target_teams_distribute_parallel_for_simd_codegen_registration.cpp
71.50s: Clang :: OpenMP/target_update_codegen.cpp
71.37s: Clang :: OpenMP/target_defaultmap_codegen_01.cpp
65.05s: Clang :: OpenMP/target_parallel_for_simd_codegen_registration.cpp
64.44s: Clang :: OpenMP/target_teams_distribute_simd_codegen_registration.cpp
63.47s: Clang :: OpenMP/task_depend_messages.cpp
62.47s: Clang :: OpenMP/target_parallel_for_codegen_registration.cpp
62.37s: Clang :: OpenMP/target_teams_distribute_codegen_registration.cpp
54.54s: Clang :: OpenMP/target_simd_codegen_registration.cpp
51.63s: Clang :: OpenMP/target_teams_codegen_registration.cpp
51.41s: Clang :: OpenMP/target_parallel_codegen_registration.cpp
40.03s: Clang :: OpenMP/nesting_of_regions_45.cpp
39.75s: Clang :: OpenMP/nesting_of_regions_51.cpp
39.70s: Clang :: OpenMP/nesting_of_regions_50.cpp
34.36s: Clang :: OpenMP/distribute_parallel_for_simd_reduction_messages.cpp
33.65s: Clang :: OpenMP/distribute_parallel_for_reduction_messages.cpp
32.35s: Clang :: OpenMP/target_parallel_for_simd_codegen.cpp
32.31s: Clang :: OpenMP/target_parallel_generic_loop_codegen-1.cpp
32.16s: Clang :: OpenMP/teams_distribute_parallel_for_reduction_messages.cpp
32.14s: Clang :: 
OpenMP/teams_distribute_parallel_for_simd_reduction_messages.cpp

Tests Times:
--
[Range] :: [   Percentage   ] :: [  Count  ]
--
[70.0s,75.0s) :: [] :: [   3/1405]
[65.0s,70.0s) :: [] :: [   1/1405]
[60.0s,65.0s) :: [] :: [   4/1405]
[55.0s,60.0s) :: [] :: [   0/1405]
[50.0s,55.0s) :: [] :: [   3/1405]
[45.0s,50.0s

[clang] [NFC][OpenMP] Split nesting_of_regions test (PR #87842)

2024-04-05 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/87842

This test is the bottleneck for OpenMP lit tests, running about twice as long 
as the others. Break it into five tests based on run lines with the same 
version.

>From e184c8ec9b25b3e077a42646775755dd3a4b4494 Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Fri, 5 Apr 2024 16:39:50 -0700
Subject: [PATCH] [NFC][OpenMP] Split nesting_of_regions test

This test is the bottleneck for OpenMP lit tests, running about
twice as long as the others. Break it into five tests based on
run lines with the same version.
---
 .../test/OpenMP/{ => Inputs}/nesting_of_regions.cpp | 13 -
 clang/test/OpenMP/nesting_of_regions_45.cpp |  4 
 clang/test/OpenMP/nesting_of_regions_50.cpp |  4 
 clang/test/OpenMP/nesting_of_regions_51.cpp |  4 
 clang/test/OpenMP/nesting_of_regions_simd_45.cpp|  3 +++
 clang/test/OpenMP/nesting_of_regions_simd_50.cpp|  3 +++
 6 files changed, 18 insertions(+), 13 deletions(-)
 rename clang/test/OpenMP/{ => Inputs}/nesting_of_regions.cpp (99%)
 create mode 100644 clang/test/OpenMP/nesting_of_regions_45.cpp
 create mode 100644 clang/test/OpenMP/nesting_of_regions_50.cpp
 create mode 100644 clang/test/OpenMP/nesting_of_regions_51.cpp
 create mode 100644 clang/test/OpenMP/nesting_of_regions_simd_45.cpp
 create mode 100644 clang/test/OpenMP/nesting_of_regions_simd_50.cpp

diff --git a/clang/test/OpenMP/nesting_of_regions.cpp 
b/clang/test/OpenMP/Inputs/nesting_of_regions.cpp
similarity index 99%
rename from clang/test/OpenMP/nesting_of_regions.cpp
rename to clang/test/OpenMP/Inputs/nesting_of_regions.cpp
index 9442fb20647d0f..e671f9b0cf4123 100644
--- a/clang/test/OpenMP/nesting_of_regions.cpp
+++ b/clang/test/OpenMP/Inputs/nesting_of_regions.cpp
@@ -1,15 +1,3 @@
-// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 
-fno-openmp-extensions -verify=expected,omp45,omp45warn,omp %s
-// RUN: %clang_cc1 -fsyntax-only -fopenmp -fno-openmp-extensions 
-verify=expected,omp50,omp %s
-// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-extensions 
-verify=expected,omp50 %s
-// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 
-verify=expected,omp45,omp -fno-openmp-extensions -Wno-openmp %s
-// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 
-verify=expected,omp45,omp -fno-openmp-extensions -Wno-source-uses-openmp %s
-// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=51 
-verify=expected,omp51,omp -fno-openmp-extensions -Wno-source-uses-openmp %s
-
-// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=45 
-fno-openmp-extensions -verify=expected,omp45,omp45warn,omp %s
-// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -verify=expected,omp50,omp 
-fno-openmp-extensions %s
-// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=51 
-verify=expected,omp51,omp -fno-openmp-extensions %s
-// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
-
 void bar();
 
 template 
@@ -19577,4 +19565,3 @@ void foo() {
 
   return foo();
 }
-
diff --git a/clang/test/OpenMP/nesting_of_regions_45.cpp 
b/clang/test/OpenMP/nesting_of_regions_45.cpp
new file mode 100644
index 00..d5870ec36486e7
--- /dev/null
+++ b/clang/test/OpenMP/nesting_of_regions_45.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 
-fno-openmp-extensions -verify=expected,omp45,omp45warn,omp %s
+// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 
-verify=expected,omp45,omp -fno-openmp-extensions -Wno-openmp %s
+
+#include "Inputs/nesting_of_regions.cpp"
diff --git a/clang/test/OpenMP/nesting_of_regions_50.cpp 
b/clang/test/OpenMP/nesting_of_regions_50.cpp
new file mode 100644
index 00..f2061553a80463
--- /dev/null
+++ b/clang/test/OpenMP/nesting_of_regions_50.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -fopenmp -fno-openmp-extensions 
-verify=expected,omp50,omp %s
+// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-extensions 
-verify=expected,omp50 %s
+
+#include "Inputs/nesting_of_regions.cpp"
diff --git a/clang/test/OpenMP/nesting_of_regions_51.cpp 
b/clang/test/OpenMP/nesting_of_regions_51.cpp
new file mode 100644
index 00..856489b042821c
--- /dev/null
+++ b/clang/test/OpenMP/nesting_of_regions_51.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=51 
-verify=expected,omp51,omp -fno-openmp-extensions %s
+// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=51 
-verify=expected,omp51,omp -fno-openmp-extensions -Wno-source-uses-openmp %s
+
+#include "Inputs/nesting_of_regions.cpp"
diff --git a/clang/test/OpenMP/nesting_of_regions_simd_45.cpp 
b/clang/test/OpenMP/nesting_of_regions_simd_45.cpp
new file mode 100644
index 00..fb0d8bbfe3e486
--- /dev/null
+++ b/clang/test/OpenMP/nesting_of_regions_simd_45.cpp
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=45 
-fno-openmp-extensions -verify=expected,omp45,omp45warn,omp

[clang-tools-extra] [clang-tidy] Fix result check after overwriteChangedFiles() (PR #86360)

2024-03-22 Thread Mike Rice via cfe-commits

mikerice1969 wrote:

> This could use a test.

I thought about it, but I have no idea how to write that test. Do you have an 
idea?

https://github.com/llvm/llvm-project/pull/86360
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fix result check after overwriteChangedFiles() (PR #86360)

2024-03-22 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/86360

If any return from overwriteChangedFiles is true some fixes were not applied.

>From 492e0fc4e146d7321003470a9cd0b4be4ae39d7a Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Fri, 22 Mar 2024 16:02:54 -0700
Subject: [PATCH] [clang-tidy] Fix result check after overwriteChangedFiles()

If any return from overwriteChangedFiles is true some fixes were not
applied.
---
 clang-tools-extra/clang-tidy/ClangTidy.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp 
b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 40ac6918faf407..b877ea06dc05cd 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -233,7 +233,7 @@ class ErrorReporter {
 if (!tooling::applyAllReplacements(Replacements.get(), Rewrite)) {
   llvm::errs() << "Can't apply replacements for file " << File << "\n";
 }
-AnyNotWritten &= Rewrite.overwriteChangedFiles();
+AnyNotWritten |= Rewrite.overwriteChangedFiles();
   }
 
   if (AnyNotWritten) {

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


[clang-tools-extra] [clang-tidy][NFC] Remove unnecessary nullptr check on cast subexpr (PR #85473)

2024-03-18 Thread Mike Rice via cfe-commits

mikerice1969 wrote:

I mentioned the assert just to make the point that setSubExpr is written so it 
doesn't return a nullptr. So it is not expected and the deference is ok. 

I went ahead with this change but feel free to update if you like. But adding a 
return when nullptr is seen here would confuse the code and static verifiers 
will complain that the return can never happen.

https://github.com/llvm/llvm-project/pull/85473
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Remove unnecessary nullptr check on cast subexpr (PR #85473)

2024-03-18 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/85473
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Remove unnecessary nullptr check on cast subexpr (PR #85473)

2024-03-15 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/85473

The value of SubExpr is not null since getSubExpr would assert in that case. 
Remove the nullptr check. This avoids confusion since SubExpr is used without 
check later in the function.

>From 56c3ca2e2cfac7b6c9b9029d14151fd80d705c2c Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Fri, 15 Mar 2024 13:37:32 -0700
Subject: [PATCH] [clang-tidy][NFC] Remove unnecessary nullptr check on cast
 subexpr

The value of SubExpr is not null since getSubExpr would assert in that
case. Remove the nullptr check. This avoids confusion since SubExpr is
used without check later in the function.
---
 .../clang-tidy/readability/ImplicitBoolConversionCheck.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 4f02950e7794cb..74152c6034510b 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -81,8 +81,7 @@ void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
 
   const Expr *SubExpr = Cast->getSubExpr();
 
-  bool NeedInnerParens =
-  SubExpr != nullptr && 
utils::fixit::areParensNeededForStatement(*SubExpr);
+  bool NeedInnerParens = utils::fixit::areParensNeededForStatement(*SubExpr);
   bool NeedOuterParens =
   Parent != nullptr && utils::fixit::areParensNeededForStatement(*Parent);
 

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


[clang] [llvm] [openmp] [OpenMP] Introduce support for OMPX extensions and taskgraph frontend (PR #66919)

2024-02-28 Thread Mike Rice via cfe-commits

mikerice1969 wrote:

Hi @josemonsalve2 if you want to help move this along it would be best to break 
this into at least three separate PRs.
1) Parsing/Sema/Serialization
2) CodeGen
3) Extension checking framework

In whatever order makes sense to you.
We've added several extension directives in our downstream so I should be able 
to help here if you can break these up a bit.

https://github.com/llvm/llvm-project/pull/66919
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenMP] Move unsupported structured bindings diagnostic (PR #80216)

2024-02-01 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/80216
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenMP] Move unsupported structured bindings diagnostic (PR #80216)

2024-01-31 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/80216

Move the diagnostic so it fires only when doing an OpenMP capture, not for 
non-OpenMP captures. This allows non-OpenMP code to work when using OpenMP 
elsewhere, such as the code reported in
https://github.com/llvm/llvm-project/issues/66999.

>From e5615a482b31c5cec1220c274c9391d47b5b0a8d Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Wed, 31 Jan 2024 15:18:39 -0800
Subject: [PATCH] [OpenMP] Move unsupported structured bindings diagnostic

Move the diagnostic so it fires only when doing an OpenMP capture, not
for non-OpenMP captures. This allows non-OpenMP code to work when using
OpenMP elsewhere, such as the code reported in
https://github.com/llvm/llvm-project/issues/66999.
---
 clang/lib/Sema/SemaExpr.cpp | 18 ++---
 clang/test/SemaCXX/decomposition-openmp.cpp | 29 +
 2 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index abe300ecc5431..d15278bce5a6b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19528,16 +19528,6 @@ static bool captureInLambda(LambdaScopeInfo *LSI, 
ValueDecl *Var,
 ByRef = (LSI->ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByref);
   }
 
-  BindingDecl *BD = dyn_cast(Var);
-  // FIXME: We should support capturing structured bindings in OpenMP.
-  if (!Invalid && BD && S.LangOpts.OpenMP) {
-if (BuildAndDiagnose) {
-  S.Diag(Loc, diag::err_capture_binding_openmp) << Var;
-  S.Diag(Var->getLocation(), diag::note_entity_declared_at) << Var;
-}
-Invalid = true;
-  }
-
   if (BuildAndDiagnose && S.Context.getTargetInfo().getTriple().isWasm() &&
   CaptureType.getNonReferenceType().isWebAssemblyReferenceType()) {
 S.Diag(Loc, diag::err_wasm_ca_reference) << 0;
@@ -19879,6 +19869,14 @@ bool Sema::tryCaptureVariable(
 // just break here. Similarly, global variables that are captured in a
 // target region should not be captured outside the scope of the 
region.
 if (RSI->CapRegionKind == CR_OpenMP) {
+  // FIXME: We should support capturing structured bindings in OpenMP.
+  if (isa(Var)) {
+if (BuildAndDiagnose) {
+  Diag(ExprLoc, diag::err_capture_binding_openmp) << Var;
+  Diag(Var->getLocation(), diag::note_entity_declared_at) << Var;
+}
+return true;
+  }
   OpenMPClauseKind IsOpenMPPrivateDecl = isOpenMPPrivateDecl(
   Var, RSI->OpenMPLevel, RSI->OpenMPCaptureLevel);
   // If the variable is private (i.e. not captured) and has variably
diff --git a/clang/test/SemaCXX/decomposition-openmp.cpp 
b/clang/test/SemaCXX/decomposition-openmp.cpp
index 28afc39800399..2185f3db83d4e 100644
--- a/clang/test/SemaCXX/decomposition-openmp.cpp
+++ b/clang/test/SemaCXX/decomposition-openmp.cpp
@@ -1,13 +1,32 @@
-
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 -fopenmp %s
 
-// FIXME: OpenMP should support capturing structured bindings
+// Okay, not an OpenMP capture.
 auto f() {
   int i[2] = {};
-  auto [a, b] = i; // expected-note 2{{declared here}}
+  auto [a, b] = i;
   return [=, &a] {
-// expected-error@-1 {{capturing a structured binding is not yet supported 
in OpenMP}}
 return a + b;
-// expected-error@-1 {{capturing a structured binding is not yet supported 
in OpenMP}}
   };
 }
+
+// Okay, not an OpenMP capture.
+void foo(int);
+void g() {
+  #pragma omp parallel
+  {
+int i[2] = {};
+auto [a, b] = i;
+auto L = [&] { foo(a+b); };
+  }
+}
+
+// FIXME: OpenMP should support capturing structured bindings
+void h() {
+  int i[2] = {};
+  auto [a, b] = i; // expected-note 2{{declared here}}
+  #pragma omp parallel
+  {
+// expected-error@+1 2{{capturing a structured binding is not yet 
supported in OpenMP}}
+foo(a + b);
+  }
+}

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


[clang] [NFC] Remove unneeded nullptr checks after cast<> (PR #74674)

2023-12-07 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/74674
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC] Remove unneeded nullptr checks after cast<> (PR #74674)

2023-12-06 Thread Mike Rice via cfe-commits


@@ -6454,8 +6454,7 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
   !EvalResult.hasSideEffects())
 Value = &EvalResult.Val;
 
-  LangAS AddrSpace =
-  VD ? GetGlobalVarAddressSpace(VD) : MaterializedType.getAddressSpace();

mikerice1969 wrote:

@yxsamliu, you may have added this back in cbf647cc3a712. Do you know when/if 
the AddrSpace should be set from MaterializedType since it seems VD is always 
non-null here.

https://github.com/llvm/llvm-project/pull/74674
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC] Remove unneeded nullptr checks after cast<> (PR #74674)

2023-12-06 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/74674

Since VD is assigned from a cast it cannot be a nullptr or it would 
have asserted. Remove the subsequent checks to clear up any misunderstanding.

>From 6b3b456534c21a74f12ac022ee99365dd3831dec Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Wed, 6 Dec 2023 14:30:09 -0800
Subject: [PATCH] [NFC] Remove unneeded nullptr checks after cast<>

Since VD is assigned from a cast it cannot be a nullptr
or it would have asserted. Remove the subsequent checks to clear
up any misunderstanding.
---
 clang/lib/CodeGen/CodeGenModule.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 6a20723bf2bca..b931a81bc0087 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -6439,7 +6439,7 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
   VD, E->getManglingNumber(), Out);
 
   APValue *Value = nullptr;
-  if (E->getStorageDuration() == SD_Static && VD && VD->evaluateValue()) {
+  if (E->getStorageDuration() == SD_Static && VD->evaluateValue()) {
 // If the initializer of the extending declaration is a constant
 // initializer, we should have a cached constant initializer for this
 // temporary. Note that this might have a different value from the value
@@ -6454,8 +6454,7 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
   !EvalResult.hasSideEffects())
 Value = &EvalResult.Val;
 
-  LangAS AddrSpace =
-  VD ? GetGlobalVarAddressSpace(VD) : MaterializedType.getAddressSpace();
+  LangAS AddrSpace = GetGlobalVarAddressSpace(VD);
 
   std::optional emitter;
   llvm::Constant *InitialValue = nullptr;

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


[compiler-rt] [flang] [clang-tools-extra] [llvm] [clang] [libc] [libcxx] [C23] Complete support for WG14 N2508 (PR #71398)

2023-11-17 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 approved this pull request.

LGTM. Thanks!

https://github.com/llvm/llvm-project/pull/71398
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Replace getAs with castAs, dyn_cast with cast (NFC) (PR #72600)

2023-11-17 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/72600
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] Replace getAs with castAs, dyn_cast with cast (NFC) (PR #72600)

2023-11-16 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/72600

Make the code clear that nullptrs are not expected.

>From da715ea17cd3a23894826eac8cc8f7cd880b5e02 Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Thu, 16 Nov 2023 18:30:47 -0800
Subject: [PATCH] Replace getAs with castAs, dyn_cast with cast (NFC)

Make the code clear that nullptrs are not expected.
---
 clang/lib/AST/ASTContext.cpp  | 4 ++--
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 4f54791b4c1e5ce..1c893d008cb49f3 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4014,8 +4014,8 @@ QualType ASTContext::getVectorType(QualType vecType, 
unsigned NumElts,
   assert(vecType->isBuiltinType() ||
  (vecType->isBitIntType() &&
   // Only support _BitInt elements with byte-sized power of 2 NumBits.
-  llvm::isPowerOf2_32(vecType->getAs()->getNumBits()) &&
-  vecType->getAs()->getNumBits() >= 8));
+  llvm::isPowerOf2_32(vecType->castAs()->getNumBits()) &&
+  vecType->castAs()->getNumBits() >= 8));
 
   // Check if we've already instantiated a vector of this type.
   llvm::FoldingSetNodeID ID;
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index ad6b0188390d88f..d04645e89f92843 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4402,7 +4402,7 @@ static void updateNVPTXMetadata(Function &Kernel, 
StringRef Name, int32_t Value,
   // Update the "maxntidx" metadata for NVIDIA, or add it.
   MDNode *ExistingOp = getNVPTXMDNode(Kernel, Name);
   if (ExistingOp) {
-auto *OldVal = dyn_cast(ExistingOp->getOperand(2));
+auto *OldVal = cast(ExistingOp->getOperand(2));
 int32_t OldLimit = cast(OldVal->getValue())->getZExtValue();
 ExistingOp->replaceOperandWith(
 2, ConstantAsMetadata::get(ConstantInt::get(
@@ -4441,7 +4441,7 @@ OpenMPIRBuilder::readThreadBoundsForKernel(const Triple 
&T, Function &Kernel) {
   }
 
   if (MDNode *ExistingOp = getNVPTXMDNode(Kernel, "maxntidx")) {
-auto *OldVal = dyn_cast(ExistingOp->getOperand(2));
+auto *OldVal = cast(ExistingOp->getOperand(2));
 int32_t UB = cast(OldVal->getValue())->getZExtValue();
 return {0, ThreadLimit ? std::min(ThreadLimit, UB) : UB};
   }

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


[clang] [clang-tools-extra] [llvm] [compiler-rt] [flang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-16 Thread Mike Rice via cfe-commits


@@ -359,16 +359,34 @@ static Attr *handleCodeAlignAttr(Sema &S, Stmt *St, const 
ParsedAttr &A) {
 static void
 CheckForDuplicateCodeAlignAttrs(Sema &S,
 const SmallVectorImpl &Attrs) {
-  const Attr *A = nullptr;
-  for (const auto *I : Attrs) {
-if (isa(I)) {
-  if (A) {
-S.Diag(I->getLocation(), diag::err_loop_attr_duplication) << A;
-S.Diag(A->getLocation(), diag::note_previous_attribute);
-  }
-  A = I;
+const auto *FirstItr =
+  std::find_if(Attrs.begin(), Attrs.end(), [](const Attr *A) {
+ return isa(A);
+  });
+
+const Attr *FirstItrAttr =

mikerice1969 wrote:

Don't think we need FirstItrAttr or NextItrAttr. Couldn't you use (*FirstItr) 
and (*NextItr) for those?

https://github.com/llvm/llvm-project/pull/70762
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Add conditional to module cloning in bitcode linking (PR #72478)

2023-11-16 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 approved this pull request.

LGTM. It fixes the performance problems we were seeing. Thanks!

https://github.com/llvm/llvm-project/pull/72478
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Implement post-opt linking option for builtin bitocdes (PR #69371)

2023-11-15 Thread Mike Rice via cfe-commits


@@ -48,428 +49,365 @@
 #include "llvm/Support/ToolOutputFile.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Transforms/IPO/Internalize.h"
+#include "llvm/Transforms/Utils/Cloning.h"
 
-#include 
 #include 
 using namespace clang;
 using namespace llvm;
 
 #define DEBUG_TYPE "codegenaction"
 
 namespace clang {
-  class BackendConsumer;
-  class ClangDiagnosticHandler final : public DiagnosticHandler {
-  public:
-ClangDiagnosticHandler(const CodeGenOptions &CGOpts, BackendConsumer *BCon)
-: CodeGenOpts(CGOpts), BackendCon(BCon) {}
+class BackendConsumer;
+class ClangDiagnosticHandler final : public DiagnosticHandler {
+public:
+  ClangDiagnosticHandler(const CodeGenOptions &CGOpts, BackendConsumer *BCon)
+  : CodeGenOpts(CGOpts), BackendCon(BCon) {}
 
-bool handleDiagnostics(const DiagnosticInfo &DI) override;
+  bool handleDiagnostics(const DiagnosticInfo &DI) override;
 
-bool isAnalysisRemarkEnabled(StringRef PassName) const override {
-  return CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(PassName);
-}
-bool isMissedOptRemarkEnabled(StringRef PassName) const override {
-  return CodeGenOpts.OptimizationRemarkMissed.patternMatches(PassName);
-}
-bool isPassedOptRemarkEnabled(StringRef PassName) const override {
-  return CodeGenOpts.OptimizationRemark.patternMatches(PassName);
-}
+  bool isAnalysisRemarkEnabled(StringRef PassName) const override {
+return CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(PassName);
+  }
+  bool isMissedOptRemarkEnabled(StringRef PassName) const override {
+return CodeGenOpts.OptimizationRemarkMissed.patternMatches(PassName);
+  }
+  bool isPassedOptRemarkEnabled(StringRef PassName) const override {
+return CodeGenOpts.OptimizationRemark.patternMatches(PassName);
+  }
 
-bool isAnyRemarkEnabled() const override {
-  return CodeGenOpts.OptimizationRemarkAnalysis.hasValidPattern() ||
- CodeGenOpts.OptimizationRemarkMissed.hasValidPattern() ||
- CodeGenOpts.OptimizationRemark.hasValidPattern();
-}
+  bool isAnyRemarkEnabled() const override {
+return CodeGenOpts.OptimizationRemarkAnalysis.hasValidPattern() ||
+   CodeGenOpts.OptimizationRemarkMissed.hasValidPattern() ||
+   CodeGenOpts.OptimizationRemark.hasValidPattern();
+  }
 
-  private:
-const CodeGenOptions &CodeGenOpts;
-BackendConsumer *BackendCon;
-  };
+private:
+  const CodeGenOptions &CodeGenOpts;
+  BackendConsumer *BackendCon;
+};
+
+static void reportOptRecordError(Error E, DiagnosticsEngine &Diags,
+ const CodeGenOptions &CodeGenOpts) {
+  handleAllErrors(
+  std::move(E),
+[&](const LLVMRemarkSetupFileError &E) {
+Diags.Report(diag::err_cannot_open_file)
+<< CodeGenOpts.OptRecordFile << E.message();
+  },
+[&](const LLVMRemarkSetupPatternError &E) {
+Diags.Report(diag::err_drv_optimization_remark_pattern)
+<< E.message() << CodeGenOpts.OptRecordPasses;
+  },
+[&](const LLVMRemarkSetupFormatError &E) {
+Diags.Report(diag::err_drv_optimization_remark_format)
+<< CodeGenOpts.OptRecordFormat;
+  });
+}
 
-  static void reportOptRecordError(Error E, DiagnosticsEngine &Diags,
-   const CodeGenOptions &CodeGenOpts) {
-handleAllErrors(
-std::move(E),
-  [&](const LLVMRemarkSetupFileError &E) {
-  Diags.Report(diag::err_cannot_open_file)
-  << CodeGenOpts.OptRecordFile << E.message();
-},
-  [&](const LLVMRemarkSetupPatternError &E) {
-  Diags.Report(diag::err_drv_optimization_remark_pattern)
-  << E.message() << CodeGenOpts.OptRecordPasses;
-},
-  [&](const LLVMRemarkSetupFormatError &E) {
-  Diags.Report(diag::err_drv_optimization_remark_format)
-  << CodeGenOpts.OptRecordFormat;
-});
-}
+BackendConsumer::BackendConsumer(BackendAction Action, DiagnosticsEngine 
&Diags,
+ IntrusiveRefCntPtr VFS,
+ const HeaderSearchOptions &HeaderSearchOpts,
+ const PreprocessorOptions &PPOpts,
+ const CodeGenOptions &CodeGenOpts,
+ const TargetOptions &TargetOpts,
+ const LangOptions &LangOpts,
+ const std::string &InFile,
+ SmallVector LinkModules,
+ std::unique_ptr OS,
+ LLVMContext &C,
+ CoverageSourceInfo *CoverageInfo)
+  : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
+  CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
+  AsmOutStream(std::move(OS)), Context(nullptr), FS(VFS),
+  LLVMIRGeneration("irgen", "LLVM

[clang] [OpenMP] Add a missing 'const' (NFC) (PR #71596)

2023-11-07 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/71596
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenMP] Add a missing 'const' (NFC) (PR #71596)

2023-11-07 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/71596

None

>From 41f147c79a0a32fa541e7fb99cb2053b8f4b7ea2 Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Tue, 7 Nov 2023 14:51:55 -0800
Subject: [PATCH] [OpenMP] Add a missing 'const' (NFC)

---
 clang/include/clang/AST/StmtOpenMP.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/StmtOpenMP.h 
b/clang/include/clang/AST/StmtOpenMP.h
index 2725747e051e728..62164339153573c 100644
--- a/clang/include/clang/AST/StmtOpenMP.h
+++ b/clang/include/clang/AST/StmtOpenMP.h
@@ -994,7 +994,7 @@ class OMPLoopTransformationDirective : public 
OMPLoopBasedDirective {
   unsigned getNumAssociatedLoops() const { return getLoopsNumber(); }
 
   /// Return the number of loops generated by this loop transformation.
-  unsigned getNumGeneratedLoops() { return NumGeneratedLoops; }
+  unsigned getNumGeneratedLoops() const { return NumGeneratedLoops; }
 
   /// Get the de-sugared statements after the loop transformation.
   ///

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


[libc] [clang] [clang-tools-extra] [libcxx] [flang] [llvm] [compiler-rt] [C23] Complete support for WG14 N2508 (PR #71398)

2023-11-06 Thread Mike Rice via cfe-commits


@@ -32,8 +32,8 @@ T tmain(T argc) {
   }
   switch (argc) {
 #pragma omp error // expected-error {{ERROR}}
-  case 1:
-#pragma omp error // expected-error {{ERROR}}
+  case 1: // FIXME: error without 'at execution' is not a stand-alone 
directive and so this should be accepted.

mikerice1969 wrote:

I would remove this FIXME. I think we want 'error' to be diagnosed. The 
original meaning of stand-alone was directives that did not has associated user 
statements. This was before utility/informational directives existed. I think 
the intention is we only allow executable statements with associated user 
statements here, not declarative, utility, etc.

https://github.com/llvm/llvm-project/pull/71398
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Remove malformed brief commands in comments (NFC) (PR #70746)

2023-10-31 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 closed 
https://github.com/llvm/llvm-project/pull/70746
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 57caadc - [MSVC] Allow declaration of multi-dim 'property' array fields

2023-04-05 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2023-04-05T10:29:37-07:00
New Revision: 57caadc57a30f2279099e5b86bb555b4aab621ce

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

LOG: [MSVC] Allow declaration of multi-dim 'property' array fields

MSVC allows declaration of multi-dim arrays like this:

__declspec(property(get=GetX, put=PutX)) int x[][][];

This syntax can appear in generated typelib headers.

Currently clang errors on declarators like this since it forms an array
type of incomplete array. Rather than try to handle such a type, ignore
adjacent empty chunks so this is treated as if there was only one empty
array chunk (i.e. int x[]).

The functionality to handle multi-dim subscripts of property fields
already works, but only if declared as a single-dim array.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/ParsedAttr.h
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CodeGenCXX/ms-property.cpp
clang/test/SemaCXX/ms-property-error.cpp
clang/test/SemaCXX/ms-property.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1e280cb633e23..bbfef9ff3cf7c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -146,6 +146,8 @@ Non-comprehensive list of changes in this release
 - Clang now supports ``__builtin_assume_separate_storage`` that indicates that
   its arguments point to objects in separate storage allocations.
 - Clang now supports expressions in ``#pragma clang __debug dump``.
+- Clang now supports declaration of multi-dimensional arrays with
+  ``__declspec(property)``.
 
 New Compiler Flags
 --

diff  --git a/clang/include/clang/Sema/ParsedAttr.h 
b/clang/include/clang/Sema/ParsedAttr.h
index e2b4be48c0bd1..5f45668851c73 100644
--- a/clang/include/clang/Sema/ParsedAttr.h
+++ b/clang/include/clang/Sema/ParsedAttr.h
@@ -896,6 +896,16 @@ class ParsedAttributesView {
 });
   }
 
+  const ParsedAttr *getMSPropertyAttr() const {
+auto It = llvm::find_if(AttrList, [](const ParsedAttr *AL) {
+  return AL->isDeclspecPropertyAttribute();
+});
+if (It != AttrList.end())
+  return *It;
+return nullptr;
+  }
+  bool hasMSPropertyAttr() const { return getMSPropertyAttr(); }
+
 private:
   VecTy AttrList;
 };

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index e28c44f97f1fe..312b6f801c1f0 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -3235,16 +3235,6 @@ static bool InitializationHasSideEffects(const FieldDecl 
&FD) {
   return false;
 }
 
-static const ParsedAttr *getMSPropertyAttr(const ParsedAttributesView &list) {
-  ParsedAttributesView::const_iterator Itr =
-  llvm::find_if(list, [](const ParsedAttr &AL) {
-return AL.isDeclspecPropertyAttribute();
-  });
-  if (Itr != list.end())
-return &*Itr;
-  return nullptr;
-}
-
 // Check if there is a field shadowing.
 void Sema::CheckShadowInheritedFields(const SourceLocation &Loc,
   DeclarationName FieldName,
@@ -3322,7 +3312,7 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier 
AS, Declarator &D,
 
   bool isFunc = D.isDeclarationOfFunction();
   const ParsedAttr *MSPropertyAttr =
-  getMSPropertyAttr(D.getDeclSpec().getAttributes());
+  D.getDeclSpec().getAttributes().getMSPropertyAttr();
 
   if (cast(CurContext)->isInterface()) {
 // The Microsoft extension __interface only permits public member functions

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 53852dd930a71..e195e85ab75b7 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5070,6 +5070,19 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
   DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr;
   Expr *ArraySize = static_cast(ATI.NumElts);
   ArrayType::ArraySizeModifier ASM;
+
+  // Microsoft property fields can have multiple sizeless array chunks
+  // (i.e. int x[][][]). Skip all of these except one to avoid creating
+  // bad incomplete array types.
+  if (chunkIndex != 0 && !ArraySize &&
+  D.getDeclSpec().getAttributes().hasMSPropertyAttr()) {
+// This is a sizeless chunk. If the next is also, skip this one.
+DeclaratorChunk &NextDeclType = D.getTypeObject(chunkIndex - 1);
+if (NextDeclType.Kind == DeclaratorChunk::Array &&
+!NextDeclType.Arr.NumElts)
+  break;
+  }
+
   if (ATI.isStar)
 ASM = ArrayType::Star;
   else if (ATI.hasStatic)
@@ -6523,6 +6536,12 @@ GetTypeSourceInfoForDeclarator(TypeProcessingState 
&State,
   }
 
   for (unsigned i = 0, e = D.getNumTypeObjects(); i 

[clang] e716b02 - [OpenMP 5.2] Deprecate 'destroy' clause without argument for 'depobj' construct

2023-02-07 Thread Mike Rice via cfe-commits

Author: Fazlay Rabbi
Date: 2023-02-07T12:09:52-08:00
New Revision: e716b0204a5ae2a96289a335b2ab30a6c3fb09cf

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

LOG: [OpenMP 5.2] Deprecate 'destroy' clause without argument for 'depobj' 
construct

Deprecate and diagnose uses of the 'destroy' clauses without an argument
in 'omp depobj' directives.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/depobj_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 36d4bc2a700d8..31519f3c04795 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1369,6 +1369,9 @@ def err_omp_map_type_modifier_missing : Error<
   "missing map type modifier">;
 def err_omp_declare_simd_inbranch_notinbranch : Error<
   "unexpected '%0' clause, '%1' is specified already">;
+def err_omp_expected_clause_argument
+: Error<"expected '%0' clause with an argument on '#pragma omp %1' "
+"construct">;
 def err_expected_end_declare_target_or_variant : Error<
   "expected '#pragma omp end declare %select{target|variant}0'">;
 def err_expected_begin_declare_variant

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index c767341d922bd..368f5ecfa23d5 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -17662,6 +17662,13 @@ OMPClause *Sema::ActOnOpenMPDestroyClause(Expr 
*InteropVar,
   SourceLocation LParenLoc,
   SourceLocation VarLoc,
   SourceLocation EndLoc) {
+  if (!InteropVar && LangOpts.OpenMP >= 52 &&
+  DSAStack->getCurrentDirective() == OMPD_depobj) {
+Diag(StartLoc, diag::err_omp_expected_clause_argument)
+<< getOpenMPClauseName(OMPC_destroy)
+<< getOpenMPDirectiveName(OMPD_depobj);
+return nullptr;
+  }
   if (InteropVar &&
   !isValidInteropVariable(*this, InteropVar, VarLoc, OMPC_destroy))
 return nullptr;

diff  --git a/clang/test/OpenMP/depobj_messages.cpp 
b/clang/test/OpenMP/depobj_messages.cpp
index c26daba2bf1d0..b05214d0ffe35 100644
--- a/clang/test/OpenMP/depobj_messages.cpp
+++ b/clang/test/OpenMP/depobj_messages.cpp
@@ -2,11 +2,15 @@
 // RUN: -ferror-limit 100 %s -Wuninitialized
 // RUN: %clang_cc1 -verify=expected,omp51 -fopenmp -fopenmp-version=51 \
 // RUN: -ferror-limit 100 %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp52 -fopenmp -fopenmp-version=52 \
+// RUN: -ferror-limit 100 %s -Wuninitialized
 
 // RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-simd -fopenmp-version=50 \
 // RUN: -ferror-limit 100 %s -Wuninitialized
 // RUN: %clang_cc1 -verify=expected,omp51 -fopenmp-simd -fopenmp-version=51 \
 // RUN: -ferror-limit 100 %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp52 -fopenmp-simd -fopenmp-version=52 \
+// RUN: -ferror-limit 100 %s -Wuninitialized
 
 struct S1 { // expected-note 2 {{declared here}}
   int a;
@@ -27,7 +31,7 @@ T tmain(T argc) {
 #pragma omp depobj(x) untied  // expected-error {{unexpected OpenMP clause 
'untied' in directive '#pragma omp depobj'}}
 #pragma omp depobj(x) unknown // expected-warning {{extra tokens at the end of 
'#pragma omp depobj' are ignored}}
   if (argc)
-#pragma omp depobj(x) destroy // expected-error {{'#pragma omp depobj' cannot 
be an immediate substatement}}
+#pragma omp depobj(x) destroy // omp52-error {{expected 'destroy' clause with 
an argument on '#pragma omp depobj' construct}} expected-error {{'#pragma omp 
depobj' cannot be an immediate substatement}}
 if (argc) {
 #pragma omp depobj(x) depend(in:s)
 }
@@ -148,16 +152,16 @@ label1 : {
 #pragma omp parallel depobj(argc) // expected-warning {{extra tokens at the 
end of '#pragma omp parallel' are ignored}}
   ;
 #pragma omp depobj(x) seq_cst // expected-error {{unexpected OpenMP clause 
'seq_cst' in directive '#pragma omp depobj'}}
-#pragma omp depobj(x) depend(source: x) // omp51-error {{expected depend 
modifier(iterator) or 'in', 'out', 'inout', 'mutexinoutset' or 'inoutset' in 
OpenMP clause 'depend'}} omp50-error {{expected depend modifier(iterator) or 
'in', 'out', 'inout' or 'mutexinoutset' in OpenMP clause 'depend'}}
+#pragma omp depobj(x) depend(source: x) // omp52-error {{expected depend 
modifier(iterator) or 'in', 'out', 'inout', 'mutexinoutset' or 'inoutset' in 
OpenMP clause 'depend'}} omp51-error {{expected depend modifier(iterator) or 
'in', 'out', 'inout', 'mutexinoutset' or 'inoutset' in OpenMP clause 'depend'}} 
omp50-e

[clang] d27fb5e - [Serialization] Add support for (de)serializing #pragma pack

2023-02-07 Thread Mike Rice via cfe-commits

Author: Dustin Howett
Date: 2023-02-07T11:37:02-08:00
New Revision: d27fb5efc5f2086fa157e7d836b61bae4d5f3734

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

LOG: [Serialization] Add support for (de)serializing #pragma pack

Serialization of tokens is required when PCH is used with late parsed
templates, including annotation tokens used for pragmas.

This patch implements the serialization for annot_pragma_pack.

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

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

Added: 
clang/test/PCH/delayed-template-with-pragma-pack.cpp

Modified: 
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTReader.h
clang/lib/Parse/ParsePragma.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6247d4a5f6a53..223190602d921 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -483,6 +483,12 @@ class Sema final {
 PSK_Pop_Set   = PSK_Pop | PSK_Set,  // #pragma (pop[, id], value)
   };
 
+  struct PragmaPackInfo {
+PragmaMsStackAction Action;
+StringRef SlotLabel;
+Token Alignment;
+  };
+
   // #pragma pack and align.
   class AlignPackInfo {
   public:

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 5cdbdfe4e38d4..007872b10e242 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -2236,7 +2236,7 @@ class ASTReader
   unsigned &Idx, LocSeq *Seq = nullptr);
 
   // Read a string
-  static std::string ReadString(const RecordData &Record, unsigned &Idx);
+  static std::string ReadString(const RecordDataImpl &Record, unsigned &Idx);
 
   // Skip a string
   static void SkipString(const RecordData &Record, unsigned &Idx) {

diff  --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 658853d42b746..ff7273eddb1a0 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -665,18 +665,10 @@ void Parser::HandlePragmaVisibility() {
   Actions.ActOnPragmaVisibility(VisType, VisLoc);
 }
 
-namespace {
-struct PragmaPackInfo {
-  Sema::PragmaMsStackAction Action;
-  StringRef SlotLabel;
-  Token Alignment;
-};
-} // end anonymous namespace
-
 void Parser::HandlePragmaPack() {
   assert(Tok.is(tok::annot_pragma_pack));
-  PragmaPackInfo *Info =
-static_cast(Tok.getAnnotationValue());
+  Sema::PragmaPackInfo *Info =
+  static_cast(Tok.getAnnotationValue());
   SourceLocation PragmaLoc = Tok.getLocation();
   ExprResult Alignment;
   if (Info->Alignment.is(tok::numeric_constant)) {
@@ -2110,8 +2102,8 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
 return;
   }
 
-  PragmaPackInfo *Info =
-  PP.getPreprocessorAllocator().Allocate(1);
+  Sema::PragmaPackInfo *Info =
+  PP.getPreprocessorAllocator().Allocate(1);
   Info->Action = Action;
   Info->SlotLabel = SlotLabel;
   Info->Alignment = Alignment;

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index eb1eda98abc79..fb723d4e46d6b 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1687,6 +1687,16 @@ Token ASTReader::ReadToken(ModuleFile &F, const 
RecordDataImpl &Record,
   Tok.setAnnotationValue(static_cast(Info));
   break;
 }
+case tok::annot_pragma_pack: {
+  auto *Info = new (PP.getPreprocessorAllocator()) Sema::PragmaPackInfo;
+  Info->Action = static_cast(Record[Idx++]);
+  auto SlotLabel = ReadString(Record, Idx);
+  Info->SlotLabel =
+  llvm::StringRef(SlotLabel).copy(PP.getPreprocessorAllocator());
+  Info->Alignment = ReadToken(F, Record, Idx);
+  Tok.setAnnotationValue(static_cast(Info));
+  break;
+}
 // Some annotation tokens do not use the PtrData field.
 case tok::annot_pragma_openmp:
 case tok::annot_pragma_openmp_end:
@@ -9084,7 +9094,7 @@ llvm::APFloat ASTRecordReader::readAPFloat(const 
llvm::fltSemantics &Sem) {
 }
 
 // Read a string
-std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) {
+std::string ASTReader::ReadString(const RecordDataImpl &Record, unsigned &Idx) 
{
   unsigned Len = Record[Idx++];
   std::string Result(Record.data() + Idx, Record.data() + Idx + Len);
   Idx += Len;

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index bdf11001473e2..c1afdeb6007db 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -4412,6 +4412,14 @@ void ASTWriter::AddToken(const T

[clang] c52053b - [clang] Fix buildbot failure in delayed-template-with-pragma.cpp

2022-11-29 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-11-29T11:53:37-08:00
New Revision: c52053bd9961cc1854e86958ffb0f89e2cfe4e5f

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

LOG: [clang] Fix buildbot failure in delayed-template-with-pragma.cpp

Use captured values to match loop metadata.

Added: 


Modified: 
clang/test/PCH/delayed-template-with-pragma.cpp

Removed: 




diff  --git a/clang/test/PCH/delayed-template-with-pragma.cpp 
b/clang/test/PCH/delayed-template-with-pragma.cpp
index abc959b20707..e54388456245 100644
--- a/clang/test/PCH/delayed-template-with-pragma.cpp
+++ b/clang/test/PCH/delayed-template-with-pragma.cpp
@@ -20,14 +20,14 @@ void a(T t) {
   }
 }
 #else
-// CHECK: !llvm.loop !3
-// CHECK: !llvm.loop !7
-// CHECK: !3 = distinct !{!3, !4, !5}
-// CHECK: !4 = !{!"llvm.loop.mustprogress"}
-// CHECK: !5 = !{!"llvm.loop.unroll.count", i32 4}
-// CHECK: !7 = distinct !{!7, !8, !9}
-// CHECK: !8 = !{!"llvm.loop.parallel_accesses", !6}
-// CHECK: !9 = !{!"llvm.loop.vectorize.enable", i1 true}
+// CHECK: !llvm.loop [[LOOP1:!.*]]
+// CHECK: !llvm.loop [[LOOP2:!.*]]
+// CHECK: [[LOOP1]] = distinct !{[[LOOP1]], [[LOOP1A:!.*]], [[LOOP1B:!.*]]}
+// CHECK: [[LOOP1A]] = !{!"llvm.loop.mustprogress"}
+// CHECK: [[LOOP1B]] = !{!"llvm.loop.unroll.count", i32 4}
+// CHECK: [[LOOP2]] = distinct !{[[LOOP2]], [[LOOP2A:!.*]], [[LOOP2B:!.*]]}
+// CHECK: [[LOOP2A]] = !{!"llvm.loop.parallel_accesses", [[LOOP2C:!.*]]}
+// CHECK: [[LOOP2B]] = !{!"llvm.loop.vectorize.enable", i1 true}
 // expected-warning@17 {{unused variable 'zz'}}
 void foo()
 {



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


[clang] 530eb26 - [clang] Add serialization for loop hint annotation tokens

2022-11-29 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-11-29T10:51:11-08:00
New Revision: 530eb263c0ec02fe8d107cbdb41ac6e482514a00

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

LOG: [clang] Add serialization for loop hint annotation tokens

When late parsed templates are used with PCH tokens are serialized. The
existing code does not handle annotation tokens which can occur due to
various pragmas.

This patch implements the serialization for annot_pragma_loop_hint.

This also enables use of OpenMP pragmas and #pragma unused which do not
need special serialization of the PtrData field.

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

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

Added: 
clang/test/PCH/delayed-template-with-pragma.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Lex/Token.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/Parse/ParsePragma.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b4f217c92ffc8..7580b14fac5d6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -450,6 +450,10 @@ Non-comprehensive list of changes in this release
   It can be used to writing conditionally constexpr code that uses builtins.
 - The time profiler (using ``-ftime-trace`` option) now traces various constant
   evaluation events.
+- Clang can now generate a PCH when using ``-fdelayed-template-parsing`` for
+  code with templates containing loop hint pragmas, OpenMP pragmas, and
+  ``#pragma unused``.
+
 
 New Compiler Flags
 --

diff  --git a/clang/include/clang/Lex/Token.h b/clang/include/clang/Lex/Token.h
index f0c0794096778..7fd48b1b4391e 100644
--- a/clang/include/clang/Lex/Token.h
+++ b/clang/include/clang/Lex/Token.h
@@ -15,6 +15,7 @@
 
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include 
 
@@ -330,6 +331,12 @@ struct PPConditionalInfo {
   bool FoundElse;
 };
 
+// Extra information needed for annonation tokens.
+struct PragmaLoopHintInfo {
+  Token PragmaName;
+  Token Option;
+  ArrayRef Toks;
+};
 } // end namespace clang
 
 #endif // LLVM_CLANG_LEX_TOKEN_H

diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 591eb34ec8839..ceaade4a6e1e8 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -41,7 +41,7 @@ namespace serialization {
 /// Version 4 of AST files also requires that the version control branch and
 /// revision match exactly, since there is no backward compatibility of
 /// AST files at this time.
-const unsigned VERSION_MAJOR = 23;
+const unsigned VERSION_MAJOR = 24;
 
 /// AST file minor version number supported by this version of
 /// Clang.

diff  --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index cddc3780133b8..360601f27176a 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -1293,14 +1293,6 @@ bool Parser::HandlePragmaMSAllocText(StringRef 
PragmaName,
   return true;
 }
 
-namespace {
-struct PragmaLoopHintInfo {
-  Token PragmaName;
-  Token Option;
-  ArrayRef Toks;
-};
-} // end anonymous namespace
-
 static std::string PragmaLoopHintString(Token PragmaName, Token Option) {
   StringRef Str = PragmaName.getIdentifierInfo()->getName();
   std::string ClangLoopStr("clang loop ");

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 4c0395cc4107b..ff324cab57bf7 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1669,11 +1669,38 @@ Token ASTReader::ReadToken(ModuleFile &F, const 
RecordDataImpl &Record,
   Token Tok;
   Tok.startToken();
   Tok.setLocation(ReadSourceLocation(F, Record, Idx));
-  Tok.setLength(Record[Idx++]);
-  if (IdentifierInfo *II = getLocalIdentifier(F, Record[Idx++]))
-Tok.setIdentifierInfo(II);
   Tok.setKind((tok::TokenKind)Record[Idx++]);
   Tok.setFlag((Token::TokenFlags)Record[Idx++]);
+
+  if (Tok.isAnnotation()) {
+Tok.setAnnotationEndLoc(ReadSourceLocation(F, Record, Idx));
+switch (Tok.getKind()) {
+case tok::annot_pragma_loop_hint: {
+  auto *Info = new (PP.getPreprocessorAllocator()) PragmaLoopHintInfo;
+  Info->PragmaName = ReadToken(F, Record, Idx);
+  Info->Option = ReadToken(F, Record, Idx);
+  unsigned NumTokens = Record[Idx++];
+  SmallVector Toks;
+  Toks.reserve(NumTokens);
+  for (unsigned I = 0; I < NumTokens; ++I)
+Toks.push_back(ReadToken(F, Record, Idx));
+  Info->Toks

[clang] 56c1660 - [OpenMP] Initial parsing/sema for 'strict' modifier with 'num_tasks' clause

2022-11-18 Thread Mike Rice via cfe-commits

Author: Fazlay Rabbi
Date: 2022-11-18T16:26:47-08:00
New Revision: 56c166017055595a9f26933e85bfd89e30c528d0

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

LOG: [OpenMP] Initial parsing/sema for 'strict' modifier with 'num_tasks' clause

This patch gives basic parsing and semantic analysis support for 'strict'
modifier with 'num_tasks' clause of 'taskloop' construct introduced in
OpenMP 5.1 (section 2.12.2)

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

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/Basic/OpenMPKinds.def
clang/include/clang/Basic/OpenMPKinds.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/taskloop_strict_modifier_ast_print.cpp
clang/test/OpenMP/taskloop_strict_modifier_messages.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 1c9f62355e4ee..21d9f740eddf1 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -6486,26 +6486,43 @@ class OMPNumTasksClause : public OMPClause, public 
OMPClauseWithPreInit {
   /// Location of '('.
   SourceLocation LParenLoc;
 
+  /// Modifiers for 'num_tasks' clause.
+  OpenMPNumTasksClauseModifier Modifier = OMPC_NUMTASKS_unknown;
+
+  /// Location of the modifier.
+  SourceLocation ModifierLoc;
+
   /// Safe iteration space distance.
   Stmt *NumTasks = nullptr;
 
   /// Set safelen.
   void setNumTasks(Expr *Size) { NumTasks = Size; }
 
+  /// Sets modifier.
+  void setModifier(OpenMPNumTasksClauseModifier M) { Modifier = M; }
+
+  /// Sets modifier location.
+  void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
+
 public:
   /// Build 'num_tasks' clause.
   ///
+  /// \param Modifier Clause modifier.
   /// \param Size Expression associated with this clause.
   /// \param HelperSize Helper grainsize for the construct.
   /// \param CaptureRegion Innermost OpenMP region where expressions in this
   /// clause must be captured.
   /// \param StartLoc Starting location of the clause.
   /// \param EndLoc Ending location of the clause.
-  OMPNumTasksClause(Expr *Size, Stmt *HelperSize,
-OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
-SourceLocation LParenLoc, SourceLocation EndLoc)
+  /// \param ModifierLoc Modifier location.
+  /// \param LParenLoc Location of '('.
+  OMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *Size,
+Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion,
+SourceLocation StartLoc, SourceLocation LParenLoc,
+SourceLocation ModifierLoc, SourceLocation EndLoc)
   : OMPClause(llvm::omp::OMPC_num_tasks, StartLoc, EndLoc),
-OMPClauseWithPreInit(this), LParenLoc(LParenLoc), NumTasks(Size) {
+OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
+ModifierLoc(ModifierLoc), NumTasks(Size) {
 setPreInitStmt(HelperSize, CaptureRegion);
   }
 
@@ -6524,6 +6541,12 @@ class OMPNumTasksClause : public OMPClause, public 
OMPClauseWithPreInit {
   /// Return safe iteration space distance.
   Expr *getNumTasks() const { return cast_or_null(NumTasks); }
 
+  /// Gets modifier.
+  OpenMPNumTasksClauseModifier getModifier() const { return Modifier; }
+
+  /// Gets modifier location.
+  SourceLocation getModifierLoc() const { return ModifierLoc; }
+
   child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
 
   const_child_range children() const {

diff  --git a/clang/include/clang/Basic/OpenMPKinds.def 
b/clang/include/clang/Basic/OpenMPKinds.def
index 339139abe2a49..a084e9686f5ee 100644
--- a/clang/include/clang/Basic/OpenMPKinds.def
+++ b/clang/include/clang/Basic/OpenMPKinds.def
@@ -74,6 +74,9 @@
 #ifndef OPENMP_GRAINSIZE_MODIFIER
 #define OPENMP_GRAINSIZE_MODIFIER(Name)
 #endif
+#ifndef OPENMP_NUMTASKS_MODIFIER
+#define OPENMP_NUMTASKS_MODIFIER(Name)
+#endif
 
 // Static attributes for 'schedule' clause.
 OPENMP_SCHEDULE_KIND(static)
@@ -187,6 +190,10 @@ OPENMP_BIND_KIND(thread)
 // Modifiers for the 'grainsize' clause.
 OPENMP_GRAINSIZE_MODIFIER(strict)
 
+// Modifiers for the 'num_tasks' clause.
+OPENMP_NUMTASKS_MODIFIER(strict)
+
+#undef OPENMP_NUMTASKS_MODIFIER
 #undef OPENMP_GRAINSIZE_MODIFIER
 #undef OPENMP_BIND_KIND
 #undef OPENMP_ADJUST_ARGS_KIND

diff  --git a/clang/include/clang/Basic/OpenMPKinds.h 
b/clang/include/clang/Basic/OpenMPKin

[clang] ab9eac7 - [OpenMP] Initial parsing/sema for 'strict' modifier with 'grainsize' clause

2022-11-17 Thread Mike Rice via cfe-commits

Author: Fazlay Rabbi
Date: 2022-11-17T20:59:07-08:00
New Revision: ab9eac762c35068e77f57795e660d06f578c9614

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

LOG: [OpenMP] Initial parsing/sema for 'strict' modifier with 'grainsize' clause

This patch gives basic parsing and semantic analysis support for 'strict'
modifier with 'grainsize' clause of 'taskloop' construct introduced in
OpenMP 5.1 (section 2.12.2)

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

Added: 
clang/test/OpenMP/taskloop_strict_modifier_ast_print.cpp
clang/test/OpenMP/taskloop_strict_modifier_messages.cpp

Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/OpenMPKinds.def
clang/include/clang/Basic/OpenMPKinds.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/masked_taskloop_grainsize_messages.cpp
clang/test/OpenMP/masked_taskloop_simd_grainsize_messages.cpp
clang/test/OpenMP/master_taskloop_grainsize_messages.cpp
clang/test/OpenMP/master_taskloop_simd_grainsize_messages.cpp
clang/test/OpenMP/parallel_masked_taskloop_simd_grainsize_messages.cpp
clang/test/OpenMP/parallel_master_taskloop_grainsize_messages.cpp
clang/test/OpenMP/parallel_master_taskloop_simd_grainsize_messages.cpp
clang/test/OpenMP/taskloop_grainsize_messages.cpp
clang/test/OpenMP/taskloop_simd_grainsize_messages.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index e7dc5e72b3a82..1c9f62355e4ee 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -6354,26 +6354,43 @@ class OMPGrainsizeClause : public OMPClause, public 
OMPClauseWithPreInit {
   /// Location of '('.
   SourceLocation LParenLoc;
 
+  /// Modifiers for 'grainsize' clause.
+  OpenMPGrainsizeClauseModifier Modifier = OMPC_GRAINSIZE_unknown;
+
+  /// Location of the modifier.
+  SourceLocation ModifierLoc;
+
   /// Safe iteration space distance.
   Stmt *Grainsize = nullptr;
 
   /// Set safelen.
   void setGrainsize(Expr *Size) { Grainsize = Size; }
 
+  /// Sets modifier.
+  void setModifier(OpenMPGrainsizeClauseModifier M) { Modifier = M; }
+
+  /// Sets modifier location.
+  void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
+
 public:
   /// Build 'grainsize' clause.
   ///
+  /// \param Modifier Clause modifier.
   /// \param Size Expression associated with this clause.
   /// \param HelperSize Helper grainsize for the construct.
   /// \param CaptureRegion Innermost OpenMP region where expressions in this
   /// clause must be captured.
   /// \param StartLoc Starting location of the clause.
+  /// \param ModifierLoc Modifier location.
+  /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
-  OMPGrainsizeClause(Expr *Size, Stmt *HelperSize,
- OpenMPDirectiveKind CaptureRegion, SourceLocation 
StartLoc,
- SourceLocation LParenLoc, SourceLocation EndLoc)
+  OMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size,
+ Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion,
+ SourceLocation StartLoc, SourceLocation LParenLoc,
+ SourceLocation ModifierLoc, SourceLocation EndLoc)
   : OMPClause(llvm::omp::OMPC_grainsize, StartLoc, EndLoc),
-OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Grainsize(Size) {
+OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
+ModifierLoc(ModifierLoc), Grainsize(Size) {
 setPreInitStmt(HelperSize, CaptureRegion);
   }
 
@@ -6392,6 +6409,12 @@ class OMPGrainsizeClause : public OMPClause, public 
OMPClauseWithPreInit {
   /// Return safe iteration space distance.
   Expr *getGrainsize() const { return cast_or_null(Grainsize); }
 
+  /// Gets modifier.
+  OpenMPGrainsizeClauseModifier getModifier() const { return Modifier; }
+
+  /// Gets modifier location.
+  SourceLocation getModifierLoc() const { return ModifierLoc; }
+
   child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
 
   const_child_range children() const {

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 27cd3da1f191c..6f46ede56f66c 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticPar

[clang] c954cfe - Some uses of the preprocessor can result in multiple target regions on the

2022-11-04 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-11-04T12:54:22-07:00
New Revision: c954cfeb57a1c8c0996a34da64243bc7f7fe1107

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

LOG: Some uses of the preprocessor can result in multiple target regions on the
same line. Cases such as those in the associated lit tests, can now be
supported.

This adds a 'Count' field to TargetRegionEntryInfo to differentiate
regions with the same source position.

The OffloadEntriesInfoManager routines are updated to maintain a count of
regions seen at a location. The registration of regions proceeds that same as
before, but now the next available count is always determined and used in the
offload entry.

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

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

Added: 
clang/test/OpenMP/Inputs/multiple_regions.inc
clang/test/OpenMP/multiple_regions_per_line.cpp

Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/target_codegen_registration.cpp
clang/test/OpenMP/target_codegen_registration_naming.cpp
clang/test/OpenMP/target_parallel_codegen_registration.cpp
clang/test/OpenMP/target_parallel_codegen_registration_naming.cpp
clang/test/OpenMP/target_parallel_for_codegen_registration.cpp
clang/test/OpenMP/target_parallel_for_codegen_registration_naming.cpp
clang/test/OpenMP/target_parallel_for_simd_codegen_registration.cpp
clang/test/OpenMP/target_parallel_for_simd_codegen_registration_naming.cpp
clang/test/OpenMP/target_simd_codegen_registration.cpp
clang/test/OpenMP/target_simd_codegen_registration_naming.cpp
clang/test/OpenMP/target_teams_codegen_registration.cpp
clang/test/OpenMP/target_teams_codegen_registration_naming.cpp
clang/test/OpenMP/target_teams_distribute_codegen_registration.cpp
clang/test/OpenMP/target_teams_distribute_codegen_registration_naming.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_simd_codegen_registration.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_simd_codegen_registration_naming.cpp
clang/test/OpenMP/target_teams_distribute_simd_codegen_registration.cpp

clang/test/OpenMP/target_teams_distribute_simd_codegen_registration_naming.cpp
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 6b0908d139f47..e52989b7c139b 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1858,7 +1858,7 @@ bool 
CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD,
   auto EntryInfo =
   getTargetEntryUniqueInfo(CGM.getContext(), Loc, VD->getName());
   SmallString<128> Buffer, Out;
-  EntryInfo.getTargetRegionEntryFnName(Buffer);
+  OffloadEntriesInfoManager.getTargetRegionEntryFnName(Buffer, EntryInfo);
 
   const Expr *Init = VD->getAnyInitializer();
   if (CGM.getLangOpts().CPlusPlus && PerformInit) {
@@ -6101,18 +6101,20 @@ void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(
   // Create a unique name for the entry function using the source location
   // information of the current target region. The name will be something like:
   //
-  // __omp_offloading_DD__PP_lBB
+  // __omp_offloading_DD__PP_lBB[_CC]
   //
   // where DD_ is an ID unique to the file (device and file IDs), PP is the
   // mangled name of the function that encloses the target region and BB is the
-  // line number of the target region.
+  // line number of the target region. CC is a count added when more than one
+  // region is located at the same location.
 
   const bool BuildOutlinedFn = CGM.getLangOpts().OpenMPIsDevice ||
!CGM.getLangOpts().OpenMPOffloadMandatory;
   auto EntryInfo =
   getTargetEntryUniqueInfo(CGM.getContext(), D.getBeginLoc(), ParentName);
+
   SmallString<64> EntryFnName;
-  EntryInfo.getTargetRegionEntryFnName(EntryFnName);
+  OffloadEntriesInfoManager.getTargetRegionEntryFnName(EntryFnName, EntryInfo);
 
   const CapturedStmt &CS = *D.getCapturedStmt(OMPD_target);
 

diff  --git a/clang/test/OpenMP/Inputs/multiple_regions.inc 
b/clang/test/OpenMP/Inputs/multiple_regions.inc
new file mode 100644
index 0..f519bee6c5b5e
--- /dev/null
+++ b/clang/test/OpenMP/Inputs/multiple_regions.inc
@@ -0,0 +1,4 @@
+#pragma omp target
+{
+  i = i + VALUE;
+}

diff  --git a/clang/test/OpenMP/multiple_regions_per_line.cpp 
b/clang/test/OpenMP/multiple_regions_per_line.cpp
new file mode 100644
index 0..4332ca052edce
--- /dev/null
+++ b/clang/test/OpenMP/multiple_regions_per_line.cpp
@@ -0,0 +1,73 @@
+//RUN: %clang_cc

[clang] 129904d - [OpenMP][NFC] Use OMPInteropInfo in the OMPDeclareVariantAttr attribute

2022-08-22 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-08-22T10:41:16-07:00
New Revision: 129904d5041ffad13747fd0ad77e44050d6c6aaa

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

LOG: [OpenMP][NFC] Use OMPInteropInfo in the OMPDeclareVariantAttr attribute

In preparation for allowing the prefer_type list in the append_args clause,
use the OMPInteropInfo in the attribute for 'declare variant'.

This requires adding a new Argument kind to the attribute code. This change
adds a specific attribute to pass an array of OMPInteropInfo. It implements
new tablegen needed to handle the interop-type part of the structure. When
prefer_type is added, more work will be needed to dump, instantiate, and
serialize the PreferTypes field in OMPInteropInfo.

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

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/OpenMPKinds.h
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/AttrImpl.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderDecl.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index a3982d7ba0aeb..fd6f50e31bfe1 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -7709,13 +7709,6 @@ class OMPOrderClause final : public OMPClause {
   }
 };
 
-/// Contains 'interop' data for 'append_args' and 'init' clauses.
-struct OMPInteropInfo final {
-  bool IsTarget = false;
-  bool IsTargetSync = false;
-  llvm::SmallVector PreferTypes;
-};
-
 /// This represents the 'init' clause in '#pragma omp ...' directives.
 ///
 /// \code

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 670af57c3def5..e504596a2067c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -221,6 +221,7 @@ class DeclArgument
 //   OMPTraitProperty := {Kind}
 //
 class OMPTraitInfoArgument : Argument;
+class VariadicOMPInteropInfoArgument : Argument;
 
 class TypeArgument : Argument;
 class UnsignedArgument : Argument;
@@ -3827,14 +3828,19 @@ def OMPDeclareVariant : InheritableAttr {
 OMPTraitInfoArgument<"TraitInfos">,
 VariadicExprArgument<"AdjustArgsNothing">,
 VariadicExprArgument<"AdjustArgsNeedDevicePtr">,
-VariadicEnumArgument<"AppendArgs", "InteropType",
- ["target", "targetsync", "target,targetsync"],
- ["Target", "TargetSync", "Target_TargetSync"]>
+VariadicOMPInteropInfoArgument<"AppendArgs">,
   ];
   let AdditionalMembers = [{
 OMPTraitInfo &getTraitInfo() { return *traitInfos; }
 void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
 const;
+static StringRef getInteropTypeString(const OMPInteropInfo *I) {
+  if (I->IsTarget && I->IsTargetSync)
+return "target,targetsync";
+  if (I->IsTarget)
+return "target";
+  return "targetsync";
+}
   }];
 }
 

diff  --git a/clang/include/clang/Basic/OpenMPKinds.h 
b/clang/include/clang/Basic/OpenMPKinds.h
index e95a717f268df..82875aa0fafa6 100644
--- a/clang/include/clang/Basic/OpenMPKinds.h
+++ b/clang/include/clang/Basic/OpenMPKinds.h
@@ -181,6 +181,16 @@ enum OpenMPBindClauseKind {
   OMPC_BIND_unknown
 };
 
+/// Contains 'interop' data for 'append_args' and 'init' clauses.
+class Expr;
+struct OMPInteropInfo final {
+  OMPInteropInfo(bool IsTarget = false, bool IsTargetSync = false)
+  : IsTarget(IsTarget), IsTargetSync(IsTargetSync) {}
+  bool IsTarget;
+  bool IsTargetSync;
+  llvm::SmallVector PreferTypes;
+};
+
 unsigned getOpenMPSimpleClauseType(OpenMPClauseKind Kind, llvm::StringRef Str,
const LangOptions &LangOpts);
 const char *getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned 
Type);

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 3dd92f08bff1f..690a56bf66142 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3180,8 +3180,7 @@ class Parser : public CodeCompletionHandler {
   bool parseOMPContextSelectors(SourceLocation Loc, OMPTraitInfo &TI);
 
   /// Parse an 'append_args' clause for '#pragma omp declare variant'.
-  bool parseOpenMPAppendArgs(
-  SmallVectorImpl &InterOpTypes);
+  bool parseOpenMPAppendArgs(SmallVectorImpl &InteropInfos);
 
   /// Parse a `match` clause for an '#pragma omp declare variant'. Return true
   /// if there was an error.

diff  --git a/clang/includ

[clang] 89167e3 - [OpenMP][NFC] Refactor code for interop parts of 'init' and 'append_args' clauses

2022-08-18 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-08-18T17:13:30-07:00
New Revision: 89167e3c5b008b44f1fa8a222652e7bdc62cfa8a

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

LOG: [OpenMP][NFC] Refactor code for interop parts of 'init' and 'append_args' 
clauses

The 'init' clause allows an interop-modifier of prefer_type(list) and
and interop-types 'target' and 'targetsync'.

The 'append_args' clause uses an append-op that also includes
interop-types ('target' and 'targetsync') and will allow
a prefer_type list in the next OpenMP version.

This change adds a helper struct OMPInteropInfo and uses it in the parsing
of both the 'init' and 'append_args' clauses.

One OMPInteropInfo object represents the info in a single 'init' clause.
Since 'append_args' allows a variable number of interop items it will
require an array of OMPInteropInfo objects once that is supported.

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

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 072519462b9f..a3982d7ba0ae 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -7709,6 +7709,13 @@ class OMPOrderClause final : public OMPClause {
   }
 };
 
+/// Contains 'interop' data for 'append_args' and 'init' clauses.
+struct OMPInteropInfo final {
+  bool IsTarget = false;
+  bool IsTargetSync = false;
+  llvm::SmallVector PreferTypes;
+};
+
 /// This represents the 'init' clause in '#pragma omp ...' directives.
 ///
 /// \code
@@ -7763,16 +7770,14 @@ class OMPInitClause final
   ///
   /// \param C AST context.
   /// \param InteropVar The interop variable.
-  /// \param PrefExprs The list of preference expressions.
-  /// \param IsTarget Uses the 'target' interop-type.
-  /// \param IsTargetSync Uses the 'targetsync' interop-type.
+  /// \param InteropInfo The interop-type and prefer_type list.
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param VarLoc Location of the interop variable.
   /// \param EndLoc Ending location of the clause.
   static OMPInitClause *Create(const ASTContext &C, Expr *InteropVar,
-   ArrayRef PrefExprs, bool IsTarget,
-   bool IsTargetSync, SourceLocation StartLoc,
+   OMPInteropInfo &InteropInfo,
+   SourceLocation StartLoc,
SourceLocation LParenLoc, SourceLocation VarLoc,
SourceLocation EndLoc);
 

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 41bfc9f48ecc..567433f2a889 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3332,6 +3332,9 @@ class Parser : public CodeCompletionHandler {
   /// '(' {  [ '('  ')' ] }+ ')'
   OMPClause *ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind);
 
+  /// Parses the 'interop' parts of the 'append_args' and 'init' clauses.
+  bool ParseOMPInteropInfo(OMPInteropInfo &InteropInfo, OpenMPClauseKind Kind);
+
   /// Parses clause with an interop variable of kind \a Kind.
   ///
   /// \param Kind Kind of current clause.

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 85641f595d41..51e526a62274 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11621,12 +11621,10 @@ class Sema final {
   SourceLocation EndLoc);
 
   /// Called on well-formed 'init' clause.
-  OMPClause *ActOnOpenMPInitClause(Expr *InteropVar, ArrayRef 
PrefExprs,
-   bool IsTarget, bool IsTargetSync,
-   SourceLocation StartLoc,
-   SourceLocation LParenLoc,
-   SourceLocation VarLoc,
-   SourceLocation EndLoc);
+  OMPClause *
+  ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo,
+SourceLocation StartLoc, SourceLocation LParenLoc,
+SourceLocation VarLoc, SourceLocation EndLoc);
 
   /// Called on well-formed 'use' clause.
   OMPClause *ActOnOpenMPUseClause(Expr *InteropVar, SourceLocation StartLoc,

diff  --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index dc2d90e366bc..214ae5bd6be4 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/cla

[clang] dd4c838 - [OpenMP] Allow data members in interop init/use/destroy clauses

2022-08-11 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-08-11T09:39:12-07:00
New Revision: dd4c838da30ad4b6d5dc0f700df0a6629469f719

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

LOG: [OpenMP] Allow data members in interop init/use/destroy clauses

Previously a diagnostic was given if the expression was not strictly a
DeclRef. Now also allow use of data members inside member functions.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/interop_ast_print.cpp
clang/test/OpenMP/interop_irbuilder.cpp
clang/test/OpenMP/interop_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 92217aed89747..e4e7d7b7338a4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10387,6 +10387,9 @@ def err_omp_unexpected_clause_value : Error<
   "expected %0 in OpenMP clause '%1'">;
 def err_omp_expected_var_name_member_expr : Error<
   "expected variable name%select{| or data member of current class}0">;
+def err_omp_expected_var_name_member_expr_with_type : Error<
+  "expected variable%select{| or static data member|, static data member, "
+  "or non-static data member of current class}0 of type '%1'">;
 def err_omp_expected_var_name_member_expr_or_array_item : Error<
   "expected variable name%select{|, data member of current class}0, array 
element or array section">;
 def err_omp_expected_addressable_lvalue_or_array_item : Error<

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 3b1aab6ca0e5f..1d9ec1162bafb 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2718,7 +2718,8 @@ void Sema::EndOpenMPClause() {
 
 static std::pair
 getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc,
-   SourceRange &ERange, bool AllowArraySection = false);
+   SourceRange &ERange, bool AllowArraySection = false,
+   StringRef DiagType = "");
 
 /// Check consistency of the reduction clauses.
 static void checkReductionClauses(Sema &S, DSAStackTy *Stack,
@@ -5279,7 +5280,8 @@ static bool checkIfClauses(Sema &S, OpenMPDirectiveKind 
Kind,
 static std::pair getPrivateItem(Sema &S, Expr *&RefExpr,
SourceLocation &ELoc,
SourceRange &ERange,
-   bool AllowArraySection) {
+   bool AllowArraySection,
+   StringRef DiagType) {
   if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() ||
   RefExpr->containsUnexpandedParameterPack())
 return std::make_pair(nullptr, true);
@@ -5324,6 +5326,12 @@ static std::pair getPrivateItem(Sema 
&S, Expr *&RefExpr,
 if (IsArrayExpr != NoArrayExpr) {
   S.Diag(ELoc, diag::err_omp_expected_base_var_name)
   << IsArrayExpr << ERange;
+} else if (!DiagType.empty()) {
+  unsigned DiagSelect = S.getLangOpts().CPlusPlus
+? (S.getCurrentThisType().isNull() ? 1 : 2)
+: 0;
+  S.Diag(ELoc, diag::err_omp_expected_var_name_member_expr_with_type)
+  << DiagSelect << DiagType << ERange;
 } else {
   S.Diag(ELoc,
  AllowArraySection
@@ -17249,32 +17257,28 @@ StmtResult 
Sema::ActOnOpenMPInteropDirective(ArrayRef Clauses,
   // OpenMP 5.1 [2.15.1, interop Construct, Restrictions]
   // Each interop-var may be specified for at most one action-clause of each
   // interop construct.
-  llvm::SmallPtrSet InteropVars;
-  for (const OMPClause *C : Clauses) {
+  llvm::SmallPtrSet InteropVars;
+  for (OMPClause *C : Clauses) {
 OpenMPClauseKind ClauseKind = C->getClauseKind();
-const DeclRefExpr *DRE = nullptr;
-SourceLocation VarLoc;
+std::pair DeclResult;
+SourceLocation ELoc;
+SourceRange ERange;
 
 if (ClauseKind == OMPC_init) {
-  const auto *IC = cast(C);
-  VarLoc = IC->getVarLoc();
-  DRE = dyn_cast_or_null(IC->getInteropVar());
+  auto *E = cast(C)->getInteropVar();
+  DeclResult = getPrivateItem(*this, E, ELoc, ERange);
 } else if (ClauseKind == OMPC_use) {
-  const auto *UC = cast(C);
-  VarLoc = UC->getVarLoc();
-  DRE = dyn_cast_or_null(UC->getInteropVar());
+  auto *E = cast(C)->getInteropVar();
+  DeclResult = getPrivateItem(*this, E, ELoc, ERange);
 } else if (ClauseKind == OMPC_destroy) {
-  const auto *DC = cast(C);
-  VarLoc = DC->getVarLoc();
-  DRE =

[clang] a35141d - [OpenMP] Add handling cases when filter(tid) appears with default(none)

2022-06-22 Thread Mike Rice via cfe-commits

Author: Fazlay Rabbi
Date: 2022-06-22T17:45:43-07:00
New Revision: a35141d395019c837d16419c6ef57662a6efefc5

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

LOG: [OpenMP] Add handling cases when filter(tid) appears with default(none)

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

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/parallel_masked_ast_print.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 84848c7be858d..e65f5a236a1ff 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -6502,6 +6502,7 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
   case OMPC_uses_allocators:
   case OMPC_affinity:
   case OMPC_bind:
+  case OMPC_filter:
 continue;
   case OMPC_allocator:
   case OMPC_flush:

diff  --git a/clang/test/OpenMP/parallel_masked_ast_print.cpp 
b/clang/test/OpenMP/parallel_masked_ast_print.cpp
index 3532cf61ec25f..ce1552ff5bcf1 100644
--- a/clang/test/OpenMP/parallel_masked_ast_print.cpp
+++ b/clang/test/OpenMP/parallel_masked_ast_print.cpp
@@ -198,6 +198,7 @@ enum Enum { };
 int main (int argc, char **argv) {
   long x;
   int b = argc, c, d, e, f, g;
+  int tid = 0;
   static int a;
   #pragma omp threadprivate(a)
   int arr[10][argc], arr1[2];
@@ -207,8 +208,8 @@ int main (int argc, char **argv) {
 // CHECK-NEXT: #pragma omp parallel masked
   a=2;
 // CHECK-NEXT: a = 2;
-#pragma omp parallel masked default(none), private(argc,b) firstprivate(argv) 
if (parallel: argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(| 
: c, d, arr1[argc]) reduction(* : e, arr[:10][0:argc]) allocate(e)
-// CHECK-NEXT: #pragma omp parallel masked default(none) private(argc,b) 
firstprivate(argv) if(parallel: argc > 0) num_threads(ee) copyin(a) 
proc_bind(spread) reduction(|: c,d,arr1[argc]) reduction(*: e,arr[:10][0:argc]) 
allocate(e)
+#pragma omp parallel masked default(none), private(argc,b) firstprivate(argv) 
if (parallel: argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(| 
: c, d, arr1[argc]) reduction(* : e, arr[:10][0:argc]) allocate(e) filter(tid)
+// CHECK-NEXT: #pragma omp parallel masked default(none) private(argc,b) 
firstprivate(argv) if(parallel: argc > 0) num_threads(ee) copyin(a) 
proc_bind(spread) reduction(|: c,d,arr1[argc]) reduction(*: e,arr[:10][0:argc]) 
allocate(e) filter(tid)
   foo();
 // CHECK-NEXT: foo();
 // CHECK-NEXT: #pragma omp parallel masked allocate(e) if(b) num_threads(c) 
proc_bind(close) reduction(^: e,f) reduction(&&: g,arr[0:argc][:10])



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


[clang] 48d6a6c - [OpenMP][NFC] update status for 'omp_all_memory' directive to 'done'

2022-06-02 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-06-02T17:31:33-07:00
New Revision: 48d6a6c9add90f3684de362907d5f05a0988244a

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

LOG: [OpenMP][NFC] update status for 'omp_all_memory' directive to 'done'

Added: 


Modified: 
clang/docs/OpenMPSupport.rst

Removed: 




diff  --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index 88e3050d3622..8e5c9158b351 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -312,7 +312,7 @@ want to help with the implementation.
 
+--+--+--+---+
 | memory model extension   | seq_cst clause on flush construct 
   | :none:`unclaimed`| 
  |
 
+--+--+--+---+
-| misc extension   | 'omp_all_memory' keyword and use in 'depend' 
clause  | :none:`unclaimed`|
   |
+| misc extension   | 'omp_all_memory' keyword and use in 'depend' 
clause  | :good:`done` | D125828, D126321   
   |
 
+--+--+--+---+
 | misc extension   | error directive   
   | :none:`unclaimed`| 
  |
 
+--+--+--+---+



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


[clang] 0a5cfbf - [OpenMP] Use the align clause value from 'omp allocate' for globals

2022-05-26 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-05-26T09:51:48-07:00
New Revision: 0a5cfbf7b2e82e7980b66428e88b4e28e814d7bb

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

LOG: [OpenMP] Use the align clause value from 'omp allocate' for globals

Refactor the code that handles the align clause of 'omp allocate' so
it can be used with globals as well as local variables.

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

Added: 
clang/test/OpenMP/align_clause_global_codegen.cpp

Modified: 
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 0f16c7f50a003..a16551e83f93b 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2694,3 +2694,22 @@ void CodeGenModule::EmitOMPAllocateDecl(const 
OMPAllocateDecl *D) {
 DummyGV->eraseFromParent();
   }
 }
+
+llvm::Optional
+CodeGenModule::getOMPAllocateAlignment(const VarDecl *VD) {
+  if (const auto *AA = VD->getAttr()) {
+if (Expr *Alignment = AA->getAlignment()) {
+  unsigned UserAlign =
+  Alignment->EvaluateKnownConstInt(getContext()).getExtValue();
+  CharUnits NaturalAlign =
+  getNaturalTypeAlignment(VD->getType().getNonReferenceType());
+
+  // OpenMP5.1 pg 185 lines 7-10
+  //   Each item in the align modifier list must be aligned to the maximum
+  //   of the specified alignment and the type's natural alignment.
+  return CharUnits::fromQuantity(
+  std::max(UserAlign, NaturalAlign.getQuantity()));
+}
+  }
+  return llvm::None;
+}

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 89e26b10dfae5..605d4fe76bc96 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -12185,25 +12185,15 @@ static llvm::Value *getAllocatorVal(CodeGenFunction 
&CGF,
   return AllocVal;
 }
 
-/// Given the allocate directive list item type and align clause value,
-/// return appropriate alignment.
-static llvm::Value *getAlignmentValue(CodeGenFunction &CGF, QualType 
ListItemTy,
-  const Expr *Alignment) {
-  if (!Alignment)
-return nullptr;
+/// Return the alignment from an allocate directive if present.
+static llvm::Value *getAlignmentValue(CodeGenModule &CGM, const VarDecl *VD) {
+  llvm::Optional AllocateAlignment = 
CGM.getOMPAllocateAlignment(VD);
 
-  unsigned UserAlign =
-  Alignment->EvaluateKnownConstInt(CGF.getContext()).getExtValue();
-  CharUnits NaturalAlign = CGF.CGM.getNaturalTypeAlignment(ListItemTy);
+  if (!AllocateAlignment)
+return nullptr;
 
-  // OpenMP5.1 pg 185 lines 7-10
-  //   Each item in the align modifier list must be aligned to the maximum
-  //   of the specified alignment and the type's natural alignment.
-  //
-  // If no alignment specified then use the natural alignment.
-  return llvm::ConstantInt::get(
-  CGF.CGM.SizeTy,
-  std::max(UserAlign, NaturalAlign.getQuantity()));
+  return llvm::ConstantInt::get(CGM.SizeTy,
+AllocateAlignment.getValue().getQuantity());
 }
 
 Address CGOpenMPRuntime::getAddressOfLocalVariable(CodeGenFunction &CGF,
@@ -12244,8 +12234,7 @@ Address 
CGOpenMPRuntime::getAddressOfLocalVariable(CodeGenFunction &CGF,
 const auto *AA = CVD->getAttr();
 const Expr *Allocator = AA->getAllocator();
 llvm::Value *AllocVal = getAllocatorVal(CGF, Allocator);
-llvm::Value *Alignment = getAlignmentValue(
-CGF, VD->getType().getNonReferenceType(), AA->getAlignment());
+llvm::Value *Alignment = getAlignmentValue(CGM, CVD);
 SmallVector Args;
 Args.push_back(ThreadID);
 if (Alignment)

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index a035e5ddd9e6d..b4ae266f89881 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4738,7 +4738,12 @@ void CodeGenModule::EmitGlobalVarDefinition(const 
VarDecl *D,
   GV->setConstant(true);
   }
 
-  GV->setAlignment(getContext().getDeclAlign(D).getAsAlign());
+  CharUnits AlignVal = getContext().getDeclAlign(D);
+  // Check for alignment specifed in an 'omp allocate' directive.
+  if (llvm::Optional AlignValFromAllocate =
+  getOMPAllocateAlignment(D))
+AlignVal = AlignValFromAllocate.getValue();
+  GV->setAlignment(AlignVal.getAsAlign());
 
   // On Darwin, unlike other Itanium C++ ABI platforms, the thread-wrapper
   // function is only defined alongside the variable, not also alongside

diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index a5ec4c8f988d6..0a

[clang] ba3f853 - [OpenMP] Add diagnostic for unterminated 'omp [begin] declare target'

2022-05-25 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-05-25T10:34:07-07:00
New Revision: ba3f85390bde10eab1cbdb68f744b8f5ab31859b

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

LOG: [OpenMP] Add diagnostic for unterminated 'omp [begin] declare target'

Warns when end-of-file is reached without seeing all matching
'omp end declare target' directives. The diagnostic shows the
location of the related begin directive.

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

Added: 
clang/test/OpenMP/Inputs/unterminated_declare_target_include.h

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/declare_target_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2969e24e3baf8..6dfe5af6ecfa3 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11001,6 +11001,9 @@ def err_omp_append_args_with_varargs : Error<
   "'append_args' is not allowed with varargs functions">;
 def err_openmp_vla_in_task_untied : Error<
   "variable length arrays are not supported in OpenMP tasking regions with 
'untied' clause">;
+def warn_omp_unterminated_declare_target : Warning<
+  "expected '#pragma omp end declare target' at end of file to match '#pragma 
omp %0'">,
+  InGroup;
 } // end of OpenMP category
 
 let CategoryName = "Related Result Type Issue" in {

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9cbbeadc3d74b..bd7a809e40474 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10769,6 +10769,10 @@ class Sema final {
   /// encountered.
   void ActOnFinishedOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI);
 
+  /// Report unterminated 'omp declare target' or 'omp begin declare target' at
+  /// the end of a compilation unit.
+  void DiagnoseUnterminatedOpenMPDeclareTarget();
+
   /// Searches for the provided declaration name for OpenMP declare target
   /// directive.
   NamedDecl *lookupOpenMPDeclareTargetName(Scope *CurScope,

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index ce104f377730c..ad2cb62a18f0c 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1157,6 +1157,7 @@ void Sema::ActOnEndOfTranslationUnit() {
 
   DiagnoseUnterminatedPragmaAlignPack();
   DiagnoseUnterminatedPragmaAttribute();
+  DiagnoseUnterminatedOpenMPDeclareTarget();
 
   // All delayed member exception specs should be checked or we end up 
accepting
   // incompatible declarations.

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 1fdb7df1feea4..fdb7658f77bda 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -22101,6 +22101,14 @@ void Sema::ActOnFinishedOpenMPDeclareTargetContext(
 ActOnOpenMPDeclareTargetName(It.first, It.second.Loc, It.second.MT, DTCI);
 }
 
+void Sema::DiagnoseUnterminatedOpenMPDeclareTarget() {
+  if (DeclareTargetNesting.empty())
+return;
+  DeclareTargetContextInfo &DTCI = DeclareTargetNesting.back();
+  Diag(DTCI.Loc, diag::warn_omp_unterminated_declare_target)
+  << getOpenMPDirectiveName(DTCI.Kind);
+}
+
 NamedDecl *Sema::lookupOpenMPDeclareTargetName(Scope *CurScope,
CXXScopeSpec &ScopeSpec,
const DeclarationNameInfo &Id) {

diff  --git a/clang/test/OpenMP/Inputs/unterminated_declare_target_include.h 
b/clang/test/OpenMP/Inputs/unterminated_declare_target_include.h
new file mode 100644
index 0..ddb60d562de15
--- /dev/null
+++ b/clang/test/OpenMP/Inputs/unterminated_declare_target_include.h
@@ -0,0 +1,3 @@
+// expected-warning@+1 {{expected '#pragma omp end declare target' at end of 
file to match '#pragma omp declare target'}}
+#pragma omp declare target
+void zxy();

diff  --git a/clang/test/OpenMP/declare_target_messages.cpp 
b/clang/test/OpenMP/declare_target_messages.cpp
index 31185881e192b..7e7cc60e75e35 100644
--- a/clang/test/OpenMP/declare_target_messages.cpp
+++ b/clang/test/OpenMP/declare_target_messages.cpp
@@ -6,6 +6,9 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 
-verify=expected,omp5,host5 -fopenmp-simd -fopenmp-is-device 
-fopenmp-targets=x86_64-apple-macos10.7.0 -fnoopenmp-use-tls -ferror-limit 100 
-o - %s
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp45 
-fopenmp-version=45 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 
-fopenmp -fopenmp-version=51 -fnoopenmp-use-tls -ferror-limi

[clang] 9ba9371 - [OpenMP] Add parsing/sema support for omp_all_memory reserved locator

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

Author: Mike Rice
Date: 2022-05-24T10:28:59-07:00
New Revision: 9ba937112fa6d4076e4a98b587a334786b6c0d9c

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

LOG: [OpenMP] Add parsing/sema support for omp_all_memory reserved locator

Adds support for the reserved locator 'omp_all_memory' for use
in depend clauses with 'out' or 'inout' dependence-types.

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

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/OpenMPKinds.def
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/task_ast_print.cpp
clang/test/OpenMP/task_depend_messages.cpp

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 3103f61d4248d..a745df1143468 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -4746,14 +4746,24 @@ class OMPDependClause final
   friend OMPVarListClause;
   friend TrailingObjects;
 
-  /// Dependency type (one of in, out, inout).
-  OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
+public:
+  struct DependDataTy final {
+/// Dependency type (one of in, out, inout).
+OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
 
-  /// Dependency type location.
-  SourceLocation DepLoc;
+/// Dependency type location.
+SourceLocation DepLoc;
 
-  /// Colon location.
-  SourceLocation ColonLoc;
+/// Colon location.
+SourceLocation ColonLoc;
+
+/// Location of 'omp_all_memory'.
+SourceLocation OmpAllMemoryLoc;
+  };
+
+private:
+  /// Dependency type and source locations.
+  DependDataTy Data;
 
   /// Number of loops, associated with the depend clause.
   unsigned NumLoops = 0;
@@ -4784,13 +4794,16 @@ class OMPDependClause final
 NumLoops(NumLoops) {}
 
   /// Set dependency kind.
-  void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
+  void setDependencyKind(OpenMPDependClauseKind K) { Data.DepKind = K; }
 
   /// Set dependency kind and its location.
-  void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
+  void setDependencyLoc(SourceLocation Loc) { Data.DepLoc = Loc; }
 
   /// Set colon location.
-  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
+  void setColonLoc(SourceLocation Loc) { Data.ColonLoc = Loc; }
+
+  /// Set the 'omp_all_memory' location.
+  void setOmpAllMemoryLoc(SourceLocation Loc) { Data.OmpAllMemoryLoc = Loc; }
 
   /// Sets optional dependency modifier.
   void setModifier(Expr *DepModifier);
@@ -4802,18 +4815,15 @@ class OMPDependClause final
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
-  /// \param DepKind Dependency type.
-  /// \param DepLoc Location of the dependency type.
-  /// \param ColonLoc Colon location.
+  /// \param Data Dependency type and source locations.
   /// \param VL List of references to the variables.
   /// \param NumLoops Number of loops that is associated with this depend
   /// clause.
   static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
  SourceLocation LParenLoc,
- SourceLocation EndLoc, Expr *DepModifier,
- OpenMPDependClauseKind DepKind,
- SourceLocation DepLoc, SourceLocation 
ColonLoc,
- ArrayRef VL, unsigned NumLoops);
+ SourceLocation EndLoc, DependDataTy Data,
+ Expr *DepModifier, ArrayRef VL,
+ unsigned NumLoops);
 
   /// Creates an empty clause with \a N variables.
   ///
@@ -4825,7 +4835,16 @@ class OMPDependClause final
   unsigned NumLoops);
 
   /// Get dependency type.
-  OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
+  OpenMPDependClauseKind getDependencyKind() const { return Data.DepKind; }
+
+  /// Get dependency type location.
+  SourceLocation getDependencyLoc() const { return Data.DepLoc; }
+
+  /// Get colon location.
+  SourceLocation getColonLoc() const { return Data.ColonLoc; }
+
+  /// Get 'omp_all_memory' location.
+  SourceLocation getOmpAllMemoryLoc() const { return Data.OmpAllMemoryLoc; }
 
   /// Return optional depend modifier.
   Expr *getMo

[clang] 0d67c8a - [OpenMP] Fix declare simd use on in-class member template function

2022-05-13 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-05-13T08:24:55-07:00
New Revision: 0d67c8a51d61cb0fac91f265a424767f072c7d5c

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

LOG: [OpenMP] Fix declare simd use on in-class member template function

Return the Decl when parsing the template member declaration so the
'omp declare simd' pragma can be applied to it. Previously a nullptr
was returned causing an error applying the pragma.

Fixes #52700.

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

Added: 


Modified: 
clang/lib/Parse/ParseTemplate.cpp
clang/test/OpenMP/declare_simd_codegen.cpp
clang/test/OpenMP/declare_simd_messages.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index 5687882251a05..e66329e3bfc7e 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -200,9 +200,12 @@ Decl *Parser::ParseSingleDeclarationAfterTemplate(
 
   if (Context == DeclaratorContext::Member) {
 // We are parsing a member template.
-ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo,
-   &DiagsFromTParams);
-return nullptr;
+DeclGroupPtrTy D = ParseCXXClassMemberDeclaration(
+AS, AccessAttrs, TemplateInfo, &DiagsFromTParams);
+
+if (!D || !D.get().isSingleDecl())
+  return nullptr;
+return D.get().getSingleDecl();
   }
 
   ParsedAttributes prefixAttrs(AttrFactory);

diff  --git a/clang/test/OpenMP/declare_simd_codegen.cpp 
b/clang/test/OpenMP/declare_simd_codegen.cpp
index 573dbdbfd69e9..d7bd798798294 100644
--- a/clang/test/OpenMP/declare_simd_codegen.cpp
+++ b/clang/test/OpenMP/declare_simd_codegen.cpp
@@ -97,6 +97,28 @@ void f(int (&g)[]) {
   foo(c, p);
 }
 
+struct A {
+  #pragma omp declare simd linear(a:X)
+  template
+  T infunc(T a) { return a * 2; }
+
+  template
+  U outfunc(U *a);
+};
+
+#pragma omp declare simd linear(a:Y)
+template
+U A::outfunc(U *a) { return *a * 2; }
+
+void test_member_template()
+{
+  struct A a;
+  int i = 32;
+  float f = 1.0;
+  int t = a.infunc<8, int>(i);
+  float u = a.outfunc<4, float>(&f);
+}
+
 #pragma omp declare simd
 #pragma omp declare simd notinbranch aligned(a : 32)
 int bar(VV v, float *a) { return 0; }
@@ -173,6 +195,8 @@ double Six(int a, float *b, int &c, int *&d, char e, char 
*f, short g) {
 // CHECK-DAG: define {{.+}}@_ZN3TVVILi16EfE6taddpfEPfRS1_(
 // CHECK-DAG: define {{.+}}@_ZN3TVVILi16EfE4taddEi(
 // CHECK-DAG: define {{.+}}@_Z3fooILi64EEvRAT__iRPf(
+// CHECK-DAG: define {{.+}}@_ZN1A6infuncILi8EiEET0_S1_
+// CHECK-DAG: define {{.+}}@_ZN1A7outfuncILi4EfEET0_PS1_
 // CHECK-DAG: define {{.+}}@_Z3bar2VVPf(
 // CHECK-DAG: define {{.+}}@_Z3baz2VVPi(
 // CHECK-DAG: define {{.+}}@_Z3bay2VVRPd(
@@ -310,6 +334,24 @@ double Six(int a, float *b, int &c, int *&d, char e, char 
*f, short g) {
 // CHECK-DAG: "_ZGVeM64va128U64__Z3fooILi64EEvRAT__iRPf"
 // CHECK-DAG: "_ZGVeN64va128U64__Z3fooILi64EEvRAT__iRPf"
 
+// CHECK-DAG: "_ZGVbM4vl8__ZN1A6infuncILi8EiEET0_S1_"
+// CHECK-DAG: "_ZGVbN4vl8__ZN1A6infuncILi8EiEET0_S1_"
+// CHECK-DAG: "_ZGVcM8vl8__ZN1A6infuncILi8EiEET0_S1_"
+// CHECK-DAG: "_ZGVcN8vl8__ZN1A6infuncILi8EiEET0_S1_"
+// CHECK-DAG: "_ZGVdM8vl8__ZN1A6infuncILi8EiEET0_S1_"
+// CHECK-DAG: "_ZGVdN8vl8__ZN1A6infuncILi8EiEET0_S1_"
+// CHECK-DAG: "_ZGVeM16vl8__ZN1A6infuncILi8EiEET0_S1_"
+// CHECK-DAG: "_ZGVeN16vl8__ZN1A6infuncILi8EiEET0_S1_"
+
+// CHECK-DAG: "_ZGVbM4vl16__ZN1A7outfuncILi4EfEET0_PS1_"
+// CHECK-DAG: "_ZGVbN4vl16__ZN1A7outfuncILi4EfEET0_PS1_"
+// CHECK-DAG: "_ZGVcM8vl16__ZN1A7outfuncILi4EfEET0_PS1_"
+// CHECK-DAG: "_ZGVcN8vl16__ZN1A7outfuncILi4EfEET0_PS1_"
+// CHECK-DAG: "_ZGVdM8vl16__ZN1A7outfuncILi4EfEET0_PS1_"
+// CHECK-DAG: "_ZGVdN8vl16__ZN1A7outfuncILi4EfEET0_PS1_"
+// CHECK-DAG: "_ZGVeM16vl16__ZN1A7outfuncILi4EfEET0_PS1_"
+// CHECK-DAG: "_ZGVeN16vl16__ZN1A7outfuncILi4EfEET0_PS1_"
+
 // CHECK-DAG: "_ZGVbM4vv__Z3bar2VVPf"
 // CHECK-DAG: "_ZGVbN4vv__Z3bar2VVPf"
 // CHECK-DAG: "_ZGVcM8vv__Z3bar2VVPf"

diff  --git a/clang/test/OpenMP/declare_simd_messages.cpp 
b/clang/test/OpenMP/declare_simd_messages.cpp
index a3188de8bd64f..60515965ce3d0 100644
--- a/clang/test/OpenMP/declare_simd_messages.cpp
+++ b/clang/test/OpenMP/declare_simd_messages.cpp
@@ -32,6 +32,13 @@ int main();
 #pragma init_seg(compiler)
 int main();
 
+struct A {
+// expected-error@+1 {{function declaration is expected after 'declare simd' 
directive}}
+  #pragma omp declare simd
+  template
+  T infunc1(T a), infunc2(T a);
+};
+
 // expected-error@+1 {{single declaration is expected after 'declare simd' 
directive}}
 #pragma omp declare simd
 // expected-note@+1 {{declared here}}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://l

[clang] 772b0c4 - [OpenMP] Fix mangling for linear parameters with negative stride

2022-05-11 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-05-11T14:02:09-07:00
New Revision: 772b0c44a4296a34cbc072c2a7cf294410d07a1a

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

LOG: [OpenMP] Fix mangling for linear parameters with negative stride

The 'n' character is used in place of '-' in the mangled name.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 52f6ca4cfb3d0..f197c331e6cfc 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11506,7 +11506,9 @@ static std::string 
mangleVectorParameters(ArrayRef ParamAttrs) {
  ParamAttr.Kind == LinearUVal || ParamAttr.Kind == LinearVal) {
   // Don't print the step value if it is not present or if it is
   // equal to 1.
-  if (ParamAttr.StrideOrArg != 1)
+  if (ParamAttr.StrideOrArg < 0)
+Out << 'n' << -ParamAttr.StrideOrArg;
+  else if (ParamAttr.StrideOrArg != 1)
 Out << ParamAttr.StrideOrArg;
 }
 

diff  --git a/clang/test/OpenMP/declare_simd_codegen.cpp 
b/clang/test/OpenMP/declare_simd_codegen.cpp
index fa0be2acc192f..573dbdbfd69e9 100644
--- a/clang/test/OpenMP/declare_simd_codegen.cpp
+++ b/clang/test/OpenMP/declare_simd_codegen.cpp
@@ -155,6 +155,14 @@ double Five(int a, short &b, short &c, short &d, short &e, 
short &f, short &g,
   return a + int(b);
 }
 
+// Test negative strides
+#pragma omp declare simd simdlen(4) linear(a:-2) linear(b:-8) \
+linear(uval(c):-4) linear(ref(d):-16) \
+linear(e:-1) linear(f:-1) linear(g:0)
+double Six(int a, float *b, int &c, int *&d, char e, char *f, short g) {
+ return a + int(*b) + c + *d + e + *f + g;
+}
+
 // CHECK-DAG: define {{.+}}@_Z5add_1Pf(
 // CHECK-DAG: define {{.+}}@_Z1hIiEvPT_S1_S1_S1_(
 // CHECK-DAG: define {{.+}}@_Z1hIfEvPT_S1_S1_S1_(
@@ -178,6 +186,7 @@ double Five(int a, short &b, short &c, short &d, short &e, 
short &f, short &g,
 // CHECK-DAG: define {{.+}}@_Z5ThreeRiS_
 // CHECK-DAG: define {{.+}}@_Z4FourRiS_
 // CHECK-DAG: define {{.+}}@_Z4FiveiRsS_S_S_S_S_S_S_
+// CHECK-DAG: define {{.+}}@_Z3SixiPfRiRPicPcs
 
 // CHECK-DAG: "_ZGVbM4l32__Z5add_1Pf"
 // CHECK-DAG: "_ZGVbN4l32__Z5add_1Pf"
@@ -399,6 +408,8 @@ double Five(int a, short &b, short &c, short &d, short &e, 
short &f, short &g,
 // CHECK-DAG: "_ZGVbN4R8R4__Z4FourRiS_"
 // CHECK-DAG: "_ZGVbM4uL2Ls0L4Ls0U8Us0R32Rs0__Z4FiveiRsS_S_S_S_S_S_S_"
 // CHECK-DAG: "_ZGVbN4uL2Ls0L4Ls0U8Us0R32Rs0__Z4FiveiRsS_S_S_S_S_S_S_"
+// CHECK-DAG: "_ZGVbM4ln2ln32Un4Rn128ln1ln1l0__Z3SixiPfRiRPicPcs"
+// CHECK-DAG: "_ZGVbN4ln2ln32Un4Rn128ln1ln1l0__Z3SixiPfRiRPicPcs"
 
 // CHECK-NOT: "_ZGV{{.+}}__Z1fRA_i
 



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


[clang] 0dbaef6 - [OpenMP] Fix mangling for linear modifiers with variable stride

2022-05-10 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-05-10T14:12:44-07:00
New Revision: 0dbaef61b56f0ef0ab0cf38ea92ffc1f35bee3ff

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

LOG: [OpenMP] Fix mangling for linear modifiers with variable stride

This adds support for variable stride with the val, uval, and ref linear
modifiers.  Previously only the no modifer type ls was supported.

  val  -> Ls
  uval -> Us
  ref  -> Rs

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

Added: 


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

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index d938bda157f9d..52f6ca4cfb3d0 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11405,7 +11405,6 @@ void CGOpenMPRuntime::emitTargetDataStandAloneCall(
 namespace {
   /// Kind of parameter in a function with 'declare simd' directive.
 enum ParamKindTy {
-  LinearWithVarStride,
   Linear,
   LinearRef,
   LinearUVal,
@@ -11418,6 +11417,7 @@ struct ParamAttrTy {
   ParamKindTy Kind = Vector;
   llvm::APSInt StrideOrArg;
   llvm::APSInt Alignment;
+  bool HasVarStride = false;
 };
 } // namespace
 
@@ -11481,9 +11481,6 @@ static std::string 
mangleVectorParameters(ArrayRef ParamAttrs) {
   llvm::raw_svector_ostream Out(Buffer);
   for (const auto &ParamAttr : ParamAttrs) {
 switch (ParamAttr.Kind) {
-case LinearWithVarStride:
-  Out << "ls" << ParamAttr.StrideOrArg;
-  break;
 case Linear:
   Out << 'l';
   break;
@@ -11503,8 +11500,10 @@ static std::string 
mangleVectorParameters(ArrayRef ParamAttrs) {
   Out << 'v';
   break;
 }
-if (ParamAttr.Kind == Linear || ParamAttr.Kind == LinearRef ||
-ParamAttr.Kind == LinearUVal || ParamAttr.Kind == LinearVal) {
+if (ParamAttr.HasVarStride)
+  Out << "s" << ParamAttr.StrideOrArg;
+else if (ParamAttr.Kind == Linear || ParamAttr.Kind == LinearRef ||
+ ParamAttr.Kind == LinearUVal || ParamAttr.Kind == LinearVal) {
   // Don't print the step value if it is not present or if it is
   // equal to 1.
   if (ParamAttr.StrideOrArg != 1)
@@ -11579,11 +11578,7 @@ emitX86DeclareSimdFunction(const FunctionDecl *FD, 
llvm::Function *Fn,
 // available at
 // 
https://developer.arm.com/products/software-development-tools/hpc/arm-compiler-for-hpc/vector-function-abi.
 
-/// Maps To Vector (MTV), as defined in 3.1.1 of the AAVFABI.
-///
-/// TODO: Need to implement the behavior for reference marked with a
-/// var or no linear modifiers (1.b in the section). For this, we
-/// need to extend ParamKindTy to support the linear modifiers.
+/// Maps To Vector (MTV), as defined in 4.1.1 of the AAVFABI (2021Q1).
 static bool getAArch64MTV(QualType QT, ParamKindTy Kind) {
   QT = QT.getCanonicalType();
 
@@ -11593,12 +11588,11 @@ static bool getAArch64MTV(QualType QT, ParamKindTy 
Kind) {
   if (Kind == ParamKindTy::Uniform)
 return false;
 
-  if (Kind == ParamKindTy::Linear)
+  if (Kind == ParamKindTy::LinearUVal || ParamKindTy::LinearRef)
 return false;
 
-  // TODO: Handle linear references with modifiers
-
-  if (Kind == ParamKindTy::LinearWithVarStride)
+  if ((Kind == ParamKindTy::Linear || Kind == ParamKindTy::LinearVal) &&
+  !QT->isReferenceType())
 return false;
 
   return true;
@@ -11949,7 +11943,7 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
 cast((*SI)->IgnoreParenImpCasts())) {
   if (const auto *StridePVD =
   dyn_cast(DRE->getDecl())) {
-ParamAttr.Kind = LinearWithVarStride;
+ParamAttr.HasVarStride = true;
 auto It = ParamPositions.find(StridePVD->getCanonicalDecl());
 assert(It != ParamPositions.end() &&
"Function parameter not found");
@@ -11963,7 +11957,8 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
 // If we are using a linear clause on a pointer, we need to
 // rescale the value of linear_step with the byte size of the
 // pointee type.
-if (ParamAttr.Kind == Linear || ParamAttr.Kind == LinearRef)
+if (!ParamAttr.HasVarStride &&
+(ParamAttr.Kind == Linear || ParamAttr.Kind == LinearRef))
   ParamAttr.StrideOrArg = ParamAttr.StrideOrArg * PtrRescalingFactor;
 ++SI;
 ++MI;

diff  --git a/clang/test/OpenMP/declare_simd_codegen.cpp 
b/clang/test/OpenMP/declare_simd_codegen.cpp
index 5a5df239f870a..fa0be2acc192f 100644
--- a/clang/test/OpenMP/declare_simd_codegen.cpp
+++ b/clang/test/OpenMP/declare_simd_codegen.cpp
@@ -144,6 +144,17 @@ double Four(int& a, i

[clang] 1a02519 - [OpenMP] Add mangling support for linear modifiers (ref,uval,val)

2022-05-10 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-05-10T09:56:55-07:00
New Revision: 1a02519bc504a12a12ba875db29c9e5901ed9bef

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

LOG: [OpenMP] Add mangling support for linear modifiers (ref,uval,val)

Add mangling for linear parameters specified with ref, uval, and val
for 'omp declare simd' vector functions.

Add missing stride for linear this parameters.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index aa8aa7d0bd5f8..d938bda157f9d 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11404,13 +11404,21 @@ void CGOpenMPRuntime::emitTargetDataStandAloneCall(
 
 namespace {
   /// Kind of parameter in a function with 'declare simd' directive.
-  enum ParamKindTy { LinearWithVarStride, Linear, Uniform, Vector };
-  /// Attribute set of the parameter.
-  struct ParamAttrTy {
-ParamKindTy Kind = Vector;
-llvm::APSInt StrideOrArg;
-llvm::APSInt Alignment;
-  };
+enum ParamKindTy {
+  LinearWithVarStride,
+  Linear,
+  LinearRef,
+  LinearUVal,
+  LinearVal,
+  Uniform,
+  Vector,
+};
+/// Attribute set of the parameter.
+struct ParamAttrTy {
+  ParamKindTy Kind = Vector;
+  llvm::APSInt StrideOrArg;
+  llvm::APSInt Alignment;
+};
 } // namespace
 
 static unsigned evaluateCDTSize(const FunctionDecl *FD,
@@ -11465,6 +11473,51 @@ static unsigned evaluateCDTSize(const FunctionDecl *FD,
   return C.getTypeSize(CDT);
 }
 
+/// Mangle the parameter part of the vector function name according to
+/// their OpenMP classification. The mangling function is defined in
+/// section 4.5 of the AAVFABI(2021Q1).
+static std::string mangleVectorParameters(ArrayRef ParamAttrs) {
+  SmallString<256> Buffer;
+  llvm::raw_svector_ostream Out(Buffer);
+  for (const auto &ParamAttr : ParamAttrs) {
+switch (ParamAttr.Kind) {
+case LinearWithVarStride:
+  Out << "ls" << ParamAttr.StrideOrArg;
+  break;
+case Linear:
+  Out << 'l';
+  break;
+case LinearRef:
+  Out << 'R';
+  break;
+case LinearUVal:
+  Out << 'U';
+  break;
+case LinearVal:
+  Out << 'L';
+  break;
+case Uniform:
+  Out << 'u';
+  break;
+case Vector:
+  Out << 'v';
+  break;
+}
+if (ParamAttr.Kind == Linear || ParamAttr.Kind == LinearRef ||
+ParamAttr.Kind == LinearUVal || ParamAttr.Kind == LinearVal) {
+  // Don't print the step value if it is not present or if it is
+  // equal to 1.
+  if (ParamAttr.StrideOrArg != 1)
+Out << ParamAttr.StrideOrArg;
+}
+
+if (!!ParamAttr.Alignment)
+  Out << 'a' << ParamAttr.Alignment;
+  }
+
+  return std::string(Out.str());
+}
+
 static void
 emitX86DeclareSimdFunction(const FunctionDecl *FD, llvm::Function *Fn,
const llvm::APSInt &VLENVal,
@@ -11513,26 +11566,7 @@ emitX86DeclareSimdFunction(const FunctionDecl *FD, 
llvm::Function *Fn,
   } else {
 Out << VLENVal;
   }
-  for (const ParamAttrTy &ParamAttr : ParamAttrs) {
-switch (ParamAttr.Kind){
-case LinearWithVarStride:
-  Out << 's' << ParamAttr.StrideOrArg;
-  break;
-case Linear:
-  Out << 'l';
-  if (ParamAttr.StrideOrArg != 1)
-Out << ParamAttr.StrideOrArg;
-  break;
-case Uniform:
-  Out << 'u';
-  break;
-case Vector:
-  Out << 'v';
-  break;
-}
-if (!!ParamAttr.Alignment)
-  Out << 'a' << ParamAttr.Alignment;
-  }
+  Out << mangleVectorParameters(ParamAttrs);
   Out << '_' << Fn->getName();
   Fn->addFnAttr(Out.str());
 }
@@ -11645,39 +11679,6 @@ getNDSWDS(const FunctionDecl *FD, 
ArrayRef ParamAttrs) {
  OutputBecomesInput);
 }
 
-/// Mangle the parameter part of the vector function name according to
-/// their OpenMP classification. The mangling function is defined in
-/// section 3.5 of the AAVFABI.
-static std::string mangleVectorParameters(ArrayRef ParamAttrs) {
-  SmallString<256> Buffer;
-  llvm::raw_svector_ostream Out(Buffer);
-  for (const auto &ParamAttr : ParamAttrs) {
-switch (ParamAttr.Kind) {
-case LinearWithVarStride:
-  Out << "ls" << ParamAttr.StrideOrArg;
-  break;
-case Linear:
-  Out << 'l';
-  // Don't print the step value if it is not present or if it is
-  // equal to 1.
-  if (ParamAttr.StrideOrArg != 1)
-Out << ParamAttr.StrideOrArg;
-  break;
-case Uniform:
-  Out << 'u';
-  break;

[clang] 37471cf - [clang][OpenMP] Local variable alignment incorrect with align clause

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

Author: David Pagan
Date: 2022-05-03T13:10:01-07:00
New Revision: 37471cf2c3fd02fac0b0dc6e513cfe6098f37764

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

LOG: [clang][OpenMP] Local variable alignment incorrect with align clause

If alignment specified with align clause is less than natural alignment for
list item type, the alignment should be set to the natural alignment.

See OMP5.1 specification, page 185, lines 7-10

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/align_clause_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 391245e3b54bb..aa8aa7d0bd5f8 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -12153,6 +12153,27 @@ static llvm::Value *getAllocatorVal(CodeGenFunction 
&CGF,
   return AllocVal;
 }
 
+/// Given the allocate directive list item type and align clause value,
+/// return appropriate alignment.
+static llvm::Value *getAlignmentValue(CodeGenFunction &CGF, QualType 
ListItemTy,
+  const Expr *Alignment) {
+  if (!Alignment)
+return nullptr;
+
+  unsigned UserAlign =
+  Alignment->EvaluateKnownConstInt(CGF.getContext()).getExtValue();
+  CharUnits NaturalAlign = CGF.CGM.getNaturalTypeAlignment(ListItemTy);
+
+  // OpenMP5.1 pg 185 lines 7-10
+  //   Each item in the align modifier list must be aligned to the maximum
+  //   of the specified alignment and the type's natural alignment.
+  //
+  // If no alignment specified then use the natural alignment.
+  return llvm::ConstantInt::get(
+  CGF.CGM.SizeTy,
+  std::max(UserAlign, NaturalAlign.getQuantity()));
+}
+
 Address CGOpenMPRuntime::getAddressOfLocalVariable(CodeGenFunction &CGF,
const VarDecl *VD) {
   if (!VD)
@@ -12191,11 +12212,8 @@ Address 
CGOpenMPRuntime::getAddressOfLocalVariable(CodeGenFunction &CGF,
 const auto *AA = CVD->getAttr();
 const Expr *Allocator = AA->getAllocator();
 llvm::Value *AllocVal = getAllocatorVal(CGF, Allocator);
-llvm::Value *Alignment =
-AA->getAlignment()
-? CGF.Builder.CreateIntCast(CGF.EmitScalarExpr(AA->getAlignment()),
-CGM.SizeTy, /*isSigned=*/false)
-: nullptr;
+llvm::Value *Alignment = getAlignmentValue(
+CGF, VD->getType().getNonReferenceType(), AA->getAlignment());
 SmallVector Args;
 Args.push_back(ThreadID);
 if (Alignment)

diff  --git a/clang/test/OpenMP/align_clause_codegen.cpp 
b/clang/test/OpenMP/align_clause_codegen.cpp
index 5ced4652aba10..b8c31d1ca9b66 100644
--- a/clang/test/OpenMP/align_clause_codegen.cpp
+++ b/clang/test/OpenMP/align_clause_codegen.cpp
@@ -85,9 +85,9 @@ int template_test() {
 // CHECK-32-NEXT:  entry:
 // CHECK-32-NEXT:[[MYALLOC:%.*]] = alloca i32, align 4
 // CHECK-32-NEXT:[[TMP0:%.*]] = call i32 
@__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]])
-// CHECK-32-NEXT:[[DOTFOO0__VOID_ADDR:%.*]] = call i8* 
@__kmpc_aligned_alloc(i32 [[TMP0]], i32 1, i32 20, i8* null)
+// CHECK-32-NEXT:[[DOTFOO0__VOID_ADDR:%.*]] = call i8* 
@__kmpc_aligned_alloc(i32 [[TMP0]], i32 4, i32 20, i8* null)
 // CHECK-32-NEXT:[[DOTFOO0__ADDR:%.*]] = bitcast i8* 
[[DOTFOO0__VOID_ADDR]] to [5 x i32]*
-// CHECK-32-NEXT:[[DOTFOO1__VOID_ADDR:%.*]] = call i8* 
@__kmpc_aligned_alloc(i32 [[TMP0]], i32 2, i32 40, i8* inttoptr (i32 7 to i8*))
+// CHECK-32-NEXT:[[DOTFOO1__VOID_ADDR:%.*]] = call i8* 
@__kmpc_aligned_alloc(i32 [[TMP0]], i32 4, i32 40, i8* inttoptr (i32 7 to i8*))
 // CHECK-32-NEXT:[[DOTFOO1__ADDR:%.*]] = bitcast i8* 
[[DOTFOO1__VOID_ADDR]] to [10 x i32]*
 // CHECK-32-NEXT:[[DOTFOO2__VOID_ADDR:%.*]] = call i8* 
@__kmpc_aligned_alloc(i32 [[TMP0]], i32 4, i32 80, i8* inttoptr (i32 6 to i8*))
 // CHECK-32-NEXT:[[DOTFOO2__ADDR:%.*]] = bitcast i8* 
[[DOTFOO2__VOID_ADDR]] to [20 x i32]*
@@ -114,15 +114,15 @@ int template_test() {
 // CHECK-32-NEXT:call void @__kmpc_free(i32 [[TMP0]], i8* [[TMP2]], i8* 
inttoptr (i32 8 to i8*))
 // CHECK-32-NEXT:[[TMP3:%.*]] = load i32, i32* [[MYALLOC]], align 4
 // CHECK-32-NEXT:[[CONV:%.*]] = inttoptr i32 [[TMP3]] to i8*
-// CHECK-32-NEXT:[[DOTBAR1__VOID_ADDR:%.*]] = call i8* 
@__kmpc_aligned_alloc(i32 [[TMP0]], i32 2, i32 4, i8* [[CONV]])
+// CHECK-32-NEXT:[[DOTBAR1__VOID_ADDR:%.*]] = call i8* 
@__kmpc_aligned_alloc(i32 [[TMP0]], i32 4, i32 4, i8* [[CONV]])
 // CHECK-32-NEXT:[[DOTBAR1__ADDR:%.*]] = bitcast i8* 
[[DOTBAR1__VOID_ADDR]] to i32*
 // CHECK-32-NEXT:[[TMP4:%.*]] = load i32, i32* [[MYALLOC]], align 4
 // CHECK-32-NEXT:

[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,

  1   2   >