[clang] f1cb64b - [MC] Remove Darwin SDK/Version from ObjFileInfo (#103025)

2024-08-14 Thread via cfe-commits

Author: Alexis Engelke
Date: 2024-08-14T09:24:07+02:00
New Revision: f1cb64b6f07184a3624ebb77f3f0e0bddafea1a4

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

LOG: [MC] Remove Darwin SDK/Version from ObjFileInfo (#103025)

There's only a single user (MCMachOStreamer), so it makes more sense to
move the version emission to the source of the data.

Added: 


Modified: 
clang/tools/driver/cc1as_main.cpp
llvm/include/llvm/MC/MCObjectFileInfo.h
llvm/lib/MC/MCMachOStreamer.cpp
llvm/lib/Object/ModuleSymbolTable.cpp
llvm/tools/llvm-mc/llvm-mc.cpp

Removed: 




diff  --git a/clang/tools/driver/cc1as_main.cpp 
b/clang/tools/driver/cc1as_main.cpp
index b661a43c88b08d..78019d39742e64 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -489,10 +489,6 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
   // MCObjectFileInfo needs a MCContext reference in order to initialize 
itself.
   std::unique_ptr MOFI(
   TheTarget->createMCObjectFileInfo(Ctx, PIC));
-  if (Opts.DarwinTargetVariantTriple)
-MOFI->setDarwinTargetVariantTriple(*Opts.DarwinTargetVariantTriple);
-  if (!Opts.DarwinTargetVariantSDKVersion.empty())
-MOFI->setDarwinTargetVariantSDKVersion(Opts.DarwinTargetVariantSDKVersion);
   Ctx.setObjectFileInfo(MOFI.get());
 
   if (Opts.GenDwarfForAssembly)
@@ -574,6 +570,13 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
 Str.reset(TheTarget->createMCObjectStreamer(
 T, Ctx, std::move(MAB), std::move(OW), std::move(CE), *STI));
 Str.get()->initSections(Opts.NoExecStack, *STI);
+if (T.isOSBinFormatMachO() && T.isOSDarwin()) {
+  Triple *TVT = Opts.DarwinTargetVariantTriple
+? &*Opts.DarwinTargetVariantTriple
+: nullptr;
+  Str->emitVersionForTarget(T, VersionTuple(), TVT,
+Opts.DarwinTargetVariantSDKVersion);
+}
   }
 
   // When -fembed-bitcode is passed to clang_as, a 1-byte marker

diff  --git a/llvm/include/llvm/MC/MCObjectFileInfo.h 
b/llvm/include/llvm/MC/MCObjectFileInfo.h
index dda3e8a020f3ae..e2a2c84e47910b 100644
--- a/llvm/include/llvm/MC/MCObjectFileInfo.h
+++ b/llvm/include/llvm/MC/MCObjectFileInfo.h
@@ -458,9 +458,6 @@ class MCObjectFileInfo {
 private:
   bool PositionIndependent = false;
   MCContext *Ctx = nullptr;
-  VersionTuple SDKVersion;
-  std::optional DarwinTargetVariantTriple;
-  VersionTuple DarwinTargetVariantSDKVersion;
 
   void initMachOMCObjectFileInfo(const Triple &T);
   void initELFMCObjectFileInfo(const Triple &T, bool Large);
@@ -471,29 +468,6 @@ class MCObjectFileInfo {
   void initXCOFFMCObjectFileInfo(const Triple &T);
   void initDXContainerObjectFileInfo(const Triple &T);
   MCSection *getDwarfComdatSection(const char *Name, uint64_t Hash) const;
-
-public:
-  void setSDKVersion(const VersionTuple &TheSDKVersion) {
-SDKVersion = TheSDKVersion;
-  }
-
-  const VersionTuple &getSDKVersion() const { return SDKVersion; }
-
-  void setDarwinTargetVariantTriple(const Triple &T) {
-DarwinTargetVariantTriple = T;
-  }
-
-  const Triple *getDarwinTargetVariantTriple() const {
-return DarwinTargetVariantTriple ? &*DarwinTargetVariantTriple : nullptr;
-  }
-
-  void setDarwinTargetVariantSDKVersion(const VersionTuple &TheSDKVersion) {
-DarwinTargetVariantSDKVersion = TheSDKVersion;
-  }
-
-  const VersionTuple &getDarwinTargetVariantSDKVersion() const {
-return DarwinTargetVariantSDKVersion;
-  }
 };
 
 } // end namespace llvm

diff  --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp
index 528caa12ec2126..2e3b67eca08c1d 100644
--- a/llvm/lib/MC/MCMachOStreamer.cpp
+++ b/llvm/lib/MC/MCMachOStreamer.cpp
@@ -533,14 +533,8 @@ MCStreamer *llvm::createMachOStreamer(MCContext &Context,
   std::unique_ptr &&CE,
   bool DWARFMustBeAtTheEnd,
   bool LabelSections) {
-  MCMachOStreamer *S = new MCMachOStreamer(
-  Context, std::move(MAB), std::move(OW), std::move(CE), LabelSections);
-  const Triple &Target = Context.getTargetTriple();
-  S->emitVersionForTarget(
-  Target, Context.getObjectFileInfo()->getSDKVersion(),
-  Context.getObjectFileInfo()->getDarwinTargetVariantTriple(),
-  Context.getObjectFileInfo()->getDarwinTargetVariantSDKVersion());
-  return S;
+  return new MCMachOStreamer(Context, std::move(MAB), std::move(OW),
+ std::move(CE), LabelSections);
 }
 
 // The AddrSig section uses a series of relocations to refer to the symbols 
that

diff  --git a/llvm/lib/Object/ModuleSymbolTable.cpp 
b/llvm/lib/Object/ModuleSymbolTable.cpp
index d8f520ad02c2f2..fb36a88b9c7

[clang] [llvm] [MC] Remove Darwin SDK/Version from ObjFileInfo (PR #103025)

2024-08-14 Thread Alexis Engelke via cfe-commits

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


[clang] [clang] Emit nuw GEPs for array subscript expressions (PR #103088)

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

https://github.com/nikic commented:

As a high level comment: Do we need to pass through the nuw flag, rather than 
deriving it from signedIndices?

Basically, I think that we should be emitting nuw if and only if 
`-fsanitize=undefined` would perform a check for unsigned overflow for that 
gep, and the information to determine whether that is done should already be 
available in the relevant places.

(Unless we currently perform incorrect sanitizer checks in some cases -- in 
which case that needs to be fixed.)

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


[clang] [clang] Emit nuw GEPs for array subscript expressions (PR #103088)

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

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


[clang] [clang] Emit nuw GEPs for array subscript expressions (PR #103088)

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


@@ -4345,8 +4355,8 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const 
ArraySubscriptExpr *E,
 QualType ptrType = E->getBase()->getType();
 Addr = emitArraySubscriptGEP(*this, Addr, Idx, E->getType(),
  !getLangOpts().isSignedOverflowDefined(),
- SignedIndices, E->getExprLoc(), &ptrType,
- E->getBase());
+ /*nuw=*/false, SignedIndices, E->getExprLoc(),
+ &ptrType, E->getBase());

nikic wrote:

Why is the handling for arrays and pointers here different? Aren't they 
essentially semantically equivalent?

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


[clang] [llvm] [RISCV][MC] Support experimental extensions Zvbc32e and Zvkgs (PR #103709)

2024-08-14 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp created 
https://github.com/llvm/llvm-project/pull/103709

These two extensions add addtional instructions for carryless
multiplication with 32-bits elements and Vector-Scalar GCM
instructions.

Please see https://github.com/riscv/riscv-isa-manual/pull/1306.


>From 0bdc302fb5b4dd7369d2f16a6da32412adbe7d7f Mon Sep 17 00:00:00 2001
From: Wang Pengcheng 
Date: Wed, 14 Aug 2024 15:14:36 +0800
Subject: [PATCH] [RISCV][MC] Support experimental extensions Zvbc32e and Zvkgs

These two extensions add addtional instructions for carryless
multiplication with 32-bits elements and Vector-Scalar GCM
instructions.

Please see https://github.com/riscv/riscv-isa-manual/pull/1306.
---
 .../Driver/print-supported-extensions-riscv.c |  2 ++
 .../test/Preprocessor/riscv-target-features.c | 18 
 llvm/docs/RISCVUsage.rst  |  3 +++
 llvm/lib/Target/RISCV/RISCVFeatures.td| 19 +
 llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td| 12 +--
 llvm/lib/TargetParser/RISCVISAInfo.cpp|  9 ++--
 llvm/test/CodeGen/RISCV/attributes.ll |  8 +++
 llvm/test/MC/RISCV/rvv/zvbc.s | 17 +++
 llvm/test/MC/RISCV/rvv/zvkgs.s| 21 +++
 .../TargetParser/RISCVISAInfoTest.cpp |  2 ++
 10 files changed, 103 insertions(+), 8 deletions(-)
 create mode 100644 llvm/test/MC/RISCV/rvv/zvkgs.s

diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 91f12b8416b2a4..132422393170a9 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -172,6 +172,8 @@
 // CHECK-NEXT: zicfiss  1.0   'Zicfiss' (Shadow stack)
 // CHECK-NEXT: zacas1.0   'Zacas' (Atomic 
Compare-And-Swap Instructions)
 // CHECK-NEXT: zalasr   0.1   'Zalasr' (Load-Acquire and 
Store-Release Instructions)
+// CHECK-NEXT: zvbc32e  0.7   'Zvbc32e' (Vector Carryless 
Multiplication with 32-bits elements)
+// CHECK-NEXT: zvkgs0.7   'Zvkgs' (Vector-Scalar GCM 
instructions for Cryptography)
 // CHECK-NEXT: smmpm1.0   'Smmpm' (Machine-level 
Pointer Masking for M-mode)
 // 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)
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 72131108cb5f6a..517702fab5b919 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -187,8 +187,10 @@
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
 // CHECK-NOT: __riscv_zicfiss {{.*$}}
 // CHECK-NOT: __riscv_ztso {{.*$}}
+// CHECK-NOT: __riscv_zvbc32e {{.*$}}
 // CHECK-NOT: __riscv_zvfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zvfbfwma {{.*$}}
+// CHECK-NOT: __riscv_zvkgs {{.*$}}
 
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN:   -march=rv32ia -E -dM %s \
@@ -1658,6 +1660,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZTSO-EXT %s
 // CHECK-ZTSO-EXT: __riscv_ztso 100{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32i_zve32x_zvbc32e0p7 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZVBC32E-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN:   -march=rv64i_zve32x_zvbc32e0p7 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZVBC32E-EXT %s
+// CHECK-ZVBC32E-EXT: __riscv_zvbc32e 7000{{$}}
+
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32ifzvfbfmin1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZVFBFMIN-EXT %s
@@ -1674,6 +1684,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZVFBFWMA-EXT %s
 // CHECK-ZVFBFWMA-EXT: __riscv_zvfbfwma 100{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32i_zve32x_zvkgs0p7 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZVKGS-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN:   -march=rv64i_zve32x_zvkgs0p7 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZVKGS-EXT %s
+// CHECK-ZVKGS-EXT: __riscv_zvkgs 7000{{$}}
+
 // RUN: %clang -target riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32izicfiss1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index b3c7b0e3883d01..3af1428138c021 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -302,6 +302,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``ex

[clang] [llvm] [RISCV][MC] Support experimental extensions Zvbc32e and Zvkgs (PR #103709)

2024-08-14 Thread via cfe-commits

llvmbot wrote:




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

Author: Pengcheng Wang (wangpc-pp)


Changes

These two extensions add addtional instructions for carryless
multiplication with 32-bits elements and Vector-Scalar GCM
instructions.

Please see https://github.com/riscv/riscv-isa-manual/pull/1306.


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


10 Files Affected:

- (modified) clang/test/Driver/print-supported-extensions-riscv.c (+2) 
- (modified) clang/test/Preprocessor/riscv-target-features.c (+18) 
- (modified) llvm/docs/RISCVUsage.rst (+3) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+19) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td (+10-2) 
- (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+7-2) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+8) 
- (modified) llvm/test/MC/RISCV/rvv/zvbc.s (+13-4) 
- (added) llvm/test/MC/RISCV/rvv/zvkgs.s (+21) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+2) 


``diff
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 91f12b8416b2a4..132422393170a9 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -172,6 +172,8 @@
 // CHECK-NEXT: zicfiss  1.0   'Zicfiss' (Shadow stack)
 // CHECK-NEXT: zacas1.0   'Zacas' (Atomic 
Compare-And-Swap Instructions)
 // CHECK-NEXT: zalasr   0.1   'Zalasr' (Load-Acquire and 
Store-Release Instructions)
+// CHECK-NEXT: zvbc32e  0.7   'Zvbc32e' (Vector Carryless 
Multiplication with 32-bits elements)
+// CHECK-NEXT: zvkgs0.7   'Zvkgs' (Vector-Scalar GCM 
instructions for Cryptography)
 // CHECK-NEXT: smmpm1.0   'Smmpm' (Machine-level 
Pointer Masking for M-mode)
 // 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)
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 72131108cb5f6a..517702fab5b919 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -187,8 +187,10 @@
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
 // CHECK-NOT: __riscv_zicfiss {{.*$}}
 // CHECK-NOT: __riscv_ztso {{.*$}}
+// CHECK-NOT: __riscv_zvbc32e {{.*$}}
 // CHECK-NOT: __riscv_zvfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zvfbfwma {{.*$}}
+// CHECK-NOT: __riscv_zvkgs {{.*$}}
 
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN:   -march=rv32ia -E -dM %s \
@@ -1658,6 +1660,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZTSO-EXT %s
 // CHECK-ZTSO-EXT: __riscv_ztso 100{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32i_zve32x_zvbc32e0p7 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZVBC32E-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN:   -march=rv64i_zve32x_zvbc32e0p7 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZVBC32E-EXT %s
+// CHECK-ZVBC32E-EXT: __riscv_zvbc32e 7000{{$}}
+
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32ifzvfbfmin1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZVFBFMIN-EXT %s
@@ -1674,6 +1684,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZVFBFWMA-EXT %s
 // CHECK-ZVFBFWMA-EXT: __riscv_zvfbfwma 100{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32i_zve32x_zvkgs0p7 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZVKGS-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN:   -march=rv64i_zve32x_zvkgs0p7 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZVKGS-EXT %s
+// CHECK-ZVKGS-EXT: __riscv_zvkgs 7000{{$}}
+
 // RUN: %clang -target riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32izicfiss1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index b3c7b0e3883d01..3af1428138c021 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -302,6 +302,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zicfilp``, ``experimental-zicfiss``
   LLVM implements the `1.0 release specification 
`__.
 
+``experimental-zvbc32e``, ``experimental-zvkgs``
+  LLVM implements the `0.7 release specification 
`__.
+
 To use an experimental extension from `clang`, you must add 
`-menable-exp

[clang] [clang][ASTMatcher] Add `matchesString` for `StringLiteral` which matches literals on given `RegExp` (PR #102152)

2024-08-14 Thread via cfe-commits

https://github.com/Gitspike updated 
https://github.com/llvm/llvm-project/pull/102152

>From 869b955eb55bc53e445a8809b56c702d7c312b46 Mon Sep 17 00:00:00 2001
From: hehouhua 
Date: Wed, 7 Aug 2024 11:55:30 +0800
Subject: [PATCH 1/2] [clang][ASTMatcher] Add matches for StringLiteral which
 matches literals on given RegExp

Add Matcher matchesString.
---
 clang/docs/LibASTMatchersReference.html   | 14 +++
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/ASTMatchers/ASTMatchers.h | 24 +++
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|  1 +
 .../ASTMatchers/ASTMatchersNarrowingTest.cpp  | 22 +
 5 files changed, 63 insertions(+)

diff --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index a16b9c44ef0eab..77b789b1ec4b94 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -5582,6 +5582,20 @@ Narrowing Matchers
 
 
 
+MatcherStringLiteral>matchesStringStringRef RegExp, 
Regex::RegexFlags Flags = NoFlags
+Matches string 
literals that contain a substring matched by the given RegExp
+
+Example matches "foo" and "foobar" but not "bar"
+  (matcher = stringLiteral(matchesString("foo.*")))
+  const char* a = "foo";
+  const char* b = "foobar";
+  const char* c = "bar";
+
+Usable as: Matcher
+
+
+
+
 MatcherStringLiteral>hasSizeunsigned N
 Matches nodes that have the 
specified size.
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7beef7be0e6a53..760d566eabe9e3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -307,6 +307,8 @@ AST Matchers
 - Fixed an issue with the `hasName` and `hasAnyName` matcher when matching
   inline namespaces with an enclosing namespace of the same name.
 
+Add `matchesString` for `StringLiteral` which matches literals on given 
`RegExp`.
+
 clang-format
 
 
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index ca44c3ee085654..bff415294c4561 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3116,6 +3116,30 @@ AST_MATCHER_REGEX(NamedDecl, matchesName, RegExp) {
   return RegExp->match(FullNameString);
 }
 
+/// Matches string literals that contain a substring matched by the given 
RegExp.
+///
+/// Example matches "foo" and "foobar" but not "bar"
+///   (matcher = stringLiteral(matchesString("foo.*")))
+/// \code
+///   const char* a = "foo";
+///   const char* b = "foobar";
+///   const char* c = "bar";
+/// \endcode
+///
+/// Usable as: Matcher
+AST_MATCHER_REGEX(StringLiteral, matchesString, RegExp) {
+  constexpr unsigned StringLength = 64;
+  SmallString Str;
+  llvm::raw_svector_ostream OS(Str);
+  Node.outputString(OS);
+  StringRef OSRef = OS.str();
+  if (OSRef.size() < 2U) {
+return false;
+  }
+  OSRef = OSRef.substr(1, OSRef.size() - 2);
+  return RegExp->match(OSRef);
+}
+
 /// Matches overloaded operator names.
 ///
 /// Matches overloaded operator names specified in strings without the
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 2c75e6beb74301..a3a2515d86be70 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -125,6 +125,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER_OVERLOAD(equals);
 
   REGISTER_REGEX_MATCHER(isExpansionInFileMatching);
+  REGISTER_REGEX_MATCHER(matchesString);
   REGISTER_REGEX_MATCHER(matchesName);
   REGISTER_REGEX_MATCHER(matchesSelector);
 
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 611e1f9ba5327c..2d2b71c5393c58 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2503,6 +2503,28 @@ TEST_P(ASTMatchersTest, IsDelegatingConstructor) {
   cxxConstructorDecl(isDelegatingConstructor(), parameterCountIs(1;
 }
 
+TEST_P(ASTMatchersTest, MatchesString) {
+  StatementMatcher Literal = stringLiteral(matchesString("foo.*"));
+  EXPECT_TRUE(matches("const char* a = \"foo\";", Literal));
+  EXPECT_TRUE(matches("const char* b = \"foobar\";", Literal));
+  EXPECT_TRUE(matches("const char* b = \"fo\"\"obar\";", Literal));
+  EXPECT_TRUE(notMatches("const char* c = \"bar\";", Literal));
+  // test embedded nulls
+  StatementMatcher Literal2 = stringLiteral(matchesString("bar"));
+  EXPECT_TRUE(matches("const char* b = \"foo\\0bar\";", Literal2));
+  EXPECT_TRUE(notMatches("const char* b = \"foo\\0b\\0ar\";", Literal2));
+}
+
+TEST(MatchesString, MatchesStringPrefixed) {
+  StatementMatcher Literal = stringLiteral(matchesString("foo.*"));
+  EXPECT_TRUE(matchesConditionally(

[clang] [clang][ASTMatcher] Add `matchesString` for `StringLiteral` which matches literals on given `RegExp` (PR #102152)

2024-08-14 Thread via cfe-commits


@@ -125,6 +125,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER_OVERLOAD(equals);
 
   REGISTER_REGEX_MATCHER(isExpansionInFileMatching);
+  REGISTER_REGEX_MATCHER(matchesString);
   REGISTER_REGEX_MATCHER(matchesName);
   REGISTER_REGEX_MATCHER(matchesSelector);

Gitspike wrote:

thanks,fixed in 
https://github.com/llvm/llvm-project/pull/102152/commits/df10be46105dfa73278c7a3bd78a02ce21a93f97

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


[clang] [analyzer] Do not reason about locations passed as inline asm input (PR #103714)

2024-08-14 Thread Pavel Skripkin via cfe-commits

https://github.com/pskrgag created 
https://github.com/llvm/llvm-project/pull/103714

If pointer is passed as input operand for inline assembly, it's possible that 
asm block will change memory behind this pointer. So if pointer is passed 
inside inline asm block, it's better to not guess and assume memory has unknown 
state.

Without such change, we observed a lot of FP with hand-written `memcpy` and 
friends.

>From e528b0ded1a9815195e33d141a9e8ce05fb26cd1 Mon Sep 17 00:00:00 2001
From: Pavel Skripkin 
Date: Wed, 14 Aug 2024 10:50:24 +0300
Subject: [PATCH] clang/csa: stop reasoning about pointers passed inside inline
 assembly

---
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp |  8 +
 clang/test/Analysis/asm.cpp  | 36 +++-
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 686310d38ebd58..d64134102d96c7 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3807,6 +3807,14 @@ void ExprEngine::VisitGCCAsmStmt(const GCCAsmStmt *A, 
ExplodedNode *Pred,
   state = state->bindLoc(*LV, UnknownVal(), Pred->getLocationContext());
   }
 
+  // Do not reason about locations passed inside inline assembly.
+  for (const Expr *O : A->inputs()) {
+SVal X = state->getSVal(O, Pred->getLocationContext());
+
+if (std::optional LV = X.getAs())
+  state = state->bindLoc(*LV, UnknownVal(), Pred->getLocationContext());
+  }
+
   Bldr.generateNode(A, Pred, state);
 }
 
diff --git a/clang/test/Analysis/asm.cpp b/clang/test/Analysis/asm.cpp
index 1180063502168f..5d158b62e7221f 100644
--- a/clang/test/Analysis/asm.cpp
+++ b/clang/test/Analysis/asm.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker debug.ExprInspection 
-fheinous-gnu-extensions -w %s -verify
+// RUN: %clang_analyze_cc1 -triple=x86_64-unknown-unknown \
+// RUN:  -analyzer-checker debug.ExprInspection,core 
-fheinous-gnu-extensions -w %s -verify
 
 int clang_analyzer_eval(int);
 
@@ -10,3 +11,36 @@ void testRValueOutput() {
   clang_analyzer_eval(global == 1); // expected-warning{{UNKNOWN}}
   clang_analyzer_eval(ref == 1);// expected-warning{{UNKNOWN}}
 }
+
+void *MyMemcpy(void *d, const void *s, const int n) {
+  asm volatile (
+"cld\n rep movsb\n"
+:: "S" (s), "D" (d), "c" (n) : "memory"
+  );
+
+  return d;
+}
+
+void testInlineAsmMemcpy(void)
+{
+int a, b = 10, c;
+
+MyMemcpy(&a, &b, sizeof(b));
+c = a; // no-warning
+}
+
+void testInlineAsmMemcpyArray(void)
+{
+int a[10], b[10] = {}, c;
+
+MyMemcpy(&a, &b, sizeof(b));
+c = a[8]; // no-warning
+}
+
+void testInlineAsmMemcpyUninit(void)
+{
+int a[10], b[10] = {}, c;
+
+MyMemcpy(&a[1], &b[1], sizeof(b) - sizeof(b[1]));
+c = a[0]; // expected-warning{{Assigned value is garbage or undefined}}
+}

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


[clang] [analyzer] Do not reason about locations passed as inline asm input (PR #103714)

2024-08-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Pavel Skripkin (pskrgag)


Changes

If pointer is passed as input operand for inline assembly, it's possible that 
asm block will change memory behind this pointer. So if pointer is passed 
inside inline asm block, it's better to not guess and assume memory has unknown 
state.

Without such change, we observed a lot of FP with hand-written `memcpy` and 
friends.

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (+8) 
- (modified) clang/test/Analysis/asm.cpp (+35-1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 686310d38ebd58..d64134102d96c7 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3807,6 +3807,14 @@ void ExprEngine::VisitGCCAsmStmt(const GCCAsmStmt *A, 
ExplodedNode *Pred,
   state = state->bindLoc(*LV, UnknownVal(), Pred->getLocationContext());
   }
 
+  // Do not reason about locations passed inside inline assembly.
+  for (const Expr *O : A->inputs()) {
+SVal X = state->getSVal(O, Pred->getLocationContext());
+
+if (std::optional LV = X.getAs())
+  state = state->bindLoc(*LV, UnknownVal(), Pred->getLocationContext());
+  }
+
   Bldr.generateNode(A, Pred, state);
 }
 
diff --git a/clang/test/Analysis/asm.cpp b/clang/test/Analysis/asm.cpp
index 1180063502168f..5d158b62e7221f 100644
--- a/clang/test/Analysis/asm.cpp
+++ b/clang/test/Analysis/asm.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker debug.ExprInspection 
-fheinous-gnu-extensions -w %s -verify
+// RUN: %clang_analyze_cc1 -triple=x86_64-unknown-unknown \
+// RUN:  -analyzer-checker debug.ExprInspection,core 
-fheinous-gnu-extensions -w %s -verify
 
 int clang_analyzer_eval(int);
 
@@ -10,3 +11,36 @@ void testRValueOutput() {
   clang_analyzer_eval(global == 1); // expected-warning{{UNKNOWN}}
   clang_analyzer_eval(ref == 1);// expected-warning{{UNKNOWN}}
 }
+
+void *MyMemcpy(void *d, const void *s, const int n) {
+  asm volatile (
+"cld\n rep movsb\n"
+:: "S" (s), "D" (d), "c" (n) : "memory"
+  );
+
+  return d;
+}
+
+void testInlineAsmMemcpy(void)
+{
+int a, b = 10, c;
+
+MyMemcpy(&a, &b, sizeof(b));
+c = a; // no-warning
+}
+
+void testInlineAsmMemcpyArray(void)
+{
+int a[10], b[10] = {}, c;
+
+MyMemcpy(&a, &b, sizeof(b));
+c = a[8]; // no-warning
+}
+
+void testInlineAsmMemcpyUninit(void)
+{
+int a[10], b[10] = {}, c;
+
+MyMemcpy(&a[1], &b[1], sizeof(b) - sizeof(b[1]));
+c = a[0]; // expected-warning{{Assigned value is garbage or undefined}}
+}

``




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


[clang] 13008aa - [clang][Interp] Diagnose pointer subtraction on zero-size arrays (#103015)

2024-08-14 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-14T10:05:06+02:00
New Revision: 13008aa45d406a65ee7adfc7672a038e4def1ad3

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

LOG: [clang][Interp] Diagnose pointer subtraction on zero-size arrays (#103015)

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Pointer.h
clang/test/AST/Interp/arrays.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 67b3fc50645097..3eab0cfd871385 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1987,6 +1987,22 @@ inline bool SubPtr(InterpState &S, CodePtr OpPC) {
   const Pointer &LHS = S.Stk.pop();
   const Pointer &RHS = S.Stk.pop();
 
+  for (const Pointer &P : {LHS, RHS}) {
+if (P.isZeroSizeArray()) {
+  QualType PtrT = P.getType();
+  while (auto *AT = dyn_cast(PtrT))
+PtrT = AT->getElementType();
+
+  QualType ArrayTy = S.getCtx().getConstantArrayType(
+  PtrT, APInt::getZero(1), nullptr, ArraySizeModifier::Normal, 0);
+  S.FFDiag(S.Current->getSource(OpPC),
+   diag::note_constexpr_pointer_subtraction_zero_size)
+  << ArrayTy;
+
+  return false;
+}
+  }
+
   if (RHS.isZero()) {
 S.Stk.push(T::from(LHS.getIndex()));
 return true;

diff  --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index 07ff8025ba9541..01ccb88ec03b29 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -613,7 +613,11 @@ class Pointer {
   bool isElementPastEnd() const { return Offset == PastEndMark; }
 
   /// Checks if the pointer is pointing to a zero-size array.
-  bool isZeroSizeArray() const { return getFieldDesc()->isZeroSizeArray(); }
+  bool isZeroSizeArray() const {
+if (const auto *Desc = getFieldDesc())
+  return Desc->isZeroSizeArray();
+return false;
+  }
 
   /// Dereferences the pointer, if it's live.
   template  T &deref() const {

diff  --git a/clang/test/AST/Interp/arrays.cpp 
b/clang/test/AST/Interp/arrays.cpp
index 98cd17276e0a06..47706bedcf3f0c 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -632,3 +632,16 @@ constexpr int fail(const int &p) {
 }
 static_assert(fail(*(&(&(*(*&(&zs[2] - 1)[0] + 2 - 2))[2])[-1][2] - 2)) == 11, 
""); // both-error {{not an integral constant expression}} \

 // both-note {{in call to}}
+
+namespace ZeroSizeTypes {
+  constexpr int (*p1)[0] = 0, (*p2)[0] = 0;
+  constexpr int k = p2 - p1; // both-error {{constexpr variable 'k' must be 
initialized by a constant expression}} \
+ // both-note {{subtraction of pointers to type 
'int[0]' of zero size}} \
+ // both-warning {{subtraction of pointers to type 
'int[0]' of zero size has undefined behavior}}
+
+  int arr[5][0];
+  constexpr int f() { // both-error {{never produces a constant expression}}
+return &arr[3] - &arr[0]; // both-note {{subtraction of pointers to type 
'int[0]' of zero size}} \
+  // both-warning {{subtraction of pointers to 
type 'int[0]' of zero size has undefined behavior}}
+  }
+}



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


[clang] [clang][Interp] Diagnose pointer subtraction on zero-size arrays (PR #103015)

2024-08-14 Thread Timm Baeder via cfe-commits

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


[clang] [llvm] Add normalize builtins and normalize HLSL function to DirectX and SPIR-V backend (PR #102683)

2024-08-14 Thread Mikael Holmén via cfe-commits


@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -verify-ignore-unexpected

mikaelholmen wrote:

Hi @bob80905 
I think this "-emit-llvm -disable-llvm-passes" will make the test write to the 
local filesystem?
Can we try to avoid that, e.g. by just removing "-emit-llvm"?
See e.g. b7730a23efb2 which fixed a similar case recently.

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


[clang] [llvm] [RISCV][MC] Support experimental extensions Zvbc32e and Zvkgs (PR #103709)

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


@@ -302,6 +302,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zicfilp``, ``experimental-zicfiss``
   LLVM implements the `1.0 release specification 
`__.
 
+``experimental-zvbc32e``, ``experimental-zvkgs``
+  LLVM implements the `0.7 release specification 
`__.

dtcxzyw wrote:

Can you replace this link with a github repo url+tag?


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


[clang] [llvm] [RISCV][MC] Support experimental extensions Zvbc32e and Zvkgs (PR #103709)

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


@@ -150,6 +150,14 @@ let Predicates = [HasStdExtZvkg], RVVConstraint = 
NoConstraint in {
  SchedBinaryMC<"WriteVGMULV", "ReadVGMULV", "ReadVGMULV">;
 } // Predicates = [HasStdExtZvkg]
 
+let Predicates = [HasStdExtZvkgs], RVVConstraint = NoConstraint in {

dtcxzyw wrote:

```suggestion
let Predicates = [HasStdExtZvkgs], RVVConstraint = VS2Constraint in {
```
Reserved Encodings
+ SEW is any value other than 32
+ **the vd register group overlaps the vs2 scalar element group**

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


[clang] [clang] Add lifetimebound attr to std::span/std::string_view constructor (PR #103716)

2024-08-14 Thread Haojian Wu via cfe-commits

https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/103716

With this patch, clang now automatically adds ``[[clang::lifetimebound]]`` to 
the parameters of `std::span, std::string_view` constructors, this enables 
Clang to capture more cases where the returned reference outlives the object.


Fixes #100567 

>From babf10959b465f96540f9c94a5d45953596dedeb Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Wed, 14 Aug 2024 10:18:09 +0200
Subject: [PATCH] [clang] Add lifetimebound attr to std::span/std::string_view
 constructor

With this patch, clang now automatically adds ``[[clang::lifetimebound]]``
to the parameters of ``std::span, std::string_view`` constructors, this
enables Clang to capture more cases where the returned reference outlives the 
object.
---
 clang/docs/ReleaseNotes.rst   |  5 +++
 clang/include/clang/Sema/Sema.h   |  3 ++
 clang/lib/Sema/SemaAttr.cpp   | 53 +++
 clang/lib/Sema/SemaDecl.cpp   | 20 +
 clang/test/SemaCXX/attr-lifetimebound.cpp | 21 +
 5 files changed, 83 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 39e1b0fcb09bbd..63ba5c4494b93e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -151,6 +151,11 @@ Attribute Changes in Clang
 - The ``hybrid_patchable`` attribute is now supported on ARM64EC targets. It 
can be used to specify
   that a function requires an additional x86-64 thunk, which may be patched at 
runtime.
 
+- Clang now automatically adds ``[[clang::lifetimebound]]`` to the parameters 
of
+  ``std::span, std::string_view`` constructors, this enables Clang to capture
+  more cases where the returned reference outlives the object.
+  (#GH100567)
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 25cb6c8fbf6104..a4e6c98ec66884 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1827,6 +1827,9 @@ class Sema final : public SemaBase {
   /// Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types.
   void inferGslOwnerPointerAttribute(CXXRecordDecl *Record);
 
+  /// Add [[clang:::lifetimebound]] attr for std:: functions and methods.
+  void inferLifetimeBoundAttribute(FunctionDecl *FD);
+
   /// Add [[gsl::Pointer]] attributes for std:: types.
   void inferGslPointerAttribute(TypedefNameDecl *TD);
 
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index b0c239678d0b01..fb83d56c2273ea 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -216,6 +216,59 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl 
*Record) {
   inferGslPointerAttribute(Record, Record);
 }
 
+void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
+  if (FD->getNumParams() == 0)
+return;
+
+  if (unsigned BuiltinID = FD->getBuiltinID()) {
+// Add lifetime attribute to std::move, std::fowrard et al.
+switch (BuiltinID) {
+case Builtin::BIaddressof:
+case Builtin::BI__addressof:
+case Builtin::BI__builtin_addressof:
+case Builtin::BIas_const:
+case Builtin::BIforward:
+case Builtin::BIforward_like:
+case Builtin::BImove:
+case Builtin::BImove_if_noexcept:
+  if (ParmVarDecl *P = FD->getParamDecl(0u);
+  !P->hasAttr())
+P->addAttr(
+LifetimeBoundAttr::CreateImplicit(Context, FD->getLocation()));
+  break;
+default:
+  break;
+}
+return;
+  }
+  if (auto *CMD = dyn_cast(FD)) {
+const auto *CRD = CMD->getParent();
+if (!CRD->isInStdNamespace() || !CRD->getIdentifier())
+  return;
+
+if (isa(CMD)) {
+  auto *Param = CMD->getParamDecl(0);
+  if (Param->hasAttr())
+return;
+  if (CRD->getName() == "basic_string_view" &&
+  Param->getType()->isPointerType()) {
+// construct from a char array pointed by a pointer.
+//   basic_string_view(const CharT* s);
+//   basic_string_view(const CharT* s, size_type count);
+Param->addAttr(
+LifetimeBoundAttr::CreateImplicit(Context, FD->getLocation()));
+  } else if (CRD->getName() == "span") {
+// construct from a reference of array.
+//   span(std::type_identity_t (&arr)[N]);
+const auto *LRT = Param->getType()->getAs();
+if (LRT && LRT->getPointeeType().IgnoreParens()->isArrayType())
+  Param->addAttr(
+  LifetimeBoundAttr::CreateImplicit(Context, FD->getLocation()));
+  }
+}
+  }
+}
+
 void Sema::inferNullableClassAttribute(CXXRecordDecl *CRD) {
   static const llvm::StringSet<> Nullable{
   "auto_ptr", "shared_ptr", "unique_ptr", "exception_ptr",
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 641b180527da55..6a79231fb3bd71 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang

[clang] [clang] Add lifetimebound attr to std::span/std::string_view constructor (PR #103716)

2024-08-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes

With this patch, clang now automatically adds ``[[clang::lifetimebound]]`` to 
the parameters of `std::span, std::string_view` constructors, this enables 
Clang to capture more cases where the returned reference outlives the object.


Fixes #100567 

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


5 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+5) 
- (modified) clang/include/clang/Sema/Sema.h (+3) 
- (modified) clang/lib/Sema/SemaAttr.cpp (+53) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+1-19) 
- (modified) clang/test/SemaCXX/attr-lifetimebound.cpp (+21) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 39e1b0fcb09bbd..63ba5c4494b93e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -151,6 +151,11 @@ Attribute Changes in Clang
 - The ``hybrid_patchable`` attribute is now supported on ARM64EC targets. It 
can be used to specify
   that a function requires an additional x86-64 thunk, which may be patched at 
runtime.
 
+- Clang now automatically adds ``[[clang::lifetimebound]]`` to the parameters 
of
+  ``std::span, std::string_view`` constructors, this enables Clang to capture
+  more cases where the returned reference outlives the object.
+  (#GH100567)
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 25cb6c8fbf6104..a4e6c98ec66884 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1827,6 +1827,9 @@ class Sema final : public SemaBase {
   /// Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types.
   void inferGslOwnerPointerAttribute(CXXRecordDecl *Record);
 
+  /// Add [[clang:::lifetimebound]] attr for std:: functions and methods.
+  void inferLifetimeBoundAttribute(FunctionDecl *FD);
+
   /// Add [[gsl::Pointer]] attributes for std:: types.
   void inferGslPointerAttribute(TypedefNameDecl *TD);
 
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index b0c239678d0b01..fb83d56c2273ea 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -216,6 +216,59 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl 
*Record) {
   inferGslPointerAttribute(Record, Record);
 }
 
+void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
+  if (FD->getNumParams() == 0)
+return;
+
+  if (unsigned BuiltinID = FD->getBuiltinID()) {
+// Add lifetime attribute to std::move, std::fowrard et al.
+switch (BuiltinID) {
+case Builtin::BIaddressof:
+case Builtin::BI__addressof:
+case Builtin::BI__builtin_addressof:
+case Builtin::BIas_const:
+case Builtin::BIforward:
+case Builtin::BIforward_like:
+case Builtin::BImove:
+case Builtin::BImove_if_noexcept:
+  if (ParmVarDecl *P = FD->getParamDecl(0u);
+  !P->hasAttr())
+P->addAttr(
+LifetimeBoundAttr::CreateImplicit(Context, FD->getLocation()));
+  break;
+default:
+  break;
+}
+return;
+  }
+  if (auto *CMD = dyn_cast(FD)) {
+const auto *CRD = CMD->getParent();
+if (!CRD->isInStdNamespace() || !CRD->getIdentifier())
+  return;
+
+if (isa(CMD)) {
+  auto *Param = CMD->getParamDecl(0);
+  if (Param->hasAttr())
+return;
+  if (CRD->getName() == "basic_string_view" &&
+  Param->getType()->isPointerType()) {
+// construct from a char array pointed by a pointer.
+//   basic_string_view(const CharT* s);
+//   basic_string_view(const CharT* s, size_type count);
+Param->addAttr(
+LifetimeBoundAttr::CreateImplicit(Context, FD->getLocation()));
+  } else if (CRD->getName() == "span") {
+// construct from a reference of array.
+//   span(std::type_identity_t (&arr)[N]);
+const auto *LRT = Param->getType()->getAs();
+if (LRT && LRT->getPointeeType().IgnoreParens()->isArrayType())
+  Param->addAttr(
+  LifetimeBoundAttr::CreateImplicit(Context, FD->getLocation()));
+  }
+}
+  }
+}
+
 void Sema::inferNullableClassAttribute(CXXRecordDecl *CRD) {
   static const llvm::StringSet<> Nullable{
   "auto_ptr", "shared_ptr", "unique_ptr", "exception_ptr",
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 641b180527da55..6a79231fb3bd71 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16593,27 +16593,9 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl 
*FD) {
 default:
   break;
 }
-
-// Add lifetime attribute to std::move, std::fowrard et al.
-switch (BuiltinID) {
-case Builtin::BIaddressof:
-case Builtin::BI__addressof:
-case Builtin::BI__builtin_addressof:
-case Builtin::BIas_const:
-case Builtin::BIforward:
-case Builtin::BIforward_lik

[clang] [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (PR #96804)

2024-08-14 Thread Owen Pan via cfe-commits


@@ -497,6 +497,16 @@ template <> struct 
MappingTraits {
   }
 };
 
+template <> struct ScalarEnumerationTraits {
+  static void enumeration(IO &IO, FormatStyle::ReflowCommentsStyle &Value) {
+IO.enumCase(Value, "Never", FormatStyle::RCS_Never);
+IO.enumCase(Value, "IndentOnly", FormatStyle::RCS_IndentOnly);
+IO.enumCase(Value, "Always", FormatStyle::RCS_Always);

owenca wrote:

```suggestion
IO.enumCase(Value, "Always", FormatStyle::RCS_Always);
// For backward compatibility:
```

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


[clang] [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (PR #96804)

2024-08-14 Thread Owen Pan via cfe-commits


@@ -3750,24 +3750,43 @@ struct FormatStyle {
   ReferenceAlignmentStyle ReferenceAlignment;
 
   // clang-format off
-  /// If ``true``, clang-format will attempt to re-flow comments. That is it
-  /// will touch a comment and *reflow* long comments into new lines, trying to
-  /// obey the ``ColumnLimit``.
-  /// \code
-  ///false:
-  ///// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with 
plenty of information
-  ////* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment 
with plenty of information */
-  ///
-  ///true:
-  ///// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with 
plenty of
-  ///// information
-  ////* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment 
with plenty of
-  /// * information */
-  /// \endcode
-  /// \version 3.8
-  bool ReflowComments;
+  /// \brief Types of comment re-flow style.

owenca wrote:

```suggestion
  /// \brief Types of comment reflow style.
```

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


[clang] [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (PR #96804)

2024-08-14 Thread Owen Pan via cfe-commits


@@ -4588,11 +4588,11 @@ bool UnwrappedLineParser::isOnNewLine(const FormatToken 
&FormatTok) {
 
 // Checks if \p FormatTok is a line comment that continues the line comment
 // section on \p Line.
-static bool
-continuesLineCommentSection(const FormatToken &FormatTok,
-const UnwrappedLine &Line,
-const llvm::Regex &CommentPragmasRegex) {
-  if (Line.Tokens.empty())
+static bool continuesLineCommentSection(
+const FormatToken &FormatTok, const UnwrappedLine &Line,
+const FormatStyle::ReflowCommentsStyle ReflowCommentsStyle,
+const llvm::Regex &CommentPragmasRegex) {
+  if (Line.Tokens.empty() || ReflowCommentsStyle != FormatStyle::RCS_Always)

owenca wrote:

```suggestion
  if (Line.Tokens.empty() || Style.ReflowComments != FormatStyle::RCS_Always)
```

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


[clang] [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (PR #96804)

2024-08-14 Thread Owen Pan via cfe-commits


@@ -4588,11 +4588,11 @@ bool UnwrappedLineParser::isOnNewLine(const FormatToken 
&FormatTok) {
 
 // Checks if \p FormatTok is a line comment that continues the line comment
 // section on \p Line.
-static bool
-continuesLineCommentSection(const FormatToken &FormatTok,
-const UnwrappedLine &Line,
-const llvm::Regex &CommentPragmasRegex) {
-  if (Line.Tokens.empty())
+static bool continuesLineCommentSection(
+const FormatToken &FormatTok, const UnwrappedLine &Line,
+const FormatStyle::ReflowCommentsStyle ReflowCommentsStyle,

owenca wrote:

```suggestion
const FormatStyle &Style,
```

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


[clang] [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (PR #96804)

2024-08-14 Thread Owen Pan via cfe-commits


@@ -855,7 +859,8 @@ bool BreakableBlockComment::mayReflow(
   StringRef IndentContent = Content[LineIndex];
   if (Lines[LineIndex].ltrim(Blanks).starts_with("*"))
 IndentContent = Lines[LineIndex].ltrim(Blanks).substr(1);
-  return LineIndex > 0 && !CommentPragmasRegex.match(IndentContent) &&
+  return LineIndex > 0 && Style.ReflowComments == FormatStyle::RCS_Always &&

owenca wrote:

```suggestion
  return LineIndex > 0 && AlwaysReflow &&
```

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


[clang] [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (PR #96804)

2024-08-14 Thread Owen Pan via cfe-commits


@@ -420,8 +420,10 @@ BreakableComment::getSplit(unsigned LineIndex, unsigned 
TailOffset,
unsigned ColumnLimit, unsigned ContentStartColumn,
const llvm::Regex &CommentPragmasRegex) const {
   // Don't break lines matching the comment pragmas regex.
-  if (CommentPragmasRegex.match(Content[LineIndex]))
+  if (Style.ReflowComments != FormatStyle::RCS_Always ||

owenca wrote:

```suggestion
  if (!AlwaysReflow ||
```
after adding the following to `BreakableToken.h`:
```c++
@@ -393,6 +393,8 @@ protected:
   // and not:
   // // comment 1comment 2
   StringRef ReflowPrefix = " ";
+
+  const bool AlwaysReflow = Style.ReflowComments == FormatStyle::RCS_Always;
 };
 
 class BreakableBlockComment : public BreakableComment {
```

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


[clang] [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (PR #96804)

2024-08-14 Thread Owen Pan via cfe-commits


@@ -493,9 +493,36 @@ TEST_F(FormatTestComments, AlignsBlockComments) {
 
 TEST_F(FormatTestComments, CommentReflowingCanBeTurnedOff) {
   FormatStyle Style = getLLVMStyleWithColumns(20);
-  Style.ReflowComments = false;
-  verifyFormat("// a aa aa", Style);
-  verifyFormat("/* a aa aa */", Style);
+  Style.ReflowComments = FormatStyle::RCS_Never;
+  verifyNoChange("// a aa aa", Style);
+  verifyNoChange("/* a aa aa */", Style);
+  verifyNoChange("/* a aa aa\n"
+ "a*/",
+ Style);
+  verifyNoChange("/* a aa aa\n"
+ "a*/",
+ Style);
+  verifyNoChange("/* a aa aa\n"
+ " *a*/",
+ Style);
+}
+
+TEST_F(FormatTestComments, CommentReflowingCanApplyOnlyToIndents) {
+  FormatStyle Style = getLLVMStyleWithColumns(20);
+  Style.ReflowComments = FormatStyle::RCS_IndentOnly;
+  verifyNoChange("// a aa aa", Style);
+  verifyNoChange("/* a aa aa */", Style);

owenca wrote:

```suggestion
  verifyFormat("// a aa aa", Style);
  verifyFormat("/* a aa aa */", Style);
```

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


[clang] [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (PR #96804)

2024-08-14 Thread Owen Pan via cfe-commits


@@ -1160,7 +1165,8 @@ bool BreakableLineCommentSection::mayReflow(
   // // text that protrudes
   // //into text with different indent
   // We do reflow in that case in block comments.
-  return LineIndex > 0 && !CommentPragmasRegex.match(IndentContent) &&
+  return LineIndex > 0 && Style.ReflowComments == FormatStyle::RCS_Always &&

owenca wrote:

Ditto.

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


[clang] [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (PR #96804)

2024-08-14 Thread Owen Pan via cfe-commits


@@ -608,8 +610,10 @@ BreakableToken::Split BreakableBlockComment::getSplit(
 unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit,
 unsigned ContentStartColumn, const llvm::Regex &CommentPragmasRegex) const 
{
   // Don't break lines matching the comment pragmas regex.
-  if (CommentPragmasRegex.match(Content[LineIndex]))
+  if (Style.ReflowComments != FormatStyle::RCS_Always ||

owenca wrote:

Ditto.

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


[clang] [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (PR #96804)

2024-08-14 Thread Owen Pan via cfe-commits


@@ -4778,8 +4778,8 @@ void UnwrappedLineParser::distributeComments(
 if (HasTrailAlignedWithNextToken && i == StartOfTrailAlignedWithNextToken) 
{
   FormatTok->ContinuesLineCommentSection = false;
 } else {
-  FormatTok->ContinuesLineCommentSection =
-  continuesLineCommentSection(*FormatTok, *Line, CommentPragmasRegex);
+  FormatTok->ContinuesLineCommentSection = continuesLineCommentSection(
+  *FormatTok, *Line, Style.ReflowComments, CommentPragmasRegex);

owenca wrote:

```suggestion
  *FormatTok, *Line, Style, CommentPragmasRegex);
```

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


[clang] [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (PR #96804)

2024-08-14 Thread Owen Pan via cfe-commits


@@ -3750,24 +3750,43 @@ struct FormatStyle {
   ReferenceAlignmentStyle ReferenceAlignment;
 
   // clang-format off
-  /// If ``true``, clang-format will attempt to re-flow comments. That is it
-  /// will touch a comment and *reflow* long comments into new lines, trying to
-  /// obey the ``ColumnLimit``.
-  /// \code
-  ///false:
-  ///// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with 
plenty of information
-  ////* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment 
with plenty of information */
-  ///
-  ///true:
-  ///// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with 
plenty of
-  ///// information
-  ////* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment 
with plenty of
-  /// * information */
-  /// \endcode
-  /// \version 3.8
-  bool ReflowComments;
+  /// \brief Types of comment re-flow style.
+  enum ReflowCommentsStyle : int8_t {
+/// Leave comments untouched.
+/// \code
+///// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with 
plenty of information
+////* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment 
with plenty of information */
+////* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment 
with plenty of information
+/// * and a misaligned second line */
+/// \endcode
+RCS_Never,
+/// Only apply indentation rules, moving comments left or right, without
+/// changing formatting inside the comments.
+/// \code
+///// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with 
plenty of information
+////* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment 
with plenty of information */
+////* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment 
with plenty of information
+/// * and a misaligned second line */
+/// \endcode
+RCS_IndentOnly,
+/// Apply indentation rules and re-flow long comments into new lines, 
trying

owenca wrote:

```suggestion
/// Apply indentation rules and reflow long comments into new lines, trying
```

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


[clang] [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (PR #96804)

2024-08-14 Thread Owen Pan via cfe-commits


@@ -493,9 +493,36 @@ TEST_F(FormatTestComments, AlignsBlockComments) {
 
 TEST_F(FormatTestComments, CommentReflowingCanBeTurnedOff) {
   FormatStyle Style = getLLVMStyleWithColumns(20);
-  Style.ReflowComments = false;
-  verifyFormat("// a aa aa", Style);
-  verifyFormat("/* a aa aa */", Style);
+  Style.ReflowComments = FormatStyle::RCS_Never;
+  verifyNoChange("// a aa aa", Style);
+  verifyNoChange("/* a aa aa */", Style);

owenca wrote:

```suggestion
  verifyFormat("// a aa aa", Style);
  verifyFormat("/* a aa aa */", Style);
```

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


[clang] [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (PR #96804)

2024-08-14 Thread Owen Pan via cfe-commits


@@ -4704,8 +4704,8 @@ void UnwrappedLineParser::flushComments(bool 
NewlineBeforeNext) {
 //
 // FIXME: Consider putting separate line comment sections as children to 
the
 // unwrapped line instead.
-Tok->ContinuesLineCommentSection =
-continuesLineCommentSection(*Tok, *Line, CommentPragmasRegex);
+Tok->ContinuesLineCommentSection = continuesLineCommentSection(
+*Tok, *Line, Style.ReflowComments, CommentPragmasRegex);

owenca wrote:

```suggestion
*Tok, *Line, Style, CommentPragmasRegex);
```

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


[clang] [llvm] [RISCV][MC] Support experimental extensions Zvbc32e and Zvkgs (PR #103709)

2024-08-14 Thread Pengcheng Wang via cfe-commits


@@ -302,6 +302,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zicfilp``, ``experimental-zicfiss``
   LLVM implements the `1.0 release specification 
`__.
 
+``experimental-zvbc32e``, ``experimental-zvkgs``
+  LLVM implements the `0.7 release specification 
`__.

wangpc-pp wrote:

Actually, there is no repo&tag. They are in a pull request.

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


[clang] [llvm] [RISCV][MC] Support experimental extensions Zvbc32e and Zvkgs (PR #103709)

2024-08-14 Thread Pengcheng Wang via cfe-commits


@@ -150,6 +150,14 @@ let Predicates = [HasStdExtZvkg], RVVConstraint = 
NoConstraint in {
  SchedBinaryMC<"WriteVGMULV", "ReadVGMULV", "ReadVGMULV">;
 } // Predicates = [HasStdExtZvkg]
 
+let Predicates = [HasStdExtZvkgs], RVVConstraint = NoConstraint in {

wangpc-pp wrote:

Oops, I think we should set this for `vghsh.vv` and `vgmul.vv` as well. cc 
@4vtomat 

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


[clang] [llvm] [analyzer] Delete `alpha.security.MallocOverflow` (PR #103059)

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


@@ -1039,10 +1039,6 @@ def ArrayBoundCheckerV2 : Checker<"ArrayBoundV2">,
   HelpText<"Warn about buffer overflows (newer checker)">,
   Documentation;
 
-def MallocOverflowSecurityChecker : Checker<"MallocOverflow">,

NagyDonat wrote:

Is it possible to write a "this checker no longer exists, but references to its 
name should not be an error" placeholder in this TD file?

If you readily know a solution, I'd be happy to add it, but I don't want to 
spend time on researching it.

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


[clang] [clang][AArch64] Point the nofp ABI check diagnostics at the callee (PR #103392)

2024-08-14 Thread Oliver Stannard via cfe-commits

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

LGTM

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


[clang] [C++20] [Modules] Merge lambdas from Sema to imported one (PR #103036)

2024-08-14 Thread Chuanqi Xu via cfe-commits

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


[clang] [clang][ExtractAPI] Compute inherited availability information (PR #103040)

2024-08-14 Thread Daniel Grumberg via cfe-commits

daniel-grumberg wrote:

> > Additionally this computes availability information for all platforms ahead
> 
> Can you add a test for this?

The behavior is not exposed yet so I can't add a test, will do when I start 
exposing the behavior.

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


[clang] [clang][ExtractAPI] Compute inherited availability information (PR #103040)

2024-08-14 Thread Daniel Grumberg via cfe-commits


@@ -0,0 +1,149 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -extract-api --pretty-sgf 
--emit-sgf-symbol-labels-for-testing -triple arm64-apple-macosx \
+// RUN:   -x objective-c-header %s -o %t/output.symbols.json -verify
+
+
+// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix A
+__attribute__((availability(macos, introduced=9.0, deprecated=12.0, 
obsoleted=20.0)))
+@interface A

daniel-grumberg wrote:

It walks DeclContext's upwards to find one to compute the most restrictive 
information. If the are no other annotations for that platform walking upwards 
then it is just the one in the availability annotation. I realized that the 
existing availability test case doesn't cover this, thanks for pointing it out 
I will add a test to validate this behavior.

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


[clang] [Clang] Implement C++26’s P2893R3 ‘Variadic friends’ (PR #101448)

2024-08-14 Thread via cfe-commits

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


[clang] [Clang] Implement C++26’s P2893R3 ‘Variadic friends’ (PR #101448)

2024-08-14 Thread via cfe-commits


@@ -17509,8 +17528,17 @@ Decl *Sema::ActOnFriendTypeDecl(Scope *S, const 
DeclSpec &DS,
   if (TheDeclarator.isInvalidType())
 return nullptr;
 
-  if (DiagnoseUnexpandedParameterPack(Loc, TSI, UPPC_FriendDeclaration))
+  // If '...' is present, the type must contain an unexpanded parameter
+  // pack, and vice versa.
+  if (EllipsisLoc.isInvalid() &&
+  DiagnoseUnexpandedParameterPack(Loc, TSI, UPPC_FriendDeclaration))
 return nullptr;
+  if (EllipsisLoc.isValid() &&
+  !TSI->getType()->containsUnexpandedParameterPack()) {
+Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
+<< TSI->getTypeLoc().getSourceRange();
+EllipsisLoc = SourceLocation();

cor3ntin wrote:

Should we mark D as an invalidDecl instead?

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


[clang] [Clang] Implement C++26’s P2893R3 ‘Variadic friends’ (PR #101448)

2024-08-14 Thread via cfe-commits

https://github.com/cor3ntin commented:

Can you make a separate pr to update the unrelated changes to cxx_status?
I think we are pretty close to be able to land this

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


[clang] [Clang] Implement C++26’s P2893R3 ‘Variadic friends’ (PR #101448)

2024-08-14 Thread via cfe-commits


@@ -17556,11 +17584,12 @@ Decl *Sema::ActOnFriendTypeDecl(Scope *S, const 
DeclSpec &DS,
 
   Decl *D;
   if (!TempParams.empty())
+// TODO: Support variadic friend template decls?

cor3ntin wrote:

Can we create an issue for that?

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


[clang] c4206f1 - [RISCV][compiler-rt] Update __init_riscv_feature_bits prototype (#101472)

2024-08-14 Thread via cfe-commits

Author: Piyou Chen
Date: 2024-08-14T17:30:53+08:00
New Revision: c4206f1ff1d946c495b74738eba9303dafb17e18

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

LOG: [RISCV][compiler-rt] Update __init_riscv_feature_bits prototype (#101472)

This patch add `void* PlatformArgs` parameter to
`__init_riscv_feature_bits`. `PlatformArgs` allows the platform to
provide pre-computed data and access it without extra effort. For
example, Linux could pass the vDSO object to avoid an extra system call.

```
__init_riscv_feature_bits()

->

__init_riscv_feature_bits(void *PlatformArgs)
```

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtin-cpu-supports.c
compiler-rt/lib/builtins/cpu_model/riscv.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bfae7f8abdb50a..b5e5240e55be3f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -14370,13 +14370,13 @@ Value *CodeGenFunction::EmitAArch64CpuInit() {
 }
 
 Value *CodeGenFunction::EmitRISCVCpuInit() {
-  llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
+  llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, {VoidPtrTy}, 
false);
   llvm::FunctionCallee Func =
   CGM.CreateRuntimeFunction(FTy, "__init_riscv_feature_bits");
   auto *CalleeGV = cast(Func.getCallee());
   CalleeGV->setDSOLocal(true);
   CalleeGV->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
-  return Builder.CreateCall(Func);
+  return Builder.CreateCall(Func, {llvm::ConstantPointerNull::get(VoidPtrTy)});
 }
 
 Value *CodeGenFunction::EmitX86CpuInit() {

diff  --git a/clang/test/CodeGen/builtin-cpu-supports.c 
b/clang/test/CodeGen/builtin-cpu-supports.c
index 071d627b7181b5..b252484fc3df95 100644
--- a/clang/test/CodeGen/builtin-cpu-supports.c
+++ b/clang/test/CodeGen/builtin-cpu-supports.c
@@ -250,7 +250,7 @@ int test_ppc(int a) {
 // CHECK-RV32-NEXT:[[RETVAL:%.*]] = alloca i32, align 4
 // CHECK-RV32-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
 // CHECK-RV32-NEXT:store i32 [[A]], ptr [[A_ADDR]], align 4
-// CHECK-RV32-NEXT:call void @__init_riscv_feature_bits()
+// CHECK-RV32-NEXT:call void @__init_riscv_feature_bits(ptr null)
 // CHECK-RV32-NEXT:[[TMP0:%.*]] = load i64, ptr getelementptr inbounds ({ 
i32, [1 x i64] }, ptr @__riscv_feature_bits, i32 0, i32 1, i32 0), align 8
 // CHECK-RV32-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 1
 // CHECK-RV32-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 1
@@ -301,7 +301,7 @@ int test_ppc(int a) {
 // CHECK-RV64-NEXT:[[RETVAL:%.*]] = alloca i32, align 4
 // CHECK-RV64-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
 // CHECK-RV64-NEXT:store i32 [[A]], ptr [[A_ADDR]], align 4
-// CHECK-RV64-NEXT:call void @__init_riscv_feature_bits()
+// CHECK-RV64-NEXT:call void @__init_riscv_feature_bits(ptr null)
 // CHECK-RV64-NEXT:[[TMP0:%.*]] = load i64, ptr getelementptr inbounds ({ 
i32, [1 x i64] }, ptr @__riscv_feature_bits, i32 0, i32 1, i32 0), align 8
 // CHECK-RV64-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 1
 // CHECK-RV64-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 1

diff  --git a/compiler-rt/lib/builtins/cpu_model/riscv.c 
b/compiler-rt/lib/builtins/cpu_model/riscv.c
index 0c443025b74c63..05c36b3d9e39ea 100644
--- a/compiler-rt/lib/builtins/cpu_model/riscv.c
+++ b/compiler-rt/lib/builtins/cpu_model/riscv.c
@@ -328,14 +328,18 @@ static void initRISCVFeature(struct riscv_hwprobe 
Hwprobes[]) {
 
 static int FeaturesBitCached = 0;
 
-void __init_riscv_feature_bits() CONSTRUCTOR_ATTRIBUTE;
+void __init_riscv_feature_bits(void *) CONSTRUCTOR_ATTRIBUTE;
 
 // A constructor function that sets __riscv_feature_bits, and
 // __riscv_vendor_feature_bits to the right values.  This needs to run
 // only once.  This constructor is given the highest priority and it should
 // run before constructors without the priority set.  However, it still runs
 // after ifunc initializers and needs to be called explicitly there.
-void CONSTRUCTOR_ATTRIBUTE __init_riscv_feature_bits() {
+
+// PlatformArgs allows the platform to provide pre-computed data and access it
+// without extra effort. For example, Linux could pass the vDSO object to avoid
+// an extra system call.
+void CONSTRUCTOR_ATTRIBUTE __init_riscv_feature_bits(void *PlatformArgs) {
 
   if (FeaturesBitCached)
 return;



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


[clang] [compiler-rt] [RISCV][compiler-rt] Update __init_riscv_feature_bits prototype (PR #101472)

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

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


[clang] [clang][ExtractAPI] Compute inherited availability information (PR #103040)

2024-08-14 Thread Daniel Grumberg via cfe-commits


@@ -16,33 +16,101 @@
 #include "clang/AST/Decl.h"
 #include "clang/Basic/TargetInfo.h"
 
-namespace clang {
+namespace {
+
+struct AvailabilitySet {
+  llvm::SmallVector Availabilities;
+  bool UnconditionallyDeprecated = false;
+  bool UnconditionallyUnavailable = false;
 
-AvailabilityInfo AvailabilityInfo::createFromDecl(const Decl *Decl) {
-  ASTContext &Context = Decl->getASTContext();
-  StringRef PlatformName = Context.getTargetInfo().getPlatformName();
-  AvailabilityInfo Availability;
+  void insert(clang::AvailabilityInfo &&Availability) {
+auto *Found = getForPlatform(Availability.Domain);
+if (Found)
+  Found->mergeWith(std::move(Availability));
+else
+  Availabilities.emplace_back(std::move(Availability));
+  }
+
+  clang::AvailabilityInfo *getForPlatform(llvm::StringRef Domain) {

daniel-grumberg wrote:

The semantic is that you get a reference of the thing inside the Availabilities 
vector if it exist (this method is used by `insert` and not just 
`AvailabilityInfo::createFromDecl`), to express that with 
`std::optional` which doesn't exist.

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-08-14 Thread via cfe-commits

https://github.com/MichelleCDjunaidi updated 
https://github.com/llvm/llvm-project/pull/102299

>From 75306bd83eb43d0606630f9f059fc04ad1b20b06 Mon Sep 17 00:00:00 2001
From: Michelle C Djunaidi 
Date: Wed, 7 Aug 2024 13:10:02 +0800
Subject: [PATCH 1/8] [clang-tidy] Add bugprone-public-enable-shared-from-this
 check

This check identifies classes deriving from std::enable_shared_from_this that 
does not inherit with the public keyword,
which may cause problems when std::make_shared is called for that class.
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../PublicEnableSharedFromThisCheck.cpp   | 45 +++
 .../PublicEnableSharedFromThisCheck.h | 33 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../bugprone/public-enable-shared-from-this   |  6 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../public-enable-shared-from-this.cpp| 56 +++
 8 files changed, 150 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/public-enable-shared-from-this
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/public-enable-shared-from-this.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 689eb92a3d8d17..f12f0cd1c47da3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -53,6 +53,7 @@
 #include "ParentVirtualCallCheck.h"
 #include "PointerArithmeticOnPolymorphicObjectCheck.h"
 #include "PosixReturnCheck.h"
+#include "PublicEnableSharedFromThisCheck.h"
 #include "RedundantBranchConditionCheck.h"
 #include "ReservedIdentifierCheck.h"
 #include "ReturnConstRefFromParameterCheck.h"
@@ -139,6 +140,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-inaccurate-erase");
 CheckFactories.registerCheck(
 "bugprone-incorrect-enable-if");
+CheckFactories.registerCheck(
+"bugprone-public-enable-shared-from-this");
 CheckFactories.registerCheck(
 "bugprone-return-const-ref-from-parameter");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index cb0d8ae98bac58..c9bea094241edc 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  PublicEnableSharedFromThisCheck.cpp
   ReturnConstRefFromParameterCheck.cpp
   SuspiciousStringviewDataUsageCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp
new file mode 100644
index 00..dab3e0ac596fe7
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp
@@ -0,0 +1,45 @@
+//===--- PublicEnableSharedFromThisCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "PublicEnableSharedFromThisCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+  void PublicEnableSharedFromThisCheck::registerMatchers(MatchFinder 
*match_finder) {
+  match_finder->addMatcher(
+  cxxRecordDecl(
+  hasAnyBase(
+  cxxBaseSpecifier(unless(isPublic()), 
+  hasType(
+  cxxRecordDecl(
+  hasName("::std::enable_shared_from_this"
+  )
+  )
+  .bind("not-public-enable-shared"), this);
+  }
+
+  void PublicEnableSharedFromThisCheck::check(const MatchFinder::MatchResult 
&result) {
+  const auto *EnableSharedClassDecl =
+  result.Nodes.getNodeAs("not-public-enable-shared");
+
+  for (const auto &Base : EnableSharedClassDecl->bases()) {
+  const auto *BaseType = Base.getType()->getAsCXXRecordDecl();
+  if (BaseType && BaseType->getQualifiedNameAsString() == 
"std::enable_shared_from_this") {
+  SourceLocation InsertLoc = Base.getBeginLoc();
+  FixItHint Hint = Fix

[clang] [clang][ExtractAPI] Compute inherited availability information (PR #103040)

2024-08-14 Thread Daniel Grumberg via cfe-commits

https://github.com/daniel-grumberg updated 
https://github.com/llvm/llvm-project/pull/103040

>From cd38c476336ea90e4d080638d028dda203b52ac4 Mon Sep 17 00:00:00 2001
From: Daniel Grumberg 
Date: Tue, 13 Aug 2024 11:30:18 +0100
Subject: [PATCH 1/5] [clang][ExtractAPI] Compute inherited availability
 information

Additionally this computes availability information for all platforms
ahead of possibly introducing a flag to enable this behavior.

rdar://123513706
---
 clang/include/clang/AST/Availability.h|   4 +
 clang/lib/AST/Availability.cpp| 100 ++--
 .../Serialization/SymbolGraphSerializer.cpp   |  31 ++--
 .../test/ExtractAPI/inherited_availability.m  | 149 ++
 4 files changed, 254 insertions(+), 30 deletions(-)
 create mode 100644 clang/test/ExtractAPI/inherited_availability.m

diff --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index 26ae622e5b4496..60ca1383f0a44e 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -97,6 +97,10 @@ struct AvailabilityInfo {
 return UnconditionallyUnavailable;
   }
 
+  /// Augments the existing information with additional constraints provided by
+  /// \c Other.
+  void mergeWith(AvailabilityInfo Other);
+
   AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
VersionTuple O, bool U, bool UD, bool UU)
   : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
diff --git a/clang/lib/AST/Availability.cpp b/clang/lib/AST/Availability.cpp
index 238359a2dedfcf..376a625b41817a 100644
--- a/clang/lib/AST/Availability.cpp
+++ b/clang/lib/AST/Availability.cpp
@@ -16,33 +16,101 @@
 #include "clang/AST/Decl.h"
 #include "clang/Basic/TargetInfo.h"
 
-namespace clang {
+namespace {
+
+struct AvailabilitySet {
+  llvm::SmallVector Availabilities;
+  bool UnconditionallyDeprecated = false;
+  bool UnconditionallyUnavailable = false;
 
-AvailabilityInfo AvailabilityInfo::createFromDecl(const Decl *Decl) {
-  ASTContext &Context = Decl->getASTContext();
-  StringRef PlatformName = Context.getTargetInfo().getPlatformName();
-  AvailabilityInfo Availability;
+  void insert(clang::AvailabilityInfo &&Availability) {
+auto *Found = getForPlatform(Availability.Domain);
+if (Found)
+  Found->mergeWith(std::move(Availability));
+else
+  Availabilities.emplace_back(std::move(Availability));
+  }
+
+  clang::AvailabilityInfo *getForPlatform(llvm::StringRef Domain) {
+auto *It = llvm::find_if(Availabilities,
+ [Domain](const clang::AvailabilityInfo &Info) {
+   return Domain.compare(Info.Domain) == 0;
+ });
+return It == Availabilities.end() ? nullptr : It;
+  }
+};
 
+static void createInfoForDecl(const clang::Decl *Decl,
+  AvailabilitySet &Availabilities) {
   // Collect availability attributes from all redeclarations.
   for (const auto *RD : Decl->redecls()) {
-for (const auto *A : RD->specific_attrs()) {
-  if (A->getPlatform()->getName() != PlatformName)
-continue;
-  Availability = AvailabilityInfo(
+for (const auto *A : RD->specific_attrs()) {
+  Availabilities.insert(clang::AvailabilityInfo(
   A->getPlatform()->getName(), A->getIntroduced(), A->getDeprecated(),
-  A->getObsoleted(), A->getUnavailable(), false, false);
-  break;
+  A->getObsoleted(), A->getUnavailable(), false, false));
 }
 
-if (const auto *A = RD->getAttr())
+if (const auto *A = RD->getAttr())
   if (!A->isImplicit())
-Availability.UnconditionallyUnavailable = true;
+Availabilities.UnconditionallyUnavailable = true;
 
-if (const auto *A = RD->getAttr())
+if (const auto *A = RD->getAttr())
   if (!A->isImplicit())
-Availability.UnconditionallyDeprecated = true;
+Availabilities.UnconditionallyDeprecated = true;
+  }
+}
+
+} // namespace
+
+namespace clang {
+
+void AvailabilityInfo::mergeWith(AvailabilityInfo Other) {
+  if (isDefault() && Other.isDefault())
+return;
+
+  if (Domain.empty())
+Domain = Other.Domain;
+
+  UnconditionallyUnavailable |= Other.UnconditionallyUnavailable;
+  UnconditionallyDeprecated |= Other.UnconditionallyDeprecated;
+  Unavailable |= Other.Unavailable;
+
+  Introduced = std::max(Introduced, Other.Introduced);
+
+  // Default VersionTuple is 0.0.0 so if both are non default let's pick the
+  // smallest version number, otherwise select the one that is non-zero if 
there
+  // is one.
+  if (!Deprecated.empty() && !Other.Deprecated.empty())
+Deprecated = std::min(Deprecated, Other.Deprecated);
+  else
+Deprecated = std::max(Deprecated, Other.Deprecated);
+
+  if (!Obsoleted.empty() && !Other.Obsoleted.empty())
+Obsoleted = std::min(Obsoleted, Other.Obsoleted);
+  else
+Obsoleted = std::max(Obsoleted, Other.Obsoleted);
+}
+
+Availabili

[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-08-14 Thread via cfe-commits

https://github.com/MichelleCDjunaidi updated 
https://github.com/llvm/llvm-project/pull/102299

>From 75306bd83eb43d0606630f9f059fc04ad1b20b06 Mon Sep 17 00:00:00 2001
From: Michelle C Djunaidi 
Date: Wed, 7 Aug 2024 13:10:02 +0800
Subject: [PATCH 1/9] [clang-tidy] Add bugprone-public-enable-shared-from-this
 check

This check identifies classes deriving from std::enable_shared_from_this that 
does not inherit with the public keyword,
which may cause problems when std::make_shared is called for that class.
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../PublicEnableSharedFromThisCheck.cpp   | 45 +++
 .../PublicEnableSharedFromThisCheck.h | 33 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../bugprone/public-enable-shared-from-this   |  6 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../public-enable-shared-from-this.cpp| 56 +++
 8 files changed, 150 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/public-enable-shared-from-this
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/public-enable-shared-from-this.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 689eb92a3d8d17..f12f0cd1c47da3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -53,6 +53,7 @@
 #include "ParentVirtualCallCheck.h"
 #include "PointerArithmeticOnPolymorphicObjectCheck.h"
 #include "PosixReturnCheck.h"
+#include "PublicEnableSharedFromThisCheck.h"
 #include "RedundantBranchConditionCheck.h"
 #include "ReservedIdentifierCheck.h"
 #include "ReturnConstRefFromParameterCheck.h"
@@ -139,6 +140,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-inaccurate-erase");
 CheckFactories.registerCheck(
 "bugprone-incorrect-enable-if");
+CheckFactories.registerCheck(
+"bugprone-public-enable-shared-from-this");
 CheckFactories.registerCheck(
 "bugprone-return-const-ref-from-parameter");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index cb0d8ae98bac58..c9bea094241edc 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  PublicEnableSharedFromThisCheck.cpp
   ReturnConstRefFromParameterCheck.cpp
   SuspiciousStringviewDataUsageCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp
new file mode 100644
index 00..dab3e0ac596fe7
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp
@@ -0,0 +1,45 @@
+//===--- PublicEnableSharedFromThisCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "PublicEnableSharedFromThisCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+  void PublicEnableSharedFromThisCheck::registerMatchers(MatchFinder 
*match_finder) {
+  match_finder->addMatcher(
+  cxxRecordDecl(
+  hasAnyBase(
+  cxxBaseSpecifier(unless(isPublic()), 
+  hasType(
+  cxxRecordDecl(
+  hasName("::std::enable_shared_from_this"
+  )
+  )
+  .bind("not-public-enable-shared"), this);
+  }
+
+  void PublicEnableSharedFromThisCheck::check(const MatchFinder::MatchResult 
&result) {
+  const auto *EnableSharedClassDecl =
+  result.Nodes.getNodeAs("not-public-enable-shared");
+
+  for (const auto &Base : EnableSharedClassDecl->bases()) {
+  const auto *BaseType = Base.getType()->getAsCXXRecordDecl();
+  if (BaseType && BaseType->getQualifiedNameAsString() == 
"std::enable_shared_from_this") {
+  SourceLocation InsertLoc = Base.getBeginLoc();
+  FixItHint Hint = Fix

[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-08-14 Thread via cfe-commits

https://github.com/MichelleCDjunaidi updated 
https://github.com/llvm/llvm-project/pull/102299

>From 75306bd83eb43d0606630f9f059fc04ad1b20b06 Mon Sep 17 00:00:00 2001
From: Michelle C Djunaidi 
Date: Wed, 7 Aug 2024 13:10:02 +0800
Subject: [PATCH 01/10] [clang-tidy] Add
 bugprone-public-enable-shared-from-this check

This check identifies classes deriving from std::enable_shared_from_this that 
does not inherit with the public keyword,
which may cause problems when std::make_shared is called for that class.
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../PublicEnableSharedFromThisCheck.cpp   | 45 +++
 .../PublicEnableSharedFromThisCheck.h | 33 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../bugprone/public-enable-shared-from-this   |  6 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../public-enable-shared-from-this.cpp| 56 +++
 8 files changed, 150 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/public-enable-shared-from-this
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/public-enable-shared-from-this.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 689eb92a3d8d17..f12f0cd1c47da3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -53,6 +53,7 @@
 #include "ParentVirtualCallCheck.h"
 #include "PointerArithmeticOnPolymorphicObjectCheck.h"
 #include "PosixReturnCheck.h"
+#include "PublicEnableSharedFromThisCheck.h"
 #include "RedundantBranchConditionCheck.h"
 #include "ReservedIdentifierCheck.h"
 #include "ReturnConstRefFromParameterCheck.h"
@@ -139,6 +140,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-inaccurate-erase");
 CheckFactories.registerCheck(
 "bugprone-incorrect-enable-if");
+CheckFactories.registerCheck(
+"bugprone-public-enable-shared-from-this");
 CheckFactories.registerCheck(
 "bugprone-return-const-ref-from-parameter");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index cb0d8ae98bac58..c9bea094241edc 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  PublicEnableSharedFromThisCheck.cpp
   ReturnConstRefFromParameterCheck.cpp
   SuspiciousStringviewDataUsageCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp
new file mode 100644
index 00..dab3e0ac596fe7
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp
@@ -0,0 +1,45 @@
+//===--- PublicEnableSharedFromThisCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "PublicEnableSharedFromThisCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+  void PublicEnableSharedFromThisCheck::registerMatchers(MatchFinder 
*match_finder) {
+  match_finder->addMatcher(
+  cxxRecordDecl(
+  hasAnyBase(
+  cxxBaseSpecifier(unless(isPublic()), 
+  hasType(
+  cxxRecordDecl(
+  hasName("::std::enable_shared_from_this"
+  )
+  )
+  .bind("not-public-enable-shared"), this);
+  }
+
+  void PublicEnableSharedFromThisCheck::check(const MatchFinder::MatchResult 
&result) {
+  const auto *EnableSharedClassDecl =
+  result.Nodes.getNodeAs("not-public-enable-shared");
+
+  for (const auto &Base : EnableSharedClassDecl->bases()) {
+  const auto *BaseType = Base.getType()->getAsCXXRecordDecl();
+  if (BaseType && BaseType->getQualifiedNameAsString() == 
"std::enable_shared_from_this") {
+  SourceLocation InsertLoc = Base.getBeginLoc();
+  FixItHint Hint = F

[clang] [Clang][Sema] fix noexecpt mismatch of friend declaration (PR #102267)

2024-08-14 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

@sdkrystian  Could you please take another look at this patch? The approach 
does what you said before.
When checking exception specific equivalence of the two functions, we do 
instantiation and substitute all the template parameters with instantiated 
ones. But we can't find them as we create a new `LocalInstantiationScope`. So 
these instantiated parameters should be added to current new 
`LocalInstantiationScope`(like what `addInstantiatedParametersToScope` does in 
the following code) to make sure they can be found.
Consider the test case:

```cpp
template 
struct C {
template 
friend void func() noexcept(N == 0);
};

template 
void func() noexcept(N == 0) {}

int main() {
C t;
return 0;
}
```

Without this patch, `Sema::FindInstantiatedDecl` returns original template 
parameter in transforming exception specific when trying to find instantiated 
parameter of `N`. So we use the original parameter(`N`) whose depth is 1 in the 
primary template and this is incorrect and make the comparison failed since it 
should be 0 in the template specialization. Adding instantiated parameters to 
current `LocalInstantiationScope` makes `Sema::FindInstantiatedDecl` returns 
the correct instantiated parameter and it works.

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


[clang-tools-extra] [clang-tidy] use upper case letters for bool conversion suffix (PR #102831)

2024-08-14 Thread Julian Schmidt via cfe-commits

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


[clang-tools-extra] [clang-tidy] use upper case letters for bool conversion suffix (PR #102831)

2024-08-14 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti commented:

Just small things from me, looking good otherwise

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


[clang-tools-extra] [clang-tidy] use upper case letters for bool conversion suffix (PR #102831)

2024-08-14 Thread Julian Schmidt via cfe-commits


@@ -39,14 +39,22 @@ AST_MATCHER(Stmt, isNULLMacroExpansion) {
 }
 
 StringRef getZeroLiteralToCompareWithForType(CastKind CastExprKind,
- QualType Type,
- ASTContext &Context) {
+ QualType Type, ASTContext 
&Context,
+ bool UseUpperCaseSuffix) {
   switch (CastExprKind) {
-  case CK_IntegralToBoolean:
-return Type->isUnsignedIntegerType() ? "0u" : "0";
+  case CK_IntegralToBoolean: {
+if (Type->isUnsignedIntegerType()) {
+  return UseUpperCaseSuffix ? "0U" : "0u";
+}
+return "0";
+  }
 
-  case CK_FloatingToBoolean:
-return Context.hasSameType(Type, Context.FloatTy) ? "0.0f" : "0.0";
+  case CK_FloatingToBoolean: {
+if (Context.hasSameType(Type, Context.FloatTy)) {
+  return UseUpperCaseSuffix ? "0.0F" : "0.0f";
+}

5chmidti wrote:

Nit: Please remove the two compound statements of the two `if` statements (LLVM 
coding standards).

e.g.,
```c++
if (Type->isUnsignedIntegerType())
  return UseUpperCaseSuffix ? "0U" : "0u";
```

This also applies to lines 214-226

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


[clang-tools-extra] [clang-tidy] use upper case letters for bool conversion suffix (PR #102831)

2024-08-14 Thread Julian Schmidt via cfe-commits


@@ -108,6 +108,10 @@ Changes in existing checks
   ` check to
   remove `->`, when reduntant `get()` is removed.
 
+- Added option `UseUpperCaseSuffix` to 
:doc:`readablility-implicit-bool-conversion
+  ` check specify the
+  case of the explicit literal

5chmidti wrote:

check to select the case of the literal suffix in fixes.

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


[clang-tools-extra] [clang-tidy] use upper case letters for bool conversion suffix (PR #102831)

2024-08-14 Thread Julian Schmidt via cfe-commits


@@ -36,6 +36,7 @@ class ImplicitBoolConversionCheck : public ClangTidyCheck {
 
   const bool AllowIntegerConditions;
   const bool AllowPointerConditions;
+  const bool UseUpperCaseSuffix;

5chmidti wrote:

`UseUpperCaseLiteralSuffix` ?

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


[clang-tools-extra] [clang-tidy] use upper case letters for bool conversion suffix (PR #102831)

2024-08-14 Thread Julian Schmidt via cfe-commits


@@ -133,3 +133,18 @@ Options
 
When `true`, the check will allow conditional pointer conversions. Default
is `false`.
+
+.. option::  UseUpperCaseSuffix
+
+   When `true`, the check will allow new explicit conversion use an uppercase
+   suffix when it applies.

5chmidti wrote:

Maybe?: 
> When `true`, the replacements will use an uppercase literal suffix in the 
> provided fixes.

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


[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)

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


@@ -873,30 +877,17 @@ class Sema final : public SemaBase {
   /// Warn when implicitly casting 0 to nullptr.
   void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E);
 
-  // - function effects ---
+  /// All functions/lambdas/blocks which have bodies and which have a non-empty
+  /// FunctionEffectsRef to be verified.
+  SmallVector DeclsWithEffectsToVerify;
+  /// The union of all effects present on DeclsWithEffectsToVerify. Conditions
+  /// are all null.
+  FunctionEffectKindSet AllEffectsToVerify;

Endilll wrote:

Yes, grouping implementations in a single `SemaFunctionEffects.cpp` is the 
right first step if you want to group your functions. Based on that, you can 
create a new section in `Sema.h`, and put all declarations and data members 
there.

I'd refrain from a Sema subcomponent at this stage. My understanding of the 
efforts in this PR is that they are neither a language nor a target, and we 
don't know yet how it should be handled.

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


[clang-tools-extra] [clang-tidy] use upper case letters for bool conversion suffix (PR #102831)

2024-08-14 Thread via cfe-commits


@@ -36,6 +36,7 @@ class ImplicitBoolConversionCheck : public ClangTidyCheck {
 
   const bool AllowIntegerConditions;
   const bool AllowPointerConditions;
+  const bool UseUpperCaseSuffix;

Da-Viper wrote:

Will this also apply to the option passed into clang-tidy 

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


[clang-tools-extra] [clang-tidy] use upper case letters for bool conversion suffix (PR #102831)

2024-08-14 Thread Julian Schmidt via cfe-commits


@@ -36,6 +36,7 @@ class ImplicitBoolConversionCheck : public ClangTidyCheck {
 
   const bool AllowIntegerConditions;
   const bool AllowPointerConditions;
+  const bool UseUpperCaseSuffix;

5chmidti wrote:

Yes, the comment is in regard to the option name. My rationale is, that the 
current option name is about an upper-case suffix, but suffix of what? Adding 
the literal will make things clearer.

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


[clang] [clang-repl] Fix PCH with delayed template parsing (PR #103028)

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

hahnjo wrote:

> > BTW, the delayed template parsing is a deprecated technique. Both clang and 
> > MSVC won't enable this after C++20 and we think it is the root of many bugs.
> 
> I agree. It was needed in the past to parse the MSVC stdlib, let's check if 
> we still need it: 
> [root-project/root#16222](https://github.com/root-project/root/pull/16222)

Update on this: testing shows that we don't need it anymore, so we turned it 
off. I guess we still want to merge the fix proposed in this PR regardless? 
@ChuanqiXu9 

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


[clang] [llvm] [clang][HLSL] Add WaveIsFirstLane() intrinsic (PR #103299)

2024-08-14 Thread Nathan Gauër via cfe-commits

Keenuts wrote:

> We have this work tracked here: #99158
> 
> there should be some dxil specific tasks.

Seems like most boxes are checked, except Sema checks:
 - what kind of Sema checks would be required for this one?
Also, the intrinsic name in the issue is using camel case vs snake case for 
this PR. But seems like existing ones like thread_id are using snake case (same 
thing on the SPIR-V backend). So shouldn't we remain consistent?

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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

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

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

>From 9c4e7ccf47d5ede2b6169effb2a09668f512a182 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sat, 3 Aug 2024 13:05:21 +0300
Subject: [PATCH 1/7] [clang] Implement `__builtin_is_implicit_lifetime()`

This intrinsic supports [P2647R1](https://wg21.link/p2674r1) "A trait for 
implicit lifetime types".
---
 clang/docs/LanguageExtensions.rst|  1 +
 clang/docs/ReleaseNotes.rst  |  3 +
 clang/include/clang/Basic/TokenKinds.def |  1 +
 clang/lib/Sema/SemaExprCXX.cpp   | 22 +++
 clang/test/SemaCXX/type-traits.cpp   | 81 +++-
 5 files changed, 107 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index a747464582e77d..f04e6b0057b512 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1546,6 +1546,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__array_extent(type, dim)`` (Embarcadero):
   The ``dim``'th array bound in the type ``type``, or ``0`` if
   ``dim >= __array_rank(type)``.
+* ``__builtin_is_implicit_lifetime`` (C++, GNU, Microsoft)
 * ``__builtin_is_virtual_base_of`` (C++, GNU, Microsoft)
 * ``__can_pass_in_regs`` (C++)
   Returns whether a class can be passed in registers under the current
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 25f5bd37bbe94f..6854a321e17206 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -86,6 +86,9 @@ C++23 Feature Support
 C++2c Feature Support
 ^
 
+- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports
+  `P2647R1 A trait for implicit lifetime types `_
+
 - Add ``__builtin_is_virtual_base_of`` intrinsic, which supports
   `P2985R0 A type trait for detecting virtual base classes 
`_
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 7e638dc1ddcdba..7505c5a1a1f27c 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -501,6 +501,7 @@ TYPE_TRAIT_1(__has_trivial_move_assign, 
HasTrivialMoveAssign, KEYCXX)
 TYPE_TRAIT_1(__has_trivial_move_constructor, HasTrivialMoveConstructor, KEYCXX)
 
 // GNU and MS Type Traits
+TYPE_TRAIT_1(__builtin_is_implicit_lifetime, IsImplicitLifetime, KEYCXX)
 TYPE_TRAIT_2(__builtin_is_virtual_base_of, IsVirtualBaseOf, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_assign, HasNothrowAssign, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_copy, HasNothrowCopy, KEYCXX)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c5003d9ac02549..504dc93316db50 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5039,6 +5039,7 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, 
TypeTrait UTT,
 
   // LWG3823: T shall be an array type, a complete type, or cv void.
   case UTT_IsAggregate:
+  case UTT_IsImplicitLifetime:
 if (ArgTy->isArrayType() || ArgTy->isVoidType())
   return true;
 
@@ -5637,6 +5638,27 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return false;
   case UTT_IsTriviallyEqualityComparable:
 return isTriviallyEqualityComparableType(Self, T, KeyLoc);
+  case UTT_IsImplicitLifetime: {
+DiagnoseVLAInCXXTypeTrait(Self, TInfo,
+  tok::kw___builtin_is_implicit_lifetime);
+QualType UnqualT = T->getCanonicalTypeUnqualified();
+if (UnqualT->isScalarType())
+  return true;
+if (UnqualT->isArrayType())
+  return true;
+
+CXXRecordDecl *RD = UnqualT->getAsCXXRecordDecl();
+if (!RD)
+  return false;
+if (UnqualT->isAggregateType())
+  if (!RD->getDestructor()->isUserProvided())
+return true;
+if (RD->hasTrivialDestructor())
+  if (RD->hasTrivialDefaultConstructor() ||
+  RD->hasTrivialCopyConstructor() || RD->hasTrivialMoveConstructor())
+return true;
+return false;
+  }
   }
 }
 
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 4acb3d6c9eebea..11041414c1bbab 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -18,7 +18,7 @@ enum class SignedEnumClass : signed int {};
 enum class UnsignedEnumClass : unsigned int {};
 struct POD { Enum e; int i; float f; NonPOD* p; };
 struct Empty {};
-struct IncompleteStruct;
+struct IncompleteStruct; // expected-note {{forward declaration of 
'IncompleteStruct'}}
 typedef Empty EmptyAr[10];
 typedef Empty EmptyArNB[];
 typedef Empty EmptyArMB[1][2];
@@ -1944,6 +1944,85 @@ void is_pointer_interconvertible_base_of(int n)
 }
 }
 
+struct NoEligibleTrivialContructor {
+  NoEligibleTrivialContructor() {};
+  NoEligibleTrivialContructor(const NoEligibleTrivialContructor&) {}
+  NoEligibleTrivialContructor(NoEligibleTrivia

[clang] [llvm] [clang][HLSL] Add WaveIsFirstLane() intrinsic (PR #103299)

2024-08-14 Thread Nathan Gauër via cfe-commits

Keenuts wrote:

> > We have this work tracked here: #99158
> > there should be some dxil specific tasks.
> 
> Seems like most boxes would be checked by this PR, except Sema checks:
> 
> * what kind of Sema checks would be required for this one?
>   Also, the intrinsic name in the issue is using camel case vs snake case for 
> this PR. But seems like existing ones like thread_id are using snake case 
> (same thing on the SPIR-V backend). So shouldn't we remain consistent?



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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

2024-08-14 Thread via cfe-commits

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

LGTM

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


[clang] [llvm] [clang][HLSL] Add WaveIsFirstLane() intrinsic (PR #103299)

2024-08-14 Thread Nathan Gauër via cfe-commits

Keenuts wrote:

> This commits add the WaveIsFirstLane() hlsl intrinsinc. This intrinsic uses 
> the convergence intrinsincs for the SPIR-V backend. On the DXIL side, I'm not 
> sure what the strategy is so this is implemented like in DXC: a simple 
> builtin function. (DXC didn't used convergence intrinsincs for DXIL).



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


[clang] [Clang] Implement C++26’s P2893R3 ‘Variadic friends’ (PR #101448)

2024-08-14 Thread via cfe-commits

Sirraide wrote:

> Can you make a separate pr to update the unrelated changes to cxx_status?

Ah, yeah, I didn’t notice those. I’ll get those removed from this pr.

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


[clang] [llvm] [clang][HLSL] Add WaveIsFirstLane() intrinsic (PR #103299)

2024-08-14 Thread Nathan Gauër via cfe-commits

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


[clang] [Clang] Implement C++26’s P2893R3 ‘Variadic friends’ (PR #101448)

2024-08-14 Thread via cfe-commits


@@ -17556,11 +17584,12 @@ Decl *Sema::ActOnFriendTypeDecl(Scope *S, const 
DeclSpec &DS,
 
   Decl *D;
   if (!TempParams.empty())
+// TODO: Support variadic friend template decls?

Sirraide wrote:

I can do that yeah. We just generally don’t support this type of friend 
declaration, irrespective of whether it’s a pack expansion or not. I can open 
an issue for that in general if there isn’t already one, because once that’s 
implemented, supporting pack expansions should be straight-forward.

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


[clang] [Clang] Implement C++26’s P2893R3 ‘Variadic friends’ (PR #101448)

2024-08-14 Thread via cfe-commits


@@ -17509,8 +17528,17 @@ Decl *Sema::ActOnFriendTypeDecl(Scope *S, const 
DeclSpec &DS,
   if (TheDeclarator.isInvalidType())
 return nullptr;
 
-  if (DiagnoseUnexpandedParameterPack(Loc, TSI, UPPC_FriendDeclaration))
+  // If '...' is present, the type must contain an unexpanded parameter
+  // pack, and vice versa.
+  if (EllipsisLoc.isInvalid() &&
+  DiagnoseUnexpandedParameterPack(Loc, TSI, UPPC_FriendDeclaration))
 return nullptr;
+  if (EllipsisLoc.isValid() &&
+  !TSI->getType()->containsUnexpandedParameterPack()) {
+Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
+<< TSI->getTypeLoc().getSourceRange();
+EllipsisLoc = SourceLocation();

Sirraide wrote:

I mean, we weren’t doing that before either, but I can try doing that.

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


[clang-tools-extra] [clang-tidy] use upper case letters for bool conversion suffix (PR #102831)

2024-08-14 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

A bit of nitpick, but would it make sense to have some consistency with 
`readability-identifier-naming`?

Instead of `UseUpperCase`, I'm thinking of:

`LiteralSuffixCase: LowerCase/UpperCase`

Like I said, not a big deal, I'm just posting as suggestion in case you like it 
better.

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


[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)

2024-08-14 Thread via cfe-commits


@@ -873,30 +877,17 @@ class Sema final : public SemaBase {
   /// Warn when implicitly casting 0 to nullptr.
   void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E);
 
-  // - function effects ---
+  /// All functions/lambdas/blocks which have bodies and which have a non-empty
+  /// FunctionEffectsRef to be verified.
+  SmallVector DeclsWithEffectsToVerify;
+  /// The union of all effects present on DeclsWithEffectsToVerify. Conditions
+  /// are all null.
+  FunctionEffectKindSet AllEffectsToVerify;

Sirraide wrote:

> My understanding of the efforts in this PR is that they are neither a 
> language nor a target, and we don't know yet how it should be handled.

That’s a good point yeah. This is mostly just to put everything effect-related 
into one place.

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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

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

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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

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

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

LGTM but with an additional test case to consider.

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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

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


@@ -5637,6 +5638,38 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return false;
   case UTT_IsTriviallyEqualityComparable:
 return isTriviallyEqualityComparableType(Self, T, KeyLoc);
+  case UTT_IsImplicitLifetime: {
+DiagnoseVLAInCXXTypeTrait(Self, TInfo,
+  tok::kw___builtin_is_implicit_lifetime);
+
+// [basic.types.general] p9
+// Scalar types, implicit-lifetime class types ([class.prop]),
+// array types, and cv-qualified versions of these types
+// are collectively called implicit-lifetime types.
+QualType UnqualT = T->getCanonicalTypeUnqualified();

AaronBallman wrote:

How should `_Atomic int` behave? We support that as an extension in C++

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


[clang] [clang] Turn -Wenum-constexpr-conversion into a hard error (PR #102364)

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

AaronBallman wrote:

> > How soon after 1.86 landing do you plan to submit this?
> 
> I was thinking as soon as it's released, I don't see a reason for waiting any 
> longer. The sooner we merge the sooner we can collect feedback and re-adjust 
> if needed. But of course it's up to the Clang owners to decide :)

I think that's a reasonable plan -- if we find it's extremely disruptive, we 
can cross that bridge when we come to it.

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


[clang] [clang] Turn -Wenum-constexpr-conversion into a hard error (PR #102364)

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

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

Code changes LGTM

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


[clang] [clang][ASTMatcher] Add `matchesString` for `StringLiteral` which matches literals on given `RegExp` (PR #102152)

2024-08-14 Thread via cfe-commits


@@ -2503,6 +2503,28 @@ TEST_P(ASTMatchersTest, IsDelegatingConstructor) {
   cxxConstructorDecl(isDelegatingConstructor(), parameterCountIs(1;
 }
 
+TEST_P(ASTMatchersTest, MatchesString) {
+  StatementMatcher Literal = stringLiteral(matchesString("foo.*"));
+  EXPECT_TRUE(matches("const char* a = \"foo\";", Literal));
+  EXPECT_TRUE(matches("const char* b = \"foobar\";", Literal));
+  EXPECT_TRUE(matches("const char* b = \"fo\"\"obar\";", Literal));
+  EXPECT_TRUE(notMatches("const char* c = \"bar\";", Literal));
+  // test embedded nulls
+  StatementMatcher Literal2 = stringLiteral(matchesString("bar"));
+  EXPECT_TRUE(matches("const char* b = \"foo\\0bar\";", Literal2));
+  EXPECT_TRUE(notMatches("const char* b = \"foo\\0b\\0ar\";", Literal2));
+}
+
+TEST(MatchesString, MatchesStringPrefixed) {
+  StatementMatcher Literal = stringLiteral(matchesString("foo.*"));
+  EXPECT_TRUE(matchesConditionally("const char16_t* a = u\"foo\";", Literal,
+   true, {"-std=c++11"}));
+  EXPECT_TRUE(matchesConditionally("const char32_t* a = U\"foo\";", Literal,
+   true, {"-std=c++11"}));
+  EXPECT_TRUE(matchesConditionally("const wchar_t* a = L\"foo\";", Literal,
+   true, {"-std=c++11"}));

cor3ntin wrote:

The matcher seems to be using the value produced by 
`StringLiteral::outputString` which will "work" - until we support non unicode 
encoding - but `StringLiteral::outputString` is really designed for debug, so 
wchar etc are going to be escaped. I think this is going to be a difficult to 
use interface.

We would be better off adding a way to convert back the string literal to 
non-escaped UTF-8 ... except numeric escape sequence would not be preserved 
(and might lead to replacement characters)


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


[clang] [clang] Turn -Wenum-constexpr-conversion into a hard error (PR #102364)

2024-08-14 Thread Sam James via cfe-commits

thesamesam wrote:

re boost: I was thinking the same re waiting until it's out but I didn't want 
to say it. Sounds good.

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


[clang] [llvm] [analyzer] Delete `alpha.security.MallocOverflow` (PR #103059)

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

https://github.com/NagyDonat updated 
https://github.com/llvm/llvm-project/pull/103059

From 36821708145587553f13df8648920f281b318240 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Tue, 13 Aug 2024 14:50:17 +0200
Subject: [PATCH 1/2] [analyzer] Delete alpha.security.MallocOverflow

...because it is too noisy to be useful right now, and its architecture
is terrible, so it can't act a starting point of future development.

The main problem with this checker is that it tries to do (or at least
fake) path-sensitive analysis without actually using the established
path-sensitive analysis engine.

Instead of actually tracking the symbolic values and the known
constraints on them, this checker blindly gropes the AST and uses
heuristics like "this variable was seen in a comparison operator
expression that is not a loop condition, so it's probably not too
large" (which was improved in a separate commit to at least ignore
comparison operators that appear after the actual `malloc()` call).

This might have been acceptable in 2011 (when this checker was added),
but since then we developed a significantly better standard approach for
analysis and this old relic doesn't deserve to remain in the codebase.

Needless to say, this primitive approach causes lots of false positives
(and presumably false negatives as well), which ensures that this
alpha checker won't be missed by the users.

It would be good to eventually have a stable, path-sensitive checker
that could succeed in the task where this hacky implementation fails,
but the first step towards that goal is taking out this old garbage,
which confuses the potential users or contributors.

(I don't have plans for reimplementing the goals of this checker. It
could happen eventually, but right now I have many plans that are higher
priority than this.)
---
 clang/docs/analyzer/checkers.rst  |  43 ---
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 -
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   1 -
 .../MallocOverflowSecurityChecker.cpp | 341 --
 clang/test/Analysis/malloc-overflow.c | 150 
 clang/test/Analysis/malloc-overflow.cpp   |  12 -
 clang/test/Analysis/malloc-overflow2.c|  40 --
 clang/www/analyzer/potential_checkers.html|   2 -
 .../lib/StaticAnalyzer/Checkers/BUILD.gn  |   1 -
 9 files changed, 594 deletions(-)
 delete mode 100644 
clang/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp
 delete mode 100644 clang/test/Analysis/malloc-overflow.c
 delete mode 100644 clang/test/Analysis/malloc-overflow.cpp
 delete mode 100644 clang/test/Analysis/malloc-overflow2.c

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 46b0b7b9c82376..0bfbc995579d41 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2951,49 +2951,6 @@ Warn about buffer overflows (newer checker).
char c = s[x]; // warn: index is tainted
  }
 
-.. _alpha-security-MallocOverflow:
-
-alpha.security.MallocOverflow (C)
-"
-Check for overflows in the arguments to ``malloc()``.
-It tries to catch ``malloc(n * c)`` patterns, where:
-
- - ``n``: a variable or member access of an object
- - ``c``: a constant foldable integral
-
-This checker was designed for code audits, so expect false-positive reports.
-One is supposed to silence this checker by ensuring proper bounds checking on
-the variable in question using e.g. an ``assert()`` or a branch.
-
-.. code-block:: c
-
- void test(int n) {
-   void *p = malloc(n * sizeof(int)); // warn
- }
-
- void test2(int n) {
-   if (n > 100) // gives an upper-bound
- return;
-   void *p = malloc(n * sizeof(int)); // no warning
- }
-
- void test3(int n) {
-   assert(n <= 100 && "Contract violated.");
-   void *p = malloc(n * sizeof(int)); // no warning
- }
-
-Limitations:
-
- - The checker won't warn for variables involved in explicit casts,
-   since that might limit the variable's domain.
-   E.g.: ``(unsigned char)int x`` would limit the domain to ``[0,255]``.
-   The checker will miss the true-positive cases when the explicit cast would
-   not tighten the domain to prevent the overflow in the subsequent
-   multiplication operation.
-
- - It is an AST-based checker, thus it does not make use of the
-   path-sensitive taint-analysis.
-
 .. _alpha-security-MmapWriteExec:
 
 alpha.security.MmapWriteExec (C)
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 38b55a0eb0a7b0..fb4114619ac3d3 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1039,10 +1039,6 @@ def ArrayBoundCheckerV2 : Checker<"ArrayBoundV2">,
   HelpText<"Warn about buffer overflows (newer checker)">,
   Documentation;
 
-def MallocOverflowSecurityChecker : Checker<"MallocOverflow">,
-  HelpText<"Check for overflows in th

[clang] [llvm] [analyzer] Delete `alpha.security.MallocOverflow` (PR #103059)

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


@@ -1,40 +0,0 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown 
-analyzer-checker=alpha.security.MallocOverflow,unix -verify %s
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown 
-analyzer-checker=alpha.security.MallocOverflow,unix,optin.portability 
-DPORTABILITY -verify %s

NagyDonat wrote:

I agree, that this might have some minor usefulness by accident, but I still 
think that it's better to remove it. (After all, we are not copying random "no 
results found" source files into our test directory...)

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


[clang] [llvm] [analyzer] Delete `alpha.security.MallocOverflow` (PR #103059)

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

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


[clang] [llvm] [analyzer] Delete `alpha.security.MallocOverflow` (PR #103059)

2024-08-14 Thread Balazs Benics via cfe-commits
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 



@@ -1039,10 +1039,6 @@ def ArrayBoundCheckerV2 : Checker<"ArrayBoundV2">,
   HelpText<"Warn about buffer overflows (newer checker)">,
   Documentation;
 
-def MallocOverflowSecurityChecker : Checker<"MallocOverflow">,

steakhal wrote:

I'm not sure it's necessity. They could fork it and revert this change if they 
really wanted. I doubt that would be the case.
@NagyDonat If you really want to make this a backward-compatible change, you 
could add a new bool checker option like 
`"enable-despite-this-checker-is-deprecated-and-will-be-removed"`, and leave 
the checker - until we branch off for clang-20 in mid January. But personally, 
I wouldn't want to wait for 4 months for removing an alpha checker.
We could reconsider this and clarify the policies if users complain that alpha 
checkers were removed without any notice.

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


[clang] [Clang] Adjust concept definition locus (PR #103867)

2024-08-14 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/103867

Per [basic.scope], the locus of a concept is immediately after the introduction 
of its name.

This let us provide better diagnostics for attempt to define recursive concepts.

Note that recursive concepts are not supported per 
https://eel.is/c++draft/basic#scope.pdecl-note-3, but there is no normative 
wording for that restriction. This is a known defect introduced by 
[p1787r6](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html).

Fixes #55875

>From 021ffdd7597c6ca480de273db5604cb482306d50 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 14 Aug 2024 12:06:03 +0200
Subject: [PATCH] [Clang] Adjust concept definition locus

Per [basic.scope], the locus of a concept is immediately
adfter the introduction of its name.

This let us provide better diagnostics for attempt
to define recursive concepts.

Note that recursive concepts are not supported per 
https://eel.is/c++draft/basic#scope.pdecl-note-3,
but there is no normative wording for that restriction.
This is a known defect introduced by 
[p1787r6](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html).

Fixes #55875
---
 clang/docs/ReleaseNotes.rst   |  4 +-
 clang/include/clang/AST/DeclTemplate.h| 13 ++-
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +
 clang/include/clang/Sema/Sema.h   | 13 +--
 clang/lib/Parse/ParseTemplate.cpp | 14 +++-
 clang/lib/Sema/SemaExpr.cpp   |  4 +
 clang/lib/Sema/SemaTemplate.cpp   | 83 +++
 clang/test/CXX/drs/cwg25xx.cpp| 10 ++-
 clang/test/SemaTemplate/concepts.cpp  |  9 +-
 9 files changed, 118 insertions(+), 34 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 39e1b0fcb09bbd..1786a70c82cd20 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,8 +217,10 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
-- Fixed an assertion failure when selecting a function from an overload set 
that includes a 
+- Fixed an assertion failure when selecting a function from an overload set 
that includes a
   specialization of a conversion function template.
+- Correctly diagnose attempts to use a concept name in its own definition;
+  A concept name is introduced to its scope sooner to match the C++ standard. 
(#GH55875)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 5b6a6b40b28ef8..687715a22e9fd3 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -3146,19 +3146,24 @@ class ConceptDecl : public TemplateDecl, public 
Mergeable {
   : TemplateDecl(Concept, DC, L, Name, Params),
 ConstraintExpr(ConstraintExpr) {};
 public:
-  static ConceptDecl *Create(ASTContext &C, DeclContext *DC,
- SourceLocation L, DeclarationName Name,
+  static ConceptDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
+ DeclarationName Name,
  TemplateParameterList *Params,
- Expr *ConstraintExpr);
+ Expr *ConstraintExpr = nullptr);
   static ConceptDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
 
   Expr *getConstraintExpr() const {
 return ConstraintExpr;
   }
 
+  bool hasDefinition() const { return ConstraintExpr != nullptr; }
+
+  void setDefinition(Expr *E) { ConstraintExpr = E; }
+
   SourceRange getSourceRange() const override LLVM_READONLY {
 return SourceRange(getTemplateParameters()->getTemplateLoc(),
-   ConstraintExpr->getEndLoc());
+   ConstraintExpr ? ConstraintExpr->getEndLoc()
+  : SourceLocation());
   }
 
   bool isTypeConcept() const {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 554dbaff2ce0d8..28fc3a69865b11 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3012,6 +3012,8 @@ def err_concept_no_parameters : Error<
   "specialization of concepts is not allowed">;
 def err_concept_extra_headers : Error<
   "extraneous template parameter list in concept definition">;
+def err_recursive_concept : Error<
+  "a concept definition cannot refer to itself">;
 def err_concept_no_associated_constraints : Error<
   "concept cannot have associated constraints">;
 def err_non_constant_constraint_expression : Error<
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/

[clang] [Clang] Adjust concept definition locus (PR #103867)

2024-08-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

Per [basic.scope], the locus of a concept is immediately after the introduction 
of its name.

This let us provide better diagnostics for attempt to define recursive concepts.

Note that recursive concepts are not supported per 
https://eel.is/c++draft/basic#scope.pdecl-note-3, but there is no normative 
wording for that restriction. This is a known defect introduced by 
[p1787r6](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html).

Fixes #55875

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


9 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3-1) 
- (modified) clang/include/clang/AST/DeclTemplate.h (+9-4) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2) 
- (modified) clang/include/clang/Sema/Sema.h (+8-5) 
- (modified) clang/lib/Parse/ParseTemplate.cpp (+11-3) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+4) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+66-17) 
- (modified) clang/test/CXX/drs/cwg25xx.cpp (+7-3) 
- (modified) clang/test/SemaTemplate/concepts.cpp (+8-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 39e1b0fcb09bbd..1786a70c82cd20 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,8 +217,10 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
-- Fixed an assertion failure when selecting a function from an overload set 
that includes a 
+- Fixed an assertion failure when selecting a function from an overload set 
that includes a
   specialization of a conversion function template.
+- Correctly diagnose attempts to use a concept name in its own definition;
+  A concept name is introduced to its scope sooner to match the C++ standard. 
(#GH55875)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 5b6a6b40b28ef8..687715a22e9fd3 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -3146,19 +3146,24 @@ class ConceptDecl : public TemplateDecl, public 
Mergeable {
   : TemplateDecl(Concept, DC, L, Name, Params),
 ConstraintExpr(ConstraintExpr) {};
 public:
-  static ConceptDecl *Create(ASTContext &C, DeclContext *DC,
- SourceLocation L, DeclarationName Name,
+  static ConceptDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
+ DeclarationName Name,
  TemplateParameterList *Params,
- Expr *ConstraintExpr);
+ Expr *ConstraintExpr = nullptr);
   static ConceptDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
 
   Expr *getConstraintExpr() const {
 return ConstraintExpr;
   }
 
+  bool hasDefinition() const { return ConstraintExpr != nullptr; }
+
+  void setDefinition(Expr *E) { ConstraintExpr = E; }
+
   SourceRange getSourceRange() const override LLVM_READONLY {
 return SourceRange(getTemplateParameters()->getTemplateLoc(),
-   ConstraintExpr->getEndLoc());
+   ConstraintExpr ? ConstraintExpr->getEndLoc()
+  : SourceLocation());
   }
 
   bool isTypeConcept() const {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 554dbaff2ce0d8..28fc3a69865b11 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3012,6 +3012,8 @@ def err_concept_no_parameters : Error<
   "specialization of concepts is not allowed">;
 def err_concept_extra_headers : Error<
   "extraneous template parameter list in concept definition">;
+def err_recursive_concept : Error<
+  "a concept definition cannot refer to itself">;
 def err_concept_no_associated_constraints : Error<
   "concept cannot have associated constraints">;
 def err_non_constant_constraint_expression : Error<
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 25cb6c8fbf6104..aace4ce351eecb 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12033,14 +12033,17 @@ class Sema final : public SemaBase {
 
   void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD);
 
-  Decl *ActOnConceptDefinition(Scope *S,
-   MultiTemplateParamsArg TemplateParameterLists,
-   const IdentifierInfo *Name,
-   SourceLocation NameLoc, Expr *ConstraintExpr,
-   const ParsedAttributesView &Attrs);
+  ConceptDecl *ActOnStartConceptDefinition(

[clang] [analyzer] Do not reason about locations passed as inline asm input (PR #103714)

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

https://github.com/steakhal commented:

Looks good overall.
Please compactify the tests by removing newlines that are not strictly 
necessary.

It's a pitty that `ProgramState::invalidateRegions` accepts an `Expr` instead 
of a `Stmt` and then later inside it just conjures the result of the 
invalidation for a Stmt... That API really should have accepted Stmts. If that 
would be the case, we could just use something like this here:
```c++
state = state->invalidateRegions(EscapingValues, A, currBldrCtx->blockCount(),
 Pred->getLocationContext(),
 /*CausedByPointerEscape=*/true);
```

Note that this would be the correct way of doing this, as it would traverse all 
the reachable regions via those arguments, thus getting the pointee of a 
pointee also invalidated etc - unlike what we do now here.

Could you use `I` or `Input` for the input expression? I suppose `O` 
represented the `Output` expression in the previous loop. 

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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

2024-08-14 Thread via cfe-commits


@@ -5637,6 +5638,38 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return false;
   case UTT_IsTriviallyEqualityComparable:
 return isTriviallyEqualityComparableType(Self, T, KeyLoc);
+  case UTT_IsImplicitLifetime: {
+DiagnoseVLAInCXXTypeTrait(Self, TInfo,
+  tok::kw___builtin_is_implicit_lifetime);
+
+// [basic.types.general] p9
+// Scalar types, implicit-lifetime class types ([class.prop]),
+// array types, and cv-qualified versions of these types
+// are collectively called implicit-lifetime types.
+QualType UnqualT = T->getCanonicalTypeUnqualified();

cor3ntin wrote:

I don't think we want to old this PR on _Atomic, but I don't know what the 
answer ought to be.
Rejecting that code all together might be the most conservative solution.

@zygoloid 


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


[clang] [analyzer] Do not reason about locations passed as inline asm input (PR #103714)

2024-08-14 Thread Pavel Skripkin via cfe-commits

https://github.com/pskrgag updated 
https://github.com/llvm/llvm-project/pull/103714

>From e528b0ded1a9815195e33d141a9e8ce05fb26cd1 Mon Sep 17 00:00:00 2001
From: Pavel Skripkin 
Date: Wed, 14 Aug 2024 10:50:24 +0300
Subject: [PATCH 1/2] clang/csa: stop reasoning about pointers passed inside
 inline assembly

---
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp |  8 +
 clang/test/Analysis/asm.cpp  | 36 +++-
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 686310d38ebd58..d64134102d96c7 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3807,6 +3807,14 @@ void ExprEngine::VisitGCCAsmStmt(const GCCAsmStmt *A, 
ExplodedNode *Pred,
   state = state->bindLoc(*LV, UnknownVal(), Pred->getLocationContext());
   }
 
+  // Do not reason about locations passed inside inline assembly.
+  for (const Expr *O : A->inputs()) {
+SVal X = state->getSVal(O, Pred->getLocationContext());
+
+if (std::optional LV = X.getAs())
+  state = state->bindLoc(*LV, UnknownVal(), Pred->getLocationContext());
+  }
+
   Bldr.generateNode(A, Pred, state);
 }
 
diff --git a/clang/test/Analysis/asm.cpp b/clang/test/Analysis/asm.cpp
index 1180063502168f..5d158b62e7221f 100644
--- a/clang/test/Analysis/asm.cpp
+++ b/clang/test/Analysis/asm.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker debug.ExprInspection 
-fheinous-gnu-extensions -w %s -verify
+// RUN: %clang_analyze_cc1 -triple=x86_64-unknown-unknown \
+// RUN:  -analyzer-checker debug.ExprInspection,core 
-fheinous-gnu-extensions -w %s -verify
 
 int clang_analyzer_eval(int);
 
@@ -10,3 +11,36 @@ void testRValueOutput() {
   clang_analyzer_eval(global == 1); // expected-warning{{UNKNOWN}}
   clang_analyzer_eval(ref == 1);// expected-warning{{UNKNOWN}}
 }
+
+void *MyMemcpy(void *d, const void *s, const int n) {
+  asm volatile (
+"cld\n rep movsb\n"
+:: "S" (s), "D" (d), "c" (n) : "memory"
+  );
+
+  return d;
+}
+
+void testInlineAsmMemcpy(void)
+{
+int a, b = 10, c;
+
+MyMemcpy(&a, &b, sizeof(b));
+c = a; // no-warning
+}
+
+void testInlineAsmMemcpyArray(void)
+{
+int a[10], b[10] = {}, c;
+
+MyMemcpy(&a, &b, sizeof(b));
+c = a[8]; // no-warning
+}
+
+void testInlineAsmMemcpyUninit(void)
+{
+int a[10], b[10] = {}, c;
+
+MyMemcpy(&a[1], &b[1], sizeof(b) - sizeof(b[1]));
+c = a[0]; // expected-warning{{Assigned value is garbage or undefined}}
+}

>From 70f9323c183fd1703f31e098bf3b3ac43dc7dc7d Mon Sep 17 00:00:00 2001
From: Pavel Skripkin 
Date: Wed, 14 Aug 2024 15:49:21 +0300
Subject: [PATCH 2/2] fix naming and remove newlines after declarations in test

---
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 4 ++--
 clang/test/Analysis/asm.cpp  | 4 
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index d64134102d96c7..493914f88ba9a5 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3808,8 +3808,8 @@ void ExprEngine::VisitGCCAsmStmt(const GCCAsmStmt *A, 
ExplodedNode *Pred,
   }
 
   // Do not reason about locations passed inside inline assembly.
-  for (const Expr *O : A->inputs()) {
-SVal X = state->getSVal(O, Pred->getLocationContext());
+  for (const Expr *I : A->inputs()) {
+SVal X = state->getSVal(I, Pred->getLocationContext());
 
 if (std::optional LV = X.getAs())
   state = state->bindLoc(*LV, UnknownVal(), Pred->getLocationContext());
diff --git a/clang/test/Analysis/asm.cpp b/clang/test/Analysis/asm.cpp
index 5d158b62e7221f..3181aea870c8aa 100644
--- a/clang/test/Analysis/asm.cpp
+++ b/clang/test/Analysis/asm.cpp
@@ -17,14 +17,12 @@ void *MyMemcpy(void *d, const void *s, const int n) {
 "cld\n rep movsb\n"
 :: "S" (s), "D" (d), "c" (n) : "memory"
   );
-
   return d;
 }
 
 void testInlineAsmMemcpy(void)
 {
 int a, b = 10, c;
-
 MyMemcpy(&a, &b, sizeof(b));
 c = a; // no-warning
 }
@@ -32,7 +30,6 @@ void testInlineAsmMemcpy(void)
 void testInlineAsmMemcpyArray(void)
 {
 int a[10], b[10] = {}, c;
-
 MyMemcpy(&a, &b, sizeof(b));
 c = a[8]; // no-warning
 }
@@ -40,7 +37,6 @@ void testInlineAsmMemcpyArray(void)
 void testInlineAsmMemcpyUninit(void)
 {
 int a[10], b[10] = {}, c;
-
 MyMemcpy(&a[1], &b[1], sizeof(b) - sizeof(b[1]));
 c = a[0]; // expected-warning{{Assigned value is garbage or undefined}}
 }

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


[clang] [llvm] [X86][MC] Remove CMPCCXADD's CondCode flavor. (PR #103898)

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

https://github.com/FreddyLeaf created 
https://github.com/llvm/llvm-project/pull/103898

None

>From d5275ef5e6a4e34bdae6b9b505ba1aae3a9a2363 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Wed, 14 Aug 2024 19:45:21 +0800
Subject: [PATCH] [X86][MC] Remove CMPCCXADD's CondCode flavor.

---
 clang/test/CodeGen/X86/cmpccxadd-builtins.c   |  48 +--
 .../X86/MCTargetDesc/X86InstPrinterCommon.cpp |  13 +-
 llvm/test/CodeGen/X86/cmpccxadd-intrinsics.ll | 120 
 .../MC/Disassembler/X86/apx/cmpccxadd.txt |  80 ++---
 .../test/MC/Disassembler/X86/cmpccxadd-64.txt | 288 +-
 llvm/test/MC/X86/apx/cmpccxadd-att.s  |  80 ++---
 llvm/test/MC/X86/apx/cmpccxadd-intel.s|  80 ++---
 llvm/test/MC/X86/cmpccxadd-att-alias.s|  26 +-
 llvm/test/MC/X86/cmpccxadd-att.s  | 288 +-
 llvm/test/MC/X86/cmpccxadd-intel-alias.s  |  26 +-
 llvm/test/MC/X86/cmpccxadd-intel.s| 288 +-
 11 files changed, 668 insertions(+), 669 deletions(-)

diff --git a/clang/test/CodeGen/X86/cmpccxadd-builtins.c 
b/clang/test/CodeGen/X86/cmpccxadd-builtins.c
index 6daed3a1b17b67..f058dc9b2baa46 100644
--- a/clang/test/CodeGen/X86/cmpccxadd-builtins.c
+++ b/clang/test/CodeGen/X86/cmpccxadd-builtins.c
@@ -52,50 +52,50 @@ long long test_cmplxadd64(void *__A, long long __B, long 
long __C) {
   return _cmpccxadd_epi64(__A, __B, __C, _CMPCCX_NB);
 }
 
-int test_cmpnbexadd32(void *__A, int __B, int __C) {
-  // CHECK-LABEL: @test_cmpnbexadd32(
+int test_cmpaxadd32(void *__A, int __B, int __C) {
+  // CHECK-LABEL: @test_cmpaxadd32(
   // CHECK: call i32 @llvm.x86.cmpccxadd32(ptr %{{.*}}, i32 %{{.*}}, i32 
%{{.*}}, i32 4)
   return _cmpccxadd_epi32(__A, __B, __C, _CMPCCX_Z);
 }
 
-long long test_cmpnbexadd64(void *__A, long long __B, long long __C) {
-  // CHECK-LABEL: @test_cmpnbexadd64(
+long long test_cmpaxadd64(void *__A, long long __B, long long __C) {
+  // CHECK-LABEL: @test_cmpaxadd64(
   // CHECK: call i64 @llvm.x86.cmpccxadd64(ptr %{{.*}}, i64 %{{.*}}, i64 
%{{.*}}, i32 4)
   return _cmpccxadd_epi64(__A, __B, __C, _CMPCCX_Z);
 }
 
-int test_cmpnbxadd32(void *__A, int __B, int __C) {
-  // CHECK-LABEL: @test_cmpnbxadd32(
+int test_cmpaexadd32(void *__A, int __B, int __C) {
+  // CHECK-LABEL: @test_cmpaexadd32(
   // CHECK: call i32 @llvm.x86.cmpccxadd32(ptr %{{.*}}, i32 %{{.*}}, i32 
%{{.*}}, i32 5)
   return _cmpccxadd_epi32(__A, __B, __C, _CMPCCX_NZ);
 }
 
-long long test_cmpnbxadd64(void *__A, long long __B, long long __C) {
-  // CHECK-LABEL: @test_cmpnbxadd64(
+long long test_cmpaexadd64(void *__A, long long __B, long long __C) {
+  // CHECK-LABEL: @test_cmpaexadd64(
   // CHECK: call i64 @llvm.x86.cmpccxadd64(ptr %{{.*}}, i64 %{{.*}}, i64 
%{{.*}}, i32 5)
   return _cmpccxadd_epi64(__A, __B, __C, _CMPCCX_NZ);
 }
 
-int test_cmpnlexadd32(void *__A, int __B, int __C) {
-  // CHECK-LABEL: @test_cmpnlexadd32(
+int test_cmpgxadd32(void *__A, int __B, int __C) {
+  // CHECK-LABEL: @test_cmpgxadd32(
   // CHECK: call i32 @llvm.x86.cmpccxadd32(ptr %{{.*}}, i32 %{{.*}}, i32 
%{{.*}}, i32 6)
   return _cmpccxadd_epi32(__A, __B, __C, _CMPCCX_BE);
 }
 
-long long test_cmpnlexadd64(void *__A, long long __B, long long __C) {
-  // CHECK-LABEL: @test_cmpnlexadd64(
+long long test_cmpgxadd64(void *__A, long long __B, long long __C) {
+  // CHECK-LABEL: @test_cmpgxadd64(
   // CHECK: call i64 @llvm.x86.cmpccxadd64(ptr %{{.*}}, i64 %{{.*}}, i64 
%{{.*}}, i32 6)
   return _cmpccxadd_epi64(__A, __B, __C, _CMPCCX_BE);
 }
 
-int test_cmpnlxadd32(void *__A, int __B, int __C) {
-  // CHECK-LABEL: @test_cmpnlxadd32(
+int test_cmpgexadd32(void *__A, int __B, int __C) {
+  // CHECK-LABEL: @test_cmpgexadd32(
   // CHECK: call i32 @llvm.x86.cmpccxadd32(ptr %{{.*}}, i32 %{{.*}}, i32 
%{{.*}}, i32 7)
   return _cmpccxadd_epi32(__A, __B, __C, _CMPCCX_NBE);
 }
 
-long long test_cmpnlxadd64(void *__A, long long __B, long long __C) {
-  // CHECK-LABEL: @test_cmpnlxadd64(
+long long test_cmpgexadd64(void *__A, long long __B, long long __C) {
+  // CHECK-LABEL: @test_cmpgexadd64(
   // CHECK: call i64 @llvm.x86.cmpccxadd64(ptr %{{.*}}, i64 %{{.*}}, i64 
%{{.*}}, i32 7)
   return _cmpccxadd_epi64(__A, __B, __C, _CMPCCX_NBE);
 }
@@ -136,14 +136,14 @@ long long test_cmpnsxadd64(void *__A, long long __B, long 
long __C) {
   return _cmpccxadd_epi64(__A, __B, __C, _CMPCCX_P);
 }
 
-int test_cmpnzxadd32(void *__A, int __B, int __C) {
-  // CHECK-LABEL: @test_cmpnzxadd32(
+int test_cmpnexadd32(void *__A, int __B, int __C) {
+  // CHECK-LABEL: @test_cmpnexadd32(
   // CHECK: call i32 @llvm.x86.cmpccxadd32(ptr %{{.*}}, i32 %{{.*}}, i32 
%{{.*}}, i32 11)
   return _cmpccxadd_epi32(__A, __B, __C, _CMPCCX_NP);
 }
 
-long long test_cmpnzxadd64(void *__A, long long __B, long long __C) {
-  // CHECK-LABEL: @test_cmpnzxadd64(
+long long test_cmpnexadd64(void *__A, long long __B, long long __C) {
+  // CHECK-LABEL: @test_cmpnexadd64(
   // CHECK: call i64 @llvm.x86.cmpccxadd64(ptr %{{.*}}, i64 %{{

[clang] [clang] Add lifetimebound attr to std::span/std::string_view constructor (PR #103716)

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

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


[clang] [clang] Add lifetimebound attr to std::span/std::string_view constructor (PR #103716)

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


@@ -216,6 +216,59 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl 
*Record) {
   inferGslPointerAttribute(Record, Record);
 }
 
+void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
+  if (FD->getNumParams() == 0)
+return;
+
+  if (unsigned BuiltinID = FD->getBuiltinID()) {
+// Add lifetime attribute to std::move, std::fowrard et al.
+switch (BuiltinID) {
+case Builtin::BIaddressof:
+case Builtin::BI__addressof:
+case Builtin::BI__builtin_addressof:
+case Builtin::BIas_const:

Xazax-hun wrote:

I start to have the feeling we are writing code like this over and over again.
Some examples:
https://github.com/llvm/llvm-project/blob/df57833ea8a3f527b7941576b4a130ddd4361e61/clang/lib/Analysis/BodyFarm.cpp#L718
https://github.com/llvm/llvm-project/blob/df57833ea8a3f527b7941576b4a130ddd4361e61/clang/lib/AST/ExprConstant.cpp#L8763

But there are more, and I always wonder if they can get out of sync. I wonder 
if this is time to introduce some helper functions that can be reused. 

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


[clang] [clang] Add lifetimebound attr to std::span/std::string_view constructor (PR #103716)

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

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

Looks great, thanks!

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


[clang] [llvm] [X86][MC] Remove CMPCCXADD's CondCode flavor. (PR #103898)

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

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


[clang] [llvm] [X86][MC] Remove CMPCCXADD's CondCode flavor. (PR #103898)

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

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


[clang] [analyzer] Do not reason about locations passed as inline asm input (PR #103714)

2024-08-14 Thread Pavel Skripkin via cfe-commits

pskrgag wrote:

Thank you for review!

Deleted newline and renamed `O` -> `I`. 

> It's a pitty that ProgramState::invalidateRegions accepts an Expr instead of 
> a Stmt and then later inside it just conjures the result of the invalidation 
> for a Stmt

I saw that API, but thought there was a reason why it accepts `Stmt`...

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


[clang] [llvm] [X86][MC] Remove CMPCCXADD's CondCode flavor. (PR #103898)

2024-08-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Freddy Ye (FreddyLeaf)


Changes

To align with gas's latest changes.

---

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


11 Files Affected:

- (modified) clang/test/CodeGen/X86/cmpccxadd-builtins.c (+24-24) 
- (modified) llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp (+6-7) 
- (modified) llvm/test/CodeGen/X86/cmpccxadd-intrinsics.ll (+60-60) 
- (modified) llvm/test/MC/Disassembler/X86/apx/cmpccxadd.txt (+40-40) 
- (modified) llvm/test/MC/Disassembler/X86/cmpccxadd-64.txt (+144-144) 
- (modified) llvm/test/MC/X86/apx/cmpccxadd-att.s (+40-40) 
- (modified) llvm/test/MC/X86/apx/cmpccxadd-intel.s (+40-40) 
- (modified) llvm/test/MC/X86/cmpccxadd-att-alias.s (+13-13) 
- (modified) llvm/test/MC/X86/cmpccxadd-att.s (+144-144) 
- (modified) llvm/test/MC/X86/cmpccxadd-intel-alias.s (+13-13) 
- (modified) llvm/test/MC/X86/cmpccxadd-intel.s (+144-144) 


``diff
diff --git a/clang/test/CodeGen/X86/cmpccxadd-builtins.c 
b/clang/test/CodeGen/X86/cmpccxadd-builtins.c
index 6daed3a1b17b67..f058dc9b2baa46 100644
--- a/clang/test/CodeGen/X86/cmpccxadd-builtins.c
+++ b/clang/test/CodeGen/X86/cmpccxadd-builtins.c
@@ -52,50 +52,50 @@ long long test_cmplxadd64(void *__A, long long __B, long 
long __C) {
   return _cmpccxadd_epi64(__A, __B, __C, _CMPCCX_NB);
 }
 
-int test_cmpnbexadd32(void *__A, int __B, int __C) {
-  // CHECK-LABEL: @test_cmpnbexadd32(
+int test_cmpaxadd32(void *__A, int __B, int __C) {
+  // CHECK-LABEL: @test_cmpaxadd32(
   // CHECK: call i32 @llvm.x86.cmpccxadd32(ptr %{{.*}}, i32 %{{.*}}, i32 
%{{.*}}, i32 4)
   return _cmpccxadd_epi32(__A, __B, __C, _CMPCCX_Z);
 }
 
-long long test_cmpnbexadd64(void *__A, long long __B, long long __C) {
-  // CHECK-LABEL: @test_cmpnbexadd64(
+long long test_cmpaxadd64(void *__A, long long __B, long long __C) {
+  // CHECK-LABEL: @test_cmpaxadd64(
   // CHECK: call i64 @llvm.x86.cmpccxadd64(ptr %{{.*}}, i64 %{{.*}}, i64 
%{{.*}}, i32 4)
   return _cmpccxadd_epi64(__A, __B, __C, _CMPCCX_Z);
 }
 
-int test_cmpnbxadd32(void *__A, int __B, int __C) {
-  // CHECK-LABEL: @test_cmpnbxadd32(
+int test_cmpaexadd32(void *__A, int __B, int __C) {
+  // CHECK-LABEL: @test_cmpaexadd32(
   // CHECK: call i32 @llvm.x86.cmpccxadd32(ptr %{{.*}}, i32 %{{.*}}, i32 
%{{.*}}, i32 5)
   return _cmpccxadd_epi32(__A, __B, __C, _CMPCCX_NZ);
 }
 
-long long test_cmpnbxadd64(void *__A, long long __B, long long __C) {
-  // CHECK-LABEL: @test_cmpnbxadd64(
+long long test_cmpaexadd64(void *__A, long long __B, long long __C) {
+  // CHECK-LABEL: @test_cmpaexadd64(
   // CHECK: call i64 @llvm.x86.cmpccxadd64(ptr %{{.*}}, i64 %{{.*}}, i64 
%{{.*}}, i32 5)
   return _cmpccxadd_epi64(__A, __B, __C, _CMPCCX_NZ);
 }
 
-int test_cmpnlexadd32(void *__A, int __B, int __C) {
-  // CHECK-LABEL: @test_cmpnlexadd32(
+int test_cmpgxadd32(void *__A, int __B, int __C) {
+  // CHECK-LABEL: @test_cmpgxadd32(
   // CHECK: call i32 @llvm.x86.cmpccxadd32(ptr %{{.*}}, i32 %{{.*}}, i32 
%{{.*}}, i32 6)
   return _cmpccxadd_epi32(__A, __B, __C, _CMPCCX_BE);
 }
 
-long long test_cmpnlexadd64(void *__A, long long __B, long long __C) {
-  // CHECK-LABEL: @test_cmpnlexadd64(
+long long test_cmpgxadd64(void *__A, long long __B, long long __C) {
+  // CHECK-LABEL: @test_cmpgxadd64(
   // CHECK: call i64 @llvm.x86.cmpccxadd64(ptr %{{.*}}, i64 %{{.*}}, i64 
%{{.*}}, i32 6)
   return _cmpccxadd_epi64(__A, __B, __C, _CMPCCX_BE);
 }
 
-int test_cmpnlxadd32(void *__A, int __B, int __C) {
-  // CHECK-LABEL: @test_cmpnlxadd32(
+int test_cmpgexadd32(void *__A, int __B, int __C) {
+  // CHECK-LABEL: @test_cmpgexadd32(
   // CHECK: call i32 @llvm.x86.cmpccxadd32(ptr %{{.*}}, i32 %{{.*}}, i32 
%{{.*}}, i32 7)
   return _cmpccxadd_epi32(__A, __B, __C, _CMPCCX_NBE);
 }
 
-long long test_cmpnlxadd64(void *__A, long long __B, long long __C) {
-  // CHECK-LABEL: @test_cmpnlxadd64(
+long long test_cmpgexadd64(void *__A, long long __B, long long __C) {
+  // CHECK-LABEL: @test_cmpgexadd64(
   // CHECK: call i64 @llvm.x86.cmpccxadd64(ptr %{{.*}}, i64 %{{.*}}, i64 
%{{.*}}, i32 7)
   return _cmpccxadd_epi64(__A, __B, __C, _CMPCCX_NBE);
 }
@@ -136,14 +136,14 @@ long long test_cmpnsxadd64(void *__A, long long __B, long 
long __C) {
   return _cmpccxadd_epi64(__A, __B, __C, _CMPCCX_P);
 }
 
-int test_cmpnzxadd32(void *__A, int __B, int __C) {
-  // CHECK-LABEL: @test_cmpnzxadd32(
+int test_cmpnexadd32(void *__A, int __B, int __C) {
+  // CHECK-LABEL: @test_cmpnexadd32(
   // CHECK: call i32 @llvm.x86.cmpccxadd32(ptr %{{.*}}, i32 %{{.*}}, i32 
%{{.*}}, i32 11)
   return _cmpccxadd_epi32(__A, __B, __C, _CMPCCX_NP);
 }
 
-long long test_cmpnzxadd64(void *__A, long long __B, long long __C) {
-  // CHECK-LABEL: @test_cmpnzxadd64(
+long long test_cmpnexadd64(void *__A, long long __B, long long __C) {
+  // CHECK-LABEL: @test_cmpnexadd64(
   // CHECK: call i64 @llvm.x86.cmpccxadd64(ptr %{{.*}}, i64 %{{.*}}, 

[clang] [llvm] [analyzer] Delete `alpha.security.MallocOverflow` (PR #103059)

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


@@ -1039,10 +1039,6 @@ def ArrayBoundCheckerV2 : Checker<"ArrayBoundV2">,
   HelpText<"Warn about buffer overflows (newer checker)">,
   Documentation;
 
-def MallocOverflowSecurityChecker : Checker<"MallocOverflow">,

NagyDonat wrote:

Now that I think about it, we already have lots of precedent for moving and 
renaming alpha checkers without prior warning, so the "updated to the new 
version and the old command line invocation doesn't work without changes" 
situation is not a problem.

The only difference is that after this change they won't be able to restore the 
behavior by using a new name for the checker, but I think that this is 
acceptable, because:
1. this checker is so unreliable that it's extremely unlikely that somebody was 
relying on it;
2. deleting a checker is a _conservative_ change: it removes the results of 
that particular checker, but it doesn't affects the results of the other 
checkers and doesn't hinder the investigation of the results by introducing 
lots of spammy results.

Based on this, I'm merging this commit now.

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


[clang] [Clang] Adjust concept definition locus (PR #103867)

2024-08-14 Thread via cfe-commits

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

>From 021ffdd7597c6ca480de273db5604cb482306d50 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 14 Aug 2024 12:06:03 +0200
Subject: [PATCH 1/2] [Clang] Adjust concept definition locus

Per [basic.scope], the locus of a concept is immediately
adfter the introduction of its name.

This let us provide better diagnostics for attempt
to define recursive concepts.

Note that recursive concepts are not supported per 
https://eel.is/c++draft/basic#scope.pdecl-note-3,
but there is no normative wording for that restriction.
This is a known defect introduced by 
[p1787r6](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html).

Fixes #55875
---
 clang/docs/ReleaseNotes.rst   |  4 +-
 clang/include/clang/AST/DeclTemplate.h| 13 ++-
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +
 clang/include/clang/Sema/Sema.h   | 13 +--
 clang/lib/Parse/ParseTemplate.cpp | 14 +++-
 clang/lib/Sema/SemaExpr.cpp   |  4 +
 clang/lib/Sema/SemaTemplate.cpp   | 83 +++
 clang/test/CXX/drs/cwg25xx.cpp| 10 ++-
 clang/test/SemaTemplate/concepts.cpp  |  9 +-
 9 files changed, 118 insertions(+), 34 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 39e1b0fcb09bbd..1786a70c82cd20 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,8 +217,10 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
-- Fixed an assertion failure when selecting a function from an overload set 
that includes a 
+- Fixed an assertion failure when selecting a function from an overload set 
that includes a
   specialization of a conversion function template.
+- Correctly diagnose attempts to use a concept name in its own definition;
+  A concept name is introduced to its scope sooner to match the C++ standard. 
(#GH55875)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 5b6a6b40b28ef8..687715a22e9fd3 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -3146,19 +3146,24 @@ class ConceptDecl : public TemplateDecl, public 
Mergeable {
   : TemplateDecl(Concept, DC, L, Name, Params),
 ConstraintExpr(ConstraintExpr) {};
 public:
-  static ConceptDecl *Create(ASTContext &C, DeclContext *DC,
- SourceLocation L, DeclarationName Name,
+  static ConceptDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
+ DeclarationName Name,
  TemplateParameterList *Params,
- Expr *ConstraintExpr);
+ Expr *ConstraintExpr = nullptr);
   static ConceptDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
 
   Expr *getConstraintExpr() const {
 return ConstraintExpr;
   }
 
+  bool hasDefinition() const { return ConstraintExpr != nullptr; }
+
+  void setDefinition(Expr *E) { ConstraintExpr = E; }
+
   SourceRange getSourceRange() const override LLVM_READONLY {
 return SourceRange(getTemplateParameters()->getTemplateLoc(),
-   ConstraintExpr->getEndLoc());
+   ConstraintExpr ? ConstraintExpr->getEndLoc()
+  : SourceLocation());
   }
 
   bool isTypeConcept() const {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 554dbaff2ce0d8..28fc3a69865b11 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3012,6 +3012,8 @@ def err_concept_no_parameters : Error<
   "specialization of concepts is not allowed">;
 def err_concept_extra_headers : Error<
   "extraneous template parameter list in concept definition">;
+def err_recursive_concept : Error<
+  "a concept definition cannot refer to itself">;
 def err_concept_no_associated_constraints : Error<
   "concept cannot have associated constraints">;
 def err_non_constant_constraint_expression : Error<
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 25cb6c8fbf6104..aace4ce351eecb 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12033,14 +12033,17 @@ class Sema final : public SemaBase {
 
   void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD);
 
-  Decl *ActOnConceptDefinition(Scope *S,
-   MultiTemplateParamsArg TemplateParameterLists,
-   const IdentifierInfo *Name,
-

[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

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

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

>From 9c4e7ccf47d5ede2b6169effb2a09668f512a182 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sat, 3 Aug 2024 13:05:21 +0300
Subject: [PATCH 1/8] [clang] Implement `__builtin_is_implicit_lifetime()`

This intrinsic supports [P2647R1](https://wg21.link/p2674r1) "A trait for 
implicit lifetime types".
---
 clang/docs/LanguageExtensions.rst|  1 +
 clang/docs/ReleaseNotes.rst  |  3 +
 clang/include/clang/Basic/TokenKinds.def |  1 +
 clang/lib/Sema/SemaExprCXX.cpp   | 22 +++
 clang/test/SemaCXX/type-traits.cpp   | 81 +++-
 5 files changed, 107 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index a747464582e77d..f04e6b0057b512 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1546,6 +1546,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__array_extent(type, dim)`` (Embarcadero):
   The ``dim``'th array bound in the type ``type``, or ``0`` if
   ``dim >= __array_rank(type)``.
+* ``__builtin_is_implicit_lifetime`` (C++, GNU, Microsoft)
 * ``__builtin_is_virtual_base_of`` (C++, GNU, Microsoft)
 * ``__can_pass_in_regs`` (C++)
   Returns whether a class can be passed in registers under the current
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 25f5bd37bbe94f..6854a321e17206 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -86,6 +86,9 @@ C++23 Feature Support
 C++2c Feature Support
 ^
 
+- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports
+  `P2647R1 A trait for implicit lifetime types `_
+
 - Add ``__builtin_is_virtual_base_of`` intrinsic, which supports
   `P2985R0 A type trait for detecting virtual base classes 
`_
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 7e638dc1ddcdba..7505c5a1a1f27c 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -501,6 +501,7 @@ TYPE_TRAIT_1(__has_trivial_move_assign, 
HasTrivialMoveAssign, KEYCXX)
 TYPE_TRAIT_1(__has_trivial_move_constructor, HasTrivialMoveConstructor, KEYCXX)
 
 // GNU and MS Type Traits
+TYPE_TRAIT_1(__builtin_is_implicit_lifetime, IsImplicitLifetime, KEYCXX)
 TYPE_TRAIT_2(__builtin_is_virtual_base_of, IsVirtualBaseOf, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_assign, HasNothrowAssign, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_copy, HasNothrowCopy, KEYCXX)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c5003d9ac02549..504dc93316db50 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5039,6 +5039,7 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, 
TypeTrait UTT,
 
   // LWG3823: T shall be an array type, a complete type, or cv void.
   case UTT_IsAggregate:
+  case UTT_IsImplicitLifetime:
 if (ArgTy->isArrayType() || ArgTy->isVoidType())
   return true;
 
@@ -5637,6 +5638,27 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return false;
   case UTT_IsTriviallyEqualityComparable:
 return isTriviallyEqualityComparableType(Self, T, KeyLoc);
+  case UTT_IsImplicitLifetime: {
+DiagnoseVLAInCXXTypeTrait(Self, TInfo,
+  tok::kw___builtin_is_implicit_lifetime);
+QualType UnqualT = T->getCanonicalTypeUnqualified();
+if (UnqualT->isScalarType())
+  return true;
+if (UnqualT->isArrayType())
+  return true;
+
+CXXRecordDecl *RD = UnqualT->getAsCXXRecordDecl();
+if (!RD)
+  return false;
+if (UnqualT->isAggregateType())
+  if (!RD->getDestructor()->isUserProvided())
+return true;
+if (RD->hasTrivialDestructor())
+  if (RD->hasTrivialDefaultConstructor() ||
+  RD->hasTrivialCopyConstructor() || RD->hasTrivialMoveConstructor())
+return true;
+return false;
+  }
   }
 }
 
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 4acb3d6c9eebea..11041414c1bbab 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -18,7 +18,7 @@ enum class SignedEnumClass : signed int {};
 enum class UnsignedEnumClass : unsigned int {};
 struct POD { Enum e; int i; float f; NonPOD* p; };
 struct Empty {};
-struct IncompleteStruct;
+struct IncompleteStruct; // expected-note {{forward declaration of 
'IncompleteStruct'}}
 typedef Empty EmptyAr[10];
 typedef Empty EmptyArNB[];
 typedef Empty EmptyArMB[1][2];
@@ -1944,6 +1944,85 @@ void is_pointer_interconvertible_base_of(int n)
 }
 }
 
+struct NoEligibleTrivialContructor {
+  NoEligibleTrivialContructor() {};
+  NoEligibleTrivialContructor(const NoEligibleTrivialContructor&) {}
+  NoEligibleTrivialContructor(NoEligibleTrivia

[clang] [llvm] [analyzer] Delete `alpha.security.MallocOverflow` (PR #103059)

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

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


[clang] [clang-repl] Fix PCH with delayed template parsing (PR #103028)

2024-08-14 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> > > BTW, the delayed template parsing is a deprecated technique. Both clang 
> > > and MSVC won't enable this after C++20 and we think it is the root of 
> > > many bugs.
> > 
> > 
> > I agree. It was needed in the past to parse the MSVC stdlib, let's check if 
> > we still need it: 
> > [root-project/root#16222](https://github.com/root-project/root/pull/16222)
> 
> Update on this: testing shows that we don't need it anymore, so we turned it 
> off. I guess we still want to merge the fix proposed in this PR regardless? 
> @ChuanqiXu9

At least it is good for the pre-c++20 codes : )

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


  1   2   3   4   5   >