[clang] 7d876c6 - [clang][Interp] Add 'Invalid' opcode and use it for throw stmts

2023-07-26 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-26T08:59:53+02:00
New Revision: 7d876c62a306fe09a69a5a923c757d2cae305d0c

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

LOG: [clang][Interp] Add 'Invalid' opcode and use it for throw stmts

We will use this opcode for conditionally executed statements that are
invalid in a constant expression.

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

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

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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index ff40fd3da13f76..bd8e3304c5893b 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -989,6 +989,14 @@ bool ByteCodeExprGen::VisitPredefinedExpr(const 
PredefinedExpr *E) {
   return this->visit(E->getFunctionName());
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXThrowExpr(const CXXThrowExpr *E) {
+  if (!this->discard(E->getSubExpr()))
+return false;
+
+  return this->emitInvalid(E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index a031aaa9fae1dd..6e29bc32ba3830 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -97,6 +97,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitTypeTraitExpr(const TypeTraitExpr *E);
   bool VisitLambdaExpr(const LambdaExpr *E);
   bool VisitPredefinedExpr(const PredefinedExpr *E);
+  bool VisitCXXThrowExpr(const CXXThrowExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index 59ef19be356a67..e5ca5c2ae4c33b 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -243,6 +243,9 @@ bool ByteCodeStmtGen::visitStmt(const Stmt *S) {
 return visitCaseStmt(cast(S));
   case Stmt::DefaultStmtClass:
 return visitDefaultStmt(cast(S));
+  case Stmt::GCCAsmStmtClass:
+  case Stmt::MSAsmStmtClass:
+return visitAsmStmt(cast(S));
   case Stmt::NullStmtClass:
 return true;
   default: {
@@ -617,6 +620,11 @@ bool ByteCodeStmtGen::visitDefaultStmt(const 
DefaultStmt *S) {
   return this->visitStmt(S->getSubStmt());
 }
 
+template 
+bool ByteCodeStmtGen::visitAsmStmt(const AsmStmt *S) {
+  return this->emitInvalid(S);
+}
+
 namespace clang {
 namespace interp {
 

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h 
b/clang/lib/AST/Interp/ByteCodeStmtGen.h
index bc50b977a6d04f..278e804a803c95 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -67,6 +67,7 @@ class ByteCodeStmtGen final : public ByteCodeExprGen 
{
   bool visitSwitchStmt(const SwitchStmt *S);
   bool visitCaseStmt(const CaseStmt *S);
   bool visitDefaultStmt(const DefaultStmt *S);
+  bool visitAsmStmt(const AsmStmt *S);
 
   bool emitLambdaStaticInvokerBody(const CXXMethodDecl *MD);
 

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 87bcf8130a73b3..8a17322ba6ca55 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1734,6 +1734,14 @@ inline bool GetFnPtr(InterpState &S, CodePtr OpPC, const 
Function *Func) {
   return true;
 }
 
+/// Just emit a diagnostic. The expression that caused emission of this
+/// op is not valid in a constant context.
+inline bool Invalid(InterpState &S, CodePtr OpPC) {
+  const SourceLocation &Loc = S.Current->getLocation(OpPC);
+  S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
+  return false;
+}
+
 
//===--===//
 // Read opcode arguments
 
//===--===//

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 28074a350d05fb..bc81dfedfc6353 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -601,3 +601,6 @@ def Dup : Opcode {
   let Types = [AllTypeClass];
   let HasGroup = 1;
 }
+
+// [] -> []
+def Invalid : Opcode {}

diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index b708f5f6a00911..46939fb6d072fa 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -325,7 +325,8 @@ namespace InitializerT

[PATCH] D150364: [clang][Interp] Add 'Invalid' opcode and use it for throw/asm stmts

2023-07-26 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7d876c62a306: [clang][Interp] Add 'Invalid' opcode 
and use it for throw stmts (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D150364?vs=521568&id=544226#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150364

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/records.cpp
  clang/test/AST/Interp/unsupported.cpp

Index: clang/test/AST/Interp/unsupported.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/unsupported.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -verify=ref %s
+
+namespace Throw {
+
+  constexpr int ConditionalThrow(bool t) {
+if (t)
+  throw 4; // expected-note {{subexpression not valid in a constant expression}} \
+   // ref-note {{subexpression not valid in a constant expression}}
+
+return 0;
+  }
+
+  static_assert(ConditionalThrow(false) == 0, "");
+  static_assert(ConditionalThrow(true) == 0, ""); // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to 'ConditionalThrow(true)'}} \
+  // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to 'ConditionalThrow(true)'}}
+
+  constexpr int Throw() { // expected-error {{never produces a constant expression}} \
+  // ref-error {{never produces a constant expression}}
+throw 5; // expected-note {{subexpression not valid in a constant expression}} \
+ // ref-note {{subexpression not valid in a constant expression}}
+return 0;
+  }
+}
+
+namespace Asm {
+  constexpr int ConditionalAsm(bool t) {
+if (t)
+  asm(""); // expected-note {{subexpression not valid in a constant expression}} \
+   // ref-note {{subexpression not valid in a constant expression}}
+
+return 0;
+  }
+  static_assert(ConditionalAsm(false) == 0, "");
+  static_assert(ConditionalAsm(true) == 0, ""); // expected-error {{not an integral constant expression}} \
+// expected-note {{in call to 'ConditionalAsm(true)'}} \
+// ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'ConditionalAsm(true)'}}
+
+
+  constexpr int Asm() { // expected-error {{never produces a constant expression}} \
+// ref-error {{never produces a constant expression}}
+__asm volatile(""); // expected-note {{subexpression not valid in a constant expression}} \
+// ref-note {{subexpression not valid in a constant expression}}
+return 0;
+  }
+}
Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -325,7 +325,8 @@
   struct S {
 constexpr S() {}
 constexpr ~S() noexcept(false) { throw 12; } // expected-error {{cannot use 'throw'}} \
- // expected-note {{declared here}} \
+ // expected-error {{never produces a constant expression}} \
+ // expected-note 2{{subexpression not valid}} \
  // ref-error {{cannot use 'throw'}} \
  // ref-error {{never produces a constant expression}} \
  // ref-note 2{{subexpression not valid}}
@@ -333,7 +334,8 @@
 
   constexpr int f() {
 S{}; // ref-note {{in call to 'S{}.~S()'}}
-return 12; // expected-note {{undefined function '~S'}}
+/// FIXME: Wrong source location below.
+return 12; // expected-note {{in call to '&S{}->~S()'}}
   }
   static_assert(f() == 12); // expected-error {{not an integral constant expression}} \
 // expected-note {{in call to 'f()'}} \
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -601,3 +601,6 @@
   let Types = [AllTypeClass];
   let HasGroup = 1;
 }
+
+// [] -> []
+def Invalid : Opcode {}

[clang] 3b48613 - [docs] [C++20] [Modules] Mark the compatiblity issue within clang-cl.exe

2023-07-26 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-07-26T15:06:13+08:00
New Revision: 3b48613f2d90bde544669437c20fcdeb01316411

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

LOG: [docs] [C++20] [Modules] Mark the compatiblity issue within clang-cl.exe

See
https://discourse.llvm.org/t/clang-cl-exe-support-for-c-modules/72257
for details. Simply, the user of clang-cl.exe can't get a good
experience with C++20 modules now. While we don't have resources to
support it well now, we should make it clear in the documentation.

Added: 


Modified: 
clang/docs/StandardCPlusPlusModules.rst

Removed: 




diff  --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index 51f67318501153..06609063c61c96 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -688,6 +688,14 @@ Currently, clang requires the file name of an ``importable 
module unit`` should
 
 This is tracked in: https://github.com/llvm/llvm-project/issues/57416
 
+clang-cl is not compatible with the standard C++ modules
+
+
+Now we can't use the `/clang:-fmodule-file` or `/clang:-fprebuilt-module-path` 
to specify
+the BMI within ``clang-cl.exe``.
+
+This is tracked in: https://github.com/llvm/llvm-project/issues/64118
+
 Header Units
 
 



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


[PATCH] D152793: [RISCV] Add MC layer support for Zicfiss.

2023-07-26 Thread Yeting Kuo via Phabricator via cfe-commits
fakepaper56 updated this revision to Diff 544228.
fakepaper56 added a comment.

Address Craig's comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152793

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
  llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
  llvm/lib/Target/RISCV/RISCVRegisterInfo.td
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/zicfiss-invalid.s
  llvm/test/MC/RISCV/zicfiss-valid.s

Index: llvm/test/MC/RISCV/zicfiss-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/zicfiss-valid.s
@@ -0,0 +1,110 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zicfiss,+c -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zicfiss,+c -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zicfiss,+c < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zicfiss -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zicfiss,+c < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zicfiss -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv32 -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv64 -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+# CHECK-ASM-AND-OBJ: ssload x1
+# CHECK-ASM: encoding: [0xf3,0x40,0xc0,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+ssload x1
+
+# CHECK-ASM-AND-OBJ: ssload x1
+# CHECK-ASM: encoding: [0xf3,0x40,0xc0,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+ssload ra
+
+# CHECK-ASM-AND-OBJ: ssload x5
+# CHECK-ASM: encoding: [0xf3,0x42,0xc0,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+ssload x5
+
+# CHECK-ASM-AND-OBJ: ssload x5
+# CHECK-ASM: encoding: [0xf3,0x42,0xc0,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+ssload t0
+
+# CHECK-ASM-AND-OBJ: sspopchk x1
+# CHECK-ASM: encoding: [0x73,0xc0,0xc0,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+sspopchk x1
+
+# CHECK-ASM-AND-OBJ: sspopchk x1
+# CHECK-ASM: encoding: [0x73,0xc0,0xc0,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+sspopchk ra
+
+# CHECK-ASM-AND-OBJ: sspopchk x5
+# CHECK-ASM: encoding: [0x73,0xc0,0xc2,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+sspopchk x5
+
+# CHECK-ASM-AND-OBJ: sspopchk x5
+# CHECK-ASM: encoding: [0x73,0xc0,0xc2,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+sspopchk t0
+
+# CHECK-ASM-AND-OBJ: sspinc 4
+# CHECK-ASM: encoding: [0x73,0x40,0xd2,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+sspinc 4
+
+# CHECK-ASM-AND-OBJ: sspush ra
+# CHECK-ASM: encoding: [0x73,0x40,0x10,0x8a]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+sspush x1
+
+# CHECK-ASM-AND-OBJ: sspush ra
+# CHECK-ASM: encoding: [0x73,0x40,0x10,0x8a]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+sspush ra
+
+# check-asm-and-obj: sspush t0
+# check-asm: encoding: [0x73,0x40,0x50,0x8a]
+# check-no-ext: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+sspush x5
+
+# check-asm-and-obj: sspush t0
+# check-asm: encoding: [0x73,0x40,0x50,0x8a]
+# check-no-ext: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+sspush t0
+
+# CHECK-ASM-AND-OBJ: ssprr ra
+# CHECK-ASM: encoding: [0xf3,0x40,0x00,0x86]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+ssprr ra
+
+# CHECK-ASM-AND-OBJ: ssamoswap t0, zero, (a0)
+# CHECK-ASM: encoding: [0xf3,0x42,0x05,0x82]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack)
+ssamoswap t0, x0, (a0)
+
+# CHECK-ASM-AND-OBJ: c.sspush x1
+# CHECK-ASM: encoding: [0x81,0x60]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions), 'Zicfiss' (Shadow stack)
+c.sspush x1
+
+# CHECK-ASM-AND-

[clang] 7a3ad8e - [clang] Provide source range to 'invalid subexpr in const expr' diags

2023-07-26 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-26T09:12:11+02:00
New Revision: 7a3ad8ed77eef2e9ac218dd5161dda5fab1238b6

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

LOG: [clang] Provide source range to 'invalid subexpr in const expr' diags

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

Added: 
clang/test/Misc/constexpr-source-ranges.cpp

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

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1c842e261993d..755e71f6011d6c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -5227,7 +5227,7 @@ static EvalStmtResult EvaluateStmt(StmtResult &Result, 
EvalInfo &Info,
   return ESR_Succeeded;
 }
 
-Info.FFDiag(S->getBeginLoc());
+Info.FFDiag(S->getBeginLoc()) << S->getSourceRange();
 return ESR_Failed;
 
   case Stmt::NullStmtClass:
@@ -7454,7 +7454,7 @@ class ExprEvaluatorBase
   /// Report an evaluation error. This should only be called when an error is
   /// first discovered. When propagating an error, just return false.
   bool Error(const Expr *E, diag::kind D) {
-Info.FFDiag(E, D);
+Info.FFDiag(E, D) << E->getSourceRange();
 return false;
   }
   bool Error(const Expr *E) {

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 8a17322ba6ca55..e0cbf56e196958 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1738,7 +1738,8 @@ inline bool GetFnPtr(InterpState &S, CodePtr OpPC, const 
Function *Func) {
 /// op is not valid in a constant context.
 inline bool Invalid(InterpState &S, CodePtr OpPC) {
   const SourceLocation &Loc = S.Current->getLocation(OpPC);
-  S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
+  S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr)
+  << S.Current->getRange(OpPC);
   return false;
 }
 

diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index 2229aa7c08f6b2..23a98543bdc3f8 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -229,3 +229,6 @@ SourceLocation InterpFrame::getLocation(CodePtr PC) const {
   return S.getLocation(Func, PC);
 }
 
+SourceRange InterpFrame::getRange(CodePtr PC) const {
+  return S.getRange(Func, PC);
+}

diff  --git a/clang/lib/AST/Interp/InterpFrame.h 
b/clang/lib/AST/Interp/InterpFrame.h
index ce58fb8d3f84eb..c2bce93a1e8f66 100644
--- a/clang/lib/AST/Interp/InterpFrame.h
+++ b/clang/lib/AST/Interp/InterpFrame.h
@@ -118,6 +118,7 @@ class InterpFrame final : public Frame {
   virtual SourceInfo getSource(CodePtr PC) const;
   const Expr *getExpr(CodePtr PC) const;
   SourceLocation getLocation(CodePtr PC) const;
+  SourceRange getRange(CodePtr PC) const;
 
   unsigned getDepth() const { return Depth; }
 

diff  --git a/clang/lib/AST/Interp/Source.cpp b/clang/lib/AST/Interp/Source.cpp
index 467cde116843c6..4e032c92d26df1 100644
--- a/clang/lib/AST/Interp/Source.cpp
+++ b/clang/lib/AST/Interp/Source.cpp
@@ -22,6 +22,16 @@ SourceLocation SourceInfo::getLoc() const {
   return SourceLocation();
 }
 
+SourceRange SourceInfo::getRange() const {
+  if (const Expr *E = asExpr())
+return E->getSourceRange();
+  if (const Stmt *S = asStmt())
+return S->getSourceRange();
+  if (const Decl *D = asDecl())
+return D->getSourceRange();
+  return SourceRange();
+}
+
 const Expr *SourceInfo::asExpr() const {
   if (auto *S = Source.dyn_cast())
 return dyn_cast(S);
@@ -37,3 +47,7 @@ const Expr *SourceMapper::getExpr(const Function *F, CodePtr 
PC) const {
 SourceLocation SourceMapper::getLocation(const Function *F, CodePtr PC) const {
   return getSource(F, PC).getLoc();
 }
+
+SourceRange SourceMapper::getRange(const Function *F, CodePtr PC) const {
+  return getSource(F, PC).getRange();
+}

diff  --git a/clang/lib/AST/Interp/Source.h b/clang/lib/AST/Interp/Source.h
index 89fca9ac80f289..6ffc7763587747 100644
--- a/clang/lib/AST/Interp/Source.h
+++ b/clang/lib/AST/Interp/Source.h
@@ -71,6 +71,7 @@ class SourceInfo final {
   SourceInfo(const Decl *D) : Source(D) {}
 
   SourceLocation getLoc() const;
+  SourceRange getRange() const;
 
   const Stmt *asStmt() const { return Source.dyn_cast(); }
   const Decl *asDecl() const { return Source.dyn_cast(); }
@@ -96,6 +97,7 @@ class SourceMapper {
   const Expr *getExpr(const Function *F, CodePtr PC) const;
   /// Returns the location from which an opcode originates.
   SourceLocation getLocation(const Function *F, CodePtr PC) const;
+  SourceRange getRange(const Function *F, CodePtr PC) const;
 }

[PATCH] D150566: [clang] Provide source range to 'invalid subexpr in const expr' diags

2023-07-26 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7a3ad8ed77ee: [clang] Provide source range to 'invalid 
subexpr in const expr' diags (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150566

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/lib/AST/Interp/InterpFrame.h
  clang/lib/AST/Interp/Source.cpp
  clang/lib/AST/Interp/Source.h
  clang/test/Misc/constexpr-source-ranges.cpp

Index: clang/test/Misc/constexpr-source-ranges.cpp
===
--- /dev/null
+++ clang/test/Misc/constexpr-source-ranges.cpp
@@ -0,0 +1,9 @@
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info -fcxx-exceptions %s 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -fsyntax-only -fexperimental-new-constant-interpreter -fdiagnostics-print-source-range-info -fcxx-exceptions %s 2>&1 | FileCheck %s
+
+constexpr int f() {
+  throw 1;
+  return 0;
+}
+
+// CHECK: constexpr-source-ranges.cpp:5:3:{5:3-5:10}
Index: clang/lib/AST/Interp/Source.h
===
--- clang/lib/AST/Interp/Source.h
+++ clang/lib/AST/Interp/Source.h
@@ -71,6 +71,7 @@
   SourceInfo(const Decl *D) : Source(D) {}
 
   SourceLocation getLoc() const;
+  SourceRange getRange() const;
 
   const Stmt *asStmt() const { return Source.dyn_cast(); }
   const Decl *asDecl() const { return Source.dyn_cast(); }
@@ -96,6 +97,7 @@
   const Expr *getExpr(const Function *F, CodePtr PC) const;
   /// Returns the location from which an opcode originates.
   SourceLocation getLocation(const Function *F, CodePtr PC) const;
+  SourceRange getRange(const Function *F, CodePtr PC) const;
 };
 
 } // namespace interp
Index: clang/lib/AST/Interp/Source.cpp
===
--- clang/lib/AST/Interp/Source.cpp
+++ clang/lib/AST/Interp/Source.cpp
@@ -22,6 +22,16 @@
   return SourceLocation();
 }
 
+SourceRange SourceInfo::getRange() const {
+  if (const Expr *E = asExpr())
+return E->getSourceRange();
+  if (const Stmt *S = asStmt())
+return S->getSourceRange();
+  if (const Decl *D = asDecl())
+return D->getSourceRange();
+  return SourceRange();
+}
+
 const Expr *SourceInfo::asExpr() const {
   if (auto *S = Source.dyn_cast())
 return dyn_cast(S);
@@ -37,3 +47,7 @@
 SourceLocation SourceMapper::getLocation(const Function *F, CodePtr PC) const {
   return getSource(F, PC).getLoc();
 }
+
+SourceRange SourceMapper::getRange(const Function *F, CodePtr PC) const {
+  return getSource(F, PC).getRange();
+}
Index: clang/lib/AST/Interp/InterpFrame.h
===
--- clang/lib/AST/Interp/InterpFrame.h
+++ clang/lib/AST/Interp/InterpFrame.h
@@ -118,6 +118,7 @@
   virtual SourceInfo getSource(CodePtr PC) const;
   const Expr *getExpr(CodePtr PC) const;
   SourceLocation getLocation(CodePtr PC) const;
+  SourceRange getRange(CodePtr PC) const;
 
   unsigned getDepth() const { return Depth; }
 
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -229,3 +229,6 @@
   return S.getLocation(Func, PC);
 }
 
+SourceRange InterpFrame::getRange(CodePtr PC) const {
+  return S.getRange(Func, PC);
+}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1738,7 +1738,8 @@
 /// op is not valid in a constant context.
 inline bool Invalid(InterpState &S, CodePtr OpPC) {
   const SourceLocation &Loc = S.Current->getLocation(OpPC);
-  S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
+  S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr)
+  << S.Current->getRange(OpPC);
   return false;
 }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -5227,7 +5227,7 @@
   return ESR_Succeeded;
 }
 
-Info.FFDiag(S->getBeginLoc());
+Info.FFDiag(S->getBeginLoc()) << S->getSourceRange();
 return ESR_Failed;
 
   case Stmt::NullStmtClass:
@@ -7454,7 +7454,7 @@
   /// Report an evaluation error. This should only be called when an error is
   /// first discovered. When propagating an error, just return false.
   bool Error(const Expr *E, diag::kind D) {
-Info.FFDiag(E, D);
+Info.FFDiag(E, D) << E->getSourceRange();
 return false;
   }
   bool Error(const Expr *E) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-

[clang] 907fb33 - [Clang][AArch64] Fix up immediate range of f64f64 mopa/mops intrinsics

2023-07-26 Thread Sander de Smalen via cfe-commits

Author: Sander de Smalen
Date: 2023-07-26T07:13:18Z
New Revision: 907fb338a2df8fe0f41ddace487b05661ecdc6aa

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

LOG: [Clang][AArch64] Fix up immediate range of f64f64 mopa/mops intrinsics

Reviewed By: bryanpkc

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

Added: 


Modified: 
clang/include/clang/Basic/arm_sme.td
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c
clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b950f5cb8acc20..f747ccde38a3a1 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -251,7 +251,7 @@ multiclass ZAFPOuterProd {
 def NAME # _ZA64_D: SInst<"sv" # n_suffix # "_za64[_{d}]", "viPPdd", "d",
   MergeOp1, "aarch64_sme_" # n_suffix,
   [IsStreaming, IsSharedZA],
-  [ImmCheck<0, ImmCheck0_3>]>;
+  [ImmCheck<0, ImmCheck0_7>]>;
   }
 }
 

diff  --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c
index 6925a450ba386f..835d7c75ba6eac 100644
--- a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c
@@ -18,11 +18,11 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PN:%.*]])
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PM:%.*]])
-// CHECK-NEXT:tail call void @llvm.aarch64.sme.smopa.wide.nxv8i16(i32 1, 
 [[TMP0]],  [[TMP1]],  
[[ZN:%.*]],  [[ZM:%.*]])
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.smopa.wide.nxv8i16(i32 7, 
 [[TMP0]],  [[TMP1]],  
[[ZN:%.*]],  [[ZM:%.*]])
 // CHECK-NEXT:ret void
 //
 void test_svmopa_za64_s16(svbool_t pn, svbool_t pm, svint16_t zn, svint16_t 
zm) {
-  SME_ACLE_FUNC(svmopa_za64, _s16, _m)(1, pn, pm, zn, zm);
+  SME_ACLE_FUNC(svmopa_za64, _s16, _m)(7, pn, pm, zn, zm);
 }
 
 // CHECK-C-LABEL: @test_svmopa_za64_u16(
@@ -42,11 +42,11 @@ void test_svmopa_za64_u16(svbool_t pn, svbool_t pm, 
svuint16_t zn, svuint16_t zm
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[PN:%.*]])
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[PM:%.*]])
-// CHECK-NEXT:tail call void @llvm.aarch64.sme.mopa.nxv2f64(i32 1,  [[TMP0]],  [[TMP1]],  
[[ZN:%.*]],  [[ZM:%.*]])
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.mopa.nxv2f64(i32 7,  [[TMP0]],  [[TMP1]],  
[[ZN:%.*]],  [[ZM:%.*]])
 // CHECK-NEXT:ret void
 //
 void test_svmopa_za64_f64(svbool_t pn, svbool_t pm, svfloat64_t zn, 
svfloat64_t zm) {
-  SME_ACLE_FUNC(svmopa_za64, _f64, _m)(1, pn, pm, zn, zm);
+  SME_ACLE_FUNC(svmopa_za64, _f64, _m)(7, pn, pm, zn, zm);
 }
 
 // CHECK-C-LABEL: @test_svsumopa_za64_s16(
@@ -66,9 +66,9 @@ void test_svsumopa_za64_s16(svbool_t pn, svbool_t pm, 
svint16_t zn, svuint16_t z
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PN:%.*]])
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PM:%.*]])
-// CHECK-NEXT:tail call void @llvm.aarch64.sme.usmopa.wide.nxv8i16(i32 2, 
 [[TMP0]],  [[TMP1]],  
[[ZN:%.*]],  [[ZM:%.*]])
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.usmopa.wide.nxv8i16(i32 7, 
 [[TMP0]],  [[TMP1]],  
[[ZN:%.*]],  [[ZM:%.*]])
 // CHECK-NEXT:ret void
 //
 void test_svusmopa_za64_u16(svbool_t pn, svbool_t pm, svuint16_t zn, svint16_t 
zm) {
-  SME_ACLE_FUNC(svusmopa_za64, _u16, _m)(2, pn, pm, zn, zm);
+  SME_ACLE_FUNC(svusmopa_za64, _u16, _m)(7, pn, pm, zn, zm);
 }

diff  --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c
index 447bca055ad422..ea1e55001b654c 100644
--- a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c
@@ -18,11 +18,11 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PN:%.*]])
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PM:%.*]])
-// CHECK-NEXT:tail call void @llvm.aarch64.sme.smops.wide.nxv8i16(i32 1, 
 [[TMP0]],  [[TMP1]],  
[[ZN:%.*]],  [[ZM:%.*]])
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.smops.

[PATCH] D156128: [Clang][AArch64] Fix up immediate range of f64f64 mopa/mops intrinsics

2023-07-26 Thread Sander de Smalen via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG907fb338a2df: [Clang][AArch64] Fix up immediate range of 
f64f64 mopa/mops intrinsics (authored by sdesmalen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156128

Files:
  clang/include/clang/Basic/arm_sme.td
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c
  clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Index: clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
===
--- clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
+++ clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
@@ -190,6 +190,11 @@
   SVE_ACLE_FUNC(svusmopa_za64, _u16, _m,)(8, pg, pg, svundef_u16(), svundef_s16());
   // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 7]}}
   SVE_ACLE_FUNC(svusmops_za64, _u16, _m,)(-1, pg, pg, svundef_u16(), svundef_s16());
+
+  // expected-error@+1 {{argument value 8 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svmopa_za64, _f64, _m,)(8, pg, pg, svundef_f64(), svundef_f64());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svmops_za64, _f64, _m,)(-1, pg, pg, svundef_f64(), svundef_f64());
 }
 
 void test_range_0_15(svbool_t pg, void *ptr) {
Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c
===
--- clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c
@@ -18,11 +18,11 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PN:%.*]])
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PM:%.*]])
-// CHECK-NEXT:tail call void @llvm.aarch64.sme.smops.wide.nxv8i16(i32 1,  [[TMP0]],  [[TMP1]],  [[ZN:%.*]],  [[ZM:%.*]])
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.smops.wide.nxv8i16(i32 7,  [[TMP0]],  [[TMP1]],  [[ZN:%.*]],  [[ZM:%.*]])
 // CHECK-NEXT:ret void
 //
 void test_svmops_za64_s16(svbool_t pn, svbool_t pm, svint16_t zn, svint16_t zm) {
-  SME_ACLE_FUNC(svmops_za64, _s16, _m)(1, pn, pm, zn, zm);
+  SME_ACLE_FUNC(svmops_za64, _s16, _m)(7, pn, pm, zn, zm);
 }
 
 // CHECK-C-LABEL: @test_svmops_za64_u16(
@@ -42,11 +42,11 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[PN:%.*]])
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[PM:%.*]])
-// CHECK-NEXT:tail call void @llvm.aarch64.sme.mops.nxv2f64(i32 1,  [[TMP0]],  [[TMP1]],  [[ZN:%.*]],  [[ZM:%.*]])
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.mops.nxv2f64(i32 7,  [[TMP0]],  [[TMP1]],  [[ZN:%.*]],  [[ZM:%.*]])
 // CHECK-NEXT:ret void
 //
 void test_svmops_za64_f64(svbool_t pn, svbool_t pm, svfloat64_t zn, svfloat64_t zm) {
-  SME_ACLE_FUNC(svmops_za64, _f64, _m)(1, pn, pm, zn, zm);
+  SME_ACLE_FUNC(svmops_za64, _f64, _m)(7, pn, pm, zn, zm);
 }
 
 // CHECK-C-LABEL: @test_svsumops_za64_s16(
@@ -66,9 +66,9 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PN:%.*]])
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PM:%.*]])
-// CHECK-NEXT:tail call void @llvm.aarch64.sme.usmops.wide.nxv8i16(i32 2,  [[TMP0]],  [[TMP1]],  [[ZN:%.*]],  [[ZM:%.*]])
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.usmops.wide.nxv8i16(i32 7,  [[TMP0]],  [[TMP1]],  [[ZN:%.*]],  [[ZM:%.*]])
 // CHECK-NEXT:ret void
 //
 void test_svusmops_za64_u16(svbool_t pn, svbool_t pm, svuint16_t zn, svint16_t zm) {
-  SME_ACLE_FUNC(svusmops_za64, _u16, _m)(2, pn, pm, zn, zm);
+  SME_ACLE_FUNC(svusmops_za64, _u16, _m)(7, pn, pm, zn, zm);
 }
Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c
===
--- clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c
@@ -18,11 +18,11 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PN:%.*]])
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PM:%.*]])
-// CHECK-NEXT:tail call void @llvm.aarch64.sme.smopa.wide.nxv8i16(i32 1,  [[TMP0]],  [[TMP1]],  [[ZN:%.*]],  [[ZM:%.*]])
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.smopa.wide.nxv8i16(i32 7,  [[TMP0]],  [[TMP1]],  [[ZN:%.*]],  [[ZM:%.*]])
 // CHECK-NEXT:ret void
 //
 void test_svmopa_za64_s16(svbool_t 

[PATCH] D153914: [clang-cl] Enable concatenation of predefined identifiers

2023-07-26 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt updated this revision to Diff 544235.
RIscRIpt marked an inline comment as done.
RIscRIpt added a comment.

Rename MicrosoftStringLiteralFromPredefined


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153914

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/ms_predefined_expr.cpp
  clang/test/Sema/ms_wide_predefined_expr.cpp

Index: clang/test/Sema/ms_wide_predefined_expr.cpp
===
--- clang/test/Sema/ms_wide_predefined_expr.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions
-// expected-no-diagnostics
-
-// Wide character predefined identifiers
-#define _STR2WSTR(str) L##str
-#define STR2WSTR(str) _STR2WSTR(str)
-void abcdefghi12(void) {
- const wchar_t (*ss)[12] = &STR2WSTR(__FUNCTION__);
- static int arr[sizeof(STR2WSTR(__FUNCTION__))==12*sizeof(wchar_t) ? 1 : -1];
- const wchar_t (*ss2)[31] = &STR2WSTR(__FUNCSIG__);
- static int arr2[sizeof(STR2WSTR(__FUNCSIG__))==31*sizeof(wchar_t) ? 1 : -1];
-}
-
-namespace PR13206 {
-void foo(const wchar_t *);
-
-template class A {
-public:
- void method() {
-  foo(L__FUNCTION__);
- }
-};
-
-void bar() {
- A x;
- x.method();
-}
-}
Index: clang/test/Sema/ms_predefined_expr.cpp
===
--- clang/test/Sema/ms_predefined_expr.cpp
+++ clang/test/Sema/ms_predefined_expr.cpp
@@ -1,9 +1,170 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
 
-void f() {
+using size_t = __SIZE_TYPE__;
+
+// Test array initialization
+void array_init() {
  const char a[] = __FUNCTION__; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
  const char b[] = __FUNCDNAME__; // expected-warning{{initializing an array from a '__FUNCDNAME__' predefined identifier is a Microsoft extension}}
  const char c[] = __FUNCSIG__; // expected-warning{{initializing an array from a '__FUNCSIG__' predefined identifier is a Microsoft extension}}
  const char d[] = __func__; // expected-warning{{initializing an array from a '__func__' predefined identifier is a Microsoft extension}}
  const char e[] = __PRETTY_FUNCTION__; // expected-warning{{initializing an array from a '__PRETTY_FUNCTION__' predefined identifier is a Microsoft extension}}
+ const wchar_t f[] = L__FUNCTION__; // expected-warning{{initializing an array from a 'L__FUNCTION__' predefined identifier is a Microsoft extension}}
+ const wchar_t g[] = L__FUNCSIG__; // expected-warning{{initializing an array from a 'L__FUNCSIG__' predefined identifier is a Microsoft extension}}
+}
+
+// Test function local identifiers outside of a function
+const char* g_function = __FUNCTION__;// expected-warning{{predefined identifier is only valid inside function}}
+const char* g_function_lconcat = "" __FUNCTION__; // expected-warning{{predefined identifier is only valid inside function}} \
+  // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+const char* g_function_rconcat = __FUNCTION__ ""; // expected-warning{{predefined identifier is only valid inside function}} \
+  // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+
+namespace NS
+{
+  const char* function = __FUNCTION__;// expected-warning{{predefined identifier is only valid inside function}}
+  const char* function_lconcat = "" __FUNCTION__; // expected-warning{{predefined identifier is only valid inside function}} \
+  // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+  const char* function_rconcat = __FUNCTION__ ""; // expected-warning{{predefined identifier is only valid inside function}} \
+  // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+
+  struct S
+  {
+static constexpr const char* function = __FUNCTION__;// expected-warning{{predefined identifier is only valid inside function}}
+static constexpr const char* function_lconcat = "" __FUNCTION__; // expected-warning{{predefined identifier is only valid inside function}} \
+ // expected-warning{{expansion of p

[PATCH] D153914: [clang-cl] Enable concatenation of predefined identifiers

2023-07-26 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt added a comment.

Thank you for the review! I apologize for missing the small details; I should 
have noticed and addressed them myself.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153914

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


[PATCH] D156223: [RISCV] Resolve a few bugs in RISCVVIntrinsicUtils.cpp

2023-07-26 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD added inline comments.



Comment at: clang/lib/Sema/SemaRISCVVectorLookup.cpp:136
   case Invalid:
+  case Undefined:
 llvm_unreachable("Unhandled type.");

Could we just reuse `Invalid`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156223

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


[clang] b2e6516 - [clang][Interp][NFC] Return std::nullopt explicitly from classify()

2023-07-26 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-26T09:34:26+02:00
New Revision: b2e6516fd1abdd9416c6085102523d577c8a2238

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

LOG: [clang][Interp][NFC] Return std::nullopt explicitly from classify()

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index d025586d91b7d3..4c4808324c3a14 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -102,7 +102,7 @@ std::optional Context::classify(QualType T) const 
{
 case 8:
   return PT_Sint8;
 default:
-  return {};
+  return std::nullopt;
 }
   }
 
@@ -117,7 +117,7 @@ std::optional Context::classify(QualType T) const 
{
 case 8:
   return PT_Uint8;
 default:
-  return {};
+  return std::nullopt;
 }
   }
 
@@ -143,7 +143,7 @@ std::optional Context::classify(QualType T) const 
{
   if (const auto *DT = dyn_cast(T))
 return classify(DT->getPointeeType());
 
-  return {};
+  return std::nullopt;
 }
 
 unsigned Context::getCharBit() const {



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


[PATCH] D156254: [clang][dataflow] Add convenience function for analysing and `FunctionDecl` and diagnosing it.

2023-07-26 Thread Martin Böhme via Phabricator via cfe-commits
mboehme accepted this revision.
mboehme added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h:244
 
+/// Runs a dataflow analysis over the given function and then runs `Diagnoser`
+/// over the results. If the analysis is successful, returns a list of

Can you document what the function signature for this should be?

Also, I'm wondering if `DiagnoserT` even needs to be a template argument. 
Shouldn't the `Diagnostic` type be the only "variable" in the type of 
`DiagnoserT`?

Or is it that you don't want to force the caller to pass a `std::function` for 
`Diagnoser`? In that case, you could consider 
[`function_ref'](https://llvm.org/docs/ProgrammersManual.html#the-function-ref-class-template).





Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h:245-246
+/// Runs a dataflow analysis over the given function and then runs `Diagnoser`
+/// over the results. If the analysis is successful, returns a list of
+/// diagnostics for `FuncDecl`. Otherwise, returns an error. Currently, errors
+/// can occur (at least) because the analysis requires too many iterations over





Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h:259
+diagnoseFunction(const FunctionDecl &FuncDecl, ASTContext &ASTCtx,
+ DiagnoserT &Diagnoser,
+ std::int64_t MaxSATIterations = 1'000'000'000) {

Does this need to be passed by non-const reference?

`std::function::operator()` is const, so a const reference should be fine for 
that. Non-const reference looks like we might be assigning to the reference 
(which we aren't).



Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h:261-265
+  using ::llvm::Expected;
+
+  Expected Context = ControlFlowContext::build(FuncDecl);
+  if (!Context)
+return Context.takeError();





Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h:267-268
+
+  auto Solver = std::make_unique(MaxSATIterations);
+  const WatchedLiteralsSolver *SolverView = Solver.get();
+  DataflowAnalysisContext AnalysisContext(std::move(Solver));

Nit: Of the two variables `Solver` and `SolverView`, `Solver` sounds like the 
more canonical name and the one to "go for". Granted, this is a short function 
with little potential for confusion, but maybe call the unique pointer 
`OwnedSolver` (or similar) and the raw pointer `Solver`?

This would also eliminate the "view", which to me sounds like there's more 
going on than just a simple pointer.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h:273-288
+  auto BlockToOutputState = runTypeErasedDataflowAnalysis(
+  *Context, Analysis, Env,
+  [&ASTCtx, &Diagnoser,
+   &Diagnostics](const CFGElement &Elt,
+ const TypeErasedDataflowAnalysisState &State) mutable {
+auto EltDiagnostics =
+Diagnoser(Elt, ASTCtx,





Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:95-98
+  auto *Func = selectFirst(
+  "func", match(functionDecl(ast_matchers::hasName("target")).bind("func"),
+AST->getASTContext()));
+  ASSERT_THAT(Func, NotNull());





Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:101-103
+  auto Diagnoser = [&Count](const CFGElement &, ASTContext &,
+const TransferStateForDiagnostics &) {
+return std::vector({++Count});

I think this gives us a stronger and more explicit check for little extra 
effort.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156254

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


[clang] c725138 - [clang][Interp] Check pointers for live-ness when returning them

2023-07-26 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-26T09:52:09+02:00
New Revision: c7251385c85ddcc1059548038e60099fcc5b304c

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

LOG: [clang][Interp] Check pointers for live-ness when returning them

We might be trying to return a pointer or reference to a local variable,
which doesn't work.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index e0cbf56e196958..4058d43c0bced5 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -181,6 +181,17 @@ template ::T>
 bool Ret(InterpState &S, CodePtr &PC, APValue &Result) {
   const T &Ret = S.Stk.pop();
 
+  // Make sure returned pointers are live. We might be trying to return a
+  // pointer or reference to a local variable.
+  // Just return false, since a diagnostic has already been emitted in Sema.
+  if constexpr (std::is_same_v) {
+// FIXME: We could be calling isLive() here, but the emitted diagnostics
+// seem a little weird, at least if the returned expression is of
+// pointer type.
+if (!Ret.isLive())
+  return false;
+  }
+
   assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame");
   if (!S.checkingPotentialConstantExpression() || S.Current->Caller)
 S.Current->popArgs();

diff  --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index 629d0323e1d2e8..4bb8791de8f4e5 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -265,3 +265,29 @@ namespace CallWithArgs {
 g(0);
   }
 }
+
+namespace ReturnLocalPtr {
+  constexpr int *p() {
+int a = 12;
+return &a; // ref-warning {{address of stack memory}} \
+   // expected-warning {{address of stack memory}}
+  }
+
+  /// GCC rejects the expression below, just like the new interpreter. The 
current interpreter
+  /// however accepts it and only warns about the function above returning an 
address to stack
+  /// memory. If we change the condition to 'p() != nullptr', it even succeeds.
+  static_assert(p() == nullptr, ""); // ref-error {{static assertion failed}} \
+ // expected-error {{not an integral 
constant expression}}
+
+  /// FIXME: The current interpreter emits diagnostics in the reference case 
below, but the
+  /// new one does not.
+  constexpr const int &p2() {
+int a = 12; // ref-note {{declared here}}
+return a; // ref-warning {{reference to stack memory associated with local 
variable}} \
+  // expected-warning {{reference to stack memory associated with 
local variable}}
+  }
+
+  static_assert(p2() == 12, ""); // ref-error {{not an integral constant 
expression}} \
+ // ref-note {{read of variable whose lifetime 
has ended}} \
+ // expected-error {{not an integral constant 
expression}}
+}



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


[PATCH] D154795: [clang][Interp] Check pointers for live-ness when returning them

2023-07-26 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7251385c85d: [clang][Interp] Check pointers for live-ness 
when returning them (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D154795?vs=538442&id=544244#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154795

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


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -265,3 +265,29 @@
 g(0);
   }
 }
+
+namespace ReturnLocalPtr {
+  constexpr int *p() {
+int a = 12;
+return &a; // ref-warning {{address of stack memory}} \
+   // expected-warning {{address of stack memory}}
+  }
+
+  /// GCC rejects the expression below, just like the new interpreter. The 
current interpreter
+  /// however accepts it and only warns about the function above returning an 
address to stack
+  /// memory. If we change the condition to 'p() != nullptr', it even succeeds.
+  static_assert(p() == nullptr, ""); // ref-error {{static assertion failed}} \
+ // expected-error {{not an integral 
constant expression}}
+
+  /// FIXME: The current interpreter emits diagnostics in the reference case 
below, but the
+  /// new one does not.
+  constexpr const int &p2() {
+int a = 12; // ref-note {{declared here}}
+return a; // ref-warning {{reference to stack memory associated with local 
variable}} \
+  // expected-warning {{reference to stack memory associated with 
local variable}}
+  }
+
+  static_assert(p2() == 12, ""); // ref-error {{not an integral constant 
expression}} \
+ // ref-note {{read of variable whose lifetime 
has ended}} \
+ // expected-error {{not an integral constant 
expression}}
+}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -181,6 +181,17 @@
 bool Ret(InterpState &S, CodePtr &PC, APValue &Result) {
   const T &Ret = S.Stk.pop();
 
+  // Make sure returned pointers are live. We might be trying to return a
+  // pointer or reference to a local variable.
+  // Just return false, since a diagnostic has already been emitted in Sema.
+  if constexpr (std::is_same_v) {
+// FIXME: We could be calling isLive() here, but the emitted diagnostics
+// seem a little weird, at least if the returned expression is of
+// pointer type.
+if (!Ret.isLive())
+  return false;
+  }
+
   assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame");
   if (!S.checkingPotentialConstantExpression() || S.Current->Caller)
 S.Current->popArgs();


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -265,3 +265,29 @@
 g(0);
   }
 }
+
+namespace ReturnLocalPtr {
+  constexpr int *p() {
+int a = 12;
+return &a; // ref-warning {{address of stack memory}} \
+   // expected-warning {{address of stack memory}}
+  }
+
+  /// GCC rejects the expression below, just like the new interpreter. The current interpreter
+  /// however accepts it and only warns about the function above returning an address to stack
+  /// memory. If we change the condition to 'p() != nullptr', it even succeeds.
+  static_assert(p() == nullptr, ""); // ref-error {{static assertion failed}} \
+ // expected-error {{not an integral constant expression}}
+
+  /// FIXME: The current interpreter emits diagnostics in the reference case below, but the
+  /// new one does not.
+  constexpr const int &p2() {
+int a = 12; // ref-note {{declared here}}
+return a; // ref-warning {{reference to stack memory associated with local variable}} \
+  // expected-warning {{reference to stack memory associated with local variable}}
+  }
+
+  static_assert(p2() == 12, ""); // ref-error {{not an integral constant expression}} \
+ // ref-note {{read of variable whose lifetime has ended}} \
+ // expected-error {{not an integral constant expression}}
+}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -181,6 +181,17 @@
 bool Ret(InterpState &S, CodePtr &PC, APValue &Result) {
   const T &Ret = S.Stk.pop();
 
+  // Make sure returned pointers are live. We might be trying to return a
+  // pointer or reference to a local varia

[PATCH] D155819: [include-cleaner] Loose matching for verbatim headers

2023-07-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h:198
   llvm::StringMap> BySpelling;
+  llvm::StringMap> BySpellingAlternate;
   llvm::DenseMap> ByFile;

maybe add a comment saying that these spellings are generated heuristically?



Comment at: clang-tools-extra/include-cleaner/lib/Types.cpp:110-112
+  while (!P.empty() && path::is_separator(P.back()))
+P.pop_back();
+  return P;

nit: `return P.rtrim('/');` // only separator we can encounter is forward slash 
at this point.



Comment at: clang-tools-extra/include-cleaner/lib/Types.cpp:129
   ByLine[I.Line] = Index;
+  if (I.Resolved) {
+ByFile[I.Resolved].push_back(Index);

nit: prefer early exit



Comment at: clang-tools-extra/include-cleaner/lib/Types.cpp:137
+// verbatim "e/f" should match (spelled=c/d/e/f, resolved=/a/b/c/d/e/f).
+// We assume entry's (normalized) name will match the search dirs.
+auto Path = normalizePath(I.Resolved->getName());

i think this assumption breaks when we have an absolute include search path, 
which is a subdirectory of the CWD of file manager. as we might now have a 
resolved include which is relative, but a search path that'll never match a 
prefix of those includes.

i guess this is fine, as we're trying to heuristically match. but it would be 
useful to mention it here and add a unittest for that. (unless I am missing 
something and headersearch already normalizes such paths)



Comment at: clang-tools-extra/include-cleaner/lib/Types.cpp:141
+ Parent = path::parent_path(Parent)) {
+  if (SearchPath.contains(Parent)) {
+llvm::StringRef Rel = llvm::StringRef(Path).drop_front(Parent.size());

nit: prefer early exit



Comment at: clang-tools-extra/include-cleaner/lib/Types.cpp:142-144
+llvm::StringRef Rel = llvm::StringRef(Path).drop_front(Parent.size());
+while (!Rel.empty() && path::is_separator(Rel.front()))
+  Rel = Rel.drop_front();

nit: `auto Rel = llvm::StringRef(Path).drop_front(Parent.size()).ltrim('/');` 
// we already normalized the path and only have forward slashes.



Comment at: clang-tools-extra/include-cleaner/lib/Types.cpp:171-173
+for (unsigned I : BySpellingAlternate.lookup(Spelling))
+  if (!llvm::is_contained(Result, &All[I]))
+Result.push_back(&All[I]);

i think we shouldn't look into alternate spellings if we've already found an 
exact spelling. we would be matching wrong headers for sure in those cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155819

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


[PATCH] D156255: [clang-tidy] Update unchecked-optional-access-check to use convenience function for diagnosing `FunctionDecl`s.

2023-07-26 Thread Martin Böhme via Phabricator via cfe-commits
mboehme accepted this revision.
mboehme added a comment.
This revision is now accepted and ready to land.

Note this appears to have clang-format errors




Comment at: 
clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp:58-63
+  if (llvm::Expected> Errors =
+  dataflow::diagnoseFunction(*FuncDecl, 
*Result.Context,
+ Diagnoser))
 for (const SourceLocation &Loc : *Errors)
   diag(Loc, "unchecked access to optional value");

`Errors` could be confused with the error that is present inside the `Expected`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156255

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


[clang] 8c0246c - [clang][Interp] Reject reinterpret_casts

2023-07-26 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-26T09:56:29+02:00
New Revision: 8c0246c7f517a9b901224474f1a608d7e5193583

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

LOG: [clang][Interp] Reject reinterpret_casts

Add a new InvalidCast op for this purpose and emit a diagnostic.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/Disasm.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/lib/AST/Interp/PrimType.h
clang/test/AST/Interp/unsupported.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index bd8e3304c5893b..7970cb63484855 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -997,6 +997,15 @@ bool ByteCodeExprGen::VisitCXXThrowExpr(const 
CXXThrowExpr *E) {
   return this->emitInvalid(E);
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXReinterpretCastExpr(
+const CXXReinterpretCastExpr *E) {
+  if (!this->discard(E->getSubExpr()))
+return false;
+
+  return this->emitInvalidCast(CastKind::Reinterpret, E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 6e29bc32ba3830..c828f319cc04cd 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -98,6 +98,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitLambdaExpr(const LambdaExpr *E);
   bool VisitPredefinedExpr(const PredefinedExpr *E);
   bool VisitCXXThrowExpr(const CXXThrowExpr *E);
+  bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;

diff  --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index 35ed5d12869719..ef4c81326d2db8 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -73,3 +73,12 @@ LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) 
const {
 Anon->dump();
   }
 }
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, interp::CastKind CK) {
+  switch (CK) {
+  case interp::CastKind::Reinterpret:
+OS << "reinterpret_cast";
+break;
+  }
+  return OS;
+}

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 4058d43c0bced5..33ab0cdedeae42 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1754,6 +1754,14 @@ inline bool Invalid(InterpState &S, CodePtr OpPC) {
   return false;
 }
 
+/// Same here, but only for casts.
+inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind) {
+  const SourceLocation &Loc = S.Current->getLocation(OpPC);
+  S.FFDiag(Loc, diag::note_constexpr_invalid_cast)
+  << static_cast(Kind) << S.Current->getRange(OpPC);
+  return false;
+}
+
 
//===--===//
 // Read opcode arguments
 
//===--===//

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index bc81dfedfc6353..6d12823990cf2c 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -51,6 +51,7 @@ def ArgRecordField : ArgType { let Name = "const 
Record::Field *"; }
 def ArgFltSemantics : ArgType { let Name = "const llvm::fltSemantics *"; }
 def ArgRoundingMode : ArgType { let Name = "llvm::RoundingMode"; }
 def ArgLETD: ArgType { let Name = "const LifetimeExtendedTemporaryDecl *"; }
+def ArgCastKind : ArgType { let Name = "CastKind"; }
 
 
//===--===//
 // Classes of types instructions operate on.
@@ -604,3 +605,6 @@ def Dup : Opcode {
 
 // [] -> []
 def Invalid : Opcode {}
+def InvalidCast : Opcode {
+  let Args = [ArgCastKind];
+}

diff  --git a/clang/lib/AST/Interp/PrimType.h b/clang/lib/AST/Interp/PrimType.h
index 693e57210608d9..c7078c6f19c1a2 100644
--- a/clang/lib/AST/Interp/PrimType.h
+++ b/clang/lib/AST/Interp/PrimType.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_AST_INTERP_TYPE_H
 #define LLVM_CLANG_AST_INTERP_TYPE_H
 
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 #include 
@@ -42,6 +43,11 @@ enum PrimType : unsigned {
   PT_FnPtr,
 };
 
+enum class CastKind : uint8_t {
+  Reinterpret,
+};
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, interp::CastKind CK);
+
 constexpr bool isIntegralType(PrimType T) { return T <= PT_Uint64; }
 
 /// Mapping from primitive types to their representation.

diff  --git a/clang/test/AST/

[PATCH] D153276: [clang][Interp] Reject reinterpret_cast expressions

2023-07-26 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8c0246c7f517: [clang][Interp] Reject reinterpret_casts 
(authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D153276?vs=533238&id=544246#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153276

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Disasm.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.h
  clang/test/AST/Interp/unsupported.cpp

Index: clang/test/AST/Interp/unsupported.cpp
===
--- clang/test/AST/Interp/unsupported.cpp
+++ clang/test/AST/Interp/unsupported.cpp
@@ -47,3 +47,11 @@
 return 0;
   }
 }
+
+namespace Casts {
+  constexpr int a = reinterpret_cast(12); // expected-error {{must be initialized by a constant expression}} \
+   // expected-note {{reinterpret_cast is not allowed}} \
+   // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{reinterpret_cast is not allowed}}
+
+}
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_AST_INTERP_TYPE_H
 #define LLVM_CLANG_AST_INTERP_TYPE_H
 
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 #include 
@@ -42,6 +43,11 @@
   PT_FnPtr,
 };
 
+enum class CastKind : uint8_t {
+  Reinterpret,
+};
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, interp::CastKind CK);
+
 constexpr bool isIntegralType(PrimType T) { return T <= PT_Uint64; }
 
 /// Mapping from primitive types to their representation.
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -51,6 +51,7 @@
 def ArgFltSemantics : ArgType { let Name = "const llvm::fltSemantics *"; }
 def ArgRoundingMode : ArgType { let Name = "llvm::RoundingMode"; }
 def ArgLETD: ArgType { let Name = "const LifetimeExtendedTemporaryDecl *"; }
+def ArgCastKind : ArgType { let Name = "CastKind"; }
 
 //===--===//
 // Classes of types instructions operate on.
@@ -604,3 +605,6 @@
 
 // [] -> []
 def Invalid : Opcode {}
+def InvalidCast : Opcode {
+  let Args = [ArgCastKind];
+}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1754,6 +1754,14 @@
   return false;
 }
 
+/// Same here, but only for casts.
+inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind) {
+  const SourceLocation &Loc = S.Current->getLocation(OpPC);
+  S.FFDiag(Loc, diag::note_constexpr_invalid_cast)
+  << static_cast(Kind) << S.Current->getRange(OpPC);
+  return false;
+}
+
 //===--===//
 // Read opcode arguments
 //===--===//
Index: clang/lib/AST/Interp/Disasm.cpp
===
--- clang/lib/AST/Interp/Disasm.cpp
+++ clang/lib/AST/Interp/Disasm.cpp
@@ -73,3 +73,12 @@
 Anon->dump();
   }
 }
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, interp::CastKind CK) {
+  switch (CK) {
+  case interp::CastKind::Reinterpret:
+OS << "reinterpret_cast";
+break;
+  }
+  return OS;
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -98,6 +98,7 @@
   bool VisitLambdaExpr(const LambdaExpr *E);
   bool VisitPredefinedExpr(const PredefinedExpr *E);
   bool VisitCXXThrowExpr(const CXXThrowExpr *E);
+  bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -997,6 +997,15 @@
   return this->emitInvalid(E);
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXReinterpretCastExpr(
+const CXXReinterpretCastExpr *E) {
+  if (!this->discard(E->getSubExpr()))
+return false;
+
+  return this->emitInvalidCast(CastKind::Reinterpret, E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) {
   if (E->containsErrors())
 return fa

[clang] 73362c4 - Revert "[CMake] Include riscv32-unknown-elf runtimes in Fuchsia toolchain"

2023-07-26 Thread Petr Hosek via cfe-commits

Author: Petr Hosek
Date: 2023-07-26T08:05:03Z
New Revision: 73362c44eb430b759c81639e67a87231ea51c48a

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

LOG: Revert "[CMake] Include riscv32-unknown-elf runtimes in Fuchsia toolchain"

This reverts commit 28f5322770a13cd2cd796d0936d3db1a454e620b.

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 468731e8543272..42d7f36df3f93d 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -7,7 +7,7 @@ set(LLVM_TARGETS_TO_BUILD X86;ARM;AArch64;RISCV CACHE STRING "")
 set(PACKAGE_VENDOR Fuchsia CACHE STRING "")
 
 set(_FUCHSIA_ENABLE_PROJECTS "bolt;clang;clang-tools-extra;lld;llvm;polly")
-set(LLVM_ENABLE_RUNTIMES "compiler-rt;libc;libcxx;libcxxabi;libunwind" CACHE 
STRING "")
+set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING 
"")
 
 set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
@@ -24,7 +24,6 @@ set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "")
 set(LLVM_ENABLE_ZLIB ON CACHE BOOL "")
 set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
 set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
-set(LLVM_LIBC_FULL_BUILD ON CACHE BOOL "")
 set(LLVM_STATIC_LINK_CXX_STDLIB ON CACHE BOOL "")
 set(LLVM_USE_RELATIVE_PATHS_IN_FILES ON CACHE BOOL "")
 set(LLDB_ENABLE_CURSES OFF CACHE BOOL "")
@@ -289,39 +288,6 @@ if(FUCHSIA_SDK)
   set(LLVM_RUNTIME_MULTILIB_hwasan+noexcept_TARGETS 
"aarch64-unknown-fuchsia;riscv64-unknown-fuchsia" CACHE STRING "")
 endif()
 
-foreach(target riscv32-unknown-elf)
-  list(APPEND BUILTIN_TARGETS "${target}")
-  set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
-  set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR RISCV CACHE STRING "")
-  set(BUILTINS_${target}_CMAKE_SYSROOT "" CACHE STRING "")
-  set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
-  foreach(lang C;CXX;ASM)
-set(BUILTINS_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-march=rv32imafc -mabi=ilp32f" CACHE STRING "")
-  endforeach()
-  foreach(type SHARED;MODULE;EXE)
-set(BUILTINS_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
-  endforeach()
-  set(BUILTINS_${target}_COMPILER_RT_BAREMETAL_BUILD ON CACHE BOOL "")
-
-  list(APPEND RUNTIME_TARGETS "${target}")
-  set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "")
-  set(RUNTIMES_${target}_CMAKE_SYSTEM_PROCESSOR RISCV CACHE STRING "")
-  set(RUNTIMES_${target}_CMAKE_SYSROOT "" CACHE STRING "")
-  set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
-  set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE 
STRING "")
-  foreach(lang C;CXX;ASM)
-set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-march=rv32imafc -mabi=ilp32f" CACHE STRING "")
-  endforeach()
-  foreach(type SHARED;MODULE;EXE)
-set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
-  endforeach()
-  set(RUNTIMES_${target}_LLVM_LIBC_FULL_BUILD ON CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBC_ENABLE_USE_BY_CLANG ON CACHE BOOL "")
-  set(RUNTIMES_${target}_LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "libc" CACHE STRING "")
-endforeach()
-
 set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "")
 set(LLVM_RUNTIME_TARGETS "${RUNTIME_TARGETS}" CACHE STRING "")
 



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


[clang] 4744693 - [clang][Interp][NFC] Move CastKind operator<< to PrimTypes.h

2023-07-26 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-26T10:06:26+02:00
New Revision: 47446939e0e60cf52ffdd3fa671949ff3183a4ca

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

LOG: [clang][Interp][NFC] Move CastKind operator<< to PrimTypes.h

So it actually works when using dump().

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index ef4c81326d2db8..35ed5d12869719 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -73,12 +73,3 @@ LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) 
const {
 Anon->dump();
   }
 }
-
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, interp::CastKind CK) {
-  switch (CK) {
-  case interp::CastKind::Reinterpret:
-OS << "reinterpret_cast";
-break;
-  }
-  return OS;
-}

diff  --git a/clang/lib/AST/Interp/PrimType.h b/clang/lib/AST/Interp/PrimType.h
index c7078c6f19c1a2..ba4f630b126437 100644
--- a/clang/lib/AST/Interp/PrimType.h
+++ b/clang/lib/AST/Interp/PrimType.h
@@ -46,7 +46,15 @@ enum PrimType : unsigned {
 enum class CastKind : uint8_t {
   Reinterpret,
 };
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, interp::CastKind CK);
+inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
+ interp::CastKind CK) {
+  switch (CK) {
+  case interp::CastKind::Reinterpret:
+OS << "reinterpret_cast";
+break;
+  }
+  return OS;
+}
 
 constexpr bool isIntegralType(PrimType T) { return T <= PT_Uint64; }
 



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


[clang] ae667f0 - [clang][Interp][NFC] Take a const InterpFrame* in InterpBuiltin.cpp

2023-07-26 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-26T10:06:26+02:00
New Revision: ae667f03d369cab8f32f28c3d765695ed4c1972b

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

LOG: [clang][Interp][NFC] Take a const InterpFrame* in InterpBuiltin.cpp

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 0d0859a4cd284b..dbefcbf961dd28 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -13,13 +13,13 @@
 namespace clang {
 namespace interp {
 
-template  T getParam(InterpFrame *Frame, unsigned Index) {
+template  T getParam(const InterpFrame *Frame, unsigned Index) {
   unsigned Offset = Frame->getFunction()->getParamOffset(Index);
   return Frame->getParam(Offset);
 }
 
 static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
-   InterpFrame *Frame) {
+   const InterpFrame *Frame) {
   const Pointer &A = getParam(Frame, 0);
   const Pointer &B = getParam(Frame, 1);
 



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


[PATCH] D156300: [clangd] Avoid unexpected desugaring in isSugaredTemplateParameter

2023-07-26 Thread Younan Zhang via Phabricator via cfe-commits
zyounan created this revision.
zyounan added a reviewer: nridge.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
zyounan requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This is a follow-up to D151785 , addressing 
https://github.com/clangd/clangd/issues/1703.

The previous approach of peeling pointer types during a traversal
using getPointeeType might have produced unexpected results; since
the method would implicitly desugar the type if the type being passed
in could not be cast to a Pointer-like Type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156300

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -81,11 +81,13 @@
 }
 
 template 
-void assertHints(InlayHintKind Kind, llvm::StringRef AnnotatedSource,
- ExpectedHints... Expected) {
+void assertHintsWithHeader(InlayHintKind Kind, llvm::StringRef AnnotatedSource,
+   llvm::StringRef HeaderContent,
+   ExpectedHints... Expected) {
   Annotations Source(AnnotatedSource);
   TestTU TU = TestTU::withCode(Source.code());
   TU.ExtraArgs.push_back("-std=c++20");
+  TU.HeaderCode = HeaderContent;
   auto AST = TU.build();
 
   EXPECT_THAT(hintsOfKind(AST, Kind),
@@ -96,6 +98,12 @@
   EXPECT_THAT(inlayHints(AST, std::nullopt), IsEmpty());
 }
 
+template 
+void assertHints(InlayHintKind Kind, llvm::StringRef AnnotatedSource,
+ ExpectedHints... Expected) {
+  return assertHintsWithHeader(Kind, AnnotatedSource, "", std::move(Expected)...);
+}
+
 // Hack to allow expression-statements operating on parameter packs in C++14.
 template  void ignore(T &&...) {}
 
@@ -1421,8 +1429,7 @@
 }
 
 TEST(TypeHints, SubstTemplateParameterAliases) {
-  assertTypeHints(
-  R"cpp(
+  llvm::StringRef Header = R"cpp(
   template  struct allocator {};
 
   template 
@@ -1455,9 +1462,34 @@
 
 T elements[10];
   };
+  )cpp";
+
+  llvm::StringRef VectorIntPtr = R"cpp(
+vector array;
+auto $no_modifier[[x]] = array[3];
+auto* $ptr_modifier[[ptr]] = &array[3];
+auto& $ref_modifier[[ref]] = array[3];
+auto& $at[[immutable]] = array.at(3);
+
+auto $data[[data]] = array.data();
+auto $allocator[[alloc]] = array.get_allocator();
+auto $size[[size]] = array.size();
+auto $begin[[begin]] = array.begin();
+auto $end[[end]] = array.end();
+  )cpp";
+
+  assertHintsWithHeader(
+  InlayHintKind::Type, VectorIntPtr, Header,
+  ExpectedHint{": int *", "no_modifier"},
+  ExpectedHint{": int **", "ptr_modifier"},
+  ExpectedHint{": int *&", "ref_modifier"},
+  ExpectedHint{": int *const &", "at"}, ExpectedHint{": int **", "data"},
+  ExpectedHint{": allocator", "allocator"},
+  ExpectedHint{": size_type", "size"}, ExpectedHint{": iterator", "begin"},
+  ExpectedHint{": non_template_iterator", "end"});
 
+  llvm::StringRef VectorInt = R"cpp(
   vector array;
-
   auto $no_modifier[[by_value]] = array[3];
   auto* $ptr_modifier[[ptr]] = &array[3];
   auto& $ref_modifier[[ref]] = array[3];
@@ -1468,8 +1500,19 @@
   auto $size[[size]] = array.size();
   auto $begin[[begin]] = array.begin();
   auto $end[[end]] = array.end();
+  )cpp";
 
+  assertHintsWithHeader(
+  InlayHintKind::Type, VectorInt, Header,
+  ExpectedHint{": int", "no_modifier"},
+  ExpectedHint{": int *", "ptr_modifier"},
+  ExpectedHint{": int &", "ref_modifier"},
+  ExpectedHint{": const int &", "at"}, ExpectedHint{": int *", "data"},
+  ExpectedHint{": allocator", "allocator"},
+  ExpectedHint{": size_type", "size"}, ExpectedHint{": iterator", "begin"},
+  ExpectedHint{": non_template_iterator", "end"});
 
+  llvm::StringRef TypeAlias = R"cpp(
   // If the type alias is not of substituted template parameter type,
   // do not show desugared type.
   using VeryLongLongTypeName = my_iterator;
@@ -1484,16 +1527,11 @@
   using static_vector = basic_static_vector>;
 
   auto $vector_name[[vec]] = static_vector();
-  )cpp",
-  ExpectedHint{": int", "no_modifier"},
-  ExpectedHint{": int *", "ptr_modifier"},
-  ExpectedHint{": int &", "ref_modifier"},
-  ExpectedHint{": const int &", "at"}, ExpectedHint{": int *", "data"},
-  ExpectedHint{": allocator", "allocator"},
-  ExpectedHint{": size_type", "size"}, ExpectedHint{": iterator", "begin"},
-  ExpectedHint{": non_template_iterator", "end"},
-  ExpectedHint{": Short", "short_name"},
-  ExpectedHint{": static_vector", "vector_name"});
+  )cpp";
+
+  assertHintsWithHeader(InlayHintKind::Type, TypeAlia

[PATCH] D156300: [clangd] Avoid unexpected desugaring in isSugaredTemplateParameter

2023-07-26 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 544252.
zyounan added a comment.

Format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156300

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -81,11 +81,13 @@
 }
 
 template 
-void assertHints(InlayHintKind Kind, llvm::StringRef AnnotatedSource,
- ExpectedHints... Expected) {
+void assertHintsWithHeader(InlayHintKind Kind, llvm::StringRef AnnotatedSource,
+   llvm::StringRef HeaderContent,
+   ExpectedHints... Expected) {
   Annotations Source(AnnotatedSource);
   TestTU TU = TestTU::withCode(Source.code());
   TU.ExtraArgs.push_back("-std=c++20");
+  TU.HeaderCode = HeaderContent;
   auto AST = TU.build();
 
   EXPECT_THAT(hintsOfKind(AST, Kind),
@@ -96,6 +98,13 @@
   EXPECT_THAT(inlayHints(AST, std::nullopt), IsEmpty());
 }
 
+template 
+void assertHints(InlayHintKind Kind, llvm::StringRef AnnotatedSource,
+ ExpectedHints... Expected) {
+  return assertHintsWithHeader(Kind, AnnotatedSource, "",
+   std::move(Expected)...);
+}
+
 // Hack to allow expression-statements operating on parameter packs in C++14.
 template  void ignore(T &&...) {}
 
@@ -1421,8 +1430,7 @@
 }
 
 TEST(TypeHints, SubstTemplateParameterAliases) {
-  assertTypeHints(
-  R"cpp(
+  llvm::StringRef Header = R"cpp(
   template  struct allocator {};
 
   template 
@@ -1455,9 +1463,34 @@
 
 T elements[10];
   };
+  )cpp";
+
+  llvm::StringRef VectorIntPtr = R"cpp(
+vector array;
+auto $no_modifier[[x]] = array[3];
+auto* $ptr_modifier[[ptr]] = &array[3];
+auto& $ref_modifier[[ref]] = array[3];
+auto& $at[[immutable]] = array.at(3);
+
+auto $data[[data]] = array.data();
+auto $allocator[[alloc]] = array.get_allocator();
+auto $size[[size]] = array.size();
+auto $begin[[begin]] = array.begin();
+auto $end[[end]] = array.end();
+  )cpp";
+
+  assertHintsWithHeader(
+  InlayHintKind::Type, VectorIntPtr, Header,
+  ExpectedHint{": int *", "no_modifier"},
+  ExpectedHint{": int **", "ptr_modifier"},
+  ExpectedHint{": int *&", "ref_modifier"},
+  ExpectedHint{": int *const &", "at"}, ExpectedHint{": int **", "data"},
+  ExpectedHint{": allocator", "allocator"},
+  ExpectedHint{": size_type", "size"}, ExpectedHint{": iterator", "begin"},
+  ExpectedHint{": non_template_iterator", "end"});
 
+  llvm::StringRef VectorInt = R"cpp(
   vector array;
-
   auto $no_modifier[[by_value]] = array[3];
   auto* $ptr_modifier[[ptr]] = &array[3];
   auto& $ref_modifier[[ref]] = array[3];
@@ -1468,8 +1501,19 @@
   auto $size[[size]] = array.size();
   auto $begin[[begin]] = array.begin();
   auto $end[[end]] = array.end();
+  )cpp";
 
+  assertHintsWithHeader(
+  InlayHintKind::Type, VectorInt, Header,
+  ExpectedHint{": int", "no_modifier"},
+  ExpectedHint{": int *", "ptr_modifier"},
+  ExpectedHint{": int &", "ref_modifier"},
+  ExpectedHint{": const int &", "at"}, ExpectedHint{": int *", "data"},
+  ExpectedHint{": allocator", "allocator"},
+  ExpectedHint{": size_type", "size"}, ExpectedHint{": iterator", "begin"},
+  ExpectedHint{": non_template_iterator", "end"});
 
+  llvm::StringRef TypeAlias = R"cpp(
   // If the type alias is not of substituted template parameter type,
   // do not show desugared type.
   using VeryLongLongTypeName = my_iterator;
@@ -1484,16 +1528,11 @@
   using static_vector = basic_static_vector>;
 
   auto $vector_name[[vec]] = static_vector();
-  )cpp",
-  ExpectedHint{": int", "no_modifier"},
-  ExpectedHint{": int *", "ptr_modifier"},
-  ExpectedHint{": int &", "ref_modifier"},
-  ExpectedHint{": const int &", "at"}, ExpectedHint{": int *", "data"},
-  ExpectedHint{": allocator", "allocator"},
-  ExpectedHint{": size_type", "size"}, ExpectedHint{": iterator", "begin"},
-  ExpectedHint{": non_template_iterator", "end"},
-  ExpectedHint{": Short", "short_name"},
-  ExpectedHint{": static_vector", "vector_name"});
+  )cpp";
+
+  assertHintsWithHeader(InlayHintKind::Type, TypeAlias, Header,
+ExpectedHint{": Short", "short_name"},
+ExpectedHint{": static_vector", "vector_name"});
 }
 
 TEST(DesignatorHints, Basic) {
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -199,18 +199,45 @@
 // Neither `PointerType` nor `ReferenceType` is considered as sugared

[PATCH] D153276: [clang][Interp] Reject reinterpret_cast expressions

2023-07-26 Thread Jan-Patrick Lehr via Phabricator via cfe-commits
jplehr added a comment.

Hi,
this seems to have broken the OpenMP AMDGPU buildbot 
(https://lab.llvm.org/buildbot/#/builders/193/builds/35471)
I'm happy to help if needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153276

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


[PATCH] D153276: [clang][Interp] Reject reinterpret_cast expressions

2023-07-26 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Yeah sorry about that, but should already be fixed by 
https://github.com/llvm/llvm-project/commit/47446939e0e60cf52ffdd3fa671949ff3183a4c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153276

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


[PATCH] D153276: [clang][Interp] Reject reinterpret_cast expressions

2023-07-26 Thread Jan-Patrick Lehr via Phabricator via cfe-commits
jplehr added a comment.

Wow, thanks for the quick fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153276

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


[PATCH] D156223: [RISCV] Resolve a few bugs in RISCVVIntrinsicUtils.cpp

2023-07-26 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat updated this revision to Diff 544254.
4vtomat added a comment.

Add a test case for invalid example.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156223

Files:
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/lib/Support/RISCVVIntrinsicUtils.cpp
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v_invalid.c


Index: 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v_invalid.c
===
--- /dev/null
+++ 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v_invalid.c
@@ -0,0 +1,21 @@
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -target-feature +zfh \
+// RUN:   -target-feature +zvfh -disable-O0-optnone %s -fsyntax-only -verify
+
+#include 
+
+vuint64m2_t test_vlmul_trunc_v_u64m2_u64m2(vuint64m2_t op1) { // expected-note 
{{'test_vlmul_trunc_v_u64m2_u64m2' declared here}}
+  return __riscv_vlmul_trunc_v_u64m2_u64m2(op1); // expected-error {{call to 
undeclared function '__riscv_vlmul_trunc_v_u64m2_u64m2'; ISO C99 and later do 
not support implicit function declarations}} expected-error {{returning 'int' 
from a function with incompatible result type 'vuint64m2_t' (aka 
'__rvv_uint64m2_t')}} expected-note {{did you mean 
'test_vlmul_trunc_v_u64m2_u64m2'?}}
+}
+
+vuint64m4_t test_vlmul_trunc_v_u64m4_u64m4(vuint64m4_t op1) { // expected-note 
{{'test_vlmul_trunc_v_u64m4_u64m4' declared here}}
+  return __riscv_vlmul_trunc_v_u64m4_u64m4(op1); // expected-error {{call to 
undeclared function '__riscv_vlmul_trunc_v_u64m4_u64m4'; ISO C99 and later do 
not support implicit function declarations}} expected-error {{returning 'int' 
from a function with incompatible result type 'vuint64m4_t' (aka 
'__rvv_uint64m4_t')}} expected-note {{did you mean 
'test_vlmul_trunc_v_u64m4_u64m4'?}}
+}
+
+vuint64m1_t test_vlmul_trunc_v_u64m1_u64m1(vuint64m1_t op1) { // expected-note 
{{'test_vlmul_trunc_v_u64m1_u64m1' declared here}}
+  return __riscv_vlmul_trunc_v_u64m1_u64m1(op1); // expected-error {{call to 
undeclared function '__riscv_vlmul_trunc_v_u64m1_u64m1'; ISO C99 and later do 
not support implicit function declarations}} expected-error {{returning 'int' 
from a function with incompatible result type 'vuint64m1_t' (aka 
'__rvv_uint64m1_t')}} expected-note {{did you mean 
'test_vlmul_trunc_v_u64m1_u64m1'?}}
+}
+
+vuint64m8_t test_vlmul_trunc_v_u64m8_u64m8(vuint64m8_t op1) { // expected-note 
{{'test_vlmul_trunc_v_u64m8_u64m8' declared here}}
+  return __riscv_vlmul_trunc_v_u64m8_u64m8(op1); // expected-error {{call to 
undeclared function '__riscv_vlmul_trunc_v_u64m8_u64m8'; ISO C99 and later do 
not support implicit function declarations}} expected-error {{returning 'int' 
from a function with incompatible result type 'vuint64m8_t' (aka 
'__rvv_uint64m8_t')}} expected-note {{did you mean 
'test_vlmul_trunc_v_u64m8_u64m8'?}}
+}
Index: clang/lib/Support/RISCVVIntrinsicUtils.cpp
===
--- clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -742,6 +742,10 @@
 break;
   }
 
+  // Early return if the current type modifier is already invalid.
+  if (ScalarType == Invalid)
+return;
+
   for (unsigned TypeModifierMaskShift = 0;
TypeModifierMaskShift <= static_cast(TypeModifier::MaxOffset);
++TypeModifierMaskShift) {
@@ -803,13 +807,13 @@
 void RVVType::applyFixedLog2LMUL(int Log2LMUL, enum FixedLMULType Type) {
   switch (Type) {
   case FixedLMULType::LargerThan:
-if (Log2LMUL < LMUL.Log2LMUL) {
+if (Log2LMUL <= LMUL.Log2LMUL) {
   ScalarType = ScalarTypeKind::Invalid;
   return;
 }
 break;
   case FixedLMULType::SmallerThan:
-if (Log2LMUL > LMUL.Log2LMUL) {
+if (Log2LMUL >= LMUL.Log2LMUL) {
   ScalarType = ScalarTypeKind::Invalid;
   return;
 }
Index: clang/lib/Sema/SemaRISCVVectorLookup.cpp
===
--- clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -133,6 +133,7 @@
 }
 break;
   case Invalid:
+  case Undefined:
 llvm_unreachable("Unhandled type.");
   }
   if (Type->isVector()) {
Index: clang/include/clang/Support/RISCVVIntrinsicUtils.h
===
--- clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -218,6 +218,7 @@
   UnsignedInteger,
   Float,
   Invalid,
+  Undefined,
 };
 
 // Exponential LMUL
@@ -240,7 +241,7 @@
   friend class RVVTypeCache;
 
   BasicType BT;
-  ScalarTypeKind ScalarType = Invalid;
+  ScalarTypeKind ScalarType = Undefined;
   LMULTy

[PATCH] D156223: [RISCV] Resolve a few bugs in RISCVVIntrinsicUtils.cpp

2023-07-26 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat added inline comments.



Comment at: clang/lib/Sema/SemaRISCVVectorLookup.cpp:136
   case Invalid:
+  case Undefined:
 llvm_unreachable("Unhandled type.");

eopXD wrote:
> Could we just reuse `Invalid`?
We can't reuse Invalid, since `ScalarType` in `RVVType` class is default to 
`Invalid`, we are not able to determine whether it's really invalid or not 
during `applyModifier` function, so that's the reason why I added `Undefined` 
to differentiate between `default` and `really invalid`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156223

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


[PATCH] D156277: [Parser][ObjC] Stop parsing on eof

2023-07-26 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/lib/Parse/ParseObjc.cpp:749
+  if (!Tok.is(tok::eof))
+ConsumeToken();
   break;

tbaeder wrote:
> Why is there a `ConsumeToken()` call at all here? The token is already being 
> consumed in line 729.
Didn't notice this, thanks for reminding!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156277

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


[PATCH] D155356: [clang][Interp] Implement __builtin_nan family of functions

2023-07-26 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 544258.

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

https://reviews.llvm.org/D155356

Files:
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/test/AST/Interp/builtin-functions.cpp

Index: clang/test/AST/Interp/builtin-functions.cpp
===
--- clang/test/AST/Interp/builtin-functions.cpp
+++ clang/test/AST/Interp/builtin-functions.cpp
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
 // RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -std=c++20 -verify=ref %s -Wno-constant-evaluated
+
 
 namespace strcmp {
   constexpr char kFoobar[6] = {'f','o','o','b','a','r'};
@@ -34,3 +37,24 @@
 // ref-error {{not an integral constant}} \
 // ref-note {{dereferenced one-past-the-end}}
 }
+
+namespace nan {
+  constexpr double NaN1 = __builtin_nan("");
+
+  /// The current interpreter does not accept this, but it should.
+  constexpr float NaN2 = __builtin_nans([](){return "0xAE98";}()); // ref-error {{must be initialized by a constant expression}}
+
+  constexpr double NaN3 = __builtin_nan("foo"); // expected-error {{must be initialized by a constant expression}} \
+// ref-error {{must be initialized by a constant expression}}
+  constexpr float NaN4 = __builtin_nanf("");
+  constexpr long double NaN5 = __builtin_nanf128("");
+
+  constexpr char f[] = {'0', 'x', 'A', 'E', '\0'};
+  constexpr double NaN6 = __builtin_nan(f); // ref-error {{must be initialized by a constant expression}}
+
+  constexpr char f2[] = {'0', 'x', 'A', 'E'}; /// No trailing 0 byte.
+  constexpr double NaN7 = __builtin_nan(f2); // ref-error {{must be initialized by a constant expression}} \
+ // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{read of dereferenced one-past-the-end pointer}} \
+ // expected-note {{in call to}}
+}
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -9,6 +9,7 @@
 #include "Interp.h"
 #include "PrimType.h"
 #include "clang/Basic/Builtins.h"
+#include "clang/Basic/TargetInfo.h"
 
 namespace clang {
 namespace interp {
@@ -57,6 +58,67 @@
   return true;
 }
 
+static bool interp__builtin_nan(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function *F,
+bool Signaling) {
+  const Pointer &Arg = getParam(Frame, 0);
+
+  if (!CheckLoad(S, OpPC, Arg))
+return false;
+
+  assert(Arg.getFieldDesc()->isPrimitiveArray());
+
+  // Convert the given string to an integer using StringRef's API.
+  llvm::APInt Fill;
+  std::string Str;
+  assert(Arg.getNumElems() >= 1);
+  for (unsigned I = 0;; ++I) {
+const Pointer &Elem = Arg.atIndex(I);
+
+if (!CheckLoad(S, OpPC, Elem))
+  return false;
+
+if (Elem.deref() == 0)
+  break;
+
+Str += Elem.deref();
+  }
+
+  // Treat empty strings as if they were zero.
+  if (Str.empty())
+Fill = llvm::APInt(32, 0);
+  else if (StringRef(Str).getAsInteger(0, Fill))
+return false;
+
+  const llvm::fltSemantics &TargetSemantics =
+  S.getCtx().getFloatTypeSemantics(F->getDecl()->getReturnType());
+
+  Floating Result;
+  if (S.getCtx().getTargetInfo().isNan2008()) {
+if (Signaling)
+  Result = Floating(
+  llvm::APFloat::getSNaN(TargetSemantics, /*Negative=*/false, &Fill));
+else
+  Result = Floating(
+  llvm::APFloat::getQNaN(TargetSemantics, /*Negative=*/false, &Fill));
+  } else {
+// Prior to IEEE 754-2008, architectures were allowed to choose whether
+// the first bit of their significand was set for qNaN or sNaN. MIPS chose
+// a different encoding to what became a standard in 2008, and for pre-
+// 2008 revisions, MIPS interpreted sNaN-2008 as qNan and qNaN-2008 as
+// sNaN. This is now known as "legacy NaN" encoding.
+if (Signaling)
+  Result = Floating(
+  llvm::APFloat::getQNaN(TargetSemantics, /*Negative=*/false, &Fill));
+else
+  Result = Floating(
+  llvm::APFloat::getSNaN(TargetSemantics, /*Negative=*/false, &Fill));
+  }
+
+  S.Stk.push(Result);
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -70,7 +132,24 @@
   case Builtin::BI__builtin_strcmp:
 if (interp__builtin_strcmp(S, OpPC, Frame))
   return Ret(S, OpPC, 

[PATCH] D155955: [Clang] Improve the handling of large arrays evaluation.

2023-07-26 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@efriedma You still have objection to landing that now with the goal to 
backport later in the release process? Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155955

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


[clang] bc37893 - [clang][dataflow] fix bug for transparent ListInitExpr handling

2023-07-26 Thread Paul Semel via cfe-commits

Author: Paul Semel
Date: 2023-07-26T08:50:28Z
New Revision: bc37893433d35b1448c5d4628d932fafec92efd0

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

LOG: [clang][dataflow] fix bug for transparent ListInitExpr handling

This fixes the handling of "transparent" ListInitExpr, when they're only
used as a copy constructor for records.

Without the fix, the two tests are crashing the process.

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 39faeca4b45ce3..0b7c22fe24e301 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -637,6 +637,13 @@ class TransferVisitor : public 
ConstStmtVisitor {
   return;
 }
 
+// In case the initializer list is transparent, we just need to propagate
+// the value that it contains.
+if (S->isSemanticForm() && S->isTransparent()) {
+  propagateValue(*S->getInit(0), *S, Env);
+  return;
+}
+
 std::vector Fields =
 getFieldsForInitListExpr(Type->getAsRecordDecl());
 llvm::DenseMap FieldLocs;

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index edd015bbf10937..5acb28bd87abff 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2183,6 +2183,39 @@ TEST(TransferTest, CopyConstructorWithParens) {
   });
 }
 
+TEST(TransferTest, CopyConstructorWithInitializerListAsSyntacticSugar) {
+  std::string Code = R"(
+  struct A {
+int Baz;
+  };
+  void target() {
+A Foo = {3};
+(void)Foo.Baz;
+A Bar = {A(Foo)};
+// [[p]]
+  }
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+
+const auto &FooLoc =
+getLocForDecl(ASTCtx, Env, "Foo");
+const auto &BarLoc =
+getLocForDecl(ASTCtx, Env, "Bar");
+
+const auto *FooBazVal =
+cast(getFieldValue(&FooLoc, *BazDecl, Env));
+const auto *BarBazVal =
+cast(getFieldValue(&BarLoc, *BazDecl, Env));
+EXPECT_EQ(FooBazVal, BarBazVal);
+  });
+}
+
 TEST(TransferTest, CopyConstructorArgIsRefReturnedByFunction) {
   // This is a crash repro.
   std::string Code = R"(



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


[clang] 145f353 - [clang][dataflow] fix failing assert in copyRecord

2023-07-26 Thread Paul Semel via cfe-commits

Author: Paul Semel
Date: 2023-07-26T08:52:06Z
New Revision: 145f353fd67909e03c39b968b464ac625edde6cb

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

LOG: [clang][dataflow] fix failing assert in copyRecord

When dealing with copy constructor, the compiler can emit an
UncheckedDerivedToBase implicit cast for the CXXConstructorExpr of the
base class. In such case, when trying to copy the src storage location
to its destination, we will fail on the assert checking that location
types are the same.

When copying from derived to base class, it is acceptable to break that
assumption to only copy common fields from the base class.

Note: the provided test crashes the process without the changes made to
copyRecord.

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/RecordOps.cpp
clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/RecordOps.cpp 
b/clang/lib/Analysis/FlowSensitive/RecordOps.cpp
index 60144531c25186..95693f2e933a49 100644
--- a/clang/lib/Analysis/FlowSensitive/RecordOps.cpp
+++ b/clang/lib/Analysis/FlowSensitive/RecordOps.cpp
@@ -17,18 +17,27 @@
 void clang::dataflow::copyRecord(AggregateStorageLocation &Src,
  AggregateStorageLocation &Dst,
  Environment &Env) {
+  auto SrcType = Src.getType().getCanonicalType().getUnqualifiedType();
+  auto DstType = Dst.getType().getCanonicalType().getUnqualifiedType();
+
+  auto SrcDecl = SrcType->getAsCXXRecordDecl();
+  auto DstDecl = DstType->getAsCXXRecordDecl();
+
+  bool compatibleTypes =
+  SrcType == DstType ||
+  (SrcDecl && DstDecl && SrcDecl->isDerivedFrom(DstDecl));
+  (void)compatibleTypes;
+
   LLVM_DEBUG({
-if (Dst.getType().getCanonicalType().getUnqualifiedType() !=
-Src.getType().getCanonicalType().getUnqualifiedType()) {
+if (!compatibleTypes) {
   llvm::dbgs() << "Source type " << Src.getType() << "\n";
   llvm::dbgs() << "Destination type " << Dst.getType() << "\n";
 }
   });
-  assert(Dst.getType().getCanonicalType().getUnqualifiedType() ==
- Src.getType().getCanonicalType().getUnqualifiedType());
+  assert(compatibleTypes);
 
-  for (auto [Field, SrcFieldLoc] : Src.children()) {
-StorageLocation *DstFieldLoc = Dst.getChild(*Field);
+  for (auto [Field, DstFieldLoc] : Dst.children()) {
+StorageLocation *SrcFieldLoc = Src.getChild(*Field);
 
 assert(Field->getType()->isReferenceType() ||
(SrcFieldLoc != nullptr && DstFieldLoc != nullptr));

diff  --git a/clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
index 2b4b64c74481fb..b4eb0f26bf76be 100644
--- a/clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
@@ -194,6 +194,40 @@ TEST(RecordOpsTest, RecordsEqual) {
   });
 }
 
+TEST(TransferTest, CopyRecordFromDerivedToBase) {
+  std::string Code = R"(
+struct A {
+  int i;
+};
+
+struct B : public A {
+};
+
+void target(A a, B b) {
+  (void)a.i;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+Environment Env = getEnvironmentAtAnnotation(Results, "p").fork();
+
+const ValueDecl *IDecl = findValueDecl(ASTCtx, "i");
+auto &A = getLocForDecl(ASTCtx, Env, "a");
+auto &B = getLocForDecl(ASTCtx, Env, "b");
+
+EXPECT_NE(Env.getValue(*A.getChild(*IDecl)),
+  Env.getValue(*B.getChild(*IDecl)));
+
+copyRecord(B, A, Env);
+
+EXPECT_EQ(Env.getValue(*A.getChild(*IDecl)),
+  Env.getValue(*B.getChild(*IDecl)));
+  });
+}
+
 } // namespace
 } // namespace test
 } // namespace dataflow



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


[PATCH] D155844: [clang][dataflow] fix failing assert in copyRecord

2023-07-26 Thread Paul Semel via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG145f353fd679: [clang][dataflow] fix failing assert in 
copyRecord (authored by paulsemel).
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155844

Files:
  clang/lib/Analysis/FlowSensitive/RecordOps.cpp
  clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
@@ -194,6 +194,40 @@
   });
 }
 
+TEST(TransferTest, CopyRecordFromDerivedToBase) {
+  std::string Code = R"(
+struct A {
+  int i;
+};
+
+struct B : public A {
+};
+
+void target(A a, B b) {
+  (void)a.i;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+Environment Env = getEnvironmentAtAnnotation(Results, "p").fork();
+
+const ValueDecl *IDecl = findValueDecl(ASTCtx, "i");
+auto &A = getLocForDecl(ASTCtx, Env, "a");
+auto &B = getLocForDecl(ASTCtx, Env, "b");
+
+EXPECT_NE(Env.getValue(*A.getChild(*IDecl)),
+  Env.getValue(*B.getChild(*IDecl)));
+
+copyRecord(B, A, Env);
+
+EXPECT_EQ(Env.getValue(*A.getChild(*IDecl)),
+  Env.getValue(*B.getChild(*IDecl)));
+  });
+}
+
 } // namespace
 } // namespace test
 } // namespace dataflow
Index: clang/lib/Analysis/FlowSensitive/RecordOps.cpp
===
--- clang/lib/Analysis/FlowSensitive/RecordOps.cpp
+++ clang/lib/Analysis/FlowSensitive/RecordOps.cpp
@@ -17,18 +17,27 @@
 void clang::dataflow::copyRecord(AggregateStorageLocation &Src,
  AggregateStorageLocation &Dst,
  Environment &Env) {
+  auto SrcType = Src.getType().getCanonicalType().getUnqualifiedType();
+  auto DstType = Dst.getType().getCanonicalType().getUnqualifiedType();
+
+  auto SrcDecl = SrcType->getAsCXXRecordDecl();
+  auto DstDecl = DstType->getAsCXXRecordDecl();
+
+  bool compatibleTypes =
+  SrcType == DstType ||
+  (SrcDecl && DstDecl && SrcDecl->isDerivedFrom(DstDecl));
+  (void)compatibleTypes;
+
   LLVM_DEBUG({
-if (Dst.getType().getCanonicalType().getUnqualifiedType() !=
-Src.getType().getCanonicalType().getUnqualifiedType()) {
+if (!compatibleTypes) {
   llvm::dbgs() << "Source type " << Src.getType() << "\n";
   llvm::dbgs() << "Destination type " << Dst.getType() << "\n";
 }
   });
-  assert(Dst.getType().getCanonicalType().getUnqualifiedType() ==
- Src.getType().getCanonicalType().getUnqualifiedType());
+  assert(compatibleTypes);
 
-  for (auto [Field, SrcFieldLoc] : Src.children()) {
-StorageLocation *DstFieldLoc = Dst.getChild(*Field);
+  for (auto [Field, DstFieldLoc] : Dst.children()) {
+StorageLocation *SrcFieldLoc = Src.getChild(*Field);
 
 assert(Field->getType()->isReferenceType() ||
(SrcFieldLoc != nullptr && DstFieldLoc != nullptr));


Index: clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
@@ -194,6 +194,40 @@
   });
 }
 
+TEST(TransferTest, CopyRecordFromDerivedToBase) {
+  std::string Code = R"(
+struct A {
+  int i;
+};
+
+struct B : public A {
+};
+
+void target(A a, B b) {
+  (void)a.i;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+Environment Env = getEnvironmentAtAnnotation(Results, "p").fork();
+
+const ValueDecl *IDecl = findValueDecl(ASTCtx, "i");
+auto &A = getLocForDecl(ASTCtx, Env, "a");
+auto &B = getLocForDecl(ASTCtx, Env, "b");
+
+EXPECT_NE(Env.getValue(*A.getChild(*IDecl)),
+  Env.getValue(*B.getChild(*IDecl)));
+
+copyRecord(B, A, Env);
+
+EXPECT_EQ(Env.getValue(*A.getChild(*IDecl)),
+  Env.getValue(*B.getChild(*IDecl)));
+  });
+}
+
 } // namespace
 } // namespace test
 } // namespace dataflow
Index: clang/lib/Analysis/FlowSensitive/RecordOps.cpp
===
--- clang/lib/Analysis/FlowSensitive/RecordOps.cpp
+++ clang/lib/Analysis/FlowSensitive/RecordOps.cpp
@@ -17,18 +17,27 @@
 void clang::dataflow::copyRecord(AggregateStorageLocation &Src,
  AggregateStorageLocation &Dst,
 

[PATCH] D155878: [clangd] Loose include-cleaner matching for verbatim headers

2023-07-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Headers.cpp:185
+  // The entries will be the same, but canonicalizing to find out is expensive!
+  if (SearchPathCanonical.empty()) {
+for (const auto &Dir :

nit: early exit



Comment at: clang-tools-extra/clangd/Headers.h:179
+  // All paths are canonical (FileManager::getCanonicalPath()).
+  std::vector SearchPathCanonical;
+

s/SearchPathCanonical/SearchPathsCanonical/



Comment at: clang-tools-extra/clangd/Hover.cpp:1250
   const SourceManager &SM = AST.getSourceManager();
-  const auto &ConvertedMainFileIncludes =
-  convertIncludes(SM, AST.getIncludeStructure().MainFileIncludes);
-  const auto &HoveredInclude = convertIncludes(SM, llvm::ArrayRef{Inc});
+  const auto &Converted = convertIncludes(AST);
   llvm::DenseSet UsedSymbols;

oops, looks like we were getting away with some dangling references.
the reference here is wrong, `convertIncludes` returns a value type. can you 
fix that while here?



Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:486-491
+  include_cleaner::walkUsed(AST.getLocalTopLevelDecls(), {},
+AST.getPragmaIncludes(), AST.getSourceManager(),
+[&](const include_cleaner::SymbolReference &Ref,
+llvm::ArrayRef P) {
+  Providers[llvm::to_string(Ref.Target)] = P.vec();
+});

i don't think making this test rely on `walkUsed` is a good idea. what about 
just populating the providers directly, like:

```
EXPECT_TRUE(isPreferredProvider(Decl, Includes, 
{include_cleaner::Header{"decl.h"}, include_cleaner::Header{"def.h"}}));
```

and verifying we're recognizing preferred providers purely on that ordering ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155878

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


[PATCH] D156222: [NFC][clang] Fix static analyzer concerns

2023-07-26 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 544262.
Fznamznon added a comment.

Rebase to maybe pass precommit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156222

Files:
  clang/lib/Sema/TypeLocBuilder.h


Index: clang/lib/Sema/TypeLocBuilder.h
===
--- clang/lib/Sema/TypeLocBuilder.h
+++ clang/lib/Sema/TypeLocBuilder.h
@@ -53,6 +53,9 @@
   delete[] Buffer;
   }
 
+  TypeLocBuilder(const TypeLocBuilder &) = delete;
+  TypeLocBuilder &operator=(const TypeLocBuilder &) = delete;
+
   /// Ensures that this buffer has at least as much capacity as described.
   void reserve(size_t Requested) {
 if (Requested > Capacity)


Index: clang/lib/Sema/TypeLocBuilder.h
===
--- clang/lib/Sema/TypeLocBuilder.h
+++ clang/lib/Sema/TypeLocBuilder.h
@@ -53,6 +53,9 @@
   delete[] Buffer;
   }
 
+  TypeLocBuilder(const TypeLocBuilder &) = delete;
+  TypeLocBuilder &operator=(const TypeLocBuilder &) = delete;
+
   /// Ensures that this buffer has at least as much capacity as described.
   void reserve(size_t Requested) {
 if (Requested > Capacity)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156303: [clang-tidy] Remove AnalyzeTemporaryDestructors configuration option

2023-07-26 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp created this revision.
Herald added subscribers: PiotrZSL, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
carlosgalvezp requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Since it was deprecated since clang-tidy 16.

Fixes #62020


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156303

Files:
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp


Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -81,7 +81,6 @@
   "HeaderFileExtensions: [\"\",\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
   "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
   "HeaderFilterRegex: \".*\"\n"
-  "AnalyzeTemporaryDtors: true\n"
   "User: some.user",
   "Options"));
   EXPECT_TRUE(!!Options);
@@ -115,7 +114,6 @@
   HeaderFileExtensions: ["h","hh"]
   ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
-  AnalyzeTemporaryDtors: true
   User: user1
   ExtraArgs: ['arg1', 'arg2']
   ExtraArgsBefore: ['arg-before1', 'arg-before2']
@@ -130,7 +128,6 @@
   HeaderFileExtensions: ["hpp","hxx"]
   ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
-  AnalyzeTemporaryDtors: false
   User: user2
   ExtraArgs: ['arg3', 'arg4']
   ExtraArgsBefore: ['arg-before3', 'arg-before4']
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -108,6 +108,9 @@
   functionality using the newly added command line option
   `--enable-module-headers-parsing`.
 
+- Remove configuration option `AnalyzeTemporaryDestructors`, which was 
deprecated since
+  :program:`clang-tidy` 16.
+
 New checks
 ^^
 
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -157,14 +157,12 @@
 
 template <> struct MappingTraits {
   static void mapping(IO &IO, ClangTidyOptions &Options) {
-bool Ignored = false;
 mapChecks(IO, Options.Checks);
 IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors);
 IO.mapOptional("HeaderFileExtensions", Options.HeaderFileExtensions);
 IO.mapOptional("ImplementationFileExtensions",
Options.ImplementationFileExtensions);
 IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
-IO.mapOptional("AnalyzeTemporaryDtors", Ignored); // deprecated
 IO.mapOptional("FormatStyle", Options.FormatStyle);
 IO.mapOptional("User", Options.User);
 IO.mapOptional("CheckOptions", Options.CheckOptions);


Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -81,7 +81,6 @@
   "HeaderFileExtensions: [\"\",\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
   "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
   "HeaderFilterRegex: \".*\"\n"
-  "AnalyzeTemporaryDtors: true\n"
   "User: some.user",
   "Options"));
   EXPECT_TRUE(!!Options);
@@ -115,7 +114,6 @@
   HeaderFileExtensions: ["h","hh"]
   ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
-  AnalyzeTemporaryDtors: true
   User: user1
   ExtraArgs: ['arg1', 'arg2']
   ExtraArgsBefore: ['arg-before1', 'arg-before2']
@@ -130,7 +128,6 @@
   HeaderFileExtensions: ["hpp","hxx"]
   ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
-  AnalyzeTemporaryDtors: false
   User: user2
   ExtraArgs: ['arg3', 'arg4']
   ExtraArgsBefore: ['arg-before3', 'arg-before4']
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -108,6 +108,9 @@
   functionality using the newly added command line option
   `--enable-module-headers-parsing`.
 
+- Remove configuration option `AnalyzeTemporaryDestructors`, which was deprecated since
+  :program:`clang-tidy` 16.
+
 New checks
 ^^
 
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===
--- c

[PATCH] D142660: [AIX] supporting -X options for llvm-ranlib in AIX OS

2023-07-26 Thread James Henderson via Phabricator via cfe-commits
jhenderson added inline comments.



Comment at: llvm/test/tools/llvm-ranlib/aix-X-option.test:68
+
+## Test the invalid -X option and OBJECT_MODE enviornment var.
+# RUN: not env OBJECT_MODE= llvm-ranlib t_X32.a 2>&1 | FileCheck 
--implicit-check-not="error:"  --check-prefixes=INVALID-OBJECT-MODE %s

Actually, you shouldn't have added "the" here. The grammatical rules are a 
little tricky to explain, so I won't bother, but you should actually say "Test 
invalid -X options and OBJECT_MODE environment variables."



Comment at: llvm/test/tools/llvm-ranlib/aix-X-option.test:17-18
+## Test the OBJECT_MODE environment variable when adding symbol table.
+# RUN: unset OBJECT_MODE
+# RUN: llvm-ranlib t_X32.a
+# RUN: llvm-nm --print-armap t_X32.a 2>&1 | FileCheck --check-prefixes=GLOB32 
--implicit-check-not="in t64" %s

DiggerLin wrote:
> jhenderson wrote:
> > Assuming the unsetting is intended to be just for the llvm-ranlib line, I 
> > believe the preferred approach is `env -u OBJECT_MODE llvm-ranlib ...`. 
> > That way, you don't impact the behaviour in subsequent lines.
> the command `env` of AIX OS do not support -u.  and there is no mapping  
> option of `env -u`
> 
> https://www.ibm.com/docs/en/aix/7.2?topic=e-env-command
I'm 90% certain that `env` here is the built-in lit `env`, not a system `env` 
executable. `env -u` seems to be only rarely used in the test suite, but see 
llvm/utils/lit/tests/Inputs/shtest-env/env-u.txt for an example. I assume you 
can run this test locally?



Comment at: llvm/tools/llvm-ar/llvm-ar.cpp:1442
+
+// -X option in ranlib do not accept "any"
+if (BitMode == BitModeTy::Unknown || BitMode == BitModeTy::Any)

DiggerLin wrote:
> jhenderson wrote:
> > DiggerLin wrote:
> > > jhenderson wrote:
> > > > I know that AIX ranlib doesn't accept "any" whereas I believe AIX ar 
> > > > does. I wonder though what the benefit is of preventing llvm-ranlib 
> > > > from accepting "any"? Dropping that special case would simplify the 
> > > > code.
> > > agree with you. but we discussed about whether to accept `any` in our 
> > > internal , we decide to keep all the behavior  as AIX `ranlib`
> > > we decide to keep all the behavior as AIX ranlib
> > 
> > We aren't in your internal company here. This is the open source community, 
> > therefore you need to be able to justify your decisions in the open source 
> > conversation. What reason is there to keep rejecting this in llvm-ranlib? 
> > Perhaps worth asking yourself is "if we could control it, why would we keep 
> > that behaviour in AIX ranlib?".
> according to 
> https://www.ibm.com/docs/en/aix/7.1?topic=ar-command
> 
> -X mode , there is `32`, `64`, `32_64`, `d64`, any mode
> 
> d64
> Examines discontinued 64-bit XCOFF files (magic number == U803XTOCMAGIC).
> 
> we do not support `d64`in llvm(since it is discontinued), but we keep `any`  
> option in llvm-ar in case of we want to use llvm-ar to replace AIX `ar`  in 
> some AIX shell script which has option `any` for ar (`any = 32_64 + d64`),  
> we do no want to modify the option from `any` to `32_64` for AIX shell 
> script, so we keep the `any` option for llvm-ar.
> 
> for AIX `ranlib`, https://www.ibm.com/docs/en/aix/7.2?topic=r-ranlib-command 
> . it only support 32,64,32_64, It do not support `d64`, so there is no `any` 
> option for AIX `ranlib`, we do not need to add a additional `any` for 
> llvm-ranlib 
> we do not need to add a additional any for llvm-ranlib

As noted earlier, adding an `any` value would align llvm-ranlib and llvm-ar's 
command-line options, allowing the code to be simpler. It doesn't break 
existing users by permitting it either. You have explained why you aren't 
accepting it, but not actually what the benefit is of that approach. What is 
the benefit of NOT accepting `any` in llvm-ranlib?



Comment at: llvm/tools/llvm-ar/llvm-ar.cpp:1463
 
+  if (object::Archive::getDefaultKindForHost() == object::Archive::K_AIXBIG) {
+// If not specify -X option, get BitMode from enviorment variable

DiggerLin wrote:
> jhenderson wrote:
> > DiggerLin wrote:
> > > jhenderson wrote:
> > > > Is there a particular reason that this is after the command-line option 
> > > > parsing for llvm-ranlib, but before it in llvm-ar? If this were before 
> > > > the option parsing, you wouldn't need the `HasAixXOption` variable.
> > > in AIX OS  `ranlib` has behavior as
> > > 
> > > 
> > > ```
> > > -bash-5.0$ env OBJECT_MODE=31 ranlib tmpk.a
> > > 0654-603 The OBJECT_MODE environment variable has an invalid setting.
> > > OBJECT_MODE must be 32, 64, or 32_64.
> > > -bash-5.0$ env OBJECT_MODE=31 ranlib -X32  tmpk.a
> > > -bash-5.0$
> > > ```  
> > > 
> > > Given invalid env OBJECT_MODE , if there is no -X option in the ranlib 
> > > command, it will output as 
> > > 
> > > ```
> > > 0654-603 The OBJECT_MODE environment variable

[clang] 2ca7416 - [clang][DeclPrinter] Fix AST print of delegating constructors

2023-07-26 Thread Timo Stripf via cfe-commits

Author: Timo Stripf
Date: 2023-07-26T09:26:53Z
New Revision: 2ca74162258b6e808e84d6700a5613c0cbf6efe9

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

LOG: [clang][DeclPrinter] Fix AST print of delegating constructors

DeclPrinter::PrintConstructorInitializers did not consider delegating 
initializers. As result, the output contained an "NULL TYPE" for delegating 
constructors.

Reviewed By: aaron.ballman

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

Added: 
clang/test/AST/ast-print-method-decl.cpp

Modified: 
clang/lib/AST/DeclPrinter.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index a6a9911c8992aa..de33d79eeb484e 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -321,6 +321,8 @@ void 
DeclPrinter::PrintConstructorInitializers(CXXConstructorDecl *CDecl,
 if (BMInitializer->isAnyMemberInitializer()) {
   FieldDecl *FD = BMInitializer->getAnyMember();
   Out << *FD;
+} else if (BMInitializer->isDelegatingInitializer()) {
+  Out << CDecl->getNameAsString();
 } else {
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }

diff  --git a/clang/test/AST/ast-print-method-decl.cpp 
b/clang/test/AST/ast-print-method-decl.cpp
new file mode 100644
index 00..4a3f5440fe158b
--- /dev/null
+++ b/clang/test/AST/ast-print-method-decl.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
+
+// CHECK: struct A {
+struct A {
+  // CHECK-NEXT: A();
+  A();
+
+  // CHECK-NEXT: A(int) : A() {
+  A(int) : A() {
+// CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+
+// CHECK: struct B {
+struct B {
+  // CHECK-NEXT: template  B(Ty);
+  template  B(Ty);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK-NEXT: template<> B(float);
+
+  // CHECK-NEXT: B(int X) : B((float)X) {
+  B(int X) : B((float)X) {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+// CHECK: struct C {
+struct C {
+  // FIXME: template <> should not be output
+  // CHECK: template <> C(auto);
+  C(auto);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK: template<> C(const char *);
+
+  // CHECK: C(int) : C("") {
+  C(int) : C("") {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};



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


[PATCH] D154186: [clang][DeclPrinter] Fix AST print of delegating constructors

2023-07-26 Thread Timo Stripf via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2ca74162258b: [clang][DeclPrinter] Fix AST print of 
delegating constructors (authored by strimo378).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154186

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- /dev/null
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
+
+// CHECK: struct A {
+struct A {
+  // CHECK-NEXT: A();
+  A();
+
+  // CHECK-NEXT: A(int) : A() {
+  A(int) : A() {
+// CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+
+// CHECK: struct B {
+struct B {
+  // CHECK-NEXT: template  B(Ty);
+  template  B(Ty);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK-NEXT: template<> B(float);
+
+  // CHECK-NEXT: B(int X) : B((float)X) {
+  B(int X) : B((float)X) {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+// CHECK: struct C {
+struct C {
+  // FIXME: template <> should not be output
+  // CHECK: template <> C(auto);
+  C(auto);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK: template<> C(const char *);
+
+  // CHECK: C(int) : C("") {
+  C(int) : C("") {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -321,6 +321,8 @@
 if (BMInitializer->isAnyMemberInitializer()) {
   FieldDecl *FD = BMInitializer->getAnyMember();
   Out << *FD;
+} else if (BMInitializer->isDelegatingInitializer()) {
+  Out << CDecl->getNameAsString();
 } else {
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- /dev/null
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
+
+// CHECK: struct A {
+struct A {
+  // CHECK-NEXT: A();
+  A();
+
+  // CHECK-NEXT: A(int) : A() {
+  A(int) : A() {
+// CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+
+// CHECK: struct B {
+struct B {
+  // CHECK-NEXT: template  B(Ty);
+  template  B(Ty);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK-NEXT: template<> B(float);
+
+  // CHECK-NEXT: B(int X) : B((float)X) {
+  B(int X) : B((float)X) {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+// CHECK: struct C {
+struct C {
+  // FIXME: template <> should not be output
+  // CHECK: template <> C(auto);
+  C(auto);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK: template<> C(const char *);
+
+  // CHECK: C(int) : C("") {
+  C(int) : C("") {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -321,6 +321,8 @@
 if (BMInitializer->isAnyMemberInitializer()) {
   FieldDecl *FD = BMInitializer->getAnyMember();
   Out << *FD;
+} else if (BMInitializer->isDelegatingInitializer()) {
+  Out << CDecl->getNameAsString();
 } else {
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156247: [Clang] Add a warning on uses of coroutine keywords

2023-07-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Thanks for the quick feedback!
I understand that this goes against common practice in Clang, but the reason we 
want this warning is very practical.

At Google, we would like to postpone adoption of coroutines until the 
aforementioned bugs are fixed, but we feel that Clang 17 would be a good 
candidate to enable other C++20 features (sans Modules).
We could have landed a local patch with a similar warning in our main toolchain 
that we control tightly. However, we want to have it for other toolchains (e.g. 
Apple Clang) that are based on upstream and we do not control.

Some code is compiled both by the main toolchain and Apple Clang and we want to 
have a way to enforce in the compiler that this code does not use coroutines, 
but is still compiled as C++20.
We are taking a very cautious approach here (the bugs above are rare), but we 
feel it is warranted given the amount of C++ users that we have.
I do not propose to have flags like this for every single feature, but for 
pragmatic reasons I think it makes sense to have it for coroutines in Clang 17.

In D156247#4532478 , @cor3ntin wrote:

> We usually reserve these warnings for feature backported to older c++ 
> standards, and I'm not sure "you are using a standard feature" is in general 
> a useful warning.

I agree that is weird, but it's not unprecedented: designated initializers are 
exactly like that .
Maybe there is a different warning wording and flag that would suit this better?

In D156247#4533848 , @ChuanqiXu wrote:

>> however, if there are important unresolved issues, why did we set 
>> __cpp_impl_coroutine ?
>
> The discussion is here: 
> https://discourse.llvm.org/t/rfc-could-we-mark-coroutines-as-unreleased-now/69220.
>  My short summary may be:
> (1) It is not necessary to claim a feature is completed only after there is 
> no related open issues. For example, GCC claims coroutines (and many other 
> features) as completed in the early stage and there are still many following 
> bug reports then. 
> (2) Coroutines are used widely and deeply around the C++ world. People from 
> Meta (Meta should be, at least, one of the most heavy user of coroutines in 
> the past years) said they would love to approve to the idea even if it is not 
> bug free.

I also feel this is the right call, coroutines are very much usable and we have 
been experimenting with them at Google for a more than a year too.
However, scale matters. Our stance is that bugs above are not blockers for one 
or two projects with experts that can deal with compiler bugs, but they are 
blockers for allowing all our C++ users to use coroutines.

A few questions for the reviewers to understand how to move forward:

- Does the use-case mentioned above makes sense (allow C++20, disallow 
coroutines for code using Clang 17)?
- Is the warning on coroutines a proper way to solve this in Clang or are there 
alternative approaches we should consider?




Comment at: clang/include/clang/Basic/DiagnosticGroups.td:308
 def : DiagGroup<"c++98-c++11-c++14-c++17-compat", [CXXPre20Compat]>;
+def CXXPre20CompatCoroutines : DiagGroup<"pre-c++20-compat-coroutines">;
 def CXXPre20CompatPedantic : DiagGroup<"pre-c++20-compat-pedantic",

aaron.ballman wrote:
> We don't typically give these their own warning group (it's also not clear 
> why this would be a pedantic warning `warn_cxx17_compat_designated_init` is 
> incorrect).
The reason for a separate warning group is to have a way to detect and prevent 
(via `-Werror`) the use of coroutines, but not other features.
`Wpre-c++20-compat-coroutines` might be a totally wrong name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156247

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


[clang] d913aa6 - [clang][Interp][NFC] Make a local function static

2023-07-26 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-26T11:50:07+02:00
New Revision: d913aa6971c582724a2ba71689fe4908a951e935

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

LOG: [clang][Interp][NFC] Make a local function static

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index dbefcbf961dd28..e161a0681dcfa4 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -13,7 +13,8 @@
 namespace clang {
 namespace interp {
 
-template  T getParam(const InterpFrame *Frame, unsigned Index) {
+template 
+static T getParam(const InterpFrame *Frame, unsigned Index) {
   unsigned Offset = Frame->getFunction()->getParamOffset(Index);
   return Frame->getParam(Offset);
 }



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


[clang] e9eb836 - [clang][Interp][NFC] Add an assertion

2023-07-26 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-26T11:50:07+02:00
New Revision: e9eb8362f0a580ba8a4cb173b6e8414a6d1a4db4

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

LOG: [clang][Interp][NFC] Add an assertion

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index e161a0681dcfa4..b29747221ab552 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -15,6 +15,7 @@ namespace interp {
 
 template 
 static T getParam(const InterpFrame *Frame, unsigned Index) {
+  assert(Frame->getFunction()->getNumParams() > Index);
   unsigned Offset = Frame->getFunction()->getParamOffset(Index);
   return Frame->getParam(Offset);
 }



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


[clang] 744a968 - [clang][Interp] Fix return statements with expresssion in void functions

2023-07-26 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-26T11:50:07+02:00
New Revision: 744a968f91f7bb92594a422c1b71f03a47c2415d

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

LOG: [clang][Interp] Fix return statements with expresssion in void functions

If the return type of a function is void, ReturnType is not set, but we
used to emit a RVOPtr instruction, which doesn't make sense for a
function returning void.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index e5ca5c2ae4c33b..e54805cd931aef 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -309,6 +309,9 @@ bool ByteCodeStmtGen::visitReturnStmt(const 
ReturnStmt *RS) {
 return false;
   this->emitCleanup();
   return this->emitRet(*ReturnType, RS);
+} else if (RE->getType()->isVoidType()) {
+  if (!this->visit(RE))
+return false;
 } else {
   // RVO - construct the value in the return location.
   if (!this->emitRVOPtr(RE))

diff  --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index 4bb8791de8f4e5..3540791917fab1 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -291,3 +291,12 @@ namespace ReturnLocalPtr {
  // ref-note {{read of variable whose lifetime 
has ended}} \
  // expected-error {{not an integral constant 
expression}}
 }
+
+namespace VoidReturn {
+  /// ReturnStmt with an expression in a void function used to cause problems.
+  constexpr void bar() {}
+  constexpr void foo() {
+return bar();
+  }
+  static_assert((foo(),1) == 1, "");
+}



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


[PATCH] D153649: [clang][Interp] Fix return statements with expresssion in void functions

2023-07-26 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG744a968f91f7: [clang][Interp] Fix return statements with 
expresssion in void functions (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D153649?vs=534021&id=544274#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153649

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


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -291,3 +291,12 @@
  // ref-note {{read of variable whose lifetime 
has ended}} \
  // expected-error {{not an integral constant 
expression}}
 }
+
+namespace VoidReturn {
+  /// ReturnStmt with an expression in a void function used to cause problems.
+  constexpr void bar() {}
+  constexpr void foo() {
+return bar();
+  }
+  static_assert((foo(),1) == 1, "");
+}
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -309,6 +309,9 @@
 return false;
   this->emitCleanup();
   return this->emitRet(*ReturnType, RS);
+} else if (RE->getType()->isVoidType()) {
+  if (!this->visit(RE))
+return false;
 } else {
   // RVO - construct the value in the return location.
   if (!this->emitRVOPtr(RE))


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -291,3 +291,12 @@
  // ref-note {{read of variable whose lifetime has ended}} \
  // expected-error {{not an integral constant expression}}
 }
+
+namespace VoidReturn {
+  /// ReturnStmt with an expression in a void function used to cause problems.
+  constexpr void bar() {}
+  constexpr void foo() {
+return bar();
+  }
+  static_assert((foo(),1) == 1, "");
+}
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -309,6 +309,9 @@
 return false;
   this->emitCleanup();
   return this->emitRet(*ReturnType, RS);
+} else if (RE->getType()->isVoidType()) {
+  if (!this->visit(RE))
+return false;
 } else {
   // RVO - construct the value in the return location.
   if (!this->emitRVOPtr(RE))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156205: wasm: link crt1 even in case of -shared

2023-07-26 Thread YAMAMOTO Takashi via Phabricator via cfe-commits
yamt updated this revision to Diff 544275.
yamt added a comment.

update test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156205

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.c


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -33,19 +33,19 @@
 // LINK_KNOWN: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
 // LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" 
"-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
 
-// -shared should be passed through to `wasm-ld` and not include crt1.o with a 
known OS.
+// -shared should be passed through to `wasm-ld` and include crt1-reactor.o 
with a known OS.
 
-// RUN: %clang -### -shared --target=wasm32-wasi --sysroot=/foo %s 2>&1 \
+// RUN: %clang -### -shared -mexec-model=reactor --target=wasm32-wasi 
--sysroot=/foo %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=LINK_KNOWN_SHARED %s
 // LINK_KNOWN_SHARED: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_KNOWN_SHARED: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-shared" 
"[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_KNOWN_SHARED: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1-reactor.o" 
"--entry" "_initialize" "-shared" "[[temp]]" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
 
-// -shared should be passed through to `wasm-ld` and not include crt1.o with 
an unknown OS.
+// -shared should be passed through to `wasm-ld` and include crt1-reactor.o 
with an unknown OS.
 
-// RUN: %clang -### -shared --target=wasm32-unknown-unknown --sysroot=/foo %s 
2>&1 \
+// RUN: %clang -### -shared -mexec-model=reactor 
--target=wasm32-unknown-unknown --sysroot=/foo %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=LINK_UNKNOWN_SHARED %s
 // LINK_UNKNOWN_SHARED: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_UNKNOWN_SHARED: wasm-ld{{.*}}" "-shared" "[[temp]]" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_UNKNOWN_SHARED: wasm-ld{{.*}}" "crt1-reactor.o" "--entry" 
"_initialize" "-shared" "[[temp]]" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
 
 // A basic C link command-line with optimization with known OS.
 
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -101,7 +101,7 @@
   << CM << A->getOption().getName();
 }
   }
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, 
options::OPT_shared))
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles))
 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(Crt1)));
   if (Entry) {
 CmdArgs.push_back(Args.MakeArgString("--entry"));


Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -33,19 +33,19 @@
 // LINK_KNOWN: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
 // LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
 
-// -shared should be passed through to `wasm-ld` and not include crt1.o with a known OS.
+// -shared should be passed through to `wasm-ld` and include crt1-reactor.o with a known OS.
 
-// RUN: %clang -### -shared --target=wasm32-wasi --sysroot=/foo %s 2>&1 \
+// RUN: %clang -### -shared -mexec-model=reactor --target=wasm32-wasi --sysroot=/foo %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=LINK_KNOWN_SHARED %s
 // LINK_KNOWN_SHARED: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_KNOWN_SHARED: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_KNOWN_SHARED: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1-reactor.o" "--entry" "_initialize" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
 
-// -shared should be passed through to `wasm-ld` and not include crt1.o with an unknown OS.
+// -shared should be passed through to `wasm-ld` and include crt1-reactor.o with an unknown OS.
 
-// RUN: %clang -### -shared --target=wasm32-unknown-unknown --sysroot=/foo %s 2>&1 \
+// RUN: %clang -### -shared -mexec-model=reactor --target=wasm32-unknown-unknown --sysroot=/foo %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=LINK_UNKNOWN_SHARED %s
 // LINK_UNKNOWN_SHARED: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_UNKNOWN_SHARED: wasm-ld{{.*}}" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_UNKNOWN_SHARED: wasm-ld{{.*}}" "crt1-reactor.o" "--entry" "_initialize" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.ou

[PATCH] D155452: [Flang] Add support for fsave-optimization-record

2023-07-26 Thread victorkingi via Phabricator via cfe-commits
victorkingi updated this revision to Diff 544277.
victorkingi added a comment.

rebasing no changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155452

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CodeGenOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/fsave-optimization-record.f90

Index: flang/test/Driver/fsave-optimization-record.f90
===
--- /dev/null
+++ flang/test/Driver/fsave-optimization-record.f90
@@ -0,0 +1,59 @@
+! Tests for the '-f[no-]save-optimization-record[=]' flag.
+
+! Test opt_record flags get generated for fc1
+! RUN: %flang -### %s 2>&1 \
+! RUN: -foptimization-record-file=%t.opt.yaml \
+! RUN:   | FileCheck --check-prefix=YAML %s
+
+! RUN: %flang -### %s 2>&1 \
+! RUN: -fsave-optimization-record \
+! RUN:   | FileCheck --check-prefix=YAML %s
+
+
+! Test -foptimization-record-file produces YAML file with given content
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -foptimization-record-file=%t.opt.yaml -c %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+
+! Test -fsave-optimization-record produces YAML file with given content
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -c -o %t.o %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -S -o %t.s %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+
+! Produces an empty file
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -S -emit-llvm -o %t.ll %s
+! RUN: cat %t.opt.yaml
+
+
+!Test unknown format produces error
+! RUN: not %flang -fsave-optimization-record=hello %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-FORMAT-ERROR %s
+
+
+! YAML: "-opt-record-file" "{{.+}}.opt.yaml"
+! YAML: "-opt-record-format" "yaml"
+
+! CHECK: --- !Analysis
+! CHECK: Pass:prologepilog
+! CHECK: Name:StackSize
+! CHECK: Function:_QQmain
+! CHECK: Pass:asm-printer
+! CHECK: Name:InstructionMix
+! CHECK: Name:InstructionCount
+
+! CHECK-FORMAT-ERROR: error: unknown remark serializer format: 'hello'
+
+program forttest
+implicit none
+integer :: n
+
+n = 1 * 1
+
+end program forttest
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -54,8 +54,16 @@
 ! HELP-NEXT: -fopenmp-version=
 ! HELP-NEXT:Set OpenMP version (e.g. 45 for OpenMP 4.5, 50 for OpenMP 5.0). Default value is 50 for Clang and 11 for Flang
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
+! HELP-NEXT: -foptimization-record-file=
+! HELP-NEXT:Specify the output name of the file containing the optimization remarks. Implies -fsave-optimization-record. On Darwin platforms, this cannot be used with multiple -arch  options.
+! HELP-NEXT: -foptimization-record-passes=
+! HELP-NEXT:Only include passes which match a specified regular expression in the generated optimization record (by default, include all passes)
 ! HELP-NEXT: -fpass-plugin= Load pass plugin from a dynamic shared object file (only with new pass manager).
 ! HELP-NEXT: -freciprocal-math  Allow division operations to be reassociated
+! HELP-NEXT: -fsave-optimization-record=
+! HELP-NEXT:Generate an optimization record file in a specific format
+! HELP-NEXT: -fsave-optimization-record
+! HELP-NEXT:Generate a YAML optimization record file
 ! HELP-NEXT: -fstack-arrays Attempt to allocate array temporaries on the stack, no matter their size
 ! HELP-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
 ! HELP-NEXT: -funderscoring Appends one trailing underscore to external names
@@ -186,6 +194,12 @@
 ! HELP-FC1-NEXT: -mrelocation-model 
 ! HELP-FC1-NEXT:The relocation model to use
 ! HELP-FC1-NEXT: -nocpp Disable predefined and command line preprocessor macros
+! HELP-FC1-NEXT: -opt-record-file 
+! HELP-FC1-NEXT:File name to use for YAML optimization record output
+! HELP-FC1-NEXT: -opt-record-format 
+! HELP-FC1-NEXT:The format used for serializing remarks (default: YAML)
+! HELP-FC1-NEXT: -opt-record-passes 
+! HELP-FC1-NEXT:Only record remark information for passes whose names match the given regular expression
 ! HELP-FC1-NEXT: -o   Write output to 
 ! HELP-FC1-NEXT: -pedantic  Warn on language extensions
 ! HELP-FC1-NEXT: -pic-is-pie

[PATCH] D156303: [clang-tidy] Remove AnalyzeTemporaryDestructors configuration option

2023-07-26 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156303

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


[PATCH] D156307: [clang][DeclPrinter] Fix AST print of curly constructor initializers

2023-07-26 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156307

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp

Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
 
-// CHECK: struct A {
-struct A {
-  // CHECK-NEXT: A();
-  A();
+// CHECK: struct DelegatingCtor1 {
+struct DelegatingCtor1 {
+  // CHECK-NEXT: DelegatingCtor1();
+  DelegatingCtor1();
 
-  // CHECK-NEXT: A(int) : A() {
-  A(int) : A() {
+  // CHECK-NEXT: DelegatingCtor1(int) : DelegatingCtor1() {
+  DelegatingCtor1(int) : DelegatingCtor1() {
 // CHECK-NEXT: }
   }
 
@@ -14,35 +14,58 @@
 };
 
 
-// CHECK: struct B {
-struct B {
-  // CHECK-NEXT: template  B(Ty);
-  template  B(Ty);
+// CHECK: struct DelegatingCtor2 {
+struct DelegatingCtor2 {
+  // CHECK-NEXT: template  DelegatingCtor2(Ty);
+  template  DelegatingCtor2(Ty);
 
   // FIXME: Implicitly specialized method should not be output
-  // CHECK-NEXT: template<> B(float);
+  // CHECK-NEXT: template<> DelegatingCtor2(float);
 
-  // CHECK-NEXT: B(int X) : B((float)X) {
-  B(int X) : B((float)X) {
+  // CHECK-NEXT: DelegatingCtor2(int X) : DelegatingCtor2((float)X) {
+  DelegatingCtor2(int X) : DelegatingCtor2((float)X) {
   // CHECK-NEXT: }
   }
 
   // CHECK-NEXT: };
 };
 
-// CHECK: struct C {
-struct C {
+// CHECK: struct DelegatingCtor3 {
+struct DelegatingCtor3 {
   // FIXME: template <> should not be output
-  // CHECK: template <> C(auto);
-  C(auto);
+  // CHECK: template <> DelegatingCtor3(auto);
+  DelegatingCtor3(auto);
 
   // FIXME: Implicitly specialized method should not be output
-  // CHECK: template<> C(const char *);
+  // CHECK: template<> DelegatingCtor3(const char *);
 
-  // CHECK: C(int) : C("") {
-  C(int) : C("") {
+  // CHECK: DelegatingCtor3(int) : DelegatingCtor3("") {
+  DelegatingCtor3(int) : DelegatingCtor3("") {
   // CHECK-NEXT: }
   }
 
   // CHECK-NEXT: };
 };
+
+// CHECK: struct CurlyCtorInit {
+struct CurlyCtorInit {
+  // CHECK-NEXT: struct A {
+  struct A {
+  // CHECK-NEXT: };
+  };
+
+  // CHECK-NEXT: A a1;
+  A a1;
+  // CHECK-NEXT: A a2;
+  A a2;
+  // CHECK-NEXT: int b;
+  int b;
+
+  // CHECK-NEXT: CurlyCtorInit() : a1({}), a2{}, b{} {
+  CurlyCtorInit() : a1({}), a2{}, b{} {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -327,11 +327,12 @@
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }
 
-Out << "(";
-if (!BMInitializer->getInit()) {
-  // Nothing to print
-} else {
-  Expr *Init = BMInitializer->getInit();
+if (Expr *Init = BMInitializer->getInit()) {
+  bool OutParens = !isa(Init);
+
+  if (OutParens)
+Out << "(";
+
   if (ExprWithCleanups *Tmp = dyn_cast(Init))
 Init = Tmp->getSubExpr();
 
@@ -365,8 +366,13 @@
&Context);
 }
   }
+
+  if (OutParens)
+Out << ")";
+} else {
+  Out << "()";
 }
-Out << ")";
+
 if (BMInitializer->isPackExpansion())
   Out << "...";
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 378fcbf - [clang][Interp] Handle CXXNoexceptExprs

2023-07-26 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-26T12:23:54+02:00
New Revision: 378fcbf20ff80035dc1b5df4dc769908a80e0c3e

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

LOG: [clang][Interp] Handle CXXNoexceptExprs

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/AST/Interp/literals.cpp
clang/test/SemaCXX/cxx0x-noexcept-expression.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 7970cb63484855..29069ba10bb86d 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1006,6 +1006,15 @@ bool 
ByteCodeExprGen::VisitCXXReinterpretCastExpr(
   return this->emitInvalidCast(CastKind::Reinterpret, E);
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXNoexceptExpr(const CXXNoexceptExpr *E) {
+  assert(E->getType()->isBooleanType());
+
+  if (DiscardResult)
+return true;
+  return this->emitConstBool(E->getValue(), E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index c828f319cc04cd..6e134680d1fc5b 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -99,6 +99,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitPredefinedExpr(const PredefinedExpr *E);
   bool VisitCXXThrowExpr(const CXXThrowExpr *E);
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E);
+  bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 25c40755c2d495..5a645621e2d756 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -910,3 +910,25 @@ namespace PredefinedExprs {
   static_assert(heh(2) == 'h', "");
 #endif
 }
+
+namespace NE {
+  constexpr int foo() noexcept {
+return 1;
+  }
+  static_assert(noexcept(foo()), "");
+  constexpr int foo2() {
+return 1;
+  }
+  static_assert(!noexcept(foo2()), "");
+
+#if __cplusplus > 201402L
+  constexpr int a() {
+int b = 0;
+(void)noexcept(++b); // expected-warning {{expression with side effects 
has no effect in an unevaluated context}} \
+ // ref-warning {{expression with side effects has no 
effect in an unevaluated context}}
+
+return b;
+  }
+  static_assert(a() == 0, "");
+#endif
+}

diff  --git a/clang/test/SemaCXX/cxx0x-noexcept-expression.cpp 
b/clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
index f4911541d1d336..6afeeefec40da8 100644
--- a/clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
+++ b/clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions 
-fcxx-exceptions -Wno-unevaluated-expression
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions 
-fcxx-exceptions -Wno-unevaluated-expression 
-fexperimental-new-constant-interpreter
 
 void f(); // expected-note {{possible target for call}}
 void f(int); // expected-note {{possible target for call}}



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


[PATCH] D155707: [clang][Interp] Handle CXXNoexceptExprs

2023-07-26 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG378fcbf20ff8: [clang][Interp] Handle CXXNoexceptExprs 
(authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D155707?vs=543266&id=544283#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155707

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/literals.cpp
  clang/test/SemaCXX/cxx0x-noexcept-expression.cpp


Index: clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
===
--- clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
+++ clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions 
-fcxx-exceptions -Wno-unevaluated-expression
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions 
-fcxx-exceptions -Wno-unevaluated-expression 
-fexperimental-new-constant-interpreter
 
 void f(); // expected-note {{possible target for call}}
 void f(int); // expected-note {{possible target for call}}
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -910,3 +910,25 @@
   static_assert(heh(2) == 'h', "");
 #endif
 }
+
+namespace NE {
+  constexpr int foo() noexcept {
+return 1;
+  }
+  static_assert(noexcept(foo()), "");
+  constexpr int foo2() {
+return 1;
+  }
+  static_assert(!noexcept(foo2()), "");
+
+#if __cplusplus > 201402L
+  constexpr int a() {
+int b = 0;
+(void)noexcept(++b); // expected-warning {{expression with side effects 
has no effect in an unevaluated context}} \
+ // ref-warning {{expression with side effects has no 
effect in an unevaluated context}}
+
+return b;
+  }
+  static_assert(a() == 0, "");
+#endif
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -99,6 +99,7 @@
   bool VisitPredefinedExpr(const PredefinedExpr *E);
   bool VisitCXXThrowExpr(const CXXThrowExpr *E);
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E);
+  bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1006,6 +1006,15 @@
   return this->emitInvalidCast(CastKind::Reinterpret, E);
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXNoexceptExpr(const CXXNoexceptExpr *E) {
+  assert(E->getType()->isBooleanType());
+
+  if (DiscardResult)
+return true;
+  return this->emitConstBool(E->getValue(), E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;


Index: clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
===
--- clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
+++ clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions -fcxx-exceptions -Wno-unevaluated-expression
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions -fcxx-exceptions -Wno-unevaluated-expression -fexperimental-new-constant-interpreter
 
 void f(); // expected-note {{possible target for call}}
 void f(int); // expected-note {{possible target for call}}
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -910,3 +910,25 @@
   static_assert(heh(2) == 'h', "");
 #endif
 }
+
+namespace NE {
+  constexpr int foo() noexcept {
+return 1;
+  }
+  static_assert(noexcept(foo()), "");
+  constexpr int foo2() {
+return 1;
+  }
+  static_assert(!noexcept(foo2()), "");
+
+#if __cplusplus > 201402L
+  constexpr int a() {
+int b = 0;
+(void)noexcept(++b); // expected-warning {{expression with side effects has no effect in an unevaluated context}} \
+ // ref-warning {{expression with side effects has no effect in an unevaluated context}}
+
+return b;
+  }
+  static_assert(a() == 0, "");
+#endif
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -99,6 +99,7 @@
   bool VisitPredefinedExpr(const PredefinedExpr *E);
   bool VisitCXXThrowExpr(const CXXThrowExpr *E);

[PATCH] D156247: [Clang] Add a warning on uses of coroutine keywords

2023-07-26 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D156247#4534645 , @ilya-biryukov 
wrote:

> Thanks for the quick feedback!
> I understand that this goes against common practice in Clang, but the reason 
> we want this warning is very practical.
>
> At Google, we would like to postpone adoption of coroutines until the 
> aforementioned bugs are fixed, but we feel that Clang 17 would be a good 
> candidate to enable other C++20 features (sans Modules).
> We could have landed a local patch with a similar warning in our main 
> toolchain that we control tightly. However, we want to have it for other 
> toolchains (e.g. Apple Clang) that are based on upstream and we do not 
> control.
>
> Some code is compiled both by the main toolchain and Apple Clang and we want 
> to have a way to enforce in the compiler that this code does not use 
> coroutines, but is still compiled as C++20.
> We are taking a very cautious approach here (the bugs above are rare), but we 
> feel it is warranted given the amount of C++ users that we have.
> I do not propose to have flags like this for every single feature, but for 
> pragmatic reasons I think it makes sense to have it for coroutines in Clang 
> 17.
>
> In D156247#4532478 , @cor3ntin 
> wrote:
>
>> We usually reserve these warnings for feature backported to older c++ 
>> standards, and I'm not sure "you are using a standard feature" is in general 
>> a useful warning.
>
> I agree that is weird, but it's not unprecedented: designated initializers 
> are exactly like that .
> Maybe there is a different warning wording and flag that would suit this 
> better?

Designated initializers have this warning because they have been backported to 
older language mode, and they have
a different warning in these modes https://gcc.godbolt.org/z/9acefPW1n (which 
is important for pedantic conformance), and i guess the c++20 warning helps 
identify portability issues when trying newer standards on code bases that use 
these extensions.

But that does not apply to coroutines that are not available in older language 
modes.

Which for me brings a few questions. Why is it an issue for coroutines 
specifically? Concepts are also rough on the edges (but we do not set up the 
feature test macro), and consteval has (or had until very recently)
some bugs too (including code gen bugs, ironically!)

So the only warning that would make sense to me is "Support for coroutines is 
still experimental." I think that's what you want to express here.
Which again begs the question of why we claim conformance for something we 
think is too unstable to use in production. 
Three of the four bugs above are miss compilation of code that does not look 
particularly unusual, so I'm not sure the number of users matters. Whoever 
encounters that code will have an unpleasant time. 
And as you say. few people can work their way around such bugs

But if we think coroutines are good enough for one groups of users but not 
another... i'm not sure the warning belongs upstream.
Because the logical conclusion of that is that we would have to add warnings 
for any features added to the language which i don't think would benefit 
the ecosystem.

Having a separate warning group (ie `pre-c++20-compat-coroutines`) also makes 
me wonder about future clang versions:

- Either we remove the warning group and break build scripts
- We keep the warning group forever
- We keep the group but stop emitting the warning, which is also not great.

Sadly, i do not have the expertise to look at codegen bugs but maybe we should 
prioritize them higher in the hope of fixing some of them in the next few weeks.
If we could identify the problematic patterns, i think emitting an error from 
codegen until we fix them would also be reasonable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156247

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


[clang-tools-extra] b7c6b39 - [clang-tidy] Remove AnalyzeTemporaryDestructors configuration option

2023-07-26 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-07-26T10:26:43Z
New Revision: b7c6b39651b3ffdabf0081c45e0455a04a8be992

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

LOG: [clang-tidy] Remove AnalyzeTemporaryDestructors configuration option

Since it was deprecated since clang-tidy 16.

Fixes #62020

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index bc2ecc6b545536..1efe35a8b8f015 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -157,14 +157,12 @@ static void mapChecks(IO &IO, std::optional 
&Checks) {
 
 template <> struct MappingTraits {
   static void mapping(IO &IO, ClangTidyOptions &Options) {
-bool Ignored = false;
 mapChecks(IO, Options.Checks);
 IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors);
 IO.mapOptional("HeaderFileExtensions", Options.HeaderFileExtensions);
 IO.mapOptional("ImplementationFileExtensions",
Options.ImplementationFileExtensions);
 IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
-IO.mapOptional("AnalyzeTemporaryDtors", Ignored); // deprecated
 IO.mapOptional("FormatStyle", Options.FormatStyle);
 IO.mapOptional("User", Options.User);
 IO.mapOptional("CheckOptions", Options.CheckOptions);

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 159366222844ec..d22287d4effe49 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -108,6 +108,9 @@ Improvements to clang-tidy
   functionality using the newly added command line option
   `--enable-module-headers-parsing`.
 
+- Remove configuration option `AnalyzeTemporaryDestructors`, which was 
deprecated since
+  :program:`clang-tidy` 16.
+
 New checks
 ^^
 

diff  --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp 
b/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
index 89d8f4400fca80..af4f66ae3c54f1 100644
--- a/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -81,7 +81,6 @@ TEST(ParseConfiguration, ValidConfiguration) {
   "HeaderFileExtensions: [\"\",\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
   "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
   "HeaderFilterRegex: \".*\"\n"
-  "AnalyzeTemporaryDtors: true\n"
   "User: some.user",
   "Options"));
   EXPECT_TRUE(!!Options);
@@ -115,7 +114,6 @@ TEST(ParseConfiguration, MergeConfigurations) {
   HeaderFileExtensions: ["h","hh"]
   ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
-  AnalyzeTemporaryDtors: true
   User: user1
   ExtraArgs: ['arg1', 'arg2']
   ExtraArgsBefore: ['arg-before1', 'arg-before2']
@@ -130,7 +128,6 @@ TEST(ParseConfiguration, MergeConfigurations) {
   HeaderFileExtensions: ["hpp","hxx"]
   ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
-  AnalyzeTemporaryDtors: false
   User: user2
   ExtraArgs: ['arg3', 'arg4']
   ExtraArgsBefore: ['arg-before3', 'arg-before4']



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


[PATCH] D156303: [clang-tidy] Remove AnalyzeTemporaryDestructors configuration option

2023-07-26 Thread Carlos Galvez via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb7c6b39651b3: [clang-tidy] Remove 
AnalyzeTemporaryDestructors configuration option (authored by carlosgalvezp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156303

Files:
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp


Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -81,7 +81,6 @@
   "HeaderFileExtensions: [\"\",\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
   "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
   "HeaderFilterRegex: \".*\"\n"
-  "AnalyzeTemporaryDtors: true\n"
   "User: some.user",
   "Options"));
   EXPECT_TRUE(!!Options);
@@ -115,7 +114,6 @@
   HeaderFileExtensions: ["h","hh"]
   ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
-  AnalyzeTemporaryDtors: true
   User: user1
   ExtraArgs: ['arg1', 'arg2']
   ExtraArgsBefore: ['arg-before1', 'arg-before2']
@@ -130,7 +128,6 @@
   HeaderFileExtensions: ["hpp","hxx"]
   ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
-  AnalyzeTemporaryDtors: false
   User: user2
   ExtraArgs: ['arg3', 'arg4']
   ExtraArgsBefore: ['arg-before3', 'arg-before4']
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -108,6 +108,9 @@
   functionality using the newly added command line option
   `--enable-module-headers-parsing`.
 
+- Remove configuration option `AnalyzeTemporaryDestructors`, which was 
deprecated since
+  :program:`clang-tidy` 16.
+
 New checks
 ^^
 
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -157,14 +157,12 @@
 
 template <> struct MappingTraits {
   static void mapping(IO &IO, ClangTidyOptions &Options) {
-bool Ignored = false;
 mapChecks(IO, Options.Checks);
 IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors);
 IO.mapOptional("HeaderFileExtensions", Options.HeaderFileExtensions);
 IO.mapOptional("ImplementationFileExtensions",
Options.ImplementationFileExtensions);
 IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
-IO.mapOptional("AnalyzeTemporaryDtors", Ignored); // deprecated
 IO.mapOptional("FormatStyle", Options.FormatStyle);
 IO.mapOptional("User", Options.User);
 IO.mapOptional("CheckOptions", Options.CheckOptions);


Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -81,7 +81,6 @@
   "HeaderFileExtensions: [\"\",\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
   "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
   "HeaderFilterRegex: \".*\"\n"
-  "AnalyzeTemporaryDtors: true\n"
   "User: some.user",
   "Options"));
   EXPECT_TRUE(!!Options);
@@ -115,7 +114,6 @@
   HeaderFileExtensions: ["h","hh"]
   ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
-  AnalyzeTemporaryDtors: true
   User: user1
   ExtraArgs: ['arg1', 'arg2']
   ExtraArgsBefore: ['arg-before1', 'arg-before2']
@@ -130,7 +128,6 @@
   HeaderFileExtensions: ["hpp","hxx"]
   ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
-  AnalyzeTemporaryDtors: false
   User: user2
   ExtraArgs: ['arg3', 'arg4']
   ExtraArgsBefore: ['arg-before3', 'arg-before4']
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -108,6 +108,9 @@
   functionality using the newly added command line option
   `--enable-module-headers-parsing`.
 
+- Remove configuration option `AnalyzeTemporaryDestructors`, which was deprecated since
+  :program:`clang-tidy` 16.
+
 New checks
 ^^
 
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===
--- clang-tools-e

[PATCH] D156239: [X86] Support -march=arrowlake, arrowlake-s, lunarlake

2023-07-26 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/test/CodeGen/X86/cpus-intel.ll:37
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake-s 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake_s 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=lunarlake 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty

duplicate?



Comment at: llvm/test/CodeGen/X86/cpus-intel.ll:99
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=arrowlake-s 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=arrowlake_s 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=lunarlake 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty

duplicate?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156239

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


[clang] 970569b - [AMDGPU] __builtin_amdgcn_read_exec_* should be implemented with llvm.amdgcn.ballot

2023-07-26 Thread via cfe-commits

Author: ranapratap55
Date: 2023-07-26T16:21:31+05:30
New Revision: 970569b6ccb071d32e67ed26e3b972141efd2c31

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

LOG: [AMDGPU] __builtin_amdgcn_read_exec_* should be implemented with 
llvm.amdgcn.ballot

Reviewed By: arsenm

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGenOpenCL/builtins-amdgcn.cl

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 30f5f4e7061c05..fc8ee06fbb0624 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -7747,6 +7747,18 @@ enum SpecialRegisterAccessKind {
   Write,
 };
 
+static Value *EmitAMDGCNBallotForExec(CodeGenFunction &CGF, const CallExpr *E,
+  llvm::Type *RegisterType,
+  llvm::Type *ValueType) {
+  CodeGen::CGBuilderTy &Builder = CGF.Builder;
+  CodeGen::CodeGenModule &CGM = CGF.CGM;
+
+  llvm::Type *ResultType = CGF.ConvertType(E->getType());
+  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
+  llvm::Value *Call = Builder.CreateCall(F, {Builder.getInt1(true)});
+  return Call;
+}
+
 // Generates the IR for the read/write special register builtin,
 // ValueType is the type of the value that is to be written or read,
 // RegisterType is the type of the register being written to or read from.
@@ -17479,20 +17491,10 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
 llvm::Function *F = CGM.getIntrinsic(IID, {ArgTy});
 return Builder.CreateCall(F, {Addr, Val, ZeroI32, ZeroI32, ZeroI1});
   }
-  case AMDGPU::BI__builtin_amdgcn_read_exec: {
-CallInst *CI = cast(
-  EmitSpecialRegisterBuiltin(*this, E, Int64Ty, Int64Ty, NormalRead, 
"exec"));
-CI->setConvergent();
-return CI;
-  }
+  case AMDGPU::BI__builtin_amdgcn_read_exec:
   case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
   case AMDGPU::BI__builtin_amdgcn_read_exec_hi: {
-StringRef RegName = BuiltinID == AMDGPU::BI__builtin_amdgcn_read_exec_lo ?
-  "exec_lo" : "exec_hi";
-CallInst *CI = cast(
-  EmitSpecialRegisterBuiltin(*this, E, Int32Ty, Int32Ty, NormalRead, 
RegName));
-CI->setConvergent();
-return CI;
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty);
   }
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
index 8e5d670b7b7880..8938642e3b19f8 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -510,21 +510,23 @@ void test_cubema(global float* out, float a, float b, 
float c) {
 }
 
 // CHECK-LABEL: @test_read_exec(
-// CHECK: call i64 @llvm.read_register.i64(metadata ![[$EXEC:[0-9]+]]) 
#[[$READ_EXEC_ATTRS:[0-9]+]]
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
 void test_read_exec(global ulong* out) {
   *out = __builtin_amdgcn_read_exec();
 }
 
-// CHECK: declare i64 @llvm.read_register.i64(metadata) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
 
 // CHECK-LABEL: @test_read_exec_lo(
-// CHECK: call i32 @llvm.read_register.i32(metadata ![[$EXEC_LO:[0-9]+]]) 
#[[$READ_EXEC_ATTRS]]
+// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
 void test_read_exec_lo(global uint* out) {
   *out = __builtin_amdgcn_read_exec_lo();
 }
 
+// CHECK: declare i32 @llvm.amdgcn.ballot.i32(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_read_exec_hi(
-// CHECK: call i32 @llvm.read_register.i32(metadata ![[$EXEC_HI:[0-9]+]]) 
#[[$READ_EXEC_ATTRS]]
+// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
 void test_read_exec_hi(global uint* out) {
   *out = __builtin_amdgcn_read_exec_hi();
 }
@@ -830,8 +832,4 @@ void test_atomic_inc_dec(local uint *lptr, global uint 
*gptr, uint val) {
 
 // CHECK-DAG: [[$WI_RANGE]] = !{i32 0, i32 1024}
 // CHECK-DAG: [[$WS_RANGE]] = !{i16 1, i16 1025}
-// CHECK-DAG: attributes #[[$NOUNWIND_READONLY]] = { mustprogress nocallback 
nofree nosync nounwind willreturn memory(read) }
-// CHECK-DAG: attributes #[[$READ_EXEC_ATTRS]] = { convergent }
-// CHECK-DAG: ![[$EXEC]] = !{!"exec"}
-// CHECK-DAG: ![[$EXEC_LO]] = !{!"exec_lo"}
-// CHECK-DAG: ![[$EXEC_HI]] = !{!"exec_hi"}
+// CHECK-DAG: attributes #[[$NOUNWIND_READONLY]] = { convergent mustprogress 
nocallback nofree nounwind willreturn memory(none) }



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


[PATCH] D156219: [AMDGPU] __builtin_amdgcn_read_exec_* should be implemented with llvm.amdgcn.ballot

2023-07-26 Thread Rana Pratap Reddy Nimmakayala via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG970569b6ccb0: [AMDGPU] __builtin_amdgcn_read_exec_* should 
be implemented with llvm.amdgcn. (authored by ranapratap55).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156219

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-amdgcn.cl


Index: clang/test/CodeGenOpenCL/builtins-amdgcn.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -510,21 +510,23 @@
 }
 
 // CHECK-LABEL: @test_read_exec(
-// CHECK: call i64 @llvm.read_register.i64(metadata ![[$EXEC:[0-9]+]]) 
#[[$READ_EXEC_ATTRS:[0-9]+]]
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
 void test_read_exec(global ulong* out) {
   *out = __builtin_amdgcn_read_exec();
 }
 
-// CHECK: declare i64 @llvm.read_register.i64(metadata) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
 
 // CHECK-LABEL: @test_read_exec_lo(
-// CHECK: call i32 @llvm.read_register.i32(metadata ![[$EXEC_LO:[0-9]+]]) 
#[[$READ_EXEC_ATTRS]]
+// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
 void test_read_exec_lo(global uint* out) {
   *out = __builtin_amdgcn_read_exec_lo();
 }
 
+// CHECK: declare i32 @llvm.amdgcn.ballot.i32(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_read_exec_hi(
-// CHECK: call i32 @llvm.read_register.i32(metadata ![[$EXEC_HI:[0-9]+]]) 
#[[$READ_EXEC_ATTRS]]
+// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
 void test_read_exec_hi(global uint* out) {
   *out = __builtin_amdgcn_read_exec_hi();
 }
@@ -830,8 +832,4 @@
 
 // CHECK-DAG: [[$WI_RANGE]] = !{i32 0, i32 1024}
 // CHECK-DAG: [[$WS_RANGE]] = !{i16 1, i16 1025}
-// CHECK-DAG: attributes #[[$NOUNWIND_READONLY]] = { mustprogress nocallback 
nofree nosync nounwind willreturn memory(read) }
-// CHECK-DAG: attributes #[[$READ_EXEC_ATTRS]] = { convergent }
-// CHECK-DAG: ![[$EXEC]] = !{!"exec"}
-// CHECK-DAG: ![[$EXEC_LO]] = !{!"exec_lo"}
-// CHECK-DAG: ![[$EXEC_HI]] = !{!"exec_hi"}
+// CHECK-DAG: attributes #[[$NOUNWIND_READONLY]] = { convergent mustprogress 
nocallback nofree nounwind willreturn memory(none) }
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -7747,6 +7747,18 @@
   Write,
 };
 
+static Value *EmitAMDGCNBallotForExec(CodeGenFunction &CGF, const CallExpr *E,
+  llvm::Type *RegisterType,
+  llvm::Type *ValueType) {
+  CodeGen::CGBuilderTy &Builder = CGF.Builder;
+  CodeGen::CodeGenModule &CGM = CGF.CGM;
+
+  llvm::Type *ResultType = CGF.ConvertType(E->getType());
+  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
+  llvm::Value *Call = Builder.CreateCall(F, {Builder.getInt1(true)});
+  return Call;
+}
+
 // Generates the IR for the read/write special register builtin,
 // ValueType is the type of the value that is to be written or read,
 // RegisterType is the type of the register being written to or read from.
@@ -17479,20 +17491,10 @@
 llvm::Function *F = CGM.getIntrinsic(IID, {ArgTy});
 return Builder.CreateCall(F, {Addr, Val, ZeroI32, ZeroI32, ZeroI1});
   }
-  case AMDGPU::BI__builtin_amdgcn_read_exec: {
-CallInst *CI = cast(
-  EmitSpecialRegisterBuiltin(*this, E, Int64Ty, Int64Ty, NormalRead, 
"exec"));
-CI->setConvergent();
-return CI;
-  }
+  case AMDGPU::BI__builtin_amdgcn_read_exec:
   case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
   case AMDGPU::BI__builtin_amdgcn_read_exec_hi: {
-StringRef RegName = BuiltinID == AMDGPU::BI__builtin_amdgcn_read_exec_lo ?
-  "exec_lo" : "exec_hi";
-CallInst *CI = cast(
-  EmitSpecialRegisterBuiltin(*this, E, Int32Ty, Int32Ty, NormalRead, 
RegName));
-CI->setConvergent();
-return CI;
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty);
   }
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:


Index: clang/test/CodeGenOpenCL/builtins-amdgcn.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -510,21 +510,23 @@
 }
 
 // CHECK-LABEL: @test_read_exec(
-// CHECK: call i64 @llvm.read_register.i64(metadata ![[$EXEC:[0-9]+]]) #[[$READ_EXEC_ATTRS:[0-9]+]]
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
 void test_read_exec(global ulong* out) {
   *out = __builtin_amdgcn_read_exec();
 }
 
-// CHECK: declare i64 @llvm.read_register.i64(metadata) #[[$NOUNWIND_READONLY:[0-9]+]]
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) #[[$NOUNWIND_READONLY:[0-9]+]]
 
 // CHECK-LABEL: @test_rea

[clang] 5e8b44c - [OpenCL] Add cl_ext_image_raw10_raw12 extension

2023-07-26 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2023-07-26T11:59:12+01:00
New Revision: 5e8b44cc447e9b901c8168825f0c77491d9111e8

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

LOG: [OpenCL] Add cl_ext_image_raw10_raw12 extension

Add the defines for the `cl_ext_image_raw10_raw12` extension.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/test/Headers/opencl-c-header.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index af3deae892c7c9..2494f6213fc569 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -45,6 +45,7 @@
 #define __opencl_c_ext_fp32_local_atomic_add 1
 #define __opencl_c_ext_fp32_global_atomic_min_max 1
 #define __opencl_c_ext_fp32_local_atomic_min_max 1
+#define __opencl_c_ext_image_raw10_raw12 1
 
 #endif // defined(__SPIR__) || defined(__SPIRV__)
 #endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
@@ -477,6 +478,10 @@ typedef enum memory_order
 #if __OPENCL_C_VERSION__ >= CL_VERSION_3_0
 #define CLK_UNORM_INT_101010_2 0x10E0
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_3_0
+#ifdef __opencl_c_ext_image_raw10_raw12
+#define CLK_UNSIGNED_INT_RAW10_EXT 0x10E3
+#define CLK_UNSIGNED_INT_RAW12_EXT 0x10E4
+#endif // __opencl_c_ext_image_raw10_raw12
 
 // Channel order, numbering must be aligned with cl_channel_order in cl.h
 //

diff  --git a/clang/test/Headers/opencl-c-header.cl 
b/clang/test/Headers/opencl-c-header.cl
index 8242798106ac30..15b52ec04e667b 100644
--- a/clang/test/Headers/opencl-c-header.cl
+++ b/clang/test/Headers/opencl-c-header.cl
@@ -187,6 +187,9 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 #if __opencl_c_ext_fp64_local_atomic_min_max != 1
 #error "Incorrectly defined __opencl_c_ext_fp64_local_atomic_min_max"
 #endif
+#if __opencl_c_ext_image_raw10_raw12 != 1
+#error "Incorrectly defined __opencl_c_ext_image_raw10_raw12"
+#endif
 
 #else
 
@@ -271,6 +274,9 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 #ifdef __opencl_c_ext_fp64_local_atomic_min_max
 #error "Incorrectly __opencl_c_ext_fp64_local_atomic_min_max defined"
 #endif
+#ifdef __opencl_c_ext_image_raw10_raw12
+#error "Incorrect __opencl_c_ext_image_raw10_raw12 define"
+#endif
 
 #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 



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


[PATCH] D151339: [OpenCL] Add cl_ext_image_raw10_raw12 extension

2023-07-26 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5e8b44cc447e: [OpenCL] Add cl_ext_image_raw10_raw12 
extension (authored by svenvh).

Changed prior to commit:
  https://reviews.llvm.org/D151339?vs=525175&id=544292#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151339

Files:
  clang/lib/Headers/opencl-c-base.h
  clang/test/Headers/opencl-c-header.cl


Index: clang/test/Headers/opencl-c-header.cl
===
--- clang/test/Headers/opencl-c-header.cl
+++ clang/test/Headers/opencl-c-header.cl
@@ -187,6 +187,9 @@
 #if __opencl_c_ext_fp64_local_atomic_min_max != 1
 #error "Incorrectly defined __opencl_c_ext_fp64_local_atomic_min_max"
 #endif
+#if __opencl_c_ext_image_raw10_raw12 != 1
+#error "Incorrectly defined __opencl_c_ext_image_raw10_raw12"
+#endif
 
 #else
 
@@ -271,6 +274,9 @@
 #ifdef __opencl_c_ext_fp64_local_atomic_min_max
 #error "Incorrectly __opencl_c_ext_fp64_local_atomic_min_max defined"
 #endif
+#ifdef __opencl_c_ext_image_raw10_raw12
+#error "Incorrect __opencl_c_ext_image_raw10_raw12 define"
+#endif
 
 #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -45,6 +45,7 @@
 #define __opencl_c_ext_fp32_local_atomic_add 1
 #define __opencl_c_ext_fp32_global_atomic_min_max 1
 #define __opencl_c_ext_fp32_local_atomic_min_max 1
+#define __opencl_c_ext_image_raw10_raw12 1
 
 #endif // defined(__SPIR__) || defined(__SPIRV__)
 #endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
@@ -477,6 +478,10 @@
 #if __OPENCL_C_VERSION__ >= CL_VERSION_3_0
 #define CLK_UNORM_INT_101010_2 0x10E0
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_3_0
+#ifdef __opencl_c_ext_image_raw10_raw12
+#define CLK_UNSIGNED_INT_RAW10_EXT 0x10E3
+#define CLK_UNSIGNED_INT_RAW12_EXT 0x10E4
+#endif // __opencl_c_ext_image_raw10_raw12
 
 // Channel order, numbering must be aligned with cl_channel_order in cl.h
 //


Index: clang/test/Headers/opencl-c-header.cl
===
--- clang/test/Headers/opencl-c-header.cl
+++ clang/test/Headers/opencl-c-header.cl
@@ -187,6 +187,9 @@
 #if __opencl_c_ext_fp64_local_atomic_min_max != 1
 #error "Incorrectly defined __opencl_c_ext_fp64_local_atomic_min_max"
 #endif
+#if __opencl_c_ext_image_raw10_raw12 != 1
+#error "Incorrectly defined __opencl_c_ext_image_raw10_raw12"
+#endif
 
 #else
 
@@ -271,6 +274,9 @@
 #ifdef __opencl_c_ext_fp64_local_atomic_min_max
 #error "Incorrectly __opencl_c_ext_fp64_local_atomic_min_max defined"
 #endif
+#ifdef __opencl_c_ext_image_raw10_raw12
+#error "Incorrect __opencl_c_ext_image_raw10_raw12 define"
+#endif
 
 #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -45,6 +45,7 @@
 #define __opencl_c_ext_fp32_local_atomic_add 1
 #define __opencl_c_ext_fp32_global_atomic_min_max 1
 #define __opencl_c_ext_fp32_local_atomic_min_max 1
+#define __opencl_c_ext_image_raw10_raw12 1
 
 #endif // defined(__SPIR__) || defined(__SPIRV__)
 #endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
@@ -477,6 +478,10 @@
 #if __OPENCL_C_VERSION__ >= CL_VERSION_3_0
 #define CLK_UNORM_INT_101010_2 0x10E0
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_3_0
+#ifdef __opencl_c_ext_image_raw10_raw12
+#define CLK_UNSIGNED_INT_RAW10_EXT 0x10E3
+#define CLK_UNSIGNED_INT_RAW12_EXT 0x10E4
+#endif // __opencl_c_ext_image_raw10_raw12
 
 // Channel order, numbering must be aligned with cl_channel_order in cl.h
 //
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156239: [X86] Support -march=arrowlake, arrowlake-s, lunarlake

2023-07-26 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe marked 2 inline comments as done.
FreddyYe added inline comments.



Comment at: llvm/test/CodeGen/X86/cpus-intel.ll:37
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake-s 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake_s 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=lunarlake 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty

RKSimon wrote:
> duplicate?
No, it is `-` vs `_`



Comment at: llvm/test/CodeGen/X86/cpus-intel.ll:99
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=arrowlake-s 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=arrowlake_s 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=lunarlake 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty

RKSimon wrote:
> duplicate?
Same above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156239

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


[PATCH] D141757: [clangd] allow extracting to variable for lambda expressions

2023-07-26 Thread Julian Schmidt via Phabricator via cfe-commits
5chmidti added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141757

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


[PATCH] D154475: [clang][Interp] Fix ignoring MaterializeTemporaryExprs

2023-07-26 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154475

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


[PATCH] D156312: [analyzer] Upstream BitwiseShiftChecker

2023-07-26 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy created this revision.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, gamesh411, 
dkrupp, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
donat.nagy requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This commit releases a checker that was developed to a stable level in the 
Ericsson-internal fork of Clang Static Analyzer.

Note that the functionality of this checker overlaps with 
core.UndefinedBinaryOperatorResult ("UBOR"), but there are several differences 
between them:
(1) UBOR is only triggered when the constant folding performed by the Clang 
Static Analyzer engine determines that the value of a binary
operator expression is undefined; this checker can report issues where the 
operands are not constants.
(2) UBOR has unrelated checks for handling other binary operators, this checker 
only examines bitwise shifts.
(3) This checker has a Pedantic flag and by default does not report expressions 
(e.g. -2 << 2) that're undefined by the standard but consistently supported in 
practice.
(4) UBOR exhibits buggy behavior in code that involves cast expressions, e.g.

  void foo(unsigned short s) {
if (s == 2) {
  (void) ((unsigned int) s) << 16;
}
  }

Later it would be good to eliminate this overlap (perhaps by deprecating and 
then eliminating the bitwise shift handling in UBOR), but in my opinion that 
that belongs to separate commits.

Co-authored-by: Endre Fulop 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156312

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/bitwise-ops-nocrash.c
  clang/test/Analysis/bitwise-ops.c
  clang/test/Analysis/bitwise-shift-common.c
  clang/test/Analysis/bitwise-shift-pedantic.c
  clang/test/Analysis/bitwise-shift-sanity-checks.c
  clang/test/Analysis/bitwise-shift-state-update.c
  clang/test/Analysis/casts.c
  clang/test/Analysis/diagnostics/track_subexpressions.cpp
  clang/test/Analysis/left-shift-cxx2a.cpp
  clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
  clang/test/Analysis/symbol-simplification-nonloc-loc.cpp

Index: clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
===
--- clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
+++ clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
@@ -14,7 +14,7 @@
   if (p) {
 // no-crash
   }
-  if (p == (int *)0x404) {
+  if (p == (int *)0x1b) {
 // no-crash
   }
 }
@@ -29,7 +29,7 @@
   if (p) {
 // no-crash
   }
-  if (p == (int *)0x404) {
+  if (p == (int *)0x1b) {
 // no-crash
   }
 }
@@ -43,8 +43,6 @@
   nonloc_OP_loc(p, BINOP(-)); // no-crash
 
   // Bitwise operators:
-  // expected-warning@+2 {{The result of the left shift is undefined due to shifting by '1028', which is greater or equal to the width of type 'int' [core.UndefinedBinaryOperatorResult]}}
-  // expected-warning@+2 {{The result of the right shift is undefined due to shifting by '1028', which is greater or equal to the width of type 'int' [core.UndefinedBinaryOperatorResult]}}
   nonloc_OP_loc(p, BINOP(<<)); // no-crash
   nonloc_OP_loc(p, BINOP(>>)); // no-crash
   nonloc_OP_loc(p, BINOP(&));
Index: clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
===
--- clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
+++ clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
@@ -24,6 +24,7 @@
 // CHECK-NEXT: apiModeling.TrustReturnsNonnull
 // CHECK-NEXT: apiModeling.llvm.CastValue
 // CHECK-NEXT: apiModeling.llvm.ReturnValue
+// CHECK-NEXT: core.BitwiseShift
 // CHECK-NEXT: core.DivideZero
 // CHECK-NEXT: core.DynamicTypePropagation
 // CHECK-NEXT: core.NonnilStringConstants
Index: clang/test/Analysis/left-shift-cxx2a.cpp
===
--- clang/test/Analysis/left-shift-cxx2a.cpp
+++ clang/test/Analysis/left-shift-cxx2a.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple x86_64-apple-darwin13 -Wno-shift-count-overflow -verify=expected,cxx17 -std=c++17 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple x86_64-apple-darwin13 -Wno-shift-count-overflow -verify=expected,cxx2a -std=c++2a %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-disable-checker core.BitwiseShift -triple x86_64-apple-darwin13 -Wno-shift-count-overflow -verify=expected,cxx17 -std=c++17 %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,de

[PATCH] D156239: [X86] Support -march=arrowlake, arrowlake-s, lunarlake

2023-07-26 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/test/CodeGen/X86/cpus-intel.ll:37
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake-s 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake_s 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=lunarlake 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty

FreddyYe wrote:
> RKSimon wrote:
> > duplicate?
> No, it is `-` vs `_`
Got it - does that mean we should have added "graniterapids_d" as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156239

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


[PATCH] D151625: [clang] Add `clang::equality_operator_compares_members_lexicographically`

2023-07-26 Thread Amirreza Ashouri via Phabricator via cfe-commits
AMP999 added a comment.

Sure, I just filed this as a GitHub issue in the following link: 
https://github.com/llvm/llvm-project/issues/64124


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151625

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


[PATCH] D155574: [clang][ASTImporter] Fix import of recursive field initializer.

2023-07-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:3936-3937
+return std::move(Err);
+  if (ToInitializer)
+ToField->setInClassInitializer(ToInitializer);
   return ToField;

danix800 wrote:
> Initializer could indirectly depends on this field and set the initializer 
> while importing.
> `setInClassInitializer()` asserts that initializer should not be set more 
> than once:
> 
> ```
> static int ref_A();
> static int ref_B();
> struct A {
>   int a = ref_B();
> };
> struct B {
>   int b = ref_A();
> };
> int ref_B() { B b; return b.b; }
> int ref_A() { A a; return a.a; }
> ```
This example code really causes problems. But import of `Expr` is not checked 
for recursion, the assertion in the new code fails for this test.

Why do you want to use such code? It looks to cause infinite loop when 
executed. Even code like `class A { int b{b}; };` is probably not correct.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155574

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


[PATCH] D156247: [Clang] Add a warning on uses of coroutine keywords

2023-07-26 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a subscriber: rsmith.
ChuanqiXu added a comment.

There are several topics now. Let's discuss them separately to make things 
clear:

(1) Should we add such warning?

> Does the use-case mentioned above make sense (allow C++20, disallow 
> coroutines for code using Clang 17)?

This looks like a coding guide to me. So I feel it may be better to follow what 
other coding guides does. As far as I know, it is rare to insert warnings to 
the compilers for a specific coding guide.

(2) Is it OK to claim coroutines as released?

The reason why we marked it is in the above link. And I think the key question 
here is that how stable coroutines is in production? And as far as I know, all 
the industry users (Facebook, Alibaba, Seastar, I am not sure if Google has 
used it in production) don't feel bad with the current status. Also there a lot 
of relatively smaller projects which have been using coroutines for a long 
time. So personally, I feel it is OK to mark it as completed.

Also my intention to mark it as released is primarily for smaller groups. Since 
they may lack the confidence to use it in serious situations. But I feel (and 
always tell) they can. Since we already tried it for a long time.

(3) What's the practical affects for these bugs?

https://github.com/llvm/llvm-project/issues/57638: it is about **the 
performance  at the O0 level**. So I feel the priority is relatively low. Since 
generally we don't care about the performance within O0. (I know there are some 
against opinions)

https://github.com/llvm/llvm-project/issues/63818: it looks like only related 
to statement expressions. Maybe it is a good idea to emit warnings for using 
coroutines in statement expressions. Maybe we can fix this in the frontend as 
@rsmith said.

https://github.com/llvm/llvm-project/issues/58459: while we need to look into 
the reasons, from the reproducer, it looks like it only appears if the return 
type of the `await_resume()` function is `std::nullptr_t`, which is rare. Also 
I feel this is a frontend issue.

https://github.com/llvm/llvm-project/issues/56301: this is the most severe 
issue among these reports.  This issue may only be possible with a special 
`await_suspend` implementation. And ecosystem of coroutines is that some people 
write coroutine library and other people use these coroutine libraries. Then it 
won't be a problem for the wide users if the library don't use a special 
`await_suspend` implementation. And this is why the existing users of 
coroutines don't meet the issue.

(4) How should we handle the issue?

I have an idea about https://github.com/llvm/llvm-project/issues/56301 and it 
requires us to implement a new alias analysis pass for coroutines.  And I can 
image there will be a lot of works and I don't think I can make it in the 
recent 2~3 months. (This may be the reason that I always delay it...). I can 
try to promote its priority but I can't promise when can I fix it...

For https://github.com/llvm/llvm-project/issues/57638, I feel it is hard to fix 
and the practical affects of it doesn't matter really. So I think we don't need 
to discuss it now.

I don't have insights about https://github.com/llvm/llvm-project/issues/63818 
and https://github.com/llvm/llvm-project/issues/58459. I feel 
https://github.com/llvm/llvm-project/issues/58459 may be an oversight somewhere 
but I didn't look into it.

Hope this helps.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156247

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


[clang] ae4849f - [clang][Interp] PointerToIntegral casts

2023-07-26 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-26T13:39:37+02:00
New Revision: ae4849f96706cde460e6c792a6c8110791a6db32

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

LOG: [clang][Interp] PointerToIntegral casts

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 29069ba10bb86d..9f17ba1d7aa05f 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -127,6 +127,15 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
   return true;
 return this->emitNull(classifyPrim(CE->getType()), CE);
 
+  case CK_PointerToIntegral: {
+// TODO: Discard handling.
+if (!this->visit(SubExpr))
+  return false;
+
+PrimType T = classifyPrim(CE->getType());
+return this->emitCastPointerIntegral(T, CE);
+  }
+
   case CK_ArrayToPointerDecay:
   case CK_AtomicToNonAtomic:
   case CK_ConstructorConversion:

diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 4917f43f9512ec..4d49c75799637b 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -462,6 +462,17 @@ bool CheckCtorCall(InterpState &S, CodePtr OpPC, const 
Pointer &This) {
   return CheckArrayInitialized(S, OpPC, This, CAT);
 }
 
+bool CheckPotentialReinterpretCast(InterpState &S, CodePtr OpPC,
+   const Pointer &Ptr) {
+  if (!S.inConstantContext())
+return true;
+
+  const SourceInfo &E = S.Current->getSource(OpPC);
+  S.CCEDiag(E, diag::note_constexpr_invalid_cast)
+  << 2 << S.getLangOpts().CPlusPlus;
+  return false;
+}
+
 bool CheckFloatResult(InterpState &S, CodePtr OpPC, APFloat::opStatus Status) {
   // In a constant context, assume that any dynamic rounding mode or FP
   // exception state matches the default floating-point environment.

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 33ab0cdedeae42..ee3b953bb69cc2 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -104,6 +104,10 @@ bool CheckPure(InterpState &S, CodePtr OpPC, const 
CXXMethodDecl *MD);
 /// Checks that all fields are initialized after a constructor call.
 bool CheckCtorCall(InterpState &S, CodePtr OpPC, const Pointer &This);
 
+/// Checks if reinterpret casts are legal in the current context.
+bool CheckPotentialReinterpretCast(InterpState &S, CodePtr OpPC,
+   const Pointer &Ptr);
+
 /// Checks if the shift operation is legal.
 template 
 bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS,
@@ -1493,6 +1497,17 @@ bool CastFloatingIntegral(InterpState &S, CodePtr OpPC) {
   }
 }
 
+template ::T>
+bool CastPointerIntegral(InterpState &S, CodePtr OpPC) {
+  const Pointer &Ptr = S.Stk.pop();
+
+  if (!CheckPotentialReinterpretCast(S, OpPC, Ptr))
+return false;
+
+  S.Stk.push(T::from(Ptr.getIntegerRepresentation()));
+  return true;
+}
+
 
//===--===//
 // Zero, Nullptr
 
//===--===//

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 6d12823990cf2c..0f494c530b2568 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -565,6 +565,12 @@ def CastFloatingIntegral : Opcode {
   let HasGroup = 1;
 }
 
+def CastPointerIntegral : Opcode {
+  let Types = [AluTypeClass];
+  let Args = [];
+  let HasGroup = 1;
+}
+
 
//===--===//
 // Comparison opcodes.
 
//===--===//

diff  --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index f795466f1db4c5..a5e7ad8af81898 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -77,6 +77,13 @@ class Pointer {
   /// Converts the pointer to an APValue.
   APValue toAPValue() const;
 
+  /// Converts the pointer to a string usable in diagnostics.
+  std::string toDiagnosticString(const ASTContext &Ctx) const;
+
+  unsigned getIntegerRepresentation() const {
+return reinterpret_cast(Pointee) + Offset;
+  }
+
   /// Offsets a pointer inside an array.
   Pointer atIndex(unsigned Idx) const {
 if (Base == RootPtrMark)

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literal

[PATCH] D150946: [clang][Interp] PointerToIntegral casts

2023-07-26 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGae4849f96706: [clang][Interp] PointerToIntegral casts 
(authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D150946?vs=523698&id=544303#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150946

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

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -6,6 +6,8 @@
 #define INT_MIN (~__INT_MAX__)
 #define INT_MAX __INT_MAX__
 
+typedef __INTPTR_TYPE__ intptr_t;
+
 
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
@@ -932,3 +934,15 @@
   static_assert(a() == 0, "");
 #endif
 }
+
+namespace PointerCasts {
+  constexpr int M = 10;
+  constexpr const int *P = &M;
+  constexpr intptr_t A = (intptr_t)P; // ref-error {{must be initialized by a constant expression}} \
+  // ref-note {{cast that performs the conversions of a reinterpret_cast}} \
+  // expected-error {{must be initialized by a constant expression}} \
+  // expected-note {{cast that performs the conversions of a reinterpret_cast}}
+
+  int array[(long)(char*)0]; // ref-warning {{variable length array folded to constant array}} \
+ // expected-warning {{variable length array folded to constant array}}
+}
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -77,6 +77,13 @@
   /// Converts the pointer to an APValue.
   APValue toAPValue() const;
 
+  /// Converts the pointer to a string usable in diagnostics.
+  std::string toDiagnosticString(const ASTContext &Ctx) const;
+
+  unsigned getIntegerRepresentation() const {
+return reinterpret_cast(Pointee) + Offset;
+  }
+
   /// Offsets a pointer inside an array.
   Pointer atIndex(unsigned Idx) const {
 if (Base == RootPtrMark)
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -565,6 +565,12 @@
   let HasGroup = 1;
 }
 
+def CastPointerIntegral : Opcode {
+  let Types = [AluTypeClass];
+  let Args = [];
+  let HasGroup = 1;
+}
+
 //===--===//
 // Comparison opcodes.
 //===--===//
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -104,6 +104,10 @@
 /// Checks that all fields are initialized after a constructor call.
 bool CheckCtorCall(InterpState &S, CodePtr OpPC, const Pointer &This);
 
+/// Checks if reinterpret casts are legal in the current context.
+bool CheckPotentialReinterpretCast(InterpState &S, CodePtr OpPC,
+   const Pointer &Ptr);
+
 /// Checks if the shift operation is legal.
 template 
 bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS,
@@ -1493,6 +1497,17 @@
   }
 }
 
+template ::T>
+bool CastPointerIntegral(InterpState &S, CodePtr OpPC) {
+  const Pointer &Ptr = S.Stk.pop();
+
+  if (!CheckPotentialReinterpretCast(S, OpPC, Ptr))
+return false;
+
+  S.Stk.push(T::from(Ptr.getIntegerRepresentation()));
+  return true;
+}
+
 //===--===//
 // Zero, Nullptr
 //===--===//
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -462,6 +462,17 @@
   return CheckArrayInitialized(S, OpPC, This, CAT);
 }
 
+bool CheckPotentialReinterpretCast(InterpState &S, CodePtr OpPC,
+   const Pointer &Ptr) {
+  if (!S.inConstantContext())
+return true;
+
+  const SourceInfo &E = S.Current->getSource(OpPC);
+  S.CCEDiag(E, diag::note_constexpr_invalid_cast)
+  << 2 << S.getLangOpts().CPlusPlus;
+  return false;
+}
+
 bool CheckFloatResult(InterpState &S, CodePtr OpPC, APFloat::opStatus Status) {
   // In a constant context, assume that any dynamic rounding mode or FP
   // exception state matches the default floating-point environment.
Index: clang/lib/A

[clang-tools-extra] f6307b2 - [include-cleaner] Switch Include from FileEntry* -> FileEntryRef

2023-07-26 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2023-07-26T13:41:55+02:00
New Revision: f6307b260b0c0d93d25d13bab7ec02d762f4a2a6

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

LOG: [include-cleaner] Switch Include from FileEntry* -> FileEntryRef

Unlike Header, we really do have a preferred spelling for an include: the one
that we used to open the file.

The fact that Header is still FileEntry* makes it difficult to accidentally
use path equality when we want inode equality.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
clang-tools-extra/include-cleaner/lib/Analysis.cpp
clang-tools-extra/include-cleaner/lib/Record.cpp
clang-tools-extra/include-cleaner/lib/Types.cpp
clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
clang-tools-extra/include-cleaner/unittests/TypesTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
index 064eccd9cd6678..f6292d765451c2 100644
--- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -147,7 +147,7 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
   continue;
 // Check if main file is the public interface for a private header. If so
 // we shouldn't diagnose it as unused.
-if (auto PHeader = RecordedPI.getPublic(I.Resolved); !PHeader.empty()) {
+if (auto PHeader = RecordedPI.getPublic(*I.Resolved); !PHeader.empty()) {
   PHeader = PHeader.trim("<>\"");
   // Since most private -> public mappings happen in a verbatim way, we
   // check textually here. This might go wrong in presence of symlinks or
@@ -156,9 +156,10 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
 continue;
 }
 
-if (llvm::none_of(IgnoreHeadersRegex,
-  [Resolved = I.Resolved->tryGetRealPathName()](
-  const llvm::Regex &R) { return R.match(Resolved); }))
+if (llvm::none_of(
+IgnoreHeadersRegex,
+[Resolved = (*I.Resolved).getFileEntry().tryGetRealPathName()](
+const llvm::Regex &R) { return R.match(Resolved); }))
   Unused.push_back(&I);
   }
 

diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index 9708c67ca2883c..78dff4dd31bc1c 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -359,10 +359,10 @@ convertIncludes(const SourceManager &SM,
 SM.getComposedLoc(SM.getMainFileID(), Inc.HashOffset);
 TransformedInc.Line = Inc.HashLine + 1;
 TransformedInc.Angled = WrittenRef.starts_with("<");
-auto FE = SM.getFileManager().getFile(Inc.Resolved);
+auto FE = SM.getFileManager().getFileRef(Inc.Resolved);
 if (!FE) {
   elog("IncludeCleaner: Failed to get an entry for resolved path {0}: {1}",
-   Inc.Resolved, FE.getError().message());
+   Inc.Resolved, FE.takeError());
   continue;
 }
 TransformedInc.Resolved = *FE;
@@ -401,7 +401,7 @@ IncludeCleanerFindings 
computeIncludeCleanerFindings(ParsedAST &AST) {
   }
   for (auto *Inc : ConvertedIncludes.match(H)) {
 Satisfied = true;
-auto HeaderID = Includes.getID(Inc->Resolved);
+auto HeaderID = Includes.getID(&Inc->Resolved->getFileEntry());
 assert(HeaderID.has_value() &&
"ConvertedIncludes only contains resolved includes.");
 Used.insert(*HeaderID);

diff  --git 
a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h 
b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
index 91dddaf9031b4a..02269cea4bdf84 100644
--- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
+++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
@@ -22,6 +22,7 @@
 #ifndef CLANG_INCLUDE_CLEANER_TYPES_H
 #define CLANG_INCLUDE_CLEANER_TYPES_H
 
+#include "clang/Basic/FileEntry.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -40,7 +41,6 @@ class raw_ostream;
 } // namespace llvm
 namespace clang {
 class Decl;
-class FileEntry;
 class IdentifierInfo;
 namespace include_cleaner {
 
@@ -154,8 +154,8 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &, const 
Header &);
 /// A single #include directive written in the main file.
 struct Include {
   

[PATCH] D155885: [include-cleaner] Switch Include from FileEntry* -> FileEntryRef

2023-07-26 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf6307b260b0c: [include-cleaner] Switch Include from 
FileEntry* -> FileEntryRef (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155885

Files:
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/lib/Types.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
  clang-tools-extra/include-cleaner/unittests/TypesTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
@@ -26,8 +26,8 @@
   // Ensure it doesn't do any actual IO.
   auto FS = llvm::makeIntrusiveRefCnt();
   FileManager FM(FileSystemOptions{});
-  const FileEntry *A = FM.getVirtualFile("/path/a", /*Size=*/0, time_t{});
-  const FileEntry *B = FM.getVirtualFile("/path/b", /*Size=*/0, time_t{});
+  FileEntryRef A = FM.getVirtualFileRef("/path/a", /*Size=*/0, time_t{});
+  FileEntryRef B = FM.getVirtualFileRef("/path/b", /*Size=*/0, time_t{});
 
   Includes Inc;
   Inc.add(Include{"a", A, SourceLocation(), 1});
@@ -35,10 +35,11 @@
   Inc.add(Include{"b", B, SourceLocation(), 3});
   Inc.add(Include{"vector", B, SourceLocation(), 4});
   Inc.add(Include{"vector", B, SourceLocation(), 5});
-  Inc.add(Include{"missing", nullptr, SourceLocation(), 6});
+  Inc.add(Include{"missing", std::nullopt, SourceLocation(), 6});
 
-  EXPECT_THAT(Inc.match(A), ElementsAre(line(1), line(2)));
-  EXPECT_THAT(Inc.match(B), ElementsAre(line(3), line(4), line(5)));
+  EXPECT_THAT(Inc.match(&A.getFileEntry()), ElementsAre(line(1), line(2)));
+  EXPECT_THAT(Inc.match(&B.getFileEntry()),
+  ElementsAre(line(3), line(4), line(5)));
   EXPECT_THAT(Inc.match(*tooling::stdlib::Header::named("")),
   ElementsAre(line(4), line(5)));
 }
Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -171,7 +171,7 @@
   EXPECT_EQ(H.HashLocation,
 AST.sourceManager().getComposedLoc(
 AST.sourceManager().getMainFileID(), MainFile.point("H")));
-  EXPECT_EQ(H.Resolved, AST.fileManager().getFile("header.h").get());
+  EXPECT_EQ(H.Resolved, *AST.fileManager().getOptionalFileRef("header.h"));
   EXPECT_FALSE(H.Angled);
 
   auto &M = Recorded.Includes.all().back();
@@ -179,7 +179,7 @@
   EXPECT_EQ(M.HashLocation,
 AST.sourceManager().getComposedLoc(
 AST.sourceManager().getMainFileID(), MainFile.point("M")));
-  EXPECT_EQ(M.Resolved, nullptr);
+  EXPECT_EQ(M.Resolved, std::nullopt);
   EXPECT_TRUE(M.Angled);
 }
 
Index: clang-tools-extra/include-cleaner/lib/Types.cpp
===
--- clang-tools-extra/include-cleaner/lib/Types.cpp
+++ clang-tools-extra/include-cleaner/lib/Types.cpp
@@ -102,7 +102,7 @@
 
   BySpellingIt->second.push_back(Index);
   if (I.Resolved)
-ByFile[I.Resolved].push_back(Index);
+ByFile[&I.Resolved->getFileEntry()].push_back(Index);
   ByLine[I.Line] = Index;
 }
 
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -47,7 +47,7 @@
 
 Include I;
 I.HashLocation = Hash;
-I.Resolved = File ? &File->getFileEntry() : nullptr;
+I.Resolved = File;
 I.Line = SM.getSpellingLineNumber(Hash);
 I.Spelled = SpelledFilename;
 I.Angled = IsAngled;
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -88,14 +88,14 @@
   AnalysisResults Results;
   for (const Include &I : Inc.all()) {
 if (Used.contains(&I) || !I.Resolved ||
-HeaderFilter(I.Resolved->tryGetRealPathName()))
+HeaderFilter(I.Resolved->getFileEntry().tryGetRealPathName()))
   continue;
 if (PI) {
   if (PI->shouldKeep(I.Line))
 continue;
   // Check if main file is the public interface for a private header. If so
   // we shouldn't diagnose it as unused.
-  if (auto PHeader = PI->getPublic(I.Resolved); !PHeader.empty()) {
+  if (auto PHeader = PI->getPublic(*I.Reso

[PATCH] D155794: [OpenMP][OpenMPIRBuilder] Migrate setPropertyExecutionMode() from Clang to OpenMPIRBuilder.

2023-07-26 Thread Jan-Patrick Lehr via Phabricator via cfe-commits
jplehr added inline comments.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4914
+  GVMode->setVisibility(llvm::GlobalVariable::ProtectedVisibility);
+  assert(!GVMode->isDeclaration() &&
+ "Only globals with definition can force usage.");

raghavendhra wrote:
> jplehr wrote:
> > Can this assertion ever be not be met? I'm just curious, given that you 
> > create that `GVMode` yourself.
> Adopted this assert from Clang Codegen addCompilerUsedGlobal() which is 
> called inside setPropertyExecutionMode() in CGOpenMPRuntimeGPU.cpp
> 
> Actual definition of addCompilerusedGlobal() in CodeGenModule.cpp
> 
> void CodeGenModule::addCompilerUsedGlobal(llvm::GlobalValue *GV) {
>   assert(!GV->isDeclaration() &&
>  "Only globals with definition can force usage.");
>   LLVMCompilerUsed.emplace_back(GV);
> }
Sorry for the confusion I potentially created: I mainly wanted to understand if 
that case can ever happen.
I'm not really familiar with this part of the compiler.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155794

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


[PATCH] D156239: [X86] Support -march=arrowlake, arrowlake-s, lunarlake

2023-07-26 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe marked 3 inline comments as done.
FreddyYe added inline comments.



Comment at: llvm/test/CodeGen/X86/cpus-intel.ll:37
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake-s 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake_s 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=lunarlake 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty

RKSimon wrote:
> FreddyYe wrote:
> > RKSimon wrote:
> > > duplicate?
> > No, it is `-` vs `_`
> Got it - does that mean we should have added "graniterapids_d" as well?
Right! I realized that's a missing when I added here. But it may introduce 
conflict here so I prefer to add it in later patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156239

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


[PATCH] D156259: Fix a bug that erroneously placed function arguments on a new line despite all arguments being able to fit on the same line.

2023-07-26 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 updated this revision to Diff 544308.
jp4a50 added a comment.

Address minor review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156259

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/ContinuationIndenter.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22177,8 +22177,25 @@
"  }\n"
"};");
 
-  // Multiple lambdas in the same parentheses change indentation rules. These
-  // lambdas are forced to start on new lines.
+  // Lambdas that fit on a single line within an argument list are not forced
+  // onto new lines.
+  verifyFormat("SomeFunction([] {});");
+  verifyFormat("SomeFunction(0, [] {});");
+  verifyFormat("SomeFunction([] {}, 0);");
+  verifyFormat("SomeFunction(0, [] {}, 0);");
+  verifyFormat("SomeFunction([] { return 0; }, 0);");
+  verifyFormat("SomeFunction(a, [] { return 0; }, b);");
+  verifyFormat("SomeFunction([] { return 0; }, [] { return 0; });");
+  verifyFormat("SomeFunction([] { return 0; }, [] { return 0; }, b);");
+  verifyFormat("auto lng =\n"
+   "SomeFunction([] { return 0; }, [] { return 0; }, b);");
+  // Exceeded column limit. We need to break.
+  verifyFormat("auto lngName = SomeFunction(\n"
+   "[] { return anotherLooonngName; }, [] { "
+   "return 0; }, b);");
+
+  // Multiple multi-line lambdas in the same parentheses change indentation
+  // rules. These lambdas are always forced to start on new lines.
   verifyFormat("SomeFunction(\n"
"[]() {\n"
"  //\n"
@@ -22187,7 +22204,7 @@
"  //\n"
"});");
 
-  // A lambda passed as arg0 is always pushed to the next line.
+  // A multi-line lambda passed as arg0 is always pushed to the next line.
   verifyFormat("SomeFunction(\n"
"[this] {\n"
"  //\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -5203,30 +5203,6 @@
   return true;
   }
 
-  // Deal with lambda arguments in C++ - we want consistent line breaks whether
-  // they happen to be at arg0, arg1 or argN. The selection is a bit nuanced
-  // as aggressive line breaks are placed when the lambda is not the last arg.
-  if ((Style.Language == FormatStyle::LK_Cpp ||
-   Style.Language == FormatStyle::LK_ObjC) &&
-  Left.is(tok::l_paren) && Left.BlockParameterCount > 0 &&
-  !Right.isOneOf(tok::l_paren, TT_LambdaLSquare)) {
-// Multiple lambdas in the same function call force line breaks.
-if (Left.BlockParameterCount > 1)
-  return true;
-
-// A lambda followed by another arg forces a line break.
-if (!Left.Role)
-  return false;
-auto Comma = Left.Role->lastComma();
-if (!Comma)
-  return false;
-auto Next = Comma->getNextNonComment();
-if (!Next)
-  return false;
-if (!Next->isOneOf(TT_LambdaLSquare, tok::l_brace, tok::caret))
-  return true;
-  }
-
   return false;
 }
 
Index: clang/lib/Format/ContinuationIndenter.h
===
--- clang/lib/Format/ContinuationIndenter.h
+++ clang/lib/Format/ContinuationIndenter.h
@@ -433,6 +433,9 @@
   /// literal sequence, 0 otherwise.
   unsigned StartOfStringLiteral;
 
+  /// Disallow line breaks for this line.
+  bool NoLineBreak;
+
   /// A stack keeping track of properties applying to parenthesis
   /// levels.
   SmallVector Stack;
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -260,6 +260,7 @@
/*NoLineBreak=*/false));
   State.NoContinuation = false;
   State.StartOfStringLiteral = 0;
+  State.NoLineBreak = false;
   State.StartOfLineLevel = 0;
   State.LowestLevelOnLine = 0;
   State.IgnoreStackForComparison = false;
@@ -342,7 +343,7 @@
 return true;
   }
 
-  return !CurrentState.NoLineBreak;
+  return !State.NoLineBreak && !CurrentState.NoLineBreak;
 }
 
 bool ContinuationIndenter::mustBreak(const LineState &State) {
@@ -653,6 +654,40 @@
   const FormatToken &Previous = *State.NextToken->Previous;
   auto &CurrentState = State.Stack.back();
 
+  bool DisallowLineBreaksOnThisLine = [&Style = this->Style, &Current] {
+// Deal with lambda arguments in C++. The aim here is to ensure that we
+// don't over-i

[PATCH] D156259: Fix a bug that erroneously placed function arguments on a new line despite all arguments being able to fit on the same line.

2023-07-26 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 marked 2 inline comments as done.
jp4a50 added inline comments.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:263
   State.StartOfStringLiteral = 0;
+  State.NoLineBreak = false;
   State.StartOfLineLevel = 0;

HazardyKnusperkeks wrote:
> Was this uninitialized?
It's a new member variable I added as part of this diff.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:664-666
+if ((Style.Language == FormatStyle::LK_Cpp ||
+ Style.Language == FormatStyle::LK_ObjC) &&
+!Current.is(tok::comment) && PrevNonComment &&

HazardyKnusperkeks wrote:
> Could move this out of the lambda.
Not sure exactly what you're referring to here. Initialization of 
`PrevNonComment`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156259

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


[PATCH] D156259: Fix a bug that erroneously placed function arguments on a new line despite all arguments being able to fit on the same line.

2023-07-26 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 updated this revision to Diff 544310.
jp4a50 added a comment.

Format files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156259

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/ContinuationIndenter.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22177,8 +22177,25 @@
"  }\n"
"};");
 
-  // Multiple lambdas in the same parentheses change indentation rules. These
-  // lambdas are forced to start on new lines.
+  // Lambdas that fit on a single line within an argument list are not forced
+  // onto new lines.
+  verifyFormat("SomeFunction([] {});");
+  verifyFormat("SomeFunction(0, [] {});");
+  verifyFormat("SomeFunction([] {}, 0);");
+  verifyFormat("SomeFunction(0, [] {}, 0);");
+  verifyFormat("SomeFunction([] { return 0; }, 0);");
+  verifyFormat("SomeFunction(a, [] { return 0; }, b);");
+  verifyFormat("SomeFunction([] { return 0; }, [] { return 0; });");
+  verifyFormat("SomeFunction([] { return 0; }, [] { return 0; }, b);");
+  verifyFormat("auto lng =\n"
+   "SomeFunction([] { return 0; }, [] { return 0; }, b);");
+  // Exceeded column limit. We need to break.
+  verifyFormat("auto lngName = SomeFunction(\n"
+   "[] { return anotherLooonngName; }, [] { "
+   "return 0; }, b);");
+
+  // Multiple multi-line lambdas in the same parentheses change indentation
+  // rules. These lambdas are always forced to start on new lines.
   verifyFormat("SomeFunction(\n"
"[]() {\n"
"  //\n"
@@ -22187,7 +22204,7 @@
"  //\n"
"});");
 
-  // A lambda passed as arg0 is always pushed to the next line.
+  // A multi-line lambda passed as arg0 is always pushed to the next line.
   verifyFormat("SomeFunction(\n"
"[this] {\n"
"  //\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -5203,30 +5203,6 @@
   return true;
   }
 
-  // Deal with lambda arguments in C++ - we want consistent line breaks whether
-  // they happen to be at arg0, arg1 or argN. The selection is a bit nuanced
-  // as aggressive line breaks are placed when the lambda is not the last arg.
-  if ((Style.Language == FormatStyle::LK_Cpp ||
-   Style.Language == FormatStyle::LK_ObjC) &&
-  Left.is(tok::l_paren) && Left.BlockParameterCount > 0 &&
-  !Right.isOneOf(tok::l_paren, TT_LambdaLSquare)) {
-// Multiple lambdas in the same function call force line breaks.
-if (Left.BlockParameterCount > 1)
-  return true;
-
-// A lambda followed by another arg forces a line break.
-if (!Left.Role)
-  return false;
-auto Comma = Left.Role->lastComma();
-if (!Comma)
-  return false;
-auto Next = Comma->getNextNonComment();
-if (!Next)
-  return false;
-if (!Next->isOneOf(TT_LambdaLSquare, tok::l_brace, tok::caret))
-  return true;
-  }
-
   return false;
 }
 
Index: clang/lib/Format/ContinuationIndenter.h
===
--- clang/lib/Format/ContinuationIndenter.h
+++ clang/lib/Format/ContinuationIndenter.h
@@ -433,6 +433,9 @@
   /// literal sequence, 0 otherwise.
   unsigned StartOfStringLiteral;
 
+  /// Disallow line breaks for this line.
+  bool NoLineBreak;
+
   /// A stack keeping track of properties applying to parenthesis
   /// levels.
   SmallVector Stack;
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -260,6 +260,7 @@
/*NoLineBreak=*/false));
   State.NoContinuation = false;
   State.StartOfStringLiteral = 0;
+  State.NoLineBreak = false;
   State.StartOfLineLevel = 0;
   State.LowestLevelOnLine = 0;
   State.IgnoreStackForComparison = false;
@@ -342,7 +343,7 @@
 return true;
   }
 
-  return !CurrentState.NoLineBreak;
+  return !State.NoLineBreak && !CurrentState.NoLineBreak;
 }
 
 bool ContinuationIndenter::mustBreak(const LineState &State) {
@@ -653,6 +654,39 @@
   const FormatToken &Previous = *State.NextToken->Previous;
   auto &CurrentState = State.Stack.back();
 
+  bool DisallowLineBreaksOnThisLine = [&Style = this->Style, &Current] {
+// Deal with lambda arguments in C++. The aim here is to ensure that we
+// don't over-indent lambda func

[PATCH] D156239: [X86] Support -march=arrowlake, arrowlake-s, lunarlake

2023-07-26 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/lib/TargetParser/X86TargetParser.cpp:430
+  { {"arrowlake-s"}, CK_ArrowlakeS, FEATURE_AVX2, FeaturesArrowlakeS, '\0', 
false },
+  { {"arrowlake_s"}, CK_Lunarlake, FEATURE_AVX2, FeaturesArrowlakeS, 'p', true 
},
+  // Lunarlake microarchitecture based processors.

CK_ArrowlakeS?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156239

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


[PATCH] D156239: [X86] Support -march=arrowlake, arrowlake-s, lunarlake

2023-07-26 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 544314.
FreddyYe marked 2 inline comments as done.
FreddyYe added a comment.

address comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156239

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/attr-cpuspecific-cpus.c
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGen/target-builtin-noerror.c
  clang/test/Driver/x86-march.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros.c
  compiler-rt/lib/builtins/cpu_model.c
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/Target/X86/X86.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -32,6 +32,10 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids-d 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=emeraldrapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake-s 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake_s 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=lunarlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=nocona 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=core2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
@@ -90,6 +94,10 @@
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids-d 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=arrowlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=arrowlake-s 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=arrowlake_s 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=lunarlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 define void @foo() {
   ret void
Index: llvm/lib/TargetParser/X86TargetParser.cpp
===
--- llvm/lib/TargetParser/X86TargetParser.cpp
+++ llvm/lib/TargetParser/X86TargetParser.cpp
@@ -237,6 +237,8 @@
 FeatureENQCMD | FeatureAVXNECONVERT | FeatureAVXVNNIINT8;
 constexpr FeatureBitset FeaturesGrandridge =
 FeaturesSierraforest | FeatureRAOINT;
+constexpr FeatureBitset FeaturesArrowlakeS = FeaturesSierraforest |
+FeatureAVXVNNIINT16 | FeatureSHA512 | FeatureSM3 | FeatureSM4;
 
 // Geode Processor.
 constexpr FeatureBitset FeaturesGeode =
@@ -422,6 +424,12 @@
   { {"raptorlake"}, CK_Raptorlake, FEATURE_AVX2, FeaturesAlderlake, 'p', false },
   // Meteorlake microarchitecture based processors.
   { {"meteorlake"}, CK_Meteorlake, FEATURE_AVX2, FeaturesAlderlake, 'p', false },
+  // Arrowlake microarchitecture based processors.
+  { {"arrowlake"}, CK_Arrowlake, FEATURE_AVX2, FeaturesSierraforest, 'p', false },
+  { {"arrowlake-s"}, CK_ArrowlakeS, FEATURE_AVX2, FeaturesArrowlakeS, '\0', false },
+  { {"arrowlake_s"}, CK_ArrowlakeS, FEATURE_AVX2, FeaturesArrowlakeS, 'p', true },
+  // Lunarlake microarchitecture based processors.
+  { {"lunarlake"}, CK_Lunarlake, FEATURE_AVX2, FeaturesArrowlakeS, 'p', false },
   // Sierraforest microarchitecture based processors.
   { {"sierraforest"}, CK_Sierraforest, FEATURE_AVX2, FeaturesSierraforest, 'p', false },
   // Grandridge microarchitecture based processors.
Index: llvm/lib/TargetParser/Host.cpp
===
--- llvm/lib/TargetPa

[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-07-26 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

> What do you mean with libstdc++ is fine?

What I mean is when I do (current patch is applied to clang):

  source/llvm-project/build/bin/clang++ -std=c++20 t.cpp -c // compilation 
succeeds

But when I do (libc++ is built together with clang)

  source/llvm-project/build/bin/clang++ -std=c++20 t.cpp -stdlib=libc++ -c
  t.cpp:4:15: error: static assertion failed due to requirement 
'!std::is_invocable_v'
  4 | static_assert(!std::is_invocable_v);
|   ^~~~
  1 error generated.



> Based on the bug and this patch I am correct that "transformation" of an 
> array of unknown bounds to anarray of known bounds only happens with an 
> explicit cast and not implicitly?

Yes, type is changed only for explicit casts.

> I have a strong suspicion that this patch changes the test to

Well technically it only changes explicit casts, so no.  With this patch this 
static assertion still fails

  static_assert(std::is_same::value);

What I'm seeing is that in libc++ there is a bunch of explicit static casts in 
`ranges::__crend::__fn` that endup transformed:

  namespace ranges {
  namespace __crend {   
 
  struct __fn {
template 
  requires is_lvalue_reference_v<_Tp&&> 
 
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp&& __t) const
  noexcept(noexcept(ranges::rend(static_cast&>(__t
  -> decltype(  ranges::rend(static_cast&>(__t)))  
  { return  ranges::rend(static_cast&>(__t)); }

 
template 
 
  requires is_rvalue_reference_v<_Tp&&> 
 
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp&& __t) const
  noexcept(noexcept(ranges::rend(static_cast(__t   
 
  -> decltype(  ranges::rend(static_cast(__t)))
  { return  ranges::rend(static_cast(__t)); }
  };
  } // namespace __crend

Is that expected?

Please note that other implementations would do the same transformation and 
that is the point of this bugfix:
https://godbolt.org/z/ff8f3YEbz


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

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


[PATCH] D156312: [analyzer] Upstream BitwiseShiftChecker

2023-07-26 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added a comment.

I tested this commit on several open source projects (in the default mode 
Pedantic=false), the following table summarizes the results:

| vim_v8.2.1920_baseline_vs_vim_v8.2.1920_with_bitwise_shift
   | New reports 

   | Lost reports 

   | no differences 
|
| 
openssl_openssl-3.0.0-alpha7_baseline_vs_openssl_openssl-3.0.0-alpha7_with_bitwise_shift
 | New reports 

 | Lost reports 

 | +2 FPs from same invalid loop assumption [1]   |
| sqlite_version-3.33.0_baseline_vs_sqlite_version-3.33.0_with_bitwise_shift
   | New reports 

   | Lost reports 

   | one FP lost for unclear reasons
|
| ffmpeg_n4.3.1_baseline_vs_ffmpeg_n4.3.1_with_bitwise_shift
   | New reports 

   | Lost reports 

   | 21 new reports, 14 lost reports, 
mostly FPs [2]|
| postgres_REL_13_0_baseline_vs_postgres_REL_13_0_with_bitwise_shift
   | New reports 

   | Lost reports 

   | two FPs are "converted" to new checker, one 
unreadable report lost |
| 
libwebm_libwebm-1.0.0.27_baseline_vs_libwebm_libwebm-1.0.0.27_with_bitwise_shift
 | New reports 

 | Lost reports 

 | no differences   
  |
| xerces_v3.2.3_baseline_vs_xerces_v3.2.3_with_bitwise_shift
   | New reports 

   | Lost reports 

   | no differences 
|
| bitcoin_v0.20.1_baseline_vs_bitcoin_v0.20.1_with_bitwise_shift
   | New reports 

   | Lost reports 

   

[PATCH] D156286: [docs] Bump minimum GCC version to 7.5

2023-07-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added subscribers: cfe-commits, clang-vendors, aaron.ballman.
aaron.ballman added a reviewer: sylvestre.ledru.
aaron.ballman added a comment.

There's a mention on the RFC thread that Ubuntu 18.04 still ships with GCC 7.3. 
That's an LTS release but it EOLed just last month, so it's not clear how 
disruptive this would be. (To be clear, I'm not saying I'm opposed to the 
changes.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156286

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


[PATCH] D156312: [analyzer] Upstream BitwiseShiftChecker

2023-07-26 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy updated this revision to Diff 544317.
donat.nagy added a comment.

(Fix incorrect filename mark in the license header.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156312

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/bitwise-ops-nocrash.c
  clang/test/Analysis/bitwise-ops.c
  clang/test/Analysis/bitwise-shift-common.c
  clang/test/Analysis/bitwise-shift-pedantic.c
  clang/test/Analysis/bitwise-shift-sanity-checks.c
  clang/test/Analysis/bitwise-shift-state-update.c
  clang/test/Analysis/casts.c
  clang/test/Analysis/diagnostics/track_subexpressions.cpp
  clang/test/Analysis/left-shift-cxx2a.cpp
  clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
  clang/test/Analysis/symbol-simplification-nonloc-loc.cpp

Index: clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
===
--- clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
+++ clang/test/Analysis/symbol-simplification-nonloc-loc.cpp
@@ -14,7 +14,7 @@
   if (p) {
 // no-crash
   }
-  if (p == (int *)0x404) {
+  if (p == (int *)0x1b) {
 // no-crash
   }
 }
@@ -29,7 +29,7 @@
   if (p) {
 // no-crash
   }
-  if (p == (int *)0x404) {
+  if (p == (int *)0x1b) {
 // no-crash
   }
 }
@@ -43,8 +43,6 @@
   nonloc_OP_loc(p, BINOP(-)); // no-crash
 
   // Bitwise operators:
-  // expected-warning@+2 {{The result of the left shift is undefined due to shifting by '1028', which is greater or equal to the width of type 'int' [core.UndefinedBinaryOperatorResult]}}
-  // expected-warning@+2 {{The result of the right shift is undefined due to shifting by '1028', which is greater or equal to the width of type 'int' [core.UndefinedBinaryOperatorResult]}}
   nonloc_OP_loc(p, BINOP(<<)); // no-crash
   nonloc_OP_loc(p, BINOP(>>)); // no-crash
   nonloc_OP_loc(p, BINOP(&));
Index: clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
===
--- clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
+++ clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
@@ -24,6 +24,7 @@
 // CHECK-NEXT: apiModeling.TrustReturnsNonnull
 // CHECK-NEXT: apiModeling.llvm.CastValue
 // CHECK-NEXT: apiModeling.llvm.ReturnValue
+// CHECK-NEXT: core.BitwiseShift
 // CHECK-NEXT: core.DivideZero
 // CHECK-NEXT: core.DynamicTypePropagation
 // CHECK-NEXT: core.NonnilStringConstants
Index: clang/test/Analysis/left-shift-cxx2a.cpp
===
--- clang/test/Analysis/left-shift-cxx2a.cpp
+++ clang/test/Analysis/left-shift-cxx2a.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple x86_64-apple-darwin13 -Wno-shift-count-overflow -verify=expected,cxx17 -std=c++17 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple x86_64-apple-darwin13 -Wno-shift-count-overflow -verify=expected,cxx2a -std=c++2a %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-disable-checker core.BitwiseShift -triple x86_64-apple-darwin13 -Wno-shift-count-overflow -verify=expected,cxx17 -std=c++17 %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-disable-checker core.BitwiseShift -triple x86_64-apple-darwin13 -Wno-shift-count-overflow -verify=expected,cxx2a -std=c++2a %s
 
 int testNegativeShift(int a) {
   if (a == -5) {
Index: clang/test/Analysis/diagnostics/track_subexpressions.cpp
===
--- clang/test/Analysis/diagnostics/track_subexpressions.cpp
+++ clang/test/Analysis/diagnostics/track_subexpressions.cpp
@@ -12,10 +12,10 @@
 
 void shift_by_undefined_value() {
   uint8_t shift_amount = get_uint8_max(); // expected-note{{'shift_amount' initialized to 255}}
-// expected-note@-1{{Calling 'get_uint8_max'}}
-// expected-note@-2{{Returning from 'get_uint8_max'}}
-  (void)(TCP_MAXWIN << shift_amount); // expected-warning{{The result of the left shift is undefined due to shifting by '255', which is greater or equal to the width of type 'int'}}
-  // expected-note@-1{{The result of the left shift is undefined due to shifting by '255', which is greater or equal to the width of type 'int'}}
+  // expected-note@-1{{Calling 'get_uint8_max'}}
+  // expected-note@-2{{Returning from 'get_uint8_max'}}
+  (void)(TCP_MAXWIN << shift_amount); // expected-warning{{Left shift by '255' overflows the capacity of 'int'}}
+  // expe

[PATCH] D156320: [FLang] Add support for Rpass flag

2023-07-26 Thread victorkingi via Phabricator via cfe-commits
victorkingi created this revision.
Herald added a reviewer: sscalpone.
Herald added a reviewer: awarzynski.
Herald added a subscriber: sunshaoce.
Herald added projects: Flang, All.
victorkingi requested review of this revision.
Herald added subscribers: cfe-commits, jdoerfert, MaskRay.
Herald added a project: clang.

Allow flang to report what optimizations were and were not done
by the compiler transformation.

A StandaloneBackendConsumer was implemented but the DiagnosticsEngine
still doesn't print to console the remarks produced.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156320

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CodeGenOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90

Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -79,6 +79,10 @@
 ! HELP-NEXT: -print-effective-triple Print the effective target triple
 ! HELP-NEXT: -print-target-triplePrint the normalized target triple
 ! HELP-NEXT: -P Disable linemarker output in -E mode
+! HELP-NEXT: -Rpass-analysis= Report transformation analysis from optimization passes whose name matches the given POSIX regular expression
+! HELP-NEXT: -Rpass-missed=   Report missed transformations by optimization passes whose name matches the given POSIX regular expression
+! HELP-NEXT: -Rpass=  Report transformations performed by optimization passes whose name matches the given POSIX regular expression
+! HELP-NEXT: -R  Enable the specified remark
 ! HELP-NEXT: -save-temps=Save intermediate compilation results.
 ! HELP-NEXT: -save-tempsSave intermediate compilation results
 ! HELP-NEXT: -std=   Language standard to compile for
@@ -192,6 +196,10 @@
 ! HELP-FC1-NEXT: -pic-level   Value for __PIC__
 ! HELP-FC1-NEXT: -plugin  Use the named plugin action instead of the default action (use "help" to list available options)
 ! HELP-FC1-NEXT: -P Disable linemarker output in -E mode
+! HELP-FC1-NEXT: -Rpass-analysis= Report transformation analysis from optimization passes whose name matches the given POSIX regular expression
+! HELP-FC1-NEXT: -Rpass-missed=   Report missed transformations by optimization passes whose name matches the given POSIX regular expression
+! HELP-FC1-NEXT: -Rpass=  Report transformations performed by optimization passes whose name matches the given POSIX regular expression
+! HELP-FC1-NEXT: -R  Enable the specified remark
 ! HELP-FC1-NEXT: -save-temps=Save intermediate compilation results.
 ! HELP-FC1-NEXT: -save-tempsSave intermediate compilation results
 ! HELP-FC1-NEXT: -std=   Language standard to compile for
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -83,6 +83,10 @@
 ! CHECK-NEXT: -print-effective-triple Print the effective target triple
 ! CHECK-NEXT: -print-target-triplePrint the normalized target triple
 ! CHECK-NEXT: -P Disable linemarker output in -E mode
+! CHECK-NEXT: -Rpass-analysis= Report transformation analysis from optimization passes whose name matches the given POSIX regular expression
+! CHECK-NEXT: -Rpass-missed=   Report missed transformations by optimization passes whose name matches the given POSIX regular expression
+! CHECK-NEXT: -Rpass=  Report transformations performed by optimization passes whose name matches the given POSIX regular expression
+! CHECK-NEXT: -R  Enable the specified remark
 ! CHECK-NEXT: -save-temps=Save intermediate compilation results.
 ! CHECK-NEXT: -save-tempsSave intermediate compilation results
 ! CHECK-NEXT: -std=   Language standard to compile for
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -42,11 +42,15 @@
 #include "mlir/Target/LLVMIR/ModuleTranslation.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticFrontend.h"
+#include "clang/Driver/DriverDiagnostic.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeWriterPass.h"
+#include "llvm/IR/DiagnosticHandler.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/LLVMRemarkStreamer.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/IR/Verifier.h"
 #include "llvm/IRReader/IRReader.h"
@@ -55,6 +59,7

[PATCH] D156321: [Clang[RISCV] Remove RVV intrinsics `vread_csr`,`vwrite_csr`

2023-07-26 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD created this revision.
eopXD added reviewers: kito-cheng, craig.topper, rogfer01.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, 
shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, arichardson.
Herald added a project: All.
eopXD requested review of this revision.
Herald added subscribers: cfe-commits, wangpc, MaskRay.
Herald added a project: clang.

As proposed in riscv-non-isa/rvv-intrinsic-doc#249, removing the interface.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156321

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vread-csr.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vwrite-csr.c

Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vwrite-csr.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vwrite-csr.c
+++ /dev/null
@@ -1,42 +0,0 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// REQUIRES: riscv-registered-target
-// RUN: %clang_cc1 -triple riscv64 -target-feature +v -disable-O0-optnone -emit-llvm %s -o - \
-// RUN: | opt -S -O2 | FileCheck  %s
-
-#include 
-
-// CHECK-LABEL: @vwrite_csr_vstart(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:tail call void asm sideeffect "csrw\09vstart, ${0:z}", "rJ,~{memory}"(i64 [[VALUE:%.*]]) #[[ATTR1:[0-9]+]], !srcloc !4
-// CHECK-NEXT:ret void
-//
-void vwrite_csr_vstart(unsigned long value) {
-  __riscv_vwrite_csr(RVV_VSTART, value);
-}
-
-// CHECK-LABEL: @vwrite_csr_vxsat(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:tail call void asm sideeffect "csrw\09vxsat, ${0:z}", "rJ,~{memory}"(i64 [[VALUE:%.*]]) #[[ATTR1]], !srcloc !5
-// CHECK-NEXT:ret void
-//
-void vwrite_csr_vxsat(unsigned long value) {
-  __riscv_vwrite_csr(RVV_VXSAT, value);
-}
-
-// CHECK-LABEL: @vwrite_csr_vxrm(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:tail call void asm sideeffect "csrw\09vxrm, ${0:z}", "rJ,~{memory}"(i64 [[VALUE:%.*]]) #[[ATTR1]], !srcloc !6
-// CHECK-NEXT:ret void
-//
-void vwrite_csr_vxrm(unsigned long value) {
-  __riscv_vwrite_csr(RVV_VXRM, value);
-}
-
-// CHECK-LABEL: @vwrite_csr_vcsr(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:tail call void asm sideeffect "csrw\09vcsr, ${0:z}", "rJ,~{memory}"(i64 [[VALUE:%.*]]) #[[ATTR1]], !srcloc !7
-// CHECK-NEXT:ret void
-//
-void vwrite_csr_vcsr(unsigned long value) {
-  __riscv_vwrite_csr(RVV_VCSR, value);
-}
Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vread-csr.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vread-csr.c
+++ /dev/null
@@ -1,42 +0,0 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// REQUIRES: riscv-registered-target
-// RUN: %clang_cc1 -triple riscv64 -target-feature +v -disable-O0-optnone -emit-llvm %s -o - \
-// RUN: | opt -S -O2 | FileCheck  %s
-
-#include 
-
-// CHECK-LABEL: @vread_csr_vstart(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 asm sideeffect "csrr\09$0, vstart", "=r,~{memory}"() #[[ATTR1:[0-9]+]], !srcloc !4
-// CHECK-NEXT:ret i64 [[TMP0]]
-//
-unsigned long vread_csr_vstart(void) {
-  return __riscv_vread_csr(RVV_VSTART);
-}
-
-// CHECK-LABEL: @vread_csr_vxsat(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 asm sideeffect "csrr\09$0, vxsat", "=r,~{memory}"() #[[ATTR1]], !srcloc !5
-// CHECK-NEXT:ret i64 [[TMP0]]
-//
-unsigned long vread_csr_vxsat(void) {
-  return __riscv_vread_csr(RVV_VXSAT);
-}
-
-// CHECK-LABEL: @vread_csr_vxrm(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 asm sideeffect "csrr\09$0, vxrm", "=r,~{memory}"() #[[ATTR1]], !srcloc !6
-// CHECK-NEXT:ret i64 [[TMP0]]
-//
-unsigned long vread_csr_vxrm(void) {
-  return __riscv_vread_csr(RVV_VXRM);
-}
-
-// CHECK-LABEL: @vread_csr_vcsr(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 asm sideeffect "csrr\09$0, vcsr", "=r,~{memory}"() #[[ATTR1]], !srcloc !7
-// CHECK-NEXT:ret i64 [[TMP0]]
-//
-unsigned long vread_csr_vcsr(void) {
-  return __riscv_vread_csr(RVV_VCSR);
-}
Index: clang/include/clang/Basic/riscv_vector.td
===
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -990,56 +990,6 @@
   }
 }
 
-// Define vread_csr&vwrite_csr described in RVV intrinsics doc.
-let HeaderCode =
-[{
-enum RVV_CSR {
-  RVV_VSTART = 0,
-  RVV_VXSAT,
-  RVV_VXRM,
-  RVV_VCSR,
-};
-
-static __inline__ __attribute__((__always_inline__, __nodebug__))
-unsigned long __riscv_vread_csr(enum RVV_CSR __csr) {
-  unsigned long __rv = 0;
-  switch (__csr) {
-case RVV_VSTART:
-  __asm__ __vo

[PATCH] D156229: [clang][dataflow] Remove checks that test for consistency between `StructValue` and `AggregateStorageLocation`.

2023-07-26 Thread Martin Böhme via Phabricator via cfe-commits
mboehme abandoned this revision.
mboehme added a comment.

This is a duplicate of https://reviews.llvm.org/D155813 that I uploaded for 
some reason. Sorry for the noise.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156229

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


[PATCH] D156322: Outputs parameter comments using clang-doc and markdown generator

2023-07-26 Thread Arnaud Botella via Phabricator via cfe-commits
BotellaA created this revision.
BotellaA added a reviewer: juliehockett.
BotellaA added a project: clang-tools-extra.
Herald added a project: All.
BotellaA requested review of this revision.
Herald added a subscriber: cfe-commits.

Current implementation outputs the parameter name when used with @param (or 
@tparam) doxygen tag but not the comment itself.


https://reviews.llvm.org/D156322

Files:
  clang-tools-extra/clang-doc/MDGenerator.cpp


Index: clang-tools-extra/clang-doc/MDGenerator.cpp
===
--- clang-tools-extra/clang-doc/MDGenerator.cpp
+++ clang-tools-extra/clang-doc/MDGenerator.cpp
@@ -82,10 +82,14 @@
 OS << genEmphasis(I.Name) << " " << I.Text;
   } else if (I.Kind == "ParamCommandComment") {
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
-OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
+OS << genEmphasis(I.ParamName) << I.Text << Direction;
+for (const auto &Child : I.Children)
+  writeDescription(*Child, OS);
   } else if (I.Kind == "TParamCommandComment") {
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
-OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
+OS << genEmphasis(I.ParamName) << I.Text << Direction;
+for (const auto &Child : I.Children)
+  writeDescription(*Child, OS);
   } else if (I.Kind == "VerbatimBlockComment") {
 for (const auto &Child : I.Children)
   writeDescription(*Child, OS);


Index: clang-tools-extra/clang-doc/MDGenerator.cpp
===
--- clang-tools-extra/clang-doc/MDGenerator.cpp
+++ clang-tools-extra/clang-doc/MDGenerator.cpp
@@ -82,10 +82,14 @@
 OS << genEmphasis(I.Name) << " " << I.Text;
   } else if (I.Kind == "ParamCommandComment") {
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
-OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
+OS << genEmphasis(I.ParamName) << I.Text << Direction;
+for (const auto &Child : I.Children)
+  writeDescription(*Child, OS);
   } else if (I.Kind == "TParamCommandComment") {
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
-OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
+OS << genEmphasis(I.ParamName) << I.Text << Direction;
+for (const auto &Child : I.Children)
+  writeDescription(*Child, OS);
   } else if (I.Kind == "VerbatimBlockComment") {
 for (const auto &Child : I.Children)
   writeDescription(*Child, OS);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156027: [clang][Interp] Rework how initializers work

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



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:240
+return Initializing ? this->visitInitializer(SubExpr)
+: this->visit(SubExpr);
 

This pattern shows up a few times, so it might make sense to add a function 
that simply passes on all the flags and doesn't do anything else. I'm just not 
sure what to call it.


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

https://reviews.llvm.org/D156027

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


[PATCH] D155819: [include-cleaner] Loose matching for verbatim headers

2023-07-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 544323.
sammccall marked 6 inline comments as done.
sammccall added a comment.

address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155819

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/lib/Types.cpp
  clang-tools-extra/include-cleaner/unittests/TypesTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
@@ -8,6 +8,7 @@
 
 #include "clang-include-cleaner/Types.h"
 #include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/Support/VirtualFileSystem.h"
@@ -17,6 +18,8 @@
 namespace clang::include_cleaner {
 namespace {
 using testing::ElementsAre;
+using testing::IsEmpty;
+using testing::UnorderedElementsAre;
 
 // Matches an Include* on the specified line;
 MATCHER_P(line, N, "") { return arg->Line == (unsigned)N; }
@@ -44,5 +47,57 @@
   ElementsAre(line(4), line(5)));
 }
 
+TEST(RecordedIncludesTest, MatchVerbatim) {
+  auto FS = llvm::makeIntrusiveRefCnt();
+  FileManager FM(FileSystemOptions{});
+  Includes Inc;
+
+  // By default, a verbatim header only matches includes with the same spelling.
+  auto Foo =
+  FM.getVirtualFileRef("repo/lib/include/rel/foo.h", /*Size=*/0, time_t{});
+  Inc.add(Include{"lib/include/rel/foo.h", Foo, SourceLocation(), 1});
+  Inc.add(Include{"rel/foo.h", Foo, SourceLocation(), 2});
+  EXPECT_THAT(Inc.match(Header("")), ElementsAre(line(2)));
+
+  // A verbatim header can match another spelling if the search path
+  // suggests it's equivalent.
+  auto Bar =
+  FM.getVirtualFileRef("repo/lib/include/rel/bar.h", /*Size=*/0, time_t{});
+  Inc.addSearchDirectory("repo/");
+  Inc.addSearchDirectory("repo/lib/include");
+  Inc.add(Include{"lib/include/rel/bar.h", Bar, SourceLocation(), 3});
+  Inc.add(Include{"rel/bar.h", Bar, SourceLocation(), 4});
+  EXPECT_THAT(Inc.match(Header("")),
+  UnorderedElementsAre(line(3), line(4)));
+
+  // We don't apply this logic to system headers, though.
+  auto Vector =
+  FM.getVirtualFileRef("repo/lib/include/vector", /*Size=*/0, time_t{});
+  Inc.add(Include{"lib/include/vector", Vector, SourceLocation(), 5});
+  EXPECT_THAT(Inc.match(Header(*tooling::stdlib::Header::named(""))),
+  IsEmpty());
+}
+
+TEST(RecordedIncludesTest, MatchVerbatimMixedAbsoluteRelative) {
+  auto FS = llvm::makeIntrusiveRefCnt();
+  FS->setCurrentWorkingDirectory("/working");
+  FileManager FM(FileSystemOptions{});
+  Includes Inc;
+
+  auto Foo =
+  FM.getVirtualFileRef("/working/rel1/rel2/foo.h", /*Size=*/0, time_t{});
+  Inc.addSearchDirectory("rel1");
+  Inc.addSearchDirectory("rel1/rel2");
+  Inc.add(Include{"rel2/foo.h", Foo, SourceLocation(), 1});
+  EXPECT_THAT(Inc.match(Header("")), IsEmpty());
+
+  Inc = Includes{};
+  auto Bar = FM.getVirtualFileRef("rel1/rel2/bar.h", /*Size=*/0, time_t{});
+  Inc.addSearchDirectory("/working/rel1");
+  Inc.addSearchDirectory("/working/rel1/rel2");
+  Inc.add(Include{"rel2/bar.h", Bar, SourceLocation(), 1});
+  EXPECT_THAT(Inc.match(Header("")), IsEmpty());
+}
+
 } // namespace
 } // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/lib/Types.cpp
===
--- clang-tools-extra/include-cleaner/lib/Types.cpp
+++ clang-tools-extra/include-cleaner/lib/Types.cpp
@@ -10,8 +10,15 @@
 #include "TypesInternal.h"
 #include "clang/AST/Decl.h"
 #include "clang/Basic/FileEntry.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 
 namespace clang::include_cleaner {
 
@@ -94,16 +101,51 @@
   .str();
 }
 
+static llvm::SmallString<128> normalizePath(llvm::StringRef Path) {
+  namespace path = llvm::sys::path;
+
+  llvm::SmallString<128> P = Path;
+  path::remove_dots(P, /*remove_dot_dot=*/true);
+  path::native(P, path::Style::posix);
+  while (!P.empty() && P.back() == '/')
+P.pop_back();
+  return P;
+}
+
+void Includes::addSearchDirectory(llvm::StringRef Path) {
+  SearchPath.try_emplace(normalizePath(Path));
+}
+
 void Includes::add(const Include &I) {
+  namespace path = llvm::sys::path;
+
   unsigned Index = All.size();
   All.push_back(I);
   auto BySpellingIt = BySpelling.try_emplace(I.Spelled).first;
   All.back().Spelled = BySpellingIt->first(); // N

[PATCH] D155819: [include-cleaner] Loose matching for verbatim headers

2023-07-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/Types.cpp:110-112
+  while (!P.empty() && path::is_separator(P.back()))
+P.pop_back();
+  return P;

kadircet wrote:
> nit: `return P.rtrim('/');` // only separator we can encounter is forward 
> slash at this point.
Oops, yes!
Kept the loop though to avoid making an extra copy, APIs are awkward



Comment at: clang-tools-extra/include-cleaner/lib/Types.cpp:137
+// verbatim "e/f" should match (spelled=c/d/e/f, resolved=/a/b/c/d/e/f).
+// We assume entry's (normalized) name will match the search dirs.
+auto Path = normalizePath(I.Resolved->getName());

kadircet wrote:
> i think this assumption breaks when we have an absolute include search path, 
> which is a subdirectory of the CWD of file manager. as we might now have a 
> resolved include which is relative, but a search path that'll never match a 
> prefix of those includes.
> 
> i guess this is fine, as we're trying to heuristically match. but it would be 
> useful to mention it here and add a unittest for that. (unless I am missing 
> something and headersearch already normalizes such paths)
This is part of the contract of the function, pulled in the doc comment from 
D155878 and added a test for the cases that don't work.



Comment at: clang-tools-extra/include-cleaner/lib/Types.cpp:171-173
+for (unsigned I : BySpellingAlternate.lookup(Spelling))
+  if (!llvm::is_contained(Result, &All[I]))
+Result.push_back(&All[I]);

kadircet wrote:
> i think we shouldn't look into alternate spellings if we've already found an 
> exact spelling. we would be matching wrong headers for sure in those cases.
I had it this way initially and changed my mind. Having the presence of some 
includes affect whether others match at all breaks an "obvious" part of the 
contract. (So obvious that I assumed it in the test ten minutes after 
deliberately breaking it). I wouldn't add a special case here unless there's 
some observed bad-results motivation for it.

> we would be matching wrong headers for sure in those cases.

You could be including the same header under two paths (and in fact that's what 
this testcase is doing). I don't know why you would, but we also don't have 
real examples of this happening with *different* headers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155819

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


[PATCH] D155870: [Clang][CodeGen] Another follow-up for `vtable`, `typeinfo` et al. are globals

2023-07-26 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx updated this revision to Diff 544324.
AlexVlx added a comment.

Rebase.


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

https://reviews.llvm.org/D155870

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/dynamic-cast-address-space.cpp


Index: clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -I%S %s -triple amdgcn-amd-amdhsa -emit-llvm 
-fcxx-exceptions -fexceptions -o - | FileCheck %s
+struct A { virtual void f(); };
+struct B : A { };
+
+// CHECK: {{define.*@_Z1fP1A}}
+// CHECK-SAME:  personality ptr @__gxx_personality_v0
+B fail;
+const B& f(A *a) {
+  try {
+// CHECK: call ptr @__dynamic_cast
+// CHECK: br i1
+// CHECK: invoke void @__cxa_bad_cast() [[NR:#[0-9]+]]
+dynamic_cast(*a);
+  } catch (...) {
+// CHECK:  landingpad { ptr, i32 }
+// CHECK-NEXT:   catch ptr null
+  }
+  return fail;
+}
+
+// CHECK: declare ptr @__dynamic_cast(ptr, ptr addrspace(1), ptr addrspace(1), 
i64) [[NUW_RO:#[0-9]+]]
+
+// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
+// CHECK: attributes [[NR]] = { noreturn }
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1344,15 +1344,16 @@
 
 static llvm::FunctionCallee getItaniumDynamicCastFn(CodeGenFunction &CGF) {
   // void *__dynamic_cast(const void *sub,
-  //  const abi::__class_type_info *src,
-  //  const abi::__class_type_info *dst,
+  //  global_as const abi::__class_type_info *src,
+  //  global_as const abi::__class_type_info *dst,
   //  std::ptrdiff_t src2dst_offset);
 
   llvm::Type *Int8PtrTy = CGF.Int8PtrTy;
+  llvm::Type *GlobInt8PtrTy = CGF.GlobalsInt8PtrTy;
   llvm::Type *PtrDiffTy =
 CGF.ConvertType(CGF.getContext().getPointerDiffType());
 
-  llvm::Type *Args[4] = { Int8PtrTy, Int8PtrTy, Int8PtrTy, PtrDiffTy };
+  llvm::Type *Args[4] = { Int8PtrTy, GlobInt8PtrTy, GlobInt8PtrTy, PtrDiffTy };
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false);
 


Index: clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -I%S %s -triple amdgcn-amd-amdhsa -emit-llvm -fcxx-exceptions -fexceptions -o - | FileCheck %s
+struct A { virtual void f(); };
+struct B : A { };
+
+// CHECK: {{define.*@_Z1fP1A}}
+// CHECK-SAME:  personality ptr @__gxx_personality_v0
+B fail;
+const B& f(A *a) {
+  try {
+// CHECK: call ptr @__dynamic_cast
+// CHECK: br i1
+// CHECK: invoke void @__cxa_bad_cast() [[NR:#[0-9]+]]
+dynamic_cast(*a);
+  } catch (...) {
+// CHECK:  landingpad { ptr, i32 }
+// CHECK-NEXT:   catch ptr null
+  }
+  return fail;
+}
+
+// CHECK: declare ptr @__dynamic_cast(ptr, ptr addrspace(1), ptr addrspace(1), i64) [[NUW_RO:#[0-9]+]]
+
+// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
+// CHECK: attributes [[NR]] = { noreturn }
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1344,15 +1344,16 @@
 
 static llvm::FunctionCallee getItaniumDynamicCastFn(CodeGenFunction &CGF) {
   // void *__dynamic_cast(const void *sub,
-  //  const abi::__class_type_info *src,
-  //  const abi::__class_type_info *dst,
+  //  global_as const abi::__class_type_info *src,
+  //  global_as const abi::__class_type_info *dst,
   //  std::ptrdiff_t src2dst_offset);
 
   llvm::Type *Int8PtrTy = CGF.Int8PtrTy;
+  llvm::Type *GlobInt8PtrTy = CGF.GlobalsInt8PtrTy;
   llvm::Type *PtrDiffTy =
 CGF.ConvertType(CGF.getContext().getPointerDiffType());
 
-  llvm::Type *Args[4] = { Int8PtrTy, Int8PtrTy, Int8PtrTy, PtrDiffTy };
+  llvm::Type *Args[4] = { Int8PtrTy, GlobInt8PtrTy, GlobInt8PtrTy, PtrDiffTy };
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155574: [clang][ASTImporter] Fix import of recursive field initializer.

2023-07-26 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:3936-3937
+return std::move(Err);
+  if (ToInitializer)
+ToField->setInClassInitializer(ToInitializer);
   return ToField;

balazske wrote:
> danix800 wrote:
> > Initializer could indirectly depends on this field and set the initializer 
> > while importing.
> > `setInClassInitializer()` asserts that initializer should not be set more 
> > than once:
> > 
> > ```
> > static int ref_A();
> > static int ref_B();
> > struct A {
> >   int a = ref_B();
> > };
> > struct B {
> >   int b = ref_A();
> > };
> > int ref_B() { B b; return b.b; }
> > int ref_A() { A a; return a.a; }
> > ```
> This example code really causes problems. But import of `Expr` is not checked 
> for recursion, the assertion in the new code fails for this test.
> 
> Why do you want to use such code? It looks to cause infinite loop when 
> executed. Even code like `class A { int b{b}; };` is probably not correct.
Like `int a{a};` this testcase is minimized to just show what might cause the 
problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155574

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


[PATCH] D155870: [Clang][CodeGen] Another follow-up for `vtable`, `typeinfo` et al. are globals

2023-07-26 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx added a comment.

Gentle ping.


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

https://reviews.llvm.org/D155870

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


[PATCH] D155457: [clang] Skip tautological comparison if the comparison involves the 'size_t' type

2023-07-26 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155457

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


[PATCH] D155878: [clangd] Loose include-cleaner matching for verbatim headers

2023-07-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/Headers.cpp:185
+  // The entries will be the same, but canonicalizing to find out is expensive!
+  if (SearchPathCanonical.empty()) {
+for (const auto &Dir :

kadircet wrote:
> nit: early exit
I don't think it makes sense here, this isn't "the remaining case" for this 
function, it's just one of many things this function does



Comment at: clang-tools-extra/clangd/Hover.cpp:1250
   const SourceManager &SM = AST.getSourceManager();
-  const auto &ConvertedMainFileIncludes =
-  convertIncludes(SM, AST.getIncludeStructure().MainFileIncludes);
-  const auto &HoveredInclude = convertIncludes(SM, llvm::ArrayRef{Inc});
+  const auto &Converted = convertIncludes(AST);
   llvm::DenseSet UsedSymbols;

kadircet wrote:
> oops, looks like we were getting away with some dangling references.
> the reference here is wrong, `convertIncludes` returns a value type. can you 
> fix that while here?
this isn't dangling, it's lifetime extension.

Can change it for style if you like, though?



Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:486-491
+  include_cleaner::walkUsed(AST.getLocalTopLevelDecls(), {},
+AST.getPragmaIncludes(), AST.getSourceManager(),
+[&](const include_cleaner::SymbolReference &Ref,
+llvm::ArrayRef P) {
+  Providers[llvm::to_string(Ref.Target)] = P.vec();
+});

kadircet wrote:
> i don't think making this test rely on `walkUsed` is a good idea. what about 
> just populating the providers directly, like:
> 
> ```
> EXPECT_TRUE(isPreferredProvider(Decl, Includes, 
> {include_cleaner::Header{"decl.h"}, include_cleaner::Header{"def.h"}}));
> ```
> 
> and verifying we're recognizing preferred providers purely on that ordering ?
That would be a strict unit test, but I think it's too easy to lose track of 
how this idea of "preferred" relates to the code.

For example, when writing this test, I expected `Y` to match the includes for 
both `Decl` and `Def`, because they're intuitively both "best matches" and we 
do allow multiple includes to match.
But of course we force the *providers* to be ranked, so really ~only multiple 
includes of the *same* header will be accepted as all-preferred.

This wrinkle seems worth recording, and totally disappears if we make the test 
abstract by describing a provider list directly.

(Can do it though if that's what you do prefer)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155878

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


[PATCH] D156325: [Driver] Link shared asan runtime lib with -z now on Solaris/x86

2023-07-26 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added reviewers: vitalybuka, MaskRay.
ro added a project: clang.
Herald added a subscriber: fedor.sergeev.
Herald added a project: All.
ro requested review of this revision.

As detailed in Issue #64126, several asan tests `FAIL` due to a cycle in 
`AsanInitInternal`.  This can by avoided by disabling lazy binding with `ld -z 
now`.

Tested on `amd64-pc-solaris2.11.`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156325

Files:
  clang/lib/Driver/ToolChains/Solaris.cpp


Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -151,18 +151,22 @@
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
+const SanitizerArgs &SA = getToolChain().getSanitizerArgs(Args);
 if (NeedsSanitizerDeps) {
   linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
 
   // Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
   // However, ld -z relax=transtls is available since Solaris 11.2, but not
   // in Illumos.
-  const SanitizerArgs &SA = getToolChain().getSanitizerArgs(Args);
   if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
   (SA.needsAsanRt() || SA.needsStatsRt() ||
(SA.needsUbsanRt() && !SA.requiresMinimalRuntime(
 CmdArgs.push_back("-zrelax=transtls");
 }
+// Avoid AsanInitInternal cycle, Issue #64126.
+if (getToolChain().getTriple().isX86() && SA.needsSharedRt() &&
+SA.needsAsanRt())
+  CmdArgs.push_back("-znow");
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,


Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -151,18 +151,22 @@
   CmdArgs.push_back("-lgcc");
   CmdArgs.push_back("-lm");
 }
+const SanitizerArgs &SA = getToolChain().getSanitizerArgs(Args);
 if (NeedsSanitizerDeps) {
   linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
 
   // Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
   // However, ld -z relax=transtls is available since Solaris 11.2, but not
   // in Illumos.
-  const SanitizerArgs &SA = getToolChain().getSanitizerArgs(Args);
   if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
   (SA.needsAsanRt() || SA.needsStatsRt() ||
(SA.needsUbsanRt() && !SA.requiresMinimalRuntime(
 CmdArgs.push_back("-zrelax=transtls");
 }
+// Avoid AsanInitInternal cycle, Issue #64126.
+if (getToolChain().getTriple().isX86() && SA.needsSharedRt() &&
+SA.needsAsanRt())
+  CmdArgs.push_back("-znow");
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155921: [clang][dataflow] Reverse course on `getValue()` deprecation.

2023-07-26 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 544335.
mboehme added a comment.

Rebase to head


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155921

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -390,7 +390,7 @@
 if (const auto *E = selectFirst(
 "call", match(cxxConstructExpr(HasSpecialBoolType).bind("call"), *S,
   getASTContext( {
-  cast(Env.getValueStrict(*E))
+  cast(Env.getValue(*E))
   ->setProperty("is_set", Env.getBoolLiteralValue(false));
 } else if (const auto *E = selectFirst(
"call", match(cxxMemberCallExpr(callee(cxxMethodDecl(ofClass(
@@ -547,7 +547,7 @@
 *S, getASTContext());
 if (const auto *E = selectFirst(
 "construct", Matches)) {
-  cast(Env.getValueStrict(*E))
+  cast(Env.getValue(*E))
   ->setProperty("has_value", Env.getBoolLiteralValue(false));
 } else if (const auto *E =
selectFirst("operator", Matches)) {
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -5524,7 +5524,7 @@
   ASTCtx));
 
 ASSERT_THAT(ImplicitCast, NotNull());
-EXPECT_THAT(Env.getValueStrict(*ImplicitCast), IsNull());
+EXPECT_THAT(Env.getValue(*ImplicitCast), IsNull());
   });
 }
 
Index: clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
@@ -114,7 +114,7 @@
 return {nullptr, {}, {}};
 
   // Value of the unary op.
-  auto *UnaryOpValue = State.Env.getValueStrict(*UO);
+  auto *UnaryOpValue = State.Env.getValue(*UO);
   if (!UnaryOpValue) {
 UnaryOpValue = &State.Env.makeAtomicBoolValue();
 State.Env.setValueStrict(*UO, *UnaryOpValue);
@@ -133,7 +133,7 @@
 LatticeTransferState &State) {
   auto &A = State.Env.arena();
   const Formula *Comp;
-  if (BoolValue *V = cast_or_null(State.Env.getValueStrict(*BO))) {
+  if (BoolValue *V = cast_or_null(State.Env.getValue(*BO))) {
 Comp = &V->formula();
   } else {
 Comp = &A.makeAtomRef(A.makeAtom());
@@ -143,8 +143,8 @@
   // FIXME Use this as well:
   // auto *NegatedComp = &State.Env.makeNot(*Comp);
 
-  auto *LHS = State.Env.getValueStrict(*BO->getLHS());
-  auto *RHS = State.Env.getValueStrict(*BO->getRHS());
+  auto *LHS = State.Env.getValue(*BO->getLHS());
+  auto *RHS = State.Env.getValue(*BO->getRHS());
 
   if (!LHS || !RHS)
 return;
@@ -271,7 +271,7 @@
   Env.setValue(*Loc, *Val);
 }
   } else {
-Val = Env.getValueStrict(*E);
+Val = Env.getValue(*E);
 if (!Val) {
   Val = Env.createValue(E->getType());
   Env.setValueStrict(*E, *Val);
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -125,10 +125,10 @@
 private:
   TerminatorVisitorRetTy extendFlowCondition(const Expr &Cond) {
 // The terminator sub-expression might not be evaluated.
-if (Env.getValueStrict(Cond) == nullptr)
+if (Env.getValue(Cond) == nullptr)
   transfer(StmtToEnv, Cond, Env);
 
-auto *Val = cast_or_null(Env.getValueStrict(Cond));
+auto *Val = cast_or_null(Env.getValue(Cond));
 // Value merging depends on flow conditions from different environments
 // being mutually exclusive -- that is, they cannot both be true in their
 // entirety (even if they may share some clauses). So, we need *some* value
@@ -407,7 +407,7 @@
   return;
 
 ParentLoc->setChild(*Member, InitExprLoc);
-  } else if (auto *InitExprVal = Env.getValueStrict(*InitExpr)) {
+  } else if (auto *InitExprVal = Env.getValue(*InitExpr)) {
 if (Member->getType

[PATCH] D155922: [clang][dataflow] Eliminate `ReferenceValue`.

2023-07-26 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 544336.
mboehme added a comment.

Rebase to head


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155922

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
  clang/lib/Analysis/FlowSensitive/Value.cpp
  clang/unittests/Analysis/FlowSensitive/ValueTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
@@ -29,14 +29,6 @@
   EXPECT_FALSE(areEquivalentValues(V1, V2));
 }
 
-TEST(ValueTest, AliasedReferencesEquivalent) {
-  auto L = ScalarStorageLocation(QualType());
-  ReferenceValue V1(L);
-  ReferenceValue V2(L);
-  EXPECT_TRUE(areEquivalentValues(V1, V2));
-  EXPECT_TRUE(areEquivalentValues(V2, V1));
-}
-
 TEST(ValueTest, AliasedPointersEquivalent) {
   auto L = ScalarStorageLocation(QualType());
   PointerValue V1(L);
@@ -68,21 +60,12 @@
 TEST(ValueTest, DifferentKindsNotEquivalent) {
   Arena A;
   auto L = ScalarStorageLocation(QualType());
-  ReferenceValue V1(L);
+  PointerValue V1(L);
   TopBoolValue V2(A.makeAtomRef(Atom(0)));
   EXPECT_FALSE(areEquivalentValues(V1, V2));
   EXPECT_FALSE(areEquivalentValues(V2, V1));
 }
 
-TEST(ValueTest, NotAliasedReferencesNotEquivalent) {
-  auto L1 = ScalarStorageLocation(QualType());
-  ReferenceValue V1(L1);
-  auto L2 = ScalarStorageLocation(QualType());
-  ReferenceValue V2(L2);
-  EXPECT_FALSE(areEquivalentValues(V1, V2));
-  EXPECT_FALSE(areEquivalentValues(V2, V1));
-}
-
 TEST(ValueTest, NotAliasedPointersNotEquivalent) {
   auto L1 = ScalarStorageLocation(QualType());
   PointerValue V1(L1);
Index: clang/lib/Analysis/FlowSensitive/Value.cpp
===
--- clang/lib/Analysis/FlowSensitive/Value.cpp
+++ clang/lib/Analysis/FlowSensitive/Value.cpp
@@ -19,10 +19,6 @@
 
 static bool areEquivalentIndirectionValues(const Value &Val1,
const Value &Val2) {
-  if (auto *IndVal1 = dyn_cast(&Val1)) {
-auto *IndVal2 = cast(&Val2);
-return &IndVal1->getReferentLoc() == &IndVal2->getReferentLoc();
-  }
   if (auto *IndVal1 = dyn_cast(&Val1)) {
 auto *IndVal2 = cast(&Val2);
 return &IndVal1->getPointeeLoc() == &IndVal2->getPointeeLoc();
@@ -38,10 +34,6 @@
 
 raw_ostream &operator<<(raw_ostream &OS, const Value &Val) {
   switch (Val.getKind()) {
-  case Value::Kind::Reference: {
-const auto *RV = cast(&Val);
-return OS << "Reference(" << &RV->getReferentLoc() << ")";
-  }
   case Value::Kind::Pointer: {
 const auto *PV = dyn_cast(&Val);
 return OS << "Pointer(" << &PV->getPointeeLoc() << ")";
Index: clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
===
--- clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
+++ clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
@@ -99,10 +99,6 @@
 case Value::Kind::AtomicBool:
 case Value::Kind::FormulaBool:
   break;
-case Value::Kind::Reference:
-  JOS.attributeObject(
-  "referent", [&] { dump(cast(V).getReferentLoc()); });
-  break;
 case Value::Kind::Pointer:
   JOS.attributeObject(
   "pointee", [&] { dump(cast(V).getPointeeLoc()); });
Index: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
===
--- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -26,8 +26,6 @@
   switch (Kind) {
   case Value::Kind::Integer:
 return "Integer";
-  case Value::Kind::Reference:
-return "Reference";
   case Value::Kind::Pointer:
 return "Pointer";
   case Value::Kind::Struct:
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -68,7 +68,6 @@
   case ComparisonResult::Unknown:
 switch (Val1.getKind()) {
 case Value::Kind::Integer:
-case Value::Kind::Reference:
 case Value::Kind::Pointer:
 case Value::Kind::Struct:
   // FIXME: this choice intentionally introduces unsoundness to allow
@@ -140,11 +139,6 @@
 
   // FIXME: Consider destroying `MergedValue` immediately if `ValueModel::merge`
   // returns false to avoid storing unneeded values in `DACtx`.
-  // FIXME: Creating the value based on the type alone creates misshapen values
-  // for lvalues, since the type does not reflect the need for `ReferenceValue`.
-  // T

[PATCH] D155921: [clang][dataflow] Reverse course on `getValue()` deprecation.

2023-07-26 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 544337.
mboehme added a comment.

Rebase to head


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155921

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -390,7 +390,7 @@
 if (const auto *E = selectFirst(
 "call", match(cxxConstructExpr(HasSpecialBoolType).bind("call"), *S,
   getASTContext( {
-  cast(Env.getValueStrict(*E))
+  cast(Env.getValue(*E))
   ->setProperty("is_set", Env.getBoolLiteralValue(false));
 } else if (const auto *E = selectFirst(
"call", match(cxxMemberCallExpr(callee(cxxMethodDecl(ofClass(
@@ -547,7 +547,7 @@
 *S, getASTContext());
 if (const auto *E = selectFirst(
 "construct", Matches)) {
-  cast(Env.getValueStrict(*E))
+  cast(Env.getValue(*E))
   ->setProperty("has_value", Env.getBoolLiteralValue(false));
 } else if (const auto *E =
selectFirst("operator", Matches)) {
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -5524,7 +5524,7 @@
   ASTCtx));
 
 ASSERT_THAT(ImplicitCast, NotNull());
-EXPECT_THAT(Env.getValueStrict(*ImplicitCast), IsNull());
+EXPECT_THAT(Env.getValue(*ImplicitCast), IsNull());
   });
 }
 
Index: clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
@@ -114,7 +114,7 @@
 return {nullptr, {}, {}};
 
   // Value of the unary op.
-  auto *UnaryOpValue = State.Env.getValueStrict(*UO);
+  auto *UnaryOpValue = State.Env.getValue(*UO);
   if (!UnaryOpValue) {
 UnaryOpValue = &State.Env.makeAtomicBoolValue();
 State.Env.setValueStrict(*UO, *UnaryOpValue);
@@ -133,7 +133,7 @@
 LatticeTransferState &State) {
   auto &A = State.Env.arena();
   const Formula *Comp;
-  if (BoolValue *V = cast_or_null(State.Env.getValueStrict(*BO))) {
+  if (BoolValue *V = cast_or_null(State.Env.getValue(*BO))) {
 Comp = &V->formula();
   } else {
 Comp = &A.makeAtomRef(A.makeAtom());
@@ -143,8 +143,8 @@
   // FIXME Use this as well:
   // auto *NegatedComp = &State.Env.makeNot(*Comp);
 
-  auto *LHS = State.Env.getValueStrict(*BO->getLHS());
-  auto *RHS = State.Env.getValueStrict(*BO->getRHS());
+  auto *LHS = State.Env.getValue(*BO->getLHS());
+  auto *RHS = State.Env.getValue(*BO->getRHS());
 
   if (!LHS || !RHS)
 return;
@@ -271,7 +271,7 @@
   Env.setValue(*Loc, *Val);
 }
   } else {
-Val = Env.getValueStrict(*E);
+Val = Env.getValue(*E);
 if (!Val) {
   Val = Env.createValue(E->getType());
   Env.setValueStrict(*E, *Val);
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -125,10 +125,10 @@
 private:
   TerminatorVisitorRetTy extendFlowCondition(const Expr &Cond) {
 // The terminator sub-expression might not be evaluated.
-if (Env.getValueStrict(Cond) == nullptr)
+if (Env.getValue(Cond) == nullptr)
   transfer(StmtToEnv, Cond, Env);
 
-auto *Val = cast_or_null(Env.getValueStrict(Cond));
+auto *Val = cast_or_null(Env.getValue(Cond));
 // Value merging depends on flow conditions from different environments
 // being mutually exclusive -- that is, they cannot both be true in their
 // entirety (even if they may share some clauses). So, we need *some* value
@@ -407,7 +407,7 @@
   return;
 
 ParentLoc->setChild(*Member, InitExprLoc);
-  } else if (auto *InitExprVal = Env.getValueStrict(*InitExpr)) {
+  } else if (auto *InitExprVal = Env.getValue(*InitExpr)) {
 if (Member->getType

[PATCH] D156274: [NFC] Avoid potential dereferencing of nullptr.

2023-07-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added subscribers: efriedma, rjmccall.
aaron.ballman added inline comments.



Comment at: clang/lib/AST/ItaniumMangle.cpp:1659
   mangleCXXDtorType(Dtor_Complete);
+assert(ND);
 writeAbiTags(ND, AdditionalAbiTags);

This seems incorrect -- if the declaration name is a destructor, then `ND` 
should always be null, right?



Comment at: clang/lib/CodeGen/CGObjCMac.cpp:1806
 // Complex types.
+assert(contBB);
 CGF.EmitBlock(contBB);

Hmmm, is assert the correct approach here? It seems to me that a Complex rvalue 
will trigger this assertion. I think this deserves some additional thinking 
rather than silencing the static analysis warning. CC @efriedma @rjmccall who 
might have ideas.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156274

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


  1   2   3   >