[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread via cfe-commits

koachan wrote:

Ping?

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


[clang] [Sema][ObjC] Add warning options to detect bad name prefixes. (PR #97597)

2024-07-31 Thread Alastair Houghton via cfe-commits

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


[clang] [Sema][ObjC] Add warning options to detect bad name prefixes. (PR #97597)

2024-07-31 Thread Alastair Houghton via cfe-commits

al45tair wrote:

Converting back to draft as I'm still tinkering slightly with the warning rules.

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


[clang] [clang] Implement type/address discrimination of type_info vtable. (PR #99726)

2024-07-31 Thread Daniil Kovalev via cfe-commits

kovdan01 wrote:

@ahmedbougacha It looks like there is some missing codegen logic. Particularly, 
in `ItaniumRTTIBuilder::BuildVTablePointer` 
(clang/lib/CodeGen/ItaniumCXXABI.cpp), there is the following piece of code:

```
  if (auto &Schema = CGM.getCodeGenOpts().PointerAuth.CXXTypeInfoVTablePointer)
VTable = CGM.getConstantSignedPointer(VTable, Schema, nullptr, GlobalDecl(),
  QualType(Ty, 0));
```

Here, `nullptr` is used as `StorageAddress` unconditionally, so, address 
discrimination is not actually enabled even if requested. It caused test-suite 
failures in several EH-related tests.

I was able to fix that locally by just using a dummy `ptr inttoptr (i64 1 to 
ptr)` value as `StorageAddress` (just like you did with coroutines and as I did 
with init/fini, see 
https://github.com/llvm/llvm-project/pull/96478#issuecomment-2196819332), and 
tests became passing. I'm not sure how to get a proper `StorageAddress` here, 
so I've used that dummy placeholder which actually seems to do the job.

Do you have some logic for this locally that you've not upstreamed yet? If yes, 
could you please open a PR adding that? If no, I'm happy to submit a PR with a 
fix described above by myself.

Also tagging @asl

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


[clang] [PPC] Disable vsx and altivec when -msoft-float is used (PR #100450)

2024-07-31 Thread Chen Zheng via cfe-commits

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


[clang] [PPC] Disable vsx and altivec when -msoft-float is used (PR #100450)

2024-07-31 Thread Chen Zheng via cfe-commits


@@ -0,0 +1,26 @@
+// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr10 -msoft-float -S 
-emit-llvm %s -o - | FileCheck %s -check-prefix=CHECKSOFT
+// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr10 -S -emit-llvm %s 
-o - | FileCheck %s -check-prefix=CHECKNOSOFT
+
+int main () {
+  return 0;
+}
+
+// CHECKSOFT-DAG: -hard-float
+// CHECKSOFT-DAG: -vsx
+// CHECKSOFT-DAG: -altivec
+// CHECKSOFT-DAG: -direct-move,
+// CHECKSOFT-DAG: -float128
+// CHECKSOFT-DAG: -mma
+// CHECKSOFT-DAG: -paired-vector-memops
+// CHECKSOFT-DAG: -power10-vector
+// CHECKSOFT-DAG: -power9-vector
+// CHECKSOFT-DAG: -power8-vector
+
+// CHECKNOSOFT-DAG: +vsx
+// CHECKNOSOFT-DAG: +altivec
+// CHECKNOSOFT-DAG: +direct-move,

chenzheng1030 wrote:

Ditto

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


[clang] [PPC] Disable vsx and altivec when -msoft-float is used (PR #100450)

2024-07-31 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 commented:

Compared with `llvm/lib/Target/PowerPC/PPC.td`, seems still miss below implicit 
flag:
`crypto`

```
def FeatureP8Crypto : SubtargetFeature<"crypto", "HasP8Crypto", "true",
   "Enable POWER8 Crypto instructions",
   [FeatureP8Altivec]>;
```

Other implications from `hard-float` are all covered in this patch.

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


[clang] [PPC] Disable vsx and altivec when -msoft-float is used (PR #100450)

2024-07-31 Thread Chen Zheng via cfe-commits


@@ -0,0 +1,26 @@
+// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr10 -msoft-float -S 
-emit-llvm %s -o - | FileCheck %s -check-prefix=CHECKSOFT
+// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr10 -S -emit-llvm %s 
-o - | FileCheck %s -check-prefix=CHECKNOSOFT
+
+int main () {
+  return 0;
+}
+
+// CHECKSOFT-DAG: -hard-float
+// CHECKSOFT-DAG: -vsx
+// CHECKSOFT-DAG: -altivec
+// CHECKSOFT-DAG: -direct-move,

chenzheng1030 wrote:

nit: do we need the `,` at the end?

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


[clang] [clang] Fix crash with multiple non-parenthsized `sizeof` (PR #101297)

2024-07-31 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/101297

There are 5 unary operators that can be followed by a non-parenthesized 
expression: `sizeof`, `__datasizeof`, `__alignof`, `alignof`, `_Alignof`. When 
we nest them too deep, `BalancedDelimiterTracker` does not help, because there 
are no parentheses, and we crash. Instead, this patch recognize chains of those 
operators, and parse them with sufficient stack space.

Fixes #45061

>From d75b3cef41c370fef939a347935a4f3ed53c46ea Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 31 Jul 2024 10:29:04 +0300
Subject: [PATCH] [clang] Fix crash with multiple non-parenthsized `sizeof`

---
 clang/lib/Parse/ParseExpr.cpp |  14 +-
 .../parser-overflow-non-parenthesized.c   | 135 ++
 2 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Parser/parser-overflow-non-parenthesized.c

diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index e82b565272831..e501d5e91e77d 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2479,7 +2479,19 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token 
&OpTok,
   return ExprError();
 }
 
-Operand = ParseCastExpression(UnaryExprOnly);
+// If we're parsing a chain that consists of keywords that could be
+// followed by a non-parenthesized expression, BalancedDelimiterTracker
+// is not going to help when the nesting is too deep. In this corner case
+// we continue to parse with sufficient stack space to avoid crashing.
+if (OpTok.isOneOf(tok::kw_sizeof, tok::kw___datasizeof, tok::kw___alignof,
+  tok::kw_alignof, tok::kw__Alignof) &&
+Tok.isOneOf(tok::kw_sizeof, tok::kw___datasizeof, tok::kw___alignof,
+tok::kw_alignof, tok::kw__Alignof))
+  Actions.runWithSufficientStackSpace(Tok.getLocation(), [&] {
+Operand = ParseCastExpression(UnaryExprOnly);
+  });
+else
+  Operand = ParseCastExpression(UnaryExprOnly);
   } else {
 // If it starts with a '(', we know that it is either a parenthesized
 // type-name, or it is a unary-expression that starts with a compound
diff --git a/clang/test/Parser/parser-overflow-non-parenthesized.c 
b/clang/test/Parser/parser-overflow-non-parenthesized.c
new file mode 100644
index 0..b6c7485274090
--- /dev/null
+++ b/clang/test/Parser/parser-overflow-non-parenthesized.c
@@ -0,0 +1,135 @@
+// RUN: %clang_cc1 %s 2>&1 | FileCheck %s
+
+void f(void) {
+  // 600 sizeof's
+  int a =
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof size

[clang] [clang] Fix crash with multiple non-parenthsized `sizeof` (PR #101297)

2024-07-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

There are 5 unary operators that can be followed by a non-parenthesized 
expression: `sizeof`, `__datasizeof`, `__alignof`, `alignof`, `_Alignof`. When 
we nest them too deep, `BalancedDelimiterTracker` does not help, because there 
are no parentheses, and we crash. Instead, this patch recognize chains of those 
operators, and parse them with sufficient stack space.

Fixes #45061

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


2 Files Affected:

- (modified) clang/lib/Parse/ParseExpr.cpp (+13-1) 
- (added) clang/test/Parser/parser-overflow-non-parenthesized.c (+135) 


``diff
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index e82b565272831..e501d5e91e77d 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2479,7 +2479,19 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token 
&OpTok,
   return ExprError();
 }
 
-Operand = ParseCastExpression(UnaryExprOnly);
+// If we're parsing a chain that consists of keywords that could be
+// followed by a non-parenthesized expression, BalancedDelimiterTracker
+// is not going to help when the nesting is too deep. In this corner case
+// we continue to parse with sufficient stack space to avoid crashing.
+if (OpTok.isOneOf(tok::kw_sizeof, tok::kw___datasizeof, tok::kw___alignof,
+  tok::kw_alignof, tok::kw__Alignof) &&
+Tok.isOneOf(tok::kw_sizeof, tok::kw___datasizeof, tok::kw___alignof,
+tok::kw_alignof, tok::kw__Alignof))
+  Actions.runWithSufficientStackSpace(Tok.getLocation(), [&] {
+Operand = ParseCastExpression(UnaryExprOnly);
+  });
+else
+  Operand = ParseCastExpression(UnaryExprOnly);
   } else {
 // If it starts with a '(', we know that it is either a parenthesized
 // type-name, or it is a unary-expression that starts with a compound
diff --git a/clang/test/Parser/parser-overflow-non-parenthesized.c 
b/clang/test/Parser/parser-overflow-non-parenthesized.c
new file mode 100644
index 0..b6c7485274090
--- /dev/null
+++ b/clang/test/Parser/parser-overflow-non-parenthesized.c
@@ -0,0 +1,135 @@
+// RUN: %clang_cc1 %s 2>&1 | FileCheck %s
+
+void f(void) {
+  // 600 sizeof's
+  int a =
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof s

[clang] [clang] Fix crash with multiple non-parenthsized `sizeof` (PR #101297)

2024-07-31 Thread Vlad Serebrennikov via cfe-commits

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

>From d75b3cef41c370fef939a347935a4f3ed53c46ea Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 31 Jul 2024 10:29:04 +0300
Subject: [PATCH 1/2] [clang] Fix crash with multiple non-parenthsized `sizeof`

---
 clang/lib/Parse/ParseExpr.cpp |  14 +-
 .../parser-overflow-non-parenthesized.c   | 135 ++
 2 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Parser/parser-overflow-non-parenthesized.c

diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index e82b565272831..e501d5e91e77d 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2479,7 +2479,19 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token 
&OpTok,
   return ExprError();
 }
 
-Operand = ParseCastExpression(UnaryExprOnly);
+// If we're parsing a chain that consists of keywords that could be
+// followed by a non-parenthesized expression, BalancedDelimiterTracker
+// is not going to help when the nesting is too deep. In this corner case
+// we continue to parse with sufficient stack space to avoid crashing.
+if (OpTok.isOneOf(tok::kw_sizeof, tok::kw___datasizeof, tok::kw___alignof,
+  tok::kw_alignof, tok::kw__Alignof) &&
+Tok.isOneOf(tok::kw_sizeof, tok::kw___datasizeof, tok::kw___alignof,
+tok::kw_alignof, tok::kw__Alignof))
+  Actions.runWithSufficientStackSpace(Tok.getLocation(), [&] {
+Operand = ParseCastExpression(UnaryExprOnly);
+  });
+else
+  Operand = ParseCastExpression(UnaryExprOnly);
   } else {
 // If it starts with a '(', we know that it is either a parenthesized
 // type-name, or it is a unary-expression that starts with a compound
diff --git a/clang/test/Parser/parser-overflow-non-parenthesized.c 
b/clang/test/Parser/parser-overflow-non-parenthesized.c
new file mode 100644
index 0..b6c7485274090
--- /dev/null
+++ b/clang/test/Parser/parser-overflow-non-parenthesized.c
@@ -0,0 +1,135 @@
+// RUN: %clang_cc1 %s 2>&1 | FileCheck %s
+
+void f(void) {
+  // 600 sizeof's
+  int a =
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeo

[clang] [clang] Fix crash with multiple non-parenthsized `sizeof` (PR #101297)

2024-07-31 Thread Vlad Serebrennikov via cfe-commits

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

>From d75b3cef41c370fef939a347935a4f3ed53c46ea Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 31 Jul 2024 10:29:04 +0300
Subject: [PATCH 1/3] [clang] Fix crash with multiple non-parenthsized `sizeof`

---
 clang/lib/Parse/ParseExpr.cpp |  14 +-
 .../parser-overflow-non-parenthesized.c   | 135 ++
 2 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Parser/parser-overflow-non-parenthesized.c

diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index e82b565272831..e501d5e91e77d 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2479,7 +2479,19 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token 
&OpTok,
   return ExprError();
 }
 
-Operand = ParseCastExpression(UnaryExprOnly);
+// If we're parsing a chain that consists of keywords that could be
+// followed by a non-parenthesized expression, BalancedDelimiterTracker
+// is not going to help when the nesting is too deep. In this corner case
+// we continue to parse with sufficient stack space to avoid crashing.
+if (OpTok.isOneOf(tok::kw_sizeof, tok::kw___datasizeof, tok::kw___alignof,
+  tok::kw_alignof, tok::kw__Alignof) &&
+Tok.isOneOf(tok::kw_sizeof, tok::kw___datasizeof, tok::kw___alignof,
+tok::kw_alignof, tok::kw__Alignof))
+  Actions.runWithSufficientStackSpace(Tok.getLocation(), [&] {
+Operand = ParseCastExpression(UnaryExprOnly);
+  });
+else
+  Operand = ParseCastExpression(UnaryExprOnly);
   } else {
 // If it starts with a '(', we know that it is either a parenthesized
 // type-name, or it is a unary-expression that starts with a compound
diff --git a/clang/test/Parser/parser-overflow-non-parenthesized.c 
b/clang/test/Parser/parser-overflow-non-parenthesized.c
new file mode 100644
index 0..b6c7485274090
--- /dev/null
+++ b/clang/test/Parser/parser-overflow-non-parenthesized.c
@@ -0,0 +1,135 @@
+// RUN: %clang_cc1 %s 2>&1 | FileCheck %s
+
+void f(void) {
+  // 600 sizeof's
+  int a =
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeo

[clang] [clang][CUDA] Add 'noconvergent' function and statement attribute (PR #100637)

2024-07-31 Thread Matt Arsenault via cfe-commits

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


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


[clang] 996075d - [clang][Interp] Handle virtual calls with covariant return types (#101218)

2024-07-31 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-07-31T09:47:45+02:00
New Revision: 996075d68357d15b9bdbbafee002e50563532cb6

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

LOG: [clang][Interp] Handle virtual calls with covariant return types (#101218)

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index d128988a480e1..63e9966b831db 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -2628,7 +2628,29 @@ inline bool CallVirt(InterpState &S, CodePtr OpPC, const 
Function *Func,
 }
   }
 
-  return Call(S, OpPC, Func, VarArgSize);
+  if (!Call(S, OpPC, Func, VarArgSize))
+return false;
+
+  // Covariant return types. The return type of Overrider is a pointer
+  // or reference to a class type.
+  if (Overrider != InitialFunction &&
+  Overrider->getReturnType()->isPointerOrReferenceType() &&
+  InitialFunction->getReturnType()->isPointerOrReferenceType()) {
+QualType OverriderPointeeType =
+Overrider->getReturnType()->getPointeeType();
+QualType InitialPointeeType =
+InitialFunction->getReturnType()->getPointeeType();
+// We've called Overrider above, but calling code expects us to return what
+// InitialFunction returned. According to the rules for covariant return
+// types, what InitialFunction returns needs to be a base class of what
+// Overrider returns. So, we need to do an upcast here.
+unsigned Offset = S.getContext().collectBaseOffset(
+InitialPointeeType->getAsRecordDecl(),
+OverriderPointeeType->getAsRecordDecl());
+return GetPtrBasePop(S, OpPC, Offset);
+  }
+
+  return true;
 }
 
 inline bool CallBI(InterpState &S, CodePtr &PC, const Function *Func,

diff  --git a/clang/test/AST/Interp/cxx2a.cpp b/clang/test/AST/Interp/cxx2a.cpp
index 27d1aa1a27f75..ad021b30cfd3c 100644
--- a/clang/test/AST/Interp/cxx2a.cpp
+++ b/clang/test/AST/Interp/cxx2a.cpp
@@ -13,3 +13,24 @@ consteval int aConstevalFunction() { // both-error 
{{consteval function never pr
   return 0;
 }
 /// We're NOT calling the above function. The diagnostics should appear anyway.
+
+namespace Covariant {
+  struct A {
+virtual constexpr char f() const { return 'Z'; }
+char a = f();
+  };
+
+  struct D : A {};
+  struct Covariant1 {
+D d;
+virtual const A *f() const;
+  };
+
+  struct Covariant3 : Covariant1 {
+constexpr virtual const D *f() const { return &this->d; }
+  };
+
+  constexpr Covariant3 cb;
+  constexpr const Covariant1 *cb1 = &cb;
+  static_assert(cb1->f()->a == 'Z');
+}



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


[clang] [clang][Interp] Handle virtual calls with covariant return types (PR #101218)

2024-07-31 Thread Timm Baeder via cfe-commits

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


[clang] [clang] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-07-31 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/78112

>From 92f8720e3d21521b589d5291f086a2f32b87bfe0 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 14 Jan 2024 19:52:31 +
Subject: [PATCH 01/11] [clang] [SemaCXX] Implement CWG2627 Bit-fields and
 narrowing conversions

---
 clang/docs/ReleaseNotes.rst   |   5 +
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Overload.h   |   7 +-
 clang/lib/Sema/SemaExpr.cpp   |  10 +-
 clang/lib/Sema/SemaInit.cpp   |  20 ++-
 clang/lib/Sema/SemaOverload.cpp   | 119 +--
 .../dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp |  24 
 clang/test/CXX/drs/dr26xx.cpp | 136 ++
 clang/www/cxx_dr_status.html  |   2 +-
 9 files changed, 278 insertions(+), 48 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 92563262cc673..28202fc604e29 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -157,6 +157,11 @@ Resolutions to C++ Defect Reports
 - Clang now diagnoses declarative nested-name-specifiers with 
pack-index-specifiers.
   (`CWG2858: Declarative nested-name-specifiers and pack-index-specifiers 
`_).
 
+- Casts from a bit-field to an integral type is now not considered narrowing 
if the
+  width of the bit-field means that all potential values are in the range
+  of the target type, even if the type of the bit-field is larger.
+  (`CWG2627. Bit-fields and narrowing conversions  
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fdca82934cb4d..6cdb439be30ae 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6253,6 +6253,9 @@ def ext_init_list_variable_narrowing_const_reference : 
ExtWarn<
 def ext_init_list_constant_narrowing : ExtWarn<
   "constant expression evaluates to %0 which cannot be narrowed to type %1">,
   InGroup, DefaultError, SFINAEFailure;
+def ext_bit_field_narrowing : Extension<
+  "narrowing non-constant-expression from %0 bit-field of width %2 to %1 is a 
C++23 extension">,
+  InGroup, SFINAEFailure;
 def ext_init_list_constant_narrowing_const_reference : ExtWarn<
   ext_init_list_constant_narrowing.Summary>,
   InGroup, DefaultError, SFINAEFailure;
diff --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index 76311b00d2fc5..0d94045cc13f7 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -244,7 +244,11 @@ class Sema;
 /// Not a narrowing conversion.
 NK_Not_Narrowing,
 
-/// A narrowing conversion by virtue of the source and destination types.
+/// Not a narrowing conversion in C++23 because the source is a bit-field
+/// whose range can fit in the target type
+NK_BitField_Not_Narrowing,
+
+/// A narrowing conversion by virtue of the source and target types.
 NK_Type_Narrowing,
 
 /// A narrowing conversion, because a constant expression got narrowed.
@@ -387,6 +391,7 @@ class Sema;
 NarrowingKind
 getNarrowingKind(ASTContext &Context, const Expr *Converted,
  APValue &ConstantValue, QualType &ConstantType,
+ unsigned &BitFieldWidth,
  bool IgnoreFloatToIntegralConversion = false) const;
 bool isPointerConversionToBool() const;
 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 50f92c496a539..4c16fcc60fc77 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -12361,8 +12361,9 @@ static bool checkThreeWayNarrowingConversion(Sema &S, 
QualType ToType, Expr *E,
 
   APValue PreNarrowingValue;
   QualType PreNarrowingType;
+  unsigned BitFieldWidth;
   switch (SCS.getNarrowingKind(S.Context, E, PreNarrowingValue,
-   PreNarrowingType,
+   PreNarrowingType, BitFieldWidth,
/*IgnoreFloatToIntegralConversion*/ true)) {
   case NK_Dependent_Narrowing:
 // Implicit conversion to a narrower type, but the expression is
@@ -12370,6 +12371,13 @@ static bool checkThreeWayNarrowingConversion(Sema &S, 
QualType ToType, Expr *E,
   case NK_Not_Narrowing:
 return false;
 
+  case NK_BitField_Not_Narrowing:
+if (!S.getLangOpts().CPlusPlus23) {
+  return S.Diag(E->getBeginLoc(), diag::ext_bit_field_narrowing)
+ << FromType << ToType << BitFieldWidth;
+}
+return false;
+
   case NK_Constant_Narrowing:
 // Implicit conversion to a narrower type, and the value is not a constant
 // expression.
diff --git a/cl

[clang] Fix coverage when `/fo` is used (PR #88201)

2024-07-31 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [CMake][Fuchsia] Include libunwind and libc++abi in baremetal build (PR #100908)

2024-07-31 Thread Petr Hosek via cfe-commits

https://github.com/petrhosek updated 
https://github.com/llvm/llvm-project/pull/100908

>From 5177b4ac9ce9d1b45e80e0613e1cb3363e73bd39 Mon Sep 17 00:00:00 2001
From: Petr Hosek 
Date: Sat, 27 Jul 2024 17:10:01 -0700
Subject: [PATCH] [CMake][Fuchsia] Include libunwind and libc++abi in baremetal
 build

These are needed for baremetal targets as well.
---
 clang/cmake/caches/Fuchsia-stage2.cmake | 42 -
 1 file changed, 34 insertions(+), 8 deletions(-)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 8e0835cb3158f..237b103ef8847 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -312,6 +312,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(BUILTINS_${target}_CMAKE_${lang}_local_flags 
"${BUILTINS_${target}_CMAKE_${lang}_local_flags} -mfloat-abi=hard 
-march=armv8m.main+fp+dsp -mcpu=cortex-m33" CACHE STRING "")
 endif()
 set(BUILTINS_${target}_CMAKE_${lang}_FLAGS 
"${BUILTINS_${target}_CMAKE_${lang}_local_flags}" CACHE STRING "")
+set(BUILTINS_${target}_CMAKE_${lang}_FLAGS_MINSIZEREL "-Oz -DNDEBUG" CACHE 
STRING "")
   endforeach()
   foreach(type SHARED;MODULE;EXE)
 set(BUILTINS_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
@@ -328,6 +329,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
 # TODO: The preprocessor defines workaround various issues in libc and 
libc++ integration.
 # These should be addressed and removed over time.
 set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mthumb 
-Wno-atomic-alignment \"-Dvfprintf(stream, format, vlist)=vprintf(format, 
vlist)\" \"-Dfprintf(stream, format, ...)=printf(format)\" \"-Dtimeval=struct 
timeval{int tv_sec; int tv_usec;}\" \"-Dgettimeofday(tv, tz)\" 
-D_LIBCPP_PRINT=1" CACHE STRING "")
+set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS_MINSIZEREL "-Oz -DNDEBUG" CACHE 
STRING "")
   endforeach()
   foreach(type SHARED;MODULE;EXE)
 set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
@@ -335,11 +337,23 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(RUNTIMES_${target}_LLVM_LIBC_FULL_BUILD ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBC_ENABLE_USE_BY_CLANG ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBC_USE_NEW_HEADER_GEN OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
-  set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
+  set(RUNTIMES_${target}_LIBUNWIND_IS_BAREMETAL ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBUNWIND_ENABLE_ASSERTIONS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBUNWIND_ENABLE_THREADS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBUNWIND_ENABLE_STATIC ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBUNWIND_REMEMBER_HEAP_ALLOC ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_BAREMETAL ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_ASSERTIONS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_STATIC ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ABI_UNSTABLE ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_LIBC "llvm-libc" CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
@@ -353,7 +367,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
   set(RUNTIMES_${target}_LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "libc;libcxx" CACHE STRING "")
+  set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES 
"libc;libunwind;libcxxabi;libcxx" CACHE STRING "")
 endforeach()
 
 foreach(target riscv32-unknown-elf)
@@ -387,11 +401,23 @@ foreach(target riscv32-unknown-elf)
   set(RUNTIMES_${target}_LLVM_LIBC_FULL_BUILD ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBC_ENABLE_USE_BY_CLANG ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBC_USE_NEW_HEADER_GEN OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
-  set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
+  set(RUN

[clang] [CMake][Fuchsia] Include libunwind and libc++abi in baremetal build (PR #100908)

2024-07-31 Thread Petr Hosek via cfe-commits

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


[clang] 8300eaa - [CMake][Fuchsia] Include libunwind and libc++abi in baremetal build (#100908)

2024-07-31 Thread via cfe-commits

Author: Petr Hosek
Date: 2024-07-31T01:08:56-07:00
New Revision: 8300eaad0f6c354f40f526f7501b624ffc389e63

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

LOG: [CMake][Fuchsia] Include libunwind and libc++abi in baremetal build 
(#100908)

These are needed for baremetal targets as well.

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 75ceb799352f9..c1d0d7b63f957 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -312,6 +312,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(BUILTINS_${target}_CMAKE_${lang}_local_flags 
"${BUILTINS_${target}_CMAKE_${lang}_local_flags} -mfloat-abi=softfp 
-march=armv8m.main+fp+dsp -mcpu=cortex-m33" CACHE STRING "")
 endif()
 set(BUILTINS_${target}_CMAKE_${lang}_FLAGS 
"${BUILTINS_${target}_CMAKE_${lang}_local_flags}" CACHE STRING "")
+set(BUILTINS_${target}_CMAKE_${lang}_FLAGS_MINSIZEREL "-Oz -DNDEBUG" CACHE 
STRING "")
   endforeach()
   foreach(type SHARED;MODULE;EXE)
 set(BUILTINS_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
@@ -332,6 +333,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(RUNTIMES_${target}_CMAKE_${lang}_local_flags 
"${RUNTIMES_${target}_CMAKE_${lang}_local_flags} -mfloat-abi=softfp 
-march=armv8m.main+fp+dsp -mcpu=cortex-m33" CACHE STRING "")
 endif()
 set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS 
"${RUNTIMES_${target}_CMAKE_${lang}_local_flags}" CACHE STRING "")
+set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS_MINSIZEREL "-Oz -DNDEBUG" CACHE 
STRING "")
   endforeach()
   foreach(type SHARED;MODULE;EXE)
 set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
@@ -339,11 +341,23 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(RUNTIMES_${target}_LLVM_LIBC_FULL_BUILD ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBC_ENABLE_USE_BY_CLANG ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBC_USE_NEW_HEADER_GEN OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
-  set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
+  set(RUNTIMES_${target}_LIBUNWIND_IS_BAREMETAL ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBUNWIND_ENABLE_ASSERTIONS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBUNWIND_ENABLE_THREADS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBUNWIND_ENABLE_STATIC ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBUNWIND_REMEMBER_HEAP_ALLOC ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_BAREMETAL ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_ASSERTIONS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_STATIC ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ABI_UNSTABLE ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_LIBC "llvm-libc" CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
@@ -357,7 +371,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
   set(RUNTIMES_${target}_LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "libc;libcxx" CACHE STRING "")
+  set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES 
"libc;libunwind;libcxxabi;libcxx" CACHE STRING "")
 endforeach()
 
 foreach(target riscv32-unknown-elf)
@@ -391,11 +405,23 @@ foreach(target riscv32-unknown-elf)
   set(RUNTIMES_${target}_LLVM_LIBC_FULL_BUILD ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBC_ENABLE_USE_BY_CLANG ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBC_USE_NEW_HEADER_GEN OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
-  set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
+  set(RUNTIMES_${target}_LIBUNWIND_IS_BAREMETAL ON CAC

[clang] [clang] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-07-31 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

@AaronBallman This shouldn't affect C at all since this is only about 
non-constant-expressions which come from a bit-field

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


[clang] Reland: "[Clang] Demote always_inline error to warning for mismatching SME attrs" (#100991) (PR #100996)

2024-07-31 Thread Sander de Smalen via cfe-commits

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


[clang] Reland: "[Clang] Demote always_inline error to warning for mismatching SME attrs" (#100991) (PR #100996)

2024-07-31 Thread Sander de Smalen via cfe-commits

sdesmalen-arm wrote:

/cherry-pick 389679d5f9055bffe8bbd25ae41f084a8d08e0f8

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


[clang] [Driver] Have getTargetSubDirPath better match get_compiler_rt_target (PR #100091)

2024-07-31 Thread Rainer Orth via cfe-commits


@@ -766,9 +766,19 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
 return {};
   };
 
-  if (auto Path = getPathForTriple(getTriple()))
+  llvm::Triple Triple = getTriple();
+
+  // Try triple as is.
+  if (auto Path = getPathForTriple(Triple))
 return *Path;
 
+  // Match transformations in CompilerRTUtils.cmake:get_compiler_rt_target.

rorth wrote:

It's not, some BSDs prefer the `amd64` form, too.  Besides, 
`get_compiler_rt_target` does it unconditionally, so `clang` should match.

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


[clang] [CMake][Fuchsia] Use standard spelling for Arm baremetal targets (PR #101302)

2024-07-31 Thread Petr Hosek via cfe-commits

https://github.com/petrhosek created 
https://github.com/llvm/llvm-project/pull/101302

It's more common to use `none` rather than `unknown` for the OS component in 
Arm baremetal targets.

>From ac8f9a208ffaae64d31c699e2bc026f1cfae9dc8 Mon Sep 17 00:00:00 2001
From: Petr Hosek 
Date: Wed, 31 Jul 2024 01:16:34 -0700
Subject: [PATCH] [CMake][Fuchsia] Use standard spelling for Arm baremetal
 targets

It's more common to use `none` rather than `unknown` for the OS
component in Arm baremetal targets.
---
 clang/cmake/caches/Fuchsia-stage2.cmake | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index c1d0d7b63f957..4eba74a016782 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -300,7 +300,7 @@ if(FUCHSIA_SDK)
   set(LLVM_RUNTIME_MULTILIB_hwasan+noexcept_TARGETS 
"aarch64-unknown-fuchsia;riscv64-unknown-fuchsia" CACHE STRING "")
 endif()
 
-foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
+foreach(target armv6m-none-eabi;armv7m-none-eabi;armv8m.main-none-eabi)
   list(APPEND BUILTIN_TARGETS "${target}")
   set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
@@ -308,7 +308,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(BUILTINS_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   foreach(lang C;CXX;ASM)
 set(BUILTINS_${target}_CMAKE_${lang}_local_flags "--target=${target} 
-mthumb")
-if(${target} STREQUAL "armv8m.main-unknown-eabi")
+if(${target} STREQUAL "armv8m.main-none-eabi")
   set(BUILTINS_${target}_CMAKE_${lang}_local_flags 
"${BUILTINS_${target}_CMAKE_${lang}_local_flags} -mfloat-abi=softfp 
-march=armv8m.main+fp+dsp -mcpu=cortex-m33" CACHE STRING "")
 endif()
 set(BUILTINS_${target}_CMAKE_${lang}_FLAGS 
"${BUILTINS_${target}_CMAKE_${lang}_local_flags}" CACHE STRING "")

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


[clang] [CMake][Fuchsia] Use standard spelling for Arm baremetal targets (PR #101302)

2024-07-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Petr Hosek (petrhosek)


Changes

It's more common to use `none` rather than `unknown` for the OS component in 
Arm baremetal targets.

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


1 Files Affected:

- (modified) clang/cmake/caches/Fuchsia-stage2.cmake (+2-2) 


``diff
diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index c1d0d7b63f957..4eba74a016782 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -300,7 +300,7 @@ if(FUCHSIA_SDK)
   set(LLVM_RUNTIME_MULTILIB_hwasan+noexcept_TARGETS 
"aarch64-unknown-fuchsia;riscv64-unknown-fuchsia" CACHE STRING "")
 endif()
 
-foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
+foreach(target armv6m-none-eabi;armv7m-none-eabi;armv8m.main-none-eabi)
   list(APPEND BUILTIN_TARGETS "${target}")
   set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "")
@@ -308,7 +308,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(BUILTINS_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   foreach(lang C;CXX;ASM)
 set(BUILTINS_${target}_CMAKE_${lang}_local_flags "--target=${target} 
-mthumb")
-if(${target} STREQUAL "armv8m.main-unknown-eabi")
+if(${target} STREQUAL "armv8m.main-none-eabi")
   set(BUILTINS_${target}_CMAKE_${lang}_local_flags 
"${BUILTINS_${target}_CMAKE_${lang}_local_flags} -mfloat-abi=softfp 
-march=armv8m.main+fp+dsp -mcpu=cortex-m33" CACHE STRING "")
 endif()
 set(BUILTINS_${target}_CMAKE_${lang}_FLAGS 
"${BUILTINS_${target}_CMAKE_${lang}_local_flags}" CACHE STRING "")

``




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


[clang] Reland: "[Clang] Demote always_inline error to warning for mismatching SME attrs" (#100991) (PR #100996)

2024-07-31 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#101303

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


[clang] [clang][OpenMP] Diagnose badly-formed collapsed imperfect loop nests (#60678) (PR #101305)

2024-07-31 Thread Julian Brown via cfe-commits

https://github.com/jtb20 created 
https://github.com/llvm/llvm-project/pull/101305

This patch fixes a couple of cases where Clang aborts with loop nests that are 
being collapsed (via the relevant OpenMP clause) into a new, combined loop.

The problematic cases happen when a variable declared within the loop nest is 
used in the (init, condition, iter) statement of a more deeply-nested loop.  I 
don't think these cases (generally?) fall under the non-rectangular loop nest 
rules as defined in OpenMP 5.0+, but I could be wrong (and anyway, emitting an 
error is better than crashing).

In terms of implementation: the crash happens because (to a first 
approximation) all the loop bounds calculations are pulled out to the start of 
the new, combined loop, but variables declared in the loop nest "haven't been 
seen yet".  I believe there is special handling for iteration variables 
declared in "for" init statements, but not for variables declared elsewhere in 
the "imperfect" parts of a loop nest.

So, this patch tries to diagnose the troublesome cases before they can cause a 
crash.  This is slightly awkward because at the point where we want to do the 
diagnosis (SemaOpenMP.cpp), we don't have scope information readily available.  
Instead we "manually" scan through the AST of the loop nest looking for var 
decls (ForVarDeclFinder), then we ensure we're not using any of those in loop 
control subexprs (ForSubExprChecker). All that is only done when we have a 
"collapse" clause.

Range-for loops can also cause crashes at present without this patch, so are 
handled too.

>From 56d5d7797929d8bc81bf394a46c97b9bf645744e Mon Sep 17 00:00:00 2001
From: Julian Brown 
Date: Wed, 26 Jun 2024 11:21:01 -0500
Subject: [PATCH] [clang][OpenMP] Diagnose badly-formed collapsed imperfect
 loop nests (#60678)

This patch fixes a couple of cases where Clang aborts with loop nests
that are being collapsed (via the relevant OpenMP clause) into a new,
combined loop.

The problematic cases happen when a variable declared within the
loop nest is used in the (init, condition, iter) statement of a more
deeply-nested loop.  I don't think these cases (generally?) fall under
the non-rectangular loop nest rules as defined in OpenMP 5.0+, but I
could be wrong (and anyway, emitting an error is better than crashing).

In terms of implementation: the crash happens because (to a first
approximation) all the loop bounds calculations are pulled out to the
start of the new, combined loop, but variables declared in the loop nest
"haven't been seen yet".  I believe there is special handling for
iteration variables declared in "for" init statements, but not for
variables declared elsewhere in the "imperfect" parts of a loop nest.

So, this patch tries to diagnose the troublesome cases before they can
cause a crash.  This is slightly awkward because at the point where we
want to do the diagnosis (SemaOpenMP.cpp), we don't have scope information
readily available.  Instead we "manually" scan through the AST of the
loop nest looking for var decls (ForVarDeclFinder), then we ensure we're
not using any of those in loop control subexprs (ForSubExprChecker).
All that is only done when we have a "collapse" clause.

Range-for loops can also cause crashes at present without this patch,
so are handled too.
---
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +
 clang/lib/AST/StmtOpenMP.cpp  |   1 +
 clang/lib/Sema/SemaOpenMP.cpp | 132 --
 clang/test/OpenMP/loop_collapse_1.c   |  40 ++
 clang/test/OpenMP/loop_collapse_2.cpp |  80 +++
 5 files changed, 247 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/OpenMP/loop_collapse_1.c
 create mode 100644 clang/test/OpenMP/loop_collapse_2.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9..beb78eb0a4ef4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11152,6 +11152,8 @@ def err_omp_loop_diff_cxx : Error<
   "upper and lower loop bounds">;
 def err_omp_loop_cannot_use_stmt : Error<
   "'%0' statement cannot be used in OpenMP for loop">;
+def err_omp_loop_bad_collapse_var : Error<
+  "cannot use variable %1 in collapsed imperfectly-nested loop 
%select{init|condition|increment}0 statement">;
 def err_omp_simd_region_cannot_use_stmt : Error<
   "'%0' statement cannot be used in OpenMP simd region">;
 def warn_omp_loop_64_bit_var : Warning<
diff --git a/clang/lib/AST/StmtOpenMP.cpp b/clang/lib/AST/StmtOpenMP.cpp
index 451a9fe9fe3d2..75ea55c99dfc5 100644
--- a/clang/lib/AST/StmtOpenMP.cpp
+++ b/clang/lib/AST/StmtOpenMP.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/StmtOpenMP.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 
 using namespace clang;
 using namespace llvm::omp;
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpen

[clang] [clang][OpenMP] Diagnose badly-formed collapsed imperfect loop nests (#60678) (PR #101305)

2024-07-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Julian Brown (jtb20)


Changes

This patch fixes a couple of cases where Clang aborts with loop nests that are 
being collapsed (via the relevant OpenMP clause) into a new, combined loop.

The problematic cases happen when a variable declared within the loop nest is 
used in the (init, condition, iter) statement of a more deeply-nested loop.  I 
don't think these cases (generally?) fall under the non-rectangular loop nest 
rules as defined in OpenMP 5.0+, but I could be wrong (and anyway, emitting an 
error is better than crashing).

In terms of implementation: the crash happens because (to a first 
approximation) all the loop bounds calculations are pulled out to the start of 
the new, combined loop, but variables declared in the loop nest "haven't been 
seen yet".  I believe there is special handling for iteration variables 
declared in "for" init statements, but not for variables declared elsewhere in 
the "imperfect" parts of a loop nest.

So, this patch tries to diagnose the troublesome cases before they can cause a 
crash.  This is slightly awkward because at the point where we want to do the 
diagnosis (SemaOpenMP.cpp), we don't have scope information readily available.  
Instead we "manually" scan through the AST of the loop nest looking for var 
decls (ForVarDeclFinder), then we ensure we're not using any of those in loop 
control subexprs (ForSubExprChecker). All that is only done when we have a 
"collapse" clause.

Range-for loops can also cause crashes at present without this patch, so are 
handled too.

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


5 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2) 
- (modified) clang/lib/AST/StmtOpenMP.cpp (+1) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+124-8) 
- (added) clang/test/OpenMP/loop_collapse_1.c (+40) 
- (added) clang/test/OpenMP/loop_collapse_2.cpp (+80) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9..beb78eb0a4ef4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11152,6 +11152,8 @@ def err_omp_loop_diff_cxx : Error<
   "upper and lower loop bounds">;
 def err_omp_loop_cannot_use_stmt : Error<
   "'%0' statement cannot be used in OpenMP for loop">;
+def err_omp_loop_bad_collapse_var : Error<
+  "cannot use variable %1 in collapsed imperfectly-nested loop 
%select{init|condition|increment}0 statement">;
 def err_omp_simd_region_cannot_use_stmt : Error<
   "'%0' statement cannot be used in OpenMP simd region">;
 def warn_omp_loop_64_bit_var : Warning<
diff --git a/clang/lib/AST/StmtOpenMP.cpp b/clang/lib/AST/StmtOpenMP.cpp
index 451a9fe9fe3d2..75ea55c99dfc5 100644
--- a/clang/lib/AST/StmtOpenMP.cpp
+++ b/clang/lib/AST/StmtOpenMP.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/StmtOpenMP.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 
 using namespace clang;
 using namespace llvm::omp;
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 4f50efda155fb..e78af5cc7ab0a 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -21,6 +21,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclOpenMP.h"
 #include "clang/AST/OpenMPClause.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtOpenMP.h"
 #include "clang/AST/StmtVisitor.h"
@@ -7668,6 +7669,47 @@ struct LoopIterationSpace final {
   Expr *FinalCondition = nullptr;
 };
 
+class ForSubExprChecker : public RecursiveASTVisitor {
+  const llvm::SmallSet *CollapsedLoopVarDecls;
+  VarDecl *ForbiddenVar;
+  SourceRange ErrLoc;
+
+public:
+  explicit ForSubExprChecker(
+  const llvm::SmallSet *CollapsedLoopVarDecls)
+  : CollapsedLoopVarDecls(CollapsedLoopVarDecls), ForbiddenVar(nullptr) {}
+
+  bool shouldVisitImplicitCode() const { return true; }
+
+  bool VisitDeclRefExpr(DeclRefExpr *E) {
+ValueDecl *VD = E->getDecl();
+if (!isa(VD))
+  return true;
+VarDecl *V = VD->getPotentiallyDecomposedVarDecl();
+if (V->getType()->isReferenceType()) {
+  VarDecl *VD = V->getDefinition();
+  if (VD->hasInit()) {
+Expr *I = VD->getInit();
+DeclRefExpr *DRE = dyn_cast(I);
+if (!DRE)
+  return true;
+V = DRE->getDecl()->getPotentiallyDecomposedVarDecl();
+  }
+}
+Decl *Canon = V->getCanonicalDecl();
+if (CollapsedLoopVarDecls->contains(Canon)) {
+  ForbiddenVar = V;
+  ErrLoc = E->getSourceRange();
+  return false;
+}
+
+return true;
+  }
+
+  VarDecl *getForbiddenVar() { return ForbiddenVar; }
+  SourceRange &getErrRange() { return ErrLoc; }
+};
+
 /// Helper class for checking canonical form of the OpenMP loops and
 /// extracting iteration space of each loop in the loop ne

[clang] [clang][OpenMP] Diagnose badly-formed collapsed imperfect loop nests (#60678) (PR #101305)

2024-07-31 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 5ef087b705099574e131ba77143b49faaee0e7f8 
56d5d7797929d8bc81bf394a46c97b9bf645744e --extensions cpp,c -- 
clang/test/OpenMP/loop_collapse_1.c clang/test/OpenMP/loop_collapse_2.cpp 
clang/lib/AST/StmtOpenMP.cpp clang/lib/Sema/SemaOpenMP.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/StmtOpenMP.cpp b/clang/lib/AST/StmtOpenMP.cpp
index 75ea55c99d..e41c26bb60 100644
--- a/clang/lib/AST/StmtOpenMP.cpp
+++ b/clang/lib/AST/StmtOpenMP.cpp
@@ -10,8 +10,8 @@
 //
 
//===--===//
 
-#include "clang/AST/ASTContext.h"
 #include "clang/AST/StmtOpenMP.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 
 using namespace clang;

``




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


[clang] [clang][OpenMP] Diagnose badly-formed collapsed imperfect loop nests (#60678) (PR #101305)

2024-07-31 Thread Julian Brown via cfe-commits

jtb20 wrote:

@jdoerfert @alexey-bataev 

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


[clang] [clang][OpenMP] Diagnose badly-formed collapsed imperfect loop nests (#60678) (PR #101305)

2024-07-31 Thread Julian Brown via cfe-commits

https://github.com/jtb20 updated 
https://github.com/llvm/llvm-project/pull/101305

>From eb60fc7c8d02877d2f8de73057c1153444cc740c Mon Sep 17 00:00:00 2001
From: Julian Brown 
Date: Wed, 26 Jun 2024 11:21:01 -0500
Subject: [PATCH] [clang][OpenMP] Diagnose badly-formed collapsed imperfect
 loop nests (#60678)

This patch fixes a couple of cases where Clang aborts with loop nests
that are being collapsed (via the relevant OpenMP clause) into a new,
combined loop.

The problematic cases happen when a variable declared within the
loop nest is used in the (init, condition, iter) statement of a more
deeply-nested loop.  I don't think these cases (generally?) fall under
the non-rectangular loop nest rules as defined in OpenMP 5.0+, but I
could be wrong (and anyway, emitting an error is better than crashing).

In terms of implementation: the crash happens because (to a first
approximation) all the loop bounds calculations are pulled out to the
start of the new, combined loop, but variables declared in the loop nest
"haven't been seen yet".  I believe there is special handling for
iteration variables declared in "for" init statements, but not for
variables declared elsewhere in the "imperfect" parts of a loop nest.

So, this patch tries to diagnose the troublesome cases before they can
cause a crash.  This is slightly awkward because at the point where we
want to do the diagnosis (SemaOpenMP.cpp), we don't have scope information
readily available.  Instead we "manually" scan through the AST of the
loop nest looking for var decls (ForVarDeclFinder), then we ensure we're
not using any of those in loop control subexprs (ForSubExprChecker).
All that is only done when we have a "collapse" clause.

Range-for loops can also cause crashes at present without this patch,
so are handled too.
---
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +
 clang/lib/AST/StmtOpenMP.cpp  |   3 +-
 clang/lib/Sema/SemaOpenMP.cpp | 132 --
 clang/test/OpenMP/loop_collapse_1.c   |  40 ++
 clang/test/OpenMP/loop_collapse_2.cpp |  80 +++
 5 files changed, 248 insertions(+), 9 deletions(-)
 create mode 100644 clang/test/OpenMP/loop_collapse_1.c
 create mode 100644 clang/test/OpenMP/loop_collapse_2.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9..beb78eb0a4ef4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11152,6 +11152,8 @@ def err_omp_loop_diff_cxx : Error<
   "upper and lower loop bounds">;
 def err_omp_loop_cannot_use_stmt : Error<
   "'%0' statement cannot be used in OpenMP for loop">;
+def err_omp_loop_bad_collapse_var : Error<
+  "cannot use variable %1 in collapsed imperfectly-nested loop 
%select{init|condition|increment}0 statement">;
 def err_omp_simd_region_cannot_use_stmt : Error<
   "'%0' statement cannot be used in OpenMP simd region">;
 def warn_omp_loop_64_bit_var : Warning<
diff --git a/clang/lib/AST/StmtOpenMP.cpp b/clang/lib/AST/StmtOpenMP.cpp
index 451a9fe9fe3d2..e41c26bb60252 100644
--- a/clang/lib/AST/StmtOpenMP.cpp
+++ b/clang/lib/AST/StmtOpenMP.cpp
@@ -10,8 +10,9 @@
 //
 
//===--===//
 
-#include "clang/AST/ASTContext.h"
 #include "clang/AST/StmtOpenMP.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 
 using namespace clang;
 using namespace llvm::omp;
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 4f50efda155fb..e78af5cc7ab0a 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -21,6 +21,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclOpenMP.h"
 #include "clang/AST/OpenMPClause.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtOpenMP.h"
 #include "clang/AST/StmtVisitor.h"
@@ -7668,6 +7669,47 @@ struct LoopIterationSpace final {
   Expr *FinalCondition = nullptr;
 };
 
+class ForSubExprChecker : public RecursiveASTVisitor {
+  const llvm::SmallSet *CollapsedLoopVarDecls;
+  VarDecl *ForbiddenVar;
+  SourceRange ErrLoc;
+
+public:
+  explicit ForSubExprChecker(
+  const llvm::SmallSet *CollapsedLoopVarDecls)
+  : CollapsedLoopVarDecls(CollapsedLoopVarDecls), ForbiddenVar(nullptr) {}
+
+  bool shouldVisitImplicitCode() const { return true; }
+
+  bool VisitDeclRefExpr(DeclRefExpr *E) {
+ValueDecl *VD = E->getDecl();
+if (!isa(VD))
+  return true;
+VarDecl *V = VD->getPotentiallyDecomposedVarDecl();
+if (V->getType()->isReferenceType()) {
+  VarDecl *VD = V->getDefinition();
+  if (VD->hasInit()) {
+Expr *I = VD->getInit();
+DeclRefExpr *DRE = dyn_cast(I);
+if (!DRE)
+  return true;
+V = DRE->getDecl()->getPotentiallyDecomposedVarDecl();
+  }
+}
+Decl *Canon = V->getC

[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-07-31 Thread Jannick Kremer via cfe-commits


@@ -3257,21 +3323,21 @@ def reparse(self, unsaved_files=None, options=0):
 if unsaved_files is None:
 unsaved_files = []
 
-unsaved_files_array = 0
+unsaved_files_array: int | Array[_CXUnsavedFile] = 0
 if len(unsaved_files):
 unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
 for i, (name, contents) in enumerate(unsaved_files):
 if hasattr(contents, "read"):
 contents = contents.read()
-contents = b(contents)
+binary_contents = b(contents)

DeinAlptraum wrote:

Assigning an incompatible type to a variable of a different type is a type 
error. Changing `binary_contents` back to `contents` produces a type error like 
this on that line:
`clang/cindex.py:3332: error: Incompatible types in assignment (expression has 
type "bytes", variable has type "str | TextIOWrapper")`
Good point with the repetition though, I'll make separate PRs for these to 
collect this into a common function.

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


[clang] [CMake][Fuchsia] Include libunwind and libc++abi in baremetal build (PR #100908)

2024-07-31 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `fuchsia-x86_64-linux` 
running on `fuchsia-debian-64-us-central1-a-1` while building `clang` at step 4 
"annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/11/builds/2659

Here is the relevant piece of the build log for the reference:
```
Step 4 (annotate) failure: 'python 
../llvm-zorg/zorg/buildbot/builders/annotated/fuchsia-linux.py ...' (failure)
...
[90/1698] Building CXX object 
libc/src/math/generic/CMakeFiles/libc.src.math.generic.inv_trigf_utils.dir/inv_trigf_utils.cpp.obj
[91/1698] Building CXX object 
libc/src/stdio/baremetal/CMakeFiles/libc.src.stdio.baremetal.putchar.dir/putchar.cpp.obj
[92/1698] Building CXX object 
libc/src/stdio/baremetal/CMakeFiles/libc.src.stdio.baremetal.puts.dir/puts.cpp.obj
[93/1698] Building CXX object 
libc/src/stdlib/baremetal/CMakeFiles/libc.src.stdlib.baremetal.abort.dir/abort.cpp.obj
[94/1698] Building CXX object 
libc/src/string/CMakeFiles/libc.src.string.memccpy.dir/memccpy.cpp.obj
[95/1698] Building CXX object 
libc/src/string/CMakeFiles/libc.src.string.memrchr.dir/memrchr.cpp.obj
[96/1698] Building CXX object 
libc/src/string/CMakeFiles/libc.src.string.strcmp.dir/strcmp.cpp.obj
[97/1698] Building CXX object 
libc/src/stdlib/CMakeFiles/libc.src.stdlib.labs.dir/labs.cpp.obj
[98/1698] Building CXX object 
libc/src/string/CMakeFiles/libc.src.string.memmem.dir/memmem.cpp.obj
[99/1698] Building CXX object 
libunwind/src/CMakeFiles/unwind_static_objects.dir/Unwind-seh.cpp.obj
FAILED: libunwind/src/CMakeFiles/unwind_static_objects.dir/Unwind-seh.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a1qojnig/bin/clang++ 
--target=armv6m-unknown-eabi -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBUNWIND_IS_BAREMETAL 
-D_LIBUNWIND_LINK_DL_LIB -D_LIBUNWIND_LINK_PTHREAD_LIB 
-D_LIBUNWIND_REMEMBER_HEAP_ALLOC -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libunwind/include 
--target=armv6m-unknown-eabi -mthumb -Wno-atomic-alignment "-Dvfprintf(stream, 
format, vlist)=vprintf(format, vlist)" "-Dfprintf(stream, format, 
...)=printf(format)" "-Dtimeval=struct timeval{int tv_sec; int tv_usec;}" 
"-Dgettimeofday(tv, tz)" -D_LIBCPP_PRINT=1 -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections 
-fdata-sections 
-ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a1qojnig/runtimes/runtimes-armv6m-unknown-eabi-bins=../../../../llvm-project
 -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= 
-no-canonical-prefixes -Oz -DNDEBUG -std=c++17 -Werror=return-type 
-funwind-tables -nostdinc++ -D_LIBUNWIND_IS_NATIVE_ONLY 
-D_LIBUNWIND_HAS_NO_THREADS -Wall -Wextra -Wnewline-eof -Wshadow 
-Wwrite-strings -Wno-unused-parameter -Wno-long-long -Werror=return-type 
-Wextra-semi -Wundef -Wunused-template -Wformat-nonliteral 
-Wno-user-defined-literals -Wno-covered-switch-default -Wno-suggest-override 
-Wno-error -pedantic -fno-rtti  -fstrict-aliasing -fno-exceptions -fno-rtti -MD 
-MT libunwind/src/CMakeFiles/unwind_static_objects.dir/Unwind-seh.cpp.obj -MF 
libunwind/src/CMakeFiles/unwind_static_objects.dir/Unwind-seh.cpp.obj.d -o 
libunwind/src/CMakeFiles/unwind_static_objects.dir/Unwind-seh.cpp.obj -c 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libunwind/src/Unwind-seh.cpp
In file included from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libunwind/src/Unwind-seh.cpp:13:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libunwind/src/config.h:17:10:
 fatal error: 'stdio.h' file not found
   17 | #include 
  |  ^
1 error generated.
[100/1698] Building CXX object 
libc/src/string/CMakeFiles/libc.src.string.strcoll.dir/strcoll.cpp.obj
[101/1698] Building CXX object 
libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.obj
[102/1698] Building CXX object 
libc/src/ctype/CMakeFiles/libc.src.ctype.isalnum.dir/isalnum.cpp.obj
[103/1698] Building CXX object 
libc/startup/baremetal/CMakeFiles/libc.startup.baremetal.fini.dir/fini.cpp.obj
[104/1698] Building CXX object 
libc/src/stdlib/CMakeFiles/libc.src.stdlib.rand_util.dir/rand_util.cpp.obj
[105/1698] Building CXX object 
libc/src/string/CMakeFiles/libc.src.string.strncpy.dir/strncpy.cpp.obj
[106/1698] Building CXX object 
libc/startup/baremetal/CMakeFiles/libc.startup.baremetal.init.dir/init.cpp.obj
[107/1698] Building CXX object 
libc/src/string/CMakeFiles/libc.src.string.strcasecmp.dir/strcasecmp.cpp.obj
[108/1698] Building CXX object 
libc/src/stdlib/C

[clang] [Clang][OpenMP] fix issue: Implicit conversion with `pragma omp taskloop` #100536 (PR #101307)

2024-07-31 Thread via cfe-commits

https://github.com/HenryZ16 created 
https://github.com/llvm/llvm-project/pull/101307

This patch is to fix [issue: Implicit conversion with `pragma omp 
taskloop`](https://github.com/llvm/llvm-project/issues/100536) #100536 
As is seen in the issue, clang will report error while compiling with `-Werror 
-Wconversion`:
```cpp
int main(void)
{
#pragma omp parallel
#pragma omp single
{
#pragma omp taskloop
for (int i = 0; i < 1; i++) {
#pragma omp task
{}
}

#pragma omp taskloop
for (long i = 0L; i < 1L; i++) {
#pragma omp task
{}
}

#pragma omp taskloop
for (unsigned long i = 0UL; i < 1UL; i++) {
#pragma omp task
{}
}
}
return 0;
}
```
During my revision of the code, I find out that the code in 
clang/lib/Sema/SemaOpenMP.cpp seems to automatically set the type of the 
iteration variable declared in the for loop to unsigned long. Note that clang 
has performed the type checking on the for loop before parsing & semantic 
checking on the OpenMP part. So I deleted the duplicated function 
`ActOnFinishFullExpr`, which will perform the type checking on the for loop 
again. Thus, clang no longer report such an error, and it can still pass `make 
clang-test`.
However, this can only be a temporary expedient. When I compare the x86_64 
assembly code generated by clang and gcc for this code, I find out that, for 
each "for" loop, clang always uses unsigned number judgment statement, while 
gcc can automatically choose the type of number judgment statement according to 
the sign of the iteration variable. I don't know whether it's a potential error.

>From 75879fa7a7e163ea350c11f37b24c0b2f5231c35 Mon Sep 17 00:00:00 2001
From: HenryZ16 <1546169...@qq.com>
Date: Wed, 31 Jul 2024 02:34:04 -0600
Subject: [PATCH] fix issue #100536: Implicit conversion with `pragma omp
 taskloop`

---
 clang/lib/Sema/SemaOpenMP.cpp | 32 +---
 1 file changed, 1 insertion(+), 31 deletions(-)

diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 4f50efda155fb..ddf1dd9824e04 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -9758,7 +9758,6 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
 LastIteration.get(), UB.get());
 EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(),
  CondOp.get());
-EUB = SemaRef.ActOnFinishFullExpr(EUB.get(), /*DiscardedValue*/ false);
 
 // If we have a combined directive that combines 'distribute', 'for' or
 // 'simd' we need to be able to access the bounds of the schedule of the
@@ -9787,8 +9786,6 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
  LastIteration.get(), CombUB.get());
   CombEUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, CombUB.get(),
CombCondOp.get());
-  CombEUB =
-  SemaRef.ActOnFinishFullExpr(CombEUB.get(), /*DiscardedValue*/ false);
 
   const CapturedDecl *CD = cast(AStmt)->getCapturedDecl();
   // We expect to have at least 2 more parameters than the 'parallel'
@@ -9824,7 +9821,6 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
 ? LB.get()
 : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get();
 Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS);
-Init = SemaRef.ActOnFinishFullExpr(Init.get(), /*DiscardedValue*/ false);
 
 if (isOpenMPLoopBoundSharingDirective(DKind)) {
   Expr *CombRHS =
@@ -9836,8 +9832,6 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
   : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get();
   CombInit =
   SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), CombRHS);
-  CombInit =
-  SemaRef.ActOnFinishFullExpr(CombInit.get(), /*DiscardedValue*/ 
false);
 }
   }
 
@@ -9856,8 +9850,6 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
 .BuildBinOp(CurScope, CondLoc, BO_Add, BoundUB,
 SemaRef.ActOnIntegerConstant(SourceLocation(), 
1).get())
 .get();
-BoundUB =
-SemaRef.ActOnFinishFullExpr(BoundUB, /*DiscardedValue*/ false).get();
   }
   ExprResult Cond =
   (isOpenMPWorksharingDirective(DKind) ||
@@ -9885,9 +9877,6 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
   CurScope, CondLoc, BO_Add, BoundCombUB,
   SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get())
   .get();
-  BoundCombUB =

[clang] [Clang][OpenMP] fix issue: Implicit conversion with `pragma omp taskloop` #100536 (PR #101307)

2024-07-31 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [Clang][OpenMP] fix issue: Implicit conversion with `pragma omp taskloop` #100536 (PR #101307)

2024-07-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (HenryZ16)


Changes

This patch is to fix [issue: Implicit conversion with `pragma omp 
taskloop`](https://github.com/llvm/llvm-project/issues/100536) #100536 
As is seen in the issue, clang will report error while compiling with `-Werror 
-Wconversion`:
```cpp
int main(void)
{
#pragma omp parallel
#pragma omp single
{
#pragma omp taskloop
for (int i = 0; i < 1; i++) {
#pragma omp task
{}
}

#pragma omp taskloop
for (long i = 0L; i < 1L; i++) {
#pragma omp task
{}
}

#pragma omp taskloop
for (unsigned long i = 0UL; i < 1UL; i++) {
#pragma omp task
{}
}
}
return 0;
}
```
During my revision of the code, I find out that the code in 
clang/lib/Sema/SemaOpenMP.cpp seems to automatically set the type of the 
iteration variable declared in the for loop to unsigned long. Note that clang 
has performed the type checking on the for loop before parsing & semantic 
checking on the OpenMP part. So I deleted the duplicated function 
`ActOnFinishFullExpr`, which will perform the type checking on the for loop 
again. Thus, clang no longer report such an error, and it can still pass `make 
clang-test`.
However, this can only be a temporary expedient. When I compare the x86_64 
assembly code generated by clang and gcc for this code, I find out that, for 
each "for" loop, clang always uses unsigned number judgment statement, while 
gcc can automatically choose the type of number judgment statement according to 
the sign of the iteration variable. I don't know whether it's a potential error.

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaOpenMP.cpp (+1-31) 


``diff
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 4f50efda155fb..ddf1dd9824e04 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -9758,7 +9758,6 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
 LastIteration.get(), UB.get());
 EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(),
  CondOp.get());
-EUB = SemaRef.ActOnFinishFullExpr(EUB.get(), /*DiscardedValue*/ false);
 
 // If we have a combined directive that combines 'distribute', 'for' or
 // 'simd' we need to be able to access the bounds of the schedule of the
@@ -9787,8 +9786,6 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
  LastIteration.get(), CombUB.get());
   CombEUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, CombUB.get(),
CombCondOp.get());
-  CombEUB =
-  SemaRef.ActOnFinishFullExpr(CombEUB.get(), /*DiscardedValue*/ false);
 
   const CapturedDecl *CD = cast(AStmt)->getCapturedDecl();
   // We expect to have at least 2 more parameters than the 'parallel'
@@ -9824,7 +9821,6 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
 ? LB.get()
 : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get();
 Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS);
-Init = SemaRef.ActOnFinishFullExpr(Init.get(), /*DiscardedValue*/ false);
 
 if (isOpenMPLoopBoundSharingDirective(DKind)) {
   Expr *CombRHS =
@@ -9836,8 +9832,6 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
   : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get();
   CombInit =
   SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), CombRHS);
-  CombInit =
-  SemaRef.ActOnFinishFullExpr(CombInit.get(), /*DiscardedValue*/ 
false);
 }
   }
 
@@ -9856,8 +9850,6 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
 .BuildBinOp(CurScope, CondLoc, BO_Add, BoundUB,
 SemaRef.ActOnIntegerConstant(SourceLocation(), 
1).get())
 .get();
-BoundUB =
-SemaRef.ActOnFinishFullExpr(BoundUB, /*DiscardedValue*/ false).get();
   }
   ExprResult Cond =
   (isOpenMPWorksharingDirective(DKind) ||
@@ -9885,9 +9877,6 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr 
*CollapseLoopCountExpr,
   CurScope, CondLoc, BO_Add, BoundCombUB,
   SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get())
   .get();
-  BoundCombUB =
-  SemaRef.ActOnFinishFullExpr(BoundCombUB, /*DiscardedValue*/ false)
-  .get();
 }
 CombCond =
 SemaRef.BuildBinOp(CurScope, CondLoc, UseStrictCompare ? BO_LT : B

[clang] [libclang/python] Factor out unsaved files processing (PR #101308)

2024-07-31 Thread Jannick Kremer via cfe-commits

https://github.com/DeinAlptraum created 
https://github.com/llvm/llvm-project/pull/101308

Factor out the processing of unsaved files into its own function as suggested 
by @Endilll  
[here](https://github.com/llvm/llvm-project/pull/78114/files#r1697730196)

>From 8780961064341bbbfd6cf97d9c6d5a4f7d012d49 Mon Sep 17 00:00:00 2001
From: Jannick Kremer 
Date: Wed, 31 Jul 2024 10:10:33 +0100
Subject: [PATCH] [libclang/python] Factor out unsaved files processing

---
 clang/bindings/python/clang/cindex.py | 47 ++-
 1 file changed, 17 insertions(+), 30 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 72509a8a54f28..f669c279aab6d 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3011,6 +3011,20 @@ class TranslationUnit(ClangObject):
 # into the set of code completions returned from this translation unit.
 PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION = 128
 
+@staticmethod
+def process_unsaved_files(unsaved_files) -> Array[_CXUnsavedFile] | None:
+unsaved_array = None
+if len(unsaved_files):
+unsaved_array = (_CXUnsavedFile * len(unsaved_files))()
+for i, (name, contents) in enumerate(unsaved_files):
+if hasattr(contents, "read"):
+contents = contents.read()
+binary_contents = b(contents)
+unsaved_array[i].name = b(os.fspath(name))
+unsaved_array[i].contents = binary_contents
+unsaved_array[i].length = len(binary_contents)
+return unsaved_array
+
 @classmethod
 def from_source(
 cls, filename, args=None, unsaved_files=None, options=0, index=None
@@ -3067,16 +3081,7 @@ def from_source(
 if len(args) > 0:
 args_array = (c_char_p * len(args))(*[b(x) for x in args])
 
-unsaved_array = None
-if len(unsaved_files) > 0:
-unsaved_array = (_CXUnsavedFile * len(unsaved_files))()
-for i, (name, contents) in enumerate(unsaved_files):
-if hasattr(contents, "read"):
-contents = contents.read()
-contents = b(contents)
-unsaved_array[i].name = b(os.fspath(name))
-unsaved_array[i].contents = contents
-unsaved_array[i].length = len(contents)
+unsaved_array = cls.process_unsaved_files(unsaved_files)
 
 ptr = conf.lib.clang_parseTranslationUnit(
 index,
@@ -3257,16 +3262,7 @@ def reparse(self, unsaved_files=None, options=0):
 if unsaved_files is None:
 unsaved_files = []
 
-unsaved_files_array = 0
-if len(unsaved_files):
-unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
-for i, (name, contents) in enumerate(unsaved_files):
-if hasattr(contents, "read"):
-contents = contents.read()
-contents = b(contents)
-unsaved_files_array[i].name = b(os.fspath(name))
-unsaved_files_array[i].contents = contents
-unsaved_files_array[i].length = len(contents)
+unsaved_files_array = self.process_unsaved_files(unsaved_files)
 ptr = conf.lib.clang_reparseTranslationUnit(
 self, len(unsaved_files), unsaved_files_array, options
 )
@@ -3329,16 +3325,7 @@ def codeComplete(
 if unsaved_files is None:
 unsaved_files = []
 
-unsaved_files_array = 0
-if len(unsaved_files):
-unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
-for i, (name, contents) in enumerate(unsaved_files):
-if hasattr(contents, "read"):
-contents = contents.read()
-contents = b(contents)
-unsaved_files_array[i].name = b(os.fspath(name))
-unsaved_files_array[i].contents = contents
-unsaved_files_array[i].length = len(contents)
+unsaved_files_array = self.process_unsaved_files(unsaved_files)
 ptr = conf.lib.clang_codeCompleteAt(
 self,
 os.fspath(path),

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


[clang] [libclang/python] Factor out unsaved files processing (PR #101308)

2024-07-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)


Changes

Factor out the processing of unsaved files into its own function as suggested 
by @Endilll  
[here](https://github.com/llvm/llvm-project/pull/78114/files#r1697730196)

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


1 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+17-30) 


``diff
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 72509a8a54f28..f669c279aab6d 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3011,6 +3011,20 @@ class TranslationUnit(ClangObject):
 # into the set of code completions returned from this translation unit.
 PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION = 128
 
+@staticmethod
+def process_unsaved_files(unsaved_files) -> Array[_CXUnsavedFile] | None:
+unsaved_array = None
+if len(unsaved_files):
+unsaved_array = (_CXUnsavedFile * len(unsaved_files))()
+for i, (name, contents) in enumerate(unsaved_files):
+if hasattr(contents, "read"):
+contents = contents.read()
+binary_contents = b(contents)
+unsaved_array[i].name = b(os.fspath(name))
+unsaved_array[i].contents = binary_contents
+unsaved_array[i].length = len(binary_contents)
+return unsaved_array
+
 @classmethod
 def from_source(
 cls, filename, args=None, unsaved_files=None, options=0, index=None
@@ -3067,16 +3081,7 @@ def from_source(
 if len(args) > 0:
 args_array = (c_char_p * len(args))(*[b(x) for x in args])
 
-unsaved_array = None
-if len(unsaved_files) > 0:
-unsaved_array = (_CXUnsavedFile * len(unsaved_files))()
-for i, (name, contents) in enumerate(unsaved_files):
-if hasattr(contents, "read"):
-contents = contents.read()
-contents = b(contents)
-unsaved_array[i].name = b(os.fspath(name))
-unsaved_array[i].contents = contents
-unsaved_array[i].length = len(contents)
+unsaved_array = cls.process_unsaved_files(unsaved_files)
 
 ptr = conf.lib.clang_parseTranslationUnit(
 index,
@@ -3257,16 +3262,7 @@ def reparse(self, unsaved_files=None, options=0):
 if unsaved_files is None:
 unsaved_files = []
 
-unsaved_files_array = 0
-if len(unsaved_files):
-unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
-for i, (name, contents) in enumerate(unsaved_files):
-if hasattr(contents, "read"):
-contents = contents.read()
-contents = b(contents)
-unsaved_files_array[i].name = b(os.fspath(name))
-unsaved_files_array[i].contents = contents
-unsaved_files_array[i].length = len(contents)
+unsaved_files_array = self.process_unsaved_files(unsaved_files)
 ptr = conf.lib.clang_reparseTranslationUnit(
 self, len(unsaved_files), unsaved_files_array, options
 )
@@ -3329,16 +3325,7 @@ def codeComplete(
 if unsaved_files is None:
 unsaved_files = []
 
-unsaved_files_array = 0
-if len(unsaved_files):
-unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
-for i, (name, contents) in enumerate(unsaved_files):
-if hasattr(contents, "read"):
-contents = contents.read()
-contents = b(contents)
-unsaved_files_array[i].name = b(os.fspath(name))
-unsaved_files_array[i].contents = contents
-unsaved_files_array[i].length = len(contents)
+unsaved_files_array = self.process_unsaved_files(unsaved_files)
 ptr = conf.lib.clang_codeCompleteAt(
 self,
 os.fspath(path),

``




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


[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-07-31 Thread Jannick Kremer via cfe-commits

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


[clang] f395d82 - [clang][LoongArch] Pre-commit test for align global. NFC

2024-07-31 Thread WANG Rui via cfe-commits

Author: WANG Rui
Date: 2024-07-31T17:13:25+08:00
New Revision: f395d826bf48ba530d0ab9480e4bc07fa335ef56

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

LOG: [clang][LoongArch] Pre-commit test for align global. NFC

Added: 
clang/test/CodeGen/LoongArch/align.c

Modified: 


Removed: 




diff  --git a/clang/test/CodeGen/LoongArch/align.c 
b/clang/test/CodeGen/LoongArch/align.c
new file mode 100644
index 0..1b171b74529d1
--- /dev/null
+++ b/clang/test/CodeGen/LoongArch/align.c
@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 -triple loongarch32 -target-feature +lsx -target-feature \
+// RUN:   +lasx -emit-llvm %s -o - | FileCheck %s --check-prefix=LA32
+// RUN: %clang_cc1 -triple loongarch64 -target-feature +lsx -target-feature \
+// RUN:   +lasx -emit-llvm %s -o - | FileCheck %s --check-prefix=LA64
+
+#include 
+#include 
+
+char *s1 = "1234";
+// LA32: @.str{{.*}} ={{.*}} constant [5 x i8] c"1234\00", align 1
+// LA64: @.str{{.*}} ={{.*}} constant [5 x i8] c"1234\00", align 1
+
+char *s2 = "12345678abcd";
+// LA32: @.str{{.*}} ={{.*}} constant [13 x i8] c"12345678abcd\00", align 1
+// LA64: @.str{{.*}} ={{.*}} constant [13 x i8] c"12345678abcd\00", align 1
+
+char *s3 = "123456789012345678901234567890ab";
+// LA32: @.str{{.*}} ={{.*}} constant [33 x i8] c"1234{{.*}}ab\00", align 1
+// LA64: @.str{{.*}} ={{.*}} constant [33 x i8] c"1234{{.*}}ab\00", align 1
+
+char *s4 = 
"123456789012345678901234567890123456789012345678901234567890abcdef";
+// LA32: @.str{{.*}} ={{.*}} constant [67 x i8] c"1234{{.*}}cdef\00", align 1
+// LA64: @.str{{.*}} ={{.*}} constant [67 x i8] c"1234{{.*}}cdef\00", align 1
+
+int8_t a;
+// LA32: @a ={{.*}} global i8 0, align 1
+// LA64: @a ={{.*}} global i8 0, align 1
+
+int16_t b;
+// LA32: @b ={{.*}} global i16 0, align 2
+// LA64: @b ={{.*}} global i16 0, align 2
+
+int32_t c;
+// LA32: @c ={{.*}} global i32 0, align 4
+// LA64: @c ={{.*}} global i32 0, align 4
+
+int64_t d;
+// LA32: @d ={{.*}} global i64 0, align 8
+// LA64: @d ={{.*}} global i64 0, align 8
+
+intptr_t e;
+// LA32: @e ={{.*}} global i32 0, align 4
+// LA64: @e ={{.*}} global i64 0, align 8
+
+float f;
+// LA32: @f ={{.*}} global float 0.00e+00, align 4
+// LA64: @f ={{.*}} global float 0.00e+00, align 4
+
+double g;
+// LA32: @g ={{.*}} global double 0.00e+00, align 8
+// LA64: @g ={{.*}} global double 0.00e+00, align 8
+
+struct H {
+  int8_t a;
+};
+struct H h;
+// LA32: @h ={{.*}} global %struct.H zeroinitializer, align 1
+// LA64: @h ={{.*}} global %struct.H zeroinitializer, align 1



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


[clang] [clang][LoongArch] Align global symbol by size (PR #101309)

2024-07-31 Thread via cfe-commits

https://github.com/heiher created 
https://github.com/llvm/llvm-project/pull/101309

Fixes #101295

>From 34c558dda32076634d9575a32a0508e576c13d0b Mon Sep 17 00:00:00 2001
From: WANG Rui 
Date: Wed, 31 Jul 2024 17:11:56 +0800
Subject: [PATCH] [clang][LoongArch] Align global symbol by size

Fixes #101295
---
 clang/lib/Basic/Targets/LoongArch.cpp | 17 +
 clang/lib/Basic/Targets/LoongArch.h   |  3 +++
 clang/test/CodeGen/LoongArch/align.c  | 20 ++--
 3 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index cb3fd12c48ddb..63c2ed987442f 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -118,6 +118,23 @@ LoongArchTargetInfo::getGCCRegAliases() const {
   return llvm::ArrayRef(GCCRegAliases);
 }
 
+unsigned LoongArchTargetInfo::getMinGlobalAlign(uint64_t TypeSize,
+bool HasNonWeakDef) const {
+  unsigned Align = TargetInfo::getMinGlobalAlign(TypeSize, HasNonWeakDef);
+
+  if (HasFeatureLASX && TypeSize >= 512) {   // TypeSize >= 64 bytes
+Align = std::max(Align, 256u);   // align type at least 32 
bytes
+  } else if (HasFeatureLSX && TypeSize >= 256) { // TypeSize >= 32 bytes
+Align = std::max(Align, 128u);   // align type at least 16 
bytes
+  } else if (TypeSize >= 64) {   // TypeSize >= 8 bytes
+Align = std::max(Align, 64u);// align type at least 8 butes
+  } else if (TypeSize >= 16) {   // TypeSize >= 2 bytes
+Align = std::max(Align, 32u);// align type at least 4 bytes
+  }
+
+  return Align;
+}
+
 bool LoongArchTargetInfo::validateAsmConstraint(
 const char *&Name, TargetInfo::ConstraintInfo &Info) const {
   // See the GCC definitions here:
diff --git a/clang/lib/Basic/Targets/LoongArch.h 
b/clang/lib/Basic/Targets/LoongArch.h
index c668ca7eca047..42aab7fe1aa49 100644
--- a/clang/lib/Basic/Targets/LoongArch.h
+++ b/clang/lib/Basic/Targets/LoongArch.h
@@ -82,6 +82,9 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
 
   ArrayRef getGCCRegAliases() const override;
 
+  unsigned getMinGlobalAlign(uint64_t TypeSize,
+ bool HasNonWeakDef) const override;
+
   bool validateAsmConstraint(const char *&Name,
  TargetInfo::ConstraintInfo &Info) const override;
   std::string convertConstraint(const char *&Constraint) const override;
diff --git a/clang/test/CodeGen/LoongArch/align.c 
b/clang/test/CodeGen/LoongArch/align.c
index 1b171b74529d1..b353a98678a06 100644
--- a/clang/test/CodeGen/LoongArch/align.c
+++ b/clang/test/CodeGen/LoongArch/align.c
@@ -7,28 +7,28 @@
 #include 
 
 char *s1 = "1234";
-// LA32: @.str{{.*}} ={{.*}} constant [5 x i8] c"1234\00", align 1
-// LA64: @.str{{.*}} ={{.*}} constant [5 x i8] c"1234\00", align 1
+// LA32: @.str{{.*}} ={{.*}} constant [5 x i8] c"1234\00", align 4
+// LA64: @.str{{.*}} ={{.*}} constant [5 x i8] c"1234\00", align 4
 
 char *s2 = "12345678abcd";
-// LA32: @.str{{.*}} ={{.*}} constant [13 x i8] c"12345678abcd\00", align 1
-// LA64: @.str{{.*}} ={{.*}} constant [13 x i8] c"12345678abcd\00", align 1
+// LA32: @.str{{.*}} ={{.*}} constant [13 x i8] c"12345678abcd\00", align 8
+// LA64: @.str{{.*}} ={{.*}} constant [13 x i8] c"12345678abcd\00", align 8
 
 char *s3 = "123456789012345678901234567890ab";
-// LA32: @.str{{.*}} ={{.*}} constant [33 x i8] c"1234{{.*}}ab\00", align 1
-// LA64: @.str{{.*}} ={{.*}} constant [33 x i8] c"1234{{.*}}ab\00", align 1
+// LA32: @.str{{.*}} ={{.*}} constant [33 x i8] c"1234{{.*}}ab\00", align 16
+// LA64: @.str{{.*}} ={{.*}} constant [33 x i8] c"1234{{.*}}ab\00", align 16
 
 char *s4 = 
"123456789012345678901234567890123456789012345678901234567890abcdef";
-// LA32: @.str{{.*}} ={{.*}} constant [67 x i8] c"1234{{.*}}cdef\00", align 1
-// LA64: @.str{{.*}} ={{.*}} constant [67 x i8] c"1234{{.*}}cdef\00", align 1
+// LA32: @.str{{.*}} ={{.*}} constant [67 x i8] c"1234{{.*}}cdef\00", align 32
+// LA64: @.str{{.*}} ={{.*}} constant [67 x i8] c"1234{{.*}}cdef\00", align 32
 
 int8_t a;
 // LA32: @a ={{.*}} global i8 0, align 1
 // LA64: @a ={{.*}} global i8 0, align 1
 
 int16_t b;
-// LA32: @b ={{.*}} global i16 0, align 2
-// LA64: @b ={{.*}} global i16 0, align 2
+// LA32: @b ={{.*}} global i16 0, align 4
+// LA64: @b ={{.*}} global i16 0, align 4
 
 int32_t c;
 // LA32: @c ={{.*}} global i32 0, align 4

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


[clang] [clang][LoongArch] Align global symbol by size (PR #101309)

2024-07-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: hev (heiher)


Changes

Fixes #101295

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


3 Files Affected:

- (modified) clang/lib/Basic/Targets/LoongArch.cpp (+17) 
- (modified) clang/lib/Basic/Targets/LoongArch.h (+3) 
- (modified) clang/test/CodeGen/LoongArch/align.c (+10-10) 


``diff
diff --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index cb3fd12c48ddb..63c2ed987442f 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -118,6 +118,23 @@ LoongArchTargetInfo::getGCCRegAliases() const {
   return llvm::ArrayRef(GCCRegAliases);
 }
 
+unsigned LoongArchTargetInfo::getMinGlobalAlign(uint64_t TypeSize,
+bool HasNonWeakDef) const {
+  unsigned Align = TargetInfo::getMinGlobalAlign(TypeSize, HasNonWeakDef);
+
+  if (HasFeatureLASX && TypeSize >= 512) {   // TypeSize >= 64 bytes
+Align = std::max(Align, 256u);   // align type at least 32 
bytes
+  } else if (HasFeatureLSX && TypeSize >= 256) { // TypeSize >= 32 bytes
+Align = std::max(Align, 128u);   // align type at least 16 
bytes
+  } else if (TypeSize >= 64) {   // TypeSize >= 8 bytes
+Align = std::max(Align, 64u);// align type at least 8 butes
+  } else if (TypeSize >= 16) {   // TypeSize >= 2 bytes
+Align = std::max(Align, 32u);// align type at least 4 bytes
+  }
+
+  return Align;
+}
+
 bool LoongArchTargetInfo::validateAsmConstraint(
 const char *&Name, TargetInfo::ConstraintInfo &Info) const {
   // See the GCC definitions here:
diff --git a/clang/lib/Basic/Targets/LoongArch.h 
b/clang/lib/Basic/Targets/LoongArch.h
index c668ca7eca047..42aab7fe1aa49 100644
--- a/clang/lib/Basic/Targets/LoongArch.h
+++ b/clang/lib/Basic/Targets/LoongArch.h
@@ -82,6 +82,9 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
 
   ArrayRef getGCCRegAliases() const override;
 
+  unsigned getMinGlobalAlign(uint64_t TypeSize,
+ bool HasNonWeakDef) const override;
+
   bool validateAsmConstraint(const char *&Name,
  TargetInfo::ConstraintInfo &Info) const override;
   std::string convertConstraint(const char *&Constraint) const override;
diff --git a/clang/test/CodeGen/LoongArch/align.c 
b/clang/test/CodeGen/LoongArch/align.c
index 1b171b74529d1..b353a98678a06 100644
--- a/clang/test/CodeGen/LoongArch/align.c
+++ b/clang/test/CodeGen/LoongArch/align.c
@@ -7,28 +7,28 @@
 #include 
 
 char *s1 = "1234";
-// LA32: @.str{{.*}} ={{.*}} constant [5 x i8] c"1234\00", align 1
-// LA64: @.str{{.*}} ={{.*}} constant [5 x i8] c"1234\00", align 1
+// LA32: @.str{{.*}} ={{.*}} constant [5 x i8] c"1234\00", align 4
+// LA64: @.str{{.*}} ={{.*}} constant [5 x i8] c"1234\00", align 4
 
 char *s2 = "12345678abcd";
-// LA32: @.str{{.*}} ={{.*}} constant [13 x i8] c"12345678abcd\00", align 1
-// LA64: @.str{{.*}} ={{.*}} constant [13 x i8] c"12345678abcd\00", align 1
+// LA32: @.str{{.*}} ={{.*}} constant [13 x i8] c"12345678abcd\00", align 8
+// LA64: @.str{{.*}} ={{.*}} constant [13 x i8] c"12345678abcd\00", align 8
 
 char *s3 = "123456789012345678901234567890ab";
-// LA32: @.str{{.*}} ={{.*}} constant [33 x i8] c"1234{{.*}}ab\00", align 1
-// LA64: @.str{{.*}} ={{.*}} constant [33 x i8] c"1234{{.*}}ab\00", align 1
+// LA32: @.str{{.*}} ={{.*}} constant [33 x i8] c"1234{{.*}}ab\00", align 16
+// LA64: @.str{{.*}} ={{.*}} constant [33 x i8] c"1234{{.*}}ab\00", align 16
 
 char *s4 = 
"123456789012345678901234567890123456789012345678901234567890abcdef";
-// LA32: @.str{{.*}} ={{.*}} constant [67 x i8] c"1234{{.*}}cdef\00", align 1
-// LA64: @.str{{.*}} ={{.*}} constant [67 x i8] c"1234{{.*}}cdef\00", align 1
+// LA32: @.str{{.*}} ={{.*}} constant [67 x i8] c"1234{{.*}}cdef\00", align 32
+// LA64: @.str{{.*}} ={{.*}} constant [67 x i8] c"1234{{.*}}cdef\00", align 32
 
 int8_t a;
 // LA32: @a ={{.*}} global i8 0, align 1
 // LA64: @a ={{.*}} global i8 0, align 1
 
 int16_t b;
-// LA32: @b ={{.*}} global i16 0, align 2
-// LA64: @b ={{.*}} global i16 0, align 2
+// LA32: @b ={{.*}} global i16 0, align 4
+// LA64: @b ={{.*}} global i16 0, align 4
 
 int32_t c;
 // LA32: @c ={{.*}} global i32 0, align 4

``




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


[clang] [Clang][Interp] Fix the location of uninitialized base warning (PR #100761)

2024-07-31 Thread via cfe-commits

yronglin wrote:

@tbaederr @Sirraide Thanks for your review!

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


[clang] 6434dce - [Clang][Interp] Fix the location of uninitialized base warning (#100761)

2024-07-31 Thread via cfe-commits

Author: yronglin
Date: 2024-07-31T17:22:44+08:00
New Revision: 6434dce85df21aabd5669dd9fbe8fa582e40c6ee

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

LOG: [Clang][Interp] Fix the location of uninitialized base warning (#100761)

Fix the location of `diag::note_constexpr_uninitialized_base`, make it
same as current interpreter.
This PR does not print type name with namespacethat was used to improve
the current interpreter's type dump of base class type.

-

Signed-off-by: yronglin 

Added: 


Modified: 
clang/lib/AST/Interp/EvaluationResult.cpp
clang/test/AST/Interp/constexpr-subobj-initialization.cpp
clang/test/C/C23/n3018.c
clang/test/CodeGen/pr3518.c
clang/test/Preprocessor/embed_weird.cpp
clang/test/SemaCXX/constexpr-subobj-initialization.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/EvaluationResult.cpp 
b/clang/lib/AST/Interp/EvaluationResult.cpp
index 1b255711c7b36..bdebd19af9f94 100644
--- a/clang/lib/AST/Interp/EvaluationResult.cpp
+++ b/clang/lib/AST/Interp/EvaluationResult.cpp
@@ -10,7 +10,9 @@
 #include "InterpState.h"
 #include "Record.h"
 #include "clang/AST/ExprCXX.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
+#include 
 
 namespace clang {
 namespace interp {
@@ -122,19 +124,18 @@ static bool CheckFieldsInitialized(InterpState &S, 
SourceLocation Loc,
   }
 
   // Check Fields in all bases
-  for (const Record::Base &B : R->bases()) {
+  for (auto [I, B] : llvm::enumerate(R->bases())) {
 Pointer P = BasePtr.atField(B.Offset);
 if (!P.isInitialized()) {
   const Descriptor *Desc = BasePtr.getDeclDesc();
-  if (Desc->asDecl())
-S.FFDiag(BasePtr.getDeclDesc()->asDecl()->getLocation(),
- diag::note_constexpr_uninitialized_base)
+  if (const auto *CD = dyn_cast_if_present(R->getDecl())) {
+const auto &BS = *std::next(CD->bases_begin(), I);
+S.FFDiag(BS.getBaseTypeLoc(), diag::note_constexpr_uninitialized_base)
+<< B.Desc->getType() << BS.getSourceRange();
+  } else {
+S.FFDiag(Desc->getLocation(), diag::note_constexpr_uninitialized_base)
 << B.Desc->getType();
-  else
-S.FFDiag(BasePtr.getDeclDesc()->asExpr()->getExprLoc(),
- diag::note_constexpr_uninitialized_base)
-<< B.Desc->getType();
-
+  }
   return false;
 }
 Result &= CheckFieldsInitialized(S, Loc, P, B.R);

diff  --git a/clang/test/AST/Interp/constexpr-subobj-initialization.cpp 
b/clang/test/AST/Interp/constexpr-subobj-initialization.cpp
index 4976b165468bd..1a35994944190 100644
--- a/clang/test/AST/Interp/constexpr-subobj-initialization.cpp
+++ b/clang/test/AST/Interp/constexpr-subobj-initialization.cpp
@@ -5,8 +5,6 @@
 /// Differences:
 ///   1) The type of the uninitialized base class is printed WITH the 
namespace,
 ///  i.e. 'baseclass_uninit::DelBase' instead of just 'DelBase'.
-///   2) The location is not the base specifier declaration, but the call site
-///  of the constructor.
 
 
 namespace baseclass_uninit {
@@ -14,33 +12,29 @@ struct DelBase {
   constexpr DelBase() = delete; // expected-note {{'DelBase' has been 
explicitly marked deleted here}}
 };
 
-struct Foo : DelBase {
+struct Foo : DelBase { // expected-note 2{{constructor of base class 
'baseclass_uninit::DelBase' is not called}}
   constexpr Foo() {}; // expected-error {{call to deleted constructor of 
'DelBase'}}
 };
-constexpr Foo f; // expected-error {{must be initialized by a constant 
expression}} \
- // expected-note {{constructor of base class 
'baseclass_uninit::DelBase' is not called}}
+constexpr Foo f; // expected-error {{must be initialized by a constant 
expression}}
 
 struct Bar : Foo {
   constexpr Bar() {};
 };
-constexpr Bar bar; // expected-error {{must be initialized by a constant 
expression}} \
-   // expected-note {{constructor of base class 
'baseclass_uninit::DelBase' is not called}}
+constexpr Bar bar; // expected-error {{must be initialized by a constant 
expression}}
 
 struct Base {};
-struct A : Base {
+struct A : Base { // expected-note {{constructor of base class 
'baseclass_uninit::Base' is not called}}
   constexpr A() : value() {} // expected-error {{member initializer 'value' 
does not name a non-static data member or base class}}
 };
 
-constexpr A a; // expected-error {{must be initialized by a constant 
expression}} \
-   // expected-note {{constructor of base class 
'baseclass_uninit::Base' is not called}}
+constexpr A a; // expected-error {{must be initialized by a constant 
expression}}
 
 
-struct B : Base {
+struct B : Base { // expected-note {{constructor of base class 
'baseclass_uninit::Base' is not called}}
   constexpr B() : 

[clang] [Clang][Interp] Fix the location of uninitialized base warning (PR #100761)

2024-07-31 Thread via cfe-commits

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


[clang] [libclang/python] type-ignore `Any` returns from library calls (PR #101310)

2024-07-31 Thread Jannick Kremer via cfe-commits

https://github.com/DeinAlptraum created 
https://github.com/llvm/llvm-project/pull/101310

On its own, this change leads to _more_ strict typing errors as the functions 
are mostly not annotated so far, so the `# type: ignore`s are reported as 
Unused. This is part of the work leading up to #78114 though, and one of the 
bigger parts factored out from it, so these will later lead to less strict 
typing errors as the functions are annotated with return types.

>From 7bf4412849774be51c170584089bde8010d0814a Mon Sep 17 00:00:00 2001
From: Jannick Kremer 
Date: Wed, 31 Jul 2024 10:27:09 +0100
Subject: [PATCH] [libclang/python] type-ignore `Any` returns from library
 calls

---
 clang/bindings/python/clang/cindex.py | 194 +-
 1 file changed, 97 insertions(+), 97 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 72509a8a54f28..60723e1aaeff7 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -276,7 +276,7 @@ def from_position(tu, file, line, column):
 Retrieve the source location associated with a given file/line/column 
in
 a particular translation unit.
 """
-return conf.lib.clang_getLocation(tu, file, line, column)
+return conf.lib.clang_getLocation(tu, file, line, column)  # type: 
ignore [no-any-return]
 
 @staticmethod
 def from_offset(tu, file, offset):
@@ -286,7 +286,7 @@ def from_offset(tu, file, offset):
 file -- File instance to obtain offset from
 offset -- Integer character offset within file
 """
-return conf.lib.clang_getLocationForOffset(tu, file, offset)
+return conf.lib.clang_getLocationForOffset(tu, file, offset)  # type: 
ignore [no-any-return]
 
 @property
 def file(self):
@@ -311,10 +311,10 @@ def offset(self):
 @property
 def is_in_system_header(self):
 """Returns true if the given source location is in a system header."""
-return conf.lib.clang_Location_isInSystemHeader(self)
+return conf.lib.clang_Location_isInSystemHeader(self)  # type: ignore 
[no-any-return]
 
 def __eq__(self, other):
-return conf.lib.clang_equalLocations(self, other)
+return conf.lib.clang_equalLocations(self, other)  # type: ignore 
[no-any-return]
 
 def __ne__(self, other):
 return not self.__eq__(other)
@@ -347,7 +347,7 @@ class SourceRange(Structure):
 # object.
 @staticmethod
 def from_locations(start, end):
-return conf.lib.clang_getRange(start, end)
+return conf.lib.clang_getRange(start, end)  # type: ignore 
[no-any-return]
 
 @property
 def start(self):
@@ -355,7 +355,7 @@ def start(self):
 Return a SourceLocation representing the first character within a
 source range.
 """
-return conf.lib.clang_getRangeStart(self)
+return conf.lib.clang_getRangeStart(self)  # type: ignore 
[no-any-return]
 
 @property
 def end(self):
@@ -363,10 +363,10 @@ def end(self):
 Return a SourceLocation representing the last character within a
 source range.
 """
-return conf.lib.clang_getRangeEnd(self)
+return conf.lib.clang_getRangeEnd(self)  # type: ignore [no-any-return]
 
 def __eq__(self, other):
-return conf.lib.clang_equalRanges(self, other)
+return conf.lib.clang_equalRanges(self, other)  # type: ignore 
[no-any-return]
 
 def __ne__(self, other):
 return not self.__eq__(other)
@@ -429,15 +429,15 @@ def __del__(self):
 
 @property
 def severity(self):
-return conf.lib.clang_getDiagnosticSeverity(self)
+return conf.lib.clang_getDiagnosticSeverity(self)  # type: ignore 
[no-any-return]
 
 @property
 def location(self):
-return conf.lib.clang_getDiagnosticLocation(self)
+return conf.lib.clang_getDiagnosticLocation(self)  # type: ignore 
[no-any-return]
 
 @property
 def spelling(self):
-return conf.lib.clang_getDiagnosticSpelling(self)
+return conf.lib.clang_getDiagnosticSpelling(self)  # type: ignore 
[no-any-return]
 
 @property
 def ranges(self) -> NoSliceSequence[SourceRange]:
@@ -451,7 +451,7 @@ def __len__(self) -> int:
 def __getitem__(self, key: int) -> SourceRange:
 if key >= len(self):
 raise IndexError
-return conf.lib.clang_getDiagnosticRange(self.diag, key)
+return conf.lib.clang_getDiagnosticRange(self.diag, key)  # 
type: ignore [no-any-return]
 
 return RangeIterator(self)
 
@@ -494,17 +494,17 @@ def __getitem__(self, key: int) -> Diagnostic:
 @property
 def category_number(self):
 """The category number for this diagnostic or 0 if unavailable."""
-return conf.lib.clang_getDiagnosticCategory(self)
+return conf.lib.clang_getDiagnosticCategory(self)  # type: ignore 
[no-an

[clang] [libclang/python] type-ignore `Any` returns from library calls (PR #101310)

2024-07-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)


Changes

On its own, this change leads to _more_ strict typing errors as the functions 
are mostly not annotated so far, so the `# type: ignore`s are reported as 
Unused. This is part of the work leading up to #78114 though, and one 
of the bigger parts factored out from it, so these will later lead to less 
strict typing errors as the functions are annotated with return types.

---

Patch is 29.82 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/101310.diff


1 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+97-97) 


``diff
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 72509a8a54f28..60723e1aaeff7 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -276,7 +276,7 @@ def from_position(tu, file, line, column):
 Retrieve the source location associated with a given file/line/column 
in
 a particular translation unit.
 """
-return conf.lib.clang_getLocation(tu, file, line, column)
+return conf.lib.clang_getLocation(tu, file, line, column)  # type: 
ignore [no-any-return]
 
 @staticmethod
 def from_offset(tu, file, offset):
@@ -286,7 +286,7 @@ def from_offset(tu, file, offset):
 file -- File instance to obtain offset from
 offset -- Integer character offset within file
 """
-return conf.lib.clang_getLocationForOffset(tu, file, offset)
+return conf.lib.clang_getLocationForOffset(tu, file, offset)  # type: 
ignore [no-any-return]
 
 @property
 def file(self):
@@ -311,10 +311,10 @@ def offset(self):
 @property
 def is_in_system_header(self):
 """Returns true if the given source location is in a system header."""
-return conf.lib.clang_Location_isInSystemHeader(self)
+return conf.lib.clang_Location_isInSystemHeader(self)  # type: ignore 
[no-any-return]
 
 def __eq__(self, other):
-return conf.lib.clang_equalLocations(self, other)
+return conf.lib.clang_equalLocations(self, other)  # type: ignore 
[no-any-return]
 
 def __ne__(self, other):
 return not self.__eq__(other)
@@ -347,7 +347,7 @@ class SourceRange(Structure):
 # object.
 @staticmethod
 def from_locations(start, end):
-return conf.lib.clang_getRange(start, end)
+return conf.lib.clang_getRange(start, end)  # type: ignore 
[no-any-return]
 
 @property
 def start(self):
@@ -355,7 +355,7 @@ def start(self):
 Return a SourceLocation representing the first character within a
 source range.
 """
-return conf.lib.clang_getRangeStart(self)
+return conf.lib.clang_getRangeStart(self)  # type: ignore 
[no-any-return]
 
 @property
 def end(self):
@@ -363,10 +363,10 @@ def end(self):
 Return a SourceLocation representing the last character within a
 source range.
 """
-return conf.lib.clang_getRangeEnd(self)
+return conf.lib.clang_getRangeEnd(self)  # type: ignore [no-any-return]
 
 def __eq__(self, other):
-return conf.lib.clang_equalRanges(self, other)
+return conf.lib.clang_equalRanges(self, other)  # type: ignore 
[no-any-return]
 
 def __ne__(self, other):
 return not self.__eq__(other)
@@ -429,15 +429,15 @@ def __del__(self):
 
 @property
 def severity(self):
-return conf.lib.clang_getDiagnosticSeverity(self)
+return conf.lib.clang_getDiagnosticSeverity(self)  # type: ignore 
[no-any-return]
 
 @property
 def location(self):
-return conf.lib.clang_getDiagnosticLocation(self)
+return conf.lib.clang_getDiagnosticLocation(self)  # type: ignore 
[no-any-return]
 
 @property
 def spelling(self):
-return conf.lib.clang_getDiagnosticSpelling(self)
+return conf.lib.clang_getDiagnosticSpelling(self)  # type: ignore 
[no-any-return]
 
 @property
 def ranges(self) -> NoSliceSequence[SourceRange]:
@@ -451,7 +451,7 @@ def __len__(self) -> int:
 def __getitem__(self, key: int) -> SourceRange:
 if key >= len(self):
 raise IndexError
-return conf.lib.clang_getDiagnosticRange(self.diag, key)
+return conf.lib.clang_getDiagnosticRange(self.diag, key)  # 
type: ignore [no-any-return]
 
 return RangeIterator(self)
 
@@ -494,17 +494,17 @@ def __getitem__(self, key: int) -> Diagnostic:
 @property
 def category_number(self):
 """The category number for this diagnostic or 0 if unavailable."""
-return conf.lib.clang_getDiagnosticCategory(self)
+return conf.lib.clang_getDiagnosticCategory(self)  # type: ignore 
[no-any-return]
 
 @property
 def category_name(self):
 """The string name of the category for this diag

[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-07-31 Thread Jannick Kremer via cfe-commits


@@ -255,71 +263,75 @@ class SourceLocation(Structure):
 """
 
 _fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_uint)]
-_data = None
+_data: tuple[File | None, int, int, int] | None = None
 
-def _get_instantiation(self):
+def _get_instantiation(self) -> tuple[File | None, int, int, int]:
 if self._data is None:
 f, l, c, o = c_object_p(), c_uint(), c_uint(), c_uint()
 conf.lib.clang_getInstantiationLocation(
 self, byref(f), byref(l), byref(c), byref(o)
 )
 if f:
-f = File(f)
+file = File(f)
 else:
-f = None
-self._data = (f, int(l.value), int(c.value), int(o.value))
+file = None
+self._data = (file, int(l.value), int(c.value), int(o.value))
 return self._data
 
 @staticmethod
-def from_position(tu, file, line, column):
+def from_position(
+tu: TranslationUnit, file: File, line: int, column: int
+) -> SourceLocation:
 """
 Retrieve the source location associated with a given file/line/column 
in
 a particular translation unit.
 """
-return conf.lib.clang_getLocation(tu, file, line, column)
+return conf.lib.clang_getLocation(tu, file, line, column)  # type: 
ignore [no-any-return]
 
 @staticmethod
-def from_offset(tu, file, offset):
+def from_offset(tu: TranslationUnit, file: File, offset: int) -> 
SourceLocation:
 """Retrieve a SourceLocation from a given character offset.
 
 tu -- TranslationUnit file belongs to
 file -- File instance to obtain offset from
 offset -- Integer character offset within file
 """
-return conf.lib.clang_getLocationForOffset(tu, file, offset)
+return conf.lib.clang_getLocationForOffset(tu, file, offset)  # type: 
ignore [no-any-return]

DeinAlptraum wrote:

I've opened a PR separating these at #101310 

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


[clang] [CMake][Fuchsia] Include libunwind and libc++abi in baremetal build (PR #100908)

2024-07-31 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `sanitizer-ppc64le-linux` 
running on `ppc64le-sanitizer` while building `clang` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/72/builds/1816

Here is the relevant piece of the build log for the reference:
```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
PASS: ThreadSanitizer-powerpc64le :: pthread_atfork_deadlock3.c (2350 of 2483)
PASS: ThreadSanitizer-powerpc64le :: ignore_lib0.cpp (2351 of 2483)
PASS: XRay-powerpc64le-linux :: TestCases/Posix/patching-unpatching.cpp (2352 
of 2483)
PASS: ThreadSanitizer-powerpc64le :: race_top_suppression.cpp (2353 of 2483)
PASS: ThreadSanitizer-powerpc64le :: fd_close_norace3.cpp (2354 of 2483)
XFAIL: ThreadSanitizer-powerpc64le :: must_deadlock.cpp (2355 of 2483)
PASS: ThreadSanitizer-powerpc64le :: mmap_stress2.cpp (2356 of 2483)
PASS: ThreadSanitizer-powerpc64le :: race_on_write.cpp (2357 of 2483)
PASS: ThreadSanitizer-powerpc64le :: setuid2.c (2358 of 2483)
PASS: ThreadSanitizer-powerpc64le :: mutexset8.cpp (2359 of 2483)
FAIL: ThreadSanitizer-powerpc64le :: signal_block.cpp (2360 of 2483)
 TEST 'ThreadSanitizer-powerpc64le :: signal_block.cpp' 
FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/./bin/clang
  -fsanitize=thread -Wall  -m64 -fno-function-sections   -gline-tables-only 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/../
 -O1 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp
 -o 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp
 &&  
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp
 2>&1 | FileCheck 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp
+ 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/./bin/clang
 -fsanitize=thread -Wall -m64 -fno-function-sections -gline-tables-only 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/../
 -O1 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp
 -o 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp
+ 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/compiler-rt/test/tsan/POWERPC64LEConfig/Output/signal_block.cpp.tmp
+ FileCheck 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:59:15:
 error: CHECK-NOT: excluded string found in input
// CHECK-NOT: WARNING: ThreadSanitizer:
  ^
:2:1: note: found here
WARNING: ThreadSanitizer: signal handler spoils errno (pid=844579)
^

Input file: 
Check file: 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp

-dump-input=help explains the following input dump.

Input was:
<<
1: == 
2: WARNING: ThreadSanitizer: signal handler spoils errno (pid=844579) 
not:59 !   
error: no match expected
3:  Signal 10 handler invoked at: 
4:  #0 handler(int) 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:13
 (signal_block.cpp.tmp+0xff1a0) 
5:  #1 thread(void*) 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:25:5
 (signal_block.cpp.tmp+0xff2f0) 
6:  
7: SUMMARY: ThreadSanitizer: signal handler spoils errno 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/tsan/signal_block.cpp:13
 in h

[clang] [CLANG][AArch64] Add the modal 8 bit floating-point scalar type (PR #97277)

2024-07-31 Thread via cfe-commits

https://github.com/CarolineConcatto updated 
https://github.com/llvm/llvm-project/pull/97277

>From fbeca5c357b1a5589757bbb2cac8208f8c9027ab Mon Sep 17 00:00:00 2001
From: Caroline Concatto 
Date: Mon, 24 Jun 2024 09:59:24 +
Subject: [PATCH 1/5] [WIP][CLANG][AArch64] Add the  modal 8 bit floating-point
 scalar type

ARM ACLE PR#323[1] adds new modal types for 8-bit floating point intrinsic.

>From the PR#323:
```
ACLE defines the `__fpm8` type, which can be used for the E5M2 and E4M3
8-bit floating-point formats. It is a storage and interchange only type
with no arithmetic operations other than intrinsic calls.


The type should be an opaque type and its format in undefined in Clang.
Only defined in the backend by a status/format register, for AArch64 the FPMR.

This patch is an attempt to the add the fpm8_t scalar type.
It has a parser and codegen for the new scalar type.

The patch it is lowering to and 8bit unsigned as it has no format.
But maybe we should add another opaque type.

[1]  https://github.com/ARM-software/acle/pull/323
---
 clang/include/clang/AST/ASTContext.h  |  1 +
 clang/include/clang/AST/BuiltinTypes.def  |  4 +
 clang/include/clang/AST/Type.h|  5 +
 clang/include/clang/Basic/Specifiers.h|  1 +
 clang/include/clang/Basic/TokenKinds.def  |  1 +
 clang/include/clang/Sema/DeclSpec.h   |  1 +
 .../include/clang/Serialization/ASTBitCodes.h |  4 +-
 clang/lib/AST/ASTContext.cpp  |  7 ++
 clang/lib/AST/ItaniumMangle.cpp   |  1 +
 clang/lib/AST/Type.cpp|  2 +
 clang/lib/AST/TypeLoc.cpp |  1 +
 clang/lib/CodeGen/CodeGenTypes.cpp|  4 +-
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  1 +
 clang/lib/Index/USRGeneration.cpp |  1 +
 clang/lib/Lex/Lexer.cpp   |  1 +
 clang/lib/Parse/ParseDecl.cpp |  7 ++
 clang/lib/Parse/ParseExpr.cpp |  1 +
 clang/lib/Parse/ParseExprCXX.cpp  |  3 +
 clang/lib/Parse/ParseTentative.cpp|  2 +
 clang/lib/Sema/DeclSpec.cpp   |  3 +
 clang/lib/Sema/SemaTemplateVariadic.cpp   |  1 +
 clang/lib/Sema/SemaType.cpp   |  3 +
 clang/lib/Serialization/ASTCommon.cpp |  3 +
 clang/test/AST/fpm8_opaque.cpp| 91 +++
 clang/test/CodeGen/fpm8_opaque.c  | 24 +
 25 files changed, 171 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/AST/fpm8_opaque.cpp
 create mode 100644 clang/test/CodeGen/fpm8_opaque.c

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 53ece996769a8..532ec05ab90a6 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1115,6 +1115,7 @@ class ASTContext : public RefCountedBase {
   CanQualType SatShortFractTy, SatFractTy, SatLongFractTy;
   CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy,
   SatUnsignedLongFractTy;
+  CanQualType Fpm8Ty;
   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
   CanQualType BFloat16Ty;
   CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a743..0c1cccf4f73b8 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -221,6 +221,10 @@ FLOATING_TYPE(Float128, Float128Ty)
 // '__ibm128'
 FLOATING_TYPE(Ibm128, Ibm128Ty)
 
+
+// '__fpm8'
+UNSIGNED_TYPE(Fpm8, Fpm8Ty)
+
 //===- Language-specific types 
===//
 
 // This is the type of C++0x 'nullptr'.
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index fab233b62d8d1..9f835b8459847 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2492,6 +2492,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isDoubleType() const;
   bool isBFloat16Type() const;
   bool isFloat128Type() const;
+  bool isFpm8Type() const;
   bool isIbm128Type() const;
   bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
   bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
@@ -7944,6 +7945,10 @@ inline bool Type::isBFloat16Type() const {
   return isSpecificBuiltinType(BuiltinType::BFloat16);
 }
 
+inline bool Type::isFpm8Type() const {
+  return isSpecificBuiltinType(BuiltinType::Fpm8);
+}
+
 inline bool Type::isFloat128Type() const {
   return isSpecificBuiltinType(BuiltinType::Float128);
 }
diff --git a/clang/include/clang/Basic/Specifiers.h 
b/clang/include/clang/Basic/Specifiers.h
index fb11e8212f8b6..b4db94d273949 100644
--- a/clang/include/clang/Basic/Specifiers.h
+++ b/clang/include/clang/Basic/Specifiers.h
@@ -68,6 +68,7 @@ namespace clang {
 TST_Accum,   // ISO/IEC JTC1 SC22 WG14 N1169 Extension
 TST_Fract,
 TST_BFloat16,
+TST_Fpm8,
   

[clang] [CLANG][AArch64] Add the modal 8 bit floating-point scalar type (PR #97277)

2024-07-31 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 9e63632b3274dc1b20502b569e79a311977e0a97 
c622d4473898f2f61a22788205c2a4ff49df58a0 --extensions h,cpp,c -- 
clang/test/AST/arm-mfp8.cpp clang/test/CodeGen/arm-mfp8.c 
clang/test/Sema/arm-mfp8.c clang/test/Sema/arm-mfp8.cpp 
clang/include/clang/AST/ASTContext.h clang/include/clang/AST/Type.h 
clang/include/clang/Basic/Specifiers.h 
clang/include/clang/Basic/TargetBuiltins.h 
clang/include/clang/Basic/TargetInfo.h clang/include/clang/Sema/DeclSpec.h 
clang/include/clang/Serialization/ASTBitCodes.h clang/lib/AST/ASTContext.cpp 
clang/lib/AST/ItaniumMangle.cpp clang/lib/AST/PrintfFormatString.cpp 
clang/lib/AST/Type.cpp clang/lib/AST/TypeLoc.cpp clang/lib/Basic/TargetInfo.cpp 
clang/lib/Basic/Targets/AArch64.cpp clang/lib/Basic/Targets/AArch64.h 
clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CodeGenModule.cpp 
clang/lib/CodeGen/CodeGenTypeCache.h clang/lib/CodeGen/CodeGenTypes.cpp 
clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/Index/USRGeneration.cpp 
clang/lib/Lex/Lexer.cpp clang/lib/Parse/ParseDecl.cpp 
clang/lib/Parse/ParseExpr.cpp clang/lib/Parse/ParseExprCXX.cpp 
clang/lib/Parse/ParseTentative.cpp clang/lib/Sema/DeclSpec.cpp 
clang/lib/Sema/SemaCast.cpp clang/lib/Sema/SemaExpr.cpp 
clang/lib/Sema/SemaTemplateVariadic.cpp clang/lib/Sema/SemaType.cpp 
clang/lib/Serialization/ASTCommon.cpp clang/lib/Serialization/ASTReader.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index fe3234ef85..19101f5a95 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3800,7 +3800,9 @@ void CXXNameMangler::mangleNeonVectorType(const 
VectorType *T) {
 case BuiltinType::Float: EltName = "float32_t"; break;
 case BuiltinType::Half:  EltName = "float16_t"; break;
 case BuiltinType::BFloat16:  EltName = "bfloat16_t"; break;
-case BuiltinType::MFloat8:   EltName = "mfloat8_t"; break;
+case BuiltinType::MFloat8:
+  EltName = "mfloat8_t";
+  break;
 default:
   llvm_unreachable("unexpected Neon vector element type");
 }
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 3af64ea55e..59a8124836 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -576,7 +576,8 @@ const char *DeclSpec::getSpecifierName(DeclSpec::TST T,
   case DeclSpec::TST_fract:   return "_Fract";
   case DeclSpec::TST_float16: return "_Float16";
   case DeclSpec::TST_float128:return "__float128";
-  case DeclSpec::TST_MFloat8: return "__mfp8";
+  case DeclSpec::TST_MFloat8:
+return "__mfp8";
   case DeclSpec::TST_ibm128:  return "__ibm128";
   case DeclSpec::TST_bool:return Policy.Bool ? "bool" : "_Bool";
   case DeclSpec::TST_decimal32:   return "_Decimal32";

``




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


[clang] [clang][DebugInfo] Don't mark structured bindings as artificial (PR #100355)

2024-07-31 Thread Michael Buch via cfe-commits

Michael137 wrote:

ping

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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread Sergei Barannikov via cfe-commits


@@ -179,6 +179,13 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
ArgList &Args,
   Features.push_back("-hard-quad-float");
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) 
{
+if (A->getOption().matches(options::OPT_mv8plus))

s-barannikov wrote:

This is quite confusing.
`-m[no]-v8plus` is an environment option, similar to X86's `-mx32`, but imposes 
more restrictions.
`-mcpu=v9 -mno-v8plus` should be equivalent to just `-mcpu=v9` because 64-bit 
environment is the default for 64-bit ISA.
`-mv8plus` enables 32-bit environment and therefore should restrict the 
compiler from using the whole set of V9 features. That is, I would expect it to 
disable something rather than to enable `v9`, which should already be set by 
`-mcpu=v9`.


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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread Sergei Barannikov via cfe-commits


@@ -179,6 +179,13 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
ArgList &Args,
   Features.push_back("-hard-quad-float");
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) 
{
+if (A->getOption().matches(options::OPT_mv8plus))

s-barannikov wrote:

Either way, the order of `-m8plus` relative to `-mcpu` shouldn't matter (one 
sets the environment, the other sets an ISA).


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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread Sergei Barannikov via cfe-commits

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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread Sergei Barannikov via cfe-commits

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


[clang] [RISCV] full support for riscv_rvv_vector_bits attribute (PR #100110)

2024-07-31 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/100110

>From 33cfa736bb19c6c8ef2d214ecafbc50605eea5eb Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Wed, 31 Jul 2024 13:37:34 +0300
Subject: [PATCH] [RISCV] full support for riscv_rvv_vector_bits attribute

---
 clang/include/clang/AST/Type.h|   4 +
 clang/lib/AST/ASTContext.cpp  |  33 +++-
 clang/lib/AST/ItaniumMangle.cpp   |  26 ++-
 clang/lib/AST/JSONNodeDumper.cpp  |   3 +
 clang/lib/AST/TextNodeDumper.cpp  |   3 +
 clang/lib/AST/TypePrinter.cpp |   6 +
 clang/lib/CodeGen/Targets/RISCV.cpp   |  22 ++-
 clang/lib/Sema/SemaExpr.cpp   |  13 +-
 clang/lib/Sema/SemaType.cpp   |  18 +-
 .../attr-riscv-rvv-vector-bits-less-8-call.c  | 178 ++
 .../attr-riscv-rvv-vector-bits-less-8-cast.c  | 123 
 .../attr-rvv-vector-bits-bitcast-less-8.c | 106 +++
 .../RISCV/attr-rvv-vector-bits-globals.c  |  36 ++--
 .../RISCV/attr-rvv-vector-bits-types.c|  78 
 .../riscv-mangle-rvv-fixed-vectors.cpp|  20 +-
 clang/test/Sema/attr-riscv-rvv-vector-bits.c  |  18 +-
 16 files changed, 587 insertions(+), 100 deletions(-)
 create mode 100644 
clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-call.c
 create mode 100644 
clang/test/CodeGen/RISCV/attr-riscv-rvv-vector-bits-less-8-cast.c
 create mode 100644 
clang/test/CodeGen/RISCV/attr-rvv-vector-bits-bitcast-less-8.c

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 25defea58c2dc..a9a87ac5837f1 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -3981,6 +3981,10 @@ enum class VectorKind {
 
   /// is RISC-V RVV fixed-length mask vector
   RVVFixedLengthMask,
+
+  RVVFixedLengthMask_1,
+  RVVFixedLengthMask_2,
+  RVVFixedLengthMask_4
 };
 
 /// Represents a GCC generic vector type. This type is created using
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 7af9ea7105bb0..1b7aed3b9dba8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1983,7 +1983,10 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) 
const {
   // Adjust the alignment for fixed-length SVE predicates.
   Align = 16;
 else if (VT->getVectorKind() == VectorKind::RVVFixedLengthData ||
- VT->getVectorKind() == VectorKind::RVVFixedLengthMask)
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask_4)
   // Adjust the alignment for fixed-length RVV vectors.
   Align = std::min(64, Width);
 break;
@@ -9896,7 +9899,13 @@ bool ASTContext::areCompatibleVectorTypes(QualType 
FirstVec,
   First->getVectorKind() != VectorKind::RVVFixedLengthData &&
   Second->getVectorKind() != VectorKind::RVVFixedLengthData &&
   First->getVectorKind() != VectorKind::RVVFixedLengthMask &&
-  Second->getVectorKind() != VectorKind::RVVFixedLengthMask)
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask_1 &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask_1 &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask_2 &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask_2 &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask_4 &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask_4)
 return true;
 
   return false;
@@ -10014,7 +10023,25 @@ bool ASTContext::areCompatibleRVVTypes(QualType 
FirstType,
   BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
   return FirstType->isRVVVLSBuiltinType() &&
  Info.ElementType == BoolTy &&
- getTypeSize(SecondType) == getRVVTypeSize(*this, BT);
+ getTypeSize(SecondType) == ((getRVVTypeSize(*this, BT)));
+}
+if (VT->getVectorKind() == VectorKind::RVVFixedLengthMask_1) {
+  BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
+  return FirstType->isRVVVLSBuiltinType() &&
+ Info.ElementType == BoolTy &&
+ getTypeSize(SecondType) == ((getRVVTypeSize(*this, BT) * 8));
+}
+if (VT->getVectorKind() == VectorKind::RVVFixedLengthMask_2) {
+  BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
+  return FirstType->isRVVVLSBuiltinType() &&
+ Info.ElementType == BoolTy &&
+ getTypeSize(SecondType) == ((getRVVTypeSize(*this, BT)) * 4);
+}
+if (VT->getVectorKind() == VectorKind::RVVFixedLengthMask_4) {
+  BuiltinVectorTypeInfo Info = getBuiltinVectorTypeInfo(BT);
+

[clang] [compiler-rt] [libcxx] [llvm] [cmake] switch to CMake's native `check_{compiler,linker}_flag` (PR #96171)

2024-07-31 Thread via cfe-commits

h-vetinari wrote:

This should be good now I think. Does someone want to approve/merge @ldionne 
@arichardson et al.?

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


[clang] [RISCV] full support for riscv_rvv_vector_bits attribute (PR #100110)

2024-07-31 Thread Vladislav Belov via cfe-commits


@@ -572,1483 +1121,44 @@ void f() {
 
//===--===//
 // Structs and unions
 
//===--===//
-// CHECK-64:  %struct.struct_int8m1 = type { <8 x i8> }

vbe-sc wrote:

Done

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


[clang] [RISCV] full support for riscv_rvv_vector_bits attribute (PR #100110)

2024-07-31 Thread Vladislav Belov via cfe-commits


@@ -176,477 +177,3110 @@ typedef vbool1_t fixed_bool1_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fi
 typedef vbool2_t fixed_bool2_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen/2)));
 typedef vbool4_t fixed_bool4_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen/4)));
 typedef vbool8_t fixed_bool8_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen/8)));
-#if __riscv_v_fixed_vlen >= 128
 typedef vbool16_t fixed_bool16_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen/16)));
-#endif
-#if __riscv_v_fixed_vlen >= 256
 typedef vbool32_t fixed_bool32_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen/32)));
-#endif
-#if __riscv_v_fixed_vlen >= 512
 typedef vbool64_t fixed_bool64_t 
__attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen/64)));
-#endif
 
 template  struct S {};
 
-// CHECK-64: _Z2f11SI9__RVV_VLSIu14__rvv_int8m1_tLj64EEE

vbe-sc wrote:

Many thanks for your comment: it allowed me to understand this test and find an 
improvement in `clang/./lib/AST/ItaniumMangle.cpp` for my patch. 
Fixed

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


[clang] [flang] [Flang][Driver] Introduce -fopenmp-targets offloading option (PR #100152)

2024-07-31 Thread Sergio Afonso via cfe-commits

https://github.com/skatrak updated 
https://github.com/llvm/llvm-project/pull/100152

>From 3861b28deeb1b558f182f2ab5680b123fd94c005 Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Tue, 23 Jul 2024 16:19:55 +0100
Subject: [PATCH] [Flang][Driver] Introduce -fopenmp-targets offloading option

This patch modifies the flang driver to introduce the `-fopenmp-targets` option
to the frontend compiler invocations corresponding to the OpenMP host device on
offloading-enabled compilations.

This option holds the list of offloading triples associated to the compilation
and is used by clang to determine whether offloading calls should be generated
for the host.
---
 clang/include/clang/Driver/Options.td  |  2 +-
 clang/lib/Driver/ToolChains/Clang.cpp  | 12 +---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 19 +++
 clang/lib/Driver/ToolChains/CommonArgs.h   |  5 +
 clang/lib/Driver/ToolChains/Flang.cpp  |  3 +++
 flang/test/Driver/omp-driver-offload.f90   | 18 ++
 6 files changed, 47 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c8c56dbb51b28..59c6bb70d75a2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3532,7 +3532,7 @@ def fopenmp_use_tls : Flag<["-"], "fopenmp-use-tls">, 
Group,
 def fnoopenmp_use_tls : Flag<["-"], "fnoopenmp-use-tls">, Group,
   Flags<[NoArgumentUnused, HelpHidden]>, Visibility<[ClangOption, CC1Option]>;
 def fopenmp_targets_EQ : CommaJoined<["-"], "fopenmp-targets=">,
-  Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option, FlangOption]>,
+  Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option, FlangOption, 
FC1Option]>,
   HelpText<"Specify comma-separated list of triples OpenMP offloading targets 
to be supported">;
 def fopenmp_relocatable_target : Flag<["-"], "fopenmp-relocatable-target">,
   Group, Flags<[NoArgumentUnused, HelpHidden]>,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 843d68c85bc59..0f1141ed8bcd9 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7789,17 +7789,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
options::OPT_mno_amdgpu_ieee);
   }
 
-  // For all the host OpenMP offloading compile jobs we need to pass the 
targets
-  // information using -fopenmp-targets= option.
-  if (JA.isHostOffloading(Action::OFK_OpenMP)) {
-SmallString<128> Targets("-fopenmp-targets=");
-
-SmallVector Triples;
-auto TCRange = C.getOffloadToolChains();
-std::transform(TCRange.first, TCRange.second, std::back_inserter(Triples),
-   [](auto TC) { return TC.second->getTripleString(); });
-CmdArgs.push_back(Args.MakeArgString(Targets + llvm::join(Triples, ",")));
-  }
+  addOpenMPHostOffloadingArgs(C, JA, Args, CmdArgs);
 
   bool VirtualFunctionElimination =
   Args.hasFlag(options::OPT_fvirtual_function_elimination,
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 1e37d9d348818..487cc8345d7e3 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1244,6 +1244,25 @@ bool tools::addOpenMPRuntime(const Compilation &C, 
ArgStringList &CmdArgs,
   return true;
 }
 
+void tools::addOpenMPHostOffloadingArgs(const Compilation &C,
+const JobAction &JA,
+const llvm::opt::ArgList &Args,
+llvm::opt::ArgStringList &CmdArgs) {
+  if (!JA.isHostOffloading(Action::OFK_OpenMP))
+return;
+
+  // For all the host OpenMP offloading compile jobs we need to pass the 
targets
+  // information using -fopenmp-targets= option.
+  constexpr llvm::StringLiteral Targets("-fopenmp-targets=");
+
+  SmallVector Triples;
+  auto TCRange = C.getOffloadToolChains();
+  std::transform(TCRange.first, TCRange.second, std::back_inserter(Triples),
+ [](auto TC) { return TC.second->getTripleString(); });
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine(Targets) + llvm::join(Triples, ",")));
+}
+
 /// Add Fortran runtime libs
 void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) {
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/lib/Driver/ToolChains/CommonArgs.h
index 0d3b4d6b783ba..0c97398dfcfa3 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -119,6 +119,11 @@ bool addOpenMPRuntime(const Compilation &C, 
llvm::opt::ArgStringList &CmdArgs,
   bool ForceStaticHostRuntime = false,
   bool IsOffloadingHost = false, bool GompNeedsRT = false);
 
+/// Adds offloading options for OpenMP host compilation to

[clang] [flang] [Flang][Driver] Introduce -fopenmp-targets offloading option (PR #100152)

2024-07-31 Thread Sergio Afonso via cfe-commits

skatrak wrote:

Thank you all for your reviews. I think it should be ok to merge at this point, 
but I'll wait until tomorrow to give some time in case there are any remaining 
concerns about this change.

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


[clang] [llvm] [RISCV] Add Syntacore SCR4 RV32/64 processors definition (PR #101321)

2024-07-31 Thread Anton Sidorenko via cfe-commits

https://github.com/asi-sc created 
https://github.com/llvm/llvm-project/pull/101321

Syntacore SCR4 is a microcontroller-class processor core that has much in 
common with SCR3. The most significant difference for compilers is F and D 
extensions support. Overview: https://syntacore.com/products/scr4

Two CPUs are added:
  * 'syntacore-scr4-rv32' -- rv32imfdc
  * 'syntacore-scr4-rv64' -- rv64imafdc

Scheduling model will be added in a separate PR.
-

>From 833727a9f23fff71695f4d2a5e7ee3e58ab5449a Mon Sep 17 00:00:00 2001
From: Anton Sidorenko 
Date: Wed, 3 Jul 2024 19:31:47 +0300
Subject: [PATCH] [RISCV] Add Syntacore SCR4 RV32/64 processors definition

Syntacore SCR4 is a microcontroller-class processor core that has much in common
with SCR3. The most significant difference for compilers is F and D extensions
support. Overview: https://syntacore.com/products/scr4

Two CPUs are added:
  * 'syntacore-scr4-rv32' -- rv32imfdc
  * 'syntacore-scr4-rv64' -- rv64imafdc

-

Co-authored-by: Dmitrii Petrov 
Co-authored-by: Anton Afanasyev 
---
 clang/test/Driver/riscv-cpus.c| 27 +++
 clang/test/Misc/target-invalid-cpu-note.c |  8 +++
 llvm/docs/ReleaseNotes.rst|  1 +
 llvm/lib/Target/RISCV/RISCVProcessors.td  | 25 +
 4 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index 26bcda6468dd2..7a885cde76d6a 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -381,3 +381,30 @@
 
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=syntacore-scr3-rv64 | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR3-RV64 %s
 // MTUNE-SYNTACORE-SCR3-RV64: "-tune-cpu" "syntacore-scr3-rv64"
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=syntacore-scr4-rv32 | 
FileCheck -check-prefix=MCPU-SYNTACORE-SCR4-RV32 %s
+// MCPU-SYNTACORE-SCR4-RV32: "-target-cpu" "syntacore-scr4-rv32"
+// MCPU-SYNTACORE-SCR4-RV32-SAME: "-target-feature" "+m"
+// MCPU-SYNTACORE-SCR4-RV32-SAME: "-target-feature" "+f"
+// MCPU-SYNTACORE-SCR4-RV32-SAME: "-target-feature" "+d"
+// MCPU-SYNTACORE-SCR4-RV32-SAME: "-target-feature" "+c"
+// MCPU-SYNTACORE-SCR4-RV32-SAME: "-target-feature" "+zicsr"
+// MCPU-SYNTACORE-SCR4-RV32-SAME: "-target-feature" "+zifencei"
+// MCPU-SYNTACORE-SCR4-RV32-SAME: "-target-abi" "ilp32d"
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=syntacore-scr4-rv32 | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR4-RV32 %s
+// MTUNE-SYNTACORE-SCR4-RV32: "-tune-cpu" "syntacore-scr4-rv32"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=syntacore-scr4-rv64 | 
FileCheck -check-prefix=MCPU-SYNTACORE-SCR4-RV64 %s
+// MCPU-SYNTACORE-SCR4-RV64: "-target-cpu" "syntacore-scr4-rv64"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-feature" "+m"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-feature" "+a"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-feature" "+f"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-feature" "+d"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-feature" "+c"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-feature" "+zicsr"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-feature" "+zifencei"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-abi" "lp64d"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=syntacore-scr4-rv64 | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR4-RV64 %s
+// MTUNE-SYNTACORE-SCR4-RV64: "-tune-cpu" "syntacore-scr4-rv64"
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index e0757b69242a8..b87bced18cb2b 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -81,16 +81,16 @@
 
 // RUN: not %clang_cc1 -triple riscv32 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV32
 // RISCV32: error: unknown target CPU 'not-a-cpu'
-// RISCV32-NEXT: note: valid target CPU values are: generic-rv32, rocket-rv32, 
sifive-e20, sifive-e21, sifive-e24, sifive-e31, sifive-e34, sifive-e76, 
syntacore-scr1-base, syntacore-scr1-max, syntacore-scr3-rv32{{$}}
+// RISCV32-NEXT: note: valid target CPU values are: generic-rv32, rocket-rv32, 
sifive-e20, sifive-e21, sifive-e24, sifive-e31, sifive-e34, sifive-e76, 
syntacore-scr1-base, syntacore-scr1-max, syntacore-scr3-rv32, 
syntacore-scr4-rv32{{$}}
 
 // RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV64
 // RISCV64: error: unknown target CPU 'not-a-cpu'
-// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-p450, sifive-p670, sifive-s21, sifive-s51, sifive-s54, sifive-s76, 
sifive-u54, sifive-u74, sifive-x280, spacemit-x60, syntacore-scr3-rv64, 
veyron-v1, xiangshan-nanhu{{$}}
+// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-p450, sifive-p670, sifive-s21, sifive-s51, sifive-s54, sifive-s76, 
sifive-u54, sifive-u74, sifive-x280, spacemit

[clang] [llvm] [RISCV] Add Syntacore SCR4 RV32/64 processors definition (PR #101321)

2024-07-31 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-risc-v

Author: Anton Sidorenko (asi-sc)


Changes

Syntacore SCR4 is a microcontroller-class processor core that has much in 
common with SCR3. The most significant difference for compilers is F and D 
extensions support. Overview: https://syntacore.com/products/scr4

Two CPUs are added:
  * 'syntacore-scr4-rv32' -- rv32imfdc
  * 'syntacore-scr4-rv64' -- rv64imafdc

Scheduling model will be added in a separate PR.
-

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


4 Files Affected:

- (modified) clang/test/Driver/riscv-cpus.c (+27) 
- (modified) clang/test/Misc/target-invalid-cpu-note.c (+4-4) 
- (modified) llvm/docs/ReleaseNotes.rst (+1) 
- (modified) llvm/lib/Target/RISCV/RISCVProcessors.td (+25) 


``diff
diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index 26bcda6468dd2..7a885cde76d6a 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -381,3 +381,30 @@
 
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=syntacore-scr3-rv64 | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR3-RV64 %s
 // MTUNE-SYNTACORE-SCR3-RV64: "-tune-cpu" "syntacore-scr3-rv64"
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=syntacore-scr4-rv32 | 
FileCheck -check-prefix=MCPU-SYNTACORE-SCR4-RV32 %s
+// MCPU-SYNTACORE-SCR4-RV32: "-target-cpu" "syntacore-scr4-rv32"
+// MCPU-SYNTACORE-SCR4-RV32-SAME: "-target-feature" "+m"
+// MCPU-SYNTACORE-SCR4-RV32-SAME: "-target-feature" "+f"
+// MCPU-SYNTACORE-SCR4-RV32-SAME: "-target-feature" "+d"
+// MCPU-SYNTACORE-SCR4-RV32-SAME: "-target-feature" "+c"
+// MCPU-SYNTACORE-SCR4-RV32-SAME: "-target-feature" "+zicsr"
+// MCPU-SYNTACORE-SCR4-RV32-SAME: "-target-feature" "+zifencei"
+// MCPU-SYNTACORE-SCR4-RV32-SAME: "-target-abi" "ilp32d"
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=syntacore-scr4-rv32 | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR4-RV32 %s
+// MTUNE-SYNTACORE-SCR4-RV32: "-tune-cpu" "syntacore-scr4-rv32"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=syntacore-scr4-rv64 | 
FileCheck -check-prefix=MCPU-SYNTACORE-SCR4-RV64 %s
+// MCPU-SYNTACORE-SCR4-RV64: "-target-cpu" "syntacore-scr4-rv64"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-feature" "+m"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-feature" "+a"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-feature" "+f"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-feature" "+d"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-feature" "+c"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-feature" "+zicsr"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-feature" "+zifencei"
+// MCPU-SYNTACORE-SCR4-RV64-SAME: "-target-abi" "lp64d"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=syntacore-scr4-rv64 | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR4-RV64 %s
+// MTUNE-SYNTACORE-SCR4-RV64: "-tune-cpu" "syntacore-scr4-rv64"
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index e0757b69242a8..b87bced18cb2b 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -81,16 +81,16 @@
 
 // RUN: not %clang_cc1 -triple riscv32 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV32
 // RISCV32: error: unknown target CPU 'not-a-cpu'
-// RISCV32-NEXT: note: valid target CPU values are: generic-rv32, rocket-rv32, 
sifive-e20, sifive-e21, sifive-e24, sifive-e31, sifive-e34, sifive-e76, 
syntacore-scr1-base, syntacore-scr1-max, syntacore-scr3-rv32{{$}}
+// RISCV32-NEXT: note: valid target CPU values are: generic-rv32, rocket-rv32, 
sifive-e20, sifive-e21, sifive-e24, sifive-e31, sifive-e34, sifive-e76, 
syntacore-scr1-base, syntacore-scr1-max, syntacore-scr3-rv32, 
syntacore-scr4-rv32{{$}}
 
 // RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV64
 // RISCV64: error: unknown target CPU 'not-a-cpu'
-// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-p450, sifive-p670, sifive-s21, sifive-s51, sifive-s54, sifive-s76, 
sifive-u54, sifive-u74, sifive-x280, spacemit-x60, syntacore-scr3-rv64, 
veyron-v1, xiangshan-nanhu{{$}}
+// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-p450, sifive-p670, sifive-s21, sifive-s51, sifive-s54, sifive-s76, 
sifive-u54, sifive-u74, sifive-x280, spacemit-x60, syntacore-scr3-rv64, 
syntacore-scr4-rv64, veyron-v1, xiangshan-nanhu{{$}}
 
 // RUN: not %clang_cc1 -triple riscv32 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV32
 // TUNE-RISCV32: error: unknown target CPU 'not-a-cpu'
-// TUNE-RISCV32-NEXT: note: valid target CPU values are: generic-rv32, 
rocket-rv32, sifive-e20, sifive-e21, sifive-e24, sifive-e31, sifive-e34, 
sifive-e76, syntacore-scr1-base, syntacore-scr1-max, syntacore-scr3-rv32, 
generic, roc

[clang] [llvm] [RISCV] Add Syntacore SCR4 RV32/64 processors definition (PR #101321)

2024-07-31 Thread Anton Sidorenko via cfe-commits

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


[clang] [llvm] [AArch64] Cleanup existing values in getMemOpInfo (PR #98196)

2024-07-31 Thread David Green via cfe-commits

https://github.com/davemgreen updated 
https://github.com/llvm/llvm-project/pull/98196

>From b46d892a43b034dd515987f37441fc842710dc62 Mon Sep 17 00:00:00 2001
From: Haowei Wu 
Date: Wed, 31 Jul 2024 12:12:26 +0100
Subject: [PATCH] Revert "[C++20] [Modules] Always emit the inline builtins"

This reverts commit ca8a4111f796fe8533e0af95557875b15becff06.
This patch broke clang test on Windows x64 msvc
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  10 +-
 clang/test/Modules/inline-builtins.cppm   |  34 ---
 .../Target/AArch64/AArch64FrameLowering.cpp   |   3 +-
 llvm/lib/Target/AArch64/AArch64InstrInfo.cpp  | 257 --
 llvm/lib/Target/AArch64/AArch64InstrInfo.h|   5 +-
 .../CodeGen/AArch64/sched-postidxalias.mir|  63 +
 6 files changed, 314 insertions(+), 58 deletions(-)
 delete mode 100644 clang/test/Modules/inline-builtins.cppm
 create mode 100644 llvm/test/CodeGen/AArch64/sched-postidxalias.mir

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 5a575c535b505..344a0e538f22a 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4022,11 +4022,6 @@ bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
 return true;
 
   const auto *F = cast(GD.getDecl());
-  // Inline builtins declaration must be emitted. They often are fortified
-  // functions.
-  if (F->isInlineBuiltinDeclaration())
-return true;
-
   if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr())
 return false;
 
@@ -4072,6 +4067,11 @@ bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
 }
   }
 
+  // Inline builtins declaration must be emitted. They often are fortified
+  // functions.
+  if (F->isInlineBuiltinDeclaration())
+return true;
+
   // PR9614. Avoid cases where the source code is lying to us. An available
   // externally function should have an equivalent function somewhere else,
   // but a function that calls itself through asm label/`__builtin_` trickery 
is
diff --git a/clang/test/Modules/inline-builtins.cppm 
b/clang/test/Modules/inline-builtins.cppm
deleted file mode 100644
index 8f41ae2659513..0
--- a/clang/test/Modules/inline-builtins.cppm
+++ /dev/null
@@ -1,34 +0,0 @@
-// RUN: rm -rf %t
-// RUN: split-file %s %t
-// RUN: cd %t
-//
-// RUN: %clang_cc1 -std=c++20 -O3 %t/a.cppm -emit-module-interface -o %t/a.pcm
-// RUN: %clang_cc1 -std=c++20 -O3 %t/test.cc -fmodule-file=a=%t/a.pcm \
-// RUN:   -emit-llvm -o - | FileCheck %t/test.cc
-
-//--- memmove.h
-typedef long unsigned int size_t;
-extern "C" void *memmove (void *__dest, const void *__src, size_t __n)
- throw () __attribute__ ((__nonnull__ (1, 2)));
-extern "C" __inline __attribute__ ((__always_inline__)) __attribute__ 
((__gnu_inline__)) void *
- memmove (void *__dest, const void *__src, size_t __len) throw ()
-{
-  return __builtin_memmove(__dest, __src, __len);
-}
-
-//--- a.cppm
-module;
-#include "memmove.h"
-export module a;
-export using ::memmove;
-
-//--- test.cc
-import a;
-
-void test() {
-  int a, b;
-  unsigned c = 0;
-  memmove(&a, &b, c);
-}
-
-// CHECK-NOT: memmove
diff --git a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
index bd530903bb664..f28511c74dcd6 100644
--- a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
@@ -1487,7 +1487,8 @@ static MachineBasicBlock::iterator 
convertCalleeSaveRestoreToSPPrePostIncDec(
   // If the first store isn't right where we want SP then we can't fold the
   // update in so create a normal arithmetic instruction instead.
   if (MBBI->getOperand(MBBI->getNumOperands() - 1).getImm() != 0 ||
-  CSStackSizeInc < MinOffset || CSStackSizeInc > MaxOffset) {
+  CSStackSizeInc < MinOffset * (int64_t)Scale.getFixedValue() ||
+  CSStackSizeInc > MaxOffset * (int64_t)Scale.getFixedValue()) {
 // If we are destroying the frame, make sure we add the increment after the
 // last frame operation.
 if (FrameFlag == MachineInstr::FrameDestroy)
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp 
b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index 6cd9a1a817086..0320c6e78ff9c 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -3487,6 +3487,229 @@ MachineInstr 
*AArch64InstrInfo::emitLdStWithAddr(MachineInstr &MemI,
   "Function must not be called with an addressing mode it can't handle");
 }
 
+/// Return true if the opcode is a post-index ld/st instruction, which really
+/// loads from base+0.
+static bool isPostIndexLdStOpcode(unsigned Opcode) {
+  switch (Opcode) {
+  default:
+return false;
+  case AArch64::LD1Fourv16b_POST:
+  case AArch64::LD1Fourv1d_POST:
+  case AArch64::LD1Fourv2d_POST:
+  case AArch64::LD1Fourv2s_POST:
+  case AArch64::LD1Fourv4h_POST:
+  case AArch64::LD1Fourv4s_POST:
+  case AArch64::LD1Fourv8b_POST:
+  case AArch64::LD1Fourv8h_POST:
+  case

[clang] [clang] Fix crash with multiple non-parenthsized `sizeof` (PR #101297)

2024-07-31 Thread Vlad Serebrennikov via cfe-commits

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

>From d75b3cef41c370fef939a347935a4f3ed53c46ea Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 31 Jul 2024 10:29:04 +0300
Subject: [PATCH 1/3] [clang] Fix crash with multiple non-parenthsized `sizeof`

---
 clang/lib/Parse/ParseExpr.cpp |  14 +-
 .../parser-overflow-non-parenthesized.c   | 135 ++
 2 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Parser/parser-overflow-non-parenthesized.c

diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index e82b565272831..e501d5e91e77d 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2479,7 +2479,19 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token 
&OpTok,
   return ExprError();
 }
 
-Operand = ParseCastExpression(UnaryExprOnly);
+// If we're parsing a chain that consists of keywords that could be
+// followed by a non-parenthesized expression, BalancedDelimiterTracker
+// is not going to help when the nesting is too deep. In this corner case
+// we continue to parse with sufficient stack space to avoid crashing.
+if (OpTok.isOneOf(tok::kw_sizeof, tok::kw___datasizeof, tok::kw___alignof,
+  tok::kw_alignof, tok::kw__Alignof) &&
+Tok.isOneOf(tok::kw_sizeof, tok::kw___datasizeof, tok::kw___alignof,
+tok::kw_alignof, tok::kw__Alignof))
+  Actions.runWithSufficientStackSpace(Tok.getLocation(), [&] {
+Operand = ParseCastExpression(UnaryExprOnly);
+  });
+else
+  Operand = ParseCastExpression(UnaryExprOnly);
   } else {
 // If it starts with a '(', we know that it is either a parenthesized
 // type-name, or it is a unary-expression that starts with a compound
diff --git a/clang/test/Parser/parser-overflow-non-parenthesized.c 
b/clang/test/Parser/parser-overflow-non-parenthesized.c
new file mode 100644
index 0..b6c7485274090
--- /dev/null
+++ b/clang/test/Parser/parser-overflow-non-parenthesized.c
@@ -0,0 +1,135 @@
+// RUN: %clang_cc1 %s 2>&1 | FileCheck %s
+
+void f(void) {
+  // 600 sizeof's
+  int a =
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof
+  sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeof sizeo

[clang] [libclang/python] Factor out unsaved files processing (PR #101308)

2024-07-31 Thread Vlad Serebrennikov via cfe-commits

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


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


[clang] 4c670b2 - [libclang/python] Factor out unsaved files processing (#101308)

2024-07-31 Thread via cfe-commits

Author: Jannick Kremer
Date: 2024-07-31T16:19:13+04:00
New Revision: 4c670b266a10d613a58b71cc9c3d3a21cb6dc36b

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

LOG: [libclang/python] Factor out unsaved files processing (#101308)

Factor out the processing of unsaved files into its own function as
suggested by @Endilll
[here](https://github.com/llvm/llvm-project/pull/78114/files#r1697730196)

Added: 


Modified: 
clang/bindings/python/clang/cindex.py

Removed: 




diff  --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 72509a8a54f28..f669c279aab6d 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3011,6 +3011,20 @@ class TranslationUnit(ClangObject):
 # into the set of code completions returned from this translation unit.
 PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION = 128
 
+@staticmethod
+def process_unsaved_files(unsaved_files) -> Array[_CXUnsavedFile] | None:
+unsaved_array = None
+if len(unsaved_files):
+unsaved_array = (_CXUnsavedFile * len(unsaved_files))()
+for i, (name, contents) in enumerate(unsaved_files):
+if hasattr(contents, "read"):
+contents = contents.read()
+binary_contents = b(contents)
+unsaved_array[i].name = b(os.fspath(name))
+unsaved_array[i].contents = binary_contents
+unsaved_array[i].length = len(binary_contents)
+return unsaved_array
+
 @classmethod
 def from_source(
 cls, filename, args=None, unsaved_files=None, options=0, index=None
@@ -3067,16 +3081,7 @@ def from_source(
 if len(args) > 0:
 args_array = (c_char_p * len(args))(*[b(x) for x in args])
 
-unsaved_array = None
-if len(unsaved_files) > 0:
-unsaved_array = (_CXUnsavedFile * len(unsaved_files))()
-for i, (name, contents) in enumerate(unsaved_files):
-if hasattr(contents, "read"):
-contents = contents.read()
-contents = b(contents)
-unsaved_array[i].name = b(os.fspath(name))
-unsaved_array[i].contents = contents
-unsaved_array[i].length = len(contents)
+unsaved_array = cls.process_unsaved_files(unsaved_files)
 
 ptr = conf.lib.clang_parseTranslationUnit(
 index,
@@ -3257,16 +3262,7 @@ def reparse(self, unsaved_files=None, options=0):
 if unsaved_files is None:
 unsaved_files = []
 
-unsaved_files_array = 0
-if len(unsaved_files):
-unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
-for i, (name, contents) in enumerate(unsaved_files):
-if hasattr(contents, "read"):
-contents = contents.read()
-contents = b(contents)
-unsaved_files_array[i].name = b(os.fspath(name))
-unsaved_files_array[i].contents = contents
-unsaved_files_array[i].length = len(contents)
+unsaved_files_array = self.process_unsaved_files(unsaved_files)
 ptr = conf.lib.clang_reparseTranslationUnit(
 self, len(unsaved_files), unsaved_files_array, options
 )
@@ -3329,16 +3325,7 @@ def codeComplete(
 if unsaved_files is None:
 unsaved_files = []
 
-unsaved_files_array = 0
-if len(unsaved_files):
-unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
-for i, (name, contents) in enumerate(unsaved_files):
-if hasattr(contents, "read"):
-contents = contents.read()
-contents = b(contents)
-unsaved_files_array[i].name = b(os.fspath(name))
-unsaved_files_array[i].contents = contents
-unsaved_files_array[i].length = len(contents)
+unsaved_files_array = self.process_unsaved_files(unsaved_files)
 ptr = conf.lib.clang_codeCompleteAt(
 self,
 os.fspath(path),



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


[clang] [libclang/python] Factor out unsaved files processing (PR #101308)

2024-07-31 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-07-31 Thread Vlad Serebrennikov via cfe-commits


@@ -3257,21 +3323,21 @@ def reparse(self, unsaved_files=None, options=0):
 if unsaved_files is None:
 unsaved_files = []
 
-unsaved_files_array = 0
+unsaved_files_array: int | Array[_CXUnsavedFile] = 0
 if len(unsaved_files):
 unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
 for i, (name, contents) in enumerate(unsaved_files):
 if hasattr(contents, "read"):
 contents = contents.read()
-contents = b(contents)
+binary_contents = b(contents)

Endilll wrote:

I merged #101308 just now, so you can sidestep the issue by updating this PR 
with changes from `main`.

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


[clang] [libclang/python] type-ignore `Any` returns from library calls (PR #101310)

2024-07-31 Thread Vlad Serebrennikov via cfe-commits

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


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


[clang] [C11] Claim conformance to WG14 N1396 (PR #101214)

2024-07-31 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

Thank you! I updated the test and status information; let me know if you'd like 
to see further adjustments.

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


[clang] 5525566 - [libclang/python] type-ignore `Any` returns from library calls (#101310)

2024-07-31 Thread via cfe-commits

Author: Jannick Kremer
Date: 2024-07-31T16:21:43+04:00
New Revision: 55255669077b191043b1a8920107890815151835

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

LOG: [libclang/python] type-ignore `Any` returns from library calls (#101310)

On its own, this change leads to _more_ strict typing errors as the
functions are mostly not annotated so far, so the `# type: ignore`s are
reported as Unused. This is part of the work leading up to #78114
though, and one of the bigger parts factored out from it, so these will
later lead to less strict typing errors as the functions are annotated
with return types.

Added: 


Modified: 
clang/bindings/python/clang/cindex.py

Removed: 




diff  --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index f669c279aab6d..2038ef6045c7d 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -276,7 +276,7 @@ def from_position(tu, file, line, column):
 Retrieve the source location associated with a given file/line/column 
in
 a particular translation unit.
 """
-return conf.lib.clang_getLocation(tu, file, line, column)
+return conf.lib.clang_getLocation(tu, file, line, column)  # type: 
ignore [no-any-return]
 
 @staticmethod
 def from_offset(tu, file, offset):
@@ -286,7 +286,7 @@ def from_offset(tu, file, offset):
 file -- File instance to obtain offset from
 offset -- Integer character offset within file
 """
-return conf.lib.clang_getLocationForOffset(tu, file, offset)
+return conf.lib.clang_getLocationForOffset(tu, file, offset)  # type: 
ignore [no-any-return]
 
 @property
 def file(self):
@@ -311,10 +311,10 @@ def offset(self):
 @property
 def is_in_system_header(self):
 """Returns true if the given source location is in a system header."""
-return conf.lib.clang_Location_isInSystemHeader(self)
+return conf.lib.clang_Location_isInSystemHeader(self)  # type: ignore 
[no-any-return]
 
 def __eq__(self, other):
-return conf.lib.clang_equalLocations(self, other)
+return conf.lib.clang_equalLocations(self, other)  # type: ignore 
[no-any-return]
 
 def __ne__(self, other):
 return not self.__eq__(other)
@@ -347,7 +347,7 @@ class SourceRange(Structure):
 # object.
 @staticmethod
 def from_locations(start, end):
-return conf.lib.clang_getRange(start, end)
+return conf.lib.clang_getRange(start, end)  # type: ignore 
[no-any-return]
 
 @property
 def start(self):
@@ -355,7 +355,7 @@ def start(self):
 Return a SourceLocation representing the first character within a
 source range.
 """
-return conf.lib.clang_getRangeStart(self)
+return conf.lib.clang_getRangeStart(self)  # type: ignore 
[no-any-return]
 
 @property
 def end(self):
@@ -363,10 +363,10 @@ def end(self):
 Return a SourceLocation representing the last character within a
 source range.
 """
-return conf.lib.clang_getRangeEnd(self)
+return conf.lib.clang_getRangeEnd(self)  # type: ignore [no-any-return]
 
 def __eq__(self, other):
-return conf.lib.clang_equalRanges(self, other)
+return conf.lib.clang_equalRanges(self, other)  # type: ignore 
[no-any-return]
 
 def __ne__(self, other):
 return not self.__eq__(other)
@@ -429,15 +429,15 @@ def __del__(self):
 
 @property
 def severity(self):
-return conf.lib.clang_getDiagnosticSeverity(self)
+return conf.lib.clang_getDiagnosticSeverity(self)  # type: ignore 
[no-any-return]
 
 @property
 def location(self):
-return conf.lib.clang_getDiagnosticLocation(self)
+return conf.lib.clang_getDiagnosticLocation(self)  # type: ignore 
[no-any-return]
 
 @property
 def spelling(self):
-return conf.lib.clang_getDiagnosticSpelling(self)
+return conf.lib.clang_getDiagnosticSpelling(self)  # type: ignore 
[no-any-return]
 
 @property
 def ranges(self) -> NoSliceSequence[SourceRange]:
@@ -451,7 +451,7 @@ def __len__(self) -> int:
 def __getitem__(self, key: int) -> SourceRange:
 if key >= len(self):
 raise IndexError
-return conf.lib.clang_getDiagnosticRange(self.diag, key)
+return conf.lib.clang_getDiagnosticRange(self.diag, key)  # 
type: ignore [no-any-return]
 
 return RangeIterator(self)
 
@@ -494,17 +494,17 @@ def __getitem__(self, key: int) -> Diagnostic:
 @property
 def category_number(self):
 """The category number for this diagnostic or 0 if unavailable."""
-return conf.lib.clang_g

[clang] [libclang/python] type-ignore `Any` returns from library calls (PR #101310)

2024-07-31 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-07-31 Thread Vlad Serebrennikov via cfe-commits


@@ -255,71 +263,75 @@ class SourceLocation(Structure):
 """
 
 _fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_uint)]
-_data = None
+_data: tuple[File | None, int, int, int] | None = None
 
-def _get_instantiation(self):
+def _get_instantiation(self) -> tuple[File | None, int, int, int]:
 if self._data is None:
 f, l, c, o = c_object_p(), c_uint(), c_uint(), c_uint()
 conf.lib.clang_getInstantiationLocation(
 self, byref(f), byref(l), byref(c), byref(o)
 )
 if f:
-f = File(f)
+file = File(f)
 else:
-f = None
-self._data = (f, int(l.value), int(c.value), int(o.value))
+file = None
+self._data = (file, int(l.value), int(c.value), int(o.value))
 return self._data
 
 @staticmethod
-def from_position(tu, file, line, column):
+def from_position(
+tu: TranslationUnit, file: File, line: int, column: int
+) -> SourceLocation:
 """
 Retrieve the source location associated with a given file/line/column 
in
 a particular translation unit.
 """
-return conf.lib.clang_getLocation(tu, file, line, column)
+return conf.lib.clang_getLocation(tu, file, line, column)  # type: 
ignore [no-any-return]
 
 @staticmethod
-def from_offset(tu, file, offset):
+def from_offset(tu: TranslationUnit, file: File, offset: int) -> 
SourceLocation:
 """Retrieve a SourceLocation from a given character offset.
 
 tu -- TranslationUnit file belongs to
 file -- File instance to obtain offset from
 offset -- Integer character offset within file
 """
-return conf.lib.clang_getLocationForOffset(tu, file, offset)
+return conf.lib.clang_getLocationForOffset(tu, file, offset)  # type: 
ignore [no-any-return]

Endilll wrote:

This one was merged just now, too.

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


[clang] [clang][ASTImporter] Remove trailing return testing on lambda proto (PR #101031)

2024-07-31 Thread Balázs Kéri via cfe-commits

balazske wrote:

This looks like a good fix if there is no other way to detect the "C++11 lambda 
without parentheses" case.

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


[clang] [clang][ASTImporter] Remove trailing return testing on lambda proto (PR #101031)

2024-07-31 Thread Balázs Kéri via cfe-commits

balazske wrote:

> Here can `ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());` 
> add any nullptr into `ToProcess` in this testing context?

I think it is possible, but I could not reproduce this case with the shown 
code. 

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


[clang] [CLANG][AArch64]Add Neon vectors for fpm8_t (PR #99865)

2024-07-31 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 9e63632b3274dc1b20502b569e79a311977e0a97 
6dd7d08634707fbaf417ae2f9f4315e529045fd4 --extensions cpp,h,c -- 
clang/test/AST/arm-mfp8.cpp clang/test/CodeGen/arm-mfp8.c 
clang/test/Sema/arm-mfp8.c clang/test/Sema/arm-mfp8.cpp 
clang/include/clang/AST/ASTContext.h clang/include/clang/AST/Type.h 
clang/include/clang/Basic/Specifiers.h 
clang/include/clang/Basic/TargetBuiltins.h 
clang/include/clang/Basic/TargetInfo.h clang/include/clang/Sema/DeclSpec.h 
clang/include/clang/Serialization/ASTBitCodes.h clang/lib/AST/ASTContext.cpp 
clang/lib/AST/ItaniumMangle.cpp clang/lib/AST/PrintfFormatString.cpp 
clang/lib/AST/Type.cpp clang/lib/AST/TypeLoc.cpp clang/lib/Basic/TargetInfo.cpp 
clang/lib/Basic/Targets/AArch64.cpp clang/lib/Basic/Targets/AArch64.h 
clang/lib/Basic/Targets/ARM.cpp clang/lib/Basic/Targets/ARM.h 
clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CGDebugInfo.cpp 
clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/CodeGenTypeCache.h 
clang/lib/CodeGen/CodeGenTypes.cpp clang/lib/CodeGen/ItaniumCXXABI.cpp 
clang/lib/Index/USRGeneration.cpp clang/lib/Lex/Lexer.cpp 
clang/lib/Parse/ParseDecl.cpp clang/lib/Parse/ParseExpr.cpp 
clang/lib/Parse/ParseExprCXX.cpp clang/lib/Parse/ParseTentative.cpp 
clang/lib/Sema/DeclSpec.cpp clang/lib/Sema/SemaARM.cpp 
clang/lib/Sema/SemaCast.cpp clang/lib/Sema/SemaExpr.cpp 
clang/lib/Sema/SemaTemplateVariadic.cpp clang/lib/Sema/SemaType.cpp 
clang/lib/Serialization/ASTCommon.cpp clang/lib/Serialization/ASTReader.cpp 
clang/utils/TableGen/NeonEmitter.cpp clang/utils/TableGen/TableGen.cpp 
clang/utils/TableGen/TableGenBackends.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index fe3234ef85..19101f5a95 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3800,7 +3800,9 @@ void CXXNameMangler::mangleNeonVectorType(const 
VectorType *T) {
 case BuiltinType::Float: EltName = "float32_t"; break;
 case BuiltinType::Half:  EltName = "float16_t"; break;
 case BuiltinType::BFloat16:  EltName = "bfloat16_t"; break;
-case BuiltinType::MFloat8:   EltName = "mfloat8_t"; break;
+case BuiltinType::MFloat8:
+  EltName = "mfloat8_t";
+  break;
 default:
   llvm_unreachable("unexpected Neon vector element type");
 }
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 3af64ea55e..59a8124836 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -576,7 +576,8 @@ const char *DeclSpec::getSpecifierName(DeclSpec::TST T,
   case DeclSpec::TST_fract:   return "_Fract";
   case DeclSpec::TST_float16: return "_Float16";
   case DeclSpec::TST_float128:return "__float128";
-  case DeclSpec::TST_MFloat8: return "__mfp8";
+  case DeclSpec::TST_MFloat8:
+return "__mfp8";
   case DeclSpec::TST_ibm128:  return "__ibm128";
   case DeclSpec::TST_bool:return Policy.Bool ? "bool" : "_Bool";
   case DeclSpec::TST_decimal32:   return "_Decimal32";
diff --git a/clang/utils/TableGen/TableGen.cpp 
b/clang/utils/TableGen/TableGen.cpp
index 8eb5b0f35f..f77e16b302 100644
--- a/clang/utils/TableGen/TableGen.cpp
+++ b/clang/utils/TableGen/TableGen.cpp
@@ -229,7 +229,8 @@ cl::opt Action(
 clEnumValN(GenArmNeon, "gen-arm-neon", "Generate arm_neon.h for 
clang"),
 clEnumValN(GenArmFP16, "gen-arm-fp16", "Generate arm_fp16.h for 
clang"),
 clEnumValN(GenArmBF16, "gen-arm-bf16", "Generate arm_bf16.h for 
clang"),
-clEnumValN(GenArmMFloat8, "gen-arm-mfp8", "Generate arm_mfp8.h for 
clang"),
+clEnumValN(GenArmMFloat8, "gen-arm-mfp8",
+   "Generate arm_mfp8.h for clang"),
 clEnumValN(GenArmVectorType, "gen-arm-vector-type",
"Generate arm_vector_types.h for clang"),
 clEnumValN(GenArmNeonSema, "gen-arm-neon-sema",

``




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


[clang] [clang][LoongArch] Align global symbol by size (PR #101309)

2024-07-31 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

This looks wrong. Preferred and ABI alignments should be set in Triple.


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


[clang] [clang] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-07-31 Thread Aaron Ballman via cfe-commits

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


[clang] [clang] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-07-31 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-linux-pc -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-windows-pc -fsyntax-only -verify -std=c++11 
%s
+// RUN: %clang_cc1 -triple i386-linux-pc -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple i386-windows-pc -fsyntax-only -verify -std=c++11 %s
+
+#if __BITINT_MAXWIDTH__ >= 35
+struct {
+  _BitInt(35) i : 33;
+} x;
+struct {
+  _BitInt(35) i : 34;
+} y;
+_BitInt(33) xx{ x.i };
+_BitInt(33) yy{ y.i };
+// expected-error@-1 {{non-constant-expression cannot be narrowed from type 
'_BitInt(35)' to '_BitInt(33)' in initializer list}}
+//   FIXME-expected-note@-2 {{insert an explicit cast to silence this issue}}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 3

AaronBallman wrote:

Same here

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


[clang] [clang] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-07-31 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-linux-pc -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-windows-pc -fsyntax-only -verify -std=c++11 
%s
+// RUN: %clang_cc1 -triple i386-linux-pc -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple i386-windows-pc -fsyntax-only -verify -std=c++11 %s

AaronBallman wrote:

Could we get away with two RUN lines instead of four by doing `-triple x86_64` 
and `-triple i386` and leaving the rest of the triple to the test runner?

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


[clang] [clang] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-07-31 Thread Aaron Ballman via cfe-commits

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

Generally LGTM, just a few minor things. Thank you for this!

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


[clang] [clang] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-07-31 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-linux-pc -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-windows-pc -fsyntax-only -verify -std=c++11 
%s
+// RUN: %clang_cc1 -triple i386-linux-pc -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple i386-windows-pc -fsyntax-only -verify -std=c++11 %s
+
+#if __BITINT_MAXWIDTH__ >= 35

AaronBallman wrote:

No need for this predicate, it's required to be at least the same width as 
`long long`.

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


[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-07-31 Thread Jannick Kremer via cfe-commits

https://github.com/DeinAlptraum updated 
https://github.com/llvm/llvm-project/pull/78114

>From 04641f7ea15382df2d43fecc32bd1b699e0b2481 Mon Sep 17 00:00:00 2001
From: Jannick Kremer 
Date: Fri, 12 Jul 2024 15:08:06 +0100
Subject: [PATCH] [libclang/python] Add strict typing to clang Python bindings

---
 clang/bindings/python/clang/cindex.py | 654 ++
 1 file changed, 364 insertions(+), 290 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 2038ef6045c7d..32ed0920ff31e 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -71,8 +71,11 @@
 from typing import (
 Any,
 Callable,
+cast as Tcast,
 Generic,
+Iterator,
 Optional,
+Sequence,
 Type as TType,
 TypeVar,
 TYPE_CHECKING,
@@ -81,14 +84,19 @@
 
 if TYPE_CHECKING:
 from ctypes import _Pointer
+from io import TextIOWrapper
 from typing_extensions import Protocol, TypeAlias
 
 StrPath: TypeAlias = TUnion[str, os.PathLike[str]]
+InMemoryFile: TypeAlias = (
+"tuple[TUnion[str, os.PathLike[Any]], TUnion[str, TextIOWrapper]]"
+)
 LibFunc: TypeAlias = TUnion[
 "tuple[str, Optional[list[Any]]]",
 "tuple[str, Optional[list[Any]], Any]",
 "tuple[str, Optional[list[Any]], Any, Callable[..., Any]]",
 ]
+CObjP: TypeAlias = _Pointer[Any]
 
 TSeq = TypeVar("TSeq", covariant=True)
 
@@ -147,7 +155,7 @@ def b(x: str | bytes) -> bytes:
 # object. This is a problem, because it means that from_parameter will see an
 # integer and pass the wrong value on platforms where int != void*. Work around
 # this by marshalling object arguments as void**.
-c_object_p: TType[_Pointer[Any]] = POINTER(c_void_p)
+c_object_p: TType[CObjP] = POINTER(c_void_p)
 
 ### Exception Classes ###
 
@@ -183,7 +191,7 @@ class TranslationUnitSaveError(Exception):
 # Indicates that the translation unit was somehow invalid.
 ERROR_INVALID_TU = 3
 
-def __init__(self, enumeration, message):
+def __init__(self, enumeration: int, message: str):
 assert isinstance(enumeration, int)
 
 if enumeration < 1 or enumeration > 3:
@@ -255,23 +263,25 @@ class SourceLocation(Structure):
 """
 
 _fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_uint)]
-_data = None
+_data: tuple[File | None, int, int, int] | None = None
 
-def _get_instantiation(self):
+def _get_instantiation(self) -> tuple[File | None, int, int, int]:
 if self._data is None:
 f, l, c, o = c_object_p(), c_uint(), c_uint(), c_uint()
 conf.lib.clang_getInstantiationLocation(
 self, byref(f), byref(l), byref(c), byref(o)
 )
 if f:
-f = File(f)
+file = File(f)
 else:
-f = None
-self._data = (f, int(l.value), int(c.value), int(o.value))
+file = None
+self._data = (file, int(l.value), int(c.value), int(o.value))
 return self._data
 
 @staticmethod
-def from_position(tu, file, line, column):
+def from_position(
+tu: TranslationUnit, file: File, line: int, column: int
+) -> SourceLocation:
 """
 Retrieve the source location associated with a given file/line/column 
in
 a particular translation unit.
@@ -279,7 +289,7 @@ def from_position(tu, file, line, column):
 return conf.lib.clang_getLocation(tu, file, line, column)  # type: 
ignore [no-any-return]
 
 @staticmethod
-def from_offset(tu, file, offset):
+def from_offset(tu: TranslationUnit, file: File, offset: int) -> 
SourceLocation:
 """Retrieve a SourceLocation from a given character offset.
 
 tu -- TranslationUnit file belongs to
@@ -289,37 +299,39 @@ def from_offset(tu, file, offset):
 return conf.lib.clang_getLocationForOffset(tu, file, offset)  # type: 
ignore [no-any-return]
 
 @property
-def file(self):
+def file(self) -> File | None:
 """Get the file represented by this source location."""
 return self._get_instantiation()[0]
 
 @property
-def line(self):
+def line(self) -> int:
 """Get the line represented by this source location."""
 return self._get_instantiation()[1]
 
 @property
-def column(self):
+def column(self) -> int:
 """Get the column represented by this source location."""
 return self._get_instantiation()[2]
 
 @property
-def offset(self):
+def offset(self) -> int:
 """Get the file offset represented by this source location."""
 return self._get_instantiation()[3]
 
 @property
-def is_in_system_header(self):
+def is_in_system_header(self) -> bool:
 """Returns true if the given source location is in a system header."""
 return conf.lib.clang_Location_isInSystemHeader(self)  # type: ignor

[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-07-31 Thread Jannick Kremer via cfe-commits

DeinAlptraum wrote:

I'm planning to do one last split that contains all "logic" changes, after 
which this PR should contain only actual typing annotations and nothing else. 
Will open a PR for that other change one of these days

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


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

2024-07-31 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> This causes significant compile-time regressions, especially for unoptimized 
> builds: 
> https://llvm-compile-time-tracker.com/compare.php?from=39b6900852e7a1187bd742ba5c1387ca1be58e2c&to=2acf77f987331c05520c5bfd849326909ffce983&stat=instructions:u
> 
> You probably need to separately match the syntax and the name without 
> constructing a temporary `std::string`.

Thank you for identifying this, @nikic!

> That should elimate the need for any new std::strings. @AaronBallman does 
> this sound reasonable?

That seems like a good approach to me

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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-07-31 Thread via cfe-commits


@@ -179,6 +179,13 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
ArgList &Args,
   Features.push_back("-hard-quad-float");
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) 
{
+if (A->getOption().matches(options::OPT_mv8plus))

koachan wrote:

It is true that those flags primarily control the target environment, however, 
on GCC, `-m[no-]v8plus` also implies that V9 instructions are available (or 
not, in case of `-mno-v8plus`) (e.g when multiplying 64-bit numbers: 
https://godbolt.org/z/5zdWez6qz).
Also, unlike `-mx32`, `-m[no-]v8plus` is intended for use with 32-bit target 
(`-m32`); again, with GCC, `-mv8plus` raises an error with `-m64`, and 
`-mno-v8plus` is ignored (i.e it still generates 64-bit instructions) 
(https://godbolt.org/z/PcfMcT8cf).

It would be possible to define the flags such that `-m[no-]v8plus` do not touch 
the V9 feature bit, but I feel like that would defeat the purpose of V8+ 
environment (that is, to let 32-bit code use some 64-bit V9 instructions).

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


[clang] [clang][LoongArch] Align global symbol by size (PR #101309)

2024-07-31 Thread via cfe-commits

heiher wrote:

> This looks wrong. Preferred and ABI alignments should be set in ~Triple~. 
> ADD: Sorry, I meant DataLayout, of course.

Thanks for pointing this out. How does data layout affect the alignment of 
constant string global variable symbols?

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


[clang] [lld] [llvm] [LTO] enable `ObjCARCContractPass` only on optimized build (PR #101114)

2024-07-31 Thread Nikita Popov via cfe-commits

nikic wrote:

The pipeline test changes here still look problematic. Can you make the 
ObjCARCContract pass preserve the DT?

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


[libcxx] [libcxxabi] [libunwind] [NFC][libc++][libc++abi][libunwind][test] Fix/unify AIX triples used in LIT tests (PR #101196)

2024-07-31 Thread Louis Dionne via cfe-commits

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


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


[libcxx] [libcxxabi] [libunwind] [NFC][libc++][libc++abi][libunwind][test] Fix/unify AIX triples used in LIT tests (PR #101196)

2024-07-31 Thread Louis Dionne via cfe-commits


@@ -6,7 +6,7 @@
 //
 
//===--===//
 
-// REQUIRES: target={{powerpc.*-ibm-aix.*}}
+// REQUIRES: target={{.+}}-aix{{.*}}

ldionne wrote:

`libcxx/test/vendor` is a bit mis-named, I guess. It's more like 
`libcxx/test/vendor-or-extremely-platform-specific-stuff`. I think it makes 
more sense to keep this here since this test doesn't make sense outside of AIX.

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


[libunwind] [libunwind] Add GCS support for AArch64 (PR #99335)

2024-07-31 Thread John Brawn via cfe-commits

john-brawn-arm wrote:

Ping

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


[libcxx] [libcxxabi] [libunwind] [NFC][libc++][libc++abi][libunwind][test] Fix/unify AIX triples used in LIT tests (PR #101196)

2024-07-31 Thread Xing Xue via cfe-commits


@@ -6,7 +6,7 @@
 //
 
//===--===//
 
-// REQUIRES: target={{powerpc.*-ibm-aix.*}}
+// REQUIRES: target={{.+}}-aix{{.*}}

xingxue-ibm wrote:

Thanks!

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


[clang] [Driver] Pass correct alignment for -falign-functions with no argument (PR #101257)

2024-07-31 Thread Saleem Abdulrasool via cfe-commits


@@ -1982,7 +1982,7 @@ unsigned tools::ParseFunctionAlignment(const ToolChain 
&TC,
 return 0;
 
   if (A->getOption().matches(options::OPT_falign_functions))
-return 0;
+return 4; // log2(16)

compnerd wrote:

@pogo59 that is documented in the GCC documentation. Many, if not most, of the 
driver arguments are GCC derived and behave identically.

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


[clang] [AIX] Turn on `#pragma mc_func` check by default (PR #101336)

2024-07-31 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu created 
https://github.com/llvm/llvm-project/pull/101336

https://github.com/llvm/llvm-project/pull/99888 added a check (and 
corresponding options) to flag uses of `#pragma mc_func` on AIX. 

This PR turns on the check by default. 

>From e823d1e7eb3357fc5c15b614ac5fd94d331ac630 Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Wed, 31 Jul 2024 10:12:59 -0400
Subject: [PATCH] Turn on mc_func check by default.

---
 clang/include/clang/Driver/Options.td | 2 +-
 clang/include/clang/Lex/PreprocessorOptions.h | 4 ++--
 clang/lib/Driver/ToolChains/AIX.cpp   | 2 +-
 clang/test/Preprocessor/pragma_mc_func.c  | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c8c56dbb51b28..7f6b8ba4d7eeb 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8097,7 +8097,7 @@ def source_date_epoch : Separate<["-"], 
"source-date-epoch">,
 } // let Visibility = [CC1Option]
 
 defm err_pragma_mc_func_aix : BoolFOption<"err-pragma-mc-func-aix",
-  PreprocessorOpts<"ErrorOnPragmaMcfuncOnAIX">, DefaultFalse,
+  PreprocessorOpts<"ErrorOnPragmaMcfuncOnAIX">, DefaultTrue,
   PosFlag,
   NegFlag&1 | 
FileCheck %s
 // RUN: not %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix 
-fsyntax-only \
 // RUN:   %s 2>&1 | FileCheck %s
 #pragma mc_func asm_barrier {"6000"}
@@ -8,11 +9,10 @@
 // RUN: %clang --target=powerpc64-ibm-aix -fno-err-pragma-mc-func-aix 
-fsyntax-only %s
 // RUN: %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix 
-fsyntax-only \
 // RUN:-fno-err-pragma-mc-func-aix %s
-// RUN: %clang --target=powerpc64-ibm-aix -fsyntax-only %s
 // RUN: %clang --target=powerpc64-ibm-aix -Werror=unknown-pragmas \
 // RUN:   -fno-err-pragma-mc-func-aix -fsyntax-only %s
 
-// Cases where we have errors or warnings.
+// Cases on a non-AIX target.
 // RUN: not %clang --target=powerpc64le-unknown-linux-gnu \
 // RUN:   -Werror=unknown-pragmas -fno-err-pragma-mc-func-aix -fsyntax-only %s 
2>&1 | \
 // RUN:   FileCheck --check-prefix=UNUSED %s

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


[clang] [AIX] Turn on `#pragma mc_func` check by default (PR #101336)

2024-07-31 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-powerpc

Author: Qiongsi Wu (qiongsiwu)


Changes

https://github.com/llvm/llvm-project/pull/99888 added a check (and 
corresponding options) to flag uses of `#pragma mc_func` on AIX. 

This PR turns on the check by default. 

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


4 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+1-1) 
- (modified) clang/include/clang/Lex/PreprocessorOptions.h (+2-2) 
- (modified) clang/lib/Driver/ToolChains/AIX.cpp (+1-1) 
- (modified) clang/test/Preprocessor/pragma_mc_func.c (+2-2) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c8c56dbb51b28..7f6b8ba4d7eeb 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8097,7 +8097,7 @@ def source_date_epoch : Separate<["-"], 
"source-date-epoch">,
 } // let Visibility = [CC1Option]
 
 defm err_pragma_mc_func_aix : BoolFOption<"err-pragma-mc-func-aix",
-  PreprocessorOpts<"ErrorOnPragmaMcfuncOnAIX">, DefaultFalse,
+  PreprocessorOpts<"ErrorOnPragmaMcfuncOnAIX">, DefaultTrue,
   PosFlag,
   NegFlag&1 | 
FileCheck %s
 // RUN: not %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix 
-fsyntax-only \
 // RUN:   %s 2>&1 | FileCheck %s
 #pragma mc_func asm_barrier {"6000"}
@@ -8,11 +9,10 @@
 // RUN: %clang --target=powerpc64-ibm-aix -fno-err-pragma-mc-func-aix 
-fsyntax-only %s
 // RUN: %clang --target=powerpc64-ibm-aix -ferr-pragma-mc-func-aix 
-fsyntax-only \
 // RUN:-fno-err-pragma-mc-func-aix %s
-// RUN: %clang --target=powerpc64-ibm-aix -fsyntax-only %s
 // RUN: %clang --target=powerpc64-ibm-aix -Werror=unknown-pragmas \
 // RUN:   -fno-err-pragma-mc-func-aix -fsyntax-only %s
 
-// Cases where we have errors or warnings.
+// Cases on a non-AIX target.
 // RUN: not %clang --target=powerpc64le-unknown-linux-gnu \
 // RUN:   -Werror=unknown-pragmas -fno-err-pragma-mc-func-aix -fsyntax-only %s 
2>&1 | \
 // RUN:   FileCheck --check-prefix=UNUSED %s

``




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


[clang] [AIX] Detect `#pragma mc_func` (PR #99888)

2024-07-31 Thread Qiongsi Wu via cfe-commits

qiongsiwu wrote:

> My preference is for this to be on-by-default (then it shows its utility), 
> and I'd like to see those changes in the 19.x release (which means we'd need 
> to turn this around fairly quickly as we've already put out rc1).

Sounds good! Thanks again for your input @AaronBallman ! 

https://github.com/llvm/llvm-project/pull/101336 is setup to turn on the check 
by default. 

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


  1   2   3   4   5   >