[clang-tools-extra] [clang-tidy][NFC] optimize unused using decls performance (PR #110200)

2024-09-28 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/110200

>From aee3cc16d9c36d2cc56247ec14f72730c7b65e80 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 26 Sep 2024 17:48:48 +0800
Subject: [PATCH 1/2] [clang-tidy][NFC] optimize unused using decls performance

---
 .../clang-tidy/misc/UnusedUsingDeclsCheck.cpp| 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 90b317527ee410..3c8dd6e9d239d9 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -25,6 +25,13 @@ AST_MATCHER_P(DeducedTemplateSpecializationType, 
refsToTemplatedDecl,
   return false;
 }
 
+AST_MATCHER_P(Type, getTagDecl, 
clang::ast_matchers::internal::Matcher,
+  DeclMatcher) {
+  if (const auto *ND = Node.getAsTagDecl())
+return DeclMatcher.matches(*ND, Finder, Builder);
+  return false;
+}
+
 } // namespace
 
 // A function that helps to tell whether a TargetDecl in a UsingDecl will be
@@ -61,7 +68,8 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder 
*Finder) {
   Finder->addMatcher(userDefinedLiteral().bind("used"), this);
   Finder->addMatcher(
   loc(elaboratedType(unless(hasQualifier(nestedNameSpecifier())),
- 
hasUnqualifiedDesugaredType(type().bind("usedType",
+ hasUnqualifiedDesugaredType(
+ type(getTagDecl(tagDecl().bind("used")),
   this);
   // Cases where we can identify the UsingShadowDecl directly, rather than
   // just its target.
@@ -139,12 +147,6 @@ void UnusedUsingDeclsCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
   }
 
-  if (const auto *T = Result.Nodes.getNodeAs("usedType")) {
-if (const auto *ND = T->getAsTagDecl())
-  RemoveNamedDecl(ND);
-return;
-  }
-
   if (const auto *UsedShadow =
   Result.Nodes.getNodeAs("usedShadow")) {
 removeFromFoundDecls(UsedShadow->getTargetDecl());

>From c195ec2aa81496d6e963e4db591ea19deec95462 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 28 Sep 2024 21:18:08 +0800
Subject: [PATCH 2/2] Update
 clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp

---
 clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 3c8dd6e9d239d9..700b0548c714cf 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -27,7 +27,7 @@ AST_MATCHER_P(DeducedTemplateSpecializationType, 
refsToTemplatedDecl,
 
 AST_MATCHER_P(Type, getTagDecl, 
clang::ast_matchers::internal::Matcher,
   DeclMatcher) {
-  if (const auto *ND = Node.getAsTagDecl())
+  if (const TagDecl *ND = Node.getAsTagDecl())
 return DeclMatcher.matches(*ND, Finder, Builder);
   return false;
 }

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


[clang] [clang][bytecode] Implement (N)EQ between fixed point and integral (PR #110358)

2024-09-28 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `openmp-s390x-linux` 
running on `systemz-1` while building `clang` at step 6 "test-openmp".

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


Here is the relevant piece of the build log for the reference

```
Step 6 (test-openmp) failure: test (failure)
 TEST 'libomp :: tasking/issue-94260-2.c' FAILED 

Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang 
-fopenmp   -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test 
-L 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -fno-omit-frame-pointer -mbackchain -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt
 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic && 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang 
-fopenmp -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test 
-L 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -fno-omit-frame-pointer -mbackchain -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt
 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic
# executed command: 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--




```



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


[clang] [clang][bytecode] Implement floating-to-fixed-point casts (PR #110361)

2024-09-28 Thread Timm Baeder via cfe-commits

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

None

>From 7583fed959318e8f0e01957d7e278998510d9b0e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 28 Sep 2024 15:50:04 +0200
Subject: [PATCH] [clang][bytecode] Implement floating-to-fixed-point casts

---
 clang/lib/AST/ByteCode/Compiler.cpp |  9 +++
 clang/lib/AST/ByteCode/Interp.h | 35 ++---
 clang/lib/AST/ByteCode/Opcodes.td   |  3 +++
 clang/test/AST/ByteCode/fixed-point.cpp |  7 +
 4 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index a80d973056db43..40cb1b2dd80f96 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -682,6 +682,15 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 return this->emitCastIntegralFixedPoint(classifyPrim(SubExpr->getType()), 
I,
 CE);
   }
+  case CK_FloatingToFixedPoint: {
+if (!this->visit(SubExpr))
+  return false;
+
+auto Sem = Ctx.getASTContext().getFixedPointSemantics(CE->getType());
+uint32_t I;
+std::memcpy(&I, &Sem, sizeof(Sem));
+return this->emitCastFloatingFixedPoint(I, CE);
+  }
 
   case CK_ToVoid:
 return discard(SubExpr);
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index f88233ed0f8f0a..23405765d8de82 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2321,7 +2321,7 @@ static inline bool CastIntegralFixedPoint(InterpState &S, 
CodePtr OpPC,
   std::memcpy(&Sem, &FPS, sizeof(Sem));
 
   bool Overflow;
-  llvm::APFixedPoint IntResult =
+  llvm::APFixedPoint Result =
   llvm::APFixedPoint::getFromIntValue(Int.toAPSInt(), Sem, &Overflow);
 
   if (Overflow) {
@@ -2329,14 +2329,41 @@ static inline bool CastIntegralFixedPoint(InterpState 
&S, CodePtr OpPC,
 if (S.checkingForUndefinedBehavior()) {
   S.getASTContext().getDiagnostics().Report(
   E->getExprLoc(), diag::warn_fixedpoint_constant_overflow)
-  << IntResult.toString() << E->getType();
+  << Result.toString() << E->getType();
 }
-S.CCEDiag(E, diag::note_constexpr_overflow) << IntResult << E->getType();
+S.CCEDiag(E, diag::note_constexpr_overflow) << Result << E->getType();
 if (!S.noteUndefinedBehavior())
   return false;
   }
 
-  S.Stk.push(IntResult);
+  S.Stk.push(Result);
+  return true;
+}
+
+static inline bool CastFloatingFixedPoint(InterpState &S, CodePtr OpPC,
+  uint32_t FPS) {
+  const auto &Float = S.Stk.pop();
+
+  FixedPointSemantics Sem(0, 0, false, false, false);
+  std::memcpy(&Sem, &FPS, sizeof(Sem));
+
+  bool Overflow;
+  llvm::APFixedPoint Result =
+  llvm::APFixedPoint::getFromFloatValue(Float.getAPFloat(), Sem, 
&Overflow);
+
+  if (Overflow) {
+const Expr *E = S.Current->getExpr(OpPC);
+if (S.checkingForUndefinedBehavior()) {
+  S.getASTContext().getDiagnostics().Report(
+  E->getExprLoc(), diag::warn_fixedpoint_constant_overflow)
+  << Result.toString() << E->getType();
+}
+S.CCEDiag(E, diag::note_constexpr_overflow) << Result << E->getType();
+if (!S.noteUndefinedBehavior())
+  return false;
+  }
+
+  S.Stk.push(Result);
   return true;
 }
 
diff --git a/clang/lib/AST/ByteCode/Opcodes.td 
b/clang/lib/AST/ByteCode/Opcodes.td
index 65eb82080a2194..240e00e59d97ec 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -679,6 +679,9 @@ def CastIntegralFixedPoint : Opcode {
   let Args = [ArgUint32];
   let HasGroup = 1;
 }
+def CastFloatingFixedPoint : Opcode {
+  let Args = [ArgUint32];
+}
 
 def PtrPtrCast : Opcode {
   let Args = [ArgBool];
diff --git a/clang/test/AST/ByteCode/fixed-point.cpp 
b/clang/test/AST/ByteCode/fixed-point.cpp
index 51ea166748730c..76da06a02e150c 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -25,3 +25,10 @@ namespace IntToFixedPointCast {
   static_assert(sf == -1.0k);
   static_assert(sf == -1);
 }
+
+namespace FloatToFixedPointCast {
+  constexpr _Fract sf = 1.0; // both-error {{must be initialized by a constant 
expression}} \
+ // both-note {{outside the range of representable 
values of type 'const _Fract'}}
+
+  constexpr _Fract sf2 = 0.5;
+}

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


[clang] [clang][bytecode] Implement floating-to-fixed-point casts (PR #110361)

2024-09-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


4 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+9) 
- (modified) clang/lib/AST/ByteCode/Interp.h (+31-4) 
- (modified) clang/lib/AST/ByteCode/Opcodes.td (+3) 
- (modified) clang/test/AST/ByteCode/fixed-point.cpp (+7) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index a80d973056db43..40cb1b2dd80f96 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -682,6 +682,15 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 return this->emitCastIntegralFixedPoint(classifyPrim(SubExpr->getType()), 
I,
 CE);
   }
+  case CK_FloatingToFixedPoint: {
+if (!this->visit(SubExpr))
+  return false;
+
+auto Sem = Ctx.getASTContext().getFixedPointSemantics(CE->getType());
+uint32_t I;
+std::memcpy(&I, &Sem, sizeof(Sem));
+return this->emitCastFloatingFixedPoint(I, CE);
+  }
 
   case CK_ToVoid:
 return discard(SubExpr);
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index f88233ed0f8f0a..23405765d8de82 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2321,7 +2321,7 @@ static inline bool CastIntegralFixedPoint(InterpState &S, 
CodePtr OpPC,
   std::memcpy(&Sem, &FPS, sizeof(Sem));
 
   bool Overflow;
-  llvm::APFixedPoint IntResult =
+  llvm::APFixedPoint Result =
   llvm::APFixedPoint::getFromIntValue(Int.toAPSInt(), Sem, &Overflow);
 
   if (Overflow) {
@@ -2329,14 +2329,41 @@ static inline bool CastIntegralFixedPoint(InterpState 
&S, CodePtr OpPC,
 if (S.checkingForUndefinedBehavior()) {
   S.getASTContext().getDiagnostics().Report(
   E->getExprLoc(), diag::warn_fixedpoint_constant_overflow)
-  << IntResult.toString() << E->getType();
+  << Result.toString() << E->getType();
 }
-S.CCEDiag(E, diag::note_constexpr_overflow) << IntResult << E->getType();
+S.CCEDiag(E, diag::note_constexpr_overflow) << Result << E->getType();
 if (!S.noteUndefinedBehavior())
   return false;
   }
 
-  S.Stk.push(IntResult);
+  S.Stk.push(Result);
+  return true;
+}
+
+static inline bool CastFloatingFixedPoint(InterpState &S, CodePtr OpPC,
+  uint32_t FPS) {
+  const auto &Float = S.Stk.pop();
+
+  FixedPointSemantics Sem(0, 0, false, false, false);
+  std::memcpy(&Sem, &FPS, sizeof(Sem));
+
+  bool Overflow;
+  llvm::APFixedPoint Result =
+  llvm::APFixedPoint::getFromFloatValue(Float.getAPFloat(), Sem, 
&Overflow);
+
+  if (Overflow) {
+const Expr *E = S.Current->getExpr(OpPC);
+if (S.checkingForUndefinedBehavior()) {
+  S.getASTContext().getDiagnostics().Report(
+  E->getExprLoc(), diag::warn_fixedpoint_constant_overflow)
+  << Result.toString() << E->getType();
+}
+S.CCEDiag(E, diag::note_constexpr_overflow) << Result << E->getType();
+if (!S.noteUndefinedBehavior())
+  return false;
+  }
+
+  S.Stk.push(Result);
   return true;
 }
 
diff --git a/clang/lib/AST/ByteCode/Opcodes.td 
b/clang/lib/AST/ByteCode/Opcodes.td
index 65eb82080a2194..240e00e59d97ec 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -679,6 +679,9 @@ def CastIntegralFixedPoint : Opcode {
   let Args = [ArgUint32];
   let HasGroup = 1;
 }
+def CastFloatingFixedPoint : Opcode {
+  let Args = [ArgUint32];
+}
 
 def PtrPtrCast : Opcode {
   let Args = [ArgBool];
diff --git a/clang/test/AST/ByteCode/fixed-point.cpp 
b/clang/test/AST/ByteCode/fixed-point.cpp
index 51ea166748730c..76da06a02e150c 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -25,3 +25,10 @@ namespace IntToFixedPointCast {
   static_assert(sf == -1.0k);
   static_assert(sf == -1);
 }
+
+namespace FloatToFixedPointCast {
+  constexpr _Fract sf = 1.0; // both-error {{must be initialized by a constant 
expression}} \
+ // both-note {{outside the range of representable 
values of type 'const _Fract'}}
+
+  constexpr _Fract sf2 = 0.5;
+}

``




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


[clang] [clang][CGOpenMPRuntimeGPU] Avoid llvm::Type::getPointerTo() (NFC) (PR #110357)

2024-09-28 Thread Nikita Popov via cfe-commits

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


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


[clang] [Clang][Concepts] Normalize SizeOfPackExpr's pack declaration (PR #110238)

2024-09-28 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/110238

>From 23a765ac6d8e455121346405332d2066dcc0861e Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 27 Sep 2024 18:23:47 +0800
Subject: [PATCH 1/7] [Clang] GH93099

---
 clang/include/clang/Sema/Sema.h   |  4 ++-
 clang/lib/Sema/SemaTemplateVariadic.cpp   | 20 +++
 clang/lib/Sema/TreeTransform.h| 16 ++---
 .../SemaTemplate/concepts-out-of-line-def.cpp | 34 +++
 4 files changed, 61 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e1c3a99cfa167e..1fce74880026ce 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14264,7 +14264,9 @@ class Sema final : public SemaBase {
   ///
   /// This is intended for use when transforming 'sizeof...(Arg)' in order to
   /// avoid actually expanding the pack where possible.
-  std::optional getFullyPackExpandedSize(TemplateArgument Arg);
+  std::optional
+  getFullyPackExpandedSize(TemplateArgument Arg,
+   const NamedDecl *&ParameterPack);
 
   /// Called when an expression computing the size of a parameter pack
   /// is parsed.
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 40522a07f6339c..79e2f1f610b11f 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1211,7 +1211,9 @@ TemplateArgumentLoc 
Sema::getTemplateArgumentPackExpansionPattern(
   llvm_unreachable("Invalid TemplateArgument Kind!");
 }
 
-std::optional Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
+std::optional
+Sema::getFullyPackExpandedSize(TemplateArgument Arg,
+   const NamedDecl *&ParameterPack) {
   assert(Arg.containsUnexpandedParameterPack());
 
   // If this is a substituted pack, grab that pack. If not, we don't know
@@ -1222,17 +1224,20 @@ std::optional 
Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
   TemplateArgument Pack;
   switch (Arg.getKind()) {
   case TemplateArgument::Type:
-if (auto *Subst = Arg.getAsType()->getAs())
+if (auto *Subst = Arg.getAsType()->getAs()) 
{
   Pack = Subst->getArgumentPack();
-else
+  ParameterPack = Subst->getReplacedParameter();
+} else
   return std::nullopt;
 break;
 
   case TemplateArgument::Expression:
 if (auto *Subst =
-dyn_cast(Arg.getAsExpr()))
+dyn_cast(Arg.getAsExpr())) {
   Pack = Subst->getArgumentPack();
-else if (auto *Subst = dyn_cast(Arg.getAsExpr()))  {
+  ParameterPack = Subst->getParameterPack();
+} else if (auto *Subst = dyn_cast(Arg.getAsExpr())) {
+  ParameterPack = Subst->getParameterPack();
   for (VarDecl *PD : *Subst)
 if (PD->isParameterPack())
   return std::nullopt;
@@ -1243,9 +1248,10 @@ std::optional 
Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
 
   case TemplateArgument::Template:
 if (SubstTemplateTemplateParmPackStorage *Subst =
-Arg.getAsTemplate().getAsSubstTemplateTemplateParmPack())
+Arg.getAsTemplate().getAsSubstTemplateTemplateParmPack()) {
   Pack = Subst->getArgumentPack();
-else
+  ParameterPack = Subst->getParameterPack();
+} else
   return std::nullopt;
 break;
 
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 91cb980ee26b26..3a029e88e865df 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -15237,6 +15237,7 @@ 
TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
 
   // Try to compute the result without performing a partial substitution.
   std::optional Result = 0;
+  NamedDecl *NewPack = E->getPack();
   for (const TemplateArgument &Arg : PackArgs) {
 if (!Arg.isPackExpansion()) {
   Result = *Result + 1;
@@ -15260,9 +15261,14 @@ 
TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
/*Uneval*/ true))
   return true;
 
+const NamedDecl *TransformedParameterPack = nullptr;
 // See if we can determine the number of arguments from the result.
-std::optional NumExpansions =
-getSema().getFullyPackExpandedSize(OutPattern.getArgument());
+std::optional NumExpansions = getSema().getFullyPackExpandedSize(
+OutPattern.getArgument(), TransformedParameterPack);
+if (TransformedParameterPack && !E->isPartiallySubstituted()) {
+  assert(PackArgs.size() == 1);
+  NewPack = const_cast(TransformedParameterPack);
+}
 if (!NumExpansions) {
   // No: we must be in an alias template expansion, and we're going to need
   // to actually expand the packs.
@@ -15277,7 +15283,7 @@ 
TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
   // substituting.
   if (Result)
 return getDerived().RebuildSizeOfPackExpr(
-E->getOperatorLoc(), E->getPa

[clang] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` (PR #110366)

2024-09-28 Thread Зишан Мирза via cfe-commits

https://github.com/zimirza created 
https://github.com/llvm/llvm-project/pull/110366

Closes #107445

From 4fb69942effb3cf34d07f33a14a95757b6ca5ee0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?=
 =?UTF-8?q?=D0=B0?= 
Date: Sat, 28 Sep 2024 17:05:42 +0200
Subject: [PATCH] [clang-tidy] add `ctime` and `localtime` to `clang-tidy`

Closes #107445
---
 clang/docs/tools/clang-formatted-files.txt   | 8 
 .../StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp   | 4 
 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc   | 4 
 clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc | 6 ++
 clang/test/Analysis/cert/env34-c.c   | 9 -
 5 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index 67ff085144f4de..5223ca82a5b575 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -3058,6 +3058,14 @@ libc/src/threads/linux/thrd_join.cpp
 libc/src/threads/linux/Thread.h
 libc/src/time/asctime.cpp
 libc/src/time/asctime.h
+libc/src/time/ctime.cpp
+libc/src/time/ctime.h
+libc/src/time/ctime_r.cpp
+libc/src/time/ctime_r.h
+libc/src/time/localtime.cpp
+libc/src/time/localtime.h
+libc/src/time/localtime_r.cpp
+libc/src/time/localtime_r.h
 libc/src/time/asctime_r.cpp
 libc/src/time/asctime_r.h
 libc/src/time/gmtime.cpp
diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
index fefe846b6911f7..9c34d3636c8488 100644
--- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
@@ -76,6 +76,10 @@ class InvalidPtrChecker
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   {{CDM::CLibrary, {"asctime"}, 1},
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
+  {{CDM::CLibrary, {"ctime"}, 1},
+   &InvalidPtrChecker::postPreviousReturnInvalidatingCall},
+  {{CDM::CLibrary, {"localtime"}, 1},
+   &InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   };
 
   // The private members of this checker corresponding to commandline options
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc
index 463ce921f0672f..aca22f869b5291 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc
@@ -220,6 +220,10 @@ SYMBOL(and, None, )
 SYMBOL(and_eq, None, )
 SYMBOL(asctime, None, )
 SYMBOL(asctime_s, None, )
+SYMBOL(ctime, None, )
+SYMBOL(ctime_s, None, )
+SYMBOL(localtime, None, )
+SYMBOL(localtime_s, None, )
 SYMBOL(asin, None, )
 SYMBOL(asinf, None, )
 SYMBOL(asinh, None, )
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
index b46bd2e4d7a4b5..8e3471e2fc5729 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
@@ -617,6 +617,12 @@ SYMBOL(as_writable_bytes, std::, )
 SYMBOL(asctime, std::, )
 SYMBOL(asctime, None, )
 SYMBOL(asctime, None, )
+SYMBOL(ctime, std::, )
+SYMBOL(ctime, None, )
+SYMBOL(ctime, None, )
+SYMBOL(localtime, std::, )
+SYMBOL(localtime, None, )
+SYMBOL(localtime, None, )
 SYMBOL(asin, std::, )
 SYMBOL(asin, None, )
 SYMBOL(asin, None, )
diff --git a/clang/test/Analysis/cert/env34-c.c 
b/clang/test/Analysis/cert/env34-c.c
index d307f0d8f4bb01..66ba0be4a67bba 100644
--- a/clang/test/Analysis/cert/env34-c.c
+++ b/clang/test/Analysis/cert/env34-c.c
@@ -15,7 +15,14 @@ lconv *localeconv(void);
 
 typedef struct {
 } tm;
-char *asctime(const tm *timeptr);
+char *asctime(const tm *timeptr)
+;
+typedef struct {
+} tm;
+char *ctime(const tm *timeptr);
+typedef struct {
+} tm;
+struct tm *localtime(struct tm *tm);
 
 int strcmp(const char*, const char*);
 extern void foo(char *e);

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


[clang] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` (PR #110366)

2024-09-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Зишан Мирза (zimirza)


Changes

Closes #107445

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


5 Files Affected:

- (modified) clang/docs/tools/clang-formatted-files.txt (+8) 
- (modified) clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp (+4) 
- (modified) clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc (+4) 
- (modified) clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc (+6) 
- (modified) clang/test/Analysis/cert/env34-c.c (+8-1) 


``diff
diff --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index 67ff085144f4de..5223ca82a5b575 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -3058,6 +3058,14 @@ libc/src/threads/linux/thrd_join.cpp
 libc/src/threads/linux/Thread.h
 libc/src/time/asctime.cpp
 libc/src/time/asctime.h
+libc/src/time/ctime.cpp
+libc/src/time/ctime.h
+libc/src/time/ctime_r.cpp
+libc/src/time/ctime_r.h
+libc/src/time/localtime.cpp
+libc/src/time/localtime.h
+libc/src/time/localtime_r.cpp
+libc/src/time/localtime_r.h
 libc/src/time/asctime_r.cpp
 libc/src/time/asctime_r.h
 libc/src/time/gmtime.cpp
diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
index fefe846b6911f7..9c34d3636c8488 100644
--- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
@@ -76,6 +76,10 @@ class InvalidPtrChecker
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   {{CDM::CLibrary, {"asctime"}, 1},
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
+  {{CDM::CLibrary, {"ctime"}, 1},
+   &InvalidPtrChecker::postPreviousReturnInvalidatingCall},
+  {{CDM::CLibrary, {"localtime"}, 1},
+   &InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   };
 
   // The private members of this checker corresponding to commandline options
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc
index 463ce921f0672f..aca22f869b5291 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc
@@ -220,6 +220,10 @@ SYMBOL(and, None, )
 SYMBOL(and_eq, None, )
 SYMBOL(asctime, None, )
 SYMBOL(asctime_s, None, )
+SYMBOL(ctime, None, )
+SYMBOL(ctime_s, None, )
+SYMBOL(localtime, None, )
+SYMBOL(localtime_s, None, )
 SYMBOL(asin, None, )
 SYMBOL(asinf, None, )
 SYMBOL(asinh, None, )
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
index b46bd2e4d7a4b5..8e3471e2fc5729 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
@@ -617,6 +617,12 @@ SYMBOL(as_writable_bytes, std::, )
 SYMBOL(asctime, std::, )
 SYMBOL(asctime, None, )
 SYMBOL(asctime, None, )
+SYMBOL(ctime, std::, )
+SYMBOL(ctime, None, )
+SYMBOL(ctime, None, )
+SYMBOL(localtime, std::, )
+SYMBOL(localtime, None, )
+SYMBOL(localtime, None, )
 SYMBOL(asin, std::, )
 SYMBOL(asin, None, )
 SYMBOL(asin, None, )
diff --git a/clang/test/Analysis/cert/env34-c.c 
b/clang/test/Analysis/cert/env34-c.c
index d307f0d8f4bb01..66ba0be4a67bba 100644
--- a/clang/test/Analysis/cert/env34-c.c
+++ b/clang/test/Analysis/cert/env34-c.c
@@ -15,7 +15,14 @@ lconv *localeconv(void);
 
 typedef struct {
 } tm;
-char *asctime(const tm *timeptr);
+char *asctime(const tm *timeptr)
+;
+typedef struct {
+} tm;
+char *ctime(const tm *timeptr);
+typedef struct {
+} tm;
+struct tm *localtime(struct tm *tm);
 
 int strcmp(const char*, const char*);
 extern void foo(char *e);

``




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


[clang] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` (PR #110366)

2024-09-28 Thread via cfe-commits

llvmbot wrote:




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

Author: Зишан Мирза (zimirza)


Changes

Closes #107445

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


5 Files Affected:

- (modified) clang/docs/tools/clang-formatted-files.txt (+8) 
- (modified) clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp (+4) 
- (modified) clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc (+4) 
- (modified) clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc (+6) 
- (modified) clang/test/Analysis/cert/env34-c.c (+8-1) 


``diff
diff --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index 67ff085144f4de..5223ca82a5b575 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -3058,6 +3058,14 @@ libc/src/threads/linux/thrd_join.cpp
 libc/src/threads/linux/Thread.h
 libc/src/time/asctime.cpp
 libc/src/time/asctime.h
+libc/src/time/ctime.cpp
+libc/src/time/ctime.h
+libc/src/time/ctime_r.cpp
+libc/src/time/ctime_r.h
+libc/src/time/localtime.cpp
+libc/src/time/localtime.h
+libc/src/time/localtime_r.cpp
+libc/src/time/localtime_r.h
 libc/src/time/asctime_r.cpp
 libc/src/time/asctime_r.h
 libc/src/time/gmtime.cpp
diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
index fefe846b6911f7..9c34d3636c8488 100644
--- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
@@ -76,6 +76,10 @@ class InvalidPtrChecker
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   {{CDM::CLibrary, {"asctime"}, 1},
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
+  {{CDM::CLibrary, {"ctime"}, 1},
+   &InvalidPtrChecker::postPreviousReturnInvalidatingCall},
+  {{CDM::CLibrary, {"localtime"}, 1},
+   &InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   };
 
   // The private members of this checker corresponding to commandline options
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc
index 463ce921f0672f..aca22f869b5291 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc
@@ -220,6 +220,10 @@ SYMBOL(and, None, )
 SYMBOL(and_eq, None, )
 SYMBOL(asctime, None, )
 SYMBOL(asctime_s, None, )
+SYMBOL(ctime, None, )
+SYMBOL(ctime_s, None, )
+SYMBOL(localtime, None, )
+SYMBOL(localtime_s, None, )
 SYMBOL(asin, None, )
 SYMBOL(asinf, None, )
 SYMBOL(asinh, None, )
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
index b46bd2e4d7a4b5..8e3471e2fc5729 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
@@ -617,6 +617,12 @@ SYMBOL(as_writable_bytes, std::, )
 SYMBOL(asctime, std::, )
 SYMBOL(asctime, None, )
 SYMBOL(asctime, None, )
+SYMBOL(ctime, std::, )
+SYMBOL(ctime, None, )
+SYMBOL(ctime, None, )
+SYMBOL(localtime, std::, )
+SYMBOL(localtime, None, )
+SYMBOL(localtime, None, )
 SYMBOL(asin, std::, )
 SYMBOL(asin, None, )
 SYMBOL(asin, None, )
diff --git a/clang/test/Analysis/cert/env34-c.c 
b/clang/test/Analysis/cert/env34-c.c
index d307f0d8f4bb01..66ba0be4a67bba 100644
--- a/clang/test/Analysis/cert/env34-c.c
+++ b/clang/test/Analysis/cert/env34-c.c
@@ -15,7 +15,14 @@ lconv *localeconv(void);
 
 typedef struct {
 } tm;
-char *asctime(const tm *timeptr);
+char *asctime(const tm *timeptr)
+;
+typedef struct {
+} tm;
+char *ctime(const tm *timeptr);
+typedef struct {
+} tm;
+struct tm *localtime(struct tm *tm);
 
 int strcmp(const char*, const char*);
 extern void foo(char *e);

``




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


[clang] [clang-tools-extra] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` (PR #110366)

2024-09-28 Thread Зишан Мирза via cfe-commits

https://github.com/zimirza updated 
https://github.com/llvm/llvm-project/pull/110366

From 4fb69942effb3cf34d07f33a14a95757b6ca5ee0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?=
 =?UTF-8?q?=D0=B0?= 
Date: Sat, 28 Sep 2024 17:05:42 +0200
Subject: [PATCH 1/2] [clang-tidy] add `ctime` and `localtime` to `clang-tidy`

Closes #107445
---
 clang/docs/tools/clang-formatted-files.txt   | 8 
 .../StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp   | 4 
 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc   | 4 
 clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc | 6 ++
 clang/test/Analysis/cert/env34-c.c   | 9 -
 5 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index 67ff085144f4de..5223ca82a5b575 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -3058,6 +3058,14 @@ libc/src/threads/linux/thrd_join.cpp
 libc/src/threads/linux/Thread.h
 libc/src/time/asctime.cpp
 libc/src/time/asctime.h
+libc/src/time/ctime.cpp
+libc/src/time/ctime.h
+libc/src/time/ctime_r.cpp
+libc/src/time/ctime_r.h
+libc/src/time/localtime.cpp
+libc/src/time/localtime.h
+libc/src/time/localtime_r.cpp
+libc/src/time/localtime_r.h
 libc/src/time/asctime_r.cpp
 libc/src/time/asctime_r.h
 libc/src/time/gmtime.cpp
diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
index fefe846b6911f7..9c34d3636c8488 100644
--- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
@@ -76,6 +76,10 @@ class InvalidPtrChecker
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   {{CDM::CLibrary, {"asctime"}, 1},
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
+  {{CDM::CLibrary, {"ctime"}, 1},
+   &InvalidPtrChecker::postPreviousReturnInvalidatingCall},
+  {{CDM::CLibrary, {"localtime"}, 1},
+   &InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   };
 
   // The private members of this checker corresponding to commandline options
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc
index 463ce921f0672f..aca22f869b5291 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc
@@ -220,6 +220,10 @@ SYMBOL(and, None, )
 SYMBOL(and_eq, None, )
 SYMBOL(asctime, None, )
 SYMBOL(asctime_s, None, )
+SYMBOL(ctime, None, )
+SYMBOL(ctime_s, None, )
+SYMBOL(localtime, None, )
+SYMBOL(localtime_s, None, )
 SYMBOL(asin, None, )
 SYMBOL(asinf, None, )
 SYMBOL(asinh, None, )
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
index b46bd2e4d7a4b5..8e3471e2fc5729 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
@@ -617,6 +617,12 @@ SYMBOL(as_writable_bytes, std::, )
 SYMBOL(asctime, std::, )
 SYMBOL(asctime, None, )
 SYMBOL(asctime, None, )
+SYMBOL(ctime, std::, )
+SYMBOL(ctime, None, )
+SYMBOL(ctime, None, )
+SYMBOL(localtime, std::, )
+SYMBOL(localtime, None, )
+SYMBOL(localtime, None, )
 SYMBOL(asin, std::, )
 SYMBOL(asin, None, )
 SYMBOL(asin, None, )
diff --git a/clang/test/Analysis/cert/env34-c.c 
b/clang/test/Analysis/cert/env34-c.c
index d307f0d8f4bb01..66ba0be4a67bba 100644
--- a/clang/test/Analysis/cert/env34-c.c
+++ b/clang/test/Analysis/cert/env34-c.c
@@ -15,7 +15,14 @@ lconv *localeconv(void);
 
 typedef struct {
 } tm;
-char *asctime(const tm *timeptr);
+char *asctime(const tm *timeptr)
+;
+typedef struct {
+} tm;
+char *ctime(const tm *timeptr);
+typedef struct {
+} tm;
+struct tm *localtime(struct tm *tm);
 
 int strcmp(const char*, const char*);
 extern void foo(char *e);

From 5be47623b21694a8f98eb6e5de0e536fdbb4ca0a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?=
 =?UTF-8?q?=D0=B0?= 
Date: Sat, 28 Sep 2024 17:20:00 +0200
Subject: [PATCH 2/2] [clang-tidy] add times to clang-tidy

add `ctime` and `localtime` to unsafe functions check function
---
 clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
index 604a7cac0e4903..f058e5ae40680f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
@@ -50,6 +50,8 @@ static StringRef getReplacementFor(StringRef FunctionName,
 StringRef AnnexKReplacementFunction =
 StringSwitch(FunctionName)
 .Cases("asctime", "a

[clang] [clang] Fix the local parameter of void type inside the `Requires` expression. (PR #109831)

2024-09-28 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

> Therefore, I recommend adding the void parameter check directly into 
> SemaExprCXX for an immediate fix. If there's a future need to consolidate the 
> checks, we can consider refactoring later.

That works for me if it turns out to take much more effort than our 
anticipation,  although it's really a shame for us to end up strewing the check 
three times.

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


[clang] 6cbd8a3 - [clang][bytecode] Implement floating-to-fixed-point casts (#110361)

2024-09-28 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-09-28T17:24:28+02:00
New Revision: 6cbd8a309485329a4fbfe7abf7b85e0b8f154561

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

LOG: [clang][bytecode] Implement floating-to-fixed-point casts (#110361)

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp
clang/lib/AST/ByteCode/Interp.h
clang/lib/AST/ByteCode/Opcodes.td
clang/test/AST/ByteCode/fixed-point.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index a80d973056db43..40cb1b2dd80f96 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -682,6 +682,15 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 return this->emitCastIntegralFixedPoint(classifyPrim(SubExpr->getType()), 
I,
 CE);
   }
+  case CK_FloatingToFixedPoint: {
+if (!this->visit(SubExpr))
+  return false;
+
+auto Sem = Ctx.getASTContext().getFixedPointSemantics(CE->getType());
+uint32_t I;
+std::memcpy(&I, &Sem, sizeof(Sem));
+return this->emitCastFloatingFixedPoint(I, CE);
+  }
 
   case CK_ToVoid:
 return discard(SubExpr);

diff  --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index f88233ed0f8f0a..23405765d8de82 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2321,7 +2321,7 @@ static inline bool CastIntegralFixedPoint(InterpState &S, 
CodePtr OpPC,
   std::memcpy(&Sem, &FPS, sizeof(Sem));
 
   bool Overflow;
-  llvm::APFixedPoint IntResult =
+  llvm::APFixedPoint Result =
   llvm::APFixedPoint::getFromIntValue(Int.toAPSInt(), Sem, &Overflow);
 
   if (Overflow) {
@@ -2329,14 +2329,41 @@ static inline bool CastIntegralFixedPoint(InterpState 
&S, CodePtr OpPC,
 if (S.checkingForUndefinedBehavior()) {
   S.getASTContext().getDiagnostics().Report(
   E->getExprLoc(), diag::warn_fixedpoint_constant_overflow)
-  << IntResult.toString() << E->getType();
+  << Result.toString() << E->getType();
 }
-S.CCEDiag(E, diag::note_constexpr_overflow) << IntResult << E->getType();
+S.CCEDiag(E, diag::note_constexpr_overflow) << Result << E->getType();
 if (!S.noteUndefinedBehavior())
   return false;
   }
 
-  S.Stk.push(IntResult);
+  S.Stk.push(Result);
+  return true;
+}
+
+static inline bool CastFloatingFixedPoint(InterpState &S, CodePtr OpPC,
+  uint32_t FPS) {
+  const auto &Float = S.Stk.pop();
+
+  FixedPointSemantics Sem(0, 0, false, false, false);
+  std::memcpy(&Sem, &FPS, sizeof(Sem));
+
+  bool Overflow;
+  llvm::APFixedPoint Result =
+  llvm::APFixedPoint::getFromFloatValue(Float.getAPFloat(), Sem, 
&Overflow);
+
+  if (Overflow) {
+const Expr *E = S.Current->getExpr(OpPC);
+if (S.checkingForUndefinedBehavior()) {
+  S.getASTContext().getDiagnostics().Report(
+  E->getExprLoc(), diag::warn_fixedpoint_constant_overflow)
+  << Result.toString() << E->getType();
+}
+S.CCEDiag(E, diag::note_constexpr_overflow) << Result << E->getType();
+if (!S.noteUndefinedBehavior())
+  return false;
+  }
+
+  S.Stk.push(Result);
   return true;
 }
 

diff  --git a/clang/lib/AST/ByteCode/Opcodes.td 
b/clang/lib/AST/ByteCode/Opcodes.td
index 65eb82080a2194..240e00e59d97ec 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -679,6 +679,9 @@ def CastIntegralFixedPoint : Opcode {
   let Args = [ArgUint32];
   let HasGroup = 1;
 }
+def CastFloatingFixedPoint : Opcode {
+  let Args = [ArgUint32];
+}
 
 def PtrPtrCast : Opcode {
   let Args = [ArgBool];

diff  --git a/clang/test/AST/ByteCode/fixed-point.cpp 
b/clang/test/AST/ByteCode/fixed-point.cpp
index 51ea166748730c..76da06a02e150c 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -25,3 +25,10 @@ namespace IntToFixedPointCast {
   static_assert(sf == -1.0k);
   static_assert(sf == -1);
 }
+
+namespace FloatToFixedPointCast {
+  constexpr _Fract sf = 1.0; // both-error {{must be initialized by a constant 
expression}} \
+ // both-note {{outside the range of representable 
values of type 'const _Fract'}}
+
+  constexpr _Fract sf2 = 0.5;
+}



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


[clang] [clang][bytecode] Implement fixed-point-to-float casts (PR #110369)

2024-09-28 Thread Timm Baeder via cfe-commits

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

None

>From af2fe551a5324cd1274e1da8d6a14303646ae5b6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 28 Sep 2024 16:02:56 +0200
Subject: [PATCH] [clang][bytecode] Implement fixed-point-to-float casts

---
 clang/lib/AST/ByteCode/Compiler.cpp | 6 ++
 clang/lib/AST/ByteCode/FixedPoint.h | 4 
 clang/lib/AST/ByteCode/Interp.h | 8 
 clang/lib/AST/ByteCode/Opcodes.td   | 3 +++
 clang/test/AST/ByteCode/fixed-point.cpp | 3 +++
 5 files changed, 24 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 40cb1b2dd80f96..77bfb3d8cd7f1a 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -691,6 +691,12 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 std::memcpy(&I, &Sem, sizeof(Sem));
 return this->emitCastFloatingFixedPoint(I, CE);
   }
+  case CK_FixedPointToFloating: {
+if (!this->visit(SubExpr))
+  return false;
+const auto *TargetSemantics = &Ctx.getFloatSemantics(CE->getType());
+return this->emitCastFixedPointFloating(TargetSemantics, CE);
+  }
 
   case CK_ToVoid:
 return discard(SubExpr);
diff --git a/clang/lib/AST/ByteCode/FixedPoint.h 
b/clang/lib/AST/ByteCode/FixedPoint.h
index daa62945346aeb..fb8457a08e93cc 100644
--- a/clang/lib/AST/ByteCode/FixedPoint.h
+++ b/clang/lib/AST/ByteCode/FixedPoint.h
@@ -52,6 +52,10 @@ class FixedPoint final {
   unsigned bitWidth() const { return V.getWidth(); }
   bool isSigned() const { return V.isSigned(); }
 
+  llvm::APFloat toFloat(const llvm::fltSemantics *Sem) const {
+return V.convertToFloat(*Sem);
+  }
+
   ComparisonCategoryResult compare(const FixedPoint &Other) const {
 if (Other.V == V)
   return ComparisonCategoryResult::Equal;
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 23405765d8de82..0a99d9440ff844 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2367,6 +2367,14 @@ static inline bool CastFloatingFixedPoint(InterpState 
&S, CodePtr OpPC,
   return true;
 }
 
+static inline bool CastFixedPointFloating(InterpState &S, CodePtr OpPC,
+  const llvm::fltSemantics *Sem) {
+  const auto &Fixed = S.Stk.pop();
+
+  S.Stk.push(Fixed.toFloat(Sem));
+  return true;
+}
+
 static inline bool PtrPtrCast(InterpState &S, CodePtr OpPC, bool SrcIsVoidPtr) 
{
   const auto &Ptr = S.Stk.peek();
 
diff --git a/clang/lib/AST/ByteCode/Opcodes.td 
b/clang/lib/AST/ByteCode/Opcodes.td
index 240e00e59d97ec..4f11b927989004 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -682,6 +682,9 @@ def CastIntegralFixedPoint : Opcode {
 def CastFloatingFixedPoint : Opcode {
   let Args = [ArgUint32];
 }
+def CastFixedPointFloating : Opcode {
+  let Args = [ArgFltSemantics];
+}
 
 def PtrPtrCast : Opcode {
   let Args = [ArgBool];
diff --git a/clang/test/AST/ByteCode/fixed-point.cpp 
b/clang/test/AST/ByteCode/fixed-point.cpp
index 76da06a02e150c..68137618b5db60 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -31,4 +31,7 @@ namespace FloatToFixedPointCast {
  // both-note {{outside the range of representable 
values of type 'const _Fract'}}
 
   constexpr _Fract sf2 = 0.5;
+  static_assert(sf2 == 0.5);
+  constexpr float sf2f = sf2;
+  static_assert(sf2f == 0.5);
 }

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


[clang] [clang][bytecode] Implement floating-to-fixed-point casts (PR #110361)

2024-09-28 Thread Timm Baeder via cfe-commits

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


[clang] [clang][bytecode] Implement fixed-point-to-float casts (PR #110369)

2024-09-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


5 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+6) 
- (modified) clang/lib/AST/ByteCode/FixedPoint.h (+4) 
- (modified) clang/lib/AST/ByteCode/Interp.h (+8) 
- (modified) clang/lib/AST/ByteCode/Opcodes.td (+3) 
- (modified) clang/test/AST/ByteCode/fixed-point.cpp (+3) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 40cb1b2dd80f96..77bfb3d8cd7f1a 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -691,6 +691,12 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 std::memcpy(&I, &Sem, sizeof(Sem));
 return this->emitCastFloatingFixedPoint(I, CE);
   }
+  case CK_FixedPointToFloating: {
+if (!this->visit(SubExpr))
+  return false;
+const auto *TargetSemantics = &Ctx.getFloatSemantics(CE->getType());
+return this->emitCastFixedPointFloating(TargetSemantics, CE);
+  }
 
   case CK_ToVoid:
 return discard(SubExpr);
diff --git a/clang/lib/AST/ByteCode/FixedPoint.h 
b/clang/lib/AST/ByteCode/FixedPoint.h
index daa62945346aeb..fb8457a08e93cc 100644
--- a/clang/lib/AST/ByteCode/FixedPoint.h
+++ b/clang/lib/AST/ByteCode/FixedPoint.h
@@ -52,6 +52,10 @@ class FixedPoint final {
   unsigned bitWidth() const { return V.getWidth(); }
   bool isSigned() const { return V.isSigned(); }
 
+  llvm::APFloat toFloat(const llvm::fltSemantics *Sem) const {
+return V.convertToFloat(*Sem);
+  }
+
   ComparisonCategoryResult compare(const FixedPoint &Other) const {
 if (Other.V == V)
   return ComparisonCategoryResult::Equal;
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 23405765d8de82..0a99d9440ff844 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2367,6 +2367,14 @@ static inline bool CastFloatingFixedPoint(InterpState 
&S, CodePtr OpPC,
   return true;
 }
 
+static inline bool CastFixedPointFloating(InterpState &S, CodePtr OpPC,
+  const llvm::fltSemantics *Sem) {
+  const auto &Fixed = S.Stk.pop();
+
+  S.Stk.push(Fixed.toFloat(Sem));
+  return true;
+}
+
 static inline bool PtrPtrCast(InterpState &S, CodePtr OpPC, bool SrcIsVoidPtr) 
{
   const auto &Ptr = S.Stk.peek();
 
diff --git a/clang/lib/AST/ByteCode/Opcodes.td 
b/clang/lib/AST/ByteCode/Opcodes.td
index 240e00e59d97ec..4f11b927989004 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -682,6 +682,9 @@ def CastIntegralFixedPoint : Opcode {
 def CastFloatingFixedPoint : Opcode {
   let Args = [ArgUint32];
 }
+def CastFixedPointFloating : Opcode {
+  let Args = [ArgFltSemantics];
+}
 
 def PtrPtrCast : Opcode {
   let Args = [ArgBool];
diff --git a/clang/test/AST/ByteCode/fixed-point.cpp 
b/clang/test/AST/ByteCode/fixed-point.cpp
index 76da06a02e150c..68137618b5db60 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -31,4 +31,7 @@ namespace FloatToFixedPointCast {
  // both-note {{outside the range of representable 
values of type 'const _Fract'}}
 
   constexpr _Fract sf2 = 0.5;
+  static_assert(sf2 == 0.5);
+  constexpr float sf2f = sf2;
+  static_assert(sf2f == 0.5);
 }

``




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


[clang] [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates (PR #107786)

2024-09-28 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/107786

>From e9948a1004cc2b486a0422d83e88392754e9f7e9 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 23 Sep 2024 17:17:30 +0300
Subject: [PATCH 1/2] [Clang] prevent recovery call expression from proceeding
 with explicit attributes and undeclared templates

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/Sema/Sema.h   |  4 ++-
 clang/lib/Sema/SemaExpr.cpp   | 12 +--
 clang/lib/Sema/SemaOverload.cpp   |  2 +-
 .../SemaTemplate/recovery-crash-cxx20.cpp | 32 +++
 5 files changed, 48 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/SemaTemplate/recovery-crash-cxx20.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b47e06cb0c5d68..110f75d739c072 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -424,6 +424,8 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure in debug mode, and potential crashes in release 
mode, when
   diagnosing a failed cast caused indirectly by a failed implicit conversion 
to the type of the constructor parameter.
 - Fixed an assertion failure by adjusting integral to boolean vector 
conversions (#GH108326)
+- Fixed an assertion failure when invoking recovery call expressions with 
explicit attributes
+  and undeclared templates. (#GH107047, #GH49093)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e1c3a99cfa167e..b2eefdbd1c56d1 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6753,7 +6753,9 @@ class Sema final : public SemaBase {
   ///
   /// Return \c true if the error is unrecoverable, or \c false if the caller
   /// should attempt to recover using these lookup results.
-  bool DiagnoseDependentMemberLookup(const LookupResult &R);
+  bool DiagnoseDependentMemberLookup(
+  const LookupResult &R,
+  TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr);
 
   /// Diagnose an empty lookup.
   ///
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 66df9c969256a2..a5770ae8848517 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2385,7 +2385,15 @@ static void emitEmptyLookupTypoDiagnostic(
  SemaRef.PDiag(NoteID));
 }
 
-bool Sema::DiagnoseDependentMemberLookup(const LookupResult &R) {
+bool Sema::DiagnoseDependentMemberLookup(
+const LookupResult &R, TemplateArgumentListInfo *ExplicitTemplateArgs) {
+  auto IsTemplated = [](NamedDecl *D) { return D->isTemplated(); };
+  if (ExplicitTemplateArgs && !llvm::all_of(R, IsTemplated)) {
+Diag(R.getNameLoc(), diag::err_non_template_in_template_id)
+<< R.getLookupName();
+return true;
+  }
+
   // During a default argument instantiation the CurContext points
   // to a CXXMethodDecl; but we can't apply a this-> fixit inside a
   // function parameter list, hence add an explicit check.
@@ -2487,7 +2495,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
   R.resolveKind();
 }
 
-return DiagnoseDependentMemberLookup(R);
+return DiagnoseDependentMemberLookup(R, ExplicitTemplateArgs);
   }
 
   R.clear();
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index d304f322aced64..fe9b16e1890c16 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -13860,7 +13860,7 @@ BuildRecoveryCallExpr(Sema &SemaRef, Scope *S, Expr *Fn,
 // enclosing class.
 // FIXME: We should also explain why the candidates found by name lookup
 // were not viable.
-if (SemaRef.DiagnoseDependentMemberLookup(R))
+if (SemaRef.DiagnoseDependentMemberLookup(R, ExplicitTemplateArgs))
   return ExprError();
   } else {
 // We had viable candidates and couldn't recover; let the caller diagnose
diff --git a/clang/test/SemaTemplate/recovery-crash-cxx20.cpp 
b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp
new file mode 100644
index 00..3651b986dfd989
--- /dev/null
+++ b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+namespace GH49093 {
+  class B {
+  public:
+static int a() { return 0; }
+decltype(a< 0 >(0)) test; // expected-error {{'a' does not name a template 
but is followed by template arguments}}
+  };
+
+  struct C {
+  static int a() { return 0; }
+  decltype(a < 0 > (0)) test; // expected-error {{'a' does not name a 
template but is followed by template arguments}}
+  };
+
+  void test_is_bool(bool t) {}
+  void test_is_bool(int t) {}
+
+  int main() {
+B b;
+test_is_bool(b.test);
+
+C c;
+test_is_bool(c.test);
+  }
+}
+
+namespace GH107047 {
+  struct A {
+static constexpr auto test() { return 1; }
+   

[clang] 1c2ed36 - [clang][x86] Add constexpr support for BMI/TBM BEXTR intrinsics (#109577)

2024-09-28 Thread via cfe-commits

Author: Simon Pilgrim
Date: 2024-09-28T17:52:54+01:00
New Revision: 1c2ed36741c6bc3921d2566123019079c4249c1a

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

LOG: [clang][x86] Add constexpr support for BMI/TBM BEXTR intrinsics (#109577)

This is an initial patch for constexpr handling of the BEXTR intrinsics - the 
plan is to support all x86 bit manipulation intrinsics eventually (and then 
SSE/AVX intrinsics), but I wanted to treat this as an initial test patch.

Hopefully this will unstick #94161 as well.

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsX86.def
clang/include/clang/Basic/BuiltinsX86_64.def
clang/lib/AST/ExprConstant.cpp
clang/lib/Headers/bmiintrin.h
clang/test/CodeGen/X86/bmi-builtins.c
clang/test/CodeGen/X86/tbm-builtins.c

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsX86.def 
b/clang/include/clang/Basic/BuiltinsX86.def
index 25c656a530b158..e4eb9bfbdd1735 100644
--- a/clang/include/clang/Basic/BuiltinsX86.def
+++ b/clang/include/clang/Basic/BuiltinsX86.def
@@ -555,7 +555,7 @@ TARGET_BUILTIN(__builtin_ia32_lzcnt_u16, "UsUs", "nc", 
"lzcnt")
 TARGET_BUILTIN(__builtin_ia32_lzcnt_u32, "UiUi", "nc", "lzcnt")
 
 // BMI
-TARGET_BUILTIN(__builtin_ia32_bextr_u32, "UiUiUi", "nc", "bmi")
+TARGET_BUILTIN(__builtin_ia32_bextr_u32, "UiUiUi", "ncE", "bmi")
 TARGET_BUILTIN(__builtin_ia32_tzcnt_u16, "UsUs", "nc", "")
 TARGET_BUILTIN(__builtin_ia32_tzcnt_u32, "UiUi", "nc", "")
 
@@ -565,7 +565,7 @@ TARGET_BUILTIN(__builtin_ia32_pdep_si, "UiUiUi", "nc", 
"bmi2")
 TARGET_BUILTIN(__builtin_ia32_pext_si, "UiUiUi", "nc", "bmi2")
 
 // TBM
-TARGET_BUILTIN(__builtin_ia32_bextri_u32, "UiUiIUi", "nc", "tbm")
+TARGET_BUILTIN(__builtin_ia32_bextri_u32, "UiUiIUi", "ncE", "tbm")
 
 // LWP
 TARGET_BUILTIN(__builtin_ia32_llwpcb, "vv*", "n", "lwp")

diff  --git a/clang/include/clang/Basic/BuiltinsX86_64.def 
b/clang/include/clang/Basic/BuiltinsX86_64.def
index db381aa77e7612..81fd46ee6d1663 100644
--- a/clang/include/clang/Basic/BuiltinsX86_64.def
+++ b/clang/include/clang/Basic/BuiltinsX86_64.def
@@ -71,12 +71,12 @@ TARGET_BUILTIN(__builtin_ia32_subborrow_u64, 
"UcUcUOiUOiUOi*", "n", "")
 TARGET_BUILTIN(__builtin_ia32_rdrand64_step, "UiUOi*", "n", "rdrnd")
 TARGET_BUILTIN(__builtin_ia32_rdseed64_step, "UiUOi*", "n", "rdseed")
 TARGET_BUILTIN(__builtin_ia32_lzcnt_u64, "UOiUOi", "nc", "lzcnt")
-TARGET_BUILTIN(__builtin_ia32_bextr_u64, "UOiUOiUOi", "nc", "bmi")
+TARGET_BUILTIN(__builtin_ia32_bextr_u64, "UOiUOiUOi", "ncE", "bmi")
 TARGET_BUILTIN(__builtin_ia32_tzcnt_u64, "UOiUOi", "nc", "")
 TARGET_BUILTIN(__builtin_ia32_bzhi_di, "UOiUOiUOi", "nc", "bmi2")
 TARGET_BUILTIN(__builtin_ia32_pdep_di, "UOiUOiUOi", "nc", "bmi2")
 TARGET_BUILTIN(__builtin_ia32_pext_di, "UOiUOiUOi", "nc", "bmi2")
-TARGET_BUILTIN(__builtin_ia32_bextri_u64, "UOiUOiIUOi", "nc", "tbm")
+TARGET_BUILTIN(__builtin_ia32_bextri_u64, "UOiUOiIUOi", "ncE", "tbm")
 TARGET_BUILTIN(__builtin_ia32_lwpins64, "UcUOiUiIUi", "n", "lwp")
 TARGET_BUILTIN(__builtin_ia32_lwpval64, "vUOiUiIUi", "n", "lwp")
 TARGET_BUILTIN(__builtin_ia32_vcvtsd2si64, "OiV2dIi", "ncV:128:", "avx512f")

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 960eae36ed1f51..51856693944761 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -52,6 +52,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/DiagnosticSema.h"
+#include "clang/Basic/TargetBuiltins.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/APFixedPoint.h"
 #include "llvm/ADT/Sequence.h"
@@ -13462,6 +13463,29 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   return false;
 return Success(DidOverflow, E);
   }
+
+  case clang::X86::BI__builtin_ia32_bextr_u32:
+  case clang::X86::BI__builtin_ia32_bextr_u64:
+  case clang::X86::BI__builtin_ia32_bextri_u32:
+  case clang::X86::BI__builtin_ia32_bextri_u64: {
+APSInt Val, Idx;
+if (!EvaluateInteger(E->getArg(0), Val, Info) ||
+!EvaluateInteger(E->getArg(1), Idx, Info))
+  return false;
+
+unsigned BitWidth = Val.getBitWidth();
+uint64_t Shift = Idx.extractBitsAsZExtValue(8, 0);
+uint64_t Length = Idx.extractBitsAsZExtValue(8, 8);
+Length = Length > BitWidth ? BitWidth : Length;
+
+// Handle out of bounds cases.
+if (Length == 0 || Shift >= BitWidth)
+  return Success(0, E);
+
+uint64_t Result = Val.getZExtValue() >> Shift;
+Result &= llvm::maskTrailingOnes(Length);
+return Success(Result, E);
+  }
   }
 }
 

diff  --git a/clang/lib/Headers/bmiintrin.h b/clang/lib/Headers/bmiintrin.h
index 78bffe68e221a9..72c84d12c0e520 100644
--- a/clang/lib/Headers/bmiintrin.h
+++ b/clang/lib/Headers/bmiintrin.h
@@ -166,6 +166,12 

[clang] [clang][x86] Add constexpr support for BMI/TBM BEXTR intrinsics (PR #109577)

2024-09-28 Thread Simon Pilgrim via cfe-commits

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


[clang] 3a5b9da - [clang][bytecode] Implement fixed-point-to-float casts (#110369)

2024-09-28 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-09-28T19:11:49+02:00
New Revision: 3a5b9da11598e714890f4e9f37f894fc2c7287c2

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

LOG: [clang][bytecode] Implement fixed-point-to-float casts (#110369)

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp
clang/lib/AST/ByteCode/FixedPoint.h
clang/lib/AST/ByteCode/Interp.h
clang/lib/AST/ByteCode/Opcodes.td
clang/test/AST/ByteCode/fixed-point.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 40cb1b2dd80f96..77bfb3d8cd7f1a 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -691,6 +691,12 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 std::memcpy(&I, &Sem, sizeof(Sem));
 return this->emitCastFloatingFixedPoint(I, CE);
   }
+  case CK_FixedPointToFloating: {
+if (!this->visit(SubExpr))
+  return false;
+const auto *TargetSemantics = &Ctx.getFloatSemantics(CE->getType());
+return this->emitCastFixedPointFloating(TargetSemantics, CE);
+  }
 
   case CK_ToVoid:
 return discard(SubExpr);

diff  --git a/clang/lib/AST/ByteCode/FixedPoint.h 
b/clang/lib/AST/ByteCode/FixedPoint.h
index daa62945346aeb..fb8457a08e93cc 100644
--- a/clang/lib/AST/ByteCode/FixedPoint.h
+++ b/clang/lib/AST/ByteCode/FixedPoint.h
@@ -52,6 +52,10 @@ class FixedPoint final {
   unsigned bitWidth() const { return V.getWidth(); }
   bool isSigned() const { return V.isSigned(); }
 
+  llvm::APFloat toFloat(const llvm::fltSemantics *Sem) const {
+return V.convertToFloat(*Sem);
+  }
+
   ComparisonCategoryResult compare(const FixedPoint &Other) const {
 if (Other.V == V)
   return ComparisonCategoryResult::Equal;

diff  --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 23405765d8de82..0a99d9440ff844 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2367,6 +2367,14 @@ static inline bool CastFloatingFixedPoint(InterpState 
&S, CodePtr OpPC,
   return true;
 }
 
+static inline bool CastFixedPointFloating(InterpState &S, CodePtr OpPC,
+  const llvm::fltSemantics *Sem) {
+  const auto &Fixed = S.Stk.pop();
+
+  S.Stk.push(Fixed.toFloat(Sem));
+  return true;
+}
+
 static inline bool PtrPtrCast(InterpState &S, CodePtr OpPC, bool SrcIsVoidPtr) 
{
   const auto &Ptr = S.Stk.peek();
 

diff  --git a/clang/lib/AST/ByteCode/Opcodes.td 
b/clang/lib/AST/ByteCode/Opcodes.td
index 240e00e59d97ec..4f11b927989004 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -682,6 +682,9 @@ def CastIntegralFixedPoint : Opcode {
 def CastFloatingFixedPoint : Opcode {
   let Args = [ArgUint32];
 }
+def CastFixedPointFloating : Opcode {
+  let Args = [ArgFltSemantics];
+}
 
 def PtrPtrCast : Opcode {
   let Args = [ArgBool];

diff  --git a/clang/test/AST/ByteCode/fixed-point.cpp 
b/clang/test/AST/ByteCode/fixed-point.cpp
index 76da06a02e150c..68137618b5db60 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -31,4 +31,7 @@ namespace FloatToFixedPointCast {
  // both-note {{outside the range of representable 
values of type 'const _Fract'}}
 
   constexpr _Fract sf2 = 0.5;
+  static_assert(sf2 == 0.5);
+  constexpr float sf2f = sf2;
+  static_assert(sf2f == 0.5);
 }



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


[clang] [clang][bytecode] Implement fixed-point-to-float casts (PR #110369)

2024-09-28 Thread Timm Baeder via cfe-commits

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-09-28 Thread Chris B via cfe-commits


@@ -422,6 +422,55 @@ template  constexpr uint asuint(T F) {
   return __detail::bit_cast(F);
 }
 
+//===--===//
+// asuint splitdouble builtins
+//===--===//
+
+/// \fn void asuint(double D, out uint lowbits, out int highbits)
+/// \brief Split and interprets the lowbits and highbits of double D into 
uints.
+/// \param D The input double.
+/// \param lowbits The output lowbits of D.
+/// \param highbits The highbits lowbits D.
+#if __is_target_arch(dxil)

llvm-beanz wrote:

>From @joaosaffran's comment on that test 
>(https://github.com/llvm/llvm-project/pull/109331#discussion_r1779366157), it 
>seems like the SPIR-V implementation fails to codegen through the SPIR-V 
>backend. It has nothing to do with the preprocessor. The `clang` commands 
>complete the codegen pipeline unless an error is encountered.

There are two concerns that brings up to me:
1) Why is an unused function being generated?
2) Why is it failing?

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


[clang] [RISCV][FMV] Support target_version (PR #99040)

2024-09-28 Thread Craig Topper via cfe-commits

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

LGTM

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-09-28 Thread Chris B via cfe-commits


@@ -438,6 +438,55 @@ template  constexpr uint asuint(T F) {
   return __detail::bit_cast(F);
 }
 
+//===--===//
+// asuint splitdouble builtins
+//===--===//
+
+/// \fn void asuint(double D, out uint lowbits, out int highbits)
+/// \brief Split and interprets the lowbits and highbits of double D into 
uints.
+/// \param D The input double.
+/// \param lowbits The output lowbits of D.
+/// \param highbits The highbits lowbits D.
+#if __is_target_arch(dxil)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
+void asuint(double, out uint, out uint);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
+void asuint(double2, out uint2, out uint2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
+void asuint(double3, out uint3, out uint3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
+void asuint(double4, out uint4, out uint4);
+
+#elif __is_target_arch(spirv)
+
+void asuint(double4 D, out uint4 lowbits, out uint4 highbits) {
+  uint4 bottom = __detail::bit_cast(D.xy);
+  uint4 top = __detail::bit_cast(D.zw);
+  lowbits = uint4(bottom.x, bottom.z, top.x, top.z);
+  highbits = uint4(bottom.y, bottom.w, top.y, top.w);
+}
+
+void asuint(double3 D, out uint3 lowbits, out uint3 highbits) {
+  uint4 bottom = __detail::bit_cast(D.xy);
+  uint2 top = __detail::bit_cast(D.z);
+  lowbits = uint3(bottom.x, bottom.z, top.x);
+  highbits = uint3(bottom.y, bottom.w, top.y);
+}
+
+void asuint(double2 D, out uint2 lowbits, out uint2 highbits) {
+  uint4 bottom = __detail::bit_cast(D.xy);
+  lowbits = uint2(bottom.x, bottom.z);
+  highbits = uint2(bottom.y, bottom.w);
+}
+
+void asuint(double D, out uint lowbits, out uint highbits) {

llvm-beanz wrote:

If we're going to do standalone functions these should be `constexpr`.

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


[clang] [Clang] Update Interpreter tests to use clang_target_link_libraries (PR #110154)

2024-09-28 Thread Thomas Fransham via cfe-commits

https://github.com/fsfod updated 
https://github.com/llvm/llvm-project/pull/110154

>From e58b244f90c0d9863a41721b7c981d5d853b3d38 Mon Sep 17 00:00:00 2001
From: Thomas Fransham 
Date: Thu, 26 Sep 2024 18:59:33 +0100
Subject: [PATCH] [Clang] Update Interpreter tests to use
 clang_target_link_libraries

This will fix duplicate and missing linker symbol errors when using
CLANG_LINK_CLANG_DYLIB on windows and explicit visibility macros are used.
This is part of the work to enable LLVM_BUILD_LLVM_DYLIB and plugins on window.
---
 clang/unittests/Interpreter/CMakeLists.txt | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/unittests/Interpreter/CMakeLists.txt 
b/clang/unittests/Interpreter/CMakeLists.txt
index ec6f81ea19b960..1ed1216c772e8f 100644
--- a/clang/unittests/Interpreter/CMakeLists.txt
+++ b/clang/unittests/Interpreter/CMakeLists.txt
@@ -16,13 +16,15 @@ add_clang_unittest(ClangReplInterpreterTests
 
   EXPORT_SYMBOLS
   )
-target_link_libraries(ClangReplInterpreterTests PUBLIC
+  
+target_link_libraries(ClangReplInterpreterTests PUBLIC LLVMTestingSupport)
+
+clang_target_link_libraries(ClangReplInterpreterTests PRIVATE
   clangAST
   clangBasic
   clangInterpreter
   clangFrontend
   clangSema
-  LLVMTestingSupport
   )
 
 # Exceptions on Windows are not yet supported.

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-09-28 Thread Chris B via cfe-commits


@@ -3,12 +3,12 @@
 
 // Supported targets
 //
-// RUN: %clang -target dxil-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
-// RUN: %clang -target spirv-unknown-vulkan-compute %s -S -o /dev/null 2>&1 | 
FileCheck --allow-empty --check-prefix=CHECK-VALID %s
-// RUN: %clang -target spirv-unknown-vulkan1.2-compute %s -S -o /dev/null 2>&1 
| FileCheck --allow-empty --check-prefix=CHECK-VALID %s
-// RUN: %clang -target spirv-unknown-vulkan1.3-compute %s -S -o /dev/null 2>&1 
| FileCheck --allow-empty --check-prefix=CHECK-VALID %s
-// RUN: %clang -target spirv1.5-unknown-vulkan1.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
-// RUN: %clang -target spirv1.6-unknown-vulkan1.3-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -cc1 -triple dxil-unknown-shadermodel6.2-compute %s -S 
-disable-llvm-passes -o /dev/null 2>&1 | FileCheck --allow-empty 
--check-prefix=CHECK-VALID %s
+// RUN: %clang -cc1 -triple spirv-unknown-vulkan-compute %s -S 
-disable-llvm-passes -o /dev/null 2>&1 | FileCheck --allow-empty 
--check-prefix=CHECK-VALID %s
+// RUN: %clang -cc1 -triple spirv-unknown-vulkan1.2-compute %s -S 
-disable-llvm-passes -o /dev/null 2>&1 | FileCheck --allow-empty 
--check-prefix=CHECK-VALID %s
+// RUN: %clang -cc1 -triple spirv-unknown-vulkan1.3-compute %s -S 
-disable-llvm-passes -o /dev/null 2>&1 | FileCheck --allow-empty 
--check-prefix=CHECK-VALID %s
+// RUN: %clang -cc1 -triple spirv1.5-unknown-vulkan1.2-compute %s -S 
-disable-llvm-passes -o /dev/null 2>&1 | FileCheck --allow-empty 
--check-prefix=CHECK-VALID %s

llvm-beanz wrote:

Updating the test case to avoid a backend failure is the wrong approach. There 
is clearly something wrong that needs to be properly fixed.

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


[clang] [llvm] [cuda][HIP] `__constant__` should imply constant (PR #110182)

2024-09-28 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/110182

>From af1adfafaa09bc7992cf9aaf34a6121cf2d56d5b Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Thu, 26 Sep 2024 04:16:52 +0100
Subject: [PATCH 1/3] Mark globals as `constant` if they have been annotated
 with `__constant__`/carry the `CUDAConstant` attribute.

---
 clang/lib/CodeGen/CodeGenModule.cpp   |  5 +-
 clang/test/CodeGenCUDA/address-spaces.cu  |  2 +-
 clang/test/CodeGenCUDA/amdgpu-visibility.cu   |  6 +--
 clang/test/CodeGenCUDA/anon-ns.cu |  4 +-
 clang/test/CodeGenCUDA/device-stub.cu |  8 ++--
 clang/test/CodeGenCUDA/device-var-init.cu | 48 +--
 clang/test/CodeGenCUDA/device-var-linkage.cu  | 14 +++---
 clang/test/CodeGenCUDA/filter-decl.cu |  4 +-
 .../CodeGenCUDA/static-device-var-no-rdc.cu   |  4 +-
 .../test/CodeGenCUDA/static-device-var-rdc.cu |  6 +--
 .../template-class-static-member.cu   |  4 +-
 clang/test/CodeGenHIP/hipspv-addr-spaces.cpp  |  2 +-
 12 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index d53d47979f29fb..4fb8a2ec73f4d3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5612,8 +5612,9 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl 
*D,
 emitter->finalize(GV);
 
   // If it is safe to mark the global 'constant', do so now.
-  GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor &&
-  D->getType().isConstantStorage(getContext(), true, true));
+  GV->setConstant(D->hasAttr() ||
+  (!NeedsGlobalCtor && !NeedsGlobalDtor &&
+   D->getType().isConstantStorage(getContext(), true, true)));
 
   // If it is in a read-only section, mark it 'constant'.
   if (const SectionAttr *SA = D->getAttr()) {
diff --git a/clang/test/CodeGenCUDA/address-spaces.cu 
b/clang/test/CodeGenCUDA/address-spaces.cu
index 0608c9cabd0489..66903c81b93339 100644
--- a/clang/test/CodeGenCUDA/address-spaces.cu
+++ b/clang/test/CodeGenCUDA/address-spaces.cu
@@ -9,7 +9,7 @@
 // CHECK: @i ={{.*}} addrspace(1) externally_initialized global
 __device__ int i;
 
-// CHECK: @j ={{.*}} addrspace(4) externally_initialized global
+// CHECK: @j ={{.*}} addrspace(4) externally_initialized constant
 __constant__ int j;
 
 // CHECK: @k ={{.*}} addrspace(3) global
diff --git a/clang/test/CodeGenCUDA/amdgpu-visibility.cu 
b/clang/test/CodeGenCUDA/amdgpu-visibility.cu
index d7dbab112a68c6..ef74d932ee8c8f 100644
--- a/clang/test/CodeGenCUDA/amdgpu-visibility.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-visibility.cu
@@ -4,11 +4,11 @@
 
 #include "Inputs/cuda.h"
 
-// CHECK-DEFAULT: @c ={{.*}} addrspace(4) externally_initialized global
+// CHECK-DEFAULT: @c ={{.*}} addrspace(4) externally_initialized constant
 // CHECK-DEFAULT: @g ={{.*}} addrspace(1) externally_initialized global
-// CHECK-PROTECTED: @c = protected addrspace(4) externally_initialized global
+// CHECK-PROTECTED: @c = protected addrspace(4) externally_initialized constant
 // CHECK-PROTECTED: @g = protected addrspace(1) externally_initialized global
-// CHECK-HIDDEN: @c = protected addrspace(4) externally_initialized global
+// CHECK-HIDDEN: @c = protected addrspace(4) externally_initialized constant
 // CHECK-HIDDEN: @g = protected addrspace(1) externally_initialized global
 __constant__ int c;
 __device__ int g;
diff --git a/clang/test/CodeGenCUDA/anon-ns.cu 
b/clang/test/CodeGenCUDA/anon-ns.cu
index 3c55e9907dd6c1..d931f31d0207c5 100644
--- a/clang/test/CodeGenCUDA/anon-ns.cu
+++ b/clang/test/CodeGenCUDA/anon-ns.cu
@@ -28,13 +28,13 @@
 // HIP-DAG: define weak_odr {{.*}}void 
@[[KTX:_Z2ktIN12_GLOBAL__N_11XEEvT_\.intern\.b04fd23c98500190]](
 // HIP-DAG: define weak_odr {{.*}}void 
@[[KTL:_Z2ktIN12_GLOBAL__N_1UlvE_EEvT_\.intern\.b04fd23c98500190]](
 // HIP-DAG: @[[VM:_ZN12_GLOBAL__N_12vmE\.static\.b04fd23c98500190]] = 
addrspace(1) externally_initialized global
-// HIP-DAG: @[[VC:_ZN12_GLOBAL__N_12vcE\.static\.b04fd23c98500190]] = 
addrspace(4) externally_initialized global
+// HIP-DAG: @[[VC:_ZN12_GLOBAL__N_12vcE\.static\.b04fd23c98500190]] = 
addrspace(4) externally_initialized constant
 // HIP-DAG: @[[VT:_Z2vtIN12_GLOBAL__N_11XEE\.static\.b04fd23c98500190]] = 
addrspace(1) externally_initialized global
 
 // CUDA-DAG: define weak_odr {{.*}}void 
@[[KERN:_ZN12_GLOBAL__N_16kernelEv__intern__b04fd23c98500190]](
 // CUDA-DAG: define weak_odr {{.*}}void 
@[[KTX:_Z2ktIN12_GLOBAL__N_11XEEvT___intern__b04fd23c98500190]](
 // CUDA-DAG: define weak_odr {{.*}}void 
@[[KTL:_Z2ktIN12_GLOBAL__N_1UlvE_EEvT___intern__b04fd23c98500190]](
-// CUDA-DAG: @[[VC:_ZN12_GLOBAL__N_12vcE__static__b04fd23c98500190]] = 
addrspace(4) externally_initialized global
+// CUDA-DAG: @[[VC:_ZN12_GLOBAL__N_12vcE__static__b04fd23c98500190]] = 
addrspace(4) externally_initialized constant
 // CUDA-DAG: @[[VT:_Z2vtIN12_GLOBAL__N_11XEE__static__b04fd23c98

[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-09-28 Thread via cfe-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/109331

>From ef969c536d700a8585f0892952fae49cdd9c42d1 Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Thu, 19 Sep 2024 00:13:51 +
Subject: [PATCH 01/10] Codegen builtin

---
 clang/include/clang/Basic/Builtins.td |  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp   | 38 
 clang/lib/CodeGen/CGCall.cpp  |  5 ++
 clang/lib/CodeGen/CGExpr.cpp  | 15 -
 clang/lib/CodeGen/CodeGenFunction.h   | 10 +++-
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 20 +++
 clang/lib/Sema/SemaHLSL.cpp   | 58 ---
 .../builtins/asuint-splitdouble.hlsl  | 10 
 llvm/include/llvm/IR/IntrinsicsDirectX.td |  5 ++
 llvm/lib/Target/DirectX/DXIL.td   |  1 +
 .../Target/DirectX/DXILIntrinsicExpansion.cpp | 13 +
 11 files changed, 167 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/asuint-splitdouble.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 8090119e512fbb..28341e001b6270 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4788,6 +4788,12 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLAsUintSplitDouble: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_asuint_splitdouble"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d739597de4c855..e9dd176fd3d76a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18852,6 +18852,44 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 retType, CGM.getHLSLRuntime().getSignIntrinsic(),
 ArrayRef{Op0}, nullptr, "hlsl.sign");
   }
+  // This should only be called when targeting DXIL
+  case Builtin::BI__builtin_hlsl_asuint_splitdouble: {
+
+assert((E->getArg(0)->getType()->hasFloatingRepresentation() &&
+E->getArg(1)->getType()->hasUnsignedIntegerRepresentation() &&
+E->getArg(2)->getType()->hasUnsignedIntegerRepresentation()) &&
+   "asuint operands types mismatch");
+
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+const HLSLOutArgExpr *OutArg1 = dyn_cast(E->getArg(1));
+const HLSLOutArgExpr *OutArg2 = dyn_cast(E->getArg(2));
+
+CallArgList Args;
+LValue Op1TmpLValue = EmitHLSLOutArgExpr(OutArg1, Args, 
OutArg1->getType());
+LValue Op2TmpLValue = EmitHLSLOutArgExpr(OutArg2, Args, 
OutArg2->getType());
+
+llvm::Type *retType = llvm::StructType::get(Int32Ty, Int32Ty);
+if (Op0->getType()->isVectorTy()) {
+  auto *XVecTy = E->getArg(0)->getType()->getAs();
+
+  llvm::VectorType *i32VecTy = llvm::VectorType::get(
+  Int32Ty, ElementCount::getFixed(XVecTy->getNumElements()));
+
+  retType = llvm::StructType::get(i32VecTy, i32VecTy);
+}
+
+CallInst *CI =
+Builder.CreateIntrinsic(retType, 
llvm::Intrinsic::dx_asuint_splitdouble,
+{Op0}, nullptr, "hlsl.asuint");
+
+Value *arg0 = Builder.CreateExtractValue(CI, 0);
+Value *arg1 = Builder.CreateExtractValue(CI, 1);
+
+Builder.CreateStore(arg0, Op1TmpLValue.getAddress());
+auto *s = Builder.CreateStore(arg1, Op2TmpLValue.getAddress());
+EmitWritebacks(*this, Args);
+return s;
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 4ae981e4013e9c..096bbafa4cc694 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4681,6 +4681,11 @@ void CallArg::copyInto(CodeGenFunction &CGF, Address 
Addr) const {
   IsUsed = true;
 }
 
+void CodeGenFunction::EmitWritebacks(CodeGenFunction &CGF,
+ const CallArgList &args) {
+  emitWritebacks(CGF, args);
+}
+
 void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
   QualType type) {
   DisableDebugLocationUpdates Dis(*this, E);
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index df4994ba9af6e1..5687682be0900e 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -19,6 +19,7 @@
 #include "CGObjCRuntime.h"
 #include "CGOpenMPRuntime.h"
 #include "CGRecordLayout.h"
+#include "CGValue.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "ConstantEmitter.h"
@@ -28,6 +29,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/NSAPI.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/SourceManager.h"
@@ -5457,9 +5459,8 @@ LValue CodeGenFunction::EmitOpaqueValueLVa

[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-09-28 Thread via cfe-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/109331

>From ef969c536d700a8585f0892952fae49cdd9c42d1 Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Thu, 19 Sep 2024 00:13:51 +
Subject: [PATCH 01/10] Codegen builtin

---
 clang/include/clang/Basic/Builtins.td |  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp   | 38 
 clang/lib/CodeGen/CGCall.cpp  |  5 ++
 clang/lib/CodeGen/CGExpr.cpp  | 15 -
 clang/lib/CodeGen/CodeGenFunction.h   | 10 +++-
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 20 +++
 clang/lib/Sema/SemaHLSL.cpp   | 58 ---
 .../builtins/asuint-splitdouble.hlsl  | 10 
 llvm/include/llvm/IR/IntrinsicsDirectX.td |  5 ++
 llvm/lib/Target/DirectX/DXIL.td   |  1 +
 .../Target/DirectX/DXILIntrinsicExpansion.cpp | 13 +
 11 files changed, 167 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/asuint-splitdouble.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 8090119e512fbb..28341e001b6270 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4788,6 +4788,12 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLAsUintSplitDouble: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_asuint_splitdouble"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d739597de4c855..e9dd176fd3d76a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18852,6 +18852,44 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 retType, CGM.getHLSLRuntime().getSignIntrinsic(),
 ArrayRef{Op0}, nullptr, "hlsl.sign");
   }
+  // This should only be called when targeting DXIL
+  case Builtin::BI__builtin_hlsl_asuint_splitdouble: {
+
+assert((E->getArg(0)->getType()->hasFloatingRepresentation() &&
+E->getArg(1)->getType()->hasUnsignedIntegerRepresentation() &&
+E->getArg(2)->getType()->hasUnsignedIntegerRepresentation()) &&
+   "asuint operands types mismatch");
+
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+const HLSLOutArgExpr *OutArg1 = dyn_cast(E->getArg(1));
+const HLSLOutArgExpr *OutArg2 = dyn_cast(E->getArg(2));
+
+CallArgList Args;
+LValue Op1TmpLValue = EmitHLSLOutArgExpr(OutArg1, Args, 
OutArg1->getType());
+LValue Op2TmpLValue = EmitHLSLOutArgExpr(OutArg2, Args, 
OutArg2->getType());
+
+llvm::Type *retType = llvm::StructType::get(Int32Ty, Int32Ty);
+if (Op0->getType()->isVectorTy()) {
+  auto *XVecTy = E->getArg(0)->getType()->getAs();
+
+  llvm::VectorType *i32VecTy = llvm::VectorType::get(
+  Int32Ty, ElementCount::getFixed(XVecTy->getNumElements()));
+
+  retType = llvm::StructType::get(i32VecTy, i32VecTy);
+}
+
+CallInst *CI =
+Builder.CreateIntrinsic(retType, 
llvm::Intrinsic::dx_asuint_splitdouble,
+{Op0}, nullptr, "hlsl.asuint");
+
+Value *arg0 = Builder.CreateExtractValue(CI, 0);
+Value *arg1 = Builder.CreateExtractValue(CI, 1);
+
+Builder.CreateStore(arg0, Op1TmpLValue.getAddress());
+auto *s = Builder.CreateStore(arg1, Op2TmpLValue.getAddress());
+EmitWritebacks(*this, Args);
+return s;
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 4ae981e4013e9c..096bbafa4cc694 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4681,6 +4681,11 @@ void CallArg::copyInto(CodeGenFunction &CGF, Address 
Addr) const {
   IsUsed = true;
 }
 
+void CodeGenFunction::EmitWritebacks(CodeGenFunction &CGF,
+ const CallArgList &args) {
+  emitWritebacks(CGF, args);
+}
+
 void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
   QualType type) {
   DisableDebugLocationUpdates Dis(*this, E);
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index df4994ba9af6e1..5687682be0900e 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -19,6 +19,7 @@
 #include "CGObjCRuntime.h"
 #include "CGOpenMPRuntime.h"
 #include "CGRecordLayout.h"
+#include "CGValue.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "ConstantEmitter.h"
@@ -28,6 +29,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/NSAPI.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/SourceManager.h"
@@ -5457,9 +5459,8 @@ LValue CodeGenFunction::EmitOpaqueValueLVa

[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-09-28 Thread via cfe-commits


@@ -438,6 +438,55 @@ template  constexpr uint asuint(T F) {
   return __detail::bit_cast(F);
 }
 
+//===--===//
+// asuint splitdouble builtins
+//===--===//
+
+/// \fn void asuint(double D, out uint lowbits, out int highbits)
+/// \brief Split and interprets the lowbits and highbits of double D into 
uints.
+/// \param D The input double.
+/// \param lowbits The output lowbits of D.
+/// \param highbits The highbits lowbits D.
+#if __is_target_arch(dxil)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
+void asuint(double, out uint, out uint);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
+void asuint(double2, out uint2, out uint2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
+void asuint(double3, out uint3, out uint3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
+void asuint(double4, out uint4, out uint4);
+
+#elif __is_target_arch(spirv)
+
+void asuint(double4 D, out uint4 lowbits, out uint4 highbits) {
+  uint4 bottom = __detail::bit_cast(D.xy);
+  uint4 top = __detail::bit_cast(D.zw);
+  lowbits = uint4(bottom.x, bottom.z, top.x, top.z);
+  highbits = uint4(bottom.y, bottom.w, top.y, top.w);
+}
+
+void asuint(double3 D, out uint3 lowbits, out uint3 highbits) {
+  uint4 bottom = __detail::bit_cast(D.xy);
+  uint2 top = __detail::bit_cast(D.z);
+  lowbits = uint3(bottom.x, bottom.z, top.x);
+  highbits = uint3(bottom.y, bottom.w, top.y);
+}
+
+void asuint(double2 D, out uint2 lowbits, out uint2 highbits) {
+  uint4 bottom = __detail::bit_cast(D.xy);
+  lowbits = uint2(bottom.x, bottom.z);
+  highbits = uint2(bottom.y, bottom.w);
+}
+
+void asuint(double D, out uint lowbits, out uint highbits) {

joaosaffran wrote:

`constexpr` doesn't compile here, since the return type is void. Here is the 
error I see when compiling with `constexpr`:
```
error: constexpr function's return type 'void' is not a literal type
```

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


[clang] [clang-format] Add an option to control indentation of `export { ... }` (PR #110381)

2024-09-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (Sirraide)


Changes

`export { ... }` blocks can get a bit long, so I thought it would make sense to 
have an option that makes it so their contents are not indented (basically the 
same argument as for namespaces). This is my first contribution to clang-format 
(I normally contribute to Clang), so I’m not entirely sure if what I did  is 
the best approach. 

I based this on the `NamespaceIndentation` option, except that I didn’t include 
an option to control the behaviour of export blocks when nested because nesting 
them doesn’t really make sense (now that I think about it, iirc they could be 
nested inside something else though—e.g. a namespace—do we care about that 
case?).

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


7 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+15) 
- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Format/Format.h (+14) 
- (modified) clang/lib/Format/Format.cpp (+1) 
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+29-19) 
- (modified) clang/lib/Format/UnwrappedLineParser.h (+2) 
- (modified) clang/unittests/Format/FormatTest.cpp (+25) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index a427d7cd40fcdd..7bdb1d3383e056 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3828,6 +3828,21 @@ the configuration (without a prefix: ``Auto``).
This is an experimental flag, that might go away or be renamed. Do
not use this in config files, etc. Use at your own risk.
 
+.. _ExportBlockIndentation:
+
+**ExportBlockIndentation** (``Boolean``) :versionbadge:`clang-format 20` 
:ref:`¶ `
+  If ``true``, clang-format will indent the body of an ``export { ... }``
+  block. This doesn't affect the formatting of anything else related to
+  exported declarations.
+
+  .. code-block:: c++
+
+ true: false:
+ export {  vs. export {
+   void foo(); void foo();
+   void bar(); void bar();
+ } }
+
 .. _FixNamespaceComments:
 
 **FixNamespaceComments** (``Boolean``) :versionbadge:`clang-format 5` :ref:`¶ 
`
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 14907e7db18de3..2588523e326d13 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -554,6 +554,7 @@ clang-format
 
 
 - Adds ``BreakBinaryOperations`` option.
+- Adds the ``ExportBlockIndentation`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index d8b62c7652a0f6..238a082e0f3670 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2655,6 +2655,19 @@ struct FormatStyle {
   /// \version 3.7
   bool ExperimentalAutoDetectBinPacking;
 
+  /// If ``true``, clang-format will indent the body of an ``export { ... }``
+  /// block. This doesn't affect the formatting of anything else related to
+  /// exported declarations.
+  /// \code
+  ///true: false:
+  ///export {  vs. export {
+  ///  void foo(); void foo();
+  ///  void bar(); void bar();
+  ///} }
+  /// \endcode
+  /// \version 20
+  bool ExportBlockIndentation;
+
   /// If ``true``, clang-format adds missing namespace end comments for
   /// namespaces and fixes invalid existing ones. This doesn't affect short
   /// namespaces, which are controlled by ``ShortNamespaceLines``.
@@ -5131,6 +5144,7 @@ struct FormatStyle {
EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
ExperimentalAutoDetectBinPacking ==
R.ExperimentalAutoDetectBinPacking &&
+   ExportBlockIndentation == R.ExportBlockIndentation &&
FixNamespaceComments == R.FixNamespaceComments &&
ForEachMacros == R.ForEachMacros &&
IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d2463b892fbb96..ee584b1ad0d1e5 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1016,6 +1016,7 @@ template <> struct MappingTraits {
Style.EmptyLineBeforeAccessModifier);
 IO.mapOptional("ExperimentalAutoDetectBinPacking",
Style.ExperimentalAutoDetectBinPacking);
+IO.mapOptional("ExportBlockIndentation", Style.ExportBlockIndentation);
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
 IO.mapOptional("IfMacros", Style.IfMacros);
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 40f77266fabdca..306747290c0a7a 100644
--- a/clang/lib/

[clang] [clang-format] Add an option to control indentation of `export { ... }` (PR #110381)

2024-09-28 Thread via cfe-commits

https://github.com/Sirraide created 
https://github.com/llvm/llvm-project/pull/110381

`export { ... }` blocks can get a bit long, so I thought it would make sense to 
have an option that makes it so their contents are not indented (basically the 
same argument as for namespaces). This is my first contribution to clang-format 
(I normally contribute to Clang), so I’m not entirely sure if what I did  is 
the best approach. 

I based this on the `NamespaceIndentation` option, except that I didn’t include 
an option to control the behaviour of export blocks when nested because nesting 
them doesn’t really make sense (now that I think about it, iirc they could be 
nested inside something else though—e.g. a namespace—do we care about that 
case?).

>From 570aff7459311a43cd9c9139de05dc2ab4cf762c Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sat, 28 Sep 2024 20:36:38 +0200
Subject: [PATCH 1/2] [clang-format] Add an option to control indentation of
 `export { ... }`

---
 clang/docs/ClangFormatStyleOptions.rst   | 15 
 clang/include/clang/Format/Format.h  | 14 +++
 clang/lib/Format/Format.cpp  |  1 +
 clang/lib/Format/UnwrappedLineParser.cpp | 48 ++--
 clang/lib/Format/UnwrappedLineParser.h   |  2 +
 clang/unittests/Format/FormatTest.cpp| 25 
 6 files changed, 86 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index a427d7cd40fcdd..7bdb1d3383e056 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3828,6 +3828,21 @@ the configuration (without a prefix: ``Auto``).
This is an experimental flag, that might go away or be renamed. Do
not use this in config files, etc. Use at your own risk.
 
+.. _ExportBlockIndentation:
+
+**ExportBlockIndentation** (``Boolean``) :versionbadge:`clang-format 20` 
:ref:`¶ `
+  If ``true``, clang-format will indent the body of an ``export { ... }``
+  block. This doesn't affect the formatting of anything else related to
+  exported declarations.
+
+  .. code-block:: c++
+
+ true: false:
+ export {  vs. export {
+   void foo(); void foo();
+   void bar(); void bar();
+ } }
+
 .. _FixNamespaceComments:
 
 **FixNamespaceComments** (``Boolean``) :versionbadge:`clang-format 5` :ref:`¶ 
`
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index d8b62c7652a0f6..238a082e0f3670 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2655,6 +2655,19 @@ struct FormatStyle {
   /// \version 3.7
   bool ExperimentalAutoDetectBinPacking;
 
+  /// If ``true``, clang-format will indent the body of an ``export { ... }``
+  /// block. This doesn't affect the formatting of anything else related to
+  /// exported declarations.
+  /// \code
+  ///true: false:
+  ///export {  vs. export {
+  ///  void foo(); void foo();
+  ///  void bar(); void bar();
+  ///} }
+  /// \endcode
+  /// \version 20
+  bool ExportBlockIndentation;
+
   /// If ``true``, clang-format adds missing namespace end comments for
   /// namespaces and fixes invalid existing ones. This doesn't affect short
   /// namespaces, which are controlled by ``ShortNamespaceLines``.
@@ -5131,6 +5144,7 @@ struct FormatStyle {
EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
ExperimentalAutoDetectBinPacking ==
R.ExperimentalAutoDetectBinPacking &&
+   ExportBlockIndentation == R.ExportBlockIndentation &&
FixNamespaceComments == R.FixNamespaceComments &&
ForEachMacros == R.ForEachMacros &&
IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d2463b892fbb96..ee584b1ad0d1e5 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1016,6 +1016,7 @@ template <> struct MappingTraits {
Style.EmptyLineBeforeAccessModifier);
 IO.mapOptional("ExperimentalAutoDetectBinPacking",
Style.ExperimentalAutoDetectBinPacking);
+IO.mapOptional("ExportBlockIndentation", Style.ExportBlockIndentation);
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
 IO.mapOptional("IfMacros", Style.IfMacros);
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 40f77266fabdca..306747290c0a7a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1616,6 +1616,10 @@ void UnwrappedLineParser::parseStructuralElement(
 parseNamespace();
 return;
   }
+  if (FormatT

[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-09-28 Thread via cfe-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/109331

>From ef969c536d700a8585f0892952fae49cdd9c42d1 Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Thu, 19 Sep 2024 00:13:51 +
Subject: [PATCH 01/10] Codegen builtin

---
 clang/include/clang/Basic/Builtins.td |  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp   | 38 
 clang/lib/CodeGen/CGCall.cpp  |  5 ++
 clang/lib/CodeGen/CGExpr.cpp  | 15 -
 clang/lib/CodeGen/CodeGenFunction.h   | 10 +++-
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 20 +++
 clang/lib/Sema/SemaHLSL.cpp   | 58 ---
 .../builtins/asuint-splitdouble.hlsl  | 10 
 llvm/include/llvm/IR/IntrinsicsDirectX.td |  5 ++
 llvm/lib/Target/DirectX/DXIL.td   |  1 +
 .../Target/DirectX/DXILIntrinsicExpansion.cpp | 13 +
 11 files changed, 167 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/asuint-splitdouble.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 8090119e512fbb..28341e001b6270 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4788,6 +4788,12 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLAsUintSplitDouble: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_asuint_splitdouble"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d739597de4c855..e9dd176fd3d76a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18852,6 +18852,44 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 retType, CGM.getHLSLRuntime().getSignIntrinsic(),
 ArrayRef{Op0}, nullptr, "hlsl.sign");
   }
+  // This should only be called when targeting DXIL
+  case Builtin::BI__builtin_hlsl_asuint_splitdouble: {
+
+assert((E->getArg(0)->getType()->hasFloatingRepresentation() &&
+E->getArg(1)->getType()->hasUnsignedIntegerRepresentation() &&
+E->getArg(2)->getType()->hasUnsignedIntegerRepresentation()) &&
+   "asuint operands types mismatch");
+
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+const HLSLOutArgExpr *OutArg1 = dyn_cast(E->getArg(1));
+const HLSLOutArgExpr *OutArg2 = dyn_cast(E->getArg(2));
+
+CallArgList Args;
+LValue Op1TmpLValue = EmitHLSLOutArgExpr(OutArg1, Args, 
OutArg1->getType());
+LValue Op2TmpLValue = EmitHLSLOutArgExpr(OutArg2, Args, 
OutArg2->getType());
+
+llvm::Type *retType = llvm::StructType::get(Int32Ty, Int32Ty);
+if (Op0->getType()->isVectorTy()) {
+  auto *XVecTy = E->getArg(0)->getType()->getAs();
+
+  llvm::VectorType *i32VecTy = llvm::VectorType::get(
+  Int32Ty, ElementCount::getFixed(XVecTy->getNumElements()));
+
+  retType = llvm::StructType::get(i32VecTy, i32VecTy);
+}
+
+CallInst *CI =
+Builder.CreateIntrinsic(retType, 
llvm::Intrinsic::dx_asuint_splitdouble,
+{Op0}, nullptr, "hlsl.asuint");
+
+Value *arg0 = Builder.CreateExtractValue(CI, 0);
+Value *arg1 = Builder.CreateExtractValue(CI, 1);
+
+Builder.CreateStore(arg0, Op1TmpLValue.getAddress());
+auto *s = Builder.CreateStore(arg1, Op2TmpLValue.getAddress());
+EmitWritebacks(*this, Args);
+return s;
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 4ae981e4013e9c..096bbafa4cc694 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4681,6 +4681,11 @@ void CallArg::copyInto(CodeGenFunction &CGF, Address 
Addr) const {
   IsUsed = true;
 }
 
+void CodeGenFunction::EmitWritebacks(CodeGenFunction &CGF,
+ const CallArgList &args) {
+  emitWritebacks(CGF, args);
+}
+
 void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
   QualType type) {
   DisableDebugLocationUpdates Dis(*this, E);
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index df4994ba9af6e1..5687682be0900e 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -19,6 +19,7 @@
 #include "CGObjCRuntime.h"
 #include "CGOpenMPRuntime.h"
 #include "CGRecordLayout.h"
+#include "CGValue.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "ConstantEmitter.h"
@@ -28,6 +29,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/NSAPI.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/SourceManager.h"
@@ -5457,9 +5459,8 @@ LValue CodeGenFunction::EmitOpaqueValueLVa

[clang] [clang-format] Add an option to control indentation of `export { ... }` (PR #110381)

2024-09-28 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/110381

>From 570aff7459311a43cd9c9139de05dc2ab4cf762c Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Sat, 28 Sep 2024 20:36:38 +0200
Subject: [PATCH 1/3] [clang-format] Add an option to control indentation of
 `export { ... }`

---
 clang/docs/ClangFormatStyleOptions.rst   | 15 
 clang/include/clang/Format/Format.h  | 14 +++
 clang/lib/Format/Format.cpp  |  1 +
 clang/lib/Format/UnwrappedLineParser.cpp | 48 ++--
 clang/lib/Format/UnwrappedLineParser.h   |  2 +
 clang/unittests/Format/FormatTest.cpp| 25 
 6 files changed, 86 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index a427d7cd40fcdd..7bdb1d3383e056 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3828,6 +3828,21 @@ the configuration (without a prefix: ``Auto``).
This is an experimental flag, that might go away or be renamed. Do
not use this in config files, etc. Use at your own risk.
 
+.. _ExportBlockIndentation:
+
+**ExportBlockIndentation** (``Boolean``) :versionbadge:`clang-format 20` 
:ref:`¶ `
+  If ``true``, clang-format will indent the body of an ``export { ... }``
+  block. This doesn't affect the formatting of anything else related to
+  exported declarations.
+
+  .. code-block:: c++
+
+ true: false:
+ export {  vs. export {
+   void foo(); void foo();
+   void bar(); void bar();
+ } }
+
 .. _FixNamespaceComments:
 
 **FixNamespaceComments** (``Boolean``) :versionbadge:`clang-format 5` :ref:`¶ 
`
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index d8b62c7652a0f6..238a082e0f3670 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2655,6 +2655,19 @@ struct FormatStyle {
   /// \version 3.7
   bool ExperimentalAutoDetectBinPacking;
 
+  /// If ``true``, clang-format will indent the body of an ``export { ... }``
+  /// block. This doesn't affect the formatting of anything else related to
+  /// exported declarations.
+  /// \code
+  ///true: false:
+  ///export {  vs. export {
+  ///  void foo(); void foo();
+  ///  void bar(); void bar();
+  ///} }
+  /// \endcode
+  /// \version 20
+  bool ExportBlockIndentation;
+
   /// If ``true``, clang-format adds missing namespace end comments for
   /// namespaces and fixes invalid existing ones. This doesn't affect short
   /// namespaces, which are controlled by ``ShortNamespaceLines``.
@@ -5131,6 +5144,7 @@ struct FormatStyle {
EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
ExperimentalAutoDetectBinPacking ==
R.ExperimentalAutoDetectBinPacking &&
+   ExportBlockIndentation == R.ExportBlockIndentation &&
FixNamespaceComments == R.FixNamespaceComments &&
ForEachMacros == R.ForEachMacros &&
IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d2463b892fbb96..ee584b1ad0d1e5 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1016,6 +1016,7 @@ template <> struct MappingTraits {
Style.EmptyLineBeforeAccessModifier);
 IO.mapOptional("ExperimentalAutoDetectBinPacking",
Style.ExperimentalAutoDetectBinPacking);
+IO.mapOptional("ExportBlockIndentation", Style.ExportBlockIndentation);
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
 IO.mapOptional("IfMacros", Style.IfMacros);
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 40f77266fabdca..306747290c0a7a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1616,6 +1616,10 @@ void UnwrappedLineParser::parseStructuralElement(
 parseNamespace();
 return;
   }
+  if (FormatTok->is(tok::l_brace)) {
+parseCXXExportBlock();
+return;
+  }
   if (FormatTok->is(Keywords.kw_import) && parseModuleImport())
 return;
 }
@@ -3075,6 +3079,26 @@ void UnwrappedLineParser::parseTryCatch() {
 addUnwrappedLine();
 }
 
+void UnwrappedLineParser::parseNamespaceOrExportBlock(unsigned AddLevels) {
+  bool ManageWhitesmithsBraces =
+  AddLevels == 0u && Style.BreakBeforeBraces == 
FormatStyle::BS_Whitesmiths;
+
+  // If we're in Whitesmiths mode, indent the brace if we're not indenting
+  // the whole block.
+  if (ManageWhitesmithsBraces)
+++Line->Level;
+
+  // Munch the semicolon after a namespace. T

[clang-tools-extra] [clangd] Add inlay hints for default function arguments (PR #95712)

2024-09-28 Thread Tor Shepherd via cfe-commits

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


[clang-tools-extra] [clangd] Add inlay hints for default function arguments (PR #95712)

2024-09-28 Thread Tor Shepherd via cfe-commits

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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-09-28 Thread Mehdi Amini via cfe-commits


@@ -231,6 +245,10 @@ linux_projects_to_test=$(exclude-linux 
$(compute-projects-to-test ${modified_pro
 linux_check_targets=$(check-targets ${linux_projects_to_test} | sort | uniq)
 linux_projects=$(add-dependencies ${linux_projects_to_test} | sort | uniq)
 
+linux_runtimes_to_test=$(compute-runtimes-to-test ${linux_projects_to_test})

joker-eph wrote:

Sure, in theory... But that seems like a stretch to me.

I remember recently that clang folks argued to removed the flang tests when 
changing clang because of the likelihood of breaking Flang with clang tests.
I'm not sure the probability of a random LLVM change breaking clang in a way 
that would only show up with a runtime tests and no other LLVM/clang test is 
higher!
The ratio value / cost isn't clear to me right now.


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


[clang] [llvm] [Utils] Add new --update-tests flag to llvm-lit (PR #108425)

2024-09-28 Thread Henrik G. Olsson via cfe-commits

https://github.com/hnrklssn updated 
https://github.com/llvm/llvm-project/pull/108425

>From 6cdb6bec945725d69d1073deeb53b7485c7e40cd Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" 
Date: Wed, 28 Aug 2024 23:30:49 -0700
Subject: [PATCH 1/3] [Utils] Add --update-tests to lit

This adds a flag to lit for detecting and updating failing tests when
possible to do so automatically. The flag uses a plugin architecture
where config files can add additional auto-updaters for the types of
tests in the test suite. When a test fails with --update-tests enabled
lit passes the test RUN invocation and output to each registered test
updater until one of them signals that it updated the test. As such it
is the responsibility of the test updater to only update tests where it
is reasonably certain that it will actually fix the test, or come close
to doing so.
---
 llvm/utils/lit/lit/LitConfig.py|  3 +++
 llvm/utils/lit/lit/TestRunner.py   | 12 
 llvm/utils/lit/lit/cl_arguments.py |  6 ++
 llvm/utils/lit/lit/llvm/config.py  |  5 +
 llvm/utils/lit/lit/main.py |  1 +
 5 files changed, 27 insertions(+)

diff --git a/llvm/utils/lit/lit/LitConfig.py b/llvm/utils/lit/lit/LitConfig.py
index 5dc712ae28370c..198a2bf3172330 100644
--- a/llvm/utils/lit/lit/LitConfig.py
+++ b/llvm/utils/lit/lit/LitConfig.py
@@ -38,6 +38,7 @@ def __init__(
 parallelism_groups={},
 per_test_coverage=False,
 gtest_sharding=True,
+update_tests=False,
 ):
 # The name of the test runner.
 self.progname = progname
@@ -89,6 +90,8 @@ def __init__(
 self.parallelism_groups = parallelism_groups
 self.per_test_coverage = per_test_coverage
 self.gtest_sharding = bool(gtest_sharding)
+self.update_tests = update_tests
+self.test_updaters = []
 
 @property
 def maxIndividualTestTime(self):
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index a1785073547ad0..7556433b83452c 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -1190,6 +1190,18 @@ def executeScriptInternal(
 str(result.timeoutReached),
 )
 
+if litConfig.update_tests:
+for test_updater in litConfig.test_updaters:
+try:
+update_output = test_updater(result)
+except Exception as e:
+out += f"Exception occurred in test updater: {e}"
+continue
+if update_output:
+for line in update_output.splitlines():
+out += f"# {line}\n"
+break
+
 return out, err, exitCode, timeoutInfo
 
 
diff --git a/llvm/utils/lit/lit/cl_arguments.py 
b/llvm/utils/lit/lit/cl_arguments.py
index ed78256ee414b4..dcbe553c6d4827 100644
--- a/llvm/utils/lit/lit/cl_arguments.py
+++ b/llvm/utils/lit/lit/cl_arguments.py
@@ -204,6 +204,12 @@ def parse_args():
 action="store_true",
 help="Exit with status zero even if some tests fail",
 )
+execution_group.add_argument(
+"--update-tests",
+dest="update_tests",
+action="store_true",
+help="Try to update regression tests to reflect current behavior, if 
possible",
+)
 execution_test_time_group = execution_group.add_mutually_exclusive_group()
 execution_test_time_group.add_argument(
 "--skip-test-time-recording",
diff --git a/llvm/utils/lit/lit/llvm/config.py 
b/llvm/utils/lit/lit/llvm/config.py
index 5f762ec7f3514a..c05ec1664d4c45 100644
--- a/llvm/utils/lit/lit/llvm/config.py
+++ b/llvm/utils/lit/lit/llvm/config.py
@@ -64,12 +64,17 @@ def __init__(self, lit_config, config):
 self.with_environment("_TAG_REDIR_ERR", "TXT")
 self.with_environment("_CEE_RUNOPTS", "FILETAG(AUTOCVT,AUTOTAG) 
POSIX(ON)")
 
+if lit_config.update_tests:
+self.use_lit_shell = True
+
 # Choose between lit's internal shell pipeline runner and a real shell.
 # If LIT_USE_INTERNAL_SHELL is in the environment, we use that as an
 # override.
 lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL")
 if lit_shell_env:
 self.use_lit_shell = lit.util.pythonize_bool(lit_shell_env)
+if not self.use_lit_shell and lit_config.update_tests:
+print("note: --update-tests is not supported when using 
external shell")
 
 if not self.use_lit_shell:
 features.add("shell")
diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py
index 24ba804f0c363f..745e376de7d529 100755
--- a/llvm/utils/lit/lit/main.py
+++ b/llvm/utils/lit/lit/main.py
@@ -42,6 +42,7 @@ def main(builtin_params={}):
 config_prefix=opts.configPrefix,
 per_test_coverage=opts.per_test_coverage,
 gtest_sharding=opts.gtest_sharding,
+update_tests=opts.update_tests,
 )
 
 discovered_tests = lit.discov

[clang] [llvm] [Utils] Add new --update-tests flag to llvm-lit (PR #108425)

2024-09-28 Thread Henrik G. Olsson via cfe-commits

hnrklssn wrote:

> Thank you. This pretty much LGTM, but it just occurred to me that there's a 
> docs/CommandGuide/lit.rst which should be updated to document the new option.

Done

> As update-verify-tests was reverted, can you rebase this to just the 
> update_test_checks support? On the LLVM side, we definitely want to have this 
> feature.

and done

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


[clang] [llvm] [Utils] Add new --update-tests flag to llvm-lit (PR #108425)

2024-09-28 Thread Henrik G. Olsson via cfe-commits

https://github.com/hnrklssn updated 
https://github.com/llvm/llvm-project/pull/108425

>From 6cdb6bec945725d69d1073deeb53b7485c7e40cd Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" 
Date: Wed, 28 Aug 2024 23:30:49 -0700
Subject: [PATCH 1/2] [Utils] Add --update-tests to lit

This adds a flag to lit for detecting and updating failing tests when
possible to do so automatically. The flag uses a plugin architecture
where config files can add additional auto-updaters for the types of
tests in the test suite. When a test fails with --update-tests enabled
lit passes the test RUN invocation and output to each registered test
updater until one of them signals that it updated the test. As such it
is the responsibility of the test updater to only update tests where it
is reasonably certain that it will actually fix the test, or come close
to doing so.
---
 llvm/utils/lit/lit/LitConfig.py|  3 +++
 llvm/utils/lit/lit/TestRunner.py   | 12 
 llvm/utils/lit/lit/cl_arguments.py |  6 ++
 llvm/utils/lit/lit/llvm/config.py  |  5 +
 llvm/utils/lit/lit/main.py |  1 +
 5 files changed, 27 insertions(+)

diff --git a/llvm/utils/lit/lit/LitConfig.py b/llvm/utils/lit/lit/LitConfig.py
index 5dc712ae28370c..198a2bf3172330 100644
--- a/llvm/utils/lit/lit/LitConfig.py
+++ b/llvm/utils/lit/lit/LitConfig.py
@@ -38,6 +38,7 @@ def __init__(
 parallelism_groups={},
 per_test_coverage=False,
 gtest_sharding=True,
+update_tests=False,
 ):
 # The name of the test runner.
 self.progname = progname
@@ -89,6 +90,8 @@ def __init__(
 self.parallelism_groups = parallelism_groups
 self.per_test_coverage = per_test_coverage
 self.gtest_sharding = bool(gtest_sharding)
+self.update_tests = update_tests
+self.test_updaters = []
 
 @property
 def maxIndividualTestTime(self):
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index a1785073547ad0..7556433b83452c 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -1190,6 +1190,18 @@ def executeScriptInternal(
 str(result.timeoutReached),
 )
 
+if litConfig.update_tests:
+for test_updater in litConfig.test_updaters:
+try:
+update_output = test_updater(result)
+except Exception as e:
+out += f"Exception occurred in test updater: {e}"
+continue
+if update_output:
+for line in update_output.splitlines():
+out += f"# {line}\n"
+break
+
 return out, err, exitCode, timeoutInfo
 
 
diff --git a/llvm/utils/lit/lit/cl_arguments.py 
b/llvm/utils/lit/lit/cl_arguments.py
index ed78256ee414b4..dcbe553c6d4827 100644
--- a/llvm/utils/lit/lit/cl_arguments.py
+++ b/llvm/utils/lit/lit/cl_arguments.py
@@ -204,6 +204,12 @@ def parse_args():
 action="store_true",
 help="Exit with status zero even if some tests fail",
 )
+execution_group.add_argument(
+"--update-tests",
+dest="update_tests",
+action="store_true",
+help="Try to update regression tests to reflect current behavior, if 
possible",
+)
 execution_test_time_group = execution_group.add_mutually_exclusive_group()
 execution_test_time_group.add_argument(
 "--skip-test-time-recording",
diff --git a/llvm/utils/lit/lit/llvm/config.py 
b/llvm/utils/lit/lit/llvm/config.py
index 5f762ec7f3514a..c05ec1664d4c45 100644
--- a/llvm/utils/lit/lit/llvm/config.py
+++ b/llvm/utils/lit/lit/llvm/config.py
@@ -64,12 +64,17 @@ def __init__(self, lit_config, config):
 self.with_environment("_TAG_REDIR_ERR", "TXT")
 self.with_environment("_CEE_RUNOPTS", "FILETAG(AUTOCVT,AUTOTAG) 
POSIX(ON)")
 
+if lit_config.update_tests:
+self.use_lit_shell = True
+
 # Choose between lit's internal shell pipeline runner and a real shell.
 # If LIT_USE_INTERNAL_SHELL is in the environment, we use that as an
 # override.
 lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL")
 if lit_shell_env:
 self.use_lit_shell = lit.util.pythonize_bool(lit_shell_env)
+if not self.use_lit_shell and lit_config.update_tests:
+print("note: --update-tests is not supported when using 
external shell")
 
 if not self.use_lit_shell:
 features.add("shell")
diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py
index 24ba804f0c363f..745e376de7d529 100755
--- a/llvm/utils/lit/lit/main.py
+++ b/llvm/utils/lit/lit/main.py
@@ -42,6 +42,7 @@ def main(builtin_params={}):
 config_prefix=opts.configPrefix,
 per_test_coverage=opts.per_test_coverage,
 gtest_sharding=opts.gtest_sharding,
+update_tests=opts.update_tests,
 )
 
 discovered_tests = lit.discov

[clang-tools-extra] [clang-tidy] support string::contains (PR #110351)

2024-09-28 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank commented:

IMO no need to update release notes:

> Improved `readability-container-contains` check to let it work on any class 
> that has a contains method.

But I think an example should be added to [the check 
documentation](https://github.com/llvm/llvm-project/blob/6022a3a05f951632022c84416209fe6d70d9105c/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst).

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


[clang-tools-extra] [clang-tidy] support string::contains (PR #110351)

2024-09-28 Thread Nicolas van Kempen via cfe-commits


@@ -51,6 +53,12 @@ void ContainerContainsCheck::registerMatchers(MatchFinder 
*Finder) {
   const auto Literal0 = integerLiteral(equals(0));
   const auto Literal1 = integerLiteral(equals(1));
 
+  const auto StringLikeClass = cxxRecordDecl(
+  hasAnyName("::std::basic_string", "::std::basic_string_view",
+ "::absl::string_view"));

nicovank wrote:

I'm a fan of not hard-coding any classes when possible. IMO it's fine to match 
`npos` without checking the DeclContext, it's not a common name.

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


[clang-tools-extra] [clang-tidy] support string::contains (PR #110351)

2024-09-28 Thread Nicolas van Kempen via cfe-commits


@@ -29,6 +29,43 @@ struct multimap {
   bool contains(const Key &K) const;
 };
 
+using size_t = decltype(sizeof(int));
+
+// Lightweight standin for std::string_view.
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const basic_string_view &);
+  basic_string_view(const C *);
+  ~basic_string_view();
+  int find(basic_string_view s, int pos = 0);
+  int find(const C *s, int pos = 0);
+  int find(const C *s, int pos, int n);
+  int find(char c, int pos = 0);
+  static constexpr size_t npos = -1;
+};
+typedef basic_string_view string_view;
+
+// Lightweight standin for std::string.
+template 
+class basic_string {
+public:
+  basic_string();
+  basic_string(const basic_string &);
+  basic_string(const C *);
+  ~basic_string();
+  int find(basic_string s, int pos = 0);
+  int find(const C *s, int pos = 0);
+  int find(const C *s, int pos, int n);
+  int find(char c, int pos = 0);
+  bool contains(const C *s) const;
+  bool contains(C s) const;
+  bool contains(basic_string_view s) const;
+  static constexpr size_t npos = -1;
+};
+typedef basic_string string;
+

nicovank wrote:

There's [already a string mock you can 
import](https://github.com/llvm/llvm-project/blob/6022a3a05f951632022c84416209fe6d70d9105c/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string),
 you need to edit the `RUN` command at the top of this file to have it in the 
search path.

Check [here for an 
example](https://github.com/llvm/llvm-project/blob/6022a3a05f951632022c84416209fe6d70d9105c/clang-tools-extra/test/clang-tidy/checkers/modernize/use-starts-ends-with.cpp).

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


[clang-tools-extra] [clang-tidy] support string::contains (PR #110351)

2024-09-28 Thread Nicolas van Kempen via cfe-commits


@@ -453,3 +490,15 @@ void testOperandPermutations(std::map& Map) {
   // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check 
for membership [readability-container-contains]
   // CHECK-FIXES: if (!Map.contains(0)) {};
 }
+
+void testStringNops(std::string Str, std::string SubStr) {
+  if (Str.find("test") == std::string::npos) {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check 
for membership [readability-container-contains]
+  // CHECK-FIXES: if (!Str.contains("test")) {};
+
+  if (Str.find('c') != std::string::npos) {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check 
for membership [readability-container-contains]
+  // CHECK-FIXES: if (Str.contains('c')) {};
+  
+  if (Str.find(SubStr) != std::string::npos) {};
+}

nicovank wrote:

Add `string_view` tests, and tests comparing to `Str.npos` instead of 
`std::string::npos`.

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


[clang-tools-extra] [clang-tidy] support string::contains (PR #110351)

2024-09-28 Thread Nicolas van Kempen via cfe-commits


@@ -94,12 +102,14 @@ void ContainerContainsCheck::registerMatchers(MatchFinder 
*Finder) {
   binaryOperator(hasLHS(Literal1), hasOperatorName(">"), hasRHS(CountCall))
   .bind("negativeComparison"));
 
-  // Find membership tests based on `find() == end()`.
+  // Find membership tests based on `find() == end() or find() == npos`.

nicovank wrote:

```suggestion
  // Find membership tests based on `find() == end()` or `find() == npos`.
```

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


[clang-tools-extra] [clang-tidy] support string::contains (PR #110351)

2024-09-28 Thread Nicolas van Kempen via cfe-commits

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


[clang-tools-extra] [clang-tidy] support string::contains (PR #110351)

2024-09-28 Thread Nicolas van Kempen via cfe-commits


@@ -32,7 +33,8 @@ void ContainerContainsCheck::registerMatchers(MatchFinder 
*Finder) {
 
   const auto FindCall =
   cxxMemberCallExpr(
-  argumentCountIs(1),
+  anyOf(argumentCountIs(1),
+allOf(argumentCountIs(2), hasArgument(1, 
cxxDefaultArgExpr(,

nicovank wrote:

Maybe a comment here saying `std::string` and `std::string_view` take an 
optional `pos` argument on where to start the search. Also match 
`ignoringParenImpCasts(integerLiteral(0))`?

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


[clang-tools-extra] [clang-tidy][readability-container-contains] Fix matching of non-binaryOperator cases (PR #110386)

2024-09-28 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank created 
https://github.com/llvm/llvm-project/pull/110386


Fix #79437.

It works with non-mock `std::map`:
```
# All cases detailed in #79437.
> cat tmp.cpp
#include 
bool a(std::map &m, int key) { return m.find(key) != m.end(); }
bool b(std::map &m, int key) { return m.count(key) > 0; }
bool c(std::map &m, int key) { return m.find(key) == m.end(); }
bool d(std::map &m, int key) { return m.count(key) == 0; }
bool e(std::map *m, int key) { return m->find(key) != m->end(); }
bool f(std::map *m, int key) { return m->find(key) == m->end(); }
bool g(std::map *m, int key) { return m->count(key) > 0; }
bool h(std::map *m, int key) { return m->count(key) == 0; }

> ./build/bin/clang-tidy -checks="-*,readability-container-contains" tmp.cpp -- 
> -std=c++20
8 warnings generated.
tmp.cpp:2:51: warning: use 'contains' to check for membership 
[readability-container-contains]
2 | bool a(std::map &m, int key) { return m.find(key) != m.end(); 
}
  |   ^~~~  ~~
  |   contains
tmp.cpp:3:51: warning: use 'contains' to check for membership 
[readability-container-contains]
3 | bool b(std::map &m, int key) { return m.count(key) > 0; }
  |   ^  ~~~
  |   contains
tmp.cpp:4:51: warning: use 'contains' to check for membership 
[readability-container-contains]
4 | bool c(std::map &m, int key) { return m.find(key) == m.end(); 
}
  |   ^~~~  ~~
  | ! contains
tmp.cpp:5:51: warning: use 'contains' to check for membership 
[readability-container-contains]
5 | bool d(std::map &m, int key) { return m.count(key) == 0; }
  |   ^  
  | ! contains
tmp.cpp:6:52: warning: use 'contains' to check for membership 
[readability-container-contains]
6 | bool e(std::map *m, int key) { return m->find(key) != 
m->end(); }
  |^~~~  ~~~
  |contains
tmp.cpp:7:52: warning: use 'contains' to check for membership 
[readability-container-contains]
7 | bool f(std::map *m, int key) { return m->find(key) == 
m->end(); }
  |^~~~  ~~~
  | !  contains
tmp.cpp:8:52: warning: use 'contains' to check for membership 
[readability-container-contains]
8 | bool g(std::map *m, int key) { return m->count(key) > 0; }
  |^  ~~~
  |contains
tmp.cpp:9:52: warning: use 'contains' to check for membership 
[readability-container-contains]
9 | bool h(std::map *m, int key) { return m->count(key) == 0; }
  |^  
  | !  contains
```


>From 032b33e2ac080ac4a878d9d9ad947008f0eddac8 Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen 
Date: Sat, 28 Sep 2024 17:52:03 -0400
Subject: [PATCH] [clang-tidy][readability-container-contains] Fix matching of
 non-binaryOperator cases

Fix #79437.

It works with non-mock `std::map`:
```
# All cases detailed in #79437.
> cat tmp.cpp
#include 
bool a(std::map &m, int key) { return m.find(key) != m.end(); }
bool b(std::map &m, int key) { return m.count(key) > 0; }
bool c(std::map &m, int key) { return m.find(key) == m.end(); }
bool d(std::map &m, int key) { return m.count(key) == 0; }
bool e(std::map *m, int key) { return m->find(key) != m->end(); }
bool f(std::map *m, int key) { return m->find(key) == m->end(); }
bool g(std::map *m, int key) { return m->count(key) > 0; }
bool h(std::map *m, int key) { return m->count(key) == 0; }

> ./build/bin/clang-tidy -checks="-*,readability-container-contains" tmp.cpp -- 
> -std=c++20
8 warnings generated.
tmp.cpp:2:51: warning: use 'contains' to check for membership 
[readability-container-contains]
2 | bool a(std::map &m, int key) { return m.find(key) != m.end(); 
}
  |   ^~~~  ~~
  |   contains
tmp.cpp:3:51: warning: use 'contains' to check for membership 
[readability-container-contains]
3 | bool b(std::map &m, int key) { return m.count(key) > 0; }
  |   ^  ~~~
  |   contains
tmp.cpp:4:51: warning: use 'contains' to check for membership 
[readability-container-contains]
4 | bool c(std::

[clang-tools-extra] [clang-tidy][readability-container-contains] Fix matching of non-binaryOperator cases (PR #110386)

2024-09-28 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tidy

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

Author: Nicolas van Kempen (nicovank)


Changes


Fix #79437.

It works with non-mock `std::map`:
```
# All cases detailed in #79437.
> cat tmp.cpp
#include 
bool a(std::map &m, int key) { return m.find(key) != 
m.end(); }
bool b(std::map &m, int key) { return m.count(key) > 0; }
bool c(std::map &m, int key) { return m.find(key) == 
m.end(); }
bool d(std::map &m, int key) { return m.count(key) == 0; }
bool e(std::map *m, int key) { return m->find(key) != 
m->end(); }
bool f(std::map *m, int key) { return m->find(key) == 
m->end(); }
bool g(std::map *m, int key) { return m->count(key) > 0; }
bool h(std::map *m, int key) { return m->count(key) == 0; }

> ./build/bin/clang-tidy -checks="-*,readability-container-contains" tmp.cpp 
-- -std=c++20
8 warnings generated.
tmp.cpp:2:51: warning: use 'contains' to check for membership 
[readability-container-contains]
2 | bool a(std::map &m, int key) { return m.find(key) 
!= m.end(); }
  |   ^~~~  ~~
  |   contains
tmp.cpp:3:51: warning: use 'contains' to check for membership 
[readability-container-contains]
3 | bool b(std::map &m, int key) { return m.count(key) 
> 0; }
  |   ^  ~~~
  |   contains
tmp.cpp:4:51: warning: use 'contains' to check for membership 
[readability-container-contains]
4 | bool c(std::map &m, int key) { return m.find(key) 
== m.end(); }
  |   ^~~~  ~~
  | ! contains
tmp.cpp:5:51: warning: use 'contains' to check for membership 
[readability-container-contains]
5 | bool d(std::map &m, int key) { return m.count(key) 
== 0; }
  |   ^  
  | ! contains
tmp.cpp:6:52: warning: use 'contains' to check for membership 
[readability-container-contains]
6 | bool e(std::map *m, int key) { return m->find(key) 
!= m->end(); }
  |^~~~  ~~~
  |contains
tmp.cpp:7:52: warning: use 'contains' to check for membership 
[readability-container-contains]
7 | bool f(std::map *m, int key) { return m->find(key) 
== m->end(); }
  |^~~~  ~~~
  | !  contains
tmp.cpp:8:52: warning: use 'contains' to check for membership 
[readability-container-contains]
8 | bool g(std::map *m, int key) { return m->count(key) 
> 0; }
  |^  ~~~
  |contains
tmp.cpp:9:52: warning: use 'contains' to check for membership 
[readability-container-contains]
9 | bool h(std::map *m, int key) { return m->count(key) 
== 0; }
  |^  
  | !  contains
```


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


2 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp (+20-20) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp 
(+8-3) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
index 05d4c87bc73cef..fb68c7d334b7f8 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
@@ -62,44 +62,44 @@ void ContainerContainsCheck::registerMatchers(MatchFinder 
*Finder) {
  .bind("positiveComparison"),
  this);
   AddSimpleMatcher(
-  binaryOperator(hasOperatorName("!="), hasOperands(CountCall, Literal0))
+  binaryOperation(hasOperatorName("!="), hasOperands(CountCall, Literal0))
   .bind("positiveComparison"));
   AddSimpleMatcher(
-  binaryOperator(hasLHS(CountCall), hasOperatorName(">"), hasRHS(Literal0))
+  binaryOperation(hasLHS(CountCall), hasOperatorName(">"), 
hasRHS(Literal0))
   .bind("positiveComparison"));
   AddSimpleMatcher(
-  binaryOperator(hasLHS(Literal0), hasOperatorName("<"), hasRHS(CountCall))
-  .bind("positiveComparison"));
-  AddSimpleMatcher(
-  binaryOperator(hasLHS(CountCall), 

[clang] [clang] Fix the local parameter of void type inside the `Requires` expression. (PR #109831)

2024-09-28 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

Same then, go ahead, but please make sure the error handling strategies don't 
diverge unnecessarily.

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


[clang] [clang] Redeclare function templates instances per primary template (PR #110387)

2024-09-28 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/110387

This fixes handling of friend function templates instances when their template 
context changes, such as when a new friend declaration is introduced after an 
instance was already created from a previous declaration.

Instead of producing one function template instance per primary template, this 
patch makes it so clang produces one instance per primary template 
redeclaration, tracking this new instance as a redeclation of the previous 
instance.

Fixes #55509

>From 362444a8fbb1c264409fc19bb80159142f8a3887 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sat, 28 Sep 2024 14:28:58 -0300
Subject: [PATCH] [clang] Redeclare function templates instances per primary
 template

This fixes handling of friend function templates instances when
their template context changes, such as when a new friend declaration
is introduced after an instance was already created from a previous
declaration.

Instead of producing one function template instance per primary template,
this patch makes it so clang produces one instance per primary template
redeclaration, tracking this new instance as a redeclation of the
previous instance.

Fixes #55509
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/Sema/SemaDecl.cpp   | 19 +++--
 clang/lib/Sema/SemaDeclCXX.cpp|  3 +
 clang/lib/Sema/SemaTemplate.cpp   | 23 ++---
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 19 +
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 15 +++-
 clang/test/SemaTemplate/GH55509.cpp   | 84 +++
 7 files changed, 129 insertions(+), 35 deletions(-)
 create mode 100644 clang/test/SemaTemplate/GH55509.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2e9560f553d94f..d4c80054dfefde 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -446,6 +446,7 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure in debug mode, and potential crashes in release 
mode, when
   diagnosing a failed cast caused indirectly by a failed implicit conversion 
to the type of the constructor parameter.
 - Fixed an assertion failure by adjusting integral to boolean vector 
conversions (#GH108326)
+- Clang is now better at keeping track of friend function template instance 
contexts. (#GH55509)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 1bf0e800a36228..b3909c7c96d631 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3150,7 +3150,13 @@ void Sema::mergeDeclAttributes(NamedDecl *New, Decl *Old,
 
   // Re-declaration cannot add abi_tag's.
   if (const auto *NewAbiTagAttr = New->getAttr()) {
-if (const auto *OldAbiTagAttr = Old->getAttr()) {
+const AbiTagAttr *OldAbiTagAttr = nullptr;
+for (auto *D = Old; D; D = D->getPreviousDecl()) {
+  OldAbiTagAttr = D->getAttr();
+  if (OldAbiTagAttr)
+break;
+}
+if (OldAbiTagAttr) {
   for (const auto &NewTag : NewAbiTagAttr->tags()) {
 if (!llvm::is_contained(OldAbiTagAttr->tags(), NewTag)) {
   Diag(NewAbiTagAttr->getLocation(),
@@ -12021,11 +12027,12 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 
 } else {
   if (shouldLinkDependentDeclWithPrevious(NewFD, OldDecl)) {
-auto *OldFD = cast(OldDecl);
-// This needs to happen first so that 'inline' propagates.
-NewFD->setPreviousDeclaration(OldFD);
-if (NewFD->isCXXClassMember())
-  NewFD->setAccess(OldFD->getAccess());
+if (auto *OldFD = cast(OldDecl); OldFD != NewFD) {
+  // This needs to happen first so that 'inline' propagates.
+  NewFD->setPreviousDeclaration(OldFD);
+  if (NewFD->isCXXClassMember())
+NewFD->setAccess(OldFD->getAccess());
+}
   }
 }
   } else if (!getLangOpts().CPlusPlus && MayNeedOverloadableChecks &&
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index d8cdfcf8c6ec05..aa881b535e4ee0 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -491,6 +491,9 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, 
FunctionDecl *Old,
   continue;
 }
 
+if (PrevForDefaultArgs->getPrimaryTemplate() != New->getPrimaryTemplate())
+  continue;
+
 // We found the right previous declaration.
 break;
   }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 99423b01114cc6..6e94831bcb2d38 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -9272,16 +9272,19 @@ bool Sema::CheckFunctionTemplateSpecialization(
 MarkUnusedFileScopedDecl(Specialization);
   }
 
-  // Turn the given function declaration into a function template
-  // specialization, with the template arguments from the previous
-  // specialization

[clang] [clang] Redeclare function templates instances per primary template (PR #110387)

2024-09-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

This fixes handling of friend function templates instances when their template 
context changes, such as when a new friend declaration is introduced after an 
instance was already created from a previous declaration.

Instead of producing one function template instance per primary template, this 
patch makes it so clang produces one instance per primary template 
redeclaration, tracking this new instance as a redeclation of the previous 
instance.

Fixes #55509

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


7 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+13-6) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+3) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+13-10) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+3-16) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+12-3) 
- (added) clang/test/SemaTemplate/GH55509.cpp (+84) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2e9560f553d94f..d4c80054dfefde 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -446,6 +446,7 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure in debug mode, and potential crashes in release 
mode, when
   diagnosing a failed cast caused indirectly by a failed implicit conversion 
to the type of the constructor parameter.
 - Fixed an assertion failure by adjusting integral to boolean vector 
conversions (#GH108326)
+- Clang is now better at keeping track of friend function template instance 
contexts. (#GH55509)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 1bf0e800a36228..b3909c7c96d631 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3150,7 +3150,13 @@ void Sema::mergeDeclAttributes(NamedDecl *New, Decl *Old,
 
   // Re-declaration cannot add abi_tag's.
   if (const auto *NewAbiTagAttr = New->getAttr()) {
-if (const auto *OldAbiTagAttr = Old->getAttr()) {
+const AbiTagAttr *OldAbiTagAttr = nullptr;
+for (auto *D = Old; D; D = D->getPreviousDecl()) {
+  OldAbiTagAttr = D->getAttr();
+  if (OldAbiTagAttr)
+break;
+}
+if (OldAbiTagAttr) {
   for (const auto &NewTag : NewAbiTagAttr->tags()) {
 if (!llvm::is_contained(OldAbiTagAttr->tags(), NewTag)) {
   Diag(NewAbiTagAttr->getLocation(),
@@ -12021,11 +12027,12 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 
 } else {
   if (shouldLinkDependentDeclWithPrevious(NewFD, OldDecl)) {
-auto *OldFD = cast(OldDecl);
-// This needs to happen first so that 'inline' propagates.
-NewFD->setPreviousDeclaration(OldFD);
-if (NewFD->isCXXClassMember())
-  NewFD->setAccess(OldFD->getAccess());
+if (auto *OldFD = cast(OldDecl); OldFD != NewFD) {
+  // This needs to happen first so that 'inline' propagates.
+  NewFD->setPreviousDeclaration(OldFD);
+  if (NewFD->isCXXClassMember())
+NewFD->setAccess(OldFD->getAccess());
+}
   }
 }
   } else if (!getLangOpts().CPlusPlus && MayNeedOverloadableChecks &&
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index d8cdfcf8c6ec05..aa881b535e4ee0 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -491,6 +491,9 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, 
FunctionDecl *Old,
   continue;
 }
 
+if (PrevForDefaultArgs->getPrimaryTemplate() != New->getPrimaryTemplate())
+  continue;
+
 // We found the right previous declaration.
 break;
   }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 99423b01114cc6..6e94831bcb2d38 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -9272,16 +9272,19 @@ bool Sema::CheckFunctionTemplateSpecialization(
 MarkUnusedFileScopedDecl(Specialization);
   }
 
-  // Turn the given function declaration into a function template
-  // specialization, with the template arguments from the previous
-  // specialization.
-  // Take copies of (semantic and syntactic) template argument lists.
-  TemplateArgumentList *TemplArgs = TemplateArgumentList::CreateCopy(
-  Context, Specialization->getTemplateSpecializationArgs()->asArray());
-  FD->setFunctionTemplateSpecialization(
-  Specialization->getPrimaryTemplate(), TemplArgs, /*InsertPos=*/nullptr,
-  SpecInfo->getTemplateSpecializationKind(),
-  ExplicitTemplateArgs ? &ConvertedTemplateArgs[Specialization] : nullptr);
+  if (FD != Specialization) {
+// Turn the given function declaration into a function template
+// specialization, with the template arguments from the previous
+// specialization.
+// Take copies of (semantic and sy

[clang] [Clang] GH93099 (PR #110238)

2024-09-28 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/110238

>From 23a765ac6d8e455121346405332d2066dcc0861e Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 27 Sep 2024 18:23:47 +0800
Subject: [PATCH 1/4] [Clang] GH93099

---
 clang/include/clang/Sema/Sema.h   |  4 ++-
 clang/lib/Sema/SemaTemplateVariadic.cpp   | 20 +++
 clang/lib/Sema/TreeTransform.h| 16 ++---
 .../SemaTemplate/concepts-out-of-line-def.cpp | 34 +++
 4 files changed, 61 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e1c3a99cfa167e..1fce74880026ce 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14264,7 +14264,9 @@ class Sema final : public SemaBase {
   ///
   /// This is intended for use when transforming 'sizeof...(Arg)' in order to
   /// avoid actually expanding the pack where possible.
-  std::optional getFullyPackExpandedSize(TemplateArgument Arg);
+  std::optional
+  getFullyPackExpandedSize(TemplateArgument Arg,
+   const NamedDecl *&ParameterPack);
 
   /// Called when an expression computing the size of a parameter pack
   /// is parsed.
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 40522a07f6339c..79e2f1f610b11f 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1211,7 +1211,9 @@ TemplateArgumentLoc 
Sema::getTemplateArgumentPackExpansionPattern(
   llvm_unreachable("Invalid TemplateArgument Kind!");
 }
 
-std::optional Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
+std::optional
+Sema::getFullyPackExpandedSize(TemplateArgument Arg,
+   const NamedDecl *&ParameterPack) {
   assert(Arg.containsUnexpandedParameterPack());
 
   // If this is a substituted pack, grab that pack. If not, we don't know
@@ -1222,17 +1224,20 @@ std::optional 
Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
   TemplateArgument Pack;
   switch (Arg.getKind()) {
   case TemplateArgument::Type:
-if (auto *Subst = Arg.getAsType()->getAs())
+if (auto *Subst = Arg.getAsType()->getAs()) 
{
   Pack = Subst->getArgumentPack();
-else
+  ParameterPack = Subst->getReplacedParameter();
+} else
   return std::nullopt;
 break;
 
   case TemplateArgument::Expression:
 if (auto *Subst =
-dyn_cast(Arg.getAsExpr()))
+dyn_cast(Arg.getAsExpr())) {
   Pack = Subst->getArgumentPack();
-else if (auto *Subst = dyn_cast(Arg.getAsExpr()))  {
+  ParameterPack = Subst->getParameterPack();
+} else if (auto *Subst = dyn_cast(Arg.getAsExpr())) {
+  ParameterPack = Subst->getParameterPack();
   for (VarDecl *PD : *Subst)
 if (PD->isParameterPack())
   return std::nullopt;
@@ -1243,9 +1248,10 @@ std::optional 
Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
 
   case TemplateArgument::Template:
 if (SubstTemplateTemplateParmPackStorage *Subst =
-Arg.getAsTemplate().getAsSubstTemplateTemplateParmPack())
+Arg.getAsTemplate().getAsSubstTemplateTemplateParmPack()) {
   Pack = Subst->getArgumentPack();
-else
+  ParameterPack = Subst->getParameterPack();
+} else
   return std::nullopt;
 break;
 
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 91cb980ee26b26..3a029e88e865df 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -15237,6 +15237,7 @@ 
TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
 
   // Try to compute the result without performing a partial substitution.
   std::optional Result = 0;
+  NamedDecl *NewPack = E->getPack();
   for (const TemplateArgument &Arg : PackArgs) {
 if (!Arg.isPackExpansion()) {
   Result = *Result + 1;
@@ -15260,9 +15261,14 @@ 
TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
/*Uneval*/ true))
   return true;
 
+const NamedDecl *TransformedParameterPack = nullptr;
 // See if we can determine the number of arguments from the result.
-std::optional NumExpansions =
-getSema().getFullyPackExpandedSize(OutPattern.getArgument());
+std::optional NumExpansions = getSema().getFullyPackExpandedSize(
+OutPattern.getArgument(), TransformedParameterPack);
+if (TransformedParameterPack && !E->isPartiallySubstituted()) {
+  assert(PackArgs.size() == 1);
+  NewPack = const_cast(TransformedParameterPack);
+}
 if (!NumExpansions) {
   // No: we must be in an alias template expansion, and we're going to need
   // to actually expand the packs.
@@ -15277,7 +15283,7 @@ 
TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
   // substituting.
   if (Result)
 return getDerived().RebuildSizeOfPackExpr(
-E->getOperatorLoc(), E->getPa

[clang] 29d0a84 - [clang][CGOpenMPRuntimeGPU] Avoid llvm::Type::getPointerTo() (NFC) (#110357)

2024-09-28 Thread via cfe-commits

Author: Youngsuk Kim
Date: 2024-09-28T09:57:20-04:00
New Revision: 29d0a8470426a8518da28c3e90ef884ad07f200a

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

LOG: [clang][CGOpenMPRuntimeGPU] Avoid llvm::Type::getPointerTo() (NFC) 
(#110357)

`llvm::Type::getPointerTo()` is to be removed soon.

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 9e095a37552196..c920d93957b16e 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1073,9 +1073,8 @@ void 
CGOpenMPRuntimeGPU::emitGenericVarsProlog(CodeGenFunction &CGF,
 CGM.getContext().getTargetInfo().getNewAlign() / 8));
 
 // Cast the void pointer and get the address of the globalized variable.
-llvm::PointerType *VarPtrTy = CGF.ConvertTypeForMem(VarTy)->getPointerTo();
 llvm::Value *CastedVoidPtr = Bld.CreatePointerBitCastOrAddrSpaceCast(
-VoidPtr, VarPtrTy, VD->getName() + "_on_stack");
+VoidPtr, Bld.getPtrTy(0), VD->getName() + "_on_stack");
 LValue VarAddr =
 CGF.MakeNaturalAlignPointeeRawAddrLValue(CastedVoidPtr, VarTy);
 Rec.second.PrivateAddr = VarAddr.getAddress();
@@ -1930,7 +1929,7 @@ llvm::Function 
*CGOpenMPRuntimeGPU::createParallelDataSharingWrapper(
   if (isOpenMPLoopBoundSharingDirective(D.getDirectiveKind())) {
 Address Src = Bld.CreateConstInBoundsGEP(SharedArgListAddress, Idx);
 Address TypedAddress = Bld.CreatePointerBitCastOrAddrSpaceCast(
-Src, CGF.SizeTy->getPointerTo(), CGF.SizeTy);
+Src, Bld.getPtrTy(0), CGF.SizeTy);
 llvm::Value *LB = CGF.EmitLoadOfScalar(
 TypedAddress,
 /*Volatile=*/false,
@@ -1939,8 +1938,8 @@ llvm::Function 
*CGOpenMPRuntimeGPU::createParallelDataSharingWrapper(
 Args.emplace_back(LB);
 ++Idx;
 Src = Bld.CreateConstInBoundsGEP(SharedArgListAddress, Idx);
-TypedAddress = Bld.CreatePointerBitCastOrAddrSpaceCast(
-Src, CGF.SizeTy->getPointerTo(), CGF.SizeTy);
+TypedAddress = Bld.CreatePointerBitCastOrAddrSpaceCast(Src, 
Bld.getPtrTy(0),
+   CGF.SizeTy);
 llvm::Value *UB = CGF.EmitLoadOfScalar(
 TypedAddress,
 /*Volatile=*/false,
@@ -2079,7 +2078,7 @@ Address 
CGOpenMPRuntimeGPU::getAddressOfLocalVariable(CodeGenFunction &CGF,
 GV->setAlignment(Align.getAsAlign());
 return Address(
 CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-GV, VarTy->getPointerTo(CGM.getContext().getTargetAddressSpace(
+GV, CGF.Builder.getPtrTy(CGM.getContext().getTargetAddressSpace(
 VD->getType().getAddressSpace(,
 VarTy, Align);
   }



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


[clang] [clang][CGOpenMPRuntimeGPU] Avoid llvm::Type::getPointerTo() (NFC) (PR #110357)

2024-09-28 Thread Youngsuk Kim via cfe-commits

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


[clang] [Clang] GH93099 (PR #110238)

2024-09-28 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/110238

>From 23a765ac6d8e455121346405332d2066dcc0861e Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 27 Sep 2024 18:23:47 +0800
Subject: [PATCH 1/5] [Clang] GH93099

---
 clang/include/clang/Sema/Sema.h   |  4 ++-
 clang/lib/Sema/SemaTemplateVariadic.cpp   | 20 +++
 clang/lib/Sema/TreeTransform.h| 16 ++---
 .../SemaTemplate/concepts-out-of-line-def.cpp | 34 +++
 4 files changed, 61 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e1c3a99cfa167e..1fce74880026ce 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14264,7 +14264,9 @@ class Sema final : public SemaBase {
   ///
   /// This is intended for use when transforming 'sizeof...(Arg)' in order to
   /// avoid actually expanding the pack where possible.
-  std::optional getFullyPackExpandedSize(TemplateArgument Arg);
+  std::optional
+  getFullyPackExpandedSize(TemplateArgument Arg,
+   const NamedDecl *&ParameterPack);
 
   /// Called when an expression computing the size of a parameter pack
   /// is parsed.
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 40522a07f6339c..79e2f1f610b11f 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1211,7 +1211,9 @@ TemplateArgumentLoc 
Sema::getTemplateArgumentPackExpansionPattern(
   llvm_unreachable("Invalid TemplateArgument Kind!");
 }
 
-std::optional Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
+std::optional
+Sema::getFullyPackExpandedSize(TemplateArgument Arg,
+   const NamedDecl *&ParameterPack) {
   assert(Arg.containsUnexpandedParameterPack());
 
   // If this is a substituted pack, grab that pack. If not, we don't know
@@ -1222,17 +1224,20 @@ std::optional 
Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
   TemplateArgument Pack;
   switch (Arg.getKind()) {
   case TemplateArgument::Type:
-if (auto *Subst = Arg.getAsType()->getAs())
+if (auto *Subst = Arg.getAsType()->getAs()) 
{
   Pack = Subst->getArgumentPack();
-else
+  ParameterPack = Subst->getReplacedParameter();
+} else
   return std::nullopt;
 break;
 
   case TemplateArgument::Expression:
 if (auto *Subst =
-dyn_cast(Arg.getAsExpr()))
+dyn_cast(Arg.getAsExpr())) {
   Pack = Subst->getArgumentPack();
-else if (auto *Subst = dyn_cast(Arg.getAsExpr()))  {
+  ParameterPack = Subst->getParameterPack();
+} else if (auto *Subst = dyn_cast(Arg.getAsExpr())) {
+  ParameterPack = Subst->getParameterPack();
   for (VarDecl *PD : *Subst)
 if (PD->isParameterPack())
   return std::nullopt;
@@ -1243,9 +1248,10 @@ std::optional 
Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
 
   case TemplateArgument::Template:
 if (SubstTemplateTemplateParmPackStorage *Subst =
-Arg.getAsTemplate().getAsSubstTemplateTemplateParmPack())
+Arg.getAsTemplate().getAsSubstTemplateTemplateParmPack()) {
   Pack = Subst->getArgumentPack();
-else
+  ParameterPack = Subst->getParameterPack();
+} else
   return std::nullopt;
 break;
 
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 91cb980ee26b26..3a029e88e865df 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -15237,6 +15237,7 @@ 
TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
 
   // Try to compute the result without performing a partial substitution.
   std::optional Result = 0;
+  NamedDecl *NewPack = E->getPack();
   for (const TemplateArgument &Arg : PackArgs) {
 if (!Arg.isPackExpansion()) {
   Result = *Result + 1;
@@ -15260,9 +15261,14 @@ 
TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
/*Uneval*/ true))
   return true;
 
+const NamedDecl *TransformedParameterPack = nullptr;
 // See if we can determine the number of arguments from the result.
-std::optional NumExpansions =
-getSema().getFullyPackExpandedSize(OutPattern.getArgument());
+std::optional NumExpansions = getSema().getFullyPackExpandedSize(
+OutPattern.getArgument(), TransformedParameterPack);
+if (TransformedParameterPack && !E->isPartiallySubstituted()) {
+  assert(PackArgs.size() == 1);
+  NewPack = const_cast(TransformedParameterPack);
+}
 if (!NumExpansions) {
   // No: we must be in an alias template expansion, and we're going to need
   // to actually expand the packs.
@@ -15277,7 +15283,7 @@ 
TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
   // substituting.
   if (Result)
 return getDerived().RebuildSizeOfPackExpr(
-E->getOperatorLoc(), E->getPa

[clang] [NFC] Correct the misuse of the API in the Clang test-report script. (PR #108725)

2024-09-28 Thread Tobias Hieta via cfe-commits

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

LGTM

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


[clang] [analyzer] Model overflow builtins (PR #102602)

2024-09-28 Thread Pavel Skripkin via cfe-commits

pskrgag wrote:

gentle ping 

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


[clang] 6b62e04 - [clang][bytecode] Implement (N)EQ between fixed point and integral (#110358)

2024-09-28 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-09-28T15:38:33+02:00
New Revision: 6b62e04e3045e5d8f4361afc100a460622266f82

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

LOG: [clang][bytecode] Implement (N)EQ between fixed point and integral 
(#110358)

Convert the non-fixed-point side to a fixed-point type before doing the
comparison.

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp
clang/lib/AST/ByteCode/Compiler.h
clang/test/AST/ByteCode/fixed-point.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 8875fc05d24bee..a80d973056db43 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -773,6 +773,8 @@ bool Compiler::VisitBinaryOperator(const 
BinaryOperator *BO) {
RHS->getType()->isAnyComplexType()) &&
   BO->isComparisonOp())
 return this->emitComplexComparison(LHS, RHS, BO);
+  if (LHS->getType()->isFixedPointType() || RHS->getType()->isFixedPointType())
+return this->VisitFixedPointBinOp(BO);
 
   if (BO->isPtrMemOp()) {
 if (!this->visit(LHS))
@@ -1469,6 +1471,55 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   return true;
 }
 
+template 
+bool Compiler::VisitFixedPointBinOp(const BinaryOperator *E) {
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+
+  assert(LHS->getType()->isFixedPointType() ||
+ RHS->getType()->isFixedPointType());
+
+  if (!this->visit(LHS))
+return false;
+  if (!LHS->getType()->isFixedPointType()) {
+auto Sem = Ctx.getASTContext().getFixedPointSemantics(LHS->getType());
+uint32_t I;
+std::memcpy(&I, &Sem, sizeof(Sem));
+if (!this->emitCastIntegralFixedPoint(classifyPrim(LHS->getType()), I, E))
+  return false;
+  }
+  if (!this->visit(RHS))
+return false;
+  if (!RHS->getType()->isFixedPointType()) {
+auto Sem = Ctx.getASTContext().getFixedPointSemantics(RHS->getType());
+uint32_t I;
+std::memcpy(&I, &Sem, sizeof(Sem));
+if (!this->emitCastIntegralFixedPoint(classifyPrim(RHS->getType()), I, E))
+  return false;
+  }
+
+  switch (E->getOpcode()) {
+  case BO_EQ:
+return this->emitEQFixedPoint(E);
+  case BO_NE:
+return this->emitNEFixedPoint(E);
+#if 0
+  case BO_LT:
+return this->emitLTFixedPoint(E);
+  case BO_LE:
+return this->emitLEFixedPoint(E);
+  case BO_GT:
+return this->emitGTFixedPoint(E);
+  case BO_GE:
+return this->emitGEFixedPoint(E);
+#endif
+  default:
+return this->emitInvalid(E);
+  }
+
+  llvm_unreachable("unhandled binop opcode");
+}
+
 template 
 bool Compiler::VisitImplicitValueInitExpr(
 const ImplicitValueInitExpr *E) {

diff  --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index d1911f11603a08..5349b184572b6e 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -132,6 +132,7 @@ class Compiler : public ConstStmtVisitor, 
bool>,
   bool VisitPointerArithBinOp(const BinaryOperator *E);
   bool VisitComplexBinOp(const BinaryOperator *E);
   bool VisitVectorBinOp(const BinaryOperator *E);
+  bool VisitFixedPointBinOp(const BinaryOperator *E);
   bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E);
   bool VisitCallExpr(const CallExpr *E);
   bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID);

diff  --git a/clang/test/AST/ByteCode/fixed-point.cpp 
b/clang/test/AST/ByteCode/fixed-point.cpp
index 77000c08918256..51ea166748730c 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -6,17 +6,22 @@ static_assert(!((bool)0.0k));
 static_assert((bool)0.0k); // both-error {{static assertion failed}}
 
 static_assert(1.0k == 1.0k);
+static_assert(1.0k == 1);
 static_assert(1.0k != 1.0k); // both-error {{failed due to requirement '1.0k 
!= 1.0k'}}
+static_assert(1.0k != 1); // both-error {{failed due to requirement '1.0k != 
1'}}
 static_assert(-12.0k == -(-(-12.0k)));
 
 /// Zero-init.
 constexpr _Accum A{};
 static_assert(A == 0.0k);
+static_assert(A == 0);
 
 namespace IntToFixedPointCast {
   constexpr _Accum B = 13;
   static_assert(B == 13.0k);
+  static_assert(B == 13);
 
   constexpr _Fract sf = -1;
   static_assert(sf == -1.0k);
+  static_assert(sf == -1);
 }



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


[clang] [clang][bytecode] Implement (N)EQ between fixed point and integral (PR #110358)

2024-09-28 Thread Timm Baeder via cfe-commits

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


[clang-tools-extra] [clang-tidy][NFC] optimize unused using decls performance (PR #110200)

2024-09-28 Thread Congcong Cai via cfe-commits


@@ -25,6 +25,13 @@ AST_MATCHER_P(DeducedTemplateSpecializationType, 
refsToTemplatedDecl,
   return false;
 }
 
+AST_MATCHER_P(Type, getTagDecl, 
clang::ast_matchers::internal::Matcher,
+  DeclMatcher) {
+  if (const auto *ND = Node.getAsTagDecl())

HerrCai0907 wrote:

```suggestion
  if (const TagDecl *ND = Node.getAsTagDecl())
```

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


[clang] [clang][CGOpenMPRuntimeGPU] Avoid llvm::Type::getPointerTo() (NFC) (PR #110357)

2024-09-28 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building 
`clang` at step 10 "Add check check-offload".

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


Here is the relevant piece of the build log for the reference

```
Step 10 (Add check check-offload) failure: test (failure)
 TEST 'libomptarget :: amdgcn-amd-amdhsa :: 
sanitizer/kernel_crash_async.c' FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp-I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test 
-I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib
  -fopenmp-targets=amdgcn-amd-amdhsa -O3 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 -o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 -Xoffload-linker -lc -Xoffload-linker -lm 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test 
-I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib
 -fopenmp-targets=amdgcn-amd-amdhsa -O3 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 -o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 -Xoffload-linker -lc -Xoffload-linker -lm 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# RUN: at line 3
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/not 
--crash env -u LLVM_DISABLE_SYMBOLIZATION 
OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 2>&1 | 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck
 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=TRACE
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/not 
--crash env -u LLVM_DISABLE_SYMBOLIZATION 
OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck
 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=TRACE
# RUN: at line 4
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/not 
--crash 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 2>&1 | 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck
 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=

[clang] [Clang] GH93099 (PR #110238)

2024-09-28 Thread Younan Zhang via cfe-commits

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


[clang] [Clang] GH93099 (PR #110238)

2024-09-28 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

The CI failure looks unrelated - it also *failed* in other PRs e.g.

https://buildkite.com/llvm-project/github-pull-requests/builds/104957#019238e6-fd32-40a1-987a-4cd1c539926a

(Which happens to fail in `std::common_type` that might have connections with 
the `sizeof...` expression)

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


[clang] [Clang] GH93099 (PR #110238)

2024-09-28 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/110238

>From 23a765ac6d8e455121346405332d2066dcc0861e Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 27 Sep 2024 18:23:47 +0800
Subject: [PATCH 1/6] [Clang] GH93099

---
 clang/include/clang/Sema/Sema.h   |  4 ++-
 clang/lib/Sema/SemaTemplateVariadic.cpp   | 20 +++
 clang/lib/Sema/TreeTransform.h| 16 ++---
 .../SemaTemplate/concepts-out-of-line-def.cpp | 34 +++
 4 files changed, 61 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e1c3a99cfa167e..1fce74880026ce 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14264,7 +14264,9 @@ class Sema final : public SemaBase {
   ///
   /// This is intended for use when transforming 'sizeof...(Arg)' in order to
   /// avoid actually expanding the pack where possible.
-  std::optional getFullyPackExpandedSize(TemplateArgument Arg);
+  std::optional
+  getFullyPackExpandedSize(TemplateArgument Arg,
+   const NamedDecl *&ParameterPack);
 
   /// Called when an expression computing the size of a parameter pack
   /// is parsed.
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 40522a07f6339c..79e2f1f610b11f 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1211,7 +1211,9 @@ TemplateArgumentLoc 
Sema::getTemplateArgumentPackExpansionPattern(
   llvm_unreachable("Invalid TemplateArgument Kind!");
 }
 
-std::optional Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
+std::optional
+Sema::getFullyPackExpandedSize(TemplateArgument Arg,
+   const NamedDecl *&ParameterPack) {
   assert(Arg.containsUnexpandedParameterPack());
 
   // If this is a substituted pack, grab that pack. If not, we don't know
@@ -1222,17 +1224,20 @@ std::optional 
Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
   TemplateArgument Pack;
   switch (Arg.getKind()) {
   case TemplateArgument::Type:
-if (auto *Subst = Arg.getAsType()->getAs())
+if (auto *Subst = Arg.getAsType()->getAs()) 
{
   Pack = Subst->getArgumentPack();
-else
+  ParameterPack = Subst->getReplacedParameter();
+} else
   return std::nullopt;
 break;
 
   case TemplateArgument::Expression:
 if (auto *Subst =
-dyn_cast(Arg.getAsExpr()))
+dyn_cast(Arg.getAsExpr())) {
   Pack = Subst->getArgumentPack();
-else if (auto *Subst = dyn_cast(Arg.getAsExpr()))  {
+  ParameterPack = Subst->getParameterPack();
+} else if (auto *Subst = dyn_cast(Arg.getAsExpr())) {
+  ParameterPack = Subst->getParameterPack();
   for (VarDecl *PD : *Subst)
 if (PD->isParameterPack())
   return std::nullopt;
@@ -1243,9 +1248,10 @@ std::optional 
Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
 
   case TemplateArgument::Template:
 if (SubstTemplateTemplateParmPackStorage *Subst =
-Arg.getAsTemplate().getAsSubstTemplateTemplateParmPack())
+Arg.getAsTemplate().getAsSubstTemplateTemplateParmPack()) {
   Pack = Subst->getArgumentPack();
-else
+  ParameterPack = Subst->getParameterPack();
+} else
   return std::nullopt;
 break;
 
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 91cb980ee26b26..3a029e88e865df 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -15237,6 +15237,7 @@ 
TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
 
   // Try to compute the result without performing a partial substitution.
   std::optional Result = 0;
+  NamedDecl *NewPack = E->getPack();
   for (const TemplateArgument &Arg : PackArgs) {
 if (!Arg.isPackExpansion()) {
   Result = *Result + 1;
@@ -15260,9 +15261,14 @@ 
TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
/*Uneval*/ true))
   return true;
 
+const NamedDecl *TransformedParameterPack = nullptr;
 // See if we can determine the number of arguments from the result.
-std::optional NumExpansions =
-getSema().getFullyPackExpandedSize(OutPattern.getArgument());
+std::optional NumExpansions = getSema().getFullyPackExpandedSize(
+OutPattern.getArgument(), TransformedParameterPack);
+if (TransformedParameterPack && !E->isPartiallySubstituted()) {
+  assert(PackArgs.size() == 1);
+  NewPack = const_cast(TransformedParameterPack);
+}
 if (!NumExpansions) {
   // No: we must be in an alias template expansion, and we're going to need
   // to actually expand the packs.
@@ -15277,7 +15283,7 @@ 
TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
   // substituting.
   if (Result)
 return getDerived().RebuildSizeOfPackExpr(
-E->getOperatorLoc(), E->getPa

[clang] [Clang][Concepts] Normalize SizeOfPackExpr's pack declaration (PR #110238)

2024-09-28 Thread Younan Zhang via cfe-commits

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


[clang] [Clang][Concepts] Normalize SizeOfPackExpr's pack declaration (PR #110238)

2024-09-28 Thread Younan Zhang via cfe-commits

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


[clang] [Clang][Concepts] Normalize SizeOfPackExpr's pack declaration (PR #110238)

2024-09-28 Thread Younan Zhang via cfe-commits

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


[clang] [Clang][Concepts] Normalize SizeOfPackExpr's pack declaration (PR #110238)

2024-09-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

SizeOfPackExpr has a pointer to the referenced pack declaration, which is left 
as-is during the transformation process.

The situation could be subtle when a friend class template declaration comes 
into play. The declaration per se would be instantiated into its parent 
declaration context, and consequently, the template parameter list would have a 
depth adjustment; however, as we don't evaluate constraints during 
instantiation, those constraints would still reference the original template 
parameters, which is fine for constraint evaluation because we have handled 
friend cases in the template argument collection.

However, things are different when we want to profile the constraint expression 
with dependent template arguments. The hash algorithm of SizeOfPackExpr takes 
its pack declaration as a factor, which is the original template parameter that 
might still have untransformed template depths after the constraint 
normalization.

This patch transforms the pack declaration when normalizing constraint 
expressions and pluses a fix in HandleFunctionTemplateDecl() where the 
associated declaration is incorrect for nested specifiers.

Note that the fix in HandleFunctionTemplateDecl(), as well as the handling 
logic for NestedNameSpecifier, would be removed once Krystian's refactoring 
patch lands. But I still want to incorporate it in the patch for the correction 
purpose, though it hasn't caused any problems so far - I just tripped over that 
in getFullyPackExpandedSize() when I tried to extract the transformed 
declarations from the TemplateArgument.

Fixes #93099 

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


5 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/AST/ExprCXX.h (+2) 
- (modified) clang/lib/Sema/SemaConcept.cpp (+9-5) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+27-1) 
- (modified) clang/test/SemaTemplate/concepts-out-of-line-def.cpp (+34) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1fbcac807d0b30..831dab0657fcaf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -444,6 +444,8 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure in debug mode, and potential crashes in release 
mode, when
   diagnosing a failed cast caused indirectly by a failed implicit conversion 
to the type of the constructor parameter.
 - Fixed an assertion failure by adjusting integral to boolean vector 
conversions (#GH108326)
+- Fixed a bug in constraint expression comparison where the ``sizeof...`` 
expression was not handled properly
+  in certain friend declarations. (#GH93099)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 975bcdac5069b9..dfcf739ed1614f 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -4326,6 +4326,8 @@ class SizeOfPackExpr final
   /// Retrieve the parameter pack.
   NamedDecl *getPack() const { return Pack; }
 
+  void setPack(NamedDecl *NewPack) { Pack = NewPack; }
+
   /// Retrieve the length of the parameter pack.
   ///
   /// This routine may only be invoked when the expression is not
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 6a1b32598bb4a6..67fc603e9ce1d5 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -975,11 +975,14 @@ static const Expr 
*SubstituteConstraintExpressionWithoutSatisfaction(
   // parameters that the surrounding function hasn't been instantiated yet. 
Note
   // this may happen while we're comparing two templates' constraint
   // equivalence.
-  LocalInstantiationScope ScopeForParameters(S);
-  if (auto *FD = DeclInfo.getDecl()->getAsFunction())
+  std::optional ScopeForParameters;
+  if (const NamedDecl *ND = DeclInfo.getDecl();
+  ND && ND->isFunctionOrFunctionTemplate()) {
+ScopeForParameters.emplace(S);
+const FunctionDecl *FD = ND->getAsFunction();
 for (auto *PVD : FD->parameters()) {
   if (!PVD->isParameterPack()) {
-ScopeForParameters.InstantiatedLocal(PVD, PVD);
+ScopeForParameters->InstantiatedLocal(PVD, PVD);
 continue;
   }
   // This is hacky: we're mapping the parameter pack to a size-of-1 
argument
@@ -998,9 +1001,10 @@ static const Expr 
*SubstituteConstraintExpressionWithoutSatisfaction(
   // that we can eliminate the Scope in the cases where the declarations 
are
   // not necessarily instantiated. It would also benefit the noexcept
   // specifier comparison.
-  ScopeForParameters.MakeInstantiatedLocalArgPack(PVD);
-  ScopeForParameters.InstantiatedLocalPackArg(PVD, PVD);
+  ScopeForParameters->MakeInstantiatedLocalArgPack(PVD);
+  ScopeForParameters->InstantiatedLocalPackArg(PVD, PVD);
 }
+  }
 

[clang] [llvm] workflows/release-binaries: Use static ZSTD on macOS (PR #109909)

2024-09-28 Thread Keith Smiley via cfe-commits

https://github.com/keith updated 
https://github.com/llvm/llvm-project/pull/109909

>From 4676d022d971ef1623b83a2731ce94572905d6ad Mon Sep 17 00:00:00 2001
From: Keith Smiley 
Date: Wed, 25 Sep 2024 05:38:04 +
Subject: [PATCH 1/2] workflows/release-binaries: Use static ZSTD on macOS

On macOS the shared zstd library points to a homebrew install that isn't
very stable for users.
---
 .github/workflows/release-binaries.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/release-binaries.yml 
b/.github/workflows/release-binaries.yml
index 925912df6843e4..f284f04ece5b3d 100644
--- a/.github/workflows/release-binaries.yml
+++ b/.github/workflows/release-binaries.yml
@@ -126,7 +126,7 @@ jobs:
 # add extra CMake args to disable them.
 # See https://github.com/llvm/llvm-project/issues/99767
 if [ "${{ runner.os }}" = "macOS" ]; then
-  target_cmake_flags="$target_cmake_flags 
-DBOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF"
+  target_cmake_flags="$target_cmake_flags 
-DBOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF -DLLVM_USE_STATIC_ZSTD=ON"
   if [ "${{ runner.arch }}" = "ARM64" ]; then
 arches=arm64
   else

>From 338527b7698f0bd8ee62728df12ed0722045e54c Mon Sep 17 00:00:00 2001
From: Keith Smiley 
Date: Sat, 28 Sep 2024 09:11:30 -0700
Subject: [PATCH 2/2] Move to release.cmake

---
 .github/workflows/release-binaries.yml | 2 +-
 clang/cmake/caches/Release.cmake   | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/release-binaries.yml 
b/.github/workflows/release-binaries.yml
index f284f04ece5b3d..925912df6843e4 100644
--- a/.github/workflows/release-binaries.yml
+++ b/.github/workflows/release-binaries.yml
@@ -126,7 +126,7 @@ jobs:
 # add extra CMake args to disable them.
 # See https://github.com/llvm/llvm-project/issues/99767
 if [ "${{ runner.os }}" = "macOS" ]; then
-  target_cmake_flags="$target_cmake_flags 
-DBOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF -DLLVM_USE_STATIC_ZSTD=ON"
+  target_cmake_flags="$target_cmake_flags 
-DBOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF"
   if [ "${{ runner.arch }}" = "ARM64" ]; then
 arches=arm64
   else
diff --git a/clang/cmake/caches/Release.cmake b/clang/cmake/caches/Release.cmake
index c93ff40ff3ee48..52167181f595bd 100644
--- a/clang/cmake/caches/Release.cmake
+++ b/clang/cmake/caches/Release.cmake
@@ -109,3 +109,6 @@ set_final_stage_var(LLVM_ENABLE_PROJECTS 
"${LLVM_RELEASE_ENABLE_PROJECTS}" STRIN
 set_final_stage_var(CPACK_GENERATOR "TXZ" STRING)
 set_final_stage_var(CPACK_ARCHIVE_THREADS "0" STRING)
 
+if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
+  set_final_stage_var(LLVM_USE_STATIC_ZSTD "ON" BOOL)
+endif()

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


[clang] [llvm] workflows/release-binaries: Use static ZSTD on macOS (PR #109909)

2024-09-28 Thread Keith Smiley via cfe-commits


@@ -126,7 +126,7 @@ jobs:
 # add extra CMake args to disable them.
 # See https://github.com/llvm/llvm-project/issues/99767
 if [ "${{ runner.os }}" = "macOS" ]; then
-  target_cmake_flags="$target_cmake_flags 
-DBOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF"
+  target_cmake_flags="$target_cmake_flags 
-DBOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF -DLLVM_USE_STATIC_ZSTD=ON"

keith wrote:

thanks, trying it in Release.cmake, still scoped to only macOS (although I 
think there's a reasonable argument to do this on Linux as well)

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


[clang] [libcxx] Revert "[libc++][modules] Rewrite the modulemap to have fewer top-level modules (#107638)" (PR #110384)

2024-09-28 Thread Aiden Grossman via cfe-commits

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

LGTM, assuming precommit CI passes.

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


[clang] [llvm] workflows/release-binaries: Use static ZSTD on macOS (PR #109909)

2024-09-28 Thread Tom Stellard via cfe-commits

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

This looks good to me.  It looks like we need to add the Release.cmake file to 
the list of files that trigger the release-binaries-all test, but that can be 
done in another PR.

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


[clang] e203a67 - [cuda][HIP] `__constant__` should imply constant (#110182)

2024-09-28 Thread via cfe-commits

Author: Alex Voicu
Date: 2024-09-29T01:22:52+01:00
New Revision: e203a67f4cef5844877f6a5720e659ea09729e9a

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

LOG: [cuda][HIP] `__constant__` should imply constant (#110182)

Currently, `__constant__` variables do not get unconditionally marked as
`constant` in IR, which seems a bit odd given their definition. This is
generally inconsequential for NVPTX/AMDGPU, since said variables get
emitted in the constant address space for those BEs. However, it is
potentially significant for e.g. HIP-on-SPIR-V cases, as SPIR-V does not
allow casts to/from the constant AS (`UniformConstant`), which forces
`__constant__` variables to be emitted in the global AS, thus making IR
constness meaningful.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCUDA/address-spaces.cu
clang/test/CodeGenCUDA/amdgpu-visibility.cu
clang/test/CodeGenCUDA/anon-ns.cu
clang/test/CodeGenCUDA/device-var-init.cu
clang/test/CodeGenCUDA/device-var-linkage.cu
clang/test/CodeGenCUDA/filter-decl.cu
clang/test/CodeGenCUDA/static-device-var-no-rdc.cu
clang/test/CodeGenCUDA/static-device-var-rdc.cu
clang/test/CodeGenCUDA/template-class-static-member.cu
clang/test/CodeGenHIP/hipspv-addr-spaces.cpp
llvm/test/Transforms/GlobalOpt/externally-initialized.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 2381fa93e23fea..25c1c496a4f27f 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5622,8 +5622,9 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl 
*D,
 emitter->finalize(GV);
 
   // If it is safe to mark the global 'constant', do so now.
-  GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor &&
-  D->getType().isConstantStorage(getContext(), true, true));
+  GV->setConstant((D->hasAttr() && LangOpts.CUDAIsDevice) ||
+  (!NeedsGlobalCtor && !NeedsGlobalDtor &&
+   D->getType().isConstantStorage(getContext(), true, true)));
 
   // If it is in a read-only section, mark it 'constant'.
   if (const SectionAttr *SA = D->getAttr()) {

diff  --git a/clang/test/CodeGenCUDA/address-spaces.cu 
b/clang/test/CodeGenCUDA/address-spaces.cu
index 0608c9cabd0489..66903c81b93339 100644
--- a/clang/test/CodeGenCUDA/address-spaces.cu
+++ b/clang/test/CodeGenCUDA/address-spaces.cu
@@ -9,7 +9,7 @@
 // CHECK: @i ={{.*}} addrspace(1) externally_initialized global
 __device__ int i;
 
-// CHECK: @j ={{.*}} addrspace(4) externally_initialized global
+// CHECK: @j ={{.*}} addrspace(4) externally_initialized constant
 __constant__ int j;
 
 // CHECK: @k ={{.*}} addrspace(3) global

diff  --git a/clang/test/CodeGenCUDA/amdgpu-visibility.cu 
b/clang/test/CodeGenCUDA/amdgpu-visibility.cu
index d7dbab112a68c6..ef74d932ee8c8f 100644
--- a/clang/test/CodeGenCUDA/amdgpu-visibility.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-visibility.cu
@@ -4,11 +4,11 @@
 
 #include "Inputs/cuda.h"
 
-// CHECK-DEFAULT: @c ={{.*}} addrspace(4) externally_initialized global
+// CHECK-DEFAULT: @c ={{.*}} addrspace(4) externally_initialized constant
 // CHECK-DEFAULT: @g ={{.*}} addrspace(1) externally_initialized global
-// CHECK-PROTECTED: @c = protected addrspace(4) externally_initialized global
+// CHECK-PROTECTED: @c = protected addrspace(4) externally_initialized constant
 // CHECK-PROTECTED: @g = protected addrspace(1) externally_initialized global
-// CHECK-HIDDEN: @c = protected addrspace(4) externally_initialized global
+// CHECK-HIDDEN: @c = protected addrspace(4) externally_initialized constant
 // CHECK-HIDDEN: @g = protected addrspace(1) externally_initialized global
 __constant__ int c;
 __device__ int g;

diff  --git a/clang/test/CodeGenCUDA/anon-ns.cu 
b/clang/test/CodeGenCUDA/anon-ns.cu
index 3c55e9907dd6c1..d931f31d0207c5 100644
--- a/clang/test/CodeGenCUDA/anon-ns.cu
+++ b/clang/test/CodeGenCUDA/anon-ns.cu
@@ -28,13 +28,13 @@
 // HIP-DAG: define weak_odr {{.*}}void 
@[[KTX:_Z2ktIN12_GLOBAL__N_11XEEvT_\.intern\.b04fd23c98500190]](
 // HIP-DAG: define weak_odr {{.*}}void 
@[[KTL:_Z2ktIN12_GLOBAL__N_1UlvE_EEvT_\.intern\.b04fd23c98500190]](
 // HIP-DAG: @[[VM:_ZN12_GLOBAL__N_12vmE\.static\.b04fd23c98500190]] = 
addrspace(1) externally_initialized global
-// HIP-DAG: @[[VC:_ZN12_GLOBAL__N_12vcE\.static\.b04fd23c98500190]] = 
addrspace(4) externally_initialized global
+// HIP-DAG: @[[VC:_ZN12_GLOBAL__N_12vcE\.static\.b04fd23c98500190]] = 
addrspace(4) externally_initialized constant
 // HIP-DAG: @[[VT:_Z2vtIN12_GLOBAL__N_11XEE\.static\.b04fd23c98500190]] = 
addrspace(1) externally_initialized global
 
 // CUDA-DAG: define weak_odr {{.*}}void 
@[[KERN:_ZN12_GLOBAL__N_16kernelEv__intern__b04f

[clang] [llvm] [cuda][HIP] `__constant__` should imply constant (PR #110182)

2024-09-28 Thread Alex Voicu via cfe-commits

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


[clang] [clang] Fix the local parameter of void type inside the `Requires` expression. (PR #109831)

2024-09-28 Thread via cfe-commits

c8ef wrote:

After spending the entire afternoon attempting to streamline the parameter 
check process, I still haven't found an elegant solution to consolidate it into 
a single location. I explored how GCC approaches this issue and discovered that 
while GCC does utilize a single parameter check function (specifically in the 
`grokparm` function in `gcc/c/c-decl.cc`), it doesn't differentiate between the 
two contexts. As a result, it permits a `requires` clause to include a 
parameter with a default argument: 
[godbolt](https://gcc.godbolt.org/z/azcrKKf7T).

Upon examining the actual parameter checking process, it seems that the most 
crucial check related to require-expressions is for void types. Other checks 
are mainly for OpenCL, Objective-C, etc. Merging these checks for just a single 
void check might be overkill.

https://github.com/llvm/llvm-project/blob/75e08a527b716a11b3085a9ea4f5bed80c386323/clang/lib/Sema/SemaType.cpp#L5143-L5236

Therefore, I recommend adding the void parameter check directly into 
`SemaExprCXX` for an immediate fix. If there's a future need to consolidate the 
checks, we can consider refactoring later.

Additionally, there appears to be some overlap between the parameter checks in 
`Sema::BuildFunctionType` and `GetFullTypeForDeclarator`. It might be worth 
cleaning up this redundancy.

https://github.com/llvm/llvm-project/blob/75e08a527b716a11b3085a9ea4f5bed80c386323/clang/lib/Sema/SemaType.cpp#L2637-L2660

CC @mizvekov @zyn0217 @erichkeane

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


[clang] [clang][CGOpenMPRuntimeGPU] Avoid llvm::Type::getPointerTo() (NFC) (PR #110357)

2024-09-28 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/110357

`llvm::Type::getPointerTo()` is to be removed soon.

>From 360e288e2ab89b050d5e9b4ea98bb3b33e72e64e Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Sat, 28 Sep 2024 05:59:30 -0500
Subject: [PATCH] [clang][CGOpenMPRuntimeGPU] Avoid llvm::Type::getPointerTo()
 (NFC)

`llvm::Type::getPointerTo()` is to be removed soon.
---
 clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 9e095a37552196..c920d93957b16e 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1073,9 +1073,8 @@ void 
CGOpenMPRuntimeGPU::emitGenericVarsProlog(CodeGenFunction &CGF,
 CGM.getContext().getTargetInfo().getNewAlign() / 8));
 
 // Cast the void pointer and get the address of the globalized variable.
-llvm::PointerType *VarPtrTy = CGF.ConvertTypeForMem(VarTy)->getPointerTo();
 llvm::Value *CastedVoidPtr = Bld.CreatePointerBitCastOrAddrSpaceCast(
-VoidPtr, VarPtrTy, VD->getName() + "_on_stack");
+VoidPtr, Bld.getPtrTy(0), VD->getName() + "_on_stack");
 LValue VarAddr =
 CGF.MakeNaturalAlignPointeeRawAddrLValue(CastedVoidPtr, VarTy);
 Rec.second.PrivateAddr = VarAddr.getAddress();
@@ -1930,7 +1929,7 @@ llvm::Function 
*CGOpenMPRuntimeGPU::createParallelDataSharingWrapper(
   if (isOpenMPLoopBoundSharingDirective(D.getDirectiveKind())) {
 Address Src = Bld.CreateConstInBoundsGEP(SharedArgListAddress, Idx);
 Address TypedAddress = Bld.CreatePointerBitCastOrAddrSpaceCast(
-Src, CGF.SizeTy->getPointerTo(), CGF.SizeTy);
+Src, Bld.getPtrTy(0), CGF.SizeTy);
 llvm::Value *LB = CGF.EmitLoadOfScalar(
 TypedAddress,
 /*Volatile=*/false,
@@ -1939,8 +1938,8 @@ llvm::Function 
*CGOpenMPRuntimeGPU::createParallelDataSharingWrapper(
 Args.emplace_back(LB);
 ++Idx;
 Src = Bld.CreateConstInBoundsGEP(SharedArgListAddress, Idx);
-TypedAddress = Bld.CreatePointerBitCastOrAddrSpaceCast(
-Src, CGF.SizeTy->getPointerTo(), CGF.SizeTy);
+TypedAddress = Bld.CreatePointerBitCastOrAddrSpaceCast(Src, 
Bld.getPtrTy(0),
+   CGF.SizeTy);
 llvm::Value *UB = CGF.EmitLoadOfScalar(
 TypedAddress,
 /*Volatile=*/false,
@@ -2079,7 +2078,7 @@ Address 
CGOpenMPRuntimeGPU::getAddressOfLocalVariable(CodeGenFunction &CGF,
 GV->setAlignment(Align.getAsAlign());
 return Address(
 CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-GV, VarTy->getPointerTo(CGM.getContext().getTargetAddressSpace(
+GV, CGF.Builder.getPtrTy(CGM.getContext().getTargetAddressSpace(
 VD->getType().getAddressSpace(,
 VarTy, Align);
   }

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


[clang] [clang][CGOpenMPRuntimeGPU] Avoid llvm::Type::getPointerTo() (NFC) (PR #110357)

2024-09-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Youngsuk Kim (JOE1994)


Changes

`llvm::Type::getPointerTo()` is to be removed soon.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+5-6) 


``diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 9e095a37552196..c920d93957b16e 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1073,9 +1073,8 @@ void 
CGOpenMPRuntimeGPU::emitGenericVarsProlog(CodeGenFunction &CGF,
 CGM.getContext().getTargetInfo().getNewAlign() / 8));
 
 // Cast the void pointer and get the address of the globalized variable.
-llvm::PointerType *VarPtrTy = CGF.ConvertTypeForMem(VarTy)->getPointerTo();
 llvm::Value *CastedVoidPtr = Bld.CreatePointerBitCastOrAddrSpaceCast(
-VoidPtr, VarPtrTy, VD->getName() + "_on_stack");
+VoidPtr, Bld.getPtrTy(0), VD->getName() + "_on_stack");
 LValue VarAddr =
 CGF.MakeNaturalAlignPointeeRawAddrLValue(CastedVoidPtr, VarTy);
 Rec.second.PrivateAddr = VarAddr.getAddress();
@@ -1930,7 +1929,7 @@ llvm::Function 
*CGOpenMPRuntimeGPU::createParallelDataSharingWrapper(
   if (isOpenMPLoopBoundSharingDirective(D.getDirectiveKind())) {
 Address Src = Bld.CreateConstInBoundsGEP(SharedArgListAddress, Idx);
 Address TypedAddress = Bld.CreatePointerBitCastOrAddrSpaceCast(
-Src, CGF.SizeTy->getPointerTo(), CGF.SizeTy);
+Src, Bld.getPtrTy(0), CGF.SizeTy);
 llvm::Value *LB = CGF.EmitLoadOfScalar(
 TypedAddress,
 /*Volatile=*/false,
@@ -1939,8 +1938,8 @@ llvm::Function 
*CGOpenMPRuntimeGPU::createParallelDataSharingWrapper(
 Args.emplace_back(LB);
 ++Idx;
 Src = Bld.CreateConstInBoundsGEP(SharedArgListAddress, Idx);
-TypedAddress = Bld.CreatePointerBitCastOrAddrSpaceCast(
-Src, CGF.SizeTy->getPointerTo(), CGF.SizeTy);
+TypedAddress = Bld.CreatePointerBitCastOrAddrSpaceCast(Src, 
Bld.getPtrTy(0),
+   CGF.SizeTy);
 llvm::Value *UB = CGF.EmitLoadOfScalar(
 TypedAddress,
 /*Volatile=*/false,
@@ -2079,7 +2078,7 @@ Address 
CGOpenMPRuntimeGPU::getAddressOfLocalVariable(CodeGenFunction &CGF,
 GV->setAlignment(Align.getAsAlign());
 return Address(
 CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-GV, VarTy->getPointerTo(CGM.getContext().getTargetAddressSpace(
+GV, CGF.Builder.getPtrTy(CGM.getContext().getTargetAddressSpace(
 VD->getType().getAddressSpace(,
 VarTy, Align);
   }

``




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


[clang] 641b4d5 - [clang][bytecode] Implement integral-to-fixed-point casts (#110350)

2024-09-28 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-09-28T13:10:23+02:00
New Revision: 641b4d5370f1ce2f5d448cf63519f391be1cf263

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

LOG: [clang][bytecode] Implement integral-to-fixed-point casts (#110350)

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp
clang/lib/AST/ByteCode/FixedPoint.h
clang/lib/AST/ByteCode/Interp.h
clang/lib/AST/ByteCode/Opcodes.td
clang/test/AST/ByteCode/fixed-point.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 2520fe30547b23..8875fc05d24bee 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -672,6 +672,17 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
ToSize, CE);
   };
 
+  case CK_IntegralToFixedPoint: {
+if (!this->visit(SubExpr))
+  return false;
+
+auto Sem = Ctx.getASTContext().getFixedPointSemantics(CE->getType());
+uint32_t I;
+std::memcpy(&I, &Sem, sizeof(Sem));
+return this->emitCastIntegralFixedPoint(classifyPrim(SubExpr->getType()), 
I,
+CE);
+  }
+
   case CK_ToVoid:
 return discard(SubExpr);
 

diff  --git a/clang/lib/AST/ByteCode/FixedPoint.h 
b/clang/lib/AST/ByteCode/FixedPoint.h
index 9dd300c3dbf6df..daa62945346aeb 100644
--- a/clang/lib/AST/ByteCode/FixedPoint.h
+++ b/clang/lib/AST/ByteCode/FixedPoint.h
@@ -23,9 +23,10 @@ using APSInt = llvm::APSInt;
 class FixedPoint final {
 private:
   llvm::APFixedPoint V;
-  FixedPoint(llvm::APFixedPoint &&V) : V(std::move(V)) {}
 
 public:
+  FixedPoint(llvm::APFixedPoint &&V) : V(std::move(V)) {}
+  FixedPoint(llvm::APFixedPoint &V) : V(V) {}
   FixedPoint(APInt V, llvm::FixedPointSemantics Sem) : V(V, Sem) {}
   // This needs to be default-constructible so llvm::endian::read works.
   FixedPoint()

diff  --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 79af426f8a913f..f88233ed0f8f0a 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -38,6 +38,7 @@ namespace clang {
 namespace interp {
 
 using APSInt = llvm::APSInt;
+using FixedPointSemantics = llvm::FixedPointSemantics;
 
 /// Convert a value to an APValue.
 template 
@@ -2311,6 +2312,34 @@ static inline bool CastPointerIntegralAPS(InterpState 
&S, CodePtr OpPC,
   return true;
 }
 
+template ::T>
+static inline bool CastIntegralFixedPoint(InterpState &S, CodePtr OpPC,
+  uint32_t FPS) {
+  const T &Int = S.Stk.pop();
+
+  FixedPointSemantics Sem(0, 0, false, false, false);
+  std::memcpy(&Sem, &FPS, sizeof(Sem));
+
+  bool Overflow;
+  llvm::APFixedPoint IntResult =
+  llvm::APFixedPoint::getFromIntValue(Int.toAPSInt(), Sem, &Overflow);
+
+  if (Overflow) {
+const Expr *E = S.Current->getExpr(OpPC);
+if (S.checkingForUndefinedBehavior()) {
+  S.getASTContext().getDiagnostics().Report(
+  E->getExprLoc(), diag::warn_fixedpoint_constant_overflow)
+  << IntResult.toString() << E->getType();
+}
+S.CCEDiag(E, diag::note_constexpr_overflow) << IntResult << E->getType();
+if (!S.noteUndefinedBehavior())
+  return false;
+  }
+
+  S.Stk.push(IntResult);
+  return true;
+}
+
 static inline bool PtrPtrCast(InterpState &S, CodePtr OpPC, bool SrcIsVoidPtr) 
{
   const auto &Ptr = S.Stk.peek();
 

diff  --git a/clang/lib/AST/ByteCode/Opcodes.td 
b/clang/lib/AST/ByteCode/Opcodes.td
index 5fdafd1bf81984..65eb82080a2194 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -674,6 +674,12 @@ def CastPointerIntegralAP : Opcode {
 def CastPointerIntegralAPS : Opcode {
   let Args = [ArgUint32];
 }
+def CastIntegralFixedPoint : Opcode {
+  let Types = [FixedSizeIntegralTypes];
+  let Args = [ArgUint32];
+  let HasGroup = 1;
+}
+
 def PtrPtrCast : Opcode {
   let Args = [ArgBool];
 

diff  --git a/clang/test/AST/ByteCode/fixed-point.cpp 
b/clang/test/AST/ByteCode/fixed-point.cpp
index bf1bd41783448f..77000c08918256 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -12,3 +12,11 @@ static_assert(-12.0k == -(-(-12.0k)));
 /// Zero-init.
 constexpr _Accum A{};
 static_assert(A == 0.0k);
+
+namespace IntToFixedPointCast {
+  constexpr _Accum B = 13;
+  static_assert(B == 13.0k);
+
+  constexpr _Fract sf = -1;
+  static_assert(sf == -1.0k);
+}



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


[clang] [clang][bytecode] Implement integral-to-fixed-point casts (PR #110350)

2024-09-28 Thread Timm Baeder via cfe-commits

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


[clang] [clang][bytecode] Implement (N)EQ between fixed point and integral (PR #110358)

2024-09-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Convert the non-fixed-point side to a fixed-point type before doing the 
comparison.

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


3 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+51) 
- (modified) clang/lib/AST/ByteCode/Compiler.h (+1) 
- (modified) clang/test/AST/ByteCode/fixed-point.cpp (+5) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 8875fc05d24bee..a80d973056db43 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -773,6 +773,8 @@ bool Compiler::VisitBinaryOperator(const 
BinaryOperator *BO) {
RHS->getType()->isAnyComplexType()) &&
   BO->isComparisonOp())
 return this->emitComplexComparison(LHS, RHS, BO);
+  if (LHS->getType()->isFixedPointType() || RHS->getType()->isFixedPointType())
+return this->VisitFixedPointBinOp(BO);
 
   if (BO->isPtrMemOp()) {
 if (!this->visit(LHS))
@@ -1469,6 +1471,55 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   return true;
 }
 
+template 
+bool Compiler::VisitFixedPointBinOp(const BinaryOperator *E) {
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+
+  assert(LHS->getType()->isFixedPointType() ||
+ RHS->getType()->isFixedPointType());
+
+  if (!this->visit(LHS))
+return false;
+  if (!LHS->getType()->isFixedPointType()) {
+auto Sem = Ctx.getASTContext().getFixedPointSemantics(LHS->getType());
+uint32_t I;
+std::memcpy(&I, &Sem, sizeof(Sem));
+if (!this->emitCastIntegralFixedPoint(classifyPrim(LHS->getType()), I, E))
+  return false;
+  }
+  if (!this->visit(RHS))
+return false;
+  if (!RHS->getType()->isFixedPointType()) {
+auto Sem = Ctx.getASTContext().getFixedPointSemantics(RHS->getType());
+uint32_t I;
+std::memcpy(&I, &Sem, sizeof(Sem));
+if (!this->emitCastIntegralFixedPoint(classifyPrim(RHS->getType()), I, E))
+  return false;
+  }
+
+  switch (E->getOpcode()) {
+  case BO_EQ:
+return this->emitEQFixedPoint(E);
+  case BO_NE:
+return this->emitNEFixedPoint(E);
+#if 0
+  case BO_LT:
+return this->emitLTFixedPoint(E);
+  case BO_LE:
+return this->emitLEFixedPoint(E);
+  case BO_GT:
+return this->emitGTFixedPoint(E);
+  case BO_GE:
+return this->emitGEFixedPoint(E);
+#endif
+  default:
+return this->emitInvalid(E);
+  }
+
+  llvm_unreachable("unhandled binop opcode");
+}
+
 template 
 bool Compiler::VisitImplicitValueInitExpr(
 const ImplicitValueInitExpr *E) {
diff --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index d1911f11603a08..5349b184572b6e 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -132,6 +132,7 @@ class Compiler : public ConstStmtVisitor, 
bool>,
   bool VisitPointerArithBinOp(const BinaryOperator *E);
   bool VisitComplexBinOp(const BinaryOperator *E);
   bool VisitVectorBinOp(const BinaryOperator *E);
+  bool VisitFixedPointBinOp(const BinaryOperator *E);
   bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E);
   bool VisitCallExpr(const CallExpr *E);
   bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID);
diff --git a/clang/test/AST/ByteCode/fixed-point.cpp 
b/clang/test/AST/ByteCode/fixed-point.cpp
index 77000c08918256..51ea166748730c 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -6,17 +6,22 @@ static_assert(!((bool)0.0k));
 static_assert((bool)0.0k); // both-error {{static assertion failed}}
 
 static_assert(1.0k == 1.0k);
+static_assert(1.0k == 1);
 static_assert(1.0k != 1.0k); // both-error {{failed due to requirement '1.0k 
!= 1.0k'}}
+static_assert(1.0k != 1); // both-error {{failed due to requirement '1.0k != 
1'}}
 static_assert(-12.0k == -(-(-12.0k)));
 
 /// Zero-init.
 constexpr _Accum A{};
 static_assert(A == 0.0k);
+static_assert(A == 0);
 
 namespace IntToFixedPointCast {
   constexpr _Accum B = 13;
   static_assert(B == 13.0k);
+  static_assert(B == 13);
 
   constexpr _Fract sf = -1;
   static_assert(sf == -1.0k);
+  static_assert(sf == -1);
 }

``




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


[clang] [clang][bytecode] Implement (N)EQ between fixed point and integral (PR #110358)

2024-09-28 Thread Timm Baeder via cfe-commits

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

Convert the non-fixed-point side to a fixed-point type before doing the 
comparison.

>From a00e1ed99bd3f02af5131e2cf32c665608650a0c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 28 Sep 2024 13:12:10 +0200
Subject: [PATCH] [clang][bytecode] Implement (N)EQ between fixed point and
 integral

Convert the non-fixed-point side to a fixed-point type before doing the
comparison.
---
 clang/lib/AST/ByteCode/Compiler.cpp | 51 +
 clang/lib/AST/ByteCode/Compiler.h   |  1 +
 clang/test/AST/ByteCode/fixed-point.cpp |  5 +++
 3 files changed, 57 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 8875fc05d24bee..a80d973056db43 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -773,6 +773,8 @@ bool Compiler::VisitBinaryOperator(const 
BinaryOperator *BO) {
RHS->getType()->isAnyComplexType()) &&
   BO->isComparisonOp())
 return this->emitComplexComparison(LHS, RHS, BO);
+  if (LHS->getType()->isFixedPointType() || RHS->getType()->isFixedPointType())
+return this->VisitFixedPointBinOp(BO);
 
   if (BO->isPtrMemOp()) {
 if (!this->visit(LHS))
@@ -1469,6 +1471,55 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   return true;
 }
 
+template 
+bool Compiler::VisitFixedPointBinOp(const BinaryOperator *E) {
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+
+  assert(LHS->getType()->isFixedPointType() ||
+ RHS->getType()->isFixedPointType());
+
+  if (!this->visit(LHS))
+return false;
+  if (!LHS->getType()->isFixedPointType()) {
+auto Sem = Ctx.getASTContext().getFixedPointSemantics(LHS->getType());
+uint32_t I;
+std::memcpy(&I, &Sem, sizeof(Sem));
+if (!this->emitCastIntegralFixedPoint(classifyPrim(LHS->getType()), I, E))
+  return false;
+  }
+  if (!this->visit(RHS))
+return false;
+  if (!RHS->getType()->isFixedPointType()) {
+auto Sem = Ctx.getASTContext().getFixedPointSemantics(RHS->getType());
+uint32_t I;
+std::memcpy(&I, &Sem, sizeof(Sem));
+if (!this->emitCastIntegralFixedPoint(classifyPrim(RHS->getType()), I, E))
+  return false;
+  }
+
+  switch (E->getOpcode()) {
+  case BO_EQ:
+return this->emitEQFixedPoint(E);
+  case BO_NE:
+return this->emitNEFixedPoint(E);
+#if 0
+  case BO_LT:
+return this->emitLTFixedPoint(E);
+  case BO_LE:
+return this->emitLEFixedPoint(E);
+  case BO_GT:
+return this->emitGTFixedPoint(E);
+  case BO_GE:
+return this->emitGEFixedPoint(E);
+#endif
+  default:
+return this->emitInvalid(E);
+  }
+
+  llvm_unreachable("unhandled binop opcode");
+}
+
 template 
 bool Compiler::VisitImplicitValueInitExpr(
 const ImplicitValueInitExpr *E) {
diff --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index d1911f11603a08..5349b184572b6e 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -132,6 +132,7 @@ class Compiler : public ConstStmtVisitor, 
bool>,
   bool VisitPointerArithBinOp(const BinaryOperator *E);
   bool VisitComplexBinOp(const BinaryOperator *E);
   bool VisitVectorBinOp(const BinaryOperator *E);
+  bool VisitFixedPointBinOp(const BinaryOperator *E);
   bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E);
   bool VisitCallExpr(const CallExpr *E);
   bool VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinID);
diff --git a/clang/test/AST/ByteCode/fixed-point.cpp 
b/clang/test/AST/ByteCode/fixed-point.cpp
index 77000c08918256..51ea166748730c 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -6,17 +6,22 @@ static_assert(!((bool)0.0k));
 static_assert((bool)0.0k); // both-error {{static assertion failed}}
 
 static_assert(1.0k == 1.0k);
+static_assert(1.0k == 1);
 static_assert(1.0k != 1.0k); // both-error {{failed due to requirement '1.0k 
!= 1.0k'}}
+static_assert(1.0k != 1); // both-error {{failed due to requirement '1.0k != 
1'}}
 static_assert(-12.0k == -(-(-12.0k)));
 
 /// Zero-init.
 constexpr _Accum A{};
 static_assert(A == 0.0k);
+static_assert(A == 0);
 
 namespace IntToFixedPointCast {
   constexpr _Accum B = 13;
   static_assert(B == 13.0k);
+  static_assert(B == 13);
 
   constexpr _Fract sf = -1;
   static_assert(sf == -1.0k);
+  static_assert(sf == -1);
 }

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


[clang] [clang] Lifetime of locals must end before musttail call (PR #109255)

2024-09-28 Thread via cfe-commits

stefson wrote:

@ostannard can you please backport this patch into the 19.x branch, and also 
other relevant changes to the musttail issue? clang-19.1.0 was released very 
broken on arm due to this. 

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


[clang-tools-extra] [clang-tidy] support string::contains (PR #110351)

2024-09-28 Thread Tommy Chen via cfe-commits

https://github.com/dl8sd11 created 
https://github.com/llvm/llvm-project/pull/110351

Starting from c++23, we can replace `std::string::find() == std::string::npos` 
with `std::string.contains()` . #109327

Currently, this is WIP because there are two limitations:

1. False positive: SubStr type is `const std::string&` which does not match 
`std::string::contains(basic_string_view)` type.

```
std::string SubStr;
  if (Str.find(SubStr) != std::string::npos) {};
```

2. Currently, the fixit for `std::string::find("test", 0)` is incorrect. 

>From b98e9a4d50d74c298096d2bd2d70ff4c0ef5c4a4 Mon Sep 17 00:00:00 2001
From: dl8sd11 
Date: Sat, 28 Sep 2024 07:37:50 +
Subject: [PATCH] [clang-tidy] support string::contains

---
 .../readability/ContainerContainsCheck.cpp| 18 +--
 .../readability/container-contains.cpp| 49 +++
 2 files changed, 63 insertions(+), 4 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
index 05d4c87bc73cef..a5e5960eaa6a3c 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
@@ -9,6 +9,7 @@
 #include "ContainerContainsCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 
 using namespace clang::ast_matchers;
 
@@ -32,7 +33,8 @@ void ContainerContainsCheck::registerMatchers(MatchFinder 
*Finder) {
 
   const auto FindCall =
   cxxMemberCallExpr(
-  argumentCountIs(1),
+  anyOf(argumentCountIs(1),
+allOf(argumentCountIs(2), hasArgument(1, 
cxxDefaultArgExpr(,
   callee(cxxMethodDecl(
   hasName("find"),
   hasParameter(0, hasType(hasUnqualifiedDesugaredType(
@@ -51,6 +53,12 @@ void ContainerContainsCheck::registerMatchers(MatchFinder 
*Finder) {
   const auto Literal0 = integerLiteral(equals(0));
   const auto Literal1 = integerLiteral(equals(1));
 
+  const auto StringLikeClass = cxxRecordDecl(
+  hasAnyName("::std::basic_string", "::std::basic_string_view",
+ "::absl::string_view"));
+  const auto StringNpos = declRefExpr(
+  to(varDecl(hasName("npos"), hasDeclContext(StringLikeClass;
+
   auto AddSimpleMatcher = [&](auto Matcher) {
 Finder->addMatcher(
 traverse(TK_IgnoreUnlessSpelledInSource, std::move(Matcher)), this);
@@ -94,12 +102,14 @@ void ContainerContainsCheck::registerMatchers(MatchFinder 
*Finder) {
   binaryOperator(hasLHS(Literal1), hasOperatorName(">"), hasRHS(CountCall))
   .bind("negativeComparison"));
 
-  // Find membership tests based on `find() == end()`.
+  // Find membership tests based on `find() == end() or find() == npos`.
   AddSimpleMatcher(
-  binaryOperator(hasOperatorName("!="), hasOperands(FindCall, EndCall))
+  binaryOperator(hasOperatorName("!="),
+ hasOperands(FindCall, anyOf(EndCall, StringNpos)))
   .bind("positiveComparison"));
   AddSimpleMatcher(
-  binaryOperator(hasOperatorName("=="), hasOperands(FindCall, EndCall))
+  binaryOperator(hasOperatorName("=="),
+ hasOperands(FindCall, anyOf(EndCall, StringNpos)))
   .bind("negativeComparison"));
 }
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
index 9a9b233e07229b..69cc5c88479040 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
@@ -29,6 +29,43 @@ struct multimap {
   bool contains(const Key &K) const;
 };
 
+using size_t = decltype(sizeof(int));
+
+// Lightweight standin for std::string_view.
+template 
+class basic_string_view {
+public:
+  basic_string_view();
+  basic_string_view(const basic_string_view &);
+  basic_string_view(const C *);
+  ~basic_string_view();
+  int find(basic_string_view s, int pos = 0);
+  int find(const C *s, int pos = 0);
+  int find(const C *s, int pos, int n);
+  int find(char c, int pos = 0);
+  static constexpr size_t npos = -1;
+};
+typedef basic_string_view string_view;
+
+// Lightweight standin for std::string.
+template 
+class basic_string {
+public:
+  basic_string();
+  basic_string(const basic_string &);
+  basic_string(const C *);
+  ~basic_string();
+  int find(basic_string s, int pos = 0);
+  int find(const C *s, int pos = 0);
+  int find(const C *s, int pos, int n);
+  int find(char c, int pos = 0);
+  bool contains(const C *s) const;
+  bool contains(C s) const;
+  bool contains(basic_string_view s) const;
+  static constexpr size_t npos = -1;
+};
+typedef basic_string string;
+
 } // namespace std
 
 // Check that we detect various common ways to check for membership
@@ -453,3 +490,

[clang-tools-extra] [clang-tidy] support string::contains (PR #110351)

2024-09-28 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [clang] Fix the local parameter of void type inside the `Requires` expression. (PR #109831)

2024-09-28 Thread via cfe-commits


@@ -0,0 +1,15 @@
+// RUN: %clang -fsyntax-only -std=c++2a -Xclang -verify %s

c8ef wrote:

I will do it later :)

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


[clang] Revert "[clang][test] add testing for the AST matcher reference" (PR #110354)

2024-09-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Julian Schmidt (5chmidti)


Changes

Reverts llvm/llvm-project#110258

The commit caused a timeout for clang-arm64-windows-msvc: 
https://lab.llvm.org/buildbot/#/builders/161/builds/2385
and it looks like my commit is at fault.

---

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


8 Files Affected:

- (modified) clang/docs/LibASTMatchersReference.html (+2273-5680) 
- (modified) clang/docs/ReleaseNotes.rst (-3) 
- (modified) clang/docs/doxygen.cfg.in (+1-8) 
- (modified) clang/docs/tools/dump_ast_matchers.py (+5-63) 
- (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (+1662-4115) 
- (modified) clang/unittests/ASTMatchers/ASTMatchersTest.h (+3-425) 
- (modified) clang/unittests/ASTMatchers/CMakeLists.txt (-15) 
- (removed) clang/utils/generate_ast_matcher_doc_tests.py (-1097) 


``diff
diff --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index baf39befd796a5..a16b9c44ef0eab 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -586,36 +586,28 @@ Node Matchers
 
   #pragma omp declare simd
   int min();
-
-The matcher attr()
-matches nodiscard, nonnull, noinline, and
-declare simd.
+attr()
+  matches "nodiscard", "nonnull", "noinline", and the whole "#pragma" line.
 
 
 
 MatcherCXXBaseSpecifier>cxxBaseSpecifierMatcherCXXBaseSpecifier>...
 Matches class 
bases.
 
-Given
+Examples matches public virtual B.
   class B {};
   class C : public virtual B {};
-
-The matcher cxxRecordDecl(hasDirectBase(cxxBaseSpecifier()))
-matches C.
 
 
 
 MatcherCXXCtorInitializer>cxxCtorInitializerMatcherCXXCtorInitializer>...
 Matches 
constructor initializers.
 
-Given
+Examples matches i(42).
   class C {
 C() : i(42) {}
 int i;
   };
-
-The matcher cxxCtorInitializer()
-matches i(42).
 
 
 
@@ -627,22 +619,17 @@ Node Matchers
   public:
 int a;
   };
-
-The matcher accessSpecDecl()
-matches public:.
+accessSpecDecl()
+  matches 'public:'
 
 
 
 MatcherDecl>bindingDeclMatcherBindingDecl>...
 Matches binding 
declarations
+Example matches foo and bar
+(matcher = bindingDecl()
 
-Given
-  struct pair { int x; int y; };
-  pair make(int, int);
-  auto [foo, bar] = make(42, 42);
-
-The matcher bindingDecl()
-matches foo and bar.
+  auto [foo, bar] = std::make_pair{42, 42};
 
 
 
@@ -655,18 +642,14 @@ Node Matchers
   myFunc(^(int p) {
 printf("%d", p);
   })
-
 
 
 
 MatcherDecl>classTemplateDeclMatcherClassTemplateDecl>...
 Matches C++ class 
template declarations.
 
-Given
+Example matches Z
   template class Z {};
-
-The matcher classTemplateDecl()
-matches Z.
 
 
 
@@ -677,14 +660,13 @@ Node Matchers
   template
   class A {};
 
-  template class A {};
+  template
+  class A {};
 
   template<>
   class A {};
-
-The matcher classTemplatePartialSpecializationDecl()
-matches template class A {},
-but does not match A.
+classTemplatePartialSpecializationDecl()
+  matches the specialization A but not A
 
 
 
@@ -695,128 +677,87 @@ Node Matchers
   template class A {};
   template<> class A {};
   A a;
-
-The matcher classTemplateSpecializationDecl()
-matches class A
-and class A.
+classTemplateSpecializationDecl()
+  matches the specializations A and A
 
 
 
 MatcherDecl>conceptDeclMatcherConceptDecl>...
 Matches concept 
declarations.
 
-Given
-  template concept my_concept = true;
-
-
-The matcher conceptDecl()
-matches template
-concept my_concept = true.
+Example matches integral
+  template
+  concept integral = std::is_integral_v;
 
 
 
 MatcherDecl>cxxConstructorDeclMatcherCXXConstructorDecl>...
 Matches C++ 
constructor declarations.
 
-Given
+Example matches Foo::Foo() and Foo::Foo(int)
   class Foo {
public:
 Foo();
 Foo(int);
 int DoSomething();
   };
-
-  struct Bar {};
-
-
-The matcher cxxConstructorDecl()
-matches Foo() and Foo(int).

[clang] Revert "[clang][test] add testing for the AST matcher reference" (PR #110354)

2024-09-28 Thread Julian Schmidt via cfe-commits

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


[clang] [llvm] [ARM] Fix musttail calls (PR #109943)

2024-09-28 Thread via cfe-commits

stefson wrote:

so, it seems I've hit one of these in compiling firefox at src/gl.cc 

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


[clang] [clang-format] Fix a bug in annotating StartOfName (PR #99791)

2024-09-28 Thread Alexander Lohnau via cfe-commits

alex1701c wrote:

I think it would be normal for distros to backport bugfixes. Thus, users should 
get the new version rather soonish.

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


[clang] [llvm] [cuda][HIP] `__constant__` should imply constant (PR #110182)

2024-09-28 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `openmp-s390x-linux` 
running on `systemz-1` while building `clang,llvm` at step 6 "test-openmp".

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


Here is the relevant piece of the build log for the reference

```
Step 6 (test-openmp) failure: test (failure)
 TEST 'libomp :: tasking/issue-94260-2.c' FAILED 

Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang 
-fopenmp   -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test 
-L 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -fno-omit-frame-pointer -mbackchain -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt
 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic && 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang 
-fopenmp -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test 
-L 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -fno-omit-frame-pointer -mbackchain -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt
 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic
# executed command: 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--




```



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


[clang] [clang] Improve deduction of reference typed NTTP (PR #110393)

2024-09-28 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/110393

This improves the existing workaround for a core issue introduced in CWG1770.

When performing template argument deduction for an NNTP which the parameter 
side is a reference, instead of dropping the references for both sides, just 
make the argument be same reference typed as the parameter, in case the 
argument is not already a reference type.

Fixes #73460

>From adc2b02c4529edb15d9dc0df55b44abb9e8f4acc Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sat, 28 Sep 2024 21:40:54 -0300
Subject: [PATCH] [clang] Improve deduction of reference typed NTTP

This improves the existing workaround for a core issue introduced in
CWG1770.

When performing template argument deduction for an NNTP which the
parameter side is a reference, instead of dropping the references
for both sides, just make the argument be same reference typed as
the parameter, in case the argument is not already a reference type.

Fixes #73460
---
 clang/docs/ReleaseNotes.rst|  1 +
 clang/lib/Sema/SemaTemplateDeduction.cpp   | 18 +-
 .../SemaTemplate/temp_arg_nontype_cxx1z.cpp|  8 
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2e9560f553d94f..9e486afda78c70 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -446,6 +446,7 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure in debug mode, and potential crashes in release 
mode, when
   diagnosing a failed cast caused indirectly by a failed implicit conversion 
to the type of the constructor parameter.
 - Fixed an assertion failure by adjusting integral to boolean vector 
conversions (#GH108326)
+- Fixed an issue deducing non-type template arguments of reference type. 
(#GH73460)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index cc095ae67ac400..d106874c4c5bda 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -440,18 +440,18 @@ DeduceNonTypeTemplateArgument(Sema &S, 
TemplateParameterList *TemplateParams,
 
   // FIXME: It's not clear how deduction of a parameter of reference
   // type from an argument (of non-reference type) should be performed.
-  // For now, we just remove reference types from both sides and let
-  // the final check for matching types sort out the mess.
-  ValueType = ValueType.getNonReferenceType();
-  if (ParamType->isReferenceType())
-ParamType = ParamType.getNonReferenceType();
-  else
-// Top-level cv-qualifiers are irrelevant for a non-reference type.
-ValueType = ValueType.getUnqualifiedType();
+  // For now, we just make the argument have same reference type as the
+  // parameter.
+  if (ParamType->isReferenceType() && !ValueType->isReferenceType()) {
+if (ParamType->isRValueReferenceType())
+  ValueType = S.Context.getRValueReferenceType(ValueType);
+else
+  ValueType = S.Context.getLValueReferenceType(ValueType);
+  }
 
   return DeduceTemplateArgumentsByTypeMatch(
   S, TemplateParams, ParamType, ValueType, Info, Deduced,
-  TDF_SkipNonDependent,
+  TDF_SkipNonDependent | TDF_IgnoreQualifiers,
   PartialOrdering ? PartialOrderingKind::NonCall
   : PartialOrderingKind::None,
   /*ArrayBound=*/NewDeduced.wasDeducedFromArrayBound(), 
HasDeducedAnyParam);
diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp 
b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
index ae06055bf52651..8d9356bb3201cd 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -613,3 +613,11 @@ struct {
 template
 using a = s;
 }
+
+namespace GH73460 {
+  template  struct A;
+  template  struct A {};
+
+  int j;
+  template struct A;
+} // namespace GH73460

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


[clang] [clang] Improve deduction of reference typed NTTP (PR #110393)

2024-09-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

This improves the existing workaround for a core issue introduced in CWG1770.

When performing template argument deduction for an NNTP which the parameter 
side is a reference, instead of dropping the references for both sides, just 
make the argument be same reference typed as the parameter, in case the 
argument is not already a reference type.

Fixes #73460

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+9-9) 
- (modified) clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp (+8) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2e9560f553d94f..9e486afda78c70 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -446,6 +446,7 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure in debug mode, and potential crashes in release 
mode, when
   diagnosing a failed cast caused indirectly by a failed implicit conversion 
to the type of the constructor parameter.
 - Fixed an assertion failure by adjusting integral to boolean vector 
conversions (#GH108326)
+- Fixed an issue deducing non-type template arguments of reference type. 
(#GH73460)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index cc095ae67ac400..d106874c4c5bda 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -440,18 +440,18 @@ DeduceNonTypeTemplateArgument(Sema &S, 
TemplateParameterList *TemplateParams,
 
   // FIXME: It's not clear how deduction of a parameter of reference
   // type from an argument (of non-reference type) should be performed.
-  // For now, we just remove reference types from both sides and let
-  // the final check for matching types sort out the mess.
-  ValueType = ValueType.getNonReferenceType();
-  if (ParamType->isReferenceType())
-ParamType = ParamType.getNonReferenceType();
-  else
-// Top-level cv-qualifiers are irrelevant for a non-reference type.
-ValueType = ValueType.getUnqualifiedType();
+  // For now, we just make the argument have same reference type as the
+  // parameter.
+  if (ParamType->isReferenceType() && !ValueType->isReferenceType()) {
+if (ParamType->isRValueReferenceType())
+  ValueType = S.Context.getRValueReferenceType(ValueType);
+else
+  ValueType = S.Context.getLValueReferenceType(ValueType);
+  }
 
   return DeduceTemplateArgumentsByTypeMatch(
   S, TemplateParams, ParamType, ValueType, Info, Deduced,
-  TDF_SkipNonDependent,
+  TDF_SkipNonDependent | TDF_IgnoreQualifiers,
   PartialOrdering ? PartialOrderingKind::NonCall
   : PartialOrderingKind::None,
   /*ArrayBound=*/NewDeduced.wasDeducedFromArrayBound(), 
HasDeducedAnyParam);
diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp 
b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
index ae06055bf52651..8d9356bb3201cd 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -613,3 +613,11 @@ struct {
 template
 using a = s;
 }
+
+namespace GH73460 {
+  template  struct A;
+  template  struct A {};
+
+  int j;
+  template struct A;
+} // namespace GH73460

``




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


[clang] [llvm] workflows/release-binaries: Use static ZSTD on macOS (PR #109909)

2024-09-28 Thread Keith Smiley via cfe-commits

keith wrote:

I pushed a dummy change to that just to verify so we don't have to go back and 
forth on it again.  I put up the PR for the path changes here 
https://github.com/llvm/llvm-project/pull/110394, I was surprised to see this 
file is in the clang/ specific subdir, but also didn't see any other 
Release.cmake files to add here

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


[clang] [libcxx] Revert "[libc++][modules] Rewrite the modulemap to have fewer top-level modules (#107638)" (PR #110384)

2024-09-28 Thread Anton Korobeynikov via cfe-commits

asl wrote:

@llvm-beanz The changes to clang/include/clang/AST/Expr.h seems to be 
unrelated, no?

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


[clang] [clang-format] Handle template closer followed by empty paretheses (PR #110408)

2024-09-28 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/110408

Fixes #109925.

>From 27135c008868cc4f17b7ca5ff9c2af9c2fc02135 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 28 Sep 2024 22:42:56 -0700
Subject: [PATCH] [clang-format] Handle template closer followed by empty
 paretheses

Fixes #109925.
---
 clang/lib/Format/TokenAnnotator.cpp   | 42 ++-
 clang/lib/Format/UnwrappedLineParser.cpp  | 15 ---
 clang/unittests/Format/TokenAnnotatorTest.cpp |  7 
 3 files changed, 40 insertions(+), 24 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index f665ce2ad81eb0..1da1bb66f84eb0 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -189,25 +189,29 @@ class AnnotatingParser {
   next();
 }
 
-for (bool SeenTernaryOperator = false; CurrentToken;) {
+for (bool SeenTernaryOperator = false, MaybeAngles = true; CurrentToken;) {
   const bool InExpr = Contexts[Contexts.size() - 2].IsExpression;
   if (CurrentToken->is(tok::greater)) {
 const auto *Next = CurrentToken->Next;
-// Try to do a better job at looking for ">>" within the condition of
-// a statement. Conservatively insert spaces between consecutive ">"
-// tokens to prevent splitting right bitshift operators and potentially
-// altering program semantics. This check is overly conservative and
-// will prevent spaces from being inserted in select nested template
-// parameter cases, but should not alter program semantics.
-if (Next && Next->is(tok::greater) &&
-Left->ParentBracket != tok::less &&
-CurrentToken->getStartOfNonWhitespace() ==
-Next->getStartOfNonWhitespace().getLocWithOffset(-1)) {
-  return false;
-}
-if (InExpr && SeenTernaryOperator &&
-(!Next || !Next->isOneOf(tok::l_paren, tok::l_brace))) {
-  return false;
+if (CurrentToken->isNot(TT_TemplateCloser)) {
+  // Try to do a better job at looking for ">>" within the condition of
+  // a statement. Conservatively insert spaces between consecutive ">"
+  // tokens to prevent splitting right shift operators and potentially
+  // altering program semantics. This check is overly conservative and
+  // will prevent spaces from being inserted in select nested template
+  // parameter cases, but should not alter program semantics.
+  if (Next && Next->is(tok::greater) &&
+  Left->ParentBracket != tok::less &&
+  CurrentToken->getStartOfNonWhitespace() ==
+  Next->getStartOfNonWhitespace().getLocWithOffset(-1)) {
+return false;
+  }
+  if (InExpr && SeenTernaryOperator &&
+  (!Next || !Next->isOneOf(tok::l_paren, tok::l_brace))) {
+return false;
+  }
+  if (!MaybeAngles)
+return false;
 }
 Left->MatchingParen = CurrentToken;
 CurrentToken->MatchingParen = Left;
@@ -243,11 +247,11 @@ class AnnotatingParser {
   // operator that was misinterpreted because we are parsing template
   // parameters.
   // FIXME: This is getting out of hand, write a decent parser.
-  if (InExpr && !Line.startsWith(tok::kw_template) &&
+  if (MaybeAngles && InExpr && !Line.startsWith(tok::kw_template) &&
   Prev.is(TT_BinaryOperator)) {
 const auto Precedence = Prev.getPrecedence();
 if (Precedence > prec::Conditional && Precedence < prec::Relational)
-  return false;
+  MaybeAngles = false;
   }
   if (Prev.isOneOf(tok::question, tok::colon) && !Style.isProto())
 SeenTernaryOperator = true;
@@ -1614,7 +1618,7 @@ class AnnotatingParser {
 return false;
   break;
 case tok::greater:
-  if (Style.Language != FormatStyle::LK_TextProto)
+  if (Style.Language != FormatStyle::LK_TextProto && Tok->is(TT_Unknown))
 Tok->setType(TT_BinaryOperator);
   if (Tok->Previous && Tok->Previous->is(TT_TemplateCloser))
 Tok->SpacesRequiredBefore = 1;
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 40f77266fabdca..1f8013e3e4858f 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2556,7 +2556,8 @@ bool UnwrappedLineParser::parseParens(TokenType 
AmpAmpTokenType) {
 parseChildBlock();
   break;
 case tok::r_paren: {
-  const auto *Prev = LeftParen->Previous;
+  auto *Prev = LeftParen->Previous;
+  const auto *PrevPrev = Prev ? Prev->getPreviousNonComment() : nullptr;
   if (!MightBeStmtExpr && !MightBeFoldExpr && !Line->InMacroBody &&
   Style.RemoveParentheses > FormatStyle::RPS_Leave) {
 const auto *Next = Tokens->peekNextToken();
@@ -2565,7 +25

[clang] [clang-format] Handle template closer followed by empty paretheses (PR #110408)

2024-09-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixes #109925.

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


3 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+23-19) 
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+10-5) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+7) 


``diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index f665ce2ad81eb0..1da1bb66f84eb0 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -189,25 +189,29 @@ class AnnotatingParser {
   next();
 }
 
-for (bool SeenTernaryOperator = false; CurrentToken;) {
+for (bool SeenTernaryOperator = false, MaybeAngles = true; CurrentToken;) {
   const bool InExpr = Contexts[Contexts.size() - 2].IsExpression;
   if (CurrentToken->is(tok::greater)) {
 const auto *Next = CurrentToken->Next;
-// Try to do a better job at looking for ">>" within the condition of
-// a statement. Conservatively insert spaces between consecutive ">"
-// tokens to prevent splitting right bitshift operators and potentially
-// altering program semantics. This check is overly conservative and
-// will prevent spaces from being inserted in select nested template
-// parameter cases, but should not alter program semantics.
-if (Next && Next->is(tok::greater) &&
-Left->ParentBracket != tok::less &&
-CurrentToken->getStartOfNonWhitespace() ==
-Next->getStartOfNonWhitespace().getLocWithOffset(-1)) {
-  return false;
-}
-if (InExpr && SeenTernaryOperator &&
-(!Next || !Next->isOneOf(tok::l_paren, tok::l_brace))) {
-  return false;
+if (CurrentToken->isNot(TT_TemplateCloser)) {
+  // Try to do a better job at looking for ">>" within the condition of
+  // a statement. Conservatively insert spaces between consecutive ">"
+  // tokens to prevent splitting right shift operators and potentially
+  // altering program semantics. This check is overly conservative and
+  // will prevent spaces from being inserted in select nested template
+  // parameter cases, but should not alter program semantics.
+  if (Next && Next->is(tok::greater) &&
+  Left->ParentBracket != tok::less &&
+  CurrentToken->getStartOfNonWhitespace() ==
+  Next->getStartOfNonWhitespace().getLocWithOffset(-1)) {
+return false;
+  }
+  if (InExpr && SeenTernaryOperator &&
+  (!Next || !Next->isOneOf(tok::l_paren, tok::l_brace))) {
+return false;
+  }
+  if (!MaybeAngles)
+return false;
 }
 Left->MatchingParen = CurrentToken;
 CurrentToken->MatchingParen = Left;
@@ -243,11 +247,11 @@ class AnnotatingParser {
   // operator that was misinterpreted because we are parsing template
   // parameters.
   // FIXME: This is getting out of hand, write a decent parser.
-  if (InExpr && !Line.startsWith(tok::kw_template) &&
+  if (MaybeAngles && InExpr && !Line.startsWith(tok::kw_template) &&
   Prev.is(TT_BinaryOperator)) {
 const auto Precedence = Prev.getPrecedence();
 if (Precedence > prec::Conditional && Precedence < prec::Relational)
-  return false;
+  MaybeAngles = false;
   }
   if (Prev.isOneOf(tok::question, tok::colon) && !Style.isProto())
 SeenTernaryOperator = true;
@@ -1614,7 +1618,7 @@ class AnnotatingParser {
 return false;
   break;
 case tok::greater:
-  if (Style.Language != FormatStyle::LK_TextProto)
+  if (Style.Language != FormatStyle::LK_TextProto && Tok->is(TT_Unknown))
 Tok->setType(TT_BinaryOperator);
   if (Tok->Previous && Tok->Previous->is(TT_TemplateCloser))
 Tok->SpacesRequiredBefore = 1;
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 40f77266fabdca..1f8013e3e4858f 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2556,7 +2556,8 @@ bool UnwrappedLineParser::parseParens(TokenType 
AmpAmpTokenType) {
 parseChildBlock();
   break;
 case tok::r_paren: {
-  const auto *Prev = LeftParen->Previous;
+  auto *Prev = LeftParen->Previous;
+  const auto *PrevPrev = Prev ? Prev->getPreviousNonComment() : nullptr;
   if (!MightBeStmtExpr && !MightBeFoldExpr && !Line->InMacroBody &&
   Style.RemoveParentheses > FormatStyle::RPS_Leave) {
 const auto *Next = Tokens->peekNextToken();
@@ -2565,7 +2566,6 @@ bool UnwrappedLineParser::parseParens(TokenType 
AmpAmpTokenType) {
 const bool CommaSeparated =
 !DoubleParens && Prev && Prev->isOneOf(tok::l_p

[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-09-28 Thread Mehdi Amini via cfe-commits

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


[clang] [clang][bytecode] Implement fixed point casts (PR #110409)

2024-09-28 Thread Timm Baeder via cfe-commits

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

None

>From 591335042fa3d0bb0fa732ece33a29e2b3565530 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 29 Sep 2024 07:52:29 +0200
Subject: [PATCH] [clang][bytecode] Implement fixed point casts

---
 clang/lib/AST/ByteCode/Compiler.cpp |  8 
 clang/lib/AST/ByteCode/FixedPoint.h |  5 +
 clang/lib/AST/ByteCode/Interp.h | 25 +
 clang/lib/AST/ByteCode/Opcodes.td   |  4 
 clang/test/AST/ByteCode/fixed-point.cpp |  6 ++
 5 files changed, 48 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index ef058e8da44b34..3a3ee3b577c29c 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -697,6 +697,14 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 const auto *TargetSemantics = &Ctx.getFloatSemantics(CE->getType());
 return this->emitCastFixedPointFloating(TargetSemantics, CE);
   }
+  case CK_FixedPointCast: {
+if (!this->visit(SubExpr))
+  return false;
+auto Sem = Ctx.getASTContext().getFixedPointSemantics(CE->getType());
+uint32_t I;
+std::memcpy(&I, &Sem, sizeof(Sem));
+return this->emitCastFixedPoint(I, CE);
+  }
 
   case CK_ToVoid:
 return discard(SubExpr);
diff --git a/clang/lib/AST/ByteCode/FixedPoint.h 
b/clang/lib/AST/ByteCode/FixedPoint.h
index 0a808e13eda4eb..0fb4576c721266 100644
--- a/clang/lib/AST/ByteCode/FixedPoint.h
+++ b/clang/lib/AST/ByteCode/FixedPoint.h
@@ -61,6 +61,11 @@ class FixedPoint final {
 
   FixedPoint truncate(unsigned BitWidth) const { return *this; }
 
+  FixedPoint toSemantics(const llvm::FixedPointSemantics &Sem,
+ bool *Overflow) const {
+return FixedPoint(V.convert(Sem, Overflow));
+  }
+
   llvm::APFloat toFloat(const llvm::fltSemantics *Sem) const {
 return V.convertToFloat(*Sem);
   }
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 0a99d9440ff844..fd09deb87d4c51 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2161,6 +2161,31 @@ inline bool CastFP(InterpState &S, CodePtr OpPC, const 
llvm::fltSemantics *Sem,
   return true;
 }
 
+inline bool CastFixedPoint(InterpState &S, CodePtr OpPC, uint32_t FPS) {
+  FixedPointSemantics TargetSemantics(0, 0, false, false, false);
+  std::memcpy(&TargetSemantics, &FPS, sizeof(TargetSemantics));
+
+  const auto &Source = S.Stk.pop();
+
+  bool Overflow;
+  FixedPoint Result = Source.toSemantics(TargetSemantics, &Overflow);
+
+  if (Overflow) {
+const Expr *E = S.Current->getExpr(OpPC);
+if (S.checkingForUndefinedBehavior()) {
+  S.getASTContext().getDiagnostics().Report(
+  E->getExprLoc(), diag::warn_fixedpoint_constant_overflow)
+  << Result.toDiagnosticString(S.getASTContext()) << E->getType();
+}
+S.CCEDiag(E, diag::note_constexpr_overflow) << Result << E->getType();
+if (!S.noteUndefinedBehavior())
+  return false;
+  }
+
+  S.Stk.push(Result);
+  return true;
+}
+
 /// Like Cast(), but we cast to an arbitrary-bitwidth integral, so we need
 /// to know what bitwidth the result should be.
 template ::T>
diff --git a/clang/lib/AST/ByteCode/Opcodes.td 
b/clang/lib/AST/ByteCode/Opcodes.td
index ceea2accc22eff..2955bc5cf8084c 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -626,6 +626,10 @@ def CastFP : Opcode {
   let Args = [ArgFltSemantics, ArgRoundingMode];
 }
 
+def CastFixedPoint : Opcode {
+  let Args = [ArgUint32];
+}
+
 def FixedSizeIntegralTypes : TypeClass {
   let Types = [Uint8, Sint8, Uint16, Sint16, Uint32, Sint32, Uint64, Sint64, 
Bool];
 }
diff --git a/clang/test/AST/ByteCode/fixed-point.cpp 
b/clang/test/AST/ByteCode/fixed-point.cpp
index 03324c79fc9cae..dd360382e7ca21 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -47,3 +47,9 @@ namespace BinOps {
   // ref-error {{is not an integral 
constant expression}} \
   // ref-note {{is outside the range of 
representable values}}
 }
+
+namespace FixedPointCasts {
+  constexpr _Fract B = 0.3;
+  constexpr _Accum A = B;
+  constexpr _Fract C = A;
+}

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


[clang] [clang][bytecode] Implement fixed point casts (PR #110409)

2024-09-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


5 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+8) 
- (modified) clang/lib/AST/ByteCode/FixedPoint.h (+5) 
- (modified) clang/lib/AST/ByteCode/Interp.h (+25) 
- (modified) clang/lib/AST/ByteCode/Opcodes.td (+4) 
- (modified) clang/test/AST/ByteCode/fixed-point.cpp (+6) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index ef058e8da44b34..3a3ee3b577c29c 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -697,6 +697,14 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 const auto *TargetSemantics = &Ctx.getFloatSemantics(CE->getType());
 return this->emitCastFixedPointFloating(TargetSemantics, CE);
   }
+  case CK_FixedPointCast: {
+if (!this->visit(SubExpr))
+  return false;
+auto Sem = Ctx.getASTContext().getFixedPointSemantics(CE->getType());
+uint32_t I;
+std::memcpy(&I, &Sem, sizeof(Sem));
+return this->emitCastFixedPoint(I, CE);
+  }
 
   case CK_ToVoid:
 return discard(SubExpr);
diff --git a/clang/lib/AST/ByteCode/FixedPoint.h 
b/clang/lib/AST/ByteCode/FixedPoint.h
index 0a808e13eda4eb..0fb4576c721266 100644
--- a/clang/lib/AST/ByteCode/FixedPoint.h
+++ b/clang/lib/AST/ByteCode/FixedPoint.h
@@ -61,6 +61,11 @@ class FixedPoint final {
 
   FixedPoint truncate(unsigned BitWidth) const { return *this; }
 
+  FixedPoint toSemantics(const llvm::FixedPointSemantics &Sem,
+ bool *Overflow) const {
+return FixedPoint(V.convert(Sem, Overflow));
+  }
+
   llvm::APFloat toFloat(const llvm::fltSemantics *Sem) const {
 return V.convertToFloat(*Sem);
   }
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 0a99d9440ff844..fd09deb87d4c51 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2161,6 +2161,31 @@ inline bool CastFP(InterpState &S, CodePtr OpPC, const 
llvm::fltSemantics *Sem,
   return true;
 }
 
+inline bool CastFixedPoint(InterpState &S, CodePtr OpPC, uint32_t FPS) {
+  FixedPointSemantics TargetSemantics(0, 0, false, false, false);
+  std::memcpy(&TargetSemantics, &FPS, sizeof(TargetSemantics));
+
+  const auto &Source = S.Stk.pop();
+
+  bool Overflow;
+  FixedPoint Result = Source.toSemantics(TargetSemantics, &Overflow);
+
+  if (Overflow) {
+const Expr *E = S.Current->getExpr(OpPC);
+if (S.checkingForUndefinedBehavior()) {
+  S.getASTContext().getDiagnostics().Report(
+  E->getExprLoc(), diag::warn_fixedpoint_constant_overflow)
+  << Result.toDiagnosticString(S.getASTContext()) << E->getType();
+}
+S.CCEDiag(E, diag::note_constexpr_overflow) << Result << E->getType();
+if (!S.noteUndefinedBehavior())
+  return false;
+  }
+
+  S.Stk.push(Result);
+  return true;
+}
+
 /// Like Cast(), but we cast to an arbitrary-bitwidth integral, so we need
 /// to know what bitwidth the result should be.
 template ::T>
diff --git a/clang/lib/AST/ByteCode/Opcodes.td 
b/clang/lib/AST/ByteCode/Opcodes.td
index ceea2accc22eff..2955bc5cf8084c 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -626,6 +626,10 @@ def CastFP : Opcode {
   let Args = [ArgFltSemantics, ArgRoundingMode];
 }
 
+def CastFixedPoint : Opcode {
+  let Args = [ArgUint32];
+}
+
 def FixedSizeIntegralTypes : TypeClass {
   let Types = [Uint8, Sint8, Uint16, Sint16, Uint32, Sint32, Uint64, Sint64, 
Bool];
 }
diff --git a/clang/test/AST/ByteCode/fixed-point.cpp 
b/clang/test/AST/ByteCode/fixed-point.cpp
index 03324c79fc9cae..dd360382e7ca21 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -47,3 +47,9 @@ namespace BinOps {
   // ref-error {{is not an integral 
constant expression}} \
   // ref-note {{is outside the range of 
representable values}}
 }
+
+namespace FixedPointCasts {
+  constexpr _Fract B = 0.3;
+  constexpr _Accum A = B;
+  constexpr _Fract C = A;
+}

``




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


[clang] [clang] Fix the local parameter of void type inside the `Requires` expression. (PR #109831)

2024-09-28 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

> ```
> static_assert(requires(this int) { true; });
> ```

The grammar doesn't appear to disallow the explicit object parameter in a 
requires expression, see 
https://eel.is/c++draft/expr.prim.req#nt:requirement-parameter-list.

But the usage is indeed suspicious to me. We probably need a CWG issue? 
@cor3ntin @mizvekov 

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


  1   2   >