[clang] [clangd] Fix C++20 modules crash (PR #81919)

2024-02-16 Thread via cfe-commits

https://github.com/CLRN updated https://github.com/llvm/llvm-project/pull/81919

>From dae725e0c48837a18aa9b90945de0b86a33890ff Mon Sep 17 00:00:00 2001
From: clrn 
Date: Thu, 15 Feb 2024 20:41:34 +
Subject: [PATCH] [clangd] Fix C++20 modules crash

This fix partially reverts 
https://github.com/llvm/llvm-project/commit/a0b6747804e46665ecfd00295b60432bfe1775b6.

The serialization part is restored to the state prior to the mentioned commit 
as it causing issue with reading back Decl.
ODR checks logic is kept in place.

Close https://github.com/llvm/llvm-project/issues/80570.
---
 clang/lib/Serialization/ASTReaderDecl.cpp | 21 +++--
 clang/lib/Serialization/ASTWriter.cpp |  9 +++--
 clang/lib/Serialization/ASTWriterDecl.cpp |  8 ++--
 3 files changed, 12 insertions(+), 26 deletions(-)

diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index ffba04f28782ea..4e58301a6b8eef 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -804,10 +804,8 @@ void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
   ED->setScopedUsingClassTag(EnumDeclBits.getNextBit());
   ED->setFixed(EnumDeclBits.getNextBit());
 
-  if (!shouldSkipCheckingODR(ED)) {
-ED->setHasODRHash(true);
-ED->ODRHash = Record.readInt();
-  }
+  ED->setHasODRHash(true);
+  ED->ODRHash = Record.readInt();
 
   // If this is a definition subject to the ODR, and we already have a
   // definition, merge this one into it.
@@ -1102,10 +1100,8 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
   if (FD->isExplicitlyDefaulted())
 FD->setDefaultLoc(readSourceLocation());
 
-  if (!shouldSkipCheckingODR(FD)) {
-FD->ODRHash = Record.readInt();
-FD->setHasODRHash(true);
-  }
+  FD->ODRHash = Record.readInt();
+  FD->setHasODRHash(true);
 
   if (FD->isDefaulted()) {
 if (unsigned NumLookups = Record.readInt()) {
@@ -1981,12 +1977,9 @@ void ASTDeclReader::ReadCXXDefinitionData(
 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
 #undef FIELD
 
-  // We only perform ODR checks for decls not in GMF.
-  if (!shouldSkipCheckingODR(D)) {
-// Note: the caller has deserialized the IsLambda bit already.
-Data.ODRHash = Record.readInt();
-Data.HasODRHash = true;
-  }
+  // Note: the caller has deserialized the IsLambda bit already.
+  Data.ODRHash = Record.readInt();
+  Data.HasODRHash = true;
 
   if (Record.readInt()) {
 Reader.DefinitionSource[D] =
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 740bec586a5e33..31789cfb289154 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -6068,12 +6068,9 @@ void ASTRecordWriter::AddCXXDefinitionData(const 
CXXRecordDecl *D) {
 
   Record->push_back(DefinitionBits);
 
-  // We only perform ODR checks for decls not in GMF.
-  if (!shouldSkipCheckingODR(D)) {
-// getODRHash will compute the ODRHash if it has not been previously
-// computed.
-Record->push_back(D->getODRHash());
-  }
+  // getODRHash will compute the ODRHash if it has not been previously
+  // computed.
+  Record->push_back(D->getODRHash());
 
   bool ModulesDebugInfo =
   Writer->Context->getLangOpts().ModulesDebugInfo && !D->isDependentType();
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index f224075643e998..496c0fdbe0ebf6 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -493,9 +493,7 @@ void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
   EnumDeclBits.addBit(D->isFixed());
   Record.push_back(EnumDeclBits);
 
-  // We only perform ODR checks for decls not in GMF.
-  if (!shouldSkipCheckingODR(D))
-Record.push_back(D->getODRHash());
+  Record.push_back(D->getODRHash());
 
   if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) 
{
 Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
@@ -703,9 +701,7 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
   if (D->isExplicitlyDefaulted())
 Record.AddSourceLocation(D->getDefaultLoc());
 
-  // We only perform ODR checks for decls not in GMF.
-  if (!shouldSkipCheckingODR(D))
-Record.push_back(D->getODRHash());
+  Record.push_back(D->getODRHash());
 
   if (D->isDefaulted()) {
 if (auto *FDI = D->getDefaultedFunctionInfo()) {

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


[clang] [clang-format] Don't sort qualifiers across preprocessor directives (PR #81958)

2024-02-16 Thread via cfe-commits

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

LGTM, as long as someone doesn't say it should be

```c++
#if FOO
   constexpr
#endif
   inline
   int i = 0;
```

but I think this change is fine..I would rather we didn't try and support 
that.. thank you.

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


[clang] fix unnecessary warning when using bitand with boolean (PR #81976)

2024-02-16 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy created 
https://github.com/llvm/llvm-project/pull/81976

**Overview:**
This pull request fixes #77601 where using the `bitand` operator with boolean 
operands should not trigger the warning, as it would indicate an intentional 
use of bitwise AND rather than a typo or error. 

**Testing:**
- Tested the updated code.
- Verified that other functionalities remain unaffected.
![Screenshot from 2024-02-16 
14-25-58](https://github.com/llvm/llvm-project/assets/76656712/63310152-6dc1-485c-b00e-d76980586d91)



**Dependencies:**
- No dependencies on other pull requests.

**CC:**
- @dtcxzyw 



>From 07c73f087a430f5115ecdfec23730c5afcab37f3 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Fri, 16 Feb 2024 14:26:36 +0530
Subject: [PATCH] fix unnecessary warning when using bitand with boolean

Signed-off-by: 11happy 
---
 clang/lib/Sema/SemaChecking.cpp | 24 ++--
 clang/test/Sema/warn-bitwise-and-bool.c |  4 ++--
 clang/test/Sema/warn-bitwise-or-bool.c  |  4 ++--
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 502b24bcdf8b42..e43892cbf35890 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16191,12 +16191,24 @@ static void AnalyzeImplicitConversions(
 BO->getRHS()->isKnownToHaveBooleanValue() &&
 BO->getLHS()->HasSideEffects(S.Context) &&
 BO->getRHS()->HasSideEffects(S.Context)) {
-  S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)
-  << (BO->getOpcode() == BO_And ? "&" : "|") << OrigE->getSourceRange()
-  << FixItHint::CreateReplacement(
- BO->getOperatorLoc(),
- (BO->getOpcode() == BO_And ? "&&" : "||"));
-  S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
+  clang::SourceManager &SM = S.getSourceManager();
+  clang::LangOptions LO = S.getLangOpts();
+  clang::SourceLocation BLoc = BO->getOperatorLoc();
+  clang::SourceLocation ELoc =
+  clang::Lexer::getLocForEndOfToken(BLoc, 0, SM, LO);
+  llvm::StringRef SR = clang::Lexer::getSourceText(
+  clang::CharSourceRange::getTokenRange(BLoc, ELoc), SM, LO);
+
+  if (SR.str() == "&" || SR.str() == "|") {
+
+S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)
+<< (BO->getOpcode() == BO_And ? "&" : "|")
+<< OrigE->getSourceRange()
+<< FixItHint::CreateReplacement(
+   BO->getOperatorLoc(),
+   (BO->getOpcode() == BO_And ? "&&" : "||"));
+S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
+  }
 }
 
   // For conditional operators, we analyze the arguments as if they
diff --git a/clang/test/Sema/warn-bitwise-and-bool.c 
b/clang/test/Sema/warn-bitwise-and-bool.c
index 6bec1be1abdef6..23e7afcc59f8aa 100644
--- a/clang/test/Sema/warn-bitwise-and-bool.c
+++ b/clang/test/Sema/warn-bitwise-and-bool.c
@@ -45,8 +45,8 @@ void test(boolean a, boolean b, int *p, volatile int *q, int 
i) {
   b = bar() & (i > 4);
   b = (i == 7) & foo();
 #ifdef __cplusplus
-  b = foo() bitand bar(); // expected-warning {{use of bitwise '&' with 
boolean operands}}
-  // expected-note@-1 {{cast one or both operands to 
int to silence this warning}}
+  b = foo() bitand bar(); // Ok, no warning expected
+  
 #endif
 
   if (foo() & bar())  // expected-warning {{use of bitwise '&' with 
boolean operands}}
diff --git a/clang/test/Sema/warn-bitwise-or-bool.c 
b/clang/test/Sema/warn-bitwise-or-bool.c
index ae86790901aac5..e84f59cf8f766a 100644
--- a/clang/test/Sema/warn-bitwise-or-bool.c
+++ b/clang/test/Sema/warn-bitwise-or-bool.c
@@ -45,8 +45,8 @@ void test(boolean a, boolean b, int *p, volatile int *q, int 
i) {
   b = bar() | (i > 4);
   b = (i == 7) | foo();
 #ifdef __cplusplus
-  b = foo() bitor bar();  // expected-warning {{use of bitwise '|' with 
boolean operands}}
-  // expected-note@-1 {{cast one or both operands to 
int to silence this warning}}
+  b = foo() bitor bar();  //Ok, no warning expected
+  
 #endif
 
   if (foo() | bar())  // expected-warning {{use of bitwise '|' with 
boolean operands}}

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


[clang] fix unnecessary warning when using bitand with boolean (PR #81976)

2024-02-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Bhuminjay Soni (11happy)


Changes

**Overview:**
This pull request fixes #77601 where using the `bitand` operator with 
boolean operands should not trigger the warning, as it would indicate an 
intentional use of bitwise AND rather than a typo or error. 

**Testing:**
- Tested the updated code.
- Verified that other functionalities remain unaffected.
![Screenshot from 2024-02-16 
14-25-58](https://github.com/llvm/llvm-project/assets/76656712/63310152-6dc1-485c-b00e-d76980586d91)



**Dependencies:**
- No dependencies on other pull requests.

**CC:**
- @dtcxzyw 



---
Full diff: https://github.com/llvm/llvm-project/pull/81976.diff


3 Files Affected:

- (modified) clang/lib/Sema/SemaChecking.cpp (+18-6) 
- (modified) clang/test/Sema/warn-bitwise-and-bool.c (+2-2) 
- (modified) clang/test/Sema/warn-bitwise-or-bool.c (+2-2) 


``diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 502b24bcdf8b42..e43892cbf35890 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16191,12 +16191,24 @@ static void AnalyzeImplicitConversions(
 BO->getRHS()->isKnownToHaveBooleanValue() &&
 BO->getLHS()->HasSideEffects(S.Context) &&
 BO->getRHS()->HasSideEffects(S.Context)) {
-  S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)
-  << (BO->getOpcode() == BO_And ? "&" : "|") << OrigE->getSourceRange()
-  << FixItHint::CreateReplacement(
- BO->getOperatorLoc(),
- (BO->getOpcode() == BO_And ? "&&" : "||"));
-  S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
+  clang::SourceManager &SM = S.getSourceManager();
+  clang::LangOptions LO = S.getLangOpts();
+  clang::SourceLocation BLoc = BO->getOperatorLoc();
+  clang::SourceLocation ELoc =
+  clang::Lexer::getLocForEndOfToken(BLoc, 0, SM, LO);
+  llvm::StringRef SR = clang::Lexer::getSourceText(
+  clang::CharSourceRange::getTokenRange(BLoc, ELoc), SM, LO);
+
+  if (SR.str() == "&" || SR.str() == "|") {
+
+S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)
+<< (BO->getOpcode() == BO_And ? "&" : "|")
+<< OrigE->getSourceRange()
+<< FixItHint::CreateReplacement(
+   BO->getOperatorLoc(),
+   (BO->getOpcode() == BO_And ? "&&" : "||"));
+S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
+  }
 }
 
   // For conditional operators, we analyze the arguments as if they
diff --git a/clang/test/Sema/warn-bitwise-and-bool.c 
b/clang/test/Sema/warn-bitwise-and-bool.c
index 6bec1be1abdef6..23e7afcc59f8aa 100644
--- a/clang/test/Sema/warn-bitwise-and-bool.c
+++ b/clang/test/Sema/warn-bitwise-and-bool.c
@@ -45,8 +45,8 @@ void test(boolean a, boolean b, int *p, volatile int *q, int 
i) {
   b = bar() & (i > 4);
   b = (i == 7) & foo();
 #ifdef __cplusplus
-  b = foo() bitand bar(); // expected-warning {{use of bitwise '&' with 
boolean operands}}
-  // expected-note@-1 {{cast one or both operands to 
int to silence this warning}}
+  b = foo() bitand bar(); // Ok, no warning expected
+  
 #endif
 
   if (foo() & bar())  // expected-warning {{use of bitwise '&' with 
boolean operands}}
diff --git a/clang/test/Sema/warn-bitwise-or-bool.c 
b/clang/test/Sema/warn-bitwise-or-bool.c
index ae86790901aac5..e84f59cf8f766a 100644
--- a/clang/test/Sema/warn-bitwise-or-bool.c
+++ b/clang/test/Sema/warn-bitwise-or-bool.c
@@ -45,8 +45,8 @@ void test(boolean a, boolean b, int *p, volatile int *q, int 
i) {
   b = bar() | (i > 4);
   b = (i == 7) | foo();
 #ifdef __cplusplus
-  b = foo() bitor bar();  // expected-warning {{use of bitwise '|' with 
boolean operands}}
-  // expected-note@-1 {{cast one or both operands to 
int to silence this warning}}
+  b = foo() bitor bar();  //Ok, no warning expected
+  
 #endif
 
   if (foo() | bar())  // expected-warning {{use of bitwise '|' with 
boolean operands}}

``




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


[clang] [COFF][Aarch64] Add _InterlockedAdd64 intrinsic (PR #81849)

2024-02-16 Thread Pierrick Bouvier via cfe-commits

pbo-linaro wrote:

clang-format failure is not related to this commit.

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


[clang] Fix build dllexport/dllimport issues when doing a shared build for Windows using GCC (PR #66881)

2024-02-16 Thread Martin Storsjö via cfe-commits

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


[clang] Fix build dllexport/dllimport issues when doing a shared build for Windows using GCC (PR #66881)

2024-02-16 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

> This is superseded by https://github.com/llvm/llvm-project/pull/71393 which 
> was merged now.

I'll close this one for now, as I believe the issue has been fixed differently.

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


[clang] [compiler-rt] [asan][windows] Eliminate the static asan runtime on windows (PR #81677)

2024-02-16 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

> The core reasoning is that asan is a "only one allowed per process" type 
> thing (you can't have one copy of the asan runtime handling a malloc while a 
> different one handles the corresponding free).

Not to distract from the direction taken here (which I do agree seems 
reasonable, even if I haven't had time to look closer at the PR yet) - but, 
when using the static CRT in general, doesn't the same concern apply there as 
well? I.e. when using the static CRT, care must be taken that the same CRT 
instances does frees as did the allocation. But I guess there are other 
asan-related aspects that makes it even more of a mess.

Also secondly, when discussing these details - how the asan runtime is built in 
one, specific way, while it is used for applications that can use a different 
CRT configuration - would you like to chime in on 
https://github.com/microsoft/vcpkg/pull/34123#issuecomment-1760396486? There, 
some people involved questioned and weren't convinced that one part of a 
project (compiler-rt in llvm) should be allowed to override the CRT choice that 
is made for the whole vcpkg build. I tried to argue that compiler-rt is a very 
special case and doesn't interact with the rest of the libraries built in vcpkg 
like that, and compiler-rt is free to override the CRT to use internally.

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


[clang] 92ef408 - [clang-format] Delete a redundant newline at the end of a test case

2024-02-16 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-02-16T01:47:49-08:00
New Revision: 92ef40874d58d4fca4b7657c31ab2538e1301f26

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

LOG: [clang-format] Delete a redundant newline at the end of a test case

It slipped in from commit fa6025e25b57.

Added: 


Modified: 
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b0687eaecb10fe..d9e369296eed16 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5019,7 +5019,7 @@ TEST_F(FormatTest, DesignatedInitializers) {
" .b = 2,\n"
" },\n"
" }) {\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTest, BracedInitializerIndentWidth) {



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


[clang] [clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda brace wrapping. (PR #81848)

2024-02-16 Thread Owen Pan via cfe-commits

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


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


[clang] [clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda brace wrapping. (PR #81848)

2024-02-16 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda brace wrapping. (PR #81848)

2024-02-16 Thread Owen Pan via cfe-commits


@@ -22893,6 +22893,19 @@ TEST_F(FormatTest, FormatsLambdas) {
LLVMWithBeforeLambdaBody);
   verifyFormat("FctWithTwoParams_SLS_All([]() { return 43; }, 87);",
LLVMWithBeforeLambdaBody);
+  verifyFormat(
+  "FctWithTwoParams_SLS_All(\n"
+  "87, []() { return LongLineThatWillForceBothParamsToNewLine(); 
});\n",

owenca wrote:

```suggestion
  "87, []() { return LongLineThatWillForceBothParamsToNewLine(); });",
```

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


[clang] [NVPTX][AMDGPU][CodeGen] Fix `local_space nullptr` handling for NVPTX and local/private `nullptr` value for AMDGPU. (PR #78759)

2024-02-16 Thread via cfe-commits

https://github.com/mmoadeli updated 
https://github.com/llvm/llvm-project/pull/78759

>From ea5af38849f3c2badbb3c1c1161a13d1c855e19b Mon Sep 17 00:00:00 2001
From: m moadeli 
Date: Fri, 19 Jan 2024 18:42:24 +
Subject: [PATCH 1/2] - Address space cast of a `local_space` specialized
 `nullptr` into a generic space for the CUDA backend. - In the context of AMD
 GPU, assigns a NULL value of `~0` for the address spaces of `sycl_local` and
 `sycl_private`

---
 clang/lib/Basic/Targets/AMDGPU.h  |   6 +-
 clang/lib/CodeGen/Targets/NVPTX.cpp   |  18 +++
 .../CodeGenSYCL/address-space-conversions.cpp |   4 +
 .../amd-address-space-conversions.cpp | 128 ++
 .../cuda-address-space-conversions.cpp| 122 +
 5 files changed, 276 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGenSYCL/amd-address-space-conversions.cpp
 create mode 100644 clang/test/CodeGenSYCL/cuda-address-space-conversions.cpp

diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index e80589dde0ecb5..94d9ba93ed226f 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -414,8 +414,10 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   // value ~0.
   uint64_t getNullPointerValue(LangAS AS) const override {
 // FIXME: Also should handle region.
-return (AS == LangAS::opencl_local || AS == LangAS::opencl_private)
-  ? ~0 : 0;
+return (AS == LangAS::opencl_local || AS == LangAS::opencl_private ||
+AS == LangAS::sycl_local || AS == LangAS::sycl_private)
+   ? ~0
+   : 0;
   }
 
   void setAuxTarget(const TargetInfo *Aux) override;
diff --git a/clang/lib/CodeGen/Targets/NVPTX.cpp 
b/clang/lib/CodeGen/Targets/NVPTX.cpp
index d0dc7c258a03a6..8718f1ecf3a7e0 100644
--- a/clang/lib/CodeGen/Targets/NVPTX.cpp
+++ b/clang/lib/CodeGen/Targets/NVPTX.cpp
@@ -47,6 +47,10 @@ class NVPTXTargetCodeGenInfo : public TargetCodeGenInfo {
CodeGen::CodeGenModule &M) const override;
   bool shouldEmitStaticExternCAliases() const override;
 
+  llvm::Constant *getNullPointer(const CodeGen::CodeGenModule &CGM,
+ llvm::PointerType *T,
+ QualType QT) const override;
+
   llvm::Type *getCUDADeviceBuiltinSurfaceDeviceType() const override {
 // On the device side, surface reference is represented as an object handle
 // in 64-bit integer.
@@ -285,6 +289,20 @@ void 
NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::GlobalValue *GV,
 bool NVPTXTargetCodeGenInfo::shouldEmitStaticExternCAliases() const {
   return false;
 }
+
+llvm::Constant *
+NVPTXTargetCodeGenInfo::getNullPointer(const CodeGen::CodeGenModule &CGM,
+   llvm::PointerType *PT,
+   QualType QT) const {
+  auto &Ctx = CGM.getContext();
+  if (PT->getAddressSpace() != Ctx.getTargetAddressSpace(LangAS::opencl_local))
+return llvm::ConstantPointerNull::get(PT);
+
+  auto NPT = llvm::PointerType::get(
+  PT->getContext(), Ctx.getTargetAddressSpace(LangAS::opencl_generic));
+  return llvm::ConstantExpr::getAddrSpaceCast(
+  llvm::ConstantPointerNull::get(NPT), PT);
+}
 }
 
 void CodeGenModule::handleCUDALaunchBoundsAttr(llvm::Function *F,
diff --git a/clang/test/CodeGenSYCL/address-space-conversions.cpp 
b/clang/test/CodeGenSYCL/address-space-conversions.cpp
index 3933ad375412da..10a181318a174b 100644
--- a/clang/test/CodeGenSYCL/address-space-conversions.cpp
+++ b/clang/test/CodeGenSYCL/address-space-conversions.cpp
@@ -25,6 +25,10 @@ void usages() {
   __attribute__((opencl_local)) int *LOC;
   // CHECK-DAG: [[NoAS:%[a-zA-Z0-9]+]] = alloca ptr addrspace(4)
   // CHECK-DAG: [[NoAS]].ascast = addrspacecast ptr [[NoAS]] to ptr 
addrspace(4)
+  LOC = nullptr;
+  // CHECK-DAG: store ptr addrspace(3) null, ptr addrspace(4) [[LOC]].ascast, 
align 8
+  GLOB = nullptr;
+  // CHECK-DAG: store ptr addrspace(1) null, ptr addrspace(4) [[GLOB]].ascast, 
align 8
   int *NoAS;
   // CHECK-DAG: [[PRIV:%[a-zA-Z0-9]+]] = alloca ptr
   // CHECK-DAG: [[PRIV]].ascast = addrspacecast ptr [[PRIV]] to ptr 
addrspace(4)
diff --git a/clang/test/CodeGenSYCL/amd-address-space-conversions.cpp 
b/clang/test/CodeGenSYCL/amd-address-space-conversions.cpp
new file mode 100644
index 00..35da61cd8cbbe3
--- /dev/null
+++ b/clang/test/CodeGenSYCL/amd-address-space-conversions.cpp
@@ -0,0 +1,128 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fsycl-is-device 
-disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
+void bar(int &Data) {}
+// CHECK-DAG: define dso_local void @[[RAW_REF:[a-zA-Z0-9_]+]](ptr noundef 
nonnull align 4 dereferenceable(4) %
+void bar2(int &Data) {}
+// CHECK-DAG: define dso_local void @[[RAW_REF2:[a-zA-Z0-9_]+]](ptr noundef 
nonnull align 4 dereferenceable(4) %
+void bar(__attribute__((opencl_local)) int &Data) {}
+// CHEC

[clang] [COFF][Aarch64] Add _InterlockedAdd64 intrinsic (PR #81849)

2024-02-16 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

It looks like your github account is set to keep your email address private - 
can you please turn that off, so we get a proper email address (when the commit 
is rewritten, as we do merges with "squash and merge" here)? See the "keep my 
email addresses private" setting at https://github.com/settings/emails, and 
https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it
 for the reasoning about this.

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


[clang] [COFF][Aarch64] Add _InterlockedAdd64 intrinsic (PR #81849)

2024-02-16 Thread Pierrick Bouvier via cfe-commits

pbo-linaro wrote:

Done :+1: 

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


[clang] 2e43ca4 - [clang][Interp] Check variable initialization in Ret op

2024-02-16 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-16T12:05:03+01:00
New Revision: 2e43ca49d06d4cf78a3fd86e1e41175fde083708

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

LOG: [clang][Interp] Check variable initialization in Ret op

Just like we did with the l-to-r conversion, we need to do this
while the data is still alive.

Added: 


Modified: 
clang/lib/AST/Interp/Context.cpp
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/EvalEmitter.h
clang/lib/AST/Interp/EvaluationResult.cpp
clang/lib/AST/Interp/EvaluationResult.h
clang/test/AST/Interp/c.c

Removed: 




diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index 6068b1a5680c83..578dc44fe4f8d4 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -88,7 +88,10 @@ bool Context::evaluateAsInitializer(State &Parent, const 
VarDecl *VD,
   assert(Stk.empty());
   ByteCodeExprGen C(*this, *P, Parent, Stk, Result);
 
-  auto Res = C.interpretDecl(VD);
+  bool CheckGlobalInitialized =
+  shouldBeGloballyIndexed(VD) &&
+  (VD->getType()->isRecordType() || VD->getType()->isArrayType());
+  auto Res = C.interpretDecl(VD, CheckGlobalInitialized);
   if (Res.isInvalid()) {
 Stk.clear();
 return false;
@@ -101,25 +104,7 @@ bool Context::evaluateAsInitializer(State &Parent, const 
VarDecl *VD,
   Stk.clear();
 #endif
 
-  // Ensure global variables are fully initialized.
-  if (shouldBeGloballyIndexed(VD) &&
-  (VD->getType()->isRecordType() || VD->getType()->isArrayType() ||
-   VD->getType()->isAnyComplexType())) {
-assert(Res.isLValue());
-
-if (!VD->getType()->isAnyComplexType() &&
-!Res.checkFullyInitialized(C.getState()))
-  return false;
-
-// lvalue-to-rvalue conversion. We do this manually here so we can
-// examine the result above before converting and returning it.
-std::optional RValueResult = Res.toRValue();
-if (!RValueResult)
-  return false;
-Result = *RValueResult;
-
-  } else
-Result = Res.toAPValue();
+  Result = Res.toAPValue();
   return true;
 }
 

diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index f14023a23af9b3..6715921ff1d975 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -44,7 +44,9 @@ EvaluationResult EvalEmitter::interpretExpr(const Expr *E,
   return std::move(this->EvalResult);
 }
 
-EvaluationResult EvalEmitter::interpretDecl(const VarDecl *VD) {
+EvaluationResult EvalEmitter::interpretDecl(const VarDecl *VD,
+bool CheckFullyInitialized) {
+  this->CheckFullyInitialized = CheckFullyInitialized;
   EvalResult.setSource(VD);
 
   if (!this->visitDecl(VD) && EvalResult.empty())
@@ -131,7 +133,17 @@ template <> bool EvalEmitter::emitRet(const 
SourceInfo &Info) {
   return false;
 }
   } else {
-EvalResult.setPointer(Ptr);
+if (CheckFullyInitialized) {
+  if (!EvalResult.checkFullyInitialized(S, Ptr))
+return false;
+
+  std::optional RValueResult = Ptr.toRValue(Ctx);
+  if (!RValueResult)
+return false;
+  EvalResult.setValue(*RValueResult);
+} else {
+  EvalResult.setValue(Ptr.toAPValue());
+}
   }
 
   return true;

diff  --git a/clang/lib/AST/Interp/EvalEmitter.h 
b/clang/lib/AST/Interp/EvalEmitter.h
index 8159e489f168e3..032c8860ee677a 100644
--- a/clang/lib/AST/Interp/EvalEmitter.h
+++ b/clang/lib/AST/Interp/EvalEmitter.h
@@ -36,7 +36,7 @@ class EvalEmitter : public SourceMapper {
 
   EvaluationResult interpretExpr(const Expr *E,
  bool ConvertResultToRValue = false);
-  EvaluationResult interpretDecl(const VarDecl *VD);
+  EvaluationResult interpretDecl(const VarDecl *VD, bool 
CheckFullyInitialized);
 
   InterpState &getState() { return S; }
 
@@ -89,6 +89,9 @@ class EvalEmitter : public SourceMapper {
   EvaluationResult EvalResult;
   /// Whether the result should be converted to an RValue.
   bool ConvertResultToRValue = false;
+  /// Whether we should check if the result has been fully
+  /// initialized.
+  bool CheckFullyInitialized = false;
 
   /// Temporaries which require storage.
   llvm::DenseMap> Locals;

diff  --git a/clang/lib/AST/Interp/EvaluationResult.cpp 
b/clang/lib/AST/Interp/EvaluationResult.cpp
index b44e8f84a1c42d..693ae9ce4a94e6 100644
--- a/clang/lib/AST/Interp/EvaluationResult.cpp
+++ b/clang/lib/AST/Interp/EvaluationResult.cpp
@@ -132,9 +132,10 @@ static bool CheckFieldsInitialized(InterpState &S, 
SourceLocation Loc,
   return Result;
 }
 
-bool EvaluationResult::checkFullyInitialized(InterpState &S) const {
+bool EvaluationResult::checkFullyInitialized(InterpState &S,
+  

[clang] [COFF][Aarch64] Add _InterlockedAdd64 intrinsic (PR #81849)

2024-02-16 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

> Done 👍

Thanks, now this looks good to merge!

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


[clang] 0ea64ad - [COFF][Aarch64] Add _InterlockedAdd64 intrinsic (#81849)

2024-02-16 Thread via cfe-commits

Author: Pierrick Bouvier
Date: 2024-02-16T13:20:08+02:00
New Revision: 0ea64ad88abcbb939547a92000d98efb2b00d95f

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

LOG: [COFF][Aarch64] Add _InterlockedAdd64 intrinsic (#81849)

Found when compiling openssl master branch using clang-cl.

This commit introduces usage of InterlockedAdd64:

https://github.com/openssl/openssl/commit/d0e1a0ae701cfaca7f3dd3bf28a3f934a6408813


https://learn.microsoft.com/en-us/cpp/intrinsics/interlockedadd-intrinsic-functions

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsAArch64.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/intrin.h
clang/test/CodeGen/arm64-microsoft-intrinsics.c
clang/test/CodeGen/ms-intrinsics-other.c
clang/test/CodeGen/ms-intrinsics-underaligned.c

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index 31ec84143f65c1..b5cbe90c8fd6a3 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -139,6 +139,7 @@ TARGET_HEADER_BUILTIN(_BitScanForward64, "UcUNi*ULLi", 
"nh", INTRIN_H, ALL_MS_LA
 TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcUNi*ULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(_InterlockedAdd,   "NiNiD*Ni","nh", 
INTRIN_H, ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_InterlockedAdd64, "LLiLLiD*LLi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_InterlockedAnd64, "LLiLLiD*LLi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_InterlockedDecrement64,   "LLiLLiD*","nh", 
INTRIN_H, ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_InterlockedExchange64,"LLiLLiD*LLi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES, "")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9bc60466d09be6..d454ccc1dd8613 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -12043,7 +12043,8 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned 
BuiltinID,
 "vgetq_lane");
   }
 
-  case clang::AArch64::BI_InterlockedAdd: {
+  case clang::AArch64::BI_InterlockedAdd:
+  case clang::AArch64::BI_InterlockedAdd64: {
 Address DestAddr = CheckAtomicAlignment(*this, E);
 Value *Val = EmitScalarExpr(E->getArg(1));
 AtomicRMWInst *RMWI =

diff  --git a/clang/lib/Headers/intrin.h b/clang/lib/Headers/intrin.h
index 9ebaea9fee9421..a6395143db54c2 100644
--- a/clang/lib/Headers/intrin.h
+++ b/clang/lib/Headers/intrin.h
@@ -551,6 +551,7 @@ static __inline__ void __DEFAULT_FN_ATTRS __nop(void) {
 #if defined(__aarch64__)
 unsigned __int64 __getReg(int);
 long _InterlockedAdd(long volatile *Addend, long Value);
+__int64 _InterlockedAdd64(__int64 volatile *Addend, __int64 Value);
 __int64 _ReadStatusReg(int);
 void _WriteStatusReg(int, __int64);
 

diff  --git a/clang/test/CodeGen/arm64-microsoft-intrinsics.c 
b/clang/test/CodeGen/arm64-microsoft-intrinsics.c
index 44b2ee28fe5681..a354ed948ca5f1 100644
--- a/clang/test/CodeGen/arm64-microsoft-intrinsics.c
+++ b/clang/test/CodeGen/arm64-microsoft-intrinsics.c
@@ -21,6 +21,20 @@ long test_InterlockedAdd_constant(long volatile *Addend) {
 // CHECK-MSVC: ret i32 %[[NEWVAL:[0-9]+]]
 // CHECK-LINUX: error: call to undeclared function '_InterlockedAdd'
 
+__int64 test_InterlockedAdd64(__int64 volatile *Addend, __int64 Value) {
+  return _InterlockedAdd64(Addend, Value);
+}
+
+__int64 test_InterlockedAdd64_constant(__int64 volatile *Addend) {
+  return _InterlockedAdd64(Addend, -1);
+}
+
+// CHECK-LABEL: define {{.*}} i64 @test_InterlockedAdd64(ptr %Addend, i64 
%Value) {{.*}} {
+// CHECK-MSVC: %[[OLDVAL:[0-9]+]] = atomicrmw add ptr %1, i64 %2 seq_cst, 
align 8
+// CHECK-MSVC: %[[NEWVAL:[0-9]+]] = add i64 %[[OLDVAL:[0-9]+]], %2
+// CHECK-MSVC: ret i64 %[[NEWVAL:[0-9]+]]
+// CHECK-LINUX: error: call to undeclared function '_InterlockedAdd64'
+
 void check__dmb(void) {
   __dmb(0);
 }

diff  --git a/clang/test/CodeGen/ms-intrinsics-other.c 
b/clang/test/CodeGen/ms-intrinsics-other.c
index 76f54add749669..36c40dddcbb4f5 100644
--- a/clang/test/CodeGen/ms-intrinsics-other.c
+++ b/clang/test/CodeGen/ms-intrinsics-other.c
@@ -240,6 +240,15 @@ LONG test_InterlockedAdd(LONG volatile *Addend, LONG 
Value) {
 // CHECK-ARM-ARM64: %[[OLDVAL:[0-9]+]] = atomicrmw add ptr %Addend, i32 %Value 
seq_cst, align 4
 // CHECK-ARM-ARM64: %[[NEWVAL:[0-9]+]] = add i32 %[[OLDVAL:[0-9]+]], %Value
 // CHECK-ARM-ARM64: ret i32 %[[NEWVAL:[0-9]+]]
+
+__int64 test_InterlockedAdd64(__int64 volatile *Addend, __int64 Value) {
+  return _InterlockedAdd64(Addend, Value);
+}
+
+// CHECK-ARM-ARM64: define{{.*}}i64 @test_InterlockedAdd64(ptr{{[a-z_ 
]*}}%Addend

[clang] [COFF][Aarch64] Add _InterlockedAdd64 intrinsic (PR #81849)

2024-02-16 Thread Martin Storsjö via cfe-commits

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


[clang] [COFF][Aarch64] Add _InterlockedAdd64 intrinsic (PR #81849)

2024-02-16 Thread Pierrick Bouvier via cfe-commits

pbo-linaro wrote:

Thanks @mstorsjo!

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


[clang] f06e07b - [clang][Interp][NFC] Check pointer compound assign operators for errors

2024-02-16 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-16T12:30:24+01:00
New Revision: f06e07be9a41978e39fdf22f6174194cf8382047

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

LOG: [clang][Interp][NFC] Check pointer compound assign operators for errors

This needs to be done but we didn't use to do it.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e4b48c4e946f13..a27a0cb2094eae 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1446,10 +1446,13 @@ bool 
ByteCodeExprGen::VisitPointerCompoundAssignOperator(
   if (!visit(RHS))
 return false;
 
-  if (Op == BO_AddAssign)
-this->emitAddOffset(*RT, E);
-  else
-this->emitSubOffset(*RT, E);
+  if (Op == BO_AddAssign) {
+if (!this->emitAddOffset(*RT, E))
+  return false;
+  } else {
+if (!this->emitSubOffset(*RT, E))
+  return false;
+  }
 
   if (DiscardResult)
 return this->emitStorePopPtr(E);



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


[clang] a52c0c7 - [clang][Interp] Lazily visit constant locals in C++

2024-02-16 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-16T12:49:05+01:00
New Revision: a52c0c770056e040390839e753dbbaccbf4d63c4

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

LOG: [clang][Interp] Lazily visit constant locals in C++

While we _do_ get them registered via visitInitializer(), they
are still local, so gone on the next call to e.g. evaluateAsRValue().

Visit them lazily, similarly like we do in C.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/arrays.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index a27a0cb2094eae..975d3b68e9b242 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3237,9 +3237,20 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
   // Try to lazily visit (or emit dummy pointers for) declarations
   // we haven't seen yet.
   if (Ctx.getLangOpts().CPlusPlus) {
-if (const auto *VD = dyn_cast(D); VD && VD->isStaticLocal()) {
-  if (std::optional I = P.getOrCreateDummy(D))
-return this->emitGetPtrGlobal(*I, E);
+if (const auto *VD = dyn_cast(D)) {
+  // Dummy for static locals
+  if (VD->isStaticLocal()) {
+if (std::optional I = P.getOrCreateDummy(D))
+  return this->emitGetPtrGlobal(*I, E);
+return false;
+  }
+  // Visit local const variables like normal.
+  if (VD->isLocalVarDecl() && VD->getType().isConstQualified()) {
+if (!this->visitVarDecl(VD))
+  return false;
+// Retry.
+return this->VisitDeclRefExpr(E);
+  }
 }
   } else {
 if (const auto *VD = dyn_cast(D);

diff  --git a/clang/test/AST/Interp/arrays.cpp 
b/clang/test/AST/Interp/arrays.cpp
index 3c06ab5fbe3657..a9450d827f6be6 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -537,3 +537,11 @@ namespace SelfComparison {
 return s3->array[t.field] == s3->array[t.field];  // both-warning 
{{self-comparison always evaluates to true}}
   };
 }
+
+namespace LocalIndex {
+  void test() {
+const int const_subscript = 3;
+int array[2]; // both-note {{declared here}}
+array[const_subscript] = 0;  // both-warning {{array index 3 is past the 
end of the array (that has type 'int[2]')}}
+  }
+}



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


[clang] [clang] Implement `__is_layout_compatible` (PR #81506)

2024-02-16 Thread Vlad Serebrennikov via cfe-commits


@@ -1558,6 +1558,89 @@ void is_standard_layout()
   int t71[F(__is_standard_layout(HasEmptyIndirectBaseAsSecondUnionMember))];
 }
 
+struct CStruct2 {
+  int one;
+  int two;
+};
+
+struct CEmptyStruct2 {};
+
+struct CppEmptyStruct2 : CStruct2 {};
+struct CppStructStandard2 : CEmptyStruct2 {
+  int three;
+  int four;
+};
+struct CppStructNonStandardByBase2 : CStruct2 {
+  int three;
+  int four;
+};
+struct CppStructNonStandardByVirt2 : CStruct2 {
+  virtual void method() {}
+};
+struct CppStructNonStandardByMemb2 : CStruct2 {
+  CppStructNonStandardByVirt member;
+};
+struct CppStructNonStandardByProt2 : CStruct2 {
+  int five;
+protected:
+  int six;
+};
+struct CppStructNonStandardByVirtBase2 : virtual CStruct2 {
+};
+struct CppStructNonStandardBySameBase2 : CEmptyStruct2 {
+  CEmptyStruct member;
+};
+struct CppStructNonStandardBy2ndVirtBase2 : CEmptyStruct2 {
+  CEmptyStruct member;
+};
+
+struct CStructWithQualifiers {
+  const int one;
+  volatile int two;
+};
+
+struct CStructNoUniqueAddress {
+  int one;
+  [[no_unique_address]] int two;
+};
+
+struct CStructNoUniqueAddress2 {
+  int one;
+  [[no_unique_address]] int two;
+};
+
+struct CStructAlignment {
+  int one;
+  alignas(16) int two;
+};
+
+struct CStructIncomplete;
+
+void is_layout_compatible()
+{
+  static_assert(__is_layout_compatible(void, void), "");
+  static_assert(__is_layout_compatible(int, int), "");
+  static_assert(__is_layout_compatible(int[], int[]), "");
+  static_assert(__is_layout_compatible(int[2], int[2]), "");
+  static_assert(__is_layout_compatible(CStruct, CStruct2), "");
+  static_assert(__is_layout_compatible(CEmptyStruct, CEmptyStruct2), "");
+  static_assert(__is_layout_compatible(CppEmptyStruct, CppEmptyStruct2), "");
+  static_assert(__is_layout_compatible(CppStructStandard, CppStructStandard2), 
"");
+  static_assert(!__is_layout_compatible(CppStructNonStandardByBase, 
CppStructNonStandardByBase2), "");
+  static_assert(!__is_layout_compatible(CppStructNonStandardByVirt, 
CppStructNonStandardByVirt2), "");
+  static_assert(!__is_layout_compatible(CppStructNonStandardByMemb, 
CppStructNonStandardByMemb2), "");
+  static_assert(!__is_layout_compatible(CppStructNonStandardByProt, 
CppStructNonStandardByProt2), "");
+  static_assert(!__is_layout_compatible(CppStructNonStandardByVirtBase, 
CppStructNonStandardByVirtBase2), "");
+  static_assert(!__is_layout_compatible(CppStructNonStandardBySameBase, 
CppStructNonStandardBySameBase2), "");
+  static_assert(!__is_layout_compatible(CppStructNonStandardBy2ndVirtBase, 
CppStructNonStandardBy2ndVirtBase2), "");
+  static_assert(!__is_layout_compatible(CStruct, CStructWithQualifiers), ""); 
// FIXME: this is CWG1719
+  static_assert(__is_layout_compatible(CStruct, CStructNoUniqueAddress) == 
bool(__has_cpp_attribute(no_unique_address)), ""); // FIXME: this is CWG2759
+  static_assert(__is_layout_compatible(CStructNoUniqueAddress, 
CStructNoUniqueAddress2) == bool(__has_cpp_attribute(no_unique_address)), ""); 
// FIXME: this is CWG2759
+  static_assert(__is_layout_compatible(CStruct, CStructAlignment), "");
+  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete), 
"");
+  static_assert(!__is_layout_compatible(CStruct, CStructIncomplete), "");
+}

Endilll wrote:

> A type is layout compatible with its qualified version. e.g., SomeStruct and 
> const SomeStruct

Done. It even works correctly for class types.

> Layout compatibility of function types (not function pointer types), e.g., 
> void(int) and void(int)

Done. I added tests for function types, reference to functions, pointers to 
function, pointers to data members, pointers to member functions.

> Diagnostics when given an incomplete type for either operand

We don't issue any, as far as I can see. And I don't think we can when the 
types are the same, ignoring cv qualifiers:
> Two types cv1 T1 and cv2 T2 are [layout-compatible 
> types](http://eel.is/c++draft/basic.types.general#def:type,layout-compatible) 
> if T1 and T2 are the same type, [layout-compatible 
> enumerations](http://eel.is/c++draft/dcl.enum#def:layout-compatible,enumeration),
>  or [layout-compatible standard-layout class 
> types](http://eel.is/c++draft/class.mem#def:layout-compatible,class)[.](http://eel.is/c++draft/basic.types.general#11.sentence-1)

> That int and unsigned int are not layout compatible
> That char and signed char/unsigned char are not layout compatible
> That an enumeration type and its underlying type are not layout compatible

Done.

> I think we should add those tests somewhere (either here or in dr1xxx.cpp) so 
> 1) we know we don't crash on them, 2) we're alerted to behavioral changes in 
> this area, and 3) better documentation of existing behavior.

Agreed. I marked 1334 as superseded as 1719, and added a test for 1719.

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

[clang] [clang] Implement `__is_layout_compatible` (PR #81506)

2024-02-16 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda brace wrapping. (PR #81848)

2024-02-16 Thread via cfe-commits

https://github.com/rmarker updated 
https://github.com/llvm/llvm-project/pull/81848

>From bd00d621611a9785c393db84105984b0082f650a Mon Sep 17 00:00:00 2001
From: rmarker 
Date: Thu, 15 Feb 2024 22:27:16 +1030
Subject: [PATCH 1/2] [clang-format] Fix AllowShortLambdasOnASingleLine
 interfering with lambda brace wrapping.

Fix an issue where the lambda body left brace could sometimes fail to be 
wrapped when AllowShortLambdasOnASingleLine is enabled.

Now, when BraceWrapping.BeforeLambdaBody is enabled,
if the brace is not wrapped we prevent breaks in the lambda body.

Resolves #81845
---
 clang/lib/Format/ContinuationIndenter.cpp | 16 
 clang/lib/Format/ContinuationIndenter.h   |  2 +-
 clang/unittests/Format/FormatTest.cpp | 13 +
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 159d130cb67332..96e9684409c744 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1794,7 +1794,7 @@ void 
ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
   }
 
   if (Current.MatchingParen && Current.is(BK_Block)) {
-moveStateToNewBlock(State);
+moveStateToNewBlock(State, Newline);
 return;
   }
 
@@ -1981,7 +1981,7 @@ void 
ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
   }
 }
 
-void ContinuationIndenter::moveStateToNewBlock(LineState &State) {
+void ContinuationIndenter::moveStateToNewBlock(LineState &State, bool NewLine) 
{
   if (Style.LambdaBodyIndentation == FormatStyle::LBI_OuterScope &&
   State.NextToken->is(TT_LambdaLBrace) &&
   !State.Line->MightBeFunctionDecl) {
@@ -1993,10 +1993,18 @@ void 
ContinuationIndenter::moveStateToNewBlock(LineState &State) {
   NestedBlockIndent + (State.NextToken->is(TT_ObjCBlockLBrace)
? Style.ObjCBlockIndentWidth
: Style.IndentWidth);
+
+  // Even when wrapping before lambda body, the left brace can still be added 
to
+  // the same line. This occurs when checking whether the whole lambda body can
+  // go on a single line. In this case we have to make sure there are no line
+  // breaks in the body, otherwise we could just end up with a regular lambda
+  // body without the brace wrapped.
+  bool NoLineBreak = Style.BraceWrapping.BeforeLambdaBody && !NewLine &&
+ State.NextToken->is(TT_LambdaLBrace);
+
   State.Stack.push_back(ParenState(State.NextToken, NewIndent,
State.Stack.back().LastSpace,
-   /*AvoidBinPacking=*/true,
-   /*NoLineBreak=*/false));
+   /*AvoidBinPacking=*/true, NoLineBreak));
   State.Stack.back().NestedBlockIndent = NestedBlockIndent;
   State.Stack.back().BreakBeforeParameter = true;
 }
diff --git a/clang/lib/Format/ContinuationIndenter.h 
b/clang/lib/Format/ContinuationIndenter.h
index 057b85bd32d505..2598947bb624c5 100644
--- a/clang/lib/Format/ContinuationIndenter.h
+++ b/clang/lib/Format/ContinuationIndenter.h
@@ -104,7 +104,7 @@ class ContinuationIndenter {
   /// Update 'State' according to the next token being one of ")>}]".
   void moveStatePastScopeCloser(LineState &State);
   /// Update 'State' with the next token opening a nested block.
-  void moveStateToNewBlock(LineState &State);
+  void moveStateToNewBlock(LineState &State, bool NewLine);
 
   /// Reformats a raw string literal.
   ///
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b0687eaecb10fe..b33613bf143170 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -22893,6 +22893,19 @@ TEST_F(FormatTest, FormatsLambdas) {
LLVMWithBeforeLambdaBody);
   verifyFormat("FctWithTwoParams_SLS_All([]() { return 43; }, 87);",
LLVMWithBeforeLambdaBody);
+  verifyFormat(
+  "FctWithTwoParams_SLS_All(\n"
+  "87, []() { return LongLineThatWillForceBothParamsToNewLine(); 
});\n",
+  LLVMWithBeforeLambdaBody);
+  verifyFormat(
+  "FctWithTwoParams_SLS_All(\n"
+  "87,\n"
+  "[]()\n"
+  "{\n"
+  "  return "
+  "LongLineThatWillForceTheLambdaBodyToBeBrokenIntoMultipleLines();\n"
+  "});",
+  LLVMWithBeforeLambdaBody);
   verifyFormat("FctWithOneNestedLambdas_SLS_All([]() { return 17; });",
LLVMWithBeforeLambdaBody);
   verifyFormat(

>From a326e09507a56dade5d4753a516b0f0dd27d3e17 Mon Sep 17 00:00:00 2001
From: rmarker <37921131+rmar...@users.noreply.github.com>
Date: Fri, 16 Feb 2024 22:34:23 +1030
Subject: [PATCH 2/2] Update clang/unittests/Format/FormatTest.cpp

Co-authored-by: Owen Pan 
---
 clang/unittests/Format/FormatTest.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/unittests/Format/FormatTest.cpp 
b/cla

[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin created 
https://github.com/llvm/llvm-project/pull/81985

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools

>From ddafb4672e1a481d4a9556ebe31ca9a07e1f3569 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 16 Feb 2024 03:51:07 -0800
Subject: [PATCH] [clang-tidy][readability-identifier-naming] Resolve symlinks
 for checking style for file

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools
---
 .../readability/IdentifierNamingCheck.cpp |  7 +--
 .../Inputs/identifier-naming/symlink/build/test.h |  1 +
 .../identifier-naming/symlink/include/.clang-tidy |  4 
 .../identifier-naming/symlink/include/test.h  |  1 +
 .../readability/identifier-naming-symlink.cpp | 15 +++
 5 files changed, 26 insertions(+), 2 deletions(-)
 create mode 12 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 5db9e99ab23708..335c3de25b861b 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1408,13 +1408,16 @@ const IdentifierNamingCheck::FileStyle &
 IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
   if (!GetConfigPerFile)
 return *MainFileStyle;
-  StringRef Parent = llvm::sys::path::parent_path(FileName);
+
+  SmallString<128> RealFileName;
+  llvm::sys::fs::real_path(FileName, RealFileName);
+  StringRef Parent = llvm::sys::path::parent_path(RealFileName);
   auto Iter = NamingStylesCache.find(Parent);
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
   llvm::StringRef CheckName = getID();
-  ClangTidyOptions Options = Context->getOptionsForFile(FileName);
+  ClangTidyOptions Options = Context->getOptionsForFile(RealFileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(
 Parent,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
new file mode 12
index 00..de218fbfa4662a
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
@@ -0,0 +1 @@
+../include/test.h
\ No newline at end of file
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
new file mode 100644
index 00..296550f3aab1eb
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
@@ -0,0 +1,4 @@
+Checks: readability-identifier-naming
+CheckOptions:
+  readability-identifier-naming.GlobalConstantCase: CamelCase
+  readability-identifier-naming.GlobalConstantPrefix: k
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
new file mode 100644
index 00..f3560e4e50b9ed
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
@@ -0,0 +1 @@
+const int global_const = 5;
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/

[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Dmitry Polukhin (dmpolukhin)


Changes

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools

---
Full diff: https://github.com/llvm/llvm-project/pull/81985.diff


5 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
(+5-2) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 (+1) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 (+4) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 (+1) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
 (+15) 


``diff
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 5db9e99ab23708..335c3de25b861b 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1408,13 +1408,16 @@ const IdentifierNamingCheck::FileStyle &
 IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
   if (!GetConfigPerFile)
 return *MainFileStyle;
-  StringRef Parent = llvm::sys::path::parent_path(FileName);
+
+  SmallString<128> RealFileName;
+  llvm::sys::fs::real_path(FileName, RealFileName);
+  StringRef Parent = llvm::sys::path::parent_path(RealFileName);
   auto Iter = NamingStylesCache.find(Parent);
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
   llvm::StringRef CheckName = getID();
-  ClangTidyOptions Options = Context->getOptionsForFile(FileName);
+  ClangTidyOptions Options = Context->getOptionsForFile(RealFileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(
 Parent,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
new file mode 12
index 00..de218fbfa4662a
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
@@ -0,0 +1 @@
+../include/test.h
\ No newline at end of file
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
new file mode 100644
index 00..296550f3aab1eb
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
@@ -0,0 +1,4 @@
+Checks: readability-identifier-naming
+CheckOptions:
+  readability-identifier-naming.GlobalConstantCase: CamelCase
+  readability-identifier-naming.GlobalConstantPrefix: k
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
new file mode 100644
index 00..f3560e4e50b9ed
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
@@ -0,0 +1 @@
+const int global_const = 5;
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
new file mode 100644
index 00..72926bff908df8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
@@ -0,0 +1,15 @@
+// Specify `-std=c++20` to run test only once becuase test expects changes
+// in the header file so it fails if runs multiple times with different
+// `-std` flags as check_clang_tidy doesn by default.
+//
+// RUN: rm -rf %T/symlink
+// RUN: cp -r %S/Inputs/identifier-naming/symlink %T/symlink
+// RUN: %check_clang_tidy -std=c++20 %s readability-identifier-naming %t -- 
--header-filter="test.h" 
--config-file=%S/Inputs/identifier-naming/symlink/include/.clang-tidy -- -I 
%T/symlink/build
+
+#include "test.h"
+
+int foo() {
+return global_const;
+// CHECK-MESSAGES: warning: invalid case style for global constant 
'

[clang] [clang] Implement `__is_layout_compatible` (PR #81506)

2024-02-16 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/81506

>From 52b239153b2fc4f52e889ad2044daa6ed5cbc836 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Mon, 12 Feb 2024 17:44:38 +0300
Subject: [PATCH 1/8] Initial implementation

---
 clang/include/clang/Basic/TokenKinds.def |  1 +
 clang/include/clang/Sema/Sema.h  |  2 +
 clang/lib/Parse/ParseDeclCXX.cpp |  1 +
 clang/lib/Parse/ParseExpr.cpp|  1 +
 clang/lib/Sema/SemaChecking.cpp  |  4 ++
 clang/lib/Sema/SemaExprCXX.cpp   |  3 +
 clang/test/SemaCXX/type-traits.cpp   | 77 
 7 files changed, 89 insertions(+)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 23817cde7a9354..112bfe8b23c2c0 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -520,6 +520,7 @@ TYPE_TRAIT_1(__is_trivially_copyable, IsTriviallyCopyable, 
KEYCXX)
 TYPE_TRAIT_1(__is_union, IsUnion, KEYCXX)
 TYPE_TRAIT_1(__has_unique_object_representations,
  HasUniqueObjectRepresentations, KEYCXX)
+TYPE_TRAIT_2(__is_layout_compatible, IsLayoutCompatible, KEYCXX)
 
 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) KEYWORD(__##Trait, KEYCXX)
 #include "clang/Basic/TransformTypeTraits.def"
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 851560f759f0e4..ddeba328749653 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14040,6 +14040,8 @@ class Sema final {
   bool SemaValueIsRunOfOnes(CallExpr *TheCall, unsigned ArgNum);
 
 public:
+  bool SemaIsLayoutCompatible(QualType T1, QualType T2);
+  
   // Used by C++ template instantiation.
   ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
   ExprResult SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo,
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 79928ddb5af599..c9360981c1c1e4 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1717,6 +1717,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   tok::kw___is_fundamental,
   tok::kw___is_integral,
   tok::kw___is_interface_class,
+  tok::kw___is_layout_compatible,
   tok::kw___is_literal,
   tok::kw___is_lvalue_expr,
   tok::kw___is_lvalue_reference,
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 52cebdb6f64bac..db21a7f1e9e368 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1114,6 +1114,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   REVERTIBLE_TYPE_TRAIT(__is_fundamental);
   REVERTIBLE_TYPE_TRAIT(__is_integral);
   REVERTIBLE_TYPE_TRAIT(__is_interface_class);
+  REVERTIBLE_TYPE_TRAIT(__is_layout_compatible);
   REVERTIBLE_TYPE_TRAIT(__is_literal);
   REVERTIBLE_TYPE_TRAIT(__is_lvalue_expr);
   REVERTIBLE_TYPE_TRAIT(__is_lvalue_reference);
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 71e6e7230fc455..8aa744873f3704 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -19150,6 +19150,10 @@ static bool isLayoutCompatible(ASTContext &C, QualType 
T1, QualType T2) {
   return false;
 }
 
+bool Sema::SemaIsLayoutCompatible(QualType T1, QualType T2) {
+  return isLayoutCompatible(getASTContext(), T1, T2);
+}
+
 //===--- CHECK: pointer_with_type_tag attribute: datatypes should match //
 
 /// Given a type tag expression find the type tag itself.
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 246d2313e089f3..b279c367342fce 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5922,6 +5922,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait 
BTT, QualType LhsT,
 
 llvm_unreachable("unhandled type trait");
 return false;
+  }
+  case BTT_IsLayoutCompatible: {
+return Self.SemaIsLayoutCompatible(LhsT, RhsT);
   }
 default: llvm_unreachable("not a BTT");
   }
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 5659594577111e..f50bedc275359b 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -1558,6 +1558,83 @@ void is_standard_layout()
   int t71[F(__is_standard_layout(HasEmptyIndirectBaseAsSecondUnionMember))];
 }
 
+struct CStruct2 {
+  int one;
+  int two;
+};
+
+struct CEmptyStruct2 {};
+
+struct CppEmptyStruct2 : CStruct2 {};
+struct CppStructStandard2 : CEmptyStruct2 {
+  int three;
+  int four;
+};
+struct CppStructNonStandardByBase2 : CStruct2 {
+  int three;
+  int four;
+};
+struct CppStructNonStandardByVirt2 : CStruct2 {
+  virtual void method() {}
+};
+struct CppStructNonStandardByMemb2 : CStruct2 {
+  CppStructNonStandardByVirt member;
+};
+struct CppStructNonStandardB

[clang] [clang] Implement `__is_layout_compatible` (PR #81506)

2024-02-16 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-16 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

> > I wonder if this should be a part of the Targets in CodeGen instead of here?
> 
> Hrm, this is a bad idea as the rest of mangling is in AST, but having 
> mangling outside of AST seems to be the problem here.

I could move the logic under ABIInfo which is already referencing AST. 
Overrides of ABIInfo are provided in CodeGen/Targets as you suggested. It 
doesn't seem a bad idea to me.

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


[clang] 8c1c94e - [clang-format] Support of TableGen basic format restrictions. (#81611)

2024-02-16 Thread via cfe-commits

Author: Hirofumi Nakamura
Date: 2024-02-16T21:35:45+09:00
New Revision: 8c1c94e8c15855ad41cfec83af61a27740e6941f

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

LOG: [clang-format] Support of TableGen basic format restrictions. (#81611)

- Allow/force to break the line or not.
- Allow/force to insert space or not.

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestTableGen.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 159d130cb67332..97500ee41259f0 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -821,6 +821,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   !CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
+  Previous.isNot(TT_TableGenDAGArgOpener) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (Current.isNot(TT_LineComment) ||
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) {
@@ -1250,7 +1251,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
 return CurrentState.Indent;
   }
   if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
-   (Current.is(tok::greater) && Style.isProto())) &&
+   (Current.is(tok::greater) && (Style.isProto() || Style.isTableGen( 
&&
   State.Stack.size() > 1) {
 if (Current.closesBlockOrBlockTypeList(Style))
   return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
@@ -1278,6 +1279,12 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) {
 return State.Stack[State.Stack.size() - 2].LastSpace;
   }
+  // When DAGArg closer exists top of line, it should be aligned in the similar
+  // way as function call above.
+  if (Style.isTableGen() && Current.is(TT_TableGenDAGArgCloser) &&
+  State.Stack.size() > 1) {
+return State.Stack[State.Stack.size() - 2].LastSpace;
+  }
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   (Current.is(tok::r_paren) ||
(Current.is(tok::r_brace) && Current.MatchingParen &&
@@ -1696,7 +1703,9 @@ void 
ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
 (!Previous || Previous->isNot(tok::kw_return) ||
  (Style.Language != FormatStyle::LK_Java && PrecedenceLevel > 0)) &&
 (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
- PrecedenceLevel != prec::Comma || Current.NestingLevel == 0)) {
+ PrecedenceLevel != prec::Comma || Current.NestingLevel == 0) &&
+(!Style.isTableGen() ||
+ (Previous && Previous->is(TT_TableGenDAGArgListComma {
   NewParenState.Indent = std::max(
   std::max(State.Column, NewParenState.Indent), 
CurrentState.LastSpace);
 }
@@ -1942,6 +1951,7 @@ void 
ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
   (Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) ||
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
State.NextToken->is(TT_TemplateCloser) ||
+   State.NextToken->is(TT_TableGenListCloser) ||
(Current.is(tok::greater) && Current.is(TT_DictLiteral {
 State.Stack.pop_back();
   }

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index ac876bf4442e95..af6e364147ef53 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5072,7 +5072,38 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
  Left.endsSequence(tok::greatergreater, tok::l_brace))) {
   return false;
 }
+  } else if (Style.isTableGen()) {
+// Avoid to connect [ and {. [{ is start token of multiline string.
+if (Left.is(tok::l_square) && Right.is(tok::l_brace))
+  return true;
+if (Left.is(tok::r_brace) && Right.is(tok::r_square))
+  return true;
+// Do not insert around colon in DAGArg and cond operator.
+if (Right.is(TT_TableGenDAGArgListColon) ||
+Left.is(TT_TableGenDAGArgListColon)) {
+  return false;
+}
+if (Right.is(TT_TableGenCondOperatorColon))
+  return false;
+// Do not insert bang operators and consequent openers.
+if (Right.isOneOf(tok::l_paren, tok::less) &&
+Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator)) {
+  return false;
+}
+// Trailing paste requires spa

[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-16 Thread Hirofumi Nakamura via cfe-commits

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


[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-16 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Thank you very much!

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


[clang] [clang] Implement `__is_layout_compatible` (PR #81506)

2024-02-16 Thread Aaron Ballman via cfe-commits


@@ -1558,6 +1558,89 @@ void is_standard_layout()
   int t71[F(__is_standard_layout(HasEmptyIndirectBaseAsSecondUnionMember))];
 }
 
+struct CStruct2 {
+  int one;
+  int two;
+};
+
+struct CEmptyStruct2 {};
+
+struct CppEmptyStruct2 : CStruct2 {};
+struct CppStructStandard2 : CEmptyStruct2 {
+  int three;
+  int four;
+};
+struct CppStructNonStandardByBase2 : CStruct2 {
+  int three;
+  int four;
+};
+struct CppStructNonStandardByVirt2 : CStruct2 {
+  virtual void method() {}
+};
+struct CppStructNonStandardByMemb2 : CStruct2 {
+  CppStructNonStandardByVirt member;
+};
+struct CppStructNonStandardByProt2 : CStruct2 {
+  int five;
+protected:
+  int six;
+};
+struct CppStructNonStandardByVirtBase2 : virtual CStruct2 {
+};
+struct CppStructNonStandardBySameBase2 : CEmptyStruct2 {
+  CEmptyStruct member;
+};
+struct CppStructNonStandardBy2ndVirtBase2 : CEmptyStruct2 {
+  CEmptyStruct member;
+};
+
+struct CStructWithQualifiers {
+  const int one;
+  volatile int two;
+};
+
+struct CStructNoUniqueAddress {
+  int one;
+  [[no_unique_address]] int two;
+};
+
+struct CStructNoUniqueAddress2 {
+  int one;
+  [[no_unique_address]] int two;
+};
+
+struct CStructAlignment {
+  int one;
+  alignas(16) int two;
+};
+
+struct CStructIncomplete;
+
+void is_layout_compatible()
+{
+  static_assert(__is_layout_compatible(void, void), "");
+  static_assert(__is_layout_compatible(int, int), "");
+  static_assert(__is_layout_compatible(int[], int[]), "");
+  static_assert(__is_layout_compatible(int[2], int[2]), "");
+  static_assert(__is_layout_compatible(CStruct, CStruct2), "");
+  static_assert(__is_layout_compatible(CEmptyStruct, CEmptyStruct2), "");
+  static_assert(__is_layout_compatible(CppEmptyStruct, CppEmptyStruct2), "");
+  static_assert(__is_layout_compatible(CppStructStandard, CppStructStandard2), 
"");
+  static_assert(!__is_layout_compatible(CppStructNonStandardByBase, 
CppStructNonStandardByBase2), "");
+  static_assert(!__is_layout_compatible(CppStructNonStandardByVirt, 
CppStructNonStandardByVirt2), "");
+  static_assert(!__is_layout_compatible(CppStructNonStandardByMemb, 
CppStructNonStandardByMemb2), "");
+  static_assert(!__is_layout_compatible(CppStructNonStandardByProt, 
CppStructNonStandardByProt2), "");
+  static_assert(!__is_layout_compatible(CppStructNonStandardByVirtBase, 
CppStructNonStandardByVirtBase2), "");
+  static_assert(!__is_layout_compatible(CppStructNonStandardBySameBase, 
CppStructNonStandardBySameBase2), "");
+  static_assert(!__is_layout_compatible(CppStructNonStandardBy2ndVirtBase, 
CppStructNonStandardBy2ndVirtBase2), "");
+  static_assert(!__is_layout_compatible(CStruct, CStructWithQualifiers), ""); 
// FIXME: this is CWG1719
+  static_assert(__is_layout_compatible(CStruct, CStructNoUniqueAddress) == 
bool(__has_cpp_attribute(no_unique_address)), ""); // FIXME: this is CWG2759
+  static_assert(__is_layout_compatible(CStructNoUniqueAddress, 
CStructNoUniqueAddress2) == bool(__has_cpp_attribute(no_unique_address)), ""); 
// FIXME: this is CWG2759
+  static_assert(__is_layout_compatible(CStruct, CStructAlignment), "");
+  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete), 
"");
+  static_assert(!__is_layout_compatible(CStruct, CStructIncomplete), "");
+}

AaronBallman wrote:

> We don't issue any, as far as I can see. And I don't think we can when the 
> types are the same, ignoring cv qualifiers:

That's a bug, see 
https://eel.is/c++draft/tab:meta.rel#row-6-column-3-sentence-1: "T and U shall 
be complete types, cv void, or arrays of unknown bound."

but also: https://eel.is/c++draft/tab:meta.rel#row-6-column-3-sentence-1and 
http://eel.is/c++draft/class.mem#general-23 -- you can't test for layout 
compatibility if the class type is not complete because you don't know the 
members. So we should accept `void` but not `struct NeverDefined`.

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


[clang] [C++] Fix parsing of _Alignas in local declarations (PR #81915)

2024-02-16 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

CI came back green (failures are unrelated to this patch) and the changes are 
trivial, so landing as a code owner (I'll happily address any feedback 
post-commit).

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


[clang] c2fea4c - [C++] Fix parsing of _Alignas in local declarations (#81915)

2024-02-16 Thread via cfe-commits

Author: Aaron Ballman
Date: 2024-02-16T07:43:55-05:00
New Revision: c2fea4cf38991669030f4190d17b645cec27a7c0

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

LOG: [C++] Fix parsing of _Alignas in local declarations (#81915)

We support '_Alignas' from C11 as an extension in C++. However, we were
not correctly parsing its use in local variable declarations. This patch
addresses that issue.

Added: 
clang/test/SemaCXX/_Alignas.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseTentative.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 608d855abf5d06..16f79a349c20c8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -259,6 +259,9 @@ Bug Fixes to C++ Support
   some of (`#80510 `).
 - Clang now ignores top-level cv-qualifiers on function parameters in template 
partial orderings.
   (`#75404 `_)
+- No longer reject valid use of the ``_Alignas`` specifier when declaring a
+  local variable, which is supported as a C11 extension in C++. Previously, it
+  was only accepted at namespace scope but not at local function scope.
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Parse/ParseTentative.cpp 
b/clang/lib/Parse/ParseTentative.cpp
index 299e46f4be9a2c..ea17c3e3252ec2 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -1842,6 +1842,9 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext 
AllowImplicitTypename,
 #include "clang/Basic/TransformTypeTraits.def"
 return TPResult::True;
 
+  // C11 _Alignas
+  case tok::kw__Alignas:
+return TPResult::True;
   // C11 _Atomic
   case tok::kw__Atomic:
 return TPResult::True;

diff  --git a/clang/test/SemaCXX/_Alignas.cpp b/clang/test/SemaCXX/_Alignas.cpp
new file mode 100644
index 00..4e892745580ed6
--- /dev/null
+++ b/clang/test/SemaCXX/_Alignas.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify=expected,cpp
+// RUN: %clang_cc1 -x c %s -fsyntax-only -verify=expected,c
+
+// Ensure that we correctly parse _Alignas as an extension in C++.
+_Alignas(64) int i1;
+_Alignas(long long) int i2;
+int volatile _Alignas(64) i3; // Test strange ordering
+
+void foo(void) {
+  // We previously rejected these valid declarations.
+  _Alignas(8) char i4;
+  _Alignas(char) char i5;
+
+  (void)(int _Alignas(64))0; // expected-warning {{'_Alignas' attribute 
ignored when parsing type}}
+  // FIXME: C and C++ should both diagnose the same way, as being ignored.
+  (void)(_Alignas(64) int)0; // c-error {{expected expression}} \
+cpp-warning {{'_Alignas' attribute ignored 
when parsing type}}
+}
+
+struct S {
+  _Alignas(int) int i;
+  _Alignas(64) int j;
+};
+
+void bar(_Alignas(8) char c1, char _Alignas(char) c2); // expected-error 2 
{{'_Alignas' attribute cannot be applied to a function parameter}}



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


[clang] [C++] Fix parsing of _Alignas in local declarations (PR #81915)

2024-02-16 Thread Aaron Ballman via cfe-commits

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


[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal (PR #81727)

2024-02-16 Thread Garvit Gupta via cfe-commits

quic-garvgupt wrote:

Hi @asb, since Petr already gave a good-ahead to this patch in the meeting, let 
me know if we can merge this PR if there are no new changes need to be made

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #67592)

2024-02-16 Thread Aaron Ballman via cfe-commits

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #67592)

2024-02-16 Thread Aaron Ballman via cfe-commits


@@ -1635,6 +1635,14 @@ void TypePrinter::printElaboratedBefore(const 
ElaboratedType *T,
 if (T->getKeyword() != ElaboratedTypeKeyword::None)
   OS << " ";
 NestedNameSpecifier *Qualifier = T->getQualifier();
+if (Policy.FullyQualifiedName) {

AaronBallman wrote:

`FullyQualifiedName` controls printing of identifier qualification, not 
elaboration of type names. IOW, it controls printing `Bar` vs `Foo::Bar` rather 
than `B` vs `struct B`.

I think you want to be looking at `!SuppressTagKeyword` right?

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #67592)

2024-02-16 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Precommit CI has relevant failures.

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


[clang] 17d8a84 - [clang][Interp] Fix handling PointerToIntegral casts

2024-02-16 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-16T14:31:42+01:00
New Revision: 17d8a84c32b7a3ecc3080c33fe2c780f029691a3

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

LOG: [clang][Interp] Fix handling PointerToIntegral casts

We need to always emit the diagnostic, but still do the cast.
This is also what the current interpreter does.

Added: 


Modified: 
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 2a51f18adf02c5..51434d65e2f53b 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -533,17 +533,6 @@ bool CheckPure(InterpState &S, CodePtr OpPC, const 
CXXMethodDecl *MD) {
   return false;
 }
 
-bool CheckPotentialReinterpretCast(InterpState &S, CodePtr OpPC,
-   const Pointer &Ptr) {
-  if (!S.inConstantContext())
-return true;
-
-  const SourceInfo &E = S.Current->getSource(OpPC);
-  S.CCEDiag(E, diag::note_constexpr_invalid_cast)
-  << 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
-  return false;
-}
-
 bool CheckFloatResult(InterpState &S, CodePtr OpPC, const Floating &Result,
   APFloat::opStatus Status) {
   const SourceInfo &E = S.Current->getSource(OpPC);

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 5bbb9f169a800e..344f523ed855a2 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -113,10 +113,6 @@ bool CheckThis(InterpState &S, CodePtr OpPC, const Pointer 
&This);
 /// Checks if a method is pure virtual.
 bool CheckPure(InterpState &S, CodePtr OpPC, const CXXMethodDecl *MD);
 
-/// Checks if reinterpret casts are legal in the current context.
-bool CheckPotentialReinterpretCast(InterpState &S, CodePtr OpPC,
-   const Pointer &Ptr);
-
 /// Sets the given integral value to the pointer, which is of
 /// a std::{weak,partial,strong}_ordering type.
 bool SetThreeWayComparisonField(InterpState &S, CodePtr OpPC,
@@ -1722,8 +1718,9 @@ template ::T>
 bool CastPointerIntegral(InterpState &S, CodePtr OpPC) {
   const Pointer &Ptr = S.Stk.pop();
 
-  if (!CheckPotentialReinterpretCast(S, OpPC, Ptr))
-return false;
+  const SourceInfo &E = S.Current->getSource(OpPC);
+  S.CCEDiag(E, diag::note_constexpr_invalid_cast)
+  << 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
 
   S.Stk.push(T::from(Ptr.getIntegerRepresentation()));
   return true;



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


[clang] [llvm] [SROA] Use !tbaa instead of !tbaa.struct if op matches field. (PR #81289)

2024-02-16 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/81289

>From e6de9f21b162c57dd09cb4de3147b7ab09ef8681 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Fri, 9 Feb 2024 13:29:19 +
Subject: [PATCH 1/5] [TBAA] Extract logic to use TBAA tag for field of
 !tbaa.struct (NFC).

---
 llvm/include/llvm/IR/Metadata.h   |  5 +
 llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp  | 14 ++
 .../Transforms/InstCombine/InstCombineCalls.cpp   | 15 +--
 3 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h
index db1f44fea3b459..6f23ac44dee968 100644
--- a/llvm/include/llvm/IR/Metadata.h
+++ b/llvm/include/llvm/IR/Metadata.h
@@ -844,6 +844,11 @@ struct AAMDNodes {
   /// together. Different from `merge`, where different locations should
   /// overlap each other, `concat` puts non-overlapping locations together.
   AAMDNodes concat(const AAMDNodes &Other) const;
+
+  /// Create a new AAMDNode for accessing \p AccessSize bytes of this AAMDNode.
+  /// If his AAMDNode has !tbaa.struct and \p AccessSize matches the size of 
the
+  /// field at offset 0, get the TBAA tag describing the accessed field.
+  AAMDNodes adjustForAccess(unsigned AccessSize);
 };
 
 // Specialize DenseMapInfo for AAMDNodes.
diff --git a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp 
b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
index e4dc1a867f6f0c..edc08cde686f1f 100644
--- a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
@@ -817,3 +817,17 @@ MDNode *AAMDNodes::extendToTBAA(MDNode *MD, ssize_t Len) {
   ConstantAsMetadata::get(ConstantInt::get(PreviousSize->getType(), Len));
   return MDNode::get(MD->getContext(), NextNodes);
 }
+
+AAMDNodes AAMDNodes::adjustForAccess(unsigned AccessSize) {
+  AAMDNodes New = *this;
+  MDNode *M = New.TBAAStruct;
+  New.TBAAStruct = nullptr;
+  if (M && M->getNumOperands() == 3 && M->getOperand(0) &&
+  mdconst::hasa(M->getOperand(0)) &&
+  mdconst::extract(M->getOperand(0))->isZero() &&
+  M->getOperand(1) && mdconst::hasa(M->getOperand(1)) &&
+  mdconst::extract(M->getOperand(1))->getValue() == 
AccessSize &&
+  M->getOperand(2) && isa(M->getOperand(2)))
+New.TBAA = cast(M->getOperand(2));
+  return New;
+}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index ed5d44757fbeb6..56d1259e955196 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -172,20 +172,7 @@ Instruction 
*InstCombinerImpl::SimplifyAnyMemTransfer(AnyMemTransferInst *MI) {
 
   // If the memcpy has metadata describing the members, see if we can get the
   // TBAA tag describing our copy.
-  AAMDNodes AACopyMD = MI->getAAMetadata();
-
-  if (MDNode *M = AACopyMD.TBAAStruct) {
-AACopyMD.TBAAStruct = nullptr;
-if (M->getNumOperands() == 3 && M->getOperand(0) &&
-mdconst::hasa(M->getOperand(0)) &&
-mdconst::extract(M->getOperand(0))->isZero() &&
-M->getOperand(1) &&
-mdconst::hasa(M->getOperand(1)) &&
-mdconst::extract(M->getOperand(1))->getValue() ==
-Size &&
-M->getOperand(2) && isa(M->getOperand(2)))
-  AACopyMD.TBAA = cast(M->getOperand(2));
-  }
+  AAMDNodes AACopyMD = MI->getAAMetadata().adjustForAccess(Size);
 
   Value *Src = MI->getArgOperand(1);
   Value *Dest = MI->getArgOperand(0);

>From 99cf032dfabb21b820559bae61d2354e56336fdd Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Fri, 9 Feb 2024 16:25:32 +
Subject: [PATCH 2/5] [TBAA] Only clear TBAAStruct if field can be extracted.

Retain TBAAStruct if we fail to match the access to a single field. All
users at the moment use this when using the full size of the original
access. SROA also retains the original TBAAStruct when accessing parts
at offset 0.

Motivation for this and follow-on patches is to improve codegen for
libc++, where using memcpy limits optimizations, like vectorization for
code iteration over std::vector>:
https://godbolt.org/z/f3vqYos3c

Depends on https://github.com/llvm/llvm-project/pull/81284
---
 llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp   | 8 +---
 llvm/test/Transforms/InstCombine/struct-assign-tbaa.ll | 5 +++--
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp 
b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
index edc08cde686f1f..bfd70414c0340c 100644
--- a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
@@ -821,13 +821,15 @@ MDNode *AAMDNodes::extendToTBAA(MDNode *MD, ssize_t Len) {
 AAMDNodes AAMDNodes::adjustForAccess(unsigned AccessSize) {
   AAMDNodes New = *this;
   MDNode *M = New.TBAAStruct;
-  New.TBAAStruct = nullptr;
   if (M && M->getNumOperands() == 3 && M->getOperand(0) &&
   mdconst::hasa

[clang] 53c0e80 - [SROA] Use !tbaa instead of !tbaa.struct if op matches field. (#81289)

2024-02-16 Thread via cfe-commits

Author: Florian Hahn
Date: 2024-02-16T13:45:01Z
New Revision: 53c0e809faacfffce097c7d220836f4f41b3979a

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

LOG: [SROA] Use !tbaa instead of !tbaa.struct if op matches field. (#81289)

If a split memory access introduced by SROA accesses precisely a single
field of the original operation's !tbaa.struct, use the !tbaa tag for
the accessed field directly instead of the full !tbaa.struct.

InstCombine already had a similar logic.

Motivation for this and follow-on patches is to improve codegen for
libc++, where using memcpy limits optimizations, like vectorization for
code iteration over std::vector>:
https://godbolt.org/z/f3vqYos3c

Depends on https://github.com/llvm/llvm-project/pull/81285.

Added: 


Modified: 
clang/test/CodeGen/aarch64-ABI-align-packed.c
llvm/include/llvm/IR/Metadata.h
llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/test/Transforms/SROA/tbaa-struct2.ll
llvm/test/Transforms/SROA/tbaa-struct3.ll

Removed: 




diff  --git a/clang/test/CodeGen/aarch64-ABI-align-packed.c 
b/clang/test/CodeGen/aarch64-ABI-align-packed.c
index 93b81d50261bf8..2b029f64589567 100644
--- a/clang/test/CodeGen/aarch64-ABI-align-packed.c
+++ b/clang/test/CodeGen/aarch64-ABI-align-packed.c
@@ -59,7 +59,7 @@ struct non_packed_struct gs_non_packed_struct;
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[S_NON_PACKED_STRUCT_COERCE_FCA_0_EXTRACT:%.*]] = 
extractvalue [1 x <8 x i16>] [[S_NON_PACKED_STRUCT_COERCE]], 0
 // CHECK-NEXT:store double [[D8]], ptr @gd, align 8, !tbaa 
[[TBAA2:![0-9]+]]
-// CHECK-NEXT:store <8 x i16> 
[[S_NON_PACKED_STRUCT_COERCE_FCA_0_EXTRACT]], ptr @gs_non_packed_struct, align 
16, !tbaa.struct [[TBAA_STRUCT6:![0-9]+]]
+// CHECK-NEXT:store <8 x i16> 
[[S_NON_PACKED_STRUCT_COERCE_FCA_0_EXTRACT]], ptr @gs_non_packed_struct, align 
16, !tbaa [[TBAA6:![0-9]+]]
 // CHECK-NEXT:ret void
 __attribute__((noinline)) void named_arg_non_packed_struct(double d0, double 
d1, double d2, double d3,
  double d4, double d5, double d6, double d7,
@@ -114,7 +114,7 @@ struct packed_struct gs_packed_struct;
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[S_PACKED_STRUCT_COERCE_FCA_0_EXTRACT:%.*]] = extractvalue 
[1 x <8 x i16>] [[S_PACKED_STRUCT_COERCE]], 0
 // CHECK-NEXT:store double [[D8]], ptr @gd, align 8, !tbaa [[TBAA2]]
-// CHECK-NEXT:store <8 x i16> [[S_PACKED_STRUCT_COERCE_FCA_0_EXTRACT]], 
ptr @gs_packed_struct, align 1, !tbaa.struct [[TBAA_STRUCT6]]
+// CHECK-NEXT:store <8 x i16> [[S_PACKED_STRUCT_COERCE_FCA_0_EXTRACT]], 
ptr @gs_packed_struct, align 1, !tbaa [[TBAA6]]
 // CHECK-NEXT:ret void
 __attribute__((noinline)) void named_arg_packed_struct(double d0, double d1, 
double d2, double d3,
  double d4, double d5, double d6, double d7,
@@ -169,7 +169,7 @@ struct packed_member gs_packed_member;
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[S_PACKED_MEMBER_COERCE_FCA_0_EXTRACT:%.*]] = extractvalue 
[1 x <8 x i16>] [[S_PACKED_MEMBER_COERCE]], 0
 // CHECK-NEXT:store double [[D8]], ptr @gd, align 8, !tbaa [[TBAA2]]
-// CHECK-NEXT:store <8 x i16> [[S_PACKED_MEMBER_COERCE_FCA_0_EXTRACT]], 
ptr @gs_packed_member, align 1, !tbaa.struct [[TBAA_STRUCT6]]
+// CHECK-NEXT:store <8 x i16> [[S_PACKED_MEMBER_COERCE_FCA_0_EXTRACT]], 
ptr @gs_packed_member, align 1, !tbaa [[TBAA6]]
 // CHECK-NEXT:ret void
 __attribute__((noinline)) void named_arg_packed_member(double d0, double d1, 
double d2, double d3,
  double d4, double d5, double d6, double d7,
@@ -224,7 +224,7 @@ struct aligned_struct_8 gs_aligned_struct_8;
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[S_ALIGNED_STRUCT_8_COERCE_FCA_0_EXTRACT:%.*]] = 
extractvalue [1 x <8 x i16>] [[S_ALIGNED_STRUCT_8_COERCE]], 0
 // CHECK-NEXT:store double [[D8]], ptr @gd, align 8, !tbaa [[TBAA2]]
-// CHECK-NEXT:store <8 x i16> [[S_ALIGNED_STRUCT_8_COERCE_FCA_0_EXTRACT]], 
ptr @gs_aligned_struct_8, align 16, !tbaa.struct [[TBAA_STRUCT6]]
+// CHECK-NEXT:store <8 x i16> [[S_ALIGNED_STRUCT_8_COERCE_FCA_0_EXTRACT]], 
ptr @gs_aligned_struct_8, align 16, !tbaa [[TBAA6]]
 // CHECK-NEXT:ret void
 __attribute__((noinline)) void named_arg_aligned_struct_8(double d0, double 
d1, double d2, double d3,
  double d4, double d5, double d6, double d7,
@@ -279,7 +279,7 @@ struct aligned_member_8 gs_aligned_member_8;
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[S_ALIGNED_MEMBER_8_COERCE_FCA_0_EXTRACT:%.*]] = 
extractvalue [1 x <8 x i16>] [[S_ALIGNED_MEMBER_8_COERCE]], 0
 // CHECK-NEXT:store double [[D8]], ptr @gd, align 8, !tbaa [[TBAA2]]
-// CHECK-NEXT:store <8 x i16> [[S_ALIGNED_MEMBER_

[clang] [llvm] [SROA] Use !tbaa instead of !tbaa.struct if op matches field. (PR #81289)

2024-02-16 Thread Florian Hahn via cfe-commits

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


[clang] [clang][analyzer] Change modeling of 'fileno' in checkers. (PR #81842)

2024-02-16 Thread via cfe-commits

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


[clang] [clang][analyzer] Change modeling of 'fileno' in checkers. (PR #81842)

2024-02-16 Thread via cfe-commits

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

LGTM with some low priority bikeshedding in a comment.

By the way it would be good to rebase this change onto your other commit #79312 
(that was merged a few hours ago) and use the "toolbox" introduced there if 
that's possible.

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


[clang] [clang][analyzer] Change modeling of 'fileno' in checkers. (PR #81842)

2024-02-16 Thread via cfe-commits


@@ -1404,6 +1486,47 @@ void StreamChecker::evalFeofFerror(const FnDescription 
*Desc,
   }
 }
 
+void StreamChecker::evalFileno(const FnDescription *Desc, const CallEvent 
&Call,
+   CheckerContext &C) const {
+  // Fileno should fail only if the passed pointer is invalid.
+  // Some of the preconditions are checked already in preDefault.
+  // Here we can assume that the operation does not fail.
+  // An added failure case causes many unexpected warnings because a file 
number
+  // becomes -1 that is not expected by the program.
+  // The stream error states are not modified by 'fileno', and not the 'errno'.
+  // (To ensure that errno is not changed, this evalCall is needed to not
+  // invalidate 'errno' like in a default case.)
+  ProgramStateRef State = C.getState();
+  SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol();
+  if (!StreamSym)
+return;
+
+  const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *SS = State->get(StreamSym);
+  if (!SS)
+return;
+
+  assertStreamStateOpened(SS);
+
+  SValBuilder &SVB = C.getSValBuilder();
+  NonLoc RetVal = makeRetVal(C, CE).castAs();
+  State = State->BindExpr(CE, C.getLocationContext(), RetVal);
+  auto Cond =
+  SVB.evalBinOp(State, BO_GE, RetVal, 
SVB.makeZeroVal(Call.getResultType()),

NagyDonat wrote:

It's a nice trick that you're creating the zero in the type of the other side 
to avoid surprising type conversion.

There's a chance that I can borrow this solution to handle tricky issues in 
ArrayBoundCheckerV2 :smile: 

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


[clang] [clang][analyzer] Change modeling of 'fileno' in checkers. (PR #81842)

2024-02-16 Thread via cfe-commits


@@ -1404,6 +1486,47 @@ void StreamChecker::evalFeofFerror(const FnDescription 
*Desc,
   }
 }
 
+void StreamChecker::evalFileno(const FnDescription *Desc, const CallEvent 
&Call,
+   CheckerContext &C) const {
+  // Fileno should fail only if the passed pointer is invalid.
+  // Some of the preconditions are checked already in preDefault.
+  // Here we can assume that the operation does not fail.
+  // An added failure case causes many unexpected warnings because a file 
number
+  // becomes -1 that is not expected by the program.
+  // The stream error states are not modified by 'fileno', and not the 'errno'.
+  // (To ensure that errno is not changed, this evalCall is needed to not
+  // invalidate 'errno' like in a default case.)

NagyDonat wrote:

```suggestion
  // Here we assume that the operation does not fail, because we introduced a
  // separate branch where fileno() returns -1, then it would cause many
  // unexpected and unwanted warnings in situations where fileno() is called
  // on vaild streams.
  // The stream error states are not modified by 'fileno', and 'errno' is also
  // left unchanged (so this evalCall does not invalidate it).
```

I felt that this comment is a bit difficult to understand and composed a 
reworded alternative. Of course, this is a very subjective matter and English 
isn't my first language, so feel free to bikeshed this and/or override my 
suggestions.

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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-16 Thread zhijian lin via cfe-commits

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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-16 Thread zhijian lin via cfe-commits

https://github.com/diggerlin updated 
https://github.com/llvm/llvm-project/pull/80069

>From a82a60e3af041f50b833d241a284e09a883e849a Mon Sep 17 00:00:00 2001
From: zhijian 
Date: Tue, 30 Jan 2024 15:13:39 -0500
Subject: [PATCH 1/4] support builtin_cpu_is() for aix

---
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +
 clang/lib/Basic/Targets/PPC.cpp   | 13 ++-
 clang/lib/Basic/Targets/PPC.h | 12 ++-
 clang/lib/CodeGen/CGBuiltin.cpp   | 57 -
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/test/CodeGen/aix-builtin-cpu-is.c   | 83 +++
 clang/test/Sema/aix-builtin-cpu-unsupports.c  |  6 ++
 .../llvm/TargetParser/PPCTargetParser.def | 53 
 8 files changed, 225 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGen/aix-builtin-cpu-is.c
 create mode 100644 clang/test/Sema/aix-builtin-cpu-unsupports.c

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1c0ebbe4e68343..139a90a3020684 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10347,6 +10347,8 @@ def err_x86_builtin_tile_arg_duplicate : Error<
 
 def err_builtin_target_unsupported : Error<
   "builtin is not supported on this target">;
+def err_builtin_aix_os_unsupported : Error<
+  "this builtin is available only in AIX 7.2 and later operating systems">;
 def err_builtin_longjmp_unsupported : Error<
   "__builtin_longjmp is not supported for the current target">;
 def err_builtin_setjmp_unsupported : Error<
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 8c891ccdeb59d4..c9cf7435334402 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -904,8 +904,17 @@ bool PPCTargetInfo::validateCpuSupports(StringRef 
FeatureStr) const {
 }
 
 bool PPCTargetInfo::validateCpuIs(StringRef CPUName) const {
+  llvm::Triple Triple = getTriple();
+  if (Triple.isOSLinux()) {
 #define PPC_LNX_CPU(NAME, NUM) .Case(NAME, true)
-  return llvm::StringSwitch(CPUName)
+return llvm::StringSwitch(CPUName)
 #include "llvm/TargetParser/PPCTargetParser.def"
-  .Default(false);
+.Default(false);
+  } else if (Triple.isOSAIX()) {
+#define PPC_AIX_CPU(NAME, SUPPORT, INDEX, MASK, OP, VALUE) .Case(NAME, true)
+return llvm::StringSwitch(CPUName)
+#include "llvm/TargetParser/PPCTargetParser.def"
+.Default(false);
+  }
+  return false;
 }
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index a91bdede53e40d..5f92c80d15c0fa 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -362,8 +362,18 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
 
   // We support __builtin_cpu_supports/__builtin_cpu_is on targets that
   // have Glibc since it is Glibc that provides the HWCAP[2] in the auxv.
+#define MINIMUM_AIX_OS_MAJOR 7
+#define MINIMUM_AIX_OS_MINOR 2
   bool supportsCpuSupports() const override { return getTriple().isOSGlibc(); }
-  bool supportsCpuIs() const override { return getTriple().isOSGlibc(); }
+  bool supportsCpuIs() const override {
+llvm::Triple Tri = getTriple();
+// The AIX7.2 is mininum requirement to support __builtin_cpu_is().
+return Tri.isOSGlibc() ||
+   (Tri.isOSAIX() &&
+!Tri.isOSVersionLT(MINIMUM_AIX_OS_MAJOR, MINIMUM_AIX_OS_MINOR));
+  }
+#undef MINIMUM_AIX_OS_MAJOR
+#undef MINIMUM_AIX_OS_MINOR
   bool validateCpuSupports(StringRef Feature) const override;
   bool validateCpuIs(StringRef Name) const override;
 };
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f3ab5ad7b08ec8..bab5b144275fd8 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -16542,22 +16542,75 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 
   Intrinsic::ID ID = Intrinsic::not_intrinsic;
 
+#include "llvm/TargetParser/PPCTargetParser.def"
+  auto GetOpRes = [&](Value *FieldValue, unsigned Mask, unsigned Op,
+  unsigned Op_Value) -> Value * {
+Value *Value1 = FieldValue;
+if (Mask)
+  Value1 = Builder.CreateAnd(Value1, Mask);
+assert((Op == OP_EQ) && "Only support equal comparision");
+return Builder.CreateICmp(ICmpInst::ICMP_EQ, FieldValue,
+  ConstantInt::get(Int32Ty, Op_Value));
+  };
+
+  auto ConvBuiltinCpu = [&](unsigned SupportOP, unsigned FieldIdx,
+unsigned Op_Mask, unsigned Op,
+unsigned Op_Value) -> Value * {
+if (SupportOP == AIX_BUILTIN_PPC_FALSE)
+  return llvm::ConstantInt::getFalse(ConvertType(E->getType()));
+
+if (SupportOP == AIX_BUILTIN_PPC_TRUE)
+  return llvm::ConstantInt::getTrue(ConvertType(E->getType()));
+
+assert(SupportOP <= COMP_OP && "Invalid value for SupportOP.");
+llvm::Type *STy = 

[clang] [OpenACC] Implement beginning parts of the 'parallel' Sema impl (PR #81659)

2024-02-16 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff db4ea21dfde307f4fc873a6fe56791cd7ae3f0a1 
cf3ac4cd3bff222ff8a78368b91675b547d86833 -- 
clang/test/SemaOpenACC/compute-construct-ast.cpp 
clang/test/SemaOpenACC/parallel-assoc-stmt-inst.cpp 
clang/test/SemaOpenACC/parallel-loc-and-stmt.c 
clang/test/SemaOpenACC/parallel-loc-and-stmt.cpp 
clang/test/SemaOpenACC/unimplemented-construct.c 
clang/include/clang/AST/StmtOpenACC.h clang/include/clang/Sema/Sema.h 
clang/lib/AST/ASTContext.cpp clang/lib/AST/StmtOpenACC.cpp 
clang/lib/Parse/ParseOpenACC.cpp clang/lib/Sema/SemaOpenACC.cpp 
clang/lib/Sema/TreeTransform.h clang/test/ParserOpenACC/parse-clauses.c 
clang/test/ParserOpenACC/parse-clauses.cpp 
clang/test/ParserOpenACC/parse-constructs.c 
clang/test/ParserOpenACC/parse-wait-clause.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index de6f1bac21..d365a5151a 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -74,14 +74,14 @@ StmtResult 
Sema::ActOnEndOpenACCStmtDirective(OpenACCDirectiveKind K,
   SourceLocation EndLoc,
   StmtResult AssocStmt) {
   switch (K) {
-default:
-  return StmtEmpty();
-case OpenACCDirectiveKind::Invalid:
-  return StmtError();
-case OpenACCDirectiveKind::Parallel:
-  return OpenACCComputeConstruct::Create(
-  getASTContext(), K, StartLoc, EndLoc,
-  AssocStmt.isUsable() ? AssocStmt.get() : nullptr);
+  default:
+return StmtEmpty();
+  case OpenACCDirectiveKind::Invalid:
+return StmtError();
+  case OpenACCDirectiveKind::Parallel:
+return OpenACCComputeConstruct::Create(
+getASTContext(), K, StartLoc, EndLoc,
+AssocStmt.isUsable() ? AssocStmt.get() : nullptr);
   }
   llvm_unreachable("Unhandled case in directive handling?");
 }
@@ -90,7 +90,7 @@ StmtResult 
Sema::ActOnOpenACCAssociatedStmt(OpenACCDirectiveKind K,
 StmtResult AssocStmt) {
   switch (K) {
   default:
-  llvm_unreachable("Unimplemented associated statement application");
+llvm_unreachable("Unimplemented associated statement application");
   case OpenACCDirectiveKind::Parallel:
 // There really isn't any checking here that could happen. As long as we
 // have a statement to associate, this should be fine.

``




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


[clang] [OpenACC] Implement beginning parts of the 'parallel' Sema impl (PR #81659)

2024-02-16 Thread Alexey Bataev via cfe-commits


@@ -0,0 +1,132 @@
+//===--- SemaOpenACC.cpp - Semantic Analysis for OpenACC constructs 
---===//
+//
+// 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
+//
+//===--===//
+/// \file
+/// This file implements semantic analysis for OpenACC constructs and
+/// clauses.
+///
+//===--===//
+
+#include "clang/Basic/DiagnosticSema.h"
+#include "clang/Basic/OpenACCKinds.h"
+#include "clang/Sema/Sema.h"
+
+using namespace clang;
+
+namespace {
+bool DiagnoseConstructAppertainment(Sema &S, OpenACCDirectiveKind K,
+SourceLocation StartLoc, bool IsStmt) {
+  switch (K) {
+  default:
+  case OpenACCDirectiveKind::Invalid:
+// Nothing to do here, both invalid and unimplemented don't really need to
+// do anything.
+break;

alexey-bataev wrote:

Should it be llvm_unreachable?

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


[clang] [llvm] [mlir] [openmp] [OpenMP] Remove `register_requires` global constructor (PR #80460)

2024-02-16 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

ping

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


[clang] fix unnecessary warning when using bitand with boolean operators (PR #81976)

2024-02-16 Thread Bhuminjay Soni via cfe-commits

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


[clang] Revert "[X86][clang] Lift _BitInt() supported max width." (PR #81175)

2024-02-16 Thread Harald van Dijk via cfe-commits

hvdijk wrote:

That would be nice, but that will take time, and I did wait months already 
before creating this PR. Leaving Clang in its current state until someone steps 
up to fix it, in my opinion, does a massive disservice to users.

If code is written to use `_BitInt`, and it correctly uses configure or CMake 
checks to try to detect compiler support, and fall back to some other 
implementation if `_BitInt` is unavailable, such code would, with Clang, use 
the non-working implementation. In which case the configure or CMake check 
would end up amended to "and if Clang, don't bother". From experience, such 
checks remain for far too long after the original problem is fixed; leaving 
Clang in its current state, I suspect, ensures that once Clang behaves 
correctly, still `_BitInt` will not be used.

I'm happy if someone is willing to step up to fix the implementation, but I am 
not able to do it, and I would really like to avoid Clang 18 being released in 
this broken state, if possible, and I see no way short of a revert to 
realistically achieve that.

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


[clang] d228191 - [clang][Interp] Create global variables for TemplateParamObjectDecls

2024-02-16 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-16T16:07:42+01:00
New Revision: d228191c8bb80ebf337d282374941c465dabc78d

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

LOG: [clang][Interp] Create global variables for TemplateParamObjectDecls

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/lambda.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 975d3b68e9b242..72789d9d348144 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3163,6 +3163,10 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
   } else if (const auto *FuncDecl = dyn_cast(D)) {
 const Function *F = getFunction(FuncDecl);
 return F && this->emitGetFnPtr(F, E);
+  } else if (isa(D)) {
+if (std::optional Index = P.getOrCreateGlobal(D))
+  return this->emitGetPtrGlobal(*Index, E);
+return false;
   }
 
   // References are implemented via pointers, so when we see a DeclRefExpr

diff  --git a/clang/test/AST/Interp/lambda.cpp 
b/clang/test/AST/Interp/lambda.cpp
index a433e5666e4f4c..75a4a628f11833 100644
--- a/clang/test/AST/Interp/lambda.cpp
+++ b/clang/test/AST/Interp/lambda.cpp
@@ -213,3 +213,15 @@ namespace ThisCapture {
   static_assert(F.a == 33, "");
   static_assert(F.Aplus2() == (33 + 2), "");
 }
+
+namespace GH62611 {
+  template 
+  struct C {
+static constexpr auto B = A;
+  };
+
+  int test() {
+C<>::B(42);
+return 0;
+  }
+}



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


[clang] [flang] [RFC][flang][runtime] Add FortranFloat128Math wrapper library. (PR #81971)

2024-02-16 Thread via cfe-commits

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

Thanks a lot for plumbing-in the quadmath runtime and offering ways to 
customize the builds here. Looks great me!

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


[clang] [OpenACC] Implement beginning parts of the 'parallel' Sema impl (PR #81659)

2024-02-16 Thread Erich Keane via cfe-commits


@@ -0,0 +1,132 @@
+//===--- SemaOpenACC.cpp - Semantic Analysis for OpenACC constructs 
---===//
+//
+// 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
+//
+//===--===//
+/// \file
+/// This file implements semantic analysis for OpenACC constructs and
+/// clauses.
+///
+//===--===//
+
+#include "clang/Basic/DiagnosticSema.h"
+#include "clang/Basic/OpenACCKinds.h"
+#include "clang/Sema/Sema.h"
+
+using namespace clang;
+
+namespace {
+bool DiagnoseConstructAppertainment(Sema &S, OpenACCDirectiveKind K,
+SourceLocation StartLoc, bool IsStmt) {
+  switch (K) {
+  default:
+  case OpenACCDirectiveKind::Invalid:
+// Nothing to do here, both invalid and unimplemented don't really need to
+// do anything.
+break;

erichkeane wrote:

No, that would just end up crashing, we're calling into the 'act on start' even 
when invalid, which should allow us to handle 'state' of bad pragmas better, so 
'invalid' has to get through here without causing problems.  The intent is that 
we wont create an AST node here, but still allow 'checking' of everything else.

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


[clang] [OpenACC] Implement beginning parts of the 'parallel' Sema impl (PR #81659)

2024-02-16 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev approved this pull request.

LG

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


[clang] [clang-tools-extra] [flang] [lld] [llvm] [flang][clang] Add Visibility specific help text for options (PR #81869)

2024-02-16 Thread Leandro Lupori via cfe-commits

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


[clang] [clang-tools-extra] [flang] [lld] [llvm] [flang][clang] Add Visibility specific help text for options (PR #81869)

2024-02-16 Thread Leandro Lupori via cfe-commits


@@ -3391,7 +3391,10 @@ def fno_openmp : Flag<["-"], "fno-openmp">, 
Group,
 def fopenmp_version_EQ : Joined<["-"], "fopenmp-version=">, Group,
   Flags<[NoArgumentUnused]>,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
-  HelpText<"Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). 
Default value is 51 for Clang">;
+  HelpText<"Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). 
Default value is 51 for Clang">,
+  HelpForVisibilityhttps://github.com/llvm/llvm-project/pull/81869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [flang] [lld] [llvm] [flang][clang] Add Visibility specific help text for options (PR #81869)

2024-02-16 Thread Leandro Lupori via cfe-commits

https://github.com/luporl commented:

I think this can be useful, to make it possible to customize flang help 
messages, even though only one flang option requires it at the moment.

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


[clang] [llvm] [AIX] support builtin_cpu_is() (PR #80069)

2024-02-16 Thread Lei Huang via cfe-commits

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


[clang] [llvm] [AIX] Lower intrinsic __builtin_cpu_is into AIX platform-specific code. (PR #80069)

2024-02-16 Thread zhijian lin via cfe-commits

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


[clang] [llvm] [AIX] Lower intrinsic __builtin_cpu_is into AIX platform-specific code. (PR #80069)

2024-02-16 Thread zhijian lin via cfe-commits

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


[clang] [llvm] [AIX] Lower intrinsic __builtin_cpu_is into AIX platform-specific code. (PR #80069)

2024-02-16 Thread zhijian lin via cfe-commits

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


[clang] [llvm] [AIX] Lower intrinsic __builtin_cpu_is into AIX platform-specific code. (PR #80069)

2024-02-16 Thread zhijian lin via cfe-commits

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


[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/82004

Summary:
The original discussion in https://reviews.llvm.org/D118493 was that
`clang` should not be adding `-rpath` implicitly for toolchains. The
main motivation behind that change was the 'Fedora' toolchain
disallowing usage of `-rpath` in their tools. This patch introduces a
new clang configuration called `CLANG_ALLOW_IMPLICT_RPATH` that defaults
to on.

The motivation behind this patch is the fact that the LLVM offloading
toolchain is currently in a nearly unusable state for casual users. This
is a problem for other runtimes like `libc++` or `libunwind`, however
`libomptarget` and other offloading runtimes like HIP are much difficult
to support. Currently, `libomptarget` is only supported to be used with
the same build that created the executable. Furthermore, `libomptarget`
is currently shipped by four different vendors, which are not mutually
compatible. Because this is totally broken as far as I'm aware all the
vendor compilers reverted the original patch turning this off.

The presented solution was to advise users to use Clang configruation
files. Since then, this was added to the documentation at the website
https://openmp.llvm.org/SupportAndFAQ.html#q-what-are-the-llvm-components-used-in-offloading-and-how-are-they-found
but this has not had any noticable effect on the number of people I've
had to coach through their broken environment since the patch was
reverted and is roughly equivalent to the currenlty accepted solution of
using LD_LIBRARY_PATH.

This would be solved with static linking, but offloading runtimes also
manage thred pools and device resources that cannot be duplicated. The
Fedora distributors were the only group that were against doing this by
default, so the suggestion is that Fedora uses
`-DCLANG_ALLOW_IMPLICIT_RPATH=OFF` when building.


>From 7ddd4ad90cda446b94d72b707015767ea759d121 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Fri, 16 Feb 2024 09:18:12 -0600
Subject: [PATCH] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain
 use of -rpath

Summary:
The original discussion in https://reviews.llvm.org/D118493 was that
`clang` should not be adding `-rpath` implicitly for toolchains. The
main motivation behind that change was the 'Fedora' toolchain
disallowing usage of `-rpath` in their tools. This patch introduces a
new clang configuration called `CLANG_ALLOW_IMPLICT_RPATH` that defaults
to on.

The motivation behind this patch is the fact that the LLVM offloading
toolchain is currently in a nearly unusable state for casual users. This
is a problem for other runtimes like `libc++` or `libunwind`, however
`libomptarget` and other offloading runtimes like HIP are much difficult
to support. Currently, `libomptarget` is only supported to be used with
the same build that created the executable. Furthermore, `libomptarget`
is currently shipped by four different vendors, which are not mutually
compatible. Because this is totally broken as far as I'm aware all the
vendor compilers reverted the original patch turning this off.

The presented solution was to advise users to use Clang configruation
files. Since then, this was added to the documentation at the website
https://openmp.llvm.org/SupportAndFAQ.html#q-what-are-the-llvm-components-used-in-offloading-and-how-are-they-found
but this has not had any noticable effect on the number of people I've
had to coach through their broken environment since the patch was
reverted and is roughly equivalent to the currenlty accepted solution of
using LD_LIBRARY_PATH.

This would be solved with static linking, but offloading runtimes also
manage thred pools and device resources that cannot be duplicated. The
Fedora distributors were the only group that were against doing this by
default, so the suggestion is that Fedora uses
`-DCLANG_ALLOW_IMPLICIT_RPATH=OFF` when building.
---
 clang/CMakeLists.txt   | 2 ++
 clang/include/clang/Config/config.h.cmake  | 3 +++
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 3 ++-
 clang/test/Driver/arch-specific-libdir-rpath.c | 7 ---
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 47fc2e4886cfc2..02e0a8f80d9c59 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -213,6 +213,8 @@ set(CLANG_SPAWN_CC1 OFF CACHE BOOL
 
 option(CLANG_DEFAULT_PIE_ON_LINUX "Default to -fPIE and -pie on linux-gnu" ON)
 
+option(CLANG_ALLOW_IMPLICIT_RPATH "Allow clang to add -rpath automatically" ON)
+
 set(CLANG_DEFAULT_LINKER "" CACHE STRING
   "Default linker to use (linker name or absolute path, empty for platform 
default)")
 
diff --git a/clang/include/clang/Config/config.h.cmake 
b/clang/include/clang/Config/config.h.cmake
index 4015ac8040861c..6ca8cc75953094 100644
--- a/clang/include/clang/Config/config.h.cmake
+++ b/clang/include/clang/Config/config.h.cmake
@@ -63,6 +63,9 @@
 /* Define if dladdr() is available on this 

[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Joseph Huber (jhuber6)


Changes

Summary:
The original discussion in https://reviews.llvm.org/D118493 was that
`clang` should not be adding `-rpath` implicitly for toolchains. The
main motivation behind that change was the 'Fedora' toolchain
disallowing usage of `-rpath` in their tools. This patch introduces a
new clang configuration called `CLANG_ALLOW_IMPLICT_RPATH` that defaults
to on.

The motivation behind this patch is the fact that the LLVM offloading
toolchain is currently in a nearly unusable state for casual users. This
is a problem for other runtimes like `libc++` or `libunwind`, however
`libomptarget` and other offloading runtimes like HIP are much difficult
to support. Currently, `libomptarget` is only supported to be used with
the same build that created the executable. Furthermore, `libomptarget`
is currently shipped by four different vendors, which are not mutually
compatible. Because this is totally broken as far as I'm aware all the
vendor compilers reverted the original patch turning this off.

The presented solution was to advise users to use Clang configruation
files. Since then, this was added to the documentation at the website
https://openmp.llvm.org/SupportAndFAQ.html#q-what-are-the-llvm-components-used-in-offloading-and-how-are-they-found
but this has not had any noticable effect on the number of people I've
had to coach through their broken environment since the patch was
reverted and is roughly equivalent to the currenlty accepted solution of
using LD_LIBRARY_PATH.

This would be solved with static linking, but offloading runtimes also
manage thred pools and device resources that cannot be duplicated. The
Fedora distributors were the only group that were against doing this by
default, so the suggestion is that Fedora uses
`-DCLANG_ALLOW_IMPLICIT_RPATH=OFF` when building.


---
Full diff: https://github.com/llvm/llvm-project/pull/82004.diff


4 Files Affected:

- (modified) clang/CMakeLists.txt (+2) 
- (modified) clang/include/clang/Config/config.h.cmake (+3) 
- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+2-1) 
- (modified) clang/test/Driver/arch-specific-libdir-rpath.c (-7) 


``diff
diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 47fc2e4886cfc2..02e0a8f80d9c59 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -213,6 +213,8 @@ set(CLANG_SPAWN_CC1 OFF CACHE BOOL
 
 option(CLANG_DEFAULT_PIE_ON_LINUX "Default to -fPIE and -pie on linux-gnu" ON)
 
+option(CLANG_ALLOW_IMPLICIT_RPATH "Allow clang to add -rpath automatically" ON)
+
 set(CLANG_DEFAULT_LINKER "" CACHE STRING
   "Default linker to use (linker name or absolute path, empty for platform 
default)")
 
diff --git a/clang/include/clang/Config/config.h.cmake 
b/clang/include/clang/Config/config.h.cmake
index 4015ac8040861c..6ca8cc75953094 100644
--- a/clang/include/clang/Config/config.h.cmake
+++ b/clang/include/clang/Config/config.h.cmake
@@ -63,6 +63,9 @@
 /* Define if dladdr() is available on this platform. */
 #cmakedefine CLANG_HAVE_DLADDR ${CLANG_HAVE_DLADDR}
 
+/* Define if we have sys/resource.h (rlimits) */
+#cmakedefine01 CLANG_ALLOW_IMPLICIT_RPATH
+
 /* Linker version detected at compile time. */
 #cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}"
 
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 0fd7b8424eb4ba..cc8e4ffa571a82 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1107,7 +1107,8 @@ void tools::addOpenMPRuntimeLibraryPath(const ToolChain 
&TC,
 void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
  ArgStringList &CmdArgs) {
   if (!Args.hasFlag(options::OPT_frtlib_add_rpath,
-options::OPT_fno_rtlib_add_rpath, false))
+options::OPT_fno_rtlib_add_rpath,
+CLANG_ALLOW_IMPLICIT_RPATH))
 return;
 
   for (const auto &CandidateRPath : TC.getArchSpecificLibPaths()) {
diff --git a/clang/test/Driver/arch-specific-libdir-rpath.c 
b/clang/test/Driver/arch-specific-libdir-rpath.c
index 1e6bbbc5929ac2..de114c67862dea 100644
--- a/clang/test/Driver/arch-specific-libdir-rpath.c
+++ b/clang/test/Driver/arch-specific-libdir-rpath.c
@@ -1,13 +1,6 @@
 // Test that the driver adds an arch-specific subdirectory in
 // {RESOURCE_DIR}/lib/linux to the linker search path and to '-rpath'
 //
-// Test the default behavior when neither -frtlib-add-rpath nor
-// -fno-rtlib-add-rpath is specified, which is to skip -rpath
-// RUN: %clang %s -### --target=x86_64-linux \
-// RUN: -fsanitize=address -shared-libasan \
-// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir 2>&1 \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
-//
 // Test that -rpath is not added under -fno-rtlib-add-rpath even if other
 // conditions ar

[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread Joseph Huber via cfe-commits

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


[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread Tom Stellard via cfe-commits

tstellar wrote:

I don't think a CMake option is the right way to go here.  For example, I doubt 
we would actually use this CMake option in Fedora if this patch is committed.

Does gcc use rpath for libgomp?

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


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1 @@
+../include/test.h

PiotrZSL wrote:

this symlink should be created on fly, to avoid some random issues on checkout.

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


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL commented:

Overall looks fine, release notes should be updated for clang-tidy.

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


[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> I don't think a CMake option is the right way to go here. For example, I 
> doubt we would actually use this CMake option in Fedora if this patch is 
> committed.

Does Fedora only use default configurations when building its packages?

> Does gcc use rpath for libgomp?

That's irrelevant to the needs of projects like `libomptarget` or other HIP 
libraries. We do not have these problems with `libomp` because it is a mostly 
stable ABI, so if users pick up the wrong one (Which happens all the time) no 
one notices and we don't get bug reports.

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


[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread Jon Chesterfield via cfe-commits

JonChesterfield wrote:

Enable by default without cmake and fedora run their own patch is my preferred 
solution.

The Siemens dev working on gcc amdgpu offloading told me they set rpath on the 
executable at a conference but I haven't checked their implementation. His 
attitude was that programs should be able to run without setting environment 
variables.

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


[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread Tom Stellard via cfe-commits

tstellar wrote:

> Does Fedora only use default configurations when building its packages?

We try to stick to the defaults as much as possible.  Having an implicit rpath 
by default causes issues when building other RPMs with clang, and typically, if 
we need to change something in order to build RPMS, we do it by adjusting the 
global C Flags used for building RPMS rather than patching the compiler.


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


[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread Shilei Tian via cfe-commits

shiltian wrote:

IMHO I prefer to ask/request users to do the right thing. Vendors are totally 
free to do whatever to be convenient for their customers via their compiler 
wrappers/drivers, but for the community version, following the convention would 
be good.

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


[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> > Does Fedora only use default configurations when building its packages?
> 
> We try to stick to the defaults as much as possible. Having an implicit rpath 
> by default causes issues when building other RPMs with clang, and typically, 
> if we need to change something in order to build RPMS, we do it by adjusting 
> the global C Flags used for building RPMS rather than patching the compiler.

We could make this logic more complicated by checking the system automatically 
`execute_command(lsb_release)` or something.

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


[clang] [llvm] [AMDGPU] Use `bf16` instead of `i16` for bfloat (PR #80908)

2024-02-16 Thread Shilei Tian via cfe-commits

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


[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread Tom Stellard via cfe-commits

tstellar wrote:

> We could make this logic more complicated by checking the system 
> automatically `execute_command(lsb_release)` or something.

I think this is too complicated and fragile.  If we want to do something 
specifically to support the distro use case, I think we should do this: 
https://reviews.llvm.org/D142174


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


[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> > We could make this logic more complicated by checking the system 
> > automatically `execute_command(lsb_release)` or something.
> 
> I think this is too complicated and fragile. If we want to do something 
> specifically to support the distro use case, I think we should do this: 
> https://reviews.llvm.org/D142174

I believe right now the `rtlib-rpath` points to the path 
`${CLANG_BINARY}../lib/${HOST_TRIPLE}/`. I think it's definitely reasonable to 
not put this on system libraries if that's a solution, since we can generally 
assume it's a global installation and already covered by the user's library 
path. Does the Fedora policy only disallow `rpath` on system installs then?

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


[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread Tom Stellard via cfe-commits

tstellar wrote:

> 
> I believe right now the `rtlib-rpath` points to the path 
> `${CLANG_BINARY}../lib/${HOST_TRIPLE}/`. I think it's definitely reasonable 
> to not put this on system libraries if that's a solution, since we can 
> generally assume it's a global installation and already covered by the user's 
> library path. Does the Fedora policy only disallow `rpath` on system installs 
> then?

Right, any official Fedora binaries we build can't have rpath in them, but 
users can still use rpath in their own applications if they want.


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


[clang] [llvm] [AMDGPU] Use `bf16` instead of `i16` for bfloat (PR #80908)

2024-02-16 Thread Shilei Tian via cfe-commits

https://github.com/shiltian updated 
https://github.com/llvm/llvm-project/pull/80908

>From d95e99ebcefa76ba2e8068f663be86340c14ab5b Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Fri, 16 Feb 2024 11:29:47 -0500
Subject: [PATCH] [RFC][WIP][AMDGPU] Use `bf16` instead of `i16` for bfloat

Currently it looks like we generally use `i16` to represent `bf16` in those 
tablegen
files. I'm not sure of the reason behind it. My wild guess is the type `bf16` 
was
not available when we enabled the support. This patch is trying to use `bf16`
directly in those tablegen files, aiming at fixing #79369. Of course for #79369
a workaround can be to treat all `INT16` variants as `BFloat` in 
`getOpFltSemantics`,
but it doesn't look good IMHO.

Since I'm fairly new to AMDGPU backend, I'd appreciate it if you can point out
where I don't understand correctly.
---
 .../builtins-amdgcn-dl-insts-gfx11.cl |  5 +-
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |  8 +-
 .../AMDGPU/AsmParser/AMDGPUAsmParser.cpp  | 92 +++
 .../AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp | 57 
 .../AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h   |  2 +
 .../MCTargetDesc/AMDGPUMCCodeEmitter.cpp  | 39 
 llvm/lib/Target/AMDGPU/SIDefines.h|  7 ++
 llvm/lib/Target/AMDGPU/SIInstrInfo.cpp| 15 +++
 llvm/lib/Target/AMDGPU/SIInstrInfo.td | 16 ++--
 llvm/lib/Target/AMDGPU/SIRegisterInfo.td  | 21 -
 .../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp| 54 +++
 llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h | 16 
 llvm/lib/Target/AMDGPU/VOP3Instructions.td|  2 +-
 .../AMDGPU/llvm.amdgcn.fdot2.bf16.bf16.ll | 39 
 llvm/test/MC/AMDGPU/bf16_imm.s|  8 ++
 llvm/test/MC/Disassembler/AMDGPU/bf16_imm.txt |  9 ++
 16 files changed, 356 insertions(+), 34 deletions(-)
 create mode 100644 llvm/test/MC/AMDGPU/bf16_imm.s
 create mode 100644 llvm/test/MC/Disassembler/AMDGPU/bf16_imm.txt

diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx11.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx11.cl
index dc7069decaaa61..7688dfa55a78e3 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx11.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx11.cl
@@ -11,7 +11,10 @@ typedef unsigned short __attribute__((ext_vector_type(2))) 
ushort2;
 // CHECK: call float @llvm.amdgcn.fdot2(<2 x half> %v2hA, <2 x half> %v2hB, 
float %fC, i1 false)
 // CHECK: call float @llvm.amdgcn.fdot2(<2 x half> %v2hA, <2 x half> %v2hB, 
float %fC, i1 true)
 // CHECK: call half @llvm.amdgcn.fdot2.f16.f16(<2 x half> %v2hA, <2 x half> 
%v2hB, half %hC)
-// CHECK: call i16 @llvm.amdgcn.fdot2.bf16.bf16(<2 x i16> %v2ssA, <2 x i16> 
%v2ssB, i16 %sC)
+// CHECK: [[s1:%[0-9]+]] = bitcast <2 x i16> %v2ssA to <2 x bfloat>
+// CHECK-NEXT: [[s2:%[0-9]+]] = bitcast <2 x i16> %v2ssB to <2 x bfloat>
+// CHECK-NEXT: [[s3:%[0-9]+]] = bitcast i16 %sC to bfloat
+// CHECK-NEXT: [[d:%[0-9]+]] = tail call bfloat 
@llvm.amdgcn.fdot2.bf16.bf16(<2 x bfloat> [[s1]], <2 x bfloat> [[s2]], bfloat 
[[s3]])
 // CHECK: call float @llvm.amdgcn.fdot2.f32.bf16(<2 x i16> %v2ssA, <2 x i16> 
%v2ssB, float %fC, i1 false)
 // CHECK: call float @llvm.amdgcn.fdot2.f32.bf16(<2 x i16> %v2ssA, <2 x i16> 
%v2ssB, float %fC, i1 true)
 // CHECK: call i32 @llvm.amdgcn.udot4(i32 %uiA, i32 %uiB, i32 %uiC, i1 false)
diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td 
b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
index 202fa4e8f4ea81..6795fb7aa0edb8 100644
--- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -2819,11 +2819,11 @@ def int_amdgcn_fdot2_f16_f16 :
 def int_amdgcn_fdot2_bf16_bf16 :
   ClangBuiltin<"__builtin_amdgcn_fdot2_bf16_bf16">,
   DefaultAttrsIntrinsic<
-[llvm_i16_ty],   // %r
+[llvm_bfloat_ty],   // %r
 [
-  llvm_v2i16_ty, // %a
-  llvm_v2i16_ty, // %b
-  llvm_i16_ty// %c
+  llvm_v2bf16_ty, // %a
+  llvm_v2bf16_ty, // %b
+  llvm_bfloat_ty// %c
 ],
 [IntrNoMem, IntrSpeculatable]
   >;
diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp 
b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 79ad6ddf7861fc..883b30562e911b 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -475,6 +475,8 @@ class AMDGPUOperand : public MCParsedAsmOperand {
 
   bool isSSrcF64() const { return isSCSrc_b64() || isLiteralImm(MVT::f64); }
 
+  bool isSSrc_bf16() const { return isSCSrcB16() || isLiteralImm(MVT::bf16); }
+
   bool isSSrc_f16() const { return isSCSrcB16() || isLiteralImm(MVT::f16); }
 
   bool isSSrcV2F16() const {
@@ -541,22 +543,40 @@ class AMDGPUOperand : public MCParsedAsmOperand {
 return isRegOrInlineNoMods(AMDGPU::VS_64RegClassID, MVT::f64);
   }
 
+  bool isVCSrcTBF16() const {
+return isRegOrInlineNoMods(AMDGPU::VS_16RegClassID, MVT::bf16);
+  }
+
   bool isVCSrcTF16() const {
 return isR

[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> > I believe right now the `rtlib-rpath` points to the path 
> > `${CLANG_BINARY}../lib/${HOST_TRIPLE}/`. I think it's definitely reasonable 
> > to not put this on system libraries if that's a solution, since we can 
> > generally assume it's a global installation and already covered by the 
> > user's library path. Does the Fedora policy only disallow `rpath` on system 
> > installs then?
> 
> Right, any official Fedora binaries we build can't have rpath in them, but 
> users can still use rpath in their own applications if they want.

I'd be okay with that solution. The majority of the issues come from people on 
cluster machines with several conflicting versions of the libraries. The only 
question is how to determine what a system library is. We could possible just 
hardcode a few paths depending on the host triple's operating system.

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


[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread Tom Stellard via cfe-commits

tstellar wrote:

> > > I believe right now the `rtlib-rpath` points to the path 
> > > `${CLANG_BINARY}../lib/${HOST_TRIPLE}/`. I think it's definitely 
> > > reasonable to not put this on system libraries if that's a solution, 
> > > since we can generally assume it's a global installation and already 
> > > covered by the user's library path. Does the Fedora policy only disallow 
> > > `rpath` on system installs then?
> > 
> > 
> > Right, any official Fedora binaries we build can't have rpath in them, but 
> > users can still use rpath in their own applications if they want.
> 
> I'd be okay with that solution. The majority of the issues come from people 
> on cluster machines with several conflicting versions of the libraries. The 
> only question is how to determine what a system library is. We could possible 
> just hardcode a few paths depending on the host triple's operating system.

I'm not a huge fan of trying to auto-detect settings based on the host OS.  
What if we just added an option like --exclude-rpath-dir= which would let a 
user or a distro specify a list of directories that aren't allowed to be added 
as rpath.  Now that we have config file support it would be easy for distros to 
add a config file with the list of its own system directories.

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


[clang] [Clang] Add 'CLANG_ALLOW_IMPLICIT_RPATH' to enable toolchain use of -rpath (PR #82004)

2024-02-16 Thread Jon Chesterfield via cfe-commits

JonChesterfield wrote:

> IMHO I prefer to ask/request users to do the right thing.

One of the drawbacks to asking users to do the "right thing" is that it goes 
something like:
- you must use global state to tell the compiler where the compiler libraries 
are
- you should do this using clang configuration files which are like commandline 
flags only different
- the flag is called rpath, which means runpath, but used to mean rpath, 
because of this historic context from glibc
- plus you need to work out what the (multiple) openmp libraries are called and 
where they are
- and some of them are bitcode, found using this different mechanism
- and if you don't get it totally right, things won't work

which means we've chosen "right" to mean "trivially convenient for compiler 
developers who don't like changing things", which is not likely to be what the 
user had in mind. They should look at this pile of spurious complexity and 
conclude they don't want to be an openmp user after all.

We really don't have a good answer to "why can't my compiler find it's own 
libraries?", since the best we've got is a reference to a build script Fedora 
deploy for reasons that they don't really go into in their docs, and where I 
still haven't managed to find the script itself to reverse engineer what 
exactly it's rejecting.

I'm still happy with a heuristic that amounts to "if the compiler libs are 
being installed under /usr or /lib, assume the system can find them, and 
otherwise set rpath on the executable", especially if it's tied to a command 
line flag or cmake control which lets the user override whichever default we 
picked for them.

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-16 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl updated 
https://github.com/llvm/llvm-project/pull/81190

>From f6dbbfbf6b8aa221035e39735c5c6e2d0936219c Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Thu, 8 Feb 2024 11:08:59 -0500
Subject: [PATCH] [HLSL] Implementation of dot intrinsic This change implements
 #70073

HLSL has a dot intrinsic defined here:
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-dot

The intrinsic itself is defined as a HLSL_LANG LangBuiltin in Builtins.td.
This is used to associate all the dot product typdef defined hlsl_intrinsics.h
with a single intrinsic check in CGBuiltin.cpp & SemaChecking.cpp.

In IntrinsicsDirectX.td we define the llvmIR for the dot product.
A few goals were in mind for this IR. First it should operate on only
vectors. Second the return type should be the vector element type. Third
the second parameter vector should be of the same size as the first
parameter. Finally `a dot b` should be the same as `b dot a`.

In CGBuiltin.cpp hlsl has built on top of existing clang intrinsics via 
EmitBuiltinExpr. Dot
product though is language specific intrinsic and so is guarded behind 
getLangOpts().HLSL.
The call chain looks like this: EmitBuiltinExpr -> EmitHLSLBuiltinExp

EmitHLSLBuiltinExp dot product intrinsics makes a destinction
between vectors and scalars. This is because HLSL supports dot product on 
scalars which simplifies down to multiply.

Sema.h & SemaChecking.cpp saw the addition of CheckHLSLBuiltinFunctionCall, a 
language specific semantic validation that can be expanded for other hlsl 
specific intrinsics.
---
 clang/include/clang/Basic/Builtins.td |   6 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +
 clang/include/clang/Sema/Sema.h   |   1 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  49 
 clang/lib/CodeGen/CodeGenFunction.h   |   1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  92 
 clang/lib/Sema/SemaChecking.cpp   |  84 ++-
 clang/test/CodeGenHLSL/builtins/dot.hlsl  | 216 ++
 clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl  |  46 
 llvm/include/llvm/IR/IntrinsicsDirectX.td |   5 +
 10 files changed, 497 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/dot.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index df74026c5d2d50..771c4f5d4121f4 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4524,6 +4524,12 @@ def HLSLCreateHandle : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void*(unsigned char)";
 }
 
+def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_dot"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fb44495199ee56..9957f4e743e9cb 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10267,6 +10267,8 @@ def err_vec_builtin_non_vector : Error<
  "first two arguments to %0 must be vectors">;
 def err_vec_builtin_incompatible_vector : Error<
   "first two arguments to %0 must have the same type">;
+def err_vec_builtin_incompatible_size : Error<
+  "first two arguments to %0 must have the same size">;
 def err_vsx_builtin_nonconstant_argument : Error<
   "argument %0 to %1 must be a 2-bit unsigned literal (i.e. 0, 1, 2 or 3)">;
 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 53f06bcaeca166..d79fd07c8069e5 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14054,6 +14054,7 @@ class Sema final {
   bool CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
CallExpr *TheCall);
   bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+  bool CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
   bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum);
   bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
  CallExpr *TheCall);
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9bc60466d09be6..1d8c1d26470639 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -44,6 +44,7 @@
 #include "llvm/IR/IntrinsicsAMDGPU.h"
 #include "llvm/IR/IntrinsicsARM.h"
 #include "llvm/IR/IntrinsicsBPF.h"
+#include "llvm/IR/IntrinsicsDirectX.h"
 #include "llvm/IR/IntrinsicsHexagon.h"
 #include "llvm/IR/IntrinsicsNVPTX.h"
 #include "llvm/IR/IntrinsicsPowerPC.h"
@@ -5982,6 +5983,10 @@ RValue CodeGenFunction::EmitBuiltinE

[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-16 Thread Farzon Lotfi via cfe-commits


@@ -144,6 +144,92 @@ double3 cos(double3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
 double4 cos(double4);
 
+//===--===//
+// dot product builtins
+//===--===//
+#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half, half);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half2, half2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half3, half3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half4, half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t, int16_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t2, int16_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t3, int16_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t4, int16_t4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t, uint16_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t2, uint16_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t3, uint16_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t4, uint16_t4);
+#endif
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float, float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float2, float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float3, float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float4, float4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double, double);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double2, double2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double3, double3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double4, double4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int dot(int, int);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int dot(int2, int2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int dot(int3, int3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int dot(int4, int4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint dot(uint, uint);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint dot(uint2, uint2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint dot(uint3, uint3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint dot(uint4, uint4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int64_t dot(int64_t, int64_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int64_t dot(int64_t2, int64_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int64_t dot(int64_t3, int64_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int64_t dot(int64_t4, int64_t4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint64_t dot(uint64_t, uint64_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint64_t dot(uint64_t2, uint64_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint64_t dot(uint64_t3, uint64_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint64_t dot(uint64_t4, uint64_t4);

farzonl wrote:

I think we all came to agreement these should be added back so updated the pr 
to add support back.

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-16 Thread Farzon Lotfi via cfe-commits

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


[clang] cb89112 - [OpenACC] Implement beginning parts of the 'parallel' Sema impl (#81659)

2024-02-16 Thread via cfe-commits

Author: Erich Keane
Date: 2024-02-16T08:53:09-08:00
New Revision: cb891127974ddba9d2e31fe16220591ff9296bdb

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

LOG: [OpenACC] Implement beginning parts of the 'parallel' Sema impl (#81659)

This patch Implements AST node creation and appertainment enforcement
for 'parallel', as well as changes the 'not implemented' messages to be
more specific. It does not deal with clauses/clause legality, nor a few
of the other rules from the standard, but this gets us most of the way
for a framework for future construct implementation.

Added: 
clang/test/SemaOpenACC/compute-construct-ast.cpp
clang/test/SemaOpenACC/parallel-assoc-stmt-inst.cpp
clang/test/SemaOpenACC/parallel-loc-and-stmt.c
clang/test/SemaOpenACC/parallel-loc-and-stmt.cpp
clang/test/SemaOpenACC/unimplemented-construct.c

Modified: 
clang/include/clang/AST/StmtOpenACC.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/StmtOpenACC.cpp
clang/lib/Parse/ParseOpenACC.cpp
clang/lib/Sema/SemaOpenACC.cpp
clang/lib/Sema/TreeTransform.h
clang/test/ParserOpenACC/parse-clauses.c
clang/test/ParserOpenACC/parse-clauses.cpp
clang/test/ParserOpenACC/parse-constructs.c
clang/test/ParserOpenACC/parse-wait-clause.c

Removed: 




diff  --git a/clang/include/clang/AST/StmtOpenACC.h 
b/clang/include/clang/AST/StmtOpenACC.h
index 9424f4f0807858..19da66832c7374 100644
--- a/clang/include/clang/AST/StmtOpenACC.h
+++ b/clang/include/clang/AST/StmtOpenACC.h
@@ -68,8 +68,9 @@ class OpenACCAssociatedStmtConstruct : public 
OpenACCConstructStmt {
 
 protected:
   OpenACCAssociatedStmtConstruct(StmtClass SC, OpenACCDirectiveKind K,
- SourceLocation Start, SourceLocation End)
-  : OpenACCConstructStmt(SC, K, Start, End) {}
+ SourceLocation Start, SourceLocation End,
+ Stmt *AssocStmt)
+  : OpenACCConstructStmt(SC, K, Start, End), AssociatedStmt(AssocStmt) {}
 
   void setAssociatedStmt(Stmt *S) { AssociatedStmt = S; }
   Stmt *getAssociatedStmt() { return AssociatedStmt; }
@@ -105,14 +106,14 @@ class OpenACCComputeConstruct : public 
OpenACCAssociatedStmtConstruct {
   friend class ASTStmtReader;
   friend class ASTContext;
   OpenACCComputeConstruct()
-  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
-   OpenACCDirectiveKind::Invalid,
-   SourceLocation{}, SourceLocation{}) {}
+  : OpenACCAssociatedStmtConstruct(
+OpenACCComputeConstructClass, OpenACCDirectiveKind::Invalid,
+SourceLocation{}, SourceLocation{}, /*AssociatedStmt=*/nullptr) {}
 
   OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start,
-  SourceLocation End)
+  SourceLocation End, Stmt *StructuredBlock)
   : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass, K, Start,
-   End) {
+   End, StructuredBlock) {
 assert((K == OpenACCDirectiveKind::Parallel ||
 K == OpenACCDirectiveKind::Serial ||
 K == OpenACCDirectiveKind::Kernels) &&
@@ -128,10 +129,9 @@ class OpenACCComputeConstruct : public 
OpenACCAssociatedStmtConstruct {
   }
 
   static OpenACCComputeConstruct *CreateEmpty(const ASTContext &C, EmptyShell);
-  static OpenACCComputeConstruct *Create(const ASTContext &C,
- OpenACCDirectiveKind K,
- SourceLocation BeginLoc,
- SourceLocation EndLoc);
+  static OpenACCComputeConstruct *
+  Create(const ASTContext &C, OpenACCDirectiveKind K, SourceLocation BeginLoc,
+ SourceLocation EndLoc, Stmt *StructuredBlock);
 
   Stmt *getStructuredBlock() { return getAssociatedStmt(); }
   const Stmt *getStructuredBlock() const {

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 53f06bcaeca166..e9cd42ae777df5 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -33,6 +33,7 @@
 #include "clang/AST/NSAPI.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/StmtCXX.h"
+#include "clang/AST/StmtOpenACC.h"
 #include "clang/AST/StmtOpenMP.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/TypeOrdering.h"

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 78a04b4c694267..c475c841233c59 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -41,6 +41,7 @@
 #include "clang/AST/RawCommentList.h"
 #include "clang/AST/RecordLayout.h"
 #inc

[clang] [OpenACC] Implement beginning parts of the 'parallel' Sema impl (PR #81659)

2024-02-16 Thread Erich Keane via cfe-commits

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-16 Thread Farzon Lotfi via cfe-commits


@@ -19,4 +19,9 @@ def int_dx_flattened_thread_id_in_group : 
Intrinsic<[llvm_i32_ty], [], [IntrNoMe
 
 def int_dx_create_handle : ClangBuiltin<"__builtin_hlsl_create_handle">,
 Intrinsic<[ llvm_ptr_ty ], [llvm_i8_ty], [IntrWillReturn]>;
-}
+
+def int_dx_dot : 
+Intrinsic<[LLVMVectorElementType<0>], 
+[llvm_anyvector_ty, LLVMScalarOrSameVectorWidth<0, 
LLVMVectorElementType<0>>],
+[IntrNoMem, IntrWillReturn, Commutative] >;

farzonl wrote:

with inclusion of i64 I don't think this request is needed anymore. 

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-16 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl updated 
https://github.com/llvm/llvm-project/pull/81190

>From bebb3ad19cc1793090265e68b25c282f90b35227 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Thu, 8 Feb 2024 11:08:59 -0500
Subject: [PATCH] [HLSL] Implementation of dot intrinsic This change implements
 #70073

HLSL has a dot intrinsic defined here:
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-dot

The intrinsic itself is defined as a HLSL_LANG LangBuiltin in Builtins.td.
This is used to associate all the dot product typdef defined hlsl_intrinsics.h
with a single intrinsic check in CGBuiltin.cpp & SemaChecking.cpp.

In IntrinsicsDirectX.td we define the llvmIR for the dot product.
A few goals were in mind for this IR. First it should operate on only
vectors. Second the return type should be the vector element type. Third
the second parameter vector should be of the same size as the first
parameter. Finally `a dot b` should be the same as `b dot a`.

In CGBuiltin.cpp hlsl has built on top of existing clang intrinsics via 
EmitBuiltinExpr. Dot
product though is language specific intrinsic and so is guarded behind 
getLangOpts().HLSL.
The call chain looks like this: EmitBuiltinExpr -> EmitHLSLBuiltinExp

EmitHLSLBuiltinExp dot product intrinsics makes a destinction
between vectors and scalars. This is because HLSL supports dot product on 
scalars which simplifies down to multiply.

Sema.h & SemaChecking.cpp saw the addition of CheckHLSLBuiltinFunctionCall, a 
language specific semantic validation that can be expanded for other hlsl 
specific intrinsics.
---
 clang/include/clang/Basic/Builtins.td |   6 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +
 clang/include/clang/Sema/Sema.h   |   1 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  49 
 clang/lib/CodeGen/CodeGenFunction.h   |   1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  92 
 clang/lib/Sema/SemaChecking.cpp   |  84 ++-
 clang/test/CodeGenHLSL/builtins/dot.hlsl  | 216 ++
 clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl  |  46 
 llvm/include/llvm/IR/IntrinsicsDirectX.td |   5 +
 10 files changed, 497 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/dot.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index df74026c5d2d50..771c4f5d4121f4 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4524,6 +4524,12 @@ def HLSLCreateHandle : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void*(unsigned char)";
 }
 
+def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_dot"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fb44495199ee56..9957f4e743e9cb 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10267,6 +10267,8 @@ def err_vec_builtin_non_vector : Error<
  "first two arguments to %0 must be vectors">;
 def err_vec_builtin_incompatible_vector : Error<
   "first two arguments to %0 must have the same type">;
+def err_vec_builtin_incompatible_size : Error<
+  "first two arguments to %0 must have the same size">;
 def err_vsx_builtin_nonconstant_argument : Error<
   "argument %0 to %1 must be a 2-bit unsigned literal (i.e. 0, 1, 2 or 3)">;
 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e9cd42ae777df5..3557db56905ff8 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14055,6 +14055,7 @@ class Sema final {
   bool CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
CallExpr *TheCall);
   bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+  bool CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
   bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum);
   bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
  CallExpr *TheCall);
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d454ccc1dd8613..4bad41a9be214e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -44,6 +44,7 @@
 #include "llvm/IR/IntrinsicsAMDGPU.h"
 #include "llvm/IR/IntrinsicsARM.h"
 #include "llvm/IR/IntrinsicsBPF.h"
+#include "llvm/IR/IntrinsicsDirectX.h"
 #include "llvm/IR/IntrinsicsHexagon.h"
 #include "llvm/IR/IntrinsicsNVPTX.h"
 #include "llvm/IR/IntrinsicsPowerPC.h"
@@ -5982,6 +5983,10 @@ RValue CodeGenFunction::EmitBuiltinE

[clang] [llvm] [AArch64] Add soft-float ABI (PR #74460)

2024-02-16 Thread Nathan Chancellor via cfe-commits

nathanchance wrote:

For what it's worth, this breaks building the Linux kernel for `ARCH=arm64` 
pretty badly, with errors in several drivers:

```
$ make -skj"$(nrpoc)" ARCH=arm64 LLVM=1 mrproper defconfig all
...
drivers/clk/qcom/gcc-ipq6018.c:896:2: error: expression requires 'double' type 
support, but ABI 'aapcs' does not support it
  896 | F(53300, P_GPLL0, 1.5, 0, 0),
  | ^
drivers/clk/qcom/clk-rcg.h:10:41: note: expanded from macro 'F'
   10 | #define F(f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) }
  | ^
...
In file included from drivers/gpu/drm/msm/adreno/a2xx_gpu.c:4:
In file included from drivers/gpu/drm/msm/adreno/a2xx_gpu.h:13:
drivers/gpu/drm/msm/adreno/a2xx.xml.h:1849:24: error: 'A2XX_PA_CL_VPORT_XSCALE' 
requires 'float' type support, but ABI 'aapcs' does not support it
 1849 | static inline uint32_t A2XX_PA_CL_VPORT_XSCALE(float val)
  |^
drivers/gpu/drm/msm/adreno/a2xx.xml.h:1849:24: note: 'A2XX_PA_CL_VPORT_XSCALE' 
defined here
drivers/gpu/drm/msm/adreno/a2xx.xml.h:1857:24: error: 
'A2XX_PA_CL_VPORT_XOFFSET' requires 'float' type support, but ABI 'aapcs' does 
not support it
 1857 | static inline uint32_t A2XX_PA_CL_VPORT_XOFFSET(float val)
  |^
drivers/gpu/drm/msm/adreno/a2xx.xml.h:1857:24: note: 'A2XX_PA_CL_VPORT_XOFFSET' 
defined here
drivers/gpu/drm/msm/adreno/a2xx.xml.h:1865:24: error: 'A2XX_PA_CL_VPORT_YSCALE' 
requires 'float' type support, but ABI 'aapcs' does not support it
 1865 | static inline uint32_t A2XX_PA_CL_VPORT_YSCALE(float val)
  |^
drivers/gpu/drm/msm/adreno/a2xx.xml.h:1865:24: note: 'A2XX_PA_CL_VPORT_YSCALE' 
defined here
...
```

I suspect this may be related to the kernel's use of `-mgeneral-regs-only`? Up 
until this point though, there have been no reported issues with code 
generation or runtime time impact with `clang`-built kernels.

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


[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

2024-02-16 Thread Atousa Duprat via cfe-commits

https://github.com/Atousa updated 
https://github.com/llvm/llvm-project/pull/80939

>From ac75fc2873fc7b8eec6c24ba97f4673e94457c8e Mon Sep 17 00:00:00 2001
From: Atousa Duprat 
Date: Tue, 6 Feb 2024 21:02:05 -0800
Subject: [PATCH 1/5] [clang] Use separator for large numeric values in
 overflow diagnostic

Add functionality to APInt::toString() that allows it to insert
separators between groups of digits, using the C++ litteral
separator ' between groups.

Fixes issue #58228
---
 clang/lib/AST/ExprConstant.cpp  |   6 +-
 clang/test/AST/Interp/c.c   |   4 +-
 clang/test/C/drs/dr0xx.c|   2 +-
 clang/test/C/drs/dr2xx.c|   2 +-
 clang/test/Sema/integer-overflow.c  | 100 -
 clang/test/Sema/switch-1.c  |   6 +-
 clang/test/SemaCXX/enum.cpp |   4 +-
 clang/test/SemaCXX/integer-overflow.cpp | 112 ++--
 clang/test/SemaObjC/integer-overflow.m  |   4 +-
 clang/test/SemaObjC/objc-literal-nsnumber.m |   2 +-
 llvm/include/llvm/ADT/APInt.h   |   3 +-
 llvm/include/llvm/ADT/StringExtras.h|   5 +-
 llvm/lib/Support/APInt.cpp  |  24 -
 llvm/unittests/ADT/APIntTest.cpp|  35 ++
 14 files changed, 185 insertions(+), 124 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f7..d9037072c6767f 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2774,7 +2774,8 @@ static bool CheckedIntArithmetic(EvalInfo &Info, const 
Expr *E,
 if (Info.checkingForUndefinedBehavior())
   Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_integer_constant_overflow)
-  << toString(Result, 10) << E->getType() << E->getSourceRange();
+  << toString(Result, 10, Result.isSigned(), false, true, true)
+  << E->getType() << E->getSourceRange();
 return HandleOverflow(Info, E, Value, E->getType());
   }
   return true;
@@ -13852,7 +13853,8 @@ bool IntExprEvaluator::VisitUnaryOperator(const 
UnaryOperator *E) {
   if (Info.checkingForUndefinedBehavior())
 Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
  diag::warn_integer_constant_overflow)
-<< toString(Value, 10) << E->getType() << E->getSourceRange();
+<< toString(Value, 10, Value.isSigned(), false, true, true)
+<< E->getType() << E->getSourceRange();
 
   if (!HandleOverflow(Info, E, -Value.extend(Value.getBitWidth() + 1),
   E->getType()))
diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 9ab271a82aeef9..aa067b0bc74831 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -109,9 +109,9 @@ int somefunc(int i) {
  // pedantic-expected-warning {{left operand of 
comma operator has no effect}} \
  // pedantic-expected-warning {{overflow in 
expression; result is 131073}} \
  // ref-warning {{left operand of comma operator 
has no effect}} \
- // ref-warning {{overflow in expression; result 
is 131073}} \
+ // ref-warning {{overflow in expression; result 
is 131'073}} \
  // pedantic-ref-warning {{left operand of comma 
operator has no effect}} \
- // pedantic-ref-warning {{overflow in expression; 
result is 131073}}
+ // pedantic-ref-warning {{overflow in expression; 
result is 131'073}}
 
 }
 
diff --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index d9c1fbe4ee40ab..c93cfb63d604cf 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -214,7 +214,7 @@ _Static_assert(__builtin_types_compatible_p(struct S { int 
a; }, union U { int a
  */
 void dr031(int i) {
   switch (i) {
-  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   #pragma clang diagnostic push
   #pragma clang diagnostic ignored "-Wswitch"
   /* Silence the targets which issue:
diff --git a/clang/test/C/drs/dr2xx.c b/clang/test/C/drs/dr2xx.c
index 9c8d77518ab55e..1b68b65acca6af 100644
--- a/clang/test/C/drs/dr2xx.c
+++ b/clang/test/C/drs/dr2xx.c
@@ -277,7 +277,7 @@ void dr258(void) {
 void dr261(void) {
   /* This is still an integer constant expression despite the overflow. */
   enum e1 {
-ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   };
 
   /* This is not an integer constant ex

[clang] [llvm] [AMDGPU] Use `bf16` instead of `i16` for bfloat (PR #80908)

2024-02-16 Thread Jay Foad via cfe-commits


@@ -157,6 +157,27 @@ static uint32_t getLit16Encoding(uint16_t Val, const 
MCSubtargetInfo &STI) {
   return 255;
 }
 
+static uint32_t getLitBF16Encoding(uint16_t Val) {
+  uint16_t IntImm = getIntInlineImmEncoding(static_cast(Val));
+  if (IntImm != 0)
+return IntImm;
+
+  // clang-format off
+  switch (Val) {

jayfoad wrote:

Can this call `getInlineEncodingV2BF16`?

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


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/81985

>From ddafb4672e1a481d4a9556ebe31ca9a07e1f3569 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 16 Feb 2024 03:51:07 -0800
Subject: [PATCH 1/2] [clang-tidy][readability-identifier-naming] Resolve
 symlinks for checking style for file

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools
---
 .../readability/IdentifierNamingCheck.cpp |  7 +--
 .../Inputs/identifier-naming/symlink/build/test.h |  1 +
 .../identifier-naming/symlink/include/.clang-tidy |  4 
 .../identifier-naming/symlink/include/test.h  |  1 +
 .../readability/identifier-naming-symlink.cpp | 15 +++
 5 files changed, 26 insertions(+), 2 deletions(-)
 create mode 12 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 5db9e99ab23708..335c3de25b861b 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1408,13 +1408,16 @@ const IdentifierNamingCheck::FileStyle &
 IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
   if (!GetConfigPerFile)
 return *MainFileStyle;
-  StringRef Parent = llvm::sys::path::parent_path(FileName);
+
+  SmallString<128> RealFileName;
+  llvm::sys::fs::real_path(FileName, RealFileName);
+  StringRef Parent = llvm::sys::path::parent_path(RealFileName);
   auto Iter = NamingStylesCache.find(Parent);
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
   llvm::StringRef CheckName = getID();
-  ClangTidyOptions Options = Context->getOptionsForFile(FileName);
+  ClangTidyOptions Options = Context->getOptionsForFile(RealFileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(
 Parent,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
new file mode 12
index 00..de218fbfa4662a
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
@@ -0,0 +1 @@
+../include/test.h
\ No newline at end of file
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
new file mode 100644
index 00..296550f3aab1eb
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
@@ -0,0 +1,4 @@
+Checks: readability-identifier-naming
+CheckOptions:
+  readability-identifier-naming.GlobalConstantCase: CamelCase
+  readability-identifier-naming.GlobalConstantPrefix: k
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
new file mode 100644
index 00..f3560e4e50b9ed
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
@@ -0,0 +1 @@
+const int global_const = 5;
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
new file mode 100644
index 00..72926bff908df8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
@@ -0,0 +1,15 @@
+// Specify `-std=c++20` to run test only once becuase test expects changes
+// in the header file so it fails if runs multiple times with different
+// `-std` flags as check_clang_tidy doesn by default.
+//
+// RUN: rm -

[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-16 Thread David Peixotto via cfe-commits

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

LGTM

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


  1   2   3   >