[clang] [clang][Interp] Fix IntAP(s) to IntAP(s) casts (PR #69915)

2023-11-06 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Interp] Fix IntAP(s) to IntAP(s) casts (PR #69915)

2023-11-06 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/69915

>From b82acd12f1217468d6fc53ab2b2f5856802b9b78 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 23 Oct 2023 12:46:25 +0200
Subject: [PATCH] [clang][Interp] Fix IntAP(s) to IntAP(s) casts

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp |  7 ++-
 clang/test/AST/Interp/intap.cpp  | 11 +++
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 485893d58f487ae..a2cf682b2532bde 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -200,16 +200,13 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
 if (!this->visit(SubExpr))
   return false;
 
-if (FromT == ToT) {
-  assert(ToT != PT_IntAP && ToT != PT_IntAPS);
-  return true;
-}
-
 if (ToT == PT_IntAP)
   return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE);
 if (ToT == PT_IntAPS)
   return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE);
 
+if (FromT == ToT)
+  return true;
 return this->emitCast(*FromT, *ToT, CE);
   }
 
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 02a860eb0986c15..c7df32b70d20a45 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -30,6 +30,17 @@ static_assert(UBitIntZero1 == 0, "");
 constexpr unsigned _BitInt(2) BI1 = 3u;
 static_assert(BI1 == 3, "");
 
+namespace APCast {
+  constexpr _BitInt(10) A = 1;
+  constexpr _BitInt(11) B = A;
+  static_assert(B == 1, "");
+  constexpr _BitInt(16) B2 = A;
+  static_assert(B2 == 1, "");
+  constexpr _BitInt(32) B3 = A;
+  static_assert(B3 == 1, "");
+  constexpr unsigned _BitInt(32) B4 = A;
+  static_assert(B4 == 1, "");
+}
 
 #ifdef __SIZEOF_INT128__
 namespace i128 {

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-11-06 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Ping

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


[clang] b178cec - [clang][NFC] Annotate most of `clang/Basic` headers with `preferred_type`

2023-11-06 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-06T14:18:26+03:00
New Revision: b178cec84f95210db615cfa0a84e78585445f16b

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

LOG: [clang][NFC] Annotate most of `clang/Basic` headers with `preferred_type`

This patch doesn't touch `CodeGenOptions.h`, `DiagnosticOptions.h`, 
`LangOptions.h`, `IdentifierTable.h`.

Added: 


Modified: 
clang/include/clang/Basic/AttributeCommonInfo.h
clang/include/clang/Basic/Diagnostic.h
clang/include/clang/Basic/DiagnosticIDs.h
clang/include/clang/Basic/Module.h
clang/include/clang/Basic/ParsedAttrInfo.h
clang/include/clang/Basic/SourceManager.h
clang/include/clang/Basic/Specifiers.h
clang/include/clang/Basic/TargetInfo.h

Removed: 




diff  --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 7dc05418498d0ae..908e0c71544279c 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -74,11 +74,16 @@ class AttributeCommonInfo {
   SourceRange AttrRange;
   const SourceLocation ScopeLoc;
   // Corresponds to the Kind enum.
+  LLVM_PREFERRED_TYPE(Kind)
   unsigned AttrKind : 16;
   /// Corresponds to the Syntax enum.
+  LLVM_PREFERRED_TYPE(Syntax)
   unsigned SyntaxUsed : 4;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned SpellingIndex : 4;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsAlignas : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsRegularKeywordAttribute : 1;
 
 protected:
@@ -123,9 +128,12 @@ class AttributeCommonInfo {
 : SyntaxUsed(SyntaxUsed), SpellingIndex(SpellingNotCalculated),
   IsAlignas(0), IsRegularKeywordAttribute(0) {}
 
+LLVM_PREFERRED_TYPE(Syntax)
 unsigned SyntaxUsed : 4;
 unsigned SpellingIndex : 4;
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsAlignas : 1;
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsRegularKeywordAttribute : 1;
   };
 

diff  --git a/clang/include/clang/Basic/Diagnostic.h 
b/clang/include/clang/Basic/Diagnostic.h
index 3df037b793b3946..0c7836c2ea569cc 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -314,18 +314,23 @@ class DiagnosticsEngine : public 
RefCountedBase {
 // "Global" configuration state that can actually vary between modules.
 
 // Ignore all warnings: -w
+LLVM_PREFERRED_TYPE(bool)
 unsigned IgnoreAllWarnings : 1;
 
 // Enable all warnings.
+LLVM_PREFERRED_TYPE(bool)
 unsigned EnableAllWarnings : 1;
 
 // Treat warnings like errors.
+LLVM_PREFERRED_TYPE(bool)
 unsigned WarningsAsErrors : 1;
 
 // Treat errors like fatal errors.
+LLVM_PREFERRED_TYPE(bool)
 unsigned ErrorsAsFatal : 1;
 
 // Suppress warnings in system headers.
+LLVM_PREFERRED_TYPE(bool)
 unsigned SuppressSystemWarnings : 1;
 
 // Map extensions to warnings or errors?
@@ -1822,12 +1827,17 @@ class ForwardingDiagnosticConsumer : public 
DiagnosticConsumer {
 struct TemplateDiffTypes {
   intptr_t FromType;
   intptr_t ToType;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned PrintTree : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned PrintFromType : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned ElideType : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned ShowColors : 1;
 
   // The printer sets this variable to true if the template 
diff  was used.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned TemplateDiffUsed : 1;
 };
 

diff  --git a/clang/include/clang/Basic/DiagnosticIDs.h 
b/clang/include/clang/Basic/DiagnosticIDs.h
index 06ef1c6904c31d1..0cdda42793f6f0a 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -100,11 +100,17 @@ namespace clang {
   }
 
 class DiagnosticMapping {
+  LLVM_PREFERRED_TYPE(diag::Severity)
   unsigned Severity : 3;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsUser : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsPragma : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned HasNoWarningAsError : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned HasNoErrorAsFatal : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned WasUpgradedFromWarning : 1;
 
 public:

diff  --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 6a7423938bdb8fa..239eb5a637f3ecf 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -298,50 +298,62 @@ class alignas(8) Module {
   /// Whether this module has declared itself unimportable, either because
   /// it's missing a requirement from \p Requirements or because it's been
   /// shadowed by another module.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsUnimportable : 1;
 
   /// Whether we tried and failed to load a module file for this module.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned HasIn

[clang] [clang][TSA] Make RequiresCapability a DeclOrType attribute (PR #67095)

2023-11-06 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -1894,6 +1894,8 @@ void TypePrinter::printAttributedAfter(const 
AttributedType *T,
   case attr::ArmMveStrictPolymorphism:
 OS << "__clang_arm_mve_strict_polymorphism";
 break;
+  case attr::RequiresCapability:
+OS << "requires_capability(blah)";

tbaederr wrote:

I was a little confused why none of the other attributes in that function seem 
to print any arguments. Is this really such a special case or am I just doing 
something wrong to end up here at all?

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


[clang] [clang][analyzer] Improve StdLibraryFunctionsChecker 'readlink' modeling. (PR #71373)

2023-11-06 Thread via cfe-commits

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

This is straightforward small change that clarifies some _very confusing_ (but 
technically true positive) bug reports that I encountered on some open source 
projects. 

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


[llvm] [clang] [clang-tools-extra] [SimplifyCFG] Prevent merging cbranch to cbranch if the branch probability from the first to second is too low. (PR #69375)

2023-11-06 Thread Valery Pykhtin via cfe-commits

vpykhtin wrote:

> I've been puzzling over the rationale for looking at `MD_unpredictable`. How 
> can a branch that is heavily biased to one side be unpredictable?

I'm curious either, I just decided to follow a 'standard' pattern in this 
source.

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


[clang] 684b8e1 - Add missing header in MigratorOptions.h for 1a0e743ab01716ecafeb33858d9975cf90017c59.

2023-11-06 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-11-06T12:32:43+01:00
New Revision: 684b8e1c08f4ed3bfa452fea5eac230e449bf2aa

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

LOG: Add missing header in MigratorOptions.h for 
1a0e743ab01716ecafeb33858d9975cf90017c59.

Added: 


Modified: 
clang/include/clang/Frontend/MigratorOptions.h

Removed: 




diff  --git a/clang/include/clang/Frontend/MigratorOptions.h 
b/clang/include/clang/Frontend/MigratorOptions.h
index 42181c585669391..da899643f0b4b2b 100644
--- a/clang/include/clang/Frontend/MigratorOptions.h
+++ b/clang/include/clang/Frontend/MigratorOptions.h
@@ -14,6 +14,8 @@
 #ifndef LLVM_CLANG_FRONTEND_MIGRATOROPTIONS_H
 #define LLVM_CLANG_FRONTEND_MIGRATOROPTIONS_H
 
+#include "llvm/Support/Compiler.h"
+
 namespace clang {
 
 class MigratorOptions {



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


[clang] [llvm] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68565)

2023-11-06 Thread Sam Tebbs via cfe-commits


@@ -4825,6 +4827,72 @@ SDValue AArch64TargetLowering::getPStateSM(SelectionDAG 
&DAG, SDValue Chain,
  Mask);
 }
 
+SDValue LowerSMELdrStr(SDValue N, SelectionDAG &DAG, bool IsLoad) {
+  // Lower an SME LDR/STR ZA intrinsic to LDR_ZA_PSEUDO or STR_ZA.
+  // If the vector number is an immediate between 0 and 15 inclusive then we 
can
+  // put that directly into the immediate field of the instruction. If it's
+  // outside of that range then we modify the base and slice by the greatest
+  // multiple of 15 smaller than that number and put the remainder in the
+  // instruction field. If it's not an immediate then we modify the base and
+  // slice registers by that number and put 0 in the instruction.
+  SDLoc DL(N);
+
+  SDValue TileSlice = N->getOperand(2);
+  SDValue Base = N->getOperand(3);
+  SDValue VecNum = N->getOperand(4);
+  SDValue Remainder = DAG.getTargetConstant(0, DL, MVT::i32);
+
+  // true if the base and slice registers need to me modified
+  bool NeedsAdd = true;
+  if (auto ImmNode = dyn_cast(VecNum)) {
+int Imm = ImmNode->getSExtValue();
+if (Imm >= 0 && Imm <= 15) {
+  Remainder = DAG.getTargetConstant(Imm, DL, MVT::i32);
+  NeedsAdd = false;
+} else {
+  Remainder = DAG.getTargetConstant(Imm % 15, DL, MVT::i32);
+  NeedsAdd = true;
+  VecNum = DAG.getConstant(Imm - (Imm % 15), DL, MVT::i32);
+}
+  } else if (VecNum.getOpcode() == ISD::ADD) {
+// If the vnum is an add, we can fold that add into the instruction if the
+// operand is an immediate in range
+if (auto ImmNode = dyn_cast(VecNum.getOperand(1))) {
+  int Imm = ImmNode->getSExtValue();
+  if (Imm >= 0 && Imm <= 15) {
+VecNum = VecNum.getOperand(0);
+Remainder = DAG.getTargetConstant(Imm, DL, MVT::i32);
+NeedsAdd = true;
+  }
+}
+  }
+  if (NeedsAdd) {
+// Get the vector length that will be multiplied by vnum
+auto SVL = DAG.getNode(AArch64ISD::RDSVL, DL, MVT::i64,
+   DAG.getConstant(1, DL, MVT::i32));
+
+// Multiply SVL and vnum then add it to the base
+// Just add vnum to the tileslice
+SDValue BaseMulOps[] = {
+SVL, VecNum.getValueType() == MVT::i32
+ ? DAG.getNode(ISD::SIGN_EXTEND, DL, MVT::i64, VecNum)

SamTebbs33 wrote:

We do indeed, I'll remove the condition.

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


[clang] [llvm] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68565)

2023-11-06 Thread Sam Tebbs via cfe-commits

https://github.com/SamTebbs33 updated 
https://github.com/llvm/llvm-project/pull/68565

>From de07976922782b9dcf5d13d44551b782dc8b3b94 Mon Sep 17 00:00:00 2001
From: Samuel Tebbs 
Date: Fri, 6 Oct 2023 17:09:36 +0100
Subject: [PATCH 1/6] [AArch64][SME] Remove immediate argument restriction for
 svldr and svstr

The svldr_vnum_za and svstr_vnum_za builtins/intrinsics currently
require that the vnum argument be an immediate, since the instructions
take an immediate vector number. However, we emit 0 as the immediate
for the instruction no matter what, and instead modify the base register.

This patch removes that restriction on the argument, so that the
argument can be a non-immediate. If an appropriate immediate was
passed to the builtin then CGBuiltin passes that directly to the LLVM
intrinsic, otherwise it modifies the base register as is existing
behaviour.
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 45 
 .../aarch64-sme-intrinsics/acle_sme_ldr.c | 71 ---
 .../aarch64-sme-intrinsics/acle_sme_str.c | 51 -
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  4 +-
 llvm/lib/Target/AArch64/SMEInstrFormats.td| 10 +--
 .../CostModel/ARM/unaligned_double_load.ll| 59 +++
 .../CodeGen/AArch64/sme-intrinsics-loads.ll   | 33 +++--
 7 files changed, 166 insertions(+), 107 deletions(-)
 create mode 100644 llvm/test/Analysis/CostModel/ARM/unaligned_double_load.ll

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e1211bb8949b665..63508b40096141e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9712,6 +9712,11 @@ Value *CodeGenFunction::EmitSVEMaskedStore(const 
CallExpr *E,
   return Store;
 }
 
+Value *CodeGenFunction::EmitTileslice(Value *Offset, Value *Base) {
+  llvm::Value *CastOffset = Builder.CreateIntCast(Offset, Int64Ty, false);
+  return Builder.CreateAdd(Base, CastOffset, "tileslice");
+}
+
 Value *CodeGenFunction::EmitSMELd1St1(const SVETypeFlags &TypeFlags,
   SmallVectorImpl &Ops,
   unsigned IntID) {
@@ -9767,18 +9772,34 @@ Value *CodeGenFunction::EmitSMEZero(const SVETypeFlags 
&TypeFlags,
 Value *CodeGenFunction::EmitSMELdrStr(const SVETypeFlags &TypeFlags,
   SmallVectorImpl &Ops,
   unsigned IntID) {
-  if (Ops.size() == 3) {
-Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
-llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-
-llvm::Value *VecNum = Ops[2];
-llvm::Value *MulVL = Builder.CreateMul(CntsbCall, VecNum, "mulvl");
-
-Ops[1] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
-Ops[0] = Builder.CreateAdd(
-Ops[0], Builder.CreateIntCast(VecNum, Int32Ty, true), "tileslice");
-Ops.erase(&Ops[2]);
-  }
+  if (Ops.size() == 2) {
+// Intrinsics without a vecnum also use this function, so just provide 0
+Ops.push_back(Ops[1]);
+Ops[1] = Builder.getInt32(0);
+  } else {
+int Imm = -1;
+if (ConstantInt* C = dyn_cast(Ops[2]))
+  if (C->getZExtValue() <= 15)
+  Imm = C->getZExtValue();
+
+if (Imm != -1) {
+  Ops[2] = Ops[1];
+  Ops[1] = Builder.getInt32(Imm);
+} else {
+  Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
+  llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
+
+  llvm::Value *VecNum = Ops[2];
+  llvm::Value *MulVL = Builder.CreateMul(
+  CntsbCall,
+  VecNum,
+  "mulvl");
+
+  Ops[2] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
+  Ops[1] = Builder.getInt32(0);
+  Ops[0] = Builder.CreateIntCast(EmitTileslice(Ops[0], VecNum), Int32Ty, 
false);
+}
+   }
   Function *F = CGM.getIntrinsic(IntID, {});
   return Builder.CreateCall(F, Ops);
 }
diff --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
index e85c47072f2df80..8e07cf1d11c19b2 100644
--- a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
@@ -6,57 +6,46 @@
 
 #include 
 
-// CHECK-C-LABEL: define dso_local void @test_svldr_vnum_za(
-// CHECK-C-SAME: i32 noundef [[SLICE_BASE:%.*]], ptr noundef [[PTR:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
-// CHECK-C-NEXT:  entry:
-// CHECK-C-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE]], 
ptr [[PTR]])
-// CHECK-C-NEXT:ret void
-//
-// CHECK-CXX-LABEL: define dso_local void @_Z18test_svldr_vnum_zajPKv(
-// CHECK-CXX-SAME: i32 noundef [[SLICE_BASE:%.*]], ptr noundef [[PTR:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
-// CHECK-CXX-NEXT:  entry:
-// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE]], 
ptr [[PTR]])
-// CHECK-CXX-NEXT:ret void
+// CHECK-C-LABEL: @test_svldr_vnum_za(
+// CHECK-CXX-LABEL: @_Z18test_svldr_vnum_zajPK

[clang] [analyzer] Fix assertion failure in `CXXInstanceCall::getCXXThisVal` (PR #70837)

2023-11-06 Thread via cfe-commits


@@ -30,3 +30,24 @@ void test(int i) {
   clang_analyzer_dump(g4);
   // expected-warning@-1 {{&i [as 64 bit integer]}}
 }
+
+struct A {
+  int n;
+  void set(int x) {
+n = x;
+  }
+};
+using ptr_size = decltype(sizeof(void *));

DonatNagyE wrote:

Thanks!

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


[clang] [clang-tools-extra] In compilation databases, add support for relative directories (PR #69856)

2023-11-06 Thread via cfe-commits

Overhatted wrote:

@MaskRay Can you take a look at this PR? For now I'm not looking for a full 
review, just an answer to my question of whether supporting a relative 
directory in the "directory" field of a compilation database is an acceptable 
change. Thanks. 

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


[clang] [analyzer][solver] On SymSym RelOps, check EQClass members for contradictions (PR #71284)

2023-11-06 Thread Balazs Benics via cfe-commits

steakhal wrote:

> @DonatNagyE  The most straightforward issue that I see is that (if I 
> understand the code correctly) the intersected constraint (the value of the 
> variable `Constraint` at the end of 
> `handleEquivalentAlternativeSymOperands()`) is just discarded after checking 
> that it's not empty. It's plausible that this discarded information will be 
> re-calculated by this process in the follow-up range calculations and don't 
> have a concrete testcase where it's relevant that we "leave food on the 
> table" (I can try to find one if you'd find it helpful) but I think that it 
> may be useful to think about "preserving" this `Constraint` that we 
> calculated. (This is not a blocking issue: I can support merging the current 
> logic if you don't see a reasonably simple improvement in this area.)

I tried adding this hunk at the end of the function, but the assertion never 
fired:
```c++
  // If we learned something, save it.
  if (Constraint != OriginalConstraint) {
assert(false);
State = assign(EquivalenceClass::find(State, SymSym), Constraint);
return static_cast(State);
  }
```

> There is also the choice that you limited the runtime to `|eqclass(X)| + 
> |eqclass(Y)|` by only checking the alternative constraints where one of the 
> two representatives is the original one. I think that here it's a good 
> decision to ensure a reasonable runtime by potentially discarding some 
> information, but I feel that it'd be good to document this decision with a 
> testcase. For example, I think
> 
> ```
> void gh_62215_left_and_right(int x, int y, int z, int w) {
>   if (x != y) return; // x == y
>   if (z != w) return; // z == w
>   if (z <= x) return; // z > x
>   if (w >= y) return; // w < y
> }
> ```

Fair point. Actually, originally I wanted a full cross-product of the 
alternatives, which I refined to a half-cross-product by following Gábor's 
comments. We shall come back here and do something more refined if there is a 
practical need.
I added a FIXME comment explaining our options, along with the test case you 
proposed. Thanks.

> Finally there is the "why do we need this trickery at all?" question that was 
> also raised by @Xazax-hun. I agree with him that on a longer term, it'd be 
> good to "strengthen" the equality classes and ensure that we assign the same 
> RangeSet to each member of an EQClass (or, in other words, we assign the 
> RangeSet to an EQClass instead of an individual symbol). This would 
> potentially improve the runtime (although I'm not sure that performance is 
> especially relevant here) and handle the left-and-right testcase adequately.

I think we haven't discussed yet the approach of applying the constraint to 
every eqclass member. That would feel like defeating the purpose of eqclasses 
at all.
To me, our best option so far is to keep the representative symbols alive and 
canonicalize (replace) all sub-symbols in constraints with representatives 
whenever we merge eqclasses or add constraints.

Thanks for the reviews folks!

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


[clang] [clang][dataflow] Fix assert-fail when calling assignment operator with by-value parameter. (PR #71384)

2023-11-06 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/71384

The code assumed that the source parameter of an assignment operator is always
passed by reference, but it is legal for it to be passed by value.

This patch includes a test that assert-fails without the fix.


>From 113a40e6c9117356428d5cd791f0c014389e27f5 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Mon, 6 Nov 2023 12:13:05 +
Subject: [PATCH] [clang][dataflow] Fix assert-fail when calling assignment
 operator with by-value parameter.

The code assumed that the source parameter of an assignment operator is always
passed by reference, but it is legal for it to be passed by value.

This patch includes a test that assert-fails without the fix.
---
 clang/lib/Analysis/FlowSensitive/Transfer.cpp | 10 -
 .../Analysis/FlowSensitive/TransferTest.cpp   | 37 +++
 2 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index bb26e9f8dc8db85..8b2f8ecc5027e8a 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -514,8 +514,14 @@ class TransferVisitor : public 
ConstStmtVisitor {
   !Method->isMoveAssignmentOperator())
 return;
 
-  auto *LocSrc =
-  cast_or_null(Env.getStorageLocation(*Arg1));
+  RecordStorageLocation *LocSrc = nullptr;
+  if (Arg1->isPRValue()) {
+if (auto *Val = cast_or_null(Env.getValue(*Arg1)))
+  LocSrc = &Val->getLoc();
+  } else {
+LocSrc =
+cast_or_null(Env.getStorageLocation(*Arg1));
+  }
   auto *LocDst =
   cast_or_null(Env.getStorageLocation(*Arg0));
 
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 0f9f13df817075e..bd9b98178b5d4e3 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2213,6 +2213,43 @@ TEST(TransferTest, AssignmentOperator) {
   });
 }
 
+// It's legal for the assignment operator to take its source parameter by 
value.
+// Check that we handle this correctly. (This is a repro -- we used to
+// assert-fail on this.)
+TEST(TransferTest, AssignmentOperator_ArgByValue) {
+  std::string Code = R"(
+struct A {
+  int Baz;
+  A &operator=(A);
+};
+
+void target() {
+  A Foo = { 1 };
+  A Bar = { 2 };
+  Foo = Bar;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+
+const auto &FooLoc =
+getLocForDecl(ASTCtx, Env, "Foo");
+const auto &BarLoc =
+getLocForDecl(ASTCtx, Env, "Bar");
+
+const auto *FooBazVal =
+cast(getFieldValue(&FooLoc, *BazDecl, Env));
+const auto *BarBazVal =
+cast(getFieldValue(&BarLoc, *BazDecl, Env));
+EXPECT_EQ(FooBazVal, BarBazVal);
+  });
+}
+
 TEST(TransferTest, AssignmentOperatorFromBase) {
   // This is a crash repro. We don't model the copy this case, so no
   // expectations on the copied field of the base class are checked.

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


[clang] [clang][dataflow] Fix assert-fail when calling assignment operator with by-value parameter. (PR #71384)

2023-11-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-analysis

Author: None (martinboehme)


Changes

The code assumed that the source parameter of an assignment operator is always
passed by reference, but it is legal for it to be passed by value.

This patch includes a test that assert-fails without the fix.


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


2 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/Transfer.cpp (+8-2) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+37) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index bb26e9f8dc8db85..8b2f8ecc5027e8a 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -514,8 +514,14 @@ class TransferVisitor : public 
ConstStmtVisitor {
   !Method->isMoveAssignmentOperator())
 return;
 
-  auto *LocSrc =
-  cast_or_null(Env.getStorageLocation(*Arg1));
+  RecordStorageLocation *LocSrc = nullptr;
+  if (Arg1->isPRValue()) {
+if (auto *Val = cast_or_null(Env.getValue(*Arg1)))
+  LocSrc = &Val->getLoc();
+  } else {
+LocSrc =
+cast_or_null(Env.getStorageLocation(*Arg1));
+  }
   auto *LocDst =
   cast_or_null(Env.getStorageLocation(*Arg0));
 
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 0f9f13df817075e..bd9b98178b5d4e3 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2213,6 +2213,43 @@ TEST(TransferTest, AssignmentOperator) {
   });
 }
 
+// It's legal for the assignment operator to take its source parameter by 
value.
+// Check that we handle this correctly. (This is a repro -- we used to
+// assert-fail on this.)
+TEST(TransferTest, AssignmentOperator_ArgByValue) {
+  std::string Code = R"(
+struct A {
+  int Baz;
+  A &operator=(A);
+};
+
+void target() {
+  A Foo = { 1 };
+  A Bar = { 2 };
+  Foo = Bar;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+
+const auto &FooLoc =
+getLocForDecl(ASTCtx, Env, "Foo");
+const auto &BarLoc =
+getLocForDecl(ASTCtx, Env, "Bar");
+
+const auto *FooBazVal =
+cast(getFieldValue(&FooLoc, *BazDecl, Env));
+const auto *BarBazVal =
+cast(getFieldValue(&BarLoc, *BazDecl, Env));
+EXPECT_EQ(FooBazVal, BarBazVal);
+  });
+}
+
 TEST(TransferTest, AssignmentOperatorFromBase) {
   // This is a crash repro. We don't model the copy this case, so no
   // expectations on the copied field of the base class are checked.

``




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


[clang] [analyzer][solver] On SymSym RelOps, check EQClass members for contradictions (PR #71284)

2023-11-06 Thread Balazs Benics via cfe-commits

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

>From 92ece501b340c3a2a52b5a4614ddb70bb3e35c93 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Sat, 4 Nov 2023 13:44:28 +0100
Subject: [PATCH 1/3] [analyzer][solver] On SymSym RelOps, check EQClass
 members for contradictions

The idea is that if we see a `X RELOP Y` being constrained to a RangeSet `S`,
then check the eqclasses of X and Y respectively and for `X' RELOP Y'`
SymSymExprs and try to infer their ranges.
If there is no contradiction with any of the equivalent alternatives,
then intersecting all these RangeSets should never be empty - aka. there
should be a value satisfying the constraints we have.

It costs around `|eqclass(X)| + |eqclass(y)|`.

The approach has its limitations, as demonstrated by
`gh_62215_contradicting_nested_right_equivalent`, where we would need to
apply the same logic, but on a sub-expression of a direct operand.

Before the patch, line 90, 100, and 112 would be reachable; and become
unreachable after this. Line 127 will remain still reachable, but keep
in mind that when cross-checking with Z3 (aka. Z3 refutation), then all
4 reports would be eliminated.

The idea comes from
https://github.com/llvm/llvm-project/issues/62215#issuecomment-1792878474

Fixes #62215
---
 .../Core/RangeConstraintManager.cpp   | 53 +++
 clang/test/Analysis/constraint-assignor.c | 48 +
 2 files changed, 101 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 5de99384449a4c8..d631369e895d3a9 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2067,6 +2067,12 @@ class ConstraintAssignor : public 
ConstraintAssignorBase {
 return Assignor.assign(CoS, NewConstraint);
   }
 
+  /// Check if using an equivalent operand alternative would lead to
+  /// contradiction.
+  /// If a contradiction is witnessed, returns false; otherwise returns true.
+  bool handleEquivalentAlternativeSymOperands(const SymSymExpr *SymSym,
+  RangeSet Constraint);
+
   /// Handle expressions like: a % b != 0.
   template 
   bool handleRemainderOp(const SymT *Sym, RangeSet Constraint) {
@@ -2218,11 +2224,58 @@ bool ConstraintAssignor::assignSymExprToConst(const 
SymExpr *Sym,
   return true;
 }
 
+bool ConstraintAssignor::handleEquivalentAlternativeSymOperands(
+const SymSymExpr *SymSym, RangeSet Constraint) {
+  SymbolRef LHS = SymSym->getLHS();
+  SymbolRef RHS = SymSym->getRHS();
+  EquivalenceClass LHSClass = EquivalenceClass::find(State, LHS);
+  EquivalenceClass RHSClass = EquivalenceClass::find(State, RHS);
+  SymbolSet SymbolsEqWithLHS = LHSClass.getClassMembers(State);
+  SymbolSet SymbolsEqWithRHS = RHSClass.getClassMembers(State);
+  llvm::SmallVector AlternativeSymSyms;
+
+  // Gather left alternatives.
+  for (SymbolRef AlternativeLHS : SymbolsEqWithLHS) {
+if (AlternativeLHS == LHS)
+  continue;
+AlternativeSymSyms.emplace_back(AlternativeLHS, SymSym->getOpcode(), RHS,
+SymSym->getType());
+  }
+
+  // Gather right alternatives.
+  for (SymbolRef AlternativeRHS : SymbolsEqWithRHS) {
+if (AlternativeRHS == RHS)
+  continue;
+AlternativeSymSyms.emplace_back(LHS, SymSym->getOpcode(), AlternativeRHS,
+SymSym->getType());
+  }
+
+  // Crosscheck the inferred ranges.
+  for (SymSymExpr AltSymSym : AlternativeSymSyms) {
+RangeSet AltSymSymConstrant =
+SymbolicRangeInferrer::inferRange(RangeFactory, State, &AltSymSym);
+Constraint = intersect(RangeFactory, Constraint, AltSymSymConstrant);
+
+// Check if we witnessed a contradiction with the equivalent alternative
+// operand.
+if (Constraint.isEmpty()) {
+  State = nullptr;
+  return false;
+}
+  }
+  return true;
+}
+
 bool ConstraintAssignor::assignSymSymExprToRangeSet(const SymSymExpr *Sym,
 RangeSet Constraint) {
   if (!handleRemainderOp(Sym, Constraint))
 return false;
 
+  if (const auto *SymSym = dyn_cast(Sym);
+  SymSym && !handleEquivalentAlternativeSymOperands(SymSym, Constraint)) {
+return false;
+  }
+
   std::optional ConstraintAsBool = interpreteAsBool(Constraint);
 
   if (!ConstraintAsBool)
diff --git a/clang/test/Analysis/constraint-assignor.c 
b/clang/test/Analysis/constraint-assignor.c
index 8210e576c98bd21..d5078b406e12601 100644
--- a/clang/test/Analysis/constraint-assignor.c
+++ b/clang/test/Analysis/constraint-assignor.c
@@ -82,3 +82,51 @@ void remainder_with_adjustment_of_composit_lhs(int x, int y) 
{
   clang_analyzer_eval(x + y != -1);// expected-warning{{TRUE}}
   (void)(x * y); // keep the constraints alive.
 }
+
+void gh_62215(int x, int y, int z) {
+  if (x != y) return; // x ==

[clang-tools-extra] [clang] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-06 Thread Aaron Ballman via cfe-commits


@@ -2034,18 +2035,19 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool 
UseGlobal,
   // - If the new-initializer is omitted, the object is default-
   //   initialized (8.5); if no initialization is performed,
   //   the object has indeterminate value
-  = initStyle == CXXNewExpr::NoInit
+  = initStyle == CXXNewInitializationStyle::None ||
+initStyle == CXXNewInitializationStyle::Implicit
 ? InitializationKind::CreateDefault(TypeRange.getBegin())
-// - Otherwise, the new-initializer is interpreted according to
-// the
-//   initialization rules of 8.5 for direct-initialization.
-: initStyle == CXXNewExpr::ListInit
-  ? InitializationKind::CreateDirectList(
-TypeRange.getBegin(), Initializer->getBeginLoc(),
-Initializer->getEndLoc())
-  : InitializationKind::CreateDirect(TypeRange.getBegin(),
- 
DirectInitRange.getBegin(),
- DirectInitRange.getEnd());
+// - Otherwise, the new-initializer is interpreted according to
+// the
+//   initialization rules of 8.5 for direct-initialization.
+: initStyle == CXXNewInitializationStyle::List
+? InitializationKind::CreateDirectList(TypeRange.getBegin(),
+   Initializer->getBeginLoc(),
+   Initializer->getEndLoc())
+: InitializationKind::CreateDirect(TypeRange.getBegin(),
+   DirectInitRange.getBegin(),
+   DirectInitRange.getEnd());

AaronBallman wrote:

Convert this to a `switch` so it's easier to read?

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


[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-06 Thread Aaron Ballman via cfe-commits


@@ -2008,22 +2008,23 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool 
UseGlobal,
   SourceRange TypeRange = AllocTypeInfo->getTypeLoc().getSourceRange();
   SourceLocation StartLoc = Range.getBegin();
 
-  CXXNewExpr::InitializationStyle initStyle;
+  CXXNewInitializationStyle initStyle;

AaronBallman wrote:

```suggestion
  CXXNewInitializationStyle InitStyle;
```
since we're already touching all those lines anyway? (I don't insist.)

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


[clang-tools-extra] [clang-tidy] Improve alternate snake case warnings (PR #71385)

2023-11-06 Thread J.C. Moyer via cfe-commits

https://github.com/jcmoyer created 
https://github.com/llvm/llvm-project/pull/71385

Improves the accuracy of `readability-identifier-naming` for cases 
`Camel_Snake_Case` and `camel_Snake_Back`. Prior to this commit, these cases 
matched identifiers with **only** a leading upper case letter or leading lower 
case letter respectively. Now, uppercase letters can only appear at the start 
of an identifier or directly following an underscore.

---

Currently, the regex for `Camel_Snake_Case` matches any identifier that starts 
with a capital letter:

```
^[A-Z]([a-z0-9]*(_[A-Z])?)*
^-- underscore + capital letter after the first capital 
is optional
```

This means that `Camel_Snake_Case` matches other cases - in particular 
`CamelCase` and `Leading_upper_snake_case` - which causes clang-tidy to 
sometimes not flag incorrect casing. It also matches `UPPER_CASE`, but I think 
it's reasonable to consider this a subset of `Camel_Snake_Case` since some 
users may prefer e.g. `XML_Parser` to `Xml_Parser`. It's really easy to 
accidentally type an identifier that clang-tidy doesn't catch; all you have to 
do is omit an underscore or forget to capitalize a letter. The same problem 
also applies to `camel_Snake_Back` except that any identifier starting with a 
lower case letter matches, so I went ahead and adjusted its regex too. Fixing 
it also uncovered a minor error in an existing test.

Here are some examples of the current behavior when using `Camel_Snake_Case`:

```cpp
// accepted by clang-tidy
String_Reader
StringReader  // bad, CamelCase
String_reader // bad, Leading_upper_snake_case
Xml_Parser_2
XML_Parser_2
XML_PaRser_2  // bad? mixed case in second word
T
Foo
A_B_C
A_b_c // bad, Leading_upper_snake_case

// rejected by clang-tidy
t
foo
a_b_c
```

After this patch:

```cpp
// accepted by clang-tidy
String_Reader
Xml_Parser_2
XML_Parser_2
T
Foo
A_B_C

// rejected by clang-tidy
StringReader
String_reader
XML_PaRser_2
t
foo
A_b_c
a_b_c
```


>From e5f12dfd2ea81f6a2c5a2978733f88da4da8420a Mon Sep 17 00:00:00 2001
From: "J.C. Moyer" 
Date: Sun, 5 Nov 2023 17:21:32 -0500
Subject: [PATCH] [clang-tidy] Improve alternate snake case warnings

Improves the accuracy of `readability-identifier-naming` for cases
`Camel_Snake_Case` and `camel_Snake_Back`. Prior to this commit, these
cases matched identifiers with only a leading upper case letter or
leading lower case letter respectively. Now, uppercase letters can only
appear at the start of an identifier or directly following an
underscore.
---
 .../readability/IdentifierNamingCheck.cpp |  4 +-
 .../identifier-naming-case-match.cpp  | 60 +++
 .../readability/identifier-naming.cpp |  3 +-
 3 files changed, 64 insertions(+), 3 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 7539b3899682e13..793b86cadd72501 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -871,8 +871,8 @@ bool IdentifierNamingCheck::matchesStyle(
   llvm::Regex("^[a-z][a-zA-Z0-9]*$"),
   llvm::Regex("^[A-Z][A-Z0-9_]*$"),
   llvm::Regex("^[A-Z][a-zA-Z0-9]*$"),
-  llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
-  llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"),
+  llvm::Regex("^[A-Z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
+  llvm::Regex("^[a-z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
   llvm::Regex("^[A-Z]([a-z0-9_]*[a-z])*$"),
   };
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
new file mode 100644
index 000..f692b01923455e8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
@@ -0,0 +1,60 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-identifier-naming %t -- \
+// RUN:   -config='{CheckOptions: { \
+// RUN: readability-identifier-naming.ClassCase: Camel_Snake_Case, \
+// RUN: readability-identifier-naming.StructCase: camel_Snake_Back, \
+// RUN:   }}'
+
+// clang-format off
+
+//===--===//
+// Camel_Snake_Case tests
+//===--===//
+class XML_Parser {};
+class Xml_Parser {};
+class XML_Parser_2 {};
+// NO warnings or fixes expected as these identifiers are Camel_Snake_Case
+
+class XmlParser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'XmlParser'
+// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}
+
+class Xml_parser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'Xm

[clang-tools-extra] [clang-tidy] Improve alternate snake case warnings (PR #71385)

2023-11-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: J.C. Moyer (jcmoyer)


Changes

Improves the accuracy of `readability-identifier-naming` for cases 
`Camel_Snake_Case` and `camel_Snake_Back`. Prior to this commit, these cases 
matched identifiers with **only** a leading upper case letter or leading lower 
case letter respectively. Now, uppercase letters can only appear at the start 
of an identifier or directly following an underscore.

---

Currently, the regex for `Camel_Snake_Case` matches any identifier that starts 
with a capital letter:

```
^[A-Z]([a-z0-9]*(_[A-Z])?)*
^-- underscore + capital letter after the first capital 
is optional
```

This means that `Camel_Snake_Case` matches other cases - in particular 
`CamelCase` and `Leading_upper_snake_case` - which causes clang-tidy to 
sometimes not flag incorrect casing. It also matches `UPPER_CASE`, but I think 
it's reasonable to consider this a subset of `Camel_Snake_Case` since some 
users may prefer e.g. `XML_Parser` to `Xml_Parser`. It's really easy to 
accidentally type an identifier that clang-tidy doesn't catch; all you have to 
do is omit an underscore or forget to capitalize a letter. The same problem 
also applies to `camel_Snake_Back` except that any identifier starting with a 
lower case letter matches, so I went ahead and adjusted its regex too. Fixing 
it also uncovered a minor error in an existing test.

Here are some examples of the current behavior when using `Camel_Snake_Case`:

```cpp
// accepted by clang-tidy
String_Reader
StringReader  // bad, CamelCase
String_reader // bad, Leading_upper_snake_case
Xml_Parser_2
XML_Parser_2
XML_PaRser_2  // bad? mixed case in second word
T
Foo
A_B_C
A_b_c // bad, Leading_upper_snake_case

// rejected by clang-tidy
t
foo
a_b_c
```

After this patch:

```cpp
// accepted by clang-tidy
String_Reader
Xml_Parser_2
XML_Parser_2
T
Foo
A_B_C

// rejected by clang-tidy
StringReader
String_reader
XML_PaRser_2
t
foo
A_b_c
a_b_c
```


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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
(+2-2) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
 (+60) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp 
(+2-1) 


``diff
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 7539b3899682e13..793b86cadd72501 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -871,8 +871,8 @@ bool IdentifierNamingCheck::matchesStyle(
   llvm::Regex("^[a-z][a-zA-Z0-9]*$"),
   llvm::Regex("^[A-Z][A-Z0-9_]*$"),
   llvm::Regex("^[A-Z][a-zA-Z0-9]*$"),
-  llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
-  llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"),
+  llvm::Regex("^[A-Z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
+  llvm::Regex("^[a-z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
   llvm::Regex("^[A-Z]([a-z0-9_]*[a-z])*$"),
   };
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
new file mode 100644
index 000..f692b01923455e8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
@@ -0,0 +1,60 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-identifier-naming %t -- \
+// RUN:   -config='{CheckOptions: { \
+// RUN: readability-identifier-naming.ClassCase: Camel_Snake_Case, \
+// RUN: readability-identifier-naming.StructCase: camel_Snake_Back, \
+// RUN:   }}'
+
+// clang-format off
+
+//===--===//
+// Camel_Snake_Case tests
+//===--===//
+class XML_Parser {};
+class Xml_Parser {};
+class XML_Parser_2 {};
+// NO warnings or fixes expected as these identifiers are Camel_Snake_Case
+
+class XmlParser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'XmlParser'
+// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}
+
+class Xml_parser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'Xml_parser'
+// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}
+
+class xml_parser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'xml_parser'
+// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}
+
+class xml_Parser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'xml_Parser'
+// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}
+
+class xml_Parser_2 {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'xml_Par

[clang] [analyzer][solver] On SymSym RelOps, check EQClass members for contradictions (PR #71284)

2023-11-06 Thread via cfe-commits

DonatNagyE wrote:

> I think we haven't discussed yet the approach of applying the constraint to 
> every eqclass member. That would feel like defeating the purpose of eqclasses 
> at all.

I only mentioned it because from a high-level perspective it's equivalent to 
applying the constraint on the eqclass representative (and acts as a 
"simplified description" of that approach); I don't think that we should use it 
as an actual implementation.

> To me, our best option so far is to keep the representative symbols alive and 
> canonicalize (replace) all sub-symbols in constraints with representatives 
> whenever we merge eqclasses or add constraints.

Yes, that seems to be the best way forward. It would probably imply that we 
introduce an "undead" (=no longer reachable, but kept as a representative) 
state for symbols which seems to be inelegant, but I think that it won't cause 
actual problems during the implementation.

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


[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-06 Thread Vlad Serebrennikov via cfe-commits

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

>From 40d25b8009f1c8734a99fd1350adaced6884cc7f Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 5 Nov 2023 18:53:48 +0300
Subject: [PATCH 1/5] [clang][NFC] Refacator `CXXNewExpr::InitializationStyle`

This patch converts `CXXNewExpr::InitializationStyle` into a scoped enum at 
namespace scope. It also affirms the status quo by adding a new enumerator to 
represent implicit initializer.
---
 .../modernize/MakeSmartPtrCheck.cpp   |  7 +--
 clang/include/clang/AST/ExprCXX.h | 48 +++
 clang/lib/AST/ExprCXX.cpp | 12 ++---
 clang/lib/AST/ItaniumMangle.cpp   |  4 +-
 clang/lib/AST/JSONNodeDumper.cpp  |  7 +--
 clang/lib/AST/StmtPrinter.cpp |  6 +--
 clang/lib/AST/StmtProfile.cpp |  2 +-
 clang/lib/Sema/SemaExprCXX.cpp| 22 -
 8 files changed, 58 insertions(+), 50 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index 71fd8eca300c1b2..616e57efa76ded5 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -323,7 +323,8 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 return false;
   };
   switch (New->getInitializationStyle()) {
-  case CXXNewExpr::NoInit: {
+  case CXXNewInitializationStyle::None:
+  case CXXNewInitializationStyle::Implicit: {
 if (ArraySizeExpr.empty()) {
   Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
 } else {
@@ -334,7 +335,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewExpr::CallInit: {
+  case CXXNewInitializationStyle::Call: {
 // FIXME: Add fixes for constructors with parameters that can be created
 // with a C++11 braced-init-list (e.g. std::vector, std::map).
 // Unlike ordinal cases, braced list can not be deduced in
@@ -371,7 +372,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewExpr::ListInit: {
+  case CXXNewInitializationStyle::List: {
 // Range of the substring that we do not want to remove.
 SourceRange InitRange;
 if (const auto *NewConstruct = New->getConstructExpr()) {
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index a106bafcfa3e021..d713bcf8eb70258 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2206,6 +2206,20 @@ class CXXScalarValueInitExpr : public Expr {
   }
 };
 
+enum class CXXNewInitializationStyle {
+  /// New-expression has no initializer as written.
+  None,
+
+  /// New-expression has no written initializer, but has an implicit one.
+  Implicit,
+
+  /// New-expression has a C++98 paren-delimited initializer.
+  Call,
+
+  /// New-expression has a C++11 list-initializer.
+  List
+};
+
 /// Represents a new-expression for memory allocation and constructor
 /// calls, e.g: "new CXXNewExpr(foo)".
 class CXXNewExpr final
@@ -2259,25 +2273,12 @@ class CXXNewExpr final
 return isParenTypeId();
   }
 
-public:
-  enum InitializationStyle {
-/// New-expression has no initializer as written.
-NoInit,
-
-/// New-expression has a C++98 paren-delimited initializer.
-CallInit,
-
-/// New-expression has a C++11 list-initializer.
-ListInit
-  };
-
-private:
   /// Build a c++ new expression.
   CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- InitializationStyle InitializationStyle, Expr *Initializer,
+ CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2292,7 +2293,7 @@ class CXXNewExpr final
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- InitializationStyle InitializationStyle, Expr *Initializer,
+ CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2388,15 +2389,20 @@ class CXXNewExpr final
 
   /// Whether this new-expression has any initializer at all.
   bool hasInitializer() const {
-return CXXNewExprBits.StoredInitializationStyle > 0;
+switch(getInitializationStyle()) {
+case CXXNewInitializationStyle::None:
+  return true;
+case CXXNewInitializationStyle::Implicit:
+   

[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-06 Thread Vlad Serebrennikov via cfe-commits


@@ -2008,22 +2008,23 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool 
UseGlobal,
   SourceRange TypeRange = AllocTypeInfo->getTypeLoc().getSourceRange();
   SourceLocation StartLoc = Range.getBegin();
 
-  CXXNewExpr::InitializationStyle initStyle;
+  CXXNewInitializationStyle initStyle;

Endilll wrote:

Done!

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


[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-06 Thread Vlad Serebrennikov via cfe-commits


@@ -2034,18 +2035,19 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool 
UseGlobal,
   // - If the new-initializer is omitted, the object is default-
   //   initialized (8.5); if no initialization is performed,
   //   the object has indeterminate value
-  = initStyle == CXXNewExpr::NoInit
+  = initStyle == CXXNewInitializationStyle::None ||
+initStyle == CXXNewInitializationStyle::Implicit
 ? InitializationKind::CreateDefault(TypeRange.getBegin())
-// - Otherwise, the new-initializer is interpreted according to
-// the
-//   initialization rules of 8.5 for direct-initialization.
-: initStyle == CXXNewExpr::ListInit
-  ? InitializationKind::CreateDirectList(
-TypeRange.getBegin(), Initializer->getBeginLoc(),
-Initializer->getEndLoc())
-  : InitializationKind::CreateDirect(TypeRange.getBegin(),
- 
DirectInitRange.getBegin(),
- DirectInitRange.getEnd());
+// - Otherwise, the new-initializer is interpreted according to
+// the
+//   initialization rules of 8.5 for direct-initialization.
+: initStyle == CXXNewInitializationStyle::List
+? InitializationKind::CreateDirectList(TypeRange.getBegin(),
+   Initializer->getBeginLoc(),
+   Initializer->getEndLoc())
+: InitializationKind::CreateDirect(TypeRange.getBegin(),
+   DirectInitRange.getBegin(),
+   DirectInitRange.getEnd());

Endilll wrote:

Because `InitializationKind` doesn't have default constructor, I had to resort 
to immediately invoked lambda expression (IILE). I think it is an improvement, 
but I haven't seen IILE in Clang code base before, so I'm not sure.

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


[clang] [llvm] [WebAssembly] Mark externref as not being valid vector elements (PR #71069)

2023-11-06 Thread Paulo Matos via cfe-commits

pmatos wrote:

I am now investigating the use of TargetExtTypes to represent Wasm Reference 
Types.

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


[clang-tools-extra] [clang] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-06 Thread Vlad Serebrennikov via cfe-commits

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


[clang-tools-extra] [clang] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Vlad Serebrennikov (Endilll)


Changes

This patch converts `CXXNewExpr::InitializationStyle` into a scoped enum at 
namespace scope. It also affirms the status quo by adding a new enumerator to 
represent implicit initializer.

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


8 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(+4-3) 
- (modified) clang/include/clang/AST/ExprCXX.h (+27-21) 
- (modified) clang/lib/AST/ExprCXX.cpp (+15-14) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+3-2) 
- (modified) clang/lib/AST/JSONNodeDumper.cpp (+9-3) 
- (modified) clang/lib/AST/StmtPrinter.cpp (+4-3) 
- (modified) clang/lib/AST/StmtProfile.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+33-27) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index 71fd8eca300c1b2..616e57efa76ded5 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -323,7 +323,8 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 return false;
   };
   switch (New->getInitializationStyle()) {
-  case CXXNewExpr::NoInit: {
+  case CXXNewInitializationStyle::None:
+  case CXXNewInitializationStyle::Implicit: {
 if (ArraySizeExpr.empty()) {
   Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
 } else {
@@ -334,7 +335,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewExpr::CallInit: {
+  case CXXNewInitializationStyle::Call: {
 // FIXME: Add fixes for constructors with parameters that can be created
 // with a C++11 braced-init-list (e.g. std::vector, std::map).
 // Unlike ordinal cases, braced list can not be deduced in
@@ -371,7 +372,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewExpr::ListInit: {
+  case CXXNewInitializationStyle::List: {
 // Range of the substring that we do not want to remove.
 SourceRange InitRange;
 if (const auto *NewConstruct = New->getConstructExpr()) {
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index a106bafcfa3e021..37d310ef967d9c0 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2206,6 +2206,20 @@ class CXXScalarValueInitExpr : public Expr {
   }
 };
 
+enum class CXXNewInitializationStyle {
+  /// New-expression has no initializer as written.
+  None,
+
+  /// New-expression has no written initializer, but has an implicit one.
+  Implicit,
+
+  /// New-expression has a C++98 paren-delimited initializer.
+  Call,
+
+  /// New-expression has a C++11 list-initializer.
+  List
+};
+
 /// Represents a new-expression for memory allocation and constructor
 /// calls, e.g: "new CXXNewExpr(foo)".
 class CXXNewExpr final
@@ -2259,25 +2273,12 @@ class CXXNewExpr final
 return isParenTypeId();
   }
 
-public:
-  enum InitializationStyle {
-/// New-expression has no initializer as written.
-NoInit,
-
-/// New-expression has a C++98 paren-delimited initializer.
-CallInit,
-
-/// New-expression has a C++11 list-initializer.
-ListInit
-  };
-
-private:
   /// Build a c++ new expression.
   CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- InitializationStyle InitializationStyle, Expr *Initializer,
+ CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2292,7 +2293,7 @@ class CXXNewExpr final
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- InitializationStyle InitializationStyle, Expr *Initializer,
+ CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2388,15 +2389,20 @@ class CXXNewExpr final
 
   /// Whether this new-expression has any initializer at all.
   bool hasInitializer() const {
-return CXXNewExprBits.StoredInitializationStyle > 0;
+switch (getInitializationStyle()) {
+case CXXNewInitializationStyle::None:
+  return false;
+case CXXNewInitializationStyle::Implicit:
+case CXXNewInitializationStyle::Call:
+case CXXNewInitializationStyle::List:
+  return true;
+}
   }
 
   /// The kind of initializer this new-expressio

[clang-tools-extra] [clang] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-06 Thread Aaron Ballman via cfe-commits

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

LGTM!

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


[clang-tools-extra] ace4489 - [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (#71322)

2023-11-06 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-06T17:34:22+04:00
New Revision: ace4489397d17abfb20d36de1404cfbe102401a7

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

LOG: [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (#71322)

This patch converts `CXXNewExpr::InitializationStyle` into a scoped enum at 
namespace scope. It also affirms the status quo by adding a new enumerator to 
represent implicit initializer.

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang/include/clang/AST/ExprCXX.h
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Sema/SemaExprCXX.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index 71fd8eca300c1b2..616e57efa76ded5 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -323,7 +323,8 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 return false;
   };
   switch (New->getInitializationStyle()) {
-  case CXXNewExpr::NoInit: {
+  case CXXNewInitializationStyle::None:
+  case CXXNewInitializationStyle::Implicit: {
 if (ArraySizeExpr.empty()) {
   Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
 } else {
@@ -334,7 +335,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewExpr::CallInit: {
+  case CXXNewInitializationStyle::Call: {
 // FIXME: Add fixes for constructors with parameters that can be created
 // with a C++11 braced-init-list (e.g. std::vector, std::map).
 // Unlike ordinal cases, braced list can not be deduced in
@@ -371,7 +372,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewExpr::ListInit: {
+  case CXXNewInitializationStyle::List: {
 // Range of the substring that we do not want to remove.
 SourceRange InitRange;
 if (const auto *NewConstruct = New->getConstructExpr()) {

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index a106bafcfa3e021..37d310ef967d9c0 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2206,6 +2206,20 @@ class CXXScalarValueInitExpr : public Expr {
   }
 };
 
+enum class CXXNewInitializationStyle {
+  /// New-expression has no initializer as written.
+  None,
+
+  /// New-expression has no written initializer, but has an implicit one.
+  Implicit,
+
+  /// New-expression has a C++98 paren-delimited initializer.
+  Call,
+
+  /// New-expression has a C++11 list-initializer.
+  List
+};
+
 /// Represents a new-expression for memory allocation and constructor
 /// calls, e.g: "new CXXNewExpr(foo)".
 class CXXNewExpr final
@@ -2259,25 +2273,12 @@ class CXXNewExpr final
 return isParenTypeId();
   }
 
-public:
-  enum InitializationStyle {
-/// New-expression has no initializer as written.
-NoInit,
-
-/// New-expression has a C++98 paren-delimited initializer.
-CallInit,
-
-/// New-expression has a C++11 list-initializer.
-ListInit
-  };
-
-private:
   /// Build a c++ new expression.
   CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- InitializationStyle InitializationStyle, Expr *Initializer,
+ CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2292,7 +2293,7 @@ class CXXNewExpr final
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- InitializationStyle InitializationStyle, Expr *Initializer,
+ CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2388,15 +2389,20 @@ class CXXNewExpr final
 
   /// Whether this new-expression has any initializer at all.
   bool hasInitializer() const {
-return CXXNewExprBits.StoredInitializationStyle > 0;
+switch (getInitializationStyle()) {
+case CXXNewInitializationStyle::None:
+  return false;
+case CXXNewInitializationStyle::Implicit:
+case CXXNew

[clang-tools-extra] [clang] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-06 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang][analyzer] Improve 'errno' handling in StdLibraryFunctionsChecker. (PR #71392)

2023-11-06 Thread Balázs Kéri via cfe-commits

https://github.com/balazske created 
https://github.com/llvm/llvm-project/pull/71392

The checker now displays one combined note tag for errno-related and 
"case"-related notes. Previous functions in the errno-modeling part that were 
used for construction of note tags are removed. The note tag added by 
StdLibraryFunctionsChecker contains the code to display the note tag for 
'errno' (this was done previously by these removed functions).

From e92bf72fc80bb6823996cb71cb811d238b304aaa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Thu, 2 Nov 2023 18:12:32 +0100
Subject: [PATCH] [clang][analyzer] Improve 'errno' handling in
 StdLibraryFunctionsChecker.

The checker now displays one combined note tag for errno-related and
"case"-related notes. Previous functions in the errno-modeling part
that were used for construction of note tags are removed. The note tag
added by StdLibraryFunctionsChecker contains the code to display the
note tag for 'errno' (this was done previously by these removed
functions).
---
 .../StaticAnalyzer/Checkers/ErrnoModeling.cpp |  12 ---
 .../StaticAnalyzer/Checkers/ErrnoModeling.h   |  16 +--
 .../Checkers/StdLibraryFunctionsChecker.cpp   | 101 ++
 .../errno-stdlibraryfunctions-notes.c |   4 +-
 .../std-c-library-functions-path-notes.c  |   9 ++
 clang/test/Analysis/stream-errno-note.c   |  41 +--
 6 files changed, 101 insertions(+), 82 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
index be2fa91b994a26d..1b34ea0e056e563 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
@@ -312,18 +312,6 @@ ProgramStateRef setErrnoStdMustBeChecked(ProgramStateRef 
State,
   return setErrnoState(State, MustBeChecked);
 }
 
-const NoteTag *getNoteTagForStdSuccess(CheckerContext &C, llvm::StringRef Fn) {
-  return getErrnoNoteTag(
-  C, llvm::formatv(
- "'errno' may be undefined after successful call to '{0}'", Fn));
-}
-
-const NoteTag *getNoteTagForStdMustBeChecked(CheckerContext &C,
- llvm::StringRef Fn) {
-  return getErrnoNoteTag(
-  C, llvm::formatv("'{0}' indicates failure only by setting 'errno'", Fn));
-}
-
 } // namespace errno_modeling
 } // namespace ento
 } // namespace clang
diff --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h 
b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
index 0707fd16d6e60a2..6b53572fe5e2d93 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
+++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
@@ -84,8 +84,7 @@ const NoteTag *getErrnoNoteTag(CheckerContext &C, const 
std::string &Message);
 
 /// Set errno state for the common case when a standard function is successful.
 /// Set \c ErrnoCheckState to \c MustNotBeChecked (the \c errno value is not
-/// affected). At the state transition a note tag created by
-/// \c getNoteTagForStdSuccess can be used.
+/// affected).
 ProgramStateRef setErrnoForStdSuccess(ProgramStateRef State, CheckerContext 
&C);
 
 /// Set errno state for the common case when a standard function fails.
@@ -100,23 +99,10 @@ ProgramStateRef setErrnoForStdFailure(ProgramStateRef 
State, CheckerContext &C,
 /// Set errno state for the common case when a standard function indicates
 /// failure only by \c errno. Sets \c ErrnoCheckState to \c MustBeChecked, and
 /// invalidates the errno region (clear of previous value).
-/// At the state transition a note tag created by
-/// \c getNoteTagForStdMustBeChecked can be used.
 /// \arg \c InvalE Expression that causes invalidation of \c errno.
 ProgramStateRef setErrnoStdMustBeChecked(ProgramStateRef State,
  CheckerContext &C, const Expr 
*InvalE);
 
-/// Generate the note tag that can be applied at the state generated by
-/// \c setErrnoForStdSuccess .
-/// \arg \c Fn Name of the (standard) function that is modeled.
-const NoteTag *getNoteTagForStdSuccess(CheckerContext &C, llvm::StringRef Fn);
-
-/// Generate the note tag that can be applied at the state generated by
-/// \c setErrnoStdMustBeChecked .
-/// \arg \c Fn Name of the (standard) function that is modeled.
-const NoteTag *getNoteTagForStdMustBeChecked(CheckerContext &C,
- llvm::StringRef Fn);
-
 } // namespace errno_modeling
 } // namespace ento
 } // namespace clang
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 13bb9cef5e490ed..035314c6f7751d5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -533,13 +533,11 @@ class StdLibraryFunctionsChecker
 virtual ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
  

[clang] [clang][analyzer] Improve 'errno' handling in StdLibraryFunctionsChecker. (PR #71392)

2023-11-06 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang

Author: Balázs Kéri (balazske)


Changes

The checker now displays one combined note tag for errno-related and 
"case"-related notes. Previous functions in the errno-modeling part that were 
used for construction of note tags are removed. The note tag added by 
StdLibraryFunctionsChecker contains the code to display the note tag for 
'errno' (this was done previously by these removed functions).

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


6 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp (-12) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h (+1-15) 
- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
(+59-42) 
- (modified) clang/test/Analysis/errno-stdlibraryfunctions-notes.c (+2-2) 
- (modified) clang/test/Analysis/std-c-library-functions-path-notes.c (+9) 
- (modified) clang/test/Analysis/stream-errno-note.c (+30-11) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
index be2fa91b994a26d..1b34ea0e056e563 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
@@ -312,18 +312,6 @@ ProgramStateRef setErrnoStdMustBeChecked(ProgramStateRef 
State,
   return setErrnoState(State, MustBeChecked);
 }
 
-const NoteTag *getNoteTagForStdSuccess(CheckerContext &C, llvm::StringRef Fn) {
-  return getErrnoNoteTag(
-  C, llvm::formatv(
- "'errno' may be undefined after successful call to '{0}'", Fn));
-}
-
-const NoteTag *getNoteTagForStdMustBeChecked(CheckerContext &C,
- llvm::StringRef Fn) {
-  return getErrnoNoteTag(
-  C, llvm::formatv("'{0}' indicates failure only by setting 'errno'", Fn));
-}
-
 } // namespace errno_modeling
 } // namespace ento
 } // namespace clang
diff --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h 
b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
index 0707fd16d6e60a2..6b53572fe5e2d93 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
+++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
@@ -84,8 +84,7 @@ const NoteTag *getErrnoNoteTag(CheckerContext &C, const 
std::string &Message);
 
 /// Set errno state for the common case when a standard function is successful.
 /// Set \c ErrnoCheckState to \c MustNotBeChecked (the \c errno value is not
-/// affected). At the state transition a note tag created by
-/// \c getNoteTagForStdSuccess can be used.
+/// affected).
 ProgramStateRef setErrnoForStdSuccess(ProgramStateRef State, CheckerContext 
&C);
 
 /// Set errno state for the common case when a standard function fails.
@@ -100,23 +99,10 @@ ProgramStateRef setErrnoForStdFailure(ProgramStateRef 
State, CheckerContext &C,
 /// Set errno state for the common case when a standard function indicates
 /// failure only by \c errno. Sets \c ErrnoCheckState to \c MustBeChecked, and
 /// invalidates the errno region (clear of previous value).
-/// At the state transition a note tag created by
-/// \c getNoteTagForStdMustBeChecked can be used.
 /// \arg \c InvalE Expression that causes invalidation of \c errno.
 ProgramStateRef setErrnoStdMustBeChecked(ProgramStateRef State,
  CheckerContext &C, const Expr 
*InvalE);
 
-/// Generate the note tag that can be applied at the state generated by
-/// \c setErrnoForStdSuccess .
-/// \arg \c Fn Name of the (standard) function that is modeled.
-const NoteTag *getNoteTagForStdSuccess(CheckerContext &C, llvm::StringRef Fn);
-
-/// Generate the note tag that can be applied at the state generated by
-/// \c setErrnoStdMustBeChecked .
-/// \arg \c Fn Name of the (standard) function that is modeled.
-const NoteTag *getNoteTagForStdMustBeChecked(CheckerContext &C,
- llvm::StringRef Fn);
-
 } // namespace errno_modeling
 } // namespace ento
 } // namespace clang
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 13bb9cef5e490ed..035314c6f7751d5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -533,13 +533,11 @@ class StdLibraryFunctionsChecker
 virtual ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
   const Summary &Summary,
   CheckerContext &C) const = 0;
-/// Get a NoteTag about the changes made to 'errno' and the possible bug.
-/// It may return \c nullptr (if no bug report from \c ErrnoChecker is
-/// expected).
-virtual const NoteTag *describe(CheckerContext &C,
-StringRef FunctionName) const {
-  return n

[clang] [clang][Interp] Fix IntAP(s) to IntAP(s) casts (PR #69915)

2023-11-06 Thread Aaron Ballman via cfe-commits

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

LGTM but please add the description to the patch commit message when landing.

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


[clang] [clang-repl] Fix BUILD_SHARED_LIBS symbols from libclangInterpreter on MinGW (PR #71393)

2023-11-06 Thread Martin Storsjö via cfe-commits

https://github.com/mstorsjo created 
https://github.com/llvm/llvm-project/pull/71393

A few symbols within libclangInterpreter have got explicit dllexport 
attributes, in order to make them exported (and thus visible at runtime) in any 
build, not only when they are part of e.g. a DLL libclang-cpp, but also when 
they are part of a plain .exe.

Due to the explicit dllexports, these symbols would sidestep the regular MinGW 
logic of exporting all symbols if there are no dllexports. Therefore, for 
libclang-cpp, a separate fix was made in 
592e935e115ffb451eb9b782376711dab6558fe0, to pass --export-all-symbols to the 
build of libclang-cpp.

If building with BUILD_SHARED_LIBS enabled, then the same issue appears in 
libclangInterpreter; pass the same flag --export-all-symbols there as well, to 
make sure all symbols are visible, not only the ones that are explicitly marked 
as dllexport.

From 9de9617b46bd3c2ff4abd9446afc72c6e91f2493 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Mon, 6 Nov 2023 15:42:42 +0200
Subject: [PATCH] [clang-repl] Fix BUILD_SHARED_LIBS symbols from
 libclangInterpreter on MinGW

A few symbols within libclangInterpreter have got explicit dllexport
attributes, in order to make them exported (and thus visible at
runtime) in any build, not only when they are part of e.g. a DLL
libclang-cpp, but also when they are part of a plain .exe.

Due to the explicit dllexports, these symbols would sidestep the
regular MinGW logic of exporting all symbols if there are no
dllexports. Therefore, for libclang-cpp, a separate fix was made
in 592e935e115ffb451eb9b782376711dab6558fe0, to pass
--export-all-symbols to the build of libclang-cpp.

If building with BUILD_SHARED_LIBS enabled, then the same issue
appears in libclangInterpreter; pass the same flag
--export-all-symbols there as well, to make sure all symbols are
visible, not only the ones that are explicitly marked as dllexport.
---
 clang/lib/Interpreter/CMakeLists.txt | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index 84f6ca5271d2ab0..9065f998f73c473 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -38,3 +38,14 @@ add_clang_library(clangInterpreter
   clangSema
   clangSerialization
   )
+
+if ((MINGW OR CYGWIN) AND BUILD_SHARED_LIBS)
+  # The DLLs are supposed to export all symbols (except for ones that are
+  # explicitly hidden). Normally, this is what happens anyway, but if there
+  # are symbols that are marked explicitly as dllexport, we'd only export them
+  # and nothing else. The Interpreter contains a few cases of such dllexports
+  # (for symbols that need to be exported even from standalone exe files);
+  # therefore, add --export-all-symbols to make sure we export all symbols
+  # despite potential dllexports.
+  target_link_options(clangInterpreter PRIVATE LINKER:--export-all-symbols)
+endif()

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


[clang] [clang-repl] Fix BUILD_SHARED_LIBS symbols from libclangInterpreter on MinGW (PR #71393)

2023-11-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Martin Storsjö (mstorsjo)


Changes

A few symbols within libclangInterpreter have got explicit dllexport 
attributes, in order to make them exported (and thus visible at runtime) in any 
build, not only when they are part of e.g. a DLL libclang-cpp, but also when 
they are part of a plain .exe.

Due to the explicit dllexports, these symbols would sidestep the regular MinGW 
logic of exporting all symbols if there are no dllexports. Therefore, for 
libclang-cpp, a separate fix was made in 
592e935e115ffb451eb9b782376711dab6558fe0, to pass --export-all-symbols to the 
build of libclang-cpp.

If building with BUILD_SHARED_LIBS enabled, then the same issue appears in 
libclangInterpreter; pass the same flag --export-all-symbols there as well, to 
make sure all symbols are visible, not only the ones that are explicitly marked 
as dllexport.

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


1 Files Affected:

- (modified) clang/lib/Interpreter/CMakeLists.txt (+11) 


``diff
diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index 84f6ca5271d2ab0..9065f998f73c473 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -38,3 +38,14 @@ add_clang_library(clangInterpreter
   clangSema
   clangSerialization
   )
+
+if ((MINGW OR CYGWIN) AND BUILD_SHARED_LIBS)
+  # The DLLs are supposed to export all symbols (except for ones that are
+  # explicitly hidden). Normally, this is what happens anyway, but if there
+  # are symbols that are marked explicitly as dllexport, we'd only export them
+  # and nothing else. The Interpreter contains a few cases of such dllexports
+  # (for symbols that need to be exported even from standalone exe files);
+  # therefore, add --export-all-symbols to make sure we export all symbols
+  # despite potential dllexports.
+  target_link_options(clangInterpreter PRIVATE LINKER:--export-all-symbols)
+endif()

``




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


[clang] [clang-repl] Fix BUILD_SHARED_LIBS symbols from libclangInterpreter on MinGW (PR #71393)

2023-11-06 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

CC @brechtsanders, this is an alternative to #66881.

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


[clang] [clang][TSA] Make RequiresCapability a DeclOrType attribute (PR #67095)

2023-11-06 Thread Aaron Ballman via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -1894,6 +1894,8 @@ void TypePrinter::printAttributedAfter(const 
AttributedType *T,
   case attr::ArmMveStrictPolymorphism:
 OS << "__clang_arm_mve_strict_polymorphism";
 break;
+  case attr::RequiresCapability:
+OS << "requires_capability(blah)";

AaronBallman wrote:

Not many type attributes have arguments to them -- but `pcs` does print its 
argument but `annotate_type` doesn't. If you've got access to the information, 
best to print it, but if you don't have what you need to print the arguments, 
then I'd go with `(...)` as the argument list with a FIXME comment.

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


[clang] [clang][Analyzer][NFC] Simplify preDefault/preFseek/preFreadFwrite of StreamChecker (PR #71394)

2023-11-06 Thread Ben Shi via cfe-commits

https://github.com/benshi001 created 
https://github.com/llvm/llvm-project/pull/71394

None

>From 965c109cc19187329d5ab2ae324665dfbd7c17ee Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Mon, 6 Nov 2023 21:49:36 +0800
Subject: [PATCH] [clang][Analyzer][NFC] Simplify
 preDefault/preFseek/preFreadFwrite of StreamChecker

---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 35 ++-
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 898906977ba9bb6..e35929c4dcd28e4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -342,6 +342,11 @@ class StreamChecker : public CheckerStreamArgNo), C,
-  State);
-  if (!State)
-return;
-  State = ensureStreamOpened(StreamVal, C, State);
-  if (!State)
+  if (!basicCheck(Desc, Call, C, State, StreamVal))
 return;
+
   State = ensureNoFilePositionIndeterminate(StreamVal, C, State);
   if (!State)
 return;
@@ -749,13 +750,9 @@ void StreamChecker::preFseek(const FnDescription *Desc, 
const CallEvent &Call,
  CheckerContext &C) const {
   ProgramStateRef State = C.getState();
   SVal StreamVal = getStreamArg(Desc, Call);
-  State = ensureStreamNonNull(StreamVal, Call.getArgExpr(Desc->StreamArgNo), C,
-  State);
-  if (!State)
-return;
-  State = ensureStreamOpened(StreamVal, C, State);
-  if (!State)
+  if (!basicCheck(Desc, Call, C, State, StreamVal))
 return;
+
   State = ensureFseekWhenceCorrect(Call.getArgSVal(2), C, State);
   if (!State)
 return;
@@ -1002,15 +999,19 @@ void StreamChecker::preDefault(const FnDescription 
*Desc, const CallEvent &Call,
CheckerContext &C) const {
   ProgramStateRef State = C.getState();
   SVal StreamVal = getStreamArg(Desc, Call);
+  if (basicCheck(Desc, Call, C, State, StreamVal))
+C.addTransition(State);
+}
+
+bool StreamChecker::basicCheck(const FnDescription *Desc, const CallEvent 
&Call,
+   CheckerContext &C, ProgramStateRef &State,
+   SVal &StreamVal) const {
   State = ensureStreamNonNull(StreamVal, Call.getArgExpr(Desc->StreamArgNo), C,
   State);
   if (!State)
-return;
+return false;
   State = ensureStreamOpened(StreamVal, C, State);
-  if (!State)
-return;
-
-  C.addTransition(State);
+  return State != nullptr;
 }
 
 void StreamChecker::evalSetFeofFerror(const FnDescription *Desc,

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


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

2023-11-06 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

Thanks, I wasn't aware of this issue (I don't routinely try building with 
`-DBUILD_SHARED_LIBS=ON`, which I presume is what you've done to trigger this). 
See 592e935e115ffb451eb9b782376711dab6558fe0 for earlier context on this issue; 
therefore I'd prefer to fix this as I do in #71393; can you confirm if that 
change works for you as well?

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


[clang-tools-extra] [clang] Revert "[clang][NFC] Refactor `CXXNewExpr::InitializationStyle`" (PR #71395)

2023-11-06 Thread Vlad Serebrennikov via cfe-commits

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

Reverts llvm/llvm-project#71322

>From 40921a217a4bda5ce739561606a4e16677ee48f5 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Mon, 6 Nov 2023 17:53:21 +0400
Subject: [PATCH] Revert "[clang][NFC] Refactor
 `CXXNewExpr::InitializationStyle` (#71322)"

This reverts commit ace4489397d17abfb20d36de1404cfbe102401a7.
---
 .../modernize/MakeSmartPtrCheck.cpp   |  7 +--
 clang/include/clang/AST/ExprCXX.h | 48 +++
 clang/lib/AST/ExprCXX.cpp | 29 +
 clang/lib/AST/ItaniumMangle.cpp   |  5 +-
 clang/lib/AST/JSONNodeDumper.cpp  | 12 +---
 clang/lib/AST/StmtPrinter.cpp |  7 +--
 clang/lib/AST/StmtProfile.cpp |  2 +-
 clang/lib/Sema/SemaExprCXX.cpp| 60 +--
 8 files changed, 74 insertions(+), 96 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index 616e57efa76ded5..71fd8eca300c1b2 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -323,8 +323,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 return false;
   };
   switch (New->getInitializationStyle()) {
-  case CXXNewInitializationStyle::None:
-  case CXXNewInitializationStyle::Implicit: {
+  case CXXNewExpr::NoInit: {
 if (ArraySizeExpr.empty()) {
   Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
 } else {
@@ -335,7 +334,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewInitializationStyle::Call: {
+  case CXXNewExpr::CallInit: {
 // FIXME: Add fixes for constructors with parameters that can be created
 // with a C++11 braced-init-list (e.g. std::vector, std::map).
 // Unlike ordinal cases, braced list can not be deduced in
@@ -372,7 +371,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewInitializationStyle::List: {
+  case CXXNewExpr::ListInit: {
 // Range of the substring that we do not want to remove.
 SourceRange InitRange;
 if (const auto *NewConstruct = New->getConstructExpr()) {
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 37d310ef967d9c0..a106bafcfa3e021 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2206,20 +2206,6 @@ class CXXScalarValueInitExpr : public Expr {
   }
 };
 
-enum class CXXNewInitializationStyle {
-  /// New-expression has no initializer as written.
-  None,
-
-  /// New-expression has no written initializer, but has an implicit one.
-  Implicit,
-
-  /// New-expression has a C++98 paren-delimited initializer.
-  Call,
-
-  /// New-expression has a C++11 list-initializer.
-  List
-};
-
 /// Represents a new-expression for memory allocation and constructor
 /// calls, e.g: "new CXXNewExpr(foo)".
 class CXXNewExpr final
@@ -2273,12 +2259,25 @@ class CXXNewExpr final
 return isParenTypeId();
   }
 
+public:
+  enum InitializationStyle {
+/// New-expression has no initializer as written.
+NoInit,
+
+/// New-expression has a C++98 paren-delimited initializer.
+CallInit,
+
+/// New-expression has a C++11 list-initializer.
+ListInit
+  };
+
+private:
   /// Build a c++ new expression.
   CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
+ InitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2293,7 +2292,7 @@ class CXXNewExpr final
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
+ InitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2389,20 +2388,15 @@ class CXXNewExpr final
 
   /// Whether this new-expression has any initializer at all.
   bool hasInitializer() const {
-switch (getInitializationStyle()) {
-case CXXNewInitializationStyle::None:
-  return false;
-case CXXNewInitializationStyle::Implicit:
-case CXXNewInitializationStyle::Call:
-case CXXNewInitializationStyle::List:
-  return true;
-}
+return CXX

[clang] 43e5f77 - Revert "[clang][NFC] Refactor `CXXNewExpr::InitializationStyle`" (#71395)

2023-11-06 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-06T17:54:09+04:00
New Revision: 43e5f77500acd64fb2738ef2832691ad488048a8

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

LOG: Revert "[clang][NFC] Refactor `CXXNewExpr::InitializationStyle`" (#71395)

Reverts llvm/llvm-project#71322

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang/include/clang/AST/ExprCXX.h
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Sema/SemaExprCXX.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index 616e57efa76ded5..71fd8eca300c1b2 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -323,8 +323,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 return false;
   };
   switch (New->getInitializationStyle()) {
-  case CXXNewInitializationStyle::None:
-  case CXXNewInitializationStyle::Implicit: {
+  case CXXNewExpr::NoInit: {
 if (ArraySizeExpr.empty()) {
   Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
 } else {
@@ -335,7 +334,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewInitializationStyle::Call: {
+  case CXXNewExpr::CallInit: {
 // FIXME: Add fixes for constructors with parameters that can be created
 // with a C++11 braced-init-list (e.g. std::vector, std::map).
 // Unlike ordinal cases, braced list can not be deduced in
@@ -372,7 +371,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewInitializationStyle::List: {
+  case CXXNewExpr::ListInit: {
 // Range of the substring that we do not want to remove.
 SourceRange InitRange;
 if (const auto *NewConstruct = New->getConstructExpr()) {

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 37d310ef967d9c0..a106bafcfa3e021 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2206,20 +2206,6 @@ class CXXScalarValueInitExpr : public Expr {
   }
 };
 
-enum class CXXNewInitializationStyle {
-  /// New-expression has no initializer as written.
-  None,
-
-  /// New-expression has no written initializer, but has an implicit one.
-  Implicit,
-
-  /// New-expression has a C++98 paren-delimited initializer.
-  Call,
-
-  /// New-expression has a C++11 list-initializer.
-  List
-};
-
 /// Represents a new-expression for memory allocation and constructor
 /// calls, e.g: "new CXXNewExpr(foo)".
 class CXXNewExpr final
@@ -2273,12 +2259,25 @@ class CXXNewExpr final
 return isParenTypeId();
   }
 
+public:
+  enum InitializationStyle {
+/// New-expression has no initializer as written.
+NoInit,
+
+/// New-expression has a C++98 paren-delimited initializer.
+CallInit,
+
+/// New-expression has a C++11 list-initializer.
+ListInit
+  };
+
+private:
   /// Build a c++ new expression.
   CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
+ InitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2293,7 +2292,7 @@ class CXXNewExpr final
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
+ InitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2389,20 +2388,15 @@ class CXXNewExpr final
 
   /// Whether this new-expression has any initializer at all.
   bool hasInitializer() const {
-switch (getInitializationStyle()) {
-case CXXNewInitializationStyle::None:
-  return false;
-case CXXNewInitializationStyle::Implicit:
-case CXXNewInitializationStyle::Call:
-case CXXNewInitializationStyle::List:
-  return true;
-}
+return CXXNewExprBits.StoredInitializationStyle > 0;
   }
 
   /// The kind of initializer this new-exp

[clang] [clang-tools-extra] Revert "[clang][NFC] Refactor `CXXNewExpr::InitializationStyle`" (PR #71395)

2023-11-06 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang-tools-extra] Revert "[clang][NFC] Refactor `CXXNewExpr::InitializationStyle`" (PR #71395)

2023-11-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Vlad Serebrennikov (Endilll)


Changes

Reverts llvm/llvm-project#71322

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


8 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(+3-4) 
- (modified) clang/include/clang/AST/ExprCXX.h (+21-27) 
- (modified) clang/lib/AST/ExprCXX.cpp (+14-15) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+2-3) 
- (modified) clang/lib/AST/JSONNodeDumper.cpp (+3-9) 
- (modified) clang/lib/AST/StmtPrinter.cpp (+3-4) 
- (modified) clang/lib/AST/StmtProfile.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+27-33) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index 616e57efa76ded5..71fd8eca300c1b2 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -323,8 +323,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 return false;
   };
   switch (New->getInitializationStyle()) {
-  case CXXNewInitializationStyle::None:
-  case CXXNewInitializationStyle::Implicit: {
+  case CXXNewExpr::NoInit: {
 if (ArraySizeExpr.empty()) {
   Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
 } else {
@@ -335,7 +334,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewInitializationStyle::Call: {
+  case CXXNewExpr::CallInit: {
 // FIXME: Add fixes for constructors with parameters that can be created
 // with a C++11 braced-init-list (e.g. std::vector, std::map).
 // Unlike ordinal cases, braced list can not be deduced in
@@ -372,7 +371,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewInitializationStyle::List: {
+  case CXXNewExpr::ListInit: {
 // Range of the substring that we do not want to remove.
 SourceRange InitRange;
 if (const auto *NewConstruct = New->getConstructExpr()) {
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 37d310ef967d9c0..a106bafcfa3e021 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2206,20 +2206,6 @@ class CXXScalarValueInitExpr : public Expr {
   }
 };
 
-enum class CXXNewInitializationStyle {
-  /// New-expression has no initializer as written.
-  None,
-
-  /// New-expression has no written initializer, but has an implicit one.
-  Implicit,
-
-  /// New-expression has a C++98 paren-delimited initializer.
-  Call,
-
-  /// New-expression has a C++11 list-initializer.
-  List
-};
-
 /// Represents a new-expression for memory allocation and constructor
 /// calls, e.g: "new CXXNewExpr(foo)".
 class CXXNewExpr final
@@ -2273,12 +2259,25 @@ class CXXNewExpr final
 return isParenTypeId();
   }
 
+public:
+  enum InitializationStyle {
+/// New-expression has no initializer as written.
+NoInit,
+
+/// New-expression has a C++98 paren-delimited initializer.
+CallInit,
+
+/// New-expression has a C++11 list-initializer.
+ListInit
+  };
+
+private:
   /// Build a c++ new expression.
   CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
+ InitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2293,7 +2292,7 @@ class CXXNewExpr final
  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
  bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs,
  SourceRange TypeIdParens, std::optional ArraySize,
- CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
+ InitializationStyle InitializationStyle, Expr *Initializer,
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
@@ -2389,20 +2388,15 @@ class CXXNewExpr final
 
   /// Whether this new-expression has any initializer at all.
   bool hasInitializer() const {
-switch (getInitializationStyle()) {
-case CXXNewInitializationStyle::None:
-  return false;
-case CXXNewInitializationStyle::Implicit:
-case CXXNewInitializationStyle::Call:
-case CXXNewInitializationStyle::List:
-  return true;
-}
+return CXXNewExprBits.StoredInitializationStyle > 0;
   }
 
   /// The kind of initializer this new-expression has.
-  CXXNewInitializationStyle getInitializationStyle() const {
-return static_cast(
-CXXNewExprBits.StoredInitializationStyle);
+  Init

[clang-tools-extra] [clang] Revert "[clang][NFC] Refactor `CXXNewExpr::InitializationStyle`" (PR #71395)

2023-11-06 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 22a323e3db0cad736b2e793dd8143195fd9c0fc0 
40921a217a4bda5ce739561606a4e16677ee48f5 -- 
clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
clang/include/clang/AST/ExprCXX.h clang/lib/AST/ExprCXX.cpp 
clang/lib/AST/ItaniumMangle.cpp clang/lib/AST/JSONNodeDumper.cpp 
clang/lib/AST/StmtPrinter.cpp clang/lib/AST/StmtProfile.cpp 
clang/lib/Sema/SemaExprCXX.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index 1a013b45c..b707212b7 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -1351,9 +1351,14 @@ void JSONNodeDumper::VisitCXXNewExpr(const CXXNewExpr 
*NE) {
   attributeOnlyIfTrue("isArray", NE->isArray());
   attributeOnlyIfTrue("isPlacement", NE->getNumPlacementArgs() != 0);
   switch (NE->getInitializationStyle()) {
-  case CXXNewExpr::NoInit: break;
-  case CXXNewExpr::CallInit: JOS.attribute("initStyle", "call"); break;
-  case CXXNewExpr::ListInit: JOS.attribute("initStyle", "list"); break;
+  case CXXNewExpr::NoInit:
+break;
+  case CXXNewExpr::CallInit:
+JOS.attribute("initStyle", "call");
+break;
+  case CXXNewExpr::ListInit:
+JOS.attribute("initStyle", "list");
+break;
   }
   if (const FunctionDecl *FD = NE->getOperatorNew())
 JOS.attribute("operatorNewDecl", createBareDeclRef(FD));
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 25d7759cc..a95fcfb2e 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2036,16 +2036,16 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool 
UseGlobal,
   //   the object has indeterminate value
   = initStyle == CXXNewExpr::NoInit
 ? InitializationKind::CreateDefault(TypeRange.getBegin())
-// - Otherwise, the new-initializer is interpreted according to
-// the
-//   initialization rules of 8.5 for direct-initialization.
-: initStyle == CXXNewExpr::ListInit
-  ? InitializationKind::CreateDirectList(
-TypeRange.getBegin(), Initializer->getBeginLoc(),
-Initializer->getEndLoc())
-  : InitializationKind::CreateDirect(TypeRange.getBegin(),
- 
DirectInitRange.getBegin(),
- DirectInitRange.getEnd());
+// - Otherwise, the new-initializer is interpreted according to
+// the
+//   initialization rules of 8.5 for direct-initialization.
+: initStyle == CXXNewExpr::ListInit
+? InitializationKind::CreateDirectList(TypeRange.getBegin(),
+   Initializer->getBeginLoc(),
+   Initializer->getEndLoc())
+: InitializationKind::CreateDirect(TypeRange.getBegin(),
+   DirectInitRange.getBegin(),
+   DirectInitRange.getEnd());
 
   // C++11 [dcl.spec.auto]p6. Deduce the type which 'auto' stands in for.
   auto *Deduced = AllocType->getContainedDeducedType();

``




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


[clang] [clang][Analyzer][NFC] Simplify preDefault/preFseek/preFreadFwrite of StreamChecker (PR #71394)

2023-11-06 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/71394

>From abbca31776cf4223392726d64aadfa5c79b57a69 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Mon, 6 Nov 2023 21:49:36 +0800
Subject: [PATCH] [clang][Analyzer][NFC] Simplify
 preDefault/preFseek/preFreadFwrite of StreamChecker

---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 34 +--
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 898906977ba9bb6..c5c33979b202154 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -342,6 +342,11 @@ class StreamChecker : public CheckerStreamArgNo), C,
-  State);
-  if (!State)
-return;
-  State = ensureStreamOpened(StreamVal, C, State);
-  if (!State)
+  if (!basicCheck(Desc, Call, C, State, StreamVal))
 return;
+
   State = ensureNoFilePositionIndeterminate(StreamVal, C, State);
   if (!State)
 return;
@@ -749,12 +750,7 @@ void StreamChecker::preFseek(const FnDescription *Desc, 
const CallEvent &Call,
  CheckerContext &C) const {
   ProgramStateRef State = C.getState();
   SVal StreamVal = getStreamArg(Desc, Call);
-  State = ensureStreamNonNull(StreamVal, Call.getArgExpr(Desc->StreamArgNo), C,
-  State);
-  if (!State)
-return;
-  State = ensureStreamOpened(StreamVal, C, State);
-  if (!State)
+  if (!basicCheck(Desc, Call, C, State, StreamVal))
 return;
   State = ensureFseekWhenceCorrect(Call.getArgSVal(2), C, State);
   if (!State)
@@ -1002,15 +998,19 @@ void StreamChecker::preDefault(const FnDescription 
*Desc, const CallEvent &Call,
CheckerContext &C) const {
   ProgramStateRef State = C.getState();
   SVal StreamVal = getStreamArg(Desc, Call);
+  if (basicCheck(Desc, Call, C, State, StreamVal))
+C.addTransition(State);
+}
+
+bool StreamChecker::basicCheck(const FnDescription *Desc, const CallEvent 
&Call,
+   CheckerContext &C, ProgramStateRef &State,
+   SVal &StreamVal) const {
   State = ensureStreamNonNull(StreamVal, Call.getArgExpr(Desc->StreamArgNo), C,
   State);
   if (!State)
-return;
+return false;
   State = ensureStreamOpened(StreamVal, C, State);
-  if (!State)
-return;
-
-  C.addTransition(State);
+  return State != nullptr;
 }
 
 void StreamChecker::evalSetFeofFerror(const FnDescription *Desc,

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


[clang] [clang-repl] Fix BUILD_SHARED_LIBS symbols from libclangInterpreter on MinGW (PR #71393)

2023-11-06 Thread Jun Zhang via cfe-commits

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

Thanks for the fix! I'm fine with it if this fixes your problem. But yeah, 
please make sure @vgvassilev is aware of it.

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


[clang] [AMDGPU] Accept/Ignore any -mcmodel arguments. (PR #70760)

2023-11-06 Thread Yaxun Liu via cfe-commits


@@ -5743,9 +5743,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 } else if (Triple.getArch() == llvm::Triple::x86_64) {
   Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"},
   CM);
-} else if (Triple.isNVPTX()) {
-  // NVPTX does not care about the code model and will accept whatever 
works
-  // for the host.
+} else if (Triple.isNVPTX() || Triple.isAMDGPU()) {
+  // NVPTX/AMDGPU does not care about the code model and will accept
+  // whatever works for the host.
   Ok = true;
 }
 if (Ok) {

yxsamliu wrote:

neither nvptx or amdgpu backend accepts -mcmodel=tiny and kernel. the backends 
will fail with error:

fatal error: error in backend: Target does not support the tiny CodeModel

for tiny and kernel, we should not pass them to clang -cc1 and emit a warning 
that they are ignored.

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


[clang] [clang][Analyzer] Move checker 'alpha.unix.Errno' to 'unix.Errno'. (PR #69469)

2023-11-06 Thread Balázs Kéri via cfe-commits

balazske wrote:

PRs #71373 and #71392 are created to improve the indicated problems.

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


[llvm] [clang] [AMDGPU] Add code model (#70760) test for amdgpu target. (PR #71019)

2023-11-06 Thread Yaxun Liu via cfe-commits

yxsamliu wrote:

I think we need to fix clang and not passing -mcmodel=tiny/kernel to clang 
-cc1. 

https://github.com/llvm/llvm-project/pull/70760/files#r1383372722

probably we can do that in this PR

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


[clang] [clang][Analyzer][NFC] Simplify preDefault/preFseek/preFreadFwrite of StreamChecker (PR #71394)

2023-11-06 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/71394

>From 56d5604cf0442919d62def08c233e8d48b654885 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Mon, 6 Nov 2023 21:49:36 +0800
Subject: [PATCH] [clang][Analyzer][NFC] Simplify
 preDefault/preFseek/preFreadFwrite of StreamChecker

---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 33 +--
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 898906977ba9bb6..877e5d2a09f398c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -342,6 +342,11 @@ class StreamChecker : public CheckerStreamArgNo), C,
-  State);
-  if (!State)
-return;
-  State = ensureStreamOpened(StreamVal, C, State);
-  if (!State)
+  if (!basicCheck(Desc, Call, C, State, StreamVal))
 return;
   State = ensureNoFilePositionIndeterminate(StreamVal, C, State);
   if (!State)
@@ -749,12 +749,7 @@ void StreamChecker::preFseek(const FnDescription *Desc, 
const CallEvent &Call,
  CheckerContext &C) const {
   ProgramStateRef State = C.getState();
   SVal StreamVal = getStreamArg(Desc, Call);
-  State = ensureStreamNonNull(StreamVal, Call.getArgExpr(Desc->StreamArgNo), C,
-  State);
-  if (!State)
-return;
-  State = ensureStreamOpened(StreamVal, C, State);
-  if (!State)
+  if (!basicCheck(Desc, Call, C, State, StreamVal))
 return;
   State = ensureFseekWhenceCorrect(Call.getArgSVal(2), C, State);
   if (!State)
@@ -1002,15 +997,19 @@ void StreamChecker::preDefault(const FnDescription 
*Desc, const CallEvent &Call,
CheckerContext &C) const {
   ProgramStateRef State = C.getState();
   SVal StreamVal = getStreamArg(Desc, Call);
+  if (basicCheck(Desc, Call, C, State, StreamVal))
+C.addTransition(State);
+}
+
+bool StreamChecker::basicCheck(const FnDescription *Desc, const CallEvent 
&Call,
+   CheckerContext &C, ProgramStateRef &State,
+   SVal &StreamVal) const {
   State = ensureStreamNonNull(StreamVal, Call.getArgExpr(Desc->StreamArgNo), C,
   State);
   if (!State)
-return;
+return false;
   State = ensureStreamOpened(StreamVal, C, State);
-  if (!State)
-return;
-
-  C.addTransition(State);
+  return State != nullptr;
 }
 
 void StreamChecker::evalSetFeofFerror(const FnDescription *Desc,

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


[llvm] [clang] [clang-tools-extra] Improve selection of conditional branch on amdgcn.ballot!=0 condition in SelectionDAG. (PR #68714)

2023-11-06 Thread Valery Pykhtin via cfe-commits

vpykhtin wrote:

Thanks Nicolai!

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


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

2023-11-06 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman created 
https://github.com/llvm/llvm-project/pull/71398

In Clang 16, we implemented the ability to add a label at the end of a compound 
statement. These changes complete the implementation by allowing a label to be 
followed by a declaration in C.

Note, this seems to have fixed an issue with some OpenMP stand-alone directives 
not being properly diagnosed as per:
https://www.openmp.org/spec-html/5.1/openmpsu19.html#x34-330002.1.3
(The same requirement exists in OpenMP 5.2 as well.)

>From 1d54a5cc6b34aca0e34ab57d7ee62815707d9153 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Mon, 6 Nov 2023 08:54:40 -0500
Subject: [PATCH] [C23] Complete support for WG14 N2508

In Clang 16, we implemented the ability to add a label at the end of
a compound statement. These changes complete the implementation by
allowing a label to be followed by a declaration in C.

Note, this seems to have fixed an issue with some OpenMP stand-alone
directives not being properly diagnosed as per:
https://www.openmp.org/spec-html/5.1/openmpsu19.html#x34-330002.1.3
(The same requirement exists in OpenMP 5.2 as well.)
---
 clang/docs/ReleaseNotes.rst   | 22 
 .../clang/Basic/DiagnosticParseKinds.td   |  6 
 clang/include/clang/Parse/Parser.h|  9 ++---
 clang/lib/Parse/ParseOpenMP.cpp   |  4 +--
 clang/lib/Parse/ParseStmt.cpp | 34 ---
 clang/test/C/C2x/n2508.c  | 11 ++
 clang/test/OpenMP/barrier_ast_print.cpp   | 24 -
 clang/test/OpenMP/barrier_messages.cpp|  8 ++---
 clang/test/OpenMP/cancel_messages.cpp |  6 ++--
 .../OpenMP/cancellation_point_messages.cpp|  6 ++--
 clang/test/OpenMP/depobj_messages.cpp |  8 ++---
 clang/test/OpenMP/error_message.cpp   | 10 +++---
 clang/test/OpenMP/flush_messages.cpp  |  8 ++---
 clang/test/OpenMP/scan_messages.cpp   | 10 +++---
 clang/test/OpenMP/taskwait_messages.cpp   |  8 ++---
 clang/test/OpenMP/taskyield_messages.cpp  |  8 ++---
 clang/www/c_status.html   |  2 +-
 17 files changed, 121 insertions(+), 63 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index afe7e2e79c2d087..91f4c90fc9b0e24 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -209,6 +209,12 @@ C23 Feature Support
 - Clang now supports  which defines several macros for 
performing
   checked integer arithmetic. It is also exposed in pre-C23 modes.
 
+- Completed the implementation of
+  `N2508 `_. We
+  previously implemented allowing a label at the end of a compound statement,
+  and now we've implemented allowing a label to be followed by a declaration
+  instead of a statement.
+
 Non-comprehensive list of changes in this release
 -
 
@@ -541,6 +547,22 @@ Bug Fixes in This Version
   Fixes (`#67687 `_)
 - Fix crash from constexpr evaluator evaluating uninitialized arrays as rvalue.
   Fixes (`#67317 `_)
+- Clang now properly diagnoses use of stand-alone OpenMP directives after a
+  label (including ``case`` or ``default`` labels).
+
+  Before:
+
+  .. code-block:: c++
+
+  label:
+  #pragma omp barrier // ok
+
+  After:
+
+  .. code-block:: c++
+
+  label:
+  #pragma omp barrier // error: '#pragma omp barrier' cannot be an immediate 
substatement
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index de180344fcc5c74..2bc72acc1375143 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -299,6 +299,12 @@ def note_missing_selector_name : Note<
 def note_force_empty_selector_name : Note<
   "or insert whitespace before ':' to use %0 as parameter name "
   "and have an empty entry in the selector">;
+def ext_c_label_followed_by_declaration : ExtWarn<
+  "label followed by a declaration is a C23 extension">,
+  InGroup;
+def warn_c23_compat_label_followed_by_declaration : Warning<
+  "label followed by a declaration is incompatible with C standards before "
+  "C23">, InGroup, DefaultIgnore;
 def ext_c_label_end_of_compound_statement : ExtWarn<
   "label at end of compound statement is a C23 extension">,
InGroup;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 30e0352c868637b..22e8c4ceea39cd6 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -410,18 +410,15 @@ class Parser : public CodeCompletionHandler {
 
   /// Flags describing a context in which we're parsing a statement.
   enum class ParsedStmtContext {
-/// This context per

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

2023-11-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-openmp

Author: Aaron Ballman (AaronBallman)


Changes

In Clang 16, we implemented the ability to add a label at the end of a compound 
statement. These changes complete the implementation by allowing a label to be 
followed by a declaration in C.

Note, this seems to have fixed an issue with some OpenMP stand-alone directives 
not being properly diagnosed as per:
https://www.openmp.org/spec-html/5.1/openmpsu19.html#x34-330002.1.3
(The same requirement exists in OpenMP 5.2 as well.)

---

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


17 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+22) 
- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+6) 
- (modified) clang/include/clang/Parse/Parser.h (+3-6) 
- (modified) clang/lib/Parse/ParseOpenMP.cpp (+2-2) 
- (modified) clang/lib/Parse/ParseStmt.cpp (+21-13) 
- (modified) clang/test/C/C2x/n2508.c (+11) 
- (modified) clang/test/OpenMP/barrier_ast_print.cpp (+16-8) 
- (modified) clang/test/OpenMP/barrier_messages.cpp (+4-4) 
- (modified) clang/test/OpenMP/cancel_messages.cpp (+4-2) 
- (modified) clang/test/OpenMP/cancellation_point_messages.cpp (+4-2) 
- (modified) clang/test/OpenMP/depobj_messages.cpp (+4-4) 
- (modified) clang/test/OpenMP/error_message.cpp (+5-5) 
- (modified) clang/test/OpenMP/flush_messages.cpp (+4-4) 
- (modified) clang/test/OpenMP/scan_messages.cpp (+6-4) 
- (modified) clang/test/OpenMP/taskwait_messages.cpp (+4-4) 
- (modified) clang/test/OpenMP/taskyield_messages.cpp (+4-4) 
- (modified) clang/www/c_status.html (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5e19dbea6608486..ae851d754c84831 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -209,6 +209,12 @@ C23 Feature Support
 - Clang now supports  which defines several macros for 
performing
   checked integer arithmetic. It is also exposed in pre-C23 modes.
 
+- Completed the implementation of
+  `N2508 `_. We
+  previously implemented allowing a label at the end of a compound statement,
+  and now we've implemented allowing a label to be followed by a declaration
+  instead of a statement.
+
 Non-comprehensive list of changes in this release
 -
 
@@ -545,6 +551,22 @@ Bug Fixes in This Version
   Fixes (`#67687 `_)
 - Fix crash from constexpr evaluator evaluating uninitialized arrays as rvalue.
   Fixes (`#67317 `_)
+- Clang now properly diagnoses use of stand-alone OpenMP directives after a
+  label (including ``case`` or ``default`` labels).
+
+  Before:
+
+  .. code-block:: c++
+
+  label:
+  #pragma omp barrier // ok
+
+  After:
+
+  .. code-block:: c++
+
+  label:
+  #pragma omp barrier // error: '#pragma omp barrier' cannot be an immediate 
substatement
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index de180344fcc5c74..2bc72acc1375143 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -299,6 +299,12 @@ def note_missing_selector_name : Note<
 def note_force_empty_selector_name : Note<
   "or insert whitespace before ':' to use %0 as parameter name "
   "and have an empty entry in the selector">;
+def ext_c_label_followed_by_declaration : ExtWarn<
+  "label followed by a declaration is a C23 extension">,
+  InGroup;
+def warn_c23_compat_label_followed_by_declaration : Warning<
+  "label followed by a declaration is incompatible with C standards before "
+  "C23">, InGroup, DefaultIgnore;
 def ext_c_label_end_of_compound_statement : ExtWarn<
   "label at end of compound statement is a C23 extension">,
InGroup;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 30e0352c868637b..22e8c4ceea39cd6 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -410,18 +410,15 @@ class Parser : public CodeCompletionHandler {
 
   /// Flags describing a context in which we're parsing a statement.
   enum class ParsedStmtContext {
-/// This context permits declarations in language modes where declarations
-/// are not statements.
-AllowDeclarationsInC = 0x1,
 /// This context permits standalone OpenMP directives.
-AllowStandaloneOpenMPDirectives = 0x2,
+AllowStandaloneOpenMPDirectives = 0x1,
 /// This context is at the top level of a GNU statement expression.
-InStmtExpr = 0x4,
+InStmtExpr = 0x2,
 
 /// The context of a regular substatement.
 SubStmt = 0,
 /// The context of a compound-statement.
-Compound = AllowDeclarationsInC | Allow

[clang] [analyzer] Trust base to derived casts for dynamic types (PR #69057)

2023-11-06 Thread Balazs Benics via cfe-commits


@@ -492,11 +492,13 @@ void check_required_cast() {
 
 void check_cast_behavior(OSObject *obj) {
   OSArray *arr1 = OSDynamicCast(OSArray, obj);
-  clang_analyzer_eval(arr1 == obj); // expected-warning{{TRUE}}
-// expected-note@-1{{TRUE}}
-// expected-note@-2{{Assuming 'arr1' is 
not equal to 'obj'}}
-// expected-warning@-3{{FALSE}}
-// expected-note@-4   {{FALSE}}
+  clang_analyzer_eval(arr1 == obj); // #check_cast_behavior_1
+  // expected-warning@#check_cast_behavior_1 {{TRUE}}
+  // expected-note@#check_cast_behavior_1{{TRUE}}
+  // expected-note@#check_cast_behavior_1{{Assuming 'arr1' is equal to 'obj'}}

steakhal wrote:

I've looked at the exploded-graph before and after the patch, and the values 
and the branches are all the same. There is only one difference: in the new 
graph, after the `(OSArray *)` cast in init-expr of the decl, we have the type 
info bound: `Dynamic Types`:
```
SymRegion{reg_$0} -> OSArray (or a sub-class)
```

Later, when we load for the analyzer_eval, we can see that on the branch where 
the `safeMetaCast` succeeds, `arr1` and `obj` refers to the same lvalue, thus 
already proven to be equal.

![image](https://github.com/llvm/llvm-project/assets/6280485/2d2ee01e-b356-43fd-aa24-62b69d08b145)

BTW if I change the test into this, it would pass on both the old and new 
versions:
```c++
void check_cast_behavior(OSObject *obj) {
  OSArray *arr1 = OSDynamicCast(OSArray, obj);
  if (!arr1) return;
  // expected-note@-1 {{'arr1' is non-null}} expected-note@-1 {{Taking false 
branch}}
  // expected-note@-2 {{'arr1' is non-null}} expected-note@-2 {{Taking false 
branch}}
  clang_analyzer_eval(arr1 == obj); // expected-warning{{TRUE}} 
expected-note{{TRUE}}
  OSArray *arr2 = OSRequiredCast(OSArray, obj);
  clang_analyzer_eval(arr2 == obj); // expected-warning{{TRUE}} 
expected-note{{TRUE}}
}
```
I think this test would describe the behavior for the "cast-succeeds" branch, 
aka. the branch where `arr1` is non-null. Consequently, I believe this PR would 
not regress this.

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


[clang] feedb7c - [clang][Interp] Fix IntAP(s) to IntAP(s) casts (#69915)

2023-11-06 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-11-06T15:13:43+01:00
New Revision: feedb7c0db1e06b9082f9c015362cdbf334696ff

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

LOG: [clang][Interp] Fix IntAP(s) to IntAP(s) casts (#69915)

This was still assert(false)'ed out, it's for casts between two IntAP/IntAPS 
expressions.
We can't just short-circuit for FromT == ToT because we need to consider the 
bitwidth when doing the cast.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 485893d58f487ae..a2cf682b2532bde 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -200,16 +200,13 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
 if (!this->visit(SubExpr))
   return false;
 
-if (FromT == ToT) {
-  assert(ToT != PT_IntAP && ToT != PT_IntAPS);
-  return true;
-}
-
 if (ToT == PT_IntAP)
   return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE);
 if (ToT == PT_IntAPS)
   return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE);
 
+if (FromT == ToT)
+  return true;
 return this->emitCast(*FromT, *ToT, CE);
   }
 

diff  --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index db9f516131af474..45961e6fc74b7a7 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -30,6 +30,17 @@ static_assert(UBitIntZero1 == 0, "");
 constexpr unsigned _BitInt(2) BI1 = 3u;
 static_assert(BI1 == 3, "");
 
+namespace APCast {
+  constexpr _BitInt(10) A = 1;
+  constexpr _BitInt(11) B = A;
+  static_assert(B == 1, "");
+  constexpr _BitInt(16) B2 = A;
+  static_assert(B2 == 1, "");
+  constexpr _BitInt(32) B3 = A;
+  static_assert(B3 == 1, "");
+  constexpr unsigned _BitInt(32) B4 = A;
+  static_assert(B4 == 1, "");
+}
 
 #ifdef __SIZEOF_INT128__
 namespace i128 {



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


[clang] [clang][Interp] Fix IntAP(s) to IntAP(s) casts (PR #69915)

2023-11-06 Thread Timm Baeder via cfe-commits

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


[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-06 Thread via cfe-commits

zmodem wrote:

I landed a commit close to this one, and got at least 10 emails about broken 
buildbots so far (e.g. 
https://lab.llvm.org/buildbot/#/builders/188/builds/37563). How come presubmit 
testing isn't catching this? @metaflow 

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


[clang] clang/CodeGen/RISCV: test lowering of math builtins (PR #71399)

2023-11-06 Thread Ramkumar Ramachandra via cfe-commits

https://github.com/artagnon created 
https://github.com/llvm/llvm-project/pull/71399

Ever since 98c90a1 (ISel: introduce vector ISD::LRINT, ISD::LLRINT; custom 
RISCV lowering) landed, there have been several discussions on how the lrint 
and llrint libcalls would lower to LLVM IR via clang on RV32 and RV64, in an 
effort to enable vectorization of lrint and llrint via SLPVectorizer and 
LoopVectorize. This patch adds a new math-builtins.c test to the RISC-V target 
to test the lowering of all math libcalls, including lrint and llrint.

>From 1f495f0002c2aaa788823726943945309271401c Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra 
Date: Mon, 6 Nov 2023 13:34:25 +
Subject: [PATCH] clang/CodeGen/RISCV: test lowering of math builtins

Ever since 98c90a1 (ISel: introduce vector ISD::LRINT, ISD::LLRINT;
custom RISCV lowering) landed, there have been several discussions on
how the lrint and llrint libcalls would lower to LLVM IR via clang on
RV32 and RV64, in an effort to enable vectorization of lrint and llrint
via SLPVectorizer and LoopVectorize. This patch adds a new
math-builtins.c test to the RISC-V target to test the lowering of all
math libcalls, including lrint and llrint.
---
 clang/test/CodeGen/RISCV/math-builtins.c | 459 +++
 clang/test/CodeGen/{ => X86}/math-builtins.c |   0
 2 files changed, 459 insertions(+)
 create mode 100644 clang/test/CodeGen/RISCV/math-builtins.c
 rename clang/test/CodeGen/{ => X86}/math-builtins.c (100%)

diff --git a/clang/test/CodeGen/RISCV/math-builtins.c 
b/clang/test/CodeGen/RISCV/math-builtins.c
new file mode 100644
index 000..9630d62f0f48292
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/math-builtins.c
@@ -0,0 +1,459 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple riscv32 -emit-llvm %s -o - | FileCheck 
--check-prefix=RV32 %s
+// RUN: %clang_cc1 -triple riscv64 -emit-llvm %s -o - | FileCheck 
--check-prefix=RV64 %s
+
+float ceilf(float);
+double ceil(double);
+long double ceill(long double);
+float copysignf(float, float);
+double copysign(double, double);
+long double copysignl(long double, long double);
+float cosf(float);
+double cos(double);
+long double cosl(long double);
+float expf(float);
+double exp(double);
+long double expl(long double);
+float exp2f(float);
+double exp2(double);
+long double exp2l(long double);
+float fabsf(float);
+double fabs(double);
+long double fabsl(long double);
+float floorf(float);
+double floor(double);
+long double floorl(long double);
+float fmaxf(float, float);
+double fmax(double, double);
+long double fmaxl(long double, long double);
+float fminf(float, float);
+double fmin(double, double);
+long double fminl(long double, long double);
+float fmodf(float, float);
+double fmod(double, double);
+long double fmodl(long double, long double);
+float logf(float);
+double log(double);
+long double logl(long double);
+float log10f(float);
+double log10(double);
+long double log10l(long double);
+float log2f(float);
+double log2(double);
+long double log2l(long double);
+float nearbyintf(float);
+double nearbyint(double);
+long double nearbyintl(long double);
+float powf(float, float);
+double pow(double, double);
+long double powl(long double, long double);
+float rintf(float);
+double rint(double);
+long double rintl(long double);
+long lrintf(float);
+long lrint(double);
+long lrintl(long double);
+long long llrintf(float);
+long long llrint(double);
+long long llrintl(long double);
+float roundf(float);
+double round(double);
+long double roundl(long double);
+long lroundf(float);
+long lround(double);
+long lroundl(long double);
+long long llroundf(float);
+long long llround(double);
+long long llroundl(long double);
+float roundevenf(float);
+double roundeven(double);
+long double roundevenl(long double);
+float sinf(float);
+double sin(double);
+long double sinl(long double);
+float sqrtf(float);
+double sqrt(double);
+long double sqrtl(long double);
+float truncf(float);
+double trunc(double);
+long double truncl(long double);
+
+// RV32-LABEL: define dso_local void @test(
+// RV32-SAME: float noundef [[FARG:%.*]], double noundef [[DARG:%.*]], fp128 
noundef [[LDARG:%.*]]) #[[ATTR0:[0-9]+]] {
+// RV32-NEXT:  entry:
+// RV32-NEXT:[[FARG_ADDR:%.*]] = alloca float, align 4
+// RV32-NEXT:[[DARG_ADDR:%.*]] = alloca double, align 8
+// RV32-NEXT:[[LDARG_ADDR:%.*]] = alloca fp128, align 16
+// RV32-NEXT:store float [[FARG]], ptr [[FARG_ADDR]], align 4
+// RV32-NEXT:store double [[DARG]], ptr [[DARG_ADDR]], align 8
+// RV32-NEXT:store fp128 [[LDARG]], ptr [[LDARG_ADDR]], align 16
+// RV32-NEXT:[[TMP0:%.*]] = load float, ptr [[FARG_ADDR]], align 4
+// RV32-NEXT:[[TMP1:%.*]] = call float @llvm.ceil.f32(float [[TMP0]])
+// RV32-NEXT:[[TMP2:%.*]] = load double, ptr [[DARG_ADDR]], align 8
+// RV32-NEXT:[[TMP3:%.*]] = call double @llvm.ceil.f64(double [[TMP2]])
+// RV32-NEXT:  

[clang] clang/CodeGen/RISCV: test lowering of math builtins (PR #71399)

2023-11-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ramkumar Ramachandra (artagnon)


Changes

Ever since 98c90a1 (ISel: introduce vector ISD::LRINT, ISD::LLRINT; custom 
RISCV lowering) landed, there have been several discussions on how the lrint 
and llrint libcalls would lower to LLVM IR via clang on RV32 and RV64, in an 
effort to enable vectorization of lrint and llrint via SLPVectorizer and 
LoopVectorize. This patch adds a new math-builtins.c test to the RISC-V target 
to test the lowering of all math libcalls, including lrint and llrint.

---

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


2 Files Affected:

- (added) clang/test/CodeGen/RISCV/math-builtins.c (+459) 
- (renamed) clang/test/CodeGen/X86/math-builtins.c () 


``diff
diff --git a/clang/test/CodeGen/RISCV/math-builtins.c 
b/clang/test/CodeGen/RISCV/math-builtins.c
new file mode 100644
index 000..9630d62f0f48292
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/math-builtins.c
@@ -0,0 +1,459 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple riscv32 -emit-llvm %s -o - | FileCheck 
--check-prefix=RV32 %s
+// RUN: %clang_cc1 -triple riscv64 -emit-llvm %s -o - | FileCheck 
--check-prefix=RV64 %s
+
+float ceilf(float);
+double ceil(double);
+long double ceill(long double);
+float copysignf(float, float);
+double copysign(double, double);
+long double copysignl(long double, long double);
+float cosf(float);
+double cos(double);
+long double cosl(long double);
+float expf(float);
+double exp(double);
+long double expl(long double);
+float exp2f(float);
+double exp2(double);
+long double exp2l(long double);
+float fabsf(float);
+double fabs(double);
+long double fabsl(long double);
+float floorf(float);
+double floor(double);
+long double floorl(long double);
+float fmaxf(float, float);
+double fmax(double, double);
+long double fmaxl(long double, long double);
+float fminf(float, float);
+double fmin(double, double);
+long double fminl(long double, long double);
+float fmodf(float, float);
+double fmod(double, double);
+long double fmodl(long double, long double);
+float logf(float);
+double log(double);
+long double logl(long double);
+float log10f(float);
+double log10(double);
+long double log10l(long double);
+float log2f(float);
+double log2(double);
+long double log2l(long double);
+float nearbyintf(float);
+double nearbyint(double);
+long double nearbyintl(long double);
+float powf(float, float);
+double pow(double, double);
+long double powl(long double, long double);
+float rintf(float);
+double rint(double);
+long double rintl(long double);
+long lrintf(float);
+long lrint(double);
+long lrintl(long double);
+long long llrintf(float);
+long long llrint(double);
+long long llrintl(long double);
+float roundf(float);
+double round(double);
+long double roundl(long double);
+long lroundf(float);
+long lround(double);
+long lroundl(long double);
+long long llroundf(float);
+long long llround(double);
+long long llroundl(long double);
+float roundevenf(float);
+double roundeven(double);
+long double roundevenl(long double);
+float sinf(float);
+double sin(double);
+long double sinl(long double);
+float sqrtf(float);
+double sqrt(double);
+long double sqrtl(long double);
+float truncf(float);
+double trunc(double);
+long double truncl(long double);
+
+// RV32-LABEL: define dso_local void @test(
+// RV32-SAME: float noundef [[FARG:%.*]], double noundef [[DARG:%.*]], fp128 
noundef [[LDARG:%.*]]) #[[ATTR0:[0-9]+]] {
+// RV32-NEXT:  entry:
+// RV32-NEXT:[[FARG_ADDR:%.*]] = alloca float, align 4
+// RV32-NEXT:[[DARG_ADDR:%.*]] = alloca double, align 8
+// RV32-NEXT:[[LDARG_ADDR:%.*]] = alloca fp128, align 16
+// RV32-NEXT:store float [[FARG]], ptr [[FARG_ADDR]], align 4
+// RV32-NEXT:store double [[DARG]], ptr [[DARG_ADDR]], align 8
+// RV32-NEXT:store fp128 [[LDARG]], ptr [[LDARG_ADDR]], align 16
+// RV32-NEXT:[[TMP0:%.*]] = load float, ptr [[FARG_ADDR]], align 4
+// RV32-NEXT:[[TMP1:%.*]] = call float @llvm.ceil.f32(float [[TMP0]])
+// RV32-NEXT:[[TMP2:%.*]] = load double, ptr [[DARG_ADDR]], align 8
+// RV32-NEXT:[[TMP3:%.*]] = call double @llvm.ceil.f64(double [[TMP2]])
+// RV32-NEXT:[[TMP4:%.*]] = load fp128, ptr [[LDARG_ADDR]], align 16
+// RV32-NEXT:[[TMP5:%.*]] = call fp128 @llvm.ceil.f128(fp128 [[TMP4]])
+// RV32-NEXT:[[TMP6:%.*]] = load float, ptr [[FARG_ADDR]], align 4
+// RV32-NEXT:[[TMP7:%.*]] = load float, ptr [[FARG_ADDR]], align 4
+// RV32-NEXT:[[TMP8:%.*]] = call float @llvm.copysign.f32(float [[TMP6]], 
float [[TMP7]])
+// RV32-NEXT:[[TMP9:%.*]] = load double, ptr [[DARG_ADDR]], align 8
+// RV32-NEXT:[[TMP10:%.*]] = load double, ptr [[DARG_ADDR]], align 8
+// RV32-NEXT:[[TMP11:%.*]] = call double @llvm.copysign.f64(double 
[[TMP9]], double [[TMP10]])
+// RV32-NEXT:[[TMP12:%.*]] = lo

[clang-tools-extra] [clang] [llvm] Improve selection of conditional branch on amdgcn.ballot!=0 condition in SelectionDAG. (PR #68714)

2023-11-06 Thread Valery Pykhtin via cfe-commits

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


[clang] [clang] Use new interpreter in EvaluateAsConstantExpr if requested (PR #70763)

2023-11-06 Thread Timm Baeder via cfe-commits

tbaederr wrote:

> I don't have a good idea how a release note could be phrased here, but if you 
> could try one, it would be appreciated and I think it is worth doing.

You mean about this change specifically?

> Side note: it would be really cool if at the end of the release cycle, you 
> did a section in the release-notes with a 'status' of the new interpreter. 
> Basically a 'things that don't work', or a 'percent of tests we have that 
> work', etc?

I could force the new interpreter and run the test suite, but that would only 
be a very rough estimate.


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


[llvm] [clang] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)

2023-11-06 Thread Yusra Syeda via cfe-commits

ysyeda wrote:

ping

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


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

2023-11-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -299,6 +299,12 @@ def note_missing_selector_name : Note<
 def note_force_empty_selector_name : Note<
   "or insert whitespace before ':' to use %0 as parameter name "
   "and have an empty entry in the selector">;
+def ext_c_label_followed_by_declaration : ExtWarn<
+  "label followed by a declaration is a C23 extension">,
+  InGroup;
+def warn_c23_compat_label_followed_by_declaration : Warning<
+  "label followed by a declaration is incompatible with C standards before "
+  "C23">, InGroup, DefaultIgnore;

Fznamznon wrote:

I can't find tests that would check that these messages are emitted. Are they 
coming?

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


[clang-tools-extra] [clang] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-06 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

It catches 
(https://buildkite.com/llvm-project/github-pull-requests/builds/12931#018ba4b7-1e05-425f-a30d-46ac33f582b6),
 you just didn't wait for a results (or ignored them) and forced a merge.

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


[openmp] [clang] [OpenMP] Cleanup and fixes for ABI agnostic DeviceRTL (PR #71234)

2023-11-06 Thread Joseph Huber via cfe-commits

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


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


[clang-tools-extra] [clang] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-06 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

I've seen those exact test failures locally, but since precommit CI was fine, I 
landed this PR and kept a close eye on the bots.
Me and Aaron are also wondering now how did it pass CI, and what's wrong with 
changes here.
I'm sorry @zmodem that we got you involved.

> It catches 
> (https://buildkite.com/llvm-project/github-pull-requests/builds/12931#018ba4b7-1e05-425f-a30d-46ac33f582b6),
>  you just didn't wait for a results (or ignored them) and forced a merge.

Me and Aaron seen them, and deemed them unrelated. For a comparison, here is a 
list of tests that fails locally for me (and post-commit bots seem to agree):
```
Failed Tests (49):
  Clang :: Analysis/NewDelete-checker-test.cpp
  Clang :: Analysis/bstring.cpp
  Clang :: Analysis/cfg.cpp
  Clang :: Analysis/ctor-array.cpp
  Clang :: Analysis/cxxctr-array-evalcall-analysis-order.cpp
  Clang :: Analysis/dtor-array.cpp
  Clang :: Analysis/dump_egraph.cpp
  Clang :: Analysis/exploded-graph-rewriter/dynamic_types.cpp
  Clang :: Analysis/flexible-array-member.cpp
  Clang :: Analysis/handle_constructors_with_new_array.cpp
  Clang :: Analysis/more-dtors-cfg-output.cpp
  Clang :: Analysis/new-ctor-conservative.cpp
  Clang :: Analysis/new-ctor-inlined.cpp
  Clang :: Analysis/this-pointer.cpp
  Clang :: CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp
  Clang :: CXX/drs/dr1748.cpp
  Clang :: CodeGen/available-externally-hidden.cpp
  Clang :: CodeGen/debug-prefix-map.cpp
  Clang :: CodeGen/split-lto-unit-input.cpp
  Clang :: CodeGen/tbaa-for-vptr.cpp
  Clang :: CodeGenCUDA/member-init.cu
  Clang :: CodeGenCXX/attr-disable-tail-calls.cpp
  Clang :: CodeGenCXX/catch-undef-behavior.cpp
  Clang :: CodeGenCXX/cfi-ms-vbase-derived-cast.cpp
  Clang :: CodeGenCXX/code-seg.cpp
  Clang :: CodeGenCXX/ctor-dtor-alias.cpp
  Clang :: CodeGenCXX/cxx1z-aligned-allocation.cpp
  Clang :: CodeGenCXX/cxx2a-destroying-delete.cpp
  Clang :: CodeGenCXX/default-arguments.cpp
  Clang :: CodeGenCXX/destructors.cpp
  Clang :: CodeGenCXX/exceptions.cpp
  Clang :: CodeGenCXX/invariant.group-for-vptrs.cpp
  Clang :: CodeGenCXX/key-function-vtable.cpp
  Clang :: CodeGenCXX/microsoft-abi-structors-delayed-template.cpp
  Clang :: CodeGenCXX/new-overflow.cpp
  Clang :: CodeGenCXX/new.cpp
  Clang :: CodeGenCXX/static-init.cpp
  Clang :: CodeGenCXX/strict-vtable-pointers.cpp
  Clang :: CodeGenCXX/type-metadata-thinlto.cpp
  Clang :: CodeGenCXX/ubsan-new-checks.cpp
  Clang :: CodeGenCXX/ubsan-suppress-checks.cpp
  Clang :: CodeGenCXX/vtable-assume-load-address-space.cpp
  Clang :: CodeGenCXX/vtable-assume-load.cpp
  Clang :: CodeGenCXX/vtable-available-externally.cpp
  Clang :: CodeGenObjCXX/arc-new-delete.mm
  Clang :: CodeGenObjCXX/destroy.mm
  Clang :: LibClang/symbols.test
  Clang :: SemaCXX/constant-expression-cxx2a.cpp
  Clang :: SemaCXX/constexpr-turing-cxx2a.cpp
```

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


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

2023-11-06 Thread Aaron Ballman via cfe-commits


@@ -299,6 +299,12 @@ def note_missing_selector_name : Note<
 def note_force_empty_selector_name : Note<
   "or insert whitespace before ':' to use %0 as parameter name "
   "and have an empty entry in the selector">;
+def ext_c_label_followed_by_declaration : ExtWarn<
+  "label followed by a declaration is a C23 extension">,
+  InGroup;
+def warn_c23_compat_label_followed_by_declaration : Warning<
+  "label followed by a declaration is incompatible with C standards before "
+  "C23">, InGroup, DefaultIgnore;

AaronBallman wrote:

Good catch, those slipped through the cracks. I'll add the tests shortly.

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


[clang] [clang-repl] Fix BUILD_SHARED_LIBS symbols from libclangInterpreter on MinGW (PR #71393)

2023-11-06 Thread Vassil Vassilev via cfe-commits

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

Thank you, @mstorsjo!

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


[clang] [llvm] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-06 Thread Youngsuk Kim via cfe-commits

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


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


[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-06 Thread Nikita Popov via cfe-commits

nikic wrote:

You also need to replace uses in polly.

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


[clang] [llvm] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-06 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

https://buildkite.com/llvm-project/github-pull-requests/builds/12872#018ba3cf-2050-4af1-b46a-55b5482323fc

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


[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)

2023-11-06 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 requested changes to this pull request.

Please update existing uses in `polly`, and rebase onto latest `main`.

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


[clang-tools-extra] [clang-tidy] Improve alternate snake case warnings (PR #71385)

2023-11-06 Thread Piotr Zegar via cfe-commits


@@ -871,8 +871,8 @@ bool IdentifierNamingCheck::matchesStyle(
   llvm::Regex("^[a-z][a-zA-Z0-9]*$"),
   llvm::Regex("^[A-Z][A-Z0-9_]*$"),
   llvm::Regex("^[A-Z][a-zA-Z0-9]*$"),
-  llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
-  llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"),
+  llvm::Regex("^[A-Z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
+  llvm::Regex("^[a-z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
   llvm::Regex("^[A-Z]([a-z0-9_]*[a-z])*$"),

PiotrZSL wrote:

Shouldn't this LeadingUpperSnakeCase also be changed ?

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


[clang-tools-extra] [clang-tidy] Improve alternate snake case warnings (PR #71385)

2023-11-06 Thread Piotr Zegar via cfe-commits

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

LGTM

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


[clang-tools-extra] [clang-tidy] Improve alternate snake case warnings (PR #71385)

2023-11-06 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

Also update release notes, add one sentence there about this.

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


[clang-tools-extra] [clang-tidy] Improve alternate snake case warnings (PR #71385)

2023-11-06 Thread J.C. Moyer via cfe-commits


@@ -871,8 +871,8 @@ bool IdentifierNamingCheck::matchesStyle(
   llvm::Regex("^[a-z][a-zA-Z0-9]*$"),
   llvm::Regex("^[A-Z][A-Z0-9_]*$"),
   llvm::Regex("^[A-Z][a-zA-Z0-9]*$"),
-  llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
-  llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"),
+  llvm::Regex("^[A-Z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
+  llvm::Regex("^[a-z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
   llvm::Regex("^[A-Z]([a-z0-9_]*[a-z])*$"),

jcmoyer wrote:

I think it's fine, `Leading_upper_snake_case` only has the first letter 
capitalized and no special requirements beyond that. Though maybe the regex 
could be slightly simplified to something like `^[A-Z][a-z0-9_]*[a-z]$`.

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


[clang] [clang][Interp] Fix creating APSInt from IntegralAP (PR #71410)

2023-11-06 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/71410

The boolean argument in the APSInt constructor is IsUnsigned, not IsSigned.

This marks the 10th time I've run into this issue. Happy anniversary.

>From 81836da057f2703f49f30d31955306577a0e1170 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 6 Nov 2023 16:59:33 +0100
Subject: [PATCH] [clang][Interp] Fix creating APSInt from IntegralAP

The boolean argument in the APSInt constructor is IsUnsigned, not
IsSigned.

This marks the 10th time I've run into this issue. Happy anniversary.
---
 clang/lib/AST/Interp/IntegralAP.h | 4 ++--
 clang/test/AST/Interp/intap.cpp   | 4 
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 1f535d420bcd54b..134b602d1bb61ca 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -119,8 +119,8 @@ template  class IntegralAP final {
 
   constexpr unsigned bitWidth() const { return V.getBitWidth(); }
 
-  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, Signed); }
-  APValue toAPValue() const { return APValue(APSInt(V, Signed)); }
+  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, !Signed); }
+  APValue toAPValue() const {return APValue(APSInt(V, !Signed)); }
 
   bool isZero() const { return V.isZero(); }
   bool isPositive() const { return V.isNonNegative(); }
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 45961e6fc74b7a7..5f08b76a565c25a 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -56,6 +56,10 @@ namespace i128 {
 
   static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
   static_assert(UINT128_MAX == -1, "");
+  static_assert(UINT128_MAX == 1, ""); // expected-error {{static assertion 
failed}} \
+   // expected-note 
{{'340282366920938463463374607431768211455 == 1'}} \
+   // ref-error {{static assertion 
failed}} \
+   // ref-note 
{{'340282366920938463463374607431768211455 == 1'}}
 
   static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
   static_assert(INT128_MAX != 0, "");

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


[clang] [clang][Interp] Fix creating APSInt from IntegralAP (PR #71410)

2023-11-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

The boolean argument in the APSInt constructor is IsUnsigned, not IsSigned.

This marks the 10th time I've run into this issue. Happy anniversary.

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


2 Files Affected:

- (modified) clang/lib/AST/Interp/IntegralAP.h (+2-2) 
- (modified) clang/test/AST/Interp/intap.cpp (+4) 


``diff
diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 1f535d420bcd54b..134b602d1bb61ca 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -119,8 +119,8 @@ template  class IntegralAP final {
 
   constexpr unsigned bitWidth() const { return V.getBitWidth(); }
 
-  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, Signed); }
-  APValue toAPValue() const { return APValue(APSInt(V, Signed)); }
+  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, !Signed); }
+  APValue toAPValue() const {return APValue(APSInt(V, !Signed)); }
 
   bool isZero() const { return V.isZero(); }
   bool isPositive() const { return V.isNonNegative(); }
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 45961e6fc74b7a7..5f08b76a565c25a 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -56,6 +56,10 @@ namespace i128 {
 
   static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
   static_assert(UINT128_MAX == -1, "");
+  static_assert(UINT128_MAX == 1, ""); // expected-error {{static assertion 
failed}} \
+   // expected-note 
{{'340282366920938463463374607431768211455 == 1'}} \
+   // ref-error {{static assertion 
failed}} \
+   // ref-note 
{{'340282366920938463463374607431768211455 == 1'}}
 
   static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
   static_assert(INT128_MAX != 0, "");

``




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


[clang] [compiler-rt] [llvm] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-06 Thread Matthew Devereau via cfe-commits


@@ -1133,6 +1133,9 @@ typedef struct __ifunc_arg_t {
 #ifndef HWCAP2_SME_F64F64
 #define HWCAP2_SME_F64F64 (1 << 25)
 #endif
+#ifndef HWCAP2_SME_FA64
+#define HWCAP2_SME_FA64 (1 << 26)

MDevereau wrote:

This comes from here 
https://github.com/torvalds/linux/blob/master/arch/arm64/include/uapi/asm/hwcap.h
 so it is in fact 30.

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


[llvm] [clang] [compiler-rt] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-06 Thread Matthew Devereau via cfe-commits


@@ -491,13 +491,15 @@ bool AArch64Subtarget::isStreamingCompatible() const {
 }
 
 bool AArch64Subtarget::isNeonAvailable() const {
-  return hasNEON() && !isStreaming() && !isStreamingCompatible();
+  if (hasSMEFA64())
+return true;
+  return (hasNEON() && !isStreaming() && !isStreamingCompatible());

MDevereau wrote:

Done

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


[clang] [compiler-rt] [llvm] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-06 Thread Matthew Devereau via cfe-commits


@@ -491,13 +491,15 @@ bool AArch64Subtarget::isStreamingCompatible() const {
 }
 
 bool AArch64Subtarget::isNeonAvailable() const {
-  return hasNEON() && !isStreaming() && !isStreamingCompatible();
+  if (hasSMEFA64())
+return true;
+  return (hasNEON() && !isStreaming() && !isStreamingCompatible());
 }
 
-bool AArch64Subtarget::isSVEAvailable() const{
-  // FIXME: Also return false if FEAT_FA64 is set, but we can't do this yet
-  // as we don't yet support the feature in LLVM.
-  return hasSVE() && !isStreaming() && !isStreamingCompatible();
+bool AArch64Subtarget::isSVEAvailable() const {
+  if (hasSMEFA64())

MDevereau wrote:

Done

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


[llvm] [clang] [compiler-rt] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-06 Thread Matthew Devereau via cfe-commits


@@ -508,6 +508,9 @@ def FeatureSMEI16I64 : SubtargetFeature<"sme-i16i64", 
"HasSMEI16I64", "true",
 def FeatureSMEF16F16 : SubtargetFeature<"sme-f16f16", "HasSMEF16F16", "true",
   "Enable SME2.1 non-widening Float16 instructions (FEAT_SME_F16F16)", []>;
 
+def FeatureSMEFA64 : SubtargetFeature<"sme-fa64", "HasSMEFA64", "true",
+  "Enable the full A64 instruction set in SVE streaming mode (FEAT_SME_FA64)", 
[]>;

MDevereau wrote:

Done

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


[llvm] [clang] [compiler-rt] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-06 Thread Matthew Devereau via cfe-commits


@@ -162,6 +163,7 @@ enum ArchExtKind : unsigned {
   AEK_FPMR =  58, // FEAT_FPMR
   AEK_FP8 =   59, // FEAT_FP8
   AEK_FAMINMAX =  60, // FEAT_FAMINMAX
+  AEK_SMEFA64 =   61, // FEAT_SMEFA64

MDevereau wrote:

I've moved it to be 

  AEK_SME =   38, // FEAT_SME
  AEK_SMEF64F64 = 39, // FEAT_SME_F64F64
  AEK_SMEI16I64 = 40, // FEAT_SME_I16I64
  AEK_SMEFA64 =   41, // FEAT_SME_FA64

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


[llvm] [clang] [compiler-rt] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-06 Thread Matthew Devereau via cfe-commits

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


[llvm] [clang] [compiler-rt] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-06 Thread Matthew Devereau via cfe-commits


@@ -0,0 +1,33 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mattr=+sve -mattr=+sme-fa64 -force-streaming-compatible-sve < %s | 
FileCheck %s -check-prefix=FA64
+; RUN: llc -mattr=+sve -force-streaming-compatible-sve < %s | FileCheck %s 
-check-prefix=NO-FA64
+
+
+target triple = "aarch64-unknown-linux-gnu"
+
+define half @fadda_v4f16(half %start, <4 x half> %a) {

MDevereau wrote:

Added test 
`llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-int-mla-neon-fa64.ll`

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


[llvm] [clang] [clang-tools-extra] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-06 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/70829

>From ac30780250875802d13450d17e6959f9e2ad3a70 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 31 Oct 2023 09:27:51 -0700
Subject: [PATCH 1/2] [clang] Fix false positive -Wmissing-field-initializer
 for anonymous unions

Normally warning is not reported when a field has default initializer.
Do so for anonymous unions with default initializers as well.
No release note since it is a regression in clang 18.

Fixes https://github.com/llvm/llvm-project/issues/70384
---
 clang/lib/Sema/SemaInit.cpp   | 99 +++
 .../SemaCXX/cxx2a-initializer-aggregates.cpp  | 66 -
 2 files changed, 122 insertions(+), 43 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ec796def96ad3d8..881e67587e430e7 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -349,17 +349,13 @@ class InitListChecker {
   bool SubobjectIsDesignatorContext, unsigned &Index,
   InitListExpr *StructuredList,
   unsigned &StructuredIndex);
-  bool CheckDesignatedInitializer(const InitializedEntity &Entity,
-  InitListExpr *IList, DesignatedInitExpr *DIE,
-  unsigned DesigIdx,
-  QualType &CurrentObjectType,
-  RecordDecl::field_iterator *NextField,
-  llvm::APSInt *NextElementIndex,
-  unsigned &Index,
-  InitListExpr *StructuredList,
-  unsigned &StructuredIndex,
-  bool FinishSubobjectInit,
-  bool TopLevelObject);
+  bool CheckDesignatedInitializer(
+  const InitializedEntity &Entity, InitListExpr *IList,
+  DesignatedInitExpr *DIE, unsigned DesigIdx, QualType &CurrentObjectType,
+  RecordDecl::field_iterator *NextField, llvm::APSInt *NextElementIndex,
+  unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex,
+  bool FinishSubobjectInit, bool TopLevelObject,
+  llvm::SmallPtrSetImpl *InitializedFields = nullptr);
   InitListExpr *getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
QualType CurrentObjectType,
InitListExpr *StructuredList,
@@ -2248,7 +2244,8 @@ void InitListChecker::CheckStructUnionTypes(
   // the next field that we'll be initializing.
   bool DesignatedInitFailed = CheckDesignatedInitializer(
   Entity, IList, DIE, 0, DeclType, &Field, nullptr, Index,
-  StructuredList, StructuredIndex, true, TopLevelObject);
+  StructuredList, StructuredIndex, true, TopLevelObject,
+  &InitializedFields);
   if (DesignatedInitFailed)
 hadError = true;
 
@@ -2256,7 +2253,6 @@ void InitListChecker::CheckStructUnionTypes(
   DesignatedInitExpr::Designator *D = DIE->getDesignator(0);
   if (!VerifyOnly && D->isFieldDesignator()) {
 FieldDecl *F = D->getFieldDecl();
-InitializedFields.insert(F);
 if (!DesignatedInitFailed) {
   QualType ET = SemaRef.Context.getBaseElementType(F->getType());
   if (checkDestructorReference(ET, InitLoc, SemaRef)) {
@@ -2365,21 +2361,43 @@ void InitListChecker::CheckStructUnionTypes(
   !RD->isUnion()) {
 // It is possible we have one or more unnamed bitfields remaining.
 // Find first (if any) named field and emit warning.
-for (RecordDecl::field_iterator it = HasDesignatedInit ? RD->field_begin()
-   : Field,
-end = RD->field_end();
- it != end; ++it) {
-  if (HasDesignatedInit && InitializedFields.count(*it))
-continue;
+auto MissingFieldCheck = [&](const RecordDecl *Record,
+ RecordDecl::field_iterator StartField,
+ auto &&MissingFieldCheck) -> bool {
+  FieldDecl *FirstUninitialized = nullptr;
+  for (RecordDecl::field_iterator it = StartField,
+  end = Record->field_end();
+   it != end; ++it) {
+bool AllSet = false;
+if (it->isAnonymousStructOrUnion()) {
+  RecordDecl *RDAnon = it->getType()->getAsRecordDecl();
+  AllSet = MissingFieldCheck(RDAnon, RDAnon->field_begin(),
+ MissingFieldCheck);
+}
+
+if ((HasDesignatedInit && InitializedFields.count(*it)) ||
+it->hasInClassInitializer() || AllSet) {
+  if (Record->isUnion())
+return true;
+  continue;
+}
 
-  if (!it->isUnnamedBitfield() && !it->hasInClassInitializer() &&

[clang-tools-extra] [clang-tidy] Improve alternate snake case warnings (PR #71385)

2023-11-06 Thread J.C. Moyer via cfe-commits

jcmoyer wrote:

> Also update release notes, add one sentence there about this.

Done.

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


[clang-tools-extra] [clang-tidy] Improve alternate snake case warnings (PR #71385)

2023-11-06 Thread J.C. Moyer via cfe-commits

https://github.com/jcmoyer updated 
https://github.com/llvm/llvm-project/pull/71385

>From 41f2765e7d3a0a04ac8c47d73059b16b138bd779 Mon Sep 17 00:00:00 2001
From: "J.C. Moyer" 
Date: Sun, 5 Nov 2023 17:21:32 -0500
Subject: [PATCH] [clang-tidy] Improve alternate snake case warnings

Improves the accuracy of `readability-identifier-naming` for cases
`Camel_Snake_Case` and `camel_Snake_Back`. Prior to this commit, these
cases matched identifiers with only a leading upper case letter or
leading lower case letter respectively. Now, uppercase letters can only
appear at the start of an identifier or directly following an
underscore.
---
 .../readability/IdentifierNamingCheck.cpp |  4 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |  2 +
 .../identifier-naming-case-match.cpp  | 60 +++
 .../readability/identifier-naming.cpp |  3 +-
 4 files changed, 66 insertions(+), 3 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 7539b3899682e13..793b86cadd72501 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -871,8 +871,8 @@ bool IdentifierNamingCheck::matchesStyle(
   llvm::Regex("^[a-z][a-zA-Z0-9]*$"),
   llvm::Regex("^[A-Z][A-Z0-9_]*$"),
   llvm::Regex("^[A-Z][a-zA-Z0-9]*$"),
-  llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
-  llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"),
+  llvm::Regex("^[A-Z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
+  llvm::Regex("^[a-z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
   llvm::Regex("^[A-Z]([a-z0-9_]*[a-z])*$"),
   };
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fe8c7175d554c7b..3edd1ca46846ad8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -399,6 +399,8 @@ Changes in existing checks
   ``Leading_upper_snake_case`` naming convention. The handling of ``typedef``
   has been enhanced, particularly within complex types like function pointers
   and cases where style checks were omitted when functions started with macros.
+  ``Camel_Snake_Case`` and ``camel_Snake_Case`` now detect more invalid
+  identifier names.
 
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to take
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
new file mode 100644
index 000..f692b01923455e8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
@@ -0,0 +1,60 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-identifier-naming %t -- \
+// RUN:   -config='{CheckOptions: { \
+// RUN: readability-identifier-naming.ClassCase: Camel_Snake_Case, \
+// RUN: readability-identifier-naming.StructCase: camel_Snake_Back, \
+// RUN:   }}'
+
+// clang-format off
+
+//===--===//
+// Camel_Snake_Case tests
+//===--===//
+class XML_Parser {};
+class Xml_Parser {};
+class XML_Parser_2 {};
+// NO warnings or fixes expected as these identifiers are Camel_Snake_Case
+
+class XmlParser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'XmlParser'
+// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}
+
+class Xml_parser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'Xml_parser'
+// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}
+
+class xml_parser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'xml_parser'
+// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}
+
+class xml_Parser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'xml_Parser'
+// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}
+
+class xml_Parser_2 {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'xml_Parser_2'
+// CHECK-FIXES: {{^}}class Xml_Parser_2 {};{{$}}
+
+class t {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 't'
+// CHECK-FIXES: {{^}}class T {};{{$}}
+
+//===--===//
+// camel_Snake_Back tests
+//===--===//
+struct json_Parser {};
+struct json_Parser_2 {};
+struct u {};
+// NO warnings or fixes expected as these identifiers are camel_Snake_Back
+
+struct JsonParser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 
'JsonParser'
+// CHECK-FIXES: {{^}}struct json_Parser {};{{$}}
+

[clang-tools-extra] [clang] [llvm] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -2537,19 +2555,13 @@ class FieldInitializerValidatorCCC final : public 
CorrectionCandidateCallback {
 /// actually be initialized.

Fznamznon wrote:

I removed addition of `InitializedFields` parameter, so probably it makes sense 
to update the comment comment in a separate patch.

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


[clang-tools-extra] [clang] [llvm] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-06 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> I wonder if it would make sense to move the checking for this warning here, 
> to the else case in line 725

Thanks for the suggestion, I gave it a try.

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


[clang] [clang][Interp] Fix creating APSInt from IntegralAP (PR #71410)

2023-11-06 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 8f76522a61d01cf7d70debd39418259e969bb8d6 
81836da057f2703f49f30d31955306577a0e1170 -- clang/lib/AST/Interp/IntegralAP.h 
clang/test/AST/Interp/intap.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 134b602d1bb6..f88e7cd19347 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -120,7 +120,7 @@ public:
   constexpr unsigned bitWidth() const { return V.getBitWidth(); }
 
   APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, !Signed); }
-  APValue toAPValue() const {return APValue(APSInt(V, !Signed)); }
+  APValue toAPValue() const { return APValue(APSInt(V, !Signed)); }
 
   bool isZero() const { return V.isZero(); }
   bool isPositive() const { return V.isNonNegative(); }

``




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


[clang] [APINotes] Upstream APINotes YAML compiler (PR #71413)

2023-11-06 Thread Egor Zhdan via cfe-commits

https://github.com/egorzhdan created 
https://github.com/llvm/llvm-project/pull/71413

This upstreams more of the Clang API Notes functionality that is currently 
implemented in the Apple fork: 
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes

>From f80d68edf0787821531c0f88d845b253703ef13e Mon Sep 17 00:00:00 2001
From: Egor Zhdan 
Date: Mon, 6 Nov 2023 15:41:19 +
Subject: [PATCH 1/2] [APINotes] NFC: rename `StoredObjCSelector::NumPieces`

This value actually represents a number of arguments the selector takes, not 
the number of identifiers. These will be different if the selector takes no 
arguments.
---
 clang/lib/APINotes/APINotesFormat.h   | 6 +++---
 clang/lib/APINotes/APINotesReader.cpp | 2 +-
 clang/lib/APINotes/APINotesWriter.cpp | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/APINotes/APINotesFormat.h 
b/clang/lib/APINotes/APINotesFormat.h
index 5897b45d3796d0e..615314c46f09cac 100644
--- a/clang/lib/APINotes/APINotesFormat.h
+++ b/clang/lib/APINotes/APINotesFormat.h
@@ -247,7 +247,7 @@ using EnumConstantDataLayout =
 
 /// A stored Objective-C selector.
 struct StoredObjCSelector {
-  unsigned NumPieces;
+  unsigned NumArgs;
   llvm::SmallVector Identifiers;
 };
 
@@ -302,7 +302,7 @@ template <> struct 
DenseMapInfo {
 
   static unsigned
   getHashValue(const clang::api_notes::StoredObjCSelector &Selector) {
-auto hash = llvm::hash_value(Selector.NumPieces);
+auto hash = llvm::hash_value(Selector.NumArgs);
 hash = hash_combine(hash, Selector.Identifiers.size());
 for (auto piece : Selector.Identifiers)
   hash = hash_combine(hash, static_cast(piece));
@@ -313,7 +313,7 @@ template <> struct 
DenseMapInfo {
 
   static bool isEqual(const clang::api_notes::StoredObjCSelector &LHS,
   const clang::api_notes::StoredObjCSelector &RHS) {
-return LHS.NumPieces == RHS.NumPieces && LHS.Identifiers == 
RHS.Identifiers;
+return LHS.NumArgs == RHS.NumArgs && LHS.Identifiers == RHS.Identifiers;
   }
 };
 
diff --git a/clang/lib/APINotes/APINotesReader.cpp 
b/clang/lib/APINotes/APINotesReader.cpp
index 2cbf5fd3bf50301..01177b9b1d04dde 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -421,7 +421,7 @@ class ObjCSelectorTableInfo {
 
   static internal_key_type ReadKey(const uint8_t *Data, unsigned Length) {
 internal_key_type Key;
-Key.NumPieces =
+Key.NumArgs =
 endian::readNext(Data);
 unsigned NumIdents = (Length - sizeof(uint16_t)) / sizeof(uint32_t);
 for (unsigned i = 0; i != NumIdents; ++i) {
diff --git a/clang/lib/APINotes/APINotesWriter.cpp 
b/clang/lib/APINotes/APINotesWriter.cpp
index 770d78e22050c01..62a2ab1799913a1 100644
--- a/clang/lib/APINotes/APINotesWriter.cpp
+++ b/clang/lib/APINotes/APINotesWriter.cpp
@@ -823,7 +823,7 @@ class ObjCSelectorTableInfo {
 
   void EmitKey(raw_ostream &OS, key_type_ref Key, unsigned) {
 llvm::support::endian::Writer writer(OS, llvm::endianness::little);
-writer.write(Key.NumPieces);
+writer.write(Key.NumArgs);
 for (auto Identifier : Key.Identifiers)
   writer.write(Identifier);
   }

>From 903b4f72f914c64698a468adbba8a7af992bc9aa Mon Sep 17 00:00:00 2001
From: Egor Zhdan 
Date: Mon, 6 Nov 2023 15:45:11 +
Subject: [PATCH 2/2] [APINotes] Upstream APINotes YAML compiler

This upstreams more of the Clang API Notes functionality that is currently 
implemented in the Apple fork: 
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes
---
 .../clang/APINotes/APINotesYAMLCompiler.h |  11 +
 clang/include/clang/APINotes/Types.h  |   1 +
 clang/lib/APINotes/APINotesReader.cpp |   1 +
 clang/lib/APINotes/APINotesYAMLCompiler.cpp   | 498 +-
 4 files changed, 510 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/APINotes/APINotesYAMLCompiler.h 
b/clang/include/clang/APINotes/APINotesYAMLCompiler.h
index 6098d0ee36fc477..9c24ed85b6a124a 100644
--- a/clang/include/clang/APINotes/APINotesYAMLCompiler.h
+++ b/clang/include/clang/APINotes/APINotesYAMLCompiler.h
@@ -10,14 +10,25 @@
 #define LLVM_CLANG_APINOTES_APINOTESYAMLCOMPILER_H
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/raw_ostream.h"
 
+namespace clang {
+class FileEntry;
+} // namespace clang
+
 namespace clang {
 namespace api_notes {
 /// Parses the APINotes YAML content and writes the representation back to the
 /// specified stream.  This provides a means of testing the YAML processing of
 /// the APINotes format.
 bool parseAndDumpAPINotes(llvm::StringRef YI, llvm::raw_ostream &OS);
+
+/// Converts API notes from YAML format to binary format.
+bool compileAPINotes(llvm::StringRef YAMLInput, const FileEntry *SourceFile,
+ llvm::raw_ostream &OS,
+ llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
+ void *DiagHandlerCtxt = nullptr);
 } // namesp

[clang] [APINotes] Upstream APINotes YAML compiler (PR #71413)

2023-11-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Egor Zhdan (egorzhdan)


Changes

This upstreams more of the Clang API Notes functionality that is currently 
implemented in the Apple fork: 
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes

---

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


6 Files Affected:

- (modified) clang/include/clang/APINotes/APINotesYAMLCompiler.h (+11) 
- (modified) clang/include/clang/APINotes/Types.h (+1) 
- (modified) clang/lib/APINotes/APINotesFormat.h (+3-3) 
- (modified) clang/lib/APINotes/APINotesReader.cpp (+2-1) 
- (modified) clang/lib/APINotes/APINotesWriter.cpp (+1-1) 
- (modified) clang/lib/APINotes/APINotesYAMLCompiler.cpp (+497-1) 


``diff
diff --git a/clang/include/clang/APINotes/APINotesYAMLCompiler.h 
b/clang/include/clang/APINotes/APINotesYAMLCompiler.h
index 6098d0ee36fc477..9c24ed85b6a124a 100644
--- a/clang/include/clang/APINotes/APINotesYAMLCompiler.h
+++ b/clang/include/clang/APINotes/APINotesYAMLCompiler.h
@@ -10,14 +10,25 @@
 #define LLVM_CLANG_APINOTES_APINOTESYAMLCOMPILER_H
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/raw_ostream.h"
 
+namespace clang {
+class FileEntry;
+} // namespace clang
+
 namespace clang {
 namespace api_notes {
 /// Parses the APINotes YAML content and writes the representation back to the
 /// specified stream.  This provides a means of testing the YAML processing of
 /// the APINotes format.
 bool parseAndDumpAPINotes(llvm::StringRef YI, llvm::raw_ostream &OS);
+
+/// Converts API notes from YAML format to binary format.
+bool compileAPINotes(llvm::StringRef YAMLInput, const FileEntry *SourceFile,
+ llvm::raw_ostream &OS,
+ llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
+ void *DiagHandlerCtxt = nullptr);
 } // namespace api_notes
 } // namespace clang
 
diff --git a/clang/include/clang/APINotes/Types.h 
b/clang/include/clang/APINotes/Types.h
index b74244bc8f1cbd3..79595abcf7d02d9 100644
--- a/clang/include/clang/APINotes/Types.h
+++ b/clang/include/clang/APINotes/Types.h
@@ -766,6 +766,7 @@ struct Context {
 /// data they contain; it is up to the user to ensure that the data
 /// referenced by the identifier list persists.
 struct ObjCSelectorRef {
+  unsigned NumArgs;
   llvm::ArrayRef Identifiers;
 };
 } // namespace api_notes
diff --git a/clang/lib/APINotes/APINotesFormat.h 
b/clang/lib/APINotes/APINotesFormat.h
index 5897b45d3796d0e..615314c46f09cac 100644
--- a/clang/lib/APINotes/APINotesFormat.h
+++ b/clang/lib/APINotes/APINotesFormat.h
@@ -247,7 +247,7 @@ using EnumConstantDataLayout =
 
 /// A stored Objective-C selector.
 struct StoredObjCSelector {
-  unsigned NumPieces;
+  unsigned NumArgs;
   llvm::SmallVector Identifiers;
 };
 
@@ -302,7 +302,7 @@ template <> struct 
DenseMapInfo {
 
   static unsigned
   getHashValue(const clang::api_notes::StoredObjCSelector &Selector) {
-auto hash = llvm::hash_value(Selector.NumPieces);
+auto hash = llvm::hash_value(Selector.NumArgs);
 hash = hash_combine(hash, Selector.Identifiers.size());
 for (auto piece : Selector.Identifiers)
   hash = hash_combine(hash, static_cast(piece));
@@ -313,7 +313,7 @@ template <> struct 
DenseMapInfo {
 
   static bool isEqual(const clang::api_notes::StoredObjCSelector &LHS,
   const clang::api_notes::StoredObjCSelector &RHS) {
-return LHS.NumPieces == RHS.NumPieces && LHS.Identifiers == 
RHS.Identifiers;
+return LHS.NumArgs == RHS.NumArgs && LHS.Identifiers == RHS.Identifiers;
   }
 };
 
diff --git a/clang/lib/APINotes/APINotesReader.cpp 
b/clang/lib/APINotes/APINotesReader.cpp
index 2cbf5fd3bf50301..ff9b95d9bf75e3d 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -421,7 +421,7 @@ class ObjCSelectorTableInfo {
 
   static internal_key_type ReadKey(const uint8_t *Data, unsigned Length) {
 internal_key_type Key;
-Key.NumPieces =
+Key.NumArgs =
 endian::readNext(Data);
 unsigned NumIdents = (Length - sizeof(uint16_t)) / sizeof(uint32_t);
 for (unsigned i = 0; i != NumIdents; ++i) {
@@ -741,6 +741,7 @@ APINotesReader::Implementation::getSelector(ObjCSelectorRef 
Selector) {
 
   // Translate the identifiers.
   StoredObjCSelector Key;
+  Key.NumArgs = Selector.NumArgs;
   for (auto Ident : Selector.Identifiers) {
 if (auto IdentID = getIdentifier(Ident)) {
   Key.Identifiers.push_back(*IdentID);
diff --git a/clang/lib/APINotes/APINotesWriter.cpp 
b/clang/lib/APINotes/APINotesWriter.cpp
index 770d78e22050c01..62a2ab1799913a1 100644
--- a/clang/lib/APINotes/APINotesWriter.cpp
+++ b/clang/lib/APINotes/APINotesWriter.cpp
@@ -823,7 +823,7 @@ class ObjCSelectorTableInfo {
 
   void EmitKey(raw_ostream &OS, key_type_ref Key, unsigned) {
 llvm::support::endian::Writer writer(OS, llvm::endianness::lit

[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-11-06 Thread Simon Tatham via cfe-commits

statham-arm wrote:

@petrhosek, do you have any further comments? I'll merge this change based on 
@MaskRay's approval if I haven't heard back in another week.

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


[clang] 34ee69b - [clang][CGObjCMac] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-06 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-06T10:19:48-06:00
New Revision: 34ee69b4ce66280ccc65acc1799a5863de2f2aa6

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

LOG: [clang][CGObjCMac] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort (NFC).

Added: 


Modified: 
clang/lib/CodeGen/CGObjCMac.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 6dd7ca64e5221bd..4ac8c4dc9a38745 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -2961,8 +2961,7 @@ llvm::Value 
*CGObjCMac::GenerateProtocolRef(CodeGenFunction &CGF,
   // resolved. Investigate. Its also wasteful to look this up over and over.
   LazySymbols.insert(&CGM.getContext().Idents.get("Protocol"));
 
-  return llvm::ConstantExpr::getBitCast(GetProtocolRef(PD),
-ObjCTypes.getExternalProtocolPtrTy());
+  return GetProtocolRef(PD);
 }
 
 void CGObjCCommonMac::GenerateProtocol(const ObjCProtocolDecl *PD) {
@@ -3182,7 +3181,7 @@ CGObjCMac::EmitProtocolList(Twine name,
 
   llvm::GlobalVariable *GV =
   CreateMetadataVar(name, values, section, CGM.getPointerAlign(), false);
-  return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.ProtocolListPtrTy);
+  return GV;
 }
 
 static void
@@ -3290,7 +3289,7 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine 
Name,
 
   llvm::GlobalVariable *GV =
   CreateMetadataVar(Name, values, Section, CGM.getPointerAlign(), true);
-  return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.PropertyListPtrTy);
+  return GV;
 }
 
 llvm::Constant *
@@ -3311,7 +3310,7 @@ CGObjCCommonMac::EmitProtocolMethodTypes(Twine Name,
 
   llvm::GlobalVariable *GV =
   CreateMetadataVar(Name, Init, Section, CGM.getPointerAlign(), true);
-  return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.Int8PtrPtrTy);
+  return GV;
 }
 
 /*
@@ -3804,7 +3803,7 @@ llvm::Constant *CGObjCMac::EmitIvarList(const 
ObjCImplementationDecl *ID,
   GV = CreateMetadataVar("OBJC_INSTANCE_VARIABLES_" + ID->getName(), ivarList,
  "__OBJC,__instance_vars,regular,no_dead_strip",
  CGM.getPointerAlign(), true);
-  return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.IvarListPtrTy);
+  return GV;
 }
 
 /// Build a struct objc_method_description constant for the given method.
@@ -3923,8 +3922,7 @@ llvm::Constant *CGObjCMac::emitMethodList(Twine name, 
MethodListType MLT,
 
 llvm::GlobalVariable *GV = CreateMetadataVar(prefix + name, values, 
section,
  CGM.getPointerAlign(), true);
-return llvm::ConstantExpr::getBitCast(GV,
-  
ObjCTypes.MethodDescriptionListPtrTy);
+return GV;
   }
 
   // Otherwise, it's an objc_method_list.
@@ -3941,7 +3939,7 @@ llvm::Constant *CGObjCMac::emitMethodList(Twine name, 
MethodListType MLT,
 
   llvm::GlobalVariable *GV = CreateMetadataVar(prefix + name, values, section,
CGM.getPointerAlign(), true);
-  return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.MethodListPtrTy);
+  return GV;
 }
 
 llvm::Function *CGObjCCommonMac::GenerateMethod(const ObjCMethodDecl *OMD,
@@ -3996,8 +3994,7 @@ CGObjCCommonMac::GenerateDirectMethod(const 
ObjCMethodDecl *OMD,
 Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage,
 "", &CGM.getModule());
 Fn->takeName(OldFn);
-OldFn->replaceAllUsesWith(
-llvm::ConstantExpr::getBitCast(Fn, OldFn->getType()));
+OldFn->replaceAllUsesWith(Fn);
 OldFn->eraseFromParent();
 
 // Replace the cached function in the map.
@@ -5204,7 +5201,7 @@ llvm::Constant *CGObjCMac::EmitModuleSymbols() {
   llvm::GlobalVariable *GV = CreateMetadataVar(
   "OBJC_SYMBOLS", values, "__OBJC,__symbols,regular,no_dead_strip",
   CGM.getPointerAlign(), true);
-  return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.SymtabPtrTy);
+  return GV;
 }
 
 llvm::Value *CGObjCMac::EmitClassRefFromId(CodeGenFunction &CGF,
@@ -5214,13 +5211,10 @@ llvm::Value 
*CGObjCMac::EmitClassRefFromId(CodeGenFunction &CGF,
   llvm::GlobalVariable *&Entry = ClassReferences[II];
 
   if (!Entry) {
-llvm::Constant *Casted =
-llvm::ConstantExpr::getBitCast(GetClassName(II->getName()),
-   ObjCTypes.ClassPtrTy);
-Entry = CreateMetadataVar(
-"OBJC_CLASS_REFERENCES_", Casted,
-"__OBJC,__cls_refs,literal_pointers,no_dead_strip",
-CGM.getPointerAlign(), true);
+Entry =
+CreateMetadataVar("OBJC_CLASS_REFERENCES_", 
GetClassName(II->getName()),
+  "__OBJC,__cls_refs,literal_pointers,no_dead_strip",
+  C

[clang] [clang][Interp] Fix creating APSInt from IntegralAP (PR #71410)

2023-11-06 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/71410

>From 8984ebb39a4bb2ba475440b0ed41c534f586a4c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 6 Nov 2023 16:59:33 +0100
Subject: [PATCH] [clang][Interp] Fix creating APSInt from IntegralAP

The boolean argument in the APSInt constructor is IsUnsigned, not
IsSigned.

This marks the 10th time I've run into this issue. Happy anniversary.
---
 clang/lib/AST/Interp/IntegralAP.h | 4 ++--
 clang/test/AST/Interp/intap.cpp   | 4 
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 1f535d420bcd54b..f88e7cd193477f6 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -119,8 +119,8 @@ template  class IntegralAP final {
 
   constexpr unsigned bitWidth() const { return V.getBitWidth(); }
 
-  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, Signed); }
-  APValue toAPValue() const { return APValue(APSInt(V, Signed)); }
+  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, !Signed); }
+  APValue toAPValue() const { return APValue(APSInt(V, !Signed)); }
 
   bool isZero() const { return V.isZero(); }
   bool isPositive() const { return V.isNonNegative(); }
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 45961e6fc74b7a7..5f08b76a565c25a 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -56,6 +56,10 @@ namespace i128 {
 
   static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
   static_assert(UINT128_MAX == -1, "");
+  static_assert(UINT128_MAX == 1, ""); // expected-error {{static assertion 
failed}} \
+   // expected-note 
{{'340282366920938463463374607431768211455 == 1'}} \
+   // ref-error {{static assertion 
failed}} \
+   // ref-note 
{{'340282366920938463463374607431768211455 == 1'}}
 
   static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
   static_assert(INT128_MAX != 0, "");

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


[clang] clang/CodeGen/RISCV: test lowering of math builtins (PR #71399)

2023-11-06 Thread Ramkumar Ramachandra via cfe-commits

artagnon wrote:

The main takeaways here:
- There is only ever an i64 variant of llrint produced, and we have tested 
codegen of that on RV32 and RV64.
- Only an i32 variant of lrint is produced on RV32, and an i64 variant on RV64. 
We have tested the codegen of both.

Hence, I would conclude that #70926 is closed justifiably, and #69945 is safe 
to re-land with respect to RISC-V (there have been some other fixes to it that 
have already landed).

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


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

2023-11-06 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/71398

>From 1d54a5cc6b34aca0e34ab57d7ee62815707d9153 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Mon, 6 Nov 2023 08:54:40 -0500
Subject: [PATCH 1/2] [C23] Complete support for WG14 N2508

In Clang 16, we implemented the ability to add a label at the end of
a compound statement. These changes complete the implementation by
allowing a label to be followed by a declaration in C.

Note, this seems to have fixed an issue with some OpenMP stand-alone
directives not being properly diagnosed as per:
https://www.openmp.org/spec-html/5.1/openmpsu19.html#x34-330002.1.3
(The same requirement exists in OpenMP 5.2 as well.)
---
 clang/docs/ReleaseNotes.rst   | 22 
 .../clang/Basic/DiagnosticParseKinds.td   |  6 
 clang/include/clang/Parse/Parser.h|  9 ++---
 clang/lib/Parse/ParseOpenMP.cpp   |  4 +--
 clang/lib/Parse/ParseStmt.cpp | 34 ---
 clang/test/C/C2x/n2508.c  | 11 ++
 clang/test/OpenMP/barrier_ast_print.cpp   | 24 -
 clang/test/OpenMP/barrier_messages.cpp|  8 ++---
 clang/test/OpenMP/cancel_messages.cpp |  6 ++--
 .../OpenMP/cancellation_point_messages.cpp|  6 ++--
 clang/test/OpenMP/depobj_messages.cpp |  8 ++---
 clang/test/OpenMP/error_message.cpp   | 10 +++---
 clang/test/OpenMP/flush_messages.cpp  |  8 ++---
 clang/test/OpenMP/scan_messages.cpp   | 10 +++---
 clang/test/OpenMP/taskwait_messages.cpp   |  8 ++---
 clang/test/OpenMP/taskyield_messages.cpp  |  8 ++---
 clang/www/c_status.html   |  2 +-
 17 files changed, 121 insertions(+), 63 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index afe7e2e79c2d087..91f4c90fc9b0e24 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -209,6 +209,12 @@ C23 Feature Support
 - Clang now supports  which defines several macros for 
performing
   checked integer arithmetic. It is also exposed in pre-C23 modes.
 
+- Completed the implementation of
+  `N2508 `_. We
+  previously implemented allowing a label at the end of a compound statement,
+  and now we've implemented allowing a label to be followed by a declaration
+  instead of a statement.
+
 Non-comprehensive list of changes in this release
 -
 
@@ -541,6 +547,22 @@ Bug Fixes in This Version
   Fixes (`#67687 `_)
 - Fix crash from constexpr evaluator evaluating uninitialized arrays as rvalue.
   Fixes (`#67317 `_)
+- Clang now properly diagnoses use of stand-alone OpenMP directives after a
+  label (including ``case`` or ``default`` labels).
+
+  Before:
+
+  .. code-block:: c++
+
+  label:
+  #pragma omp barrier // ok
+
+  After:
+
+  .. code-block:: c++
+
+  label:
+  #pragma omp barrier // error: '#pragma omp barrier' cannot be an immediate 
substatement
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index de180344fcc5c74..2bc72acc1375143 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -299,6 +299,12 @@ def note_missing_selector_name : Note<
 def note_force_empty_selector_name : Note<
   "or insert whitespace before ':' to use %0 as parameter name "
   "and have an empty entry in the selector">;
+def ext_c_label_followed_by_declaration : ExtWarn<
+  "label followed by a declaration is a C23 extension">,
+  InGroup;
+def warn_c23_compat_label_followed_by_declaration : Warning<
+  "label followed by a declaration is incompatible with C standards before "
+  "C23">, InGroup, DefaultIgnore;
 def ext_c_label_end_of_compound_statement : ExtWarn<
   "label at end of compound statement is a C23 extension">,
InGroup;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 30e0352c868637b..22e8c4ceea39cd6 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -410,18 +410,15 @@ class Parser : public CodeCompletionHandler {
 
   /// Flags describing a context in which we're parsing a statement.
   enum class ParsedStmtContext {
-/// This context permits declarations in language modes where declarations
-/// are not statements.
-AllowDeclarationsInC = 0x1,
 /// This context permits standalone OpenMP directives.
-AllowStandaloneOpenMPDirectives = 0x2,
+AllowStandaloneOpenMPDirectives = 0x1,
 /// This context is at the top level of a GNU statement expression.
-InStmtExpr = 0x4,
+InStmtExpr = 0x2,
 
 /// The context of a regular substateme

[llvm] [compiler-rt] [clang] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-06 Thread Sander de Smalen via cfe-commits

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


[clang] [compiler-rt] [llvm] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-06 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm approved this pull request.

LGTM (with nit addressed), but please check with @ilinpv on the FMV priorities 
before merging the patch.

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


  1   2   3   4   5   >