[PATCH] D76646: Rename/refactor isIntegerConstantExpression to getIntegerConstantExpression

2020-07-27 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added inline comments.



Comment at: clang/include/clang/AST/Expr.h:513
 
-  /// isIntegerConstantExpr - Return true if this expression is a valid integer
-  /// constant expression, and, if so, return its value in Result.  If not a
-  /// valid i-c-e, return false and fill in Loc (if specified) with the 
location
-  /// of the invalid expression.
+  /// isIntegerConstantExpr - Return the value if this expression is a valid
+  /// integer constant expression.  If not a valid i-c-e, return None and fill

I think the "Return the value..." description now matches 
getIntegerConstantExpr, not isIntegerConstantExpr


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76646



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


[PATCH] D76646: Rename/refactor isIntegerConstantExpression to getIntegerConstantExpression

2020-07-12 Thread David Blaikie via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG49e5f603d400: Rename/refactor isIntegerConstantExpression to 
getIntegerConstantExpression (authored by dblaikie).
Herald added a subscriber: sstefan1.

Changed prior to commit:
  https://reviews.llvm.org/D76646?vs=252158&id=277317#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76646

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/lib/Sema/SemaType.cpp

Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2476,8 +2476,8 @@
 return Context.getDependentVectorType(CurType, SizeExpr, AttrLoc,
VectorType::GenericVector);
 
-  llvm::APSInt VecSize(32);
-  if (!SizeExpr->isIntegerConstantExpr(VecSize, Context)) {
+  Optional VecSize = SizeExpr->getIntegerConstantExpr(Context);
+  if (!VecSize) {
 Diag(AttrLoc, diag::err_attribute_argument_type)
 << "vector_size" << AANT_ArgumentIntegerConstant
 << SizeExpr->getSourceRange();
@@ -2489,13 +2489,13 @@
VectorType::GenericVector);
 
   // vecSize is specified in bytes - convert to bits.
-  if (!VecSize.isIntN(61)) {
+  if (!VecSize->isIntN(61)) {
 // Bit size will overflow uint64.
 Diag(AttrLoc, diag::err_attribute_size_too_large)
 << SizeExpr->getSourceRange() << "vector";
 return QualType();
   }
-  uint64_t VectorSizeBits = VecSize.getZExtValue() * 8;
+  uint64_t VectorSizeBits = VecSize->getZExtValue() * 8;
   unsigned TypeSize = static_cast(Context.getTypeSize(CurType));
 
   if (VectorSizeBits == 0) {
@@ -2540,8 +2540,8 @@
   }
 
   if (!ArraySize->isTypeDependent() && !ArraySize->isValueDependent()) {
-llvm::APSInt vecSize(32);
-if (!ArraySize->isIntegerConstantExpr(vecSize, Context)) {
+Optional vecSize = ArraySize->getIntegerConstantExpr(Context);
+if (!vecSize) {
   Diag(AttrLoc, diag::err_attribute_argument_type)
 << "ext_vector_type" << AANT_ArgumentIntegerConstant
 << ArraySize->getSourceRange();
@@ -2555,7 +2555,7 @@
 }
 // Unlike gcc's vector_size attribute, the size is specified as the
 // number of elements, not the number of bytes.
-unsigned vectorSize = static_cast(vecSize.getZExtValue());
+unsigned vectorSize = static_cast(vecSize->getZExtValue());
 
 if (vectorSize == 0) {
   Diag(AttrLoc, diag::err_attribute_zero_size)
@@ -6254,13 +6254,15 @@
const Expr *AddrSpace,
SourceLocation AttrLoc) {
   if (!AddrSpace->isValueDependent()) {
-llvm::APSInt addrSpace(32);
-if (!AddrSpace->isIntegerConstantExpr(addrSpace, S.Context)) {
+Optional OptAddrSpace =
+AddrSpace->getIntegerConstantExpr(S.Context);
+if (!OptAddrSpace) {
   S.Diag(AttrLoc, diag::err_attribute_argument_type)
   << "'address_space'" << AANT_ArgumentIntegerConstant
   << AddrSpace->getSourceRange();
   return false;
 }
+llvm::APSInt &addrSpace = *OptAddrSpace;
 
 // Bounds checking.
 if (addrSpace.isSigned()) {
@@ -7712,9 +7714,9 @@
   }
   // The number of elements must be an ICE.
   Expr *numEltsExpr = static_cast(Attr.getArgAsExpr(0));
-  llvm::APSInt numEltsInt(32);
+  Optional numEltsInt;
   if (numEltsExpr->isTypeDependent() || numEltsExpr->isValueDependent() ||
-  !numEltsExpr->isIntegerConstantExpr(numEltsInt, S.Context)) {
+  !(numEltsInt = numEltsExpr->getIntegerConstantExpr(S.Context))) {
 S.Diag(Attr.getLoc(), diag::err_attribute_argument_type)
 << Attr << AANT_ArgumentIntegerConstant
 << numEltsExpr->getSourceRange();
@@ -7730,7 +7732,7 @@
 
   // The total size of the vector must be 64 or 128 bits.
   unsigned typeSize = static_cast(S.Context.getTypeSize(CurType));
-  unsigned numElts = static_cast(numEltsInt.getZExtValue());
+  unsigned numElts = static_cast(numEltsInt->getZExtValue());
   unsigned vecSize = typeSize * numElts;
   if (vecSize != 64 && vecSize != 128) {
 S.Diag(Attr.getLoc(), diag::err_attribute_bad_neon_vector_size) << CurType;
Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -335,15 +335,15 @@
 
   if (NumArgs == 1) {
 Expr *E = A.getArgAsExpr(0

[PATCH] D76646: Rename/refactor isIntegerConstantExpression to getIntegerConstantExpression

2020-05-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from the formatting nits. I think this is a nice cleanup, thanks!




Comment at: clang/include/clang/AST/Expr.h:503
 
-  /// isIntegerConstantExpr - Return true if this expression is a valid integer
-  /// constant expression, and, if so, return its value in Result.  If not a
-  /// valid i-c-e, return false and fill in Loc (if specified) with the 
location
-  /// of the invalid expression.
+  /// isIntegerConstantExpr - Return the value if this expression is a valid 
integer
+  /// constant expression.  If not a valid i-c-e, return None and fill in Loc

80-col issue, should clang-format the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76646



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


[PATCH] D76646: Rename/refactor isIntegerConstantExpression to getIntegerConstantExpression

2020-05-04 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.
Herald added a reviewer: aaron.ballman.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76646



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


[PATCH] D76646: Rename/refactor isIntegerConstantExpression to getIntegerConstantExpression

2020-04-14 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76646



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


[PATCH] D76646: Rename/refactor isIntegerConstantExpression to getIntegerConstantExpression

2020-04-05 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76646



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


[PATCH] D76646: Rename/refactor isIntegerConstantExpression to getIntegerConstantExpression

2020-03-23 Thread David Blaikie via Phabricator via cfe-commits
dblaikie created this revision.
dblaikie added a reviewer: rsmith.
Herald added subscribers: cfe-commits, jfb.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

There is a version that just tests (also called
isIntegerConstantExpression) & whereas this version is specifically used
when the value is of interest (a few call sites were actually refactored
to calling the test-only version) so let's make the API look more like
it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76646

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/lib/Sema/SemaType.cpp

Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2417,8 +2417,8 @@
 return Context.getDependentVectorType(CurType, SizeExpr, AttrLoc,
VectorType::GenericVector);
 
-  llvm::APSInt VecSize(32);
-  if (!SizeExpr->isIntegerConstantExpr(VecSize, Context)) {
+  Optional VecSize = SizeExpr->getIntegerConstantExpr(Context);
+  if (!VecSize) {
 Diag(AttrLoc, diag::err_attribute_argument_type)
 << "vector_size" << AANT_ArgumentIntegerConstant
 << SizeExpr->getSourceRange();
@@ -2429,7 +2429,7 @@
 return Context.getDependentVectorType(CurType, SizeExpr, AttrLoc,
VectorType::GenericVector);
 
-  unsigned VectorSize = static_cast(VecSize.getZExtValue() * 8);
+  unsigned VectorSize = static_cast(VecSize->getZExtValue() * 8);
   unsigned TypeSize = static_cast(Context.getTypeSize(CurType));
 
   if (VectorSize == 0) {
@@ -2474,8 +2474,8 @@
   }
 
   if (!ArraySize->isTypeDependent() && !ArraySize->isValueDependent()) {
-llvm::APSInt vecSize(32);
-if (!ArraySize->isIntegerConstantExpr(vecSize, Context)) {
+Optional vecSize = ArraySize->getIntegerConstantExpr(Context);
+if (!vecSize) {
   Diag(AttrLoc, diag::err_attribute_argument_type)
 << "ext_vector_type" << AANT_ArgumentIntegerConstant
 << ArraySize->getSourceRange();
@@ -2484,7 +2484,7 @@
 
 // Unlike gcc's vector_size attribute, the size is specified as the
 // number of elements, not the number of bytes.
-unsigned vectorSize = static_cast(vecSize.getZExtValue());
+unsigned vectorSize = static_cast(vecSize->getZExtValue());
 
 if (vectorSize == 0) {
   Diag(AttrLoc, diag::err_attribute_zero_size)
@@ -6073,13 +6073,15 @@
const Expr *AddrSpace,
SourceLocation AttrLoc) {
   if (!AddrSpace->isValueDependent()) {
-llvm::APSInt addrSpace(32);
-if (!AddrSpace->isIntegerConstantExpr(addrSpace, S.Context)) {
+Optional OptAddrSpace =
+AddrSpace->getIntegerConstantExpr(S.Context);
+if (!OptAddrSpace) {
   S.Diag(AttrLoc, diag::err_attribute_argument_type)
   << "'address_space'" << AANT_ArgumentIntegerConstant
   << AddrSpace->getSourceRange();
   return false;
 }
+llvm::APSInt &addrSpace = *OptAddrSpace;
 
 // Bounds checking.
 if (addrSpace.isSigned()) {
@@ -7510,9 +7512,9 @@
   }
   // The number of elements must be an ICE.
   Expr *numEltsExpr = static_cast(Attr.getArgAsExpr(0));
-  llvm::APSInt numEltsInt(32);
+  Optional numEltsInt;
   if (numEltsExpr->isTypeDependent() || numEltsExpr->isValueDependent() ||
-  !numEltsExpr->isIntegerConstantExpr(numEltsInt, S.Context)) {
+  !(numEltsInt = numEltsExpr->getIntegerConstantExpr(S.Context))) {
 S.Diag(Attr.getLoc(), diag::err_attribute_argument_type)
 << Attr << AANT_ArgumentIntegerConstant
 << numEltsExpr->getSourceRange();
@@ -7528,7 +7530,7 @@
 
   // The total size of the vector must be 64 or 128 bits.
   unsigned typeSize = static_cast(S.Context.getTypeSize(CurType));
-  unsigned numElts = static_cast(numEltsInt.getZExtValue());
+  unsigned numElts = static_cast(numEltsInt->getZExtValue());
   unsigned vecSize = typeSize * numElts;
   if (vecSize != 64 && vecSize != 128) {
 S.Diag(Attr.getLoc(), diag::err_attribute_bad_neon_vector_size) << CurType;
Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -296,15 +296,15 @@
 
   if (NumArgs == 1) {
 Expr *E = A.getArgAsExpr(0);
-llvm::APSInt ArgVal(32);
+Optional ArgVal;
 
-if (!E->isIntegerConstantExpr(ArgVal, S.Context)) {
+if (!(ArgVal = E->getIntegerConstantExpr