[clang] 947b9f5 - [clang-repl] Fix printing preprocessed tokens and macros (#104964)

2024-08-21 Thread via cfe-commits

Author: Jonas Hahnfeld
Date: 2024-08-21T09:09:06+02:00
New Revision: 947b9f55b5f327e14368a48fb6ce10242ea29bf3

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

LOG: [clang-repl] Fix printing preprocessed tokens and macros (#104964)

Added: 
clang/test/Interpreter/preprocessor.cpp

Modified: 
clang/lib/Frontend/PrintPreprocessedOutput.cpp

Removed: 




diff  --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp 
b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 135dca0e6a1775..383d4356084916 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -916,8 +916,7 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token 
&Tok,
   PP.Lex(Tok);
   continue;
 } else if (Tok.is(tok::annot_repl_input_end)) {
-  PP.Lex(Tok);
-  continue;
+  // Fall through to exit the loop.
 } else if (Tok.is(tok::eod)) {
   // Don't print end of directive tokens, since they are typically newlines
   // that mess up our line tracking. These come from unknown pre-processor
@@ -1025,7 +1024,8 @@ static void PrintPreprocessedTokens(Preprocessor &PP, 
Token &Tok,
 Callbacks->setEmittedTokensOnThisLine();
 IsStartOfLine = false;
 
-if (Tok.is(tok::eof)) break;
+if (Tok.is(tok::eof) || Tok.is(tok::annot_repl_input_end))
+  break;
 
 PP.Lex(Tok);
 // If lexing that token causes us to need to skip future tokens, do so now.
@@ -1048,9 +1048,7 @@ static void DoPrintMacros(Preprocessor &PP, raw_ostream 
*OS) {
   // the macro table at the end.
   PP.EnterMainSourceFile();
 
-  Token Tok;
-  do PP.Lex(Tok);
-  while (Tok.isNot(tok::eof));
+  PP.LexTokensUntilEOF();
 
   SmallVector MacrosByID;
   for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();

diff  --git a/clang/test/Interpreter/preprocessor.cpp 
b/clang/test/Interpreter/preprocessor.cpp
new file mode 100644
index 00..8239fd45e661b0
--- /dev/null
+++ b/clang/test/Interpreter/preprocessor.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fincremental-extensions -E %s
+// RUN: %clang_cc1 -fincremental-extensions -E -dD %s
+// RUN: %clang_cc1 -fincremental-extensions -E -dI %s
+// RUN: %clang_cc1 -fincremental-extensions -E -dM %s



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


[clang] [clang-repl] Fix printing preprocessed tokens and macros (PR #104964)

2024-08-21 Thread Jonas Hahnfeld via cfe-commits

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


[clang] [llvm] [RISCV] Remove experimental for Ssqosid ext (PR #105476)

2024-08-21 Thread Shao-Ce SUN via cfe-commits

https://github.com/sunshaoce created 
https://github.com/llvm/llvm-project/pull/105476

Ratified: https://github.com/riscv/riscv-ssqosid/releases/tag/v1.0

>From acffcc86ffd145849ffeb884ab31d32c5cff5710 Mon Sep 17 00:00:00 2001
From: Shao-Ce SUN 
Date: Wed, 21 Aug 2024 15:12:32 +0800
Subject: [PATCH] [RISCV] Remove experimental for Ssqosid ext

Ratified: https://github.com/riscv/riscv-ssqosid/releases/tag/v1.0
---
 .../Driver/print-supported-extensions-riscv.c  |  2 +-
 .../test/Preprocessor/riscv-target-features.c  | 18 +-
 llvm/docs/RISCVUsage.rst   |  4 +---
 llvm/lib/Target/RISCV/RISCVFeatures.td |  6 +++---
 llvm/test/CodeGen/RISCV/attributes.ll  |  8 
 .../TargetParser/RISCVISAInfoTest.cpp  |  2 +-
 6 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 132422393170a9..9497d01a832604 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -126,6 +126,7 @@
 // CHECK-NEXT: sscofpmf 1.0   'Sscofpmf' (Count Overflow 
and Mode-Based Filtering)
 // CHECK-NEXT: sscounterenw 1.0   'Sscounterenw' (Support 
writeable scounteren enable bit for any hpmcounter that is not read-only zero)
 // CHECK-NEXT: sscsrind 1.0   'Sscsrind' (Indirect CSR 
Access Supervisor Level)
+// CHECK-NEXT: ssqosid  1.0   'Ssqosid' 
(Quality-of-Service (QoS) Identifiers)
 // CHECK-NEXT: ssstateen1.0   'Ssstateen' (Supervisor-mode 
view of the state-enable extension)
 // CHECK-NEXT: ssstrict 1.0   'Ssstrict' (No 
non-conforming extensions are present)
 // CHECK-NEXT: sstc 1.0   'Sstc' (Supervisor-mode 
timer interrupts)
@@ -178,7 +179,6 @@
 // CHECK-NEXT: smnpm1.0   'Smnpm' (Machine-level 
Pointer Masking for next lower privilege mode)
 // CHECK-NEXT: ssnpm1.0   'Ssnpm' (Supervisor-level 
Pointer Masking for next lower privilege mode)
 // CHECK-NEXT: sspm 1.0   'Sspm' (Indicates 
Supervisor-mode Pointer Masking)
-// CHECK-NEXT: ssqosid  1.0   'Ssqosid' 
(Quality-of-Service (QoS) Identifiers)
 // CHECK-NEXT: supm 1.0   'Supm' (Indicates User-mode 
Pointer Masking)
 // CHECK-EMPTY:
 // CHECK-NEXT: Supported Profiles
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 517702fab5b919..5bb6c10f85f1a7 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -37,6 +37,7 @@
 // CHECK-NOT: __riscv_sscofpmf {{.*$}}
 // CHECK-NOT: __riscv_sscounterenw {{.*$}}
 // CHECK-NOT: __riscv_sscsrind {{.*$}}
+// CHECK-NOT: __riscv_ssqosid{{.*$}}
 // CHECK-NOT: __riscv_ssstateen {{.*$}}
 // CHECK-NOT: __riscv_ssstrict {{.*$}}
 // CHECK-NOT: __riscv_sstc {{.*$}}
@@ -179,7 +180,6 @@
 // CHECK-NOT: __riscv_smnpm{{.*$}}
 // CHECK-NOT: __riscv_ssnpm{{.*$}}
 // CHECK-NOT: __riscv_sspm{{.*$}}
-// CHECK-NOT: __riscv_ssqosid{{.*$}}
 // CHECK-NOT: __riscv_supm{{.*$}}
 // CHECK-NOT: __riscv_zacas {{.*$}}
 // CHECK-NOT: __riscv_zalasr {{.*$}}
@@ -1415,6 +1415,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SSCSRIND-EXT %s
 // CHECK-SSCSRIND-EXT: __riscv_sscsrind  100{{$}}
 
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_ssqosid1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSQOSID-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_ssqosid1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSQOSID-EXT %s
+// CHECK-SSQOSID-EXT: __riscv_ssqosid 100{{$}}
+
 // RUN: %clang --target=riscv32 \
 // RUN:   -march=rv32ismcdeleg1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SMCDELEG-EXT %s
@@ -1740,14 +1748,6 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SUPM-EXT %s
 // CHECK-SUPM-EXT: __riscv_supm 100{{$}}
 
-// RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN:   -march=rv32i_ssqosid1p0 -E -dM %s \
-// RUN:   -o - | FileCheck --check-prefix=CHECK-SSQOSID-EXT %s
-// RUN: %clang --target=riscv64 -menable-experimental-extensions \
-// RUN:   -march=rv64i_ssqosid1p0 -E -dM %s \
-// RUN:   -o - | FileCheck --check-prefix=CHECK-SSQOSID-EXT %s
-// CHECK-SSQOSID-EXT: __riscv_ssqosid 100{{$}}
-
 // Misaligned
 
 // RUN: %clang --target=riscv32-unknown-linux-gnu -march=rv32i -E -dM %s \
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 3af1428138c021..4e50f55e4cb60b 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -136,6 +136,7 @@ on support follow.
  ``Sscofpmf``  Assembly Support
  ``Sscounterenw``  Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
  

[clang] [llvm] [RISCV] Remove experimental for Ssqosid ext (PR #105476)

2024-08-21 Thread via cfe-commits

llvmbot wrote:




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

Author: Shao-Ce SUN (sunshaoce)


Changes

Ratified: https://github.com/riscv/riscv-ssqosid/releases/tag/v1.0

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


6 Files Affected:

- (modified) clang/test/Driver/print-supported-extensions-riscv.c (+1-1) 
- (modified) clang/test/Preprocessor/riscv-target-features.c (+9-9) 
- (modified) llvm/docs/RISCVUsage.rst (+1-3) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+3-3) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+4-4) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+1-1) 


``diff
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 132422393170a9..9497d01a832604 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -126,6 +126,7 @@
 // CHECK-NEXT: sscofpmf 1.0   'Sscofpmf' (Count Overflow 
and Mode-Based Filtering)
 // CHECK-NEXT: sscounterenw 1.0   'Sscounterenw' (Support 
writeable scounteren enable bit for any hpmcounter that is not read-only zero)
 // CHECK-NEXT: sscsrind 1.0   'Sscsrind' (Indirect CSR 
Access Supervisor Level)
+// CHECK-NEXT: ssqosid  1.0   'Ssqosid' 
(Quality-of-Service (QoS) Identifiers)
 // CHECK-NEXT: ssstateen1.0   'Ssstateen' (Supervisor-mode 
view of the state-enable extension)
 // CHECK-NEXT: ssstrict 1.0   'Ssstrict' (No 
non-conforming extensions are present)
 // CHECK-NEXT: sstc 1.0   'Sstc' (Supervisor-mode 
timer interrupts)
@@ -178,7 +179,6 @@
 // CHECK-NEXT: smnpm1.0   'Smnpm' (Machine-level 
Pointer Masking for next lower privilege mode)
 // CHECK-NEXT: ssnpm1.0   'Ssnpm' (Supervisor-level 
Pointer Masking for next lower privilege mode)
 // CHECK-NEXT: sspm 1.0   'Sspm' (Indicates 
Supervisor-mode Pointer Masking)
-// CHECK-NEXT: ssqosid  1.0   'Ssqosid' 
(Quality-of-Service (QoS) Identifiers)
 // CHECK-NEXT: supm 1.0   'Supm' (Indicates User-mode 
Pointer Masking)
 // CHECK-EMPTY:
 // CHECK-NEXT: Supported Profiles
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 517702fab5b919..5bb6c10f85f1a7 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -37,6 +37,7 @@
 // CHECK-NOT: __riscv_sscofpmf {{.*$}}
 // CHECK-NOT: __riscv_sscounterenw {{.*$}}
 // CHECK-NOT: __riscv_sscsrind {{.*$}}
+// CHECK-NOT: __riscv_ssqosid{{.*$}}
 // CHECK-NOT: __riscv_ssstateen {{.*$}}
 // CHECK-NOT: __riscv_ssstrict {{.*$}}
 // CHECK-NOT: __riscv_sstc {{.*$}}
@@ -179,7 +180,6 @@
 // CHECK-NOT: __riscv_smnpm{{.*$}}
 // CHECK-NOT: __riscv_ssnpm{{.*$}}
 // CHECK-NOT: __riscv_sspm{{.*$}}
-// CHECK-NOT: __riscv_ssqosid{{.*$}}
 // CHECK-NOT: __riscv_supm{{.*$}}
 // CHECK-NOT: __riscv_zacas {{.*$}}
 // CHECK-NOT: __riscv_zalasr {{.*$}}
@@ -1415,6 +1415,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SSCSRIND-EXT %s
 // CHECK-SSCSRIND-EXT: __riscv_sscsrind  100{{$}}
 
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_ssqosid1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSQOSID-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_ssqosid1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSQOSID-EXT %s
+// CHECK-SSQOSID-EXT: __riscv_ssqosid 100{{$}}
+
 // RUN: %clang --target=riscv32 \
 // RUN:   -march=rv32ismcdeleg1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SMCDELEG-EXT %s
@@ -1740,14 +1748,6 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SUPM-EXT %s
 // CHECK-SUPM-EXT: __riscv_supm 100{{$}}
 
-// RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN:   -march=rv32i_ssqosid1p0 -E -dM %s \
-// RUN:   -o - | FileCheck --check-prefix=CHECK-SSQOSID-EXT %s
-// RUN: %clang --target=riscv64 -menable-experimental-extensions \
-// RUN:   -march=rv64i_ssqosid1p0 -E -dM %s \
-// RUN:   -o - | FileCheck --check-prefix=CHECK-SSQOSID-EXT %s
-// CHECK-SSQOSID-EXT: __riscv_ssqosid 100{{$}}
-
 // Misaligned
 
 // RUN: %clang --target=riscv32-unknown-linux-gnu -march=rv32i -E -dM %s \
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 3af1428138c021..4e50f55e4cb60b 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -136,6 +136,7 @@ on support follow.
  ``Sscofpmf``  Assembly Support
  ``Sscounterenw``  Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Sscsrind``  Supported
+ ``Ssqosid``   Assembly Support
  ``Ssstateen`` Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Ssstrict`` 

[clang] [llvm] [RISCV] Remove experimental for Ssqosid ext (PR #105476)

2024-08-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Shao-Ce SUN (sunshaoce)


Changes

Ratified: https://github.com/riscv/riscv-ssqosid/releases/tag/v1.0

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


6 Files Affected:

- (modified) clang/test/Driver/print-supported-extensions-riscv.c (+1-1) 
- (modified) clang/test/Preprocessor/riscv-target-features.c (+9-9) 
- (modified) llvm/docs/RISCVUsage.rst (+1-3) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+3-3) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+4-4) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+1-1) 


``diff
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 132422393170a9..9497d01a832604 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -126,6 +126,7 @@
 // CHECK-NEXT: sscofpmf 1.0   'Sscofpmf' (Count Overflow 
and Mode-Based Filtering)
 // CHECK-NEXT: sscounterenw 1.0   'Sscounterenw' (Support 
writeable scounteren enable bit for any hpmcounter that is not read-only zero)
 // CHECK-NEXT: sscsrind 1.0   'Sscsrind' (Indirect CSR 
Access Supervisor Level)
+// CHECK-NEXT: ssqosid  1.0   'Ssqosid' 
(Quality-of-Service (QoS) Identifiers)
 // CHECK-NEXT: ssstateen1.0   'Ssstateen' (Supervisor-mode 
view of the state-enable extension)
 // CHECK-NEXT: ssstrict 1.0   'Ssstrict' (No 
non-conforming extensions are present)
 // CHECK-NEXT: sstc 1.0   'Sstc' (Supervisor-mode 
timer interrupts)
@@ -178,7 +179,6 @@
 // CHECK-NEXT: smnpm1.0   'Smnpm' (Machine-level 
Pointer Masking for next lower privilege mode)
 // CHECK-NEXT: ssnpm1.0   'Ssnpm' (Supervisor-level 
Pointer Masking for next lower privilege mode)
 // CHECK-NEXT: sspm 1.0   'Sspm' (Indicates 
Supervisor-mode Pointer Masking)
-// CHECK-NEXT: ssqosid  1.0   'Ssqosid' 
(Quality-of-Service (QoS) Identifiers)
 // CHECK-NEXT: supm 1.0   'Supm' (Indicates User-mode 
Pointer Masking)
 // CHECK-EMPTY:
 // CHECK-NEXT: Supported Profiles
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 517702fab5b919..5bb6c10f85f1a7 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -37,6 +37,7 @@
 // CHECK-NOT: __riscv_sscofpmf {{.*$}}
 // CHECK-NOT: __riscv_sscounterenw {{.*$}}
 // CHECK-NOT: __riscv_sscsrind {{.*$}}
+// CHECK-NOT: __riscv_ssqosid{{.*$}}
 // CHECK-NOT: __riscv_ssstateen {{.*$}}
 // CHECK-NOT: __riscv_ssstrict {{.*$}}
 // CHECK-NOT: __riscv_sstc {{.*$}}
@@ -179,7 +180,6 @@
 // CHECK-NOT: __riscv_smnpm{{.*$}}
 // CHECK-NOT: __riscv_ssnpm{{.*$}}
 // CHECK-NOT: __riscv_sspm{{.*$}}
-// CHECK-NOT: __riscv_ssqosid{{.*$}}
 // CHECK-NOT: __riscv_supm{{.*$}}
 // CHECK-NOT: __riscv_zacas {{.*$}}
 // CHECK-NOT: __riscv_zalasr {{.*$}}
@@ -1415,6 +1415,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SSCSRIND-EXT %s
 // CHECK-SSCSRIND-EXT: __riscv_sscsrind  100{{$}}
 
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_ssqosid1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSQOSID-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_ssqosid1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSQOSID-EXT %s
+// CHECK-SSQOSID-EXT: __riscv_ssqosid 100{{$}}
+
 // RUN: %clang --target=riscv32 \
 // RUN:   -march=rv32ismcdeleg1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SMCDELEG-EXT %s
@@ -1740,14 +1748,6 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SUPM-EXT %s
 // CHECK-SUPM-EXT: __riscv_supm 100{{$}}
 
-// RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN:   -march=rv32i_ssqosid1p0 -E -dM %s \
-// RUN:   -o - | FileCheck --check-prefix=CHECK-SSQOSID-EXT %s
-// RUN: %clang --target=riscv64 -menable-experimental-extensions \
-// RUN:   -march=rv64i_ssqosid1p0 -E -dM %s \
-// RUN:   -o - | FileCheck --check-prefix=CHECK-SSQOSID-EXT %s
-// CHECK-SSQOSID-EXT: __riscv_ssqosid 100{{$}}
-
 // Misaligned
 
 // RUN: %clang --target=riscv32-unknown-linux-gnu -march=rv32i -E -dM %s \
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 3af1428138c021..4e50f55e4cb60b 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -136,6 +136,7 @@ on support follow.
  ``Sscofpmf``  Assembly Support
  ``Sscounterenw``  Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Sscsrind``  Supported
+ ``Ssqosid``   Assembly Support
  ``Ssstateen`` Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Ssstrict``  Assembly

RE: cfe-commits Digest, Vol 206, Issue 1693

2024-08-21 Thread via cfe-commits
Questioned   1 of 10
FRM:cfe-commits-bounces@lists.llvm.org
SU & 

  -Original Message-
  From: 
  Sent: Wed, 21 Aug 2024 00:14:58 -0700
  To: 7578703...@txt.att.net
 Subject: =?utf-8?q?cfe-commits_Digest=2C_Vol_206=2C_Issue_1693?=

>Send cfe-commits mailing list submissions to
>   cfe-commits@lists.llvm.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>   https://lists.llvm.org/cgi-bin/mailman/listin


==
This mobile text message is brought to you by AT&T
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [X86][AVX10.2] Support AVX10.2-CONVERT new instructions. (PR #101600)

2024-08-21 Thread Freddy Ye via cfe-commits

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


[clang] 9fa2386 - [RISCV] Add Hazard3 Core as taped out for RP2350 (#102452)

2024-08-21 Thread via cfe-commits

Author: Sam Elliott
Date: 2024-08-21T08:45:45+01:00
New Revision: 9fa2386ff13289d46ebf31656f4be7859f501468

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

LOG: [RISCV] Add Hazard3 Core as taped out for RP2350 (#102452)

Luke Wren's Hazard3 is a configurable, open-source 32-bit RISC-V core.
The core's source code and docs are available on github:
https://github.com/wren6991/hazard3

This is the RISC-V core used in the RP2350, a recently announced SoC by
Raspberry Pi (which also contains Arm cores):
https://datasheets.raspberrypi.com/rp2350/rp2350-datasheet.pdf

We have agreed to name this `-mcpu` option `rp2350-hazard3`, and it
reflects exactly the options configured in the RP2350 chips. Notably,
the Zbc is not configured, and nor is B because the `misa.B` bit is not
either.

Added: 


Modified: 
clang/test/Driver/riscv-cpus.c
clang/test/Misc/target-invalid-cpu-note/riscv.c
llvm/docs/ReleaseNotes.rst
llvm/lib/Target/RISCV/RISCVProcessors.td

Removed: 




diff  --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index 2fa5b1753745f8..481eaae9153e86 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -402,6 +402,21 @@
 // MCPU-SIFIVE-P670-SAME: "-target-feature" "+zvkt"
 // MCPU-SIFIVE-P670-SAME: "-target-abi" "lp64d"
 
+// RUN: %clang -target riscv32 -### -c %s 2>&1 -mcpu=rp2350-hazard3 | 
FileCheck -check-prefix=MCPU-HAZARD3 %s
+// MCPU-HAZARD3: "-target-cpu" "rp2350-hazard3"
+// MCPU-HAZARD3-SAME: "-target-feature" "+m"
+// MCPU-HAZARD3-SAME: "-target-feature" "+a"
+// MCPU-HAZARD3-SAME: "-target-feature" "+c"
+// MCPU-HAZARD3-SAME: "-target-feature" "+zicsr"
+// MCPU-HAZARD3-SAME: "-target-feature" "+zifencei"
+// MCPU-HAZARD3-SAME: "-target-feature" "+zcb"
+// MCPU-HAZARD3-SAME: "-target-feature" "+zcmp"
+// MCPU-HAZARD3-SAME: "-target-feature" "+zba"
+// MCPU-HAZARD3-SAME: "-target-feature" "+zbb"
+// MCPU-HAZARD3-SAME: "-target-feature" "+zbkb"
+// MCPU-HAZARD3-SAME: "-target-feature" "+zbs"
+// MCPU-HAZARD3-SAME: "-target-abi" "ilp32"
+
 // Check failed cases
 
 // RUN: not %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv321 | 
FileCheck -check-prefix=FAIL-MCPU-NAME %s

diff  --git a/clang/test/Misc/target-invalid-cpu-note/riscv.c 
b/clang/test/Misc/target-invalid-cpu-note/riscv.c
index 0a49755de7d25f..96d3cefd434d78 100644
--- a/clang/test/Misc/target-invalid-cpu-note/riscv.c
+++ b/clang/test/Misc/target-invalid-cpu-note/riscv.c
@@ -7,6 +7,7 @@
 // RISCV32-NEXT: note: valid target CPU values are:
 // RISCV32-SAME: {{^}} generic-rv32
 // RISCV32-SAME: {{^}}, rocket-rv32
+// RISCV32-SAME: {{^}}, rp2350-hazard3
 // RISCV32-SAME: {{^}}, sifive-e20
 // RISCV32-SAME: {{^}}, sifive-e21
 // RISCV32-SAME: {{^}}, sifive-e24
@@ -48,6 +49,7 @@
 // TUNE-RISCV32-NEXT: note: valid target CPU values are:
 // TUNE-RISCV32-SAME: {{^}} generic-rv32
 // TUNE-RISCV32-SAME: {{^}}, rocket-rv32
+// TUNE-RISCV32-SAME: {{^}}, rp2350-hazard3
 // TUNE-RISCV32-SAME: {{^}}, sifive-e20
 // TUNE-RISCV32-SAME: {{^}}, sifive-e21
 // TUNE-RISCV32-SAME: {{^}}, sifive-e24

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 005c59e00fb128..65fa21e517940b 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -108,6 +108,8 @@ Changes to the RISC-V Backend
   fill value) rather than NOPs.
 * Added Syntacore SCR4 and SCR5 CPUs: ``-mcpu=syntacore-scr4/5-rv32/64``
 * ``-mcpu=sifive-p470`` was added.
+* Added Hazard3 CPU as taped out for RP2350: ``-mcpu=rp2350-hazard3`` (32-bit
+  only).
 * Fixed length vector support using RVV instructions now requires VLEN>=64. 
This
   means Zve32x and Zve32f will also require Zvl64b. The prior support was
   largely untested.

diff  --git a/llvm/lib/Target/RISCV/RISCVProcessors.td 
b/llvm/lib/Target/RISCV/RISCVProcessors.td
index 640fe9670d542b..d4ec5ecc6489c1 100644
--- a/llvm/lib/Target/RISCV/RISCVProcessors.td
+++ b/llvm/lib/Target/RISCV/RISCVProcessors.td
@@ -454,3 +454,19 @@ def SPACEMIT_X60 : RISCVProcessorModel<"spacemit-x60",
 FeatureStdExtZvkt,
 FeatureStdExtZvl256b]),
[TuneDLenFactor2]>;
+
+def RP2350_HAZARD3 : RISCVProcessorModel<"rp2350-hazard3",
+ NoSchedModel,
+ [Feature32Bit,
+  FeatureStdExtI,
+  FeatureStdExtM,
+  FeatureStdExtA,
+  FeatureStdExtC,
+  FeatureStdExtZicsr,
+  FeatureStdExtZifencei,
+ 

[clang] [llvm] [RISCV] Add Hazard3 Core as taped out for RP2350 (PR #102452)

2024-08-21 Thread Sam Elliott via cfe-commits

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


[clang] [llvm] [RISCV] Remove experimental for Ssqosid ext (PR #105476)

2024-08-21 Thread Yingwei Zheng via cfe-commits

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

LGTM.

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


[clang] [clang][ASTImporter] New fix for default template parameter values. (PR #101836)

2024-08-21 Thread Balázs Kéri via cfe-commits


@@ -5968,11 +5962,21 @@ 
ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
   }
 
   if (D->hasDefaultArgument()) {
+// Default argument can be "inherited" when it has a reference to the
+// previous declaration (of the default argument) which is stored only 
once.
+// Here we import the default argument in any case, and the inherited state
+// is updated later after the parent template was created. If the
+// inherited-from object would be imported here it causes more difficulties
+// (parent template may not be created yet and import loops can occur).
 Expected ToDefaultArgOrErr =
 import(D->getDefaultArgument());
 if (!ToDefaultArgOrErr)
   return ToDefaultArgOrErr.takeError();
-ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);
+// The just called import process can trigger import of the parent template
+// which can update the default argument value to "inherited". This should
+// not be changed.
+if (!ToD->hasDefaultArgument())
+  ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);

balazske wrote:

The case when default argument becomes already set happens when it is changed 
in function `updateTemplateParametersInheritedFrom` that is called when the 
template is imported. This change can happen during the import of the default 
argument object. That function calls the `setInheritedFrom` function. I was 
experimenting with your idea to just call `getInheritedFrom` and import the 
result and set it (and not use `updateTemplateParametersInheritedFrom`), but I 
got another crash. I tried to explain this in the added comment.

The "deferring" is done in the current code from 
`updateTemplateParametersInheritedFrom` that is called at end of the template 
import. I wanted to ensure that a default value is always set in the template 
parameter object, because until `updateTemplateParametersInheritedFrom` is 
called some other import may happen that uses this value. I think this can 
cause ODR detection problem. If the default argument is not set (but will be 
set later from `updateTemplateParametersInheritedFrom`) this causes a gap where 
the default argument is missing. If during this time something is compared to 
this object it can cause false structural in-equivalence. To avoid this the 
default argument is imported and set immediately (even if this object is later 
discarded). Structural equivalence comparison does not compare if the argument 
is "inherited" or not, but it does compare the argument value. 

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


[clang] [PS5][Driver] Link main components with -pie by default (PR #102901)

2024-08-21 Thread Edd Dawson via cfe-commits

https://github.com/playstation-edd updated 
https://github.com/llvm/llvm-project/pull/102901

>From 0ca2239d21cb414ce5e6fb9057d442c18f61a32e Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Mon, 12 Aug 2024 14:11:11 +0100
Subject: [PATCH 1/3] [PS5][Driver] Link main components with -pie by default

The PS5 linker currently forces `-pie` for typical link jobs. Have the
driver pass `pie` under the same conditions. With this change we can
remove our private linker patch and also allow `-no-pie` to have an
effect.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp |  5 -
 clang/test/Driver/ps5-linker.c | 15 +++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 0175b5eb63e657..73f4c4e2fc7a49 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -237,7 +237,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  if (Args.hasArg(options::OPT_pie))
+  // Default to PIE for non-static main components.
+  const bool PIE =
+  !Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
+  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
 CmdArgs.push_back("-pie");
 
   if (Args.hasArg(options::OPT_static))
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 95d64d9017be04..fb954b938c1ab9 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -1,3 +1,18 @@
+// Test that PIE is the default for main components
+
+// RUN: %clang --target=x86_64-scei-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PIE %s
+
+// CHECK-PIE: {{ld(\.exe)?}}"
+// CHECK-PIE-SAME: "-pie"
+
+// RUN: %clang --target=x86_64-scei-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+
+// CHECK-NO-PIE: {{ld(\.exe)?}}"
+// CHECK-NO-PIE-NOT: "-pie"
+
 // Test that -static is forwarded to the linker
 
 // RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-STATIC %s

>From b7ff265805d8f2c5e7cb22e8c7fd1440665599a8 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 21 Aug 2024 08:48:37 +0100
Subject: [PATCH 2/3] "main components" -> "executables"

---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 73f4c4e2fc7a49..22103eb50803a5 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -237,7 +237,7 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  // Default to PIE for non-static main components.
+  // Default to PIE for non-static executables.
   const bool PIE =
   !Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
   if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))

>From 7280be4660df554541f0c700d943016ba2d2430d Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Wed, 21 Aug 2024 09:00:49 +0100
Subject: [PATCH 3/3] Add check for "--shared", along with lack of "-pie".

---
 clang/test/Driver/ps5-linker.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index fb954b938c1ab9..c462e5a178e4a6 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -7,11 +7,12 @@
 
 // RUN: %clang --target=x86_64-scei-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
 // RUN: %clang --target=x86_64-scei-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
-// RUN: %clang --target=x86_64-scei-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE,CHECK-SHARED %s
 // RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
 
 // CHECK-NO-PIE: {{ld(\.exe)?}}"
 // CHECK-NO-PIE-NOT: "-pie"
+// CHECK-SHARED: "--shared"
 
 // Test that -static is forwarded to the linker
 

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


[clang] [clang] Catch missing format attributes (PR #105479)

2024-08-21 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovichtec created 
https://github.com/llvm/llvm-project/pull/105479

Enable flag -Wmissing-format-attribute to catch missing attributes.

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

From 69f6b14f71222d66bb7785fef51514431e86d1e4 Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 5 Apr 2024 15:20:37 +0200
Subject: [PATCH] [clang] Catch missing format attributes

---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   1 -
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Attr.h   |   7 +
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/Sema/SemaDecl.cpp   |   2 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 216 +-
 clang/test/Sema/attr-format-missing.c | 393 ++
 clang/test/Sema/attr-format-missing.cpp   | 174 
 9 files changed, 800 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c
 create mode 100644 clang/test/Sema/attr-format-missing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6adf57da42e656..f9fd4a20ea6bf6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -707,6 +707,9 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses integer constant expressions that are folded to a 
constant value as an extension in more circumstances. Fixes #GH59863
 
+- Clang now diagnoses missing format attributes for non-template functions and
+  class/struct/union members. Fixes #GH60718
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2241f8481484e2..da6a3b2fe3571b 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -525,7 +525,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def MissingIncludeDirs : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 940f9ac226ca87..75e51c5aa166d2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1031,6 +1031,9 @@ def err_opencl_invalid_param : Error<
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
 def warn_enum_value_overflow : Warning<"overflow in enumeration value">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Attr.h b/clang/include/clang/Sema/Attr.h
index 3f0b10212789a4..37c124ca7b454a 100644
--- a/clang/include/clang/Sema/Attr.h
+++ b/clang/include/clang/Sema/Attr.h
@@ -123,6 +123,13 @@ inline bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+inline bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 /// Diagnose mutually exclusive attributes when present on a given
 /// declaration. Returns true if diagnosed.
 template 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 57994f4033922c..9022ac86edf817 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4602,6 +4602,10 @@ class Sema final : public SemaBase {
 
   enum class RetainOwnershipKind { NS, CF, OS };
 
+  void DiagnoseMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl);
+  std::vector
+  GetMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 66eeaa8e6f..29c28d4b567513 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15925,6 +15925,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 }
   }
 
+  DiagnoseMissingFormatAttributes(Body, FD);
+
   // We might not have found a prototype because we didn't wish to warn on
   // the lack of a missing prototype. Try again w

[clang] [clang] Catch missing format attributes (PR #105479)

2024-08-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Budimir Aranđelović (budimirarandjelovichtec)


Changes

Enable flag -Wmissing-format-attribute to catch missing attributes.

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

---

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


9 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (-1) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+3) 
- (modified) clang/include/clang/Sema/Attr.h (+7) 
- (modified) clang/include/clang/Sema/Sema.h (+4) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+2) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+214-2) 
- (added) clang/test/Sema/attr-format-missing.c (+393) 
- (added) clang/test/Sema/attr-format-missing.cpp (+174) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6adf57da42e656..f9fd4a20ea6bf6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -707,6 +707,9 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses integer constant expressions that are folded to a 
constant value as an extension in more circumstances. Fixes #GH59863
 
+- Clang now diagnoses missing format attributes for non-template functions and
+  class/struct/union members. Fixes #GH60718
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2241f8481484e2..da6a3b2fe3571b 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -525,7 +525,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def MissingIncludeDirs : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 940f9ac226ca87..75e51c5aa166d2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1031,6 +1031,9 @@ def err_opencl_invalid_param : Error<
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
 def warn_enum_value_overflow : Warning<"overflow in enumeration value">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Attr.h b/clang/include/clang/Sema/Attr.h
index 3f0b10212789a4..37c124ca7b454a 100644
--- a/clang/include/clang/Sema/Attr.h
+++ b/clang/include/clang/Sema/Attr.h
@@ -123,6 +123,13 @@ inline bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+inline bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 /// Diagnose mutually exclusive attributes when present on a given
 /// declaration. Returns true if diagnosed.
 template 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 57994f4033922c..9022ac86edf817 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4602,6 +4602,10 @@ class Sema final : public SemaBase {
 
   enum class RetainOwnershipKind { NS, CF, OS };
 
+  void DiagnoseMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl);
+  std::vector
+  GetMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 66eeaa8e6f..29c28d4b567513 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15925,6 +15925,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 }
   }
 
+  DiagnoseMissingFormatAttributes(Body, FD);
+
   // We might not have found a prototype because we didn't wish to warn on
   // the lack of a missing prototype. Try again without the checks for
   // whether we want to warn on the missing prototype.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index f2cd46d1e7c932..4634dd8b9cce80 100644
--- a/clang/lib/Sema/SemaDe

[clang] [clang] Catch missing format attributes (PR #70024)

2024-08-21 Thread Budimir Aranđelović via cfe-commits

budimirarandjelovichtec wrote:

@AaronBallman @aaronpuchert @vitalybuka @Endilll

Last found issues are addressed and new PR is created: 
https://github.com/llvm/llvm-project/pull/105479

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


[clang] 9d739e5 - [Clang] Implement CWG2351 `void{}` (#78060)

2024-08-21 Thread via cfe-commits

Author: Mital Ashok
Date: 2024-08-21T10:09:08+02:00
New Revision: 9d739e54f4506bf9bd220c5d65f710b86a39f6d5

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

LOG: [Clang] Implement CWG2351 `void{}` (#78060)

Per [CWG2351](https://wg21.link/CWG2351), allow `void{}`, treated the
same as `void()`: a prvalue expression of type `void` that performs no
initialization.

Note that the AST for the expression `T{}` looks like:

```
// using T = int;
CXXFunctionalCastExpr 'T':'int' functional cast to T 
`-InitListExpr 'T':'int'
// using T = const int;
CXXFunctionalCastExpr 'int' functional cast to T 
`-InitListExpr 'int'
// using T = void;
CXXFunctionalCastExpr 'T':'void' functional cast to T 
`-InitListExpr 'void'
// using T = const void;
CXXFunctionalCastExpr 'void' functional cast to T 
`-InitListExpr 'void'
```

As for `void()`/`T() [T = const void]`, that looked like
`CXXScalarValueInitExpr 'void'` and is unchanged after this.

For reference, C++98 [5.2.3p2] says:

> The expression `T()`, where `T` is a simple-type-specifier (7.1.5.2)
for a non-array complete object type or the (possibly cv-qualified) void
type, creates an rvalue of the specified type, whose value is determined
by default-initialization (8.5; no initialization is done for the
`void()` case). [*Note:* if `T` is a non-class type that is
*cv-qualified*, the `cv-qualifiers` are ignored when determining the
type of the resulting rvalue (3.10). ]

Though it is a bit of a misnomer that, for `T = void`,
`CXXScalarValueInitExpr` does not perform value initialization, it would
be a breaking change to change the AST node for `void()`, so I simply
reworded the doc comment.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprCXX.h
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaInit.cpp
clang/test/CXX/drs/cwg23xx.cpp
clang/test/SemaCXX/attr-annotate.cpp
clang/test/SemaCXX/cxx2a-explicit-bool.cpp
clang/test/SemaCXX/sugared-auto.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1df3f0e7e75ca3..127b9541d5c5d8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -152,6 +152,9 @@ Resolutions to C++ Defect Reports
 - ``nullptr`` is now promoted to ``void*`` when passed to a C-style variadic 
function.
   (`CWG722: Can nullptr be passed to an ellipsis? 
`_)
 
+- Allow ``void{}`` as a prvalue of type ``void``.
+  (`CWG2351: void{} `_).
+
 C Language Changes
 --
 

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 847a6ea408e98e..975bcdac5069b9 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2176,8 +2176,9 @@ class LambdaExpr final : public Expr,
   const_child_range children() const;
 };
 
-/// An expression "T()" which creates a value-initialized rvalue of type
-/// T, which is a non-class type.  See (C++98 [5.2.3p2]).
+/// An expression "T()" which creates an rvalue of a non-class type T.
+/// For non-void T, the rvalue is value-initialized.
+/// See (C++98 [5.2.3p2]).
 class CXXScalarValueInitExpr : public Expr {
   friend class ASTStmtReader;
 

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5356bcf172f752..746c67ff1e979f 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1646,12 +1646,23 @@ Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo,
 return ExprError(Diag(TyBeginLoc, diag::err_init_for_function_type)
<< Ty << FullRange);
 
-  // C++17 [expr.type.conv]p2:
-  //   If the type is cv void and the initializer is (), the expression is a
-  //   prvalue of the specified type that performs no initialization.
-  if (!Ty->isVoidType() &&
-  RequireCompleteType(TyBeginLoc, ElemTy,
-  diag::err_invalid_incomplete_type_use, FullRange))
+  // C++17 [expr.type.conv]p2, per DR2351:
+  //   If the type is cv void and the initializer is () or {}, the expression 
is
+  //   a prvalue of the specified type that performs no initialization.
+  if (Ty->isVoidType()) {
+if (Exprs.empty())
+  return new (Context) CXXScalarValueInitExpr(
+  Ty.getUnqualifiedType(), TInfo, Kind.getRange().getEnd());
+if (ListInitialization &&
+cast(Exprs[0])->getNumInits() == 0) {
+  return CXXFunctionalCastExpr::Create(
+  Context, Ty.getUnqualifiedType(), VK_PRValue, TInfo, CK_ToVoid,
+  Exprs[0], /*Path=*/nullptr, CurFPFeatureOverrides(),
+  Exprs[0]->getBeginLoc(), Exprs[0]->getEndLoc());
+}
+  } else if (RequireCompleteType

[clang] [Clang] Implement CWG2351 `void{}` (PR #78060)

2024-08-21 Thread via cfe-commits

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


[clang] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)

2024-08-21 Thread via cfe-commits


@@ -0,0 +1,8 @@
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \

yingopq wrote:

OK,Thanks!

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


[clang] [clang][ASTImporter] New fix for default template parameter values. (PR #101836)

2024-08-21 Thread Balázs Kéri via cfe-commits


@@ -5968,11 +5962,21 @@ 
ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
   }
 
   if (D->hasDefaultArgument()) {
+// Default argument can be "inherited" when it has a reference to the
+// previous declaration (of the default argument) which is stored only 
once.
+// Here we import the default argument in any case, and the inherited state
+// is updated later after the parent template was created. If the
+// inherited-from object would be imported here it causes more difficulties
+// (parent template may not be created yet and import loops can occur).
 Expected ToDefaultArgOrErr =
 import(D->getDefaultArgument());
 if (!ToDefaultArgOrErr)
   return ToDefaultArgOrErr.takeError();
-ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);
+// The just called import process can trigger import of the parent template
+// which can update the default argument value to "inherited". This should
+// not be changed.
+if (!ToD->hasDefaultArgument())
+  ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);

balazske wrote:

I try to explain the source location problem with this code:
```
template  class X;
template  class X {};
```
At the second `X` (definition) `P` has inherited default argument.
The import may reverse the order (this reversal looks hard to fix):
```
template  class X {};
template  class X;
```
The default argument is now at the definition of `X`. I think this is the good 
behavior at import and this is how it currently works. The source location of 
`= Def` becomes inconsistent with the line where it originally was, and this 
can affect the "end" location of `` too.

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


[clang] [Clang] [NFC] Introduce `DynamicRecursiveASTVisitor` (PR #105195)

2024-08-21 Thread via cfe-commits

cor3ntin wrote:

This is a very impressive piece of work!
I think we are looking at a non-trivial choice: 

- Do we make clang faster to compile for ourselves, or slightly faster for 
everyone? My initial thinking is that clang is run orders of magnitude more 
often than it is compile, and so improving compile times might not be the best 
tradeoff? 
It would certainly be nice _for ourselves_.

We should also look at how PGO/BOLT affect both of these options. (Note sure 
how one does that though
https://github.com/llvm/llvm-project/issues/65010).


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


[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)

2024-08-21 Thread via cfe-commits


@@ -5346,7 +5346,6 @@ static EvalStmtResult EvaluateStmt(StmtResult &Result, 
EvalInfo &Info,
 const Expr *RetExpr = cast(S)->getRetValue();
 FullExpressionRAII Scope(Info);
 if (RetExpr && RetExpr->isValueDependent()) {
-  EvaluateDependentExpr(RetExpr, Info);

cor3ntin wrote:

Should we do that _sometimes_  (ie when not do it partial ordering)?
But it's unclear to me why EvaluateDependentExpr is needed to begin with

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


[clang] [clang-format] Don't insert a space between :: and * (PR #105043)

2024-08-21 Thread via cfe-commits

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


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


[clang] 126b56a - [RISCV] Make EmitRISCVCpuSupports accept multiple features (#104917)

2024-08-21 Thread via cfe-commits

Author: Piyou Chen
Date: 2024-08-21T16:46:59+08:00
New Revision: 126b56a234486a2cd05a8beca78bcf89fe47d167

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

LOG: [RISCV] Make EmitRISCVCpuSupports accept multiple features (#104917)

This patch creates an additional EmitRISCVCpuSupports function to handle
situations with multiple features. It also modifies the original
EmitRISCVCpuSupports function to invoke the new one.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/CodeGen/builtin-cpu-supports.c
llvm/include/llvm/TargetParser/RISCVISAInfo.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3e787cad6e82fa..3d77b118235ca0 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -14439,33 +14439,59 @@ Value *CodeGenFunction::EmitRISCVCpuSupports(const 
CallExpr *E) {
   if (!getContext().getTargetInfo().validateCpuSupports(FeatureStr))
 return Builder.getFalse();
 
-  // Note: We are making an unchecked assumption that the size of the
-  // feature array is >= 1.  This holds for any version of compiler-rt
-  // which defines this interface.
-  llvm::ArrayType *ArrayOfInt64Ty = llvm::ArrayType::get(Int64Ty, 1);
+  return EmitRISCVCpuSupports(ArrayRef(FeatureStr));
+}
+
+static Value *loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder,
+   CodeGenModule &CGM) {
+  llvm::Type *Int32Ty = Builder.getInt32Ty();
+  llvm::Type *Int64Ty = Builder.getInt64Ty();
+  llvm::ArrayType *ArrayOfInt64Ty =
+  llvm::ArrayType::get(Int64Ty, llvm::RISCVISAInfo::FeatureBitSize);
   llvm::Type *StructTy = llvm::StructType::get(Int32Ty, ArrayOfInt64Ty);
   llvm::Constant *RISCVFeaturesBits =
   CGM.CreateRuntimeVariable(StructTy, "__riscv_feature_bits");
-  auto *GV = cast(RISCVFeaturesBits);
-  GV->setDSOLocal(true);
-
-  auto LoadFeatureBit = [&](unsigned Index) {
-// Create GEP then load.
-Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index);
-llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1),
- IndexVal};
-Value *Ptr =
-Builder.CreateInBoundsGEP(StructTy, RISCVFeaturesBits, GEPIndices);
-Value *FeaturesBit =
-Builder.CreateAlignedLoad(Int64Ty, Ptr, CharUnits::fromQuantity(8));
-return FeaturesBit;
-  };
+  cast(RISCVFeaturesBits)->setDSOLocal(true);
+  Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index);
+  llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1),
+   IndexVal};
+  Value *Ptr =
+  Builder.CreateInBoundsGEP(StructTy, RISCVFeaturesBits, GEPIndices);
+  Value *FeaturesBit =
+  Builder.CreateAlignedLoad(Int64Ty, Ptr, CharUnits::fromQuantity(8));
+  return FeaturesBit;
+}
+
+Value *CodeGenFunction::EmitRISCVCpuSupports(ArrayRef FeaturesStrs) 
{
+  const unsigned RISCVFeatureLength = llvm::RISCVISAInfo::FeatureBitSize;
+  uint64_t RequireBitMasks[RISCVFeatureLength] = {0};
+
+  for (auto Feat : FeaturesStrs) {
+auto [GroupID, BitPos] = RISCVISAInfo::getRISCVFeaturesBitsInfo(Feat);
+
+// If there isn't BitPos for this feature, skip this version.
+// It also report the warning to user during compilation.
+if (BitPos == -1)
+  return Builder.getFalse();
 
-  auto [GroupID, BitPos] = RISCVISAInfo::getRISCVFeaturesBitsInfo(FeatureStr);
-  assert(BitPos != -1 && "validation should have rejected this feature");
-  Value *MaskV = Builder.getInt64(1ULL << BitPos);
-  Value *Bitset = Builder.CreateAnd(LoadFeatureBit(GroupID), MaskV);
-  return Builder.CreateICmpEQ(Bitset, MaskV);
+RequireBitMasks[GroupID] |= (1ULL << BitPos);
+  }
+
+  Value *Result = nullptr;
+  for (unsigned Idx = 0; Idx < RISCVFeatureLength; Idx++) {
+if (RequireBitMasks[Idx] == 0)
+  continue;
+
+Value *Mask = Builder.getInt64(RequireBitMasks[Idx]);
+Value *Bitset =
+Builder.CreateAnd(loadRISCVFeatureBits(Idx, Builder, CGM), Mask);
+Value *CmpV = Builder.CreateICmpEQ(Bitset, Mask);
+Result = (!Result) ? CmpV : Builder.CreateAnd(Result, CmpV);
+  }
+
+  assert(Result && "Should have value here.");
+
+  return Result;
 }
 
 Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,

diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 57e0b7f91e9bf8..e1b9ada3c1e1fd 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4704,6 +4704,7 @@ class CodeGenFunction : public CodeGenTypeCache {
 ReturnValueSlot ReturnValue);
 
   llvm::Value *EmitRISCVCpuSupports(const CallExpr *E);
+  llvm::Value *EmitRISCVCpuSupports(ArrayRe

[clang] [llvm] [RISC-V] Make EmitRISCVCpuSupports accept multiple features (PR #104917)

2024-08-21 Thread Piyou Chen via cfe-commits

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


[clang] [Clang][Concepts] Fix the constraint equivalence checking for TemplateTypeParmTypes (PR #102131)

2024-08-21 Thread via cfe-commits

cor3ntin wrote:

What's the status of that?

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


[clang] [Clang][NFCI] Cleanup the fix for default function argument substitution (PR #104911)

2024-08-21 Thread Younan Zhang via cfe-commits


@@ -285,7 +286,8 @@ Response HandleFunction(Sema &SemaRef, const FunctionDecl 
*Function,
 // If this function was instantiated from a specialized member that is
 // a function template, we're done.
 assert(Function->getPrimaryTemplate() && "No function template?");
-if (Function->getPrimaryTemplate()->isMemberSpecialization())
+if (!ForDefaultArgumentSubstitution &&
+Function->getPrimaryTemplate()->isMemberSpecialization())

zyn0217 wrote:

Thanks!

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


[clang] 8ac140f - [Clang][NFCI] Cleanup the fix for default function argument substitution (#104911)

2024-08-21 Thread via cfe-commits

Author: Younan Zhang
Date: 2024-08-21T17:01:05+08:00
New Revision: 8ac140f390847e4e85e0a4fd910baaf46e5d115b

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

LOG: [Clang][NFCI] Cleanup the fix for default function argument substitution 
(#104911)

(This is one step towards tweaking `getTemplateInstantiationArgs()` as
discussed in https://github.com/llvm/llvm-project/pull/102922)

We don't always substitute into default arguments while transforming a
function parameter. In that case, we would preserve the uninstantiated
expression until after, e.g. building up a CXXDefaultArgExpr and
instantiate the expression there.

For member function instantiation, this algorithm used to cause a
problem in that the default argument of an out-of-line member function
specialization couldn't get properly instantiated. This is because, in
`getTemplateInstantiationArgs()`, we would give up visiting a function's
declaration context if the function is a specialization of a member
template. For example,

```cpp
template 
struct S {
  template 
  void f(T = sizeof(T));
};

template <> template 
void S::f(int) {}
```

The default argument `sizeof(U)` that lexically appears inside the
declaration would be copied to the function declaration in the class
template specialization `S`, as well as to the function's
out-of-line definition. We use template arguments collected from the
out-of-line function definition when substituting into the default
arguments. We would therefore give up the traversal after the function,
resulting in a single-level template argument of the `f` itself. However
the default argument here could still reference the template parameters
of the primary template, hence the error.

In fact, this is similar to constraint checking in some respects: we
actually want the "whole" template arguments relative to the primary
template, not those relative to the function definition. So this patch
adds another flag to indicate `getTemplateInstantiationArgs()` for that.

This patch also consolidates the tests for default arguments and removes
some unnecessary tests.

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 299a916b9abf8d..1f7e555d1b8717 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13071,12 +13071,19 @@ class Sema final : public SemaBase {
   /// ForConstraintInstantiation indicates we should continue looking when
   /// encountering a lambda generic call operator, and continue looking for
   /// arguments on an enclosing class template.
+  ///
+  /// \param SkipForSpecialization when specified, any template specializations
+  /// in a traversal would be ignored.
+  /// \param ForDefaultArgumentSubstitution indicates we should continue 
looking
+  /// when encountering a specialized member function template, rather than
+  /// returning immediately.
   MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
   const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false,
   std::optional> Innermost = std::nullopt,
   bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
   bool ForConstraintInstantiation = false,
-  bool SkipForSpecialization = false);
+  bool SkipForSpecialization = false,
+  bool ForDefaultArgumentSubstitution = false);
 
   /// RAII object to handle the state changes required to synthesize
   /// a function body.

diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 9a6cd2cd0ab751..fd90f83f3976ca 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -256,7 +256,8 @@ HandleClassTemplateSpec(const 
ClassTemplateSpecializationDecl *ClassTemplSpec,
 Response HandleFunction(Sema &SemaRef, const FunctionDecl *Function,
 MultiLevelTemplateArgumentList &Result,
 const FunctionDecl *Pattern, bool RelativeToPrimary,
-bool ForConstraintInstantiation) {
+bool ForConstraintInstantiation,
+bool ForDefaultArgumentSubstitution) {
   // Add template arguments from a function template specialization.
   if (!RelativeToPrimary &&
   Function->getTemplateSpecializationKindForInstantiation() ==
@@ -286,7 +287,8 @@ Response HandleFunction(Sema &SemaRef, const FunctionDecl 
*Function,
 // If this function was instantiated from a specialized member that is
 // a function template, we're done.
 assert(Function->getPrimaryTemplate() && "No function templa

[clang] [Clang][NFCI] Cleanup the fix for default function argument substitution (PR #104911)

2024-08-21 Thread Younan Zhang via cfe-commits

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


[clang] [Clang] fix generic lambda inside requires-clause of friend function template (PR #99813)

2024-08-21 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/99813

>From 5d7f291e35930e07f52a7ac17a09f93690b64def Mon Sep 17 00:00:00 2001
From: Backl1ght 
Date: Sun, 21 Jul 2024 23:43:24 +0800
Subject: [PATCH 1/2] fix

---
 clang/docs/ReleaseNotes.rst  |  2 ++
 clang/lib/Sema/SemaTemplate.cpp  |  5 +
 clang/test/SemaTemplate/concepts-friends.cpp | 16 
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4f1a916aad9d2b..b4ed5730f5af37 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -158,6 +158,8 @@ Bug Fixes to C++ Support
 
 - Fixed a crash when an expression with a dependent ``__typeof__`` type is 
used as the operand of a unary operator. (#GH97646)
 - Fixed a failed assertion when checking invalid delete operator declaration. 
(#GH96191)
+- Fixed an assertion failure about a constraint of a friend function template 
references to a value with greater
+  template depth than the friend function template. (#GH98258)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 87b1f98bbe5ac9..e8b8bbe6d90547 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1691,10 +1691,7 @@ class ConstraintRefersToContainingTemplateChecker
   using inherited::TransformTemplateTypeParmType;
   QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
  TemplateTypeParmTypeLoc TL, bool) {
-assert(TL.getDecl()->getDepth() <= TemplateDepth &&
-   "Nothing should reference a value below the actual template depth, "
-   "depth is likely wrong");
-if (TL.getDecl()->getDepth() != TemplateDepth)
+if (TL.getDecl()->getDepth() < TemplateDepth)
   Result = true;
 return inherited::TransformTemplateTypeParmType(
 TLB, TL,
diff --git a/clang/test/SemaTemplate/concepts-friends.cpp 
b/clang/test/SemaTemplate/concepts-friends.cpp
index 91b797034ed6cf..9a77aad24f1cdb 100644
--- a/clang/test/SemaTemplate/concepts-friends.cpp
+++ b/clang/test/SemaTemplate/concepts-friends.cpp
@@ -504,3 +504,19 @@ template struct Z;
 Y y(1);
 
 }
+
+namespace GH98258 {
+
+struct S {
+  template 
+  friend void f() requires requires { [](V){}; } {
+return;
+  }
+
+  template 
+  friend void f2() requires requires { [](auto){}; } {
+return;
+  }
+};
+
+}

>From 558168eed0f3176376108534a2e949a8ad96505d Mon Sep 17 00:00:00 2001
From: Backl1ght 
Date: Sat, 27 Jul 2024 13:21:22 +0800
Subject: [PATCH 2/2] fix nttp

---
 clang/lib/Sema/SemaTemplate.cpp  | 5 +
 clang/test/SemaTemplate/concepts-friends.cpp | 5 +
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index e8b8bbe6d90547..cf183fb9b80867 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1664,10 +1664,7 @@ class ConstraintRefersToContainingTemplateChecker
   }
 
   void CheckNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
-assert(D->getDepth() <= TemplateDepth &&
-   "Nothing should reference a value below the actual template depth, "
-   "depth is likely wrong");
-if (D->getDepth() != TemplateDepth)
+if (D->getDepth() < TemplateDepth)
   Result = true;
 
 // Necessary because the type of the NTTP might be what refers to the 
parent
diff --git a/clang/test/SemaTemplate/concepts-friends.cpp 
b/clang/test/SemaTemplate/concepts-friends.cpp
index 9a77aad24f1cdb..14b37d78d951dc 100644
--- a/clang/test/SemaTemplate/concepts-friends.cpp
+++ b/clang/test/SemaTemplate/concepts-friends.cpp
@@ -517,6 +517,11 @@ struct S {
   friend void f2() requires requires { [](auto){}; } {
 return;
   }
+
+  template 
+  friend void f3() requires requires { [](){ return X; }; } {
+return;
+  }
 };
 
 }

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


[clang] [Clang][Concepts] Fix the constraint equivalence checking for TemplateTypeParmTypes (PR #102131)

2024-08-21 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

@mizvekov suggested in 
https://github.com/llvm/llvm-project/issues/101735#issuecomment-2273950029 we 
should try to decouple the constraint checking from the redeclaration chain 
building, however that is somehow involved.

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


[clang] [clang] Diagnose functions with too many parameters (PR #104833)

2024-08-21 Thread via cfe-commits

cor3ntin wrote:

@Endilll  you forgot to update the tests - hence the ci failure

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


[clang] [Clang] [NFC] Introduce `DynamicRecursiveASTVisitor` (PR #105195)

2024-08-21 Thread Younan Zhang via cfe-commits

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


[clang] [Clang] [NFC] Introduce `DynamicRecursiveASTVisitor` (PR #105195)

2024-08-21 Thread Younan Zhang via cfe-commits


@@ -0,0 +1,252 @@
+#ifndef LLVM_CLANG_AST_DYNAMIC_RECURSIVE_AST_VISITOR_H

zyn0217 wrote:

Don't forget the license header :)

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


[clang] [Clang] [NFC] Introduce `DynamicRecursiveASTVisitor` (PR #105195)

2024-08-21 Thread Younan Zhang via cfe-commits


@@ -0,0 +1,252 @@
+#ifndef LLVM_CLANG_AST_DYNAMIC_RECURSIVE_AST_VISITOR_H
+#define LLVM_CLANG_AST_DYNAMIC_RECURSIVE_AST_VISITOR_H
+
+#include "clang/AST/Attr.h"
+#include "clang/AST/ExprConcepts.h"
+#include "clang/AST/TypeLoc.h"
+
+namespace clang {
+class ASTContext;
+
+/// Recursive AST visitor that supports extension via dynamic dispatch.
+///
+/// This only supports some of the more common visitation operations; in
+/// particular, it does not support overriding WalkUpFromX or post-order
+/// traversal.
+///
+/// Features that are currently not supported:
+///
+///   - Visiting attributes
+///   - Post-order traversal
+///   - Overriding WalkUpFromX
+///   - Overriding getStmtChildren()
+///
+/// \see RecursiveASTVisitor
+class DynamicRecursiveASTVisitor {
+public:
+  /// Whether this visitor should recurse into template instantiations.
+  bool ShouldVisitTemplateInstantiations = false;
+
+  /// Whether this visitor should recurse into the types of TypeLocs.
+  bool ShouldWalkTypesOfTypeLocs = true;
+
+  /// Whether this visitor should recurse into implicit code, e.g.
+  /// implicit constructors and destructors.
+  bool ShouldVisitImplicitCode = false;
+
+  /// Whether this visitor should recurse into lambda body
+  bool ShouldVisitLambdaBody = true;
+
+protected:
+  DynamicRecursiveASTVisitor() = default;
+
+public:
+  virtual void anchor();
+
+  // Copying/moving a polymorphic type is a bad idea.
+  DynamicRecursiveASTVisitor(DynamicRecursiveASTVisitor &&) = delete;
+  DynamicRecursiveASTVisitor(const DynamicRecursiveASTVisitor &) = delete;
+  DynamicRecursiveASTVisitor &operator=(DynamicRecursiveASTVisitor &&) = 
delete;
+  DynamicRecursiveASTVisitor &
+  operator=(const DynamicRecursiveASTVisitor &) = delete;

zyn0217 wrote:

Sorry for being dense, but can you explain why this is a bad idea? We allow 
copying/moving an RAV, right? (I might be wrong, because I hardly remember I've 
copied/moved an RAV)

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


[clang] [Clang] [NFC] Introduce `DynamicRecursiveASTVisitor` (PR #105195)

2024-08-21 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 commented:

Thanks!

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


[clang] [RISCV][FMV] Support target_clones (PR #85786)

2024-08-21 Thread Piyou Chen via cfe-commits

https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/85786

>From 395ce72afbf9e4b12fcbfaf9cdbda8921c9ff72a Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Tue, 23 Jul 2024 19:59:06 -0700
Subject: [PATCH 1/2] [RISCV][FMV] Support target_clones

---
 .../clang/Basic/DiagnosticFrontendKinds.td|   4 +
 clang/include/clang/Basic/TargetInfo.h|   3 +-
 clang/include/clang/Sema/SemaRISCV.h  |   1 +
 clang/lib/AST/ASTContext.cpp  |  12 +
 clang/lib/CodeGen/CodeGenFunction.cpp | 106 -
 clang/lib/CodeGen/CodeGenFunction.h   |   3 +
 clang/lib/CodeGen/CodeGenModule.cpp   |   5 +-
 clang/lib/CodeGen/Targets/RISCV.cpp   |  35 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  30 +++
 clang/lib/Sema/SemaRISCV.cpp  |  10 +
 .../attr-target-clones-riscv-invalid.c|   8 +
 clang/test/CodeGen/attr-target-clones-riscv.c | 211 ++
 .../CodeGenCXX/attr-target-clones-riscv.cpp   | 210 +
 .../test/SemaCXX/attr-target-clones-riscv.cpp |  35 +++
 14 files changed, 670 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-target-clones-riscv-invalid.c
 create mode 100644 clang/test/CodeGen/attr-target-clones-riscv.c
 create mode 100644 clang/test/CodeGenCXX/attr-target-clones-riscv.cpp
 create mode 100644 clang/test/SemaCXX/attr-target-clones-riscv.cpp

diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 8a1462c670d68f..0c870a1f3f1442 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -378,4 +378,8 @@ def warn_missing_symbol_graph_dir : Warning<
 def err_ast_action_on_llvm_ir : Error<
   "cannot apply AST actions to LLVM IR file '%0'">,
   DefaultFatal;
+
+def err_os_unsupport_riscv_target_clones : Error<
+  "target_clones is currently only supported on Linux">;
+
 }
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index a58fb5f9792720..f31d88a354ea28 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1496,7 +1496,8 @@ class TargetInfo : public TransferrableTargetInfo,
   /// Identify whether this target supports multiversioning of functions,
   /// which requires support for cpu_supports and cpu_is functionality.
   bool supportsMultiVersioning() const {
-return getTriple().isX86() || getTriple().isAArch64();
+return getTriple().isX86() || getTriple().isAArch64() ||
+   getTriple().isRISCV();
   }
 
   /// Identify whether this target supports IFuncs.
diff --git a/clang/include/clang/Sema/SemaRISCV.h 
b/clang/include/clang/Sema/SemaRISCV.h
index d62fca8128b2a3..d7f17797283b86 100644
--- a/clang/include/clang/Sema/SemaRISCV.h
+++ b/clang/include/clang/Sema/SemaRISCV.h
@@ -43,6 +43,7 @@ class SemaRISCV : public SemaBase {
 
   void handleInterruptAttr(Decl *D, const ParsedAttr &AL);
   bool isAliasValid(unsigned BuiltinID, llvm::StringRef AliasName);
+  bool isValidFMVExtension(StringRef Ext);
 
   /// Indicate RISC-V vector builtin functions enabled or not.
   bool DeclareRVVBuiltins = false;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index b201d201e1ea6a..a4d123219770bb 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14181,6 +14181,18 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   Target->getTargetOpts().FeaturesAsWritten.begin(),
   Target->getTargetOpts().FeaturesAsWritten.end());
   Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, 
Features);
+} else if (Target->getTriple().isRISCV()) {
+  StringRef VersionStr = TC->getFeatureStr(GD.getMultiVersionIndex());
+  std::vector Features;
+  if (VersionStr != "default") {
+ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(VersionStr);
+Features.insert(Features.begin(), ParsedAttr.Features.begin(),
+ParsedAttr.Features.end());
+  }
+  Features.insert(Features.begin(),
+  Target->getTargetOpts().FeaturesAsWritten.begin(),
+  Target->getTargetOpts().FeaturesAsWritten.end());
+  Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, 
Features);
 } else {
   std::vector Features;
   StringRef VersionStr = TC->getFeatureStr(GD.getMultiVersionIndex());
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index eff8c9f5694084..d625dde684933b 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2877,12 +2877,116 @@ void CodeGenFunction::EmitMultiVersionResolver(
   case llvm::Triple::aarch64:
 EmitAArch64MultiVersionResolver(Resolver, Options);
 return;
+  case llvm::Triple::riscv32:
+  case ll

[clang] [PS5][Driver] Link main components with -pie by default (PR #102901)

2024-08-21 Thread Edd Dawson via cfe-commits


@@ -237,7 +237,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  if (Args.hasArg(options::OPT_pie))
+  // Default to PIE for non-static main components.

playstation-edd wrote:

Done!

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


[clang] [PS5][Driver] Link main components with -pie by default (PR #102901)

2024-08-21 Thread Edd Dawson via cfe-commits


@@ -1,3 +1,18 @@
+// Test that PIE is the default for main components
+
+// RUN: %clang --target=x86_64-scei-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PIE %s
+
+// CHECK-PIE: {{ld(\.exe)?}}"
+// CHECK-PIE-SAME: "-pie"
+
+// RUN: %clang --target=x86_64-scei-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s

playstation-edd wrote:

Done!

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


[clang] [libclang/python] Do not rely on `ctypes`' `errcheck` (PR #105490)

2024-08-21 Thread Jannick Kremer via cfe-commits

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

Call conversion functions directly instead of using them for type conversion on 
library function calls via `ctypes`' `errcheck` functionality.

>From 8cf94c6486b47cbe4f9ec82cc7c8a9c4948ed012 Mon Sep 17 00:00:00 2001
From: Jannick Kremer 
Date: Wed, 21 Aug 2024 11:50:05 +0200
Subject: [PATCH] [libclang/python] Do not rely on ctypes' errcheck

Call conversion functions directly instead of using them for
type conversion on library function calls via ctypes' errcheck functionality
---
 clang/bindings/python/clang/cindex.py | 353 --
 1 file changed, 168 insertions(+), 185 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 4da99e899e7f7c..f8a20a1e224724 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -133,7 +133,7 @@ def from_param(cls, param: str | bytes | None) -> 
c_interop_string:
 )
 
 @staticmethod
-def to_python_string(x: c_interop_string, *args: Any) -> str | None:
+def to_python_string(x: c_interop_string) -> str | None:
 return x.value
 
 
@@ -241,9 +241,9 @@ def __del__(self) -> None:
 conf.lib.clang_disposeString(self)
 
 @staticmethod
-def from_result(res: _CXString, fn: Any = None, args: Any = None) -> str:
+def from_result(res: _CXString) -> str:
 assert isinstance(res, _CXString)
-pystr: str | None = conf.lib.clang_getCString(res)
+pystr = 
c_interop_string.to_python_string(conf.lib.clang_getCString(res))
 if pystr is None:
 return ""
 return pystr
@@ -424,7 +424,7 @@ def location(self):
 
 @property
 def spelling(self):
-return conf.lib.clang_getDiagnosticSpelling(self)  # type: ignore 
[no-any-return]
+return 
_CXString.from_result(conf.lib.clang_getDiagnosticSpelling(self))
 
 @property
 def ranges(self) -> NoSliceSequence[SourceRange]:
@@ -453,7 +453,9 @@ def __len__(self) -> int:
 
 def __getitem__(self, key: int) -> FixIt:
 range = SourceRange()
-value = conf.lib.clang_getDiagnosticFixIt(self.diag, key, 
byref(range))
+value = _CXString.from_result(
+conf.lib.clang_getDiagnosticFixIt(self.diag, key, 
byref(range))
+)
 if len(value) == 0:
 raise IndexError
 
@@ -486,12 +488,12 @@ def category_number(self):
 @property
 def category_name(self):
 """The string name of the category for this diagnostic."""
-return conf.lib.clang_getDiagnosticCategoryText(self)  # type: ignore 
[no-any-return]
+return 
_CXString.from_result(conf.lib.clang_getDiagnosticCategoryText(self))
 
 @property
 def option(self):
 """The command-line option that enables this diagnostic."""
-return conf.lib.clang_getDiagnosticOption(self, None)  # type: ignore 
[no-any-return]
+return _CXString.from_result(conf.lib.clang_getDiagnosticOption(self, 
None))
 
 @property
 def disable_option(self):
@@ -511,7 +513,7 @@ def format(self, options=None):
 options = conf.lib.clang_defaultDiagnosticDisplayOptions()
 if options & ~Diagnostic._FormatOptionsMask:
 raise ValueError("Invalid format options")
-return conf.lib.clang_formatDiagnostic(self, options)  # type: ignore 
[no-any-return]
+return _CXString.from_result(conf.lib.clang_formatDiagnostic(self, 
options))
 
 def __repr__(self):
 return "" % (
@@ -1734,7 +1736,7 @@ def get_definition(self):
 """
 # TODO: Should probably check that this is either a reference or
 # declaration prior to issuing the lookup.
-return conf.lib.clang_getCursorDefinition(self)  # type: ignore 
[no-any-return]
+return Cursor.from_result(conf.lib.clang_getCursorDefinition(self), 
self)
 
 def get_usr(self):
 """Return the Unified Symbol Resolution (USR) for the entity referenced
@@ -1745,13 +1747,13 @@ def get_usr(self):
 program. USRs can be compared across translation units to determine,
 e.g., when references in one translation refer to an entity defined in
 another translation unit."""
-return conf.lib.clang_getCursorUSR(self)  # type: ignore 
[no-any-return]
+return _CXString.from_result(conf.lib.clang_getCursorUSR(self))
 
 def get_included_file(self):
 """Returns the File that is included by the current inclusion 
cursor."""
 assert self.kind == CursorKind.INCLUSION_DIRECTIVE
 
-return conf.lib.clang_getIncludedFile(self)  # type: ignore 
[no-any-return]
+return File.from_result(conf.lib.clang_getIncludedFile(self), self)
 
 @property
 def kind(self):
@@ -1762,7 +1764,9 @@ def kind(self):
 def spelling(self):
 """Return the spelling of the 

[clang] [libclang/python] Do not rely on `ctypes`' `errcheck` (PR #105490)

2024-08-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)


Changes

Call conversion functions directly instead of using them for type conversion on 
library function calls via `ctypes`' `errcheck` functionality.

---

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


1 Files Affected:

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


``diff
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 4da99e899e7f7c..f8a20a1e224724 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -133,7 +133,7 @@ def from_param(cls, param: str | bytes | None) -> 
c_interop_string:
 )
 
 @staticmethod
-def to_python_string(x: c_interop_string, *args: Any) -> str | None:
+def to_python_string(x: c_interop_string) -> str | None:
 return x.value
 
 
@@ -241,9 +241,9 @@ def __del__(self) -> None:
 conf.lib.clang_disposeString(self)
 
 @staticmethod
-def from_result(res: _CXString, fn: Any = None, args: Any = None) -> str:
+def from_result(res: _CXString) -> str:
 assert isinstance(res, _CXString)
-pystr: str | None = conf.lib.clang_getCString(res)
+pystr = 
c_interop_string.to_python_string(conf.lib.clang_getCString(res))
 if pystr is None:
 return ""
 return pystr
@@ -424,7 +424,7 @@ def location(self):
 
 @property
 def spelling(self):
-return conf.lib.clang_getDiagnosticSpelling(self)  # type: ignore 
[no-any-return]
+return 
_CXString.from_result(conf.lib.clang_getDiagnosticSpelling(self))
 
 @property
 def ranges(self) -> NoSliceSequence[SourceRange]:
@@ -453,7 +453,9 @@ def __len__(self) -> int:
 
 def __getitem__(self, key: int) -> FixIt:
 range = SourceRange()
-value = conf.lib.clang_getDiagnosticFixIt(self.diag, key, 
byref(range))
+value = _CXString.from_result(
+conf.lib.clang_getDiagnosticFixIt(self.diag, key, 
byref(range))
+)
 if len(value) == 0:
 raise IndexError
 
@@ -486,12 +488,12 @@ def category_number(self):
 @property
 def category_name(self):
 """The string name of the category for this diagnostic."""
-return conf.lib.clang_getDiagnosticCategoryText(self)  # type: ignore 
[no-any-return]
+return 
_CXString.from_result(conf.lib.clang_getDiagnosticCategoryText(self))
 
 @property
 def option(self):
 """The command-line option that enables this diagnostic."""
-return conf.lib.clang_getDiagnosticOption(self, None)  # type: ignore 
[no-any-return]
+return _CXString.from_result(conf.lib.clang_getDiagnosticOption(self, 
None))
 
 @property
 def disable_option(self):
@@ -511,7 +513,7 @@ def format(self, options=None):
 options = conf.lib.clang_defaultDiagnosticDisplayOptions()
 if options & ~Diagnostic._FormatOptionsMask:
 raise ValueError("Invalid format options")
-return conf.lib.clang_formatDiagnostic(self, options)  # type: ignore 
[no-any-return]
+return _CXString.from_result(conf.lib.clang_formatDiagnostic(self, 
options))
 
 def __repr__(self):
 return "" % (
@@ -1734,7 +1736,7 @@ def get_definition(self):
 """
 # TODO: Should probably check that this is either a reference or
 # declaration prior to issuing the lookup.
-return conf.lib.clang_getCursorDefinition(self)  # type: ignore 
[no-any-return]
+return Cursor.from_result(conf.lib.clang_getCursorDefinition(self), 
self)
 
 def get_usr(self):
 """Return the Unified Symbol Resolution (USR) for the entity referenced
@@ -1745,13 +1747,13 @@ def get_usr(self):
 program. USRs can be compared across translation units to determine,
 e.g., when references in one translation refer to an entity defined in
 another translation unit."""
-return conf.lib.clang_getCursorUSR(self)  # type: ignore 
[no-any-return]
+return _CXString.from_result(conf.lib.clang_getCursorUSR(self))
 
 def get_included_file(self):
 """Returns the File that is included by the current inclusion 
cursor."""
 assert self.kind == CursorKind.INCLUSION_DIRECTIVE
 
-return conf.lib.clang_getIncludedFile(self)  # type: ignore 
[no-any-return]
+return File.from_result(conf.lib.clang_getIncludedFile(self), self)
 
 @property
 def kind(self):
@@ -1762,7 +1764,9 @@ def kind(self):
 def spelling(self):
 """Return the spelling of the entity pointed at by the cursor."""
 if not hasattr(self, "_spelling"):
-self._spelling = conf.lib.clang_getCursorSpelling(self)
+self._spelling = _CXString.from_result(
+conf.lib.clang_getC

[clang] 297bb46 - [PS5][Driver] Link main components with -pie by default (#102901)

2024-08-21 Thread via cfe-commits

Author: Edd Dawson
Date: 2024-08-21T10:53:45+01:00
New Revision: 297bb467acd31447d64f0540835127d50408e87d

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

LOG: [PS5][Driver] Link main components with -pie by default (#102901)

The PS5 linker currently forces `-pie` for typical link jobs. Have the
driver pass `pie` under the same conditions. With this change we can
remove our private linker patch and also allow `-no-pie` to have an
effect.

SIE tracker: TOOLCHAIN-16704

Added: 


Modified: 
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/test/Driver/ps5-linker.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 0175b5eb63e65..22103eb50803a 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -237,7 +237,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  if (Args.hasArg(options::OPT_pie))
+  // Default to PIE for non-static executables.
+  const bool PIE =
+  !Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
+  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
 CmdArgs.push_back("-pie");
 
   if (Args.hasArg(options::OPT_static))

diff  --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 95d64d9017be0..c462e5a178e4a 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -1,3 +1,19 @@
+// Test that PIE is the default for main components
+
+// RUN: %clang --target=x86_64-scei-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-PIE %s
+
+// CHECK-PIE: {{ld(\.exe)?}}"
+// CHECK-PIE-SAME: "-pie"
+
+// RUN: %clang --target=x86_64-scei-ps5 -no-pie %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -r %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -shared %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE,CHECK-SHARED %s
+// RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-NO-PIE %s
+
+// CHECK-NO-PIE: {{ld(\.exe)?}}"
+// CHECK-NO-PIE-NOT: "-pie"
+// CHECK-SHARED: "--shared"
+
 // Test that -static is forwarded to the linker
 
 // RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-STATIC %s



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


[clang] [PS5][Driver] Link main components with -pie by default (PR #102901)

2024-08-21 Thread Edd Dawson via cfe-commits

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


[clang] [clang][ASTImporter] set nonnull type for var specialized from lambda template (PR #105492)

2024-08-21 Thread Ding Fei via cfe-commits

https://github.com/danix800 created 
https://github.com/llvm/llvm-project/pull/105492

There's circular deps here when importing btw VarTemplateSpecializationDecl (m) 
and its type.

VarDecl is created with a null type QualType(), and the importing of its type 
will leads to linkage computation (for the templated lambda) which depends on 
the var's type (not yet imported).

This fix uses a non-null type instead of a null one. But this seems still 
cannot ensure the computation is correct.

Fixes #104622 

>From 2ac3aa1b85d727fd15d49fa1649147f2229576cb Mon Sep 17 00:00:00 2001
From: dingfei 
Date: Wed, 21 Aug 2024 17:52:04 +0800
Subject: [PATCH] [clang][ASTImporter] set nonnull type for var specialized
 from lambda template

There's circular deps here when importing btw VarTemplateSpecializationDecl (m)
and its type.

VarDecl is created with a null type QualType(), and the importing of its type
will leads to linkage computation (for the templated lambda) which depends on
the var's type (not yet imported).

This fix uses a non-null type instead of a null one. But this seems
still cannot ensure the computation is correct.
---
 clang/lib/AST/ASTImporter.cpp   |  6 --
 clang/unittests/AST/ASTImporterTest.cpp | 13 +
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 103235547f482e..cc1bd01f15bef6 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6582,6 +6582,8 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
   return std::move(Err);
   }
 
+  QualType ToTmpTy = Importer.getToContext().IntTy;
+  ToTmpTy = ToTmpTy.withCVRQualifiers(D->getType().getCVRQualifiers());
   using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
   // Create a new specialization.
   if (auto *FromPartial = dyn_cast(D)) {
@@ -6592,7 +6594,7 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
 PartVarSpecDecl *ToPartial;
 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
-VarTemplate, QualType(), nullptr,
+VarTemplate, ToTmpTy, nullptr,
 D->getStorageClass(), TemplateArgs))
   return ToPartial;
 
@@ -6613,7 +6615,7 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
   } else { // Full specialization
 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
-QualType(), nullptr, D->getStorageClass(),
+ToTmpTy, nullptr, D->getStorageClass(),
 TemplateArgs))
   return D2;
   }
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 57242ff49fe3b8..06996268d1fb94 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -9919,6 +9919,19 @@ TEST_P(ImportTemplateParmDeclDefaultValue, 
ImportExistingVarTemplate) {
   testImport(FromLastD);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VarTemplatedLambdaInGlobalScope) {
+  Decl *FromTU = getTuDecl(
+  R"(
+namespace { template  auto m = [] {}; }
+void bar() { auto n = m; }
+  )",
+  Lang_CXX14, "input0.cc");
+  FunctionDecl *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("bar")));
+  FunctionDecl *ToF = Import(FromF, Lang_CXX14);
+  EXPECT_TRUE(ToF);
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 

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


[clang] [clang][ASTImporter] set nonnull type for var specialized from lambda template (PR #105492)

2024-08-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ding Fei (danix800)


Changes

There's circular deps here when importing btw VarTemplateSpecializationDecl (m) 
and its type.

VarDecl is created with a null type QualType(), and the importing of its type 
will leads to linkage computation (for the templated lambda) which depends on 
the var's type (not yet imported).

This fix uses a non-null type instead of a null one. But this seems still 
cannot ensure the computation is correct.

Fixes #104622 

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


2 Files Affected:

- (modified) clang/lib/AST/ASTImporter.cpp (+4-2) 
- (modified) clang/unittests/AST/ASTImporterTest.cpp (+13) 


``diff
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 103235547f482e..cc1bd01f15bef6 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6582,6 +6582,8 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
   return std::move(Err);
   }
 
+  QualType ToTmpTy = Importer.getToContext().IntTy;
+  ToTmpTy = ToTmpTy.withCVRQualifiers(D->getType().getCVRQualifiers());
   using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
   // Create a new specialization.
   if (auto *FromPartial = dyn_cast(D)) {
@@ -6592,7 +6594,7 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
 PartVarSpecDecl *ToPartial;
 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
-VarTemplate, QualType(), nullptr,
+VarTemplate, ToTmpTy, nullptr,
 D->getStorageClass(), TemplateArgs))
   return ToPartial;
 
@@ -6613,7 +6615,7 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
   } else { // Full specialization
 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
-QualType(), nullptr, D->getStorageClass(),
+ToTmpTy, nullptr, D->getStorageClass(),
 TemplateArgs))
   return D2;
   }
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 57242ff49fe3b8..06996268d1fb94 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -9919,6 +9919,19 @@ TEST_P(ImportTemplateParmDeclDefaultValue, 
ImportExistingVarTemplate) {
   testImport(FromLastD);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VarTemplatedLambdaInGlobalScope) {
+  Decl *FromTU = getTuDecl(
+  R"(
+namespace { template  auto m = [] {}; }
+void bar() { auto n = m; }
+  )",
+  Lang_CXX14, "input0.cc");
+  FunctionDecl *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("bar")));
+  FunctionDecl *ToF = Import(FromF, Lang_CXX14);
+  EXPECT_TRUE(ToF);
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 

``




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


[clang] [libclang/python] Do not rely on `ctypes`' `errcheck` (PR #105490)

2024-08-21 Thread Jannick Kremer via cfe-commits

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


[clang] [libclang/python] Do not rely on `ctypes`' `errcheck` (PR #105490)

2024-08-21 Thread Jannick Kremer via cfe-commits

https://github.com/DeinAlptraum commented:

@Endilll this removes the `errcheck` magic conversion stuff that we discussed 
the other day

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


[clang] [libclang/python] Do not rely on `ctypes`' `errcheck` (PR #105490)

2024-08-21 Thread Jannick Kremer via cfe-commits


@@ -424,7 +424,7 @@ def location(self):
 
 @property
 def spelling(self):
-return conf.lib.clang_getDiagnosticSpelling(self)  # type: ignore 
[no-any-return]
+return 
_CXString.from_result(conf.lib.clang_getDiagnosticSpelling(self))

DeinAlptraum wrote:

This allows us to remove 30 out of the 98 existing `type: ignore 
[no-any-return]` statements

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


[clang] [libclang/python] Do not rely on `ctypes`' `errcheck` (PR #105490)

2024-08-21 Thread Jannick Kremer via cfe-commits


@@ -3743,82 +3765,62 @@ def write_main_file_to_stdout(self):
 ("clang_equalLocations", [SourceLocation, SourceLocation], bool),
 ("clang_equalRanges", [SourceRange, SourceRange], bool),
 ("clang_equalTypes", [Type, Type], bool),
-("clang_formatDiagnostic", [Diagnostic, c_uint], _CXString, 
_CXString.from_result),
-("clang_getArgType", [Type, c_uint], Type, Type.from_result),
-("clang_getArrayElementType", [Type], Type, Type.from_result),
+("clang_formatDiagnostic", [Diagnostic, c_uint], _CXString),
+("clang_getArgType", [Type, c_uint], Type),
+("clang_getArrayElementType", [Type], Type),
 ("clang_getArraySize", [Type], c_longlong),
 ("clang_getFieldDeclBitWidth", [Cursor], c_int),
-("clang_getCanonicalCursor", [Cursor], Cursor, Cursor.from_cursor_result),
-("clang_getCanonicalType", [Type], Type, Type.from_result),
+("clang_getCanonicalCursor", [Cursor], Cursor),
+("clang_getCanonicalType", [Type], Type),
 ("clang_getChildDiagnostics", [Diagnostic], c_object_p),
 ("clang_getCompletionAvailability", [c_void_p], c_int),
-("clang_getCompletionBriefComment", [c_void_p], _CXString, 
_CXString.from_result),
+("clang_getCompletionBriefComment", [c_void_p], _CXString),
 ("clang_getCompletionChunkCompletionString", [c_void_p, c_int], 
c_object_p),
 ("clang_getCompletionChunkKind", [c_void_p, c_int], c_int),
-(
-"clang_getCompletionChunkText",
-[c_void_p, c_int],
-_CXString,
-_CXString.from_result,
-),
+("clang_getCompletionChunkText", [c_void_p, c_int], _CXString),
 ("clang_getCompletionPriority", [c_void_p], c_int),
-(
-"clang_getCString",
-[_CXString],
-c_interop_string,
-c_interop_string.to_python_string,
-),
+("clang_getCString", [_CXString], c_interop_string),
 ("clang_getCursor", [TranslationUnit, SourceLocation], Cursor),
 ("clang_getCursorAvailability", [Cursor], c_int),
-("clang_getCursorDefinition", [Cursor], Cursor, Cursor.from_result),
-("clang_getCursorDisplayName", [Cursor], _CXString, _CXString.from_result),
+("clang_getCursorDefinition", [Cursor], Cursor),
+("clang_getCursorDisplayName", [Cursor], _CXString),
 ("clang_getCursorExtent", [Cursor], SourceRange),
-("clang_getCursorLexicalParent", [Cursor], Cursor, 
Cursor.from_cursor_result),
+("clang_getCursorLexicalParent", [Cursor], Cursor),
 ("clang_getCursorLocation", [Cursor], SourceLocation),
-("clang_getCursorReferenced", [Cursor], Cursor, Cursor.from_result),
+("clang_getCursorReferenced", [Cursor], Cursor),
 ("clang_getCursorReferenceNameRange", [Cursor, c_uint, c_uint], 
SourceRange),
-("clang_getCursorResultType", [Cursor], Type, Type.from_result),
-("clang_getCursorSemanticParent", [Cursor], Cursor, 
Cursor.from_cursor_result),
-("clang_getCursorSpelling", [Cursor], _CXString, _CXString.from_result),
-("clang_getCursorType", [Cursor], Type, Type.from_result),
-("clang_getCursorUSR", [Cursor], _CXString, _CXString.from_result),
-("clang_Cursor_getMangling", [Cursor], _CXString, _CXString.from_result),
+("clang_getCursorResultType", [Cursor], Type),
+("clang_getCursorSemanticParent", [Cursor], Cursor),
+("clang_getCursorSpelling", [Cursor], _CXString),
+("clang_getCursorType", [Cursor], Type),
+("clang_getCursorUSR", [Cursor], _CXString),
+("clang_Cursor_getMangling", [Cursor], _CXString),
 # ("clang_getCXTUResourceUsage",
 #  [TranslationUnit],
 #  CXTUResourceUsage),
 ("clang_getCXXAccessSpecifier", [Cursor], c_uint),
-("clang_getDeclObjCTypeEncoding", [Cursor], _CXString, 
_CXString.from_result),
+("clang_getDeclObjCTypeEncoding", [Cursor], _CXString),
 ("clang_getDiagnostic", [c_object_p, c_uint], c_object_p),
 ("clang_getDiagnosticCategory", [Diagnostic], c_uint),
-("clang_getDiagnosticCategoryText", [Diagnostic], _CXString, 
_CXString.from_result),
-(
-"clang_getDiagnosticFixIt",
-[Diagnostic, c_uint, POINTER(SourceRange)],
-_CXString,
-_CXString.from_result,
-),
+("clang_getDiagnosticCategoryText", [Diagnostic], _CXString),
+("clang_getDiagnosticFixIt", [Diagnostic, c_uint, POINTER(SourceRange)], 
_CXString),
 ("clang_getDiagnosticInSet", [c_object_p, c_uint], c_object_p),
 ("clang_getDiagnosticLocation", [Diagnostic], SourceLocation),
 ("clang_getDiagnosticNumFixIts", [Diagnostic], c_uint),
 ("clang_getDiagnosticNumRanges", [Diagnostic], c_uint),
-(
-"clang_getDiagnosticOption",
-[Diagnostic, POINTER(_CXString)],
-_CXString,
-_CXString.from_result,
-),
+("clang_getDiagnosticOption", [Diagnostic, POINTER(_CXString)], _CXString),
 ("clang_getDiagnosticRange", [Diagnostic, c_uint], SourceRange),
 ("clang_getDiagnosticSeverity", [Diagnostic], c_int),
-("clang_getDiagnosticSpelling", [Diagnostic], 

[clang] [libclang/python] Do not rely on `ctypes`' `errcheck` (PR #105490)

2024-08-21 Thread Jannick Kremer via cfe-commits


@@ -2454,7 +2480,7 @@ def element_type(self):
 If accessed on a type that is not an array, complex, or vector type, an
 exception will be raised.
 """
-result = conf.lib.clang_getElementType(self)
+result = Type.from_result(conf.lib.clang_getElementType(self), (self,))

DeinAlptraum wrote:

I wonder if we should simplify this further. E.g. instead of passing the result 
of the library function call on `self`, and then `self` separately, should we 
pass just the callable and `self`, and then have the `from_result` function 
call the library function itself?
Would change e.g. the call marked here to 
`Type.from_result(conf.lib.clang_getElementType, self)`

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


[clang] [clang][ASTImporter] set nonnull type for var specialized from lambda template (PR #105492)

2024-08-21 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 08decd20a968ddec459376ef64a4987ef74e15dc 
2ac3aa1b85d727fd15d49fa1649147f2229576cb --extensions cpp -- 
clang/lib/AST/ASTImporter.cpp clang/unittests/AST/ASTImporterTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index cc1bd01f15..ad7cd7eee2 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6613,10 +6613,9 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
 // to adopt template parameters.
 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
   } else { // Full specialization
-if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
-*BeginLocOrErr, *IdLocOrErr, VarTemplate,
-ToTmpTy, nullptr, D->getStorageClass(),
-TemplateArgs))
+if (GetImportedOrCreateDecl(
+D2, D, Importer.getToContext(), DC, *BeginLocOrErr, *IdLocOrErr,
+VarTemplate, ToTmpTy, nullptr, D->getStorageClass(), TemplateArgs))
   return D2;
   }
 

``




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


[clang] [llvm] [InstCombine] Remove some of the complexity-based canonicalization (PR #91185)

2024-08-21 Thread Nikita Popov via cfe-commits

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


[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Balazs Benics via cfe-commits

https://github.com/steakhal created 
https://github.com/llvm/llvm-project/pull/105493

As discussed in
https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570/10

Some `isTainted()` queries can blow up the analysis times, and effectively halt 
the analysis under specific workloads.

We don't really have the time now to do a caching re-implementation of 
`isTainted()`, so we need to workaround the case.

The workaround with the smallest blast radius was to limit what symbols 
`isTainted()` does the query (by walking the SymExpr). So far, the threshold 10 
worked for us, but this value can be overridden using the 
"max-tainted-symbol-complexity" config value.

This new option is "deprecated" from the getgo, as I expect this issue to be 
fixed within the next few months and I don't want users to override this value 
anyways. If they do, this message will let them know that they are on their 
own, and the next release may break them (as we no longer recognize this option 
if we drop it).

>From f9f481a55d174746205f33472e49410b7f57bc5a Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Wed, 21 Aug 2024 11:51:30 +0200
Subject: [PATCH] [analyzer] Limit `isTainted()` by skipping complicated
 symbols

As discussed in
https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570/10

Some `isTainted()` queries can blow up the analysis times, and
effectively halt the analysis under specific workloads.

We don't really have the time now to do a caching re-implementation of
`isTainted()`, so we need to workaround the case.

The workaround with the smallest blast radius was to limit what symbols
`isTainted()` does the query (by walking the SymExpr).
So far, the threshold 10 worked for us, but this value can be overridden
using the "max-tainted-symbol-complexity" config value.

This new option is "deprecated" from the getgo, as I expect this issue
to be fixed within the next few months and I don't want users to
override this value anyways. If they do, this message will let them know
that they are on their own, and the next release may break them (as we
no longer recognize this option if we drop it).
---
 .../StaticAnalyzer/Core/AnalyzerOptions.def   |  5 ++
 clang/lib/StaticAnalyzer/Checkers/Taint.cpp   |  7 +++
 clang/test/Analysis/analyzer-config.c |  1 +
 clang/test/Analysis/taint-generic.c   | 49 ++-
 4 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
index 29aa6a3b8a16e7..98c659192b55d5 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
@@ -407,6 +407,11 @@ ANALYZER_OPTION(
 ANALYZER_OPTION(unsigned, MaxSymbolComplexity, "max-symbol-complexity",
 "The maximum complexity of symbolic constraint.", 35)
 
+// 
HACK:https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570
+// Ideally, we should get rid of this option soon.
+ANALYZER_OPTION(unsigned, MaxTaintedSymbolComplexity, 
"max-tainted-symbol-complexity",
+"[DEPRECATED] The maximum complexity of symbolic to carry 
taint", 10)
+
 ANALYZER_OPTION(unsigned, MaxTimesInlineLarge, "max-times-inline-large",
 "The maximum times a large function could be inlined.", 32)
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/Taint.cpp 
b/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
index 6362c82b009d72..5408db85bbb0bb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/StaticAnalyzer/Checkers/Taint.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 #include 
 
@@ -256,6 +257,12 @@ std::vector 
taint::getTaintedSymbolsImpl(ProgramStateRef State,
   if (!Sym)
 return TaintedSymbols;
 
+  // 
HACK:https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570
+  if (const auto &Opts = State->getAnalysisManager().getAnalyzerOptions();
+  Sym->computeComplexity() >= Opts.MaxTaintedSymbolComplexity) {
+return {};
+  }
+
   // Traverse all the symbols this symbol depends on to see if any are tainted.
   for (SymbolRef SubSym : Sym->symbols()) {
 if (!isa(SubSym))
diff --git a/clang/test/Analysis/analyzer-config.c 
b/clang/test/Analysis/analyzer-config.c
index b8dbcdd7e55afe..13cb50451f2618 100644
--- a/clang/test/Analysis/analyzer-config.c
+++ b/clang/test/Analysis/analyzer-config.c
@@ -94,6 +94,7 @@
 // CHECK-NEXT: max-inlinable-size = 100
 // CHECK-NEXT: max-nodes = 225000
 // CHECK-NEXT: max-symbol-complexity = 35
+// CHECK-NEXT: max-tainted-symbol-complexity = 10
 // CHECK-NEXT: max-times-inline-large = 32
 // CHECK-NEXT: min-cfg-size-tre

[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Balazs Benics (steakhal)


Changes

As discussed in
https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570/10

Some `isTainted()` queries can blow up the analysis times, and effectively halt 
the analysis under specific workloads.

We don't really have the time now to do a caching re-implementation of 
`isTainted()`, so we need to workaround the case.

The workaround with the smallest blast radius was to limit what symbols 
`isTainted()` does the query (by walking the SymExpr). So far, the threshold 10 
worked for us, but this value can be overridden using the 
"max-tainted-symbol-complexity" config value.

This new option is "deprecated" from the getgo, as I expect this issue to be 
fixed within the next few months and I don't want users to override this value 
anyways. If they do, this message will let them know that they are on their 
own, and the next release may break them (as we no longer recognize this option 
if we drop it).

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


4 Files Affected:

- (modified) clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def (+5) 
- (modified) clang/lib/StaticAnalyzer/Checkers/Taint.cpp (+7) 
- (modified) clang/test/Analysis/analyzer-config.c (+1) 
- (modified) clang/test/Analysis/taint-generic.c (+48-1) 


``diff
diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
index 29aa6a3b8a16e7..98c659192b55d5 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
@@ -407,6 +407,11 @@ ANALYZER_OPTION(
 ANALYZER_OPTION(unsigned, MaxSymbolComplexity, "max-symbol-complexity",
 "The maximum complexity of symbolic constraint.", 35)
 
+// 
HACK:https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570
+// Ideally, we should get rid of this option soon.
+ANALYZER_OPTION(unsigned, MaxTaintedSymbolComplexity, 
"max-tainted-symbol-complexity",
+"[DEPRECATED] The maximum complexity of symbolic to carry 
taint", 10)
+
 ANALYZER_OPTION(unsigned, MaxTimesInlineLarge, "max-times-inline-large",
 "The maximum times a large function could be inlined.", 32)
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/Taint.cpp 
b/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
index 6362c82b009d72..5408db85bbb0bb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/StaticAnalyzer/Checkers/Taint.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 #include 
 
@@ -256,6 +257,12 @@ std::vector 
taint::getTaintedSymbolsImpl(ProgramStateRef State,
   if (!Sym)
 return TaintedSymbols;
 
+  // 
HACK:https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570
+  if (const auto &Opts = State->getAnalysisManager().getAnalyzerOptions();
+  Sym->computeComplexity() >= Opts.MaxTaintedSymbolComplexity) {
+return {};
+  }
+
   // Traverse all the symbols this symbol depends on to see if any are tainted.
   for (SymbolRef SubSym : Sym->symbols()) {
 if (!isa(SubSym))
diff --git a/clang/test/Analysis/analyzer-config.c 
b/clang/test/Analysis/analyzer-config.c
index b8dbcdd7e55afe..13cb50451f2618 100644
--- a/clang/test/Analysis/analyzer-config.c
+++ b/clang/test/Analysis/analyzer-config.c
@@ -94,6 +94,7 @@
 // CHECK-NEXT: max-inlinable-size = 100
 // CHECK-NEXT: max-nodes = 225000
 // CHECK-NEXT: max-symbol-complexity = 35
+// CHECK-NEXT: max-tainted-symbol-complexity = 10
 // CHECK-NEXT: max-times-inline-large = 32
 // CHECK-NEXT: min-cfg-size-treat-functions-as-large = 14
 // CHECK-NEXT: mode = deep
diff --git a/clang/test/Analysis/taint-generic.c 
b/clang/test/Analysis/taint-generic.c
index b0df85f237298d..174ecaabfbab44 100644
--- a/clang/test/Analysis/taint-generic.c
+++ b/clang/test/Analysis/taint-generic.c
@@ -63,6 +63,7 @@ void clang_analyzer_isTainted_char(char);
 void clang_analyzer_isTainted_wchar(wchar_t);
 void clang_analyzer_isTainted_charp(char*);
 void clang_analyzer_isTainted_int(int);
+void clang_analyzer_dump_int(int);
 
 int coin();
 
@@ -459,7 +460,53 @@ unsigned radar11369570_hanging(const unsigned char *arr, 
int l) {
 longcmp(a, t, c);
 l -= 12;
   }
-  return 5/a; // expected-warning {{Division by a tainted value, possibly 
zero}}
+  return 5/a; // FIXME: Should be a "div by tainted" warning here.
+}
+
+// This computation used to take a very long time.
+void complex_taint_queries(const int *p) {
+  int tainted = 0;
+  scanf("%d", &tainted);
+
+  // Make "tmp" tainted.
+  int tmp = tainted + tainted;
+  clang_analyzer_isTainted_int(tmp); // ex

[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Balazs Benics via cfe-commits

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


[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Balazs Benics via cfe-commits

steakhal wrote:

Next release is scheduled for the 3rd of September. I want to backport this 
there too.

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


[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.

LGTM!

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


[clang] [RISCV][FMV] Support target_clones (PR #85786)

2024-08-21 Thread Piyou Chen via cfe-commits

https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/85786

>From 395ce72afbf9e4b12fcbfaf9cdbda8921c9ff72a Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Tue, 23 Jul 2024 19:59:06 -0700
Subject: [PATCH 1/4] [RISCV][FMV] Support target_clones

---
 .../clang/Basic/DiagnosticFrontendKinds.td|   4 +
 clang/include/clang/Basic/TargetInfo.h|   3 +-
 clang/include/clang/Sema/SemaRISCV.h  |   1 +
 clang/lib/AST/ASTContext.cpp  |  12 +
 clang/lib/CodeGen/CodeGenFunction.cpp | 106 -
 clang/lib/CodeGen/CodeGenFunction.h   |   3 +
 clang/lib/CodeGen/CodeGenModule.cpp   |   5 +-
 clang/lib/CodeGen/Targets/RISCV.cpp   |  35 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  30 +++
 clang/lib/Sema/SemaRISCV.cpp  |  10 +
 .../attr-target-clones-riscv-invalid.c|   8 +
 clang/test/CodeGen/attr-target-clones-riscv.c | 211 ++
 .../CodeGenCXX/attr-target-clones-riscv.cpp   | 210 +
 .../test/SemaCXX/attr-target-clones-riscv.cpp |  35 +++
 14 files changed, 670 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-target-clones-riscv-invalid.c
 create mode 100644 clang/test/CodeGen/attr-target-clones-riscv.c
 create mode 100644 clang/test/CodeGenCXX/attr-target-clones-riscv.cpp
 create mode 100644 clang/test/SemaCXX/attr-target-clones-riscv.cpp

diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 8a1462c670d68f..0c870a1f3f1442 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -378,4 +378,8 @@ def warn_missing_symbol_graph_dir : Warning<
 def err_ast_action_on_llvm_ir : Error<
   "cannot apply AST actions to LLVM IR file '%0'">,
   DefaultFatal;
+
+def err_os_unsupport_riscv_target_clones : Error<
+  "target_clones is currently only supported on Linux">;
+
 }
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index a58fb5f9792720..f31d88a354ea28 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1496,7 +1496,8 @@ class TargetInfo : public TransferrableTargetInfo,
   /// Identify whether this target supports multiversioning of functions,
   /// which requires support for cpu_supports and cpu_is functionality.
   bool supportsMultiVersioning() const {
-return getTriple().isX86() || getTriple().isAArch64();
+return getTriple().isX86() || getTriple().isAArch64() ||
+   getTriple().isRISCV();
   }
 
   /// Identify whether this target supports IFuncs.
diff --git a/clang/include/clang/Sema/SemaRISCV.h 
b/clang/include/clang/Sema/SemaRISCV.h
index d62fca8128b2a3..d7f17797283b86 100644
--- a/clang/include/clang/Sema/SemaRISCV.h
+++ b/clang/include/clang/Sema/SemaRISCV.h
@@ -43,6 +43,7 @@ class SemaRISCV : public SemaBase {
 
   void handleInterruptAttr(Decl *D, const ParsedAttr &AL);
   bool isAliasValid(unsigned BuiltinID, llvm::StringRef AliasName);
+  bool isValidFMVExtension(StringRef Ext);
 
   /// Indicate RISC-V vector builtin functions enabled or not.
   bool DeclareRVVBuiltins = false;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index b201d201e1ea6a..a4d123219770bb 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14181,6 +14181,18 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   Target->getTargetOpts().FeaturesAsWritten.begin(),
   Target->getTargetOpts().FeaturesAsWritten.end());
   Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, 
Features);
+} else if (Target->getTriple().isRISCV()) {
+  StringRef VersionStr = TC->getFeatureStr(GD.getMultiVersionIndex());
+  std::vector Features;
+  if (VersionStr != "default") {
+ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(VersionStr);
+Features.insert(Features.begin(), ParsedAttr.Features.begin(),
+ParsedAttr.Features.end());
+  }
+  Features.insert(Features.begin(),
+  Target->getTargetOpts().FeaturesAsWritten.begin(),
+  Target->getTargetOpts().FeaturesAsWritten.end());
+  Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, 
Features);
 } else {
   std::vector Features;
   StringRef VersionStr = TC->getFeatureStr(GD.getMultiVersionIndex());
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index eff8c9f5694084..d625dde684933b 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2877,12 +2877,116 @@ void CodeGenFunction::EmitMultiVersionResolver(
   case llvm::Triple::aarch64:
 EmitAArch64MultiVersionResolver(Resolver, Options);
 return;
+  case llvm::Triple::riscv32:
+  case ll

[clang] [clang] Add nuw attribute to GEPs (PR #105496)

2024-08-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-hlsl

Author: Hari Limaye (hazzlim)


Changes

Add nuw attribute to inbounds GEPs where the expression used to form the GEP is 
an addition of unsigned indices.

---

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


91 Files Affected:

- (modified) clang/lib/CodeGen/CGBuilder.h (+4-2) 
- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+14-3) 
- (modified) clang/test/CodeGen/2005-01-02-ConstantInits.c (+1-8) 
- (modified) clang/test/CodeGen/PowerPC/ppc-emmintrin.c (+6-6) 
- (modified) clang/test/CodeGen/PowerPC/ppc-xmmintrin.c (+8-8) 
- (modified) clang/test/CodeGen/attr-counted-by.c (+8-8) 
- (modified) 
clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c 
(+1-1) 
- (modified) clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c (+32-32) 
- (modified) clang/test/CodeGen/catch-pointer-overflow-volatile.c (+1-1) 
- (modified) clang/test/CodeGen/catch-pointer-overflow.c (+3-3) 
- (modified) clang/test/CodeGen/ext-int.c (+1-1) 
- (modified) clang/test/CodeGen/hexagon-brev-ld-ptr-incdec.c (+3-3) 
- (modified) clang/test/CodeGen/integer-overflow.c (+3-3) 
- (modified) clang/test/CodeGen/ms-intrinsics.c (+6-6) 
- (modified) clang/test/CodeGen/ubsan-pointer-overflow.m (+1-1) 
- (modified) clang/test/CodeGen/vla.c (+1-1) 
- (modified) clang/test/CodeGenCXX/attr-likelihood-iteration-stmt.cpp (+18-18) 
- (modified) clang/test/CodeGenCXX/for-range.cpp (+6-6) 
- (modified) clang/test/CodeGenCXX/pr45964-decomp-transform.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/vla.cpp (+2-2) 
- (modified) clang/test/CodeGenHLSL/buffer-array-operator.hlsl (+2-2) 
- (modified) clang/test/CodeGenSYCL/address-space-deduction.cpp (+24-24) 
- (modified) clang/test/Headers/__clang_hip_math.hip (+27-27) 
- (modified) clang/test/OpenMP/bug60602.cpp (+4-4) 
- (modified) clang/test/OpenMP/declare_mapper_codegen.cpp (+2-2) 
- (modified) clang/test/OpenMP/distribute_codegen.cpp (+16-16) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/distribute_simd_codegen.cpp (+48-48) 
- (modified) clang/test/OpenMP/for_linear_codegen.cpp (+1-1) 
- (modified) clang/test/OpenMP/for_reduction_codegen.cpp (+32-32) 
- (modified) clang/test/OpenMP/for_reduction_codegen_UDR.cpp (+16-16) 
- (modified) clang/test/OpenMP/for_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/for_scan_codegen.cpp (+20-20) 
- (modified) clang/test/OpenMP/for_simd_scan_codegen.cpp (+20-20) 
- (modified) clang/test/OpenMP/irbuilder_for_iterator.cpp (+3-3) 
- (modified) clang/test/OpenMP/irbuilder_for_rangefor.cpp (+3-3) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_auto.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_down.c (+1-1) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_dynamic.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_dynamic_chunked.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_runtime.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_static_chunked.c (+4-4) 
- (modified) clang/test/OpenMP/map_struct_ordering.cpp (+1-1) 
- (modified) clang/test/OpenMP/master_taskloop_in_reduction_codegen.cpp (+5-5) 
- (modified) clang/test/OpenMP/master_taskloop_reduction_codegen.cpp (+6-6) 
- (modified) clang/test/OpenMP/master_taskloop_simd_in_reduction_codegen.cpp 
(+5-5) 
- (modified) clang/test/OpenMP/master_taskloop_simd_reduction_codegen.cpp 
(+6-6) 
- (modified) clang/test/OpenMP/ordered_codegen.cpp (+40-40) 
- (modified) clang/test/OpenMP/parallel_for_codegen.cpp (+72-72) 
- (modified) clang/test/OpenMP/parallel_for_linear_codegen.cpp (+1-1) 
- (modified) clang/test/OpenMP/parallel_for_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/parallel_for_scan_codegen.cpp (+22-22) 
- (modified) clang/test/OpenMP/parallel_for_simd_scan_codegen.cpp (+20-20) 
- (modified) clang/test/OpenMP/parallel_master_reduction_task_codegen.cpp 
(+12-12) 
- (modified) clang/test/OpenMP/parallel_master_taskloop_reduction_codegen.cpp 
(+6-6) 
- (modified) 
clang/test/OpenMP/parallel_master_taskloop_simd_reduction_codegen.cpp (+6-6) 
- (modified) clang/test/OpenMP/parallel_reduction_codegen.cpp (+6-6) 
- (modified) clang/test/OpenMP/parallel_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/parallel_sections_reduction_task_codegen.cpp 
(+12-12) 
- (modified) clang/test/OpenMP/reduction_implicit_map.cpp (+25-25) 
- (modified) clang/test/OpenMP/sections_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/target_data_use_device_addr_codegen.cpp (+5-5) 
- (modified) clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp (+41-41) 
- (modified) clang/test/OpenMP/target_has_device_addr_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/target_in_reduction_codegen.cpp (+5-5) 
- (modified)

[clang] [clang] Add nuw attribute to GEPs (PR #105496)

2024-08-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Hari Limaye (hazzlim)


Changes

Add nuw attribute to inbounds GEPs where the expression used to form the GEP is 
an addition of unsigned indices.

---

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


91 Files Affected:

- (modified) clang/lib/CodeGen/CGBuilder.h (+4-2) 
- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+14-3) 
- (modified) clang/test/CodeGen/2005-01-02-ConstantInits.c (+1-8) 
- (modified) clang/test/CodeGen/PowerPC/ppc-emmintrin.c (+6-6) 
- (modified) clang/test/CodeGen/PowerPC/ppc-xmmintrin.c (+8-8) 
- (modified) clang/test/CodeGen/attr-counted-by.c (+8-8) 
- (modified) 
clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c 
(+1-1) 
- (modified) clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c (+32-32) 
- (modified) clang/test/CodeGen/catch-pointer-overflow-volatile.c (+1-1) 
- (modified) clang/test/CodeGen/catch-pointer-overflow.c (+3-3) 
- (modified) clang/test/CodeGen/ext-int.c (+1-1) 
- (modified) clang/test/CodeGen/hexagon-brev-ld-ptr-incdec.c (+3-3) 
- (modified) clang/test/CodeGen/integer-overflow.c (+3-3) 
- (modified) clang/test/CodeGen/ms-intrinsics.c (+6-6) 
- (modified) clang/test/CodeGen/ubsan-pointer-overflow.m (+1-1) 
- (modified) clang/test/CodeGen/vla.c (+1-1) 
- (modified) clang/test/CodeGenCXX/attr-likelihood-iteration-stmt.cpp (+18-18) 
- (modified) clang/test/CodeGenCXX/for-range.cpp (+6-6) 
- (modified) clang/test/CodeGenCXX/pr45964-decomp-transform.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/vla.cpp (+2-2) 
- (modified) clang/test/CodeGenHLSL/buffer-array-operator.hlsl (+2-2) 
- (modified) clang/test/CodeGenSYCL/address-space-deduction.cpp (+24-24) 
- (modified) clang/test/Headers/__clang_hip_math.hip (+27-27) 
- (modified) clang/test/OpenMP/bug60602.cpp (+4-4) 
- (modified) clang/test/OpenMP/declare_mapper_codegen.cpp (+2-2) 
- (modified) clang/test/OpenMP/distribute_codegen.cpp (+16-16) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/distribute_simd_codegen.cpp (+48-48) 
- (modified) clang/test/OpenMP/for_linear_codegen.cpp (+1-1) 
- (modified) clang/test/OpenMP/for_reduction_codegen.cpp (+32-32) 
- (modified) clang/test/OpenMP/for_reduction_codegen_UDR.cpp (+16-16) 
- (modified) clang/test/OpenMP/for_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/for_scan_codegen.cpp (+20-20) 
- (modified) clang/test/OpenMP/for_simd_scan_codegen.cpp (+20-20) 
- (modified) clang/test/OpenMP/irbuilder_for_iterator.cpp (+3-3) 
- (modified) clang/test/OpenMP/irbuilder_for_rangefor.cpp (+3-3) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_auto.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_down.c (+1-1) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_dynamic.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_dynamic_chunked.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_runtime.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_static_chunked.c (+4-4) 
- (modified) clang/test/OpenMP/map_struct_ordering.cpp (+1-1) 
- (modified) clang/test/OpenMP/master_taskloop_in_reduction_codegen.cpp (+5-5) 
- (modified) clang/test/OpenMP/master_taskloop_reduction_codegen.cpp (+6-6) 
- (modified) clang/test/OpenMP/master_taskloop_simd_in_reduction_codegen.cpp 
(+5-5) 
- (modified) clang/test/OpenMP/master_taskloop_simd_reduction_codegen.cpp 
(+6-6) 
- (modified) clang/test/OpenMP/ordered_codegen.cpp (+40-40) 
- (modified) clang/test/OpenMP/parallel_for_codegen.cpp (+72-72) 
- (modified) clang/test/OpenMP/parallel_for_linear_codegen.cpp (+1-1) 
- (modified) clang/test/OpenMP/parallel_for_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/parallel_for_scan_codegen.cpp (+22-22) 
- (modified) clang/test/OpenMP/parallel_for_simd_scan_codegen.cpp (+20-20) 
- (modified) clang/test/OpenMP/parallel_master_reduction_task_codegen.cpp 
(+12-12) 
- (modified) clang/test/OpenMP/parallel_master_taskloop_reduction_codegen.cpp 
(+6-6) 
- (modified) 
clang/test/OpenMP/parallel_master_taskloop_simd_reduction_codegen.cpp (+6-6) 
- (modified) clang/test/OpenMP/parallel_reduction_codegen.cpp (+6-6) 
- (modified) clang/test/OpenMP/parallel_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/parallel_sections_reduction_task_codegen.cpp 
(+12-12) 
- (modified) clang/test/OpenMP/reduction_implicit_map.cpp (+25-25) 
- (modified) clang/test/OpenMP/sections_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/target_data_use_device_addr_codegen.cpp (+5-5) 
- (modified) clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp (+41-41) 
- (modified) clang/test/OpenMP/target_has_device_addr_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/target_in_reduction_codegen.cpp (+5-5) 
- (

[clang] [clang] Add nuw attribute to GEPs (PR #105496)

2024-08-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Hari Limaye (hazzlim)


Changes

Add nuw attribute to inbounds GEPs where the expression used to form the GEP is 
an addition of unsigned indices.

---

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


91 Files Affected:

- (modified) clang/lib/CodeGen/CGBuilder.h (+4-2) 
- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+14-3) 
- (modified) clang/test/CodeGen/2005-01-02-ConstantInits.c (+1-8) 
- (modified) clang/test/CodeGen/PowerPC/ppc-emmintrin.c (+6-6) 
- (modified) clang/test/CodeGen/PowerPC/ppc-xmmintrin.c (+8-8) 
- (modified) clang/test/CodeGen/attr-counted-by.c (+8-8) 
- (modified) 
clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c 
(+1-1) 
- (modified) clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c (+32-32) 
- (modified) clang/test/CodeGen/catch-pointer-overflow-volatile.c (+1-1) 
- (modified) clang/test/CodeGen/catch-pointer-overflow.c (+3-3) 
- (modified) clang/test/CodeGen/ext-int.c (+1-1) 
- (modified) clang/test/CodeGen/hexagon-brev-ld-ptr-incdec.c (+3-3) 
- (modified) clang/test/CodeGen/integer-overflow.c (+3-3) 
- (modified) clang/test/CodeGen/ms-intrinsics.c (+6-6) 
- (modified) clang/test/CodeGen/ubsan-pointer-overflow.m (+1-1) 
- (modified) clang/test/CodeGen/vla.c (+1-1) 
- (modified) clang/test/CodeGenCXX/attr-likelihood-iteration-stmt.cpp (+18-18) 
- (modified) clang/test/CodeGenCXX/for-range.cpp (+6-6) 
- (modified) clang/test/CodeGenCXX/pr45964-decomp-transform.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/vla.cpp (+2-2) 
- (modified) clang/test/CodeGenHLSL/buffer-array-operator.hlsl (+2-2) 
- (modified) clang/test/CodeGenSYCL/address-space-deduction.cpp (+24-24) 
- (modified) clang/test/Headers/__clang_hip_math.hip (+27-27) 
- (modified) clang/test/OpenMP/bug60602.cpp (+4-4) 
- (modified) clang/test/OpenMP/declare_mapper_codegen.cpp (+2-2) 
- (modified) clang/test/OpenMP/distribute_codegen.cpp (+16-16) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/distribute_simd_codegen.cpp (+48-48) 
- (modified) clang/test/OpenMP/for_linear_codegen.cpp (+1-1) 
- (modified) clang/test/OpenMP/for_reduction_codegen.cpp (+32-32) 
- (modified) clang/test/OpenMP/for_reduction_codegen_UDR.cpp (+16-16) 
- (modified) clang/test/OpenMP/for_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/for_scan_codegen.cpp (+20-20) 
- (modified) clang/test/OpenMP/for_simd_scan_codegen.cpp (+20-20) 
- (modified) clang/test/OpenMP/irbuilder_for_iterator.cpp (+3-3) 
- (modified) clang/test/OpenMP/irbuilder_for_rangefor.cpp (+3-3) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_auto.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_down.c (+1-1) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_dynamic.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_dynamic_chunked.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_runtime.c (+4-4) 
- (modified) clang/test/OpenMP/irbuilder_for_unsigned_static_chunked.c (+4-4) 
- (modified) clang/test/OpenMP/map_struct_ordering.cpp (+1-1) 
- (modified) clang/test/OpenMP/master_taskloop_in_reduction_codegen.cpp (+5-5) 
- (modified) clang/test/OpenMP/master_taskloop_reduction_codegen.cpp (+6-6) 
- (modified) clang/test/OpenMP/master_taskloop_simd_in_reduction_codegen.cpp 
(+5-5) 
- (modified) clang/test/OpenMP/master_taskloop_simd_reduction_codegen.cpp 
(+6-6) 
- (modified) clang/test/OpenMP/ordered_codegen.cpp (+40-40) 
- (modified) clang/test/OpenMP/parallel_for_codegen.cpp (+72-72) 
- (modified) clang/test/OpenMP/parallel_for_linear_codegen.cpp (+1-1) 
- (modified) clang/test/OpenMP/parallel_for_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/parallel_for_scan_codegen.cpp (+22-22) 
- (modified) clang/test/OpenMP/parallel_for_simd_scan_codegen.cpp (+20-20) 
- (modified) clang/test/OpenMP/parallel_master_reduction_task_codegen.cpp 
(+12-12) 
- (modified) clang/test/OpenMP/parallel_master_taskloop_reduction_codegen.cpp 
(+6-6) 
- (modified) 
clang/test/OpenMP/parallel_master_taskloop_simd_reduction_codegen.cpp (+6-6) 
- (modified) clang/test/OpenMP/parallel_reduction_codegen.cpp (+6-6) 
- (modified) clang/test/OpenMP/parallel_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/parallel_sections_reduction_task_codegen.cpp 
(+12-12) 
- (modified) clang/test/OpenMP/reduction_implicit_map.cpp (+25-25) 
- (modified) clang/test/OpenMP/sections_reduction_task_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/target_data_use_device_addr_codegen.cpp (+5-5) 
- (modified) clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp (+41-41) 
- (modified) clang/test/OpenMP/target_has_device_addr_codegen.cpp (+12-12) 
- (modified) clang/test/OpenMP/target_in_reduction_codegen.cpp (+5-5) 
- (modified

[clang] [clang] Catch missing format attributes (PR #105479)

2024-08-21 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovichtec updated 
https://github.com/llvm/llvm-project/pull/105479

From 8b5876fea6d3073332da972416c09602b81264af Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 5 Apr 2024 15:20:37 +0200
Subject: [PATCH] [clang] Catch missing format attributes

---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   1 -
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Attr.h   |   7 +
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/Sema/SemaDecl.cpp   |   2 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 219 +-
 clang/test/Sema/attr-format-missing.c | 393 ++
 clang/test/Sema/attr-format-missing.cpp   | 174 
 9 files changed, 803 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c
 create mode 100644 clang/test/Sema/attr-format-missing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 127b9541d5c5d8..aa3e25f4339a51 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -239,6 +239,9 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses when the result of a [[nodiscard]] function is discarded 
after being cast in C. Fixes #GH104391.
 
+- Clang now diagnoses missing format attributes for non-template functions and
+  class/struct/union members. Fixes #GH60718
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 19c3f1e0433496..3924677150a3a4 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -529,7 +529,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def MissingIncludeDirs : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4b6aadd635786a..14160f2911957e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1040,6 +1040,9 @@ def err_opencl_invalid_param : Error<
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
 def warn_enum_value_overflow : Warning<"overflow in enumeration value">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Attr.h b/clang/include/clang/Sema/Attr.h
index 3f0b10212789a4..37c124ca7b454a 100644
--- a/clang/include/clang/Sema/Attr.h
+++ b/clang/include/clang/Sema/Attr.h
@@ -123,6 +123,13 @@ inline bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+inline bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 /// Diagnose mutually exclusive attributes when present on a given
 /// declaration. Returns true if diagnosed.
 template 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1f7e555d1b8717..9189216ed6e301 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4619,6 +4619,10 @@ class Sema final : public SemaBase {
 
   enum class RetainOwnershipKind { NS, CF, OS };
 
+  void DiagnoseMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl);
+  std::vector
+  GetMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 503e93f9257137..500fb9d844372e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15998,6 +15998,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 }
   }
 
+  DiagnoseMissingFormatAttributes(Body, FD);
+
   // We might not have found a prototype because we didn't wish to warn on
   // the lack of a missing prototype. Try again without the checks for
   // whether we want to warn on the missing prototype.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/Sema

[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-21 Thread via cfe-commits


@@ -369,12 +372,13 @@ class Intrinsic {
 public:
   Intrinsic(Record *R, StringRef Name, StringRef Proto, TypeSpec OutTS,
 TypeSpec InTS, ClassKind CK, ListInit *Body, NeonEmitter &Emitter,
-StringRef ArchGuard, StringRef TargetGuard, bool IsUnavailable, 
bool BigEndianSafe)
+StringRef ArchGuard, StringRef TargetGuard, bool IsUnavailable,
+bool BigEndianSafe)
   : R(R), Name(Name.str()), OutTS(OutTS), InTS(InTS), CK(CK), Body(Body),
-ArchGuard(ArchGuard.str()), TargetGuard(TargetGuard.str()), 
IsUnavailable(IsUnavailable),
-BigEndianSafe(BigEndianSafe), PolymorphicKeyType(0), 
NeededEarly(false),
-UseMacro(false), BaseType(OutTS, "."), InBaseType(InTS, "."),
-Emitter(Emitter) {
+ArchGuard(ArchGuard.str()), TargetGuard(TargetGuard.str()),

SpencerAbson wrote:

clang-format I'm afraid.

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


[clang] [RISCV] Allow YAML file to control multilib selection (PR #98856)

2024-08-21 Thread Simon Cook via cfe-commits

simonpcook wrote:

I think the fake flag hack may have a limitation in that since the 
`--XXX-fake-flag-...` appears in `--print-multi-lib` it may get imported into 
some build system and used as a flag for building particular libraries. For 
example with the above, newlib will not build since `error: unknown argument: 
'--XXX-fake-flag-yaml-has-m'`.

Of course, I can build newlib with a different multilib.yaml file that I later 
distribute the tools with - more an FYI for anyone who hits that one in the 
future.

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


[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Donát Nagy via cfe-commits

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


[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Donát Nagy via cfe-commits


@@ -459,7 +460,53 @@ unsigned radar11369570_hanging(const unsigned char *arr, 
int l) {
 longcmp(a, t, c);
 l -= 12;
   }
-  return 5/a; // expected-warning {{Division by a tainted value, possibly 
zero}}
+  return 5/a; // FIXME: Should be a "div by tainted" warning here.
+}
+
+// This computation used to take a very long time.
+void complex_taint_queries(const int *p) {
+  int tainted = 0;
+  scanf("%d", &tainted);
+
+  // Make "tmp" tainted.
+  int tmp = tainted + tainted;
+  clang_analyzer_isTainted_int(tmp); // expected-warning{{YES}}
+
+  // Make "tmp" SymExpr a lot more complicated by applying computation.
+  // This should balloon the symbol complexity.
+  tmp += p[0] + p[0];
+  tmp += p[1] + p[1];
+  tmp += p[2] + p[2];
+  clang_analyzer_dump_int(tmp); // expected-warning{{conj_}} symbol 
complexity: 8
+  clang_analyzer_isTainted_int(tmp); // expected-warning{{YES}}
+
+  tmp += p[3] + p[3];
+  clang_analyzer_dump_int(tmp); // expected-warning{{(conj_}} symbol 
complexity: 10
+  clang_analyzer_isTainted_int(tmp); // expected-warning{{NO}} 10 is already 
to ocomplex to be traversed

NagyDonat wrote:

```suggestion
  clang_analyzer_isTainted_int(tmp); // expected-warning{{NO}} 10 is already 
too complex to be traversed
```

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


[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Donát Nagy via cfe-commits

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

The change LGTM overall, I support this kind of mitigation.

I added several cosmetic bikeshedding remarks as inline comments, but they are 
not important enough to block this PR.

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


[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Donát Nagy via cfe-commits


@@ -256,6 +257,12 @@ std::vector 
taint::getTaintedSymbolsImpl(ProgramStateRef State,
   if (!Sym)
 return TaintedSymbols;
 
+  // 
HACK:https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570
+  if (const auto &Opts = State->getAnalysisManager().getAnalyzerOptions();
+  Sym->computeComplexity() >= Opts.MaxTaintedSymbolComplexity) {

NagyDonat wrote:

```suggestion
  Sym->computeComplexity() > Opts.MaxTaintedSymbolComplexity) {
```
I know that this is pedantic bikeshedding, but if the name and documentation 
claims that "this is the maximal possible complexity of a tainted symbol", then 
make it actually possible to have a tainted symbol with that complexity.

(Feel free to change the default value to 9 to compensate for this change. 
Alternatively you could keep the `>=` and rename the analyzer option to 
discard-taint-at-complexity or something similar.)

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


[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Donát Nagy via cfe-commits


@@ -407,6 +407,11 @@ ANALYZER_OPTION(
 ANALYZER_OPTION(unsigned, MaxSymbolComplexity, "max-symbol-complexity",
 "The maximum complexity of symbolic constraint.", 35)
 
+// 
HACK:https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570
+// Ideally, we should get rid of this option soon.
+ANALYZER_OPTION(unsigned, MaxTaintedSymbolComplexity, 
"max-tainted-symbol-complexity",
+"[DEPRECATED] The maximum complexity of symbolic to carry 
taint", 10)

NagyDonat wrote:

```suggestion
"[DEPRECATED] The maximum complexity of a symbol to carry 
taint", 10)
```
Or something else might be even better, but the adjective "symbolic" is awkward 
without a noun.

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


[clang] [RISCV] Allow YAML file to control multilib selection (PR #98856)

2024-08-21 Thread via cfe-commits

ArcaneNibble wrote:

... I had no idea that build systems might do that. Thanks, this probably 
explains why the feature was initially designed so that flags would be valid to 
pass as arguments

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


[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-21 Thread Nico Weber via cfe-commits

nico wrote:

The test added here was tweaked a bit and then deleted in 
https://github.com/llvm/llvm-project/commit/07a8cbaf8dc16bebf6e875173d20299d9cc47cc5

What gives?

Instead of deleting tests, we should revert the PR that adds them and then 
reland the PR with working tests.

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


[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Balazs Benics via cfe-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/105493

>From f9f481a55d174746205f33472e49410b7f57bc5a Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Wed, 21 Aug 2024 11:51:30 +0200
Subject: [PATCH 1/4] [analyzer] Limit `isTainted()` by skipping complicated
 symbols

As discussed in
https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570/10

Some `isTainted()` queries can blow up the analysis times, and
effectively halt the analysis under specific workloads.

We don't really have the time now to do a caching re-implementation of
`isTainted()`, so we need to workaround the case.

The workaround with the smallest blast radius was to limit what symbols
`isTainted()` does the query (by walking the SymExpr).
So far, the threshold 10 worked for us, but this value can be overridden
using the "max-tainted-symbol-complexity" config value.

This new option is "deprecated" from the getgo, as I expect this issue
to be fixed within the next few months and I don't want users to
override this value anyways. If they do, this message will let them know
that they are on their own, and the next release may break them (as we
no longer recognize this option if we drop it).
---
 .../StaticAnalyzer/Core/AnalyzerOptions.def   |  5 ++
 clang/lib/StaticAnalyzer/Checkers/Taint.cpp   |  7 +++
 clang/test/Analysis/analyzer-config.c |  1 +
 clang/test/Analysis/taint-generic.c   | 49 ++-
 4 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
index 29aa6a3b8a16e7..98c659192b55d5 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
@@ -407,6 +407,11 @@ ANALYZER_OPTION(
 ANALYZER_OPTION(unsigned, MaxSymbolComplexity, "max-symbol-complexity",
 "The maximum complexity of symbolic constraint.", 35)
 
+// 
HACK:https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570
+// Ideally, we should get rid of this option soon.
+ANALYZER_OPTION(unsigned, MaxTaintedSymbolComplexity, 
"max-tainted-symbol-complexity",
+"[DEPRECATED] The maximum complexity of symbolic to carry 
taint", 10)
+
 ANALYZER_OPTION(unsigned, MaxTimesInlineLarge, "max-times-inline-large",
 "The maximum times a large function could be inlined.", 32)
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/Taint.cpp 
b/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
index 6362c82b009d72..5408db85bbb0bb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/StaticAnalyzer/Checkers/Taint.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 #include 
 
@@ -256,6 +257,12 @@ std::vector 
taint::getTaintedSymbolsImpl(ProgramStateRef State,
   if (!Sym)
 return TaintedSymbols;
 
+  // 
HACK:https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570
+  if (const auto &Opts = State->getAnalysisManager().getAnalyzerOptions();
+  Sym->computeComplexity() >= Opts.MaxTaintedSymbolComplexity) {
+return {};
+  }
+
   // Traverse all the symbols this symbol depends on to see if any are tainted.
   for (SymbolRef SubSym : Sym->symbols()) {
 if (!isa(SubSym))
diff --git a/clang/test/Analysis/analyzer-config.c 
b/clang/test/Analysis/analyzer-config.c
index b8dbcdd7e55afe..13cb50451f2618 100644
--- a/clang/test/Analysis/analyzer-config.c
+++ b/clang/test/Analysis/analyzer-config.c
@@ -94,6 +94,7 @@
 // CHECK-NEXT: max-inlinable-size = 100
 // CHECK-NEXT: max-nodes = 225000
 // CHECK-NEXT: max-symbol-complexity = 35
+// CHECK-NEXT: max-tainted-symbol-complexity = 10
 // CHECK-NEXT: max-times-inline-large = 32
 // CHECK-NEXT: min-cfg-size-treat-functions-as-large = 14
 // CHECK-NEXT: mode = deep
diff --git a/clang/test/Analysis/taint-generic.c 
b/clang/test/Analysis/taint-generic.c
index b0df85f237298d..174ecaabfbab44 100644
--- a/clang/test/Analysis/taint-generic.c
+++ b/clang/test/Analysis/taint-generic.c
@@ -63,6 +63,7 @@ void clang_analyzer_isTainted_char(char);
 void clang_analyzer_isTainted_wchar(wchar_t);
 void clang_analyzer_isTainted_charp(char*);
 void clang_analyzer_isTainted_int(int);
+void clang_analyzer_dump_int(int);
 
 int coin();
 
@@ -459,7 +460,53 @@ unsigned radar11369570_hanging(const unsigned char *arr, 
int l) {
 longcmp(a, t, c);
 l -= 12;
   }
-  return 5/a; // expected-warning {{Division by a tainted value, possibly 
zero}}
+  return 5/a; // FIXME: Should be a "div by tainted" warning here.
+}
+
+// This computation used to take a very long time.
+void complex_taint_queries(const int *p) {
+  int tainted = 0;
+  scanf("%d", &

[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Balazs Benics via cfe-commits

steakhal wrote:

Fixed all remarks. Excellent feedback, thanks!

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


[clang] ad435bc - [clang][CodeGen][SPIR-V][AMDGPU] Tweak AMDGCNSPIRV ABI to allow for the correct handling of aggregates passed to kernels / functions. (#102776)

2024-08-21 Thread via cfe-commits

Author: Alex Voicu
Date: 2024-08-21T13:16:59+01:00
New Revision: ad435bcc14f42dc97286c717cd12446a0facb2ee

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

LOG: [clang][CodeGen][SPIR-V][AMDGPU] Tweak AMDGCNSPIRV ABI to allow for the 
correct handling of aggregates passed to kernels / functions. (#102776)

The AMDGPU kernel ABI is not directly representable in SPIR-V, since it
relies on passing aggregates `byref`, and SPIR-V only encodes `byval`
(which the AMDGPU BE disallows for kernel arguments). As a temporary
solution to this mismatch, we add special handling for AMDGCN flavoured
SPIR-V, whereby aggregates are passed as direct, both to kernels and to
normal functions. This is not ideal (there are pathological cases where
performance is heavily impacted), but empirically robust and guaranteed
to work as the AMDGPU BE retains handling of `direct` passing for legacy
reasons.

We will revisit this in the future, but as it stands it is enough to
pass a wide array of integration tests and generates correct SPIR-V and
correct reverse translation into LLVM IR. The
amdgpu-kernel-arg-pointer-type test is updated via the automated script,
and thus becomes quite noisy.

Added: 


Modified: 
clang/lib/CodeGen/Targets/SPIR.cpp
clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
clang/test/CodeGenCUDA/kernel-args.cu

Removed: 




diff  --git a/clang/lib/CodeGen/Targets/SPIR.cpp 
b/clang/lib/CodeGen/Targets/SPIR.cpp
index cf068cbc4fcd36..cc52925e2e523f 100644
--- a/clang/lib/CodeGen/Targets/SPIR.cpp
+++ b/clang/lib/CodeGen/Targets/SPIR.cpp
@@ -32,7 +32,9 @@ class SPIRVABIInfo : public CommonSPIRABIInfo {
   void computeInfo(CGFunctionInfo &FI) const override;
 
 private:
+  ABIArgInfo classifyReturnType(QualType RetTy) const;
   ABIArgInfo classifyKernelArgumentType(QualType Ty) const;
+  ABIArgInfo classifyArgumentType(QualType Ty) const;
 };
 } // end anonymous namespace
 namespace {
@@ -64,6 +66,27 @@ void CommonSPIRABIInfo::setCCs() {
   RuntimeCC = llvm::CallingConv::SPIR_FUNC;
 }
 
+ABIArgInfo SPIRVABIInfo::classifyReturnType(QualType RetTy) const {
+  if (getTarget().getTriple().getVendor() != llvm::Triple::AMD)
+return DefaultABIInfo::classifyReturnType(RetTy);
+  if (!isAggregateTypeForABI(RetTy) || getRecordArgABI(RetTy, getCXXABI()))
+return DefaultABIInfo::classifyReturnType(RetTy);
+
+  if (const RecordType *RT = RetTy->getAs()) {
+const RecordDecl *RD = RT->getDecl();
+if (RD->hasFlexibleArrayMember())
+  return DefaultABIInfo::classifyReturnType(RetTy);
+  }
+
+  // TODO: The AMDGPU ABI is non-trivial to represent in SPIR-V; in order to
+  // avoid encoding various architecture specific bits here we return 
everything
+  // as direct to retain type info for things like aggregates, for later 
perusal
+  // when translating back to LLVM/lowering in the BE. This is also why we
+  // disable flattening as the outcomes can mismatch between SPIR-V and AMDGPU.
+  // This will be revisited / optimised in the future.
+  return ABIArgInfo::getDirect(CGT.ConvertType(RetTy), 0u, nullptr, false);
+}
+
 ABIArgInfo SPIRVABIInfo::classifyKernelArgumentType(QualType Ty) const {
   if (getContext().getLangOpts().CUDAIsDevice) {
 // Coerce pointer arguments with default address space to CrossWorkGroup
@@ -78,18 +101,51 @@ ABIArgInfo 
SPIRVABIInfo::classifyKernelArgumentType(QualType Ty) const {
   return ABIArgInfo::getDirect(LTy, 0, nullptr, false);
 }
 
-// Force copying aggregate type in kernel arguments by value when
-// compiling CUDA targeting SPIR-V. This is required for the object
-// copied to be valid on the device.
-// This behavior follows the CUDA spec
-// 
https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#global-function-argument-processing,
-// and matches the NVPTX implementation.
-if (isAggregateTypeForABI(Ty))
+if (isAggregateTypeForABI(Ty)) {
+  if (getTarget().getTriple().getVendor() == llvm::Triple::AMD)
+// TODO: The AMDGPU kernel ABI passes aggregates byref, which is not
+// currently expressible in SPIR-V; SPIR-V passes aggregates byval,
+// which the AMDGPU kernel ABI does not allow. Passing aggregates as
+// direct works around this impedance mismatch, as it retains type info
+// and can be correctly handled, post reverse-translation, by the 
AMDGPU
+// BE, which has to support this CC for legacy OpenCL purposes. It can
+// be brittle and does lead to performance degradation in certain
+// pathological cases. This will be revisited / optimised in the 
future,
+// once a way to deal with the byref/byval impedance mismatch is
+// identified.
+return ABIArgInfo::getDirect(LTy, 0, nullptr, f

[clang] [clang][CodeGen][SPIR-V][AMDGPU] Tweak AMDGCNSPIRV ABI to allow for the correct handling of aggregates passed to kernels / functions. (PR #102776)

2024-08-21 Thread Alex Voicu via cfe-commits

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


[clang] [clang] Diagnose functions with too many parameters (PR #104833)

2024-08-21 Thread Vlad Serebrennikov via cfe-commits

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

>From 424818620766cedb2770e076ee359afeb0cc14ec Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Mon, 19 Aug 2024 19:26:46 +0300
Subject: [PATCH 1/7] Add in-loop check

---
 clang/include/clang/AST/Type.h   |  7 ++-
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  3 +++
 clang/lib/Parse/ParseDecl.cpp| 10 ++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 27618604192c51..575f3c17a3f691 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1929,6 +1929,11 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 unsigned Kind : NumOfBuiltinTypeBits;
   };
 
+public:
+  static constexpr int FunctionTypeNumParamsWidth = 16;
+  static constexpr int FunctionTypeNumParamsLimit = (1 << 16) - 1;
+
+protected:
   /// FunctionTypeBitfields store various bits belonging to FunctionProtoType.
   /// Only common bits are stored here. Additional uncommon bits are stored
   /// in a trailing object after FunctionProtoType.
@@ -1966,7 +1971,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 /// According to [implimits] 8 bits should be enough here but this is
 /// somewhat easy to exceed with metaprogramming and so we would like to
 /// keep NumParams as wide as reasonably possible.
-unsigned NumParams : 16;
+unsigned NumParams : FunctionTypeNumParamsWidth;
 
 /// The type of exception specification this function has.
 LLVM_PREFERRED_TYPE(ExceptionSpecificationType)
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8a92973236ddbd..1f97db2e13ebf9 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9311,6 +9311,9 @@ def note_constinit_missing_here : Note<
 def err_dimension_expr_not_constant_integer : Error<
   "dimension expression does not evaluate to a constant unsigned int">;
 
+def err_function_parameter_limit_exceeded : Error<
+  "too many function parameters; subsequent parameters are skipped">;
+
 def err_typecheck_cond_incompatible_operands_null : Error<
   "non-pointer operand type %0 incompatible with %select{NULL|nullptr}1">;
 def ext_empty_struct_union : Extension<
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index a8a9d3f3f5b088..94f2366d484f2d 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -8025,6 +8025,16 @@ void Parser::ParseParameterDeclarationClause(
 // Consume the keyword.
 ConsumeToken();
   }
+
+  // FunctionTypeBitfields::NumParams can only hold so much.
+  // Skip until the the end of the parameter list, ignoring
+  // parameters that would overflow.
+  if (ParamInfo.size() == Type::FunctionTypeNumParamsLimit) {
+Diag(ParmDeclarator.getBeginLoc(), 
diag::err_function_parameter_limit_exceeded);
+SkipUntil(tok::r_paren, SkipUntilFlags::StopBeforeMatch);
+break;
+  }
+
   // Inform the actions module about the parameter declarator, so it gets
   // added to the current scope.
   Decl *Param =

>From 11c54d40f39005ac20f8fb212981bc443a197ed8 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Mon, 19 Aug 2024 21:30:35 +0300
Subject: [PATCH 2/7] Add a test and a release note

---
 clang/docs/ReleaseNotes.rst   |  3 ++
 .../test/Parser/function-parameter-limit.cpp  | 29 +++
 2 files changed, 32 insertions(+)
 create mode 100644 clang/test/Parser/function-parameter-limit.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a4257ea1f48c11..e1ab1d45bed766 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -288,6 +288,9 @@ Miscellaneous Clang Crashes Fixed
 - Fixed a crash caused by long chains of ``sizeof`` and other similar operators
   that can be followed by a non-parenthesized expression. (#GH45061)
 
+- Fixed a crash when function has more than 65536 parameters.
+  Now a diagnostic is emitted. (#GH35741)
+
 OpenACC Specific Changes
 
 
diff --git a/clang/test/Parser/function-parameter-limit.cpp 
b/clang/test/Parser/function-parameter-limit.cpp
new file mode 100644
index 00..c6917c51644187
--- /dev/null
+++ b/clang/test/Parser/function-parameter-limit.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -verify %s
+
+#define P_10(x) x##0, x##1, x##2, x##3, x##4, x##5, x##6, x##7, x##8, x##9,
+#define P_100(x) P_10(x##0) P_10(x##1) P_10(x##2) P_10(x##3) P_10(x##4) \
+P_10(x##5) P_10(x##6) P_10(x##7) P_10(x##8) 
P_10(x##9)
+#define P_1000(x) P_100(x##0) P_100(x##1) P_100(x##2) P_100(x##3) P_100(x##4) \
+ P_100(x##5) P_100(x##6) P_100(x##

[clang] [clang] Diagnose functions with too many parameters (PR #104833)

2024-08-21 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> @Endilll you forgot to update the tests - hence the ci failure

Thank you! Should be good to go now

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


[clang] 8486589 - [analyzer] Limit `isTainted()` by skipping complicated symbols (#105493)

2024-08-21 Thread via cfe-commits

Author: Balazs Benics
Date: 2024-08-21T14:24:56+02:00
New Revision: 848658955a9d2d42ea3e319d191e2dcd5d76c837

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

LOG: [analyzer] Limit `isTainted()` by skipping complicated symbols (#105493)

As discussed in

https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570/10

Some `isTainted()` queries can blow up the analysis times, and
effectively halt the analysis under specific workloads.

We don't really have the time now to do a caching re-implementation of
`isTainted()`, so we need to workaround the case.

The workaround with the smallest blast radius was to limit what symbols
`isTainted()` does the query (by walking the SymExpr). So far, the
threshold 10 worked for us, but this value can be overridden using the
"max-tainted-symbol-complexity" config value.

This new option is "deprecated" from the getgo, as I expect this issue
to be fixed within the next few months and I don't want users to
override this value anyways. If they do, this message will let them know
that they are on their own, and the next release may break them (as we
no longer recognize this option if we drop it).

Mitigates #89720

CPP-5414

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
clang/lib/StaticAnalyzer/Checkers/Taint.cpp
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/taint-generic.c

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
index 29aa6a3b8a16e7..737bc8e86cfb6a 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
@@ -407,6 +407,11 @@ ANALYZER_OPTION(
 ANALYZER_OPTION(unsigned, MaxSymbolComplexity, "max-symbol-complexity",
 "The maximum complexity of symbolic constraint.", 35)
 
+// 
HACK:https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570
+// Ideally, we should get rid of this option soon.
+ANALYZER_OPTION(unsigned, MaxTaintedSymbolComplexity, 
"max-tainted-symbol-complexity",
+"[DEPRECATED] The maximum complexity of a symbol to carry 
taint", 9)
+
 ANALYZER_OPTION(unsigned, MaxTimesInlineLarge, "max-times-inline-large",
 "The maximum times a large function could be inlined.", 32)
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/Taint.cpp 
b/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
index 6362c82b009d72..0bb5739db4b756 100644
--- a/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/Taint.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/StaticAnalyzer/Checkers/Taint.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 #include 
 
@@ -256,6 +257,12 @@ std::vector 
taint::getTaintedSymbolsImpl(ProgramStateRef State,
   if (!Sym)
 return TaintedSymbols;
 
+  // 
HACK:https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570
+  if (const auto &Opts = State->getAnalysisManager().getAnalyzerOptions();
+  Sym->computeComplexity() > Opts.MaxTaintedSymbolComplexity) {
+return {};
+  }
+
   // Traverse all the symbols this symbol depends on to see if any are tainted.
   for (SymbolRef SubSym : Sym->symbols()) {
 if (!isa(SubSym))

diff  --git a/clang/test/Analysis/analyzer-config.c 
b/clang/test/Analysis/analyzer-config.c
index b8dbcdd7e55afe..8eb869bac46f8f 100644
--- a/clang/test/Analysis/analyzer-config.c
+++ b/clang/test/Analysis/analyzer-config.c
@@ -94,6 +94,7 @@
 // CHECK-NEXT: max-inlinable-size = 100
 // CHECK-NEXT: max-nodes = 225000
 // CHECK-NEXT: max-symbol-complexity = 35
+// CHECK-NEXT: max-tainted-symbol-complexity = 9
 // CHECK-NEXT: max-times-inline-large = 32
 // CHECK-NEXT: min-cfg-size-treat-functions-as-large = 14
 // CHECK-NEXT: mode = deep

diff  --git a/clang/test/Analysis/taint-generic.c 
b/clang/test/Analysis/taint-generic.c
index b0df85f237298d..1c139312734bca 100644
--- a/clang/test/Analysis/taint-generic.c
+++ b/clang/test/Analysis/taint-generic.c
@@ -63,6 +63,7 @@ void clang_analyzer_isTainted_char(char);
 void clang_analyzer_isTainted_wchar(wchar_t);
 void clang_analyzer_isTainted_charp(char*);
 void clang_analyzer_isTainted_int(int);
+void clang_analyzer_dump_int(int);
 
 int coin();
 
@@ -459,7 +460,53 @@ unsigned radar11369570_hanging(const unsigned char *arr, 
int l) {
 longcmp(a, t, c);
 l -= 12;
   }
-  return 5/a; // expected-warning {{Division by a tainted value, possibly 
zero}}
+  return 5/a; // FIXME: Should be a "div by tainted" warning here.
+}

[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Balazs Benics via cfe-commits

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


[clang] [clang] Diagnose functions with too many parameters (PR #104833)

2024-08-21 Thread via cfe-commits

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


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


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-08-21 Thread Janek van Oirschot via cfe-commits


@@ -68,82 +71,84 @@ void MCResourceInfo::assignMaxRegs() {
   assignMaxRegSym(MaxSGPRSym, MaxSGPR);
 }
 
-void MCResourceInfo::finalize() {
-  assert(!finalized && "Cannot finalize ResourceInfo again.");
-  finalized = true;
-  assignMaxRegs();
+void MCResourceInfo::finalize(MCContext &OutContext) {
+  assert(!Finalized && "Cannot finalize ResourceInfo again.");
+  Finalized = true;
+  assignMaxRegs(OutContext);
 }
 
-MCSymbol *MCResourceInfo::getMaxVGPRSymbol() {
+MCSymbol *MCResourceInfo::getMaxVGPRSymbol(MCContext &OutContext) {
   return OutContext.getOrCreateSymbol("max_num_vgpr");
 }
 
-MCSymbol *MCResourceInfo::getMaxAGPRSymbol() {
+MCSymbol *MCResourceInfo::getMaxAGPRSymbol(MCContext &OutContext) {
   return OutContext.getOrCreateSymbol("max_num_agpr");
 }
 
-MCSymbol *MCResourceInfo::getMaxSGPRSymbol() {
+MCSymbol *MCResourceInfo::getMaxSGPRSymbol(MCContext &OutContext) {
   return OutContext.getOrCreateSymbol("max_num_sgpr");
 }
 
 void MCResourceInfo::assignResourceInfoExpr(
-int64_t localValue, ResourceInfoKind RIK, AMDGPUMCExpr::VariantKind Kind,
-const MachineFunction &MF,
-const SmallVectorImpl &Callees) {
-  const MCConstantExpr *localConstExpr =
-  MCConstantExpr::create(localValue, OutContext);
-  const MCExpr *SymVal = localConstExpr;
+int64_t LocalValue, ResourceInfoKind RIK, AMDGPUMCExpr::VariantKind Kind,
+const MachineFunction &MF, const SmallVectorImpl 
&Callees,
+MCContext &OutContext) {
+  const MCConstantExpr *LocalConstExpr =
+  MCConstantExpr::create(LocalValue, OutContext);
+  const MCExpr *SymVal = LocalConstExpr;

JanekvO wrote:

Had to look into this a bit as I wasn't aware of the !callees metadata: but 
yes, we currently don't take advantage of this. I was able to create an example 
that emits the !callees metadata for an indirect call but it will always fall 
back on the worst case (i.e., module level worst case values).

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


[clang] [llvm] [BPF] introduce __attribute__((bpf_fastcall)) (PR #105417)

2024-08-21 Thread Nikita Popov via cfe-commits

nikic wrote:

The last commit looks fine to me, I didn't look at the rest in detail assuming 
it was already reviewed.

One thing I'm curious about is why this is implemented as a function attribute 
rather than as a calling convention.

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


[clang] [llvm] [BPF] introduce __attribute__((bpf_fastcall)) (PR #105417)

2024-08-21 Thread via cfe-commits

eddyz87 wrote:

> The last commit looks fine to me, I didn't look at the rest in detail 
> assuming it was already reviewed.
> 
> One thing I'm curious about is why this is implemented as a function 
> attribute rather than as a calling convention.

Hi @nikic ,

Same question was raised on a previous iteration, please refer to these two 
comments: 
[1](https://github.com/llvm/llvm-project/pull/101228#issuecomment-2263848414), 
[2](https://github.com/llvm/llvm-project/pull/101228#issuecomment-2269797853).

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


[libcxx] [libcxxabi] [libunwind] [runtimes] Always define cxx_shared, cxx_static & other targets (PR #80007)

2024-08-21 Thread Louis Dionne via cfe-commits

ldionne wrote:

Ping @petrhosek @vitalybuka. I would like to merge this patch this week. CI 
seems to be happy, but your CI may be doing something different since IIRC this 
patch upset your bots the last time I tried landing it. Can you take it for a 
round to see if that's still the case?

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


[clang] [Clang] [NFC] Introduce `DynamicRecursiveASTVisitor` (PR #105195)

2024-08-21 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

I wonder if we can reduce binary size by simply marking RAV as 
`visibility("hidden")`

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


[clang] [clang] Add nuw attribute to GEPs (PR #105496)

2024-08-21 Thread Hari Limaye via cfe-commits


@@ -7,13 +7,6 @@
 struct X { int a[2]; };
 extern int bar();
 
-//.
-// CHECK: @test.i23 = internal global i32 4, align 4
-// CHECK: @i = global i32 4, align 4
-// CHECK: @Arr = global [100 x i32] zeroinitializer, align 16
-// CHECK: @foo2.X = internal global ptr getelementptr (i8, ptr @Arr, i64 196), 
align 8
-// CHECK: @foo2.i23 = internal global i32 0, align 4

hazzlim wrote:

Yeah, possibly something that could be addressed in the script if desired - not 
sure how much it comes up.

Ok great, I've updated the `--global-value-regex` argument and fixed up the 
missing global CHECKs.

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


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-08-21 Thread Janek van Oirschot via cfe-commits


@@ -3,6 +3,18 @@
 
 declare i32 @llvm.amdgcn.workitem.id.x()
 
+define <2 x i64> @f1() #0 {

JanekvO wrote:

There were some function order changes in some tests. This function is the same 
one as the function that is removed a couple of lines below.

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


[clang] [clang][ASTImporter] New fix for default template parameter values. (PR #101836)

2024-08-21 Thread Ding Fei via cfe-commits
=?utf-8?q?Balázs_Kéri?= 
Message-ID:
In-Reply-To: 



@@ -5968,11 +5962,21 @@ 
ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
   }
 
   if (D->hasDefaultArgument()) {
+// Default argument can be "inherited" when it has a reference to the
+// previous declaration (of the default argument) which is stored only 
once.
+// Here we import the default argument in any case, and the inherited state
+// is updated later after the parent template was created. If the
+// inherited-from object would be imported here it causes more difficulties
+// (parent template may not be created yet and import loops can occur).
 Expected ToDefaultArgOrErr =
 import(D->getDefaultArgument());
 if (!ToDefaultArgOrErr)
   return ToDefaultArgOrErr.takeError();
-ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);
+// The just called import process can trigger import of the parent template
+// which can update the default argument value to "inherited". This should
+// not be changed.
+if (!ToD->hasDefaultArgument())
+  ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);

danix800 wrote:

I digged a little bit about template importing and have a few questions:

1. Templates are redeclarable, but not like some other nodes (`FunctionDecl`/
`VarDecl`/`TagDecl` currently), no redecls are imported ahead of the 
current one.
if redecls are imported, the ordering problem might go away. If this works,
we could apply the same mechnism to some other redeclarables too (I tested
locally and templates can be imported with correct order).

Or, there might be other considerations about not importing redecls for some
nodes (like performance? but redecls are usually small, right?), for some 
client
(StaticAnalyzer), this mis-ordering is still acceptable, but I'm not quite 
sure how
many clients depend on the importer and how they depends on the ordering.

2. For template parameters, current implementation supports importing them 
directly
but added it into the top-level TU context, which might not be the good for 
any
clients, not to say about ODR violations. I'm not clear what's the 
consideration
of not importing some of the nodes without importing context firstly.

For the crash fix it's a LGTM.

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


[clang] Thread Safety Analysis: Differentiate between lock sets at real join points and expected/actual sets at function end (PR #105526)

2024-08-21 Thread Malek Ben Slimane via cfe-commits

https://github.com/malek203 created 
https://github.com/llvm/llvm-project/pull/105526

This fixes false positives related to returning a scoped lockable object. At 
the end of a function, we check managed locks instead of scoped locks.

At real join points, we skip checking managed locks because we assume that the 
scope keeps track of its underlying mutexes and will release them at its 
destruction. So, checking for the scopes is sufficient. However, at the end of 
a function, we aim at comparing the expected and the actual lock sets. There, 
we skip checking scoped locks to prevent to get duplicate warnings for the same 
lock.

>From 9d4dbf5c3be29175e23f1881efa8f3b7626de755 Mon Sep 17 00:00:00 2001
From: Malek Ben Slimane 
Date: Tue, 20 Aug 2024 14:53:54 +0200
Subject: [PATCH] Thread Safety Analysis: Differentiate between lock sets at
 real join points and expected/actual sets at function end

This fixes false positives related to returning a scoped lockable
object. At the end of a function, we check managed locks instead of
scoped locks.

At real join points, we skip checking managed locks because we assume
that the scope keeps track of its underlying mutexes and will release
them at its destruction. So, checking for the scopes is sufficient.
However, at the end of a function, we aim at comparing the expected and
the actual lock sets. There, we skip checking scoped locks to prevent to
get duplicate warnings for the same lock.
---
 clang/lib/Analysis/ThreadSafety.cpp   |  8 ++--
 .../SemaCXX/warn-thread-safety-analysis.cpp   | 20 ---
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index e25b843c9bf83e..c4a83b069e0792 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -922,6 +922,9 @@ class ScopedLockableFactEntry : public FactEntry {
   handleRemovalFromIntersection(const FactSet &FSet, FactManager &FactMan,
 SourceLocation JoinLoc, LockErrorKind LEK,
 ThreadSafetyHandler &Handler) const override {
+if (LEK == LEK_LockedAtEndOfFunction || LEK == 
LEK_NotLockedAtEndOfFunction)
+  return;
+
 for (const auto &UnderlyingMutex : UnderlyingMutexes) {
   const auto *Entry = FSet.findLock(FactMan, UnderlyingMutex.Cap);
   if ((UnderlyingMutex.Kind == UCK_Acquired && Entry) ||
@@ -2224,7 +2227,7 @@ void ThreadSafetyAnalyzer::intersectAndWarn(FactSet 
&EntrySet,
   if (join(FactMan[*EntryIt], ExitFact,
EntryLEK != LEK_LockedSomeLoopIterations))
 *EntryIt = Fact;
-} else if (!ExitFact.managed()) {
+} else if (!ExitFact.managed() || EntryLEK == LEK_LockedAtEndOfFunction) {
   ExitFact.handleRemovalFromIntersection(ExitSet, FactMan, JoinLoc,
  EntryLEK, Handler);
 }
@@ -2236,7 +2239,8 @@ void ThreadSafetyAnalyzer::intersectAndWarn(FactSet 
&EntrySet,
 const FactEntry *ExitFact = ExitSet.findLock(FactMan, *EntryFact);
 
 if (!ExitFact) {
-  if (!EntryFact->managed() || ExitLEK == LEK_LockedSomeLoopIterations)
+  if (!EntryFact->managed() || ExitLEK == LEK_LockedSomeLoopIterations ||
+  ExitLEK == LEK_NotLockedAtEndOfFunction)
 EntryFact->handleRemovalFromIntersection(EntrySetOrig, FactMan, 
JoinLoc,
  ExitLEK, Handler);
   if (ExitLEK == LEK_LockedSomePredecessors)
diff --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp 
b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
index af9254508d8050..8477200456d985 100644
--- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -6077,24 +6077,20 @@ namespace ReturnScopedLockable {
 class Object {
 public:
   MutexLock lock() EXCLUSIVE_LOCK_FUNCTION(mutex) {
-// TODO: False positive because scoped lock isn't destructed.
-return MutexLock(&mutex); // expected-note {{mutex acquired here}}
-  }   // expected-warning {{mutex 'mutex' is still 
held at the end of function}}
+return MutexLock(&mutex);
+  }
 
   ReaderMutexLock lockShared() SHARED_LOCK_FUNCTION(mutex) {
-// TODO: False positive because scoped lock isn't destructed.
-return ReaderMutexLock(&mutex); // expected-note {{mutex acquired here}}
-  } // expected-warning {{mutex 'mutex' is 
still held at the end of function}}
+return ReaderMutexLock(&mutex);
+  }
 
   MutexLock adopt() EXCLUSIVE_LOCKS_REQUIRED(mutex) {
-// TODO: False positive because scoped lock isn't destructed.
-return MutexLock(&mutex, true); // expected-note {{mutex acquired here}}
-  } // expected-warning {{mutex 'mutex' is 
still held at the end of function}}
+return MutexLock(&mutex, true);
+  }
 
   ReaderMutexLock adoptShared() SHARED_LOCKS_REQUIR

[clang] 281d178 - [clang] Diagnose functions with too many parameters (#104833)

2024-08-21 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-08-21T17:38:24+04:00
New Revision: 281d17840c35a1d80303bb6170c253fe2411f95f

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

LOG: [clang] Diagnose functions with too many parameters (#104833)

This patch adds a parser check when a function declaration or function
type declaration (in a function pointer declaration, for example) has
too many parameters for `FunctionTypeBits::NumParams` to hold. At the
moment of writing it's a 16-bit-wide bit-field, limiting the number of
parameters at 65536.

The check is added in the parser loop that goes over comma-separated
list of function parameters. This is not the solution Aaron suggested in
https://github.com/llvm/llvm-project/issues/35741#issuecomment-1638086571,
because it was found out that it's quite hard to recover from this
particular error in `GetFullTypeForDeclarator()`. Multiple options were
tried, but all of them led to crashes down the line.

I used LLVM Compile Time Tracker to ensure this does not introduce a
performance regression. I believe changes are in the noise:
https://llvm-compile-time-tracker.com/compare.php?from=de5ea2d122c31e1551654ff506c33df299f351b8&to=424818620766cedb2770e076ee359afeb0cc14ec&stat=instructions:u

Fixes #35741

Added: 
clang/test/Parser/function-parameter-limit.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Type.h
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Parse/ParseDecl.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5aedfc654e8dbb..8f98167dff31ef 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -310,6 +310,9 @@ Miscellaneous Clang Crashes Fixed
 - Fixed a crash caused by long chains of ``sizeof`` and other similar operators
   that can be followed by a non-parenthesized expression. (#GH45061)
 
+- Fixed a crash when function has more than 65536 parameters.
+  Now a diagnostic is emitted. (#GH35741)
+
 OpenACC Specific Changes
 
 

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 27618604192c51..575f3c17a3f691 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1929,6 +1929,11 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 unsigned Kind : NumOfBuiltinTypeBits;
   };
 
+public:
+  static constexpr int FunctionTypeNumParamsWidth = 16;
+  static constexpr int FunctionTypeNumParamsLimit = (1 << 16) - 1;
+
+protected:
   /// FunctionTypeBitfields store various bits belonging to FunctionProtoType.
   /// Only common bits are stored here. Additional uncommon bits are stored
   /// in a trailing object after FunctionProtoType.
@@ -1966,7 +1971,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 /// According to [implimits] 8 bits should be enough here but this is
 /// somewhat easy to exceed with metaprogramming and so we would like to
 /// keep NumParams as wide as reasonably possible.
-unsigned NumParams : 16;
+unsigned NumParams : FunctionTypeNumParamsWidth;
 
 /// The type of exception specification this function has.
 LLVM_PREFERRED_TYPE(ExceptionSpecificationType)

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 62a97b36737e72..464f08637332d4 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -481,6 +481,9 @@ def ext_decomp_decl_empty : ExtWarn<
   "ISO C++17 does not allow a decomposition group to be empty">,
   InGroup>;
 
+def err_function_parameter_limit_exceeded : Error<
+  "too many function parameters; subsequent parameters will be ignored">;
+
 // C++26 structured bindings
 def ext_decl_attrs_on_binding : ExtWarn<
   "an attribute specifier sequence attached to a structured binding 
declaration "

diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index a8a9d3f3f5b088..ed5d6ce90aa7d1 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -8025,6 +8025,17 @@ void Parser::ParseParameterDeclarationClause(
 // Consume the keyword.
 ConsumeToken();
   }
+
+  // We can only store so many parameters
+  // Skip until the the end of the parameter list, ignoring
+  // parameters that would overflow.
+  if (ParamInfo.size() == Type::FunctionTypeNumParamsLimit) {
+Diag(ParmDeclarator.getBeginLoc(),
+ diag::err_function_parameter_limit_exceeded);
+SkipUntil(tok::r_paren, SkipUntilFlags::StopBeforeMatch);
+break;
+  }
+
   // Inform the actions module about the parameter declarator, so it gets
   

[clang] [llvm] [Coverage][MC/DC] Show uncoverable and unreachable conditions (PR #94137)

2024-08-21 Thread via cfe-commits

Lambdaris wrote:

I have no authority to request reviewers or commit this patch. So let's request 
someone, @chapuni @ornata @hanickadot 

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


[clang] [clang][ASTImporter] set nonnull type for var specialized from lambda template (PR #105492)

2024-08-21 Thread Ding Fei via cfe-commits

https://github.com/danix800 updated 
https://github.com/llvm/llvm-project/pull/105492

>From 2ac3aa1b85d727fd15d49fa1649147f2229576cb Mon Sep 17 00:00:00 2001
From: dingfei 
Date: Wed, 21 Aug 2024 17:52:04 +0800
Subject: [PATCH 1/2] [clang][ASTImporter] set nonnull type for var specialized
 from lambda template

There's circular deps here when importing btw VarTemplateSpecializationDecl (m)
and its type.

VarDecl is created with a null type QualType(), and the importing of its type
will leads to linkage computation (for the templated lambda) which depends on
the var's type (not yet imported).

This fix uses a non-null type instead of a null one. But this seems
still cannot ensure the computation is correct.
---
 clang/lib/AST/ASTImporter.cpp   |  6 --
 clang/unittests/AST/ASTImporterTest.cpp | 13 +
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 103235547f482e..cc1bd01f15bef6 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6582,6 +6582,8 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
   return std::move(Err);
   }
 
+  QualType ToTmpTy = Importer.getToContext().IntTy;
+  ToTmpTy = ToTmpTy.withCVRQualifiers(D->getType().getCVRQualifiers());
   using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
   // Create a new specialization.
   if (auto *FromPartial = dyn_cast(D)) {
@@ -6592,7 +6594,7 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
 PartVarSpecDecl *ToPartial;
 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
-VarTemplate, QualType(), nullptr,
+VarTemplate, ToTmpTy, nullptr,
 D->getStorageClass(), TemplateArgs))
   return ToPartial;
 
@@ -6613,7 +6615,7 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
   } else { // Full specialization
 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
-QualType(), nullptr, D->getStorageClass(),
+ToTmpTy, nullptr, D->getStorageClass(),
 TemplateArgs))
   return D2;
   }
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 57242ff49fe3b8..06996268d1fb94 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -9919,6 +9919,19 @@ TEST_P(ImportTemplateParmDeclDefaultValue, 
ImportExistingVarTemplate) {
   testImport(FromLastD);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VarTemplatedLambdaInGlobalScope) {
+  Decl *FromTU = getTuDecl(
+  R"(
+namespace { template  auto m = [] {}; }
+void bar() { auto n = m; }
+  )",
+  Lang_CXX14, "input0.cc");
+  FunctionDecl *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("bar")));
+  FunctionDecl *ToF = Import(FromF, Lang_CXX14);
+  EXPECT_TRUE(ToF);
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 

>From 81efe9531fb901b18191c850e838b1825562d650 Mon Sep 17 00:00:00 2001
From: dingfei 
Date: Wed, 21 Aug 2024 21:52:04 +0800
Subject: [PATCH 2/2] fix clang-format check failure

---
 clang/lib/AST/ASTImporter.cpp | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index cc1bd01f15bef6..ad7cd7eee2a4e7 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6613,10 +6613,9 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
 // to adopt template parameters.
 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
   } else { // Full specialization
-if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
-*BeginLocOrErr, *IdLocOrErr, VarTemplate,
-ToTmpTy, nullptr, D->getStorageClass(),
-TemplateArgs))
+if (GetImportedOrCreateDecl(
+D2, D, Importer.getToContext(), DC, *BeginLocOrErr, *IdLocOrErr,
+VarTemplate, ToTmpTy, nullptr, D->getStorageClass(), TemplateArgs))
   return D2;
   }
 

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


[clang] [Sparc] Add flags to enable errata workaround pass for GR712RC and UT700 (PR #104742)

2024-08-21 Thread Daniel Cederman via cfe-commits

doac wrote:

Our UT700 and GR712RC processors are in active production and we have customers 
that for various reasons wants to use clang instead of gcc. To do that they 
need to use these workarounds to avoid certain sensitive code sequences (the 
same workarounds are already available in gcc). 
We have also developed some performance related patches for the Sparc backend, 
but it has been difficult to get them upstreamed as, as you say, few people are 
working on the Sparc backend. So instead we have provided our customers with 
custom versions of clang/llvm for the different operating systems that we 
support. 
In my experience these workarounds have been very easy to port forward, but the 
downside of not having them in mainline is that they are not included in 3:rd 
party tools that uses llvm nor in different operating system vendors custom 
toolchains.

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


[clang] [clang][driver] Fix -print-target-triple OS version for apple targets (PR #104037)

2024-08-21 Thread Louis Dionne via cfe-commits

ldionne wrote:

Thanks for the writeup, this is useful. This leaves me wondering if 
`arm64-apple-darwin22.4.0` might be the right target triple then, but the 
effective triple would be e.g. `arm64-apple-macos12.0.0`?

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


[clang] [clang][ASTImporter] set nonnull type for var specialized from lambda template (PR #105492)

2024-08-21 Thread Ding Fei via cfe-commits

https://github.com/danix800 updated 
https://github.com/llvm/llvm-project/pull/105492

>From 2ac3aa1b85d727fd15d49fa1649147f2229576cb Mon Sep 17 00:00:00 2001
From: dingfei 
Date: Wed, 21 Aug 2024 17:52:04 +0800
Subject: [PATCH 1/3] [clang][ASTImporter] set nonnull type for var specialized
 from lambda template

There's circular deps here when importing btw VarTemplateSpecializationDecl (m)
and its type.

VarDecl is created with a null type QualType(), and the importing of its type
will leads to linkage computation (for the templated lambda) which depends on
the var's type (not yet imported).

This fix uses a non-null type instead of a null one. But this seems
still cannot ensure the computation is correct.
---
 clang/lib/AST/ASTImporter.cpp   |  6 --
 clang/unittests/AST/ASTImporterTest.cpp | 13 +
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 103235547f482e..cc1bd01f15bef6 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6582,6 +6582,8 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
   return std::move(Err);
   }
 
+  QualType ToTmpTy = Importer.getToContext().IntTy;
+  ToTmpTy = ToTmpTy.withCVRQualifiers(D->getType().getCVRQualifiers());
   using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
   // Create a new specialization.
   if (auto *FromPartial = dyn_cast(D)) {
@@ -6592,7 +6594,7 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
 PartVarSpecDecl *ToPartial;
 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
-VarTemplate, QualType(), nullptr,
+VarTemplate, ToTmpTy, nullptr,
 D->getStorageClass(), TemplateArgs))
   return ToPartial;
 
@@ -6613,7 +6615,7 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
   } else { // Full specialization
 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
-QualType(), nullptr, D->getStorageClass(),
+ToTmpTy, nullptr, D->getStorageClass(),
 TemplateArgs))
   return D2;
   }
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 57242ff49fe3b8..06996268d1fb94 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -9919,6 +9919,19 @@ TEST_P(ImportTemplateParmDeclDefaultValue, 
ImportExistingVarTemplate) {
   testImport(FromLastD);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VarTemplatedLambdaInGlobalScope) {
+  Decl *FromTU = getTuDecl(
+  R"(
+namespace { template  auto m = [] {}; }
+void bar() { auto n = m; }
+  )",
+  Lang_CXX14, "input0.cc");
+  FunctionDecl *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("bar")));
+  FunctionDecl *ToF = Import(FromF, Lang_CXX14);
+  EXPECT_TRUE(ToF);
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 

>From 81efe9531fb901b18191c850e838b1825562d650 Mon Sep 17 00:00:00 2001
From: dingfei 
Date: Wed, 21 Aug 2024 21:52:04 +0800
Subject: [PATCH 2/3] fix clang-format check failure

---
 clang/lib/AST/ASTImporter.cpp | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index cc1bd01f15bef6..ad7cd7eee2a4e7 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6613,10 +6613,9 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
 // to adopt template parameters.
 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
   } else { // Full specialization
-if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
-*BeginLocOrErr, *IdLocOrErr, VarTemplate,
-ToTmpTy, nullptr, D->getStorageClass(),
-TemplateArgs))
+if (GetImportedOrCreateDecl(
+D2, D, Importer.getToContext(), DC, *BeginLocOrErr, *IdLocOrErr,
+VarTemplate, ToTmpTy, nullptr, D->getStorageClass(), TemplateArgs))
   return D2;
   }
 

>From 8f1fc146b7d2a6d6accfdfeae53f13c6cdb5413b Mon Sep 17 00:00:00 2001
From: dingfei 
Date: Wed, 21 Aug 2024 21:56:12 +0800
Subject: [PATCH 3/3] rename testcase

---
 clang/unittests/AST/ASTImporterTest.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 06996268d1fb94..827e73e90d2e70 100644
--- a/clang/unittests/AST/ASTImporterTe

[clang] [llvm] [Coverage][MC/DC] Show uncoverable and unreachable conditions (PR #94137)

2024-08-21 Thread via cfe-commits

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


[clang] [Clang] Implement P2747 constexpr placement new (PR #104586)

2024-08-21 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Thank you for working on this! Given that it's an extension in C++20 mode, 
we're missing diagnostics and test coverage for issuing extension/precompat 
diagnostics.

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


[clang] [Clang] Implement P2747 constexpr placement new (PR #104586)

2024-08-21 Thread Aaron Ballman via cfe-commits


@@ -245,7 +245,7 @@ namespace std {
 namespace PlacementNew {
   constexpr int foo() { // both-error {{never produces a constant expression}}
 char c[sizeof(int)];
-new (c) int{12}; // ref-note {{call to placement 'operator new'}} \
+new (c) int{12}; // ref-note {{this placement new expression is not yet 
supported in constant expressions}} \

AaronBallman wrote:

Why is this not yet supported? Should this be fixed as part of this patch?

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


[clang] [Clang] Implement P2747 constexpr placement new (PR #104586)

2024-08-21 Thread Aaron Ballman via cfe-commits


@@ -6691,7 +6691,7 @@ static bool HandleDestructionImpl(EvalInfo &Info, 
SourceRange CallRange,
 if (Size && Size > Value.getArrayInitializedElts())
   expandArray(Value, Value.getArraySize() - 1);
 
-for (; Size != 0; --Size) {
+for (Size = Value.getArraySize(); Size != 0; --Size) {

AaronBallman wrote:

Can you explain why this change is needed?

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


[clang] [Clang] Implement P2747 constexpr placement new (PR #104586)

2024-08-21 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -std=c++2c -verify %s
+
+
+namespace std {
+  using size_t = decltype(sizeof(0));
+}
+
+void *operator new(std::size_t, void *p) { return p; }
+void* operator new[] (std::size_t, void* p) {return p;}
+
+
+consteval int ok() {
+int i;
+new (&i) int(0);
+new (&i) int[1]{1};
+new (static_cast(&i)) int(0);
+return 0;
+}
+
+consteval int conversion() { // expected-error {{consteval function never 
produces a constant expression}}
+int i;
+new (static_cast(&i)) float(0);
+// expected-note@-1 {{placement new would change type of storage from 
'int' to 'float'}}
+return 0;
+}
+
+consteval int indeterminate() {
+int * indeterminate;
+new (indeterminate) int(0);
+// expected-note@-1 {{read of uninitialized object is not allowed in a 
constant expression}}
+return 0;
+}
+
+consteval int array1() {
+int i[2];
+new (&i) int[]{1,2};
+new (&i) int[]{1};
+new (&i) int(0);
+new (static_cast(&i)) int[]{1,2};
+new (static_cast(&i)) int[]{1};
+return 0;
+}
+
+consteval int array2() { // expected-error {{consteval function never produces 
a constant expression}}
+int i[1];
+new (&i) int[2];
+//expected-note@-1 {{placement new would change type of storage from 
'int[1]' to 'int[2]'}}
+return 0;
+}
+
+struct S{
+int* i;
+constexpr S() : i(new int(42)) {} // expected-note {{allocation performed 
here was not deallocated}}
+constexpr ~S() {delete i;}
+};
+
+consteval void alloc() {
+S* s = new S();
+s->~S();
+new (s) S();
+delete s;
+}
+
+
+consteval void alloc_err() {
+S* s = new S();
+new (s) S();
+delete s;
+}
+

AaronBallman wrote:

Can you also add a test for pointer interconvertible types? Basically, coverage 
for:

> the placement argument to the new-expression points to an object that is 
> pointer-interconvertible with an object of type T or, if T is an array type, 
> with the first element of an object of type T, and


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


[clang] [Clang] Implement P2747 constexpr placement new (PR #104586)

2024-08-21 Thread Aaron Ballman via cfe-commits

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


  1   2   3   4   >