[clang] [clang][analyzer] PutenvStackArrayChecker: No warning from 'main' (PR #93299)

2024-05-24 Thread via cfe-commits

llvmbot wrote:




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

Author: Balázs Kéri (balazske)


Changes



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


3 Files Affected:

- (modified) clang/docs/analyzer/checkers.rst (+10) 
- (modified) clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp 
(+7-2) 
- (modified) clang/test/Analysis/putenv-stack-array.c (+20) 


``diff
diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index ac9f0b06f63ba..3a31708a1e9de 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2858,6 +2858,16 @@ The check corresponds to CERT rule
 return putenv(env); // putenv function should not be called with 
stack-allocated string
   }
 
+There is one case where the checker can report a false positive. This is when
+the stack-allocated array is used at `putenv` in a function or code branch that
+does not return (calls `fork` or `exec` like function).
+
+Another special case is if the `putenv` is called from function `main`. Here
+the stack is deallocated at the end of the program and it should be no problem
+to use the stack-allocated string (a multi-threaded program may require more
+attention). The checker does not warn for cases when stack space of `main` is
+used at the `putenv` call.
+
 .. _alpha-security-ReturnPtrRange:
 
 alpha.security.ReturnPtrRange (C)
diff --git a/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
index d59cebf0aa5cb..bf81d57bf82fd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
@@ -44,9 +44,14 @@ void PutenvStackArrayChecker::checkPostCall(const CallEvent 
,
 
   SVal ArgV = Call.getArgSVal(0);
   const Expr *ArgExpr = Call.getArgExpr(0);
-  const MemSpaceRegion *MSR = ArgV.getAsRegion()->getMemorySpace();
 
-  if (!isa(MSR))
+  const auto *SSR =
+  dyn_cast(ArgV.getAsRegion()->getMemorySpace());
+  if (!SSR)
+return;
+  const auto *StackFrameFuncD =
+  dyn_cast_or_null(SSR->getStackFrame()->getDecl());
+  if (StackFrameFuncD && StackFrameFuncD->isMain())
 return;
 
   StringRef ErrorMsg = "The 'putenv' function should not be called with "
diff --git a/clang/test/Analysis/putenv-stack-array.c 
b/clang/test/Analysis/putenv-stack-array.c
index fbbf93259ab85..f28aed73031d3 100644
--- a/clang/test/Analysis/putenv-stack-array.c
+++ b/clang/test/Analysis/putenv-stack-array.c
@@ -45,6 +45,15 @@ int test_auto_var_subarray() {
   return putenv(env + 100); // expected-warning{{The 'putenv' function should 
not be called with}}
 }
 
+int f_test_auto_var_call(char *env) {
+  return putenv(env); // expected-warning{{The 'putenv' function should not be 
called with}}
+}
+
+int test_auto_var_call() {
+  char env[1024];
+  return f_test_auto_var_call(env);
+}
+
 int test_constant() {
   char *env = "TEST";
   return putenv(env); // no-warning: data is not on the stack
@@ -68,3 +77,14 @@ void test_auto_var_reset() {
   // become invalid.
   putenv((char *)"NAME=anothervalue");
 }
+
+void f_main(char *env) {
+  putenv(env); // no warning: string allocated in stack of 'main'
+}
+
+int main(int argc, char **argv) {
+  char env[] = "NAME=value";
+  putenv(env); // no warning: string allocated in stack of 'main'
+  f_main(env);
+  return 0;
+}

``




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


[clang] [clang][analyzer] PutenvStackArrayChecker: No warning from 'main' (PR #93299)

2024-05-24 Thread Balázs Kéri via cfe-commits

https://github.com/balazske created 
https://github.com/llvm/llvm-project/pull/93299

None

From 9baa8cc3a1a738a43deee811b51593db85d5c88c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Fri, 24 May 2024 15:22:22 +0200
Subject: [PATCH] [clang][analyzer] PutenvStackArrayChecker: No warning from
 'main'

---
 clang/docs/analyzer/checkers.rst  | 10 ++
 .../Checkers/PutenvStackArrayChecker.cpp  |  9 +++--
 clang/test/Analysis/putenv-stack-array.c  | 20 +++
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index ac9f0b06f63ba..3a31708a1e9de 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2858,6 +2858,16 @@ The check corresponds to CERT rule
 return putenv(env); // putenv function should not be called with 
stack-allocated string
   }
 
+There is one case where the checker can report a false positive. This is when
+the stack-allocated array is used at `putenv` in a function or code branch that
+does not return (calls `fork` or `exec` like function).
+
+Another special case is if the `putenv` is called from function `main`. Here
+the stack is deallocated at the end of the program and it should be no problem
+to use the stack-allocated string (a multi-threaded program may require more
+attention). The checker does not warn for cases when stack space of `main` is
+used at the `putenv` call.
+
 .. _alpha-security-ReturnPtrRange:
 
 alpha.security.ReturnPtrRange (C)
diff --git a/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
index d59cebf0aa5cb..bf81d57bf82fd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PutenvStackArrayChecker.cpp
@@ -44,9 +44,14 @@ void PutenvStackArrayChecker::checkPostCall(const CallEvent 
,
 
   SVal ArgV = Call.getArgSVal(0);
   const Expr *ArgExpr = Call.getArgExpr(0);
-  const MemSpaceRegion *MSR = ArgV.getAsRegion()->getMemorySpace();
 
-  if (!isa(MSR))
+  const auto *SSR =
+  dyn_cast(ArgV.getAsRegion()->getMemorySpace());
+  if (!SSR)
+return;
+  const auto *StackFrameFuncD =
+  dyn_cast_or_null(SSR->getStackFrame()->getDecl());
+  if (StackFrameFuncD && StackFrameFuncD->isMain())
 return;
 
   StringRef ErrorMsg = "The 'putenv' function should not be called with "
diff --git a/clang/test/Analysis/putenv-stack-array.c 
b/clang/test/Analysis/putenv-stack-array.c
index fbbf93259ab85..f28aed73031d3 100644
--- a/clang/test/Analysis/putenv-stack-array.c
+++ b/clang/test/Analysis/putenv-stack-array.c
@@ -45,6 +45,15 @@ int test_auto_var_subarray() {
   return putenv(env + 100); // expected-warning{{The 'putenv' function should 
not be called with}}
 }
 
+int f_test_auto_var_call(char *env) {
+  return putenv(env); // expected-warning{{The 'putenv' function should not be 
called with}}
+}
+
+int test_auto_var_call() {
+  char env[1024];
+  return f_test_auto_var_call(env);
+}
+
 int test_constant() {
   char *env = "TEST";
   return putenv(env); // no-warning: data is not on the stack
@@ -68,3 +77,14 @@ void test_auto_var_reset() {
   // become invalid.
   putenv((char *)"NAME=anothervalue");
 }
+
+void f_main(char *env) {
+  putenv(env); // no warning: string allocated in stack of 'main'
+}
+
+int main(int argc, char **argv) {
+  char env[] = "NAME=value";
+  putenv(env); // no warning: string allocated in stack of 'main'
+  f_main(env);
+  return 0;
+}

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


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Matheus Izvekov via cfe-commits




mizvekov wrote:

We usually create new tests under the latest standard.

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


[clang] f35aac6 - [clang][Interp] Fix zero-initializing unions

2024-05-24 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-24T15:15:40+02:00
New Revision: f35aac699167ef1046e2f177d2ba899c6975374e

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

LOG: [clang][Interp] Fix zero-initializing unions

Only with primitive fields for now.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index b885cbe2c4b0e..f73eaeebf9fe8 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1053,9 +1053,6 @@ bool 
ByteCodeExprGen::visitInitList(ArrayRef Inits,
 if (Inits.size() == 1 && E->getType() == Inits[0]->getType())
   return this->visitInitializer(Inits[0]);
 
-if (Inits.size() == 0)
-  return this->emitFinishInit(E);
-
 auto initPrimitiveField = [=](const Record::Field *FieldToInit,
   const Expr *Init, PrimType T) -> bool {
   if (!this->visit(Init))
@@ -1083,24 +1080,38 @@ bool 
ByteCodeExprGen::visitInitList(ArrayRef Inits,
 };
 
 if (R->isUnion()) {
-  assert(Inits.size() == 1);
-  const Expr *Init = Inits[0];
-  const FieldDecl *FToInit = nullptr;
-  if (const auto *ILE = dyn_cast(E))
-FToInit = ILE->getInitializedFieldInUnion();
-  else
-FToInit = cast(E)->getInitializedFieldInUnion();
-
-  if (!this->emitDupPtr(E))
-return false;
-
-  const Record::Field *FieldToInit = R->getField(FToInit);
-  if (std::optional T = classify(Init)) {
-if (!initPrimitiveField(FieldToInit, Init, *T))
-  return false;
+  if (Inits.size() == 0) {
+// Zero-initialize the first union field.
+if (R->getNumFields() == 0)
+  return this->emitFinishInit(E);
+const Record::Field *FieldToInit = R->getField(0u);
+QualType FieldType = FieldToInit->Desc->getType();
+if (std::optional T = classify(FieldType)) {
+  if (!this->visitZeroInitializer(*T, FieldType, E))
+return false;
+  if (!this->emitInitField(*T, FieldToInit->Offset, E))
+return false;
+}
+// FIXME: Non-primitive case?
   } else {
-if (!initCompositeField(FieldToInit, Init))
+const Expr *Init = Inits[0];
+const FieldDecl *FToInit = nullptr;
+if (const auto *ILE = dyn_cast(E))
+  FToInit = ILE->getInitializedFieldInUnion();
+else
+  FToInit = 
cast(E)->getInitializedFieldInUnion();
+
+if (!this->emitDupPtr(E))
   return false;
+
+const Record::Field *FieldToInit = R->getField(FToInit);
+if (std::optional T = classify(Init)) {
+  if (!initPrimitiveField(FieldToInit, Init, *T))
+return false;
+} else {
+  if (!initCompositeField(FieldToInit, Init))
+return false;
+}
   }
   return this->emitFinishInit(E);
 }

diff  --git a/clang/test/AST/Interp/unions.cpp 
b/clang/test/AST/Interp/unions.cpp
index b0b1b19617408..293a1981a52f0 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -31,6 +31,12 @@ static_assert(ab.d == 1.0, "");
 static_assert(ab.a == 1, ""); // both-error {{not an integral constant 
expression}} \
   // both-note {{read of member 'a' of union with 
active member 'd'}}
 
+
+namespace Empty {
+  union E {};
+  constexpr E e{};
+}
+
 namespace SimpleStore {
   union A {
 int a;
@@ -49,3 +55,13 @@ namespace SimpleStore {
   }
   static_assert(empty() == 10, "");
 }
+
+namespace ZeroInit {
+  struct S { int m; };
+  union Z {
+float f;
+  };
+
+  constexpr Z z{};
+  static_assert(z.f == 0.0, "");
+}



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


[clang] [clang] Fix PS "selective" DLL import/export of vtable & typeinfo (PR #92579)

2024-05-24 Thread Andrew Ng via cfe-commits

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


[clang] 0ad4c80 - [clang] Fix PS "selective" DLL import/export of vtable & typeinfo (#92579)

2024-05-24 Thread via cfe-commits

Author: Andrew Ng
Date: 2024-05-24T14:04:22+01:00
New Revision: 0ad4c8075985a0b82c01b28750a49e9e46a8c220

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

LOG: [clang] Fix PS "selective" DLL import/export of vtable & typeinfo (#92579)

Prior to this patch, for "selective" DLL import/export, the vtable &
typeinfo would be imported/exported on the condition that all non-inline
virtual methods are imported/exported. This condition was based upon MS
guidelines related to "selective" DLL import/export.

However, in reality, this condition is too rigid and can result in
undefined vtable & typeinfo symbols for code that builds fine with MSVC.
Therefore, relax this condition to be if any non-inline method is
imported/exported.

Added: 
clang/test/CodeGenCXX/ps-dllstorage-vtable-rtti.cpp

Modified: 
clang/lib/CodeGen/ItaniumCXXABI.cpp

Removed: 
clang/test/CodeGenCXX/ps4-dllstorage-vtable-rtti.cpp



diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 18acf7784f714..8427286dee887 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1793,6 +1793,37 @@ void ItaniumCXXABI::EmitDestructorCall(CodeGenFunction 
,
 ThisTy, VTT, VTTTy, nullptr);
 }
 
+// Check if any non-inline method has the specified attribute.
+template 
+static bool CXXRecordNonInlineHasAttr(const CXXRecordDecl *RD) {
+  for (const auto *D : RD->noload_decls()) {
+if (const auto *FD = dyn_cast(D)) {
+  if (FD->isInlined() || FD->doesThisDeclarationHaveABody() ||
+  FD->isPureVirtual())
+continue;
+  if (D->hasAttr())
+return true;
+}
+  }
+
+  return false;
+}
+
+static void setVTableSelectiveDLLImportExport(CodeGenModule ,
+  llvm::GlobalVariable *VTable,
+  const CXXRecordDecl *RD) {
+  if (VTable->getDLLStorageClass() !=
+  llvm::GlobalVariable::DefaultStorageClass ||
+  RD->hasAttr() || RD->hasAttr())
+return;
+
+  if (CGM.getVTables().isVTableExternal(RD)) {
+if (CXXRecordNonInlineHasAttr(RD))
+  VTable->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+  } else if (CXXRecordNonInlineHasAttr(RD))
+VTable->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
+}
+
 void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables ,
   const CXXRecordDecl *RD) {
   llvm::GlobalVariable *VTable = getAddrOfVTable(RD, CharUnits());
@@ -1818,6 +1849,9 @@ void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables 
,
   if (CGM.supportsCOMDAT() && VTable->isWeakForLinker())
 VTable->setComdat(CGM.getModule().getOrInsertComdat(VTable->getName()));
 
+  if (CGM.getTarget().hasPS4DLLImportExport())
+setVTableSelectiveDLLImportExport(CGM, VTable, RD);
+
   // Set the right visibility.
   CGM.setGVProperties(VTable, RD);
 
@@ -1905,29 +1939,6 @@ ItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base,
   VTable->getValueType(), VTable, Indices, /*InBounds=*/true, InRange);
 }
 
-// Check whether all the non-inline virtual methods for the class have the
-// specified attribute.
-template 
-static bool CXXRecordAllNonInlineVirtualsHaveAttr(const CXXRecordDecl *RD) {
-  bool FoundNonInlineVirtualMethodWithAttr = false;
-  for (const auto *D : RD->noload_decls()) {
-if (const auto *FD = dyn_cast(D)) {
-  if (!FD->isVirtualAsWritten() || FD->isInlineSpecified() ||
-  FD->doesThisDeclarationHaveABody())
-continue;
-  if (!D->hasAttr())
-return false;
-  FoundNonInlineVirtualMethodWithAttr = true;
-}
-  }
-
-  // We didn't find any non-inline virtual methods missing the attribute.  We
-  // will return true when we found at least one non-inline virtual with the
-  // attribute.  (This lets our caller know that the attribute needs to be
-  // propagated up to the vtable.)
-  return FoundNonInlineVirtualMethodWithAttr;
-}
-
 llvm::Value *ItaniumCXXABI::getVTableAddressPointInStructorWithVTT(
 CodeGenFunction , const CXXRecordDecl *VTableClass, BaseSubobject Base,
 const CXXRecordDecl *NearestVBase) {
@@ -1981,26 +1992,10 @@ llvm::GlobalVariable 
*ItaniumCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
   getContext().toCharUnitsFromBits(PAlign).getAsAlign());
   VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 
-  // In MS C++ if you have a class with virtual functions in which you are 
using
-  // selective member import/export, then all virtual functions must be 
exported
-  // unless they are inline, otherwise a link error will result. To match this
-  // behavior, for such classes, we dllimport the vtable if it is defined
-  // externally 

[clang] [clang] Fix PS "selective" DLL import/export of vtable & typeinfo (PR #92579)

2024-05-24 Thread Andrew Ng via cfe-commits

https://github.com/nga888 updated 
https://github.com/llvm/llvm-project/pull/92579

>From 09fbe6bf163680105c42d4ecbb502ea6519e8b7b Mon Sep 17 00:00:00 2001
From: Andrew Ng 
Date: Mon, 22 Apr 2024 19:29:01 +0100
Subject: [PATCH] [clang] Fix PS "selective" DLL import/export of vtable &
 typeinfo

Prior to this patch, for "selective" DLL import/export, the vtable &
typeinfo would be imported/exported on the condition that all non-inline
virtual methods are imported/exported. This condition was based upon MS
guidelines related to "selective" DLL import/export.

However, in reality, this condition is too rigid and can result in
undefined vtable & typeinfo symbols for code that builds fine with
MSVC. Therefore, relax this condition to be if any non-inline method is
imported/exported.
---
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  91 
 .../CodeGenCXX/ps-dllstorage-vtable-rtti.cpp  | 114 ++
 .../CodeGenCXX/ps4-dllstorage-vtable-rtti.cpp | 211 --
 3 files changed, 156 insertions(+), 260 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/ps-dllstorage-vtable-rtti.cpp
 delete mode 100644 clang/test/CodeGenCXX/ps4-dllstorage-vtable-rtti.cpp

diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 18acf7784f714..8427286dee887 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1793,6 +1793,37 @@ void ItaniumCXXABI::EmitDestructorCall(CodeGenFunction 
,
 ThisTy, VTT, VTTTy, nullptr);
 }
 
+// Check if any non-inline method has the specified attribute.
+template 
+static bool CXXRecordNonInlineHasAttr(const CXXRecordDecl *RD) {
+  for (const auto *D : RD->noload_decls()) {
+if (const auto *FD = dyn_cast(D)) {
+  if (FD->isInlined() || FD->doesThisDeclarationHaveABody() ||
+  FD->isPureVirtual())
+continue;
+  if (D->hasAttr())
+return true;
+}
+  }
+
+  return false;
+}
+
+static void setVTableSelectiveDLLImportExport(CodeGenModule ,
+  llvm::GlobalVariable *VTable,
+  const CXXRecordDecl *RD) {
+  if (VTable->getDLLStorageClass() !=
+  llvm::GlobalVariable::DefaultStorageClass ||
+  RD->hasAttr() || RD->hasAttr())
+return;
+
+  if (CGM.getVTables().isVTableExternal(RD)) {
+if (CXXRecordNonInlineHasAttr(RD))
+  VTable->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+  } else if (CXXRecordNonInlineHasAttr(RD))
+VTable->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
+}
+
 void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables ,
   const CXXRecordDecl *RD) {
   llvm::GlobalVariable *VTable = getAddrOfVTable(RD, CharUnits());
@@ -1818,6 +1849,9 @@ void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables 
,
   if (CGM.supportsCOMDAT() && VTable->isWeakForLinker())
 VTable->setComdat(CGM.getModule().getOrInsertComdat(VTable->getName()));
 
+  if (CGM.getTarget().hasPS4DLLImportExport())
+setVTableSelectiveDLLImportExport(CGM, VTable, RD);
+
   // Set the right visibility.
   CGM.setGVProperties(VTable, RD);
 
@@ -1905,29 +1939,6 @@ ItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base,
   VTable->getValueType(), VTable, Indices, /*InBounds=*/true, InRange);
 }
 
-// Check whether all the non-inline virtual methods for the class have the
-// specified attribute.
-template 
-static bool CXXRecordAllNonInlineVirtualsHaveAttr(const CXXRecordDecl *RD) {
-  bool FoundNonInlineVirtualMethodWithAttr = false;
-  for (const auto *D : RD->noload_decls()) {
-if (const auto *FD = dyn_cast(D)) {
-  if (!FD->isVirtualAsWritten() || FD->isInlineSpecified() ||
-  FD->doesThisDeclarationHaveABody())
-continue;
-  if (!D->hasAttr())
-return false;
-  FoundNonInlineVirtualMethodWithAttr = true;
-}
-  }
-
-  // We didn't find any non-inline virtual methods missing the attribute.  We
-  // will return true when we found at least one non-inline virtual with the
-  // attribute.  (This lets our caller know that the attribute needs to be
-  // propagated up to the vtable.)
-  return FoundNonInlineVirtualMethodWithAttr;
-}
-
 llvm::Value *ItaniumCXXABI::getVTableAddressPointInStructorWithVTT(
 CodeGenFunction , const CXXRecordDecl *VTableClass, BaseSubobject Base,
 const CXXRecordDecl *NearestVBase) {
@@ -1981,26 +1992,10 @@ llvm::GlobalVariable 
*ItaniumCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
   getContext().toCharUnitsFromBits(PAlign).getAsAlign());
   VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 
-  // In MS C++ if you have a class with virtual functions in which you are 
using
-  // selective member import/export, then all virtual functions must be 
exported
-  // unless they are inline, otherwise a link error will result. To match this
-  // behavior, for such classes, we 

[clang] [serialization] no transitive decl change (PR #92083)

2024-05-24 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 commented:

This looks good conceptually, I left a couple of minor notes.

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


[clang] [serialization] no transitive decl change (PR #92083)

2024-05-24 Thread Jan Svoboda via cfe-commits


@@ -7802,20 +7800,31 @@ Decl *ASTReader::GetDecl(GlobalDeclID ID) {
 
 LocalDeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile ,
GlobalDeclID GlobalID) {
-  DeclID ID = GlobalID.get();
-  if (ID < NUM_PREDEF_DECL_IDS)
+  if (GlobalID.get() < NUM_PREDEF_DECL_IDS)
+return LocalDeclID(GlobalID.get());
+
+  if (!M.ModuleOffsetMap.empty())
+ReadModuleOffsetMap(M);
+
+  ModuleFile *Owner = getOwningModuleFile(GlobalID);
+  DeclID ID = GlobalID.getLocalDeclIndex();
+
+  if (Owner == ) {
+ID += NUM_PREDEF_DECL_IDS;
 return LocalDeclID(ID);
+  }
 
-  GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID);
-  assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
-  ModuleFile *Owner = I->second;
+  uint64_t OrignalModuleFileIndex = 0;
+  for (unsigned I = 0; I < M.DependentModules.size(); I++)

jansvoboda11 wrote:

I just now noticed the name `DependentModules` (introduced in #86912) sounds 
like exactly the opposite of what this member represents. Can we rename this to 
`TransitiveImports` (or something similar) in a prep patch to clarify the 
semantics here?

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


[libunwind] Use relative includes to allow source-based dependencies without `-I` (PR #80443)

2024-05-24 Thread Yuriy Chernyshov via cfe-commits

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


[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-05-24 Thread Henry Linjamäki via cfe-commits

https://github.com/linehill updated 
https://github.com/llvm/llvm-project/pull/77897

From 13609260c7ef2b57751975a6c7847439958978d6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henry=20Linjam=C3=A4ki?= 
Date: Thu, 21 Dec 2023 08:43:16 +0200
Subject: [PATCH 1/2] [SPIR-V] Prefer llvm-spirv- tool

Prefer using `llvm-spirv-` tool
(i.e. `llvm-spirv-18`) over plain `llvm-spirv`. If the versioned tool
is not found in PATH, fall back to use the plain `llvm-spirv`.

An issue with the using `llvm-spirv` is that the one found in PATH
might be compiled against older LLVM version which could lead to
crashes or obscure bugs. For example, `llvm-spirv` distributed by
Ubuntu links against different LLVM version depending on the Ubuntu
release (LLVM-10 in 20.04LTS, LLVM-13 in 22.04LTS).
---
 clang/lib/Driver/ToolChains/SPIRV.cpp  | 12 ++--
 clang/test/Driver/hipspv-toolchain.hip | 13 +
 clang/test/Driver/spirv-toolchain.cl   | 10 ++
 clang/test/lit.site.cfg.py.in  |  1 +
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/SPIRV.cpp 
b/clang/lib/Driver/ToolChains/SPIRV.cpp
index 27de69550853c..ce900600cbee5 100644
--- a/clang/lib/Driver/ToolChains/SPIRV.cpp
+++ b/clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 #include "SPIRV.h"
 #include "CommonArgs.h"
+#include "clang/Basic/Version.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/InputInfo.h"
@@ -32,8 +33,15 @@ void SPIRV::constructTranslateCommand(Compilation , const 
Tool ,
 
   CmdArgs.append({"-o", Output.getFilename()});
 
-  const char *Exec =
-  C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv"));
+  // Try to find "llvm-spirv-". Otherwise, fall back to
+  // plain "llvm-spirv".
+  using namespace std::string_literals;
+  auto VersionedTool = "llvm-spirv-"s + std::to_string(LLVM_VERSION_MAJOR);
+  std::string ExeCand = T.getToolChain().GetProgramPath(VersionedTool.c_str());
+  if (!llvm::sys::fs::can_execute(ExeCand))
+ExeCand = T.getToolChain().GetProgramPath("llvm-spirv");
+
+  const char *Exec = C.getArgs().MakeArgString(ExeCand);
   C.addCommand(std::make_unique(JA, T, ResponseFileSupport::None(),
  Exec, CmdArgs, Input, Output));
 }
diff --git a/clang/test/Driver/hipspv-toolchain.hip 
b/clang/test/Driver/hipspv-toolchain.hip
index 4602cd3fc8d68..4005d9889051f 100644
--- a/clang/test/Driver/hipspv-toolchain.hip
+++ b/clang/test/Driver/hipspv-toolchain.hip
@@ -34,3 +34,16 @@
 // CHECK-SAME: "-o" [[OBJ_HOST:".*o"]] "-x" "hip"
 
 // CHECK: {{".*ld.*"}} {{.*}}[[OBJ_HOST]]
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### -target x86_64-linux-gnu \
+// RUN:   --offload=spirv64 --hip-path=%S/Inputs/hipspv -nohipwrapperinc \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major \
+// RUN:   --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/Driver/spirv-toolchain.cl 
b/clang/test/Driver/spirv-toolchain.cl
index db3ee4d3fe02f..de818177cb19f 100644
--- a/clang/test/Driver/spirv-toolchain.cl
+++ b/clang/test/Driver/spirv-toolchain.cl
@@ -77,3 +77,13 @@
 
 // XTOR: {{llvm-spirv.*"}}
 // BACKEND-NOT: {{llvm-spirv.*"}}
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### --target=spirv64 -x cl -c %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index ec6d30e6c2203..1cbd876ac5bb9 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -43,6 +43,7 @@ config.llvm_external_lit = path(r"@LLVM_EXTERNAL_LIT@")
 config.standalone_build = @CLANG_BUILT_STANDALONE@
 config.ppc_linux_default_ieeelongdouble = @PPC_LINUX_DEFAULT_IEEELONGDOUBLE@
 config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@
+config.substitutions.append(("%llvm-version-major", "@LLVM_VERSION_MAJOR@"))
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)

From 28c8da48fa98b18de1e7f77c4316bb3bfff933e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henry=20Linjam=C3=A4ki?= 
Date: Mon, 22 Jan 2024 11:25:46 +0200
Subject: [PATCH 2/2] Document llvm-spirv-

---
 clang/docs/UsersManual.rst | 6 +++---
 1 file changed, 3 

[clang] [serialization] no transitive decl change (PR #92083)

2024-05-24 Thread Jan Svoboda via cfe-commits


@@ -111,6 +109,28 @@ void *Decl::operator new(std::size_t Size, const 
ASTContext ,
   return ::operator new(Size + Extra, Ctx);
 }
 
+GlobalDeclID Decl::getGlobalID() const {
+  if (!isFromASTFile())
+return GlobalDeclID();
+  uint64_t ID = *((const uint64_t *)this - 1);

jansvoboda11 wrote:

Can you explain what this is doing?

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


[clang] [clang] Diagnose problematic diagnostic messages (PR #93229)

2024-05-24 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/93229

>From 38d6d9b809e1cf9d6a8f577630c838421486cd04 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Thu, 23 May 2024 14:55:16 -0400
Subject: [PATCH 1/3] Diagnose problematic diagnostic messages

Clang has some unwritten rules about diagnostic wording regarding
things like punctuation and capitalization. This patch documents those
rules and adds some tablegen support for checking diagnostics follow
the rules.

Specifically: tablegen now checks that a diagnostic does not start with
a capital letter or end with punctuation, except for the usual
exceptions like proper nouns or ending with a question.
---
 clang/docs/InternalsManual.rst|  38 
 clang/test/TableGen/deferred-diag.td  |  10 +-
 clang/test/TableGen/text-substitution.td  |   4 +-
 clang/test/TableGen/wording-errors.td |  55 +
 .../TableGen/ClangDiagnosticsEmitter.cpp  | 191 ++
 5 files changed, 291 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/TableGen/wording-errors.td

diff --git a/clang/docs/InternalsManual.rst b/clang/docs/InternalsManual.rst
index b3e2b870ae5f9..3d21e37784b36 100644
--- a/clang/docs/InternalsManual.rst
+++ b/clang/docs/InternalsManual.rst
@@ -123,6 +123,44 @@ severe that error recovery won't be able to recover 
sensibly from them (thus
 spewing a ton of bogus errors).  One example of this class of error are failure
 to ``#include`` a file.
 
+Diagnostic Wording
+^^
+The wording used for a diagnostic is critical because it is the only way for a
+user to know how to correct their code. Use the following suggestions when
+wording a diagnostic.
+
+* Diagnostics in Clang do not start with a capital letter and do not end with
+  punctuation.
+
+* This does not apply to proper nouns like ``Clang`` or ``OpenMP``, to
+  acronyms like ``GCC`` or ``ARC``, or to language standards like ``C23``
+  or ``C++17``.
+* A trailing question mark is allowed. e.g., ``unknown identifier %0; did
+  you mean %1?``.
+
+* Appropriately capitalize proper nouns like ``Clang``, ``OpenCL``, ``GCC``,
+  ``Objective-C``, etc and language standard versions like ``C11`` or 
``C++11``.
+* The wording should be succinct. If necessary, use a semicolon to combine
+  sentence fragments instead of using complete sentences. e.g., prefer wording
+  like ``'%0' is deprecated; it will be removed in a future release of Clang``
+  over wording like ``'%0' is deprecated. It will be removed in a future 
release
+  of Clang``.
+* The wording should be actionable and avoid using standards terms or grammar
+  productions that a new user would not be familiar with. e.g., prefer wording
+  like ``missing semicolon`` over wording like ``syntax error`` (which is not
+  actionable) or ``expected unqualified-id`` (which uses standards 
terminology).
+* The wording should clearly explain what is wrong with the code rather than
+  restating what the code does. e.g., prefer wording like ``type %0 requires a
+  value in the range %1 to %2`` over wording like ``%0 is invalid``.
+* The wording should have enough contextual information to help the user
+  identify the issue in a complex expression. e.g., prefer wording like
+  ``both sides of the %0 binary operator are identical`` over wording like
+  ``identical operands to binary operator``.
+* Use single quotes to denote syntactic constructs or command line arguments
+  named in a diagnostic message. e.g., prefer wording like ``'this' pointer
+  cannot be null in well-defined C++ code`` over wording like ``this pointer
+  cannot be null in well-defined C++ code``.
+
 The Format String
 ^
 
diff --git a/clang/test/TableGen/deferred-diag.td 
b/clang/test/TableGen/deferred-diag.td
index c1906d4a9e45e..d7e8e694c7b3e 100644
--- a/clang/test/TableGen/deferred-diag.td
+++ b/clang/test/TableGen/deferred-diag.td
@@ -4,24 +4,24 @@ include "DiagnosticBase.inc"
 
 // Test usage of Deferrable and NonDeferrable in diagnostics.
 
-def test_default : Error<"This error is non-deferrable by default">;
+def test_default : Error<"this error is non-deferrable by default">;
 // CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, 
true, true, false, 0)
 
-def test_deferrable : Error<"This error is deferrable">, Deferrable;
+def test_deferrable : Error<"this error is deferrable">, Deferrable;
 // CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, 
true, true, true, 0)
 
-def test_non_deferrable : Error<"This error is non-deferrable">, NonDeferrable;
+def test_non_deferrable : Error<"this error is non-deferrable">, NonDeferrable;
 // CHECK-DAG: DIAG(test_non_deferrable, {{.*}} SFINAE_SubstitutionFailure, 
false, true, true, false, 0)
 
 let Deferrable = 1 in {
 
-def test_let : Error<"This error is deferrable by let">;
+def test_let : Error<"this error is deferrable by let">;
 // CHECK-DAG: 

[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-05-24 Thread Sven van Haastregt via cfe-commits
Henry =?utf-8?q?Linjamäki?= 
Message-ID:
In-Reply-To: 


svenvh wrote:

> Thanks for the review. Could you merge this PR on my behalf (I don't have 
> write access)?

Yes I am happy to do so, but would you mind rebasing this PR onto latest `main` 
first?  Just so that the checks can run again to avoid any potential new 
regressions since the checks ran last.

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


[clang] [clang] Diagnose problematic diagnostic messages (PR #93229)

2024-05-24 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/93229

>From 38d6d9b809e1cf9d6a8f577630c838421486cd04 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Thu, 23 May 2024 14:55:16 -0400
Subject: [PATCH 1/3] Diagnose problematic diagnostic messages

Clang has some unwritten rules about diagnostic wording regarding
things like punctuation and capitalization. This patch documents those
rules and adds some tablegen support for checking diagnostics follow
the rules.

Specifically: tablegen now checks that a diagnostic does not start with
a capital letter or end with punctuation, except for the usual
exceptions like proper nouns or ending with a question.
---
 clang/docs/InternalsManual.rst|  38 
 clang/test/TableGen/deferred-diag.td  |  10 +-
 clang/test/TableGen/text-substitution.td  |   4 +-
 clang/test/TableGen/wording-errors.td |  55 +
 .../TableGen/ClangDiagnosticsEmitter.cpp  | 191 ++
 5 files changed, 291 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/TableGen/wording-errors.td

diff --git a/clang/docs/InternalsManual.rst b/clang/docs/InternalsManual.rst
index b3e2b870ae5f9..3d21e37784b36 100644
--- a/clang/docs/InternalsManual.rst
+++ b/clang/docs/InternalsManual.rst
@@ -123,6 +123,44 @@ severe that error recovery won't be able to recover 
sensibly from them (thus
 spewing a ton of bogus errors).  One example of this class of error are failure
 to ``#include`` a file.
 
+Diagnostic Wording
+^^
+The wording used for a diagnostic is critical because it is the only way for a
+user to know how to correct their code. Use the following suggestions when
+wording a diagnostic.
+
+* Diagnostics in Clang do not start with a capital letter and do not end with
+  punctuation.
+
+* This does not apply to proper nouns like ``Clang`` or ``OpenMP``, to
+  acronyms like ``GCC`` or ``ARC``, or to language standards like ``C23``
+  or ``C++17``.
+* A trailing question mark is allowed. e.g., ``unknown identifier %0; did
+  you mean %1?``.
+
+* Appropriately capitalize proper nouns like ``Clang``, ``OpenCL``, ``GCC``,
+  ``Objective-C``, etc and language standard versions like ``C11`` or 
``C++11``.
+* The wording should be succinct. If necessary, use a semicolon to combine
+  sentence fragments instead of using complete sentences. e.g., prefer wording
+  like ``'%0' is deprecated; it will be removed in a future release of Clang``
+  over wording like ``'%0' is deprecated. It will be removed in a future 
release
+  of Clang``.
+* The wording should be actionable and avoid using standards terms or grammar
+  productions that a new user would not be familiar with. e.g., prefer wording
+  like ``missing semicolon`` over wording like ``syntax error`` (which is not
+  actionable) or ``expected unqualified-id`` (which uses standards 
terminology).
+* The wording should clearly explain what is wrong with the code rather than
+  restating what the code does. e.g., prefer wording like ``type %0 requires a
+  value in the range %1 to %2`` over wording like ``%0 is invalid``.
+* The wording should have enough contextual information to help the user
+  identify the issue in a complex expression. e.g., prefer wording like
+  ``both sides of the %0 binary operator are identical`` over wording like
+  ``identical operands to binary operator``.
+* Use single quotes to denote syntactic constructs or command line arguments
+  named in a diagnostic message. e.g., prefer wording like ``'this' pointer
+  cannot be null in well-defined C++ code`` over wording like ``this pointer
+  cannot be null in well-defined C++ code``.
+
 The Format String
 ^
 
diff --git a/clang/test/TableGen/deferred-diag.td 
b/clang/test/TableGen/deferred-diag.td
index c1906d4a9e45e..d7e8e694c7b3e 100644
--- a/clang/test/TableGen/deferred-diag.td
+++ b/clang/test/TableGen/deferred-diag.td
@@ -4,24 +4,24 @@ include "DiagnosticBase.inc"
 
 // Test usage of Deferrable and NonDeferrable in diagnostics.
 
-def test_default : Error<"This error is non-deferrable by default">;
+def test_default : Error<"this error is non-deferrable by default">;
 // CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, 
true, true, false, 0)
 
-def test_deferrable : Error<"This error is deferrable">, Deferrable;
+def test_deferrable : Error<"this error is deferrable">, Deferrable;
 // CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, 
true, true, true, 0)
 
-def test_non_deferrable : Error<"This error is non-deferrable">, NonDeferrable;
+def test_non_deferrable : Error<"this error is non-deferrable">, NonDeferrable;
 // CHECK-DAG: DIAG(test_non_deferrable, {{.*}} SFINAE_SubstitutionFailure, 
false, true, true, false, 0)
 
 let Deferrable = 1 in {
 
-def test_let : Error<"This error is deferrable by let">;
+def test_let : Error<"this error is deferrable by let">;
 // CHECK-DAG: 

[clang] [clang-format] Don't always break before << between string literals (PR #92214)

2024-05-24 Thread via cfe-commits


@@ -10539,6 +10539,17 @@ TEST_F(FormatTest, KeepStringLabelValuePairsOnALine) {
   "  bbb);");
 }
 
+TEST_F(FormatTest, WrapBeforeInsertionOperatorbetweenStringLiterals) {
+  verifyFormat("QStringList() << \"foo\" << \"bar\";");

Alexolut wrote:

Will `verifyNoChange` here be better suitable?

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


[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-05-24 Thread Henry Linjamäki via cfe-commits

linehill wrote:

Thanks for the review. Could you merge this PR on my behalf (I don't have write 
access)?

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


[clang] [serialization] no transitive decl change (PR #92083)

2024-05-24 Thread Jan Svoboda via cfe-commits


@@ -255,6 +255,12 @@ class DeclOffset {
   }
 };
 
+// The unaligned decl ID used in the Blobs of bistreams.
+using unalighed_decl_id_t =

jansvoboda11 wrote:

I know this typo isn't introduced by your PR, but since your PR is touching it, 
please fix it in a prep commit.
```suggestion
using unaligned_decl_id_t =
```

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


[clang] [serialization] no transitive decl change (PR #92083)

2024-05-24 Thread Jan Svoboda via cfe-commits


@@ -124,6 +130,15 @@ class DeclIDBase {
 
   bool isInvalid() const { return ID == PREDEF_DECL_NULL_ID; }
 
+  unsigned getModuleFileIndex() const { return ID >> 32; }
+
+  unsigned getLocalDeclIndex() const {
+// Implement it directly instead of calling `llvm::maskTrailingOnes` since
+// we don't want `MathExtras.h` to be inclued here.

jansvoboda11 wrote:

Why not? Just to keep the amount of code lower? Can't we move the function body 
to an implementation file?

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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() (PR #90043)

2024-05-24 Thread Sebastian Wolf via cfe-commits

https://github.com/sebwolf-de updated 
https://github.com/llvm/llvm-project/pull/90043

>From 8eb5863305e8f9a1311a540faf35f24fc6f55c6c Mon Sep 17 00:00:00 2001
From: Sebastian Wolf 
Date: Wed, 17 Apr 2024 16:16:35 +0200
Subject: [PATCH 1/3] Enforce SL.con.3: Add check to replace operator[] with
 at() on std containers

---
 .../AvoidBoundsErrorsCheck.cpp| 81 +++
 .../AvoidBoundsErrorsCheck.h  | 32 
 .../cppcoreguidelines/CMakeLists.txt  |  1 +
 .../CppCoreGuidelinesTidyModule.cpp   |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../cppcoreguidelines/avoid-bounds-errors.rst | 20 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../cppcoreguidelines/avoid-bounds-errors.cpp | 66 +++
 8 files changed, 209 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-bounds-errors.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-bounds-errors.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
new file mode 100644
index 0..524c21b5bdb81
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
@@ -0,0 +1,81 @@
+//===--- AvoidBoundsErrorsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "AvoidBoundsErrorsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+bool isApplicable(const QualType ) {
+  const auto TypeStr = Type.getAsString();
+  bool Result = false;
+  // Only check for containers in the std namespace
+  if (TypeStr.find("std::vector") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::array") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::deque") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::unordered_map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::flat_map") != std::string::npos) {
+Result = true;
+  }
+  // TODO Add std::span with C++26
+  return Result;
+}
+
+void AvoidBoundsErrorsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(callee(cxxMethodDecl(hasName("operator[]")).bind("f")))
+  .bind("x"),
+  this);
+}
+
+void AvoidBoundsErrorsCheck::check(const MatchFinder::MatchResult ) {
+  const ASTContext  = *Result.Context;
+  const SourceManager  = Context.getSourceManager();
+  const auto *MatchedExpr = Result.Nodes.getNodeAs("x");
+  const auto *MatchedFunction = Result.Nodes.getNodeAs("f");
+  const auto Type = MatchedFunction->getThisType();
+  if (!isApplicable(Type)) {
+return;
+  }
+
+  // Get original code.
+  const SourceLocation b(MatchedExpr->getBeginLoc());
+  const SourceLocation e(MatchedExpr->getEndLoc());
+  const std::string OriginalCode =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(b, e), Source,
+   getLangOpts())
+  .str();
+  const auto Range = SourceRange(b, e);
+
+  // Build replacement.
+  std::string NewCode = OriginalCode;
+  const auto BeginOpen = NewCode.find("[");
+  NewCode.replace(BeginOpen, 1, ".at(");
+  const auto BeginClose = NewCode.find("]");
+  NewCode.replace(BeginClose, 1, ")");
+
+  diag(MatchedExpr->getBeginLoc(), "Do not use operator[], use at() instead.")
+  << FixItHint::CreateReplacement(Range, NewCode);
+}
+
+} // namespace clang::tidy::cppcoreguidelines
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
new file mode 100644
index 0..f915729cd7bbe
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
@@ -0,0 +1,32 @@
+//===--- AvoidBoundsErrorsCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 

[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 updated 
https://github.com/llvm/llvm-project/pull/92997

>From 7c1e44455a343cef3c5ab0da22c9971888cf Mon Sep 17 00:00:00 2001
From: Chen Zheng 
Date: Wed, 22 May 2024 02:37:04 -0400
Subject: [PATCH 1/3] [PowerPC] Support -fpatchable-function-entry

For now only PPC big endian Linux is supported.
PPC little endian Linux has XRAY support for 64-bit.
PPC AIX has different patchable function entry implementations.

Fixes #63220
Fixes #57031
---
 clang/include/clang/Basic/Attr.td |  2 +-
 clang/include/clang/Basic/AttrDocs.td |  3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  4 ++
 clang/test/Driver/fpatchable-function-entry.c |  9 +++-
 .../patchable-function-entry-attr-aix.cpp |  4 ++
 .../Sema/patchable-function-entry-attr.cpp|  2 +
 llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 24 -
 .../PowerPC/patchable-function-entry.ll   | 49 +++
 10 files changed, 96 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/Sema/patchable-function-entry-attr-aix.cpp
 create mode 100644 llvm/test/CodeGen/PowerPC/patchable-function-entry.ll

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index e59cdd369..c85a6690d6ad9 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -892,7 +892,7 @@ def PatchableFunctionEntry
 : InheritableAttr,
   TargetSpecificAttr> {
+   "riscv64", "x86", "x86_64", "ppc", "ppc64"]>> {
   let Spellings = [GCC<"patchable_function_entry">];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Args = [UnsignedArgument<"Count">, DefaultIntArgument<"Offset", 0>];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a313e811c9d21..b7858a5ce0247 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5796,7 +5796,8 @@ takes precedence over the command line option 
``-fpatchable-function-entry=N,M``
 ``M`` defaults to 0 if omitted.
 
 This attribute is only supported on
-aarch64/aarch64-be/loongarch32/loongarch64/riscv32/riscv64/i386/x86-64 targets.
+aarch64/aarch64-be/loongarch32/loongarch64/riscv32/riscv64/i386/x86-64/ppc/ppc64
 targets.
+For ppc/ppc64 targets, AIX is still not supported.
 }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 270b0a1e01307..31c3a6007a1a1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3470,7 +3470,7 @@ def err_attr_tlsmodel_arg : Error<"tls_model must be 
\"global-dynamic\", "
 
 def err_attr_codemodel_arg : Error<"code model '%0' is not supported on this 
target">;
 
-def err_aix_attr_unsupported_tls_model : Error<"TLS model '%0' is not yet 
supported on AIX">;
+def err_aix_attr_unsupported : Error<"%0 attribute is not yet supported on 
AIX">;
 
 def err_tls_var_aligned_over_maximum : Error<
   "alignment (%0) of thread-local variable %1 is greater than the maximum 
supported "
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 18de8781e894a..e1023477653b9 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6681,7 +6681,9 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 StringRef S0 = A->getValue(), S = S0;
 unsigned Size, Offset = 0;
 if (!Triple.isAArch64() && !Triple.isLoongArch() && !Triple.isRISCV() &&
-!Triple.isX86())
+!Triple.isX86() &&
+!(!Triple.isOSAIX() && (Triple.getArch() == llvm::Triple::ppc ||
+Triple.getArch() == llvm::Triple::ppc64)))
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 else if (S.consumeInteger(10, Size) ||
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 5041fd65286fa..5c7cb08060061 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5922,6 +5922,10 @@ static void handleXRayLogArgsAttr(Sema , Decl *D, 
const ParsedAttr ) {
 
 static void handlePatchableFunctionEntryAttr(Sema , Decl *D,
  const ParsedAttr ) {
+  if (S.Context.getTargetInfo().getTriple().isOSAIX()) {
+S.Diag(AL.getLoc(), diag::err_aix_attr_unsupported) << AL;
+return;
+  }
   uint32_t Count = 0, Offset = 0;
   if (!checkUInt32Argument(S, AL, AL.getArgAsExpr(0), Count, 0, true))
 return;
diff --git a/clang/test/Driver/fpatchable-function-entry.c 
b/clang/test/Driver/fpatchable-function-entry.c
index ab04fd39ffa1c..26ec4669ccb77 100644
--- a/clang/test/Driver/fpatchable-function-entry.c
+++ b/clang/test/Driver/fpatchable-function-entry.c
@@ -6,6 +6,8 @@
 // RUN: %clang 

[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits


@@ -0,0 +1,49 @@
+; RUN: llc -mtriple=powerpc-unknown-linux-gnu %s -o - | FileCheck %s 
--check-prefixes=CHECK,PPC32
+; RUN: llc -mtriple=powerpc64-unknown-linux-gnu %s -o - | FileCheck %s 
--check-prefixes=CHECK,PPC64
+
+define void @f0() {
+; CHECK-LABEL: f0:
+; CHECK-NOT:   nop
+; CHECK:   # %bb.0:
+; CHECK-NEXT:blr
+; CHECK-NOT:   .section__patchable_function_entries
+  ret void
+}
+
+define void @f1() "patchable-function-entry"="0" {
+; CHECK-LABEL: f1:
+; CHECK-NOT:   nop
+; CHECK:   # %bb.0:
+; CHECK-NEXT:blr
+; CHECK-NOT:   .section__patchable_function_entries
+  ret void
+}
+
+define void @f2() "patchable-function-entry"="1" {
+; CHECK-LABEL: f2:
+; CHECK-LABEL-NEXT:  .Lfunc_begin2:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:nop
+; CHECK-NEXT:blr
+; CHECK:   .section__patchable_function_entries
+; PPC32:   .p2align2, 0x0
+; PPC64:   .p2align3, 0x0
+; PPC32-NEXT:  .long   .Lfunc_begin2
+; PPC64-NEXT:  .quad   .Lfunc_begin2
+  ret void
+}
+
+define void @f3() "patchable-function-entry"="1" 
"patchable-function-prefix"="2" {
+; CHECK-LABEL: .Ltmp0:
+; CHECK-COUNT-2: nop
+; CHECK-LABEL: f3:

chenzheng1030 wrote:

Updated.

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits


@@ -6,15 +6,20 @@
 // RUN: %clang -target loongarch64 %s -fpatchable-function-entry=1,0 -c -### 
2>&1 | FileCheck %s
 // RUN: %clang -target riscv32 %s -fpatchable-function-entry=1,0 -c -### 2>&1 
| FileCheck %s
 // RUN: %clang -target riscv64 %s -fpatchable-function-entry=1,0 -c -### 2>&1 
| FileCheck %s
+// RUN: %clang -target powerpc-unknown-linux-gnu %s 
-fpatchable-function-entry=1,0 -c -### 2>&1 | FileCheck %s

chenzheng1030 wrote:

Thank you. Updated.

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits


@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fsyntax-only -verify %s
+
+// expected-error@+1 {{'patchable_function_entry' attribute is not yet 
supported on AIX}}
+__attribute__((patchable_function_entry(0))) void f();

chenzheng1030 wrote:

Updated, moved the file to the existing one.

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits


@@ -6681,7 +6681,9 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 StringRef S0 = A->getValue(), S = S0;
 unsigned Size, Offset = 0;
 if (!Triple.isAArch64() && !Triple.isLoongArch() && !Triple.isRISCV() &&
-!Triple.isX86())
+!Triple.isX86() &&
+!(!Triple.isOSAIX() && (Triple.getArch() == llvm::Triple::ppc ||

chenzheng1030 wrote:

Linux little endian targets are this patch's scope. This patch tries to support 
-fpatchable-function-entry for big endian targets but not AIX.

If we are going to support little endian, we first need to check the 
possibility about removal of XRAY. (XRAY also uses backend node 
`PATCHABLE_FUNCTION_ENTER`)

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits


@@ -0,0 +1,49 @@
+; RUN: llc -mtriple=powerpc-unknown-linux-gnu %s -o - | FileCheck %s 
--check-prefixes=CHECK,PPC32

chenzheng1030 wrote:

Thank you, changed the triple. Little endian is not going to be supported in 
this patch.

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 commented:

> So PPC64 can use ELFv2 for Triple::OpenBSD. We probably want to diagnose this 
> OS for PPC64, since with ELFv2 we might emit separate local and global entry 
> points which means only certain values can be passed to 
> -fpatchable-function-entry option.

For targets with ABI elfv2 which means there are dual entries, this patch can 
generate expected patchable entry:
For -mtriple=powerpc64-unknown-freebsd-unknown
```
.Ltmp0:
nop
nop
f3: # @f3
.Lfunc_begin0:
.cfi_startproc
.Lfunc_gep0:
addis 2, 12, .TOC.-.Lfunc_gep0@ha
addi 2, 2, .TOC.-.Lfunc_gep0@l
.Lfunc_lep0:
.localentry f3, .Lfunc_lep0-.Lfunc_gep0
# %bb.0:# %entry
nop
```

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


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -1265,13 +1238,62 @@ class TemplateDiff {
 IsNullPtr = true;
 return;
   case TemplateArgument::Expression:
-// TODO: Sometimes, the desugared template argument Expr differs from
-// the sugared template argument Expr.  It may be useful in the future
-// but for now, it is just discarded.
-if (!E)
-  E = TA.getAsExpr();
-return;
+E = Iter->getAsExpr();
+break;
+  case TemplateArgument::Null:
+  case TemplateArgument::Type:
+  case TemplateArgument::Template:
+  case TemplateArgument::TemplateExpansion:
+llvm_unreachable("TemplateArgument kind is not expected for NTTP");
+  case TemplateArgument::Pack:
+llvm_unreachable("TemplateArgument kind handled elsewhere");

bolshakov-a wrote:

Nit: "... _should be_ handled ..."?

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


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a approved this pull request.

One question about the version of the C++ standard under testing, otherwise 
LGTM, thanks!

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


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Andrey Ali Khan Bolshakov via cfe-commits

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


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Andrey Ali Khan Bolshakov via cfe-commits




bolshakov-a wrote:

I don't see any C++26-specific stuff here, only C++20.

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


[clang] [llvm] [PowerPC] Support -fpatchable-function-entry (PR #92997)

2024-05-24 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 updated 
https://github.com/llvm/llvm-project/pull/92997

>From 751d80c61f0e42daa3796a8270e186153dd9413f Mon Sep 17 00:00:00 2001
From: Chen Zheng 
Date: Wed, 22 May 2024 02:37:04 -0400
Subject: [PATCH 1/3] [PowerPC] Support -fpatchable-function-entry

For now only PPC big endian Linux is supported.
PPC little endian Linux has XRAY support for 64-bit.
PPC AIX has different patchable function entry implementations.

Fixes #63220
Fixes #57031
---
 clang/include/clang/Basic/Attr.td |  2 +-
 clang/include/clang/Basic/AttrDocs.td |  3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  4 ++
 clang/test/Driver/fpatchable-function-entry.c |  9 +++-
 .../patchable-function-entry-attr-aix.cpp |  4 ++
 .../Sema/patchable-function-entry-attr.cpp|  2 +
 llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 24 -
 .../PowerPC/patchable-function-entry.ll   | 49 +++
 10 files changed, 96 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/Sema/patchable-function-entry-attr-aix.cpp
 create mode 100644 llvm/test/CodeGen/PowerPC/patchable-function-entry.ll

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index a2c8cc42195fd..c05bfa96efe35 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -892,7 +892,7 @@ def PatchableFunctionEntry
 : InheritableAttr,
   TargetSpecificAttr> {
+   "riscv64", "x86", "x86_64", "ppc", "ppc64"]>> {
   let Spellings = [GCC<"patchable_function_entry">];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Args = [UnsignedArgument<"Count">, DefaultIntArgument<"Offset", 0>];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a313e811c9d21..b7858a5ce0247 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5796,7 +5796,8 @@ takes precedence over the command line option 
``-fpatchable-function-entry=N,M``
 ``M`` defaults to 0 if omitted.
 
 This attribute is only supported on
-aarch64/aarch64-be/loongarch32/loongarch64/riscv32/riscv64/i386/x86-64 targets.
+aarch64/aarch64-be/loongarch32/loongarch64/riscv32/riscv64/i386/x86-64/ppc/ppc64
 targets.
+For ppc/ppc64 targets, AIX is still not supported.
 }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index cc402182687f3..7e0286890b999 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3470,7 +3470,7 @@ def err_attr_tlsmodel_arg : Error<"tls_model must be 
\"global-dynamic\", "
 
 def err_attr_codemodel_arg : Error<"code model '%0' is not supported on this 
target">;
 
-def err_aix_attr_unsupported_tls_model : Error<"TLS model '%0' is not yet 
supported on AIX">;
+def err_aix_attr_unsupported : Error<"%0 attribute is not yet supported on 
AIX">;
 
 def err_tls_var_aligned_over_maximum : Error<
   "alignment (%0) of thread-local variable %1 is greater than the maximum 
supported "
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 588f0c511cd2e..5bb05d5c3091d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6681,7 +6681,9 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 StringRef S0 = A->getValue(), S = S0;
 unsigned Size, Offset = 0;
 if (!Triple.isAArch64() && !Triple.isLoongArch() && !Triple.isRISCV() &&
-!Triple.isX86())
+!Triple.isX86() &&
+!(!Triple.isOSAIX() && (Triple.getArch() == llvm::Triple::ppc ||
+Triple.getArch() == llvm::Triple::ppc64)))
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 else if (S.consumeInteger(10, Size) ||
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index ca5938083917f..17c17032ef96b 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5922,6 +5922,10 @@ static void handleXRayLogArgsAttr(Sema , Decl *D, 
const ParsedAttr ) {
 
 static void handlePatchableFunctionEntryAttr(Sema , Decl *D,
  const ParsedAttr ) {
+  if (S.Context.getTargetInfo().getTriple().isOSAIX()) {
+S.Diag(AL.getLoc(), diag::err_aix_attr_unsupported) << AL;
+return;
+  }
   uint32_t Count = 0, Offset = 0;
   if (!checkUInt32Argument(S, AL, AL.getArgAsExpr(0), Count, 0, true))
 return;
diff --git a/clang/test/Driver/fpatchable-function-entry.c 
b/clang/test/Driver/fpatchable-function-entry.c
index 4d0d609584c8d..8df3311f33b0e 100644
--- a/clang/test/Driver/fpatchable-function-entry.c
+++ b/clang/test/Driver/fpatchable-function-entry.c
@@ -6,6 +6,8 @@
 // RUN: %clang 

[clang] [Clang] Only check exprs that might be immediate escalating in evaluated contexts (PR #93187)

2024-05-24 Thread Mariya Podchishchaeva via cfe-commits


@@ -5146,6 +5153,12 @@ class Sema final : public SemaBase {
 return ExprEvalContexts.back();
   };
 
+  const ExpressionEvaluationContextRecord () const {
+assert(ExprEvalContexts.size() >= 2 &&
+   "Must be in an expression evaluation context");
+return ExprEvalContexts[ExprEvalContexts.size() - 2];

Fznamznon wrote:

Submitted https://github.com/llvm/llvm-project/issues/93284

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-05-24 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/93206

>From 658e9d46adf6dd79aa6aef03a1817444a880348a Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Thu, 23 May 2024 22:35:11 +0800
Subject: [PATCH] [Clang][Sema] Tweak tryCaptureVariable for unevaluated
 lambdas

This patch picks up #78598 with the hope that we can address such
crashes in tryCaptureVariable for unevaluated lambdas.

In addition to tryCaptureVariable, this also contains several other
fixes on e.g. lambda parsing/dependencies.
---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/AST/DeclBase.h|   4 +
 clang/lib/Parse/ParseExprCXX.cpp  |   5 +-
 clang/lib/Sema/SemaExpr.cpp   |  10 ++
 clang/lib/Sema/SemaLambda.cpp |  20 +++
 clang/lib/Sema/TreeTransform.h|   2 +-
 clang/test/SemaCXX/lambda-unevaluated.cpp | 164 ++
 7 files changed, 206 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 49ab222bec405..e06a5cd9536aa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -710,6 +710,9 @@ Bug Fixes to C++ Support
 - Correctly treat the compound statement of an ``if consteval`` as an 
immediate context. Fixes (#GH91509).
 - When partial ordering alias templates against template template parameters,
   allow pack expansions when the alias has a fixed-size parameter list. Fixes 
(#GH62529).
+- Fixes several bugs in capturing variables within unevaluated contexts. Fixes 
(#GH63845), (#GH67260), (#GH69307), (#GH88081),
+  (#GH89496), (#GH90669) and (#GH91633).
+
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index e43e812cd9455..3a311d4c55916 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -2148,6 +2148,10 @@ class DeclContext {
getDeclKind() <= Decl::lastRecord;
   }
 
+  bool isRequiresExprBody() const {
+return getDeclKind() == Decl::RequiresExprBody;
+  }
+
   bool isNamespace() const { return getDeclKind() == Decl::Namespace; }
 
   bool isStdNamespace() const;
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 825031da358ad..73f619a085b04 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1576,7 +1576,10 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   TrailingReturnTypeLoc, ),
   std::move(Attributes), DeclEndLoc);
 
-Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
+// We have called ActOnLambdaClosureQualifiers for parentheses-less cases
+// above.
+if (HasParentheses)
+  Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
 
 if (HasParentheses && Tok.is(tok::kw_requires))
   ParseTrailingRequiresClause(D);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e6c3fa51d54da..7a4ede9898034 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18831,6 +18831,10 @@ bool Sema::tryCaptureVariable(
   DeclContext *VarDC = Var->getDeclContext();
   DeclContext *DC = CurContext;
 
+  // Skip past RequiresExprBodys because they don't constitute function scopes.
+  while (DC->isRequiresExprBody())
+DC = DC->getParent();
+
   // tryCaptureVariable is called every time a DeclRef is formed,
   // it can therefore have non-negigible impact on performances.
   // For local variables and when there is no capturing scope,
@@ -18838,6 +18842,12 @@ bool Sema::tryCaptureVariable(
   if (CapturingFunctionScopes == 0 && (!BuildAndDiagnose || VarDC == DC))
 return true;
 
+  // Exception: Function parameters are not tied to the function's DeclContext
+  // until we enter the function definition. Capturing them anyway would result
+  // in an out-of-bounds error while traversing DC and its parents.
+  if (isa(Var) && !VarDC->isFunctionOrMethod())
+return true;
+
   const auto *VD = dyn_cast(Var);
   if (VD) {
 if (VD->isInitCapture())
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 1743afaf15287..999316e544b91 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1036,6 +1036,7 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer ,
   // be dependent, because there are template parameters in scope.
   CXXRecordDecl::LambdaDependencyKind LambdaDependencyKind =
   CXXRecordDecl::LDK_Unknown;
+
   if (LSI->NumExplicitTemplateParams > 0) {
 Scope *TemplateParamScope = CurScope->getTemplateParamParent();
 assert(TemplateParamScope &&
@@ -1046,6 +1047,25 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer ,
   LambdaDependencyKind = CXXRecordDecl::LDK_AlwaysDependent;
   } else if (CurScope->getTemplateParamParent() != nullptr) {
 LambdaDependencyKind = 

[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-05-24 Thread Younan Zhang via cfe-commits

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-05-24 Thread Younan Zhang via cfe-commits

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


[clang] [clang] MangledSymbol: Added move to Names param in init list (PR #87287)

2024-05-24 Thread Braden Helmer via cfe-commits

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


[clang-tools-extra] Clang doc async (PR #93276)

2024-05-24 Thread via cfe-commits

https://github.com/PeterChou1 updated 
https://github.com/llvm/llvm-project/pull/93276

>From 0b6d536133f63e078fbde491a8c92c7ec916cb47 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 05:18:05 -0400
Subject: [PATCH] [clang-doc] make loading of json side bar async

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 28 +--
 clang-tools-extra/clang-doc/Representation.h  |  1 +
 clang-tools-extra/clang-doc/assets/index.js   |  5 ++--
 .../clang-doc/tool/ClangDocMain.cpp   |  6 +++-
 4 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index c0faf5f7e8fd9..fb1a7f94c9094 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -964,7 +964,7 @@ static llvm::Error SerializeIndex(ClangDocContext ) {
   std::error_code FileErr;
   llvm::SmallString<128> FilePath;
   llvm::sys::path::native(CDCtx.OutDirectory, FilePath);
-  llvm::sys::path::append(FilePath, "index_json.js");
+  llvm::sys::path::append(FilePath, "index.json");
   llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_None);
   if (FileErr != OK) {
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -985,9 +985,7 @@ static llvm::Error SerializeIndex(ClangDocContext ) {
   });
 });
   };
-  OS << "var JsonIndex = `\n";
   IndexToJSON(CDCtx.Idx);
-  OS << "`;\n";
   return llvm::Error::success();
 }
 
@@ -1049,31 +1047,33 @@ static llvm::Error CopyFile(StringRef FilePath, 
StringRef OutDirectory) {
   std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite);
   if (FileErr != OK) {
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
-   "error creating file " +
-   llvm::sys::path::filename(FilePath) +
-   ": " + FileErr.message() + "\n");
+   "error creating file " + FilePath + ": " +
+   FileErr.message() + "\n");
   }
   return llvm::Error::success();
 }
 
 llvm::Error HTMLGenerator::createResources(ClangDocContext ) {
-  auto Err = SerializeIndex(CDCtx);
-  if (Err)
+  if (auto Err = SerializeIndex(CDCtx)) {
 return Err;
-  Err = GenIndex(CDCtx);
-  if (Err)
+  }
+
+  if (auto Err = GenIndex(CDCtx)) {
 return Err;
+  }
 
   for (const auto  : CDCtx.UserStylesheets) {
-Err = CopyFile(FilePath, CDCtx.OutDirectory);
-if (Err)
+if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) {
   return Err;
+}
   }
+
   for (const auto  : CDCtx.FilesToCopy) {
-Err = CopyFile(FilePath, CDCtx.OutDirectory);
-if (Err)
+if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) {
   return Err;
+}
   }
+
   return llvm::Error::success();
 }
 
diff --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index a6b144eb7fa2a..23323f1cbdf46 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -491,6 +491,7 @@ struct ClangDocContext {
   std::string SourceRoot;   // Directory where processed files are stored. 
Links
 // to definition locations will only be generated 
if
 // the file is in this dir.
+
   // URL of repository that hosts code used for links to definition locations.
   std::optional RepositoryUrl;
   // Path of CSS stylesheets that will be copied to OutDirectory and used to
diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..379867268527e 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -82,6 +82,7 @@ function createIndex(Index) {
 document.addEventListener("DOMContentLoaded", function() {
   // JsonIndex is a variable from another file that contains the index
   // in JSON format
-  var Index = JSON.parse(JsonIndex);
-  createIndex(Index);
+  fetch("/index.json")
+  .then((response) => response.json())
+  .then((Index) => { createIndex(Index); });
 });
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 21b581fa6df2e..53108a77dab21 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -155,6 +155,10 @@ Example usage for a project using a compile commands 
database:
 return 1;
   }
 
+  // add option to customize url fragment
+  // such as
+  // 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-doc/ClangDocMain.cpp#L1
+
   // Fail early if an invalid format was provided.
   std::string Format = getFormatString();
   llvm::outs() << "Emiting docs in " << Format << " format.\n";
@@ -179,7 +183,7 @@ Example usage for a 

[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)

2024-05-24 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/93281

>From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 04:28:08 -0400
Subject: [PATCH 1/2] clang-doc switched from using relative to absolute paths

---
 clang-tools-extra/clang-doc/assets/index.js | 72 ++---
 1 file changed, 35 insertions(+), 37 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..fe35e706cc98d 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -1,48 +1,46 @@
-// Append using posix-style a file name or directory to Base
-function append(Base, New) {
-  if (!New)
-return Base;
-  if (Base)
-Base += "/";
-  Base += New;
-  return Base;
-}
-
-// Get relative path to access FilePath from CurrentDirectory
-function computeRelativePath(FilePath, CurrentDirectory) {
-  var Path = FilePath;
-  while (Path) {
-if (CurrentDirectory == Path)
-  return FilePath.substring(Path.length + 1);
-Path = Path.substring(0, Path.lastIndexOf("/"));
-  }
-
-  var Dir = CurrentDirectory;
-  var Result = "";
-  while (Dir) {
-if (Dir == FilePath)
-  break;
-Dir = Dir.substring(0, Dir.lastIndexOf("/"));
-Result = append(Result, "..")
+function genLink(Ref) {
+  var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  if (Ref.RefType !== "namespace") {
+if (Ref.Path === "") {
+  Path = `${Path}${Ref.Name}.html`;
+}
+else {
+  Path = `${Path}/${Ref.Name}.html`;
+}
   }
-  Result = append(Result, FilePath.substring(Dir.length))
-  return Result;
-}
-
-function genLink(Ref, CurrentDirectory) {
-  var Path = computeRelativePath(Ref.Path, CurrentDirectory);
-  if (Ref.RefType == "namespace")
-Path = append(Path, "index.html");
-  else
-Path = append(Path, Ref.Name + ".html")
 
-ANode = document.createElement("a");
+  ANode = document.createElement("a");
   ANode.setAttribute("href", Path);
   var TextNode = document.createTextNode(Ref.Name);
   ANode.appendChild(TextNode);
   return ANode;
 }
 
+function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
+  // Out will store the HTML elements that Index requires to be generated
+  var Out = [];
+  if (Index.Name) {
+var SpanNode = document.createElement("span");
+var TextNode = document.createTextNode(Index.Name);
+SpanNode.appendChild(genLink(Index));
+Out.push(SpanNode);
+  }
+  if (Index.Children.length == 0)
+return Out;
+  // Only the outermost list should use ol, the others should use ul
+  var ListNodeName = IsOutermostList ? "ol" : "ul";
+  var ListNode = document.createElement(ListNodeName);
+  for (Child of Index.Children) {
+var LiNode = document.createElement("li");
+ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
+for (Node of ChildNodes)
+  LiNode.appendChild(Node);
+ListNode.appendChild(LiNode);
+  }
+  Out.push(ListNode);
+  return Out;
+}
+
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated
   var Out = [];

>From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 05:10:03 -0400
Subject: [PATCH 2/2] remove duplicate function

---
 clang-tools-extra/clang-doc/assets/index.js | 24 -
 1 file changed, 24 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index fe35e706cc98d..b013418c82093 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -16,30 +16,6 @@ function genLink(Ref) {
   return ANode;
 }
 
-function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
-  // Out will store the HTML elements that Index requires to be generated
-  var Out = [];
-  if (Index.Name) {
-var SpanNode = document.createElement("span");
-var TextNode = document.createTextNode(Index.Name);
-SpanNode.appendChild(genLink(Index));
-Out.push(SpanNode);
-  }
-  if (Index.Children.length == 0)
-return Out;
-  // Only the outermost list should use ol, the others should use ul
-  var ListNodeName = IsOutermostList ? "ol" : "ul";
-  var ListNode = document.createElement(ListNodeName);
-  for (Child of Index.Children) {
-var LiNode = document.createElement("li");
-ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
-for (Node of ChildNodes)
-  LiNode.appendChild(Node);
-ListNode.appendChild(LiNode);
-  }
-  Out.push(ListNode);
-  return Out;
-}
 
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated

___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)

2024-05-24 Thread via cfe-commits

https://github.com/PeterChou1 updated 
https://github.com/llvm/llvm-project/pull/93281

>From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 04:28:08 -0400
Subject: [PATCH 1/2] clang-doc switched from using relative to absolute paths

---
 clang-tools-extra/clang-doc/assets/index.js | 72 ++---
 1 file changed, 35 insertions(+), 37 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..fe35e706cc98d 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -1,48 +1,46 @@
-// Append using posix-style a file name or directory to Base
-function append(Base, New) {
-  if (!New)
-return Base;
-  if (Base)
-Base += "/";
-  Base += New;
-  return Base;
-}
-
-// Get relative path to access FilePath from CurrentDirectory
-function computeRelativePath(FilePath, CurrentDirectory) {
-  var Path = FilePath;
-  while (Path) {
-if (CurrentDirectory == Path)
-  return FilePath.substring(Path.length + 1);
-Path = Path.substring(0, Path.lastIndexOf("/"));
-  }
-
-  var Dir = CurrentDirectory;
-  var Result = "";
-  while (Dir) {
-if (Dir == FilePath)
-  break;
-Dir = Dir.substring(0, Dir.lastIndexOf("/"));
-Result = append(Result, "..")
+function genLink(Ref) {
+  var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  if (Ref.RefType !== "namespace") {
+if (Ref.Path === "") {
+  Path = `${Path}${Ref.Name}.html`;
+}
+else {
+  Path = `${Path}/${Ref.Name}.html`;
+}
   }
-  Result = append(Result, FilePath.substring(Dir.length))
-  return Result;
-}
-
-function genLink(Ref, CurrentDirectory) {
-  var Path = computeRelativePath(Ref.Path, CurrentDirectory);
-  if (Ref.RefType == "namespace")
-Path = append(Path, "index.html");
-  else
-Path = append(Path, Ref.Name + ".html")
 
-ANode = document.createElement("a");
+  ANode = document.createElement("a");
   ANode.setAttribute("href", Path);
   var TextNode = document.createTextNode(Ref.Name);
   ANode.appendChild(TextNode);
   return ANode;
 }
 
+function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
+  // Out will store the HTML elements that Index requires to be generated
+  var Out = [];
+  if (Index.Name) {
+var SpanNode = document.createElement("span");
+var TextNode = document.createTextNode(Index.Name);
+SpanNode.appendChild(genLink(Index));
+Out.push(SpanNode);
+  }
+  if (Index.Children.length == 0)
+return Out;
+  // Only the outermost list should use ol, the others should use ul
+  var ListNodeName = IsOutermostList ? "ol" : "ul";
+  var ListNode = document.createElement(ListNodeName);
+  for (Child of Index.Children) {
+var LiNode = document.createElement("li");
+ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
+for (Node of ChildNodes)
+  LiNode.appendChild(Node);
+ListNode.appendChild(LiNode);
+  }
+  Out.push(ListNode);
+  return Out;
+}
+
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated
   var Out = [];

>From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 05:10:03 -0400
Subject: [PATCH 2/2] remove duplicate function

---
 clang-tools-extra/clang-doc/assets/index.js | 24 -
 1 file changed, 24 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index fe35e706cc98d..b013418c82093 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -16,30 +16,6 @@ function genLink(Ref) {
   return ANode;
 }
 
-function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
-  // Out will store the HTML elements that Index requires to be generated
-  var Out = [];
-  if (Index.Name) {
-var SpanNode = document.createElement("span");
-var TextNode = document.createTextNode(Index.Name);
-SpanNode.appendChild(genLink(Index));
-Out.push(SpanNode);
-  }
-  if (Index.Children.length == 0)
-return Out;
-  // Only the outermost list should use ol, the others should use ul
-  var ListNodeName = IsOutermostList ? "ol" : "ul";
-  var ListNode = document.createElement(ListNodeName);
-  for (Child of Index.Children) {
-var LiNode = document.createElement("li");
-ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
-for (Node of ChildNodes)
-  LiNode.appendChild(Node);
-ListNode.appendChild(LiNode);
-  }
-  Out.push(ListNode);
-  return Out;
-}
 
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated

___
cfe-commits mailing list

[clang] [clang][Driver] Fix enabling strict alising by default when the environment is MSVC (PR #91689)

2024-05-24 Thread via cfe-commits

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

lgtm

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


[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)

2024-05-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: None (PeterChou1)


Changes

issue: https://github.com/llvm/llvm-project/issues/92867

I solved the problem by making the js use absolute path instead relative I 
think this also makes it more permanent since there is no need to compute 
relative path anymore

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


1 Files Affected:

- (modified) clang-tools-extra/clang-doc/assets/index.js (+35-37) 


``diff
diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..fe35e706cc98d 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -1,48 +1,46 @@
-// Append using posix-style a file name or directory to Base
-function append(Base, New) {
-  if (!New)
-return Base;
-  if (Base)
-Base += "/";
-  Base += New;
-  return Base;
-}
-
-// Get relative path to access FilePath from CurrentDirectory
-function computeRelativePath(FilePath, CurrentDirectory) {
-  var Path = FilePath;
-  while (Path) {
-if (CurrentDirectory == Path)
-  return FilePath.substring(Path.length + 1);
-Path = Path.substring(0, Path.lastIndexOf("/"));
-  }
-
-  var Dir = CurrentDirectory;
-  var Result = "";
-  while (Dir) {
-if (Dir == FilePath)
-  break;
-Dir = Dir.substring(0, Dir.lastIndexOf("/"));
-Result = append(Result, "..")
+function genLink(Ref) {
+  var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  if (Ref.RefType !== "namespace") {
+if (Ref.Path === "") {
+  Path = `${Path}${Ref.Name}.html`;
+}
+else {
+  Path = `${Path}/${Ref.Name}.html`;
+}
   }
-  Result = append(Result, FilePath.substring(Dir.length))
-  return Result;
-}
-
-function genLink(Ref, CurrentDirectory) {
-  var Path = computeRelativePath(Ref.Path, CurrentDirectory);
-  if (Ref.RefType == "namespace")
-Path = append(Path, "index.html");
-  else
-Path = append(Path, Ref.Name + ".html")
 
-ANode = document.createElement("a");
+  ANode = document.createElement("a");
   ANode.setAttribute("href", Path);
   var TextNode = document.createTextNode(Ref.Name);
   ANode.appendChild(TextNode);
   return ANode;
 }
 
+function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
+  // Out will store the HTML elements that Index requires to be generated
+  var Out = [];
+  if (Index.Name) {
+var SpanNode = document.createElement("span");
+var TextNode = document.createTextNode(Index.Name);
+SpanNode.appendChild(genLink(Index));
+Out.push(SpanNode);
+  }
+  if (Index.Children.length == 0)
+return Out;
+  // Only the outermost list should use ol, the others should use ul
+  var ListNodeName = IsOutermostList ? "ol" : "ul";
+  var ListNode = document.createElement(ListNodeName);
+  for (Child of Index.Children) {
+var LiNode = document.createElement("li");
+ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
+for (Node of ChildNodes)
+  LiNode.appendChild(Node);
+ListNode.appendChild(LiNode);
+  }
+  Out.push(ListNode);
+  return Out;
+}
+
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated
   var Out = [];

``




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


[clang-tools-extra] clang-doc switched from using relative to absolute paths (PR #93281)

2024-05-24 Thread via cfe-commits

https://github.com/PeterChou1 created 
https://github.com/llvm/llvm-project/pull/93281

issue: https://github.com/llvm/llvm-project/issues/92867

I solved the problem by making the js use absolute path instead relative I 
think this also makes it more permanent since there is no need to compute 
relative path anymore

>From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 04:28:08 -0400
Subject: [PATCH] clang-doc switched from using relative to absolute paths

---
 clang-tools-extra/clang-doc/assets/index.js | 72 ++---
 1 file changed, 35 insertions(+), 37 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..fe35e706cc98d 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -1,48 +1,46 @@
-// Append using posix-style a file name or directory to Base
-function append(Base, New) {
-  if (!New)
-return Base;
-  if (Base)
-Base += "/";
-  Base += New;
-  return Base;
-}
-
-// Get relative path to access FilePath from CurrentDirectory
-function computeRelativePath(FilePath, CurrentDirectory) {
-  var Path = FilePath;
-  while (Path) {
-if (CurrentDirectory == Path)
-  return FilePath.substring(Path.length + 1);
-Path = Path.substring(0, Path.lastIndexOf("/"));
-  }
-
-  var Dir = CurrentDirectory;
-  var Result = "";
-  while (Dir) {
-if (Dir == FilePath)
-  break;
-Dir = Dir.substring(0, Dir.lastIndexOf("/"));
-Result = append(Result, "..")
+function genLink(Ref) {
+  var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  if (Ref.RefType !== "namespace") {
+if (Ref.Path === "") {
+  Path = `${Path}${Ref.Name}.html`;
+}
+else {
+  Path = `${Path}/${Ref.Name}.html`;
+}
   }
-  Result = append(Result, FilePath.substring(Dir.length))
-  return Result;
-}
-
-function genLink(Ref, CurrentDirectory) {
-  var Path = computeRelativePath(Ref.Path, CurrentDirectory);
-  if (Ref.RefType == "namespace")
-Path = append(Path, "index.html");
-  else
-Path = append(Path, Ref.Name + ".html")
 
-ANode = document.createElement("a");
+  ANode = document.createElement("a");
   ANode.setAttribute("href", Path);
   var TextNode = document.createTextNode(Ref.Name);
   ANode.appendChild(TextNode);
   return ANode;
 }
 
+function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
+  // Out will store the HTML elements that Index requires to be generated
+  var Out = [];
+  if (Index.Name) {
+var SpanNode = document.createElement("span");
+var TextNode = document.createTextNode(Index.Name);
+SpanNode.appendChild(genLink(Index));
+Out.push(SpanNode);
+  }
+  if (Index.Children.length == 0)
+return Out;
+  // Only the outermost list should use ol, the others should use ul
+  var ListNodeName = IsOutermostList ? "ol" : "ul";
+  var ListNode = document.createElement(ListNodeName);
+  for (Child of Index.Children) {
+var LiNode = document.createElement("li");
+ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
+for (Node of ChildNodes)
+  LiNode.appendChild(Node);
+ListNode.appendChild(LiNode);
+  }
+  Out.push(ListNode);
+  return Out;
+}
+
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated
   var Out = [];

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


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-05-24 Thread Jan Svoboda via cfe-commits

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

LGTM, thanks!

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


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-05-24 Thread Jan Svoboda via cfe-commits

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


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-05-24 Thread Jan Svoboda via cfe-commits


@@ -0,0 +1,36 @@
+// Check that the scanner can adjust arguments by reading .rsp files in 
advance.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json

jansvoboda11 wrote:

Ok, that makes sense, thanks!

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


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-05-24 Thread Jan Svoboda via cfe-commits


@@ -86,6 +86,8 @@ static bool DeprecatedDriverCommand;
 static ResourceDirRecipeKind ResourceDirRecipe;
 static bool Verbose;
 static bool PrintTiming;
+static llvm::BumpPtrAllocator Alloc;
+static llvm::StringSaver Saver{Alloc};

jansvoboda11 wrote:

Why do these need to be global?

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


[clang] [analyzer] Fix a test issue in mingw configurations (PR #92737)

2024-05-24 Thread via cfe-commits

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

lgtm

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


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet updated 
https://github.com/llvm/llvm-project/pull/93079

From 9c691ab41ba500c1962bf9d63de86b65f184f047 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Wed, 22 May 2024 19:37:18 +0200
Subject: [PATCH] [clang][Sema] Fix crash when diagnosing candidates with
 parameter packs

Prevent OOB access by not printing target parameter range when there's a
pack in the function parameters.

Fixes https://github.com/llvm/llvm-project/issues/93076.
Fixes https://github.com/llvm/llvm-project/issues/76354.
Fixes https://github.com/llvm/llvm-project/issues/70191.
---
 clang/docs/ReleaseNotes.rst  |  3 ++-
 clang/lib/Sema/SemaOverload.cpp  | 11 +--
 clang/test/SemaCXX/overload-template.cpp |  3 +++
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45676a02b760b..023af70572306 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -730,7 +730,6 @@ Bug Fixes to C++ Support
   from being explicitly specialized for a given implicit instantiation of the 
class template.
 - Fixed a crash when ``this`` is used in a dependent class scope function 
template specialization
   that instantiates to a static member function.
-
 - Fix crash when inheriting from a cv-qualified type. Fixes #GH35603
 - Fix a crash when the using enum declaration uses an anonymous enumeration. 
Fixes (#GH86790).
 - Handled an edge case in ``getFullyPackExpandedSize`` so that we now avoid a 
false-positive diagnostic. (#GH84220)
@@ -790,6 +789,8 @@ Bug Fixes to C++ Support
   Fixes (#GH87210), (GH89541).
 - Clang no longer tries to check if an expression is immediate-escalating in 
an unevaluated context.
   Fixes (#GH91308).
+- Fixed a crash when diagnosing failed conversions involving template parameter
+  packs. (#GH93076)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 0c89fca8d38eb..86e869c7c72ff 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTLambda.h"
 #include "clang/AST/CXXInheritance.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DependenceFlags.h"
@@ -11301,8 +11302,14 @@ static void DiagnoseBadConversion(Sema , 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+
+  // FIXME: In presence of parameter packs we can't determine parameter range
+  // reliably, as we don't have access to instantiation.
+  bool HasParamPack = llvm::any_of(Fn->parameters().take_front(I),
+   [](const ParmVarDecl *Parm) { return Parm->isParameterPack(); 
});
+  if (!isObjectArgument && !HasParamPack)
+ToParamRange = Fn->getParamDecl(I)->getSourceRange();
 
   if (FromTy == S.Context.OverloadTy) {
 assert(FromExpr && "overload set argument came from implicit argument?");
diff --git a/clang/test/SemaCXX/overload-template.cpp 
b/clang/test/SemaCXX/overload-template.cpp
index 0fe13c479cce2..01cfe87a05831 100644
--- a/clang/test/SemaCXX/overload-template.cpp
+++ b/clang/test/SemaCXX/overload-template.cpp
@@ -58,3 +58,6 @@ namespace overloadCheck{
   }
 }
 #endif
+
+template  int b(a...); // expected-note {{candidate function 
template not viable: no known conversion from 'int ()' to 'int' for 2nd 
argument}}
+int d() { return b(0, d); } // expected-error {{no matching function 
for call to 'b'}}

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -58024,15 +58043,22 @@ X86TargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'r':   // GENERAL_REGS
 case 'l':   // INDEX_REGS
   if (VT == MVT::i8 || VT == MVT::i1)
-return std::make_pair(0U, ::GR8_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()
+  ? ::GR8_NOREX2RegClass
+  : ::GR8RegClass);
   if (VT == MVT::i16)
-return std::make_pair(0U, ::GR16_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()
+  ? ::GR16_NOREX2RegClass
+  : ::GR16RegClass);
   if (VT == MVT::i32 || VT == MVT::f32 ||
   (!VT.isVector() && !Subtarget.is64Bit()))
-return std::make_pair(0U, ::GR32_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()

KanRobert wrote:

The order should be reversed.
Subtarget.useInlineAsmGPR32() ? GR32 : GR32_NOREX2

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Freddy Ye via cfe-commits


@@ -58024,15 +58043,22 @@ X86TargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'r':   // GENERAL_REGS
 case 'l':   // INDEX_REGS
   if (VT == MVT::i8 || VT == MVT::i1)
-return std::make_pair(0U, ::GR8_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()
+  ? ::GR8_NOREX2RegClass
+  : ::GR8RegClass);
   if (VT == MVT::i16)
-return std::make_pair(0U, ::GR16_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()
+  ? ::GR16_NOREX2RegClass
+  : ::GR16RegClass);
   if (VT == MVT::i32 || VT == MVT::f32 ||
   (!VT.isVector() && !Subtarget.is64Bit()))
-return std::make_pair(0U, ::GR32_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()

FreddyLeaf wrote:

covered by getPreserverdRegister in RA.

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


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

@shafik thx for the pointers, i didn't know this came up before and even there 
were attempted fixes. I can verify that both of those are also fixed with this 
patch.

@knightXun do you plan to proceed with 
https://github.com/llvm/llvm-project/pull/70280 ? If so I am happy to discard 
this PR in favor of yours.

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


[clang] [clang] [SemaCXX] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-05-24 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/78112

>From 92f8720e3d21521b589d5291f086a2f32b87bfe0 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 14 Jan 2024 19:52:31 +
Subject: [PATCH 1/3] [clang] [SemaCXX] Implement CWG2627 Bit-fields and
 narrowing conversions

---
 clang/docs/ReleaseNotes.rst   |   5 +
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Overload.h   |   7 +-
 clang/lib/Sema/SemaExpr.cpp   |  10 +-
 clang/lib/Sema/SemaInit.cpp   |  20 ++-
 clang/lib/Sema/SemaOverload.cpp   | 119 +--
 .../dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp |  24 
 clang/test/CXX/drs/dr26xx.cpp | 136 ++
 clang/www/cxx_dr_status.html  |   2 +-
 9 files changed, 278 insertions(+), 48 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 92563262cc673..28202fc604e29 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -157,6 +157,11 @@ Resolutions to C++ Defect Reports
 - Clang now diagnoses declarative nested-name-specifiers with 
pack-index-specifiers.
   (`CWG2858: Declarative nested-name-specifiers and pack-index-specifiers 
`_).
 
+- Casts from a bit-field to an integral type is now not considered narrowing 
if the
+  width of the bit-field means that all potential values are in the range
+  of the target type, even if the type of the bit-field is larger.
+  (`CWG2627. Bit-fields and narrowing conversions  
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fdca82934cb4d..6cdb439be30ae 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6253,6 +6253,9 @@ def ext_init_list_variable_narrowing_const_reference : 
ExtWarn<
 def ext_init_list_constant_narrowing : ExtWarn<
   "constant expression evaluates to %0 which cannot be narrowed to type %1">,
   InGroup, DefaultError, SFINAEFailure;
+def ext_bit_field_narrowing : Extension<
+  "narrowing non-constant-expression from %0 bit-field of width %2 to %1 is a 
C++23 extension">,
+  InGroup, SFINAEFailure;
 def ext_init_list_constant_narrowing_const_reference : ExtWarn<
   ext_init_list_constant_narrowing.Summary>,
   InGroup, DefaultError, SFINAEFailure;
diff --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index 76311b00d2fc5..0d94045cc13f7 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -244,7 +244,11 @@ class Sema;
 /// Not a narrowing conversion.
 NK_Not_Narrowing,
 
-/// A narrowing conversion by virtue of the source and destination types.
+/// Not a narrowing conversion in C++23 because the source is a bit-field
+/// whose range can fit in the target type
+NK_BitField_Not_Narrowing,
+
+/// A narrowing conversion by virtue of the source and target types.
 NK_Type_Narrowing,
 
 /// A narrowing conversion, because a constant expression got narrowed.
@@ -387,6 +391,7 @@ class Sema;
 NarrowingKind
 getNarrowingKind(ASTContext , const Expr *Converted,
  APValue , QualType ,
+ unsigned ,
  bool IgnoreFloatToIntegralConversion = false) const;
 bool isPointerConversionToBool() const;
 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 50f92c496a539..4c16fcc60fc77 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -12361,8 +12361,9 @@ static bool checkThreeWayNarrowingConversion(Sema , 
QualType ToType, Expr *E,
 
   APValue PreNarrowingValue;
   QualType PreNarrowingType;
+  unsigned BitFieldWidth;
   switch (SCS.getNarrowingKind(S.Context, E, PreNarrowingValue,
-   PreNarrowingType,
+   PreNarrowingType, BitFieldWidth,
/*IgnoreFloatToIntegralConversion*/ true)) {
   case NK_Dependent_Narrowing:
 // Implicit conversion to a narrower type, but the expression is
@@ -12370,6 +12371,13 @@ static bool checkThreeWayNarrowingConversion(Sema , 
QualType ToType, Expr *E,
   case NK_Not_Narrowing:
 return false;
 
+  case NK_BitField_Not_Narrowing:
+if (!S.getLangOpts().CPlusPlus23) {
+  return S.Diag(E->getBeginLoc(), diag::ext_bit_field_narrowing)
+ << FromType << ToType << BitFieldWidth;
+}
+return false;
+
   case NK_Constant_Narrowing:
 // Implicit conversion to a narrower type, and the value is not a constant
 // expression.
diff --git a/clang/lib/Sema/SemaInit.cpp 

[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet updated 
https://github.com/llvm/llvm-project/pull/93079

From 6a057ff4b539045ce81e55b63702892496d18a97 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Wed, 22 May 2024 19:37:18 +0200
Subject: [PATCH] [clang][Sema] Fix crash when diagnosing candidates with
 parameter packs

Prevent OOB access.

Fixes https://github.com/llvm/llvm-project/issues/93076.
Fixes https://github.com/llvm/llvm-project/issues/76354.
Fixes https://github.com/llvm/llvm-project/issues/70191.
---
 clang/lib/Sema/SemaOverload.cpp  | 11 +--
 clang/test/SemaCXX/overload-template.cpp |  3 +++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 0c89fca8d38eb..86e869c7c72ff 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTLambda.h"
 #include "clang/AST/CXXInheritance.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DependenceFlags.h"
@@ -11301,8 +11302,14 @@ static void DiagnoseBadConversion(Sema , 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+
+  // FIXME: In presence of parameter packs we can't determine parameter range
+  // reliably, as we don't have access to instantiation.
+  bool HasParamPack = llvm::any_of(Fn->parameters().take_front(I),
+   [](const ParmVarDecl *Parm) { return Parm->isParameterPack(); 
});
+  if (!isObjectArgument && !HasParamPack)
+ToParamRange = Fn->getParamDecl(I)->getSourceRange();
 
   if (FromTy == S.Context.OverloadTy) {
 assert(FromExpr && "overload set argument came from implicit argument?");
diff --git a/clang/test/SemaCXX/overload-template.cpp 
b/clang/test/SemaCXX/overload-template.cpp
index 0fe13c479cce2..01cfe87a05831 100644
--- a/clang/test/SemaCXX/overload-template.cpp
+++ b/clang/test/SemaCXX/overload-template.cpp
@@ -58,3 +58,6 @@ namespace overloadCheck{
   }
 }
 #endif
+
+template  int b(a...); // expected-note {{candidate function 
template not viable: no known conversion from 'int ()' to 'int' for 2nd 
argument}}
+int d() { return b(0, d); } // expected-error {{no matching function 
for call to 'b'}}

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


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff a79a0c52885c3a60d6afdda3b125866b8ed75fce 
7c5716a726fe0c4a2a3e0ddfe8f992491bd0299d -- clang/lib/Sema/SemaOverload.cpp 
clang/test/SemaCXX/overload-template.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 86e869c7c7..61d3c1633a 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11306,8 +11306,10 @@ static void DiagnoseBadConversion(Sema , 
OverloadCandidate *Cand,
 
   // FIXME: In presence of parameter packs we can't determine parameter range
   // reliably, as we don't have access to instantiation.
-  bool HasParamPack = llvm::any_of(Fn->parameters().take_front(I),
-   [](const ParmVarDecl *Parm) { return Parm->isParameterPack(); 
});
+  bool HasParamPack =
+  llvm::any_of(Fn->parameters().take_front(I), [](const ParmVarDecl *Parm) 
{
+return Parm->isParameterPack();
+  });
   if (!isObjectArgument && !HasParamPack)
 ToParamRange = Fn->getParamDecl(I)->getSourceRange();
 

``




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


[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet updated 
https://github.com/llvm/llvm-project/pull/93079

From f7bdd39714e21ff31b3c5aa6a3a18967cb6fef2c Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Wed, 22 May 2024 19:37:18 +0200
Subject: [PATCH 1/2] [clang][Sema] Fix crash when diagnosing candidates with
 parameter packs

Prevent OOB access.

Fixes https://github.com/llvm/llvm-project/issues/93076
---
 clang/lib/Sema/SemaOverload.cpp  | 5 +++--
 clang/test/SemaCXX/overload-template.cpp | 3 +++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 0c89fca8d38eb..7465d6d96c20f 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11301,8 +11301,9 @@ static void DiagnoseBadConversion(Sema , 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+  if (!isObjectArgument && I < Fn->getNumParams())
+ToParamRange = Fn->getParamDecl(I)->getSourceRange();
 
   if (FromTy == S.Context.OverloadTy) {
 assert(FromExpr && "overload set argument came from implicit argument?");
diff --git a/clang/test/SemaCXX/overload-template.cpp 
b/clang/test/SemaCXX/overload-template.cpp
index 0fe13c479cce2..01cfe87a05831 100644
--- a/clang/test/SemaCXX/overload-template.cpp
+++ b/clang/test/SemaCXX/overload-template.cpp
@@ -58,3 +58,6 @@ namespace overloadCheck{
   }
 }
 #endif
+
+template  int b(a...); // expected-note {{candidate function 
template not viable: no known conversion from 'int ()' to 'int' for 2nd 
argument}}
+int d() { return b(0, d); } // expected-error {{no matching function 
for call to 'b'}}

From 7c5716a726fe0c4a2a3e0ddfe8f992491bd0299d Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Fri, 24 May 2024 10:25:25 +0200
Subject: [PATCH 2/2] add fixme and improve range handling

---
 clang/lib/Sema/SemaOverload.cpp | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 7465d6d96c20f..86e869c7c72ff 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTLambda.h"
 #include "clang/AST/CXXInheritance.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DependenceFlags.h"
@@ -11302,7 +11303,12 @@ static void DiagnoseBadConversion(Sema , 
OverloadCandidate *Cand,
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
   SourceRange ToParamRange;
-  if (!isObjectArgument && I < Fn->getNumParams())
+
+  // FIXME: In presence of parameter packs we can't determine parameter range
+  // reliably, as we don't have access to instantiation.
+  bool HasParamPack = llvm::any_of(Fn->parameters().take_front(I),
+   [](const ParmVarDecl *Parm) { return Parm->isParameterPack(); 
});
+  if (!isObjectArgument && !HasParamPack)
 ToParamRange = Fn->getParamDecl(I)->getSourceRange();
 
   if (FromTy == S.Context.OverloadTy) {

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


[clang] [clang] [SemaCXX] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-05-24 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/78112

>From 92f8720e3d21521b589d5291f086a2f32b87bfe0 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 14 Jan 2024 19:52:31 +
Subject: [PATCH 1/3] [clang] [SemaCXX] Implement CWG2627 Bit-fields and
 narrowing conversions

---
 clang/docs/ReleaseNotes.rst   |   5 +
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Overload.h   |   7 +-
 clang/lib/Sema/SemaExpr.cpp   |  10 +-
 clang/lib/Sema/SemaInit.cpp   |  20 ++-
 clang/lib/Sema/SemaOverload.cpp   | 119 +--
 .../dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp |  24 
 clang/test/CXX/drs/dr26xx.cpp | 136 ++
 clang/www/cxx_dr_status.html  |   2 +-
 9 files changed, 278 insertions(+), 48 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 92563262cc673..28202fc604e29 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -157,6 +157,11 @@ Resolutions to C++ Defect Reports
 - Clang now diagnoses declarative nested-name-specifiers with 
pack-index-specifiers.
   (`CWG2858: Declarative nested-name-specifiers and pack-index-specifiers 
`_).
 
+- Casts from a bit-field to an integral type is now not considered narrowing 
if the
+  width of the bit-field means that all potential values are in the range
+  of the target type, even if the type of the bit-field is larger.
+  (`CWG2627. Bit-fields and narrowing conversions  
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fdca82934cb4d..6cdb439be30ae 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6253,6 +6253,9 @@ def ext_init_list_variable_narrowing_const_reference : 
ExtWarn<
 def ext_init_list_constant_narrowing : ExtWarn<
   "constant expression evaluates to %0 which cannot be narrowed to type %1">,
   InGroup, DefaultError, SFINAEFailure;
+def ext_bit_field_narrowing : Extension<
+  "narrowing non-constant-expression from %0 bit-field of width %2 to %1 is a 
C++23 extension">,
+  InGroup, SFINAEFailure;
 def ext_init_list_constant_narrowing_const_reference : ExtWarn<
   ext_init_list_constant_narrowing.Summary>,
   InGroup, DefaultError, SFINAEFailure;
diff --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index 76311b00d2fc5..0d94045cc13f7 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -244,7 +244,11 @@ class Sema;
 /// Not a narrowing conversion.
 NK_Not_Narrowing,
 
-/// A narrowing conversion by virtue of the source and destination types.
+/// Not a narrowing conversion in C++23 because the source is a bit-field
+/// whose range can fit in the target type
+NK_BitField_Not_Narrowing,
+
+/// A narrowing conversion by virtue of the source and target types.
 NK_Type_Narrowing,
 
 /// A narrowing conversion, because a constant expression got narrowed.
@@ -387,6 +391,7 @@ class Sema;
 NarrowingKind
 getNarrowingKind(ASTContext , const Expr *Converted,
  APValue , QualType ,
+ unsigned ,
  bool IgnoreFloatToIntegralConversion = false) const;
 bool isPointerConversionToBool() const;
 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 50f92c496a539..4c16fcc60fc77 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -12361,8 +12361,9 @@ static bool checkThreeWayNarrowingConversion(Sema , 
QualType ToType, Expr *E,
 
   APValue PreNarrowingValue;
   QualType PreNarrowingType;
+  unsigned BitFieldWidth;
   switch (SCS.getNarrowingKind(S.Context, E, PreNarrowingValue,
-   PreNarrowingType,
+   PreNarrowingType, BitFieldWidth,
/*IgnoreFloatToIntegralConversion*/ true)) {
   case NK_Dependent_Narrowing:
 // Implicit conversion to a narrower type, but the expression is
@@ -12370,6 +12371,13 @@ static bool checkThreeWayNarrowingConversion(Sema , 
QualType ToType, Expr *E,
   case NK_Not_Narrowing:
 return false;
 
+  case NK_BitField_Not_Narrowing:
+if (!S.getLangOpts().CPlusPlus23) {
+  return S.Diag(E->getBeginLoc(), diag::ext_bit_field_narrowing)
+ << FromType << ToType << BitFieldWidth;
+}
+return false;
+
   case NK_Constant_Narrowing:
 // Implicit conversion to a narrower type, and the value is not a constant
 // expression.
diff --git a/clang/lib/Sema/SemaInit.cpp 

[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)

2024-05-24 Thread kadir çetinkaya via cfe-commits


@@ -11298,8 +11298,9 @@ static void DiagnoseBadConversion(Sema , 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  SourceRange ToParamRange;
+  if (!isObjectArgument && I < Fn->getNumParams())
+ToParamRange = Fn->getParamDecl(I)->getSourceRange();

kadircet wrote:

> Though I don't think solving this is complicated

sorry I guess I didn't convey full context in my previous message when I just 
said "it requires propagating extra information in the bad conversion about the 
parameter location".  `Fn` in this context is the template decl itself, hence 
the packs in the parameters are dependent. hence we can't simply ask how many 
expansions are there.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Freddy Ye via cfe-commits


@@ -5418,6 +5418,8 @@ X86:
   operand will get allocated only to RAX -- if two 32-bit operands are needed,
   you're better off splitting it yourself, before passing it to the asm
   statement.
+- ``jR``: An 8, 16, 32, or 64-bit integer EGPR when EGPR feature is on.
+  Otherwise, same as ``R``.

FreddyLeaf wrote:

> `r` is same as `R` for X86 IIUC.

Sorry, wrong conclusion. I did bad experiment before, making me judge clang 
didn't clarify for 'R' and 'r' for X86. 

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


[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

2024-05-24 Thread via cfe-commits

xbjfk wrote:

Hi @MaxEW707 
Yes, I will need someone to commit this for me.
Thanks!

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: not llc -mtriple=x86_64 %s 2>&1 | FileCheck %s --check-prefix=ERR
+; RUN: llc -mtriple=x86_64 -mattr=+egpr < %s | FileCheck %s
+; RUN: llc -mtriple=x86_64 -mattr=+egpr,+inline-asm-use-gpr32 < %s | FileCheck 
%s
+
+; ERR: error: inline assembly requires more registers than available
+
+define void @constraint_jR_test() nounwind "frame-pointer"="all" {

KanRobert wrote:

How does it help? The error should not be related to frame pointer.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -5418,6 +5418,8 @@ X86:
   operand will get allocated only to RAX -- if two 32-bit operands are needed,
   you're better off splitting it yourself, before passing it to the asm
   statement.
+- ``jR``: An 8, 16, 32, or 64-bit integer EGPR when EGPR feature is on.
+  Otherwise, same as ``R``.

KanRobert wrote:

I think no
```
- ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register.
- ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has
  existed since i386, and can be accessed without the REX prefix.
```

`jR` seems weird by the existing conventions. We can change the design before 
we have the real users.

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


[clang] [llvm] [PowerPC] Diagnose musttail instead of crash inside backend (PR #93267)

2024-05-24 Thread Chen Zheng via cfe-commits

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: not llc -mtriple=x86_64 < %s 2>&1 | FileCheck %s --check-prefix=ERR
+; RUN: not llc -mtriple=x86_64 -mattr=+egpr < %s 2>&1 | FileCheck %s 
--check-prefix=ERR
+; RUN: llc -mtriple=x86_64 -mattr=+egpr,+inline-asm-use-gpr32 < %s | FileCheck 
%s

KanRobert wrote:

I find you also extend the `l` constraint. Should we have a test for it? And 
how about `q` https://github.com/llvm/llvm-project/pull/73529 ?

I think it should be extended too.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Freddy Ye via cfe-commits


@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: not llc -mtriple=x86_64 %s 2>&1 | FileCheck %s --check-prefix=ERR
+; RUN: llc -mtriple=x86_64 -mattr=+egpr < %s | FileCheck %s
+; RUN: llc -mtriple=x86_64 -mattr=+egpr,+inline-asm-use-gpr32 < %s | FileCheck 
%s
+
+; ERR: error: inline assembly requires more registers than available
+
+define void @constraint_jR_test() nounwind "frame-pointer"="all" {

FreddyLeaf wrote:

"frame-pointer"="all" helps throw the error here.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Freddy Ye via cfe-commits


@@ -5418,6 +5418,8 @@ X86:
   operand will get allocated only to RAX -- if two 32-bit operands are needed,
   you're better off splitting it yourself, before passing it to the asm
   statement.
+- ``jR``: An 8, 16, 32, or 64-bit integer EGPR when EGPR feature is on.
+  Otherwise, same as ``R``.

FreddyLeaf wrote:

`r` is same as `R` for X86 IIUC. jR is to follow gcc

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


[clang] [alpha.webkit.UncountedLocalVarsChecker] Detect assignments to uncounted local variable and parameters. (PR #92639)

2024-05-24 Thread Ryosuke Niwa via cfe-commits

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


[clang] b80d982 - [alpha.webkit.UncountedLocalVarsChecker] Detect assignments to uncounted local variable and parameters. (#92639)

2024-05-24 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2024-05-24T00:06:06-07:00
New Revision: b80d982a62676314ec93dc8881b9f8957217192a

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

LOG: [alpha.webkit.UncountedLocalVarsChecker] Detect assignments to uncounted 
local variable and parameters. (#92639)

This PR updates alpha.webkit.UncountedLocalVarsChecker to emit warnings
for assignments to uncounted local variable and parameters instead of
just the initialization during the declaration.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp

Removed: 




diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
index 0d9710a5e2d83..274da0baf2ce5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp
@@ -135,7 +135,19 @@ class UncountedLocalVarsChecker
   bool shouldVisitImplicitCode() const { return false; }
 
   bool VisitVarDecl(VarDecl *V) {
-Checker->visitVarDecl(V);
+auto *Init = V->getInit();
+if (Init && V->isLocalVarDecl())
+  Checker->visitVarDecl(V, Init);
+return true;
+  }
+
+  bool VisitBinaryOperator(const BinaryOperator *BO) {
+if (BO->isAssignmentOp()) {
+  if (auto *VarRef = dyn_cast(BO->getLHS())) {
+if (auto *V = dyn_cast(VarRef->getDecl()))
+  Checker->visitVarDecl(V, BO->getRHS());
+  }
+}
 return true;
   }
 
@@ -174,7 +186,7 @@ class UncountedLocalVarsChecker
 visitor.TraverseDecl(const_cast(TUD));
   }
 
-  void visitVarDecl(const VarDecl *V) const {
+  void visitVarDecl(const VarDecl *V, const Expr *Value) const {
 if (shouldSkipVarDecl(V))
   return;
 
@@ -184,12 +196,8 @@ class UncountedLocalVarsChecker
 
 std::optional IsUncountedPtr = isUncountedPtr(ArgType);
 if (IsUncountedPtr && *IsUncountedPtr) {
-  const Expr *const InitExpr = V->getInit();
-  if (!InitExpr)
-return; // FIXME: later on we might warn on uninitialized vars too
-
   if (tryToFindPtrOrigin(
-  InitExpr, /*StopAtFirstRefCountedObj=*/false,
+  Value, /*StopAtFirstRefCountedObj=*/false,
   [&](const clang::Expr *InitArgOrigin, bool IsSafe) {
 if (!InitArgOrigin)
   return true;
@@ -232,34 +240,46 @@ class UncountedLocalVarsChecker
   }))
 return;
 
-  reportBug(V);
+  reportBug(V, Value);
 }
   }
 
   bool shouldSkipVarDecl(const VarDecl *V) const {
 assert(V);
-if (!V->isLocalVarDecl())
-  return true;
-
-if (BR->getSourceManager().isInSystemHeader(V->getLocation()))
-  return true;
-
-return false;
+return BR->getSourceManager().isInSystemHeader(V->getLocation());
   }
 
-  void reportBug(const VarDecl *V) const {
+  void reportBug(const VarDecl *V, const Expr *Value) const {
 assert(V);
 SmallString<100> Buf;
 llvm::raw_svector_ostream Os(Buf);
 
-Os << "Local variable ";
-printQuotedQualifiedName(Os, V);
-Os << " is uncounted and unsafe.";
-
-PathDiagnosticLocation BSLoc(V->getLocation(), BR->getSourceManager());
-auto Report = std::make_unique(Bug, Os.str(), BSLoc);
-Report->addRange(V->getSourceRange());
-BR->emitReport(std::move(Report));
+if (dyn_cast(V)) {
+  Os << "Assignment to an uncounted parameter ";
+  printQuotedQualifiedName(Os, V);
+  Os << " is unsafe.";
+
+  PathDiagnosticLocation BSLoc(Value->getExprLoc(), 
BR->getSourceManager());
+  auto Report = std::make_unique(Bug, Os.str(), BSLoc);
+  Report->addRange(Value->getSourceRange());
+  BR->emitReport(std::move(Report));
+} else {
+  if (V->hasLocalStorage())
+Os << "Local variable ";
+  else if (V->isStaticLocal())
+Os << "Static local variable ";
+  else if (V->hasGlobalStorage())
+Os << "Global variable ";
+  else
+Os << "Variable ";
+  printQuotedQualifiedName(Os, V);
+  Os << " is uncounted and unsafe.";
+
+  PathDiagnosticLocation BSLoc(V->getLocation(), BR->getSourceManager());
+  auto Report = std::make_unique(Bug, Os.str(), BSLoc);
+  Report->addRange(V->getSourceRange());
+  BR->emitReport(std::move(Report));
+}
   }
 };
 } // namespace

diff  --git a/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp
index 632a82eb0d8d1..25776870dd3ae 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp
+++ 

[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: not llc -mtriple=x86_64 < %s 2>&1 | FileCheck %s --check-prefix=ERR
+; RUN: not llc -mtriple=x86_64 -mattr=+egpr < %s 2>&1 | FileCheck %s 
--check-prefix=ERR
+; RUN: llc -mtriple=x86_64 -mattr=+egpr,+inline-asm-use-gpr32 < %s | FileCheck 
%s
+
+; ERR: error: inline assembly requires more registers than available
+
+define void @constraint_r_test() nounwind "frame-pointer"="all" {

KanRobert wrote:

ditto

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: not llc -mtriple=x86_64 %s 2>&1 | FileCheck %s --check-prefix=ERR
+; RUN: llc -mtriple=x86_64 -mattr=+egpr < %s | FileCheck %s
+; RUN: llc -mtriple=x86_64 -mattr=+egpr,+inline-asm-use-gpr32 < %s | FileCheck 
%s
+
+; ERR: error: inline assembly requires more registers than available
+
+define void @constraint_jR_test() nounwind "frame-pointer"="all" {

KanRobert wrote:

Remove "frame-pointer"="all"?

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -58255,6 +58281,22 @@ X86TargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
   }
   break;
 }
+  } else if (Constraint.size() == 2 && Constraint[0] == 'j') {
+switch (Constraint[1]) {
+default:
+  break;
+case 'R':
+  if (VT == MVT::i8 || VT == MVT::i1)
+return std::make_pair(0U, ::GR8RegClass);
+  if (VT == MVT::i16)
+return std::make_pair(0U, ::GR16RegClass);
+  if (VT == MVT::i32 || VT == MVT::f32 ||
+  (!VT.isVector() && !Subtarget.is64Bit()))
+return std::make_pair(0U, ::GR32RegClass);

KanRobert wrote:

The predicate is incorrect.  EGPR is not supported in 32-bit mode.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -58024,15 +58043,22 @@ X86TargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'r':   // GENERAL_REGS
 case 'l':   // INDEX_REGS
   if (VT == MVT::i8 || VT == MVT::i1)
-return std::make_pair(0U, ::GR8_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()
+  ? ::GR8_NOREX2RegClass
+  : ::GR8RegClass);
   if (VT == MVT::i16)
-return std::make_pair(0U, ::GR16_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()
+  ? ::GR16_NOREX2RegClass
+  : ::GR16RegClass);
   if (VT == MVT::i32 || VT == MVT::f32 ||
   (!VT.isVector() && !Subtarget.is64Bit()))
-return std::make_pair(0U, ::GR32_NOREX2RegClass);
+return std::make_pair(0U, Subtarget.useInlineAsmGPR32()

KanRobert wrote:

Need to check hasEGPR() too

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -346,6 +346,9 @@ def FeatureNF : SubtargetFeature<"nf", "HasNF", "true",
  "Support status flags update suppression">;
 def FeatureCF : SubtargetFeature<"cf", "HasCF", "true",
  "Support conditional faulting">;
+def FeatureUseGPR32InInlineAsm
+: SubtargetFeature<"inline-asm-use-gpr32", "UseInlineAsmGPR32", "false",
+   "Enable use of GPR32 in inline assembly for APX">;

KanRobert wrote:

Add `[FeatureEGPR]`

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -5418,6 +5418,8 @@ X86:
   operand will get allocated only to RAX -- if two 32-bit operands are needed,
   you're better off splitting it yourself, before passing it to the asm
   statement.
+- ``jR``: An 8, 16, 32, or 64-bit integer EGPR when EGPR feature is on.
+  Otherwise, same as ``R``.

KanRobert wrote:

I think it's same as `r` instead of `R` if egpr is off. Could I know why we 
design it as  `jR` instead of `jr`?

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


[clang-tools-extra] Clang doc async (PR #93276)

2024-05-24 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 2287f8d2353dadcbe210e07776c927c9fabca57c 
0fa00f0a6064dd0ab42dfd0863ebdcf90daa1742 -- 
clang-tools-extra/clang-doc/HTMLGenerator.cpp 
clang-tools-extra/clang-doc/Representation.h 
clang-tools-extra/clang-doc/Serialize.cpp 
clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index fd3807014f..fb1a7f94c9 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -1047,9 +1047,8 @@ static llvm::Error CopyFile(StringRef FilePath, StringRef 
OutDirectory) {
   std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite);
   if (FileErr != OK) {
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
-   "error creating file " +
-   FilePath +
-   ": " + FileErr.message() + "\n");
+   "error creating file " + FilePath + ": " +
+   FileErr.message() + "\n");
   }
   return llvm::Error::success();
 }
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index 49062af637..3b074d849e 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -32,7 +32,6 @@ populateParentNamespaces(llvm::SmallVector 
,
 
 static void populateMemberTypeInfo(MemberTypeInfo , const FieldDecl *D);
 
-
 // A function to extract the appropriate relative path for a given info's
 // documentation. The path returned is a composite of the parent namespaces.
 //
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index af892b5402..53108a77da 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -156,8 +156,8 @@ Example usage for a project using a compile commands 
database:
   }
 
   // add option to customize url fragment
-  // such as 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-doc/ClangDocMain.cpp#L1
-
+  // such as
+  // 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-doc/ClangDocMain.cpp#L1
 
   // Fail early if an invalid format was provided.
   std::string Format = getFormatString();
@@ -205,7 +205,6 @@ Example usage for a project using a compile commands 
database:
 CDCtx.FilesToCopy.emplace_back(IndexJS.str());
   }
 
-
   // Mapping phase
   llvm::outs() << "Mapping decls...\n";
   auto Err =

``




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


[clang-tools-extra] Clang doc async (PR #93276)

2024-05-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: None (PeterChou1)


Changes

relevant issue: https://github.com/llvm/llvm-project/issues/93273

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


5 Files Affected:

- (modified) clang-tools-extra/clang-doc/HTMLGenerator.cpp (+13-12) 
- (modified) clang-tools-extra/clang-doc/Representation.h (+1) 
- (modified) clang-tools-extra/clang-doc/Serialize.cpp (+1) 
- (modified) clang-tools-extra/clang-doc/assets/index.js (+5-2) 
- (modified) clang-tools-extra/clang-doc/tool/ClangDocMain.cpp (+6-1) 


``diff
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index c0faf5f7e8fd9..fd3807014fd09 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -964,7 +964,7 @@ static llvm::Error SerializeIndex(ClangDocContext ) {
   std::error_code FileErr;
   llvm::SmallString<128> FilePath;
   llvm::sys::path::native(CDCtx.OutDirectory, FilePath);
-  llvm::sys::path::append(FilePath, "index_json.js");
+  llvm::sys::path::append(FilePath, "index.json");
   llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_None);
   if (FileErr != OK) {
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -985,9 +985,7 @@ static llvm::Error SerializeIndex(ClangDocContext ) {
   });
 });
   };
-  OS << "var JsonIndex = `\n";
   IndexToJSON(CDCtx.Idx);
-  OS << "`;\n";
   return llvm::Error::success();
 }
 
@@ -1050,30 +1048,33 @@ static llvm::Error CopyFile(StringRef FilePath, 
StringRef OutDirectory) {
   if (FileErr != OK) {
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"error creating file " +
-   llvm::sys::path::filename(FilePath) +
+   FilePath +
": " + FileErr.message() + "\n");
   }
   return llvm::Error::success();
 }
 
 llvm::Error HTMLGenerator::createResources(ClangDocContext ) {
-  auto Err = SerializeIndex(CDCtx);
-  if (Err)
+  if (auto Err = SerializeIndex(CDCtx)) {
 return Err;
-  Err = GenIndex(CDCtx);
-  if (Err)
+  }
+
+  if (auto Err = GenIndex(CDCtx)) {
 return Err;
+  }
 
   for (const auto  : CDCtx.UserStylesheets) {
-Err = CopyFile(FilePath, CDCtx.OutDirectory);
-if (Err)
+if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) {
   return Err;
+}
   }
+
   for (const auto  : CDCtx.FilesToCopy) {
-Err = CopyFile(FilePath, CDCtx.OutDirectory);
-if (Err)
+if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) {
   return Err;
+}
   }
+
   return llvm::Error::success();
 }
 
diff --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index a6b144eb7fa2a..23323f1cbdf46 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -491,6 +491,7 @@ struct ClangDocContext {
   std::string SourceRoot;   // Directory where processed files are stored. 
Links
 // to definition locations will only be generated 
if
 // the file is in this dir.
+
   // URL of repository that hosts code used for links to definition locations.
   std::optional RepositoryUrl;
   // Path of CSS stylesheets that will be copied to OutDirectory and used to
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index 3b074d849e8a9..49062af637ea0 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -32,6 +32,7 @@ populateParentNamespaces(llvm::SmallVector 
,
 
 static void populateMemberTypeInfo(MemberTypeInfo , const FieldDecl *D);
 
+
 // A function to extract the appropriate relative path for a given info's
 // documentation. The path returned is a composite of the parent namespaces.
 //
diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..b659b20069ac5 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -82,6 +82,9 @@ function createIndex(Index) {
 document.addEventListener("DOMContentLoaded", function() {
   // JsonIndex is a variable from another file that contains the index
   // in JSON format
-  var Index = JSON.parse(JsonIndex);
-  createIndex(Index);
+  fetch("/index.json")
+  .then((response) => response.json())
+  .then((Index) => {
+createIndex(Index);
+  });
 });
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 21b581fa6df2e..af892b5402092 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -155,6 +155,10 @@ Example usage for a project using a compile 

[clang-tools-extra] Clang doc async (PR #93276)

2024-05-24 Thread via cfe-commits

https://github.com/PeterChou1 created 
https://github.com/llvm/llvm-project/pull/93276

relevant issue: https://github.com/llvm/llvm-project/issues/93273

>From 1afdd4f6ef0c6e5caad06425cfa83036880ac08b Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 02:32:44 -0400
Subject: [PATCH 1/2] [clang-doc] make loading of json side bar async

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 25 ++-
 clang-tools-extra/clang-doc/Representation.h  |  2 ++
 clang-tools-extra/clang-doc/Serialize.cpp |  1 +
 clang-tools-extra/clang-doc/assets/index.js   |  7 --
 .../clang-doc/tool/ClangDocMain.cpp   |  7 +-
 5 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index c0faf5f7e8fd9..fd3807014fd09 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -964,7 +964,7 @@ static llvm::Error SerializeIndex(ClangDocContext ) {
   std::error_code FileErr;
   llvm::SmallString<128> FilePath;
   llvm::sys::path::native(CDCtx.OutDirectory, FilePath);
-  llvm::sys::path::append(FilePath, "index_json.js");
+  llvm::sys::path::append(FilePath, "index.json");
   llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_None);
   if (FileErr != OK) {
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -985,9 +985,7 @@ static llvm::Error SerializeIndex(ClangDocContext ) {
   });
 });
   };
-  OS << "var JsonIndex = `\n";
   IndexToJSON(CDCtx.Idx);
-  OS << "`;\n";
   return llvm::Error::success();
 }
 
@@ -1050,30 +1048,33 @@ static llvm::Error CopyFile(StringRef FilePath, 
StringRef OutDirectory) {
   if (FileErr != OK) {
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"error creating file " +
-   llvm::sys::path::filename(FilePath) +
+   FilePath +
": " + FileErr.message() + "\n");
   }
   return llvm::Error::success();
 }
 
 llvm::Error HTMLGenerator::createResources(ClangDocContext ) {
-  auto Err = SerializeIndex(CDCtx);
-  if (Err)
+  if (auto Err = SerializeIndex(CDCtx)) {
 return Err;
-  Err = GenIndex(CDCtx);
-  if (Err)
+  }
+
+  if (auto Err = GenIndex(CDCtx)) {
 return Err;
+  }
 
   for (const auto  : CDCtx.UserStylesheets) {
-Err = CopyFile(FilePath, CDCtx.OutDirectory);
-if (Err)
+if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) {
   return Err;
+}
   }
+
   for (const auto  : CDCtx.FilesToCopy) {
-Err = CopyFile(FilePath, CDCtx.OutDirectory);
-if (Err)
+if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) {
   return Err;
+}
   }
+
   return llvm::Error::success();
 }
 
diff --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index a6b144eb7fa2a..0a9002d21a20b 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -491,6 +491,8 @@ struct ClangDocContext {
   std::string SourceRoot;   // Directory where processed files are stored. 
Links
 // to definition locations will only be generated 
if
 // the file is in this dir.
+
+  std::string LineFragment;
   // URL of repository that hosts code used for links to definition locations.
   std::optional RepositoryUrl;
   // Path of CSS stylesheets that will be copied to OutDirectory and used to
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index 3b074d849e8a9..49062af637ea0 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -32,6 +32,7 @@ populateParentNamespaces(llvm::SmallVector 
,
 
 static void populateMemberTypeInfo(MemberTypeInfo , const FieldDecl *D);
 
+
 // A function to extract the appropriate relative path for a given info's
 // documentation. The path returned is a composite of the parent namespaces.
 //
diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..b659b20069ac5 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -82,6 +82,9 @@ function createIndex(Index) {
 document.addEventListener("DOMContentLoaded", function() {
   // JsonIndex is a variable from another file that contains the index
   // in JSON format
-  var Index = JSON.parse(JsonIndex);
-  createIndex(Index);
+  fetch("/index.json")
+  .then((response) => response.json())
+  .then((Index) => {
+createIndex(Index);
+  });
 });
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 21b581fa6df2e..af892b5402092 100644
--- 

[clang] [llvm] [PowerPC] Diagnose musttail instead of crash inside backend (PR #93267)

2024-05-24 Thread Chen Zheng via cfe-commits


@@ -3833,6 +3833,11 @@ def note_cannot_use_trivial_abi_reason : Note<
   "it is polymorphic|"
   "it has a base of a non-trivial class type|it has a virtual base|"
   "it has a __weak field|it has a field of a non-trivial class type}1">;
+def warn_ppc_musttail_maybe_ignored: Warning<
+  "'musttail' attribute may be ignored on ppc targets">,
+  InGroup;

chenzheng1030 wrote:

Thank you for giving a look. Will update.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits


@@ -5418,6 +5418,8 @@ X86:
   operand will get allocated only to RAX -- if two 32-bit operands are needed,
   you're better off splitting it yourself, before passing it to the asm
   statement.
+- ``jR``: An 8, 16, 32, or 64-bit integer EGPR when EGPR feature is on.

KanRobert wrote:

```suggestion
- ``jR``: An 8, 16, 32, or 64-bit gpr32 if EGPR is enabled.
```

The old statement is misleading b/c EGPR refers to R16-R31 only.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Shengchen Kan via cfe-commits

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Freddy Ye via cfe-commits

FreddyLeaf wrote:

ping @KanRobert 

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-24 Thread Freddy Ye via cfe-commits

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

>From 41fbc18c7a4a26b11bc4b772bbe2e384ad9d9dbc Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Fri, 10 May 2024 16:29:55 +0800
Subject: [PATCH 1/8] [X86] Support EGPR for inline assembly.

"jR": explictly enables EGPR
"r": enables/disables EGPR w/wo -mapx-inline-asm-use-gpr32
-mapx-inline-asm-use-gpr32 will also define a new Macro:
__APX_INLINE_ASM_USE_GPR32__
---
 clang/include/clang/Driver/Options.td |  2 +
 clang/lib/Basic/Targets/X86.cpp   | 26 +
 clang/lib/Basic/Targets/X86.h |  1 +
 clang/lib/Driver/ToolChains/Arch/X86.cpp  |  2 +
 .../Driver/x86-apx-inline-asm-use-gpr32.cpp   |  3 +
 clang/test/Preprocessor/x86_target_features.c |  3 +
 llvm/lib/Target/X86/X86.td|  3 +
 llvm/lib/Target/X86/X86ISelLowering.cpp   | 57 +--
 .../CodeGen/X86/inline-asm-jR-constraint.ll   | 19 +++
 .../CodeGen/X86/inline-asm-r-constraint.ll| 16 ++
 10 files changed, 127 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Driver/x86-apx-inline-asm-use-gpr32.cpp
 create mode 100644 llvm/test/CodeGen/X86/inline-asm-jR-constraint.ll
 create mode 100644 llvm/test/CodeGen/X86/inline-asm-r-constraint.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 73a2518480e9b..20a7c482bbf06 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6281,6 +6281,8 @@ def mno_apx_features_EQ : CommaJoined<["-"], 
"mno-apx-features=">, Group, Alias, 
AliasArgs<["egpr","push2pop2","ppx", "ndd"]>;
 def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd"]>;
+def mapx_inline_asm_use_gpr32 : Flag<["-"], "mapx-inline-asm-use-gpr32">, 
Group,
+HelpText<"Enable use of GPR32 in inline 
assembly for APX">;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 67e2126cf766b..9e61b6e6d6441 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -450,6 +450,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasFullBFloat16 = true;
 } else if (Feature == "+egpr") {
   HasEGPR = true;
+} else if (Feature == "+inline-asm-use-gpr32") {
+  HasInlineAsmUseGPR32 = true;
 } else if (Feature == "+push2pop2") {
   HasPush2Pop2 = true;
 } else if (Feature == "+ppx") {
@@ -974,6 +976,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
   // Condition here is aligned with the feature set of mapxf in Options.td
   if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD)
 Builder.defineMacro("__APX_F__");
+  if (HasInlineAsmUseGPR32)
+Builder.defineMacro("__APX_INLINE_ASM_USE_GPR32__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1493,6 +1497,15 @@ bool X86TargetInfo::validateAsmConstraint(
   case 'C': // SSE floating point constant.
   case 'G': // x87 floating point constant.
 return true;
+  case 'j':
+Name++;
+switch (*Name) {
+default:
+  return false;
+case 'R':
+  Info.setAllowsRegister();
+  return true;
+}
   case '@':
 // CC condition changes.
 if (auto Len = matchAsmCCConstraint(Name)) {
@@ -1764,6 +1777,19 @@ std::string X86TargetInfo::convertConstraint(const char 
*) const {
   // to the next constraint.
   return std::string("^") + std::string(Constraint++, 2);
 }
+  case 'j':
+switch (Constraint[1]) {
+default:
+  // Break from inner switch and fall through (copy single char),
+  // continue parsing after copying the current constraint into
+  // the return string.
+  break;
+case 'R':
+  // "^" hints llvm that this is a 2 letter constraint.
+  // "Constraint++" is used to promote the string iterator
+  // to the next constraint.
+  return std::string("^") + std::string(Constraint++, 2);
+}
 [[fallthrough]];
   default:
 return std::string(1, *Constraint);
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index c14e4d5f433d8..69c68ee80f3ba 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -174,6 +174,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public 
TargetInfo {
   bool HasNDD = false;
   bool HasCCMP = false;
   bool HasCF = false;
+  bool HasInlineAsmUseGPR32 = false;
 
 protected:
   llvm::X86::CPUKind CPU = llvm::X86::CK_None;
diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp 
b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index 53e26a9f8e229..085ff4824a9b0 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -309,4 +309,6 @@ void x86::getX86TargetFeatures(const Driver , const 
llvm::Triple ,
 Features.push_back("+prefer-no-gather");
   if 

[clang] [clang] Macro for constant rounding mode (PR #92699)

2024-05-24 Thread Serge Pavlov via cfe-commits


@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -emit-llvm -triple i386-linux -Wno-unknown-pragmas %s -o - 
| FileCheck %s

spavloff wrote:

Parsing pragma FENV_ROUND has been moved to the preprocessor.

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


[clang] [clang] Macro for constant rounding mode (PR #92699)

2024-05-24 Thread Serge Pavlov via cfe-commits

https://github.com/spavloff updated 
https://github.com/llvm/llvm-project/pull/92699

>From f8cd2539fb7f0388d7f3955f58b61b09da03bf0c Mon Sep 17 00:00:00 2001
From: Serge Pavlov 
Date: Sun, 19 May 2024 18:43:08 +0700
Subject: [PATCH 1/2] [clang] Macro for constant rounding mode
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The forthcoming C standard defines pragma FENV_ROUND to support constant
rounding mode. It also requires some functions to be evaluated with such
mode, N3096 7.6.2p4 states:

Within the scope of an FENV_ROUND pragma establishing a mode other
than FE_DYNAMIC ... invocations of functions indicated in the table
below, for which macro replacement has not been suppressed (7.1.4),
shall be evaluated according to the specified constant rounding mode
... . Invocations of functions for which macro replacement has been
suppressed and invocations of functions other than those indicated
in the table below shall not be affected by constant rounding modes
– they are affected by (and affect) only the dynamic mode.

The way this requirement is formulated indicates that it could be
implemented using preprocessor facility. Such implementation would
require a builtin macro that is set in the region where pragma
FENV_ROUND is in effect and reflects constant rounding mode.

This change introduces macro __ROUNDING_MODE__, which is a string
dependent on the constant rounding mode:

FE_TOWARDZERO"_rtz"
FE_TONEAREST "_rte"
FE_DOWNWARD  "_rtp"
FE_UPWARD"_rtn"
FE_TONEARESTFROMZERO "_rta"
FE_DYNAMIC   empty string

All these values except "_rta" are OpenCL rounding mode modifiers.
Default value, when no pragma FENV_ROUND is specified, is empty string.
Concatenation of a function name with the builtin macro can be used to
obtain name of the function variant for particular rounding mode, like
"sin_rtz", or "__builtin_cos_rtd". The test "macro_rounding_mode.c"
added in this change provides an example of possible use.

The macro is implemented in the same way as FLT_EVAL_METHOD, which also
depends on the results of semantic analysis.
---
 clang/include/clang/Lex/Preprocessor.h| 12 
 clang/lib/Lex/PPMacroExpansion.cpp| 25 +
 clang/lib/Sema/Sema.cpp   |  1 +
 clang/lib/Sema/SemaAttr.cpp   |  1 +
 clang/test/Preprocessor/macro_rounding_mode.c | 55 +++
 5 files changed, 94 insertions(+)
 create mode 100644 clang/test/Preprocessor/macro_rounding_mode.c

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index c0850a8fa9f7f..295633b2e3c73 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -181,6 +181,7 @@ class Preprocessor {
   IdentifierInfo *Ident__is_target_variant_os;
   IdentifierInfo *Ident__is_target_variant_environment;
   IdentifierInfo *Ident__FLT_EVAL_METHOD__;// __FLT_EVAL_METHOD
+  IdentifierInfo *Ident__ROUNDING_MODE__;  // __ROUNDING_MODE__
 
   // Weak, only valid (and set) while InMacroArgs is true.
   Token* ArgMacro;
@@ -201,6 +202,9 @@ class Preprocessor {
   LangOptions::FPEvalMethodKind TUFPEvalMethod =
   LangOptions::FPEvalMethodKind::FEM_UnsetOnCommandLine;
 
+  LangOptions::RoundingMode CurrentRoundingMode =
+  LangOptions::RoundingMode::Dynamic;
+
   // Next __COUNTER__ value, starts at 0.
   unsigned CounterValue = 0;
 
@@ -2356,6 +2360,14 @@ class Preprocessor {
 TUFPEvalMethod = Val;
   }
 
+  LangOptions::RoundingMode getCurrentRoundingMode() const {
+return CurrentRoundingMode;
+  }
+
+  void setCurrentRoundingMode(LangOptions::RoundingMode RM) {
+CurrentRoundingMode = RM;
+  }
+
   /// Retrieves the module that we're currently building, if any.
   Module *getCurrentModule();
 
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 8af4a97d00cb8..519fbfd666375 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -344,6 +344,7 @@ void Preprocessor::RegisterBuiltinMacros() {
   Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__");
   Ident_Pragma  = RegisterBuiltinMacro(*this, "_Pragma");
   Ident__FLT_EVAL_METHOD__ = RegisterBuiltinMacro(*this, 
"__FLT_EVAL_METHOD__");
+  Ident__ROUNDING_MODE__ = RegisterBuiltinMacro(*this, "__ROUNDING_MODE__");
 
   // C++ Standing Document Extensions.
   if (getLangOpts().CPlusPlus)
@@ -1654,6 +1655,30 @@ void Preprocessor::ExpandBuiltinMacro(Token ) {
   Diag(Tok, diag::err_illegal_use_of_flt_eval_macro);
   Diag(getLastFPEvalPragmaLocation(), diag::note_pragma_entered_here);
 }
+  } else if (II == Ident__ROUNDING_MODE__) {
+switch (getCurrentRoundingMode()) {
+case LangOptions::RoundingMode::TowardZero:
+  OS << "_rtz";
+  break;
+case LangOptions::RoundingMode::NearestTiesToEven:
+  OS 

[clang] [Clang] allow `` `@$ `` in raw string delimiters in C++26 (PR #93216)

2024-05-24 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/93216

>From 556c622275c630b74c0f9000c5c599ff665595e1 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Thu, 23 May 2024 18:45:58 +0200
Subject: [PATCH 1/2] [Clang] allow `` `@$ `` in raw string delimiters in C++26

And as an extension in older language modes.

Per https://eel.is/c++draft/lex.string#nt:d-char

Fixes #93130
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/CharInfo.h  | 15 +++---
 .../include/clang/Basic/DiagnosticLexKinds.td |  8 
 clang/lib/Basic/CharInfo.cpp  | 20 +--
 clang/lib/Lex/Lexer.cpp   | 11 +-
 clang/test/Lexer/cxx2c-raw-strings.cpp| 12 +++
 6 files changed, 49 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/Lexer/cxx2c-raw-strings.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7bcdee96e213e..2e298cd9cdb82 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -771,6 +771,7 @@ Bug Fixes to C++ Support
   Fixes (#GH87210), (GH89541).
 - Clang no longer tries to check if an expression is immediate-escalating in 
an unevaluated context.
   Fixes (#GH91308).
+- Clang now allow ``@$``` in raw string literals. Fixes (#GH93130).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Basic/CharInfo.h 
b/clang/include/clang/Basic/CharInfo.h
index d807955311828..4d90528f7992e 100644
--- a/clang/include/clang/Basic/CharInfo.h
+++ b/clang/include/clang/Basic/CharInfo.h
@@ -28,8 +28,7 @@ namespace charinfo {
 CHAR_LOWER= 0x0040,  // a-z
 CHAR_UNDER= 0x0080,  // _
 CHAR_PERIOD   = 0x0100,  // .
-CHAR_RAWDEL   = 0x0200,  // {}[]#<>%:;?*+-/^&|~!=,"'
-CHAR_PUNCT= 0x0400   // `$@()
+CHAR_PUNCT= 0x0200,  // {}[]#<>%:;?*+-/^&|~!=,"'`$@()
   };
 
   enum {
@@ -152,7 +151,8 @@ LLVM_READONLY inline bool isHexDigit(unsigned char c) {
 /// Note that '_' is both a punctuation character and an identifier character!
 LLVM_READONLY inline bool isPunctuation(unsigned char c) {
   using namespace charinfo;
-  return (InfoTable[c] & (CHAR_UNDER|CHAR_PERIOD|CHAR_RAWDEL|CHAR_PUNCT)) != 0;
+  return (InfoTable[c] &
+  (CHAR_UNDER | CHAR_PERIOD | CHAR_PUNCT | CHAR_PUNCT)) != 0;
 }
 
 /// Return true if this character is an ASCII printable character; that is, a
@@ -160,8 +160,8 @@ LLVM_READONLY inline bool isPunctuation(unsigned char c) {
 /// terminal.
 LLVM_READONLY inline bool isPrintable(unsigned char c) {
   using namespace charinfo;
-  return (InfoTable[c] & (CHAR_UPPER|CHAR_LOWER|CHAR_PERIOD|CHAR_PUNCT|
-  CHAR_DIGIT|CHAR_UNDER|CHAR_RAWDEL|CHAR_SPACE)) != 0;
+  return (InfoTable[c] & (CHAR_UPPER | CHAR_LOWER | CHAR_PERIOD | CHAR_PUNCT |
+  CHAR_DIGIT | CHAR_UNDER | CHAR_SPACE)) != 0;
 }
 
 /// Return true if this is the body character of a C preprocessing number,
@@ -175,8 +175,9 @@ LLVM_READONLY inline bool 
isPreprocessingNumberBody(unsigned char c) {
 /// Return true if this is the body character of a C++ raw string delimiter.
 LLVM_READONLY inline bool isRawStringDelimBody(unsigned char c) {
   using namespace charinfo;
-  return (InfoTable[c] & (CHAR_UPPER|CHAR_LOWER|CHAR_PERIOD|
-  CHAR_DIGIT|CHAR_UNDER|CHAR_RAWDEL)) != 0;
+  return (InfoTable[c] & (CHAR_UPPER | CHAR_LOWER | CHAR_PERIOD | CHAR_DIGIT |
+  CHAR_UNDER | CHAR_PUNCT)) != 0 &&
+ c != '(' && c != ')';
 }
 
 enum class EscapeChar {
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ad6bacfb118d4..8411842490c4e 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -111,6 +111,14 @@ def warn_cxx98_compat_raw_string_literal : Warning<
   "raw string literals are incompatible with C++98">,
   InGroup, DefaultIgnore;
 
+def warn_cxx26_compat_raw_string_literal_character_set : Warning<
+  "'%0'in a raw string literal delimiter is incompatible "
+  "with standards before C++2c">,
+  InGroup, DefaultIgnore;
+def ext_cxx26_raw_string_literal_character_set : Extension<
+  "'%0'in a raw string literal delimiter is a C++2c extension">,
+  InGroup, DefaultIgnore;
+
 def warn_multichar_character_literal : Warning<
   "multi-character character constant">, InGroup;
 def warn_four_char_character_literal : Warning<
diff --git a/clang/lib/Basic/CharInfo.cpp b/clang/lib/Basic/CharInfo.cpp
index d02054c9718f5..26d693b8e9b94 100644
--- a/clang/lib/Basic/CharInfo.cpp
+++ b/clang/lib/Basic/CharInfo.cpp
@@ -31,20 +31,20 @@ const uint16_t clang::charinfo::InfoTable[256] = {
   0   , 0   , 0   , 0   ,
   //32 SP 33  ! 34  " 35  #
   //36  $ 37  % 38  & 39  '
-  CHAR_SPACE  , CHAR_RAWDEL , 

[clang] [lld] [llvm] Run ObjCContractPass in Default Codegen Pipeline (PR #92331)

2024-05-24 Thread Nikita Popov via cfe-commits


@@ -31,6 +31,10 @@
 ; CHECK-NEXT:   AArch64 Stack Tagging
 ; CHECK-NEXT:   SME ABI Pass
 ; CHECK-NEXT:   Exception handling preparation
+; CHECK-NEXT:   Dominator Tree Construction
+; CHECK-NEXT:   Basic Alias Analysis (stateless AA impl)
+; CHECK-NEXT:   Function Alias Analysis Results

nikic wrote:

Presumably the extra analysis passes are the reason for the compile-time 
regressions. While you may be skipping the execution of the pass itself, you 
are not skipping the execution of the analyses.

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


[clang] [lld] [llvm] Run ObjCContractPass in Default Codegen Pipeline (PR #92331)

2024-05-24 Thread Nikita Popov via cfe-commits

nikic wrote:

Reverted due to major compile-time regressions for unoptimized builds, see 
https://llvm-compile-time-tracker.com/compare.php?from=910292c3ac2ebe43cdbc90223c6c9702128316db=8cc8e5d6c6ac9bfc888f3449f7e424678deae8c2=instructions:u.

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


[clang] 1579e9c - Revert "Run ObjCContractPass in Default Codegen Pipeline (#92331)"

2024-05-24 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2024-05-24T08:14:26+02:00
New Revision: 1579e9ca9ce17364963861517fecf13b00fe4d8a

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

LOG: Revert "Run ObjCContractPass in Default Codegen Pipeline (#92331)"

This reverts commit 8cc8e5d6c6ac9bfc888f3449f7e424678deae8c2.
This reverts commit dae55c89835347a353619f506ee5c8f8a2c136a7.

Causes major compile-time regressions for unoptimized builds.

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
lld/MachO/LTO.cpp
llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h
llvm/lib/CodeGen/TargetPassConfig.cpp
llvm/lib/LTO/LTOCodeGenerator.cpp
llvm/lib/LTO/ThinLTOCodeGenerator.cpp
llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
llvm/test/CodeGen/AArch64/O0-pipeline.ll
llvm/test/CodeGen/AArch64/O3-pipeline.ll
llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
llvm/test/CodeGen/ARM/O3-pipeline.ll
llvm/test/CodeGen/LoongArch/O0-pipeline.ll
llvm/test/CodeGen/LoongArch/opt-pipeline.ll
llvm/test/CodeGen/M68k/pipeline.ll
llvm/test/CodeGen/PowerPC/O0-pipeline.ll
llvm/test/CodeGen/PowerPC/O3-pipeline.ll
llvm/test/CodeGen/RISCV/O0-pipeline.ll
llvm/test/CodeGen/RISCV/O3-pipeline.ll
llvm/test/CodeGen/X86/O0-pipeline.ll
llvm/test/CodeGen/X86/opt-pipeline.ll

Removed: 
clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll



diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 1f778099a48c1..90985c08fe7f8 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -587,6 +587,12 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager 
,
   // this also adds codegenerator level optimization passes.
   CodeGenFileType CGFT = getCodeGenFileType(Action);
 
+  // Add ObjC ARC final-cleanup optimizations. This is done as part of the
+  // "codegen" passes so that it isn't run multiple times when there is
+  // inlining happening.
+  if (CodeGenOpts.OptimizationLevel > 0)
+CodeGenPasses.add(createObjCARCContractPass());
+
   if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT,
   /*DisableVerify=*/!CodeGenOpts.VerifyModule)) {
 Diags.Report(diag::err_fe_unable_to_interface_with_target);

diff  --git a/clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll 
b/clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll
deleted file mode 100644
index a2a7b62cb7f93..0
--- a/clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll
+++ /dev/null
@@ -1,19 +0,0 @@
-; RUN: opt -thinlto-bc -o %t.o %s
-
-; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
-; RUN:   -o %t2.index \
-; RUN:   -r=%t.o,_use_arc,px
-
-; RUN: %clang_cc1 -triple x86_64-apple-darwin \
-; RUN:   -emit-obj -fthinlto-index=%t.o.thinlto.bc \
-; RUN:   -o %t.native.o -x ir %t.o
-
-target datalayout = 
"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-apple-darwin"
-
-define void @use_arc(ptr %a, ptr %b) {
-  call void (...) @llvm.objc.clang.arc.use(ptr %a, ptr %b) nounwind
-  ret void
-}
-
-declare void @llvm.objc.clang.arc.use(...) nounwind

diff  --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp
index 6527cbb68f249..7a9a9223a0322 100644
--- a/lld/MachO/LTO.cpp
+++ b/lld/MachO/LTO.cpp
@@ -48,6 +48,9 @@ static lto::Config createConfig() {
   c.CPU = getCPUStr();
   c.MAttrs = getMAttrs();
   c.DiagHandler = diagnosticHandler;
+  c.PreCodeGenPassesHook = [](legacy::PassManager ) {
+pm.add(createObjCARCContractPass());
+  };
 
   c.AlwaysEmitRegularLTOObj = !config->ltoObjPath.empty();
 

diff  --git a/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h 
b/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h
index 5ac6ad47f7799..ccf859922e163 100644
--- a/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h
+++ b/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h
@@ -41,26 +41,26 @@ extern bool EnableARCOpts;
 /// Test if the given module looks interesting to run ARC optimization
 /// on.
 inline bool ModuleHasARC(const Module ) {
-  return M.getNamedValue("llvm.objc.retain") ||
- M.getNamedValue("llvm.objc.release") ||
- M.getNamedValue("llvm.objc.autorelease") ||
- M.getNamedValue("llvm.objc.retainAutoreleasedReturnValue") ||
- M.getNamedValue("llvm.objc.unsafeClaimAutoreleasedReturnValue") ||
- M.getNamedValue("llvm.objc.retainBlock") ||
- M.getNamedValue("llvm.objc.autoreleaseReturnValue") ||
- M.getNamedValue("llvm.objc.autoreleasePoolPush") ||
- M.getNamedValue("llvm.objc.loadWeakRetained") ||
- M.getNamedValue("llvm.objc.loadWeak") ||
- M.getNamedValue("llvm.objc.destroyWeak") ||
- M.getNamedValue("llvm.objc.storeWeak") ||
- 

[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-05-24 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/66462

>From 32010ae7e0a47cd4a70a9401980b32ed1d3e10f6 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Fri, 15 Sep 2023 11:33:53 +0800
Subject: [PATCH] [clangd] [C++20] [Modules] Introduce initial support for
 C++20 Modules

Alternatives to https://reviews.llvm.org/D153114.

Try to address https://github.com/clangd/clangd/issues/1293.

See the links for design ideas. We want to have some initial support in
clang18.

This is the initial support for C++20 Modules in clangd.
As suggested by sammccall in https://reviews.llvm.org/D153114,
we should minimize the scope of the initial patch to make it easier
to review and understand so that every one are in the same page:

> Don't attempt any cross-file or cross-version coordination: i.e. don't
> try to reuse BMIs between different files, don't try to reuse BMIs
> between (preamble) reparses of the same file, don't try to persist the
> module graph. Instead, when building a preamble, synchronously scan
> for the module graph, build the required PCMs on the single preamble
> thread with filenames private to that preamble, and then proceed to
> build the preamble.

And this patch reflects the above opinions.
---
 clang-tools-extra/clangd/CMakeLists.txt   |   4 +
 clang-tools-extra/clangd/ClangdServer.cpp |   2 +
 clang-tools-extra/clangd/ClangdServer.h   |   3 +
 .../clangd/GlobalCompilationDatabase.cpp  |  23 ++
 .../clangd/GlobalCompilationDatabase.h|  14 +
 .../clangd/ModuleDependencyScanner.cpp|  81 +
 .../clangd/ModuleDependencyScanner.h  | 106 ++
 clang-tools-extra/clangd/ModulesBuilder.cpp   | 339 ++
 clang-tools-extra/clangd/ModulesBuilder.h |  71 
 clang-tools-extra/clangd/ParsedAST.cpp|   7 +
 clang-tools-extra/clangd/Preamble.cpp |  28 +-
 clang-tools-extra/clangd/Preamble.h   |  10 +
 .../clangd/PrerequisiteModules.h  |  87 +
 clang-tools-extra/clangd/ProjectModules.cpp   |  62 
 clang-tools-extra/clangd/ProjectModules.h |  55 +++
 clang-tools-extra/clangd/TUScheduler.cpp  |  50 ++-
 clang-tools-extra/clangd/TUScheduler.h|   7 +
 clang-tools-extra/clangd/test/CMakeLists.txt  |   1 +
 clang-tools-extra/clangd/test/modules.test|  83 +
 clang-tools-extra/clangd/tool/Check.cpp   |  13 +-
 clang-tools-extra/clangd/tool/ClangdMain.cpp  |   8 +
 .../clangd/unittests/CMakeLists.txt   |   2 +
 .../clangd/unittests/CodeCompleteTests.cpp|  22 +-
 .../clangd/unittests/FileIndexTests.cpp   |   4 +-
 .../unittests/ModuleDependencyScannerTest.cpp | 176 +
 .../clangd/unittests/ModulesTestSetup.h   | 103 ++
 .../clangd/unittests/ParsedASTTests.cpp   |   8 +-
 .../clangd/unittests/PreambleTests.cpp|   6 +-
 .../unittests/PrerequisiteModulesTest.cpp | 224 
 clang-tools-extra/clangd/unittests/TestTU.cpp |  14 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +
 31 files changed, 1576 insertions(+), 40 deletions(-)
 create mode 100644 clang-tools-extra/clangd/ModuleDependencyScanner.cpp
 create mode 100644 clang-tools-extra/clangd/ModuleDependencyScanner.h
 create mode 100644 clang-tools-extra/clangd/ModulesBuilder.cpp
 create mode 100644 clang-tools-extra/clangd/ModulesBuilder.h
 create mode 100644 clang-tools-extra/clangd/PrerequisiteModules.h
 create mode 100644 clang-tools-extra/clangd/ProjectModules.cpp
 create mode 100644 clang-tools-extra/clangd/ProjectModules.h
 create mode 100644 clang-tools-extra/clangd/test/modules.test
 create mode 100644 
clang-tools-extra/clangd/unittests/ModuleDependencyScannerTest.cpp
 create mode 100644 clang-tools-extra/clangd/unittests/ModulesTestSetup.h
 create mode 100644 
clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp

diff --git a/clang-tools-extra/clangd/CMakeLists.txt 
b/clang-tools-extra/clangd/CMakeLists.txt
index 3911fb6c6c746..242a8ad2e350b 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -97,7 +97,10 @@ add_clang_library(clangDaemon
   IncludeFixer.cpp
   InlayHints.cpp
   JSONTransport.cpp
+  ModuleDependencyScanner.cpp
+  ModulesBuilder.cpp
   PathMapping.cpp
+  ProjectModules.cpp
   Protocol.cpp
   Quality.cpp
   ParsedAST.cpp
@@ -161,6 +164,7 @@ clang_target_link_libraries(clangDaemon
   clangAST
   clangASTMatchers
   clangBasic
+  clangDependencyScanning
   clangDriver
   clangFormat
   clangFrontend
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 13d788162817f..8ba4b38c420ab 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -202,6 +202,7 @@ ClangdServer::Options::operator TUScheduler::Options() 
const {
   Opts.UpdateDebounce = UpdateDebounce;
   Opts.ContextProvider = ContextProvider;
   Opts.PreambleThrottler = PreambleThrottler;
+  

[clang] [clang][ASTImporter] Fix possible crash "given incorrect InsertPos for specialization". (PR #89887)

2024-05-24 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> A test is needed to make the change acceptable but I could not find an easy 
> case to provoke the situation. The problem looks to be related to his code:
> 
> ```c++
> using size_t = int;
> template class tuple;
> 
> template
> struct integral_constant
> {
> static constexpr T value = v;
> using value_type = T;
> using type = integral_constant; // using injected-class-name
> constexpr operator value_type() const noexcept { return value; }
> constexpr value_type operator()() const noexcept { return value; } // 
> since c++14
> };
> 
> using true_type = integral_constant;
> using false_type = integral_constant;
> 
> template
> struct is_same : false_type {};
>  
> template
> struct is_same : true_type {};
> 
> template< class T, class U >
> inline constexpr bool is_same_v = is_same::value;
> 
> namespace A {
>   template
>   struct __tuple_count;
> 
>   template
> inline constexpr size_t __tuple_count_v =
>   __tuple_count<_Tp, _Tuple>::value;
> 
>   template
> struct __tuple_count<_Tp, tuple<_Types...>>
> : integral_constant { };
> 
>   template
> struct __tuple_count<_Tp, tuple<_First, _Rest...>>
> : integral_constant<
>   size_t,
>   __tuple_count_v<_Tp, tuple<_Rest...>> + is_same_v<_Tp, _First>> { };
> };
> 
> 
> size_t x = A::__tuple_count_v>;
> ```

Could you please show your commands which reproduced this crash? I tested 
locally with the following commands and it runs OK.
```cpp
clang++ -cc1 -std=c++17 -emit-pch -o test.cpp.ast test.cpp
clang++ -cc1 -x c++ -ast-merge test.cpp.ast  /dev/null -ast-dump
```

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


[clang] [webkit.RefCntblBaseVirtualDtor] Allow CRTP classes without a virtual destructor. (PR #92837)

2024-05-24 Thread Ryosuke Niwa via cfe-commits

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

>From 9c2ae2b2b14d27270589f3775df95a7547e74c83 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Mon, 20 May 2024 16:12:44 -0700
Subject: [PATCH 1/3] [webkit.RefCntblBaseVirtualDtor] Allow CRTP classes
 without a virtual destructor.

Exempt CRTP (Curiously Recurring Template Pattern) classes with a delete 
operation
acting on "this" pointer with an appropriate cast from the requirement that
a ref-countable superclass must have a virtual destructor.

To do this, this PR introduces new DerefAnalysisVisitor, which looks for a 
delete
operation with an explicit cast to the derived class in a base class.

This PR also changes the checker so that we only check a given class's immediate
base class instead of all ancestor base classes in the class hierarchy. This is
sufficient because the checker will eventually see the definition for every 
class
in the class hierarchy and transitively proves every ref-counted base class has
a virtual destructor or deref function which casts this pointer back to the 
derived
class before deleting. Without this change, we would keep traversing the same 
list
of base classes whenever we encounter a new subclass, which is wholly 
unnecessary.

It's possible for DerefAnalysisVisitor to come to a conclusoin that there isn't
enough information to determine whether a given templated superclass invokes 
delete
operation on a subclass when the template isn't fully specialized for the 
subclass.
In this case, we return std::nullopt in HasSpecializedDelete, and 
visitCXXRecordDecl
will skip this declaration. This is okay because the checker will eventually see
a concreate fully specialized class definition if it ever gets instantiated.
---
 .../WebKit/RefCntblBaseVirtualDtorChecker.cpp | 311 +
 ...virtual-dtor-ref-deref-on-diff-classes.cpp |   1 +
 .../ref-cntbl-base-virtual-dtor-templates.cpp | 324 +-
 3 files changed, 567 insertions(+), 69 deletions(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
index 7f4c3a7b787e8..efb7b4456f2ca 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -11,16 +11,134 @@
 #include "PtrTypesSemantics.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SetVector.h"
 #include 
 
 using namespace clang;
 using namespace ento;
 
 namespace {
+
+class DerefAnalysisVisitor
+: public ConstStmtVisitor {
+  // Returns true if any of child statements return true.
+  bool VisitChildren(const Stmt *S) {
+for (const Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+
+  bool VisitBody(const Stmt *Body) {
+if (!Body)
+  return false;
+
+auto [It, IsNew] = VisitedBody.insert(Body);
+if (!IsNew) // This body is recursive
+  return false;
+
+return Visit(Body);
+  }
+
+public:
+  DerefAnalysisVisitor(const TemplateArgumentList ,
+   const CXXRecordDecl *ClassDecl)
+  : ArgList(), ClassDecl(ClassDecl) {}
+
+  DerefAnalysisVisitor(const CXXRecordDecl *ClassDecl) : ClassDecl(ClassDecl) 
{}
+
+  std::optional HasSpecializedDelete(CXXMethodDecl *Decl) {
+if (auto *Body = Decl->getBody())
+  return VisitBody(Body);
+if (auto *Tmpl = Decl->getTemplateInstantiationPattern())
+  return std::nullopt; // Indeterminate. There was no concrete instance.
+return false;
+  }
+
+  bool VisitCallExpr(const CallExpr *CE) {
+auto *Callee = CE->getCallee();
+while (auto *Expr = dyn_cast(Callee))
+  Callee = Expr->getSubExpr();
+if (auto *DeclRef = dyn_cast(Callee)) {
+  auto *Decl = DeclRef->getDecl();
+  if (auto *VD = dyn_cast(Decl)) {
+if (auto *Init = VD->getInit()) {
+  if (auto *Lambda = dyn_cast(Init))
+return VisitBody(Lambda->getBody());
+}
+  } else if (auto *FD = dyn_cast(Decl))
+return VisitBody(FD->getBody());
+}
+return false;
+  }
+
+  bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *MCE) {
+auto *Callee = MCE->getMethodDecl();
+if (!Callee)
+  return false;
+return VisitBody(Callee->getBody());
+  }
+
+  bool VisitCXXDeleteExpr(const CXXDeleteExpr *E) {
+auto *Arg = E->getArgument();
+while (Arg) {
+  if (auto *Paren = dyn_cast(Arg))
+Arg = Paren->getSubExpr();
+  else if (auto *Cast = dyn_cast(Arg)) {

[clang] [webkit.RefCntblBaseVirtualDtor] Allow CRTP classes without a virtual destructor. (PR #92837)

2024-05-23 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 72200fcc346bee1830d9e640e42d717a55acd74c 
69103682e29b58b09da7773e205875b9c75f830e -- 
clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor-ref-deref-on-diff-classes.cpp
 clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor-templates.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
index 4547ffd800..72a7363204 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -173,7 +173,7 @@ public:
 continue;
 
   if (auto *CTSD = dyn_cast(C)) {
-for (auto& Arg : CTSD->getTemplateArgs().asArray()) {
+for (auto  : CTSD->getTemplateArgs().asArray()) {
   if (Arg.getKind() != TemplateArgument::Type)
 continue;
   auto TemplT = Arg.getAsType();

``




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


[clang] [webkit.RefCntblBaseVirtualDtor] Allow CRTP classes without a virtual destructor. (PR #92837)

2024-05-23 Thread Ryosuke Niwa via cfe-commits

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

>From 9c2ae2b2b14d27270589f3775df95a7547e74c83 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Mon, 20 May 2024 16:12:44 -0700
Subject: [PATCH 1/2] [webkit.RefCntblBaseVirtualDtor] Allow CRTP classes
 without a virtual destructor.

Exempt CRTP (Curiously Recurring Template Pattern) classes with a delete 
operation
acting on "this" pointer with an appropriate cast from the requirement that
a ref-countable superclass must have a virtual destructor.

To do this, this PR introduces new DerefAnalysisVisitor, which looks for a 
delete
operation with an explicit cast to the derived class in a base class.

This PR also changes the checker so that we only check a given class's immediate
base class instead of all ancestor base classes in the class hierarchy. This is
sufficient because the checker will eventually see the definition for every 
class
in the class hierarchy and transitively proves every ref-counted base class has
a virtual destructor or deref function which casts this pointer back to the 
derived
class before deleting. Without this change, we would keep traversing the same 
list
of base classes whenever we encounter a new subclass, which is wholly 
unnecessary.

It's possible for DerefAnalysisVisitor to come to a conclusoin that there isn't
enough information to determine whether a given templated superclass invokes 
delete
operation on a subclass when the template isn't fully specialized for the 
subclass.
In this case, we return std::nullopt in HasSpecializedDelete, and 
visitCXXRecordDecl
will skip this declaration. This is okay because the checker will eventually see
a concreate fully specialized class definition if it ever gets instantiated.
---
 .../WebKit/RefCntblBaseVirtualDtorChecker.cpp | 311 +
 ...virtual-dtor-ref-deref-on-diff-classes.cpp |   1 +
 .../ref-cntbl-base-virtual-dtor-templates.cpp | 324 +-
 3 files changed, 567 insertions(+), 69 deletions(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
index 7f4c3a7b787e8..efb7b4456f2ca 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -11,16 +11,134 @@
 #include "PtrTypesSemantics.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SetVector.h"
 #include 
 
 using namespace clang;
 using namespace ento;
 
 namespace {
+
+class DerefAnalysisVisitor
+: public ConstStmtVisitor {
+  // Returns true if any of child statements return true.
+  bool VisitChildren(const Stmt *S) {
+for (const Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+
+  bool VisitBody(const Stmt *Body) {
+if (!Body)
+  return false;
+
+auto [It, IsNew] = VisitedBody.insert(Body);
+if (!IsNew) // This body is recursive
+  return false;
+
+return Visit(Body);
+  }
+
+public:
+  DerefAnalysisVisitor(const TemplateArgumentList ,
+   const CXXRecordDecl *ClassDecl)
+  : ArgList(), ClassDecl(ClassDecl) {}
+
+  DerefAnalysisVisitor(const CXXRecordDecl *ClassDecl) : ClassDecl(ClassDecl) 
{}
+
+  std::optional HasSpecializedDelete(CXXMethodDecl *Decl) {
+if (auto *Body = Decl->getBody())
+  return VisitBody(Body);
+if (auto *Tmpl = Decl->getTemplateInstantiationPattern())
+  return std::nullopt; // Indeterminate. There was no concrete instance.
+return false;
+  }
+
+  bool VisitCallExpr(const CallExpr *CE) {
+auto *Callee = CE->getCallee();
+while (auto *Expr = dyn_cast(Callee))
+  Callee = Expr->getSubExpr();
+if (auto *DeclRef = dyn_cast(Callee)) {
+  auto *Decl = DeclRef->getDecl();
+  if (auto *VD = dyn_cast(Decl)) {
+if (auto *Init = VD->getInit()) {
+  if (auto *Lambda = dyn_cast(Init))
+return VisitBody(Lambda->getBody());
+}
+  } else if (auto *FD = dyn_cast(Decl))
+return VisitBody(FD->getBody());
+}
+return false;
+  }
+
+  bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *MCE) {
+auto *Callee = MCE->getMethodDecl();
+if (!Callee)
+  return false;
+return VisitBody(Callee->getBody());
+  }
+
+  bool VisitCXXDeleteExpr(const CXXDeleteExpr *E) {
+auto *Arg = E->getArgument();
+while (Arg) {
+  if (auto *Paren = dyn_cast(Arg))
+Arg = Paren->getSubExpr();
+  else if (auto *Cast = dyn_cast(Arg)) {

[clang] [webkit.RefCntblBaseVirtualDtor] Allow CRTP classes without a virtual destructor. (PR #92837)

2024-05-23 Thread Ryosuke Niwa via cfe-commits


@@ -11,16 +11,134 @@
 #include "PtrTypesSemantics.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SetVector.h"
 #include 
 
 using namespace clang;
 using namespace ento;
 
 namespace {
+
+class DerefAnalysisVisitor
+: public ConstStmtVisitor {
+  // Returns true if any of child statements return true.
+  bool VisitChildren(const Stmt *S) {
+for (const Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+
+  bool VisitBody(const Stmt *Body) {
+if (!Body)
+  return false;
+
+auto [It, IsNew] = VisitedBody.insert(Body);
+if (!IsNew) // This body is recursive

rniwa wrote:

Actually, the only way we'd hit this code path is if the function is recursive 
and we're still in the middle of recursively visiting the function definition 
so the best we can do here is to return false (since we haven't finished 
traversing the function body yet).

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


[clang] [webkit.RefCntblBaseVirtualDtor] Allow CRTP classes without a virtual destructor. (PR #92837)

2024-05-23 Thread Ryosuke Niwa via cfe-commits


@@ -11,16 +11,134 @@
 #include "PtrTypesSemantics.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SetVector.h"
 #include 
 
 using namespace clang;
 using namespace ento;
 
 namespace {
+
+class DerefAnalysisVisitor
+: public ConstStmtVisitor {
+  // Returns true if any of child statements return true.
+  bool VisitChildren(const Stmt *S) {
+for (const Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+
+  bool VisitBody(const Stmt *Body) {
+if (!Body)
+  return false;
+
+auto [It, IsNew] = VisitedBody.insert(Body);
+if (!IsNew) // This body is recursive
+  return false;
+
+return Visit(Body);
+  }
+
+public:
+  DerefAnalysisVisitor(const TemplateArgumentList ,
+   const CXXRecordDecl *ClassDecl)
+  : ArgList(), ClassDecl(ClassDecl) {}
+
+  DerefAnalysisVisitor(const CXXRecordDecl *ClassDecl) : ClassDecl(ClassDecl) 
{}
+
+  std::optional HasSpecializedDelete(CXXMethodDecl *Decl) {
+if (auto *Body = Decl->getBody())
+  return VisitBody(Body);
+if (auto *Tmpl = Decl->getTemplateInstantiationPattern())
+  return std::nullopt; // Indeterminate. There was no concrete instance.
+return false;
+  }
+
+  bool VisitCallExpr(const CallExpr *CE) {
+auto *Callee = CE->getCallee();
+while (auto *Expr = dyn_cast(Callee))
+  Callee = Expr->getSubExpr();
+if (auto *DeclRef = dyn_cast(Callee)) {
+  auto *Decl = DeclRef->getDecl();
+  if (auto *VD = dyn_cast(Decl)) {
+if (auto *Init = VD->getInit()) {

rniwa wrote:

Oh I see. Indeed, it looks like we can get away with just:
```cpp
  bool VisitCallExpr(const CallExpr *CE) {
const Decl *D = CE->getCalleeDecl();
if (D && D->hasBody())
  return VisitBody(D->getBody());
return false;
  }
```

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


[clang] [llvm] Reland "[X86] Remove knl/knm specific ISAs supports (#92883)" (PR #93136)

2024-05-23 Thread Freddy Ye via cfe-commits

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


[clang] [llvm] Reland "[X86] Remove knl/knm specific ISAs supports (#92883)" (PR #93136)

2024-05-23 Thread Phoebe Wang via cfe-commits

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

LGTM.

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


  1   2   3   4   5   6   7   8   9   10   >