[clang] Diagnose misuse of the cleanup attribute (PR #80040)

2024-02-06 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

I have added a test, but will be adding more in some upcoming commits as I test 
them locally.

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


[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

2024-02-06 Thread Atousa Duprat via cfe-commits

https://github.com/Atousa updated 
https://github.com/llvm/llvm-project/pull/80939

>From b32eb14ee8eaa337fa4efafda30dc02a86667965 Mon Sep 17 00:00:00 2001
From: Atousa Duprat 
Date: Tue, 6 Feb 2024 21:02:05 -0800
Subject: [PATCH] [clang] Use separator for large numeric values in overflow
 diagnostic

Add functionality to APInt::toString() that allows it to insert
separators between groups of digits, using the C++ litteral
separator ' between groups.

Fixes issue #58228
---
 clang/lib/AST/ExprConstant.cpp  |   6 +-
 clang/test/AST/Interp/c.c   |   4 +-
 clang/test/C/drs/dr0xx.c|   2 +-
 clang/test/C/drs/dr2xx.c|   2 +-
 clang/test/Sema/integer-overflow.c  | 100 -
 clang/test/Sema/switch-1.c  |   6 +-
 clang/test/SemaCXX/enum.cpp |   4 +-
 clang/test/SemaCXX/integer-overflow.cpp | 112 ++--
 clang/test/SemaObjC/integer-overflow.m  |   4 +-
 clang/test/SemaObjC/objc-literal-nsnumber.m |   2 +-
 llvm/include/llvm/ADT/APInt.h   |   3 +-
 llvm/include/llvm/ADT/StringExtras.h|  12 ++-
 llvm/lib/Support/APInt.cpp  |  24 -
 llvm/unittests/ADT/APIntTest.cpp|  35 ++
 14 files changed, 190 insertions(+), 126 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f7..53eaefe7c0dc7e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2774,7 +2774,8 @@ static bool CheckedIntArithmetic(EvalInfo , const 
Expr *E,
 if (Info.checkingForUndefinedBehavior())
   Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_integer_constant_overflow)
-  << toString(Result, 10) << E->getType() << E->getSourceRange();
+  << toString(Result, 10, Result.isSigned(), false, true, true)
+  << E->getType() << E->getSourceRange();
 return HandleOverflow(Info, E, Value, E->getType());
   }
   return true;
@@ -13852,7 +13853,8 @@ bool IntExprEvaluator::VisitUnaryOperator(const 
UnaryOperator *E) {
   if (Info.checkingForUndefinedBehavior())
 Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
  diag::warn_integer_constant_overflow)
-<< toString(Value, 10) << E->getType() << E->getSourceRange();
+<< toString(Value, 10, false, true, true) << E->getType()
+<< E->getSourceRange();
 
   if (!HandleOverflow(Info, E, -Value.extend(Value.getBitWidth() + 1),
   E->getType()))
diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 9ab271a82aeef9..aa067b0bc74831 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -109,9 +109,9 @@ int somefunc(int i) {
  // pedantic-expected-warning {{left operand of 
comma operator has no effect}} \
  // pedantic-expected-warning {{overflow in 
expression; result is 131073}} \
  // ref-warning {{left operand of comma operator 
has no effect}} \
- // ref-warning {{overflow in expression; result 
is 131073}} \
+ // ref-warning {{overflow in expression; result 
is 131'073}} \
  // pedantic-ref-warning {{left operand of comma 
operator has no effect}} \
- // pedantic-ref-warning {{overflow in expression; 
result is 131073}}
+ // pedantic-ref-warning {{overflow in expression; 
result is 131'073}}
 
 }
 
diff --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index d9c1fbe4ee40ab..c93cfb63d604cf 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -214,7 +214,7 @@ _Static_assert(__builtin_types_compatible_p(struct S { int 
a; }, union U { int a
  */
 void dr031(int i) {
   switch (i) {
-  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   #pragma clang diagnostic push
   #pragma clang diagnostic ignored "-Wswitch"
   /* Silence the targets which issue:
diff --git a/clang/test/C/drs/dr2xx.c b/clang/test/C/drs/dr2xx.c
index 9c8d77518ab55e..1b68b65acca6af 100644
--- a/clang/test/C/drs/dr2xx.c
+++ b/clang/test/C/drs/dr2xx.c
@@ -277,7 +277,7 @@ void dr258(void) {
 void dr261(void) {
   /* This is still an integer constant expression despite the overflow. */
   enum e1 {
-ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   };
 
   /* This is not an integer constant expression, because of the 

[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)

2024-02-06 Thread Phoebe Wang via cfe-commits


@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) {
   Features["prefetchi"]  = HasLeaf7Subleaf1 && ((EDX >> 14) & 1);
   Features["usermsr"]  = HasLeaf7Subleaf1 && ((EDX >> 15) & 1);
   Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1);
+  Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1);

phoebewang wrote:

I think you cannot actually enable APX features when using 
`__attribute__((__target__("apxf")))` either.

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


[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

2024-02-06 Thread Atousa Duprat via cfe-commits

https://github.com/Atousa updated 
https://github.com/llvm/llvm-project/pull/80939

>From c672d736f9cdce9ac9cbbf79df0d5c081d1a0792 Mon Sep 17 00:00:00 2001
From: Atousa Duprat 
Date: Tue, 6 Feb 2024 21:02:05 -0800
Subject: [PATCH] [clang] Use separator for large numeric values in overflow
 diagnostic

Add functionality to APInt::toString() that allows it to insert
separators between groups of digits, using the C++ litteral
separator ' between groups.

Fixes issue #58228
---
 clang/lib/AST/ExprConstant.cpp  |   6 +-
 clang/test/AST/Interp/c.c   |   4 +-
 clang/test/C/drs/dr0xx.c|   2 +-
 clang/test/C/drs/dr2xx.c|   2 +-
 clang/test/Sema/integer-overflow.c  | 100 +-
 clang/test/Sema/switch-1.c  |   6 +-
 clang/test/SemaCXX/enum.cpp |   4 +-
 clang/test/SemaCXX/integer-overflow.cpp | 110 ++--
 clang/test/SemaObjC/integer-overflow.m  |   4 +-
 clang/test/SemaObjC/objc-literal-nsnumber.m |   2 +-
 llvm/include/llvm/ADT/APInt.h   |   3 +-
 llvm/include/llvm/ADT/StringExtras.h|  11 +-
 llvm/lib/Support/APInt.cpp  |  24 -
 llvm/unittests/ADT/APIntTest.cpp|  35 +++
 14 files changed, 188 insertions(+), 125 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f7..22bc50d25a37a8 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2774,7 +2774,8 @@ static bool CheckedIntArithmetic(EvalInfo , const 
Expr *E,
 if (Info.checkingForUndefinedBehavior())
   Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_integer_constant_overflow)
-  << toString(Result, 10) << E->getType() << E->getSourceRange();
+  << toString(Result, 10, Result.isSigned(), false, true, true)
+  << E->getType() << E->getSourceRange();
 return HandleOverflow(Info, E, Value, E->getType());
   }
   return true;
@@ -13852,7 +13853,8 @@ bool IntExprEvaluator::VisitUnaryOperator(const 
UnaryOperator *E) {
   if (Info.checkingForUndefinedBehavior())
 Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
  diag::warn_integer_constant_overflow)
-<< toString(Value, 10) << E->getType() << E->getSourceRange();
+<< toString(Value, 10, false, true, true)
+<< E->getType() << E->getSourceRange();
 
   if (!HandleOverflow(Info, E, -Value.extend(Value.getBitWidth() + 1),
   E->getType()))
diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 9ab271a82aeef9..aa067b0bc74831 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -109,9 +109,9 @@ int somefunc(int i) {
  // pedantic-expected-warning {{left operand of 
comma operator has no effect}} \
  // pedantic-expected-warning {{overflow in 
expression; result is 131073}} \
  // ref-warning {{left operand of comma operator 
has no effect}} \
- // ref-warning {{overflow in expression; result 
is 131073}} \
+ // ref-warning {{overflow in expression; result 
is 131'073}} \
  // pedantic-ref-warning {{left operand of comma 
operator has no effect}} \
- // pedantic-ref-warning {{overflow in expression; 
result is 131073}}
+ // pedantic-ref-warning {{overflow in expression; 
result is 131'073}}
 
 }
 
diff --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index d9c1fbe4ee40ab..c93cfb63d604cf 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -214,7 +214,7 @@ _Static_assert(__builtin_types_compatible_p(struct S { int 
a; }, union U { int a
  */
 void dr031(int i) {
   switch (i) {
-  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   #pragma clang diagnostic push
   #pragma clang diagnostic ignored "-Wswitch"
   /* Silence the targets which issue:
diff --git a/clang/test/C/drs/dr2xx.c b/clang/test/C/drs/dr2xx.c
index 9c8d77518ab55e..1b68b65acca6af 100644
--- a/clang/test/C/drs/dr2xx.c
+++ b/clang/test/C/drs/dr2xx.c
@@ -277,7 +277,7 @@ void dr258(void) {
 void dr261(void) {
   /* This is still an integer constant expression despite the overflow. */
   enum e1 {
-ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   };
 
   /* This is not an integer constant expression, because of the 

[clang] 28b8207 - [clang][Interp] Support ImplicitValueInitExpr for complex types

2024-02-06 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-07T08:26:47+01:00
New Revision: 28b82075ff3e58ba9c6959a585d3d0fc5d0325e5

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

LOG: [clang][Interp] Support ImplicitValueInitExpr for complex types

Initialize both elements to 0, once again.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 49f9878d42480..38b2d6fad043c 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -820,6 +820,19 @@ bool 
ByteCodeExprGen::VisitImplicitValueInitExpr(const ImplicitValueIni
 return true;
   }
 
+  if (QT->isAnyComplexType()) {
+assert(Initializing);
+QualType ElemQT = QT->getAs()->getElementType();
+PrimType ElemT = classifyPrim(ElemQT);
+for (unsigned I = 0; I < 2; ++I) {
+  if (!this->visitZeroInitializer(ElemT, ElemQT, E))
+return false;
+  if (!this->emitInitElem(ElemT, I, E))
+return false;
+}
+return true;
+  }
+
   return false;
 }
 

diff  --git a/clang/test/AST/Interp/complex.cpp 
b/clang/test/AST/Interp/complex.cpp
index 20c00b8e1ba3f..7d625ab1f378e 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -102,6 +102,16 @@ static_assert(__imag(I3) == 0, "");
 // constexpr _Complex _BitInt(8) A = 0;// = {4};
 
 
+constexpr _Complex double Doubles[4] = {{1.0, 2.0}};
+static_assert(__real(Doubles[0]) == 1.0, "");
+static_assert(__imag(Doubles[0]) == 2.0, "");
+static_assert(__real(Doubles[1]) == 0.0, "");
+static_assert(__imag(Doubles[1]) == 0.0, "");
+static_assert(__real(Doubles[2]) == 0.0, "");
+static_assert(__imag(Doubles[2]) == 0.0, "");
+static_assert(__real(Doubles[3]) == 0.0, "");
+static_assert(__imag(Doubles[3]) == 0.0, "");
+
 void func(void) {
   __complex__ int arr;
   _Complex int result;



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


[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

2024-02-06 Thread Atousa Duprat via cfe-commits

https://github.com/Atousa updated 
https://github.com/llvm/llvm-project/pull/80939

>From 2e5efd9623f10aae54798c4d664c479be93ae77f Mon Sep 17 00:00:00 2001
From: Atousa Duprat 
Date: Tue, 6 Feb 2024 21:02:05 -0800
Subject: [PATCH] [clang] Use separator for large numeric values in overflow
 diagnostic

Add functionality to APInt::toString() that allows it to insert
separators between groups of digits, using the C++ litteral
separator ' between groups.

Fixes issue #58228
---
 clang/lib/AST/ExprConstant.cpp  |   6 +-
 clang/test/AST/Interp/c.c   |   8 +-
 clang/test/C/drs/dr0xx.c|   2 +-
 clang/test/C/drs/dr2xx.c|   2 +-
 clang/test/Sema/integer-overflow.c  | 100 +-
 clang/test/Sema/switch-1.c  |   6 +-
 clang/test/SemaCXX/enum.cpp |   4 +-
 clang/test/SemaCXX/integer-overflow.cpp | 110 ++--
 clang/test/SemaObjC/integer-overflow.m  |   4 +-
 clang/test/SemaObjC/objc-literal-nsnumber.m |   2 +-
 llvm/include/llvm/ADT/APInt.h   |   3 +-
 llvm/include/llvm/ADT/StringExtras.h|  11 +-
 llvm/lib/Support/APInt.cpp  |  24 -
 llvm/unittests/ADT/APIntTest.cpp|  35 +++
 14 files changed, 190 insertions(+), 127 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f7..22bc50d25a37a8 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2774,7 +2774,8 @@ static bool CheckedIntArithmetic(EvalInfo , const 
Expr *E,
 if (Info.checkingForUndefinedBehavior())
   Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_integer_constant_overflow)
-  << toString(Result, 10) << E->getType() << E->getSourceRange();
+  << toString(Result, 10, Result.isSigned(), false, true, true)
+  << E->getType() << E->getSourceRange();
 return HandleOverflow(Info, E, Value, E->getType());
   }
   return true;
@@ -13852,7 +13853,8 @@ bool IntExprEvaluator::VisitUnaryOperator(const 
UnaryOperator *E) {
   if (Info.checkingForUndefinedBehavior())
 Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
  diag::warn_integer_constant_overflow)
-<< toString(Value, 10) << E->getType() << E->getSourceRange();
+<< toString(Value, 10, false, true, true)
+<< E->getType() << E->getSourceRange();
 
   if (!HandleOverflow(Info, E, -Value.extend(Value.getBitWidth() + 1),
   E->getType()))
diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 9ab271a82aeef9..8738e4add7b752 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -105,13 +105,13 @@ int chooseexpr[__builtin_choose_expr(1, 1, expr)];
 
 int somefunc(int i) {
   return (i, 65537) * 65537; // expected-warning {{left operand of comma 
operator has no effect}} \
- // expected-warning {{overflow in expression; 
result is 131073}} \
+ // expected-warning {{overflow in expression; 
result is 131'073}} \
  // pedantic-expected-warning {{left operand of 
comma operator has no effect}} \
- // pedantic-expected-warning {{overflow in 
expression; result is 131073}} \
+ // pedantic-expected-warning {{overflow in 
expression; result is 131'073}} \
  // ref-warning {{left operand of comma operator 
has no effect}} \
- // ref-warning {{overflow in expression; result 
is 131073}} \
+ // ref-warning {{overflow in expression; result 
is 131'073}} \
  // pedantic-ref-warning {{left operand of comma 
operator has no effect}} \
- // pedantic-ref-warning {{overflow in expression; 
result is 131073}}
+ // pedantic-ref-warning {{overflow in expression; 
result is 131'073}}
 
 }
 
diff --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index d9c1fbe4ee40ab..c93cfb63d604cf 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -214,7 +214,7 @@ _Static_assert(__builtin_types_compatible_p(struct S { int 
a; }, union U { int a
  */
 void dr031(int i) {
   switch (i) {
-  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   #pragma clang diagnostic push
   #pragma clang diagnostic ignored "-Wswitch"
   /* Silence the targets which issue:
diff --git a/clang/test/C/drs/dr2xx.c b/clang/test/C/drs/dr2xx.c
index 9c8d77518ab55e..1b68b65acca6af 100644
--- a/clang/test/C/drs/dr2xx.c
+++ 

[clang] [Clang][TableGen] Add Features to TargetBuiltin (PR #80279)

2024-02-06 Thread Wang Pengcheng via cfe-commits

wangpc-pp wrote:

Ping.

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


[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)

2024-02-06 Thread Freddy Ye via cfe-commits


@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) {
   Features["prefetchi"]  = HasLeaf7Subleaf1 && ((EDX >> 14) & 1);
   Features["usermsr"]  = HasLeaf7Subleaf1 && ((EDX >> 15) & 1);
   Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1);
+  Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1);

FreddyLeaf wrote:

Emm, I happened to find an issue with this patch.
```
$ clang -march=native foo.c -S -emit-llvm 
'-apxf' is not a recognized feature for this target (ignoring feature)
```
It turns out even not adding logics in X86TargetInfo::hasFeature it will still 
return false for "apxf". I also found "-egpr" is not generated. How did you 
handle this?

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


[clang] 8c84096 - [clang][Interp] Fix initializing _Complex values from DeclRefExpr

2024-02-06 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-07T08:07:05+01:00
New Revision: 8c84096da195ae38336ba9aa700dc35e567157ba

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

LOG: [clang][Interp] Fix initializing _Complex values from DeclRefExpr

See the comment I added. When initializing a complex value from a
DeclRefExpr, we need to manually copy both array elements.
This adds some unfortunate code duplication that I'm still pondering
on how to get rid of best.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 79d44842d83195..49f9878d42480f 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3009,21 +3009,53 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
   // pointer to the actual value) instead of a pointer to the pointer to the
   // value.
   bool IsReference = D->getType()->isReferenceType();
+  // Complex values are copied in the AST via a simply assignment or
+  // ltor cast. But we represent them as two-element arrays, which means
+  // we pass them around as pointers. So, to assignm from them, we will
+  // have to copy both (primitive) elements instead.
+  bool IsComplex = D->getType()->isAnyComplexType();
 
   // Check for local/global variables and parameters.
   if (auto It = Locals.find(D); It != Locals.end()) {
 const unsigned Offset = It->second.Offset;
+// FIXME: Fix the code duplication here with the code in the global case.
+if (Initializing && IsComplex) {
+  PrimType ElemT = classifyComplexElementType(D->getType());
+  for (unsigned I = 0; I != 2; ++I) {
+if (!this->emitGetPtrLocal(Offset, E))
+  return false;
+if (!this->emitArrayElemPop(ElemT, I, E))
+  return false;
+if (!this->emitInitElem(ElemT, I, E))
+  return false;
+  }
+  return true;
+}
 
 if (IsReference)
   return this->emitGetLocal(PT_Ptr, Offset, E);
 return this->emitGetPtrLocal(Offset, E);
   } else if (auto GlobalIndex = P.getGlobal(D)) {
+if (Initializing && IsComplex) {
+  PrimType ElemT = classifyComplexElementType(D->getType());
+  for (unsigned I = 0; I != 2; ++I) {
+if (!this->emitGetPtrGlobal(*GlobalIndex, E))
+  return false;
+if (!this->emitArrayElemPop(ElemT, I, E))
+  return false;
+if (!this->emitInitElem(ElemT, I, E))
+  return false;
+  }
+  return true;
+}
+
 if (IsReference)
   return this->emitGetGlobalPtr(*GlobalIndex, E);
 
 return this->emitGetPtrGlobal(*GlobalIndex, E);
   } else if (const auto *PVD = dyn_cast(D)) {
 if (auto It = this->Params.find(PVD); It != this->Params.end()) {
+  // FIXME: _Complex initializing case?
   if (IsReference || !It->second.IsPtr)
 return this->emitGetParamPtr(It->second.Offset, E);
 

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index b33cf55c61f036..a76e63395157f7 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1878,6 +1878,14 @@ inline bool ArrayElemPtrPop(InterpState , CodePtr 
OpPC) {
   return NarrowPtr(S, OpPC);
 }
 
+template ::T>
+inline bool ArrayElemPop(InterpState , CodePtr OpPC, uint32_t Index) {
+  const Pointer  = S.Stk.pop();
+
+  S.Stk.push(Ptr.atIndex(Index).deref());
+  return true;
+}
+
 /// Just takes a pointer and checks if it's an incomplete
 /// array type.
 inline bool ArrayDecay(InterpState , CodePtr OpPC) {

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index e720b95498f17f..7f5bd7e5b44bca 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -357,6 +357,12 @@ def ExpandPtr : Opcode;
 def ArrayElemPtr : AluOpcode;
 def ArrayElemPtrPop : AluOpcode;
 
+def ArrayElemPop : Opcode {
+  let Args = [ArgUint32];
+  let Types = [AllTypeClass];
+  let HasGroup = 1;
+}
+
 
//===--===//
 // Direct field accessors
 
//===--===//

diff  --git a/clang/test/AST/Interp/complex.cpp 
b/clang/test/AST/Interp/complex.cpp
index 7f02bfa18bbdb0..20c00b8e1ba3fe 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -194,3 +194,21 @@ namespace ZeroInit {
 
   constexpr int ignored = (fcomplex(), 0);
 }
+
+namespace DeclRefCopy {
+  constexpr _Complex int ComplexInt = 42 + 24i;
+
+  constexpr _Complex int B = ComplexInt;
+  constexpr _Complex int 

[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

2024-02-06 Thread Atousa Duprat via cfe-commits

https://github.com/Atousa updated 
https://github.com/llvm/llvm-project/pull/80939

>From d04a66e5bc56f4ec09339a202fd6047f570a59ae Mon Sep 17 00:00:00 2001
From: Atousa Duprat 
Date: Tue, 6 Feb 2024 21:02:05 -0800
Subject: [PATCH] [clang] Use separator for large numeric values in overflow
 diagnostic

Add functionality to APInt::toString() that allows it to insert
separators between groups of digits, using the C++ litteral
separator ' between groups.

Fixes issue #58228
---
 clang/lib/AST/ExprConstant.cpp  |   3 +-
 clang/test/AST/Interp/c.c   |   8 +-
 clang/test/C/drs/dr0xx.c|   2 +-
 clang/test/C/drs/dr2xx.c|   2 +-
 clang/test/Sema/integer-overflow.c  | 100 +-
 clang/test/Sema/switch-1.c  |   6 +-
 clang/test/SemaCXX/enum.cpp |   4 +-
 clang/test/SemaCXX/integer-overflow.cpp | 110 ++--
 clang/test/SemaObjC/integer-overflow.m  |   4 +-
 clang/test/SemaObjC/objc-literal-nsnumber.m |   2 +-
 llvm/include/llvm/ADT/APInt.h   |   3 +-
 llvm/include/llvm/ADT/StringExtras.h|   5 +-
 llvm/lib/Support/APInt.cpp  |  24 -
 llvm/unittests/ADT/APIntTest.cpp|  35 +++
 14 files changed, 184 insertions(+), 124 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f7..a46887d6cf1be0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2774,7 +2774,8 @@ static bool CheckedIntArithmetic(EvalInfo , const 
Expr *E,
 if (Info.checkingForUndefinedBehavior())
   Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_integer_constant_overflow)
-  << toString(Result, 10) << E->getType() << E->getSourceRange();
+  << toString(Result, 10, Result.isSigned(), false, true, true)
+  << E->getType() << E->getSourceRange();
 return HandleOverflow(Info, E, Value, E->getType());
   }
   return true;
diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 9ab271a82aeef9..e1245728a7f268 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -105,13 +105,13 @@ int chooseexpr[__builtin_choose_expr(1, 1, expr)];
 
 int somefunc(int i) {
   return (i, 65537) * 65537; // expected-warning {{left operand of comma 
operator has no effect}} \
- // expected-warning {{overflow in expression; 
result is 131073}} \
+ // expected-warning {{overflow in expression; 
result is 131'073}} \
  // pedantic-expected-warning {{left operand of 
comma operator has no effect}} \
- // pedantic-expected-warning {{overflow in 
expression; result is 131073}} \
+ // pedantic-expected-warning {{overflow in 
expression; result is 131'073}} \
  // ref-warning {{left operand of comma operator 
has no effect}} \
- // ref-warning {{overflow in expression; result 
is 131073}} \
+ // ref-warning {{overflow in expression; result 
is 131'073}} \
  // pedantic-ref-warning {{left operand of comma 
operator has no effect}} \
- // pedantic-ref-warning {{overflow in expression; 
result is 131073}}
+ // pedantic-ref-warning {{overflow in expression; 
result is 1310'73}}
 
 }
 
diff --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index d9c1fbe4ee40ab..c93cfb63d604cf 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -214,7 +214,7 @@ _Static_assert(__builtin_types_compatible_p(struct S { int 
a; }, union U { int a
  */
 void dr031(int i) {
   switch (i) {
-  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   #pragma clang diagnostic push
   #pragma clang diagnostic ignored "-Wswitch"
   /* Silence the targets which issue:
diff --git a/clang/test/C/drs/dr2xx.c b/clang/test/C/drs/dr2xx.c
index 9c8d77518ab55e..1b68b65acca6af 100644
--- a/clang/test/C/drs/dr2xx.c
+++ b/clang/test/C/drs/dr2xx.c
@@ -277,7 +277,7 @@ void dr258(void) {
 void dr261(void) {
   /* This is still an integer constant expression despite the overflow. */
   enum e1 {
-ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   };
 
   /* This is not an integer constant expression, because of the comma operator,
diff --git a/clang/test/Sema/integer-overflow.c 
b/clang/test/Sema/integer-overflow.c
index 

[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)

2024-02-06 Thread Shengchen Kan via cfe-commits


@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) {
   Features["prefetchi"]  = HasLeaf7Subleaf1 && ((EDX >> 14) & 1);
   Features["usermsr"]  = HasLeaf7Subleaf1 && ((EDX >> 15) & 1);
   Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1);
+  Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1);

KanRobert wrote:

> if llc read "apxf" in attribute, I think a warning will be given like:
> 
> ```
> '+apxf' is not a recognized feature for this target (ignoring feature)
> ```

Did you check the behavior w/ this patch?


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


[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)

2024-02-06 Thread Freddy Ye via cfe-commits


@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) {
   Features["prefetchi"]  = HasLeaf7Subleaf1 && ((EDX >> 14) & 1);
   Features["usermsr"]  = HasLeaf7Subleaf1 && ((EDX >> 15) & 1);
   Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1);
+  Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1);

FreddyLeaf wrote:

> My understanding is "apxf" here is used by front-end for FMV, right?

Yes, not only FMV, but also __builtin_cpu_supports.
> What would happen if there is "apxf" in the IR after this patch?

if llc read "apxf" in attribute, I think a warning will be given like:
```
'+apxf' is not a recognized feature for this target (ignoring feature)
```
But such attribute won't be generated from frontend, because we didn't add 
logics for "apxf" in X86TargetInfo::hasFeature.

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


[clang] [CodeGen] Update test intrinsic to support immediates (PR #79174)

2024-02-06 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/79174

>From 428bd6c4a69a6f4ba5b646086f7ad4d11f33fffa Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Tue, 23 Jan 2024 12:31:49 -0500
Subject: [PATCH] [CodeGen] Update test intrinsic to support immediates

---
 clang/lib/CodeGen/CGBuiltin.cpp | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e051cbc6486353..e69235f350825b 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1203,10 +1203,24 @@ static llvm::Value 
*EmitX86BitTestIntrinsic(CodeGenFunction ,
   AsmOS << "bt";
   if (Action)
 AsmOS << Action;
-  AsmOS << SizeSuffix << " $2, ($1)";
 
-  // Build the constraints. FIXME: We should support immediates when possible.
-  std::string Constraints = "={@ccc},r,r,~{cc},~{memory}";
+  // Check if BitPos is a ConstantInt (immediate value)
+  if (llvm::ConstantInt *CI = llvm::dyn_cast(BitPos)) {
+// If it is, use the immediate value in the assembly string
+AsmOS << SizeSuffix << " $" << CI->getZExtValue() << ", ($1)";
+  } else {
+// Otherwise, fall back to the existing behavior
+AsmOS << SizeSuffix << " $2, ($1)";
+  }
+
+  // Build the constraints.
+  std::string Constraints;
+  if (llvm::isa(BitPos)) {
+Constraints = "={@ccc},r,~{cc},~{memory}";
+  } else {
+Constraints = "={@ccc},r,r,~{cc},~{memory}";
+  }
+
   std::string_view MachineClobbers = CGF.getTarget().getClobbers();
   if (!MachineClobbers.empty()) {
 Constraints += ',';

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


[clang] [CodeGen] Update test intrinsic to support immediates (PR #79174)

2024-02-06 Thread via cfe-commits

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


[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

2024-02-06 Thread Atousa Duprat via cfe-commits

https://github.com/Atousa updated 
https://github.com/llvm/llvm-project/pull/80939

>From a73812395e80ef79ce19378cae2aed58ad5b0532 Mon Sep 17 00:00:00 2001
From: Atousa Duprat 
Date: Tue, 6 Feb 2024 21:02:05 -0800
Subject: [PATCH] [clang] Use separator for large numeric values in overflow
 diagnostic

Add functionality to APInt::toString() that allows it to insert
separators between groups of digits, using the C++ litteral
separator ' between groups.

Fixes issue #58228
---
 clang/lib/AST/ExprConstant.cpp  |   3 +-
 clang/test/C/drs/dr0xx.c|   2 +-
 clang/test/C/drs/dr2xx.c|   2 +-
 clang/test/Sema/integer-overflow.c  | 100 +-
 clang/test/Sema/switch-1.c  |   6 +-
 clang/test/SemaCXX/enum.cpp |   4 +-
 clang/test/SemaCXX/integer-overflow.cpp | 110 ++--
 clang/test/SemaObjC/integer-overflow.m  |   4 +-
 clang/test/SemaObjC/objc-literal-nsnumber.m |   2 +-
 llvm/include/llvm/ADT/APInt.h   |   3 +-
 llvm/include/llvm/ADT/StringExtras.h|   5 +-
 llvm/lib/Support/APInt.cpp  |  24 -
 llvm/unittests/ADT/APIntTest.cpp|  35 +++
 13 files changed, 180 insertions(+), 120 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f..a46887d6cf1be 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2774,7 +2774,8 @@ static bool CheckedIntArithmetic(EvalInfo , const 
Expr *E,
 if (Info.checkingForUndefinedBehavior())
   Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_integer_constant_overflow)
-  << toString(Result, 10) << E->getType() << E->getSourceRange();
+  << toString(Result, 10, Result.isSigned(), false, true, true)
+  << E->getType() << E->getSourceRange();
 return HandleOverflow(Info, E, Value, E->getType());
   }
   return true;
diff --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index d9c1fbe4ee40a..c93cfb63d604c 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -214,7 +214,7 @@ _Static_assert(__builtin_types_compatible_p(struct S { int 
a; }, union U { int a
  */
 void dr031(int i) {
   switch (i) {
-  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   #pragma clang diagnostic push
   #pragma clang diagnostic ignored "-Wswitch"
   /* Silence the targets which issue:
diff --git a/clang/test/C/drs/dr2xx.c b/clang/test/C/drs/dr2xx.c
index 9c8d77518ab55..1b68b65acca6a 100644
--- a/clang/test/C/drs/dr2xx.c
+++ b/clang/test/C/drs/dr2xx.c
@@ -277,7 +277,7 @@ void dr258(void) {
 void dr261(void) {
   /* This is still an integer constant expression despite the overflow. */
   enum e1 {
-ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   };
 
   /* This is not an integer constant expression, because of the comma operator,
diff --git a/clang/test/Sema/integer-overflow.c 
b/clang/test/Sema/integer-overflow.c
index cf822f346e8b2..220fc1bed515a 100644
--- a/clang/test/Sema/integer-overflow.c
+++ b/clang/test/Sema/integer-overflow.c
@@ -11,169 +11,169 @@ uint64_t f0(uint64_t);
 uint64_t f1(uint64_t, uint32_t);
 uint64_t f2(uint64_t, ...);
 
-static const uint64_t overflow = 1 * 4608 * 1024 * 1024; // expected-warning 
{{overflow in expression; result is 536870912 with type 'int'}}
+static const uint64_t overflow = 1 * 4608 * 1024 * 1024; // expected-warning 
{{overflow in expression; result is 536'870'912 with type 'int'}}
 
 uint64_t check_integer_overflows(int i) {
-// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+// expected-warning@+1 {{overflow in expression; result is 536'870'912 with 
type 'int'}}
   uint64_t overflow = 4608 * 1024 * 1024,
-// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+// expected-warning@+1 {{overflow in expression; result is 536'870'912 with 
type 'int'}}
overflow2 = (uint64_t)(4608 * 1024 * 1024),
-// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+// expected-warning@+1 {{overflow in expression; result is 536'870'912 with 
type 'int'}}
overflow3 = (uint64_t)(4608 * 1024 * 1024 * i),
-// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+// expected-warning@+1 {{overflow in expression; result is 536'870'912 with 
type 'int'}}
overflow4 =  (1ULL * ((4608) * ((1024) * (1024))) + 2ULL),
-// expected-warning@+1 2{{overflow in expression; result 

[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)

2024-02-06 Thread Shengchen Kan via cfe-commits


@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) {
   Features["prefetchi"]  = HasLeaf7Subleaf1 && ((EDX >> 14) & 1);
   Features["usermsr"]  = HasLeaf7Subleaf1 && ((EDX >> 15) & 1);
   Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1);
+  Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1);

KanRobert wrote:

My understanding is "apxf" here is used by front-end for FMV, right?
What would happen if there is "apxf" in the IR after this patch?

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


[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)

2024-02-06 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/80636

>From b131b0971d5c38a29c954b37c0da8fb3177e5c92 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Mon, 5 Feb 2024 14:07:29 +0800
Subject: [PATCH 1/3] [X86] Support APXF to enable __builtin_cpu_supports.

---
 clang/test/CodeGen/target-builtin-noerror.c| 1 +
 compiler-rt/lib/builtins/cpu_model/x86.c   | 4 +++-
 llvm/include/llvm/TargetParser/X86TargetParser.def | 3 ++-
 llvm/lib/TargetParser/Host.cpp | 1 +
 llvm/lib/TargetParser/X86TargetParser.cpp  | 1 +
 5 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGen/target-builtin-noerror.c 
b/clang/test/CodeGen/target-builtin-noerror.c
index 9608b5f37baaae..b438e50848a4b6 100644
--- a/clang/test/CodeGen/target-builtin-noerror.c
+++ b/clang/test/CodeGen/target-builtin-noerror.c
@@ -141,6 +141,7 @@ void verifyfeaturestrings(void) {
   (void)__builtin_cpu_supports("sm3");
   (void)__builtin_cpu_supports("sha512");
   (void)__builtin_cpu_supports("sm4");
+  (void)__builtin_cpu_supports("apxf");
   (void)__builtin_cpu_supports("usermsr");
   (void)__builtin_cpu_supports("avx10.1-256");
   (void)__builtin_cpu_supports("avx10.1-512");
diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c 
b/compiler-rt/lib/builtins/cpu_model/x86.c
index 1afa468c4ae8c1..35375c6e8d55b6 100644
--- a/compiler-rt/lib/builtins/cpu_model/x86.c
+++ b/compiler-rt/lib/builtins/cpu_model/x86.c
@@ -217,7 +217,7 @@ enum ProcessorFeatures {
   FEATURE_SM3,
   FEATURE_SHA512,
   FEATURE_SM4,
-  // FEATURE_APXF,
+  FEATURE_APXF,
   FEATURE_USERMSR = 112,
   FEATURE_AVX10_1_256,
   FEATURE_AVX10_1_512,
@@ -983,6 +983,8 @@ static void getAvailableFeatures(unsigned ECX, unsigned 
EDX, unsigned MaxLeaf,
 setFeature(FEATURE_USERMSR);
   if (HasLeaf7Subleaf1 && ((EDX >> 19) & 1))
 setFeature(FEATURE_AVX10_1_256);
+  if (HasLeaf7Subleaf1 && ((EDX >> 21) & 1))
+setFeature(FEATURE_APXF);
 
   unsigned MaxLevel;
   getX86CpuIDAndInfo(0, , , , );
diff --git a/llvm/include/llvm/TargetParser/X86TargetParser.def 
b/llvm/include/llvm/TargetParser/X86TargetParser.def
index 4c630c1eb06e8c..ec52062a2baacf 100644
--- a/llvm/include/llvm/TargetParser/X86TargetParser.def
+++ b/llvm/include/llvm/TargetParser/X86TargetParser.def
@@ -248,10 +248,11 @@ X86_FEATURE_COMPAT(AVXVNNIINT16,"avxvnniint16",   
0)
 X86_FEATURE_COMPAT(SM3, "sm3",0)
 X86_FEATURE_COMPAT(SHA512,  "sha512", 0)
 X86_FEATURE_COMPAT(SM4, "sm4",0)
-X86_FEATURE   (EGPR,"egpr")
+X86_FEATURE_COMPAT(APXF,"apxf",   0)
 X86_FEATURE_COMPAT(USERMSR, "usermsr",0)
 X86_FEATURE_COMPAT(AVX10_1, "avx10.1-256",0)
 X86_FEATURE_COMPAT(AVX10_1_512, "avx10.1-512",0)
+X86_FEATURE   (EGPR,"egpr")
 X86_FEATURE   (EVEX512, "evex512")
 X86_FEATURE   (CF,  "cf")
 // These features aren't really CPU features, but the frontend can set them.
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index f1197c29655380..233ee12a000962 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) {
   Features["prefetchi"]  = HasLeaf7Subleaf1 && ((EDX >> 14) & 1);
   Features["usermsr"]  = HasLeaf7Subleaf1 && ((EDX >> 15) & 1);
   Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1);
+  Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1);
 
   bool HasLeafD = MaxLevel >= 0xd &&
   !getX86CpuIDAndInfoEx(0xd, 0x1, , , , );
diff --git a/llvm/lib/TargetParser/X86TargetParser.cpp 
b/llvm/lib/TargetParser/X86TargetParser.cpp
index 21f46f576490a8..ea1f8517bb3329 100644
--- a/llvm/lib/TargetParser/X86TargetParser.cpp
+++ b/llvm/lib/TargetParser/X86TargetParser.cpp
@@ -633,6 +633,7 @@ constexpr FeatureBitset ImpliedFeaturesPPX = {};
 constexpr FeatureBitset ImpliedFeaturesNDD = {};
 constexpr FeatureBitset ImpliedFeaturesCCMP = {};
 constexpr FeatureBitset ImpliedFeaturesCF = {};
+constexpr FeatureBitset ImpliedFeaturesAPXF = {};
 
 constexpr FeatureInfo FeatureInfos[X86::CPU_FEATURE_MAX] = {
 #define X86_FEATURE(ENUM, STR) {{"+" STR}, ImpliedFeatures##ENUM},

>From a1ecdf5fe54cb03045748e3d49f23e24e9428973 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Tue, 6 Feb 2024 17:19:28 +0800
Subject: [PATCH 2/3] misc

---
 compiler-rt/lib/builtins/cpu_model/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c 
b/compiler-rt/lib/builtins/cpu_model/x86.c
index 35375c6e8d55b6..7e8acb3e73eda9 100644
--- a/compiler-rt/lib/builtins/cpu_model/x86.c
+++ b/compiler-rt/lib/builtins/cpu_model/x86.c
@@ -218,7 +218,7 @@ enum ProcessorFeatures {
   FEATURE_SHA512,
   FEATURE_SM4,
   FEATURE_APXF,
-  FEATURE_USERMSR = 

[clang] [X86] Add missing MACROs in cpuid.h (PR #80815)

2024-02-06 Thread Freddy Ye via cfe-commits

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


[clang] c5e5661 - [X86] Add missing MACROs in cpuid.h (#80815)

2024-02-06 Thread via cfe-commits

Author: Freddy Ye
Date: 2024-02-07T14:33:20+08:00
New Revision: c5e5661591a90094eeb5831de86d701419c74f07

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

LOG: [X86] Add missing MACROs in cpuid.h (#80815)

Relate gcc file:
https://github.com/gcc-mirror/gcc/blob/master/gcc/config/i386/cpuid.h

Added: 


Modified: 
clang/lib/Headers/cpuid.h

Removed: 




diff  --git a/clang/lib/Headers/cpuid.h b/clang/lib/Headers/cpuid.h
index 1ad6853a97c9d..c968d37fb8cd6 100644
--- a/clang/lib/Headers/cpuid.h
+++ b/clang/lib/Headers/cpuid.h
@@ -200,6 +200,9 @@
 #define bit_AMXINT8   0x0200
 
 /* Features in %eax for leaf 7 sub-leaf 1 */
+#define bit_SHA5120x0001
+#define bit_SM3   0x0002
+#define bit_SM4   0x0004
 #define bit_RAOINT0x0008
 #define bit_AVXVNNI   0x0010
 #define bit_AVX512BF160x0020
@@ -211,7 +214,11 @@
 /* Features in %edx for leaf 7 sub-leaf 1 */
 #define bit_AVXVNNIINT8   0x0010
 #define bit_AVXNECONVERT  0x0020
+#define bit_AMXCOMPLEX0x0100
+#define bit_AVXVNNIINT16  0x0400
 #define bit_PREFETCHI 0x4000
+#define bit_USERMSR   0x8000
+#define bit_AVX10 0x0008
 
 /* Features in %eax for leaf 13 sub-leaf 1 */
 #define bit_XSAVEOPT0x0001
@@ -244,6 +251,9 @@
 #define bit_RDPRU   0x0010
 #define bit_WBNOINVD0x0200
 
+/* Features in %ebx for leaf 0x24 */
+#define bit_AVX10_256   0x0002
+#define bit_AVX10_512   0x0004
 
 #if __i386__
 #define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) \



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


[clang] [X86] Add missing MACROs in cpuid.h (PR #80815)

2024-02-06 Thread Freddy Ye via cfe-commits

FreddyLeaf wrote:

Thanks review!

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


[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)

2024-02-06 Thread Freddy Ye via cfe-commits


@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) {
   Features["prefetchi"]  = HasLeaf7Subleaf1 && ((EDX >> 14) & 1);
   Features["usermsr"]  = HasLeaf7Subleaf1 && ((EDX >> 15) & 1);
   Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1);
+  Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1);

FreddyLeaf wrote:

This patch defined one in clang through 
llvm/include/llvm/TargetParser/X86TargetParser.def. I think it's ok to do so.

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


[clang] [X86] Add missing MACROs in cpuid.h (PR #80815)

2024-02-06 Thread Phoebe Wang via cfe-commits

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

LGTM.

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


[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

2024-02-06 Thread Atousa Duprat via cfe-commits

https://github.com/Atousa updated 
https://github.com/llvm/llvm-project/pull/80939

>From 7dd1c213b650550e0fd47ff1c9d79ee3b510eddb Mon Sep 17 00:00:00 2001
From: Atousa Duprat 
Date: Tue, 6 Feb 2024 21:02:05 -0800
Subject: [PATCH] [clang] Use separator for large numeric values in overflow
 diagnostic

Add functionality to APInt::toString() that allows it to insert
separators between groups of digits, using the C++ litteral
separator ' between groups.

Fixes issue #58228
---
 clang/lib/AST/ExprConstant.cpp  |   3 +-
 clang/test/C/drs/dr0xx.c|   2 +-
 clang/test/C/drs/dr2xx.c|   2 +-
 clang/test/Sema/integer-overflow.c  | 100 +-
 clang/test/Sema/switch-1.c  |   6 +-
 clang/test/SemaCXX/enum.cpp |   4 +-
 clang/test/SemaCXX/integer-overflow.cpp | 106 ++--
 clang/test/SemaObjC/integer-overflow.m  |   4 +-
 clang/test/SemaObjC/objc-literal-nsnumber.m |   2 +-
 llvm/include/llvm/ADT/APInt.h   |   3 +-
 llvm/include/llvm/ADT/StringExtras.h|   5 +-
 llvm/lib/Support/APInt.cpp  |  24 -
 llvm/unittests/ADT/APIntTest.cpp|  35 +++
 13 files changed, 178 insertions(+), 118 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f..a46887d6cf1be 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2774,7 +2774,8 @@ static bool CheckedIntArithmetic(EvalInfo , const 
Expr *E,
 if (Info.checkingForUndefinedBehavior())
   Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_integer_constant_overflow)
-  << toString(Result, 10) << E->getType() << E->getSourceRange();
+  << toString(Result, 10, Result.isSigned(), false, true, true)
+  << E->getType() << E->getSourceRange();
 return HandleOverflow(Info, E, Value, E->getType());
   }
   return true;
diff --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index d9c1fbe4ee40a..c93cfb63d604c 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -214,7 +214,7 @@ _Static_assert(__builtin_types_compatible_p(struct S { int 
a; }, union U { int a
  */
 void dr031(int i) {
   switch (i) {
-  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+  case __INT_MAX__ + 1: break; /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   #pragma clang diagnostic push
   #pragma clang diagnostic ignored "-Wswitch"
   /* Silence the targets which issue:
diff --git a/clang/test/C/drs/dr2xx.c b/clang/test/C/drs/dr2xx.c
index 9c8d77518ab55..1b68b65acca6a 100644
--- a/clang/test/C/drs/dr2xx.c
+++ b/clang/test/C/drs/dr2xx.c
@@ -277,7 +277,7 @@ void dr258(void) {
 void dr261(void) {
   /* This is still an integer constant expression despite the overflow. */
   enum e1 {
-ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2'147'483'648 with type 'int'}} */
   };
 
   /* This is not an integer constant expression, because of the comma operator,
diff --git a/clang/test/Sema/integer-overflow.c 
b/clang/test/Sema/integer-overflow.c
index cf822f346e8b2..220fc1bed515a 100644
--- a/clang/test/Sema/integer-overflow.c
+++ b/clang/test/Sema/integer-overflow.c
@@ -11,169 +11,169 @@ uint64_t f0(uint64_t);
 uint64_t f1(uint64_t, uint32_t);
 uint64_t f2(uint64_t, ...);
 
-static const uint64_t overflow = 1 * 4608 * 1024 * 1024; // expected-warning 
{{overflow in expression; result is 536870912 with type 'int'}}
+static const uint64_t overflow = 1 * 4608 * 1024 * 1024; // expected-warning 
{{overflow in expression; result is 536'870'912 with type 'int'}}
 
 uint64_t check_integer_overflows(int i) {
-// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+// expected-warning@+1 {{overflow in expression; result is 536'870'912 with 
type 'int'}}
   uint64_t overflow = 4608 * 1024 * 1024,
-// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+// expected-warning@+1 {{overflow in expression; result is 536'870'912 with 
type 'int'}}
overflow2 = (uint64_t)(4608 * 1024 * 1024),
-// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+// expected-warning@+1 {{overflow in expression; result is 536'870'912 with 
type 'int'}}
overflow3 = (uint64_t)(4608 * 1024 * 1024 * i),
-// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+// expected-warning@+1 {{overflow in expression; result is 536'870'912 with 
type 'int'}}
overflow4 =  (1ULL * ((4608) * ((1024) * (1024))) + 2ULL),
-// expected-warning@+1 2{{overflow in expression; result 

[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)

2024-02-06 Thread Phoebe Wang via cfe-commits


@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) {
   Features["prefetchi"]  = HasLeaf7Subleaf1 && ((EDX >> 14) & 1);
   Features["usermsr"]  = HasLeaf7Subleaf1 && ((EDX >> 15) & 1);
   Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1);
+  Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1);

phoebewang wrote:

I don't think we have a `apxf` feature in LLVM, should it be `egpr`?

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


[clang] [docs] [C++20] [Modules] Ideas for transitioning to modules (PR #80687)

2024-02-06 Thread Chuanqi Xu via cfe-commits


@@ -610,6 +610,345 @@ the following style significantly:
 
 The key part of the tip is to reduce the duplications from the text includes.
 
+Ideas for converting to modules
+---
+
+For new libraries, we encourage them to use modules completely from day one if 
possible.
+This will be pretty helpful to make the whole ecosystems to get ready.
+
+For many existing libraries, it may be a breaking change to refactor themselves
+into modules completely. So that many existing libraries need to provide 
headers and module
+interfaces for a while to not break existing users.
+Here we provide some ideas to ease the transition process for existing 
libraries.
+**Note that the this section is only about helping ideas instead of 
requirement from clang**.
+
+Let's start with the case that there is no dependency or no dependent 
libraries providing
+modules for your library.
+
+ABI non-breaking styles
+~~~
+
+export-using style
+^^
+
+.. code-block:: c++
+
+  module;
+  #include "header_1.h"
+  #include "header_2.h"
+  ...
+  #include "header_n.h"
+  export module your_library;
+  export namespace your_namespace {
+using decl_1;
+using decl_2;
+...
+using decl_n;
+  }
+
+As the example shows, you need to include all the headers containing 
declarations needs
+to be exported and `using` such declarations in an `export` block. Then, 
basically,
+we're done.
+
+export extern-C++ style
+^^^
+
+.. code-block:: c++
+
+  module;
+  #include "third_party/A/headers.h"
+  #include "third_party/B/headers.h"
+  ...
+  #include "third_party/Z/headers.h"
+  export module your_library;
+  #define IN_MODULE_INTERFACE
+  extern "C++" {
+#include "header_1.h"
+#include "header_2.h"
+...
+#include "header_n.h"
+  }
+
+Then in your headers (from ``header_1.h`` to ``header_n.h``), you need to 
define the macro:
+
+.. code-block:: c++
+
+  #ifdef IN_MODULE_INTERFACE
+  #define EXPORT export
+  #else
+  #define EXPORT
+  #endif
+
+And you should put ``EXPORT`` to the beginning of the declarations you want to 
export.
+
+Also it is suggested to refactor your headers to include thirdparty headers 
conditionally:
+
+.. code-block:: c++
+
+  + #ifndef IN_MODULE_INTERFACE
+  #include "third_party/A/headers.h"
+  + #endif
+
+  #include "header_x.h"
+
+  ...
+
+This may be helpful to get better diagnostic messages if you forgot to update 
your module 
+interface unit file during maintaining.
+
+The reasoning for the practice is that the declarations in the language 
linkage are considered
+to be attached to the global module. So the ABI of your library in the modular 
version
+wouldn't change.
+
+While this style looks not as convenient as the export-using style, it is 
easier to convert 
+to other styles.
+
+ABI breaking style
+~~
+
+The term ``ABI breaking`` sounds terrifying generally. But you may want it 
here if you want
+to force your users to introduce your library in a consistent way. E.g., they 
either include
+your headers all the way or import your modules all the way.
+The style prevents the users to include your headers and import your modules 
at the same time
+in the same repo.

ChuanqiXu9 wrote:

For example, if the library is in a closed-ended ecosystem (e.g., only 
available to an organization internally), then  we want to provide modules 
interfaces for the library and we want our users to avoid the accidental 
performance cost due to mixing use of include and import, then such pattern 
helps. In case, the user repo A depends on a repo B and repo B include the 
modularized library, the repo A can reach out repo B to refactor itself. I feel 
such workflow can be understandable in a close ended organization.

 It will bring some burden to users initially, but in the end it would bring 
better quality. I understand this is not a helpful universally. But I feel it 
may be helpful to people who want to bring stronger requirement to the usage of 
their codes.

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


[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

2024-02-06 Thread Atousa Duprat via cfe-commits

https://github.com/Atousa updated 
https://github.com/llvm/llvm-project/pull/80939

>From 6ca8091362baf63fcbfeff60816830cc88c5a36f Mon Sep 17 00:00:00 2001
From: Atousa Duprat 
Date: Tue, 6 Feb 2024 21:02:05 -0800
Subject: [PATCH] [clang] Use separator for large numeric values in overflow
 diagnostic

Add functionality to APInt::toString() that allows it to insert
separators between groups of digits, using the C++ litteral
separator ' between groups.

Fixes issue #58228
---
 clang/lib/AST/ExprConstant.cpp   |  3 ++-
 llvm/include/llvm/ADT/APInt.h|  3 ++-
 llvm/include/llvm/ADT/StringExtras.h |  5 ++--
 llvm/lib/Support/APInt.cpp   | 24 ++-
 llvm/unittests/ADT/APIntTest.cpp | 35 
 5 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f..a46887d6cf1be 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2774,7 +2774,8 @@ static bool CheckedIntArithmetic(EvalInfo , const 
Expr *E,
 if (Info.checkingForUndefinedBehavior())
   Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_integer_constant_overflow)
-  << toString(Result, 10) << E->getType() << E->getSourceRange();
+  << toString(Result, 10, Result.isSigned(), false, true, true)
+  << E->getType() << E->getSourceRange();
 return HandleOverflow(Info, E, Value, E->getType());
   }
   return true;
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 6f2f25548cc84..dd6d71b93334b 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -1626,7 +1626,8 @@ class [[nodiscard]] APInt {
   /// SmallString. If Radix > 10, UpperCase determine the case of letter
   /// digits.
   void toString(SmallVectorImpl , unsigned Radix, bool Signed,
-bool formatAsCLiteral = false, bool UpperCase = true) const;
+bool formatAsCLiteral = false, bool UpperCase = true,
+bool insertSeparators = false) const;
 
   /// Considers the APInt to be unsigned and converts it into a string in the
   /// radix given. The radix can be 2, 8, 10 16, or 36.
diff --git a/llvm/include/llvm/ADT/StringExtras.h 
b/llvm/include/llvm/ADT/StringExtras.h
index a24368924bc90..32f5828c92d05 100644
--- a/llvm/include/llvm/ADT/StringExtras.h
+++ b/llvm/include/llvm/ADT/StringExtras.h
@@ -329,9 +329,10 @@ inline std::string itostr(int64_t X) {
 }
 
 inline std::string toString(const APInt , unsigned Radix, bool Signed,
-bool formatAsCLiteral = false) {
+bool formatAsCLiteral = false,
+bool upperCase = true, bool addSeparators = false) 
{
   SmallString<40> S;
-  I.toString(S, Radix, Signed, formatAsCLiteral);
+  I.toString(S, Radix, Signed, formatAsCLiteral, upperCase, addSeparators);
   return std::string(S);
 }
 
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 05b1526da95ff..a186b81bc6797 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -2161,7 +2161,8 @@ void APInt::fromString(unsigned numbits, StringRef str, 
uint8_t radix) {
 }
 
 void APInt::toString(SmallVectorImpl , unsigned Radix, bool Signed,
- bool formatAsCLiteral, bool UpperCase) const {
+ bool formatAsCLiteral, bool UpperCase,
+ bool insertSeparators) const {
   assert((Radix == 10 || Radix == 8 || Radix == 16 || Radix == 2 ||
   Radix == 36) &&
  "Radix should be 2, 8, 10, 16, or 36!");
@@ -2187,6 +2188,12 @@ void APInt::toString(SmallVectorImpl , 
unsigned Radix, bool Signed,
 }
   }
 
+  // Number of digits in a group between separators
+  int Grouping = 4;
+  if (Radix == 8 || Radix == 10) {
+Grouping = 3;
+  }
+
   // First, check for a zero value and just short circuit the logic below.
   if (isZero()) {
 while (*Prefix) {
@@ -2223,9 +2230,14 @@ void APInt::toString(SmallVectorImpl , 
unsigned Radix, bool Signed,
   ++Prefix;
 };
 
+int Pos = 0;
 while (N) {
+  if (insertSeparators && Pos % Grouping == 0 && Pos > 0) {
+*--BufPtr = '\'';
+  }
   *--BufPtr = Digits[N % Radix];
   N /= Radix;
+  Pos++;
 }
 Str.append(BufPtr, std::end(Buffer));
 return;
@@ -2257,17 +2269,27 @@ void APInt::toString(SmallVectorImpl , 
unsigned Radix, bool Signed,
 unsigned ShiftAmt = (Radix == 16 ? 4 : (Radix == 8 ? 3 : 1));
 unsigned MaskAmt = Radix - 1;
 
+int Pos = 0;
 while (Tmp.getBoolValue()) {
   unsigned Digit = unsigned(Tmp.getRawData()[0]) & MaskAmt;
+  if (insertSeparators && Pos % Grouping == 0 && Pos > 0) {
+Str.push_back('\'');
+  }
   Str.push_back(Digits[Digit]);
   Tmp.lshrInPlace(ShiftAmt);
+  Pos++;
 }
   } else {
+int Pos = 0;
 while 

[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

2024-02-06 Thread Atousa Duprat via cfe-commits

https://github.com/Atousa updated 
https://github.com/llvm/llvm-project/pull/80939

>From 6dcb144b92ad2cd4198a53aae40f77d3eba3dbca Mon Sep 17 00:00:00 2001
From: Atousa Duprat 
Date: Tue, 6 Feb 2024 21:02:05 -0800
Subject: [PATCH] [clang] Use separator for large numeric values in overflow
 diagnostic

Add functionality to APInt::toString() that allows it to insert
separators between groups of digits, using the C++ litteral
separator ' between groups.

Fixes issue #58228
---
 clang/lib/AST/ExprConstant.cpp   |  3 ++-
 llvm/include/llvm/ADT/APInt.h|  3 ++-
 llvm/include/llvm/ADT/StringExtras.h |  6 +++--
 llvm/lib/Support/APInt.cpp   | 24 ++-
 llvm/unittests/ADT/APIntTest.cpp | 35 
 5 files changed, 66 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f..a46887d6cf1be 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2774,7 +2774,8 @@ static bool CheckedIntArithmetic(EvalInfo , const 
Expr *E,
 if (Info.checkingForUndefinedBehavior())
   Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_integer_constant_overflow)
-  << toString(Result, 10) << E->getType() << E->getSourceRange();
+  << toString(Result, 10, Result.isSigned(), false, true, true)
+  << E->getType() << E->getSourceRange();
 return HandleOverflow(Info, E, Value, E->getType());
   }
   return true;
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 6f2f25548cc84..0d696e7a6f981 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -1626,7 +1626,8 @@ class [[nodiscard]] APInt {
   /// SmallString. If Radix > 10, UpperCase determine the case of letter
   /// digits.
   void toString(SmallVectorImpl , unsigned Radix, bool Signed,
-bool formatAsCLiteral = false, bool UpperCase = true) const;
+bool formatAsCLiteral = false, bool UpperCase = true, 
+bool insertSeparators = false) const;
 
   /// Considers the APInt to be unsigned and converts it into a string in the
   /// radix given. The radix can be 2, 8, 10 16, or 36.
diff --git a/llvm/include/llvm/ADT/StringExtras.h 
b/llvm/include/llvm/ADT/StringExtras.h
index a24368924bc90..f96b2032f048c 100644
--- a/llvm/include/llvm/ADT/StringExtras.h
+++ b/llvm/include/llvm/ADT/StringExtras.h
@@ -329,9 +329,11 @@ inline std::string itostr(int64_t X) {
 }
 
 inline std::string toString(const APInt , unsigned Radix, bool Signed,
-bool formatAsCLiteral = false) {
+bool formatAsCLiteral = false,
+bool upperCase = true,
+bool addSeparators = false) {
   SmallString<40> S;
-  I.toString(S, Radix, Signed, formatAsCLiteral);
+  I.toString(S, Radix, Signed, formatAsCLiteral, upperCase, addSeparators);
   return std::string(S);
 }
 
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 05b1526da95ff..e7ca82a6c126d 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -2161,7 +2161,8 @@ void APInt::fromString(unsigned numbits, StringRef str, 
uint8_t radix) {
 }
 
 void APInt::toString(SmallVectorImpl , unsigned Radix, bool Signed,
- bool formatAsCLiteral, bool UpperCase) const {
+ bool formatAsCLiteral, bool UpperCase, 
+ bool insertSeparators) const {
   assert((Radix == 10 || Radix == 8 || Radix == 16 || Radix == 2 ||
   Radix == 36) &&
  "Radix should be 2, 8, 10, 16, or 36!");
@@ -2187,6 +2188,12 @@ void APInt::toString(SmallVectorImpl , 
unsigned Radix, bool Signed,
 }
   }
 
+  // Number of digits in a group between separators
+  int Grouping = 4;
+  if (Radix == 8 || Radix == 10) {
+Grouping = 3;
+  }
+
   // First, check for a zero value and just short circuit the logic below.
   if (isZero()) {
 while (*Prefix) {
@@ -2223,9 +2230,14 @@ void APInt::toString(SmallVectorImpl , 
unsigned Radix, bool Signed,
   ++Prefix;
 };
 
+int Pos = 0;
 while (N) {
+  if (insertSeparators && Pos%Grouping==0 && Pos > 0) {
+*--BufPtr = '\'';
+  }
   *--BufPtr = Digits[N % Radix];
   N /= Radix;
+  Pos++;
 }
 Str.append(BufPtr, std::end(Buffer));
 return;
@@ -2257,17 +2269,27 @@ void APInt::toString(SmallVectorImpl , 
unsigned Radix, bool Signed,
 unsigned ShiftAmt = (Radix == 16 ? 4 : (Radix == 8 ? 3 : 1));
 unsigned MaskAmt = Radix - 1;
 
+int Pos = 0;
 while (Tmp.getBoolValue()) {
   unsigned Digit = unsigned(Tmp.getRawData()[0]) & MaskAmt;
+  if (insertSeparators && Pos%Grouping==0 && Pos>0) {
+Str.push_back('\'');
+  }
   Str.push_back(Digits[Digit]);
   Tmp.lshrInPlace(ShiftAmt);
+  Pos++;
 }
   } else {
+int 

[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

2024-02-06 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff adbf21f12b3069b2554efb39f2e92c6cf6f24940 
c3efdb00f58ef91e587d37b08d06982a81ccefc4 -- clang/lib/AST/ExprConstant.cpp 
llvm/include/llvm/ADT/APInt.h llvm/include/llvm/ADT/StringExtras.h 
llvm/lib/Support/APInt.cpp llvm/unittests/ADT/APIntTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 0d696e7a6f..dd6d71b933 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -1626,7 +1626,7 @@ public:
   /// SmallString. If Radix > 10, UpperCase determine the case of letter
   /// digits.
   void toString(SmallVectorImpl , unsigned Radix, bool Signed,
-bool formatAsCLiteral = false, bool UpperCase = true, 
+bool formatAsCLiteral = false, bool UpperCase = true,
 bool insertSeparators = false) const;
 
   /// Considers the APInt to be unsigned and converts it into a string in the
diff --git a/llvm/include/llvm/ADT/StringExtras.h 
b/llvm/include/llvm/ADT/StringExtras.h
index f96b2032f0..32f5828c92 100644
--- a/llvm/include/llvm/ADT/StringExtras.h
+++ b/llvm/include/llvm/ADT/StringExtras.h
@@ -330,8 +330,7 @@ inline std::string itostr(int64_t X) {
 
 inline std::string toString(const APInt , unsigned Radix, bool Signed,
 bool formatAsCLiteral = false,
-bool upperCase = true,
-bool addSeparators = false) {
+bool upperCase = true, bool addSeparators = false) 
{
   SmallString<40> S;
   I.toString(S, Radix, Signed, formatAsCLiteral, upperCase, addSeparators);
   return std::string(S);
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index e7ca82a6c1..a186b81bc6 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -2161,7 +2161,7 @@ void APInt::fromString(unsigned numbits, StringRef str, 
uint8_t radix) {
 }
 
 void APInt::toString(SmallVectorImpl , unsigned Radix, bool Signed,
- bool formatAsCLiteral, bool UpperCase, 
+ bool formatAsCLiteral, bool UpperCase,
  bool insertSeparators) const {
   assert((Radix == 10 || Radix == 8 || Radix == 16 || Radix == 2 ||
   Radix == 36) &&
@@ -2232,7 +2232,7 @@ void APInt::toString(SmallVectorImpl , unsigned 
Radix, bool Signed,
 
 int Pos = 0;
 while (N) {
-  if (insertSeparators && Pos%Grouping==0 && Pos > 0) {
+  if (insertSeparators && Pos % Grouping == 0 && Pos > 0) {
 *--BufPtr = '\'';
   }
   *--BufPtr = Digits[N % Radix];
@@ -2272,7 +2272,7 @@ void APInt::toString(SmallVectorImpl , unsigned 
Radix, bool Signed,
 int Pos = 0;
 while (Tmp.getBoolValue()) {
   unsigned Digit = unsigned(Tmp.getRawData()[0]) & MaskAmt;
-  if (insertSeparators && Pos%Grouping==0 && Pos>0) {
+  if (insertSeparators && Pos % Grouping == 0 && Pos > 0) {
 Str.push_back('\'');
   }
   Str.push_back(Digits[Digit]);
@@ -2285,7 +2285,7 @@ void APInt::toString(SmallVectorImpl , unsigned 
Radix, bool Signed,
   uint64_t Digit;
   udivrem(Tmp, Radix, Tmp, Digit);
   assert(Digit < Radix && "divide failed");
-  if (insertSeparators && Pos%Grouping==0 && Pos>0) {
+  if (insertSeparators && Pos % Grouping == 0 && Pos > 0) {
 Str.push_back('\'');
   }
   Str.push_back(Digits[Digit]);
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index 843a7c447c..e3e7e1e7ba 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -1446,10 +1446,10 @@ TEST(APIntTest, toString) {
   APInt(64, -100, isSigned).toString(S, 16, isSigned, true, true, true);
   EXPECT_EQ(std::string(S), "-0xF'4240");
   S.clear();
-  APInt(64, -1'000'000'000, isSigned).toString(S, 36, isSigned, false, false, 
true);
+  APInt(64, -1'000'000'000, isSigned)
+  .toString(S, 36, isSigned, false, false, true);
   EXPECT_EQ(std::string(S), "-gj'dgxs");
   S.clear();
-
 }
 
 TEST(APIntTest, Log2) {

``




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


[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

2024-02-06 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [llvm] [clang] Use separator for large numeric values in overflow diagnostic (PR #80939)

2024-02-06 Thread Atousa Duprat via cfe-commits

https://github.com/Atousa created 
https://github.com/llvm/llvm-project/pull/80939

Add functionality to APInt::toString() that allows it to insert
separators between groups of digits, using the C++ litteral
separator ' between groups.

Fixes issue #58228


>From 6dcb144b92ad2cd4198a53aae40f77d3eba3dbca Mon Sep 17 00:00:00 2001
From: Atousa Duprat 
Date: Tue, 6 Feb 2024 21:02:05 -0800
Subject: [PATCH 1/2] [clang] Use separator for large numeric values in
 overflow diagnostic

Add functionality to APInt::toString() that allows it to insert
separators between groups of digits, using the C++ litteral
separator ' between groups.

Fixes issue #58228
---
 clang/lib/AST/ExprConstant.cpp   |  3 ++-
 llvm/include/llvm/ADT/APInt.h|  3 ++-
 llvm/include/llvm/ADT/StringExtras.h |  6 +++--
 llvm/lib/Support/APInt.cpp   | 24 ++-
 llvm/unittests/ADT/APIntTest.cpp | 35 
 5 files changed, 66 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f7..a46887d6cf1be0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2774,7 +2774,8 @@ static bool CheckedIntArithmetic(EvalInfo , const 
Expr *E,
 if (Info.checkingForUndefinedBehavior())
   Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_integer_constant_overflow)
-  << toString(Result, 10) << E->getType() << E->getSourceRange();
+  << toString(Result, 10, Result.isSigned(), false, true, true)
+  << E->getType() << E->getSourceRange();
 return HandleOverflow(Info, E, Value, E->getType());
   }
   return true;
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 6f2f25548cc84b..0d696e7a6f981b 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -1626,7 +1626,8 @@ class [[nodiscard]] APInt {
   /// SmallString. If Radix > 10, UpperCase determine the case of letter
   /// digits.
   void toString(SmallVectorImpl , unsigned Radix, bool Signed,
-bool formatAsCLiteral = false, bool UpperCase = true) const;
+bool formatAsCLiteral = false, bool UpperCase = true, 
+bool insertSeparators = false) const;
 
   /// Considers the APInt to be unsigned and converts it into a string in the
   /// radix given. The radix can be 2, 8, 10 16, or 36.
diff --git a/llvm/include/llvm/ADT/StringExtras.h 
b/llvm/include/llvm/ADT/StringExtras.h
index a24368924bc90a..f96b2032f048c4 100644
--- a/llvm/include/llvm/ADT/StringExtras.h
+++ b/llvm/include/llvm/ADT/StringExtras.h
@@ -329,9 +329,11 @@ inline std::string itostr(int64_t X) {
 }
 
 inline std::string toString(const APInt , unsigned Radix, bool Signed,
-bool formatAsCLiteral = false) {
+bool formatAsCLiteral = false,
+bool upperCase = true,
+bool addSeparators = false) {
   SmallString<40> S;
-  I.toString(S, Radix, Signed, formatAsCLiteral);
+  I.toString(S, Radix, Signed, formatAsCLiteral, upperCase, addSeparators);
   return std::string(S);
 }
 
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 05b1526da95ff7..e7ca82a6c126d5 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -2161,7 +2161,8 @@ void APInt::fromString(unsigned numbits, StringRef str, 
uint8_t radix) {
 }
 
 void APInt::toString(SmallVectorImpl , unsigned Radix, bool Signed,
- bool formatAsCLiteral, bool UpperCase) const {
+ bool formatAsCLiteral, bool UpperCase, 
+ bool insertSeparators) const {
   assert((Radix == 10 || Radix == 8 || Radix == 16 || Radix == 2 ||
   Radix == 36) &&
  "Radix should be 2, 8, 10, 16, or 36!");
@@ -2187,6 +2188,12 @@ void APInt::toString(SmallVectorImpl , 
unsigned Radix, bool Signed,
 }
   }
 
+  // Number of digits in a group between separators
+  int Grouping = 4;
+  if (Radix == 8 || Radix == 10) {
+Grouping = 3;
+  }
+
   // First, check for a zero value and just short circuit the logic below.
   if (isZero()) {
 while (*Prefix) {
@@ -2223,9 +2230,14 @@ void APInt::toString(SmallVectorImpl , 
unsigned Radix, bool Signed,
   ++Prefix;
 };
 
+int Pos = 0;
 while (N) {
+  if (insertSeparators && Pos%Grouping==0 && Pos > 0) {
+*--BufPtr = '\'';
+  }
   *--BufPtr = Digits[N % Radix];
   N /= Radix;
+  Pos++;
 }
 Str.append(BufPtr, std::end(Buffer));
 return;
@@ -2257,17 +2269,27 @@ void APInt::toString(SmallVectorImpl , 
unsigned Radix, bool Signed,
 unsigned ShiftAmt = (Radix == 16 ? 4 : (Radix == 8 ? 3 : 1));
 unsigned MaskAmt = Radix - 1;
 
+int Pos = 0;
 while (Tmp.getBoolValue()) {
   unsigned Digit = unsigned(Tmp.getRawData()[0]) & MaskAmt;
+  if 

[clang] Disable FTZ/DAZ when compiling shared libraries by default. (PR #80475)

2024-02-06 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> Do you only set the register for kernel entries?

Yes, it's the pre-initialized state. Non kernels can't be arbitrarily invoked 
from the host 

>  Is the attribute ignored for other functions?

No, it's an informative attribute about that the mode is. The compiler isn't 
trying to fix up the modes for you. If you enter the function with the wrong 
mode, you get what you get. 



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


[clang] [clang-format] Fix a regression in dumping the config (PR #80628)

2024-02-06 Thread Owen Pan via cfe-commits


@@ -1,5 +1,8 @@
+// RUN: clang-format -assume-filename=foo.m -dump-config | FileCheck %s

owenca wrote:

Yes, because it wouldn't make a difference before and after the patch. I don't 
think we can use lit to test that behavior (i.e., not waiting for an EOF) of 
clang-format in the terminal.

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


[clang] [clang] Add fbasic-block-sections support for AArch64 (PR #80916)

2024-02-06 Thread Mingming Liu via cfe-commits


@@ -5972,6 +5972,15 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 << A->getAsString(Args) << A->getValue();
   else
 A->render(Args, CmdArgs);
+} else if (Triple.isAArch64()) {
+  // "all" is not supported on AArch64 since branch relaxation creates new

minglotus-6 wrote:

I think `Triple.isOSBinFormatELF()` is needed (just like for x86).

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


[clang] [clang] Add fbasic-block-sections support for AArch64 (PR #80916)

2024-02-06 Thread Mingming Liu via cfe-commits

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


[clang] [clang] Add fbasic-block-sections support for AArch64 (PR #80916)

2024-02-06 Thread Mingming Liu via cfe-commits

https://github.com/minglotus-6 commented:

Optional suggestion to revise the title as something like 'Clang options for 
basic block sections on aarch64"

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


[clang] Fix an implicit cast to a base ref counted class generates a false positive. (PR #80934)

2024-02-06 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/80934

>From 9154815c48578df9ee384a9707dd79ee64259cea Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Tue, 6 Feb 2024 20:10:33 -0800
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Fix an implicit cast
 to a base ref counted class generates a false positive.

The bug was caused by isRefCountable erroneously returning false for a class
with both ref() and deref() functions defined because we were not resetting
the base paths results between looking for "ref()" and "deref()"
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp |  1 +
 ...to-base-class-with-deref-in-superclass.cpp | 51 +++
 2 files changed, 52 insertions(+)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index d2b66341058000..0fd8afedc0b0f5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -84,6 +84,7 @@ std::optional isRefCountable(const CXXRecordDecl* R)
   if (AnyInconclusiveBase)
 return std::nullopt;
 
+  Paths.clear();
   const auto hasPublicDerefInBase =
   [](const CXXBaseSpecifier *Base, CXXBasePath &) {
 auto hasDerefInBase = clang::hasPublicMethodInBase(Base, "deref");
diff --git 
a/clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp
 
b/clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp
new file mode 100644
index 00..49826c98a4610d
--- /dev/null
+++ 
b/clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+template
+class Ref {
+public:
+~Ref()
+{
+if (auto* ptr = m_ptr)
+ptr->deref();
+m_ptr = nullptr;
+}
+
+Ref(T& object)
+: m_ptr()
+{
+object.ref();
+}
+
+operator T&() const { return *m_ptr; }
+bool operator!() const { return !*m_ptr; }
+
+private:
+T* m_ptr;
+};
+
+class Base {
+public:
+virtual ~Base();
+void ref() const;
+void deref() const;
+};
+
+class Event : public Base {
+protected:
+explicit Event();
+};
+
+class SubEvent : public Event {
+public:
+static Ref create();
+private:
+SubEvent() = default;
+};
+
+void someFunction(Base&);
+
+static void test()
+{
+someFunction(SubEvent::create());
+}

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


[clang] Fix an implicit cast to a base ref counted class generates a false positive. (PR #80934)

2024-02-06 Thread via cfe-commits

llvmbot wrote:




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

Author: Ryosuke Niwa (rniwa)


Changes

The bug was caused by isRefCountable erroneously returning false for a class 
with both ref() and deref() functions defined because we were not resetting the 
base paths results between looking for "ref()" and "deref()"

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(+1) 
- (added) 
clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp
 (+51) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index d2b66341058000..0fd8afedc0b0f5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -84,6 +84,7 @@ std::optional isRefCountable(const CXXRecordDecl* R)
   if (AnyInconclusiveBase)
 return std::nullopt;
 
+  Paths.clear();
   const auto hasPublicDerefInBase =
   [](const CXXBaseSpecifier *Base, CXXBasePath &) {
 auto hasDerefInBase = clang::hasPublicMethodInBase(Base, "deref");
diff --git 
a/clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp
 
b/clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp
new file mode 100644
index 00..49826c98a4610d
--- /dev/null
+++ 
b/clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+template
+class Ref {
+public:
+~Ref()
+{
+if (auto* ptr = m_ptr)
+ptr->deref();
+m_ptr = nullptr;
+}
+
+Ref(T& object)
+: m_ptr()
+{
+object.ref();
+}
+
+operator T&() const { return *m_ptr; }
+bool operator!() const { return !*m_ptr; }
+
+private:
+T* m_ptr;
+};
+
+class Base {
+public:
+virtual ~Base();
+void ref() const;
+void deref() const;
+};
+
+class Event : public Base {
+protected:
+explicit Event();
+};
+
+class SubEvent : public Event {
+public:
+static Ref create();
+private:
+SubEvent() = default;
+};
+
+void someFunction(Base&);
+
+static void test()
+{
+someFunction(SubEvent::create());
+}

``




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


[clang] Fix an implicit cast to a base ref counted class generates a false positive. (PR #80934)

2024-02-06 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/80934

The bug was caused by isRefCountable erroneously returning false for a class 
with both ref() and deref() functions defined because we were not resetting the 
base paths results between looking for "ref()" and "deref()"

>From 377f096eda881b9a7c9b4d413081f11a3c4af62e Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Tue, 6 Feb 2024 20:10:33 -0800
Subject: [PATCH] Fix an implicit cast to a base ref counted class generates a
 false positive.

The bug was caused by isRefCountable erroneously returning false for a class
with both ref() and deref() functions defined because we were not resetting
the base paths results between looking for "ref()" and "deref()"
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp |  1 +
 ...to-base-class-with-deref-in-superclass.cpp | 51 +++
 2 files changed, 52 insertions(+)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index d2b66341058000..0fd8afedc0b0f5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -84,6 +84,7 @@ std::optional isRefCountable(const CXXRecordDecl* R)
   if (AnyInconclusiveBase)
 return std::nullopt;
 
+  Paths.clear();
   const auto hasPublicDerefInBase =
   [](const CXXBaseSpecifier *Base, CXXBasePath &) {
 auto hasDerefInBase = clang::hasPublicMethodInBase(Base, "deref");
diff --git 
a/clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp
 
b/clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp
new file mode 100644
index 00..49826c98a4610d
--- /dev/null
+++ 
b/clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+template
+class Ref {
+public:
+~Ref()
+{
+if (auto* ptr = m_ptr)
+ptr->deref();
+m_ptr = nullptr;
+}
+
+Ref(T& object)
+: m_ptr()
+{
+object.ref();
+}
+
+operator T&() const { return *m_ptr; }
+bool operator!() const { return !*m_ptr; }
+
+private:
+T* m_ptr;
+};
+
+class Base {
+public:
+virtual ~Base();
+void ref() const;
+void deref() const;
+};
+
+class Event : public Base {
+protected:
+explicit Event();
+};
+
+class SubEvent : public Event {
+public:
+static Ref create();
+private:
+SubEvent() = default;
+};
+
+void someFunction(Base&);
+
+static void test()
+{
+someFunction(SubEvent::create());
+}

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


[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)

2024-02-06 Thread Freddy Ye via cfe-commits

FreddyLeaf wrote:

ping for review

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


[clang] [llvm] [RISCV] RISCV vector calling convention (1/2) (PR #77560)

2024-02-06 Thread Brandon Wu via cfe-commits

4vtomat wrote:

The latest fixup commit add [[riscv::riscv_vector]] supports for C23 and C++11.

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


[clang] [Headers][X86] Editorial fixes to ia32intrin.h descriptions (PR #80490)

2024-02-06 Thread via cfe-commits

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


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


[clang] [WebAssembly] Add more features to generic CPU config (PR #80923)

2024-02-06 Thread Sam Clegg via cfe-commits

sbc100 wrote:

> Tried running Emscripten tests, and some of them fail with reference-types or 
> bulk-memory. I haven't investigated the causes yet, but it could be better to 
> start with the other two (nontrapping-fptoint and multivalue).

No need to block these on emscripten failures.. I'm sure we can find and fix 
those.   We should make this decision based on current browser stats and 
release dates I think,

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


[clang] [X86] Add missing MACROs in cpuid.h (PR #80815)

2024-02-06 Thread Freddy Ye via cfe-commits


@@ -211,7 +214,11 @@
 /* Features in %edx for leaf 7 sub-leaf 1 */
 #define bit_AVXVNNIINT8   0x0010
 #define bit_AVXNECONVERT  0x0020
+#define bit_AMXCOMPLEX0x0100
+#define bit_AVXVNNIINT16  0x0400
 #define bit_PREFETCHI 0x4000
+#define bit_USERMSR   0x8000
+#define bit_AVX10_256 0x0008

FreddyLeaf wrote:

I see. Aligned with gcc: 
[fd0c860](https://github.com/llvm/llvm-project/pull/80815/commits/fd0c860aab3c78505222c281419a366a36104e37)

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


[clang] [WebAssembly] Add more features to generic CPU config (PR #80923)

2024-02-06 Thread Heejin Ahn via cfe-commits

aheejin wrote:

Tried running Emscripten tests, and some of them fail with reference-types or 
bulk-memory. I haven't investigated the cause yet, but it could be better to 
start with the other two (nontrapping-fptoint and multivalue).

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


[clang] [Headers][X86] Editorial fixes to ia32intrin.h descriptions (PR #80490)

2024-02-06 Thread via cfe-commits

https://github.com/craigflores commented:

@pogo59 Paul, this looks good. My apologies but I saw a few other changes that 
we might ideally make. I will send you a file with my suggestions.

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


[clang] [Clang][RISCV] Add assumptions to vsetvli/vsetvlimax (PR #79975)

2024-02-06 Thread Wang Pengcheng via cfe-commits

wangpc-pp wrote:

Ping for comments.

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


[clang] [X86] Add missing MACROs in cpuid.h (PR #80815)

2024-02-06 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/80815

>From 2ed2333085d40ece903b2d70e0da7371b72209f4 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Tue, 6 Feb 2024 17:20:31 +0800
Subject: [PATCH 1/2] [X86] Add missing MACROs in cpuid.h

---
 clang/lib/Headers/cpuid.h | 9 +
 1 file changed, 9 insertions(+)

diff --git a/clang/lib/Headers/cpuid.h b/clang/lib/Headers/cpuid.h
index 1ad6853a97c9d2..1f3e28a3bfa61b 100644
--- a/clang/lib/Headers/cpuid.h
+++ b/clang/lib/Headers/cpuid.h
@@ -200,6 +200,9 @@
 #define bit_AMXINT8   0x0200
 
 /* Features in %eax for leaf 7 sub-leaf 1 */
+#define bit_SHA5120x0001
+#define bit_SM3   0x0002
+#define bit_SM4   0x0004
 #define bit_RAOINT0x0008
 #define bit_AVXVNNI   0x0010
 #define bit_AVX512BF160x0020
@@ -211,7 +214,11 @@
 /* Features in %edx for leaf 7 sub-leaf 1 */
 #define bit_AVXVNNIINT8   0x0010
 #define bit_AVXNECONVERT  0x0020
+#define bit_AMXCOMPLEX0x0100
+#define bit_AVXVNNIINT16  0x0400
 #define bit_PREFETCHI 0x4000
+#define bit_USERMSR   0x8000
+#define bit_AVX10_256 0x0008
 
 /* Features in %eax for leaf 13 sub-leaf 1 */
 #define bit_XSAVEOPT0x0001
@@ -244,6 +251,8 @@
 #define bit_RDPRU   0x0010
 #define bit_WBNOINVD0x0200
 
+/* Features in %ebx for leaf 0x24 */
+#define bit_AVX10_512   0x0004
 
 #if __i386__
 #define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) \

>From fd0c860aab3c78505222c281419a366a36104e37 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Wed, 7 Feb 2024 10:42:40 +0800
Subject: [PATCH 2/2] address comment

---
 clang/lib/Headers/cpuid.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Headers/cpuid.h b/clang/lib/Headers/cpuid.h
index 1f3e28a3bfa61b..c968d37fb8cd64 100644
--- a/clang/lib/Headers/cpuid.h
+++ b/clang/lib/Headers/cpuid.h
@@ -218,7 +218,7 @@
 #define bit_AVXVNNIINT16  0x0400
 #define bit_PREFETCHI 0x4000
 #define bit_USERMSR   0x8000
-#define bit_AVX10_256 0x0008
+#define bit_AVX10 0x0008
 
 /* Features in %eax for leaf 13 sub-leaf 1 */
 #define bit_XSAVEOPT0x0001
@@ -252,6 +252,7 @@
 #define bit_WBNOINVD0x0200
 
 /* Features in %ebx for leaf 0x24 */
+#define bit_AVX10_256   0x0002
 #define bit_AVX10_512   0x0004
 
 #if __i386__

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


[clang] [X86] Add missing MACROs in cpuid.h (PR #80815)

2024-02-06 Thread Freddy Ye via cfe-commits

FreddyLeaf wrote:

> Past the link of GCC files in description?

Done.

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


[clang] [X86] Add missing MACROs in cpuid.h (PR #80815)

2024-02-06 Thread Freddy Ye via cfe-commits

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


[clang] [WebAssembly] Add more features to generic CPU config (PR #80923)

2024-02-06 Thread Sam Clegg via cfe-commits

sbc100 wrote:

@kripken 

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


[clang] [WebAssembly] Add more features to generic CPU config (PR #80923)

2024-02-06 Thread Heejin Ahn via cfe-commits

https://github.com/aheejin updated 
https://github.com/llvm/llvm-project/pull/80923

>From d6fd48794112d6c140024d7cd55b5fe5e55e Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Tue, 6 Feb 2024 00:31:59 +
Subject: [PATCH] [WebAssembly] Add more features to generic CPU config

This enables nontrapping-fptoint, multivlaue, reference-types, and
bulk-memory in `-mcpu=generic` configuration. These proposals have been
standardized and supported in all major browsers for several years at
this point: 
https://github.com/WebAssembly/proposals/blob/main/finished-proposals.md
---
 clang/docs/ReleaseNotes.rst|  4 
 clang/lib/Basic/Targets/WebAssembly.cpp| 18 --
 clang/test/Preprocessor/wasm-target-features.c |  8 
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 802c44b6c8608..5a07dcca10687 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -259,6 +259,10 @@ AIX Support
 WebAssembly Support
 ^^^
 
+The -mcpu=generic configuration now enables nontrapping-fptoint, multivalue,
+reference-types, and bulk-memory.These proposals are standardized and available
+in all major engines.
+
 AVR Support
 ^^^
 
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index f1c925d90cb64..38fe4013090f4 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -147,19 +147,25 @@ void 
WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap ,
 bool WebAssemblyTargetInfo::initFeatureMap(
 llvm::StringMap , DiagnosticsEngine , StringRef CPU,
 const std::vector ) const {
-  if (CPU == "bleeding-edge") {
-Features["nontrapping-fptoint"] = true;
+  auto addGenericFeatures = [&]() {
 Features["sign-ext"] = true;
+Features["mutable-globals"] = true;
+Features["nontrapping-fptoint"] = true;
 Features["bulk-memory"] = true;
+Features["reference-types"] = true;
+Features["multivalue"] = true;
+  };
+  auto addBleedingEdgeFeatures = [&]() {
 Features["atomics"] = true;
-Features["mutable-globals"] = true;
 Features["tail-call"] = true;
-Features["reference-types"] = true;
 Features["multimemory"] = true;
 setSIMDLevel(Features, SIMD128, true);
+  };
+  if (CPU == "bleeding-edge") {
+addGenericFeatures();
+addBleedingEdgeFeatures();
   } else if (CPU == "generic") {
-Features["sign-ext"] = true;
-Features["mutable-globals"] = true;
+addGenericFeatures();
   }
 
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
diff --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index eccd432aa8eee..5834e6d183bc9 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -155,15 +155,15 @@
 //
 // GENERIC-DAG:#define __wasm_sign_ext__ 1{{$}}
 // GENERIC-DAG:#define __wasm_mutable_globals__ 1{{$}}
-// GENERIC-NOT:#define __wasm_nontrapping_fptoint__ 1{{$}}
-// GENERIC-NOT:#define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-DAG:#define __wasm_nontrapping_fptoint__ 1{{$}}
+// GENERIC-DAG:#define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-DAG:#define __wasm_multivalue__ 1{{$}}
+// GENERIC-DAG:#define __wasm_reference_types__ 1{{$}}
 // GENERIC-NOT:#define __wasm_simd128__ 1{{$}}
 // GENERIC-NOT:#define __wasm_atomics__ 1{{$}}
 // GENERIC-NOT:#define __wasm_tail_call__ 1{{$}}
 // GENERIC-NOT:#define __wasm_multimemory__ 1{{$}}
 // GENERIC-NOT:#define __wasm_exception_handling__ 1{{$}}
-// GENERIC-NOT:#define __wasm_multivalue__ 1{{$}}
-// GENERIC-NOT:#define __wasm_reference_types__ 1{{$}}
 // GENERIC-NOT:#define __wasm_extended_const__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \

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


[clang] [Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context (PR #80802)

2024-02-06 Thread Qizhi Hu via cfe-commits


@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -verify -std=c++20 -emit-llvm -o - %s

jcsxky wrote:

removed `-verify`

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


[clang] [Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context (PR #80802)

2024-02-06 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/80802

>From 9dbc077e263bc16ab3919b6691ee8c4585377caf Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Tue, 6 Feb 2024 14:06:40 +0800
Subject: [PATCH] [Clang][Sema] fix crash in codegen stage when an lambda
 expression declared in an unevaluated context

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  7 ---
 clang/test/CodeGen/PR76674.cpp | 11 +++
 3 files changed, 17 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/PR76674.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4d57ea4fd55b8..7ad575e4f57fa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -204,6 +204,8 @@ Bug Fixes to C++ Support
   parameter where we did an incorrect specialization of the initialization of
   the default parameter.
   Fixes (`#68490 `_)
+- Fix a crash in codegen when lambdas declared in an unevaluated context.
+  Fixes (`#76674 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d..383163ea969a9 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1613,8 +1613,8 @@ namespace {
 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
   if (T.isNull())
 return true;
-
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
+  (SemaRef.getLangOpts().CPlusPlus20 && T->isDecltypeType()))
 return false;
 
   getSema().MarkDeclarationsReferencedInType(Loc, T);
@@ -2685,7 +2685,8 @@ QualType Sema::SubstType(QualType T,
 
   // If T is not a dependent type or a variably-modified type, there
   // is nothing to do.
-  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
+  if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType() &&
+  (getLangOpts().CPlusPlus20 && !T->isDecltypeType()))
 return T;
 
   TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
diff --git a/clang/test/CodeGen/PR76674.cpp b/clang/test/CodeGen/PR76674.cpp
new file mode 100644
index 0..2ce931920afe4
--- /dev/null
+++ b/clang/test/CodeGen/PR76674.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -std=c++20 -emit-llvm -o - %s
+// expected-no-diagnostics
+
+template 
+struct A {
+template 
+using Func = decltype([] {return U{};});
+};
+
+A::Func f{};
+int i{f()};

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


[clang] [X86] Add missing MACROs in cpuid.h (PR #80815)

2024-02-06 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert commented:

Past the link of GCC files in description?

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


[clang] [Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context (PR #80802)

2024-02-06 Thread Qizhi Hu via cfe-commits


@@ -1613,8 +1613,8 @@ namespace {
 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
   if (T.isNull())
 return true;
-
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
+  (SemaRef.getLangOpts().CPlusPlus20 && T->isDecltypeType()))

jcsxky wrote:

> Can you please add the relevant standards-quote here, particularly for the 
> C++20 vs pre-C++20 change here?

Sorry, I couldn't get what you mean of  relevant standards-quote and I am not 
very familiar with cpp standards. I add `SemaRef.getLangOpts().CPlusPlus20` 
just because command args contains `-std=c++20` and clang diagnose says 'lambda 
expression in an unevaluated operand' and don't retransform `decltype` all the 
time(issue only exists in code of cpp20 and later).

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


[clang] [WebAssembly] Add more features to generic CPU config (PR #80923)

2024-02-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-webassembly

Author: Heejin Ahn (aheejin)


Changes

This enables nontrapping-fptoint, multivlaue, reference-types, and bulk-memory 
in `-mcpu=generic` configuration. These proposals have been standardized and 
supported in all major browsers for several years at this point: 
https://github.com/WebAssembly/proposals/blob/main/finished-proposals.md

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/lib/Basic/Targets/WebAssembly.cpp (+12-6) 
- (modified) clang/test/Preprocessor/wasm-target-features.c (+4-4) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 802c44b6c86080..5a07dcca106876 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -259,6 +259,10 @@ AIX Support
 WebAssembly Support
 ^^^
 
+The -mcpu=generic configuration now enables nontrapping-fptoint, multivalue,
+reference-types, and bulk-memory.These proposals are standardized and available
+in all major engines.
+
 AVR Support
 ^^^
 
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index f1c925d90cb649..38fe4013090f40 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -147,19 +147,25 @@ void 
WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap ,
 bool WebAssemblyTargetInfo::initFeatureMap(
 llvm::StringMap , DiagnosticsEngine , StringRef CPU,
 const std::vector ) const {
-  if (CPU == "bleeding-edge") {
-Features["nontrapping-fptoint"] = true;
+  auto addGenericFeatures = [&]() {
 Features["sign-ext"] = true;
+Features["mutable-globals"] = true;
+Features["nontrapping-fptoint"] = true;
 Features["bulk-memory"] = true;
+Features["reference-types"] = true;
+Features["multivalue"] = true;
+  };
+  auto addBleedingEdgeFeatures = [&]() {
 Features["atomics"] = true;
-Features["mutable-globals"] = true;
 Features["tail-call"] = true;
-Features["reference-types"] = true;
 Features["multimemory"] = true;
 setSIMDLevel(Features, SIMD128, true);
+  };
+  if (CPU == "bleeding-edge") {
+addGenericFeatures();
+addBleedingEdgeFeatures();
   } else if (CPU == "generic") {
-Features["sign-ext"] = true;
-Features["mutable-globals"] = true;
+addGenericFeatures();
   }
 
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
diff --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index eccd432aa8eee6..5834e6d183bc9c 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -155,15 +155,15 @@
 //
 // GENERIC-DAG:#define __wasm_sign_ext__ 1{{$}}
 // GENERIC-DAG:#define __wasm_mutable_globals__ 1{{$}}
-// GENERIC-NOT:#define __wasm_nontrapping_fptoint__ 1{{$}}
-// GENERIC-NOT:#define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-DAG:#define __wasm_nontrapping_fptoint__ 1{{$}}
+// GENERIC-DAG:#define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-DAG:#define __wasm_multivalue__ 1{{$}}
+// GENERIC-DAG:#define __wasm_reference_types__ 1{{$}}
 // GENERIC-NOT:#define __wasm_simd128__ 1{{$}}
 // GENERIC-NOT:#define __wasm_atomics__ 1{{$}}
 // GENERIC-NOT:#define __wasm_tail_call__ 1{{$}}
 // GENERIC-NOT:#define __wasm_multimemory__ 1{{$}}
 // GENERIC-NOT:#define __wasm_exception_handling__ 1{{$}}
-// GENERIC-NOT:#define __wasm_multivalue__ 1{{$}}
-// GENERIC-NOT:#define __wasm_reference_types__ 1{{$}}
 // GENERIC-NOT:#define __wasm_extended_const__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \

``




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


[clang] [WebAssembly] Add more features to generic CPU config (PR #80923)

2024-02-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Heejin Ahn (aheejin)


Changes

This enables nontrapping-fptoint, multivlaue, reference-types, and bulk-memory 
in `-mcpu=generic` configuration. These proposals have been standardized and 
supported in all major browsers for several years at this point: 
https://github.com/WebAssembly/proposals/blob/main/finished-proposals.md

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/lib/Basic/Targets/WebAssembly.cpp (+12-6) 
- (modified) clang/test/Preprocessor/wasm-target-features.c (+4-4) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 802c44b6c86080..5a07dcca106876 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -259,6 +259,10 @@ AIX Support
 WebAssembly Support
 ^^^
 
+The -mcpu=generic configuration now enables nontrapping-fptoint, multivalue,
+reference-types, and bulk-memory.These proposals are standardized and available
+in all major engines.
+
 AVR Support
 ^^^
 
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index f1c925d90cb649..38fe4013090f40 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -147,19 +147,25 @@ void 
WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap ,
 bool WebAssemblyTargetInfo::initFeatureMap(
 llvm::StringMap , DiagnosticsEngine , StringRef CPU,
 const std::vector ) const {
-  if (CPU == "bleeding-edge") {
-Features["nontrapping-fptoint"] = true;
+  auto addGenericFeatures = [&]() {
 Features["sign-ext"] = true;
+Features["mutable-globals"] = true;
+Features["nontrapping-fptoint"] = true;
 Features["bulk-memory"] = true;
+Features["reference-types"] = true;
+Features["multivalue"] = true;
+  };
+  auto addBleedingEdgeFeatures = [&]() {
 Features["atomics"] = true;
-Features["mutable-globals"] = true;
 Features["tail-call"] = true;
-Features["reference-types"] = true;
 Features["multimemory"] = true;
 setSIMDLevel(Features, SIMD128, true);
+  };
+  if (CPU == "bleeding-edge") {
+addGenericFeatures();
+addBleedingEdgeFeatures();
   } else if (CPU == "generic") {
-Features["sign-ext"] = true;
-Features["mutable-globals"] = true;
+addGenericFeatures();
   }
 
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
diff --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index eccd432aa8eee6..5834e6d183bc9c 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -155,15 +155,15 @@
 //
 // GENERIC-DAG:#define __wasm_sign_ext__ 1{{$}}
 // GENERIC-DAG:#define __wasm_mutable_globals__ 1{{$}}
-// GENERIC-NOT:#define __wasm_nontrapping_fptoint__ 1{{$}}
-// GENERIC-NOT:#define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-DAG:#define __wasm_nontrapping_fptoint__ 1{{$}}
+// GENERIC-DAG:#define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-DAG:#define __wasm_multivalue__ 1{{$}}
+// GENERIC-DAG:#define __wasm_reference_types__ 1{{$}}
 // GENERIC-NOT:#define __wasm_simd128__ 1{{$}}
 // GENERIC-NOT:#define __wasm_atomics__ 1{{$}}
 // GENERIC-NOT:#define __wasm_tail_call__ 1{{$}}
 // GENERIC-NOT:#define __wasm_multimemory__ 1{{$}}
 // GENERIC-NOT:#define __wasm_exception_handling__ 1{{$}}
-// GENERIC-NOT:#define __wasm_multivalue__ 1{{$}}
-// GENERIC-NOT:#define __wasm_reference_types__ 1{{$}}
 // GENERIC-NOT:#define __wasm_extended_const__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \

``




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


[clang] [WebAssembly] Add more features to generic CPU config (PR #80923)

2024-02-06 Thread Heejin Ahn via cfe-commits

https://github.com/aheejin created 
https://github.com/llvm/llvm-project/pull/80923

This enables nontrapping-fptoint, multivlaue, reference-types, and bulk-memory 
in `-mcpu=generic` configuration. These proposals have been standardized and 
supported in all major browsers for several years at this point: 
https://github.com/WebAssembly/proposals/blob/main/finished-proposals.md

>From d6fd48794112d6c140024d7cd55b5fe5e55e Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Tue, 6 Feb 2024 00:31:59 +
Subject: [PATCH] [WebAssembly] Add more features to generic CPU config

This enables nontrapping-fptoint, multivlaue, reference-types, and
bulk-memory in `-mcpu=generic` configuration. These proposals have been
standardized and supported in all major browsers for several years at
this point: 
https://github.com/WebAssembly/proposals/blob/main/finished-proposals.md
---
 clang/docs/ReleaseNotes.rst|  4 
 clang/lib/Basic/Targets/WebAssembly.cpp| 18 --
 clang/test/Preprocessor/wasm-target-features.c |  8 
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 802c44b6c86080..5a07dcca106876 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -259,6 +259,10 @@ AIX Support
 WebAssembly Support
 ^^^
 
+The -mcpu=generic configuration now enables nontrapping-fptoint, multivalue,
+reference-types, and bulk-memory.These proposals are standardized and available
+in all major engines.
+
 AVR Support
 ^^^
 
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index f1c925d90cb649..38fe4013090f40 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -147,19 +147,25 @@ void 
WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap ,
 bool WebAssemblyTargetInfo::initFeatureMap(
 llvm::StringMap , DiagnosticsEngine , StringRef CPU,
 const std::vector ) const {
-  if (CPU == "bleeding-edge") {
-Features["nontrapping-fptoint"] = true;
+  auto addGenericFeatures = [&]() {
 Features["sign-ext"] = true;
+Features["mutable-globals"] = true;
+Features["nontrapping-fptoint"] = true;
 Features["bulk-memory"] = true;
+Features["reference-types"] = true;
+Features["multivalue"] = true;
+  };
+  auto addBleedingEdgeFeatures = [&]() {
 Features["atomics"] = true;
-Features["mutable-globals"] = true;
 Features["tail-call"] = true;
-Features["reference-types"] = true;
 Features["multimemory"] = true;
 setSIMDLevel(Features, SIMD128, true);
+  };
+  if (CPU == "bleeding-edge") {
+addGenericFeatures();
+addBleedingEdgeFeatures();
   } else if (CPU == "generic") {
-Features["sign-ext"] = true;
-Features["mutable-globals"] = true;
+addGenericFeatures();
   }
 
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
diff --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index eccd432aa8eee6..5834e6d183bc9c 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -155,15 +155,15 @@
 //
 // GENERIC-DAG:#define __wasm_sign_ext__ 1{{$}}
 // GENERIC-DAG:#define __wasm_mutable_globals__ 1{{$}}
-// GENERIC-NOT:#define __wasm_nontrapping_fptoint__ 1{{$}}
-// GENERIC-NOT:#define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-DAG:#define __wasm_nontrapping_fptoint__ 1{{$}}
+// GENERIC-DAG:#define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-DAG:#define __wasm_multivalue__ 1{{$}}
+// GENERIC-DAG:#define __wasm_reference_types__ 1{{$}}
 // GENERIC-NOT:#define __wasm_simd128__ 1{{$}}
 // GENERIC-NOT:#define __wasm_atomics__ 1{{$}}
 // GENERIC-NOT:#define __wasm_tail_call__ 1{{$}}
 // GENERIC-NOT:#define __wasm_multimemory__ 1{{$}}
 // GENERIC-NOT:#define __wasm_exception_handling__ 1{{$}}
-// GENERIC-NOT:#define __wasm_multivalue__ 1{{$}}
-// GENERIC-NOT:#define __wasm_reference_types__ 1{{$}}
 // GENERIC-NOT:#define __wasm_extended_const__ 1{{$}}
 
 // RUN: %clang -E -dM %s -o - 2>&1 \

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


[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-06 Thread Yeoul Na via cfe-commits

rapidsna wrote:

FWIW, in the context of `-fbounds-safety` 
(https://github.com/llvm/llvm-project/blob/main/clang/docs/BoundsSafety.rst), I 
think the best is to have the bounds-annotated types to be part of the 
canonical type system because they affect the semantics and the codegen (again 
with `-fbounds-safety`) and the annotations should also apply to rvalues (e.g., 
function return types).

That said, sugar types happen to work fine overall because where the compiler 
is about to lose the type sugar (e.g., assigning it to a variable with type 
that doesn't have the same attribute), the model naturally prevented it by 
either emitting an error for incompatible type conversion, or promoting the 
type into a wide pointer type (i.e., `__bidi_indexable` for lvalue-to-rvalue 
conversion on `__counted_by`). That being said, we still encountered some cases 
where the type sugars are lost inconsistently due to implementation issues 
(e.g., getting unqualified type also removes the type sugar depending on the 
position it appertains to). So again, ideally, I like it to be part of the type 
system.

However, without `-fbounds-safety`, `__counted_by` is merely used as a helper 
for sanitizers and the `__builtin_dynamic_object_size`, so it would make more 
sense to be a sugar type. Then, the question is whether we want the attribute 
to be parsed different with or without `-fbounds-safety` and would that be a 
problem.

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


[clang] Add the support for calling Ref::ptr accessor. (PR #80919)

2024-02-06 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/80919

>From b117f4c8247a14a02ddb2cc89493a54a6dd3815e Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Tue, 6 Feb 2024 17:56:01 -0800
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Add the support for
 calling Ref::ptr accessor.

This accessor returns a pointer from Ref type and is therefore safe.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp |  1 +
 .../Checkers/WebKit/ref-ptr-accessor.cpp  | 86 +++
 2 files changed, 87 insertions(+)
 create mode 100644 clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index c1f180f31338c..4bc3f7a8c9c3c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -148,6 +148,7 @@ std::optional isGetterOfRefCounted(const 
CXXMethodDecl* M)
 
 if (((className == "Ref" || className == "RefPtr") &&
  methodName == "get") ||
+(className == "Ref" && methodName == "ptr") ||
 ((className == "String" || className == "AtomString" ||
   className == "AtomStringImpl" || className == "UniqueString" ||
   className == "UniqueStringImpl" || className == "Identifier") &&
diff --git a/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp 
b/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp
new file mode 100644
index 0..d3185a9f2d58a
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp
@@ -0,0 +1,86 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+template
+class Ref {
+public:
+~Ref()
+{
+if (auto* ptr = m_ptr)
+ptr->deref();
+m_ptr = nullptr;
+}
+
+Ref(T& object)
+: m_ptr()
+{
+object.ref();
+}
+
+Ref(const Ref& other)
+: m_ptr(other.ptr())
+{
+m_ptr->ref();
+}
+
+template Ref(const Ref& other)
+: m_ptr(other.ptr())
+{
+m_ptr->ref();
+}
+
+Ref(Ref&& other)
+: m_ptr(())
+{
+}
+
+template
+Ref(Ref&& other)
+: m_ptr(())
+{
+}
+
+T* operator->() const { return m_ptr; }
+T* ptr() const { return m_ptr; }
+T& get() const { return *m_ptr; }
+operator T&() const { return *m_ptr; }
+bool operator!() const { return !*m_ptr; }
+
+T& leakRef()
+{
+T& result = *m_ptr;
+m_ptr = nullptr;
+return result;
+}
+
+private:
+template friend inline Ref adoptRef(U&);
+
+enum AdoptTag { Adopt };
+Ref(T& object, AdoptTag)
+: m_ptr()
+{
+}
+
+T* m_ptr;
+};
+
+class Node {
+public:
+static Ref create();
+virtual ~Node();
+
+void ref() const;
+void deref() const;
+
+protected:
+explicit Node();
+};
+
+void someFunction(Node*);
+
+void testFunction()
+{
+Ref node = Node::create();
+someFunction(node.ptr());
+}

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


[clang] [NFC][clang][Driver] Specify options for with -save-temps= (PR #80921)

2024-02-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jacob Lambert (lamb-j)


Changes



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


1 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+3-1) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4b232b8aab722..6b13530799e10 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5392,7 +5392,9 @@ def regcall4 : Flag<["-"], "regcall4">, Group,
   MarshallingInfoFlag>;
 def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
-  HelpText<"Save intermediate compilation results.">;
+  HelpText<"Save intermediate compilation results. The  option can be set 
"
+  "to cwd for current working directory, or obj which will save temporary "
+  "files in the same directory as the final output file">;
 def save_temps : Flag<["-", "--"], "save-temps">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, FlangOption, FC1Option]>,
   Alias, AliasArgs<["cwd"]>,

``




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


[clang] [NFC][clang][Driver] Specify options for with -save-temps= (PR #80921)

2024-02-06 Thread Jacob Lambert via cfe-commits

https://github.com/lamb-j created 
https://github.com/llvm/llvm-project/pull/80921

None

>From 9f021f6d2b99ae73c47313ddc6043ab2af926f23 Mon Sep 17 00:00:00 2001
From: Jacob Lambert 
Date: Tue, 6 Feb 2024 17:57:12 -0800
Subject: [PATCH] [NFC][clang][Driver] Specify options for  with
 -save-temps=

---
 clang/include/clang/Driver/Options.td | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4b232b8aab722a..6b13530799e102 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5392,7 +5392,9 @@ def regcall4 : Flag<["-"], "regcall4">, Group,
   MarshallingInfoFlag>;
 def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
-  HelpText<"Save intermediate compilation results.">;
+  HelpText<"Save intermediate compilation results. The  option can be set 
"
+  "to cwd for current working directory, or obj which will save temporary "
+  "files in the same directory as the final output file">;
 def save_temps : Flag<["-", "--"], "save-temps">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, FlangOption, FC1Option]>,
   Alias, AliasArgs<["cwd"]>,

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


[clang] Add a new attribute value for suppressing WebKit's unsafe member variable warning (PR #70124)

2024-02-06 Thread Ryosuke Niwa via cfe-commits

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


[clang] Add the support for calling Ref::ptr accessor. (PR #80919)

2024-02-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes

This accessor returns a pointer from Ref type and is therefore safe.

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(+1) 
- (added) clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp (+86) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index c1f180f31338cb..4bc3f7a8c9c3ce 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -148,6 +148,7 @@ std::optional isGetterOfRefCounted(const 
CXXMethodDecl* M)
 
 if (((className == "Ref" || className == "RefPtr") &&
  methodName == "get") ||
+(className == "Ref" && methodName == "ptr") ||
 ((className == "String" || className == "AtomString" ||
   className == "AtomStringImpl" || className == "UniqueString" ||
   className == "UniqueStringImpl" || className == "Identifier") &&
diff --git a/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp 
b/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp
new file mode 100644
index 00..d3185a9f2d58a4
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp
@@ -0,0 +1,86 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+template
+class Ref {
+public:
+~Ref()
+{
+if (auto* ptr = m_ptr)
+ptr->deref();
+m_ptr = nullptr;
+}
+
+Ref(T& object)
+: m_ptr()
+{
+object.ref();
+}
+
+Ref(const Ref& other)
+: m_ptr(other.ptr())
+{
+m_ptr->ref();
+}
+
+template Ref(const Ref& other)
+: m_ptr(other.ptr())
+{
+m_ptr->ref();
+}
+
+Ref(Ref&& other)
+: m_ptr(())
+{
+}
+
+template
+Ref(Ref&& other)
+: m_ptr(())
+{
+}
+
+T* operator->() const { return m_ptr; }
+T* ptr() const { return m_ptr; }
+T& get() const { return *m_ptr; }
+operator T&() const { return *m_ptr; }
+bool operator!() const { return !*m_ptr; }
+
+T& leakRef()
+{
+T& result = *m_ptr;
+m_ptr = nullptr;
+return result;
+}
+
+private:
+template friend inline Ref adoptRef(U&);
+
+enum AdoptTag { Adopt };
+Ref(T& object, AdoptTag)
+: m_ptr()
+{
+}
+
+T* m_ptr;
+};
+
+class Node {
+public:
+static Ref create();
+virtual ~Node();
+
+void ref() const;
+void deref() const;
+
+protected:
+explicit Node();
+};
+
+void someFunction(Node*);
+
+void testFunction()
+{
+Ref node = Node::create();
+someFunction(node.ptr());
+}

``




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


[clang] Add the support for calling Ref::ptr accessor. (PR #80919)

2024-02-06 Thread via cfe-commits

llvmbot wrote:




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

Author: Ryosuke Niwa (rniwa)


Changes

This accessor returns a pointer from Ref type and is therefore safe.

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(+1) 
- (added) clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp (+86) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index c1f180f31338c..4bc3f7a8c9c3c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -148,6 +148,7 @@ std::optional isGetterOfRefCounted(const 
CXXMethodDecl* M)
 
 if (((className == "Ref" || className == "RefPtr") &&
  methodName == "get") ||
+(className == "Ref" && methodName == "ptr") ||
 ((className == "String" || className == "AtomString" ||
   className == "AtomStringImpl" || className == "UniqueString" ||
   className == "UniqueStringImpl" || className == "Identifier") &&
diff --git a/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp 
b/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp
new file mode 100644
index 0..d3185a9f2d58a
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp
@@ -0,0 +1,86 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+template
+class Ref {
+public:
+~Ref()
+{
+if (auto* ptr = m_ptr)
+ptr->deref();
+m_ptr = nullptr;
+}
+
+Ref(T& object)
+: m_ptr()
+{
+object.ref();
+}
+
+Ref(const Ref& other)
+: m_ptr(other.ptr())
+{
+m_ptr->ref();
+}
+
+template Ref(const Ref& other)
+: m_ptr(other.ptr())
+{
+m_ptr->ref();
+}
+
+Ref(Ref&& other)
+: m_ptr(())
+{
+}
+
+template
+Ref(Ref&& other)
+: m_ptr(())
+{
+}
+
+T* operator->() const { return m_ptr; }
+T* ptr() const { return m_ptr; }
+T& get() const { return *m_ptr; }
+operator T&() const { return *m_ptr; }
+bool operator!() const { return !*m_ptr; }
+
+T& leakRef()
+{
+T& result = *m_ptr;
+m_ptr = nullptr;
+return result;
+}
+
+private:
+template friend inline Ref adoptRef(U&);
+
+enum AdoptTag { Adopt };
+Ref(T& object, AdoptTag)
+: m_ptr()
+{
+}
+
+T* m_ptr;
+};
+
+class Node {
+public:
+static Ref create();
+virtual ~Node();
+
+void ref() const;
+void deref() const;
+
+protected:
+explicit Node();
+};
+
+void someFunction(Node*);
+
+void testFunction()
+{
+Ref node = Node::create();
+someFunction(node.ptr());
+}

``




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


[clang] Add the support for calling Ref::ptr accessor. (PR #80919)

2024-02-06 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/80919

This accessor returns a pointer from Ref type and is therefore safe.

>From 63a64cf22e5e470db3426688a2517c2fef64fd46 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Tue, 6 Feb 2024 17:56:01 -0800
Subject: [PATCH] Add the support for calling Ref::ptr accessor.

This accessor returns a pointer from Ref type and is therefore safe.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp |  1 +
 .../Checkers/WebKit/ref-ptr-accessor.cpp  | 86 +++
 2 files changed, 87 insertions(+)
 create mode 100644 clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index c1f180f31338cb..4bc3f7a8c9c3ce 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -148,6 +148,7 @@ std::optional isGetterOfRefCounted(const 
CXXMethodDecl* M)
 
 if (((className == "Ref" || className == "RefPtr") &&
  methodName == "get") ||
+(className == "Ref" && methodName == "ptr") ||
 ((className == "String" || className == "AtomString" ||
   className == "AtomStringImpl" || className == "UniqueString" ||
   className == "UniqueStringImpl" || className == "Identifier") &&
diff --git a/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp 
b/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp
new file mode 100644
index 00..d3185a9f2d58a4
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/ref-ptr-accessor.cpp
@@ -0,0 +1,86 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+template
+class Ref {
+public:
+~Ref()
+{
+if (auto* ptr = m_ptr)
+ptr->deref();
+m_ptr = nullptr;
+}
+
+Ref(T& object)
+: m_ptr()
+{
+object.ref();
+}
+
+Ref(const Ref& other)
+: m_ptr(other.ptr())
+{
+m_ptr->ref();
+}
+
+template Ref(const Ref& other)
+: m_ptr(other.ptr())
+{
+m_ptr->ref();
+}
+
+Ref(Ref&& other)
+: m_ptr(())
+{
+}
+
+template
+Ref(Ref&& other)
+: m_ptr(())
+{
+}
+
+T* operator->() const { return m_ptr; }
+T* ptr() const { return m_ptr; }
+T& get() const { return *m_ptr; }
+operator T&() const { return *m_ptr; }
+bool operator!() const { return !*m_ptr; }
+
+T& leakRef()
+{
+T& result = *m_ptr;
+m_ptr = nullptr;
+return result;
+}
+
+private:
+template friend inline Ref adoptRef(U&);
+
+enum AdoptTag { Adopt };
+Ref(T& object, AdoptTag)
+: m_ptr()
+{
+}
+
+T* m_ptr;
+};
+
+class Node {
+public:
+static Ref create();
+virtual ~Node();
+
+void ref() const;
+void deref() const;
+
+protected:
+explicit Node();
+};
+
+void someFunction(Node*);
+
+void testFunction()
+{
+Ref node = Node::create();
+someFunction(node.ptr());
+}

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


[clang] [Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context (PR #80802)

2024-02-06 Thread Qizhi Hu via cfe-commits


@@ -1613,8 +1613,8 @@ namespace {
 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
   if (T.isNull())
 return true;
-
-  if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+  if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
+  (SemaRef.getLangOpts().CPlusPlus20 && T->isDecltypeType()))

jcsxky wrote:

@cor3ntin I use this test case locally:
```cpp
A::Func f{};
```
AST looks like:
```cpp
Breakpoint 42, clang::DecltypeType::DecltypeType (this=0x39d190, E=0x39cfd0, 
underlyingType=..., can=...) at 
/home/huqizhi/Downloads/llvm-project/clang/lib/AST/Type.cpp:3797
3797  E(E), UnderlyingType(underlyingType) {}
(gdb-ChatDBG) p E->dumpColor()
CXXBindTemporaryExpr 0x39cfd0 'class A::(lambda at 
/home/huqizhi/K.cpp:18:27)' (CXXTemporary 0x39cfd0)
`-LambdaExpr 0x39cfa0 'class A::(lambda at /home/huqizhi/K.cpp:18:27)'
  |-CXXRecordDecl 0x39ca60  implicit class definition
  | |-DefinitionData lambda pass_in_registers empty standard_layout 
trivially_copyable trivial literal has_constexpr_non_copy_move_ctor 
can_const_default_init
  | | |-DefaultConstructor exists trivial constexpr needs_implicit 
defaulted_is_constexpr
  | | |-CopyConstructor simple trivial has_const_param needs_implicit 
implicit_has_const_param
  | | |-MoveConstructor exists simple trivial needs_implicit
  | | |-CopyAssignment simple trivial has_const_param needs_implicit 
implicit_has_const_param
  | | |-MoveAssignment exists simple trivial needs_implicit
  | | `-Destructor simple irrelevant trivial constexpr
  | |-CXXMethodDecl 0x39cbc8  constexpr operator() 'auto (void) const -> auto' 
implicit_instantiation inline instantiated_from 0x37cc18
  | | `-CompoundStmt 0x39cd58
  | |   `-ReturnStmt 0x39cd48
  | | `-CXXUnresolvedConstructExpr 0x39cd08 'U' 'U' list
  | |   `-InitListExpr 0x39ccc8 'void'
  | |-CXXConversionDecl 0x39cdf0  implicit constexpr operator auto (*)() 'auto 
(*(void) const noexcept)(void) -> auto' inline
  | |-CXXMethodDecl 0x39ceb0  implicit __invoke 'auto (void) -> auto' static 
inline
  | `-CXXDestructorDecl 0x39cff8  implicit referenced constexpr ~(lambda at 
/home/huqizhi/K.cpp:18:27) 'void (void) noexcept' inline default trivial
  `-CompoundStmt 0x39cd58
`-ReturnStmt 0x39cd48
  `-CXXUnresolvedConstructExpr 0x39cd08 'U' 'U' list
`-InitListExpr 0x39ccc8 'void'
```
`CXXBindTemporaryExpr` and `LambdaExpr` both are not 
`InstantiationDependentType`
```cpp
(gdb-ChatDBG) p E->isInstantiationDependent()
$306 = false
(gdb-ChatDBG) p 
((CXXBindTemporaryExpr*)E)->getSubExpr()->isInstantiationDependent()
$308 = false
```
This is because type of the lambda is not `InstantiationDependentType`:
```cpp
(gdb-ChatDBG) p 
((LambdaExpr*)(((CXXBindTemporaryExpr*)E)->getSubExpr()))->getType().dump()
RecordType 0x39cba0 'class A::(lambda at /home/huqizhi/K.cpp:18:27)'
`-CXXRecord 0x39ca60 ''
$312 = void
```
I think retransforming all the` decltype` should be right because 
retransforming should not change the result. But, this may involve some 
efficiency problem.
Since `CXXUnresolvedConstructExpr` in the lambda expression is 
`InstantiationDependentType`, Maybe visiting the lambda expression and checking 
whether it has `InstantiationDependentType` child is a better approach (I 
think, but more complex).




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


[clang] [llvm] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)

2024-02-06 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

> I see what you're saying about the metadata being incorrect; I feel like I've 
> seen it before, but can't pin it down. For the record, all the builds where 
> we saw this assertion were thin/full LTO.
> 
> I've kicked off a reduction of a large reproducer that I have to hand; I'm 
> not immensely confident that it'll complete in a reasonable timescale (i.e.: 
> days) as it's a large project being reduced. If any of the other reporters 
> have anything smaller they can reduce, that'd assist significantly.

Thanks a lot!

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


[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-06 Thread Yeoul Na via cfe-commits

rapidsna wrote:

> One possibility would be to use a type qualifier? It has basically the kind 
> of properties you want... the underlying type is > still there, and places 
> that strip qualifiers will automatically do the right thing in a lot of 
> cases. It might require a bit more > work to handle it in various places in 
> semantic analysis, though.

Thanks @efriedma-quic! We also thought about using qualifiers before but it's 
tricky because we would like the bounds annotations to be able to apply to 
function return types and parameters. WDYT?

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


[clang] [clang] Add fbasic-block-sections support for AArch64 (PR #80916)

2024-02-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Daniel Hoekwater (dhoekwater)


Changes

Basic block sections "all" doesn't work on AArch64 since branch
relaxation may create new basic blocks. However, the other basic
block section modes should work out of the box since machine function
splitting already uses the basic block sections pass.


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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+9) 
- (modified) clang/test/Driver/fbasic-block-sections.c (+4) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 13bf2421154372..4a3fe7c5148b31 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5972,6 +5972,15 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 << A->getAsString(Args) << A->getValue();
   else
 A->render(Args, CmdArgs);
+} else if (Triple.isAArch64()) {
+  // "all" is not supported on AArch64 since branch relaxation creates new
+  // basic blocks for some cross-section branches.
+  if (Val != "labels" && Val != "none" && !Val.starts_with("list="))
+D.Diag(diag::err_drv_invalid_value)
+<< A->getAsString(Args) << A->getValue();
+  else
+A->render(Args, CmdArgs);
+}
 } else if (Triple.isNVPTX()) {
   // Do not pass the option to the GPU compilation. We still want it 
enabled
   // for the host-side compilation, so seeing it here is not an error.
diff --git a/clang/test/Driver/fbasic-block-sections.c 
b/clang/test/Driver/fbasic-block-sections.c
index 24262209d1e4d5..5e701072bfc74a 100644
--- a/clang/test/Driver/fbasic-block-sections.c
+++ b/clang/test/Driver/fbasic-block-sections.c
@@ -2,6 +2,10 @@
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=all %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-ALL %s
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=labels %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=none %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NONE %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=labels %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: not %clang -### --target=aarch64 -fbasic-block-sections=all %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-ALL %s
 // RUN: not %clang -c --target=arm-unknown-linux -fbasic-block-sections=all %s 
-S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
 // RUN: %clang -### --target=arm-unknown-linux -fbasic-block-sections=all 
-fbasic-block-sections=none %s -S 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-NOOPT %s

``




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


[clang] [clang] Add fbasic-block-sections support for AArch64 (PR #80916)

2024-02-06 Thread Daniel Hoekwater via cfe-commits

https://github.com/dhoekwater created 
https://github.com/llvm/llvm-project/pull/80916

Basic block sections "all" doesn't work on AArch64 since branch
relaxation may create new basic blocks. However, the other basic
block section modes should work out of the box since machine function
splitting already uses the basic block sections pass.


>From 70ff01eb23fa1cc860d0af11f75c2067f488646d Mon Sep 17 00:00:00 2001
From: Daniel Hoekwater 
Date: Wed, 7 Feb 2024 01:03:17 +
Subject: [PATCH] [clang] Add fbasic-block-sections support for AArch64

Basic block sections "all" doesn't work on AArch64 since branch
relaxation may create new basic blocks. However, the other basic
block section modes should work out of the box since machine function
splitting already uses the basic block sections pass.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 9 +
 clang/test/Driver/fbasic-block-sections.c | 4 
 2 files changed, 13 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 13bf242115437..4a3fe7c5148b3 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5972,6 +5972,15 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 << A->getAsString(Args) << A->getValue();
   else
 A->render(Args, CmdArgs);
+} else if (Triple.isAArch64()) {
+  // "all" is not supported on AArch64 since branch relaxation creates new
+  // basic blocks for some cross-section branches.
+  if (Val != "labels" && Val != "none" && !Val.starts_with("list="))
+D.Diag(diag::err_drv_invalid_value)
+<< A->getAsString(Args) << A->getValue();
+  else
+A->render(Args, CmdArgs);
+}
 } else if (Triple.isNVPTX()) {
   // Do not pass the option to the GPU compilation. We still want it 
enabled
   // for the host-side compilation, so seeing it here is not an error.
diff --git a/clang/test/Driver/fbasic-block-sections.c 
b/clang/test/Driver/fbasic-block-sections.c
index 24262209d1e4d..5e701072bfc74 100644
--- a/clang/test/Driver/fbasic-block-sections.c
+++ b/clang/test/Driver/fbasic-block-sections.c
@@ -2,6 +2,10 @@
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=all %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-ALL %s
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=labels %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=none %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NONE %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=labels %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: not %clang -### --target=aarch64 -fbasic-block-sections=all %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-ALL %s
 // RUN: not %clang -c --target=arm-unknown-linux -fbasic-block-sections=all %s 
-S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
 // RUN: %clang -### --target=arm-unknown-linux -fbasic-block-sections=all 
-fbasic-block-sections=none %s -S 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-NOOPT %s

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


[clang] [WebAssembly] Fix CPU tests in wasm-features.c (PR #80900)

2024-02-06 Thread Heejin Ahn via cfe-commits

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


[clang] 897297e - [WebAssembly] Fix CPU tests in wasm-features.c (#80900)

2024-02-06 Thread via cfe-commits

Author: Heejin Ahn
Date: 2024-02-06T17:07:33-08:00
New Revision: 897297e8b09ed6076f5dc6883b459b209bb9e29f

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

LOG: [WebAssembly] Fix CPU tests in wasm-features.c (#80900)

The CPU tests in this file are not working as intended. Specifying
`-mcpu=[mvp|generic|bleeding-edge]` in `clang` command line does NOT add
arguments like `-target-feature`, `+feature-name`, ... to `clang-14`
command line. Specifying `-mcpu=[mvp|generic|bleeding-edge]` in `clang`
command line will just add `-target-cpu` `[mvp|generic|bleeding-edge]`
to `clang-14` command line, and individual features are added here
within `clang-14` invocation:
https://github.com/llvm/llvm-project/blob/5b780c8c6c558ec283a9eec485a4f172df0f9fe1/clang/lib/Basic/Targets/WebAssembly.cpp#L150-L163

The reason these CPU tests are passing is because they only have `-NOT`
checks, and we don't emit `-target-feature` arguments for them anyway,
the test passes, but they don't check what they are supposed to check.

This make CPU tests only check `-target-cpu` lines instead of individual
features, which will not be emitted.

Added: 


Modified: 
clang/test/Driver/wasm-features.c

Removed: 




diff  --git a/clang/test/Driver/wasm-features.c 
b/clang/test/Driver/wasm-features.c
index 4fba3da7bea267..5dae5dbc89b905 100644
--- a/clang/test/Driver/wasm-features.c
+++ b/clang/test/Driver/wasm-features.c
@@ -2,131 +2,89 @@
 
 // CHECK: "-fvisibility=hidden"
 
-// RUN: %clang --target=wasm32-unknown-unknown -### %s 2>&1 | FileCheck %s 
-check-prefix=DEFAULT
 // RUN: %clang --target=wasm32-unknown-unknown -### %s -mcpu=mvp 2>&1 | 
FileCheck %s -check-prefix=MVP
+// RUN: %clang --target=wasm32-unknown-unknown -### %s 2>&1 | FileCheck %s 
-check-prefix=GENERIC
+// RUN: %clang --target=wasm32-unknown-unknown -### %s -mcpu=generic 2>&1 | 
FileCheck %s -check-prefix=GENERIC
 // RUN: %clang --target=wasm32-unknown-unknown -### %s -mcpu=bleeding-edge 
2>&1 | FileCheck %s -check-prefix=BLEEDING-EDGE
 
+// MVP: "-target-cpu" "mvp"
+// GENERIC: "-target-cpu" "generic"
+// BLEEDING-EDGE: "-target-cpu" "bleeding-edge"
+
 // RUN: %clang --target=wasm32-unknown-unknown -### %s -mbulk-memory 2>&1 | 
FileCheck %s -check-prefix=BULK-MEMORY
 // RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-bulk-memory 2>&1 | 
FileCheck %s -check-prefix=NO-BULK-MEMORY
 
 // BULK-MEMORY: "-target-feature" "+bulk-memory"
 // NO-BULK-MEMORY: "-target-feature" "-bulk-memory"
-// DEFAULT-NOT: "-target-feature" "-bulk-memory"
-// MVP-NOT: "-target-feature" "+bulk-memory"
-// BLEEDING-EDGE-NOT: "-target-feature" "-bulk-memory"
 
 // RUN: %clang --target=wasm32-unknown-unknown -### %s -mmutable-globals 2>&1 
| FileCheck %s -check-prefix=MUTABLE-GLOBALS
 // RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-mutable-globals 
2>&1 | FileCheck %s -check-prefix=NO-MUTABLE-GLOBALS
 
 // MUTABLE-GLOBALS: "-target-feature" "+mutable-globals"
 // NO-MUTABLE-GLOBALS: "-target-feature" "-mutable-globals"
-// DEFAULT-NOT: "-target-feature" "-mutable-globals"
-// MVP-NOT: "-target-feature" "+mutable-globals"
-// BLEEDING-EDGE-NOT: "-target-feature" "-mutable-globals"
 
 // RUN: %clang --target=wasm32-unknown-unknown -### %s -msign-ext 2>&1 | 
FileCheck %s -check-prefix=SIGN-EXT
 // RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-sign-ext 2>&1 | 
FileCheck %s -check-prefix=NO-SIGN-EXT
 
 // SIGN-EXT: "-target-feature" "+sign-ext"
 // NO-SIGN-EXT: "-target-feature" "-sign-ext"
-// DEFAULT-NOT: "-target-feature" "-sign-ext"
-// MVP-NOT: "-target-feature" "+sign-ext"
-// BLEEDING-EDGE-NOT: "-target-feature" "-sign-ext"
 
 // RUN: %clang --target=wasm32-unknown-unknown -### %s -mnontrapping-fptoint 
2>&1 | FileCheck %s -check-prefix=NONTRAPPING-FPTOINT
 // RUN: %clang --target=wasm32-unknown-unknown -### %s 
-mno-nontrapping-fptoint 2>&1 | FileCheck %s 
-check-prefix=NO-NONTRAPPING-FPTOINT
 
 // NONTRAPPING-FPTOINT: "-target-feature" "+nontrapping-fptoint"
 // NO-NONTRAPPING-FPTOINT: "-target-feature" "-nontrapping-fptoint"
-// DEFAULT-NOT: "-target-feature" "-nontrapping-fptoint"
-// MVP-NOT: "-target-feature" "+nontrapping-fptoint"
-// BLEEDING-EDGE-NOT: "-target-feature" "-nontrapping-fptoint"
 
 // RUN: %clang --target=wasm32-unknown-unknown -### %s -mmultivalue 2>&1 | 
FileCheck %s -check-prefix=MULTIVALUE
 // RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-multivalue 2>&1 | 
FileCheck %s -check-prefix=NO-MULTIVALUE
 
 // MULTIVALUE: "-target-feature" "+multivalue"
 // NO-MULTIVALUE: "-target-feature" "-multivalue"
-// DEFAULT-NOT: "-target-feature" "-multivalue"
-// MVP-NOT: "-target-feature" "+multivalue"
-// GENERIC-NOT: "-target-feature" 

[clang] [WebAssembly] Add tests for generic CPU config (PR #80775)

2024-02-06 Thread Heejin Ahn via cfe-commits

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


[clang] 4476727 - [WebAssembly] Add tests for generic CPU config (#80775)

2024-02-06 Thread via cfe-commits

Author: Heejin Ahn
Date: 2024-02-06T16:58:58-08:00
New Revision: 44767278650227b30cf969170dc139197ce4338d

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

LOG: [WebAssembly] Add tests for generic CPU config (#80775)

This adds tests for `generic` cpu configuration. We had tests for `mvp`
and `bleeding-edge` configs but not `generic`.

Added: 


Modified: 
clang/test/Preprocessor/wasm-target-features.c

Removed: 




diff  --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index e50c5a4afe79c..eccd432aa8eee 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -146,6 +146,26 @@
 // MVP-NOT:#define __wasm_multimemory__
 // MVP-NOT:#define __wasm_relaxed_simd__
 
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm32-unknown-unknown -mcpu=generic \
+// RUN:   | FileCheck %s -check-prefix=GENERIC
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm64-unknown-unknown -mcpu=generic \
+// RUN:   | FileCheck %s -check-prefix=GENERIC
+//
+// GENERIC-DAG:#define __wasm_sign_ext__ 1{{$}}
+// GENERIC-DAG:#define __wasm_mutable_globals__ 1{{$}}
+// GENERIC-NOT:#define __wasm_nontrapping_fptoint__ 1{{$}}
+// GENERIC-NOT:#define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-NOT:#define __wasm_simd128__ 1{{$}}
+// GENERIC-NOT:#define __wasm_atomics__ 1{{$}}
+// GENERIC-NOT:#define __wasm_tail_call__ 1{{$}}
+// GENERIC-NOT:#define __wasm_multimemory__ 1{{$}}
+// GENERIC-NOT:#define __wasm_exception_handling__ 1{{$}}
+// GENERIC-NOT:#define __wasm_multivalue__ 1{{$}}
+// GENERIC-NOT:#define __wasm_reference_types__ 1{{$}}
+// GENERIC-NOT:#define __wasm_extended_const__ 1{{$}}
+
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge \
 // RUN:   | FileCheck %s -check-prefix=BLEEDING-EDGE



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


[clang] [clang] require template arg list after template kw (PR #80801)

2024-02-06 Thread Davis Herring via cfe-commits


@@ -1414,7 +1414,7 @@ namespace dr96 { // dr96: no
 // FIXME: This is ill-formed, because 'f' is not a template-id and does not

opensdh wrote:

Yes, P1787R6 deprecated that use case; you're supposed to just not use 
`template` there.  This is consistent with the _recommendation_ in N1528, but 
of course we now reject the premise that `template` is _needed_ for a template 
template argument.  The reasoning, if it helps, is that compilers already have 
to deal with ambiguity there:
```cpp
template void f();// #1
template void f(int=0);  // #2
template class> void f(void*=nullptr);  // #3

template void g() {
  // in C++20, [temp.res]/6 and [temp.arg.template]/1 contradict each other 
here:
  f(); // could be #1 or #3
}
template struct X {
  // OK per [temp.local]/1
  void h() {f(T());}  // could be #2 or #3
  void i() {T::template R();}  // could be anything
}
```
Accordingly, [CWG1478](https://cplusplus.github.io/CWG/issues/1478.html)'s 
question was answered in the negative, and `template` (is to be) restricted to 
the case where it influences the interpretation of a `<`.

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


[clang] [clang-format] Handle doxygen commands starting with \ (PR #80381)

2024-02-06 Thread Fernando Tagawa via cfe-commits

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


[clang] 1b03cbc - [clang-format] Handle doxygen commands starting with \ (#80381)

2024-02-06 Thread via cfe-commits

Author: Fernando Tagawa
Date: 2024-02-06T21:23:12-03:00
New Revision: 1b03cbc93989c84ad0b78c27d4427a7eaa5842f1

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

LOG: [clang-format] Handle doxygen commands starting with \ (#80381)

Fixes llvm/llvm-project#63241

Doxygen commands can start with `@` or `\`.

Added: 


Modified: 
clang/lib/Format/BreakableToken.cpp
clang/unittests/Format/FormatTestComments.cpp

Removed: 




diff  --git a/clang/lib/Format/BreakableToken.cpp 
b/clang/lib/Format/BreakableToken.cpp
index 473908e8fee3b3..75304908dc6506 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -449,11 +449,11 @@ const FormatToken ::tokenAt(unsigned 
LineIndex) const {
 
 static bool mayReflowContent(StringRef Content) {
   Content = Content.trim(Blanks);
-  // Lines starting with '@' commonly have special meaning.
+  // Lines starting with '@' or '\' commonly have special meaning.
   // Lines starting with '-', '-#', '+' or '*' are bulleted/numbered lists.
   bool hasSpecialMeaningPrefix = false;
   for (StringRef Prefix :
-   {"@", "TODO", "FIXME", "XXX", "-# ", "- ", "+ ", "* "}) {
+   {"@", "\\", "TODO", "FIXME", "XXX", "-# ", "- ", "+ ", "* "}) {
 if (Content.starts_with(Prefix)) {
   hasSpecialMeaningPrefix = true;
   break;

diff  --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index c249f4d9333fd0..d705cf34d8af02 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -1909,6 +1909,14 @@ TEST_F(FormatTestComments, ReflowsComments) {
"// @param arg",
getLLVMStyleWithColumns(20)));
 
+  // Don't reflow lines starting with '\'.
+  verifyFormat("// long long long\n"
+   "// long\n"
+   "// \\param arg",
+   "// long long long long\n"
+   "// \\param arg",
+   getLLVMStyleWithColumns(20));
+
   // Don't reflow lines starting with 'TODO'.
   EXPECT_EQ("// long long long\n"
 "// long\n"



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


[clang] Ignore assignment to Ref / RefPtr in alpha.webkit.UncountedCallArgsChecker. (PR #80810)

2024-02-06 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/80810

>From e179bbef69084caac3948977a7091332c69130f5 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Tue, 6 Feb 2024 01:13:34 -0800
Subject: [PATCH] Ignore assignment to Ref / RefPtr in
 alpha.webkit.UncountedCallArgsChecker.

---
 .../WebKit/UncountedCallArgsChecker.cpp   | 10 +++
 .../Checkers/WebKit/assignment-to-refptr.cpp  | 71 +++
 2 files changed, 81 insertions(+)
 create mode 100644 clang/test/Analysis/Checkers/WebKit/assignment-to-refptr.cpp

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 407b6ba7a76428..419140bf12b66c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -126,6 +126,16 @@ class UncountedCallArgsChecker
 // of object on LHS.
 if (auto *MemberOp = dyn_cast(CE)) {
   // Note: assignemnt to built-in type isn't derived from CallExpr.
+  if (MemberOp->getOperator() ==
+  OO_Equal) { // Ignore assignment to Ref/RefPtr.
+auto *callee = MemberOp->getDirectCallee();
+if (auto *calleeDecl = dyn_cast(callee)) {
+  if (const CXXRecordDecl *classDecl = calleeDecl->getParent()) {
+if (isRefCounted(classDecl))
+  return true;
+  }
+}
+  }
   if (MemberOp->isAssignmentOp())
 return false;
 }
diff --git a/clang/test/Analysis/Checkers/WebKit/assignment-to-refptr.cpp 
b/clang/test/Analysis/Checkers/WebKit/assignment-to-refptr.cpp
new file mode 100644
index 00..c8ad634a5493f5
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/assignment-to-refptr.cpp
@@ -0,0 +1,71 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+template
+class RefPtr {
+public:
+inline constexpr RefPtr() : m_ptr(nullptr) { }
+inline RefPtr(T* ptr)
+  : m_ptr(ptr)
+{
+if (m_ptr)
+m_ptr->ref();
+}
+
+inline RefPtr(const RefPtr& o)
+: m_ptr(o.m_ptr)
+{
+if (m_ptr)
+m_ptr->ref();
+}
+
+inline ~RefPtr()
+{
+if (m_ptr)
+m_ptr->deref();
+}
+
+inline T* operator->() const { return m_ptr; }
+explicit operator bool() const { return m_ptr; }
+  
+RefPtr& operator=(const RefPtr&);
+RefPtr& operator=(T*);
+
+private:
+T* m_ptr;
+};
+
+template
+inline RefPtr& RefPtr::operator=(const RefPtr& o)
+{
+if (m_ptr)
+m_ptr->deref();
+m_ptr = o.m_ptr;
+if (m_ptr)
+m_ptr->ref();
+return *this;
+}
+
+template
+inline RefPtr& RefPtr::operator=(T* optr)
+{
+if (m_ptr)
+m_ptr->deref();
+m_ptr = optr;
+if (m_ptr)
+m_ptr->ref();
+return *this;
+}
+
+class Node {
+public:
+Node* nextSibling() const;
+
+void ref() const;
+void deref() const;
+};
+
+static void removeDetachedChildren(Node* firstChild)
+{
+for (RefPtr child = firstChild; child; child = child->nextSibling());
+}

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


[clang] [-Wunsafe-buffer-usage] Fix debug notes for unclaimed DREs (PR #80787)

2024-02-06 Thread via cfe-commits

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


[clang] 2f49058 - [-Wunsafe-buffer-usage] Fix debug notes for unclaimed DREs (#80787)

2024-02-06 Thread via cfe-commits

Author: jkorous-apple
Date: 2024-02-06T16:19:46-08:00
New Revision: 2f490583c368627f552c71e340c39f2b55c0526c

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

LOG: [-Wunsafe-buffer-usage] Fix debug notes for unclaimed DREs (#80787)

Debug notes for unclaimed DeclRefExpr should report any DRE of an unsafe
variable that is not covered by a Fixable (i. e. fixit for the
particular AST pattern isn't implemented for whatever reason). Currently
not all unclaimed DeclRefExpr-s are reported which is a bug. The debug
notes report only those DREs where the referred VarDecl has at least one
other DeclRefExpr which is claimed (covered by a fixit). If there is an
unsafe VarDecl that has exactly one DRE and the DRE isn't claimed then
the debug note about missing fixit won't be emitted. That is because the
debug note is emitted from within a loop over set of successfully
matched FixableGadgets which by-definition is missing those DRE that are
not matched at all.

The new code simply iterates over all unsafe VarDecls and all of their
unclaimed DREs.

Added: 


Modified: 
clang/lib/Analysis/UnsafeBufferUsage.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp

Removed: 




diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 823cd2a7b99691..a6dcf16b928e26 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -2870,19 +2870,6 @@ void clang::checkUnsafeBufferUsage(const Decl *D,
 #endif
 it = FixablesForAllVars.byVar.erase(it);
   } else if (Tracker.hasUnclaimedUses(it->first)) {
-#ifndef NDEBUG
-auto AllUnclaimed = Tracker.getUnclaimedUses(it->first);
-for (auto UnclaimedDRE : AllUnclaimed) {
-std::string UnclaimedUseTrace =
-getDREAncestorString(UnclaimedDRE, D->getASTContext());
-
-Handler.addDebugNoteForVar(
-it->first, UnclaimedDRE->getBeginLoc(),
-("failed to produce fixit for '" + it->first->getNameAsString() +
- "' : has an unclaimed use\nThe unclaimed DRE trace: " +
- UnclaimedUseTrace));
-}
-#endif
 it = FixablesForAllVars.byVar.erase(it);
   } else if (it->first->isInitCapture()) {
 #ifndef NDEBUG
@@ -2892,10 +2879,30 @@ void clang::checkUnsafeBufferUsage(const Decl *D,
 "' : init capture"));
 #endif
 it = FixablesForAllVars.byVar.erase(it);
-  }else {
-  ++it;
+  } else {
+++it;
+  }
+  }
+
+#ifndef NDEBUG
+  for (const auto  : UnsafeOps.byVar) {
+const VarDecl *const UnsafeVD = it.first;
+auto UnclaimedDREs = Tracker.getUnclaimedUses(UnsafeVD);
+if (UnclaimedDREs.empty())
+  continue;
+const auto UnfixedVDName = UnsafeVD->getNameAsString();
+for (const clang::DeclRefExpr *UnclaimedDRE : UnclaimedDREs) {
+  std::string UnclaimedUseTrace =
+  getDREAncestorString(UnclaimedDRE, D->getASTContext());
+
+  Handler.addDebugNoteForVar(
+  UnsafeVD, UnclaimedDRE->getBeginLoc(),
+  ("failed to produce fixit for '" + UnfixedVDName +
+   "' : has an unclaimed use\nThe unclaimed DRE trace: " +
+   UnclaimedUseTrace));
 }
   }
+#endif
 
   // Fixpoint iteration for pointer assignments
   using DepMapTy = DenseMap>;

diff  --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp
index e08f70d97e3912..5fff0854d45467 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp
@@ -98,3 +98,10 @@ void test_struct_claim_use() {
   x[6] = 8;  // expected-warning{{unsafe buffer access}}
   x++;  // expected-warning{{unsafe pointer arithmetic}}
 }
+
+void use(int*);
+void array2d(int idx) {
+  int buffer[10][5]; // expected-warning{{'buffer' is an unsafe buffer that 
does not perform bounds checks}}
+  use(buffer[idx]);  // expected-note{{used in buffer access here}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for 'buffer' : 
has an unclaimed use}}
+}



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


[clang] [-Wunsafe-buffer-usage] Fix debug notes for unclaimed DREs (PR #80787)

2024-02-06 Thread via cfe-commits

jkorous-apple wrote:

> LGTM! I think I did something similar locally when I collected data of 
> unclaimed DREs on those big adopter projects. So I guess the data that we 
> used to find major missing patterns for fix-its is still valid.

So, on one hand it's good that the data are representative but on the other 
hand if you had discovered this before me you could have saved me some time by 
sharing the fix :)

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


[clang] [compiler-rt] [llvm] [InstrProf] Single byte counters in coverage (PR #75425)

2024-02-06 Thread Reid Kleckner via cfe-commits

https://github.com/rnk commented:

What are the next steps to work to land this? We're interested to try this out 
for Chrome!

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


[clang] [NVPTX][AMDGPU][CodeGen] Fix `local_space nullptr` handling for NVPTX and local/private `nullptr` value for AMDGPU. (PR #78759)

2024-02-06 Thread Alexander Richardson via cfe-commits


@@ -285,6 +289,20 @@ void 
NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::GlobalValue *GV,
 bool NVPTXTargetCodeGenInfo::shouldEmitStaticExternCAliases() const {
   return false;
 }
+
+llvm::Constant *
+NVPTXTargetCodeGenInfo::getNullPointer(const CodeGen::CodeGenModule ,
+   llvm::PointerType *PT,
+   QualType QT) const {
+  auto  = CGM.getContext();
+  if (PT->getAddressSpace() != Ctx.getTargetAddressSpace(LangAS::opencl_local))
+return llvm::ConstantPointerNull::get(PT);
+
+  auto NPT = llvm::PointerType::get(
+  PT->getContext(), Ctx.getTargetAddressSpace(LangAS::opencl_generic));
+  return llvm::ConstantExpr::getAddrSpaceCast(
+  llvm::ConstantPointerNull::get(NPT), PT);
+}

arichardson wrote:

As far as I can tell the reason for the AMDGPU code using an addrspacecast is 
the following comment `// Currently LLVM assumes null pointers always have 
value 0, which results in incorrectly transformed IR.` so it can't use a `null` 
literal for all ones.

Looking at the lang-ref I can't actually see anywhere that `ptr addrspace(X) 
null` is the zero value, so this should probably be clarified in the lagref: 
https://llvm.org/docs/LangRef.html#t-pointer

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


[clang] [clang] Add zero-initialization for fixed point types (PR #80781)

2024-02-06 Thread via cfe-commits

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


[clang] 42357df - [clang] Add zero-initialization for fixed point types (#80781)

2024-02-06 Thread via cfe-commits

Author: PiJoules
Date: 2024-02-06T15:57:15-08:00
New Revision: 42357df2df4977c80aba77fcab706638a121bde0

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

LOG: [clang] Add zero-initialization for fixed point types (#80781)

Added: 
clang/test/AST/fixed-point-zero-init.cpp

Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 63453890d98798..089bc2094567f7 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11427,6 +11427,10 @@ class FixedPointExprEvaluator
 return true;
   }
 
+  bool ZeroInitialization(const Expr *E) {
+return Success(0, E);
+  }
+
   
//======//
   //Visitor Methods
   
//======//

diff  --git a/clang/test/AST/fixed-point-zero-init.cpp 
b/clang/test/AST/fixed-point-zero-init.cpp
new file mode 100644
index 00..abe8aa8c396a85
--- /dev/null
+++ b/clang/test/AST/fixed-point-zero-init.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -ffixed-point %s -verify
+// expected-no-diagnostics
+
+constexpr _Accum a[2] = {};
+static_assert(a[0] == 0 && a[0] != 1);



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


[clang] [NVPTX][AMDGPU][CodeGen] Fix `local_space nullptr` handling for NVPTX and local/private `nullptr` value for AMDGPU. (PR #78759)

2024-02-06 Thread Alexander Richardson via cfe-commits


@@ -0,0 +1,122 @@
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsycl-is-device 
-disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
+void bar(int ) {}
+// CHECK-DAG: define dso_local void @[[RAW_REF:[a-zA-Z0-9_]+]](ptr noundef 
nonnull align 4 dereferenceable(4) %
+void bar2(int ) {}
+// CHECK-DAG: define dso_local void @[[RAW_REF2:[a-zA-Z0-9_]+]](ptr noundef 
nonnull align 4 dereferenceable(4) %
+void bar(__attribute__((opencl_local)) int ) {}
+// CHECK-DAG: define dso_local void @[[LOCAL_REF:[a-zA-Z0-9_]+]](ptr 
addrspace(3) noundef align 4 dereferenceable(4) %
+void foo(int *Data) {}
+// CHECK-DAG: define dso_local void @[[RAW_PTR:[a-zA-Z0-9_]+]](ptr noundef %
+void foo2(int *Data) {}
+// CHECK-DAG: define dso_local void @[[RAW_PTR2:[a-zA-Z0-9_]+]](ptr noundef %
+void foo(__attribute__((opencl_local)) int *Data) {}
+// CHECK-DAG: define dso_local void @[[LOC_PTR:[a-zA-Z0-9_]+]](ptr 
addrspace(3) noundef %
+
+template 
+void tmpl(T t);
+// See Check Lines below.
+
+void usages() {
+  __attribute__((opencl_global)) int *GLOB;
+  // CHECK-DAG: [[GLOB:%[a-zA-Z0-9]+]] = alloca ptr addrspace(1), align 8
+  __attribute__((opencl_local)) int *LOC;
+  // CHECK-DAG: [[LOC:%[a-zA-Z0-9]+]] = alloca ptr addrspace(3), align 8
+  LOC = nullptr;
+  // CHECK-DAG: store ptr addrspace(3) addrspacecast (ptr null to ptr 
addrspace(3)), ptr [[LOC]], align 8
+  GLOB = nullptr;
+  // CHECK-DAG: store ptr addrspace(1) null, ptr [[GLOB]], align 8
+  int *NoAS;
+  // CHECK-DAG: [[NoAS:%[a-zA-Z0-9]+]] = alloca ptr, align 8
+  __attribute__((opencl_private)) int *PRIV;
+  // CHECK-DAG: [[PRIV:%[a-zA-Z0-9]+]] = alloca ptr, align 8
+  __attribute__((opencl_global_device)) int *GLOBDEVICE;
+  // CHECK-DAG: [[GLOB_DEVICE:%[a-zA-Z0-9]+]] = alloca ptr addrspace(1), align 
8
+  __attribute__((opencl_global_host)) int *GLOBHOST;
+  // CHECK-DAG: [[GLOB_HOST:%[a-zA-Z0-9]+]] = alloca ptr addrspace(1), align 8
+  NoAS = (int *)GLOB;
+  // CHECK-DAG: [[GLOB_LOAD:%[a-zA-Z0-9]+]] = load ptr addrspace(1), ptr 
[[GLOB]], align 8
+  // CHECK-DAG: [[GLOB_CAST:%[a-zA-Z0-9]+]] = addrspacecast ptr addrspace(1) 
[[GLOB_LOAD]] to ptr
+  // CHECK-DAG: store ptr [[GLOB_CAST]], ptr [[NoAS]], align 8
+  NoAS = (int *)LOC;
+  // CHECK-DAG: [[LOC_LOAD:%[a-zA-Z0-9]+]] = load ptr addrspace(3), ptr 
[[LOC]], align 8
+  // CHECK-DAG: [[LOC_CAST:%[a-zA-Z0-9]+]] = addrspacecast ptr addrspace(3) 
[[LOC_LOAD]] to ptr
+  // CHECK-DAG: store ptr [[LOC_CAST]], ptr [[NoAS]], align 8
+  NoAS = (int *)PRIV;
+  // CHECK-DAG: [[LOC_LOAD:%[a-zA-Z0-9]+]] = load ptr, ptr [[PRIV]], align 8
+  // CHECK-DAG: store ptr [[LOC_LOAD]], ptr [[NoAS]], align 8
+  GLOB = (__attribute__((opencl_global)) int *)NoAS;
+  // CHECK-DAG: [[NoAS_LOAD:%[a-zA-Z0-9]+]] = load ptr, ptr [[NoAS]], align 8
+  // CHECK-DAG: [[NoAS_CAST:%[a-zA-Z0-9]+]] = addrspacecast ptr [[NoAS_LOAD]] 
to ptr addrspace(1)
+  // CHECK-DAG: store ptr addrspace(1) [[NoAS_CAST]], ptr [[GLOB]], align 8
+  LOC = (__attribute__((opencl_local)) int *)NoAS;
+  // CHECK-DAG: [[NoAS_LOAD:%[a-zA-Z0-9]+]] = load ptr, ptr [[NoAS]], align 8
+  // CHECK-DAG: [[NoAS_CAST:%[a-zA-Z0-9]+]] = addrspacecast ptr [[NoAS_LOAD]] 
to ptr addrspace(3)
+  // CHECK-DAG: store ptr addrspace(3) [[NoAS_CAST]], ptr [[LOC]], align 8
+  PRIV = (__attribute__((opencl_private)) int *)NoAS;
+  // CHECK-DAG: [[NoAS_LOAD:%[a-zA-Z0-9]+]] = load ptr, ptr [[NoAS]], align 8
+  // CHECK-DAG: store ptr [[NoAS_LOAD]], ptr [[PRIV]], align 8
+  GLOB = (__attribute__((opencl_global)) int *)GLOBDEVICE;
+  // CHECK-DAG: [[GLOBDEVICE_LOAD:%[a-zA-Z0-9]+]] = load ptr addrspace(1), ptr 
[[GLOB_DEVICE]], align 8
+  // CHECK-DAG: store ptr addrspace(1) [[GLOBDEVICE_LOAD]], ptr %GLOB, align 8
+  GLOB = (__attribute__((opencl_global)) int *)GLOBHOST;
+  // CHECK-DAG: [[GLOB_HOST_LOAD:%[a-zA-Z0-9]+]] = load ptr addrspace(1), ptr 
[[GLOB_HOST]], align 8
+  // CHECK-DAG: store ptr addrspace(1) [[GLOB_HOST_LOAD]], ptr [[GLOB]], align 
8
+  bar(*GLOB);

arichardson wrote:

Why are all these CHECK lines using CHECK-DAG? I would not expect them to be 
reordered, so `CHECK:` should work just fine?

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


[clang] [-Wunsafe-buffer-usage] Fix debug notes for unclaimed DREs (PR #80787)

2024-02-06 Thread Ziqing Luo via cfe-commits

https://github.com/ziqingluo-90 approved this pull request.

LGTM!  
I think I did something similar locally when I collected data of unclaimed DREs 
on those big adopter projects.   So I guess the data that we used to find major 
missing patterns for fix-its is still valid.

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


[clang] [clang] Add zero-initialization for fixed point types (PR #80781)

2024-02-06 Thread Fangrui Song via cfe-commits

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


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


[clang] Extend life of variables in `DiagComparison` in `ExprConstant` (PR #79522)

2024-02-06 Thread via cfe-commits

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


[clang] Extend life of variables in `DiagComparison` in `ExprConstant` (PR #79522)

2024-02-06 Thread via cfe-commits

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


[clang] [clang] Add zero-initialization for fixed point types (PR #80781)

2024-02-06 Thread via cfe-commits

https://github.com/PiJoules updated 
https://github.com/llvm/llvm-project/pull/80781

>From 3b267b1aeb49aa5ab54920da5f6a1fa7492ae88c Mon Sep 17 00:00:00 2001
From: Leonard Chan 
Date: Mon, 5 Feb 2024 17:58:08 -0800
Subject: [PATCH] [clang] Add zero-initialization for fixed point types

---
 clang/lib/AST/ExprConstant.cpp   | 4 
 clang/test/AST/fixed-point-zero-init.cpp | 5 +
 2 files changed, 9 insertions(+)
 create mode 100644 clang/test/AST/fixed-point-zero-init.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 63453890d98798..089bc2094567f7 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11427,6 +11427,10 @@ class FixedPointExprEvaluator
 return true;
   }
 
+  bool ZeroInitialization(const Expr *E) {
+return Success(0, E);
+  }
+
   
//======//
   //Visitor Methods
   
//======//
diff --git a/clang/test/AST/fixed-point-zero-init.cpp 
b/clang/test/AST/fixed-point-zero-init.cpp
new file mode 100644
index 00..abe8aa8c396a85
--- /dev/null
+++ b/clang/test/AST/fixed-point-zero-init.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -ffixed-point %s -verify
+// expected-no-diagnostics
+
+constexpr _Accum a[2] = {};
+static_assert(a[0] == 0 && a[0] != 1);

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


[clang] [Driver] Check the environment version except wasm case. (PR #80783)

2024-02-06 Thread via cfe-commits

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


[clang] fbded66 - [Driver] Check the environment version except wasm case. (#80783)

2024-02-06 Thread via cfe-commits

Author: ZijunZhaoCCK
Date: 2024-02-06T15:40:27-08:00
New Revision: fbded6663fb04d12f451c18bc8018989d2db3a87

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

LOG: [Driver] Check the environment version except wasm case. (#80783)

Add isWasm() check for here:
https://github.com/llvm/llvm-project/pull/78655#issuecomment-1928075569

Added: 
clang/test/Driver/invalid-version.cpp

Modified: 
clang/lib/Driver/Driver.cpp

Removed: 
clang/test/Driver/android-version.cpp



diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 29db9543f3655..00e14071a4afe 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1443,16 +1443,18 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   const ToolChain  = getToolChain(
   *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
 
-  // Check if the environment version is valid.
+  // Check if the environment version is valid except wasm case.
   llvm::Triple Triple = TC.getTriple();
-  StringRef TripleVersionName = Triple.getEnvironmentVersionString();
-  StringRef TripleObjectFormat =
-  Triple.getObjectFormatTypeName(Triple.getObjectFormat());
-  if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "" &&
-  TripleVersionName != TripleObjectFormat) {
-Diags.Report(diag::err_drv_triple_version_invalid)
-<< TripleVersionName << TC.getTripleString();
-ContainsError = true;
+  if (!Triple.isWasm()) {
+StringRef TripleVersionName = Triple.getEnvironmentVersionString();
+StringRef TripleObjectFormat =
+Triple.getObjectFormatTypeName(Triple.getObjectFormat());
+if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "" &&
+TripleVersionName != TripleObjectFormat) {
+  Diags.Report(diag::err_drv_triple_version_invalid)
+  << TripleVersionName << TC.getTripleString();
+  ContainsError = true;
+}
   }
 
   // Report warning when arm64EC option is overridden by specified target

diff  --git a/clang/test/Driver/android-version.cpp 
b/clang/test/Driver/invalid-version.cpp
similarity index 54%
rename from clang/test/Driver/android-version.cpp
rename to clang/test/Driver/invalid-version.cpp
index d365b701c0223..6a4702a9b66b0 100644
--- a/clang/test/Driver/android-version.cpp
+++ b/clang/test/Driver/invalid-version.cpp
@@ -14,3 +14,18 @@
 // RUN:   FileCheck --check-prefix=CHECK-TARGET %s
 
 // CHECK-TARGET: "aarch64-unknown-linux-android31"
+
+// RUN: not %clang --target=armv7-linux-gnuS -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-ERROR2 %s
+
+// CHECK-ERROR2: error: version 'S' in target triple 
'armv7-unknown-linux-gnuS' is invalid
+
+// RUN: %clang --target=wasm32-unknown-wasi-preview2 -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-WASM %s
+
+// CHECK-WASM: "-triple" "wasm32-unknown-wasi-preview2"
+
+// RUN: %clang --target=wasm32-wasi-pthread -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-WASM1 %s
+
+// CHECK-WASM1: "-triple" "wasm32-unknown-wasi-pthread"



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


[clang] [clang] Match -isysroot behaviour with system compiler on Darwin (PR #80524)

2024-02-06 Thread Louis Dionne via cfe-commits

ldionne wrote:

If we do that, we’ll just create churn. It’s a moving target.

You will « fix » upstream Clang to match « the system compiler » temporarily, 
but by doing so you’re causing the downstream Clang to ingest that change too 
via auto-merging and that means you’ll flip-flop the state of downstream. That 
is, unless we manually undo the change downstream but then upstream Clang is 
the one that will eventually need to play catch up with downstream.

IMO that’s just churn. It’s a lot easier and better to let upstream be the 
canonical version and let downstream play catch up like it normally does. It 
just sucks that it took so long for this change to make it into downstream 
clang but that’s a separate story.

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


[clang] [clang-format] Fix a regression in dumping the config (PR #80628)

2024-02-06 Thread Ben Hamilton via cfe-commits


@@ -1,5 +1,8 @@
+// RUN: clang-format -assume-filename=foo.m -dump-config | FileCheck %s

bhamiltoncx wrote:

It looks like you reverted the lit test which just runs `clang-format 
-dump-config` without any other arguments. Is that what you wanted to do?


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


[clang] Disable FTZ/DAZ when compiling shared libraries by default. (PR #80475)

2024-02-06 Thread Andy Kaylor via cfe-commits

andykaylor wrote:

> > > So, alternatively...we could just go with the simplest solution, and use 
> > > "ieee" as the default even under -ffast-math.
> 
> +1. **There hasn't been a performance reason to use FTZ/DAZ since ~2011.** 
> Maybe there's still a power benefit? But in that case you could still 
> explicitly request the flush separate from -ffast-math

I don't think this is correct. I know there have been improvements, but there 
are still cases where setting ftz can have a significant performance impact.

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


[clang] [llvm] [AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets (PR #76955)

2024-02-06 Thread Tony Tye via cfe-commits


@@ -1642,80 +1746,118 @@ The AMDGPU backend uses the following ELF header:
  ``EF_AMDGPU_FEATURE_SRAMECC_ON_V4``  0xc00 SRAMECC enabled.
   = 
===
 
+  .. table:: AMDGPU ELF Header ``e_flags`` for Code Object V6 and After
+ :name: amdgpu-elf-header-e_flags-table-v6-onwards
+
+  == 
=
+ Name Value  Description
+  == 
=
+ ``EF_AMDGPU_MACH``   0x0ff  AMDGPU processor 
selection
+ mask for
+ 
``EF_AMDGPU_MACH_xxx`` values
+ defined in
+ 
:ref:`amdgpu-ef-amdgpu-mach-table`.
+ ``EF_AMDGPU_FEATURE_XNACK_V4``   0x300  XNACK selection 
mask for
+ 
``EF_AMDGPU_FEATURE_XNACK_*_V4``
+ values.
+ ``EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4``   0x000  XNACK unsupported.
+ ``EF_AMDGPU_FEATURE_XNACK_ANY_V4``   0x100  XNACK can have 
any value.
+ ``EF_AMDGPU_FEATURE_XNACK_OFF_V4``   0x200  XNACK disabled.
+ ``EF_AMDGPU_FEATURE_XNACK_ON_V4``0x300  XNACK enabled.
+ ``EF_AMDGPU_FEATURE_SRAMECC_V4`` 0xc00  SRAMECC selection 
mask for
+ 
``EF_AMDGPU_FEATURE_SRAMECC_*_V4``
+ values.
+ ``EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4`` 0x000  SRAMECC 
unsupported.
+ ``EF_AMDGPU_FEATURE_SRAMECC_ANY_V4`` 0x400  SRAMECC can have 
any value.
+ ``EF_AMDGPU_FEATURE_SRAMECC_OFF_V4`` 0x800  SRAMECC disabled,
+ ``EF_AMDGPU_FEATURE_SRAMECC_ON_V4``  0xc00  SRAMECC enabled.
+ ``EF_AMDGPU_GENERIC_VERSION_V``   0x0100 Value between 1 
and 255 for generic code

t-tye wrote:

There needs to be a selection mask like for other fields.

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


[clang] [llvm] [AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets (PR #76955)

2024-02-06 Thread Tony Tye via cfe-commits


@@ -4135,6 +4283,33 @@ Code object V5 metadata is the same as
 
  == == = 

 
+.. _amdgpu-amdhsa-code-object-metadata-v6:
+
+Code Object V6 Metadata

+
+.. warning::
+  Code object V6 is not the default code object version emitted by this version
+  of LLVM.
+
+
+Code object V6 metadata is the same as
+:ref:`amdgpu-amdhsa-code-object-metadata-v5` with the changes defined in table
+:ref:`amdgpu-amdhsa-code-object-metadata-map-table-v6`.
+
+  .. table:: AMDHSA Code Object V6 Metadata Map Changes
+ :name: amdgpu-amdhsa-code-object-metadata-map-table-v6
+
+ = == = 
===
+ String KeyValue Type Required? Description
+ = == = 
===
+ "amdhsa.version"  sequence ofRequired  - The first integer is the 
major

t-tye wrote:

I am not sure what metadata changes would be needed to support generic code 
objects. I would not add this section.

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


[clang] [llvm] [AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets (PR #76955)

2024-02-06 Thread Tony Tye via cfe-commits


@@ -520,6 +520,102 @@ Every processor supports every OS ABI (see 
:ref:`amdgpu-os`) with the following
 
  === ===  = = 
=== === ==
 
+Generic processors allow execution of a single code objects on any of the 
processors that

t-tye wrote:

objects -> object

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


  1   2   3   4   5   6   >