[PATCH] D159250: [X86][RFC] Add new option `-m[no-]evex512` to disable ZMM and 64-bit mask instructions for AVX512 features

2023-09-01 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/lib/CodeGen/Targets/X86.cpp:1517
+  bool Caller256 = CallerMap.lookup("avx512f") && !CallerMap.lookup("evex512");
+  bool Callee256 = CallerMap.lookup("avx512f") && !CallerMap.lookup("evex512");
+

RKSimon wrote:
> typo in Callee256?
Good catch!



Comment at: clang/test/CodeGen/X86/avx512-error.c:9
+  return __builtin_ia32_sqrtpd512(a, _MM_FROUND_CUR_DIRECTION); // 
expected-error {{'__builtin_ia32_sqrtpd512' needs target feature evex512}}
+}

RKSimon wrote:
> add  __mmask64 test ? _knot_mask64 or _cvtmask64_u64 maybe?
Good point! This exposed a design problem. We cannot only check for 512-bit 
vector, instead, we need to add `evex512` to all ZMM or 64-bit mask 
builtin/intrinsic attribute list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159250

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


[PATCH] D159279: [clang] Emit `Wformat` for bool value and char specifier confusion in scanf

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

Rebase to maybe pass precommit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159279

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/FormatString.cpp
  clang/test/SemaCXX/format-strings-scanf.cpp


Index: clang/test/SemaCXX/format-strings-scanf.cpp
===
--- clang/test/SemaCXX/format-strings-scanf.cpp
+++ clang/test/SemaCXX/format-strings-scanf.cpp
@@ -29,6 +29,8 @@
 
 void test(void) {
 bag b;
+// expected-warning@+2 {{format specifies type 'char *' but the argument 
has type 'bool *'}}
+// expected-warning@+1 {{format specifies type 'unsigned char *' but the 
argument has type 'bool *'}}
 scan("%hhi %hhu %hhi %hhu", &b.sc, &b.uc, &b.b, &b.b);
 scan("%hi %hu", &b.ss, &b.us);
 scan("%i %u", &b.si, &b.ui);
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -368,8 +368,11 @@
 case BuiltinType::SChar:
 case BuiltinType::UChar:
 case BuiltinType::Char_U:
+return Match;
 case BuiltinType::Bool:
-  return Match;
+  if (!Ptr)
+return Match;
+  break;
 }
 // "Partially matched" because of promotions?
 if (!Ptr) {
@@ -410,11 +413,14 @@
 switch (BT->getKind()) {
   default:
 break;
+  case BuiltinType::Bool:
+if (Ptr && (T == C.UnsignedCharTy || T == C.SignedCharTy))
+  return NoMatch;
+[[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
-  case BuiltinType::Bool:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
 if (T == C.UnsignedCharTy || T == C.SignedCharTy)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -205,6 +205,9 @@
 - For function multi-versioning using the ``target`` or ``target_clones``
   attributes, remove comdat for internal linkage functions.
   (`#65114 `_)
+- Clang now reports ``-Wformat`` for bool value and char specifier confusion
+  in scanf. Fixes
+  (`#64987 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/format-strings-scanf.cpp
===
--- clang/test/SemaCXX/format-strings-scanf.cpp
+++ clang/test/SemaCXX/format-strings-scanf.cpp
@@ -29,6 +29,8 @@
 
 void test(void) {
 bag b;
+// expected-warning@+2 {{format specifies type 'char *' but the argument has type 'bool *'}}
+// expected-warning@+1 {{format specifies type 'unsigned char *' but the argument has type 'bool *'}}
 scan("%hhi %hhu %hhi %hhu", &b.sc, &b.uc, &b.b, &b.b);
 scan("%hi %hu", &b.ss, &b.us);
 scan("%i %u", &b.si, &b.ui);
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -368,8 +368,11 @@
 case BuiltinType::SChar:
 case BuiltinType::UChar:
 case BuiltinType::Char_U:
+return Match;
 case BuiltinType::Bool:
-  return Match;
+  if (!Ptr)
+return Match;
+  break;
 }
 // "Partially matched" because of promotions?
 if (!Ptr) {
@@ -410,11 +413,14 @@
 switch (BT->getKind()) {
   default:
 break;
+  case BuiltinType::Bool:
+if (Ptr && (T == C.UnsignedCharTy || T == C.SignedCharTy))
+  return NoMatch;
+[[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
-  case BuiltinType::Bool:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
 if (T == C.UnsignedCharTy || T == C.SignedCharTy)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -205,6 +205,9 @@
 - For function multi-versioning using the ``target`` or ``target_clones``
   attributes, remove comdat for internal linkage functions.
   (`#65114 `_)
+- Clang now reports ``-Wformat`` for bool value and char specifier confusion
+  in scanf. Fixes
+  (`#64987 

[clang] 2fd01d7 - [clang] Construct ExprRequirement with SubstitutionDiagnostic on SubstFailure

2023-09-01 Thread Younan Zhang via cfe-commits

Author: Younan Zhang
Date: 2023-09-01T15:49:39+08:00
New Revision: 2fd01d75a863184766ee0c82b5c0fc8be172448a

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

LOG: [clang] Construct ExprRequirement with SubstitutionDiagnostic on 
SubstFailure

We're expecting a SubstitutionDiagnostic in diagnoseUnsatisfiedRequirement
if the status of ExprRequirement is SubstFailure. Previously, the Requirement
was created with Expr on SubstFailure by mistake, which could lead to the
assertion failure in the subsequent diagnosis.

Fixes https://github.com/clangd/clangd/issues/1726
Fixes https://github.com/llvm/llvm-project/issues/64723
Fixes https://github.com/llvm/llvm-project/issues/64172

In addition, this patch also fixes an invalid test from D129499.

Reviewed By: erichkeane

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

Added: 
clang/test/SemaCXX/concept-crash-on-diagnostic.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprConcepts.h
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/SemaCXX/concept-fatal-error.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 15d318ef75f05a..fc96ccb992ed78 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -250,6 +250,10 @@ Bug Fixes to C++ Support
   (`#64962 `_) and
   (`#28679 `_).
 
+- Fix a crash caused by substitution failure in expression requirements.
+  (`#64172 `_) and
+  (`#64723 `_).
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.

diff  --git a/clang/include/clang/AST/ExprConcepts.h 
b/clang/include/clang/AST/ExprConcepts.h
index 6449f1b56821f0..6f38b2c4b05714 100644
--- a/clang/include/clang/AST/ExprConcepts.h
+++ b/clang/include/clang/AST/ExprConcepts.h
@@ -14,20 +14,21 @@
 #ifndef LLVM_CLANG_AST_EXPRCONCEPTS_H
 #define LLVM_CLANG_AST_EXPRCONCEPTS_H
 
-#include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTConcept.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
-#include "clang/AST/DeclarationName.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/DeclarationName.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/TrailingObjects.h"
-#include 
 #include 
+#include 
 
 namespace clang {
 class ASTStmtReader;
@@ -486,6 +487,13 @@ class NestedRequirement : public Requirement {
   }
 };
 
+using EntityPrinter = llvm::function_ref;
+
+/// \brief create a Requirement::SubstitutionDiagnostic with only a
+/// SubstitutedEntity and DiagLoc using Sema's allocator.
+Requirement::SubstitutionDiagnostic *
+createSubstDiagAt(Sema &S, SourceLocation Location, EntityPrinter Printer);
+
 } // namespace concepts
 
 /// C++2a [expr.prim.req]:

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 472fbdbdb5d0e6..833223f7968944 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -19,6 +19,7 @@
 #include "clang/AST/CharUnits.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
@@ -9080,16 +9081,22 @@ Sema::BuildExprRequirement(
 MLTAL.addOuterRetainedLevels(TPL->getDepth());
 const TypeConstraint *TC = Param->getTypeConstraint();
 assert(TC && "Type Constraint cannot be null here");
-ExprResult Constraint =
-SubstExpr(TC->getImmediatelyDeclaredConstraint(), MLTAL);
+auto *IDC = TC->getImmediatelyDeclaredConstraint();
+assert(IDC && "ImmediatelyDeclaredConstraint can't be null here.");
+ExprResult Constraint = SubstExpr(IDC, MLTAL);
 if (Constraint.isInvalid()) {
-  Status = concepts::ExprRequirement::SS_ExprSubstitutionFailure;
-} else {
-  SubstitutedConstraintExpr =
-  cast(Constraint.get());
-  if (!SubstitutedConstraintExpr->isSatisfied())
-Status = concepts::ExprRequirement::SS_ConstraintsNotSatisfied;
-}
+  return new (Context) concepts::ExprRequirement(
+  concepts::createSubstDiagAt(*this, IDC->getExprLoc(),
+  [&](llvm::raw_ostream &OS) {
+IDC->printPretty(OS, 
/*Helper=*/nullptr,
+ 

[PATCH] D158061: [clang] Construct ExprRequirement with SubstitutionDiagnostic on SubstFailure

2023-09-01 Thread Younan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2fd01d75a863: [clang] Construct ExprRequirement with 
SubstitutionDiagnostic on SubstFailure (authored by zyounan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158061

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ExprConcepts.h
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaCXX/concept-crash-on-diagnostic.cpp
  clang/test/SemaCXX/concept-fatal-error.cpp

Index: clang/test/SemaCXX/concept-fatal-error.cpp
===
--- clang/test/SemaCXX/concept-fatal-error.cpp
+++ clang/test/SemaCXX/concept-fatal-error.cpp
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -fsyntax-only -std=c++20 -ferror-limit 1 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -ferror-limit 1 -verify %s
 
 template 
 concept f = requires { 42; };
@@ -6,5 +6,5 @@
   // The missing semicolon will trigger an error and -ferror-limit=1 will make it fatal
   // We test that we do not crash in such cases (#55401)
   int i = requires { { i } f } // expected-error {{expected ';' at end of declaration list}}
-   // expected-error@* {{too many errros emitted}}
+   // expected-error@* {{too many errors emitted}}
 };
Index: clang/test/SemaCXX/concept-crash-on-diagnostic.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/concept-crash-on-diagnostic.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+
+template  class normal_iterator {};
+
+template  struct is_convertible {};
+
+template 
+inline constexpr bool is_convertible_v = is_convertible::value; // expected-error {{no member named 'value' in 'is_convertible'}}
+
+template 
+concept convertible_to = is_convertible_v; // #1
+
+template 
+  requires requires(IteratorL lhs, IteratorR rhs) { // #2
+{ lhs == rhs } -> convertible_to; // #3
+  }
+constexpr bool compare(normal_iterator lhs, normal_iterator rhs) { // #4
+  return false;
+}
+
+class Object;
+
+void function() {
+  normal_iterator begin, end;
+  compare(begin, end); // expected-error {{no matching function for call to 'compare'}} #5
+}
+
+// expected-note@#1 {{in instantiation of variable template specialization 'is_convertible_v' requested here}}
+// expected-note@#1 {{substituting template arguments into constraint expression here}}
+// expected-note@#3 {{checking the satisfaction of concept 'convertible_to'}}
+// expected-note@#2 {{substituting template arguments into constraint expression here}}
+// expected-note@#5 {{checking constraint satisfaction for template 'compare'}}
+// expected-note@#5 {{in instantiation of function template specialization 'compare' requested here}}
+
+// expected-note@#4 {{candidate template ignored: constraints not satisfied [with IteratorL = Object *, IteratorR = Object *]}}
+// We don't know exactly the substituted type for `lhs == rhs`, thus a placeholder 'expr-type' is emitted.
+// expected-note@#3 {{because 'convertible_to' would be invalid}}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2271,9 +2271,9 @@
   getPackIndex(Pack), Arg, TL.getNameLoc());
 }
 
-template
 static concepts::Requirement::SubstitutionDiagnostic *
-createSubstDiag(Sema &S, TemplateDeductionInfo &Info, EntityPrinter Printer) {
+createSubstDiag(Sema &S, TemplateDeductionInfo &Info,
+concepts::EntityPrinter Printer) {
   SmallString<128> Message;
   SourceLocation ErrorLoc;
   if (Info.hasSFINAEDiagnostic()) {
@@ -2297,6 +2297,19 @@
   StringRef(MessageBuf, Message.size())};
 }
 
+concepts::Requirement::SubstitutionDiagnostic *
+concepts::createSubstDiagAt(Sema &S, SourceLocation Location,
+EntityPrinter Printer) {
+  SmallString<128> Entity;
+  llvm::raw_svector_ostream OS(Entity);
+  Printer(OS);
+  char *EntityBuf = new (S.Context) char[Entity.size()];
+  llvm::copy(Entity, EntityBuf);
+  return new (S.Context) concepts::Requirement::SubstitutionDiagnostic{
+  /*SubstitutedEntity=*/StringRef(EntityBuf, Entity.size()),
+  /*DiagLoc=*/Location, /*DiagMessage=*/StringRef()};
+}
+
 ExprResult TemplateInstantiator::TransformRequiresTypeParams(
 SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
 RequiresExprBodyDecl *Body, ArrayRef Params,
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -19,6 +19,7 @@
 #include "clang/AST/CharUnits.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AS

[PATCH] D159174: [Clang] Use stable_sort in AppendTargetMangling

2023-09-01 Thread Dave Green via Phabricator via cfe-commits
dmgreen added a comment.

Do you have a test-case where they were out of order? Or is that dependent on 
the C++ library?

I think I just moved this code from elsewhere when I changed it, but it sounds 
like a sensible change to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159174

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


[clang] e4e56f9 - [clang] Emit `Wformat` for bool value and char specifier confusion in scanf

2023-09-01 Thread via cfe-commits

Author: Podchishchaeva, Mariya
Date: 2023-09-01T01:38:07-07:00
New Revision: e4e56f91df6a6078a82abd59e00a93b63de664b7

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

LOG: [clang] Emit `Wformat` for bool value and char specifier confusion in scanf

Fixes https://github.com/llvm/llvm-project/issues/64987

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/FormatString.cpp
clang/test/SemaCXX/format-strings-scanf.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc96ccb992ed78..e9c4010665b7c8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -205,6 +205,9 @@ Bug Fixes in This Version
 - For function multi-versioning using the ``target`` or ``target_clones``
   attributes, remove comdat for internal linkage functions.
   (`#65114 `_)
+- Clang now reports ``-Wformat`` for bool value and char specifier confusion
+  in scanf. Fixes
+  (`#64987 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index f86278e4b5163d..e0c9e18cfe3a24 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -368,8 +368,11 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 case BuiltinType::SChar:
 case BuiltinType::UChar:
 case BuiltinType::Char_U:
+return Match;
 case BuiltinType::Bool:
-  return Match;
+  if (!Ptr)
+return Match;
+  break;
 }
 // "Partially matched" because of promotions?
 if (!Ptr) {
@@ -410,11 +413,14 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 switch (BT->getKind()) {
   default:
 break;
+  case BuiltinType::Bool:
+if (Ptr && (T == C.UnsignedCharTy || T == C.SignedCharTy))
+  return NoMatch;
+[[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
-  case BuiltinType::Bool:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
 if (T == C.UnsignedCharTy || T == C.SignedCharTy)

diff  --git a/clang/test/SemaCXX/format-strings-scanf.cpp 
b/clang/test/SemaCXX/format-strings-scanf.cpp
index f78d334d1685ed..25fe5346791a0d 100644
--- a/clang/test/SemaCXX/format-strings-scanf.cpp
+++ b/clang/test/SemaCXX/format-strings-scanf.cpp
@@ -29,6 +29,8 @@ union bag {
 
 void test(void) {
 bag b;
+// expected-warning@+2 {{format specifies type 'char *' but the argument 
has type 'bool *'}}
+// expected-warning@+1 {{format specifies type 'unsigned char *' but the 
argument has type 'bool *'}}
 scan("%hhi %hhu %hhi %hhu", &b.sc, &b.uc, &b.b, &b.b);
 scan("%hi %hu", &b.ss, &b.us);
 scan("%i %u", &b.si, &b.ui);



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


[PATCH] D159279: [clang] Emit `Wformat` for bool value and char specifier confusion in scanf

2023-09-01 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe4e56f91df6a: [clang] Emit `Wformat` for bool value and char 
specifier confusion in scanf (authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159279

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/FormatString.cpp
  clang/test/SemaCXX/format-strings-scanf.cpp


Index: clang/test/SemaCXX/format-strings-scanf.cpp
===
--- clang/test/SemaCXX/format-strings-scanf.cpp
+++ clang/test/SemaCXX/format-strings-scanf.cpp
@@ -29,6 +29,8 @@
 
 void test(void) {
 bag b;
+// expected-warning@+2 {{format specifies type 'char *' but the argument 
has type 'bool *'}}
+// expected-warning@+1 {{format specifies type 'unsigned char *' but the 
argument has type 'bool *'}}
 scan("%hhi %hhu %hhi %hhu", &b.sc, &b.uc, &b.b, &b.b);
 scan("%hi %hu", &b.ss, &b.us);
 scan("%i %u", &b.si, &b.ui);
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -368,8 +368,11 @@
 case BuiltinType::SChar:
 case BuiltinType::UChar:
 case BuiltinType::Char_U:
+return Match;
 case BuiltinType::Bool:
-  return Match;
+  if (!Ptr)
+return Match;
+  break;
 }
 // "Partially matched" because of promotions?
 if (!Ptr) {
@@ -410,11 +413,14 @@
 switch (BT->getKind()) {
   default:
 break;
+  case BuiltinType::Bool:
+if (Ptr && (T == C.UnsignedCharTy || T == C.SignedCharTy))
+  return NoMatch;
+[[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
-  case BuiltinType::Bool:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
 if (T == C.UnsignedCharTy || T == C.SignedCharTy)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -205,6 +205,9 @@
 - For function multi-versioning using the ``target`` or ``target_clones``
   attributes, remove comdat for internal linkage functions.
   (`#65114 `_)
+- Clang now reports ``-Wformat`` for bool value and char specifier confusion
+  in scanf. Fixes
+  (`#64987 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/format-strings-scanf.cpp
===
--- clang/test/SemaCXX/format-strings-scanf.cpp
+++ clang/test/SemaCXX/format-strings-scanf.cpp
@@ -29,6 +29,8 @@
 
 void test(void) {
 bag b;
+// expected-warning@+2 {{format specifies type 'char *' but the argument has type 'bool *'}}
+// expected-warning@+1 {{format specifies type 'unsigned char *' but the argument has type 'bool *'}}
 scan("%hhi %hhu %hhi %hhu", &b.sc, &b.uc, &b.b, &b.b);
 scan("%hi %hu", &b.ss, &b.us);
 scan("%i %u", &b.si, &b.ui);
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -368,8 +368,11 @@
 case BuiltinType::SChar:
 case BuiltinType::UChar:
 case BuiltinType::Char_U:
+return Match;
 case BuiltinType::Bool:
-  return Match;
+  if (!Ptr)
+return Match;
+  break;
 }
 // "Partially matched" because of promotions?
 if (!Ptr) {
@@ -410,11 +413,14 @@
 switch (BT->getKind()) {
   default:
 break;
+  case BuiltinType::Bool:
+if (Ptr && (T == C.UnsignedCharTy || T == C.SignedCharTy))
+  return NoMatch;
+[[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
-  case BuiltinType::Bool:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
 if (T == C.UnsignedCharTy || T == C.SignedCharTy)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -205,6 +205,9 @@
 - For function multi-versioning using the ``target`` or ``target_clones``
   attributes, remove comdat for internal linkage functions.
   (`#65114 `_)
+- Clang now repo

[PATCH] D158050: [RISCV] RISCV vector calling convention (2/2)

2023-09-01 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat updated this revision to Diff 555304.
4vtomat added a comment.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Finish handling vector arguments in backend.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158050

Files:
  clang/include/clang/AST/Type.h
  clang/lib/CodeGen/Targets/RISCV.cpp
  clang/test/CodeGen/RISCV/riscv-vector-callingconv-llvm-ir.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vghsh.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vnmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vnmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsha2ch.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsha2cl.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsha2ms.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-xvv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfnmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfnmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfnmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfnmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vghsh.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vnmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vnmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vsha2ch.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vsha2cl.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vsha2ms.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vaadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vaaddu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vadc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vand.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vandn.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vasub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vasubu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vclmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vclmulh.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vdivu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vfadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vfdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vfmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vfmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vfmax.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenera

[PATCH] D158050: [RISCV] RISCV vector calling convention (2/2)

2023-09-01 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat added a comment.

`RVVArgDispatcher` is the class used to compute and maximize the register usage 
by using the vector argument information placed in `std::vector`, 
it's both used by `frontend` and `backend`.
Currently I'm not sure where is the better file to place this class, so I just 
place it in `RISCVTargetParser.h`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158050

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


[PATCH] D158050: [RISCV] RISCV vector calling convention (2/2)

2023-09-01 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat updated this revision to Diff 555307.
4vtomat edited the summary of this revision.
4vtomat added a comment.

Update commit message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158050

Files:
  clang/include/clang/AST/Type.h
  clang/lib/CodeGen/Targets/RISCV.cpp
  clang/test/CodeGen/RISCV/riscv-vector-callingconv-llvm-ir.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vghsh.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vnmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vnmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsha2ch.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsha2cl.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsha2ms.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-xvv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfnmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfnmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfnmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfnmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vghsh.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vnmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vnmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vsha2ch.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vsha2cl.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vsha2ms.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vaadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vaaddu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vadc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vand.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vandn.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vasub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vasubu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vclmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vclmulh.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vdivu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vfadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vfdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vfmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vfmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vfmax.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vfmin.c
  
clang/test/CodeGen/RI

[PATCH] D159345: [Clang] Handle non-ASCII after line splicing

2023-09-01 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

int a\
ス;

Failed to be parsed as a valid identifier.

Fixes #65156


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159345

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Lex/Lexer.h
  clang/lib/Lex/Lexer.cpp
  clang/test/Lexer/escape_newline_unicode.c

Index: clang/test/Lexer/escape_newline_unicode.c
===
--- /dev/null
+++ clang/test/Lexer/escape_newline_unicode.c
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -verify=expected,c -x c -Wunused %s
+// RUN: %clang_cc1 -verify=expected,cpp -x c++ -Wunused %s
+
+void gh65156(void) {
+
+int a\
+ス = 42;
+// expected-warning@-2 {{unused variable 'aス'}}
+
+int b\ 
+\ 
+ス = 42;
+// expected-warning@-2 {{backslash and newline separated by space}}
+// expected-warning@-4 {{backslash and newline separated by space}}
+// expected-warning@-5 {{unused variable 'bス'}}
+
+int ス\
+ス = 42;
+// expected-warning@-2 {{unused variable 'スス'}}
+
+int \
+ス = 42;
+// expected-warning@-2 {{unused variable 'ス'}}
+
+}
+
+void gh65156_err(void) {
+
+int \
+❌ = 0;
+// cpp-error@-2 {{expected unqualified-id}}
+// c-error@-3 {{expected identifier}}
+
+
+int a\
+❌ = 0;
+// expected-error@-1 {{character  not allowed in an identifier}}
+}
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -1750,9 +1750,17 @@
   return true;
 }
 
-bool Lexer::tryConsumeIdentifierUTF8Char(const char *&CurPtr) {
-  const char *UnicodePtr = CurPtr;
+bool Lexer::tryConsumeIdentifierUTF8Char(const char *&CurPtr, Token &Tok) {
   llvm::UTF32 CodePoint;
+
+  // If a UTF-8 codepoint appears immediately after an escaped new line,
+  // CurPtr may point to the splicing \ at the on the preceding line,
+  // so we need to skip it.
+  unsigned FirstCodeUnitSize;
+  getCharAndSize(CurPtr, FirstCodeUnitSize);
+  const char *CharStart = CurPtr + FirstCodeUnitSize - 1;
+  const char *UnicodePtr = CharStart;
+
   llvm::ConversionResult Result =
   llvm::convertUTF8Sequence((const llvm::UTF8 **)&UnicodePtr,
 (const llvm::UTF8 *)BufferEnd,
@@ -1771,21 +1779,23 @@
 !PP->isPreprocessedOutput())
   diagnoseInvalidUnicodeCodepointInIdentifier(
   PP->getDiagnostics(), LangOpts, CodePoint,
-  makeCharRange(*this, CurPtr, UnicodePtr), /*IsFirst=*/false);
+  makeCharRange(*this, CharStart, UnicodePtr), /*IsFirst=*/false);
 // We got a unicode codepoint that is neither a space nor a
 // a valid identifier part. Carry on as if the codepoint was
 // valid for recovery purposes.
   } else if (!isLexingRawMode()) {
 if (IsExtension)
-  diagnoseExtensionInIdentifier(PP->getDiagnostics(), CodePoint,
-makeCharRange(*this, CurPtr, UnicodePtr));
+  diagnoseExtensionInIdentifier(
+  PP->getDiagnostics(), CodePoint,
+  makeCharRange(*this, CharStart, UnicodePtr));
 maybeDiagnoseIDCharCompat(PP->getDiagnostics(), CodePoint,
-  makeCharRange(*this, CurPtr, UnicodePtr),
+  makeCharRange(*this, CharStart, UnicodePtr),
   /*IsFirst=*/false);
 maybeDiagnoseUTF8Homoglyph(PP->getDiagnostics(), CodePoint,
-   makeCharRange(*this, CurPtr, UnicodePtr));
+   makeCharRange(*this, CharStart, UnicodePtr));
   }
 
+  ConsumeChar(CurPtr, FirstCodeUnitSize, Tok);
   CurPtr = UnicodePtr;
   return true;
 }
@@ -1865,7 +1875,7 @@
 }
 if (C == '\\' && tryConsumeIdentifierUCN(CurPtr, Size, Result))
   continue;
-if (!isASCII(C) && tryConsumeIdentifierUTF8Char(CurPtr))
+if (!isASCII(C) && tryConsumeIdentifierUTF8Char(CurPtr, Result))
   continue;
 // Neither an expected Unicode codepoint nor a UCN.
 break;
@@ -1985,7 +1995,7 @@
   // If we have a UCN or UTF-8 character (perhaps in a ud-suffix), continue.
   if (C == '\\' && tryConsumeIdentifierUCN(CurPtr, Size, Result))
 return LexNumericConstant(Result, CurPtr);
-  if (!isASCII(C) && tryConsumeIdentifierUTF8Char(CurPtr))
+  if (!isASCII(C) && tryConsumeIdentifierUTF8Char(CurPtr, Result))
 return LexNumericConstant(Result, CurPtr);
 
   // Update the location of token as well as BufferPtr.
@@ -2009,7 +2019,7 @@
   if (!isAsciiIdentifierStart(C)) {
 if (C == '\\' && tryConsumeIdentifierUCN(CurPtr, Size, Result))
   Consumed = true;
-else if (!isASCII(C) && tryConsumeIdentifierUTF8Char(CurPtr))
+else if (!isASCII(C) && tryConsumeIdentifierUTF8Char(CurPtr, Result))
   Consumed = true;
 else
   return CurPtr;
@@ -2079,7 +2089,7 @@
 if (isAsciiIdentifierContinue(C)) {
   CurPtr

[PATCH] D159346: Revert "Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas"

2023-09-01 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh created this revision.
alexfh added reviewers: vitalybuka, nickdesaulniers.
Herald added a subscriber: jvesely.
Herald added a project: All.
alexfh requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This reverts commit e698695fbbf62e6676f8907665187f2d2c4d814b 
. The 
commit caused
invalid AddressSanitizer: stack-use-after-scope errors.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159346

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGCall.h
  clang/test/CodeGen/lifetime-call-temp.c
  clang/test/CodeGenCXX/amdgcn-call-with-aggarg.cpp
  clang/test/CodeGenCXX/stack-reuse-miscompile.cpp
  clang/test/CodeGenCoroutines/pr59181.cpp

Index: clang/test/CodeGenCoroutines/pr59181.cpp
===
--- clang/test/CodeGenCoroutines/pr59181.cpp
+++ clang/test/CodeGenCoroutines/pr59181.cpp
@@ -49,7 +49,6 @@
 }
 
 // CHECK: cleanup.cont:{{.*}}
-// CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr [[AGG:%agg.tmp[0-9]+]])
 // CHECK-NEXT: load i8
 // CHECK-NEXT: trunc
 // CHECK-NEXT: store i1 false
@@ -57,7 +56,5 @@
 
 // CHECK: await.suspend:{{.*}}
 // CHECK-NOT: call void @llvm.lifetime.start.p0(i64 8, ptr [[REF]])
-// CHECK-NOT: call void @llvm.lifetime.start.p0(i64 8, ptr [[AGG]])
 // CHECK: call void @_ZZN4Task12promise_type15await_transformES_EN10Suspension13await_suspendESt16coroutine_handleIvE
-// CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 8, ptr [[AGG2:%agg.tmp[0-9]+]])
 // CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 8, ptr [[REF]])
Index: clang/test/CodeGenCXX/stack-reuse-miscompile.cpp
===
--- clang/test/CodeGenCXX/stack-reuse-miscompile.cpp
+++ clang/test/CodeGenCXX/stack-reuse-miscompile.cpp
@@ -26,8 +26,6 @@
 // CHECK: [[T2:%.*]] = alloca %class.T, align 4
 // CHECK: [[T3:%.*]] = alloca %class.T, align 4
 //
-// CHECK: [[AGG:%.*]] = alloca %class.S, align 4
-//
 // FIXME: We could defer starting the lifetime of the return object of concat
 // until the call.
 // CHECK: call void @llvm.lifetime.start.p0(i64 16, ptr [[T1]])
@@ -36,9 +34,7 @@
 // CHECK: [[T4:%.*]] = call noundef ptr @_ZN1TC1EPKc(ptr {{[^,]*}} [[T2]], ptr noundef @.str)
 //
 // CHECK: call void @llvm.lifetime.start.p0(i64 16, ptr [[T3]])
-// CHECK: call void @llvm.lifetime.start.p0(i64 8, ptr [[AGG]])
 // CHECK: [[T5:%.*]] = call noundef ptr @_ZN1TC1E1S(ptr {{[^,]*}} [[T3]], [2 x i32] %{{.*}})
-// CHECK: call void @llvm.lifetime.end.p0(i64 8, ptr [[AGG]]
 //
 // CHECK: call void @_ZNK1T6concatERKS_(ptr sret(%class.T) align 4 [[T1]], ptr {{[^,]*}} [[T2]], ptr noundef nonnull align 4 dereferenceable(16) [[T3]])
 // CHECK: [[T6:%.*]] = call noundef ptr @_ZNK1T3strEv(ptr {{[^,]*}} [[T1]])
Index: clang/test/CodeGenCXX/amdgcn-call-with-aggarg.cpp
===
--- clang/test/CodeGenCXX/amdgcn-call-with-aggarg.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm -O3 -disable-llvm-passes -o - %s | FileCheck %s
-
-struct A {
-  float x, y, z, w;
-};
-
-void foo(A a);
-
-// CHECK-LABEL: @_Z4testv
-// CHECK: [[A:%.*]] = alloca [[STRUCT_A:%.*]], align 4, addrspace(5)
-// CHECK-NEXT:[[AGG_TMP:%.*]] = alloca [[STRUCT_A]], align 4, addrspace(5)
-// CHECK-NEXT:[[A_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[A]] to ptr
-// CHECK-NEXT:[[AGG_TMP_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[AGG_TMP]] to ptr
-// CHECK-NEXT:call void @llvm.lifetime.start.p5(i64 16, ptr addrspace(5) [[A]]) #[[ATTR4:[0-9]+]]
-// CHECK-NEXT:call void @llvm.lifetime.start.p5(i64 16, ptr addrspace(5) [[AGG_TMP]]) #[[ATTR4]]
-void test() {
-  A a;
-  foo(a);
-}
Index: clang/test/CodeGen/lifetime-call-temp.c
===
--- clang/test/CodeGen/lifetime-call-temp.c
+++ /dev/null
@@ -1,81 +0,0 @@
-// RUN: %clang -cc1  -triple x86_64-apple-macos -O1 -disable-llvm-passes %s -S -emit-llvm -o - | FileCheck %s --implicit-check-not=llvm.lifetime
-// RUN: %clang -cc1 -xc++ -std=c++17 -triple x86_64-apple-macos -O1 -disable-llvm-passes %s -S -emit-llvm -o - -Wno-return-type-c-linkage | FileCheck %s --implicit-check-not=llvm.lifetime --check-prefix=CHECK --check-prefix=CXX
-// RUN: %clang -cc1 -xobjective-c-triple x86_64-apple-macos -O1 -disable-llvm-passes %s -S -emit-llvm -o - | FileCheck %s --implicit-check-not=llvm.lifetime --check-prefix=CHECK --check-prefix=OBJC
-
-typedef struct { int x[100]; } aggregate;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void takes_aggregate(aggregate);
-aggregate gives_aggregate();
-
-// CHECK-LABEL: define void @t1
-void t1() {
-  takes_aggregate(gives_aggregate());
-
-  // CHECK: [[AGGTMP:%.*]] = alloca %struct.aggregate, align 8
-  // CHECK: call void @llvm.lifetime.st

[PATCH] D159105: [analyzer] ArrayBoundCheckerV2 should check the region for taint as well

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

In D159105#4631504 , @steakhal wrote:

> There are still a few FPs of the kind, where they iterate over the result of 
> `getenv` in a loop, and continuously checks the character against the zero 
> terminator.
> I refined the suppression heuristic as follows:
>
> - If the offset is zero, don't report taint issue. (as I suggested in the 
> previous heuristic)
> - If the offset is non-zero, calculate the offset for the previous element 
> and check if the value there is proven to be non-zero. If it cannot be zero, 
> don't report this taint issue.
>
> I'll check the results tomorrow.

There are still FPs. I'll refine the heuristic to accept any constraint.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159105

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


[PATCH] D158707: [analyzer] Fix a few size-type signedness inconsistency related to DynamicExtent

2023-09-01 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/test/Analysis/memory-model.cpp:167
+  clang_analyzer_dumpExtent(a);   // expected-warning {{0 S64b}}
+  clang_analyzer_dumpElementCount(a); // expected-warning {{5 S64b}}
+  clang_analyzer_dumpExtent(t);   // expected-warning {{0 S64b}}

donat.nagy wrote:
> steakhal wrote:
> > If the array has zero extent, how can is have any elements?
> It has five elements, each element is a 0-element array, total size is 5*0 = 
> 0.
Okay, makes sense. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158707

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


[PATCH] D74094: Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas

2023-09-01 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added subscribers: vitalybuka, alexfh.
alexfh added a comment.

This commit caused invalid AddressSanitizer: stack-use-after-scope errors in 
our internal setup. Trying to create a standalone repro, but so far we think 
that the patch is incorrect. @vitalybuka says "The patch seems wrong, callee 
can return a reference to temp, so lifetime should be extended to full 
expression."


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74094

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


[PATCH] D159233: [clang-format][NFC] Change duplicate config files to symlinks

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

out of interest what happens on windows?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159233

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


[PATCH] D158363: [clang-format] Fix segmentation fault when formatting nested namespaces

2023-09-01 Thread Arkadiy Yudintsev via Phabricator via cfe-commits
d0nc1h0t updated this revision to Diff 555317.
d0nc1h0t added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158363

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4180,6 +4180,16 @@
"void foo() {}\n"
"} // namespace ns",
Style);
+
+  FormatStyle LLVMWithCompactInnerNamespace = getLLVMStyle();
+  LLVMWithCompactInnerNamespace.CompactNamespaces = true;
+  LLVMWithCompactInnerNamespace.NamespaceIndentation = FormatStyle::NI_Inner;
+  verifyFormat("namespace ns1 { namespace ns2 { namespace ns3 {\n"
+   "// block for debug mode\n"
+   "#ifndef NDEBUG\n"
+   "#endif\n"
+   "}}} // namespace ns1::ns2::ns3",
+   LLVMWithCompactInnerNamespace);
 }
 
 TEST_F(FormatTest, NamespaceMacros) {
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -386,11 +386,14 @@
   // Reduce indent level for bodies of namespaces which were compacted,
   // but only if their content was indented in the first place.
   auto *ClosingLine = AnnotatedLines.begin() + ClosingLineIndex + 1;
-  auto OutdentBy = I[J]->Level - TheLine->Level;
+  const int OutdentBy = I[J]->Level - TheLine->Level;
+  assert(OutdentBy >= 0);
   for (auto *CompactedLine = I + J; CompactedLine <= ClosingLine;
++CompactedLine) {
-if (!(*CompactedLine)->InPPDirective)
-  (*CompactedLine)->Level -= OutdentBy;
+if (!(*CompactedLine)->InPPDirective) {
+  const int Level = (*CompactedLine)->Level;
+  (*CompactedLine)->Level = std::max(Level - OutdentBy, 0);
+}
   }
 }
 return J - 1;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4180,6 +4180,16 @@
"void foo() {}\n"
"} // namespace ns",
Style);
+
+  FormatStyle LLVMWithCompactInnerNamespace = getLLVMStyle();
+  LLVMWithCompactInnerNamespace.CompactNamespaces = true;
+  LLVMWithCompactInnerNamespace.NamespaceIndentation = FormatStyle::NI_Inner;
+  verifyFormat("namespace ns1 { namespace ns2 { namespace ns3 {\n"
+   "// block for debug mode\n"
+   "#ifndef NDEBUG\n"
+   "#endif\n"
+   "}}} // namespace ns1::ns2::ns3",
+   LLVMWithCompactInnerNamespace);
 }
 
 TEST_F(FormatTest, NamespaceMacros) {
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -386,11 +386,14 @@
   // Reduce indent level for bodies of namespaces which were compacted,
   // but only if their content was indented in the first place.
   auto *ClosingLine = AnnotatedLines.begin() + ClosingLineIndex + 1;
-  auto OutdentBy = I[J]->Level - TheLine->Level;
+  const int OutdentBy = I[J]->Level - TheLine->Level;
+  assert(OutdentBy >= 0);
   for (auto *CompactedLine = I + J; CompactedLine <= ClosingLine;
++CompactedLine) {
-if (!(*CompactedLine)->InPPDirective)
-  (*CompactedLine)->Level -= OutdentBy;
+if (!(*CompactedLine)->InPPDirective) {
+  const int Level = (*CompactedLine)->Level;
+  (*CompactedLine)->Level = std::max(Level - OutdentBy, 0);
+}
   }
 }
 return J - 1;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D74094: Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas

2023-09-01 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In D74094#4633785 , @alexfh wrote:

> This commit caused invalid AddressSanitizer: stack-use-after-scope errors in 
> our internal setup. Trying to create a standalone repro, but so far we think 
> that the patch is incorrect. @vitalybuka says "The patch seems wrong, callee 
> can return a reference to temp, so lifetime should be extended to full 
> expression."

A standalone reproducer is here: https://gcc.godbolt.org/z/Ed1s15Kv5. The test 
passes when compiled with clang before this patch, and generates a bogus 
address sanitizer error after this patch. This only happens with 
`-march=haswell`.

The affected code is:

  #include 
  #include 
  #include 
  #include 
  
  template 
  auto AsArray(const Tensor& t)
  -> absl::Span {
return {t.data(), (size_t)t.size()};
  }
  using testing::ElementsAre;
  
  int main() {
using Tensor = Eigen::TensorFixedSize,
 Eigen::RowMajor, Eigen::DenseIndex>;
Tensor a;
a.setValues({{1, 2}, {3, 4}});
auto round = [](Tensor m) {
  return (m + 0.5f).cast().cast();
};
  
const Tensor t3 = round(a.log().exp());
EXPECT_THAT(AsArray(t3), ElementsAre(1, 2, 3, 4));
  }

The problem reproduces with `clang -std=c++17 -O3 -fsanitize=address 
-march=haswell`.

I'm going to revert the commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74094

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


[clang-tools-extra] 69feef0 - [clangd][tests] Assert for idleness of scheduler

2023-09-01 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-09-01T12:19:09+02:00
New Revision: 69feef0e827793fd1c9df5dddc736441ff46f8af

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

LOG: [clangd][tests] Assert for idleness of scheduler

We could fail going idle in 5 seconds and get spurious errors
afterwards. See https://github.com/llvm/llvm-project/issues/64964.

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp 
b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
index 5d5b618a854806..a3c1916b9b1d41 100644
--- a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -1307,7 +1307,7 @@ TEST_F(TUSchedulerTests, PublishWithStalePreamble) {
   ASSERT_THAT(BlockForDiags(PI), testing::Pair("1", "3"));
 
   UnblockPreamble.notify();
-  S.blockUntilIdle(timeoutSeconds(5));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(5)));
 
   // Make sure that we have eventual consistency.
   EXPECT_THAT(Collector.diagVersions().back(), Pair(PI.Version, PI.Version));
@@ -1316,7 +1316,7 @@ TEST_F(TUSchedulerTests, PublishWithStalePreamble) {
   PI.Version = "4";
   PI.Contents = "#define FOO\n" + PI.Version;
   S.update(File, PI, WantDiagnostics::No);
-  S.blockUntilIdle(timeoutSeconds(5));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(5)));
   EXPECT_THAT(Collector.diagVersions().back(), Pair("3", "3"));
 }
 



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


[clang-tools-extra] 16b8b3e - [clangd][tests] Bump timeouts in TUSchedulerTests to 60 secs

2023-09-01 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-09-01T12:19:10+02:00
New Revision: 16b8b3e59f7e5d64d4bb4e252a6fea5235feb630

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

LOG: [clangd][tests] Bump timeouts in TUSchedulerTests to 60 secs

There are some slow/congested bots, that can't go idle in 10 secs, see 
https://github.com/llvm/llvm-project/issues/64964

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp 
b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
index a3c1916b9b1d41..4f028f2cbe5a14 100644
--- a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -251,7 +251,7 @@ TEST_F(TUSchedulerTests, WantDiagnostics) {
 [&](std::vector) { ++CallbackCount; });
 Ready.notify();
 
-ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
   }
   EXPECT_EQ(2, CallbackCount);
 }
@@ -274,7 +274,7 @@ TEST_F(TUSchedulerTests, Debounce) {
   Notification N;
   updateWithDiags(S, Path, "auto (timed out)", WantDiagnostics::Auto,
   [&](std::vector) { N.notify(); });
-  EXPECT_TRUE(N.wait(timeoutSeconds(5)));
+  EXPECT_TRUE(N.wait(timeoutSeconds(60)));
 
   // Once we start shutting down the TUScheduler, this one becomes a dead 
write.
   updateWithDiags(S, Path, "auto (discarded)", WantDiagnostics::Auto,
@@ -340,7 +340,7 @@ TEST_F(TUSchedulerTests, Cancellation) {
 Read("R3")();
 Proceed.notify();
 
-ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
   }
   EXPECT_THAT(DiagsSeen, ElementsAre("U2", "U3"))
   << "U1 and all dependent reads were cancelled. "
@@ -361,7 +361,7 @@ TEST_F(TUSchedulerTests, InvalidationNoCrash) {
   // We expect invalidation logic to not crash by trying to invalidate a 
running
   // request.
   S.update(Path, getInputs(Path, ""), WantDiagnostics::Auto);
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
   S.runWithAST(
   "invalidatable-but-running", Path,
   [&](llvm::Expected AST) {
@@ -373,7 +373,7 @@ TEST_F(TUSchedulerTests, InvalidationNoCrash) {
   StartedRunning.wait();
   S.update(Path, getInputs(Path, ""), WantDiagnostics::Auto);
   ScheduledChange.notify();
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
 }
 
 TEST_F(TUSchedulerTests, Invalidation) {
@@ -429,7 +429,7 @@ TEST_F(TUSchedulerTests, Invalidation) {
   },
   TUScheduler::InvalidateOnUpdate);
   Start.notify();
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
 
   EXPECT_EQ(2, Builds.load()) << "Middle build should be skipped";
   EXPECT_EQ(4, Actions.load()) << "All actions should run (some with error)";
@@ -462,7 +462,7 @@ TEST_F(TUSchedulerTests, InvalidationUnchanged) {
 ADD_FAILURE() << "Shouldn't build, identical to previous";
   });
   Start.notify();
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
 
   EXPECT_EQ(1, Actions.load()) << "All actions should run";
 }
@@ -569,7 +569,7 @@ TEST_F(TUSchedulerTests, ManyUpdates) {
 }
   }
 }
-ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
   } // TUScheduler destructor waits for all operations to finish.
 
   std::lock_guard Lock(Mut);
@@ -611,7 +611,7 @@ TEST_F(TUSchedulerTests, EvictedAST) {
   // one that the cache will evict.
   updateWithCallback(S, Foo, SourceContents, WantDiagnostics::Yes,
  [&BuiltASTCounter]() { ++BuiltASTCounter; });
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
   ASSERT_EQ(BuiltASTCounter.load(), 1);
   EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "hit"), SizeIs(0));
   EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "miss"), SizeIs(1));
@@ -622,7 +622,7 @@ TEST_F(TUSchedulerTests, EvictedAST) {
  [&BuiltASTCounter]() { ++BuiltASTCounter; });
   updateWithCallback(S, Baz, SourceContents, WantDiagnostics::Yes,
  [&BuiltASTCounter]() { ++BuiltASTCounter; });
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
   ASSERT_EQ(BuiltASTCounter.load(), 3);
   EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "hit"), SizeIs(0));
   EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "miss"), SizeIs(2));
@@ -633,7 +633,7 @@ TES

[PATCH] D159337: [clangd][tests] Assert for idleness of scheduler

2023-09-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG69feef0e8277: [clangd][tests] Assert for idleness of 
scheduler (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159337

Files:
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp


Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -1307,7 +1307,7 @@
   ASSERT_THAT(BlockForDiags(PI), testing::Pair("1", "3"));
 
   UnblockPreamble.notify();
-  S.blockUntilIdle(timeoutSeconds(5));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(5)));
 
   // Make sure that we have eventual consistency.
   EXPECT_THAT(Collector.diagVersions().back(), Pair(PI.Version, PI.Version));
@@ -1316,7 +1316,7 @@
   PI.Version = "4";
   PI.Contents = "#define FOO\n" + PI.Version;
   S.update(File, PI, WantDiagnostics::No);
-  S.blockUntilIdle(timeoutSeconds(5));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(5)));
   EXPECT_THAT(Collector.diagVersions().back(), Pair("3", "3"));
 }
 


Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -1307,7 +1307,7 @@
   ASSERT_THAT(BlockForDiags(PI), testing::Pair("1", "3"));
 
   UnblockPreamble.notify();
-  S.blockUntilIdle(timeoutSeconds(5));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(5)));
 
   // Make sure that we have eventual consistency.
   EXPECT_THAT(Collector.diagVersions().back(), Pair(PI.Version, PI.Version));
@@ -1316,7 +1316,7 @@
   PI.Version = "4";
   PI.Contents = "#define FOO\n" + PI.Version;
   S.update(File, PI, WantDiagnostics::No);
-  S.blockUntilIdle(timeoutSeconds(5));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(5)));
   EXPECT_THAT(Collector.diagVersions().back(), Pair("3", "3"));
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159338: [clangd][tests] Bump timeouts in TUSchedulerTests to 60 secs

2023-09-01 Thread Kadir Cetinkaya 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 rG16b8b3e59f7e: [clangd][tests] Bump timeouts in 
TUSchedulerTests to 60 secs (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159338

Files:
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -251,7 +251,7 @@
 [&](std::vector) { ++CallbackCount; });
 Ready.notify();
 
-ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
   }
   EXPECT_EQ(2, CallbackCount);
 }
@@ -274,7 +274,7 @@
   Notification N;
   updateWithDiags(S, Path, "auto (timed out)", WantDiagnostics::Auto,
   [&](std::vector) { N.notify(); });
-  EXPECT_TRUE(N.wait(timeoutSeconds(5)));
+  EXPECT_TRUE(N.wait(timeoutSeconds(60)));
 
   // Once we start shutting down the TUScheduler, this one becomes a dead write.
   updateWithDiags(S, Path, "auto (discarded)", WantDiagnostics::Auto,
@@ -340,7 +340,7 @@
 Read("R3")();
 Proceed.notify();
 
-ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
   }
   EXPECT_THAT(DiagsSeen, ElementsAre("U2", "U3"))
   << "U1 and all dependent reads were cancelled. "
@@ -361,7 +361,7 @@
   // We expect invalidation logic to not crash by trying to invalidate a running
   // request.
   S.update(Path, getInputs(Path, ""), WantDiagnostics::Auto);
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
   S.runWithAST(
   "invalidatable-but-running", Path,
   [&](llvm::Expected AST) {
@@ -373,7 +373,7 @@
   StartedRunning.wait();
   S.update(Path, getInputs(Path, ""), WantDiagnostics::Auto);
   ScheduledChange.notify();
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
 }
 
 TEST_F(TUSchedulerTests, Invalidation) {
@@ -429,7 +429,7 @@
   },
   TUScheduler::InvalidateOnUpdate);
   Start.notify();
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
 
   EXPECT_EQ(2, Builds.load()) << "Middle build should be skipped";
   EXPECT_EQ(4, Actions.load()) << "All actions should run (some with error)";
@@ -462,7 +462,7 @@
 ADD_FAILURE() << "Shouldn't build, identical to previous";
   });
   Start.notify();
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
 
   EXPECT_EQ(1, Actions.load()) << "All actions should run";
 }
@@ -569,7 +569,7 @@
 }
   }
 }
-ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
   } // TUScheduler destructor waits for all operations to finish.
 
   std::lock_guard Lock(Mut);
@@ -611,7 +611,7 @@
   // one that the cache will evict.
   updateWithCallback(S, Foo, SourceContents, WantDiagnostics::Yes,
  [&BuiltASTCounter]() { ++BuiltASTCounter; });
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
   ASSERT_EQ(BuiltASTCounter.load(), 1);
   EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "hit"), SizeIs(0));
   EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "miss"), SizeIs(1));
@@ -622,7 +622,7 @@
  [&BuiltASTCounter]() { ++BuiltASTCounter; });
   updateWithCallback(S, Baz, SourceContents, WantDiagnostics::Yes,
  [&BuiltASTCounter]() { ++BuiltASTCounter; });
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
   ASSERT_EQ(BuiltASTCounter.load(), 3);
   EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "hit"), SizeIs(0));
   EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "miss"), SizeIs(2));
@@ -633,7 +633,7 @@
   // Access the old file again.
   updateWithCallback(S, Foo, OtherSourceContents, WantDiagnostics::Yes,
  [&BuiltASTCounter]() { ++BuiltASTCounter; });
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
   ASSERT_EQ(BuiltASTCounter.load(), 4);
   EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "hit"), SizeIs(0));
   EXPECT_THAT(Tracer.takeMetric("ast_access_diag", "miss"), SizeIs(1));
@@ -659,16 +659,16 @@
 
   // After opening Foo then Bar, AST cache contains Bar.
   S.update(Foo, FooInputs, WantDiagnostics::Auto);
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(60)));
   S.update(Bar, BarInputs, WantDiagnostics::

[PATCH] D158566: Add CLANGD_INCLUDE_TESTS as a separate flag to control clangd tests

2023-09-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

In D158566#4616417 , @ilya-biryukov 
wrote:

> Open question: I also feel like the best option here is to fix the tests, but 
> I'm not sure how hard that would be. @sammccall any thoughts?
> I suspect the particular tests are flaky is because they rely on timeouts, 
> not sure it's easy to disentangle them. Therefore, some workaround seems 
> reasonable

FWIW, i've put some details in 
https://github.com/llvm/llvm-project/issues/64964#issuecomment-1702249740 and 
we had some previous discussions but unfortunately these tests have timeouts as 
a "poor-mans-deadlock-detection". i don't think we can get rid of the timeouts, 
without sacrificing that detection.
I can't remember how misleading buildbot outputs were, when deadlocks happened, 
before we introduced timeouts though. So one alternative is let the buildbots 
hang instead.

---

Regarding the approach in this patch, I don't feel strongly about it but I 
don't think it's a good idea to let people build clangd, without testing it on 
environments they care about. They might suppress legitimate issues. (there's 
also some value though, e.g. maybe they already performed testing before, and 
don't want to run tests again, but in such a scenario we've non-check 
equivalents of targets to only run builds).

Are you building clangd deliberately or is it just being pulled in via 
check-clang-tools? If you don't want to ship clangd with your toolchain at all, 
I think it's better to set `CLANG_ENABLE_CLANGD` to `OFF`.


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

https://reviews.llvm.org/D158566

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


[PATCH] D159105: [analyzer] ArrayBoundCheckerV2 should check the region for taint as well

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

As I thought more about this commit I realized that I have two vague but 
significant concerns. I'm sorry that I wasn't able to describe these before you 
started to dig into the details of the heuristics.

(1) I don't think that code like `int *ptr; scanf("%ld", &ptr);` should be 
covered by an ArrayBound checker: this is not just a "be careful with the value 
of the index" issue, but a raw pointer that's completely controlled by an 
untrusted source. I'd try to cover this kind of bug with either the StdLibrary 
checker or a small new checker [or perhaps just a clang-tidy check] which would 
report pointers coming from `scanf` or other user input even if it doesn't see 
a dereference of the pointer value.

(2) Taintedness of a memory region (i.e. `isTainted(state, location)` where 
`location` is presumably a `MemRegionVal`) is poorly defined and might mean 
three different things:
(a) **The 'begin' pointer value of the region is tainted** (controlled by an 
untrusted source). This may be a "we're already dead" situation (e.g. the 
pointer is an arbitrary value from `scanf`) or something completely harmless 
(we are examining something like the second subscript operator in 
`large_array[user_input].field[idx]` after verifying that the first subscript 
with the tainted index is valid), but in either case, the reliability of the 
'begin' pointer should not affect the comparison between the region extent and 
the index value.
(b)** The extent of the region is tainted** (controlled by an untrusted source, 
e.g. it's an user input string with an unknown length). In this case it's 
reasonable to turn on the "paranoid" comparison mode -- however, this situation 
should be recorded by marking the //extent symbol// of the region as tainted 
instead of marking the region itself as tainted. I'd be happy to see a commit 
that ensures that the extent symbol of user input strings is tainted and its 
taintedness is handled in ArrayBoundsV2.
(c)** The contents of the region are tainted** (controlled by an untrusted 
source). Arguably this should be recorded by marking the //contents// as 
tainted, but that's difficult to implement on a string/array, so it's a 
somewhat reasonable shortcut to put the taint on the region itself. This kind 
of taint is completely irrelevant for out of bounds memory access and should 
not affect the comparisons.

In summary, I'd say that this checker should not be affected by the taintedness 
of the memory region itself (but it should continue to monitor tainted indices, 
and if possible, it should be extended to handle tainted extent values). I'm 
not completely opposed to merging this patch if you add enough heuristics and 
workarounds to make it stable in practice, but I feel that this is not the 
right way forward.

It's fortunate that we'll meet in person on Monday because there we can discuss 
this topic (and other plans) in more detail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159105

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


[clang] b7f4915 - Revert "Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas"

2023-09-01 Thread Alexander Kornienko via cfe-commits

Author: Alexander Kornienko
Date: 2023-09-01T12:53:24+02:00
New Revision: b7f4915644844fb9f32e8763922a070f5fe4fd29

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

LOG: Revert "Reapply: [IRGen] Emit lifetime intrinsics around temporary 
aggregate argument allocas"

This reverts commit e698695fbbf62e6676f8907665187f2d2c4d814b. The commit caused
invalid AddressSanitizer: stack-use-after-scope errors.

See https://reviews.llvm.org/D74094#4633785 for details.

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

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGCall.h
clang/test/CodeGenCXX/stack-reuse-miscompile.cpp
clang/test/CodeGenCoroutines/pr59181.cpp

Removed: 
clang/test/CodeGen/lifetime-call-temp.c
clang/test/CodeGenCXX/amdgcn-call-with-aggarg.cpp



diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index af05eec0ce19fc..37ccd0d8a2c6cd 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -40,7 +40,6 @@
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/Type.h"
-#include "llvm/Support/TypeSize.h"
 #include "llvm/Transforms/Utils/Local.h"
 #include 
 using namespace clang;
@@ -4616,24 +4615,7 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, 
const Expr *E,
 return;
   }
 
-  AggValueSlot ArgSlot = AggValueSlot::ignored();
-  if (hasAggregateEvaluationKind(E->getType())) {
-Address ArgSlotAlloca = Address::invalid();
-ArgSlot = CreateAggTemp(E->getType(), "agg.tmp", &ArgSlotAlloca);
-
-// Emit a lifetime start/end for this temporary. If the type has a
-// destructor, then we need to keep it alive. FIXME: We should still be 
able
-// to end the lifetime after the destructor returns.
-if (!E->getType().isDestructedType()) {
-  llvm::TypeSize size =
-  
CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(E->getType()));
-  if (llvm::Value *lifetimeSize =
-  EmitLifetimeStart(size, ArgSlotAlloca.getPointer()))
-args.addLifetimeCleanup({ArgSlotAlloca.getPointer(), lifetimeSize});
-}
-  }
-
-  args.add(EmitAnyExpr(E, ArgSlot), type);
+  args.add(EmitAnyExprToTemp(E), type);
 }
 
 QualType CodeGenFunction::getVarArgType(const Expr *Arg) {
@@ -5822,9 +5804,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   for (CallLifetimeEnd &LifetimeEnd : CallLifetimeEndAfterCall)
 LifetimeEnd.Emit(*this, /*Flags=*/{});
 
-  for (const CallArgList::EndLifetimeInfo < : CallArgs.getLifetimeCleanups())
-EmitLifetimeEnd(LT.Size, LT.Addr);
-
   if (!ReturnValue.isExternallyDestructed() &&
   RetTy.isDestructedType() == QualType::DK_nontrivial_c_struct)
 pushDestroy(QualType::DK_nontrivial_c_struct, Ret.getAggregateAddress(),

diff  --git a/clang/lib/CodeGen/CGCall.h b/clang/lib/CodeGen/CGCall.h
index cc0b1daf338e65..aee86a3242fd3f 100644
--- a/clang/lib/CodeGen/CGCall.h
+++ b/clang/lib/CodeGen/CGCall.h
@@ -278,11 +278,6 @@ class CallArgList : public SmallVector {
 llvm::Instruction *IsActiveIP;
   };
 
-  struct EndLifetimeInfo {
-llvm::Value *Addr;
-llvm::Value *Size;
-  };
-
   void add(RValue rvalue, QualType type) { push_back(CallArg(rvalue, type)); }
 
   void addUncopiedAggregate(LValue LV, QualType type) {
@@ -299,9 +294,6 @@ class CallArgList : public SmallVector {
 CleanupsToDeactivate.insert(CleanupsToDeactivate.end(),
 other.CleanupsToDeactivate.begin(),
 other.CleanupsToDeactivate.end());
-LifetimeCleanups.insert(LifetimeCleanups.end(),
-other.LifetimeCleanups.begin(),
-other.LifetimeCleanups.end());
 assert(!(StackBase && other.StackBase) && "can't merge stackbases");
 if (!StackBase)
   StackBase = other.StackBase;
@@ -341,14 +333,6 @@ class CallArgList : public SmallVector {
   /// memory.
   bool isUsingInAlloca() const { return StackBase; }
 
-  void addLifetimeCleanup(EndLifetimeInfo Info) {
-LifetimeCleanups.push_back(Info);
-  }
-
-  ArrayRef getLifetimeCleanups() const {
-return LifetimeCleanups;
-  }
-
 private:
   SmallVector Writebacks;
 
@@ -357,10 +341,6 @@ class CallArgList : public SmallVector {
   /// occurs.
   SmallVector CleanupsToDeactivate;
 
-  /// Lifetime information needed to call llvm.lifetime.end for any temporary
-  /// argument allocas.
-  SmallVector LifetimeCleanups;
-
   /// The stacksave call.  It dominates all of the argument evaluation.
   llvm::CallInst *StackBase = nullptr;
 };

diff  --git a/clang/test/CodeGen/lifetime-call-temp.c 
b/clang/test/CodeGen/lifetime-call-temp.c
deleted file mode 100644
index fcc225aeb07a3f..00
--- a/clang/test/Code

[PATCH] D159346: Revert "Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas"

2023-09-01 Thread Alexander Kornienko via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb7f491564484: Revert "Reapply: [IRGen] Emit lifetime 
intrinsics around temporary aggregate… (authored by alexfh).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159346

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGCall.h
  clang/test/CodeGen/lifetime-call-temp.c
  clang/test/CodeGenCXX/amdgcn-call-with-aggarg.cpp
  clang/test/CodeGenCXX/stack-reuse-miscompile.cpp
  clang/test/CodeGenCoroutines/pr59181.cpp

Index: clang/test/CodeGenCoroutines/pr59181.cpp
===
--- clang/test/CodeGenCoroutines/pr59181.cpp
+++ clang/test/CodeGenCoroutines/pr59181.cpp
@@ -49,7 +49,6 @@
 }
 
 // CHECK: cleanup.cont:{{.*}}
-// CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr [[AGG:%agg.tmp[0-9]+]])
 // CHECK-NEXT: load i8
 // CHECK-NEXT: trunc
 // CHECK-NEXT: store i1 false
@@ -57,7 +56,5 @@
 
 // CHECK: await.suspend:{{.*}}
 // CHECK-NOT: call void @llvm.lifetime.start.p0(i64 8, ptr [[REF]])
-// CHECK-NOT: call void @llvm.lifetime.start.p0(i64 8, ptr [[AGG]])
 // CHECK: call void @_ZZN4Task12promise_type15await_transformES_EN10Suspension13await_suspendESt16coroutine_handleIvE
-// CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 8, ptr [[AGG2:%agg.tmp[0-9]+]])
 // CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 8, ptr [[REF]])
Index: clang/test/CodeGenCXX/stack-reuse-miscompile.cpp
===
--- clang/test/CodeGenCXX/stack-reuse-miscompile.cpp
+++ clang/test/CodeGenCXX/stack-reuse-miscompile.cpp
@@ -26,8 +26,6 @@
 // CHECK: [[T2:%.*]] = alloca %class.T, align 4
 // CHECK: [[T3:%.*]] = alloca %class.T, align 4
 //
-// CHECK: [[AGG:%.*]] = alloca %class.S, align 4
-//
 // FIXME: We could defer starting the lifetime of the return object of concat
 // until the call.
 // CHECK: call void @llvm.lifetime.start.p0(i64 16, ptr [[T1]])
@@ -36,9 +34,7 @@
 // CHECK: [[T4:%.*]] = call noundef ptr @_ZN1TC1EPKc(ptr {{[^,]*}} [[T2]], ptr noundef @.str)
 //
 // CHECK: call void @llvm.lifetime.start.p0(i64 16, ptr [[T3]])
-// CHECK: call void @llvm.lifetime.start.p0(i64 8, ptr [[AGG]])
 // CHECK: [[T5:%.*]] = call noundef ptr @_ZN1TC1E1S(ptr {{[^,]*}} [[T3]], [2 x i32] %{{.*}})
-// CHECK: call void @llvm.lifetime.end.p0(i64 8, ptr [[AGG]]
 //
 // CHECK: call void @_ZNK1T6concatERKS_(ptr sret(%class.T) align 4 [[T1]], ptr {{[^,]*}} [[T2]], ptr noundef nonnull align 4 dereferenceable(16) [[T3]])
 // CHECK: [[T6:%.*]] = call noundef ptr @_ZNK1T3strEv(ptr {{[^,]*}} [[T1]])
Index: clang/test/CodeGenCXX/amdgcn-call-with-aggarg.cpp
===
--- clang/test/CodeGenCXX/amdgcn-call-with-aggarg.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm -O3 -disable-llvm-passes -o - %s | FileCheck %s
-
-struct A {
-  float x, y, z, w;
-};
-
-void foo(A a);
-
-// CHECK-LABEL: @_Z4testv
-// CHECK: [[A:%.*]] = alloca [[STRUCT_A:%.*]], align 4, addrspace(5)
-// CHECK-NEXT:[[AGG_TMP:%.*]] = alloca [[STRUCT_A]], align 4, addrspace(5)
-// CHECK-NEXT:[[A_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[A]] to ptr
-// CHECK-NEXT:[[AGG_TMP_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[AGG_TMP]] to ptr
-// CHECK-NEXT:call void @llvm.lifetime.start.p5(i64 16, ptr addrspace(5) [[A]]) #[[ATTR4:[0-9]+]]
-// CHECK-NEXT:call void @llvm.lifetime.start.p5(i64 16, ptr addrspace(5) [[AGG_TMP]]) #[[ATTR4]]
-void test() {
-  A a;
-  foo(a);
-}
Index: clang/test/CodeGen/lifetime-call-temp.c
===
--- clang/test/CodeGen/lifetime-call-temp.c
+++ /dev/null
@@ -1,81 +0,0 @@
-// RUN: %clang -cc1  -triple x86_64-apple-macos -O1 -disable-llvm-passes %s -S -emit-llvm -o - | FileCheck %s --implicit-check-not=llvm.lifetime
-// RUN: %clang -cc1 -xc++ -std=c++17 -triple x86_64-apple-macos -O1 -disable-llvm-passes %s -S -emit-llvm -o - -Wno-return-type-c-linkage | FileCheck %s --implicit-check-not=llvm.lifetime --check-prefix=CHECK --check-prefix=CXX
-// RUN: %clang -cc1 -xobjective-c-triple x86_64-apple-macos -O1 -disable-llvm-passes %s -S -emit-llvm -o - | FileCheck %s --implicit-check-not=llvm.lifetime --check-prefix=CHECK --check-prefix=OBJC
-
-typedef struct { int x[100]; } aggregate;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void takes_aggregate(aggregate);
-aggregate gives_aggregate();
-
-// CHECK-LABEL: define void @t1
-void t1() {
-  takes_aggregate(gives_aggregate());
-
-  // CHECK: [[AGGTMP:%.*]] = alloca %struct.aggregate, align 8
-  // CHECK: call void @llvm.lifetime.start.p0(i64 400, ptr [[AGGTMP]])
-  // CHECK: call void{{.*}} @gives_aggregate(ptr sret(%struct.aggregate) align 4

[PATCH] D159105: [analyzer] ArrayBoundCheckerV2 should check the region for taint as well

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

In D159105#4633864 , @donat.nagy 
wrote:

> As I thought more about this commit I realized that I have two vague but 
> significant concerns. I'm sorry that I wasn't able to describe these before 
> you started to dig into the details of the heuristics.
>
> (1) I don't think that code like `int *ptr; scanf("%ld", &ptr);` should be 
> covered by an ArrayBound checker: this is not just a "be careful with the 
> value of the index" issue, but a raw pointer that's completely controlled by 
> an untrusted source. I'd try to cover this kind of bug with either the 
> StdLibrary checker or a small new checker [or perhaps just a clang-tidy 
> check] which would report pointers coming from `scanf` or other user input 
> even if it doesn't see a dereference of the pointer value.
>
> (2) Taintedness of a memory region (i.e. `isTainted(state, location)` where 
> `location` is presumably a `MemRegionVal`) is poorly defined and might mean 
> three different things:
> (a) **The 'begin' pointer value of the region is tainted** (controlled by an 
> untrusted source). This may be a "we're already dead" situation (e.g. the 
> pointer is an arbitrary value from `scanf`) or something completely harmless 
> (we are examining something like the second subscript operator in 
> `large_array[user_input].field[idx]` after verifying that the first subscript 
> with the tainted index is valid), but in either case, the reliability of the 
> 'begin' pointer should not affect the comparison between the region extent 
> and the index value.
> (b)** The extent of the region is tainted** (controlled by an untrusted 
> source, e.g. it's an user input string with an unknown length). In this case 
> it's reasonable to turn on the "paranoid" comparison mode -- however, this 
> situation should be recorded by marking the //extent symbol// of the region 
> as tainted instead of marking the region itself as tainted. I'd be happy to 
> see a commit that ensures that the extent symbol of user input strings is 
> tainted and its taintedness is handled in ArrayBoundsV2.
> (c)** The contents of the region are tainted** (controlled by an untrusted 
> source). Arguably this should be recorded by marking the //contents// as 
> tainted, but that's difficult to implement on a string/array, so it's a 
> somewhat reasonable shortcut to put the taint on the region itself. This kind 
> of taint is completely irrelevant for out of bounds memory access and should 
> not affect the comparisons.
>
> In summary, I'd say that this checker should not be affected by the 
> taintedness of the memory region itself (but it should continue to monitor 
> tainted indices, and if possible, it should be extended to handle tainted 
> extent values). I'm not completely opposed to merging this patch if you add 
> enough heuristics and workarounds to make it stable in practice, but I feel 
> that this is not the right way forward.

I see your point, makes sense and I'd agree.
Probably, by another checker/check, we could indeed sidestep the problem by 
handling these situations separately. I'll think about it.

To me, the whole boils down to null-terminated buffers, such as one returned by 
`getenv`.
There, we have an implicit dependency between the extent of the region and the 
position of the null-terminator inside; as such it affects what locations are 
allowed to be read.
Locations are usually checked by the array-bounds checker (V1 xor V2). 
Consequently, it's still not clear to me if this falls in/out of this checker's 
responsibility.
We don't have many APIs like `getenv`, but users could define custom rules that 
would cause similar problems, thus ATM only `getenv` suffers from these new FPs.

The fact that `isTainted()` could mean so many things, as you enumerated has 3 
different meanings, which is a problem on its own. The design decision was to 
make it deliberately vague to let users express their custom APIs more easily 
in their yaml files.

The measurement is still running, and I'll post a few words about that once I 
had a look; but anyway, I feel that this patch is controversial and needs more 
discussion before it could land.
I plan to abandon this and think about it. We can continue the discussion of 
course.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159105

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


[PATCH] D158363: [clang-format] Fix segmentation fault when formatting nested namespaces

2023-09-01 Thread Arkadiy Yudintsev via Phabricator via cfe-commits
d0nc1h0t added a comment.

In D158363#4632451 , @owenpan wrote:

> Do you need us to commit it for you? See 
> https://llvm.org/docs/Phabricator.html#committing-someone-s-change-from-phabricator.

'git push' or 'arc land' give an error 'remote: Permission to 
llvm/llvm-project.git denied to d0nc1h0t'. 
On an empty folder I tried

  git clone https://github.com/llvm/llvm-project.git/ .
  arc patch D158363
  arc land

with the same error. Maybe there are not enough rights to the project on GitHub?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158363

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


[PATCH] D159351: [Sema] Change order of displayed overloads in diagnostics

2023-09-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
Herald added a project: All.
ilya-biryukov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Make it a strict weak order.

Fixes #64121.

Current implementation uses the definition the definition of ordering
in the C++ standard. The definition provides only a partial order and
cannot be used in sorting algorithms.

The debug builds of libc++ are capable of detecting that problem
and this failure was found when building Clang with libc++ and
those extra checks enabled, see #64121.

The new ordering takes attempts to be a strict weak order and still
pushes most interesting functions to the start of the list.
In some cases, it leads to better results, e.g.

  struct Foo {
operator int();
operator const char*();
  };
  
  void test() { Foo() - Foo(); }

Now produces a list with two most relevant builtin operators at the top,
i.e. `operator-(int, int)` and `operator-(const char*, const char*)`.
Previously `operator-(const char*, const char*)` was the first element,
but `operator-(int, int)` was only the 13th element in the output.
This is a consequence of `stable_sort` now being able to compare those
two candidates, which are indistinguishable in the semantic partial order
despite being two local minimums in their respective comparable
subsets.

However, new implementation does not take into account some aspects of
C++ semantics, e.g. which function template is more specialized. This
can also lead to worse ordering sometimes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159351

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/overloaded-operators-display-order-crash.cpp

Index: clang/test/SemaCXX/overloaded-operators-display-order-crash.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/overloaded-operators-display-order-crash.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+namespace ambig {
+  struct Foo {
+operator int();
+operator const char *();
+  };
+
+
+  void func(const char*, long);
+  void func(const char*, const char*);
+  void func(int, int);
+
+  bool doit(Foo x) {
+func(x, x); // expected-error {{call to 'func' is ambiguous}}
+// expected-note@* 3{{candidate}}
+  }
+}
+
+namespace bad_conversion {
+  struct Foo {
+operator int();
+operator const char *();
+  };
+
+
+  void func(double*, const char*, long);
+  void func(double*, const char*, const char*);
+  void func(double*, int, int);
+
+  bool doit(Foo x) {
+func((int*)0, x, x); // expected-error {{no matching function for call to 'func'}}
+ // expected-note@* 3{{candidate}}
+  }
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -38,8 +38,10 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -11774,6 +11776,7 @@
 }
 
 namespace {
+
 struct CompareOverloadCandidatesForDisplay {
   Sema &S;
   SourceLocation Loc;
@@ -11811,13 +11814,10 @@
 if (L->Viable) {
   if (!R->Viable) return true;
 
-  // TODO: introduce a tri-valued comparison for overload
-  // candidates.  Would be more worthwhile if we had a sort
-  // that could exploit it.
-  if (isBetterOverloadCandidate(S, *L, *R, SourceLocation(), CSK))
-return true;
-  if (isBetterOverloadCandidate(S, *R, *L, SourceLocation(), CSK))
-return false;
+  if (int Ord = CompareConversions(*L, *R)) {
+return Ord < 0;
+  }
+  // Use other tie breakers.
 } else if (R->Viable)
   return false;
 
@@ -11869,30 +11869,9 @@
 }
 
 // If there's any ordering between the defined conversions...
-// FIXME: this might not be transitive.
-assert(L->Conversions.size() == R->Conversions.size());
-
-int leftBetter = 0;
-unsigned I = (L->IgnoreObjectArgument || R->IgnoreObjectArgument);
-for (unsigned E = L->Conversions.size(); I != E; ++I) {
-  switch (CompareImplicitConversionSequences(S, Loc,
- L->Conversions[I],
- R->Conversions[I])) {
-  case ImplicitConversionSequence::Better:
-leftBetter++;
-break;
-
-  case ImplicitConversionSequence::Worse:
-leftBetter--;
-break;
-
-  case ImplicitConversionSequence::Indistinguishable:
-break;
-  }
+if (int Ord = CompareConversions(*L, *R)) {
+  return Ord < 0;
 }
-if (leftBetter > 0) return true;
-if (leftBetter < 0) return false;
-
  

[PATCH] D159351: [Sema] Change order of displayed overloads in diagnostics

2023-09-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added reviewers: rnk, clang-language-wg.
ilya-biryukov added a subscriber: rnk.
ilya-biryukov added a comment.

This change mainly tried to address the assertion failure in libc++, but got 
into the territory of changing the order of displayed overloads.
Which might be a more complicated topic, so it would be great to get feedback 
from Clang maintainers.

I am on vacation next week, so @rnk might want pick this up if fixing the 
assertion turns out to be urgent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159351

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


[PATCH] D159312: [Headers] Remove a space in NULL define

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



Comment at: clang/lib/Headers/__stddef_null.h:18-21
+// Don't add any whitespaces in ((void*)0) below!
+// musl (https://www.musl-libc.org/) redefines `NULL` as such and redefinition
+// with a different expression, even in terms of a single whitespace, causes a
+// warning.

My concern with this comment is that it implies we can never change our 
definition of `NULL` -- as the implementation, this is ours to define and if 
other C standard libraries (also part of the implementation!) are redefining 
the macro, IMO, they need to solve this themselves with either `#ifdef` or 
`#undef` as needed instead of expecting the definitions to stay in lock-step 
including whitespace. I don't expect us to change the definition of `NULL` any 
time soon, but this feels like a bad precedent to set. I'm not opposed (this is 
solving a real problem), but I'm wondering if musl would consider guarding 
their macro definitions so we don't have this fragility forever? We need to 
keep it for now so existing musl uses don't have this problem, but I don't 
really want to make the guarantees this comment is claiming.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159312

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


[PATCH] D159312: [Headers] Remove a space in NULL define

2023-09-01 Thread Rich Felker via Phabricator via cfe-commits
dalias added a comment.

I don't understand the motivation of trying to match musl's definition here. 
musl explicitly **does not support** using a compiler-provided `stddef.h` or 
other standard headers. If it's getting included, this is a symption of an 
include order problem that needs to be fixed, and getting an error telling you 
that is preferable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159312

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


[PATCH] D157385: [clang][CFG] Cleanup functions

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

Not sure I have enough CFG knowledge. Do I just need to create another noreturn 
block for the cleanup function?

This is the CFG I get when both the cleanup function and the destructor are 
noreturn:

  int main()
   [B4 (ENTRY)]
 Succs (1): B3
  
   [B1]
 1: CFGScopeEnd(f)
 Succs (1): B0
  
   [B2 (NORETURN)]
 1: [B3.3].~F() (Implicit destructor)
 Succs (1): B0
  
   [B3 (NORETURN)]
 1: CFGScopeBegin(f)
 2:  (CXXConstructExpr, [B3.3], F)
 3: F f __attribute__((cleanup(f_)));
 4: CleanupFunction (f_)
 Preds (1): B4
 Succs (1): B0
  
   [B0 (EXIT)]
 Preds (3): B1 B2 B3


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

https://reviews.llvm.org/D157385

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


[PATCH] D159312: [Headers] Remove a space in NULL define

2023-09-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D159312#4633989 , @dalias wrote:

> I don't understand the motivation of trying to match musl's definition here. 
> musl explicitly **does not support** using a compiler-provided `stddef.h` or 
> other standard headers. If it's getting included, this is a symption of an 
> include order problem that needs to be fixed, and getting an error telling 
> you that is preferable.

Oh! Thank you for that information, that's really good to know! Our stddef.h is 
one of the few headers we provide that doesn't do an `include_next` to get to 
the system library header if one is available; I wonder if that's a 
contributing factor?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159312

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


[PATCH] D159105: [analyzer] ArrayBoundCheckerV2 should check the region for taint as well

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

In D159105#4633899 , @steakhal wrote:

> The measurement is still running, and I'll post a few words about that once I 
> had a look; but anyway, I feel that this patch is controversial and needs 
> more discussion before it could land.
> I plan to abandon this and think about it. We can continue the discussion of 
> course.

Here are the results after applying the suppression heuristic for `getenv`, 
plus D159108  and D159109 
:

- `=X`: Given message appeared X times in baseline.
- `+X (+Y%)`: Patch added X new reports with this message, and that is Y 
percent increase compared to the baseline.
- `-X (-Y%)`: Removed X reports with this message, and that is Y percent 
decrease compared to the baseline.

  * Out of bound memory access (accessed memory precedes memory block)
=1221, +0 (+0%), -4 (-0%)
  * Out of bound memory access (access exceeds upper limit of memory block)
=10547, +7 (+0%), -5 (-0%)
  * Out of bound memory access (index is tainted)
=624, +71 (+11%), -1 (-0%)
  
  * Memory copy function overflows the destination buffer
=436, +45 (+10%), -1 (-0%)
  * Memory copy function accesses out-of-bound array element
=443, +19 (+4%), -1 (-0%)
  * Memory comparison function accesses out-of-bound array element
=102, +1 (+1%), -1 (-1%)
  * Memory set function overflows the destination buffer
=119, +10 (+8%), -0 (-0%)
  * String copy function overflows the destination buffer
 =42, +3 (+7%), -0 (-0%)
  
  * This was not the most recently acquired lock. Possible lock order reversal
=81, +0 (+0%), -1 (-1%)
  * Division by zero
=775, +1 (+0%), -0 (-0%)
  * Called C++ object pointer is null
=3719, +0 (+0%), -2 (-0%)
  * Potential leak of memory pointed to by
=1996, +0 (+0%), -2 (-0%)
  * Returned pointer value points outside the original object (potential buffer 
overflow)
=625, +2 (+0%), -0 (-0%)

I think the mentioned heuristic works quite well, and really decreased the 
number of FPs for `Out of bound memory access (index is tainted)`.
I still don't want to commit to this patch, so I'm abandoning this.

I don't plan to repeat the measurement for D159108 
 and D159109 
, as the numbers related to those messages 
look nice.
I had a look at the reports for those, and as expected it's barely impossible 
to make sense of them. But at least nothing dumb stood out.
If you are okay, I'll commit D159108  and 
D159109  later today. @donat.nagy


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159105

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


[PATCH] D159352: [Driver] Don't default to DWARF 2 on Solaris

2023-09-01 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added a reviewer: MaskRay.
ro added a project: clang.
Herald added subscribers: fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

`clang` currently defaults to DWARF 2 on Solaris.  This dates back to LLVM 
3.8.0.  I suspect this is related to `gcc/config/sol2.cc` 
(`solaris_override_options`) doing the same unless `HAVE_LD_EH_FRAME_CIEV3`.  
The latter is 1 on both Solaris 11.3 and 11.4, so the workaround has become 
irrelevant these days.

This patch removes the Solaris override, adjusting affected testcases 
accordingly.

Tested on `amd64-pc-solaris2.11` (`Release` and `Debug` builds) and 
`sparcv9-sun-solaris2.11` (`Release` build).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159352

Files:
  clang/lib/Driver/ToolChains/Solaris.h
  clang/test/CodeGen/dwarf-version.c
  clang/test/Driver/clang-g-opts.c
  clang/test/Driver/debug-options.c


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -195,7 +195,7 @@
 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-pc-freebsd10.0 
2>&1 \
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-tables-only -g %s -target i386-pc-solaris 2>&1 \
-// RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
+// RUN: | FileCheck -check-prefix=G_ONLY %s
 // RUN: %clang -### -c -gline-tables-only -g0 %s 2>&1 \
 // RUN: | FileCheck -check-prefix=GLTO_NO %s
 //
@@ -214,7 +214,7 @@
 // RUN: %clang -### -c -gline-directives-only -g %s -target 
x86_64-pc-freebsd10.0 2>&1 \
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-directives-only -g %s -target i386-pc-solaris 
2>&1 \
-// RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
+// RUN: | FileCheck -check-prefix=G_ONLY %s
 // RUN: %clang -### -c -gline-directives-only -g0 %s 2>&1 \
 // RUN: | FileCheck -check-prefix=GLIO_NO %s
 
Index: clang/test/Driver/clang-g-opts.c
===
--- clang/test/Driver/clang-g-opts.c
+++ clang/test/Driver/clang-g-opts.c
@@ -28,7 +28,7 @@
 // RUN: %clang -### -S %s -g0 -g -target x86_64-pc-freebsd10.0 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
 // RUN: %clang -### -S %s -g0 -g -target i386-pc-solaris 2>&1 \
-// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G %s
 
 // CHECK-WITHOUT-G-NOT: -debug-info-kind
 // CHECK-WITH-G: "-debug-info-kind=constructor"
Index: clang/test/CodeGen/dwarf-version.c
===
--- clang/test/CodeGen/dwarf-version.c
+++ clang/test/CodeGen/dwarf-version.c
@@ -4,6 +4,8 @@
 // RUN: %clang -target x86_64-linux-gnu -gdwarf-5 -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
 // RUN: %clang -target x86_64-linux-gnu -g -S -emit-llvm -o - %s | FileCheck 
%s --check-prefix=VER5
 // RUN: %clang -target x86_64-linux-gnu -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
+// RUN: %clang -target i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VER5
+// RUN: %clang -target i386-pc-solaris -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
 
 // The -isysroot is used as a hack to avoid LIT messing with the SDKROOT
 // environment variable which indirecty overrides the version in the target
@@ -13,8 +15,6 @@
 
 // RUN: %clang -target powerpc-unknown-openbsd -g -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER2
 // RUN: %clang -target powerpc-unknown-freebsd -g -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER4
-// RUN: %clang -target i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VER2
-// RUN: %clang -target i386-pc-solaris -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER2
 
 // Check which debug info formats we use on Windows. By default, in an MSVC
 // environment, we should use codeview. You can enable dwarf, which implicitly
Index: clang/lib/Driver/ToolChains/Solaris.h
===
--- clang/lib/Driver/ToolChains/Solaris.h
+++ clang/lib/Driver/ToolChains/Solaris.h
@@ -66,7 +66,6 @@
llvm::opt::ArgStringList &CC1Args) const override;
 
   SanitizerMask getSupportedSanitizers() const override;
-  unsigned GetDefaultDwarfVersion() const override { return 2; }
 
   const char *getDefaultLinker() const override;
 


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -195,7 +195,7 @@
 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-pc-free

[PATCH] D157385: [clang][CFG] Cleanup functions

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



Comment at: clang/lib/Analysis/CFG.cpp:1901-1902
   appendLifetimeEnds(Block, VD, S);
-if (BuildOpts.AddImplicitDtors)
+if (BuildOpts.AddImplicitDtors && !hasTrivialDestructor(VD))
   appendAutomaticObjDtor(Block, VD, S);
+if (HasCleanupAttr)

steakhal wrote:
> steakhal wrote:
> > This condition looks new. Is it an orthogonal improvement?
> Shouldn't the cleanup function run first, and then the dtor of the variable?
> This way the object is already "dead" even before reaching the cleanup 
> handler.
> https://godbolt.org/z/sT65boooW
This check is needed because it's not implied anymore by the variable being in 
the list. It might be in there because it has a cleanup function.


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

https://reviews.llvm.org/D157385

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


[PATCH] D158519: [clangd] Move diagnostics from modules to the main source file

2023-09-01 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.

Friendly ping, any thoughts about this diff?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158519

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


[PATCH] D148131: Avoid unnecessarily aggressive line-breaking when using "LambdaBodyIndentation: OuterScope" with argument bin-packing.

2023-09-01 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added a comment.

In D148131#4628719 , 
@HazardyKnusperkeks wrote:

> But please wait for other opinions.

OK sure. @owenpan, any thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148131

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


[PATCH] D159355: [clang][dataflow] Unsoundly treat "Unknown" as "Equivalent" in widening.

2023-09-01 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added reviewers: xazax.hun, gribozavr2, mboehme.
Herald added a subscriber: martong.
Herald added a reviewer: NoQ.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.

This change makes widening act the same as equivalence checking. When the
analysis does not provide an answer regarding the equivalence of two distinct
values, the framework treats them as equivalent. This is an unsound choice that
enables convergence.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159355

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3843,10 +3843,7 @@
   }
 }
   )cc";
-  // FIXME: Implement pointer value widening to make analysis converge.
-  ASSERT_THAT_ERROR(
-  checkDataflowWithNoopAnalysis(Code),
-  llvm::FailedWithMessage("maximum number of iterations reached"));
+  ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
 }
 
 TEST(TransferTest, LoopDereferencingChangingRecordPointerConverges) {
@@ -3868,10 +3865,7 @@
   }
 }
   )cc";
-  // FIXME: Implement pointer value widening to make analysis converge.
-  ASSERT_THAT_ERROR(
-  checkDataflowWithNoopAnalysis(Code),
-  llvm::FailedWithMessage("maximum number of iterations reached"));
+  ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
 }
 
 TEST(TransferTest, DoesNotCrashOnUnionThisExpr) {
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -22,10 +22,8 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
-#include 
 #include 
 
 namespace clang {
@@ -50,6 +48,23 @@
   return Result;
 }
 
+// Whether to consider equivalent two values with an unknown relation.
+//
+// FIXME: this function is a hook that enable unsoundness in support of
+// convergence. Once we have widening support for the reference/pointer and
+// struct built-in models, this should be unconditionally `false` (and inlined
+// as such at its call sites)
+static bool equateUnknownValues(Value::Kind K) {
+  switch (K) {
+  case Value::Kind::Integer:
+  case Value::Kind::Pointer:
+  case Value::Kind::Record:
+return true;
+  default:
+return false;
+  }
+}
+
 static bool compareDistinctValues(QualType Type, Value &Val1,
   const Environment &Env1, Value &Val2,
   const Environment &Env2,
@@ -66,18 +81,7 @@
   case ComparisonResult::Different:
 return false;
   case ComparisonResult::Unknown:
-switch (Val1.getKind()) {
-case Value::Kind::Integer:
-case Value::Kind::Pointer:
-case Value::Kind::Record:
-  // FIXME: this choice intentionally introduces unsoundness to allow
-  // for convergence. Once we have widening support for the
-  // reference/pointer and struct built-in models, this should be
-  // `false`.
-  return true;
-default:
-  return false;
-}
+return equateUnknownValues(Val1.getKind());
   }
   llvm_unreachable("All cases covered in switch");
 }
@@ -167,8 +171,7 @@
   if (auto *W = Model.widen(Type, Prev, PrevEnv, Current, CurrentEnv))
 return *W;
 
-  // Default of widening is a no-op: leave the current value unchanged.
-  return Current;
+  return equateUnknownValues(Prev.getKind()) ? Prev : Current;
 }
 
 // Returns whether the values in `Map1` and `Map2` compare equal for those


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3843,10 +3843,7 @@
   }
 }
   )cc";
-  // FIXME: Implement pointer value widening to make analysis converge.
-  ASSERT_THAT_ERROR(
-  checkDataflowWithNoopAnalysis(Code),
-  llvm::FailedWithMessage("maximum number of iterations reached"));
+  ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
 }
 
 TEST(TransferTest, LoopDereferencingChangingRecordPointerConverges) {
@@ -3868,10 +3865,7 @@
   }
 }
   )cc";
-  // FIXME: Implement pointer value widening to make analysis converge.
-  ASSERT_THAT_ERROR(
-  checkDataflowWithNoopAnalysis(Code),
-  llvm::FailedWithMessage("maximum number of iterations reached"));
+  ASSERT_THAT_ERROR(checkD

[clang] 1255906 - [analyzer] Fix a few size-type inconsistency relating to DynamicExtent

2023-09-01 Thread via cfe-commits

Author: dingfei
Date: 2023-09-01T21:03:16+08:00
New Revision: 12559064e05a11e8418425de59d8745f0cfb1122

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

LOG: [analyzer] Fix a few size-type inconsistency relating to DynamicExtent

Size-type inconsistency (signedness) causes confusion and even bugs.
For example when signed compared to unsigned the result might not
be expected. Summary of this commit:

Related APIs changes:
1. getDynamicExtent() returns signed version of extent;
2. Add getDynamicElementCountWithOffset() for offset version of element count;
3. getElementExtent() could be 0, add defensive checking for
   getDynamicElementCount(), if element is of zero-length, try
   ConstantArrayType::getSize() as element count;

Related checker changes:
1. ArrayBoundCheckerV2: add testcase for signed <-> unsigned comparison from
   type-inconsistency results by getDynamicExtent()
2. ExprInspection: use more general API to report more results

Fixes https://github.com/llvm/llvm-project/issues/64920

Reviewed By: donat.nagy, steakhal

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h
clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp
clang/test/Analysis/array-bound-v2-constraint-check.c
clang/test/Analysis/flexible-array-members.c
clang/test/Analysis/memory-model.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h
index cfd7aa9664b696..50d5d254415af3 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h
@@ -53,6 +53,11 @@ ProgramStateRef setDynamicExtent(ProgramStateRef State, 
const MemRegion *MR,
 ///   (bufptr) // extent is unknown
 SVal getDynamicExtentWithOffset(ProgramStateRef State, SVal BufV);
 
+/// \returns The stored element count of the region represented by a symbolic
+/// value \p BufV.
+DefinedOrUnknownSVal getDynamicElementCountWithOffset(ProgramStateRef State,
+  SVal BufV, QualType Ty);
+
 } // namespace ento
 } // namespace clang
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
index 15ba29050e9032..2c7bacac33a687 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -325,12 +325,12 @@ void ExprInspectionChecker::analyzerDump(const CallExpr 
*CE,
 
 void ExprInspectionChecker::analyzerGetExtent(const CallExpr *CE,
   CheckerContext &C) const {
-  const MemRegion *MR = getArgRegion(CE, C);
-  if (!MR)
+  const Expr *Arg = getArgExpr(CE, C);
+  if (!Arg)
 return;
 
   ProgramStateRef State = C.getState();
-  DefinedOrUnknownSVal Size = getDynamicExtent(State, MR, C.getSValBuilder());
+  SVal Size = getDynamicExtentWithOffset(State, C.getSVal(Arg));
 
   State = State->BindExpr(CE, C.getLocationContext(), Size);
   C.addTransition(State);
@@ -338,12 +338,12 @@ void ExprInspectionChecker::analyzerGetExtent(const 
CallExpr *CE,
 
 void ExprInspectionChecker::analyzerDumpExtent(const CallExpr *CE,
CheckerContext &C) const {
-  const MemRegion *MR = getArgRegion(CE, C);
-  if (!MR)
+  const Expr *Arg = getArgExpr(CE, C);
+  if (!Arg)
 return;
 
-  DefinedOrUnknownSVal Size =
-  getDynamicExtent(C.getState(), MR, C.getSValBuilder());
+  ProgramStateRef State = C.getState();
+  SVal Size = getDynamicExtentWithOffset(State, C.getSVal(Arg));
   printAndReport(C, Size);
 }
 
@@ -362,8 +362,8 @@ void ExprInspectionChecker::analyzerDumpElementCount(const 
CallExpr *CE,
 
   assert(!ElementTy->isPointerType());
 
-  DefinedOrUnknownSVal ElementCount =
-  getDynamicElementCount(C.getState(), MR, C.getSValBuilder(), ElementTy);
+  DefinedOrUnknownSVal ElementCount = getDynamicElementCountWithOffset(
+  C.getState(), C.getSVal(getArgExpr(CE, C)), ElementTy);
   printAndReport(C, ElementCount);
 }
 

diff  --git a/clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp 
b/clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp
index 6a86536492cd3d..6cf06413b5372c 100644
--- a/clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp
+++ b/clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp
@@ -30,7 +30,9 @@ DefinedOrUnknownSVal getDynamicExtent(ProgramStateRef State,
   MR = MR->StripCasts();
 
   if (const DefinedOrUnknownSVal *Size = State->get(MR))
-return *Size;
+if (

[PATCH] D158499: [analyzer] Compute FAM dynamic size

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

@danix800 FYI I think you used the wrong revision link in the commit. Maybe 
mark this revision as "abandoned" again, to reflect the actual status.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158499

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


[PATCH] D158707: [analyzer] Fix a few size-type signedness inconsistency related to DynamicExtent

2023-09-01 Thread Balázs Benics via Phabricator via cfe-commits
steakhal closed this revision.
steakhal added a comment.

Landed as 
https://github.com/llvm/llvm-project/commit/12559064e05a11e8418425de59d8745f0cfb1122


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158707

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


[PATCH] D158967: [clang][clangd] Ensure the stack bottom before building AST

2023-09-01 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 555356.
zyounan added a comment.
Herald added a subscriber: javed.absar.

Disperse the call over clangd tasks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158967

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/support/Threading.cpp
  clang-tools-extra/clangd/test/infinite-instantiation.test
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang/lib/Frontend/FrontendAction.cpp

Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -15,6 +15,7 @@
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/LangStandard.h"
 #include "clang/Basic/Sarif.h"
+#include "clang/Basic/Stack.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
@@ -1155,6 +1156,10 @@
   CompilerInstance &CI = getCompilerInstance();
   if (!CI.hasPreprocessor())
 return;
+  // This is a fallback: If the client forgets to invoke this, we mark the
+  // current stack as the bottom. Though not optimal, this could help prevent
+  // stack overflow during deep recursion.
+  clang::noteBottomOfStack();
 
   // FIXME: Move the truncation aspect of this into Sema, we delayed this till
   // here so the source manager would be initialized.
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -29,6 +29,7 @@
 #include "support/ThreadCrashReporter.h"
 #include "support/ThreadsafeFS.h"
 #include "support/Trace.h"
+#include "clang/Basic/Stack.h"
 #include "clang/Format/Format.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
@@ -710,6 +711,9 @@
 };
 
 int clangdMain(int argc, char *argv[]) {
+  // Clang could run on the main thread. e.g., when the flag '-check' or '-sync'
+  // is enabled.
+  clang::noteBottomOfStack();
   llvm::InitializeAllTargetInfos();
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   llvm::sys::AddSignalHandler(
Index: clang-tools-extra/clangd/test/infinite-instantiation.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/infinite-instantiation.test
@@ -0,0 +1,13 @@
+// RUN: cp %s %t.cpp
+// RUN: not clangd -check=%t.cpp 2>&1 | FileCheck -strict-whitespace %s
+
+// CHECK: [template_recursion_depth_exceeded]
+
+template 
+constexpr int f(T... args) {
+  return f(0, args...);
+}
+
+int main() {
+  auto i = f();
+}
Index: clang-tools-extra/clangd/support/Threading.cpp
===
--- clang-tools-extra/clangd/support/Threading.cpp
+++ clang-tools-extra/clangd/support/Threading.cpp
@@ -8,6 +8,7 @@
 
 #include "support/Threading.h"
 #include "support/Trace.h"
+#include "clang/Basic/Stack.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/thread.h"
Index: clang-tools-extra/clangd/index/Background.cpp
===
--- clang-tools-extra/clangd/index/Background.cpp
+++ clang-tools-extra/clangd/index/Background.cpp
@@ -30,6 +30,7 @@
 #include "support/Trace.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/Stack.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseSet.h"
@@ -108,6 +109,7 @@
   for (unsigned I = 0; I < Opts.ThreadPoolSize; ++I) {
 ThreadPool.runAsync("background-worker-" + llvm::Twine(I + 1),
 [this, Ctx(Context::current().clone())]() mutable {
+  clang::noteBottomOfStack();
   WithContext BGContext(std::move(Ctx));
   Queue.work([&] { Rebuilder.idle(); });
 });
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -63,6 +63,7 @@
 #include "support/ThreadCrashReporter.h"
 #include "support/Threading.h"
 #include "support/Trace.h"
+#include "clang/Basic/Stack.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/ADT/FunctionExtras.h"
@@ -464,6 +465,10 @@
   }
 
   void run() {
+// We mark the current as the stack bottom so that clang running on this
+// thread can notice the stack usage and prevent stack overflow with best
+// efforts. Same applies to other calls thoughout clangd.
+clang:

[PATCH] D158967: [clang][clangd] Ensure the stack bottom before building AST

2023-09-01 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added a comment.

Thanks! I hope I'm getting things right. Specifically,

1. `UpdateIndexCallbacks::indexStdlib()::Task` in `ClangdServer.cpp`
2. `PreambleThread::run()`, `ASTWorker::run()` and 
`TUScheduler::runWithPreamble()::Task` in `TUScheduler.cpp`
3. The lambda of `runAsync` in `BackgroundIndex::BackgroundIndex()` in 
`index/Background.cpp`.




Comment at: clang-tools-extra/clangd/support/Threading.cpp:102
 llvm::set_thread_name(Name);
+// Mark the bottom of the stack for clang to be aware of the stack usage 
and
+// prevent stack overflow.

sammccall wrote:
> ugh, I forgot: this function is part of clangBasic (which is not small!) and 
> clangdSupport shouldn't depend on clang at all.
> 
> I'm afraid the easiest fix is to move this to the tasks in the relevant 
> callsites:
> - indexStdlib() in ClangdServer.cpp
> - ASTWorker::run(), PreambleWorker::run(), TUScheduler::runWithPreamble() in 
> TUScheduler.cpp
> - BackgroundIndex() in index/Background.cpp
> 
> (I guess principled thing would be to make noteBottomOfStack() part of llvm 
> Support, but that seems complicated)
Ah, I've never noticed clangdSupport is independent of clang.

> (I guess principled thing would be to make noteBottomOfStack() part of llvm 
> Support, but that seems complicated)

Agreed. And I think it requires an RFC before we have that migrate to 
llvmSupport.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158967

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


[PATCH] D157385: [clang][CFG] Cleanup functions

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

When I added `-analyzer-config cfg-lifetime=true` to 
`clang/test/Analysis/scopes-cfg-output.cpp`, suddenly duplicated lifetime ends 
entries appeared where we have `CleanupFunctions`.
My output is:

  void test_cleanup_functions()
   [B2 (ENTRY)]
 Succs (1): B1
  
   [B1]
 1: CFGScopeBegin(i)
 2: int i __attribute__((cleanup(cleanup_int)));
 3: CleanupFunction (cleanup_int)
 4: [B1.2] (Lifetime ends)
 5: [B1.2] (Lifetime ends)
 6: CFGScopeEnd(i)
 Preds (1): B2
 Succs (1): B0
  
   [B0 (EXIT)]
 Preds (1): B1
  
  void test_cleanup_functions2(int m)
   [B4 (ENTRY)]
 Succs (1): B3
  
   [B1]
 1: 10
 2: i
 3: [B1.2] = [B1.1]
 4: return;
 5: CleanupFunction (cleanup_int)
 6: [B3.2] (Lifetime ends)
 7: [B3.2] (Lifetime ends)
 8: CFGScopeEnd(i)
 Preds (1): B3
 Succs (1): B0
  
   [B2]
 1: return;
 2: CleanupFunction (cleanup_int)
 3: [B3.2] (Lifetime ends)
 4: [B3.2] (Lifetime ends)
 5: CFGScopeEnd(i)
 Preds (1): B3
 Succs (1): B0
  
   [B3]
 1: CFGScopeBegin(i)
 2: int i __attribute__((cleanup(cleanup_int)));
 3: m
 4: [B3.3] (ImplicitCastExpr, LValueToRValue, int)
 5: 1
 6: [B3.4] == [B3.5]
 T: if [B3.6]
 Preds (1): B4
 Succs (2): B2 B1
  
   [B0 (EXIT)]
 Preds (2): B1 B2
  
  void test()
   [B2 (ENTRY)]
 Succs (1): B1
  
   [B1]
 1: CFGScopeBegin(f)
 2:  (CXXConstructExpr, [B1.3], F)
 3: F f __attribute__((cleanup(cleanup_F)));
 4: CleanupFunction (cleanup_F)
 5: [B1.3].~F() (Implicit destructor)
 6: [B1.3] (Lifetime ends)
 7: CFGScopeEnd(f)
 Preds (1): B2
 Succs (1): B0
  
   [B0 (EXIT)]
 Preds (1): B1

Notice the `[B3.2] (Lifetime ends)` lines for example.

The order in which the Lifetime, Scope and Cleanup elements appear looks 
correct; my only concern is the duplicate Lifetime ends marker.

About the `noreturn` cleanup function, well, GCC says: `It is undefined what 
happens if cleanup_function does not return normally.` here 
,
 thus I'm not sure what to do in that case. GCC seems to optimize accordingly, 
but clang does not. See https://godbolt.org/z/z8s6bPPjv.

FYI Unfortunately, I don't have much experience with CFG either.


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

https://reviews.llvm.org/D157385

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


[PATCH] D158499: [analyzer] Compute FAM dynamic size

2023-09-01 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

https://github.com/llvm/llvm-project/commit/12559064e05a11e8418425de59d8745f0cfb1122
 mistakingly linked here. The actual revision is D158707 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158499

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


[PATCH] D158499: [analyzer] Compute FAM dynamic size

2023-09-01 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

In D158499#4634166 , @steakhal wrote:

> @danix800 FYI I think you used the wrong revision link in the commit. Maybe 
> mark this revision as "abandoned" again, to reflect the actual status.

Sorry for this mistake.

D158707  originates from this but I forgot to 
update the revision ID.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158499

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


[PATCH] D158407: [clang][dataflow] #llvm #flow-analysis Simplify formula at CNF construction time, and short-cut solving of known contradictory formulas.

2023-09-01 Thread Burak Emir via Phabricator via cfe-commits
burakemir updated this revision to Diff 555363.
burakemir marked 4 inline comments as done.
burakemir added a comment.

Applied reviewer comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158407

Files:
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -369,4 +369,32 @@
   EXPECT_TRUE(solver.reachedLimit());
 }
 
+TEST(SolverTest, SimpleButLargeContradiction) {
+  // This test ensures that the solver takes a short-cut on known
+  // contradictory inputs, without using max_iterations. At the time
+  // this test is added, formulas that are easily recognized to be
+  // contradictory at CNF construction time would lead to timeout.
+  WatchedLiteralsSolver solver(10);
+  ConstraintContext Ctx;
+  auto first = Ctx.atom();
+  auto last = first;
+  for (int i = 1; i < 1; ++i) {
+last = Ctx.conj(last, Ctx.atom());
+  }
+  last = Ctx.conj(Ctx.neg(first), last);
+  ASSERT_EQ(solver.solve({last}).getStatus(),
+Solver::Result::Status::Unsatisfiable);
+  EXPECT_FALSE(solver.reachedLimit());
+
+  first = Ctx.atom();
+  last = Ctx.neg(first);
+  for (int i = 1; i < 1; ++i) {
+last = Ctx.conj(last, Ctx.neg(Ctx.atom()));
+  }
+  last = Ctx.conj(first, last);
+  ASSERT_EQ(solver.solve({last}).getStatus(),
+Solver::Result::Status::Unsatisfiable);
+  EXPECT_FALSE(solver.reachedLimit());
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
===
--- clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
+++ clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
@@ -12,8 +12,8 @@
 //===--===//
 
 #include 
+#include 
 #include 
-#include 
 #include 
 #include 
 
@@ -23,8 +23,10 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/STLExtras.h"
 
+
 namespace clang {
 namespace dataflow {
 
@@ -62,6 +64,10 @@
 /// Returns the positive literal `V`.
 static constexpr Literal posLit(Variable V) { return 2 * V; }
 
+static constexpr bool isPosLit(Literal L) { return 0 == (L & 1); }
+
+static constexpr bool isNegLit(Literal L) { return 1 == (L & 1); }
+
 /// Returns the negative literal `!V`.
 static constexpr Literal negLit(Variable V) { return 2 * V + 1; }
 
@@ -125,9 +131,14 @@
   /// formula.
   llvm::DenseMap Atomics;
 
+  /// Indicates that we already know the formula is unsatisfiable.
+  /// During construction, we catch simple cases of conflicting unit-clauses.
+  bool KnownContradictory;
+
   explicit CNFFormula(Variable LargestVar,
   llvm::DenseMap Atomics)
-  : LargestVar(LargestVar), Atomics(std::move(Atomics)) {
+  : LargestVar(LargestVar), Atomics(std::move(Atomics)),
+KnownContradictory(false) {
 Clauses.push_back(0);
 ClauseStarts.push_back(0);
 NextWatched.push_back(0);
@@ -135,33 +146,24 @@
 WatchedHead.resize(NumLiterals + 1, 0);
   }
 
-  /// Adds the `L1 v L2 v L3` clause to the formula. If `L2` or `L3` are
-  /// `NullLit` they are respectively omitted from the clause.
-  ///
+  /// Adds the `L1 v ... v Ln` clause to the formula.
   /// Requirements:
   ///
-  ///  `L1` must not be `NullLit`.
+  ///  `Li` must not be `NullLit`.
   ///
   ///  All literals in the input that are not `NullLit` must be distinct.
-  void addClause(Literal L1, Literal L2 = NullLit, Literal L3 = NullLit) {
-// The literals are guaranteed to be distinct from properties of Formula
-// and the construction in `buildCNF`.
-assert(L1 != NullLit && L1 != L2 && L1 != L3 &&
-   (L2 != L3 || L2 == NullLit));
+  void addClause(ArrayRef lits) {
+assert(!lits.empty());
+assert(llvm::all_of(lits, [](Literal L) { return L != NullLit; }));
 
 const ClauseID C = ClauseStarts.size();
 const size_t S = Clauses.size();
 ClauseStarts.push_back(S);
-
-Clauses.push_back(L1);
-if (L2 != NullLit)
-  Clauses.push_back(L2);
-if (L3 != NullLit)
-  Clauses.push_back(L3);
+Clauses.insert(Clauses.end(), lits.begin(), lits.end());
 
 // Designate the first literal as the "watched" literal of the clause.
-NextWatched.push_back(WatchedHead[L1]);
-WatchedHead[L1] = C;
+NextWatched.push_back(WatchedHead[lits.front()]);
+WatchedHead[lits.front()] = C;
   }
 
   /// Returns the number of literals in clause `C`.
@@ -176,6 +178,84 @@
   }
 };
 
+/// Applies simplifications while building up a BooleanFormula.
+/// We keep track of u

[PATCH] D158407: [clang][dataflow] #llvm #flow-analysis Simplify formula at CNF construction time, and short-cut solving of known contradictory formulas.

2023-09-01 Thread Burak Emir via Phabricator via cfe-commits
burakemir added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:184
+/// may in turn yield more unit clauses or even a contradiction.
+/// The complexity of this preprocessing is O(log(K)) where K is the number
+/// of unit clauses. Assuming K << N, it is negligible. This method

sammccall wrote:
> I'm confused about this comment: the preprocessing looks like O(N): we 
> process every clause once, and addClauseLiterals() runs in constant time. 
> What am I missing?
> 
I am sorry for the misleading text: I only talked about addClause complexity.

And I estimated the lookup at a conservative O(log(K)) worst case complexity. 
And this is just completely wrong, since we can expect lookup to be on a 
hash-table. It would be O(1) average and worst case O(K).
I guess my mind was wandering off thinking about improving worst case lookup 
complexity.

Changed to O(N).



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:202
+  ///  All literals in the input that are not `NullLit` must be distinct.
+  void addClause(Literal L1, Literal L2 = NullLit, Literal L3 = NullLit) {
+// The literals are guaranteed to be distinct from properties of BoolValue

sammccall wrote:
> if you're going to form an ArrayRef in any case, might as well skip this 
> indirection and have the callsites pass `addClause({L1, L2})` or so?
Thanks, this looks much nicer.

I chose to preserve the assert condition to check that there are <= 3 literals.

I believe the solver way work with clauses that have more literals but I don't 
know whether any trade-offs were made to focus on 3SAT in the solver.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158407

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


[PATCH] D159358: [Clang] Realize generic lambda call operators are dependent sooner

2023-09-01 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When parsing a trailing return type / noexcept / constraint
of a generic lambda, we need to know that we are in a dependent
context. We currently don't because we only create a TemplateDecl
for the call operator one its fully parsed.

This patch attach a template decl to the call operator as soon
as the parameter declaration clause is parsed - the point at which
we  have collected all template parameters

Fixes #64689


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159358

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/cxx2a-template-lambdas.cpp

Index: clang/test/SemaCXX/cxx2a-template-lambdas.cpp
===
--- clang/test/SemaCXX/cxx2a-template-lambdas.cpp
+++ clang/test/SemaCXX/cxx2a-template-lambdas.cpp
@@ -70,3 +70,22 @@
 }
 
 }
+
+namespace GH64689 {
+void f();
+void foo() {
+  [](int)
+noexcept(requires(int t) { f(); })
+-> decltype(requires(int t) { f(); })
+requires requires(int t) { f(); }
+  {return {};}.operator()(0);
+  [](auto)
+noexcept(requires(int t) { f(); })
+-> decltype(requires(int t) { f(); })
+requires requires(int t) { f(); }
+  {return {};}(1);
+}
+
+}
+
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -13554,6 +13554,9 @@
   auto TPL = getDerived().TransformTemplateParameterList(
   E->getTemplateParameterList());
   LSI->GLTemplateParameterList = TPL;
+  if (TPL)
+getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
+TPL);
 
   // Transform the type of the original lambda's call operator.
   // The transformation MUST be done in the CurrentInstantiationScope since
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -912,6 +912,17 @@
   return Method;
 }
 
+void Sema::AddTemplateParametersToLambdaCallOperator(
+CXXMethodDecl *CallOperator, CXXRecordDecl *Class,
+TemplateParameterList *TemplateParams) {
+  assert(TemplateParams && "no template parameters");
+  FunctionTemplateDecl *TemplateMethod = FunctionTemplateDecl::Create(
+  Context, Class, CallOperator->getLocation(), CallOperator->getDeclName(),
+  TemplateParams, CallOperator);
+  TemplateMethod->setAccess(AS_public);
+  CallOperator->setDescribedFunctionTemplate(TemplateMethod);
+}
+
 void Sema::CompleteLambdaCallOperator(
 CXXMethodDecl *Method, SourceLocation LambdaLoc,
 SourceLocation CallOperatorLoc, Expr *TrailingRequiresClause,
@@ -930,11 +941,11 @@
   DeclContext *DC = Method->getLexicalDeclContext();
   Method->setLexicalDeclContext(LSI->Lambda);
   if (TemplateParams) {
-FunctionTemplateDecl *TemplateMethod = FunctionTemplateDecl::Create(
-Context, LSI->Lambda, Method->getLocation(), Method->getDeclName(),
-TemplateParams, Method);
-TemplateMethod->setAccess(AS_public);
-Method->setDescribedFunctionTemplate(TemplateMethod);
+FunctionTemplateDecl *TemplateMethod =
+Method->getDescribedFunctionTemplate();
+assert(TemplateMethod &&
+   "AddTemplateParametersToLambdaCallOperator should have been called");
+
 LSI->Lambda->addDecl(TemplateMethod);
 TemplateMethod->setLexicalDeclContext(DC);
   } else {
@@ -1262,10 +1273,17 @@
   PushOnScopeChains(Param, LambdaScope, false);
   }
 
-  bool IsGenericLambda = getGenericLambdaTemplateParameterList(LSI, *this);
-  LSI->Lambda->setLambdaIsGeneric(IsGenericLambda);
-
-
+  // After the parameter list, we may parse a noexcept/requires/trailing return
+  // type which need to know whether the call operator constiture a dependent
+  // context, so we need to setup the FunctionTemplateDecl of generic lambdas
+  // now.
+  TemplateParameterList *TemplateParams =
+  getGenericLambdaTemplateParameterList(LSI, *this);
+  if (TemplateParams) {
+AddTemplateParametersToLambdaCallOperator(LSI->CallOperator, LSI->Lambda,
+  TemplateParams);
+LSI->Lambda->setLambdaIsGeneric(true);
+  }
   LSI->AfterParameterList = true;
 }
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -7229,6 +7229,11 @@
 
   CXXMethodDecl *CreateLambdaCallOperator(SourceRange IntroducerRange,
   CXXRecordDecl *Class);
+
+  void AddTemplateParametersToLamb

[PATCH] D159358: [Clang] Realize generic lambda call operators are dependent sooner

2023-09-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

This is great! Probably worth the cherry pick to Clang17 as well!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159358

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


[PATCH] D159358: [Clang] Realize generic lambda call operators are dependent sooner

2023-09-01 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 555374.
cor3ntin added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159358

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/cxx2a-template-lambdas.cpp

Index: clang/test/SemaCXX/cxx2a-template-lambdas.cpp
===
--- clang/test/SemaCXX/cxx2a-template-lambdas.cpp
+++ clang/test/SemaCXX/cxx2a-template-lambdas.cpp
@@ -70,3 +70,22 @@
 }
 
 }
+
+namespace GH64689 {
+void f();
+void foo() {
+  [](int)
+noexcept(requires(int t) { f(); })
+-> decltype(requires(int t) { f(); })
+requires requires(int t) { f(); }
+  {return {};}.operator()(0);
+  [](auto)
+noexcept(requires(int t) { f(); })
+-> decltype(requires(int t) { f(); })
+requires requires(int t) { f(); }
+  {return {};}(1);
+}
+
+}
+
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -13554,6 +13554,9 @@
   auto TPL = getDerived().TransformTemplateParameterList(
   E->getTemplateParameterList());
   LSI->GLTemplateParameterList = TPL;
+  if (TPL)
+getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
+TPL);
 
   // Transform the type of the original lambda's call operator.
   // The transformation MUST be done in the CurrentInstantiationScope since
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -912,6 +912,17 @@
   return Method;
 }
 
+void Sema::AddTemplateParametersToLambdaCallOperator(
+CXXMethodDecl *CallOperator, CXXRecordDecl *Class,
+TemplateParameterList *TemplateParams) {
+  assert(TemplateParams && "no template parameters");
+  FunctionTemplateDecl *TemplateMethod = FunctionTemplateDecl::Create(
+  Context, Class, CallOperator->getLocation(), CallOperator->getDeclName(),
+  TemplateParams, CallOperator);
+  TemplateMethod->setAccess(AS_public);
+  CallOperator->setDescribedFunctionTemplate(TemplateMethod);
+}
+
 void Sema::CompleteLambdaCallOperator(
 CXXMethodDecl *Method, SourceLocation LambdaLoc,
 SourceLocation CallOperatorLoc, Expr *TrailingRequiresClause,
@@ -930,11 +941,11 @@
   DeclContext *DC = Method->getLexicalDeclContext();
   Method->setLexicalDeclContext(LSI->Lambda);
   if (TemplateParams) {
-FunctionTemplateDecl *TemplateMethod = FunctionTemplateDecl::Create(
-Context, LSI->Lambda, Method->getLocation(), Method->getDeclName(),
-TemplateParams, Method);
-TemplateMethod->setAccess(AS_public);
-Method->setDescribedFunctionTemplate(TemplateMethod);
+FunctionTemplateDecl *TemplateMethod =
+Method->getDescribedFunctionTemplate();
+assert(TemplateMethod &&
+   "AddTemplateParametersToLambdaCallOperator should have been called");
+
 LSI->Lambda->addDecl(TemplateMethod);
 TemplateMethod->setLexicalDeclContext(DC);
   } else {
@@ -1262,6 +1273,17 @@
   PushOnScopeChains(Param, LambdaScope, false);
   }
 
+  // After the parameter list, we may parse a noexcept/requires/trailing return
+  // type which need to know whether the call operator constiture a dependent
+  // context, so we need to setup the FunctionTemplateDecl of generic lambdas
+  // now.
+  TemplateParameterList *TemplateParams =
+  getGenericLambdaTemplateParameterList(LSI, *this);
+  if (TemplateParams) {
+AddTemplateParametersToLambdaCallOperator(LSI->CallOperator, LSI->Lambda,
+  TemplateParams);
+LSI->Lambda->setLambdaIsGeneric(true);
+  }
   LSI->AfterParameterList = true;
 }
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -7229,6 +7229,11 @@
 
   CXXMethodDecl *CreateLambdaCallOperator(SourceRange IntroducerRange,
   CXXRecordDecl *Class);
+
+  void AddTemplateParametersToLambdaCallOperator(
+  CXXMethodDecl *CallOperator, CXXRecordDecl *Class,
+  TemplateParameterList *TemplateParams);
+
   void CompleteLambdaCallOperator(
   CXXMethodDecl *Method, SourceLocation LambdaLoc,
   SourceLocation CallOperatorLoc, Expr *TrailingRequiresClause,
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -250,6 +250,9 @@
   (`#64962 `_) and
   (`#28679 `_).
 
+- Fix cra

[PATCH] D159358: [Clang] Realize generic lambda call operators are dependent sooner

2023-09-01 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 555375.
cor3ntin added a comment.

Fix tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159358

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/cxx2a-template-lambdas.cpp

Index: clang/test/SemaCXX/cxx2a-template-lambdas.cpp
===
--- clang/test/SemaCXX/cxx2a-template-lambdas.cpp
+++ clang/test/SemaCXX/cxx2a-template-lambdas.cpp
@@ -70,3 +70,20 @@
 }
 
 }
+
+namespace GH64689 {
+void f();
+void foo() {
+  [](int)
+noexcept(requires(int t) { f(); })
+-> decltype(requires(int t) { f(); })
+requires requires(int t) { f(); }
+  {return {};}.operator()(0);
+  [](auto)
+noexcept(requires(int t) { f(); })
+-> decltype(requires(int t) { f(); })
+requires requires(int t) { f(); }
+  {return {};}(1);
+}
+
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -13554,6 +13554,9 @@
   auto TPL = getDerived().TransformTemplateParameterList(
   E->getTemplateParameterList());
   LSI->GLTemplateParameterList = TPL;
+  if (TPL)
+getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
+TPL);
 
   // Transform the type of the original lambda's call operator.
   // The transformation MUST be done in the CurrentInstantiationScope since
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -912,6 +912,17 @@
   return Method;
 }
 
+void Sema::AddTemplateParametersToLambdaCallOperator(
+CXXMethodDecl *CallOperator, CXXRecordDecl *Class,
+TemplateParameterList *TemplateParams) {
+  assert(TemplateParams && "no template parameters");
+  FunctionTemplateDecl *TemplateMethod = FunctionTemplateDecl::Create(
+  Context, Class, CallOperator->getLocation(), CallOperator->getDeclName(),
+  TemplateParams, CallOperator);
+  TemplateMethod->setAccess(AS_public);
+  CallOperator->setDescribedFunctionTemplate(TemplateMethod);
+}
+
 void Sema::CompleteLambdaCallOperator(
 CXXMethodDecl *Method, SourceLocation LambdaLoc,
 SourceLocation CallOperatorLoc, Expr *TrailingRequiresClause,
@@ -930,11 +941,11 @@
   DeclContext *DC = Method->getLexicalDeclContext();
   Method->setLexicalDeclContext(LSI->Lambda);
   if (TemplateParams) {
-FunctionTemplateDecl *TemplateMethod = FunctionTemplateDecl::Create(
-Context, LSI->Lambda, Method->getLocation(), Method->getDeclName(),
-TemplateParams, Method);
-TemplateMethod->setAccess(AS_public);
-Method->setDescribedFunctionTemplate(TemplateMethod);
+FunctionTemplateDecl *TemplateMethod =
+Method->getDescribedFunctionTemplate();
+assert(TemplateMethod &&
+   "AddTemplateParametersToLambdaCallOperator should have been called");
+
 LSI->Lambda->addDecl(TemplateMethod);
 TemplateMethod->setLexicalDeclContext(DC);
   } else {
@@ -1262,6 +1273,17 @@
   PushOnScopeChains(Param, LambdaScope, false);
   }
 
+  // After the parameter list, we may parse a noexcept/requires/trailing return
+  // type which need to know whether the call operator constiture a dependent
+  // context, so we need to setup the FunctionTemplateDecl of generic lambdas
+  // now.
+  TemplateParameterList *TemplateParams =
+  getGenericLambdaTemplateParameterList(LSI, *this);
+  if (TemplateParams) {
+AddTemplateParametersToLambdaCallOperator(LSI->CallOperator, LSI->Lambda,
+  TemplateParams);
+LSI->Lambda->setLambdaIsGeneric(true);
+  }
   LSI->AfterParameterList = true;
 }
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -7229,6 +7229,11 @@
 
   CXXMethodDecl *CreateLambdaCallOperator(SourceRange IntroducerRange,
   CXXRecordDecl *Class);
+
+  void AddTemplateParametersToLambdaCallOperator(
+  CXXMethodDecl *CallOperator, CXXRecordDecl *Class,
+  TemplateParameterList *TemplateParams);
+
   void CompleteLambdaCallOperator(
   CXXMethodDecl *Method, SourceLocation LambdaLoc,
   SourceLocation CallOperatorLoc, Expr *TrailingRequiresClause,
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -250,6 +250,9 @@
   (`#64962 `_) and
   (`#28679 `_).
 
+- Fix crash

[PATCH] D158296: [clang] Diagnose overly complex Record in __builtin_dump_struct

2023-09-01 Thread Yurong via Phabricator via cfe-commits
yronglin updated this revision to Diff 555376.
yronglin added a comment.

Address Aaron's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158296

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/builtin-dump-struct.cpp


Index: clang/test/SemaCXX/builtin-dump-struct.cpp
===
--- clang/test/SemaCXX/builtin-dump-struct.cpp
+++ clang/test/SemaCXX/builtin-dump-struct.cpp
@@ -184,3 +184,22 @@
 
 int printf(const char *, ...);
 void f1(t2 w) { __builtin_dump_struct(&w, printf); }
+
+struct t3 { };
+template
+struct templ {
+T1 v1;
+T1 v2;
+T1 v3;
+T1 v4;
+};
+
+struct t4 {
+  templ> c0;
+  templ> c1;
+  templ> c2;
+};
+
+void aj(...);
+void f2(t4 w) { __builtin_dump_struct(&w, aj); } // expected-error{{struct 
't4' is too complex to dump}}
+
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -724,6 +724,16 @@
   if (Generator.dumpUnnamedRecord(RD, PtrArg, 0))
 return ExprError();
 
+  // We create a `PseudoObjectExpr` as a wrapper, but the
+  // `PseudoObjectExprBits.NumSubExprs` in `PseudoObjectExpr` restricts its
+  // value to no more than std::numeric_limits::max().
+  if (Generator.Actions.size() > std::numeric_limits::max()) {
+int RDKind = RD->isClass() ? 0 : (RD->isStruct() ? 1 : 2);
+S.Diag(PtrArg->getBeginLoc(), diag::err_builtin_dump_struct_too_complex)
+<< RDKind << RD;
+return ExprError();
+  }
+
   return Generator.buildWrapper();
 }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10176,6 +10176,9 @@
   "argument to __builtin_longjmp must be a constant 1">;
 def err_builtin_requires_language : Error<"'%0' is only available in %1">;
 
+def err_builtin_dump_struct_too_complex : Error<
+"%select{class|struct|union}0 %1 is too complex to dump">;
+
 def err_constant_integer_arg_type : Error<
   "argument to %0 must be a constant integer">;
 


Index: clang/test/SemaCXX/builtin-dump-struct.cpp
===
--- clang/test/SemaCXX/builtin-dump-struct.cpp
+++ clang/test/SemaCXX/builtin-dump-struct.cpp
@@ -184,3 +184,22 @@
 
 int printf(const char *, ...);
 void f1(t2 w) { __builtin_dump_struct(&w, printf); }
+
+struct t3 { };
+template
+struct templ {
+T1 v1;
+T1 v2;
+T1 v3;
+T1 v4;
+};
+
+struct t4 {
+  templ> c0;
+  templ> c1;
+  templ> c2;
+};
+
+void aj(...);
+void f2(t4 w) { __builtin_dump_struct(&w, aj); } // expected-error{{struct 't4' is too complex to dump}}
+
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -724,6 +724,16 @@
   if (Generator.dumpUnnamedRecord(RD, PtrArg, 0))
 return ExprError();
 
+  // We create a `PseudoObjectExpr` as a wrapper, but the
+  // `PseudoObjectExprBits.NumSubExprs` in `PseudoObjectExpr` restricts its
+  // value to no more than std::numeric_limits::max().
+  if (Generator.Actions.size() > std::numeric_limits::max()) {
+int RDKind = RD->isClass() ? 0 : (RD->isStruct() ? 1 : 2);
+S.Diag(PtrArg->getBeginLoc(), diag::err_builtin_dump_struct_too_complex)
+<< RDKind << RD;
+return ExprError();
+  }
+
   return Generator.buildWrapper();
 }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10176,6 +10176,9 @@
   "argument to __builtin_longjmp must be a constant 1">;
 def err_builtin_requires_language : Error<"'%0' is only available in %1">;
 
+def err_builtin_dump_struct_too_complex : Error<
+"%select{class|struct|union}0 %1 is too complex to dump">;
+
 def err_constant_integer_arg_type : Error<
   "argument to %0 must be a constant integer">;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158296: [clang] Diagnose overly complex Record in __builtin_dump_struct

2023-09-01 Thread Yurong via Phabricator via cfe-commits
yronglin marked 4 inline comments as done.
yronglin added a comment.

Thank you for your review @aaron.ballman @rsmith , I will be happy to continue 
cook this patch once we reach a consensus.




Comment at: clang/lib/Sema/SemaChecking.cpp:732-733
+int RDKind = RD->isClass() ? 0 : (RD->isStruct() ? 1 : 2);
+S.Diag(PtrArg->getBeginLoc(), diag::err_builtin_dump_struct_too_complex)
+<< RDKind << RD->getName();
+return ExprError();

rsmith wrote:
> aaron.ballman wrote:
> > rsmith wrote:
> > > aaron.ballman wrote:
> > > > This will correctly handle diagnosing a gigantic anonymous struct.
> > > Producing an error here seems likely to eventually cause problems in 
> > > practice for some users: people are using `__builtin_dump_struct` in 
> > > generic code for reflection purposes, not just for debugging, and this 
> > > will cause us to start rejecting complex generic code.
> > > 
> > > Instead of rejecting, can we produce a tree of `PseudoObjectExpr`s if we 
> > > have too many steps to store in a single expression?
> > > Producing an error here seems likely to eventually cause problems in 
> > > practice for some users: people are using __builtin_dump_struct in 
> > > generic code for reflection purposes, not just for debugging, and this 
> > > will cause us to start rejecting complex generic code.
> > >
> > > Instead of rejecting, can we produce a tree of PseudoObjectExprs if we 
> > > have too many steps to store in a single expression?
> > 
> > I think that requires wider discussion -- I don't think 
> > `__builtin_dump_struct` is a reasonable interface we want to support for 
> > reflection (in fact, I'd argue it's an explicit non-goal, the same as 
> > reflection via `-ast-dump`). Compile-time reflection is something we're 
> > likely to need to support more intentionally and I don't think we're going 
> > to want to use this as an interface for it or have to maintain it as a 
> > reflection tool long-term. As such, I think producing a tree of 
> > `PseudoObjectExpr`s is overkill; you can quote me on this a few years from 
> > now when we're laughing at its quaintness, but "16k fields of debug output 
> > is enough for anyone" for a debugging interface.
> > 
> > (That said, I think we should be considering what support we want to add to 
> > the compiler for reflection in service of the work being done in WG21 on 
> > the topic -- if `__builtin_dump_struct` is being used for reflection in 
> > practice, it would be nice to give people a supported, more ergonomic 
> > interface for it that we can use for a future version of C++.)
> The bug report https://github.com/llvm/llvm-project/issues/63169 was 
> encountered by a user hitting the previous 256-element limit in practice when 
> using `__builtin_dump_struct` for reflection. I don't think we can reasonably 
> prevent that from happening, other than -- as you say -- encouraging WG21 to 
> give us a real reflection design we can implement.
fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158296

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


[clang] 7c65443 - [clang][Sema] Correct RUN line in fixit tests

2023-09-01 Thread David Spickett via cfe-commits

Author: David Spickett
Date: 2023-09-01T14:53:41Z
New Revision: 7c6544333eba516c1b569fb74288bbfe9ca54c1f

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

LOG: [clang][Sema] Correct RUN line in fixit tests

These were missing the ":" on the end.

Added: 


Modified: 
clang/test/Sema/warn-documentation-fixits.c
clang/test/Sema/warn-documentation-fixits.cpp

Removed: 




diff  --git a/clang/test/Sema/warn-documentation-fixits.c 
b/clang/test/Sema/warn-documentation-fixits.c
index 413ebb26b3153d..5b6efb2018d827 100644
--- a/clang/test/Sema/warn-documentation-fixits.c
+++ b/clang/test/Sema/warn-documentation-fixits.c
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wdocumentation -Wdocumentation-pedantic 
-fcomment-block-commands=foobar -verify %s
-// RUN  %clang_cc1 -std=c18 -fsyntax-only -Wdocumentation 
-Wdocumentation-pedantic -fcomment-block-commands=foobar 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck 
-DATTRIBUTE="__attribute__((deprecated))" %s
+// RUN: %clang_cc1 -std=c18 -fsyntax-only -Wdocumentation 
-Wdocumentation-pedantic -fcomment-block-commands=foobar 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck 
-DATTRIBUTE="__attribute__((deprecated))" %s
 // RUN: %clang_cc1 -std=c2x -DC2x -fsyntax-only -Wdocumentation 
-Wdocumentation-pedantic -fcomment-block-commands=foobar 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck 
--check-prefixes=CHECK,CHECK2x -DATTRIBUTE="[[deprecated]]" %s
 
 // expected-warning@+1 {{declaration is marked with '\deprecated' command but 
does not have a deprecation attribute}} expected-note@+2 {{add a deprecation 
attribute to the declaration to silence this warning}}

diff  --git a/clang/test/Sema/warn-documentation-fixits.cpp 
b/clang/test/Sema/warn-documentation-fixits.cpp
index 8c1b1eae021f6a..bccc8e17ca121b 100644
--- a/clang/test/Sema/warn-documentation-fixits.cpp
+++ b/clang/test/Sema/warn-documentation-fixits.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wdocumentation -Wdocumentation-pedantic 
-fcomment-block-commands=foobar -verify %s
-// RUN  %clang_cc1 -std=c++11 -fsyntax-only -Wdocumentation 
-Wdocumentation-pedantic -fcomment-block-commands=foobar 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck 
-DATTRIBUTE="__attribute__((deprecated))" %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wdocumentation 
-Wdocumentation-pedantic -fcomment-block-commands=foobar 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck 
-DATTRIBUTE="__attribute__((deprecated))" %s
 // RUN: %clang_cc1 -std=c++14 -fsyntax-only -Wdocumentation 
-Wdocumentation-pedantic -fcomment-block-commands=foobar 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck 
--check-prefixes=CHECK,CHECK14 -DATTRIBUTE="[[deprecated]]" %s
 
 // expected-warning@+1 {{parameter 'ZZ' not found in the function 
declaration}} expected-note@+1 {{did you mean 'a'?}}



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


[clang] ef5219c - [clang][Driver] Correct OpenBSD UBSAN options test

2023-09-01 Thread David Spickett via cfe-commits

Author: David Spickett
Date: 2023-09-01T14:55:11Z
New Revision: ef5219c18b252ac36815d5f322acab704259df08

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

LOG: [clang][Driver] Correct OpenBSD UBSAN options test

The RUN here was mising ":" and there was no check file passed
to FileCheck. This has been the case since this was originally added.

UBSAN is the only sanitizer that is available for OpenBSD,
but it does not add a simple "-fsanitize=undefined" instead
it adds a bunch of smaller options. So check for those like
the existing tests do.

Added: 


Modified: 
clang/test/Driver/fsanitize.c

Removed: 




diff  --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 3b9b399cb8235e..19e10f6043123f 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -548,8 +548,8 @@
 // RUN: %clang --target=armv7-apple-ios7 -miphoneos-version-min=7.0 
-fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-IOS
 // CHECK-ASAN-IOS: -fsanitize=address
 
-// RUN %clang --target=i386-pc-openbsd -fsanitize=undefined %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-UBSAN-OPENBSD
-// CHECK-UBSAN-OPENBSD: -fsanitize=undefined
+// RUN: %clang --target=i386-pc-openbsd -fsanitize=undefined %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-UBSAN-OPENBSD
+// CHECK-UBSAN-OPENBSD: 
"-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){19}"}}
 
 // RUN: not %clang --target=i386-pc-openbsd -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-ASAN-OPENBSD
 // CHECK-ASAN-OPENBSD: unsupported option '-fsanitize=address' for target 
'i386-pc-openbsd'



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


[PATCH] D159247: [HLSL] Cleanup support for `this` as an l-value

2023-09-01 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 555380.
beanz added a comment.

Updating based on PR feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159247

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Analysis/Consumed.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/Sema/HLSLExternalSemaSource.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/test/CodeGenHLSL/this-reference.hlsl

Index: clang/test/CodeGenHLSL/this-reference.hlsl
===
--- clang/test/CodeGenHLSL/this-reference.hlsl
+++ clang/test/CodeGenHLSL/this-reference.hlsl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -emit-llvm -disable-llvm-passes -o - -hlsl-entry main %s | FileCheck %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -emit-llvm -disable-llvm-passes -o - -hlsl-entry main %s -debug-info-kind=standalone -dwarf-version=4 | FileCheck %s
 
 struct Pair {
   int First;
@@ -26,3 +26,9 @@
   // CHECK-NEXT:  store i32 %call, ptr %First, align 4
   // CHECK-NEXT:  %call1 = call noundef float @"?getSecond@Pair@@QAAMXZ"(ptr noundef nonnull align 4 dereferenceable(8) %Vals)
   // CHECK-NEXT:  %Second = getelementptr inbounds %struct.Pair, ptr %Vals, i32 0, i32 1
+
+// CHECK: [[Pair:![0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Pair"
+// CHECK: [[getFirst:![0-9]+]] = distinct !DISubprogram(name: "getFirst"
+// CHECK-SAME: scope: [[Pair]]
+// CHECK: [[FirstThis:![0-9]+]] = !DILocalVariable(name: "this", arg: 1, scope: [[getFirst]], type: [[thisType:![0-9]+]]
+// CHECK: [[thisType]] = !DIDerivedType(tag: DW_TAG_reference_type, baseType: [[Pair]], size: 32)
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -3880,7 +3880,7 @@
   break;
 
 case EXPR_CXX_THIS:
-  S = new (Context) CXXThisExpr(Empty);
+  S = CXXThisExpr::CreateEmpty(Context);
   break;
 
 case EXPR_CXX_THROW:
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -753,15 +753,16 @@
 
   if (!MightBeCxx11UnevalField && !isAddressOfOperand && !IsEnum &&
   isa(DC) && cast(DC)->isInstance()) {
-QualType ThisType = cast(DC)->getThisType();
+QualType ThisType = cast(DC)->getThisType().getNonReferenceType();
 
 // Since the 'this' expression is synthesized, we don't need to
 // perform the double-lookup check.
 NamedDecl *FirstQualifierInScope = nullptr;
 
 return CXXDependentScopeMemberExpr::Create(
-Context, /*This*/ nullptr, ThisType, /*IsArrow*/ true,
-/*Op*/ SourceLocation(), SS.getWithLocInContext(Context), TemplateKWLoc,
+Context, /*This=*/nullptr, ThisType,
+/*IsArrow=*/!Context.getLangOpts().HLSL,
+/*Op=*/SourceLocation(), SS.getWithLocInContext(Context), TemplateKWLoc,
 FirstQualifierInScope, NameInfo, TemplateArgs);
   }
 
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -689,7 +689,7 @@
 if (CMD->isStatic())
   Type.MemberType = FuncType::ft_static_member;
 else {
-  Type.This = CMD->getThisType()->getPointeeType();
+  Type.This = CMD->getThisObjectType();
   Type.MemberType = FuncType::ft_non_static_member;
 }
 Type.Func = CMD->getType()->castAs();
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -3532,14 +3532,14 @@
   case OR_Success: {
 // Record the standard conversion we used and the conversion function.
 CXXConstructorDecl *Constructor = cast(Best->Function);
-QualType ThisType = Constructor->getThisType();
+QualType ThisType = Constructor->getThisObjectType();
 // Initializer lists don't have conversions as such.
 User.Before.setAsIdentityConversion();
 User.HadMultipleCandidates = HadMultipleCandidates;
 User.ConversionFunction = Constructor;
 User.FoundConversionFunction = Best->FoundDecl;
 User.After.setAsIdentityConversion();
-User.After.setFrom

[PATCH] D159312: [Headers] Remove a space in NULL define

2023-09-01 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin added a comment.

I believe this is better solved downstream, i.e., in musl. I'm not a musl 
developer but a user, but I can consider contributing a patch there. I'd like 
to remove the whitespace for now because it is currently breaking us and it had 
been that way for a long time anyway, but I don't mind removing the comments, 
given that it sounds like we cannot change this forever.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159312

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


[PATCH] D158363: [clang-format] Fix segmentation fault when formatting nested namespaces

2023-09-01 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

We need the name and email you want to use in order to commit the patch for you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158363

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


[PATCH] D114903: [clang] Support array placement new in constant expressions

2023-09-01 Thread Louis Dionne via Phabricator via cfe-commits
ldionne abandoned this revision.
ldionne added a comment.
Herald added a project: All.

I've run out of time to work on this. It's also not clear that it's supported 
by the Standard right now since there's a not-voted-yet LWG issue about it 
(http://wg21.link/LWG3436).

Abandoning. This isn't blocking libc++ anymore, too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114903

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


[PATCH] D159363: [clangd] SIGSEGV at clangd: DiagnosticConsumer Is Used After Free

2023-09-01 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko created this revision.
ivanmurashko added reviewers: kadircet, sammccall.
ivanmurashko added projects: clang, clang-tools-extra.
Herald added a subscriber: arphaman.
Herald added a project: All.
ivanmurashko requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

This is a follow-up patch for D148088 . The 
dynamic symbol index (`FileIndex::updatePreamble`) may run in a separate 
thread, and the `DiagnosticConsumer` that is set up in `buildPreamble` might go 
out of scope before it is used. This could result in a SIGSEGV when attempting 
to call any method of the `DiagnosticConsumer` class.

The function `buildPreamble` sets up the `DiagnosticConsumer` as follows:

  ... buildPreamble(...) {
  ...
StoreDiags PreambleDiagnostics;
...
llvm::IntrusiveRefCntPtr PreambleDiagsEngine =
  CompilerInstance::createDiagnostics(&CI.getDiagnosticOpts(),
  &PreambleDiagnostics,
  /*ShouldOwnClient=*/false);
...
// The call might use the diagnostic consumer in a separate thread
PreambleCallback(...)
...
  }

`PreambleDiagnostics` might be out of scope for `buildPreamble` function when 
we call it inside `PreambleCallback` in a separate thread.

The Fix
The fix involves replacing the client (DiagnosticConsumer) with an 
`IgnoringDiagConsumer` instance, which will print messages to the clangd log.

Alternatively, we can replace `PreambleDiagnostics` with an object that is 
owned by `DiagnosticsEngine`.

Note
There is no corresponding LIT/GTest for this issue, since there is a specific 
race condition that is difficult to reproduce within a test framework.

Test Plan:

  ninja check-clangd


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159363

Files:
  clang-tools-extra/clangd/Preamble.cpp


Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -706,6 +706,11 @@
   // While extending the life of FileMgr and VFS, StatCache should also be
   // extended.
   Ctx->setStatCache(Result->StatCache);
+  // We have to setup DiagnosticConsumer that will be alife
+  // while preamble callback is executed
+  Ctx->getASTContext().getDiagnostics().setClient(new IgnoringDiagConsumer,
+  true);
+
   PreambleCallback(std::move(*Ctx), Result->Pragmas);
 }
 return Result;


Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -706,6 +706,11 @@
   // While extending the life of FileMgr and VFS, StatCache should also be
   // extended.
   Ctx->setStatCache(Result->StatCache);
+  // We have to setup DiagnosticConsumer that will be alife
+  // while preamble callback is executed
+  Ctx->getASTContext().getDiagnostics().setClient(new IgnoringDiagConsumer,
+  true);
+
   PreambleCallback(std::move(*Ctx), Result->Pragmas);
 }
 return Result;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159362: [clang][AST][DeclPrinter] Change "__attribute__" AST printing location for the sake of GCC compatibility.

2023-09-01 Thread Mateusz Stachyra via Phabricator via cfe-commits
mstachyraa created this revision.
Herald added a project: All.
mstachyraa requested review of this revision.
Herald added a subscriber: wangpc.
Herald added a project: clang.

When printing C representation of AST, clang puts the "__attribute__" elements 
after the name of printed function.
In order for the generated code to be GCC compatible, these attributes should 
be put at the beginning of function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159362

Files:
  clang/lib/AST/DeclPrinter.cpp


Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -612,6 +612,8 @@
  I < NumTemplateParams; ++I)
   printTemplateParameters(D->getTemplateParameterList(I));
   }
+  
+  prettyPrintAttributes(D);
 
   CXXConstructorDecl *CDecl = dyn_cast(D);
   CXXConversionDecl *ConversionDecl = dyn_cast(D);
@@ -774,8 +776,6 @@
 Ty.print(Out, Policy, Proto);
   }
 
-  prettyPrintAttributes(D);
-
   if (D->isPure())
 Out << " = 0";
   else if (D->isDeletedAsWritten())


Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -612,6 +612,8 @@
  I < NumTemplateParams; ++I)
   printTemplateParameters(D->getTemplateParameterList(I));
   }
+  
+  prettyPrintAttributes(D);
 
   CXXConstructorDecl *CDecl = dyn_cast(D);
   CXXConversionDecl *ConversionDecl = dyn_cast(D);
@@ -774,8 +776,6 @@
 Ty.print(Out, Policy, Proto);
   }
 
-  prettyPrintAttributes(D);
-
   if (D->isPure())
 Out << " = 0";
   else if (D->isDeletedAsWritten())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158967: [clang][clangd] Ensure the stack bottom before building AST

2023-09-01 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks! Sorry about the layering mess...




Comment at: clang-tools-extra/clangd/support/Threading.cpp:11
 #include "support/Trace.h"
+#include "clang/Basic/Stack.h"
 #include "llvm/ADT/ScopeExit.h"

need to remove this include too :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158967

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


[PATCH] D159345: [Clang] Handle non-ASCII after line splicing

2023-09-01 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:1757
+  // If a UTF-8 codepoint appears immediately after an escaped new line,
+  // CurPtr may point to the splicing \ at the on the preceding line,
+  // so we need to skip it.

I think that is what you meant to say



Comment at: clang/lib/Lex/Lexer.cpp:1761
+  getCharAndSize(CurPtr, FirstCodeUnitSize);
+  const char *CharStart = CurPtr + FirstCodeUnitSize - 1;
+  const char *UnicodePtr = CharStart;

Do we need to verify that `FirstCodeUnitSize` is not zero?



Comment at: clang/lib/Lex/Lexer.cpp:1798
 
+  ConsumeChar(CurPtr, FirstCodeUnitSize, Tok);
   CurPtr = UnicodePtr;

So if we get here it mean we have the splice to skip?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159345

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


[PATCH] D159363: [clangd] SIGSEGV at clangd: DiagnosticConsumer Is Used After Free

2023-09-01 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko added inline comments.



Comment at: clang-tools-extra/clangd/Preamble.cpp:610-619
   StoreDiags PreambleDiagnostics;
   PreambleDiagnostics.setDiagCallback(
   [&ASTListeners](const clang::Diagnostic &D, clangd::Diag &Diag) {
 llvm::for_each(ASTListeners,
[&](const auto &L) { L->sawDiagnostic(D, Diag); });
   });
   llvm::IntrusiveRefCntPtr PreambleDiagsEngine =

Alternative fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159363

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


[PATCH] D159363: [clangd] SIGSEGV at clangd: DiagnosticConsumer Is Used After Free

2023-09-01 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Nice catch!




Comment at: clang-tools-extra/clangd/Preamble.cpp:709
   Ctx->setStatCache(Result->StatCache);
+  // We have to setup DiagnosticConsumer that will be alife
+  // while preamble callback is executed

I think this should go up next to PreambleDiagsEngine.reset() etc, as it's 
basically the same thing: we're trying to avoid any race between the async work 
done by the callback and the cleanup at the end of the function.

Also I think it's slightly clearer for us to consistently be taking the 
diagnostics from PreambleDiagnostics *after* it's detached from the compiler.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159363

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


[PATCH] D159363: [clangd] SIGSEGV at clangd: DiagnosticConsumer Is Used After Free

2023-09-01 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/Preamble.cpp:610-619
   StoreDiags PreambleDiagnostics;
   PreambleDiagnostics.setDiagCallback(
   [&ASTListeners](const clang::Diagnostic &D, clangd::Diag &Diag) {
 llvm::for_each(ASTListeners,
[&](const auto &L) { L->sawDiagnostic(D, Diag); });
   });
   llvm::IntrusiveRefCntPtr PreambleDiagsEngine =

ivanmurashko wrote:
> Alternative fix
I prefer the version in the patch: we keep PreambleDiagnostics auto-scoped and 
can more easily reason about its lifetime.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159363

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


[PATCH] D159188: [AArch64][SME] Make the overloaded svreinterpret_* functions streaming-compatible.

2023-09-01 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen updated this revision to Diff 555402.
sdesmalen marked an inline comment as done.
sdesmalen added a comment.

Added "aarch64_32" to TargetAArch64.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159188

Files:
  clang/include/clang/Basic/Attr.td
  
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_reinterpret_from_streaming_mode.c
  clang/utils/TableGen/SveEmitter.cpp


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -1284,7 +1284,7 @@
 if (ShortForm) {
   OS << "__aio __attribute__((target(\"sve\"))) " << From.Type
  << " svreinterpret_" << From.Suffix;
-  OS << "(" << To.Type << " op) {\n";
+  OS << "(" << To.Type << " op) __arm_streaming_compatible {\n";
   OS << "  return __builtin_sve_reinterpret_" << From.Suffix << "_"
  << To.Suffix << "(op);\n";
   OS << "}\n\n";
Index: 
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_reinterpret_from_streaming_mode.c
===
--- /dev/null
+++ 
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_reinterpret_from_streaming_mode.c
@@ -0,0 +1,35 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -S -O1 
-Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -S -O1 
-Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -S -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck 
%s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -S -O1 
-Werror -Wall -o /dev/null %s
+
+// Note: We need to run this test with '-O1' because oddly enough the 
svreinterpret is always inlined at -O0.
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3##A4
+#endif
+
+// Test that svreinterpret is inlined (because it should be 
streaming-compatible)
+__attribute__((target("sme")))
+// CHECK-LABEL: @test_svreinterpret_s16_s8_from_streaming_mode(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast  [[OP:%.*]] to 

+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: 
@_Z45test_svreinterpret_s16_s8_from_streaming_modeu10__SVInt8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = bitcast  [[OP:%.*]] to 

+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint16_t test_svreinterpret_s16_s8_from_streaming_mode(svint8_t op) 
__arm_streaming {
+  return SVE_ACLE_FUNC(svreinterpret_s16,_s8,,)(op);
+}
+
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -415,7 +415,7 @@
   let Arches = arches;
 }
 def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
-def TargetAArch64 : TargetArch<["aarch64"]>;
+def TargetAArch64 : TargetArch<["aarch64", "aarch64_be", "aarch64_32"]>;
 def TargetAnyArm : TargetArch;
 def TargetAVR : TargetArch<["avr"]>;
 def TargetBPF : TargetArch<["bpfel", "bpfeb"]>;


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -1284,7 +1284,7 @@
 if (ShortForm) {
   OS << "__aio __attribute__((target(\"sve\"))) " << From.Type
  << " svreinterpret_" << From.Suffix;
-  OS << "(" << To.Type << " op) {\n";
+  OS << "(" << To.Type << " op) __arm_streaming_compatible {\n";
   OS << "  return __builtin_sve_reinterpret_" << From.Suffix << "_"
  << To.Suffix << "(op);\n";
   OS << "}\n\n";
Index: clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_reinterpret_from_streaming_mode.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_reinterpret_from_streaming_mode.c
@@ -0,0 +1,35 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gn

[PATCH] D157385: [clang][CFG] Cleanup functions

2023-09-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 555403.

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

https://reviews.llvm.org/D157385

Files:
  clang/include/clang/Analysis/CFG.h
  clang/lib/Analysis/CFG.cpp
  clang/lib/Analysis/PathDiagnostic.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/Analysis/scopes-cfg-output.cpp

Index: clang/test/Analysis/scopes-cfg-output.cpp
===
--- clang/test/Analysis/scopes-cfg-output.cpp
+++ clang/test/Analysis/scopes-cfg-output.cpp
@@ -1419,3 +1419,68 @@
 }
   }
 }
+
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(i)
+// CHECK-NEXT:   2: int i __attribute__((cleanup(cleanup_int)));
+// CHECK-NEXT:   3: CleanupFunction (cleanup_int)
+// CHECK-NEXT:   4: CFGScopeEnd(i)
+void cleanup_int(int *i);
+void test_cleanup_functions() {
+  int i __attribute__((cleanup(cleanup_int)));
+}
+
+// CHECK:  [B1]
+// CHECK-NEXT:1: 10
+// CHECK-NEXT:2: i
+// CHECK-NEXT:3: [B1.2] = [B1.1]
+// CHECK-NEXT:4: return;
+// CHECK-NEXT:5: CleanupFunction (cleanup_int)
+// CHECK-NEXT:6: CFGScopeEnd(i)
+// CHECK-NEXT:Preds (1): B3
+// CHECK-NEXT:Succs (1): B0
+// CHECK:  [B2]
+// CHECK-NEXT:1: return;
+// CHECK-NEXT:2: CleanupFunction (cleanup_int)
+// CHECK-NEXT:3: CFGScopeEnd(i)
+// CHECK-NEXT:Preds (1): B3
+// CHECK-NEXT:Succs (1): B0
+// CHECK:  [B3]
+// CHECK-NEXT:1: CFGScopeBegin(i)
+// CHECK-NEXT:2: int i __attribute__((cleanup(cleanup_int)));
+// CHECK-NEXT:3: m
+// CHECK-NEXT:4: [B3.3] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:5: 1
+// CHECK-NEXT:6: [B3.4] == [B3.5]
+// CHECK-NEXT:T: if [B3.6]
+// CHECK-NEXT:Preds (1): B4
+// CHECK-NEXT:Succs (2): B2 B1
+void test_cleanup_functions2(int m) {
+  int i __attribute__((cleanup(cleanup_int)));
+
+  if (m == 1) {
+return;
+  }
+
+  i = 10;
+  return;
+}
+
+// CHECK:   [B1]
+// CHECK-NEXT:1: CFGScopeBegin(f)
+// CHECK-NEXT:2:  (CXXConstructExpr, [B1.3], F)
+// CHECK-NEXT:3: F f __attribute__((cleanup(cleanup_F)));
+// CHECK-NEXT:4: CleanupFunction (cleanup_F)
+// CHECK-NEXT:5: [B1.3].~F() (Implicit destructor)
+// CHECK-NEXT:6: CFGScopeEnd(f)
+// CHECK-NEXT:Preds (1): B2
+// CHECK-NEXT:Succs (1): B0
+class F {
+public:
+  ~F();
+};
+void cleanup_F(F *f);
+
+void test() {
+  F f __attribute((cleanup(cleanup_F)));
+}
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -993,6 +993,7 @@
   ProcessLoopExit(E.castAs().getLoopStmt(), Pred);
   return;
 case CFGElement::LifetimeEnds:
+case CFGElement::CleanupFunction:
 case CFGElement::ScopeBegin:
 case CFGElement::ScopeEnd:
   return;
Index: clang/lib/Analysis/PathDiagnostic.cpp
===
--- clang/lib/Analysis/PathDiagnostic.cpp
+++ clang/lib/Analysis/PathDiagnostic.cpp
@@ -565,6 +565,7 @@
   }
   case CFGElement::ScopeBegin:
   case CFGElement::ScopeEnd:
+  case CFGElement::CleanupFunction:
 llvm_unreachable("not yet implemented!");
   case CFGElement::LifetimeEnds:
   case CFGElement::LoopExit:
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -881,6 +881,10 @@
 B->appendAutomaticObjDtor(VD, S, cfg->getBumpVectorContext());
   }
 
+  void appendCleanupFunction(CFGBlock *B, VarDecl *VD) {
+B->appendCleanupFunction(VD, cfg->getBumpVectorContext());
+  }
+
   void appendLifetimeEnds(CFGBlock *B, VarDecl *VD, Stmt *S) {
 B->appendLifetimeEnds(VD, S, cfg->getBumpVectorContext());
   }
@@ -1346,7 +1350,8 @@
 return {};
   }
 
-  bool hasTrivialDestructor(VarDecl *VD);
+  bool hasTrivialDestructor(const VarDecl *VD) const;
+  bool needsAutomaticDestruction(const VarDecl *VD) const;
 };
 
 } // namespace
@@ -1861,14 +1866,14 @@
   if (B == E)
 return;
 
-  SmallVector DeclsNonTrivial;
-  DeclsNonTrivial.reserve(B.distance(E));
+  SmallVector DeclsNeedDestruction;
+  DeclsNeedDestruction.reserve(B.distance(E));
 
   for (VarDecl* D : llvm::make_range(B, E))
-if (!hasTrivialDestructor(D))
-  DeclsNonTrivial.push_back(D);
+if (needsAutomaticDestruction(D))
+  DeclsNeedDestruction.push_back(D);
 
-  for (VarDecl *VD : llvm::reverse(DeclsNonTrivial)) {
+  for (VarDecl *VD : llvm::reverse(DeclsNeedDestruction)) {
 if (BuildOpts.AddImplicitDtors) {
   // If this destructor is marked as a no-return destructor, we need to
   // create a new block for the destructor which does not have as a
@@ -1879,19 +1884,24 @@
 Ty = getReferenceInitTemporaryType(VD->getInit());
   Ty = Context->getBaseElementType(Ty);
 
-  if (Ty->getAsCXXRecordDecl()

[PATCH] D159188: [AArch64][SME] Make the overloaded svreinterpret_* functions streaming-compatible.

2023-09-01 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:418
 def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
-def TargetAArch64 : TargetArch<["aarch64"]>;
+def TargetAArch64 : TargetArch<["aarch64", "aarch64_be"]>;
 def TargetAnyArm : TargetArch;

david-arm wrote:
> I'm not sure why this change is included in this patch?
This is needed for `clang/test/Sema/aarch64-sve-intrinsics/big_endian.cpp` 
which  has `aarch64_be` as target and includes arm_sve.h.
Without this change the `__arm_streaming_compatible` attribute is unsupported 
and leads to loads of error messages, thus failing the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159188

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


[PATCH] D157385: [clang][CFG] Cleanup functions

2023-09-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added a comment.

@steakhal Double lifetime ends should be fixed now.


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

https://reviews.llvm.org/D157385

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


[clang] 8eb3470 - [SpecialCaseList] Add option to use Globs instead of Regex to match patterns

2023-09-01 Thread Ellis Hoag via cfe-commits

Author: Ellis Hoag
Date: 2023-09-01T09:06:11-07:00
New Revision: 8eb34700c2b1847ec6dfb8f92b305b65278d2ec0

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

LOG: [SpecialCaseList] Add option to use Globs instead of Regex to match 
patterns

Add an option in `SpecialCaseList` to use Globs instead of Regex to match 
patterns. `GlobPattern` was extended in https://reviews.llvm.org/D153587 to 
support brace expansions which allows us to use patterns like 
`*/src/foo.{c,cpp}`. It turns out that most patterns only take advantage of `*` 
so using Regex was overkill and required lots of escaping in practice. This 
often led to bugs due to forgetting to escape special characters.

Since this would be a breaking change, we temporarily support Regex by default 
and use Globs when `#!special-case-list-v2` is the first line in the file. 
Users should switch to the glob format described in 
https://llvm.org/doxygen/classllvm_1_1GlobPattern.html. For example, 
`(abc|def)` should become `{abc,def}`.

See discussion in https://reviews.llvm.org/D152762 and 
https://discourse.llvm.org/t/use-glob-instead-of-regex-for-specialcaselists/71666.

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/docs/SanitizerSpecialCaseList.rst
clang/lib/Basic/ProfileList.cpp
clang/lib/Basic/SanitizerSpecialCaseList.cpp
llvm/include/llvm/Support/SpecialCaseList.h
llvm/lib/Support/SpecialCaseList.cpp
llvm/unittests/Support/SpecialCaseListTest.cpp

Removed: 




diff  --git a/clang/docs/SanitizerSpecialCaseList.rst 
b/clang/docs/SanitizerSpecialCaseList.rst
index 15e19b9c129ca46..ab39276b0439577 100644
--- a/clang/docs/SanitizerSpecialCaseList.rst
+++ b/clang/docs/SanitizerSpecialCaseList.rst
@@ -15,7 +15,7 @@ file at compile-time.
 Goal and usage
 ==
 
-User of sanitizer tools, such as :doc:`AddressSanitizer`, 
:doc:`ThreadSanitizer`
+Users of sanitizer tools, such as :doc:`AddressSanitizer`, 
:doc:`ThreadSanitizer`
 or :doc:`MemorySanitizer` may want to disable or alter some checks for
 certain source-level entities to:
 
@@ -54,37 +54,48 @@ Format
 Ignorelists consist of entries, optionally grouped into sections. Empty lines
 and lines starting with "#" are ignored.
 
-Section names are regular expressions written in square brackets that denote
+.. note::
+
+  In `D154014 `_ we transitioned to using 
globs instead
+  of regexes to match patterns in special case lists. Since this was a
+  breaking change, we will temporarily support the original behavior using
+  regexes. If ``#!special-case-list-v2`` is the first line of the file, then
+  we will use the new behavior using globs. For more details, see
+  `this discourse post 
`_.
+
+
+Section names are globs written in square brackets that denote
 which sanitizer the following entries apply to. For example, ``[address]``
-specifies AddressSanitizer while ``[cfi-vcall|cfi-icall]`` specifies Control
+specifies AddressSanitizer while ``[{cfi-vcall,cfi-icall}]`` specifies Control
 Flow Integrity virtual and indirect call checking. Entries without a section
 will be placed under the ``[*]`` section applying to all enabled sanitizers.
 
-Entries contain an entity type, followed by a colon and a regular expression,
+Entries contain an entity type, followed by a colon and a glob,
 specifying the names of the entities, optionally followed by an equals sign and
-a tool-specific category, e.g. ``fun:*ExampleFunc=example_category``.  The
-meaning of ``*`` in regular expression for entity names is 
diff erent - it is
-treated as in shell wildcarding. Two generic entity types are ``src`` and
+a tool-specific category, e.g. ``fun:*ExampleFunc=example_category``.
+Two generic entity types are ``src`` and
 ``fun``, which allow users to specify source files and functions, respectively.
 Some sanitizer tools may introduce custom entity types and categories - refer 
to
 tool-specific docs.
 
 .. code-block:: bash
 
+#!special-case-list-v2
+# The line above is explained in the note above
 # Lines starting with # are ignored.
-# Turn off checks for the source file (use absolute path or path relative
-# to the current working directory):
-src:/path/to/source/file.c
+# Turn off checks for the source file
+# Entries without sections are placed into [*] and apply to all sanitizers
+src:path/to/source/file.c
+src:*/source/file.c
 # Turn off checks for this main file, including files included by it.
 # Useful when the main file instead of an included file should be ignored.
 mainfile:file.c
 # Turn off checks for a particular functions (us

[PATCH] D154014: [SpecialCaseList] Add option to use Globs instead of Regex to match patterns

2023-09-01 Thread Ellis Hoag 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 rG8eb34700c2b1: [SpecialCaseList] Add option to use Globs 
instead of Regex to match patterns (authored by ellis).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154014

Files:
  clang/docs/SanitizerSpecialCaseList.rst
  clang/lib/Basic/ProfileList.cpp
  clang/lib/Basic/SanitizerSpecialCaseList.cpp
  llvm/include/llvm/Support/SpecialCaseList.h
  llvm/lib/Support/SpecialCaseList.cpp
  llvm/unittests/Support/SpecialCaseListTest.cpp

Index: llvm/unittests/Support/SpecialCaseListTest.cpp
===
--- llvm/unittests/Support/SpecialCaseListTest.cpp
+++ llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -10,8 +10,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+using testing::HasSubstr;
+using testing::StartsWith;
 using namespace llvm;
 
 namespace {
@@ -19,24 +22,32 @@
 class SpecialCaseListTest : public ::testing::Test {
 protected:
   std::unique_ptr makeSpecialCaseList(StringRef List,
-   std::string &Error) {
-std::unique_ptr MB = MemoryBuffer::getMemBuffer(List);
+   std::string &Error,
+   bool UseGlobs = true) {
+auto S = List.str();
+if (UseGlobs)
+  S = (Twine("#!special-case-list-v2\n") + S).str();
+std::unique_ptr MB = MemoryBuffer::getMemBuffer(S);
 return SpecialCaseList::create(MB.get(), Error);
   }
 
-  std::unique_ptr makeSpecialCaseList(StringRef List) {
+  std::unique_ptr makeSpecialCaseList(StringRef List,
+   bool UseGlobs = true) {
 std::string Error;
-auto SCL = makeSpecialCaseList(List, Error);
+auto SCL = makeSpecialCaseList(List, Error, UseGlobs);
 assert(SCL);
 assert(Error == "");
 return SCL;
   }
 
-  std::string makeSpecialCaseListFile(StringRef Contents) {
+  std::string makeSpecialCaseListFile(StringRef Contents,
+  bool UseGlobs = true) {
 int FD;
 SmallString<64> Path;
 sys::fs::createTemporaryFile("SpecialCaseListTest", "temp", FD, Path);
 raw_fd_ostream OF(FD, true, true);
+if (UseGlobs)
+  OF << "#!special-case-list-v2\n";
 OF << Contents;
 OF.close();
 return std::string(Path.str());
@@ -59,10 +70,10 @@
   EXPECT_FALSE(SCL->inSection("", "fun", "hello"));
   EXPECT_FALSE(SCL->inSection("", "src", "hello", "category"));
 
-  EXPECT_EQ(3u, SCL->inSectionBlame("", "src", "hello"));
-  EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "bye"));
-  EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "hi", "category"));
-  EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "", "category"));
+  EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "hello"));
+  EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "bye"));
+  EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "hi", "category"));
+  EXPECT_EQ(7u, SCL->inSectionBlame("", "src", "", "category"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hi"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "fun", "hello"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hello", "category"));
@@ -74,31 +85,31 @@
  "\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 3:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 4:"));
 
   EXPECT_EQ(nullptr, makeSpecialCaseList("\n\n\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 4:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 5:"));
 }
 
-TEST_F(SpecialCaseListTest, SectionRegexErrorHandling) {
+TEST_F(SpecialCaseListTest, SectionGlobErrorHandling) {
   std::string Error;
   EXPECT_EQ(makeSpecialCaseList("[address", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed section header "));
+  EXPECT_THAT(Error, StartsWith("malformed section header "));
 
   EXPECT_EQ(makeSpecialCaseList("[[]", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed regex for section [: "));
+  EXPECT_EQ(
+  Error,
+  "malformed section at line 2: '[': invalid glob pattern, unmatched '['");
 
   EXPECT_EQ(makeSpecialCaseList("src:=", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).endswith("Supplied regexp was blank"));
+  EXPECT_THAT(Error, HasSubstr("Supplied glob was bla

[PATCH] D159312: [Headers] Remove a space in NULL define

2023-09-01 Thread Rich Felker via Phabricator via cfe-commits
dalias added a comment.

Please report what you're actually trying to do that's breaking rather than 
sending patches to align definitions that are not intended to be aligned.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159312

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


[PATCH] D159352: [Driver] Don't default to DWARF 2 on Solaris

2023-09-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Looks great!




Comment at: clang/test/CodeGen/dwarf-version.c:7
 // RUN: %clang -target x86_64-linux-gnu -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
+// RUN: %clang -target i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VER5
+// RUN: %clang -target i386-pc-solaris -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5

Switch to `--target=` while moving lines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159352

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


[PATCH] D147219: [OpenMP][Flang][MLIR] Lowering of requires directive from MLIR to LLVM IR

2023-09-01 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan accepted this revision.
kiranchandramohan added a comment.
This revision is now accepted and ready to land.

LG.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147219

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


[clang] f93c271 - [Object] Change OffloadBinary::write to return SmallString<0>

2023-09-01 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-09-01T09:19:25-07:00
New Revision: f93c271d4cc11b865b87da1402e1cb33449fe4bf

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

LOG: [Object] Change OffloadBinary::write to return SmallString<0>

SmallString<0> is more flexible and avoids an unneeded copy in
ObjectYAML/OffloadEmitter.cpp.

Reviewed By: jhuber6

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

Added: 


Modified: 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
llvm/include/llvm/Object/OffloadBinary.h
llvm/lib/Object/OffloadBinary.cpp
llvm/lib/ObjectYAML/OffloadEmitter.cpp
llvm/unittests/Object/OffloadingTest.cpp

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index dcf23d538c7e331..432a34730f923c2 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -184,7 +184,8 @@ Expected getInputBitcodeLibrary(StringRef 
Input) {
   Image.StringData["arch"] = Arch;
   Image.Image = std::move(*ImageOrError);
 
-  std::unique_ptr Binary = OffloadBinary::write(Image);
+  std::unique_ptr Binary =
+  MemoryBuffer::getMemBufferCopy(OffloadBinary::write(Image));
   auto NewBinaryOrErr = OffloadBinary::create(*Binary);
   if (!NewBinaryOrErr)
 return NewBinaryOrErr.takeError();
@@ -909,7 +910,8 @@ Expected>>
 bundleOpenMP(ArrayRef Images) {
   SmallVector> Buffers;
   for (const OffloadingImage &Image : Images)
-Buffers.emplace_back(OffloadBinary::write(Image));
+Buffers.emplace_back(
+MemoryBuffer::getMemBufferCopy(OffloadBinary::write(Image)));
 
   return std::move(Buffers);
 }

diff  --git a/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp 
b/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
index 7100727015e7b7f..08de3f3a3771c12 100644
--- a/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
+++ b/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
@@ -126,11 +126,11 @@ static Error bundleImages() {
 ImageBinary.StringData[Key] = Value;
   }
 }
-std::unique_ptr Buffer = OffloadBinary::write(ImageBinary);
-if (Buffer->getBufferSize() % OffloadBinary::getAlignment() != 0)
+llvm::SmallString<0> Buffer = OffloadBinary::write(ImageBinary);
+if (Buffer.size() % OffloadBinary::getAlignment() != 0)
   return createStringError(inconvertibleErrorCode(),
"Offload binary has invalid size alignment");
-OS << Buffer->getBuffer();
+OS << Buffer;
   }
 
   if (Error E = writeFile(OutputFile,

diff  --git a/llvm/include/llvm/Object/OffloadBinary.h 
b/llvm/include/llvm/Object/OffloadBinary.h
index 320a8e1f6d8ff90..dda1e7f1eafbbae 100644
--- a/llvm/include/llvm/Object/OffloadBinary.h
+++ b/llvm/include/llvm/Object/OffloadBinary.h
@@ -18,6 +18,7 @@
 #define LLVM_OBJECT_OFFLOADBINARY_H
 
 #include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Object/Binary.h"
 #include "llvm/Support/Error.h"
@@ -78,7 +79,7 @@ class OffloadBinary : public Binary {
   static Expected> create(MemoryBufferRef);
 
   /// Serialize the contents of \p File to a binary buffer to be read later.
-  static std::unique_ptr write(const OffloadingImage &);
+  static SmallString<0> write(const OffloadingImage &);
 
   static uint64_t getAlignment() { return 8; }
 

diff  --git a/llvm/lib/Object/OffloadBinary.cpp 
b/llvm/lib/Object/OffloadBinary.cpp
index 342327daf7e4dea..1de784c44da10e8 100644
--- a/llvm/lib/Object/OffloadBinary.cpp
+++ b/llvm/lib/Object/OffloadBinary.cpp
@@ -204,8 +204,7 @@ OffloadBinary::create(MemoryBufferRef Buf) {
   new OffloadBinary(Buf, TheHeader, TheEntry));
 }
 
-std::unique_ptr
-OffloadBinary::write(const OffloadingImage &OffloadingData) {
+SmallString<0> OffloadBinary::write(const OffloadingImage &OffloadingData) {
   // Create a null-terminated string table with all the used strings.
   StringTableBuilder StrTab(StringTableBuilder::ELF);
   for (auto &KeyAndValue : OffloadingData.StringData) {
@@ -243,7 +242,7 @@ OffloadBinary::write(const OffloadingImage &OffloadingData) 
{
   TheEntry.ImageOffset = BinaryDataSize;
   TheEntry.ImageSize = OffloadingData.Image->getBufferSize();
 
-  SmallVector Data;
+  SmallString<0> Data;
   Data.reserve(TheHeader.Size);
   raw_svector_ostream OS(Data);
   OS << StringRef(reinterpret_cast(&TheHeader), sizeof(Header));
@@ -264,7 +263,7 @@ OffloadBinary::write(const OffloadingImage &OffloadingData) 
{
   OS.write_zeros(TheHeader.Size - OS.tell());
   assert(TheHeader.Size == OS.tell() && "Size mismatch");
 
-  return Me

[PATCH] D159335: [Object] Change OffloadBinary::write to return SmallString<0>

2023-09-01 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf93c271d4cc1: [Object] Change OffloadBinary::write to return 
SmallString<0> (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159335

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
  llvm/include/llvm/Object/OffloadBinary.h
  llvm/lib/Object/OffloadBinary.cpp
  llvm/lib/ObjectYAML/OffloadEmitter.cpp
  llvm/unittests/Object/OffloadingTest.cpp

Index: llvm/unittests/Object/OffloadingTest.cpp
===
--- llvm/unittests/Object/OffloadingTest.cpp
+++ llvm/unittests/Object/OffloadingTest.cpp
@@ -43,8 +43,8 @@
   Data.StringData = StringData;
   Data.Image = std::move(ImageData);
 
-  auto BinaryBuffer = OffloadBinary::write(Data);
-
+  auto BinaryBuffer =
+  MemoryBuffer::getMemBufferCopy(OffloadBinary::write(Data));
   auto BinaryOrErr = OffloadBinary::create(*BinaryBuffer);
   if (!BinaryOrErr)
 FAIL();
Index: llvm/lib/ObjectYAML/OffloadEmitter.cpp
===
--- llvm/lib/ObjectYAML/OffloadEmitter.cpp
+++ llvm/lib/ObjectYAML/OffloadEmitter.cpp
@@ -38,14 +38,10 @@
   Member.Content->writeAsBinary(OS);
 Image.Image = MemoryBuffer::getMemBufferCopy(OS.str());
 
-std::unique_ptr Binary = object::OffloadBinary::write(Image);
-
 // Copy the data to a new buffer so we can modify the bytes directly.
-SmallVector NewBuffer;
-std::copy(Binary->getBufferStart(), Binary->getBufferEnd(),
-  std::back_inserter(NewBuffer));
+auto Buffer = object::OffloadBinary::write(Image);
 auto *TheHeader =
-reinterpret_cast(&NewBuffer[0]);
+reinterpret_cast(&Buffer[0]);
 if (Doc.Version)
   TheHeader->Version = *Doc.Version;
 if (Doc.Size)
@@ -55,7 +51,7 @@
 if (Doc.EntrySize)
   TheHeader->EntrySize = *Doc.EntrySize;
 
-Out.write(NewBuffer.begin(), NewBuffer.size());
+Out.write(Buffer.begin(), Buffer.size());
   }
 
   return true;
Index: llvm/lib/Object/OffloadBinary.cpp
===
--- llvm/lib/Object/OffloadBinary.cpp
+++ llvm/lib/Object/OffloadBinary.cpp
@@ -204,8 +204,7 @@
   new OffloadBinary(Buf, TheHeader, TheEntry));
 }
 
-std::unique_ptr
-OffloadBinary::write(const OffloadingImage &OffloadingData) {
+SmallString<0> OffloadBinary::write(const OffloadingImage &OffloadingData) {
   // Create a null-terminated string table with all the used strings.
   StringTableBuilder StrTab(StringTableBuilder::ELF);
   for (auto &KeyAndValue : OffloadingData.StringData) {
@@ -243,7 +242,7 @@
   TheEntry.ImageOffset = BinaryDataSize;
   TheEntry.ImageSize = OffloadingData.Image->getBufferSize();
 
-  SmallVector Data;
+  SmallString<0> Data;
   Data.reserve(TheHeader.Size);
   raw_svector_ostream OS(Data);
   OS << StringRef(reinterpret_cast(&TheHeader), sizeof(Header));
@@ -264,7 +263,7 @@
   OS.write_zeros(TheHeader.Size - OS.tell());
   assert(TheHeader.Size == OS.tell() && "Size mismatch");
 
-  return MemoryBuffer::getMemBufferCopy(OS.str());
+  return Data;
 }
 
 Error object::extractOffloadBinaries(MemoryBufferRef Buffer,
Index: llvm/include/llvm/Object/OffloadBinary.h
===
--- llvm/include/llvm/Object/OffloadBinary.h
+++ llvm/include/llvm/Object/OffloadBinary.h
@@ -18,6 +18,7 @@
 #define LLVM_OBJECT_OFFLOADBINARY_H
 
 #include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Object/Binary.h"
 #include "llvm/Support/Error.h"
@@ -78,7 +79,7 @@
   static Expected> create(MemoryBufferRef);
 
   /// Serialize the contents of \p File to a binary buffer to be read later.
-  static std::unique_ptr write(const OffloadingImage &);
+  static SmallString<0> write(const OffloadingImage &);
 
   static uint64_t getAlignment() { return 8; }
 
Index: clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
===
--- clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
+++ clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
@@ -126,11 +126,11 @@
 ImageBinary.StringData[Key] = Value;
   }
 }
-std::unique_ptr Buffer = OffloadBinary::write(ImageBinary);
-if (Buffer->getBufferSize() % OffloadBinary::getAlignment() != 0)
+llvm::SmallString<0> Buffer = OffloadBinary::write(ImageBinary);
+if (Buffer.size() % OffloadBinary::getAlignment() != 0)
   return createStringError(inconvertibleErrorCode(),
"Offload binary has invalid size alignment");
-OS << Buffer->getBuffer();
+OS << Buffer;
   }
 
   if (Error E = writeFile(OutputFile,
Index: clang/tool

[PATCH] D157385: [clang][CFG] Cleanup functions

2023-09-01 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

In D157385#4634591 , @tbaeder wrote:

> @steakhal Double lifetime ends should be fixed now.

I haven't verified, but it should be good now.


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

https://reviews.llvm.org/D157385

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


[PATCH] D159250: [X86][RFC] Add new option `-m[no-]evex512` to disable ZMM and 64-bit mask instructions for AVX512 features

2023-09-01 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In D159250#4633530 , @pengfei wrote:

> In D159250#4631786 , @RKSimon wrote:
>
>> Would it be possible to add function multiversioning tests to ensure the 
>> evex512 attribute would work with it?
>
> Function multiversioning is orthogonal to evex512 feature.
>
> When user uses `-mno-evex512` in command line, all the code generation, 
> including function multiversioning are limited to 256-bit vector and 32-bit 
> mask.
>
> User is not suggested to use `avx512xxx,evex512` in function attributes for 
> function multiversioning, because EVEX512 is a software concept and the 
> dispatcher cannot distinguish between `avx512xxx` and `avx512xxx,evex512`.

If the dispatcher is updated to take into account AVX10.1 CPUID, it could 
distinguish the different hardware support.

That is:

- to check for AVX512xxx with evex512 //enabled//, the dispatcher need only 
check for the AVX512xxx CPUID bit, since according to the doc, a CPU which 
implements AVX10.1 with 512-bit register size will also set the corresponding 
AVX512 CPUID bits. No change there.
- to check for AVX512xxx with evex512 //disabled//, the dispatcher function 
should check that either CPUID reports the AVX512xxx bit OR that the CPUID 
reports AVX10.1 with support for at least 256-bit register size. (But only for 
the 'AVX512xxx' features which are actually included in AVX10.1, of course).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159250

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


[PATCH] D159363: [clangd] SIGSEGV at clangd: DiagnosticConsumer Is Used After Free

2023-09-01 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko updated this revision to Diff 555441.
ivanmurashko marked an inline comment as done.
ivanmurashko added a comment.

@sammccall's comment was addressed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159363

Files:
  clang-tools-extra/clangd/Preamble.cpp


Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -665,6 +665,10 @@
   Stats ? TimedFS : StatCacheFS, 
std::make_shared(),
   StoreInMemory, /*StoragePath=*/"", CapturedInfo);
   PreambleTimer.stopTimer();
+
+  // We have to setup DiagnosticConsumer that will be alife
+  // while preamble callback is executed
+  PreambleDiagsEngine->setClient(new IgnoringDiagConsumer, true);
   // Reset references to ref-counted-ptrs before executing the callbacks, to
   // prevent resetting them concurrently.
   PreambleDiagsEngine.reset();
@@ -706,6 +710,7 @@
   // While extending the life of FileMgr and VFS, StatCache should also be
   // extended.
   Ctx->setStatCache(Result->StatCache);
+
   PreambleCallback(std::move(*Ctx), Result->Pragmas);
 }
 return Result;


Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -665,6 +665,10 @@
   Stats ? TimedFS : StatCacheFS, std::make_shared(),
   StoreInMemory, /*StoragePath=*/"", CapturedInfo);
   PreambleTimer.stopTimer();
+
+  // We have to setup DiagnosticConsumer that will be alife
+  // while preamble callback is executed
+  PreambleDiagsEngine->setClient(new IgnoringDiagConsumer, true);
   // Reset references to ref-counted-ptrs before executing the callbacks, to
   // prevent resetting them concurrently.
   PreambleDiagsEngine.reset();
@@ -706,6 +710,7 @@
   // While extending the life of FileMgr and VFS, StatCache should also be
   // extended.
   Ctx->setStatCache(Result->StatCache);
+
   PreambleCallback(std::move(*Ctx), Result->Pragmas);
 }
 return Result;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159363: [clangd] SIGSEGV at clangd: DiagnosticConsumer Is Used After Free

2023-09-01 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko added inline comments.



Comment at: clang-tools-extra/clangd/Preamble.cpp:709
   Ctx->setStatCache(Result->StatCache);
+  // We have to setup DiagnosticConsumer that will be alife
+  // while preamble callback is executed

sammccall wrote:
> I think this should go up next to PreambleDiagsEngine.reset() etc, as it's 
> basically the same thing: we're trying to avoid any race between the async 
> work done by the callback and the cleanup at the end of the function.
> 
> Also I think it's slightly clearer for us to consistently be taking the 
> diagnostics from PreambleDiagnostics *after* it's detached from the compiler.
I applied the change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159363

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


[PATCH] D74094: Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas

2023-09-01 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In D74094#4633785 , @alexfh wrote:

> This commit caused invalid AddressSanitizer: stack-use-after-scope errors in 
> our internal setup. Trying to create a standalone repro, but so far we think 
> that the patch is incorrect. @vitalybuka says "The patch seems wrong, callee 
> can return a reference to temp, so lifetime should be extended to full 
> expression."

I will lazily quote https://en.cppreference.com/w/cpp/language/lifetime, we can 
lookup the standard, all ask experts, if this is wrong:

  All temporary objects are destroyed as the last step in evaluating the 
full-expression that (lexically) contains the point where they were created, 
and if multiple temporary objects were created, they are destroyed in the order 
opposite to the order of creation. This is true even if that evaluation ends in 
throwing an exception.

And full-expression here is:

  const Tensor t3 = round(a.log().exp());




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74094

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


[PATCH] D159352: [Driver] Don't default to DWARF 2 on Solaris

2023-09-01 Thread Rainer Orth via Phabricator via cfe-commits
ro marked an inline comment as done.
ro added inline comments.



Comment at: clang/test/CodeGen/dwarf-version.c:7
 // RUN: %clang -target x86_64-linux-gnu -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
+// RUN: %clang -target i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VER5
+// RUN: %clang -target i386-pc-solaris -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5

MaskRay wrote:
> Switch to `--target=` while moving lines.
Two questions:
- Wouldn't it be better to keep the style consistent across a file, rather than 
introduce a mix?
- I guess it's ok to just commit the patch with such a slight revision without 
re-uploading it to Phabricator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159352

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


[clang] b1b1f36 - [Driver] Don't default to DWARF 2 on Solaris

2023-09-01 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2023-09-01T20:02:37+02:00
New Revision: b1b1f364d63382637fa5f64871ee06bf74bd0405

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

LOG: [Driver] Don't default to DWARF 2 on Solaris

`clang` currently defaults to DWARF 2 on Solaris.  This dates back to LLVM
3.8.0.  I suspect this is related to `gcc/config/sol2.cc`
(`solaris_override_options`) doing the same unless
`HAVE_LD_EH_FRAME_CIEV3`.  The latter is 1 on both Solaris 11.3 and 11.4,
so the workaround has become irrelevant these days.

This patch removes the Solaris override, adjusting affected testcases
accordingly.

Tested on `amd64-pc-solaris2.11` (`Release` and `Debug` builds) and
`sparcv9-sun-solaris2.11` (`Release` build).

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Solaris.h
clang/test/CodeGen/dwarf-version.c
clang/test/Driver/clang-g-opts.c
clang/test/Driver/debug-options.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Solaris.h 
b/clang/lib/Driver/ToolChains/Solaris.h
index fbac92c2c0f31c..9023bf7c37c522 100644
--- a/clang/lib/Driver/ToolChains/Solaris.h
+++ b/clang/lib/Driver/ToolChains/Solaris.h
@@ -63,7 +63,6 @@ class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_ELF {
llvm::opt::ArgStringList &CC1Args) const override;
 
   SanitizerMask getSupportedSanitizers() const override;
-  unsigned GetDefaultDwarfVersion() const override { return 2; }
 
   const char *getDefaultLinker() const override {
 // clang currently uses Solaris ld-only options.

diff  --git a/clang/test/CodeGen/dwarf-version.c 
b/clang/test/CodeGen/dwarf-version.c
index d307eb3f101f8f..850cedf4d14c76 100644
--- a/clang/test/CodeGen/dwarf-version.c
+++ b/clang/test/CodeGen/dwarf-version.c
@@ -4,6 +4,8 @@
 // RUN: %clang -target x86_64-linux-gnu -gdwarf-5 -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
 // RUN: %clang -target x86_64-linux-gnu -g -S -emit-llvm -o - %s | FileCheck 
%s --check-prefix=VER5
 // RUN: %clang -target x86_64-linux-gnu -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
+// RUN: %clang --target=i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck 
%s --check-prefix=VER5
+// RUN: %clang --target=i386-pc-solaris -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
 
 // The -isysroot is used as a hack to avoid LIT messing with the SDKROOT
 // environment variable which indirecty overrides the version in the target
@@ -13,8 +15,6 @@
 
 // RUN: %clang -target powerpc-unknown-openbsd -g -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER2
 // RUN: %clang -target powerpc-unknown-freebsd -g -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER4
-// RUN: %clang -target i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VER2
-// RUN: %clang -target i386-pc-solaris -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER2
 
 // Check which debug info formats we use on Windows. By default, in an MSVC
 // environment, we should use codeview. You can enable dwarf, which implicitly

diff  --git a/clang/test/Driver/clang-g-opts.c 
b/clang/test/Driver/clang-g-opts.c
index 5ee0fe64fe484f..4882eb6068f436 100644
--- a/clang/test/Driver/clang-g-opts.c
+++ b/clang/test/Driver/clang-g-opts.c
@@ -27,8 +27,8 @@
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
 // RUN: %clang -### -S %s -g0 -g -target x86_64-pc-freebsd10.0 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
-// RUN: %clang -### -S %s -g0 -g -target i386-pc-solaris 2>&1 \
-// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: %clang -### -S %s -g0 -g --target=i386-pc-solaris 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G %s
 
 // CHECK-WITHOUT-G-NOT: -debug-info-kind
 // CHECK-WITH-G: "-debug-info-kind=constructor"

diff  --git a/clang/test/Driver/debug-options.c 
b/clang/test/Driver/debug-options.c
index 4dbd7be10982e3..8ffa88d00dff37 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -193,8 +193,8 @@
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-pc-freebsd10.0 
2>&1 \
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
-// RUN: %clang -### -c -gline-tables-only -g %s -target i386-pc-solaris 2>&1 \
-// RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
+// RUN: %clang -### -c -gline-tables-only -g %s --target=i386-pc-solaris 2>&1 \
+// RUN: | FileCheck -check-prefix=G_ONLY %s
 // RUN: %clang -### -c -gline-tables-only -g0 %s 2>&1 \
 // RUN: | FileCheck -check-prefix=GLTO_NO %s
 //
@@ -212,8 +212,8 @@
 // RUN:

[PATCH] D159352: [Driver] Don't default to DWARF 2 on Solaris

2023-09-01 Thread Rainer Orth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
ro marked an inline comment as done.
Closed by commit rGb1b1f364d633: [Driver] Don't default to DWARF 2 on 
Solaris (authored by ro).

Changed prior to commit:
  https://reviews.llvm.org/D159352?vs=555335&id=555443#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159352

Files:
  clang/lib/Driver/ToolChains/Solaris.h
  clang/test/CodeGen/dwarf-version.c
  clang/test/Driver/clang-g-opts.c
  clang/test/Driver/debug-options.c


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -193,8 +193,8 @@
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-pc-freebsd10.0 
2>&1 \
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
-// RUN: %clang -### -c -gline-tables-only -g %s -target i386-pc-solaris 2>&1 \
-// RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
+// RUN: %clang -### -c -gline-tables-only -g %s --target=i386-pc-solaris 2>&1 \
+// RUN: | FileCheck -check-prefix=G_ONLY %s
 // RUN: %clang -### -c -gline-tables-only -g0 %s 2>&1 \
 // RUN: | FileCheck -check-prefix=GLTO_NO %s
 //
@@ -212,8 +212,8 @@
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-directives-only -g %s -target 
x86_64-pc-freebsd10.0 2>&1 \
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
-// RUN: %clang -### -c -gline-directives-only -g %s -target i386-pc-solaris 
2>&1 \
-// RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
+// RUN: %clang -### -c -gline-directives-only -g %s --target=i386-pc-solaris 
2>&1 \
+// RUN: | FileCheck -check-prefix=G_ONLY %s
 // RUN: %clang -### -c -gline-directives-only -g0 %s 2>&1 \
 // RUN: | FileCheck -check-prefix=GLIO_NO %s
 
Index: clang/test/Driver/clang-g-opts.c
===
--- clang/test/Driver/clang-g-opts.c
+++ clang/test/Driver/clang-g-opts.c
@@ -27,8 +27,8 @@
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
 // RUN: %clang -### -S %s -g0 -g -target x86_64-pc-freebsd10.0 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
-// RUN: %clang -### -S %s -g0 -g -target i386-pc-solaris 2>&1 \
-// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: %clang -### -S %s -g0 -g --target=i386-pc-solaris 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G %s
 
 // CHECK-WITHOUT-G-NOT: -debug-info-kind
 // CHECK-WITH-G: "-debug-info-kind=constructor"
Index: clang/test/CodeGen/dwarf-version.c
===
--- clang/test/CodeGen/dwarf-version.c
+++ clang/test/CodeGen/dwarf-version.c
@@ -4,6 +4,8 @@
 // RUN: %clang -target x86_64-linux-gnu -gdwarf-5 -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
 // RUN: %clang -target x86_64-linux-gnu -g -S -emit-llvm -o - %s | FileCheck 
%s --check-prefix=VER5
 // RUN: %clang -target x86_64-linux-gnu -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
+// RUN: %clang --target=i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck 
%s --check-prefix=VER5
+// RUN: %clang --target=i386-pc-solaris -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER5
 
 // The -isysroot is used as a hack to avoid LIT messing with the SDKROOT
 // environment variable which indirecty overrides the version in the target
@@ -13,8 +15,6 @@
 
 // RUN: %clang -target powerpc-unknown-openbsd -g -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER2
 // RUN: %clang -target powerpc-unknown-freebsd -g -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER4
-// RUN: %clang -target i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VER2
-// RUN: %clang -target i386-pc-solaris -gdwarf -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER2
 
 // Check which debug info formats we use on Windows. By default, in an MSVC
 // environment, we should use codeview. You can enable dwarf, which implicitly
Index: clang/lib/Driver/ToolChains/Solaris.h
===
--- clang/lib/Driver/ToolChains/Solaris.h
+++ clang/lib/Driver/ToolChains/Solaris.h
@@ -63,7 +63,6 @@
llvm::opt::ArgStringList &CC1Args) const override;
 
   SanitizerMask getSupportedSanitizers() const override;
-  unsigned GetDefaultDwarfVersion() const override { return 2; }
 
   const char *getDefaultLinker() const override {
 // clang currently uses Solaris ld-only options.


Index: clang/test/Driver/debug-options.c
=

[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-01 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

In D157913#4626007 , @zequanwu wrote:

>> It seems that the `__llvm_prf_names` is retained in this mode. What is the 
>> overhead of this section generally? Can we instead use debug info to lookup 
>> function names?
>
> With debug info correlation enabled, `__llvm_prf_names` section will only 
> contain functions names that are not emitted to the final binary, not even in 
> debug info. So, this section is still much smaller compared to when not 
> enabling debug info correlation. This is used to indicate that those 
> functions are covered but not executed.
>
> Example from the test case above:
>
>   $ cat a.cpp
>   struct A {
> void unused_func() {}
>   };
>   void used_func() {}
>   int main() {
> used_func();
> return 0;
>   }
>   $ clang -fprofile-instr-generate -fcoverage-mapping -mllvm 
> -enable-name-compression=false -mllvm -debug-info-correlate -g a.cpp -o a.out
>   $ llvm-objdump --section=__llvm_prf_names --full-contents a.out
>   
>   a.out:  file format elf64-x86-64
>   Contents of section __llvm_prf_names:
>7b65 14005f5a 4e314131 31756e75 7365645f  .._ZN1A11unused_
>7b75 66756e63 4576funcEv

Thanks for the explanation!




Comment at: clang/test/CodeGen/coverage-debug-info-correlate.c:1
+// RUN: %clang_cc1 -debug-info-kind=standalone -mllvm -debug-info-correlate 
-fprofile-instrument=clang -fcoverage-mapping -emit-llvm -o - %s | FileCheck %s
+

I think this test can be generalized to check that `__llvm_profile_raw_version` 
is emitted with or without debug info correlation.



Comment at: compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.cpp:9
+// RUN: %clang_profgen -o %t -g -mllvm --debug-info-correlate 
-fcoverage-mapping %S/../Inputs/instrprof-debug-info-correlate-main.cpp 
%S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t.dSYM %t.profraw

NIT



Comment at: compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.cpp:29
+
+// RUN: llvm-cov report --instr-profile=%t.profdata %t | FileCheck %s 
-check-prefix=NONAME
+

Is it worth testing that `%t.normal.profdata` emits the same coverage?



Comment at: llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp:1019-1029
+  if (auto E = NamesSection.takeError()) {
+if (ProfileNames.isEmpty())
+  return std::move(E);
+consumeError(std::move(E));
+  } else {
+std::vector NamesSectionRefs = *NamesSection;
+if (NamesSectionRefs.size() != 1)

I don't quite understand why this was changed. Is there is a test case that 
covers this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157913

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


[PATCH] D74094: Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas

2023-09-01 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Parameter objects are not temporaries and have their own lifetime rules, so 
there's nothing wrong with this idea in principle.  This seems to just be a 
bug, probably that we're doing a type check on `E->getType()` without 
considering whether E might be a gl-value.  We definitely do not want to be 
emitting lifetime intrinsics for the referent of a reference argument just 
because the underlying type is an aggregate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74094

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


[PATCH] D159339: [urgent][CodeGen] First check the kind and then the llvm::Function properties.

2023-09-01 Thread David Tenty via Phabricator via cfe-commits
daltenty added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2389
   if (getTarget().getCXXABI().areMemberFunctionsAligned()) {
-if (F->getPointerAlignment(getDataLayout()) < 2 && isa(D))
+if (isa(D) && F->getPointerAlignment(getDataLayout()) < 2)
   F->setAlignment(std::max(llvm::Align(2), F->getAlign().valueOrOne()));

Thanks for looking into this. 

It's not clear to me how this re-ordering ends up fixing things. Can you 
clarify what the uninitialized value was in this expression?




Repository:
  rC Clang

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

https://reviews.llvm.org/D159339

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


[PATCH] D85309: [Driver] Support GNU ld on Solaris

2023-09-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: clang/lib/Driver/ToolChains/Solaris.cpp:55
+  StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER;
+  // FIXME: What about -fuse-ld=?
+  return UseLinker == "bfd" || UseLinker == "gld";

`-fuse-ld=` is deprecated by `--ld-path=`. So just drop this FIXME.



Comment at: clang/lib/Driver/ToolChains/Solaris.cpp:84
+// FIXME: Could also use /usr/bin/gld here.
+return std::string("/usr/gnu/bin/ld");
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85309

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


[PATCH] D158566: Add CLANGD_INCLUDE_TESTS as a separate flag to control clangd tests

2023-09-01 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya added a comment.

In D158566#4633847 , @kadircet wrote:

> In D158566#4616417 , @ilya-biryukov 
> wrote:
>
>> Open question: I also feel like the best option here is to fix the tests, 
>> but I'm not sure how hard that would be. @sammccall any thoughts?
>> I suspect the particular tests are flaky is because they rely on timeouts, 
>> not sure it's easy to disentangle them. Therefore, some workaround seems 
>> reasonable
>
> FWIW, i've put some details in 
> https://github.com/llvm/llvm-project/issues/64964#issuecomment-1702249740 and 
> we had some previous discussions but unfortunately these tests have timeouts 
> as a "poor-mans-deadlock-detection". i don't think we can get rid of the 
> timeouts, without sacrificing that detection.
> I can't remember how misleading buildbot outputs were, when deadlocks 
> happened, before we introduced timeouts though. So one alternative is let the 
> buildbots hang instead.
>
> ---
>
> Regarding the approach in this patch, I don't feel strongly about it but I 
> don't think it's a good idea to let people build clangd, without testing it 
> on environments they care about. They might suppress legitimate issues. 
> (there's also some value though, e.g. maybe they already performed testing 
> before, and don't want to run tests again, but in such a scenario we've 
> non-check equivalents of targets to only run builds).

This option only allows more flexibility to the developers and by default it is 
on so anyone who doesn't care about switching off the test on constrained 
systems can continue to do so. Do you have specific concerns on why this will 
prevent developers from testing?

> Are you building clangd deliberately or is it just being pulled in via 
> check-clang-tools? If you don't want to ship clangd with your toolchain at 
> all, I think it's better to set `CLANG_ENABLE_CLANGD` to `OFF`.

We want to build clangd and it gets tested on a regular basis but the timeout 
happens on mac builds that are overloaded at times. I don't want to disable the 
build of clangd just because 1 test is failing.


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

https://reviews.llvm.org/D158566

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


[PATCH] D159338: [clangd][tests] Bump timeouts in TUSchedulerTests to 60 secs

2023-09-01 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya added a comment.

not sure if this is the right way to fix these tests. The problem is if a 
device is constraiend, this will further slow down the device and create more 
backlogs. Can we allow a way to skip these tests based on a flag/environment 
variable?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159338

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


[PATCH] D155769: [HIP][Clang][docs][RFC] Add documentation for C++ Parallel Algorithm Offload

2023-09-01 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx updated this revision to Diff 555450.
AlexVlx added a reviewer: JonChesterfield.
AlexVlx added a comment.

Correctly reflect AMDGPU-only nature of the extension.


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

https://reviews.llvm.org/D155769

Files:
  clang/docs/HIPSupport.rst
  clang/docs/ReleaseNotes.rst

Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -311,6 +311,11 @@
 CUDA/HIP Language Changes
 ^
 
+- [HIP Only] add experimental support for offloading select C++ Algorithms,
+  which can be toggled via the ``-hipstdpar`` flag. This is available only for
+  the AMDGPU target at the moment. See the dedicated entry in the `HIP Language
+  support document for details `_
+
 CUDA Support
 
 
Index: clang/docs/HIPSupport.rst
===
--- clang/docs/HIPSupport.rst
+++ clang/docs/HIPSupport.rst
@@ -176,3 +176,391 @@
* - ``HIP_API_PER_THREAD_DEFAULT_STREAM``
  - Alias to ``__HIP_API_PER_THREAD_DEFAULT_STREAM__``. Deprecated.
 
+C++ Standard Parallelism Offload Support: Compiler And Runtime
+==
+
+Introduction
+
+
+This document describes the implementation of support for offloading the
+execution of standard C++ algorithms to accelerators that can be targeted via
+HIP. Furthermore, it enumerates restrictions on user defined code, as well as
+the interactions with runtimes.
+
+Algorithm Offload: What, Why, Where
+===
+
+C++17 introduced overloads
+`for most algorithms in the standard library `_
+which allow the user to specify a desired
+`execution policy `_.
+The `parallel_unsequenced_policy `_
+maps relatively well to the execution model of many accelerators, such as GPUs.
+This, coupled with the ubiquity of GPU accelerated algorithm libraries that
+implement most / all corresponding libraries in the standard library
+(e.g. `rocThrust `_), makes
+it feasible to provide seamless accelerator offload for supported algorithms,
+when an accelerated version exists. Thus, it becomes possible to easily access
+the computational resources of an accelerator, via a well specified, familiar,
+algorithmic interface, without having to delve into low-level hardware specific
+details. Putting it all together:
+
+- **What**: standard library algorithms, when invoked with the
+  ``parallel_unsequenced_policy``
+- **Why**: democratise accelerator programming, without loss of user familiarity
+- **Where**: only AMDGPU accelerators targeted by Clang/LLVM via HIP
+
+Small Example
+=
+
+Given the following C++ code, which assumes the ``std`` namespace is included:
+
+.. code-block:: C++
+
+   bool has_the_answer(const vector& v) {
+ return find(execution::par_unseq, cbegin(v), cend(v), 42) != cend(v);
+   }
+
+if Clang is invoked with the ``-hipstdpar --offload-arch=foo`` flags, the call
+to ``find`` will be offloaded to an accelerator that is part of the ``foo``
+target family. If either ``foo`` or its runtime environment do not support
+transparent on-demand paging (such as e.g. that provided in Linux via
+`HMM `_), it is necessary to also include
+the ``--hipstdpar-interpose-alloc`` flag. If the accelerator specific algorithm
+library ``foo`` uses doesn't have an implementation of a particular algorithm,
+execution seamlessly falls back to the host CPU. It is legal to specify multiple
+``--offload-arch``s. All the flags we introduce, as well as a thorough view of
+various restrictions and their implications will be provided below.
+
+Implementation - General View
+=
+
+We built support for Algorithm Offload support atop the pre-existing HIP
+infrastructure. More specifically, when one requests offload via ``-hipstdpar``,
+compilation is switched to HIP compilation, as if ``-x hip`` was specified.
+Similarly, linking is also switched to HIP linking, as if ``--hip-link`` was
+specified. Note that these are implicit, and one should not assume that any
+interop with HIP specific language constructs is available e.g. ``__device__``
+annotations are neither necessary nor guaranteed to work.
+
+Since there are no language restriction mechanisms in place, it is necessary to
+relax HIP language specific semantic checks performed by the FE; they would
+identify otherwise valid, offloadable code, as invalid HIP code. Given that we
+know that the user intended only for certain algorithms to be offloaded, and
+encoded

[PATCH] D159103: [Driver][HLSL] Improve diagnostics for invalid shader model and stage

2023-09-01 Thread Justin Bogner via Phabricator via cfe-commits
bogner updated this revision to Diff 555451.
bogner added a comment.

- Consolidate error messages
- Error messages should start with a lower case letter


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159103

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Driver/hlsl-lang-targets.hlsl
  llvm/include/llvm/TargetParser/Triple.h

Index: llvm/include/llvm/TargetParser/Triple.h
===
--- llvm/include/llvm/TargetParser/Triple.h
+++ llvm/include/llvm/TargetParser/Triple.h
@@ -270,7 +270,9 @@
 Callable,
 Mesh,
 Amplification,
+
 OpenHOS,
+
 LastEnvironmentType = OpenHOS
   };
   enum ObjectFormatType {
@@ -755,6 +757,22 @@
 return getArch() == Triple::dxil;
   }
 
+  bool isShaderModelOS() const {
+return getOS() == Triple::ShaderModel;
+  }
+
+  bool isShaderStageEnvironment() const {
+EnvironmentType Env = getEnvironment();
+return Env == Triple::Pixel || Env == Triple::Vertex ||
+   Env == Triple::Geometry || Env == Triple::Hull ||
+   Env == Triple::Domain || Env == Triple::Compute ||
+   Env == Triple::Library || Env == Triple::RayGeneration ||
+   Env == Triple::Intersection || Env == Triple::AnyHit ||
+   Env == Triple::ClosestHit || Env == Triple::Miss ||
+   Env == Triple::Callable || Env == Triple::Mesh ||
+   Env == Triple::Amplification;
+  }
+
   /// Tests whether the target is SPIR (32- or 64-bit).
   bool isSPIR() const {
 return getArch() == Triple::spir || getArch() == Triple::spir64;
Index: clang/test/Driver/hlsl-lang-targets.hlsl
===
--- clang/test/Driver/hlsl-lang-targets.hlsl
+++ clang/test/Driver/hlsl-lang-targets.hlsl
@@ -1,14 +1,52 @@
-// RUN: not %clang -target x86_64-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=X86
-// RUN: not %clang -target dxil-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=DXIL
-// RUN: not %clang -target x86_64-unknown-shadermodel %s 2>&1 | FileCheck %s --check-prefix=SM
-// RUN: not %clang -target spirv64-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=SPIRV
+// Supported targets
+//
+// RUN: %clang -target dxil--shadermodel6.2-pixel %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-pixel %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil--shadermodel6.2-library %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-library %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
 
+// Empty shader model
+//
+// RUN: not %clang -target dxil %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-NO-OS %s
 
-// A completely unsupported target...
-// X86: error: HLSL code generation is unsupported for target 'x86_64-unknown-unknown'
+// Invalid shader models
+//
+// RUN: not %clang -target dxil--linux %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s
+// RUN: not %clang -target dxil--win32 %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s
+// RUN: not %clang -target dxil--unknown %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s
+// RUN: not %clang -target dxil--invalidos %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s
 
-// Poorly specified targets
-// DXIL: error: HLSL code generation is unsupported for target 'dxil-unknown-unknown'
-// SM: error: HLSL code generation is unsupported for target 'x86_64-unknown-shadermodel'
+// Bad shader model versions. Currently we just check for any version at all.
+//
+// RUN: not %clang -target dxil--shadermodel %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s
+// RUN: not %clang -target dxil--shadermodel0.0 %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s
 
-// FIXME// SPIRV: error: HLSL code generation is unsupported for target 'spirv64-unknown-unknown'
+// Empty shader stage
+//
+// RUN: not %clang -target dxil-shadermodel6.2 %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-NO-ENV %s
+// RUN: not %clang -target dxil--shadermodel6.2 %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-NO-ENV %s
+// RUN: not %clang -target dxil--shadermodel6.2 %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-NO-ENV %s
+
+// Invalid shader stages
+//
+// RUN: not %clang -target dxil--shadermodel6.2-unknown %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-ENV %s
+// RUN: not %clang -target dxil--shadermodel6.2-invalidenvironment %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-ENV %s
+// RUN: not %clang -target dxil--shadermodel6.2-eabi %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD

[clang] [APINotes] Remove unused OS-availability feature (PR #65178)

2023-09-01 Thread Egor Zhdan via cfe-commits

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


[clang] [APINotes] Remove unused OS-availability feature (PR #65178)

2023-09-01 Thread Egor Zhdan via cfe-commits

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


[clang] [APINotes] Remove unused OS-availability feature (PR #65178)

2023-09-01 Thread Egor Zhdan via cfe-commits

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


[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-01 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

Ah, the tests are failing because some of them are putting the builtin headers 
in other modules. This is going to need the "optionally ignore the builtin 
modules" change first then. I almost have that one finished.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159064

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


  1   2   3   >