[PATCH] D139774: [libclang] Add API to set temporary directory location

2023-01-25 Thread Igor Kushnir via Phabricator via cfe-commits
vedgy added a comment.

Now that a consensus has been reached that this revision is to be discarded, 
can we please resume the discussion of which alternative should be implemented 
in the replacement revision?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139774/new/

https://reviews.llvm.org/D139774

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


[PATCH] D133375: [CMake] Remove CLANG_DEFAULT_STD_C/CLANG_DEFAULT_STD_CXX

2023-01-25 Thread Raul Tambre via Phabricator via cfe-commits
tambre added a comment.

A Clang 16 release note for this would be nice. I didn't immediately notice and 
got a bit broken by this change. 🙂


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133375/new/

https://reviews.llvm.org/D133375

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


[PATCH] D141432: Add two additional float8 types to MLIR and APFloat.

2023-01-25 Thread Jake Hall via Phabricator via cfe-commits
jakeh-gc abandoned this revision.
jakeh-gc added a comment.

I'm going to put up a narrower version of this based on D141863 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141432/new/

https://reviews.llvm.org/D141432

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


[clang] de3a3cb - [clang][Interp] Fix compound assign operator types

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T10:12:26+01:00
New Revision: de3a3cb987f11075a62680c001d3cadd0a1d1397

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

LOG: [clang][Interp] Fix compound assign operator types

Just like we do (or will do) for floating types, we need to take into
acocunt that the LHSComputationType, ResultType and type of the
expression (what we ultimately store) might be different.

Do this by emitting cast ops before and after doing the computation.

This fixes the test failures introduced by
490e8214fca48824beda8b508d6d6bbbf3d8d9a7 on big endian machines.

Differential Revision: https://reviews.llvm.org/D142328

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 615dbdefefbe..a68061c4 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -498,10 +498,13 @@ bool 
ByteCodeExprGen::VisitCompoundAssignOperator(
 const CompoundAssignOperator *E) {
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
-  std::optional LT = classify(E->getLHS()->getType());
-  std::optional RT = classify(E->getRHS()->getType());
+  std::optional LHSComputationT =
+  classify(E->getComputationLHSType());
+  std::optional LT = classify(LHS->getType());
+  std::optional RT = classify(E->getComputationResultType());
+  std::optional ResultT = classify(E->getType());
 
-  if (!LT || !RT)
+  if (!LT || !RT || !ResultT || !LHSComputationT)
 return false;
 
   assert(!E->getType()->isPointerType() &&
@@ -512,29 +515,36 @@ bool 
ByteCodeExprGen::VisitCompoundAssignOperator(
 return false;
   if (!this->emitLoad(*LT, E))
 return false;
+  // If necessary, cast LHS to its computation type.
+  if (*LT != *LHSComputationT) {
+if (!this->emitCast(*LT, *LHSComputationT, E))
+  return false;
+  }
+
   if (!visit(RHS))
 return false;
 
   // Perform operation.
   switch (E->getOpcode()) {
   case BO_AddAssign:
-if (!this->emitAdd(*LT, E))
+if (!this->emitAdd(*LHSComputationT, E))
   return false;
 break;
   case BO_SubAssign:
-if (!this->emitSub(*LT, E))
+if (!this->emitSub(*LHSComputationT, E))
   return false;
 break;
 
   case BO_MulAssign:
   case BO_DivAssign:
   case BO_RemAssign:
+
   case BO_ShlAssign:
-if (!this->emitShl(*LT, *RT, E))
+if (!this->emitShl(*LHSComputationT, *RT, E))
   return false;
 break;
   case BO_ShrAssign:
-if (!this->emitShr(*LT, *RT, E))
+if (!this->emitShr(*LHSComputationT, *RT, E))
   return false;
 break;
   case BO_AndAssign:
@@ -544,10 +554,16 @@ bool 
ByteCodeExprGen::VisitCompoundAssignOperator(
 llvm_unreachable("Unimplemented compound assign operator");
   }
 
+  // And now cast from LHSComputationT to ResultT.
+  if (*ResultT != *LHSComputationT) {
+if (!this->emitCast(*LHSComputationT, *ResultT, E))
+  return false;
+  }
+
   // And store the result in LHS.
   if (DiscardResult)
-return this->emitStorePop(*LT, E);
-  return this->emitStore(*LT, E);
+return this->emitStorePop(*ResultT, E);
+  return this->emitStore(*ResultT, E);
 }
 
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{



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


[PATCH] D142328: [clang][Interp] Fix compound assign operator types

2023-01-25 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGde3a3cb987f1: [clang][Interp] Fix compound assign operator 
types (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142328/new/

https://reviews.llvm.org/D142328

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp


Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -498,10 +498,13 @@
 const CompoundAssignOperator *E) {
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
-  std::optional LT = classify(E->getLHS()->getType());
-  std::optional RT = classify(E->getRHS()->getType());
+  std::optional LHSComputationT =
+  classify(E->getComputationLHSType());
+  std::optional LT = classify(LHS->getType());
+  std::optional RT = classify(E->getComputationResultType());
+  std::optional ResultT = classify(E->getType());
 
-  if (!LT || !RT)
+  if (!LT || !RT || !ResultT || !LHSComputationT)
 return false;
 
   assert(!E->getType()->isPointerType() &&
@@ -512,29 +515,36 @@
 return false;
   if (!this->emitLoad(*LT, E))
 return false;
+  // If necessary, cast LHS to its computation type.
+  if (*LT != *LHSComputationT) {
+if (!this->emitCast(*LT, *LHSComputationT, E))
+  return false;
+  }
+
   if (!visit(RHS))
 return false;
 
   // Perform operation.
   switch (E->getOpcode()) {
   case BO_AddAssign:
-if (!this->emitAdd(*LT, E))
+if (!this->emitAdd(*LHSComputationT, E))
   return false;
 break;
   case BO_SubAssign:
-if (!this->emitSub(*LT, E))
+if (!this->emitSub(*LHSComputationT, E))
   return false;
 break;
 
   case BO_MulAssign:
   case BO_DivAssign:
   case BO_RemAssign:
+
   case BO_ShlAssign:
-if (!this->emitShl(*LT, *RT, E))
+if (!this->emitShl(*LHSComputationT, *RT, E))
   return false;
 break;
   case BO_ShrAssign:
-if (!this->emitShr(*LT, *RT, E))
+if (!this->emitShr(*LHSComputationT, *RT, E))
   return false;
 break;
   case BO_AndAssign:
@@ -544,10 +554,16 @@
 llvm_unreachable("Unimplemented compound assign operator");
   }
 
+  // And now cast from LHSComputationT to ResultT.
+  if (*ResultT != *LHSComputationT) {
+if (!this->emitCast(*LHSComputationT, *ResultT, E))
+  return false;
+  }
+
   // And store the result in LHS.
   if (DiscardResult)
-return this->emitStorePop(*LT, E);
-  return this->emitStore(*LT, E);
+return this->emitStorePop(*ResultT, E);
+  return this->emitStore(*ResultT, E);
 }
 
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{


Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -498,10 +498,13 @@
 const CompoundAssignOperator *E) {
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
-  std::optional LT = classify(E->getLHS()->getType());
-  std::optional RT = classify(E->getRHS()->getType());
+  std::optional LHSComputationT =
+  classify(E->getComputationLHSType());
+  std::optional LT = classify(LHS->getType());
+  std::optional RT = classify(E->getComputationResultType());
+  std::optional ResultT = classify(E->getType());
 
-  if (!LT || !RT)
+  if (!LT || !RT || !ResultT || !LHSComputationT)
 return false;
 
   assert(!E->getType()->isPointerType() &&
@@ -512,29 +515,36 @@
 return false;
   if (!this->emitLoad(*LT, E))
 return false;
+  // If necessary, cast LHS to its computation type.
+  if (*LT != *LHSComputationT) {
+if (!this->emitCast(*LT, *LHSComputationT, E))
+  return false;
+  }
+
   if (!visit(RHS))
 return false;
 
   // Perform operation.
   switch (E->getOpcode()) {
   case BO_AddAssign:
-if (!this->emitAdd(*LT, E))
+if (!this->emitAdd(*LHSComputationT, E))
   return false;
 break;
   case BO_SubAssign:
-if (!this->emitSub(*LT, E))
+if (!this->emitSub(*LHSComputationT, E))
   return false;
 break;
 
   case BO_MulAssign:
   case BO_DivAssign:
   case BO_RemAssign:
+
   case BO_ShlAssign:
-if (!this->emitShl(*LT, *RT, E))
+if (!this->emitShl(*LHSComputationT, *RT, E))
   return false;
 break;
   case BO_ShrAssign:
-if (!this->emitShr(*LT, *RT, E))
+if (!this->emitShr(*LHSComputationT, *RT, E))
   return false;
 break;
   case BO_AndAssign:
@@ -544,10 +554,16 @@
 llvm_unreachable("Unimplemented compound assign operator");
   }
 
+  // And now cast from LHSComputationT to ResultT.
+  if (*ResultT != *LHSComputationT) {
+if (!this->emitCast(*LHSComputationT, *ResultT, E))
+  return false;
+  }
+
   // And store the result in LHS.
   if (DiscardResult)
-return this->emitStoreP

[clang] 902140d - [clang][Interp] Re-apply "Implement missing compound assign operators"

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T10:24:50+01:00
New Revision: 902140dd3877b63bb749fce64e22d0d39e3a9ec2

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

LOG: [clang][Interp] Re-apply "Implement missing compound assign operators"

Implement mul, div, rem, etc. compound assign operators.

Differential Revision: https://reviews.llvm.org/D137071

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index a68061c4..fa2c74c4e1a5 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -534,11 +534,18 @@ bool 
ByteCodeExprGen::VisitCompoundAssignOperator(
 if (!this->emitSub(*LHSComputationT, E))
   return false;
 break;
-
   case BO_MulAssign:
+if (!this->emitMul(*LHSComputationT, E))
+  return false;
+break;
   case BO_DivAssign:
+if (!this->emitDiv(*LHSComputationT, E))
+  return false;
+break;
   case BO_RemAssign:
-
+if (!this->emitRem(*LHSComputationT, E))
+  return false;
+break;
   case BO_ShlAssign:
 if (!this->emitShl(*LHSComputationT, *RT, E))
   return false;
@@ -548,8 +555,17 @@ bool ByteCodeExprGen::VisitCompoundAssignOperator(
   return false;
 break;
   case BO_AndAssign:
+if (!this->emitBitAnd(*LHSComputationT, E))
+  return false;
+break;
   case BO_XorAssign:
+if (!this->emitBitXor(*LHSComputationT, E))
+  return false;
+break;
   case BO_OrAssign:
+if (!this->emitBitOr(*LHSComputationT, E))
+  return false;
+break;
   default:
 llvm_unreachable("Unimplemented compound assign operator");
   }

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index cd5c9da9bda5..4fc9489941e5 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -469,5 +469,160 @@ namespace IncDec {
 return (a -= a);
   }
   static_assert(subAll(213) == 0, "");
+
+  constexpr bool BoolOr(bool b1, bool b2) {
+bool a;
+a = b1;
+a |= b2;
+return a;
+  }
+  static_assert(BoolOr(true, true), "");
+  static_assert(BoolOr(true, false), "");
+  static_assert(BoolOr(false, true), "");
+  static_assert(!BoolOr(false, false), "");
+
+  constexpr int IntOr(unsigned a, unsigned b) {
+unsigned r;
+r = a;
+r |= b;
+return r;
+  }
+  static_assert(IntOr(10, 1) == 11, "");
+  static_assert(IntOr(1337, -1) == -1, "");
+  static_assert(IntOr(0, 12) == 12, "");
+
+  constexpr bool BoolAnd(bool b1, bool b2) {
+bool a;
+a = b1;
+a &= b2;
+return a;
+  }
+  static_assert(BoolAnd(true, true), "");
+  static_assert(!BoolAnd(true, false), "");
+  static_assert(!BoolAnd(false, true), "");
+  static_assert(!BoolAnd(false, false), "");
+
+  constexpr int IntAnd(unsigned a, unsigned b) {
+unsigned r;
+r = a;
+r &= b;
+return r;
+  }
+  static_assert(IntAnd(10, 1) == 0, "");
+  static_assert(IntAnd(1337, -1) == 1337, "");
+  static_assert(IntAnd(0, 12) == 0, "");
+
+  constexpr bool BoolXor(bool b1, bool b2) {
+bool a;
+a = b1;
+a ^= b2;
+return a;
+  }
+  static_assert(!BoolXor(true, true), "");
+  static_assert(BoolXor(true, false), "");
+  static_assert(BoolXor(false, true), "");
+  static_assert(!BoolXor(false, false), "");
+
+  constexpr int IntXor(unsigned a, unsigned b) {
+unsigned r;
+r = a;
+r ^= b;
+return r;
+  }
+  static_assert(IntXor(10, 1) == 11, "");
+  static_assert(IntXor(10, 10) == 0, "");
+  static_assert(IntXor(12, true) == 13, "");
+
+  constexpr bool BoolRem(bool b1, bool b2) {
+bool a;
+a = b1;
+a %= b2;
+return a;
+  }
+  static_assert(!BoolRem(true, true), "");
+  static_assert(!BoolRem(false, true), "");
+
+  constexpr int IntRem(int a, int b) {
+int r;
+r = a;
+r %= b; // expected-note {{division by zero}} \
+// ref-note {{division by zero}} \
+// expected-note {{outside the range of representable values}} \
+// ref-note {{outside the range of representable values}}
+return r;
+  }
+  static_assert(IntRem(2, 2) == 0, "");
+  static_assert(IntRem(2, 1) == 0, "");
+  static_assert(IntRem(9, 7) == 2, "");
+  static_assert(IntRem(5, 0) == 0, ""); // expected-error {{not an integral 
constant expression}} \
+// expected-note {{in call to 
'IntRem(5, 0)'}} \
+// ref-error {{not an integral 
constant expression}} \
+// ref-note {{in call to 'IntRem(5, 
0)'}}
+
+  static_assert(IntRem(INT_MIN, -1) == 0, ""); // expected-error {{not an 
integ

[PATCH] D140415: [flang] stack arrays pass

2023-01-25 Thread Jean Perier via Phabricator via cfe-commits
jeanPerier added a comment.

Thanks for all the updates. This looks functionally correct to me. Since I am 
not very familiar with this kind of analysis and transformation, it would be 
great if another reviewer could give his/her opinion. But otherwise, given this 
solution is well isolated from a code point of view and can be turned and 
on/off easily, I'll be glad to approve it.




Comment at: flang/lib/Optimizer/Transforms/StackArrays.cpp:352
+  LLVM_DEBUG(llvm::dbgs()
+ << "--Allocation is not for an array: skipping\n");
+}

I think the early return may be missing here.



Comment at: flang/lib/Optimizer/Transforms/StackArrays.cpp:446
+  candidateOps.insert({allocmem, insertionPoint});
+}
+  }

nit: MLIR/LLVM coding style do not use `{}` for single line if.



Comment at: flang/lib/Optimizer/Transforms/StackArrays.cpp:642
+rewriter.setInsertionPointAfter(op);
+  else if (mlir::Block *block = insertionPoint.tryGetBlock())
+rewriter.setInsertionPointToStart(block);

If this case must succeed when the other failed, it may be better to place it 
in an `else {` and assert that a block was obtained, so that it is certain that 
the insertion point was correctly set when looking at this code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140415/new/

https://reviews.llvm.org/D140415

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


[PATCH] D142459: [clang] Deprecate uses of GlobalObject::getAlignment

2023-01-25 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet added inline comments.



Comment at: clang/lib/CodeGen/CGCUDANV.cpp:491
   new llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,
- llvm::Align(Var->getAlignment()), I);
+ Var->getAlign().valueOrOne(), I);
   WorkItem.pop_back();

barannikov88 wrote:
> barannikov88 wrote:
> > tra wrote:
> > > gchatelet wrote:
> > > > tra wrote:
> > > > > This appears to be a change in behavior. AFAICT, previously used 
> > > > > Var->getAlignment() could return alignment value or 0. Now it's value 
> > > > > or 1.
> > > > > 
> > > > > Is it intentional?
> > > > The previous statement was constructing an `llvm::Align` from a value, 
> > > > and `llvm::Align` [asserts when the provided value is 
> > > > 0](https://github.com/llvm/llvm-project/blob/4ab2246d486ba30c4b2d654323a0c0b97565c0f1/llvm/include/llvm/Support/Alignment.h#L76-L81).
> > > >  This means that it is undefined to pass the value `0`.
> > > > 
> > > > As far as `LoadInst` is concerned it can only accept valid alignments 
> > > > (i.e., powers of two => non zero).
> > > > 
> > > > So you're right that it is not strictly NFC and that 
> > > > `*Var->getAlign()`would be a more rigorous transformation but I 
> > > > //think// that converting the `0` value to `1` moves us from UB to 
> > > > semantically valid code.
> > > > 
> > > > I don't feel strongly about it though and I'm fine changing this to 
> > > > `*Var->getAlign()` to keep this patch NFC. WDYT?
> > > Enforcing alignment of 1 would potentially force us to generate overly 
> > > conservative one byte at a time loads/stores.
> > > I agree that passing 0 is a wrong choice here, but 1 does not seem to be 
> > > correct, either.
> > > Unfortunately LoadInst does not have overloads accepting MaybeAlign so we 
> > > need to use different `LoadInst` overload depending on whether alignment 
> > > is specified.
> > > 
> > > ```
> > > NewV =  Var->getAlign().isAligned() 
> > >   ? llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,  
> > > Var->getAlign().value(), I)
> > >   : llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,  I);
> > > ```
> > > 
> > > @yaxunl -- Sam, does it make sense? This seems to be largely HIP-specific.
> > I think it should be just `Var->getAlign()` to allow propagating absent 
> > alignment.
> > Curiously, the old code didn't assert because `GlobalVariable` seem to 
> > always(?) have non-empty alignment if the global had an associated 
> > `VarDecl` (set [[ 
> > https://github.com/llvm/llvm-project/blob/6ad0788c332bb2043142954d300c49ac3e537f34/clang/lib/CodeGen/CodeGenModule.cpp#L4442
> >  | here ]], changed(?) by [[ 
> > https://github.com/llvm/llvm-project/commit/c79099e0f44d0f85515fd30c83923d9d9dc1679b
> >  | this patch ]]).
> > 
> > Unfortunately LoadInst does not have overloads accepting MaybeAlign so we 
> > need to use different `LoadInst` overload depending on whether alignment is 
> > specified.
> 
> That's interesting, because `SelectionDAG::getLoad` has many variants with 
> `MaybeAlign`, but only one with `Align`.
> 
[The documentation](https://llvm.org/docs/LangRef.html#load-instruction) says 
that `LoadInst` alignment is optional so indeed it should accept a `MaybeAlign` 
instead of an `Align`.
I'll send a patch to fix this.

Then we can indeed simply use `Var->getAlign()`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142459/new/

https://reviews.llvm.org/D142459

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


[clang] ad2fb01 - [clang][Interp] Fix dereferencing arrays with no offset applied

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T11:21:31+01:00
New Revision: ad2fb01cb68dc17594d2a923da90f5e01e127cdf

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

LOG: [clang][Interp] Fix dereferencing arrays with no offset applied

A pointer to an array and a pointer to the first element of the array
are not the same in the interpreter, so handle this specially in
deref().

Differential Revision: https://reviews.llvm.org/D137082

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index 1462d01c24126..489884a256598 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -225,6 +225,10 @@ class Pointer {
 return Offset - Base - Adjust;
   }
 
+  /// Whether this array refers to an array, but not
+  /// to the first element.
+  bool isArrayRoot() const { return inArray() && Offset == Base; }
+
   /// Checks if the innermost field is an array.
   bool inArray() const { return getFieldDesc()->IsArray; }
   /// Checks if the structure is a primitive array.
@@ -306,6 +310,10 @@ class Pointer {
   /// Dereferences the pointer, if it's live.
   template  T &deref() const {
 assert(isLive() && "Invalid pointer");
+if (isArrayRoot())
+  return *reinterpret_cast(Pointee->rawData() + Base +
+sizeof(InitMap *));
+
 return *reinterpret_cast(Pointee->rawData() + Offset);
   }
 

diff  --git a/clang/test/AST/Interp/arrays.cpp 
b/clang/test/AST/Interp/arrays.cpp
index cd8d37442e089..3c0eaefeb7965 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -42,6 +42,21 @@ constexpr int getElement(const int *Arr, int index) {
   return *(Arr + index);
 }
 
+constexpr int derefPtr(const int *d) {
+  return *d;
+}
+static_assert(derefPtr(data) == 5, "");
+
+constexpr int storePtr() {
+  int b[] = {1,2,3,4};
+  int *c = b;
+
+  *c = 4;
+  return *c;
+}
+static_assert(storePtr() == 4, "");
+
+
 static_assert(getElement(data, 1) == 4, "");
 static_assert(getElement(data, 4) == 1, "");
 



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


[PATCH] D137082: [clang][Interp] Fix dereferencing arrays with no offset applied

2023-01-25 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGad2fb01cb68d: [clang][Interp] Fix dereferencing arrays with 
no offset applied (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D137082?vs=472887&id=492041#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137082/new/

https://reviews.llvm.org/D137082

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


Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -42,6 +42,21 @@
   return *(Arr + index);
 }
 
+constexpr int derefPtr(const int *d) {
+  return *d;
+}
+static_assert(derefPtr(data) == 5, "");
+
+constexpr int storePtr() {
+  int b[] = {1,2,3,4};
+  int *c = b;
+
+  *c = 4;
+  return *c;
+}
+static_assert(storePtr() == 4, "");
+
+
 static_assert(getElement(data, 1) == 4, "");
 static_assert(getElement(data, 4) == 1, "");
 
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -225,6 +225,10 @@
 return Offset - Base - Adjust;
   }
 
+  /// Whether this array refers to an array, but not
+  /// to the first element.
+  bool isArrayRoot() const { return inArray() && Offset == Base; }
+
   /// Checks if the innermost field is an array.
   bool inArray() const { return getFieldDesc()->IsArray; }
   /// Checks if the structure is a primitive array.
@@ -306,6 +310,10 @@
   /// Dereferences the pointer, if it's live.
   template  T &deref() const {
 assert(isLive() && "Invalid pointer");
+if (isArrayRoot())
+  return *reinterpret_cast(Pointee->rawData() + Base +
+sizeof(InitMap *));
+
 return *reinterpret_cast(Pointee->rawData() + Offset);
   }
 


Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -42,6 +42,21 @@
   return *(Arr + index);
 }
 
+constexpr int derefPtr(const int *d) {
+  return *d;
+}
+static_assert(derefPtr(data) == 5, "");
+
+constexpr int storePtr() {
+  int b[] = {1,2,3,4};
+  int *c = b;
+
+  *c = 4;
+  return *c;
+}
+static_assert(storePtr() == 4, "");
+
+
 static_assert(getElement(data, 1) == 4, "");
 static_assert(getElement(data, 4) == 1, "");
 
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -225,6 +225,10 @@
 return Offset - Base - Adjust;
   }
 
+  /// Whether this array refers to an array, but not
+  /// to the first element.
+  bool isArrayRoot() const { return inArray() && Offset == Base; }
+
   /// Checks if the innermost field is an array.
   bool inArray() const { return getFieldDesc()->IsArray; }
   /// Checks if the structure is a primitive array.
@@ -306,6 +310,10 @@
   /// Dereferences the pointer, if it's live.
   template  T &deref() const {
 assert(isLive() && "Invalid pointer");
+if (isArrayRoot())
+  return *reinterpret_cast(Pointee->rawData() + Base +
+sizeof(InitMap *));
+
 return *reinterpret_cast(Pointee->rawData() + Offset);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140756: Add clang_CXXMethod_isExplicit to libclang

2023-01-25 Thread Luca Di sera via Phabricator via cfe-commits
diseraluca reopened this revision.
diseraluca added a comment.
This revision is now accepted and ready to land.

When I pushed the patch the tests produced failures in buildbot. 
I reverted the patch as I did not have the time to check what was happening.

I've now had time to check and the failures seems to be due to the 
implementation dependent signed-ness of char, 
thus failing on platforms where char is unsigned (like power pc).

I've changed the tests to use a more precise unsigned char which should solve 
the issue.
There is probably a way to only check for the presence or lack thereof of the 
(explicit) tag without checking those unimportant details, 
but I had not time to accustom myself to FileCheck yet.

I reopened the revision to have a second set of eyes check this as I would 
really like to avoid blocking the integrations again.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140756/new/

https://reviews.llvm.org/D140756

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


[PATCH] D140756: Add clang_CXXMethod_isExplicit to libclang

2023-01-25 Thread Luca Di sera via Phabricator via cfe-commits
diseraluca updated this revision to Diff 492042.
diseraluca added a comment.

Fixed tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140756/new/

https://reviews.llvm.org/D140756

Files:
  clang/bindings/python/clang/cindex.py
  clang/bindings/python/tests/cindex/test_cursor.py
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/test/Index/explicit-constructor.cpp
  clang/test/Index/explicit-conversion-function.cpp
  clang/test/Index/get-cursor.cpp
  clang/test/Index/index-file.cpp
  clang/test/Index/recursive-cxx-member-calls.cpp
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/libclang.map

Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -416,6 +416,7 @@
 clang_disposeAPISet;
 clang_getSymbolGraphForCursor;
 clang_getSymbolGraphForUSR;
+clang_CXXMethod_isExplicit;
 };
 
 # Example of how to add a new symbol version entry.  If you do add a new symbol
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -8947,6 +8947,25 @@
   return (Method && Method->isMoveAssignmentOperator()) ? 1 : 0;
 }
 
+unsigned clang_CXXMethod_isExplicit(CXCursor C) {
+  if (!clang_isDeclaration(C.kind))
+return 0;
+
+  const Decl *D = cxcursor::getCursorDecl(C);
+  const FunctionDecl *FD = D->getAsFunction();
+
+  if (!FD)
+return 0;
+
+  if (const auto *Ctor = dyn_cast(FD))
+return Ctor->isExplicit();
+
+  if (const auto *Conv = dyn_cast(FD))
+return Conv->isExplicit();
+
+  return 0;
+}
+
 unsigned clang_CXXRecord_isAbstract(CXCursor C) {
   if (!clang_isDeclaration(C.kind))
 return 0;
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -916,6 +916,8 @@
   printf(" (copy-assignment operator)");
 if (clang_CXXMethod_isMoveAssignmentOperator(Cursor))
   printf(" (move-assignment operator)");
+if (clang_CXXMethod_isExplicit(Cursor))
+  printf(" (explicit)");
 if (clang_CXXRecord_isAbstract(Cursor))
   printf(" (abstract)");
 if (clang_EnumDecl_isScoped(Cursor))
Index: clang/test/Index/recursive-cxx-member-calls.cpp
===
--- clang/test/Index/recursive-cxx-member-calls.cpp
+++ clang/test/Index/recursive-cxx-member-calls.cpp
@@ -824,7 +824,7 @@
 // CHECK-tokens: Keyword: "public" [86:1 - 86:7] CXXAccessSpecifier=:86:1 (Definition)
 // CHECK-tokens: Punctuation: ":" [86:7 - 86:8] CXXAccessSpecifier=:86:1 (Definition)
 // CHECK-tokens: Keyword: "explicit" [87:3 - 87:11] CXXConstructor=StringSwitch:87:12 (Definition)
-// CHECK-tokens: Identifier: "StringSwitch" [87:12 - 87:24] CXXConstructor=StringSwitch:87:12 (Definition)
+// CHECK-tokens: Identifier: "StringSwitch" [87:12 - 87:24] CXXConstructor=StringSwitch:87:12 (Definition) (explicit)
 // CHECK-tokens: Punctuation: "(" [87:24 - 87:25] CXXConstructor=StringSwitch:87:12 (Definition)
 // CHECK-tokens: Identifier: "StringRef" [87:25 - 87:34] TypeRef=class llvm::StringRef:38:7
 // CHECK-tokens: Identifier: "Str" [87:35 - 87:38] ParmDecl=Str:87:35 (Definition)
@@ -1839,7 +1839,7 @@
 // CHECK: 84:3: TypeRef=class llvm::StringRef:38:7 Extent=[84:3 - 84:12]
 // CHECK: 85:12: FieldDecl=Result:85:12 (Definition) Extent=[85:3 - 85:18]
 // CHECK: 86:1: CXXAccessSpecifier=:86:1 (Definition) Extent=[86:1 - 86:8]
-// CHECK: 87:12: CXXConstructor=StringSwitch:87:12 (Definition) Extent=[87:3 - 87:64]
+// CHECK: 87:12: CXXConstructor=StringSwitch:87:12 (Definition) (explicit) Extent=[87:3 - 87:64]
 // CHECK: 87:35: ParmDecl=Str:87:35 (Definition) Extent=[87:25 - 87:38]
 // CHECK: 87:25: TypeRef=class llvm::StringRef:38:7 Extent=[87:25 - 87:34]
 // CHECK: 87:42: MemberRef=Str:84:13 Extent=[87:42 - 87:45]
Index: clang/test/Index/index-file.cpp
===
--- clang/test/Index/index-file.cpp
+++ clang/test/Index/index-file.cpp
@@ -53,4 +53,4 @@
 // CHECK: [indexDeclaration]: kind: constructor | name: B | {{.*}} | loc: 33:12
 // CHECK: [indexDeclaration]: kind: constructor | name: B | {{.*}} (copy constructor) (converting constructor) | loc: 34:3
 // CHECK: [indexDeclaration]: kind: constructor | name: B | {{.*}} (move constructor) (converting constructor) | loc: 35:3
-// CHECK: [indexDeclaration]: kind: constructor | name: C | {{.*}} (copy constructor) | loc: 39:12
+// CHECK: [indexDeclaration]: kind: constructor | name: C | {{.*}} (copy constructor) (explicit) | loc: 39:12
Index: clang/test/Index/get-cursor.cpp
===
--- clang

[PATCH] D142500: Fix one of the regressions found in revert of concept sugaring

2023-01-25 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Thanks for preparing this fix! I've verified that it fixes the original 
reproducer as well.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142500/new/

https://reviews.llvm.org/D142500

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


[PATCH] D140415: [flang] stack arrays pass

2023-01-25 Thread Tom Eccles via Phabricator via cfe-commits
tblah updated this revision to Diff 492044.
tblah marked 5 inline comments as done.
tblah added a comment.

- Add missing early return for allocations not for arrays
- Remove braces from if statement with a single statement in its body
- Assert that a correct insertion point is found for the alloca


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140415/new/

https://reviews.llvm.org/D140415

Files:
  clang/docs/tools/clang-formatted-files.txt
  flang/include/flang/Optimizer/Builder/MutableBox.h
  flang/include/flang/Optimizer/Dialect/FIRAttr.h
  flang/include/flang/Optimizer/Transforms/Passes.h
  flang/include/flang/Optimizer/Transforms/Passes.td
  flang/lib/Lower/Allocatable.cpp
  flang/lib/Optimizer/Builder/MutableBox.cpp
  flang/lib/Optimizer/Transforms/CMakeLists.txt
  flang/lib/Optimizer/Transforms/StackArrays.cpp
  flang/test/Lower/HLFIR/allocatable-and-pointer-status-change.f90
  flang/test/Lower/Intrinsics/c_loc.f90
  flang/test/Lower/Intrinsics/system_clock.f90
  flang/test/Transforms/stack-arrays.f90
  flang/test/Transforms/stack-arrays.fir

Index: flang/test/Transforms/stack-arrays.fir
===
--- /dev/null
+++ flang/test/Transforms/stack-arrays.fir
@@ -0,0 +1,242 @@
+// RUN: fir-opt --stack-arrays %s | FileCheck %s
+
+// Simplest transformation
+func.func @simple() {
+  %0 = fir.allocmem !fir.array<42xi32>
+  fir.freemem %0 : !fir.heap>
+  return
+}
+// CHECK: func.func @simple() {
+// CHECK-NEXT: fir.alloca !fir.array<42xi32>
+// CHECK-NEXT: return
+// CHECK-NEXT: }
+
+// Check fir.must_be_heap allocations are not moved
+func.func @must_be_heap() {
+  %0 = fir.allocmem !fir.array<42xi32> {fir.must_be_heap = true}
+  fir.freemem %0 : !fir.heap>
+  return
+}
+// CHECK:  func.func @must_be_heap() {
+// CHECK-NEXT:   %[[ALLOC:.*]] = fir.allocmem !fir.array<42xi32> {fir.must_be_heap = true}
+// CHECK-NEXT:   fir.freemem %[[ALLOC]] : !fir.heap>
+// CHECK-NEXT:   return
+// CHECK-NEXT: }
+
+// Check the data-flow-analysis can detect cases where we aren't sure if memory
+// is freed by the end of the function
+func.func @dfa1(%arg0: !fir.ref> {fir.bindc_name = "cond"}) {
+  %7 = arith.constant 42 : index
+  %8 = fir.allocmem !fir.array, %7 {uniq_name = "_QFdfa1Earr.alloc"}
+  %9 = fir.load %arg0 : !fir.ref>
+  %10 = fir.convert %9 : (!fir.logical<4>) -> i1
+  fir.if %10 {
+fir.freemem %8 : !fir.heap>
+  } else {
+  }
+  return
+}
+// CHECK:  func.func @dfa1(%arg0: !fir.ref> {fir.bindc_name = "cond"}) {
+// CHECK-NEXT:   %c42 = arith.constant 42 : index
+// CHECK-NEXT:   %0 = fir.allocmem !fir.array, %c42 {uniq_name = "_QFdfa1Earr.alloc"}
+// CHECK-NEXT:   %1 = fir.load %arg0 : !fir.ref>
+// CHECK-NEXT:   %2 = fir.convert %1 : (!fir.logical<4>) -> i1
+// CHECK-NEXT:   fir.if %2 {
+// CHECK-NEXT: fir.freemem %0 : !fir.heap>
+// CHECK-NEXT:   } else {
+// CHECK-NEXT:   }
+// CHECK-NEXT:   return
+// CHECK-NEXT: }
+
+// Check scf.if (fir.if is not considered a branch operation)
+func.func @dfa2(%arg0: i1) {
+  %a = fir.allocmem !fir.array<1xi8>
+  scf.if %arg0 {
+fir.freemem %a : !fir.heap>
+  } else {
+  }
+  return
+}
+// CHECK: func.func @dfa2(%arg0: i1) {
+// CHECK-NEXT:  %[[MEM:.*]] = fir.allocmem !fir.array<1xi8>
+// CHECK-NEXT:  scf.if %arg0 {
+// CHECK-NEXT:fir.freemem %[[MEM]] : !fir.heap>
+// CHECK-NEXT:  } else {
+// CHECK-NEXT:  }
+// CHECK-NEXT:  return
+// CHECK-NEXT:  }
+
+// check the alloca is placed after all operands become available
+func.func @placement1() {
+  // do some stuff with other ssa values
+  %1 = arith.constant 1 : index
+  %2 = arith.constant 2 : index
+  %3 = arith.addi %1, %2 : index
+  // operand is now available
+  %4 = fir.allocmem !fir.array, %3
+  // ...
+  fir.freemem %4 : !fir.heap>
+  return
+}
+// CHECK:  func.func @placement1() {
+// CHECK-NEXT:   %[[ONE:.*]] = arith.constant 1 : index
+// CHECK-NEXT:   %[[TWO:.*]] = arith.constant 2 : index
+// CHECK-NEXT:   %[[ARG:.*]] = arith.addi %[[ONE]], %[[TWO]] : index
+// CHECK-NEXT:   %[[MEM:.*]] = fir.alloca !fir.array, %[[ARG]]
+// CHECK-NEXT:   return
+// CHECK-NEXT: }
+
+// check that if there are no operands, then the alloca is placed early
+func.func @placement2() {
+  // do some stuff with other ssa values
+  %1 = arith.constant 1 : index
+  %2 = arith.constant 2 : index
+  %3 = arith.addi %1, %2 : index
+  %4 = fir.allocmem !fir.array<42xi32>
+  // ...
+  fir.freemem %4 : !fir.heap>
+  return
+}
+// CHECK:  func.func @placement2() {
+// CHECK-NEXT:   %[[MEM:.*]] = fir.alloca !fir.array<42xi32>
+// CHECK-NEXT:   %[[ONE:.*]] = arith.constant 1 : index
+// CHECK-NEXT:   %[[TWO:.*]] = arith.constant 2 : index
+// CHECK-NEXT:   %[[SUM:.*]] = arith.addi %[[ONE]], %[[TWO]] : index
+// CHECK-NEXT:   return
+// CHECK-NEXT: }
+
+// check that stack allocations which must be placed in loops use stacksave
+func.func @placement3() {
+  %c1 = arith.constant 1 : index
+  %c1_i32 = fir

[PATCH] D140415: [flang] stack arrays pass

2023-01-25 Thread Tom Eccles via Phabricator via cfe-commits
tblah added inline comments.



Comment at: flang/lib/Optimizer/Transforms/StackArrays.cpp:352
+  LLVM_DEBUG(llvm::dbgs()
+ << "--Allocation is not for an array: skipping\n");
+}

jeanPerier wrote:
> I think the early return may be missing here.
Thanks, good spot!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140415/new/

https://reviews.llvm.org/D140415

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


[PATCH] D142477: [X86] Ensure the _mm_test_all_ones macro does not reuse argument (PR60006)

2023-01-25 Thread Simon Pilgrim via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc9b28233599a: [X86] Ensure the _mm_test_all_ones macro does 
not reuse argument (PR60006) (authored by RKSimon).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142477/new/

https://reviews.llvm.org/D142477

Files:
  clang/lib/Headers/smmintrin.h
  clang/test/CodeGen/X86/sse41-builtins.c


Index: clang/test/CodeGen/X86/sse41-builtins.c
===
--- clang/test/CodeGen/X86/sse41-builtins.c
+++ clang/test/CodeGen/X86/sse41-builtins.c
@@ -401,3 +401,13 @@
   // CHECK: extractelement <4 x float> %{{.*}}, i32 0
   return _mm_round_ps(a, 0)[0];
 }
+
+// Ensure _mm_test_all_ones macro doesn't reuse argument
+__m128i expensive_call();
+int pr60006() {
+  // CHECK-LABEL: pr60006
+  // CHECK: call {{.*}} @expensive_call
+  // CHECK-NOT: call {{.*}} @expensive_call
+  // CHECK: call i32 @llvm.x86.sse41.ptestc(<2 x i64> %{{.*}}, <2 x i64> 
%{{.*}})
+  return _mm_test_all_ones(expensive_call());
+}
Index: clang/lib/Headers/smmintrin.h
===
--- clang/lib/Headers/smmintrin.h
+++ clang/lib/Headers/smmintrin.h
@@ -1145,7 +1145,7 @@
 ///A 128-bit integer vector containing the bits to be tested.
 /// \returns TRUE if the bits specified in the operand are all set to 1; FALSE
 ///otherwise.
-#define _mm_test_all_ones(V) _mm_testc_si128((V), _mm_cmpeq_epi32((V), (V)))
+#define _mm_test_all_ones(V) _mm_testc_si128((V), _mm_set1_epi32(-1))
 
 /// Tests whether the specified bits in a 128-bit integer vector are
 ///neither all zeros nor all ones.


Index: clang/test/CodeGen/X86/sse41-builtins.c
===
--- clang/test/CodeGen/X86/sse41-builtins.c
+++ clang/test/CodeGen/X86/sse41-builtins.c
@@ -401,3 +401,13 @@
   // CHECK: extractelement <4 x float> %{{.*}}, i32 0
   return _mm_round_ps(a, 0)[0];
 }
+
+// Ensure _mm_test_all_ones macro doesn't reuse argument
+__m128i expensive_call();
+int pr60006() {
+  // CHECK-LABEL: pr60006
+  // CHECK: call {{.*}} @expensive_call
+  // CHECK-NOT: call {{.*}} @expensive_call
+  // CHECK: call i32 @llvm.x86.sse41.ptestc(<2 x i64> %{{.*}}, <2 x i64> %{{.*}})
+  return _mm_test_all_ones(expensive_call());
+}
Index: clang/lib/Headers/smmintrin.h
===
--- clang/lib/Headers/smmintrin.h
+++ clang/lib/Headers/smmintrin.h
@@ -1145,7 +1145,7 @@
 ///A 128-bit integer vector containing the bits to be tested.
 /// \returns TRUE if the bits specified in the operand are all set to 1; FALSE
 ///otherwise.
-#define _mm_test_all_ones(V) _mm_testc_si128((V), _mm_cmpeq_epi32((V), (V)))
+#define _mm_test_all_ones(V) _mm_testc_si128((V), _mm_set1_epi32(-1))
 
 /// Tests whether the specified bits in a 128-bit integer vector are
 ///neither all zeros nor all ones.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c9b2823 - [X86] Ensure the _mm_test_all_ones macro does not reuse argument (PR60006)

2023-01-25 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2023-01-25T10:56:01Z
New Revision: c9b28233599a753506687f2f8a4f96331cd5dbb2

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

LOG: [X86] Ensure the _mm_test_all_ones macro does not reuse argument (PR60006)

The macro _mm_test_all_ones(V) was defined as _mm_testc_si128((V), 
_mm_cmpeq_epi32((V), (V))) - which could cause side effects depending on the 
source of the V value.

The _mm_cmpeq_epi32((V), (V)) trick was just to materialize an all-ones value, 
which can be more safely generated with _mm_set1_epi32(-1) .

Fixes #60006

Differential Revision: https://reviews.llvm.org/D142477

Added: 


Modified: 
clang/lib/Headers/smmintrin.h
clang/test/CodeGen/X86/sse41-builtins.c

Removed: 




diff  --git a/clang/lib/Headers/smmintrin.h b/clang/lib/Headers/smmintrin.h
index 2111c24f31a60..16d8855a1c0b5 100644
--- a/clang/lib/Headers/smmintrin.h
+++ b/clang/lib/Headers/smmintrin.h
@@ -1145,7 +1145,7 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_testnzc_si128(__m128i __M,
 ///A 128-bit integer vector containing the bits to be tested.
 /// \returns TRUE if the bits specified in the operand are all set to 1; FALSE
 ///otherwise.
-#define _mm_test_all_ones(V) _mm_testc_si128((V), _mm_cmpeq_epi32((V), (V)))
+#define _mm_test_all_ones(V) _mm_testc_si128((V), _mm_set1_epi32(-1))
 
 /// Tests whether the specified bits in a 128-bit integer vector are
 ///neither all zeros nor all ones.

diff  --git a/clang/test/CodeGen/X86/sse41-builtins.c 
b/clang/test/CodeGen/X86/sse41-builtins.c
index 8573960babb7b..fe59cbcaf1938 100644
--- a/clang/test/CodeGen/X86/sse41-builtins.c
+++ b/clang/test/CodeGen/X86/sse41-builtins.c
@@ -401,3 +401,13 @@ float pr51324(__m128 a) {
   // CHECK: extractelement <4 x float> %{{.*}}, i32 0
   return _mm_round_ps(a, 0)[0];
 }
+
+// Ensure _mm_test_all_ones macro doesn't reuse argument
+__m128i expensive_call();
+int pr60006() {
+  // CHECK-LABEL: pr60006
+  // CHECK: call {{.*}} @expensive_call
+  // CHECK-NOT: call {{.*}} @expensive_call
+  // CHECK: call i32 @llvm.x86.sse41.ptestc(<2 x i64> %{{.*}}, <2 x i64> 
%{{.*}})
+  return _mm_test_all_ones(expensive_call());
+}



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


[PATCH] D137232: [clang][Interp] Support inc/dec operators on pointers

2023-01-25 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7348bb36c557: [clang][Interp] Support inc/dec operators for 
pointers (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D137232?vs=474724&id=492048#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137232/new/

https://reviews.llvm.org/D137232

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/arrays.cpp

Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -235,9 +235,6 @@
  // ref-note {{in call to 'BU()'}}
 
 namespace IncDec {
-  // FIXME: Pointer arithmethic needs to be supported in inc/dec
-  //   unary operators
-#if 0
   constexpr int getNextElem(const int *A, int I) {
 const int *B = (A + I);
 ++B;
@@ -245,6 +242,91 @@
   }
   constexpr int E[] = {1,2,3,4};
 
-  static_assert(getNextElem(E, 1) == 3);
-#endif
+  static_assert(getNextElem(E, 1) == 3, "");
+
+  constexpr int getFirst() {
+const int *e = E;
+return *(e++);
+  }
+  static_assert(getFirst() == 1, "");
+
+  constexpr int getFirst2() {
+const int *e = E;
+e++;
+return *e;
+  }
+  static_assert(getFirst2() == 2, "");
+
+  constexpr int getSecond() {
+const int *e = E;
+return *(++e);
+  }
+  static_assert(getSecond() == 2, "");
+
+  constexpr int getSecond2() {
+const int *e = E;
+++e;
+return *e;
+  }
+  static_assert(getSecond2() == 2, "");
+
+  constexpr int getLast() {
+const int *e = E + 3;
+return *(e--);
+  }
+  static_assert(getLast() == 4, "");
+
+  constexpr int getLast2() {
+const int *e = E + 3;
+e--;
+return *e;
+  }
+  static_assert(getLast2() == 3, "");
+
+  constexpr int getSecondToLast() {
+const int *e = E + 3;
+return *(--e);
+  }
+  static_assert(getSecondToLast() == 3, "");
+
+  constexpr int getSecondToLast2() {
+const int *e = E + 3;
+--e;
+return *e;
+  }
+  static_assert(getSecondToLast2() == 3, "");
+
+  constexpr int bad1() { // ref-error {{never produces a constant expression}}
+const int *e =  E + 3;
+e++; // This is fine because it's a one-past-the-end pointer
+return *e; // expected-note {{read of dereferenced one-past-the-end pointer}} \
+   // ref-note 2{{read of dereferenced one-past-the-end pointer}}
+  }
+  static_assert(bad1() == 0, ""); // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to}} \
+  // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to}}
+
+  constexpr int bad2() { // ref-error {{never produces a constant expression}}
+const int *e = E + 4;
+e++; // expected-note {{cannot refer to element 5 of array of 4 elements}} \
+ // ref-note 2{{cannot refer to element 5 of array of 4 elements}}
+return *e; // This is UB as well
+  }
+  static_assert(bad2() == 0, ""); // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to}} \
+  // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to}}
+
+
+  constexpr int bad3() { // ref-error {{never produces a constant expression}}
+const int *e = E;
+e--; // expected-note {{cannot refer to element -1 of array of 4 elements}} \
+ // ref-note 2{{cannot refer to element -1 of array of 4 elements}}
+return *e; // This is UB as well
+  }
+   static_assert(bad3() == 0, ""); // expected-error {{not an integral constant expression}} \
+   // expected-note {{in call to}} \
+   // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to}}
 };
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -393,12 +393,21 @@
 // [Pointer, Integral] -> [Pointer]
 def SubOffset : AluOpcode;
 
-// Pointer, Pointer] - [Integral]
+// [Pointer, Pointer] -> [Integral]
 def SubPtr : Opcode {
   let Types = [IntegerTypeClass];
   let HasGroup = 1;
 }
 
+// [Pointer] -> [Pointer]
+def IncPtr : Opcode {
+  let HasGroup = 0;
+}
+// [Pointer] -> [Pointer]
+def DecPtr : Opcode {
+  let HasGroup = 0;
+}
+
 //===--===//
 // Binary operators.
 //===--===//
Index: clang/lib/AST/Interp/Interp.h

[clang] 7348bb3 - [clang][Interp] Support inc/dec operators for pointers

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T11:57:05+01:00
New Revision: 7348bb36c5570e718469f043504e80491bb7f12b

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

LOG: [clang][Interp] Support inc/dec operators for pointers

Differential Revision: https://reviews.llvm.org/D137232

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/arrays.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index fa2c74c4e1a5..dd7d88ae715d 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1333,24 +1333,44 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
   const Expr *SubExpr = E->getSubExpr();
   std::optional T = classify(SubExpr->getType());
 
-  // TODO: Support pointers for inc/dec operators.
   switch (E->getOpcode()) {
   case UO_PostInc: { // x++
 if (!this->visit(SubExpr))
   return false;
 
+if (T == PT_Ptr) {
+  if (!this->emitIncPtr(E))
+return false;
+
+  return DiscardResult ? this->emitPopPtr(E) : true;
+}
+
 return DiscardResult ? this->emitIncPop(*T, E) : this->emitInc(*T, E);
   }
   case UO_PostDec: { // x--
 if (!this->visit(SubExpr))
   return false;
 
+if (T == PT_Ptr) {
+  if (!this->emitDecPtr(E))
+return false;
+
+  return DiscardResult ? this->emitPopPtr(E) : true;
+}
+
 return DiscardResult ? this->emitDecPop(*T, E) : this->emitDec(*T, E);
   }
   case UO_PreInc: { // ++x
 if (!this->visit(SubExpr))
   return false;
 
+if (T == PT_Ptr) {
+  this->emitLoadPtr(E);
+  this->emitConstUint8(1, E);
+  this->emitAddOffsetUint8(E);
+  return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
+}
+
 // Post-inc and pre-inc are the same if the value is to be discarded.
 if (DiscardResult)
   return this->emitIncPop(*T, E);
@@ -1364,6 +1384,13 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
 if (!this->visit(SubExpr))
   return false;
 
+if (T == PT_Ptr) {
+  this->emitLoadPtr(E);
+  this->emitConstUint8(1, E);
+  this->emitSubOffsetUint8(E);
+  return DiscardResult ? this->emitStorePopPtr(E) : this->emitStorePtr(E);
+}
+
 // Post-dec and pre-dec are the same if the value is to be discarded.
 if (DiscardResult)
   return this->emitDecPop(*T, E);

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index ed3accd98a90..9433652f1526 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -140,6 +140,8 @@ bool CheckDivRem(InterpState &S, CodePtr OpPC, const T 
&LHS, const T &RHS) {
 /// Interpreter entry point.
 bool Interpret(InterpState &S, APValue &Result);
 
+enum class ArithOp { Add, Sub };
+
 
//===--===//
 // Add, Sub, Mul
 
//===--===//
@@ -1112,6 +1114,34 @@ bool SubOffset(InterpState &S, CodePtr OpPC) {
   return OffsetHelper(S, OpPC);
 }
 
+template 
+static inline bool IncDecPtrHelper(InterpState &S, CodePtr OpPC) {
+  using OneT = Integral<8, false>;
+  const Pointer &Ptr = S.Stk.pop();
+
+  // Get the current value on the stack.
+  S.Stk.push(Ptr.deref());
+
+  // Now the current Ptr again and a constant 1.
+  // FIXME: We shouldn't have to push these two on the stack.
+  S.Stk.push(Ptr.deref());
+  S.Stk.push(OneT::from(1));
+  if (!OffsetHelper(S, OpPC))
+return false;
+
+  // Store the new value.
+  Ptr.deref() = S.Stk.pop();
+  return true;
+}
+
+static inline bool IncPtr(InterpState &S, CodePtr OpPC) {
+  return IncDecPtrHelper(S, OpPC);
+}
+
+static inline bool DecPtr(InterpState &S, CodePtr OpPC) {
+  return IncDecPtrHelper(S, OpPC);
+}
+
 /// 1) Pops a Pointer from the stack.
 /// 2) Pops another Pointer from the stack.
 /// 3) Pushes the 
diff erent of the indices of the two pointers on the stack.

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 058475b2d399..07facb6a6024 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -393,12 +393,21 @@ def AddOffset : AluOpcode;
 // [Pointer, Integral] -> [Pointer]
 def SubOffset : AluOpcode;
 
-// Pointer, Pointer] - [Integral]
+// [Pointer, Pointer] -> [Integral]
 def SubPtr : Opcode {
   let Types = [IntegerTypeClass];
   let HasGroup = 1;
 }
 
+// [Pointer] -> [Pointer]
+def IncPtr : Opcode {
+  let HasGroup = 0;
+}
+// [Pointer] -> [Pointer]
+def DecPtr : Opcode {
+  let HasGroup = 0;
+}
+
 
//===--

[clang] fb6c130 - [LTO] Remove -lto-opaque-pointers flag

2023-01-25 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2023-01-25T12:18:50+01:00
New Revision: fb6c1300f23f249aa29eb6c5325aebc7d61d7345

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

LOG: [LTO] Remove -lto-opaque-pointers flag

Always use the config default of OpaquePointers == true.

Added: 


Modified: 
clang/test/CodeGen/thinlto-inline-asm2.c
clang/test/Driver/arm-float-abi-lto.c
clang/test/Driver/memtag-stack_lto.c
llvm/test/LTO/X86/mix-opaque-typed.ll
llvm/tools/llvm-lto2/llvm-lto2.cpp

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-inline-asm2.c 
b/clang/test/CodeGen/thinlto-inline-asm2.c
index 7606b27deac87..5d7bbc097de7c 100644
--- a/clang/test/CodeGen/thinlto-inline-asm2.c
+++ b/clang/test/CodeGen/thinlto-inline-asm2.c
@@ -5,7 +5,7 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -flto=thin -emit-llvm-bc 
%t/b.c -o %t/b.bc
 // RUN: llvm-nm %t/a.bc | FileCheck %s --check-prefix=NM
 
-// RUN: llvm-lto2 run -lto-opaque-pointers %t/a.bc %t/b.bc -o %t/out 
-save-temps -r=%t/a.bc,ref,plx -r=%t/b.bc,ff_h264_cabac_tables,pl
+// RUN: llvm-lto2 run %t/a.bc %t/b.bc -o %t/out -save-temps -r=%t/a.bc,ref,plx 
-r=%t/b.bc,ff_h264_cabac_tables,pl
 // RUN: llvm-dis < %t/out.2.2.internalize.bc | FileCheck %s
 
 //--- a.c

diff  --git a/clang/test/Driver/arm-float-abi-lto.c 
b/clang/test/Driver/arm-float-abi-lto.c
index 8b6d8ff6b5d7a..b8788f485cbff 100644
--- a/clang/test/Driver/arm-float-abi-lto.c
+++ b/clang/test/Driver/arm-float-abi-lto.c
@@ -4,7 +4,7 @@
 
 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s 
-Xclang -opaque-pointers -flto=full -c -o %t.call_full.bc -DCALL_LIB
 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s 
-Xclang -opaque-pointers -flto=full -c -o %t.define_full.bc -DDEFINE_LIB
-// RUN: llvm-lto2 run -lto-opaque-pointers -o %t.lto_full -save-temps 
%t.call_full.bc %t.define_full.bc \
+// RUN: llvm-lto2 run -o %t.lto_full -save-temps %t.call_full.bc 
%t.define_full.bc \
 // RUN:  -r %t.call_full.bc,fn,px \
 // RUN:  -r %t.call_full.bc,fwrite,l \
 // RUN:  -r %t.call_full.bc,putchar,l \
@@ -16,7 +16,7 @@
 
 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s 
-Xclang -opaque-pointers -flto=thin -c -o %t.call_thin.bc -DCALL_LIB
 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s 
-Xclang -opaque-pointers -flto=thin -c -o %t.define_thin.bc -DDEFINE_LIB
-// RUN: llvm-lto2 run -lto-opaque-pointers -o %t.lto_thin -save-temps 
%t.call_thin.bc %t.define_thin.bc \
+// RUN: llvm-lto2 run -o %t.lto_thin -save-temps %t.call_thin.bc 
%t.define_thin.bc \
 // RUN:  -r %t.call_thin.bc,fn,px \
 // RUN:  -r %t.call_thin.bc,fwrite,l \
 // RUN:  -r %t.call_thin.bc,putchar,l \

diff  --git a/clang/test/Driver/memtag-stack_lto.c 
b/clang/test/Driver/memtag-stack_lto.c
index 2fe15a119d2a7..3cafe83069a0b 100644
--- a/clang/test/Driver/memtag-stack_lto.c
+++ b/clang/test/Driver/memtag-stack_lto.c
@@ -10,7 +10,7 @@
 // Full LTO
 // RUN: %clang -O1 -target aarch64-unknown-linux -c %s -Xclang 
-opaque-pointers -flto=full -o %t.ltonewpm1.bc
 // RUN: %clang -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -Xclang 
-opaque-pointers -flto=full -o %t.ltonewpm2.bc
-// RUN: llvm-lto2 run -lto-opaque-pointers -o %t.ltonewpm %t.ltonewpm1.bc 
%t.ltonewpm2.bc -save-temps -stack-safety-print -thinlto-threads 1 -O1 \
+// RUN: llvm-lto2 run -o %t.ltonewpm %t.ltonewpm1.bc %t.ltonewpm2.bc 
-save-temps -stack-safety-print -thinlto-threads 1 -O1 \
 // RUN:  -r %t.ltonewpm1.bc,fn,plx \
 // RUN:  -r %t.ltonewpm1.bc,use,lx \
 // RUN:  -r %t.ltonewpm1.bc,use_local,plx \
@@ -21,7 +21,7 @@
 // Thin LTO, new PM
 // RUN: %clang -O1 -target aarch64-unknown-linux -c %s -Xclang 
-opaque-pointers -flto=thin -o %t.thinltonewpm1.bc
 // RUN: %clang -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -Xclang 
-opaque-pointers -flto=thin -o %t.thinltonewpm2.bc
-// RUN: llvm-lto2 run -lto-opaque-pointers -o %t.thinltonewpm 
%t.thinltonewpm1.bc %t.thinltonewpm2.bc -save-temps -stack-safety-print 
-thinlto-threads 1 -O1 \
+// RUN: llvm-lto2 run -o %t.thinltonewpm %t.thinltonewpm1.bc 
%t.thinltonewpm2.bc -save-temps -stack-safety-print -thinlto-threads 1 -O1 \
 // RUN:  -r %t.thinltonewpm1.bc,fn,plx \
 // RUN:  -r %t.thinltonewpm1.bc,use,lx \
 // RUN:  -r %t.thinltonewpm1.bc,use_local,plx \
@@ -41,7 +41,7 @@
 // Full LTO: both are safe.
 // RUN: %clang -O1 -target aarch64-unknown-linux -march=armv8+memtag 
-fsanitize=memtag-stack -c %s -Xclang -opaque-pointers -flto=full -o 
%t.ltonewpm1.bc
 // RUN: %clang -O1 -target aarch64-unknown-linux -march=armv8+memtag 
-fsanitize=memtag-stack -c -DBUILD2 %s -Xclang -opaque-pointers -flto=full -o 
%t.ltonewpm2.bc
-// RUN: llvm-lto2 run -lto-opaque-pointers -o %t.ltonewpm %t.lton

[clang] 2725e2c - [clang][Interp] Fix ImplicitValueInitExprs for pointer types

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T12:31:49+01:00
New Revision: 2725e2c0323f1408467452e3cc2a4a8cb3ea49a7

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

LOG: [clang][Interp] Fix ImplicitValueInitExprs for pointer types

This previously ran into an "unknown type" assertion when trying to emit
a 'Zero' op for a pointer type. Emit a NullPtr op instead.

Differential Revision: https://reviews.llvm.org/D137235

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index dd7d88ae715d..5952e3aa681c 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -279,10 +279,15 @@ bool 
ByteCodeExprGen::VisitPointerArithBinOp(const BinaryOperator *E) {
 
 template 
 bool ByteCodeExprGen::VisitImplicitValueInitExpr(const 
ImplicitValueInitExpr *E) {
-  if (std::optional T = classify(E))
-return this->emitZero(*T, E);
+  std::optional T = classify(E);
 
-  return false;
+  if (!T)
+return false;
+
+  if (E->getType()->isPointerType())
+return this->emitNullPtr(E);
+
+  return this->emitZero(*T, E);
 }
 
 template 

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 4fc9489941e5..4c88e861a443 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -49,7 +49,10 @@ namespace IntegralCasts {
   static_assert(!nu, "");
 };
 
-
+constexpr int UninitI; // expected-error {{must be initialized by a constant 
expression}} \
+   // ref-error {{must be initialized by a constant 
expression}}
+constexpr int *UninitPtr; // expected-error {{must be initialized by a 
constant expression}} \
+  // ref-error {{must be initialized by a constant 
expression}}
 
 constexpr bool getTrue() { return true; }
 constexpr bool getFalse() { return false; }



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


[PATCH] D137235: [clang][Interp] Fix ImplicitValueInitExprs for pointer types

2023-01-25 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2725e2c0323f: [clang][Interp] Fix ImplicitValueInitExprs for 
pointer types (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D137235?vs=472545&id=492049#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137235/new/

https://reviews.llvm.org/D137235

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/literals.cpp


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -49,7 +49,10 @@
   static_assert(!nu, "");
 };
 
-
+constexpr int UninitI; // expected-error {{must be initialized by a constant 
expression}} \
+   // ref-error {{must be initialized by a constant 
expression}}
+constexpr int *UninitPtr; // expected-error {{must be initialized by a 
constant expression}} \
+  // ref-error {{must be initialized by a constant 
expression}}
 
 constexpr bool getTrue() { return true; }
 constexpr bool getFalse() { return false; }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -279,10 +279,15 @@
 
 template 
 bool ByteCodeExprGen::VisitImplicitValueInitExpr(const 
ImplicitValueInitExpr *E) {
-  if (std::optional T = classify(E))
-return this->emitZero(*T, E);
+  std::optional T = classify(E);
 
-  return false;
+  if (!T)
+return false;
+
+  if (E->getType()->isPointerType())
+return this->emitNullPtr(E);
+
+  return this->emitZero(*T, E);
 }
 
 template 


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -49,7 +49,10 @@
   static_assert(!nu, "");
 };
 
-
+constexpr int UninitI; // expected-error {{must be initialized by a constant expression}} \
+   // ref-error {{must be initialized by a constant expression}}
+constexpr int *UninitPtr; // expected-error {{must be initialized by a constant expression}} \
+  // ref-error {{must be initialized by a constant expression}}
 
 constexpr bool getTrue() { return true; }
 constexpr bool getFalse() { return false; }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -279,10 +279,15 @@
 
 template 
 bool ByteCodeExprGen::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) {
-  if (std::optional T = classify(E))
-return this->emitZero(*T, E);
+  std::optional T = classify(E);
 
-  return false;
+  if (!T)
+return false;
+
+  if (E->getType()->isPointerType())
+return this->emitNullPtr(E);
+
+  return this->emitZero(*T, E);
 }
 
 template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f4a6842 - [clang][Interp] Reject invalid declarations and expressions

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T12:52:44+01:00
New Revision: f4a6842c5a4d729bacfd0240b44fa726a28e6bfb

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

LOG: [clang][Interp] Reject invalid declarations and expressions

Reject them early, since we will run into problems and/or assertions
later on anyway.

Differential Revision: https://reviews.llvm.org/D137386

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 5952e3aa681c..d28b89381b87 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -588,12 +588,18 @@ bool 
ByteCodeExprGen::VisitCompoundAssignOperator(
 }
 
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
+  if (E->containsErrors())
+return false;
+
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
 }
 
 template 
 bool ByteCodeExprGen::visit(const Expr *E) {
+  if (E->containsErrors())
+return false;
+
   OptionScope Scope(this, /*NewDiscardResult=*/false);
   return this->Visit(E);
 }
@@ -1156,6 +1162,7 @@ bool ByteCodeExprGen::visitExpr(const Expr *Exp) 
{
 /// We need to evaluate the initializer and return its value.
 template 
 bool ByteCodeExprGen::visitDecl(const VarDecl *VD) {
+  assert(!VD->isInvalidDecl() && "Trying to constant evaluate an invalid 
decl");
   std::optional VarT = classify(VD->getType());
 
   // Create and initialize the variable.

diff  --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index e372f23987e2..4fb5d3d98d74 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -84,3 +84,18 @@ constexpr int f() {
   return 5;
 }
 static_assert(a() == 5, "");
+
+constexpr int invalid() {
+  // Invalid expression in visit().
+  while(huh) {} // expected-error {{use of undeclared identifier}} \
+// ref-error {{use of undeclared identifier}}
+
+  return 0;
+}
+
+constexpr void invalid2() {
+  int i = 0;
+  // Invalid expression in discard().
+  huh(); // expected-error {{use of undeclared identifier}} \
+ // ref-error {{use of undeclared identifier}}
+}



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


[PATCH] D137386: [clang][Interp] Reject invalid declarations and expressions

2023-01-25 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf4a6842c5a4d: [clang][Interp] Reject invalid declarations 
and expressions (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D137386?vs=474727&id=492054#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137386/new/

https://reviews.llvm.org/D137386

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/functions.cpp


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -84,3 +84,18 @@
   return 5;
 }
 static_assert(a() == 5, "");
+
+constexpr int invalid() {
+  // Invalid expression in visit().
+  while(huh) {} // expected-error {{use of undeclared identifier}} \
+// ref-error {{use of undeclared identifier}}
+
+  return 0;
+}
+
+constexpr void invalid2() {
+  int i = 0;
+  // Invalid expression in discard().
+  huh(); // expected-error {{use of undeclared identifier}} \
+ // ref-error {{use of undeclared identifier}}
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -588,12 +588,18 @@
 }
 
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
+  if (E->containsErrors())
+return false;
+
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
 }
 
 template 
 bool ByteCodeExprGen::visit(const Expr *E) {
+  if (E->containsErrors())
+return false;
+
   OptionScope Scope(this, /*NewDiscardResult=*/false);
   return this->Visit(E);
 }
@@ -1156,6 +1162,7 @@
 /// We need to evaluate the initializer and return its value.
 template 
 bool ByteCodeExprGen::visitDecl(const VarDecl *VD) {
+  assert(!VD->isInvalidDecl() && "Trying to constant evaluate an invalid 
decl");
   std::optional VarT = classify(VD->getType());
 
   // Create and initialize the variable.


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -84,3 +84,18 @@
   return 5;
 }
 static_assert(a() == 5, "");
+
+constexpr int invalid() {
+  // Invalid expression in visit().
+  while(huh) {} // expected-error {{use of undeclared identifier}} \
+// ref-error {{use of undeclared identifier}}
+
+  return 0;
+}
+
+constexpr void invalid2() {
+  int i = 0;
+  // Invalid expression in discard().
+  huh(); // expected-error {{use of undeclared identifier}} \
+ // ref-error {{use of undeclared identifier}}
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -588,12 +588,18 @@
 }
 
 template  bool ByteCodeExprGen::discard(const Expr *E) {
+  if (E->containsErrors())
+return false;
+
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
 }
 
 template 
 bool ByteCodeExprGen::visit(const Expr *E) {
+  if (E->containsErrors())
+return false;
+
   OptionScope Scope(this, /*NewDiscardResult=*/false);
   return this->Visit(E);
 }
@@ -1156,6 +1162,7 @@
 /// We need to evaluate the initializer and return its value.
 template 
 bool ByteCodeExprGen::visitDecl(const VarDecl *VD) {
+  assert(!VD->isInvalidDecl() && "Trying to constant evaluate an invalid decl");
   std::optional VarT = classify(VD->getType());
 
   // Create and initialize the variable.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 024e4f1 - [clang][Interp] Implement switch statements

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T13:21:24+01:00
New Revision: 024e4f16ca795b98a5dea371cab623f851858925

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

LOG: [clang][Interp] Implement switch statements

Differential Revision: https://reviews.llvm.org/D137415

Added: 
clang/test/AST/Interp/switch.cpp

Modified: 
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/ByteCodeStmtGen.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index af97c57c98b7..ed8794f49a64 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -182,6 +182,12 @@ bool ByteCodeStmtGen::visitStmt(const Stmt *S) {
 return visitBreakStmt(cast(S));
   case Stmt::ContinueStmtClass:
 return visitContinueStmt(cast(S));
+  case Stmt::SwitchStmtClass:
+return visitSwitchStmt(cast(S));
+  case Stmt::CaseStmtClass:
+return visitCaseStmt(cast(S));
+  case Stmt::DefaultStmtClass:
+return visitDefaultStmt(cast(S));
   case Stmt::NullStmtClass:
 return true;
   default: {
@@ -391,6 +397,84 @@ bool ByteCodeStmtGen::visitContinueStmt(const 
ContinueStmt *S) {
   return this->jump(*ContinueLabel);
 }
 
+template 
+bool ByteCodeStmtGen::visitSwitchStmt(const SwitchStmt *S) {
+  const Expr *Cond = S->getCond();
+  PrimType CondT = this->classifyPrim(Cond->getType());
+
+  LabelTy EndLabel = this->getLabel();
+  OptLabelTy DefaultLabel = std::nullopt;
+  unsigned CondVar = this->allocateLocalPrimitive(Cond, CondT, true, false);
+
+  if (const auto *CondInit = S->getInit())
+if (!visitStmt(CondInit))
+  return false;
+
+  // Initialize condition variable.
+  if (!this->visit(Cond))
+return false;
+  if (!this->emitSetLocal(CondT, CondVar, S))
+return false;
+
+  CaseMap CaseLabels;
+  // Create labels and comparison ops for all case statements.
+  for (const SwitchCase *SC = S->getSwitchCaseList(); SC;
+   SC = SC->getNextSwitchCase()) {
+if (const auto *CS = dyn_cast(SC)) {
+  // FIXME: Implement ranges.
+  if (CS->caseStmtIsGNURange())
+return false;
+  CaseLabels[SC] = this->getLabel();
+
+  const Expr *Value = CS->getLHS();
+  PrimType ValueT = this->classifyPrim(Value->getType());
+
+  // Compare the case statment's value to the switch condition.
+  if (!this->emitGetLocal(CondT, CondVar, CS))
+return false;
+  if (!this->visit(Value))
+return false;
+
+  // Compare and jump to the case label.
+  if (!this->emitEQ(ValueT, S))
+return false;
+  if (!this->jumpTrue(CaseLabels[CS]))
+return false;
+} else {
+  assert(!DefaultLabel);
+  DefaultLabel = this->getLabel();
+}
+  }
+
+  // If none of the conditions above were true, fall through to the default
+  // statement or jump after the switch statement.
+  if (DefaultLabel) {
+if (!this->jump(*DefaultLabel))
+  return false;
+  } else {
+if (!this->jump(EndLabel))
+  return false;
+  }
+
+  SwitchScope SS(this, std::move(CaseLabels), EndLabel, DefaultLabel);
+  if (!this->visitStmt(S->getBody()))
+return false;
+  this->emitLabel(EndLabel);
+  return true;
+}
+
+template 
+bool ByteCodeStmtGen::visitCaseStmt(const CaseStmt *S) {
+  this->emitLabel(CaseLabels[S]);
+  return this->visitStmt(S->getSubStmt());
+}
+
+template 
+bool ByteCodeStmtGen::visitDefaultStmt(const DefaultStmt *S) {
+  this->emitLabel(*DefaultLabel);
+  return this->visitStmt(S->getSubStmt());
+}
+
 namespace clang {
 namespace interp {
 

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h 
b/clang/lib/AST/Interp/ByteCodeStmtGen.h
index 829e199f827c..7a30f7b69470 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -62,6 +62,9 @@ class ByteCodeStmtGen final : public ByteCodeExprGen 
{
   bool visitForStmt(const ForStmt *S);
   bool visitBreakStmt(const BreakStmt *S);
   bool visitContinueStmt(const ContinueStmt *S);
+  bool visitSwitchStmt(const SwitchStmt *S);
+  bool visitCaseStmt(const CaseStmt *S);
+  bool visitDefaultStmt(const DefaultStmt *S);
 
   /// Type of the expression returned by the function.
   std::optional ReturnType;

diff  --git a/clang/test/AST/Interp/switch.cpp 
b/clang/test/AST/Interp/switch.cpp
new file mode 100644
index ..17cae3aadc35
--- /dev/null
+++ b/clang/test/AST/Interp/switch.cpp
@@ -0,0 +1,94 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+constexpr bool isEven(int a) {
+  bool v = false;
+  switch(a) {
+  case 2: return true;
+  case 4: return true;
+  case 6: return true;
+
+  case 8:
+  case 10:
+  case 12:
+  case 14:
+  case 16:
+return true;
+  case 18:

[PATCH] D137415: [clang][Interp] Implement switch statements

2023-01-25 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG024e4f16ca79: [clang][Interp] Implement switch statements 
(authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D137415?vs=478895&id=492062#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137415/new/

https://reviews.llvm.org/D137415

Files:
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h
  clang/test/AST/Interp/switch.cpp

Index: clang/test/AST/Interp/switch.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/switch.cpp
@@ -0,0 +1,94 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+constexpr bool isEven(int a) {
+  bool v = false;
+  switch(a) {
+  case 2: return true;
+  case 4: return true;
+  case 6: return true;
+
+  case 8:
+  case 10:
+  case 12:
+  case 14:
+  case 16:
+return true;
+  case 18:
+v = true;
+break;
+
+  default:
+  switch(a) {
+  case 1:
+break;
+  case 3:
+return false;
+  default:
+break;
+  }
+  }
+
+  return v;
+}
+static_assert(isEven(2), "");
+static_assert(isEven(8), "");
+static_assert(isEven(10), "");
+static_assert(isEven(18), "");
+static_assert(!isEven(1), "");
+static_assert(!isEven(3), "");
+
+
+constexpr int withInit() {
+  switch(int a = 2; a) {
+case 1: return -1;
+case 2: return 2;
+  }
+  return -1;
+}
+static_assert(withInit() == 2, "");
+
+constexpr int FT(int a) {
+  int m = 0;
+  switch(a) {
+  case 4: m++;
+  case 3: m++;
+  case 2: m++;
+  case 1: m++;
+return m;
+  }
+
+  return -1;
+}
+static_assert(FT(1) == 1, "");
+static_assert(FT(4) == 4, "");
+static_assert(FT(5) == -1, "");
+
+
+constexpr int good() { return 1; }
+constexpr int test(int val) {
+  switch (val) {
+  case good(): return 100;
+  default: return -1;
+  }
+  return 0;
+}
+static_assert(test(1) == 100, "");
+
+constexpr int bad(int val) { return val / 0; } // expected-warning {{division by zero}} \
+   // ref-warning {{division by zero}}
+constexpr int another_test(int val) { // expected-note {{declared here}} \
+  // ref-note {{declared here}}
+  switch (val) {
+  case bad(val): return 100; // expected-error {{case value is not a constant expression}} \
+ // expected-note {{cannot be used in a constant expression}} \
+ // ref-error {{case value is not a constant expression}} \
+ // ref-note {{cannot be used in a constant expression}}
+  default: return -1;
+  }
+  return 0;
+}
+static_assert(another_test(1) == 100, ""); // expected-error {{static assertion failed}} \
+   // expected-note {{evaluates to}} \
+   // ref-error {{static assertion failed}} \
+   // ref-note {{evaluates to}}
Index: clang/lib/AST/Interp/ByteCodeStmtGen.h
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -62,6 +62,9 @@
   bool visitForStmt(const ForStmt *S);
   bool visitBreakStmt(const BreakStmt *S);
   bool visitContinueStmt(const ContinueStmt *S);
+  bool visitSwitchStmt(const SwitchStmt *S);
+  bool visitCaseStmt(const CaseStmt *S);
+  bool visitDefaultStmt(const DefaultStmt *S);
 
   /// Type of the expression returned by the function.
   std::optional ReturnType;
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -182,6 +182,12 @@
 return visitBreakStmt(cast(S));
   case Stmt::ContinueStmtClass:
 return visitContinueStmt(cast(S));
+  case Stmt::SwitchStmtClass:
+return visitSwitchStmt(cast(S));
+  case Stmt::CaseStmtClass:
+return visitCaseStmt(cast(S));
+  case Stmt::DefaultStmtClass:
+return visitDefaultStmt(cast(S));
   case Stmt::NullStmtClass:
 return true;
   default: {
@@ -391,6 +397,84 @@
   return this->jump(*ContinueLabel);
 }
 
+template 
+bool ByteCodeStmtGen::visitSwitchStmt(const SwitchStmt *S) {
+  const Expr *Cond = S->getCond();
+  PrimType CondT = this->classifyPrim(Cond->getType());
+
+  LabelTy EndLabel = this->getLabel();
+  OptLabelTy DefaultLabel = std::nullopt;
+  unsigned CondVar = this->allocateLocalPrimitive(Cond, CondT, true, false);
+
+  if (const auto *CondInit = S->getInit())
+if (!visitStmt(CondInit))
+  return false;
+
+  // Initialize condition variable.
+  if (!this->visit(Cond))
+return false;
+  if (!this->emitSetLocal(CondT, CondVar, S))
+return false;
+
+  CaseMap CaseLabels;
+  // Cre

[clang] 1a84036 - [clang][Interp] Specify c++ standard used in switch test

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T13:33:25+01:00
New Revision: 1a84036bb979c0ef34a8add2fe27ad9f0cb50b99

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

LOG: [clang][Interp] Specify c++ standard used in switch test

As a follow up for 024e4f16ca795b98a5dea371cab623f851858925.

This should fix builders defaulting to pre-c++17.
E.g. https://lab.llvm.org/buildbot/#/builders/139/builds/34918

Added: 


Modified: 
clang/test/AST/Interp/switch.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/switch.cpp 
b/clang/test/AST/Interp/switch.cpp
index 17cae3aadc35..79b630f80074 100644
--- a/clang/test/AST/Interp/switch.cpp
+++ b/clang/test/AST/Interp/switch.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
-// RUN: %clang_cc1 -verify=ref %s
+// RUN: %clang_cc1 -std=c++17 -fexperimental-new-constant-interpreter -verify 
%s
+// RUN: %clang_cc1 -std=c++17 -verify=ref %s
 
 constexpr bool isEven(int a) {
   bool v = false;



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


[PATCH] D142534: Fix emission of consteval constructor of derived type

2023-01-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For simple derived type ConstantEmitter returns a struct of the same
size but different type which is then stored field-by-field into memory
via pointer to derived type. In case base type has more fields than derived,
the incorrect GEP is emitted. So, just cast pointer to derived type to
appropriate type with enough fields.

Fixes #60166


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142534

Files:
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/test/CodeGenCXX/cxx20-consteval-crash.cpp


Index: clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
===
--- clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
+++ clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
@@ -92,3 +92,27 @@
 }
 } // namespace Issue55065
 
+namespace Issue60166 {
+
+struct Base {
+   void* one = nullptr;
+   void* two = nullptr;
+};
+
+struct Derived : Base {
+   void* three = nullptr;
+   consteval Derived() = default;
+};
+
+void method() {
+  // CHECK: %agg.tmp.ensured = alloca %"struct.Issue60166::Derived"
+  // CHECK: %0 = getelementptr inbounds { ptr, ptr, ptr }, ptr 
%agg.tmp.ensured, i32 0, i32 0
+  // CHECK: store ptr null, ptr %0, align 8
+  // CHECK: %1 = getelementptr inbounds { ptr, ptr, ptr }, ptr 
%agg.tmp.ensured, i32 0, i32 1
+  // CHECK: store ptr null, ptr %1, align 8
+  // CHECK: %2 = getelementptr inbounds { ptr, ptr, ptr }, ptr 
%agg.tmp.ensured, i32 0, i32 2
+  // CHECK: store ptr null, ptr %2, align 8
+   (void)Derived();
+}
+
+} // namespace Issue60166
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -131,7 +131,14 @@
 EnsureDest(E->getType());
 
 if (llvm::Value *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
-  CGF.EmitAggregateStore(Result, Dest.getAddress(),
+  Address StoreDest = Dest.getAddress();
+  // The emitted value is guaranteed to have the same size as the
+  // destination but can have a different type. Just do a bitcast in this
+  // case to avoid incorrect GEPs.
+  if (Result->getType() != StoreDest.getType())
+StoreDest =
+CGF.Builder.CreateElementBitCast(StoreDest, Result->getType());
+  CGF.EmitAggregateStore(Result, StoreDest,
  E->getType().isVolatileQualified());
   return;
 }


Index: clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
===
--- clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
+++ clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
@@ -92,3 +92,27 @@
 }
 } // namespace Issue55065
 
+namespace Issue60166 {
+
+struct Base {
+   void* one = nullptr;
+   void* two = nullptr;
+};
+
+struct Derived : Base {
+   void* three = nullptr;
+   consteval Derived() = default;
+};
+
+void method() {
+  // CHECK: %agg.tmp.ensured = alloca %"struct.Issue60166::Derived"
+  // CHECK: %0 = getelementptr inbounds { ptr, ptr, ptr }, ptr %agg.tmp.ensured, i32 0, i32 0
+  // CHECK: store ptr null, ptr %0, align 8
+  // CHECK: %1 = getelementptr inbounds { ptr, ptr, ptr }, ptr %agg.tmp.ensured, i32 0, i32 1
+  // CHECK: store ptr null, ptr %1, align 8
+  // CHECK: %2 = getelementptr inbounds { ptr, ptr, ptr }, ptr %agg.tmp.ensured, i32 0, i32 2
+  // CHECK: store ptr null, ptr %2, align 8
+   (void)Derived();
+}
+
+} // namespace Issue60166
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -131,7 +131,14 @@
 EnsureDest(E->getType());
 
 if (llvm::Value *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
-  CGF.EmitAggregateStore(Result, Dest.getAddress(),
+  Address StoreDest = Dest.getAddress();
+  // The emitted value is guaranteed to have the same size as the
+  // destination but can have a different type. Just do a bitcast in this
+  // case to avoid incorrect GEPs.
+  if (Result->getType() != StoreDest.getType())
+StoreDest =
+CGF.Builder.CreateElementBitCast(StoreDest, Result->getType());
+  CGF.EmitAggregateStore(Result, StoreDest,
  E->getType().isVolatileQualified());
   return;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133375: [CMake] Remove CLANG_DEFAULT_STD_C/CLANG_DEFAULT_STD_CXX

2023-01-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: clang-vendors.
aaron.ballman added a comment.

In D133375#4079251 , @tambre wrote:

> A Clang 16 release note for this would be nice. I didn't immediately notice 
> and got a bit broken by this change. 🙂

+1 to the request, also adding clang vendors now for early warning despite this 
already being landed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133375/new/

https://reviews.llvm.org/D133375

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


[clang] a7a4463 - [clang][Interp] Start implementing builtin functions

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T14:08:03+01:00
New Revision: a7a4463acbe10d1b5c9eadcd6cb94790caad86e4

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

LOG: [clang][Interp] Start implementing builtin functions

Differential Revision: https://reviews.llvm.org/D137487

Added: 
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/AST/Interp/builtins.cpp

Modified: 
clang/lib/AST/CMakeLists.txt
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/Function.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td

Removed: 




diff  --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index 40a5d6694f83..e4c1008fe34b 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -73,6 +73,7 @@ add_clang_library(clangAST
   Interp/EvalEmitter.cpp
   Interp/Frame.cpp
   Interp/Function.cpp
+  Interp/InterpBuiltin.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d28b89381b87..2581c1c36da2 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1240,9 +1240,35 @@ bool ByteCodeExprGen::visitVarDecl(const 
VarDecl *VD) {
   return false;
 }
 
+template 
+bool ByteCodeExprGen::VisitBuiltinCallExpr(const CallExpr *E) {
+  const Function *Func = getFunction(E->getDirectCallee());
+  if (!Func)
+return false;
+
+  // Put arguments on the stack.
+  for (const auto *Arg : E->arguments()) {
+if (!this->visit(Arg))
+  return false;
+  }
+
+  if (!this->emitCallBI(Func, E))
+return false;
+
+  if (DiscardResult) {
+QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
+PrimType T = classifyPrim(ReturnType);
+
+return this->emitPop(T, E);
+  }
+
+  return true;
+}
+
 template 
 bool ByteCodeExprGen::VisitCallExpr(const CallExpr *E) {
-  assert(!E->getBuiltinCallee() && "Builtin functions aren't supported yet");
+  if (E->getBuiltinCallee())
+return VisitBuiltinCallExpr(E);
 
   const Decl *Callee = E->getCalleeDecl();
   if (const auto *FuncDecl = dyn_cast_or_null(Callee)) {
@@ -1276,9 +1302,9 @@ bool ByteCodeExprGen::VisitCallExpr(const 
CallExpr *E) {
 return false;
 }
 
-// In any case call the function. The return value will end up on the 
stack and
-// if the function has RVO, we already have the pointer on the stack to 
write
-// the result into.
+// In any case call the function. The return value will end up on the stack
+// and if the function has RVO, we already have the pointer on the stack to
+// write the result into.
 if (!this->emitCall(Func, E))
   return false;
 

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index c7fcc59e5a60..7af61695864c 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -63,6 +63,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitPointerArithBinOp(const BinaryOperator *E);
   bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E);
   bool VisitCallExpr(const CallExpr *E);
+  bool VisitBuiltinCallExpr(const CallExpr *E);
   bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *E);
   bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E);
   bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E);

diff  --git a/clang/lib/AST/Interp/Function.h b/clang/lib/AST/Interp/Function.h
index 5b2a77f1a12d..434c3f7b0def 100644
--- a/clang/lib/AST/Interp/Function.h
+++ b/clang/lib/AST/Interp/Function.h
@@ -138,6 +138,8 @@ class Function final {
   // Checks if the funtion already has a body attached.
   bool hasBody() const { return HasBody; }
 
+  unsigned getBuiltinID() const { return F->getBuiltinID(); }
+
   unsigned getNumParams() const { return ParamTypes.size(); }
 
 private:

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 9433652f1526..7ee823ef130a 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -140,6 +140,8 @@ bool CheckDivRem(InterpState &S, CodePtr OpPC, const T 
&LHS, const T &RHS) {
 /// Interpreter entry point.
 bool Interpret(InterpState &S, APValue &Result);
 
+bool InterpretBuiltin(InterpState &S, CodePtr PC, unsigned BuiltinID);
+
 enum class ArithOp { Add, Sub };
 
 
//===--===//
@@ -1320,6 +1322,20 @@ inline bool Call(InterpState &S, CodePtr &PC, const 
Function *Func) {
   return false;
 }
 
+inline bool CallBI(InterpState &S, CodePtr &PC, const Function *Func) {
+  auto NewFrame = std::make_unique(S, Func, PC);
+
+  I

[PATCH] D137487: [clang][Interp] Start implementing builtin functions

2023-01-25 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
tbaeder marked an inline comment as done.
Closed by commit rGa7a4463acbe1: [clang][Interp] Start implementing builtin 
functions (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137487/new/

https://reviews.llvm.org/D137487

Files:
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/builtins.cpp

Index: clang/test/AST/Interp/builtins.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/builtins.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated %s -S -emit-llvm -o - | FileCheck %s
+
+// expected-no-diagnostics
+// ref-no-diagnostics
+
+using size_t = decltype(sizeof(int));
+
+namespace std {
+inline constexpr bool is_constant_evaluated() noexcept {
+  return __builtin_is_constant_evaluated();
+}
+} // namespace std
+
+constexpr bool b = std::is_constant_evaluated();
+static_assert(b, "");
+static_assert(std::is_constant_evaluated() , "");
+
+
+bool is_this_constant() {
+  return __builtin_is_constant_evaluated(); // CHECK: ret i1 false
+}
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -164,6 +164,12 @@
   let ChangesPC = 1;
 }
 
+def CallBI : Opcode {
+  let Args = [ArgFunction];
+  let Types = [];
+  let ChangesPC = 1;
+}
+
 //===--===//
 // Frame management
 //===--===//
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- /dev/null
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -0,0 +1,51 @@
+//===--- InterpBuiltin.cpp - Interpreter for the constexpr VM ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "Boolean.h"
+#include "Interp.h"
+#include "PrimType.h"
+#include "clang/Basic/Builtins.h"
+
+namespace clang {
+namespace interp {
+
+/// This is a slightly simplified version of the Ret() we have in Interp.cpp
+/// If they end up diverging in the future, we should get rid of the code
+/// duplication.
+template ::T>
+static bool Ret(InterpState &S, CodePtr &PC) {
+  S.CallStackDepth--;
+  const T &Ret = S.Stk.pop();
+
+  assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame");
+  if (!S.checkingPotentialConstantExpression())
+S.Current->popArgs();
+
+  InterpFrame *Caller = S.Current->Caller;
+  assert(Caller);
+
+  PC = S.Current->getRetPC();
+  delete S.Current;
+  S.Current = Caller;
+  S.Stk.push(Ret);
+
+  return true;
+}
+
+bool InterpretBuiltin(InterpState &S, CodePtr PC, unsigned BuiltinID) {
+  switch (BuiltinID) {
+  case Builtin::BI__builtin_is_constant_evaluated:
+S.Stk.push(Boolean::from(S.inConstantContext()));
+Ret(S, PC);
+return true;
+  }
+
+  return false;
+}
+
+} // namespace interp
+} // namespace clang
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -140,6 +140,8 @@
 /// Interpreter entry point.
 bool Interpret(InterpState &S, APValue &Result);
 
+bool InterpretBuiltin(InterpState &S, CodePtr PC, unsigned BuiltinID);
+
 enum class ArithOp { Add, Sub };
 
 //===--===//
@@ -1320,6 +1322,20 @@
   return false;
 }
 
+inline bool CallBI(InterpState &S, CodePtr &PC, const Function *Func) {
+  auto NewFrame = std::make_unique(S, Func, PC);
+
+  InterpFrame *FrameBefore = S.Current;
+  S.Current = NewFrame.get();
+
+  if (InterpretBuiltin(S, PC, Func->getBuiltinID())) {
+NewFrame.release();
+return true;
+  }
+  S.Current = FrameBefore;
+  return false;
+}
+
 //===--===//
 // Read opcode arguments
 //===--===//
Index: clang/lib/AST/Interp/Function.h
==

[clang] 0a3243d - [clang][Interp] Array initialization via string literal

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T14:22:05+01:00
New Revision: 0a3243de62c1f0a1e0c2b3c5b4aae8323bef9605

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

LOG: [clang][Interp] Array initialization via string literal

Differential Revision: https://reviews.llvm.org/D137488

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 2581c1c36da2..ae8bf377d262 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1010,6 +1010,34 @@ bool 
ByteCodeExprGen::visitArrayInitializer(const Expr *Initializer) {
 return false;
 }
 return true;
+  } else if (const auto *SL = dyn_cast(Initializer)) {
+const ConstantArrayType *CAT =
+Ctx.getASTContext().getAsConstantArrayType(SL->getType());
+assert(CAT && "a string literal that's not a constant array?");
+
+// If the initializer string is too long, a diagnostic has already been
+// emitted. Read only the array length from the string literal.
+unsigned N =
+std::min(unsigned(CAT->getSize().getZExtValue()), SL->getLength());
+size_t CharWidth = SL->getCharByteWidth();
+
+for (unsigned I = 0; I != N; ++I) {
+  uint32_t CodeUnit = SL->getCodeUnit(I);
+
+  if (CharWidth == 1) {
+this->emitConstSint8(CodeUnit, SL);
+this->emitInitElemSint8(I, SL);
+  } else if (CharWidth == 2) {
+this->emitConstUint16(CodeUnit, SL);
+this->emitInitElemUint16(I, SL);
+  } else if (CharWidth == 4) {
+this->emitConstUint32(CodeUnit, SL);
+this->emitInitElemUint32(I, SL);
+  } else {
+llvm_unreachable("unsupported character width");
+  }
+}
+return true;
   }
 
   assert(false && "Unknown expression for array initialization");

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 4c88e861a443..4ba6d750db78 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -350,6 +350,46 @@ namespace strings {
 #endif
 
 #pragma clang diagnostic pop
+
+  constexpr char foo[12] = "abc";
+  static_assert(foo[0] == 'a', "");
+  static_assert(foo[1] == 'b', "");
+  static_assert(foo[2] == 'c', "");
+  static_assert(foo[3] == 0, "");
+  static_assert(foo[11] == 0, "");
+
+  constexpr char foo2[] = "abc\0def";
+  static_assert(foo2[0] == 'a', "");
+  static_assert(foo2[3] == '\0', "");
+  static_assert(foo2[6] == 'f', "");
+  static_assert(foo2[7] == '\0', "");
+  static_assert(foo2[8] == '\0', ""); // expected-error {{not an integral 
constant expression}} \
+  // expected-note {{read of dereferenced 
one-past-the-end pointer}} \
+  // ref-error {{not an integral constant 
expression}} \
+  // ref-note {{read of dereferenced 
one-past-the-end pointer}}
+
+  constexpr char foo3[4] = "abc";
+  static_assert(foo3[3] == '\0', "");
+  static_assert(foo3[4] == '\0', ""); // expected-error {{not an integral 
constant expression}} \
+  // expected-note {{read of dereferenced 
one-past-the-end pointer}} \
+  // ref-error {{not an integral constant 
expression}} \
+  // ref-note {{read of dereferenced 
one-past-the-end pointer}}
+
+  constexpr char foo4[2] = "abcd"; // expected-error {{initializer-string for 
char array is too long}} \
+   // ref-error {{initializer-string for char 
array is too long}}
+  static_assert(foo4[0] == 'a', "");
+  static_assert(foo4[1] == 'b', "");
+  static_assert(foo4[2] == '\0', ""); // expected-error {{not an integral 
constant expression}} \
+  // expected-note {{read of dereferenced 
one-past-the-end pointer}} \
+  // ref-error {{not an integral constant 
expression}} \
+  // ref-note {{read of dereferenced 
one-past-the-end pointer}}
+
+constexpr char foo5[12] = "abc\xff";
+#if defined(__CHAR_UNSIGNED__) || __CHAR_BIT__ > 8
+static_assert(foo5[3] == 255, "");
+#else
+static_assert(foo5[3] == -1, "");
+#endif
 };
 
 #if __cplusplus > 201402L



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


[PATCH] D137488: [clang][Interp] Array initialization via string literal

2023-01-25 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0a3243de62c1: [clang][Interp] Array initialization via 
string literal (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D137488?vs=477409&id=492073#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137488/new/

https://reviews.llvm.org/D137488

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/literals.cpp


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -350,6 +350,46 @@
 #endif
 
 #pragma clang diagnostic pop
+
+  constexpr char foo[12] = "abc";
+  static_assert(foo[0] == 'a', "");
+  static_assert(foo[1] == 'b', "");
+  static_assert(foo[2] == 'c', "");
+  static_assert(foo[3] == 0, "");
+  static_assert(foo[11] == 0, "");
+
+  constexpr char foo2[] = "abc\0def";
+  static_assert(foo2[0] == 'a', "");
+  static_assert(foo2[3] == '\0', "");
+  static_assert(foo2[6] == 'f', "");
+  static_assert(foo2[7] == '\0', "");
+  static_assert(foo2[8] == '\0', ""); // expected-error {{not an integral 
constant expression}} \
+  // expected-note {{read of dereferenced 
one-past-the-end pointer}} \
+  // ref-error {{not an integral constant 
expression}} \
+  // ref-note {{read of dereferenced 
one-past-the-end pointer}}
+
+  constexpr char foo3[4] = "abc";
+  static_assert(foo3[3] == '\0', "");
+  static_assert(foo3[4] == '\0', ""); // expected-error {{not an integral 
constant expression}} \
+  // expected-note {{read of dereferenced 
one-past-the-end pointer}} \
+  // ref-error {{not an integral constant 
expression}} \
+  // ref-note {{read of dereferenced 
one-past-the-end pointer}}
+
+  constexpr char foo4[2] = "abcd"; // expected-error {{initializer-string for 
char array is too long}} \
+   // ref-error {{initializer-string for char 
array is too long}}
+  static_assert(foo4[0] == 'a', "");
+  static_assert(foo4[1] == 'b', "");
+  static_assert(foo4[2] == '\0', ""); // expected-error {{not an integral 
constant expression}} \
+  // expected-note {{read of dereferenced 
one-past-the-end pointer}} \
+  // ref-error {{not an integral constant 
expression}} \
+  // ref-note {{read of dereferenced 
one-past-the-end pointer}}
+
+constexpr char foo5[12] = "abc\xff";
+#if defined(__CHAR_UNSIGNED__) || __CHAR_BIT__ > 8
+static_assert(foo5[3] == 255, "");
+#else
+static_assert(foo5[3] == -1, "");
+#endif
 };
 
 #if __cplusplus > 201402L
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1010,6 +1010,34 @@
 return false;
 }
 return true;
+  } else if (const auto *SL = dyn_cast(Initializer)) {
+const ConstantArrayType *CAT =
+Ctx.getASTContext().getAsConstantArrayType(SL->getType());
+assert(CAT && "a string literal that's not a constant array?");
+
+// If the initializer string is too long, a diagnostic has already been
+// emitted. Read only the array length from the string literal.
+unsigned N =
+std::min(unsigned(CAT->getSize().getZExtValue()), SL->getLength());
+size_t CharWidth = SL->getCharByteWidth();
+
+for (unsigned I = 0; I != N; ++I) {
+  uint32_t CodeUnit = SL->getCodeUnit(I);
+
+  if (CharWidth == 1) {
+this->emitConstSint8(CodeUnit, SL);
+this->emitInitElemSint8(I, SL);
+  } else if (CharWidth == 2) {
+this->emitConstUint16(CodeUnit, SL);
+this->emitInitElemUint16(I, SL);
+  } else if (CharWidth == 4) {
+this->emitConstUint32(CodeUnit, SL);
+this->emitInitElemUint32(I, SL);
+  } else {
+llvm_unreachable("unsupported character width");
+  }
+}
+return true;
   }
 
   assert(false && "Unknown expression for array initialization");


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -350,6 +350,46 @@
 #endif
 
 #pragma clang diagnostic pop
+
+  constexpr char foo[12] = "abc";
+  static_assert(foo[0] == 'a', "");
+  static_assert(foo[1] == 'b', "");
+  static_assert(foo[2] == 'c', "");
+  static_assert(foo[3] == 0, "");
+  static_assert(foo[11] == 0, "");
+
+  constexpr char foo2[] = "abc\0def";
+  static_assert(foo2[0] == 'a', "");
+  st

[clang] 62f43c3 - [clang][Interp] Support floating-point values

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T14:41:26+01:00
New Revision: 62f43c3eae2460d4ca3da7897fd2d7c56920638c

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

LOG: [clang][Interp] Support floating-point values

Add a new Floating type and a few new opcodes to support floating point
values.

Differential Revision: https://reviews.llvm.org/D134859

Added: 
clang/lib/AST/Interp/Floating.cpp
clang/lib/AST/Interp/Floating.h
clang/lib/AST/Interp/Primitives.h
clang/test/AST/Interp/const-fpfeatures.cpp
clang/test/AST/Interp/floats.cpp

Modified: 
clang/lib/AST/CMakeLists.txt
clang/lib/AST/Interp/Boolean.h
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/Context.cpp
clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/Disasm.cpp
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpFrame.cpp
clang/lib/AST/Interp/InterpStack.h
clang/lib/AST/Interp/Opcodes.td
clang/lib/AST/Interp/PrimType.cpp
clang/lib/AST/Interp/PrimType.h
clang/test/SemaCXX/rounding-math.cpp

Removed: 




diff  --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index e4c1008fe34b1..3d8d8cc077615 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -74,6 +74,7 @@ add_clang_library(clangAST
   Interp/Frame.cpp
   Interp/Function.cpp
   Interp/InterpBuiltin.cpp
+  Interp/Floating.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp

diff  --git a/clang/lib/AST/Interp/Boolean.h b/clang/lib/AST/Interp/Boolean.h
index 3122388a49a55..e496f70eb4117 100644
--- a/clang/lib/AST/Interp/Boolean.h
+++ b/clang/lib/AST/Interp/Boolean.h
@@ -27,12 +27,10 @@ class Boolean final {
   /// Underlying boolean.
   bool V;
 
-  /// Construct a wrapper from a boolean.
-  explicit Boolean(bool V) : V(V) {}
-
  public:
   /// Zero-initializes a boolean.
   Boolean() : V(false) {}
+  explicit Boolean(bool V) : V(V) {}
 
   bool operator<(Boolean RHS) const { return V < RHS.V; }
   bool operator>(Boolean RHS) const { return V > RHS.V; }

diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index 4633d1e0823b6..be56348beca73 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -8,6 +8,7 @@
 
 #include "ByteCodeEmitter.h"
 #include "Context.h"
+#include "Floating.h"
 #include "Opcode.h"
 #include "Program.h"
 #include "clang/AST/DeclCXX.h"

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index ae8bf377d262f..62ed09f078c18 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -11,6 +11,7 @@
 #include "ByteCodeGenError.h"
 #include "ByteCodeStmtGen.h"
 #include "Context.h"
+#include "Floating.h"
 #include "Function.h"
 #include "PrimType.h"
 #include "Program.h"
@@ -95,6 +96,41 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
 return this->emitGetPtrBase(ToBase->Offset, CE);
   }
 
+  case CK_FloatingCast: {
+if (!this->visit(SubExpr))
+  return false;
+const auto *TargetSemantics =
+&Ctx.getASTContext().getFloatTypeSemantics(CE->getType());
+return this->emitCastFP(TargetSemantics, getRoundingMode(CE), CE);
+  }
+
+  case CK_IntegralToFloating: {
+std::optional FromT = classify(SubExpr->getType());
+if (!FromT)
+  return false;
+
+if (!this->visit(SubExpr))
+  return false;
+
+const auto *TargetSemantics =
+&Ctx.getASTContext().getFloatTypeSemantics(CE->getType());
+llvm::RoundingMode RM = getRoundingMode(CE);
+return this->emitCastIntegralFloating(*FromT, TargetSemantics, RM, CE);
+  }
+
+  case CK_FloatingToBoolean:
+  case CK_FloatingToIntegral: {
+std::optional ToT = classify(CE->getType());
+
+if (!ToT)
+  return false;
+
+if (!this->visit(SubExpr))
+  return false;
+
+return this->emitCastFloatingIntegral(*ToT, CE);
+  }
+
   case CK_ArrayToPointerDecay:
   case CK_AtomicToNonAtomic:
   case CK_ConstructorConversion:
@@ -136,6 +172,14 @@ bool ByteCodeExprGen::VisitIntegerLiteral(const 
IntegerLiteral *LE) {
   return this->emitConst(LE->getValue(), LE);
 }
 
+template 
+bool ByteCodeExprGen::VisitFloatingLiteral(const FloatingLiteral *E) {
+  if (DiscardResult)
+return true;
+
+  return this->emitConstFloat(E->getValue(), E);
+}
+
 template 
 bool ByteCodeExprGen::VisitParenExpr(const ParenExpr *PE) {
   return this->visit(PE->getSubExpr());
@@ -195,14 +239,22 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
   case 

[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2023-01-25 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG62f43c3eae24: [clang][Interp] Support floating-point values 
(authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D134859?vs=483802&id=492076#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134859/new/

https://reviews.llvm.org/D134859

Files:
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Disasm.cpp
  clang/lib/AST/Interp/Floating.cpp
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.cpp
  clang/lib/AST/Interp/PrimType.h
  clang/lib/AST/Interp/Primitives.h
  clang/test/AST/Interp/const-fpfeatures.cpp
  clang/test/AST/Interp/floats.cpp
  clang/test/SemaCXX/rounding-math.cpp

Index: clang/test/SemaCXX/rounding-math.cpp
===
--- clang/test/SemaCXX/rounding-math.cpp
+++ clang/test/SemaCXX/rounding-math.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-linux -verify=norounding -Wno-unknown-pragmas %s
 // RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -Wno-unknown-pragmas
+// RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -fexperimental-new-constant-interpreter -Wno-unknown-pragmas
 // rounding-no-diagnostics
 
 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
Index: clang/test/AST/Interp/floats.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/floats.cpp
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+constexpr int i = 2;
+constexpr float f = 1.0f;
+static_assert(f == 1.0f, "");
+
+constexpr float f2 = 1u * f;
+static_assert(f2 == 1.0f, "");
+
+constexpr float f3 = 1.5;
+constexpr int i3 = f3;
+static_assert(i3 == 1);
+
+constexpr bool b3 = f3;
+static_assert(b3);
+
+
+static_assert(1.0f + 3u == 4, "");
+static_assert(4.0f / 1.0f == 4, "");
+static_assert(10.0f * false == 0, "");
+
+constexpr float floats[] = {1.0f, 2.0f, 3.0f, 4.0f};
+
+constexpr float m = 5.0f / 0.0f; // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{division by zero}} \
+ // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{division by zero}}
+
+static_assert(~2.0f == 3, ""); // ref-error {{invalid argument type 'float' to unary expression}} \
+   // expected-error {{invalid argument type 'float' to unary expression}}
+
+/// Initialized by a double.
+constexpr float df = 0.0;
+/// The other way around.
+constexpr double fd = 0.0f;
+
+static_assert(0.0f == -0.0f, "");
+
+const int k = 3 * (1.0f / 3.0f);
+static_assert(k == 1, "");
+
+constexpr bool b = 1.0;
+static_assert(b, "");
+
+constexpr double db = true;
+static_assert(db == 1.0, "");
+
+constexpr float fa[] = {1.0f, 2.0, 1, false};
+constexpr double da[] = {1.0f, 2.0, 1, false};
+
+constexpr float fm = __FLT_MAX__;
+constexpr int someInt = fm; // ref-error {{must be initialized by a constant expression}} \
+// ref-note {{is outside the range of representable values}} \
+// expected-error {{must be initialized by a constant expression}} \
+// expected-note {{is outside the range of representable values}}
Index: clang/test/AST/Interp/const-fpfeatures.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/const-fpfeatures.cpp
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -S -emit-llvm -triple i386-linux -std=c++2a -Wno-unknown-pragmas %s -o - | FileCheck %s
+// RUN: %clang_cc1 -S -emit-llvm -triple i386-linux -fexperimental-new-constant-interpreter -std=c++2a -Wno-unknown-pragmas %s -o - | FileCheck %s
+
+
+#pragma STDC FENV_ROUND FE_UPWARD
+
+float F1u = 1.0F + 0x0.02p0F;
+float F2u = 1.0F + 0x0.01p0F;
+float F3u = 0x1.01p0;
+// CHECK: @F1u = {{.*}} float 0x3FF02000
+// CHECK: @F2u = {{.*}} float 0x3FF02000
+// CHECK: @F3u = {{.*}} float 0x3FF02000
+
+float FI1u = 0xU;
+// CHECK: @FI1u = {{.*}} float 0x41F0
+
+#pragma STDC FENV_ROUND FE_DOWNWARD
+
+float F1d = 1.0F + 0x0.02p0F;
+float F2d = 1.0F + 0x0.01p0F;
+float F3d = 0x1.01p0;
+
+// CHECK: @F1d = {{.*}} float 0x3FF

[PATCH] D142354: [analyzer] Create a stub for an std::variant checker

2023-01-25 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D142354#4078450 , @NoQ wrote:

> Interesting, what specific goals do you have here? Are you planning to find 
> specific bugs (eg. force-unwrap to a wrong type) or just to model the 
> semantics?

Hi!

Meant to write this comment yesterday, but here we go. My idea was aiming for 
both of the goals you mentioned:

1. Emit diagnostics on improper usages of `std::variant`, which mostly boils 
down retrieving a field through a wrong type, yes. This will be, in my view, 
the main showpiece of the thesis.
2. Model the semantics.

In this or in a followup patch I think we should demonstrate with a few tests 
what we expect the checker to be capable of.

> In the latter case, have you explored the possibility of force-inlining the 
> class instead, like I suggested in the thread?

I have done some tests then, and figured that the analyzer can't really follow 
what happens in std::variant. I admit, now that I've taken a more thorough 
look, I was wrong! Here are some examples.

  std::variant v = 0;
  int i = std::get(v);
  clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}
  10 / i; // FIXME: This should warn for division by zero!



  std::variant v = 0;
  std::string *sptr = std::get_if(&v);
  clang_analyzer_eval(sptr == nullptr); // expected-warning{{TRUE}}
  *sptr = "Alma!"; // FIXME: Should warn, sptr is a null pointer!



  void g(std::variant v) {
if (!std::get_if(&v))
  return;
int *iptr = std::get_if(&v);
clang_analyzer_eval(iptr == nullptr); // expected-warning{{TRUE}}
*iptr = 5; // FIXME: Should warn, iptr is a null pointer!
  }

In neither of these cases was a warning emitted, but that was a result of bug 
report suppression, because the exploded graph indicates that the errors were 
found.

We will need to teach these suppression strategies in these cases, the 
heuristic is too conservative, and I wouldn't mind some `NoteTag`s to tell the 
user something along the lines of "Assuming this variant holds and std::string 
value".

> Have you found a reasonable amount of code that uses `std::variant`, to test 
> your checker on?

Acid  has a few, csv-parser 
 in one place, there is a couple in 
config-loader  and cista 
, and a surprising amount in userver 
. Though its a question how 
painful it is to set up their dependencies.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142354/new/

https://reviews.llvm.org/D142354

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


[clang] b3b1d86 - Revert "[clang][Interp] Support floating-point values"

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T14:48:39+01:00
New Revision: b3b1d86137422dbdc9e8626925067f1b50734036

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

LOG: Revert "[clang][Interp] Support floating-point values"

This reverts commit 62f43c3eae2460d4ca3da7897fd2d7c56920638c.

This breaks a couple of builders, e.g.

https://lab.llvm.org/buildbot/#/builders/139/builds/34925

Added: 


Modified: 
clang/lib/AST/CMakeLists.txt
clang/lib/AST/Interp/Boolean.h
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/Context.cpp
clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/Disasm.cpp
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpFrame.cpp
clang/lib/AST/Interp/InterpStack.h
clang/lib/AST/Interp/Opcodes.td
clang/lib/AST/Interp/PrimType.cpp
clang/lib/AST/Interp/PrimType.h
clang/test/SemaCXX/rounding-math.cpp

Removed: 
clang/lib/AST/Interp/Floating.cpp
clang/lib/AST/Interp/Floating.h
clang/lib/AST/Interp/Primitives.h
clang/test/AST/Interp/const-fpfeatures.cpp
clang/test/AST/Interp/floats.cpp



diff  --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index 3d8d8cc077615..e4c1008fe34b1 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -74,7 +74,6 @@ add_clang_library(clangAST
   Interp/Frame.cpp
   Interp/Function.cpp
   Interp/InterpBuiltin.cpp
-  Interp/Floating.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp

diff  --git a/clang/lib/AST/Interp/Boolean.h b/clang/lib/AST/Interp/Boolean.h
index e496f70eb4117..3122388a49a55 100644
--- a/clang/lib/AST/Interp/Boolean.h
+++ b/clang/lib/AST/Interp/Boolean.h
@@ -27,10 +27,12 @@ class Boolean final {
   /// Underlying boolean.
   bool V;
 
+  /// Construct a wrapper from a boolean.
+  explicit Boolean(bool V) : V(V) {}
+
  public:
   /// Zero-initializes a boolean.
   Boolean() : V(false) {}
-  explicit Boolean(bool V) : V(V) {}
 
   bool operator<(Boolean RHS) const { return V < RHS.V; }
   bool operator>(Boolean RHS) const { return V > RHS.V; }

diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index be56348beca73..4633d1e0823b6 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -8,7 +8,6 @@
 
 #include "ByteCodeEmitter.h"
 #include "Context.h"
-#include "Floating.h"
 #include "Opcode.h"
 #include "Program.h"
 #include "clang/AST/DeclCXX.h"

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 62ed09f078c18..ae8bf377d262f 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -11,7 +11,6 @@
 #include "ByteCodeGenError.h"
 #include "ByteCodeStmtGen.h"
 #include "Context.h"
-#include "Floating.h"
 #include "Function.h"
 #include "PrimType.h"
 #include "Program.h"
@@ -96,41 +95,6 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
 return this->emitGetPtrBase(ToBase->Offset, CE);
   }
 
-  case CK_FloatingCast: {
-if (!this->visit(SubExpr))
-  return false;
-const auto *TargetSemantics =
-&Ctx.getASTContext().getFloatTypeSemantics(CE->getType());
-return this->emitCastFP(TargetSemantics, getRoundingMode(CE), CE);
-  }
-
-  case CK_IntegralToFloating: {
-std::optional FromT = classify(SubExpr->getType());
-if (!FromT)
-  return false;
-
-if (!this->visit(SubExpr))
-  return false;
-
-const auto *TargetSemantics =
-&Ctx.getASTContext().getFloatTypeSemantics(CE->getType());
-llvm::RoundingMode RM = getRoundingMode(CE);
-return this->emitCastIntegralFloating(*FromT, TargetSemantics, RM, CE);
-  }
-
-  case CK_FloatingToBoolean:
-  case CK_FloatingToIntegral: {
-std::optional ToT = classify(CE->getType());
-
-if (!ToT)
-  return false;
-
-if (!this->visit(SubExpr))
-  return false;
-
-return this->emitCastFloatingIntegral(*ToT, CE);
-  }
-
   case CK_ArrayToPointerDecay:
   case CK_AtomicToNonAtomic:
   case CK_ConstructorConversion:
@@ -172,14 +136,6 @@ bool ByteCodeExprGen::VisitIntegerLiteral(const 
IntegerLiteral *LE) {
   return this->emitConst(LE->getValue(), LE);
 }
 
-template 
-bool ByteCodeExprGen::VisitFloatingLiteral(const FloatingLiteral *E) {
-  if (DiscardResult)
-return true;
-
-  return this->emitConstFloat(E->getValue(), E);
-}
-
 template 
 bool ByteCodeExprGen::VisitParenExpr(const ParenExpr *PE) {
   return this->visit(PE->getSubExpr());
@@ -239,22 +195,14 @@ bool ByteCodeExprGen::VisitBinaryOperator(cons

[PATCH] D129008: [Clang][OpenMP] Fix the issue that globalization doesn't work with byval struct function argument

2023-01-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added subscribers: efriedma, rjmccall.
aaron.ballman added a comment.

In D129008#3640194 , @tianshilei1992 
wrote:

> `callCStructCopyConstructor` is actually for Objective-C…Cannot use it here.

Is it for ObjC? Looking at the comments, it looks like it's for C:

  // These functions emit calls to the special functions of non-trivial C
  // structs.




Comment at: clang/lib/CodeGen/CGDecl.cpp:2501
+  LValue Src = MakeAddrLValue(Arg.getIndirectAddress(), Ty);
+  callCStructCopyConstructor(Dst, Src);
+  PushCleanupIfNeeded(Arg.getIndirectAddress());

tianshilei1992 wrote:
> Hi @aaron.ballman, is it possible to invoke the copy constructor of a 
> struct/class here, either it is user defined or default one?
CC @rjmccall and @efriedma for codegen owner opinions.

I'm honestly not certain; I would imagine that OpenMP defines what should 
happen, but this is outside of my area of expertise.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129008/new/

https://reviews.llvm.org/D129008

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


[PATCH] D142500: Fix one of the regressions found in revert of concept sugaring

2023-01-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D142500#4079135 , @Mordante wrote:

> FYI I tested this patch with libc++ and as expected it does not fix the 
> libc++ modular build ICE.

A man can dream, eh?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142500/new/

https://reviews.llvm.org/D142500

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


[clang] 228462f - Fix one of the regressions found in revert of concept sugaring

2023-01-25 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2023-01-25T06:01:44-08:00
New Revision: 228462f755f0d459882b19115c60e8872a057b25

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

LOG: Fix one of the regressions found in revert of concept sugaring

It seems that the sugaring patches had some pretty significant
interdependencies, and at least one issue exists that requires part of
the concept-sugaring patch.  I don't believe this to have anything to do
with the increased compile-times that were seen, so hopefully this will
fix our problems without further regressions.

See https://reviews.llvm.org/rG12cb1cb3720de8d164196010123ce1a8901d8122
for discussion.

Differential Revision: https://reviews.llvm.org/D142500

Added: 
clang/test/SemaTemplate/sugar-crashes.cpp

Modified: 
clang/lib/Sema/SemaExprCXX.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index e3eef9323b2f8..abf5a72e7308a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1483,13 +1483,14 @@ Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo,
   //   Otherwise, if the type contains a placeholder type, it is replaced by 
the
   //   type determined by placeholder type deduction.
   DeducedType *Deduced = Ty->getContainedDeducedType();
-  if (Deduced && isa(Deduced)) {
+  if (Deduced && !Deduced->isDeduced() &&
+  isa(Deduced)) {
 Ty = DeduceTemplateSpecializationFromInitializer(TInfo, Entity,
  Kind, Exprs);
 if (Ty.isNull())
   return ExprError();
 Entity = InitializedEntity::InitializeTemporary(TInfo, Ty);
-  } else if (Deduced) {
+  } else if (Deduced && !Deduced->isDeduced()) {
 MultiExprArg Inits = Exprs;
 if (ListInitialization) {
   auto *ILE = cast(Exprs[0]);
@@ -2016,7 +2017,8 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool 
UseGlobal,
 
   // C++11 [dcl.spec.auto]p6. Deduce the type which 'auto' stands in for.
   auto *Deduced = AllocType->getContainedDeducedType();
-  if (Deduced && isa(Deduced)) {
+  if (Deduced && !Deduced->isDeduced() &&
+  isa(Deduced)) {
 if (ArraySize)
   return ExprError(
   Diag(*ArraySize ? (*ArraySize)->getExprLoc() : TypeRange.getBegin(),
@@ -2030,7 +2032,7 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool 
UseGlobal,
 AllocTypeInfo, Entity, Kind, Exprs);
 if (AllocType.isNull())
   return ExprError();
-  } else if (Deduced) {
+  } else if (Deduced && !Deduced->isDeduced()) {
 MultiExprArg Inits = Exprs;
 bool Braced = (initStyle == CXXNewExpr::ListInit);
 if (Braced) {

diff  --git a/clang/test/SemaTemplate/sugar-crashes.cpp 
b/clang/test/SemaTemplate/sugar-crashes.cpp
new file mode 100644
index 0..fd0789d044e29
--- /dev/null
+++ b/clang/test/SemaTemplate/sugar-crashes.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify %s
+// expected-no-diagnostics
+
+
+struct StringPiece {
+  template 
+ StringPiece(T str) {}
+};
+
+void f(StringPiece utf8) {}
+
+struct S {
+};
+
+void G() {
+  const auto s = S{};
+  StringPiece U{s};
+}
+



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


[PATCH] D142500: Fix one of the regressions found in revert of concept sugaring

2023-01-25 Thread Erich Keane via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG228462f755f0: Fix one of the regressions found in revert of 
concept sugaring (authored by erichkeane).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142500/new/

https://reviews.llvm.org/D142500

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaTemplate/sugar-crashes.cpp


Index: clang/test/SemaTemplate/sugar-crashes.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/sugar-crashes.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify %s
+// expected-no-diagnostics
+
+
+struct StringPiece {
+  template 
+ StringPiece(T str) {}
+};
+
+void f(StringPiece utf8) {}
+
+struct S {
+};
+
+void G() {
+  const auto s = S{};
+  StringPiece U{s};
+}
+
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1483,13 +1483,14 @@
   //   Otherwise, if the type contains a placeholder type, it is replaced by 
the
   //   type determined by placeholder type deduction.
   DeducedType *Deduced = Ty->getContainedDeducedType();
-  if (Deduced && isa(Deduced)) {
+  if (Deduced && !Deduced->isDeduced() &&
+  isa(Deduced)) {
 Ty = DeduceTemplateSpecializationFromInitializer(TInfo, Entity,
  Kind, Exprs);
 if (Ty.isNull())
   return ExprError();
 Entity = InitializedEntity::InitializeTemporary(TInfo, Ty);
-  } else if (Deduced) {
+  } else if (Deduced && !Deduced->isDeduced()) {
 MultiExprArg Inits = Exprs;
 if (ListInitialization) {
   auto *ILE = cast(Exprs[0]);
@@ -2016,7 +2017,8 @@
 
   // C++11 [dcl.spec.auto]p6. Deduce the type which 'auto' stands in for.
   auto *Deduced = AllocType->getContainedDeducedType();
-  if (Deduced && isa(Deduced)) {
+  if (Deduced && !Deduced->isDeduced() &&
+  isa(Deduced)) {
 if (ArraySize)
   return ExprError(
   Diag(*ArraySize ? (*ArraySize)->getExprLoc() : TypeRange.getBegin(),
@@ -2030,7 +2032,7 @@
 AllocTypeInfo, Entity, Kind, Exprs);
 if (AllocType.isNull())
   return ExprError();
-  } else if (Deduced) {
+  } else if (Deduced && !Deduced->isDeduced()) {
 MultiExprArg Inits = Exprs;
 bool Braced = (initStyle == CXXNewExpr::ListInit);
 if (Braced) {


Index: clang/test/SemaTemplate/sugar-crashes.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/sugar-crashes.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify %s
+// expected-no-diagnostics
+
+
+struct StringPiece {
+  template 
+ StringPiece(T str) {}
+};
+
+void f(StringPiece utf8) {}
+
+struct S {
+};
+
+void G() {
+  const auto s = S{};
+  StringPiece U{s};
+}
+
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1483,13 +1483,14 @@
   //   Otherwise, if the type contains a placeholder type, it is replaced by the
   //   type determined by placeholder type deduction.
   DeducedType *Deduced = Ty->getContainedDeducedType();
-  if (Deduced && isa(Deduced)) {
+  if (Deduced && !Deduced->isDeduced() &&
+  isa(Deduced)) {
 Ty = DeduceTemplateSpecializationFromInitializer(TInfo, Entity,
  Kind, Exprs);
 if (Ty.isNull())
   return ExprError();
 Entity = InitializedEntity::InitializeTemporary(TInfo, Ty);
-  } else if (Deduced) {
+  } else if (Deduced && !Deduced->isDeduced()) {
 MultiExprArg Inits = Exprs;
 if (ListInitialization) {
   auto *ILE = cast(Exprs[0]);
@@ -2016,7 +2017,8 @@
 
   // C++11 [dcl.spec.auto]p6. Deduce the type which 'auto' stands in for.
   auto *Deduced = AllocType->getContainedDeducedType();
-  if (Deduced && isa(Deduced)) {
+  if (Deduced && !Deduced->isDeduced() &&
+  isa(Deduced)) {
 if (ArraySize)
   return ExprError(
   Diag(*ArraySize ? (*ArraySize)->getExprLoc() : TypeRange.getBegin(),
@@ -2030,7 +2032,7 @@
 AllocTypeInfo, Entity, Kind, Exprs);
 if (AllocType.isNull())
   return ExprError();
-  } else if (Deduced) {
+  } else if (Deduced && !Deduced->isDeduced()) {
 MultiExprArg Inits = Exprs;
 bool Braced = (initStyle == CXXNewExpr::ListInit);
 if (Braced) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] cb7f582 - Re-apply "[clang][Interp] Support floating-point values"

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T15:13:09+01:00
New Revision: cb7f58221101cfad0ddec987465de57a20b0d11c

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

LOG: Re-apply "[clang][Interp] Support floating-point values"

Don't move the Repr struct into Integral this time.

Differential Revision: https://reviews.llvm.org/D134859

Added: 
clang/lib/AST/Interp/Floating.cpp
clang/lib/AST/Interp/Floating.h
clang/lib/AST/Interp/Primitives.h
clang/test/AST/Interp/const-fpfeatures.cpp
clang/test/AST/Interp/floats.cpp

Modified: 
clang/lib/AST/CMakeLists.txt
clang/lib/AST/Interp/Boolean.h
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/Context.cpp
clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/Disasm.cpp
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpFrame.cpp
clang/lib/AST/Interp/InterpStack.h
clang/lib/AST/Interp/Opcodes.td
clang/lib/AST/Interp/PrimType.cpp
clang/lib/AST/Interp/PrimType.h
clang/test/SemaCXX/rounding-math.cpp

Removed: 




diff  --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index e4c1008fe34b1..3d8d8cc077615 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -74,6 +74,7 @@ add_clang_library(clangAST
   Interp/Frame.cpp
   Interp/Function.cpp
   Interp/InterpBuiltin.cpp
+  Interp/Floating.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp

diff  --git a/clang/lib/AST/Interp/Boolean.h b/clang/lib/AST/Interp/Boolean.h
index 3122388a49a55..e496f70eb4117 100644
--- a/clang/lib/AST/Interp/Boolean.h
+++ b/clang/lib/AST/Interp/Boolean.h
@@ -27,12 +27,10 @@ class Boolean final {
   /// Underlying boolean.
   bool V;
 
-  /// Construct a wrapper from a boolean.
-  explicit Boolean(bool V) : V(V) {}
-
  public:
   /// Zero-initializes a boolean.
   Boolean() : V(false) {}
+  explicit Boolean(bool V) : V(V) {}
 
   bool operator<(Boolean RHS) const { return V < RHS.V; }
   bool operator>(Boolean RHS) const { return V > RHS.V; }

diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index 4633d1e0823b6..be56348beca73 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -8,6 +8,7 @@
 
 #include "ByteCodeEmitter.h"
 #include "Context.h"
+#include "Floating.h"
 #include "Opcode.h"
 #include "Program.h"
 #include "clang/AST/DeclCXX.h"

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index ae8bf377d262f..62ed09f078c18 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -11,6 +11,7 @@
 #include "ByteCodeGenError.h"
 #include "ByteCodeStmtGen.h"
 #include "Context.h"
+#include "Floating.h"
 #include "Function.h"
 #include "PrimType.h"
 #include "Program.h"
@@ -95,6 +96,41 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
 return this->emitGetPtrBase(ToBase->Offset, CE);
   }
 
+  case CK_FloatingCast: {
+if (!this->visit(SubExpr))
+  return false;
+const auto *TargetSemantics =
+&Ctx.getASTContext().getFloatTypeSemantics(CE->getType());
+return this->emitCastFP(TargetSemantics, getRoundingMode(CE), CE);
+  }
+
+  case CK_IntegralToFloating: {
+std::optional FromT = classify(SubExpr->getType());
+if (!FromT)
+  return false;
+
+if (!this->visit(SubExpr))
+  return false;
+
+const auto *TargetSemantics =
+&Ctx.getASTContext().getFloatTypeSemantics(CE->getType());
+llvm::RoundingMode RM = getRoundingMode(CE);
+return this->emitCastIntegralFloating(*FromT, TargetSemantics, RM, CE);
+  }
+
+  case CK_FloatingToBoolean:
+  case CK_FloatingToIntegral: {
+std::optional ToT = classify(CE->getType());
+
+if (!ToT)
+  return false;
+
+if (!this->visit(SubExpr))
+  return false;
+
+return this->emitCastFloatingIntegral(*ToT, CE);
+  }
+
   case CK_ArrayToPointerDecay:
   case CK_AtomicToNonAtomic:
   case CK_ConstructorConversion:
@@ -136,6 +172,14 @@ bool ByteCodeExprGen::VisitIntegerLiteral(const 
IntegerLiteral *LE) {
   return this->emitConst(LE->getValue(), LE);
 }
 
+template 
+bool ByteCodeExprGen::VisitFloatingLiteral(const FloatingLiteral *E) {
+  if (DiscardResult)
+return true;
+
+  return this->emitConstFloat(E->getValue(), E);
+}
+
 template 
 bool ByteCodeExprGen::VisitParenExpr(const ParenExpr *PE) {
   return this->visit(PE->getSubExpr());
@@ -195,14 +239,22 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
   case BO_GE:
 retur

[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
llvm/test/DebugInfo/Generic/assignment-tracking/sroa/unspecified-var-size.ll:37
 !7 = !DIFile(filename: "clang/12.0.0/include/__stddef_max_align_t.h", 
directory: "/")
-!8 = !DICompositeType(tag: DW_TAG_structure_type, file: !7, line: 19, size: 
256, flags: DIFlagFwdDecl, identifier: "_ZTS11max_align_t")
-!9 = !DIFile(filename: "include/c++/7.5.0/cstddef", directory: "")
-!10 = !{i32 7, !"Dwarf Version", i32 4}
-!11 = !{i32 2, !"Debug Info Version", i32 3}
-!12 = !{i32 1, !"wchar_size", i32 4}
-!13 = !{!"clang version 12.0.0"}
-!14 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funDn", scope: !1, 
file: !1, line: 20, type: !15, scopeLine: 20, flags: DIFlagPrototyped | 
DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: 
!0, retainedNodes: !20)
-!15 = !DISubroutineType(types: !16)
-!16 = !{null, !17}
-!17 = !DIDerivedType(tag: DW_TAG_typedef, name: "nullptr_t", scope: !5, file: 
!18, line: 235, baseType: !19)
-!18 = !DIFile(filename: "include/x86_64-linux-gnu/c++/7.5.0/bits/c++config.h", 
directory: "")
-!19 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
-!20 = !{!21}
-!21 = !DILocalVariable(arg: 1, scope: !14, file: !1, line: 20, type: !17)
-!22 = distinct !DIAssignID()
-!23 = !DILocation(line: 0, scope: !14)
-!28 = distinct !DIAssignID()
-!29 = !DILocation(line: 20, column: 27, scope: !14)
+!8 = !DIFile(filename: "clang/12.0.0/include/__stddef_null.h", directory: "/")
+!9 = !DICompositeType(tag: DW_TAG_structure_type, file: !7, line: 19, size: 
256, flags: DIFlagFwdDecl, identifier: "_ZTS11max_align_t")

iana wrote:
> dblaikie wrote:
> > aaron.ballman wrote:
> > > iana wrote:
> > > > Adding this line is the only reason I changed this file. I'm not 
> > > > familiar at all with how these tests work, so I don't really know if 
> > > > it's necessary. The test passes with and without these changes.
> > > CC @dblaikie and @echristo for questions about whether we should be 
> > > updating this debug info test or not.
> > Don't think there's any reason/need to - what motivated changing this file?
> I found it when I was checking for places that handled 
> `__stddef_max_align_t.h` specially. I'm not sure if that's in here to check 
> `_ZTS11max_align_t` under it, or if it's just there because stddef.h includes 
> it. __stddef_null.h doesn't define any types like that, so maybe it's fine to 
> just revert this file?
Yeah, I think it's reasonable to revert the changes to this file.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140250/new/

https://reviews.llvm.org/D140250

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


[PATCH] D14484: [clang-format] Formatting constructor initializer lists by putting them always on different lines

2023-01-25 Thread Hantao Pan via Phabricator via cfe-commits
HantaoPan added a comment.
Herald added a project: All.

Hi,
I am interesting in this feature too. You know, consistency is crucial to a 
large program...

regards,


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D14484/new/

https://reviews.llvm.org/D14484

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


[clang] 611a748 - [clang][Interp] Add empty messages to static_asserts

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T15:20:46+01:00
New Revision: 611a748b2252f9c529805cc2fa34c073e9b42bcd

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

LOG: [clang][Interp] Add empty messages to static_asserts

To satisfy builders:
https://lab.llvm.org/buildbot/#/builders/216/builds/16264

Added: 


Modified: 
clang/test/AST/Interp/floats.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/floats.cpp 
b/clang/test/AST/Interp/floats.cpp
index 9c9831c3f10a..ab5d51ca400d 100644
--- a/clang/test/AST/Interp/floats.cpp
+++ b/clang/test/AST/Interp/floats.cpp
@@ -10,10 +10,10 @@ static_assert(f2 == 1.0f, "");
 
 constexpr float f3 = 1.5;
 constexpr int i3 = f3;
-static_assert(i3 == 1);
+static_assert(i3 == 1, "");
 
 constexpr bool b3 = f3;
-static_assert(b3);
+static_assert(b3, "");
 
 
 static_assert(1.0f + 3u == 4, "");



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


cfe-commits@lists.llvm.org

2023-01-25 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I think they have branched 
(https://clang.llvm.org/docs/ClangFormatStyleOptions.html) the documentation 
has changed to 17.0

We would need your name and email in order to commit on your behalf.

I checked this patch out and tested it on my large project and I didn't see 
anything immediately jump out.

@owenpan, @rymiel  any concerns?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141959/new/

https://reviews.llvm.org/D141959

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


[clang-tools-extra] 007b353 - doc: Fix typo in clang-tidy no-automatic-move doc

2023-01-25 Thread via cfe-commits

Author: MarcoFalke
Date: 2023-01-25T15:39:41+01:00
New Revision: 007b35369501b244c8736d2c75b942d1d91d5d18

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

LOG: doc: Fix typo in clang-tidy no-automatic-move doc

The latter version is called NotCool in the source code and on godbolt.

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/performance/no-automatic-move.rst

Removed: 




diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/performance/no-automatic-move.rst 
b/clang-tools-extra/docs/clang-tidy/checks/performance/no-automatic-move.rst
index 7064e0298b9bb..5572bb176d2cc 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/performance/no-automatic-move.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/performance/no-automatic-move.rst
@@ -25,7 +25,7 @@ Example `[1] `_:
 return obj;  // calls `StatusOr::StatusOr(const std::vector&)`
   }
 
-The former version (``Cool``) should be preferred over the latter (``Uncool``)
+The former version (``Cool``) should be preferred over the latter (``NotCool``)
 as it will avoid allocations and potentially large memory copies.
 
 Semantics



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


[PATCH] D142354: [analyzer] Create a stub for an std::variant checker

2023-01-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I would be interested in some of the free-functions dealing with variants, such 
as `std::visit()`. https://godbolt.org/z/bbocrz4dG
I hope that's also on the radar.

In D142354#4079643 , @Szelethus wrote:

> In D142354#4078450 , @NoQ wrote:
>
>> Have you found a reasonable amount of code that uses `std::variant`, to test 
>> your checker on?
>
> Acid  has a few, csv-parser 
>  in one place, there is a couple in 
> config-loader  and cista 
> , and a surprising amount in userver 
> . Though its a question how 
> painful it is to set up their dependencies.

I think bitcoin  and qtbase 
 also have some uses for variant.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142354/new/

https://reviews.llvm.org/D142354

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


[PATCH] D142539: [NFC][AArch64] Use optional returns in target parser instead of 'invalid' objects

2023-01-25 Thread Lucas Prates via Phabricator via cfe-commits
pratlucas created this revision.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
pratlucas requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

This updates the parsing methods in AArch64's Target Parser to make use
of optional returns instead of "invalid" enum values, making the API's
behaviour clearer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142539

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  llvm/include/llvm/TargetParser/AArch64TargetParser.h
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/lib/TargetParser/AArch64TargetParser.cpp
  llvm/unittests/TargetParser/TargetParserTest.cpp

Index: llvm/unittests/TargetParser/TargetParserTest.cpp
===
--- llvm/unittests/TargetParser/TargetParserTest.cpp
+++ llvm/unittests/TargetParser/TargetParserTest.cpp
@@ -17,6 +17,7 @@
 #include "llvm/TargetParser/Triple.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 #include 
 
 using namespace llvm;
@@ -961,11 +962,12 @@
 TEST_P(AArch64CPUTestFixture, testAArch64CPU) {
   ARMCPUTestParams params = GetParam();
 
-  const AArch64::ArchInfo &AI = AArch64::parseCpu(params.CPUName).Arch;
-  EXPECT_EQ(params.ExpectedArch, AI.Name);
+  const std::optional Cpu = AArch64::parseCpu(params.CPUName);
+  EXPECT_TRUE(Cpu);
+  EXPECT_EQ(params.ExpectedArch, Cpu->Arch.Name);
 
   uint64_t default_extensions =
-  AArch64::getDefaultExtensions(params.CPUName, AI);
+  AArch64::getDefaultExtensions(params.CPUName, Cpu->Arch);
   EXPECT_PRED_FORMAT2(
   AssertSameExtensionFlags(params.CPUName),
   params.ExpectedFlags, default_extensions);
@@ -974,10 +976,6 @@
 INSTANTIATE_TEST_SUITE_P(
 AArch64CPUTests, AArch64CPUTestFixture,
 ::testing::Values(
-ARMCPUTestParams("invalid", "invalid", "invalid", AArch64::AEK_NONE,
- ""),
-ARMCPUTestParams("generic", "invalid", "none", AArch64::AEK_NONE, ""),
-
 ARMCPUTestParams("cortex-a34", "armv8-a", "crypto-neon-fp-armv8",
  AArch64::AEK_CRC | AArch64::AEK_CRYPTO |
  AArch64::AEK_FP | AArch64::AEK_SIMD,
@@ -1410,14 +1408,14 @@
   // valid, and match the expected 'magic' count.
   EXPECT_EQ(List.size(), NumAArch64CPUArchs);
   for(StringRef CPU : List) {
-EXPECT_NE(AArch64::parseCpu(CPU).Arch, AArch64::INVALID);
+EXPECT_TRUE(AArch64::parseCpu(CPU));
   }
 }
 
 bool testAArch64Arch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
  unsigned ArchAttr) {
-  const AArch64::ArchInfo &AI = AArch64::parseArch(Arch);
-  return AI != AArch64::INVALID;
+  const std::optional AI = AArch64::parseArch(Arch);
+  return AI.has_value();
 }
 
 TEST(TargetParserTest, testAArch64Arch) {
@@ -1453,81 +1451,92 @@
   ARMBuildAttrs::CPUArch::v8_A));
 }
 
-bool testAArch64Extension(StringRef CPUName, const AArch64::ArchInfo &AI,
-  StringRef ArchExt) {
-  return AArch64::getDefaultExtensions(CPUName, AI) &
- AArch64::parseArchExt(ArchExt);
+bool testAArch64Extension(StringRef CPUName, StringRef ArchExt) {
+  std::optional Extension =
+  AArch64::parseArchExtension(ArchExt);
+  if (!Extension)
+return false;
+  std::optional CpuInfo = AArch64::parseCpu(CPUName);
+  return (CpuInfo->Arch.DefaultExts | CpuInfo->DefaultExtensions) & Extension->ID;
+}
+
+bool testAArch64Extension(const AArch64::ArchInfo &AI, StringRef ArchExt) {
+  std::optional Extension =
+  AArch64::parseArchExtension(ArchExt);
+  if (!Extension)
+return false;
+  return AI.DefaultExts & Extension->ID;
 }
 
 TEST(TargetParserTest, testAArch64Extension) {
-  EXPECT_FALSE(testAArch64Extension("cortex-a34", AArch64::INVALID, "ras"));
-  EXPECT_FALSE(testAArch64Extension("cortex-a35", AArch64::INVALID, "ras"));
-  EXPECT_FALSE(testAArch64Extension("cortex-a53", AArch64::INVALID, "ras"));
-  EXPECT_TRUE(testAArch64Extension("cortex-a55", AArch64::INVALID, "ras"));
-  EXPECT_TRUE(testAArch64Extension("cortex-a55", AArch64::INVALID, "fp16"));
-  EXPECT_FALSE(testAArch64Extension("cortex-a55", AArch64::INVALID, "fp16fml"));
-  EXPECT_TRUE(testAArch64Extension("cortex-a55", AArch64::INVALID, "dotprod"));
-  EXPECT_FALSE(testAArch64Extension("cortex-a57", AArch64::INVALID, "ras"));
-  EXPECT_FALSE(testAArch64Extension("cortex-a72", AArch64::INVALID, "ras"));
-  EXPECT_FALSE(testAArch64Extension("cortex-a73", AArch64::INVALID, "ras"));
-  EXPECT_TRUE(testAArch64Extension("cortex-a75", AArch64::INVALID, "ras"));
-  EXPECT_TRUE(testAArch64Extension("cortex-a75", AArch64::INVALID, "fp16"));
-  EXPECT_FALSE(testAArch64Extension("cortex-a75", AArch64::INVALID, "fp16fml"));
-  EXPECT_TRUE(testAArch64Extension("cortex-a75", AArch64::INVALID, "dotprod"));
-  EXPECT_TRUE(

[PATCH] D142540: [NFC][AArch64] Get default features directly from ArchInfo and CpuInfo objects

2023-01-25 Thread Lucas Prates via Phabricator via cfe-commits
pratlucas created this revision.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
pratlucas requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

This updates the AArch64's Target Parser and its uses to capture
information about default features directly from ArchInfo and CpuInfo
objects, instead of relying on an API function to access them
indirectly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142540

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  llvm/include/llvm/TargetParser/AArch64TargetParser.h
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/lib/TargetParser/AArch64TargetParser.cpp
  llvm/unittests/TargetParser/TargetParserTest.cpp

Index: llvm/unittests/TargetParser/TargetParserTest.cpp
===
--- llvm/unittests/TargetParser/TargetParserTest.cpp
+++ llvm/unittests/TargetParser/TargetParserTest.cpp
@@ -966,11 +966,9 @@
   EXPECT_TRUE(Cpu);
   EXPECT_EQ(params.ExpectedArch, Cpu->Arch.Name);
 
-  uint64_t default_extensions =
-  AArch64::getDefaultExtensions(params.CPUName, Cpu->Arch);
   EXPECT_PRED_FORMAT2(
   AssertSameExtensionFlags(params.CPUName),
-  params.ExpectedFlags, default_extensions);
+  params.ExpectedFlags, Cpu->getDefaultExtensions());
 }
 
 INSTANTIATE_TEST_SUITE_P(
@@ -1457,7 +1455,7 @@
   if (!Extension)
 return false;
   std::optional CpuInfo = AArch64::parseCpu(CPUName);
-  return (CpuInfo->Arch.DefaultExts | CpuInfo->DefaultExtensions) & Extension->ID;
+  return CpuInfo->getDefaultExtensions() & Extension->ID;
 }
 
 bool testAArch64Extension(const AArch64::ArchInfo &AI, StringRef ArchExt) {
Index: llvm/lib/TargetParser/AArch64TargetParser.cpp
===
--- llvm/lib/TargetParser/AArch64TargetParser.cpp
+++ llvm/lib/TargetParser/AArch64TargetParser.cpp
@@ -25,19 +25,6 @@
   return 0;
 }
 
-uint64_t AArch64::getDefaultExtensions(StringRef CPU,
-   const AArch64::ArchInfo &AI) {
-  if (CPU == "generic")
-return AI.DefaultExts;
-
-  // Note: this now takes cpu aliases into account
-  std::optional Cpu = parseCpu(CPU);
-  if (!Cpu)
-return AI.DefaultExts;
-
-  return Cpu->Arch.DefaultExts | Cpu->DefaultExtensions;
-}
-
 void AArch64::getFeatureOption(StringRef Name, std::string &Feature) {
   for (const auto &E : llvm::AArch64::Extensions) {
 if (Name == E.Name) {
Index: llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
===
--- llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -6891,8 +6891,7 @@
   // Get the architecture and extension features.
   std::vector AArch64Features;
   AArch64Features.push_back(ArchInfo->ArchFeature);
-  AArch64::getExtensionFeatures(
-  AArch64::getDefaultExtensions("generic", *ArchInfo), AArch64Features);
+  AArch64::getExtensionFeatures(ArchInfo->DefaultExts, AArch64Features);
 
   MCSubtargetInfo &STI = copySTI();
   std::vector ArchFeatures(AArch64Features.begin(), AArch64Features.end());
Index: llvm/include/llvm/TargetParser/AArch64TargetParser.h
===
--- llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -334,6 +334,10 @@
   const ArchInfo &Arch;
   uint64_t DefaultExtensions; // Default extensions for this CPU. These will be
   // ORd with the architecture defaults.
+
+  uint64_t getDefaultExtensions() const {
+return DefaultExtensions | Arch.DefaultExts;
+  }
 };
 
 inline constexpr CpuInfo CpuInfos[] = {
@@ -501,7 +505,6 @@
 StringRef resolveCPUAlias(StringRef CPU);
 
 // Information by Name
-uint64_t getDefaultExtensions(StringRef CPU, const ArchInfo &AI);
 void getFeatureOption(StringRef Name, std::string &Feature);
 std::optional getArchForCpu(StringRef CPU);
 
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -140,7 +140,7 @@
 
 Features.push_back(ArchInfo->ArchFeature);
 
-uint64_t Extension = llvm::AArch64::getDefaultExtensions(CPU, *ArchInfo);
+uint64_t Extension = CpuInfo->getDefaultExtensions();
 if (!llvm::AArch64::getExtensionFeatures(Extension, Features))
   return false;
   }
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -692,10 +692,8 @@
   Features[OtherArch->getSubArch()] = Enabled;
 
   // Set any features implied by the arch

[PATCH] D142541: [NFC][AArch64] Get extension strings directly from ArchInfo in target parser

2023-01-25 Thread Lucas Prates via Phabricator via cfe-commits
pratlucas created this revision.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
pratlucas requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142541

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  llvm/include/llvm/TargetParser/AArch64TargetParser.h
  llvm/lib/TargetParser/AArch64TargetParser.cpp


Index: llvm/lib/TargetParser/AArch64TargetParser.cpp
===
--- llvm/lib/TargetParser/AArch64TargetParser.cpp
+++ llvm/lib/TargetParser/AArch64TargetParser.cpp
@@ -25,16 +25,6 @@
   return 0;
 }
 
-void AArch64::getFeatureOption(StringRef Name, std::string &Feature) {
-  for (const auto &E : llvm::AArch64::Extensions) {
-if (Name == E.Name) {
-  Feature = E.Feature;
-  return;
-}
-  }
-  Feature = Name.str();
-}
-
 std::optional AArch64::getArchForCpu(StringRef CPU) {
   if (CPU == "generic")
 return ARMV8A;
Index: llvm/include/llvm/TargetParser/AArch64TargetParser.h
===
--- llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -505,7 +505,6 @@
 StringRef resolveCPUAlias(StringRef CPU);
 
 // Information by Name
-void getFeatureOption(StringRef Name, std::string &Feature);
 std::optional getArchForCpu(StringRef CPU);
 
 // Parser
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -973,12 +973,16 @@
   }
 }
   for (const auto &Feature : FeaturesVec)
-if (Feature[0] == '+') {
-  std::string F;
-  llvm::AArch64::getFeatureOption(Feature, F);
-  UpdatedFeaturesVec.push_back(F);
-} else if (Feature[0] != '?')
-  UpdatedFeaturesVec.push_back(Feature);
+if (Feature[0] != '?') {
+  std::string UpdatedFeature = Feature;
+  if (Feature[0] == '+') {
+std::optional Extension =
+  llvm::AArch64::parseArchExtension(Feature.substr(1));
+if (Extension)
+  UpdatedFeature = Extension->Feature.str();
+  }
+  UpdatedFeaturesVec.push_back(UpdatedFeature);
+}
 
   return TargetInfo::initFeatureMap(Features, Diags, CPU, UpdatedFeaturesVec);
 }


Index: llvm/lib/TargetParser/AArch64TargetParser.cpp
===
--- llvm/lib/TargetParser/AArch64TargetParser.cpp
+++ llvm/lib/TargetParser/AArch64TargetParser.cpp
@@ -25,16 +25,6 @@
   return 0;
 }
 
-void AArch64::getFeatureOption(StringRef Name, std::string &Feature) {
-  for (const auto &E : llvm::AArch64::Extensions) {
-if (Name == E.Name) {
-  Feature = E.Feature;
-  return;
-}
-  }
-  Feature = Name.str();
-}
-
 std::optional AArch64::getArchForCpu(StringRef CPU) {
   if (CPU == "generic")
 return ARMV8A;
Index: llvm/include/llvm/TargetParser/AArch64TargetParser.h
===
--- llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -505,7 +505,6 @@
 StringRef resolveCPUAlias(StringRef CPU);
 
 // Information by Name
-void getFeatureOption(StringRef Name, std::string &Feature);
 std::optional getArchForCpu(StringRef CPU);
 
 // Parser
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -973,12 +973,16 @@
   }
 }
   for (const auto &Feature : FeaturesVec)
-if (Feature[0] == '+') {
-  std::string F;
-  llvm::AArch64::getFeatureOption(Feature, F);
-  UpdatedFeaturesVec.push_back(F);
-} else if (Feature[0] != '?')
-  UpdatedFeaturesVec.push_back(Feature);
+if (Feature[0] != '?') {
+  std::string UpdatedFeature = Feature;
+  if (Feature[0] == '+') {
+std::optional Extension =
+  llvm::AArch64::parseArchExtension(Feature.substr(1));
+if (Extension)
+  UpdatedFeature = Extension->Feature.str();
+  }
+  UpdatedFeaturesVec.push_back(UpdatedFeature);
+}
 
   return TargetInfo::initFeatureMap(Features, Diags, CPU, UpdatedFeaturesVec);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 56184bb - [AMDGCN] Fix device lib test to work with lib64

2023-01-25 Thread Siu Chi Chan via cfe-commits

Author: Siu Chi Chan
Date: 2023-01-25T09:55:35-05:00
New Revision: 56184bb3ad3ff4f7ca00667ec4759648ce112269

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

LOG: [AMDGCN] Fix device lib test to work with lib64

This change fixes an issue introduced by
https://reviews.llvm.org/D140315.  A new unit test was added to validate
the search for the device libraries being placed in Clang's resource
directory; however, the test didn't take into account that certain
platforms use lib64 for 64-bit library directory.

Differential Revision: https://reviews.llvm.org/D142506

Change-Id: I9c31a4f08fbc383350d82d6aba01987a3ef63e51

Added: 
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/asanrtl.bc
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/hip.bc
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/ockl.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_abi_version_400.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_abi_version_500.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_correctly_rounded_sqrt_off.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_correctly_rounded_sqrt_on.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_daz_opt_off.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_daz_opt_on.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_finite_only_off.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_finite_only_on.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_isa_version_1010.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_isa_version_1011.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_isa_version_1012.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_isa_version_803.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_isa_version_900.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_isa_version_908.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_unsafe_math_off.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_unsafe_math_on.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_wavefrontsize64_off.bc

clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_wavefrontsize64_on.bc
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/ocml.bc
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/opencl.bc

Modified: 
clang/test/Driver/hip-device-libs.hip

Removed: 




diff  --git 
a/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/asanrtl.bc 
b/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/asanrtl.bc
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/hip.bc 
b/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/hip.bc
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/ockl.bc 
b/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/ockl.bc
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_abi_version_400.bc
 
b/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_abi_version_400.bc
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_abi_version_500.bc
 
b/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_abi_version_500.bc
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_correctly_rounded_sqrt_off.bc
 
b/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_correctly_rounded_sqrt_off.bc
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_correctly_rounded_sqrt_on.bc
 
b/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_correctly_rounded_sqrt_on.bc
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_daz_opt_off.bc
 
b/clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_daz_opt_off.bc
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/

[PATCH] D142506: [AMDGCN] Fix device lib test to work with lib64

2023-01-25 Thread Siu Chi Chan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG56184bb3ad3f: [AMDGCN] Fix device lib test to work with 
lib64 (authored by scchan).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142506/new/

https://reviews.llvm.org/D142506

Files:
  clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/asanrtl.bc
  clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/hip.bc
  clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/ockl.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_abi_version_400.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_abi_version_500.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_correctly_rounded_sqrt_off.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_correctly_rounded_sqrt_on.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_daz_opt_off.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_daz_opt_on.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_finite_only_off.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_finite_only_on.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_isa_version_1010.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_isa_version_1011.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_isa_version_1012.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_isa_version_803.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_isa_version_900.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_isa_version_908.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_unsafe_math_off.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_unsafe_math_on.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_wavefrontsize64_off.bc
  
clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/oclc_wavefrontsize64_on.bc
  clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/ocml.bc
  clang/test/Driver/Inputs/rocm_resource_dir/lib64/amdgcn/bitcode/opencl.bc
  clang/test/Driver/hip-device-libs.hip


Index: clang/test/Driver/hip-device-libs.hip
===
--- clang/test/Driver/hip-device-libs.hip
+++ clang/test/Driver/hip-device-libs.hip
@@ -203,7 +203,7 @@
 // ALL-NOT: error:
 // ALL: {{"[^"]*clang[^"]*"}}
 
-// RESDIR-SAME: "-mlink-builtin-bitcode" 
"[[DEVICELIB_DIR:[^"]+(/|)rocm_resource_dir(/|)lib(/|)amdgcn(/|).*]]hip.bc"
+// RESDIR-SAME: "-mlink-builtin-bitcode" 
"[[DEVICELIB_DIR:[^"]+(/|)rocm_resource_dir(/|)lib(64)?(/|)amdgcn(/|).*]]hip.bc"
 // ROCMDIR-SAME: "-mlink-builtin-bitcode" 
"[[DEVICELIB_DIR:[^"]+(/|)rocm(/|)amdgcn(/|).*]]hip.bc"
 
 // ALL-SAME: "-mlink-builtin-bitcode" "[[DEVICELIB_DIR]]ocml.bc"


Index: clang/test/Driver/hip-device-libs.hip
===
--- clang/test/Driver/hip-device-libs.hip
+++ clang/test/Driver/hip-device-libs.hip
@@ -203,7 +203,7 @@
 // ALL-NOT: error:
 // ALL: {{"[^"]*clang[^"]*"}}
 
-// RESDIR-SAME: "-mlink-builtin-bitcode" "[[DEVICELIB_DIR:[^"]+(/|)rocm_resource_dir(/|)lib(/|)amdgcn(/|).*]]hip.bc"
+// RESDIR-SAME: "-mlink-builtin-bitcode" "[[DEVICELIB_DIR:[^"]+(/|)rocm_resource_dir(/|)lib(64)?(/|)amdgcn(/|).*]]hip.bc"
 // ROCMDIR-SAME: "-mlink-builtin-bitcode" "[[DEVICELIB_DIR:[^"]+(/|)rocm(/|)amdgcn(/|).*]]hip.bc"
 
 // ALL-SAME: "-mlink-builtin-bitcode" "[[DEVICELIB_DIR]]ocml.bc"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] df33d17 - [clang][Interp][NFC] Remove an unused function

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T16:03:33+01:00
New Revision: df33d17b38a179fb3f811d1983a48f160220d699

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

LOG: [clang][Interp][NFC] Remove an unused function

Added: 


Modified: 
clang/lib/AST/Interp/PrimType.h

Removed: 




diff  --git a/clang/lib/AST/Interp/PrimType.h b/clang/lib/AST/Interp/PrimType.h
index 042325ad8428..db9d8c3a8579 100644
--- a/clang/lib/AST/Interp/PrimType.h
+++ b/clang/lib/AST/Interp/PrimType.h
@@ -69,24 +69,6 @@ static inline bool aligned(const void *P) {
   return aligned(reinterpret_cast(P));
 }
 
-inline bool isPrimitiveIntegral(PrimType Type) {
-  switch (Type) {
-  case PT_Bool:
-  case PT_Sint8:
-  case PT_Uint8:
-  case PT_Sint16:
-  case PT_Uint16:
-  case PT_Sint32:
-  case PT_Uint32:
-  case PT_Sint64:
-  case PT_Uint64:
-  case PT_Float:
-return true;
-  default:
-return false;
-  }
-}
-
 } // namespace interp
 } // namespace clang
 



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


[clang] c61fe18 - [clang][Interp][NFC] Get rid of InterpSize

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T16:03:33+01:00
New Revision: c61fe188a7e8e8c4b3098998f3dfa194e4842ebc

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

LOG: [clang][Interp][NFC] Get rid of InterpSize

Added: 


Modified: 
clang/lib/AST/Interp/Descriptor.h
clang/lib/AST/Interp/InterpBlock.h
clang/lib/AST/Interp/Program.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Descriptor.h 
b/clang/lib/AST/Interp/Descriptor.h
index 6ef4fc2f4c9b..57cb5728c9ba 100644
--- a/clang/lib/AST/Interp/Descriptor.h
+++ b/clang/lib/AST/Interp/Descriptor.h
@@ -44,9 +44,6 @@ using BlockDtorFn = void (*)(Block *Storage, char *FieldPtr,
 using BlockMoveFn = void (*)(Block *Storage, char *SrcFieldPtr,
  char *DstFieldPtr, Descriptor *FieldDesc);
 
-/// Object size as used by the interpreter.
-using InterpSize = unsigned;
-
 /// Inline descriptor embedded in structures and arrays.
 ///
 /// Such descriptors precede all composite array elements and structure fields.
@@ -81,13 +78,13 @@ struct Descriptor final {
   /// Original declaration, used to emit the error message.
   const DeclTy Source;
   /// Size of an element, in host bytes.
-  const InterpSize ElemSize;
+  const unsigned ElemSize;
   /// Size of the storage, in host bytes.
-  const InterpSize Size;
+  const unsigned Size;
   // Size of the metadata.
-  const InterpSize MDSize;
+  const unsigned MDSize;
   /// Size of the allocation (storage + metadata), in host bytes.
-  const InterpSize AllocSize;
+  const unsigned AllocSize;
 
   /// Value to denote arrays of unknown size.
   static constexpr unsigned UnknownSizeMark = (unsigned)-1;
@@ -96,7 +93,7 @@ struct Descriptor final {
   /// Token to denote structures of unknown size.
   struct UnknownSize {};
 
-  using MetadataSize = std::optional;
+  using MetadataSize = std::optional;
   static constexpr MetadataSize InlineDescMD = sizeof(InlineDescriptor);
 
   /// Pointer to the record, if block contains records.

diff  --git a/clang/lib/AST/Interp/InterpBlock.h 
b/clang/lib/AST/Interp/InterpBlock.h
index f790c50a9123..edcbec232e23 100644
--- a/clang/lib/AST/Interp/InterpBlock.h
+++ b/clang/lib/AST/Interp/InterpBlock.h
@@ -68,7 +68,7 @@ class Block final {
   /// Checks if the block is temporary.
   bool isTemporary() const { return Desc->IsTemporary; }
   /// Returns the size of the block.
-  InterpSize getSize() const { return Desc->getAllocSize(); }
+  unsigned getSize() const { return Desc->getAllocSize(); }
   /// Returns the declaration ID.
   std::optional getDeclID() const { return DeclID; }
 

diff  --git a/clang/lib/AST/Interp/Program.cpp 
b/clang/lib/AST/Interp/Program.cpp
index 5305ddd8de18..106c59463e2b 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -340,7 +340,7 @@ Descriptor *Program::createDescriptor(const DeclTy &D, 
const Type *Ty,
 D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary);
 if (!ElemDesc)
   return nullptr;
-InterpSize ElemSize =
+unsigned ElemSize =
 ElemDesc->getAllocSize() + sizeof(InlineDescriptor);
 if (std::numeric_limits::max() / ElemSize <= NumElems)
   return {};



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


[PATCH] D142534: Fix emission of consteval constructor of derived type

2023-01-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Unit tests fail seems unrelated. I'm seeing the same test fail for a commit 
that is already in main 
https://github.com/llvm/llvm-project/commit/f1f583347d00aad378eb0128e72d3d2e8be5174b
 .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142534/new/

https://reviews.llvm.org/D142534

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


[PATCH] D142484: [LinkerWrapper] Only import static libraries with needed symbols

2023-01-25 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan added a comment.

Hi, this new test fails on AIX. Could you take a look?
https://lab.llvm.org/buildbot/#/builders/214/builds/5477/steps/6/logs/FAIL__Clang__linker-wrapper-libs_c


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142484/new/

https://reviews.llvm.org/D142484

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


[PATCH] D129008: [Clang][OpenMP] Fix the issue that globalization doesn't work with byval struct function argument

2023-01-25 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

In D129008#4079660 , @aaron.ballman 
wrote:

> In D129008#3640194 , 
> @tianshilei1992 wrote:
>
>> `callCStructCopyConstructor` is actually for Objective-C…Cannot use it here.
>
> Is it for ObjC? Looking at the comments, it looks like it's for C:
>
>   // These functions emit calls to the special functions of non-trivial C
>   // structs.

That's not ObjC. It can be C or C++.

My apology I should have added more context here. In OpenMP, we need to 
"globalize" certain captured local variables by allocating another buffers and 
then copy the memory. If the local variables are structs or even C++ classes, 
the copy has to be done by invoking the corresponding copy constructors. 
However, I don't know how to invoke the copy constructor here. 
`callCStructCopyConstructor` only does plain copy. It's not gonna work for C++ 
classes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129008/new/

https://reviews.llvm.org/D129008

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


[clang] af3a171 - [clang][Interp] Compound assign operators for FP values

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T16:25:04+01:00
New Revision: af3a171dcffd73837d1debdd81399d51f0a0054a

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

LOG: [clang][Interp] Compound assign operators for FP values

Differential Revision: https://reviews.llvm.org/D140377

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/AST/Interp/const-fpfeatures.cpp
clang/test/AST/Interp/floats.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 62ed09f078c1..d7b429c38f10 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -550,9 +550,86 @@ bool ByteCodeExprGen::VisitCharacterLiteral(
   return this->emitConst(E->getValue(), E);
 }
 
+template 
+bool ByteCodeExprGen::VisitFloatCompoundAssignOperator(
+const CompoundAssignOperator *E) {
+  assert(E->getType()->isFloatingType());
+
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+  llvm::RoundingMode RM = getRoundingMode(E);
+  QualType LHSComputationType = E->getComputationLHSType();
+  QualType ResultType = E->getComputationResultType();
+  std::optional LT = classify(LHSComputationType);
+  std::optional RT = classify(ResultType);
+
+  if (!LT || !RT)
+return false;
+
+  // First, visit LHS.
+  if (!visit(LHS))
+return false;
+
+  if (!this->emitLoad(*LT, E))
+return false;
+
+  // If necessary, convert LHS to its computation type.
+  if (LHS->getType() != LHSComputationType) {
+const auto *TargetSemantics =
+&Ctx.getASTContext().getFloatTypeSemantics(LHSComputationType);
+
+if (!this->emitCastFP(TargetSemantics, RM, E))
+  return false;
+  }
+
+  // Now load RHS.
+  if (!visit(RHS))
+return false;
+
+  switch (E->getOpcode()) {
+  case BO_AddAssign:
+if (!this->emitAddf(RM, E))
+  return false;
+break;
+  case BO_SubAssign:
+if (!this->emitSubf(RM, E))
+  return false;
+break;
+  case BO_MulAssign:
+if (!this->emitMulf(RM, E))
+  return false;
+break;
+  case BO_DivAssign:
+if (!this->emitDivf(RM, E))
+  return false;
+break;
+  default:
+return false;
+  }
+
+  // If necessary, convert result to LHS's type.
+  if (LHS->getType() != ResultType) {
+const auto *TargetSemantics =
+&Ctx.getASTContext().getFloatTypeSemantics(LHS->getType());
+
+if (!this->emitCastFP(TargetSemantics, RM, E))
+  return false;
+  }
+
+  if (DiscardResult)
+return this->emitStorePop(*LT, E);
+  return this->emitStore(*LT, E);
+}
+
 template 
 bool ByteCodeExprGen::VisitCompoundAssignOperator(
 const CompoundAssignOperator *E) {
+
+  // Handle floating point operations separately here, since they
+  // require special care.
+  if (E->getType()->isFloatingType())
+return VisitFloatCompoundAssignOperator(E);
+
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
   std::optional LHSComputationT =
@@ -567,8 +644,7 @@ bool ByteCodeExprGen::VisitCompoundAssignOperator(
   assert(!E->getType()->isPointerType() &&
  "Support pointer arithmethic in compound assignment operators");
 
-  assert(!E->getType()->isFloatingType() &&
- "Support floating types in compound assignment operators");
+  assert(!E->getType()->isFloatingType() && "Handled above");
 
   // Get LHS pointer, load its value and get RHS value.
   if (!visit(LHS))

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 6b82818fe09a..ed33e0285a8f 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -85,6 +85,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitStringLiteral(const StringLiteral *E);
   bool VisitCharacterLiteral(const CharacterLiteral *E);
   bool VisitCompoundAssignOperator(const CompoundAssignOperator *E);
+  bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E);
 
 protected:
   bool visitExpr(const Expr *E) override;

diff  --git a/clang/test/AST/Interp/const-fpfeatures.cpp 
b/clang/test/AST/Interp/const-fpfeatures.cpp
index 8f5d87291667..e24210810025 100644
--- a/clang/test/AST/Interp/const-fpfeatures.cpp
+++ b/clang/test/AST/Interp/const-fpfeatures.cpp
@@ -50,9 +50,6 @@ float V2 = add_round_up(1.0F, 0x0.01p0F);
 // CHECK: @V2 = {{.*}} float 0x3FF02000
 
 
-/// FIXME: The following tests need support for compound assign operators
-///   with LHS and RHS of 
diff erent semantics.
-#if 0
 constexpr float add_cast_round_down(float x, double y) {
   #pragma STDC FENV_ROUND FE_DOWNWARD
   float res = x;
@@ -70,5 +67,5 @@ constexpr float add_cast_round_up(float x, double y) {
 float V3 = 

[PATCH] D140377: [clang][Interp] Compound assign operators for FP values

2023-01-25 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf3a171dcffd: [clang][Interp] Compound assign operators for 
FP values (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D140377?vs=484184&id=492104#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140377/new/

https://reviews.llvm.org/D140377

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/const-fpfeatures.cpp
  clang/test/AST/Interp/floats.cpp

Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -54,3 +54,27 @@
 // ref-note {{is outside the range of representable values}} \
 // expected-error {{must be initialized by a constant expression}} \
 // expected-note {{is outside the range of representable values}}
+
+namespace compound {
+  constexpr float f1() {
+float f = 0;
+f += 3.0;
+f -= 3.0f;
+
+f += 1;
+f /= 1;
+f /= 1.0;
+f *= f;
+
+f *= 2.0;
+return f;
+  }
+  static_assert(f1() == 2, "");
+
+  constexpr float f2() {
+float f = __FLT_MAX__;
+f += 1.0;
+return f;
+  }
+  static_assert(f2() == __FLT_MAX__, "");
+}
Index: clang/test/AST/Interp/const-fpfeatures.cpp
===
--- clang/test/AST/Interp/const-fpfeatures.cpp
+++ clang/test/AST/Interp/const-fpfeatures.cpp
@@ -50,9 +50,6 @@
 // CHECK: @V2 = {{.*}} float 0x3FF02000
 
 
-/// FIXME: The following tests need support for compound assign operators
-///   with LHS and RHS of different semantics.
-#if 0
 constexpr float add_cast_round_down(float x, double y) {
   #pragma STDC FENV_ROUND FE_DOWNWARD
   float res = x;
@@ -70,5 +67,5 @@
 float V3 = add_cast_round_down(1.0F, 0x0.01p0F);
 float V4 = add_cast_round_up(1.0F, 0x0.01p0F);
 
-
-#endif
+// CHECK: @V3 = {{.*}} float 1.00e+00
+// CHECK: @V4 = {{.*}} float 0x3FF02000
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -85,6 +85,7 @@
   bool VisitStringLiteral(const StringLiteral *E);
   bool VisitCharacterLiteral(const CharacterLiteral *E);
   bool VisitCompoundAssignOperator(const CompoundAssignOperator *E);
+  bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -550,9 +550,86 @@
   return this->emitConst(E->getValue(), E);
 }
 
+template 
+bool ByteCodeExprGen::VisitFloatCompoundAssignOperator(
+const CompoundAssignOperator *E) {
+  assert(E->getType()->isFloatingType());
+
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+  llvm::RoundingMode RM = getRoundingMode(E);
+  QualType LHSComputationType = E->getComputationLHSType();
+  QualType ResultType = E->getComputationResultType();
+  std::optional LT = classify(LHSComputationType);
+  std::optional RT = classify(ResultType);
+
+  if (!LT || !RT)
+return false;
+
+  // First, visit LHS.
+  if (!visit(LHS))
+return false;
+
+  if (!this->emitLoad(*LT, E))
+return false;
+
+  // If necessary, convert LHS to its computation type.
+  if (LHS->getType() != LHSComputationType) {
+const auto *TargetSemantics =
+&Ctx.getASTContext().getFloatTypeSemantics(LHSComputationType);
+
+if (!this->emitCastFP(TargetSemantics, RM, E))
+  return false;
+  }
+
+  // Now load RHS.
+  if (!visit(RHS))
+return false;
+
+  switch (E->getOpcode()) {
+  case BO_AddAssign:
+if (!this->emitAddf(RM, E))
+  return false;
+break;
+  case BO_SubAssign:
+if (!this->emitSubf(RM, E))
+  return false;
+break;
+  case BO_MulAssign:
+if (!this->emitMulf(RM, E))
+  return false;
+break;
+  case BO_DivAssign:
+if (!this->emitDivf(RM, E))
+  return false;
+break;
+  default:
+return false;
+  }
+
+  // If necessary, convert result to LHS's type.
+  if (LHS->getType() != ResultType) {
+const auto *TargetSemantics =
+&Ctx.getASTContext().getFloatTypeSemantics(LHS->getType());
+
+if (!this->emitCastFP(TargetSemantics, RM, E))
+  return false;
+  }
+
+  if (DiscardResult)
+return this->emitStorePop(*LT, E);
+  return this->emitStore(*LT, E);
+}
+
 template 
 bool ByteCodeExprGen::VisitCompoundAssignOperator(
 const CompoundAssignOperator *E) {
+
+  // Handle floating point operations separately 

[PATCH] D129008: [Clang][OpenMP] Fix the issue that globalization doesn't work with byval struct function argument

2023-01-25 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D129008#4079872 , @tianshilei1992 
wrote:

> In D129008#4079660 , @aaron.ballman 
> wrote:
>
>> In D129008#3640194 , 
>> @tianshilei1992 wrote:
>>
>>> `callCStructCopyConstructor` is actually for Objective-C…Cannot use it here.
>>
>> Is it for ObjC? Looking at the comments, it looks like it's for C:
>>
>>   // These functions emit calls to the special functions of non-trivial C
>>   // structs.
>
> That's not ObjC. It can be C or C++.
>
> My apology I should have added more context here. In OpenMP, we need to 
> "globalize" certain captured local variables by allocating another buffers 
> and then copy the memory. If the local variables are structs or even C++ 
> classes, the copy has to be done by invoking the corresponding copy 
> constructors. However, I don't know how to invoke the copy constructor here. 
> `callCStructCopyConstructor` only does plain copy. It's not gonna work for 
> C++ classes.

You need to do it manually. Usually we built the required copy constructor call 
in Sema (it requires correct lookup) and then emitted it in codegen.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129008/new/

https://reviews.llvm.org/D129008

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


[PATCH] D142484: [LinkerWrapper] Only import static libraries with needed symbols

2023-01-25 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D142484#4079869 , @Jake-Egan wrote:

> Hi, this new test fails on AIX. Could you take a look?
> https://lab.llvm.org/buildbot/#/builders/214/builds/5477/steps/6/logs/FAIL__Clang__linker-wrapper-libs_c

I'm actually not sure why the test it failing this way. The failure suggests 
that it's not extracting the members, but I have absolutely no clue what could 
be different on AIX versus all the other systems the tests pass on. Nothing in 
this logic should be target dependent, unless there's something weird with how 
we handle `llvm-ar` or similar.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142484/new/

https://reviews.llvm.org/D142484

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


[PATCH] D142014: [clangd] fix wrong CalleeArgInfo in the hover

2023-01-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:994
   HI.CalleeArgInfo.emplace(toHoverInfoParam(PVD, PP));
+  PassType.PassBy = getPassMode(PVD->getType());
+}

sorry for showing up late to the party but instead of changing rest of the 
code, can we apply this logic only when there are no implicit casts/conversions 
between the arg and callexpr (i.e `N == &OuterNode`)?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142014/new/

https://reviews.llvm.org/D142014

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


[PATCH] D142484: [LinkerWrapper] Only import static libraries with needed symbols

2023-01-25 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D142484#4079869 , @Jake-Egan wrote:

> Hi, this new test fails on AIX. Could you take a look?
> https://lab.llvm.org/buildbot/#/builders/214/builds/5477/steps/6/logs/FAIL__Clang__linker-wrapper-libs_c

I might just put that this test requires Linux. Because I don't think I can 
debug it without access to the system. We don't really support offloading on 
anything but Linux anyway.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142484/new/

https://reviews.llvm.org/D142484

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


[clang] d5fe78d - [Clang] Make the linker wrapper test require Linux

2023-01-25 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-01-25T09:31:59-06:00
New Revision: d5fe78d939d25e5508ae57a2dc0c587c79ad16b1

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

LOG: [Clang] Make the linker wrapper test require Linux

Summary:
We only support this offloading on Linux currently, and this handling of
static libraries is mostly based on Linux systems. So we should only
test those systems for now until we expland to other operating systems
in the future.

Added: 


Modified: 
clang/test/Driver/linker-wrapper-libs.c

Removed: 




diff  --git a/clang/test/Driver/linker-wrapper-libs.c 
b/clang/test/Driver/linker-wrapper-libs.c
index aa82dd5c44b0..a97420c34162 100644
--- a/clang/test/Driver/linker-wrapper-libs.c
+++ b/clang/test/Driver/linker-wrapper-libs.c
@@ -2,6 +2,8 @@
 // REQUIRES: nvptx-registered-target
 // REQUIRES: amdgpu-registered-target
 
+// REQUIRES: system-linux
+
 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.elf.o
 
 #if defined(RESOLVES)



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


[PATCH] D129008: [Clang][OpenMP] Fix the issue that globalization doesn't work with byval struct function argument

2023-01-25 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

In D129008#4079892 , @ABataev wrote:

> In D129008#4079872 , 
> @tianshilei1992 wrote:
>
>> In D129008#4079660 , 
>> @aaron.ballman wrote:
>>
>>> In D129008#3640194 , 
>>> @tianshilei1992 wrote:
>>>
 `callCStructCopyConstructor` is actually for Objective-C…Cannot use it 
 here.
>>>
>>> Is it for ObjC? Looking at the comments, it looks like it's for C:
>>>
>>>   // These functions emit calls to the special functions of non-trivial C
>>>   // structs.
>>
>> That's not ObjC. It can be C or C++.
>>
>> My apology I should have added more context here. In OpenMP, we need to 
>> "globalize" certain captured local variables by allocating another buffers 
>> and then copy the memory. If the local variables are structs or even C++ 
>> classes, the copy has to be done by invoking the corresponding copy 
>> constructors. However, I don't know how to invoke the copy constructor here. 
>> `callCStructCopyConstructor` only does plain copy. It's not gonna work for 
>> C++ classes.
>
> You need to do it manually. Usually we built the required copy constructor 
> call in Sema (it requires correct lookup) and then emitted it in codegen.

But we don't do globalization in Sema right?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129008/new/

https://reviews.llvm.org/D129008

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


[PATCH] D129008: [Clang][OpenMP] Fix the issue that globalization doesn't work with byval struct function argument

2023-01-25 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D129008#4079914 , @tianshilei1992 
wrote:

> In D129008#4079892 , @ABataev wrote:
>
>> In D129008#4079872 , 
>> @tianshilei1992 wrote:
>>
>>> In D129008#4079660 , 
>>> @aaron.ballman wrote:
>>>
 In D129008#3640194 , 
 @tianshilei1992 wrote:

> `callCStructCopyConstructor` is actually for Objective-C…Cannot use it 
> here.

 Is it for ObjC? Looking at the comments, it looks like it's for C:

   // These functions emit calls to the special functions of non-trivial C
   // structs.
>>>
>>> That's not ObjC. It can be C or C++.
>>>
>>> My apology I should have added more context here. In OpenMP, we need to 
>>> "globalize" certain captured local variables by allocating another buffers 
>>> and then copy the memory. If the local variables are structs or even C++ 
>>> classes, the copy has to be done by invoking the corresponding copy 
>>> constructors. However, I don't know how to invoke the copy constructor 
>>> here. `callCStructCopyConstructor` only does plain copy. It's not gonna 
>>> work for C++ classes.
>>
>> You need to do it manually. Usually we built the required copy constructor 
>> call in Sema (it requires correct lookup) and then emitted it in codegen.
>
> But we don't do globalization in Sema right?

Right. If we really needed the constructor call, we emitted special helper 
expressions/statements and stored them in the associated construct/clause, and 
then emitted it, if required.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129008/new/

https://reviews.llvm.org/D129008

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


[PATCH] D140562: [clang][ASTImporter] Improve import of InjectedClassNameType.

2023-01-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 492106.
balazske added a comment.

New patch after more thorough debugging.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140562/new/

https://reviews.llvm.org/D140562

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8084,6 +8084,247 @@
   EXPECT_FALSE(SharedStatePtr->isNewDecl(ToBar));
 }
 
+struct ImportInjectedClassNameType : public ASTImporterOptionSpecificTestBase {
+protected:
+  const CXXRecordDecl *findInjected(const CXXRecordDecl *Parent) {
+for (Decl *Found : Parent->decls()) {
+  const auto *Record = dyn_cast(Found);
+  if (Record && Record->isInjectedClassName())
+return Record;
+}
+return nullptr;
+  }
+
+  void checkInjType(const CXXRecordDecl *D) {
+// The whole redecl chain should have the same InjectedClassNameType
+// instance. The injected record declaration is a separate chain, this
+// should contain the same type too.
+const Type *Ty = nullptr;
+for (const Decl *ReD : D->redecls()) {
+  const auto *ReRD = cast(ReD);
+  EXPECT_TRUE(ReRD->getTypeForDecl());
+  EXPECT_TRUE(!Ty || Ty == ReRD->getTypeForDecl());
+  Ty = ReRD->getTypeForDecl();
+}
+ASSERT_TRUE(Ty);
+const auto *InjTy = Ty->castAs();
+EXPECT_TRUE(InjTy);
+if (CXXRecordDecl *Def = D->getDefinition()) {
+  const CXXRecordDecl *InjRD = findInjected(Def);
+  EXPECT_TRUE(InjRD);
+  EXPECT_EQ(InjRD->getTypeForDecl(), InjTy);
+}
+  }
+
+  void testImport(Decl *ToTU, Decl *FromTU, Decl *FromD) {
+checkInjType(cast(FromD));
+Decl *ToD = Import(FromD, Lang_CXX11);
+if (auto *ToRD = dyn_cast(ToD))
+  checkInjType(ToRD);
+  }
+
+  const char *ToCodeA =
+  R"(
+  template 
+  struct A;
+  )";
+  const char *ToCodeADef =
+  R"(
+  template 
+  struct A {
+typedef A T1;
+  };
+  )";
+  const char *ToCodeC =
+  R"(
+  template 
+  struct C;
+  )";
+  const char *ToCodeCDef =
+  R"(
+  template 
+  struct A {
+typedef A T1;
+  };
+
+  template 
+  struct B {};
+
+  template
+  struct C {
+typedef typename A::T1 T1;
+typedef B T2;
+typedef B T3;
+  };
+  )";
+  const char *FromCode =
+  R"(
+  template 
+  struct A;
+  template 
+  struct A {
+typedef A T1;
+  };
+  template 
+  struct A;
+
+  template 
+  struct B {};
+
+  template 
+  struct C;
+  template 
+  struct C {
+typedef typename A::T1 T1;
+typedef B T2;
+typedef B T3;
+  };
+  template 
+  struct C;
+
+  template 
+  struct D {
+void f(typename C::T3 *);
+  };
+  )";
+};
+
+TEST_P(ImportInjectedClassNameType, ImportADef) {
+  Decl *ToTU = getToTuDecl(ToCodeA, Lang_CXX11);
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX11);
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A"), isDefinition()));
+  testImport(ToTU, FromTU, FromA);
+}
+
+TEST_P(ImportInjectedClassNameType, ImportAFirst) {
+  Decl *ToTU = getToTuDecl(ToCodeA, Lang_CXX11);
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX11);
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+  testImport(ToTU, FromTU, FromA);
+}
+
+TEST_P(ImportInjectedClassNameType, ImportALast) {
+  Decl *ToTU = getToTuDecl(ToCodeA, Lang_CXX11);
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX11);
+  auto *FromA = LastDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+  testImport(ToTU, FromTU, FromA);
+}
+
+TEST_P(ImportInjectedClassNameType, ImportADefToDef) {
+  Decl *ToTU = getToTuDecl(ToCodeADef, Lang_CXX11);
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX11);
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A"), isDefinition()));
+  testImport(ToTU, FromTU, FromA);
+}
+
+TEST_P(ImportInjectedClassNameType, ImportAFirstToDef) {
+  Decl *ToTU = getToTuDecl(ToCodeADef, Lang_CXX11);
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX11);
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+  testImport(ToTU, FromTU, FromA);
+}
+
+TEST_P(ImportInjectedClassNameType, ImportALastToDef) {
+  Decl *ToTU = getToTuDecl(ToCodeADef, Lang_CXX11);
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX11);
+  auto *FromA = LastDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A")));
+  testImport(ToTU, FromTU, FromA);
+}
+
+TEST_P(ImportInjectedClassNameType, ImportCDef) {
+  Decl *ToTU = getToTuDecl(ToCodeC, Lang_CXX11);
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX11);
+  auto *FromC = FirstDeclMat

[clang] 5de6b94 - [clang][Interp][NFC] Replace remaining dyn_cast_or_null uses

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T16:39:26+01:00
New Revision: 5de6b94f856f696832ce7df167e1dbc096fbe598

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

LOG: [clang][Interp][NFC] Replace remaining dyn_cast_or_null uses

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/State.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d7b429c38f10..392052f2 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -965,7 +965,7 @@ unsigned 
ByteCodeExprGen::allocateLocalPrimitive(DeclTy &&Src,
   Descriptor *D = P.createDescriptor(Src, Ty, Descriptor::InlineDescMD, 
IsConst,
  Src.is());
   Scope::Local Local = this->createLocal(D);
-  if (auto *VD = dyn_cast_or_null(Src.dyn_cast()))
+  if (auto *VD = dyn_cast_if_present(Src.dyn_cast()))
 Locals.insert({VD, Local});
   VarScope->add(Local, IsExtended);
   return Local.Offset;
@@ -1433,7 +1433,7 @@ bool ByteCodeExprGen::VisitCallExpr(const 
CallExpr *E) {
 return VisitBuiltinCallExpr(E);
 
   const Decl *Callee = E->getCalleeDecl();
-  if (const auto *FuncDecl = dyn_cast_or_null(Callee)) {
+  if (const auto *FuncDecl = dyn_cast_if_present(Callee)) {
 const Function *Func = getFunction(FuncDecl);
 if (!Func)
   return false;

diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 648f63105985..31f141b9dde3 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -381,7 +381,7 @@ bool CheckThis(InterpState &S, CodePtr OpPC, const Pointer 
&This) {
   const SourceInfo &Loc = S.Current->getSource(OpPC);
 
   bool IsImplicit = false;
-  if (auto *E = dyn_cast_or_null(Loc.asExpr()))
+  if (auto *E = dyn_cast_if_present(Loc.asExpr()))
 IsImplicit = E->isImplicit();
 
   if (S.getLangOpts().CPlusPlus11)

diff  --git a/clang/lib/AST/Interp/State.cpp b/clang/lib/AST/Interp/State.cpp
index 56774f88fb45..f0eed85054ce 100644
--- a/clang/lib/AST/Interp/State.cpp
+++ b/clang/lib/AST/Interp/State.cpp
@@ -142,7 +142,7 @@ void State::addCallStack(unsigned Limit) {
 
 // Use a 
diff erent note for an inheriting constructor, because from the
 // user's perspective it's not really a function at all.
-if (auto *CD = dyn_cast_or_null(F->getCallee())) {
+if (auto *CD = dyn_cast_if_present(F->getCallee())) {
   if (CD->isInheritingConstructor()) {
 addDiag(CallLocation, diag::note_constexpr_inherited_ctor_call_here)
 << CD->getParent();



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


[PATCH] D142534: Fix emission of consteval constructor of derived type

2023-01-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

Makes sense to me but I am not familiar with this area so I will let someone 
else who has more knowledge approve.




Comment at: clang/test/CodeGenCXX/cxx20-consteval-crash.cpp:95
 
+namespace Issue60166 {
+

nitpick: I have been using `GH` as a prefix for Github issues.



Comment at: clang/test/CodeGenCXX/cxx20-consteval-crash.cpp:118
+
+} // namespace Issue60166




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142534/new/

https://reviews.llvm.org/D142534

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


[PATCH] D142534: Fix emission of consteval constructor of derived type

2023-01-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

I think having a link to the github issue in the summary allows for the issue 
be closed automatically when you commit. Is this correct @aaron.ballman I have 
been doing this for a while and they get closed when I commit but maybe there 
is another mechanism involved.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142534/new/

https://reviews.llvm.org/D142534

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


[PATCH] D138337: Add support for kcfi-seal optimization with LTO

2023-01-25 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen added a comment.

In D138337#4078843 , @nickdesaulniers 
wrote:

> Is https://reviews.llvm.org/D142163 a blocker for this?

Yes, and this patch needs to be updated to take `VisibleToRegularObj` into 
account. I'll update this patch once we figure out how the export symbol list 
for relocatable links should work.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138337/new/

https://reviews.llvm.org/D138337

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


[PATCH] D142534: Fix emission of consteval constructor of derived type

2023-01-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

In D142534#4079958 , @shafik wrote:

> I think having a link to the github issue in the summary allows for the issue 
> be closed automatically when you commit. Is this correct @aaron.ballman I 
> have been doing this for a while and they get closed when I commit but maybe 
> there is another mechanism involved.

This works at least for GitHub pull requests, see 
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
 . We've been using this in a downstream project. I was hoping it works in the 
same way for commits, so added issue ID to a commit message.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142534/new/

https://reviews.llvm.org/D142534

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


[clang] 0a6c8c1 - [clang][Interp][NFC] Add a helper function for local variables

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T16:57:59+01:00
New Revision: 0a6c8c1b2570e3fc9c652989afed5de1aee0c0be

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

LOG: [clang][Interp][NFC] Add a helper function for local variables

... in EvalEmitter.

Added: 


Modified: 
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/EvalEmitter.h

Removed: 




diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index 72fd3b45254b..6d89bc407aad 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -208,9 +208,7 @@ bool EvalEmitter::emitGetPtrLocal(uint32_t I, const 
SourceInfo &Info) {
   if (!isActive())
 return true;
 
-  auto It = Locals.find(I);
-  assert(It != Locals.end() && "Missing local variable");
-  Block *B = reinterpret_cast(It->second.get());
+  Block *B = getLocal(I);
   S.Stk.push(B, sizeof(InlineDescriptor));
   return true;
 }
@@ -222,9 +220,7 @@ bool EvalEmitter::emitGetLocal(uint32_t I, const SourceInfo 
&Info) {
 
   using T = typename PrimConv::T;
 
-  auto It = Locals.find(I);
-  assert(It != Locals.end() && "Missing local variable");
-  auto *B = reinterpret_cast(It->second.get());
+  Block *B = getLocal(I);
   S.Stk.push(*reinterpret_cast(B->data()));
   return true;
 }
@@ -236,9 +232,7 @@ bool EvalEmitter::emitSetLocal(uint32_t I, const SourceInfo 
&Info) {
 
   using T = typename PrimConv::T;
 
-  auto It = Locals.find(I);
-  assert(It != Locals.end() && "Missing local variable");
-  auto *B = reinterpret_cast(It->second.get());
+  Block *B = getLocal(I);
   *reinterpret_cast(B->data()) = S.Stk.pop();
   InlineDescriptor &Desc = *reinterpret_cast(B->rawData());
   Desc.IsInitialized = true;
@@ -251,9 +245,8 @@ bool EvalEmitter::emitDestroy(uint32_t I, const SourceInfo 
&Info) {
 return true;
 
   for (auto &Local : Descriptors[I]) {
-auto It = Locals.find(Local.Offset);
-assert(It != Locals.end() && "Missing local variable");
-S.deallocate(reinterpret_cast(It->second.get()));
+Block *B = getLocal(Local.Offset);
+S.deallocate(B);
   }
 
   return true;

diff  --git a/clang/lib/AST/Interp/EvalEmitter.h 
b/clang/lib/AST/Interp/EvalEmitter.h
index 6b6d0d621901..22d7b7c68d10 100644
--- a/clang/lib/AST/Interp/EvalEmitter.h
+++ b/clang/lib/AST/Interp/EvalEmitter.h
@@ -92,6 +92,12 @@ class EvalEmitter : public SourceMapper {
   /// Temporaries which require storage.
   llvm::DenseMap> Locals;
 
+  Block *getLocal(unsigned Index) const {
+auto It = Locals.find(Index);
+assert(It != Locals.end() && "Missing local variable");
+return reinterpret_cast(It->second.get());
+  }
+
   // The emitter always tracks the current instruction and sets OpPC to a token
   // value which is mapped to the location of the opcode being evaluated.
   CodePtr OpPC;



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


[clang] 8b70d97 - [clang][Interp][NFC] Use InitThisField in initializers

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T16:59:19+01:00
New Revision: 8b70d97c39174e1547447e8d33b228384987a152

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

LOG: [clang][Interp][NFC] Use InitThisField in initializers

This creates fewer instructions, makes the bytecode easier to read and
InitThisField also cares about checkingPotentialConstantExpression()
cases.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeStmtGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index ed8794f49a64..522b04254e85 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -107,16 +107,10 @@ bool ByteCodeStmtGen::visitFunc(const 
FunctionDecl *F) {
 const Record::Field *F = R->getField(Member);
 
 if (std::optional T = this->classify(InitExpr)) {
-  if (!this->emitThis(InitExpr))
-return false;
-
   if (!this->visit(InitExpr))
 return false;
 
-  if (!this->emitInitField(*T, F->Offset, InitExpr))
-return false;
-
-  if (!this->emitPopPtr(InitExpr))
+  if (!this->emitInitThisField(*T, F->Offset, InitExpr))
 return false;
 } else {
   // Non-primitive case. Get a pointer to the field-to-initialize



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


[clang] cb70343 - [clang][Interp] Add back Run() call

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T17:01:55+01:00
New Revision: cb703434cbdc71beb02a7b555083f3e160a13363

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

LOG: [clang][Interp] Add back Run() call

We need to run the functions we compiled immediately after to check if
they can ever be a constant expression.

Differential Revision: https://reviews.llvm.org/D140724

Added: 


Modified: 
clang/lib/AST/Interp/Context.cpp
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/arrays.cpp
clang/test/AST/Interp/literals.cpp
clang/test/AST/Interp/records.cpp
clang/test/AST/Interp/shifts.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index 8d1c077e1817..dcf41a5c4020 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -42,6 +42,11 @@ bool Context::isPotentialConstantExpr(State &Parent, const 
FunctionDecl *FD) {
 }
   }
 
+  APValue DummyResult;
+  if (!Run(Parent, Func, DummyResult)) {
+return false;
+  }
+
   return Func->isConstexpr();
 }
 

diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 31f141b9dde3..77b85d81c5f8 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -342,6 +342,11 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const 
Function *F) {
   }
 
   if (!F->isConstexpr()) {
+// Don't emit anything if we're checking for a potential constant
+// expression. That will happen later when actually executing.
+if (S.checkingPotentialConstantExpression())
+  return false;
+
 const SourceLocation &Loc = S.Current->getLocation(OpPC);
 if (S.getLangOpts().CPlusPlus11) {
   const FunctionDecl *DiagDecl = F->getDecl();

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 9613eafdb591..78a65b7995db 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1311,6 +1311,8 @@ inline bool This(InterpState &S, CodePtr OpPC) {
 
 inline bool RVOPtr(InterpState &S, CodePtr OpPC) {
   assert(S.Current->getFunction()->hasRVO());
+  if (S.checkingPotentialConstantExpression())
+return false;
   S.Stk.push(S.Current->getRVOPtr());
   return true;
 }
@@ -1383,9 +1385,11 @@ inline bool Call(InterpState &S, CodePtr &PC, const 
Function *Func) {
   Pointer ThisPtr;
   if (Func->hasThisPointer()) {
 ThisPtr = NewFrame->getThis();
-if (!CheckInvoke(S, PC, ThisPtr)) {
+if (!CheckInvoke(S, PC, ThisPtr))
+  return false;
+
+if (S.checkingPotentialConstantExpression())
   return false;
-}
   }
 
   if (!CheckCallable(S, PC, Func))

diff  --git a/clang/test/AST/Interp/arrays.cpp 
b/clang/test/AST/Interp/arrays.cpp
index accef60e38d6..413ab2fa45d8 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -209,7 +209,8 @@ class AU {
 public:
   int a;
   constexpr AU() : a(5 / 0) {} // expected-warning {{division by zero is 
undefined}} \
-   // expected-note {{division by zero}} \
+   // expected-note 2{{division by zero}} \
+   // expected-error {{never produces a constant 
expression}} \
// ref-error {{never produces a constant 
expression}} \
// ref-note 2{{division by zero}} \
// ref-warning {{division by zero is undefined}}
@@ -296,10 +297,11 @@ namespace IncDec {
   }
   static_assert(getSecondToLast2() == 3, "");
 
-  constexpr int bad1() { // ref-error {{never produces a constant expression}}
+  constexpr int bad1() { // ref-error {{never produces a constant expression}} 
\
+ // expected-error {{never produces a constant 
expression}}
 const int *e =  E + 3;
 e++; // This is fine because it's a one-past-the-end pointer
-return *e; // expected-note {{read of dereferenced one-past-the-end 
pointer}} \
+return *e; // expected-note 2{{read of dereferenced one-past-the-end 
pointer}} \
// ref-note 2{{read of dereferenced one-past-the-end pointer}}
   }
   static_assert(bad1() == 0, ""); // expected-error {{not an integral constant 
expression}} \
@@ -307,9 +309,10 @@ namespace IncDec {
   // ref-error {{not an integral constant 
expression}} \
   // ref-note {{in call to}}
 
-  constexpr int bad2() { // ref-error {{never produces a constant expression}}
+  constexpr int bad2() { // ref-error {{never produces a constant expression}} 
\
+ // expected-error {{never produces a constant 
expression}}
 const int *e = E + 4;
-  

[PATCH] D140724: [clang][Interp] Add back Run() call

2023-01-25 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcb703434cbdc: [clang][Interp] Add back Run() call (authored 
by tbaeder).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140724/new/

https://reviews.llvm.org/D140724

Files:
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/test/AST/Interp/arrays.cpp
  clang/test/AST/Interp/literals.cpp
  clang/test/AST/Interp/records.cpp
  clang/test/AST/Interp/shifts.cpp

Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ clang/test/AST/Interp/shifts.cpp
@@ -8,7 +8,9 @@
 
 namespace shifts {
   constexpr void test() { // ref-error {{constexpr function never produces a constant expression}} \
-  // ref-cxx17-error {{constexpr function never produces a constant expression}}
+  // ref-cxx17-error {{constexpr function never produces a constant expression}} \
+  // expected-error {{constexpr function never produces a constant expression}} \
+  // cxx17-error {{constexpr function never produces a constant expression}} \
 
 char c; // cxx17-warning {{uninitialized variable}} \
 // ref-cxx17-warning {{uninitialized variable}}
@@ -19,6 +21,8 @@
 c = 1 << -0;
 c = 1 >> -0;
 c = 1 << -1; // expected-warning {{shift count is negative}} \
+ // expected-note {{negative shift count -1}} \
+ // cxx17-note {{negative shift count -1}} \
  // cxx17-warning {{shift count is negative}} \
  // ref-warning {{shift count is negative}} \
  // ref-note {{negative shift count -1}} \
Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -174,10 +174,11 @@
 constexpr int get12() { return 12; }
   };
 
-  constexpr int foo() { // ref-error {{never produces a constant expression}}
+  constexpr int foo() { // ref-error {{never produces a constant expression}} \
+// expected-error {{never produces a constant expression}}
 S *s = nullptr;
 return s->get12(); // ref-note 2{{member call on dereferenced null pointer}} \
-   // expected-note {{member call on dereferenced null pointer}}
+   // expected-note 2{{member call on dereferenced null pointer}}
 
   }
   static_assert(foo() == 12, ""); // ref-error {{not an integral constant expression}} \
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -452,10 +452,11 @@
   static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
// ref-note {{in call to 'uninit()'}}
 
-  constexpr int OverFlow() { // ref-error {{never produces a constant expression}}
+  constexpr int OverFlow() { // ref-error {{never produces a constant expression}} \
+ // expected-error {{never produces a constant expression}}
 int a = INT_MAX;
 ++a; // ref-note 2{{is outside the range}} \
- // expected-note {{is outside the range}}
+ // expected-note 2{{is outside the range}}
 return -1;
   }
   static_assert(OverFlow() == -1, "");  // expected-error {{not an integral constant expression}} \
@@ -464,10 +465,11 @@
 // ref-note {{in call to 'OverFlow()'}}
 
 
-  constexpr int UnderFlow() { // ref-error {{never produces a constant expression}}
+  constexpr int UnderFlow() { // ref-error {{never produces a constant expression}} \
+  // expected-error {{never produces a constant expression}}
 int a = INT_MIN;
 --a; // ref-note 2{{is outside the range}} \
- // expected-note {{is outside the range}}
+ // expected-note 2{{is outside the range}}
 return -1;
   }
   static_assert(UnderFlow() == -1, "");  // expected-error {{not an integral constant expression}} \
Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -209,7 +209,8 @@
 public:
   int a;
   constexpr AU() : a(5 / 0) {} // expected-warning {{division by zero is undefined}} \
-   // expected-note {{division by zero}} \
+   // expected-note 2{{division by zero}} \
+   // expected-error {{never produces a constant expression}} \
// ref-error {{never produ

[PATCH] D135495: [clang-tidy] handle pointers in `ExceptionAnalyzer`

2023-01-25 Thread Domján Dániel via Phabricator via cfe-commits
isuckatcs added a comment.

This patch got a little bit out of control at the last revision, so I decided 
to remove every change from clang and add everything to the `ExceptionAnalyzer` 
only.
The reason for that is with exceptions we have less conversions to check than 
we have inside the compiler, which can lead to confusion.

For example:

  class A {};
  class B : public A {};
  
  int A::* pa;
  int B::* pb = pa; <-- valid outside of exception handler, invalid in 
exception handler

We can have the conversion `int B::* pb = pa;` because of `7.3.12 
Pointer-to-member conversions`, which is by standard not performed when an 
exception needs to be caught.
See godbolt . (MSVC does catch `A::*` with a 
`B::*` handler for some reason, maybe I miss some flag)

For the above reason, sadly we can't test the changes the way you suggested 
@xazax.hun, like checking if the assigment compiles or not.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135495/new/

https://reviews.llvm.org/D135495

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


[PATCH] D142550: Fix sizeof of boolean vector

2023-01-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Ensure it is at least 8 bits.

Fixes #59801


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142550

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/vector-bool.cpp


Index: clang/test/SemaCXX/vector-bool.cpp
===
--- clang/test/SemaCXX/vector-bool.cpp
+++ clang/test/SemaCXX/vector-bool.cpp
@@ -90,3 +90,9 @@
   foo(eight_bools.w);// expected-error@90 {{illegal vector component name 
''w''}}
   foo(eight_bools.wyx);  // expected-error@91 {{illegal vector component name 
''wyx''}}
 }
+
+void Sizeof() {
+  using FourBools = bool __attribute__((ext_vector_type(8)));
+  static_assert(sizeof(FourBools) == 1);
+  static_assert(sizeof(EightBools) == 1);
+}
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2002,7 +2002,8 @@
 TypeInfo EltInfo = getTypeInfo(VT->getElementType());
 Width = VT->isExtVectorBoolType() ? VT->getNumElements()
   : EltInfo.Width * VT->getNumElements();
-// Enforce at least byte alignment.
+// Enforce at least byte size and alignment.
+Width = std::max(8, Width);
 Align = std::max(8, Width);
 
 // If the alignment is not a power of 2, round up to the next power of 2.


Index: clang/test/SemaCXX/vector-bool.cpp
===
--- clang/test/SemaCXX/vector-bool.cpp
+++ clang/test/SemaCXX/vector-bool.cpp
@@ -90,3 +90,9 @@
   foo(eight_bools.w);// expected-error@90 {{illegal vector component name ''w''}}
   foo(eight_bools.wyx);  // expected-error@91 {{illegal vector component name ''wyx''}}
 }
+
+void Sizeof() {
+  using FourBools = bool __attribute__((ext_vector_type(8)));
+  static_assert(sizeof(FourBools) == 1);
+  static_assert(sizeof(EightBools) == 1);
+}
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2002,7 +2002,8 @@
 TypeInfo EltInfo = getTypeInfo(VT->getElementType());
 Width = VT->isExtVectorBoolType() ? VT->getNumElements()
   : EltInfo.Width * VT->getNumElements();
-// Enforce at least byte alignment.
+// Enforce at least byte size and alignment.
+Width = std::max(8, Width);
 Align = std::max(8, Width);
 
 // If the alignment is not a power of 2, round up to the next power of 2.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135495: [clang-tidy] handle pointers in `ExceptionAnalyzer`

2023-01-25 Thread Domján Dániel via Phabricator via cfe-commits
isuckatcs updated this revision to Diff 492115.
isuckatcs added a comment.

- Reverted the changes related to clang itself
- Added more checks for exception handling
- `isQualificationConvertiblePointer` is now iterative, not recursive
- Added more test cases


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135495/new/

https://reviews.llvm.org/D135495

Files:
  clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
  clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -101,6 +101,126 @@
   }
 }
 
+void throw_catch_pointer_c() noexcept {
+  try {
+int a = 1;
+throw &a;
+  } catch(const int *) {}
+}
+
+void throw_catch_pointer_v() noexcept {
+  try {
+int a = 1;
+throw &a;
+  } catch(volatile int *) {}
+}
+
+void throw_catch_pointer_cv() noexcept {
+  try {
+int a = 1;
+throw &a;
+  } catch(const volatile int *) {}
+}
+
+void throw_catch_multi_ptr_1() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_catch_multi_ptr_1' which should not throw exceptions
+  try {
+char **p = 0;
+throw p;
+  } catch (const char **) {
+  }
+}
+
+void throw_catch_multi_ptr_2() noexcept {
+  try {
+char **p = 0;
+throw p;
+  } catch (const char *const *) {
+  }
+}
+
+void throw_catch_multi_ptr_3() noexcept {
+  try {
+char **p = 0;
+throw p;
+  } catch (volatile char *const *) {
+  }
+}
+
+void throw_catch_multi_ptr_4() noexcept {
+  try {
+char **p = 0;
+throw p;
+  } catch (volatile const char *const *) {
+  }
+}
+
+// FIXME: In this case 'a' is convertible to the handler and should be caught
+// but in reality it's thrown. Note that clang doesn't report a warning for 
+// this either.
+void throw_catch_multi_ptr_5() noexcept {
+  try {
+double *a[2][3];
+throw a;
+  } catch (double *(*)[3]) {
+  }
+}
+
+
+void throw_c_catch_pointer() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_c_catch_pointer' which should not throw exceptions
+  try {
+int a = 1;
+const int *p = &a;
+throw p;
+  } catch(int *) {}
+}
+
+void throw_c_catch_pointer_v() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_c_catch_pointer_v' which should not throw exceptions
+  try {
+int a = 1;
+const int *p = &a;
+throw p;
+  } catch(volatile int *) {}
+}
+
+void throw_v_catch_pointer() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_v_catch_pointer' which should not throw exceptions
+  try {
+int a = 1;
+volatile int *p = &a;
+throw p;
+  } catch(int *) {}
+}
+
+void throw_v_catch_pointer_c() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_v_catch_pointer_c' which should not throw exceptions
+  try {
+int a = 1;
+volatile int *p = &a;
+throw p;
+  } catch(const int *) {}
+}
+
+void throw_cv_catch_pointer_c() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_cv_catch_pointer_c' which should not throw exceptions
+  try {
+int a = 1;
+const volatile int *p = &a;
+throw p;
+  } catch(const int *) {}
+}
+
+void throw_cv_catch_pointer_v() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_cv_catch_pointer_v' which should not throw exceptions
+  try {
+int a = 1;
+const volatile int *p = &a;
+throw p;
+  } catch(volatile int *) {}
+}
+
 class base {};
 class derived: public base {};
 
@@ -112,6 +232,84 @@
   }
 }
 
+void throw_derived_catch_base_ptr_c() noexcept {
+  try {
+derived d;
+throw &d; 
+  } catch(const base *) {
+  }
+}
+
+void throw_derived_catch_base_ptr() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ptr' which should not throw exceptions
+  try {
+derived d;
+const derived *p = &d;
+throw p; 
+  } catch(base *) {
+  }
+}
+
+class A {};
+class B : A {};
+class C : protected A {};
+class D : public A {};
+class E : public A, public D {};
+
+void throw_derived_catch_base_private() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private' which should not throw exceptions
+  try {
+B b;
+throw b; 
+  } catch(A) {
+  }
+}
+
+void throw_derived_catch_base_private_ptr() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_bas

[PATCH] D142327: [clang][RISCV] Fix ABI handling of empty structs with hard FP calling conventions in C++

2023-01-25 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

Thanks Luis for the quick review. As an important part of this is trying to 
align with gcc/g++ I'd really appreciate a review from @kito-cheng too if you 
have the time (thanks in advance!).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142327/new/

https://reviews.llvm.org/D142327

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


[PATCH] D142550: Fix sizeof of boolean vector

2023-01-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/SemaCXX/vector-bool.cpp:95
+void Sizeof() {
+  using FourBools = bool __attribute__((ext_vector_type(8)));
+  static_assert(sizeof(FourBools) == 1);

Should be 4 instead of 8, shouldn't it?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142550/new/

https://reviews.llvm.org/D142550

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


[PATCH] D142550: Fix sizeof of boolean vector

2023-01-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/test/SemaCXX/vector-bool.cpp:95
+void Sizeof() {
+  using FourBools = bool __attribute__((ext_vector_type(8)));
+  static_assert(sizeof(FourBools) == 1);

This is not four bools.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142550/new/

https://reviews.llvm.org/D142550

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


[PATCH] D142550: Fix sizeof of boolean vector

2023-01-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/test/SemaCXX/vector-bool.cpp:95
+void Sizeof() {
+  using FourBools = bool __attribute__((ext_vector_type(8)));
+  static_assert(sizeof(FourBools) == 1);

tbaeder wrote:
> Fznamznon wrote:
> > This is not four bools.
> Should be 4 instead of 8, shouldn't it?
Can you add another couple of 'oddball' sizes and make sure they work out 
right?  I THINK the alignment logic gets it right, but I'd like tests to 
confirm.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142550/new/

https://reviews.llvm.org/D142550

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


[PATCH] D142550: Fix sizeof of boolean vector

2023-01-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/test/SemaCXX/vector-bool.cpp:95
+void Sizeof() {
+  using FourBools = bool __attribute__((ext_vector_type(8)));
+  static_assert(sizeof(FourBools) == 1);

erichkeane wrote:
> tbaeder wrote:
> > Fznamznon wrote:
> > > This is not four bools.
> > Should be 4 instead of 8, shouldn't it?
> Can you add another couple of 'oddball' sizes and make sure they work out 
> right?  I THINK the alignment logic gets it right, but I'd like tests to 
> confirm.
Yes, will fix in a moment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142550/new/

https://reviews.llvm.org/D142550

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


[clang] eee8075 - [clang][Interp][NFCI] Remove an unnecessary DupPtr op

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T17:09:33+01:00
New Revision: eee8075f57f018e047b5bc8923b0284a6f62ea3e

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

LOG: [clang][Interp][NFCI] Remove an unnecessary DupPtr op

When initializing a primitive array, we don't need to dup the base
pointer for every element.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 392052f2..a2f0a77142ad 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1022,8 +1022,6 @@ bool 
ByteCodeExprGen::visitArrayInitializer(const Expr *Initializer) {
 for (const Expr *Init : InitList->inits()) {
   if (std::optional T = classify(Init->getType())) {
 // Visit the primitive element like normal.
-if (!this->emitDupPtr(Init))
-  return false;
 if (!this->visit(Init))
   return false;
 if (!this->emitInitElem(*T, ElementIndex, Init))
@@ -1042,9 +1040,9 @@ bool 
ByteCodeExprGen::visitArrayInitializer(const Expr *Initializer) {
 
 if (!visitInitializer(Init))
   return false;
-  }
 if (!this->emitPopPtr(Init))
   return false;
+  }
 
   ++ElementIndex;
 }



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


[clang] c68af56 - [clang][Interp][NFC] Cast in InterpFrame::localBlock

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T17:09:34+01:00
New Revision: c68af565ff0c2fdc5537e9ac0c2d7c75df44b035

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

LOG: [clang][Interp][NFC] Cast in InterpFrame::localBlock

We know we save a Block* here, so do the cast there instead of
everywhere we're calling this function.

Added: 


Modified: 
clang/lib/AST/Interp/InterpFrame.cpp
clang/lib/AST/Interp/InterpFrame.h

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index ee29997cfecc..584cf1a9a69e 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -76,7 +76,7 @@ InterpFrame::~InterpFrame() {
 
 void InterpFrame::destroy(unsigned Idx) {
   for (auto &Local : Func->getScope(Idx).locals()) {
-S.deallocate(reinterpret_cast(localBlock(Local.Offset)));
+S.deallocate(localBlock(Local.Offset));
   }
 }
 
@@ -185,8 +185,7 @@ const FunctionDecl *InterpFrame::getCallee() const {
 
 Pointer InterpFrame::getLocalPointer(unsigned Offset) const {
   assert(Offset < Func->getFrameSize() && "Invalid local offset.");
-  return Pointer(reinterpret_cast(localBlock(Offset)),
- sizeof(InlineDescriptor));
+  return Pointer(localBlock(Offset), sizeof(InlineDescriptor));
 }
 
 Pointer InterpFrame::getParamPointer(unsigned Off) {

diff  --git a/clang/lib/AST/Interp/InterpFrame.h 
b/clang/lib/AST/Interp/InterpFrame.h
index bfa02c90ebec..c0f4825096be 100644
--- a/clang/lib/AST/Interp/InterpFrame.h
+++ b/clang/lib/AST/Interp/InterpFrame.h
@@ -133,8 +133,8 @@ class InterpFrame final : public Frame {
   }
 
   /// Returns a pointer to a local's block.
-  void *localBlock(unsigned Offset) const {
-return Locals.get() + Offset - sizeof(Block);
+  Block *localBlock(unsigned Offset) const {
+return reinterpret_cast(Locals.get() + Offset - sizeof(Block));
   }
 
   // Returns the inline descriptor of the local.



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


[PATCH] D140415: [flang] stack arrays pass

2023-01-25 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Quick questions, and they might not apply here since you seem to only look at 
explicit Flang generated values, right?
Are you handling unwinding/exceptions, especially in-between the allocation and 
deallocation?
Are you handling non-accessible stacks (e.g., on GPUs) for escaping pointers?
Do you check the size to (reasonably) ensure we don't overflow the stack?
Are you trying to move the alloca into the entry, if possible?

Did you check LLVM's heap2stack and the corresponding tests?
https://github.com/llvm/llvm-project/blob/c68af565ff0c2fdc5537e9ac0c2d7c75df44b035/llvm/lib/Transforms/IPO/AttributorAttributes.cpp#L6480
https://github.com/llvm/llvm-project/blob/main/llvm/test/Transforms/Attributor/heap_to_stack.ll
https://github.com/llvm/llvm-project/blob/main/llvm/test/Transforms/Attributor/heap_to_stack_gpu.ll


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140415/new/

https://reviews.llvm.org/D140415

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


[clang-tools-extra] c4c5e79 - Fix warnings

2023-01-25 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-01-25T08:21:29-08:00
New Revision: c4c5e79dd4b4c78eee7cffd9b0d7394b5bedcf12

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

LOG: Fix warnings

This patch fixes:

  clang-tools-extra/clangd/Hover.cpp:1036:28: warning: unused variable
  ‘MTE’ [-Wunused-variable]

  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:22295:19: error:
  unused variable 'AN' [-Werror,-Wunused-variable]

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 7f09e091afcb1..8649ddc9479ed 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -1033,8 +1033,7 @@ void maybeAddCalleeArgInfo(const SelectionTree::Node *N, 
HoverInfo &HI,
 PassType.PassBy = HoverInfo::PassType::Value;
   else
 PassType.Converted = true;
-} else if (const auto *MTE =
-   CastNode->ASTNode.get()) {
+} else if (CastNode->ASTNode.get()) {
   // Can't bind a non-const-ref to a temporary, so has to be const-ref
   PassType.PassBy = HoverInfo::PassType::ConstRef;
 } else { // Unknown implicit node, assume type conversion.

diff  --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 46db20ecdd742..5afa4fbf9288d 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -22292,8 +22292,7 @@ void AArch64TargetLowering::ReplaceNodeResults(
   case ISD::ATOMIC_LOAD_AND:
   case ISD::ATOMIC_LOAD_OR:
   case ISD::ATOMIC_SWAP: {
-AtomicSDNode *AN = cast(N);
-assert(AN->getVal().getValueType() == MVT::i128 &&
+assert(cast(N)->getVal().getValueType() == MVT::i128 &&
"Expected 128-bit atomicrmw.");
 // These need custom type legalisation so we go directly to instruction.
 ReplaceATOMIC_LOAD_128Results(N, Results, DAG, Subtarget);



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


[PATCH] D142506: [AMDGCN] Fix device lib test to work with lib64

2023-01-25 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D142506#4078532 , @scchan wrote:

> In D142506#4078402 , @arsenm wrote:
>
>> The resource directory should be strictly controlled. why would lib64 ever 
>> be used here?
>
> The intention is to eventually move the device libs into the library 
> directory inside clang's resource directory, which its name is affected 
> LLVM_LIBDIR_SUFFIX.

The resource directory is the directory above lib64, there's no reason to put 
this in something configurable


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142506/new/

https://reviews.llvm.org/D142506

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


[PATCH] D142550: Fix sizeof of boolean vector

2023-01-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 492125.
Fznamznon added a comment.

Adjust the test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142550/new/

https://reviews.llvm.org/D142550

Files:
  clang/test/SemaCXX/vector-bool.cpp


Index: clang/test/SemaCXX/vector-bool.cpp
===
--- clang/test/SemaCXX/vector-bool.cpp
+++ clang/test/SemaCXX/vector-bool.cpp
@@ -92,7 +92,11 @@
 }
 
 void Sizeof() {
-  using FourBools = bool __attribute__((ext_vector_type(8)));
+  using FourBools = bool __attribute__((ext_vector_type(4)));
+  using NineBools = bool __attribute__((ext_vector_type(9)));
+  using ABunchOfBools = bool __attribute__((ext_vector_type(28)));
   static_assert(sizeof(FourBools) == 1);
   static_assert(sizeof(EightBools) == 1);
+  static_assert(sizeof(NineBools) == 2);
+  static_assert(sizeof(ABunchOfBools) == 4);
 }


Index: clang/test/SemaCXX/vector-bool.cpp
===
--- clang/test/SemaCXX/vector-bool.cpp
+++ clang/test/SemaCXX/vector-bool.cpp
@@ -92,7 +92,11 @@
 }
 
 void Sizeof() {
-  using FourBools = bool __attribute__((ext_vector_type(8)));
+  using FourBools = bool __attribute__((ext_vector_type(4)));
+  using NineBools = bool __attribute__((ext_vector_type(9)));
+  using ABunchOfBools = bool __attribute__((ext_vector_type(28)));
   static_assert(sizeof(FourBools) == 1);
   static_assert(sizeof(EightBools) == 1);
+  static_assert(sizeof(NineBools) == 2);
+  static_assert(sizeof(ABunchOfBools) == 4);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142550: Fix sizeof of boolean vector

2023-01-25 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/test/SemaCXX/vector-bool.cpp:95
+void Sizeof() {
+  using FourBools = bool __attribute__((ext_vector_type(8)));
+  static_assert(sizeof(FourBools) == 1);

Fznamznon wrote:
> erichkeane wrote:
> > tbaeder wrote:
> > > Fznamznon wrote:
> > > > This is not four bools.
> > > Should be 4 instead of 8, shouldn't it?
> > Can you add another couple of 'oddball' sizes and make sure they work out 
> > right?  I THINK the alignment logic gets it right, but I'd like tests to 
> > confirm.
> Yes, will fix in a moment.
Okay, done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142550/new/

https://reviews.llvm.org/D142550

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


[clang] 93aa412 - [clang][Interp][NFC] Refector OffsetHelper

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-25T17:22:59+01:00
New Revision: 93aa4123066fb32a8e3c757ff0a280cfd93ec9f3

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

LOG: [clang][Interp][NFC] Refector OffsetHelper

There was a FIXME comment for this. Stop getting the values in
OffsetHelper and let the caller do that instead, so we can control
whether the value(s) are removed from the stack at all.

Also use ArithOp instead of the unclear boolean for Add.

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 78a65b7995db..466df04ac08d 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1082,11 +1082,9 @@ bool InitElemPop(InterpState &S, CodePtr OpPC, uint32_t 
Idx) {
 // AddOffset, SubOffset
 
//===--===//
 
-template  bool OffsetHelper(InterpState &S, CodePtr OpPC) {
-  // Fetch the pointer and the offset.
-  const T &Offset = S.Stk.pop();
-  const Pointer &Ptr = S.Stk.pop();
-
+template 
+bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset,
+  const Pointer &Ptr) {
   if (!CheckRange(S, OpPC, Ptr, CSK_ArrayToPointer))
 return false;
 
@@ -1113,7 +,8 @@ template  bool 
OffsetHelper(InterpState &S, CodePtr OpPC) {
 const unsigned Bits = Offset.bitWidth();
 APSInt APOffset(Offset.toAPSInt().extend(Bits + 2), false);
 APSInt APIndex(Index.toAPSInt().extend(Bits + 2), false);
-APSInt NewIndex = Add ? (APIndex + APOffset) : (APIndex - APOffset);
+APSInt NewIndex =
+(Op == ArithOp::Add) ? (APIndex + APOffset) : (APIndex - APOffset);
 S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_array_index)
 << NewIndex
 << /*array*/ static_cast(!Ptr.inArray())
@@ -1122,7 +1121,7 @@ template  bool 
OffsetHelper(InterpState &S, CodePtr OpPC) {
   };
 
   unsigned MaxOffset = MaxIndex - Ptr.getIndex();
-  if constexpr (Add) {
+  if constexpr (Op == ArithOp::Add) {
 // If the new offset would be negative, bail out.
 if (Offset.isNegative() && (Offset.isMin() || -Offset > Index))
   return InvalidOffset();
@@ -1144,7 +1143,7 @@ template  bool 
OffsetHelper(InterpState &S, CodePtr OpPC) {
   int64_t WideIndex = static_cast(Index);
   int64_t WideOffset = static_cast(Offset);
   int64_t Result;
-  if constexpr (Add)
+  if constexpr (Op == ArithOp::Add)
 Result = WideIndex + WideOffset;
   else
 Result = WideIndex - WideOffset;
@@ -1155,12 +1154,16 @@ template  bool 
OffsetHelper(InterpState &S, CodePtr OpPC) {
 
 template ::T>
 bool AddOffset(InterpState &S, CodePtr OpPC) {
-  return OffsetHelper(S, OpPC);
+  const T &Offset = S.Stk.pop();
+  const Pointer &Ptr = S.Stk.pop();
+  return OffsetHelper(S, OpPC, Offset, Ptr);
 }
 
 template ::T>
 bool SubOffset(InterpState &S, CodePtr OpPC) {
-  return OffsetHelper(S, OpPC);
+  const T &Offset = S.Stk.pop();
+  const Pointer &Ptr = S.Stk.pop();
+  return OffsetHelper(S, OpPC, Offset, Ptr);
 }
 
 template 
@@ -1172,10 +1175,9 @@ static inline bool IncDecPtrHelper(InterpState &S, 
CodePtr OpPC) {
   S.Stk.push(Ptr.deref());
 
   // Now the current Ptr again and a constant 1.
-  // FIXME: We shouldn't have to push these two on the stack.
-  S.Stk.push(Ptr.deref());
-  S.Stk.push(OneT::from(1));
-  if (!OffsetHelper(S, OpPC))
+  Pointer P = Ptr.deref();
+  OneT One = OneT::from(1);
+  if (!OffsetHelper(S, OpPC, One, P))
 return false;
 
   // Store the new value.



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


[PATCH] D142555: Refactor symbol page parsing.

2023-01-25 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142555

Files:
  clang/tools/include-mapping/cppreference_parser.py


Index: clang/tools/include-mapping/cppreference_parser.py
===
--- clang/tools/include-mapping/cppreference_parser.py
+++ clang/tools/include-mapping/cppreference_parser.py
@@ -47,7 +47,7 @@
 
   Returns a list of headers.
   """
-  headers = set()
+  symbol_headers = set()
   all_headers = set()
 
   soup = BeautifulSoup(symbol_page_html, "html.parser")
@@ -58,31 +58,39 @@
   #   Defined in header   .t-dsc-header
   #   decl2.t-dcl
   for table in soup.select('table.t-dcl-begin, table.t-dsc-begin'):
-current_headers = []
-was_decl = False
-for row in table.select('tr'):
-  if _HasClass(row, 't-dcl', 't-dsc'):
-was_decl = True
-# Symbols are in the first cell.
-found_symbols = row.find('td').stripped_strings
-if not symbol_name in found_symbols:
-  continue
-headers.update(current_headers)
-  elif _HasClass(row, 't-dsc-header'):
-# If we saw a decl since the last header, this is a new block of 
headers
-# for a new block of decls.
-if was_decl:
-  current_headers = []
-was_decl = False
+rows = table.select('tr')
+i = 0
+while i < len(rows):
+  start = i
+  current_headers = set()
+  while i < len(rows) and _HasClass(rows[i], 't-dsc-header'):
+row = rows[i]
 # There are also .t-dsc-header for "defined in namespace".
 if not "Defined in header " in row.text:
+  i = i + 1
   continue
 # The interesting header content (e.g. ) is wrapped in .
 for header_code in row.find_all("code"):
-  current_headers.append(header_code.text)
   all_headers.add(header_code.text)
-  # If the symbol was never named, consider all named headers.
-  return headers or all_headers
+  current_headers.add(header_code.text)
+i = i + 1
+  # some tables have header rows, skip them  
+  while i < len(rows) and _HasClass(rows[i], 't-dsc-hitem'):
+i = i + 1
+  while i < len(rows) and (_HasClass(rows[i], 't-dcl', 't-dsc') or not 
rows[i].has_attr("class")):
+row = rows[i]
+# Symbols are in the first cell.
+found_symbols = row.find('td').stripped_strings
+if symbol_name in found_symbols:
+  for header in current_headers:
+symbol_headers.add(header)
+i = i + 1
+  # no headers or symbols in this block
+  if i == start:
+i = i + 1
+
+  # If the symbol was never named, consider all named headers.  
+  return symbol_headers or all_headers
 
 
 def _ParseIndexPage(index_page_html):


Index: clang/tools/include-mapping/cppreference_parser.py
===
--- clang/tools/include-mapping/cppreference_parser.py
+++ clang/tools/include-mapping/cppreference_parser.py
@@ -47,7 +47,7 @@
 
   Returns a list of headers.
   """
-  headers = set()
+  symbol_headers = set()
   all_headers = set()
 
   soup = BeautifulSoup(symbol_page_html, "html.parser")
@@ -58,31 +58,39 @@
   #   Defined in header   .t-dsc-header
   #   decl2.t-dcl
   for table in soup.select('table.t-dcl-begin, table.t-dsc-begin'):
-current_headers = []
-was_decl = False
-for row in table.select('tr'):
-  if _HasClass(row, 't-dcl', 't-dsc'):
-was_decl = True
-# Symbols are in the first cell.
-found_symbols = row.find('td').stripped_strings
-if not symbol_name in found_symbols:
-  continue
-headers.update(current_headers)
-  elif _HasClass(row, 't-dsc-header'):
-# If we saw a decl since the last header, this is a new block of headers
-# for a new block of decls.
-if was_decl:
-  current_headers = []
-was_decl = False
+rows = table.select('tr')
+i = 0
+while i < len(rows):
+  start = i
+  current_headers = set()
+  while i < len(rows) and _HasClass(rows[i], 't-dsc-header'):
+row = rows[i]
 # There are also .t-dsc-header for "defined in namespace".
 if not "Defined in header " in row.text:
+  i = i + 1
   continue
 # The interesting header content (e.g. ) is wrapped in .
 for header_code in row.find_all("code"):
-  current_headers.append(header_code.text)
   all_headers.add(header_code.text)
-  # If the symbol was never named, consider all named headers.
-  return headers or all_headers
+  current_headers.add(header_code.text)
+i = i + 1
+  # some tables have header rows, skip them  
+   

[PATCH] D142550: Fix sizeof of boolean vector

2023-01-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/test/SemaCXX/vector-bool.cpp:97
+  using NineBools = bool __attribute__((ext_vector_type(9)));
+  using ABunchOfBools = bool __attribute__((ext_vector_type(28)));
   static_assert(sizeof(FourBools) == 1);

How about 33?  Does it grow appropriately with alignment?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142550/new/

https://reviews.llvm.org/D142550

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


[PATCH] D140415: [flang] stack arrays pass

2023-01-25 Thread Tom Eccles via Phabricator via cfe-commits
tblah added a comment.

In D140415#4080080 , @jdoerfert wrote:

> 

Thanks for taking a look, see my responses inline. For more information, the 
RFC is at https://reviews.llvm.org/D139617

> Quick questions, and they might not apply here since you seem to only look at 
> explicit Flang generated values, right?

Yes only heap allocations added by flang are considered. `allocate` statements 
in source code are not changed.

> Are you handling unwinding/exceptions, especially in-between the allocation 
> and deallocation?

There is no special handling for exceptions.

> Are you handling non-accessible stacks (e.g., on GPUs) for escaping pointers?

I am not. I am unfamiliar with this area, do you have any suggestions?

> Do you check the size to (reasonably) ensure we don't overflow the stack?

This pass avoids placing stack allocations inside loops, but does not check the 
size of the stack allocations themselves. In general, Flang will place local 
arrays of any size on the stack. These allocations can be moved to the heap 
using the MemoryAllocationOpt pass. In https://reviews.llvm.org/D140972 I made 
that pass mutually exclusive with this one, but so far as I know, it should be 
possible to run MemoryAllocaitonOpt after this one to move some of the 
temporary allocations back to the heap again. Note: you have to set non-default 
options for the MemoryAllocationOpt pass to move any allocations.

> Are you trying to move the alloca into the entry, if possible?

Yes

> Did you check LLVM's heap2stack and the corresponding tests?
> https://github.com/llvm/llvm-project/blob/c68af565ff0c2fdc5537e9ac0c2d7c75df44b035/llvm/lib/Transforms/IPO/AttributorAttributes.cpp#L6480
> https://github.com/llvm/llvm-project/blob/main/llvm/test/Transforms/Attributor/heap_to_stack.ll
> https://github.com/llvm/llvm-project/blob/main/llvm/test/Transforms/Attributor/heap_to_stack_gpu.ll

No I have not seen that. I will take a look, thank you.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140415/new/

https://reviews.llvm.org/D140415

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


[PATCH] D142092: [include-mapping] Allow multiple headers for the same symbol. Choose the first header of available ones.

2023-01-25 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 492130.
VitaNuo added a comment.

Refactor the symbol parsing loop.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142092/new/

https://reviews.llvm.org/D142092

Files:
  clang/include/clang/Tooling/Inclusions/CSymbolMap.inc
  clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/tools/include-mapping/cppreference_parser.py
  clang/tools/include-mapping/gen_std.py

Index: clang/tools/include-mapping/gen_std.py
===
--- clang/tools/include-mapping/gen_std.py
+++ clang/tools/include-mapping/gen_std.py
@@ -14,10 +14,7 @@
 The generated files are located in clang/include/Tooling/Inclusions.
 
 Caveats and FIXMEs:
-  - only symbols directly in "std" namespace are added, we should also add std's
-subnamespace symbols (e.g. chrono).
-  - symbols with multiple variants or defined in multiple headers aren't added,
-e.g. std::move, std::swap
+  - symbols with multiple variants aren't added, e.g., std::move
 
 Usage:
   1. Install BeautifulSoup dependency, see instruction:
@@ -41,6 +38,7 @@
 import datetime
 import os
 import sys
+import re
 
 CODE_PREFIX = """\
 //===-- gen_std.py generated file ---*- C++ -*-===//
@@ -109,18 +107,16 @@
   cppreference_modified_date = datetime.datetime.fromtimestamp(
 os.stat(index_page_path).st_mtime).strftime('%Y-%m-%d')
   print(CODE_PREFIX % (args.symbols.upper(), cppreference_modified_date))
+  # FIXME: take care of overloads
   for symbol in symbols:
-if len(symbol.headers) == 1:
-  # SYMBOL(unqualified_name, namespace, header)
-  print("SYMBOL(%s, %s, %s)" % (symbol.name, symbol.namespace,
-symbol.headers[0]))
-elif len(symbol.headers) == 0:
+if re.match("^remove$|^swap$", symbol.name) and symbol.namespace == "std::":
+  continue
+if len(symbol.headers) == 0:
   sys.stderr.write("No header found for symbol %s\n" % symbol.name)
 else:
-  # FIXME: support symbols with multiple headers (e.g. std::move).
-  sys.stderr.write("Ambiguous header for symbol %s: %s\n" % (
-  symbol.name, ', '.join(symbol.headers)))
-
-
+  for header in symbol.headers:
+# SYMBOL(unqualified_name, namespace, header)
+print("SYMBOL(%s, %s, %s)" % (symbol.name, symbol.namespace,
+  header))
 if __name__ == '__main__':
   main()
Index: clang/tools/include-mapping/cppreference_parser.py
===
--- clang/tools/include-mapping/cppreference_parser.py
+++ clang/tools/include-mapping/cppreference_parser.py
@@ -47,7 +47,7 @@
 
   Returns a list of headers.
   """
-  headers = set()
+  symbol_headers = set()
   all_headers = set()
 
   soup = BeautifulSoup(symbol_page_html, "html.parser")
@@ -58,32 +58,39 @@
   #   Defined in header   .t-dsc-header
   #   decl2.t-dcl
   for table in soup.select('table.t-dcl-begin, table.t-dsc-begin'):
-current_headers = []
-was_decl = False
-for row in table.select('tr'):
-  if _HasClass(row, 't-dcl', 't-dsc'):
-was_decl = True
-# Symbols are in the first cell.
-found_symbols = row.find('td').stripped_strings
-if not symbol_name in found_symbols:
-  continue
-headers.update(current_headers)
-  elif _HasClass(row, 't-dsc-header'):
-# If we saw a decl since the last header, this is a new block of headers
-# for a new block of decls.
-if was_decl:
-  current_headers = []
-was_decl = False
+rows = table.select('tr')
+i = 0
+while i < len(rows):
+  start = i
+  current_headers = set()
+  while i < len(rows) and _HasClass(rows[i], 't-dsc-header'):
+row = rows[i]
 # There are also .t-dsc-header for "defined in namespace".
 if not "Defined in header " in row.text:
+  i = i + 1
   continue
 # The interesting header content (e.g. ) is wrapped in .
 for header_code in row.find_all("code"):
-  current_headers.append(header_code.text)
   all_headers.add(header_code.text)
-  # If the symbol was never named, consider all named headers.
-  return headers or all_headers
-
+  current_headers.add(header_code.text)
+i = i + 1
+  # some tables have header rows, skip them  
+  while i < len(rows) and _HasClass(rows[i], 't-dsc-hitem'):
+i = i + 1
+  while i < len(rows) and (_HasClass(rows[i], 't-dcl', 't-dsc') or not rows[i].has_attr("class")):
+row = rows[i]
+# Symbols are in the first cell.
+found_symbols = row.find('td').stripped_strings
+if symbol_name in found_symbols:
+  for header in current_headers:
+symbol_headers.add(header)
+  

[PATCH] D142484: [LinkerWrapper] Only import static libraries with needed symbols

2023-01-25 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan added a comment.

In D142484#4079909 , @jhuber6 wrote:

> In D142484#4079869 , @Jake-Egan 
> wrote:
>
>> Hi, this new test fails on AIX. Could you take a look?
>> https://lab.llvm.org/buildbot/#/builders/214/builds/5477/steps/6/logs/FAIL__Clang__linker-wrapper-libs_c
>
> I might just put that this test requires Linux. Because I don't think I can 
> debug it without access to the system. We don't really support offloading on 
> anything but Linux anyway.

I think that makes sense. We'd need time to investigate it on AIX anyways.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142484/new/

https://reviews.llvm.org/D142484

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


[PATCH] D142014: [clangd] fix wrong CalleeArgInfo in the hover

2023-01-25 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:994
   HI.CalleeArgInfo.emplace(toHoverInfoParam(PVD, PP));
+  PassType.PassBy = getPassMode(PVD->getType());
+}

kadircet wrote:
> sorry for showing up late to the party but instead of changing rest of the 
> code, can we apply this logic only when there are no implicit 
> casts/conversions between the arg and callexpr (i.e `N == &OuterNode`)?
To make sure I understand it correctly, do you mean I should give up any other 
code changes I made but keep this logic, and put this logic into the `N == 
&OuterNode` branch?

Sorry if I misunderstood anything! Shame for not being a good reader :(


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142014/new/

https://reviews.llvm.org/D142014

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


[PATCH] D138472: clang/cmake: Use installed gtest libraries for stand-alone builds

2023-01-25 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk accepted this revision.
kwk added a comment.
This revision is now accepted and ready to land.

Working for me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138472/new/

https://reviews.llvm.org/D138472

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


  1   2   3   >