[PATCH] D158158: [clang] Set FP options in Sema when instantiating CompoundStmt

2023-08-20 Thread Serge Pavlov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0baf85c33109: [clang] Set FP options in Sema when 
instantiating CompoundStmt (authored by sepavloff).

Changed prior to commit:
  https://reviews.llvm.org/D158158?vs=551044=551902#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158158

Files:
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/template-64605.cpp


Index: clang/test/SemaCXX/template-64605.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/template-64605.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -ast-dump -ast-dump-filter=b_64605 %s | FileCheck %s
+
+// https://github.com/llvm/llvm-project/issues/64605
+
+#pragma STDC FENV_ACCESS ON
+template 
+int b_64605() {
+  int x;
+  if ((float)0x != (float)0x1) {
+x = 1;
+  }
+  return x;
+}
+int f() { return b_64605(); }
+
+// CHECK:  ImplicitCastExpr {{.*}} 'float'  
RoundingMath=1 AllowFEnvAccess=1
+// CHECK-NEXT: IntegerLiteral {{.*}} 4294967295
+
+// CHECK:  FunctionDecl {{.*}} b_64605 'int ()' implicit_instantiation
+// CHECK-NEXT: TemplateArgument type 'void'
+
+// CHECK:  ImplicitCastExpr {{.*}} 'float'  
RoundingMath=1 AllowFEnvAccess=1
+// CHECK-NEXT: IntegerLiteral {{.*}} 4294967295
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -7491,6 +7491,10 @@
 TreeTransform::TransformCompoundStmt(CompoundStmt *S,
   bool IsStmtExpr) {
   Sema::CompoundScopeRAII CompoundScope(getSema());
+  Sema::FPFeaturesStateRAII FPSave(getSema());
+  if (S->hasStoredFPFeatures())
+getSema().resetFPOptions(
+S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
 
   const Stmt *ExprResult = S->getStmtExprResult();
   bool SubStmtInvalid = false;


Index: clang/test/SemaCXX/template-64605.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/template-64605.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -ast-dump -ast-dump-filter=b_64605 %s | FileCheck %s
+
+// https://github.com/llvm/llvm-project/issues/64605
+
+#pragma STDC FENV_ACCESS ON
+template 
+int b_64605() {
+  int x;
+  if ((float)0x != (float)0x1) {
+x = 1;
+  }
+  return x;
+}
+int f() { return b_64605(); }
+
+// CHECK:  ImplicitCastExpr {{.*}} 'float'  RoundingMath=1 AllowFEnvAccess=1
+// CHECK-NEXT: IntegerLiteral {{.*}} 4294967295
+
+// CHECK:  FunctionDecl {{.*}} b_64605 'int ()' implicit_instantiation
+// CHECK-NEXT: TemplateArgument type 'void'
+
+// CHECK:  ImplicitCastExpr {{.*}} 'float'  RoundingMath=1 AllowFEnvAccess=1
+// CHECK-NEXT: IntegerLiteral {{.*}} 4294967295
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -7491,6 +7491,10 @@
 TreeTransform::TransformCompoundStmt(CompoundStmt *S,
   bool IsStmtExpr) {
   Sema::CompoundScopeRAII CompoundScope(getSema());
+  Sema::FPFeaturesStateRAII FPSave(getSema());
+  if (S->hasStoredFPFeatures())
+getSema().resetFPOptions(
+S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
 
   const Stmt *ExprResult = S->getStmtExprResult();
   bool SubStmtInvalid = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0baf85c - [clang] Set FP options in Sema when instantiating CompoundStmt

2023-08-20 Thread Serge Pavlov via cfe-commits

Author: Serge Pavlov
Date: 2023-08-21T12:36:41+07:00
New Revision: 0baf85c331090fbe2d2b42214ed0664d55feb0b5

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

LOG: [clang] Set FP options in Sema when instantiating CompoundStmt

When an expression is instantiated, TreeTransform skips ImplicitCastExpr
nodes, assuming they are recreated when the instantiated expression is
built. It breaks functions that use non-default floating-point options,
because they are kept in these ImplicitCastExprs. In this case the
recreated ImplicitCastExpr takes FP options from the current Sema state
and not from AST node.

To fix this issue the FP options in Sema object are set when a compound
statement is cloned in TreeTransform.

This change fixes https://github.com/llvm/llvm-project/issues/64605
([Regression 16 -> 17] Template instantiation ignores FENV_ACCESS being
ON for both definition and instantiation).

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

Added: 
clang/test/SemaCXX/template-64605.cpp

Modified: 
clang/lib/Sema/TreeTransform.h

Removed: 




diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 1f41bbb189df26..769811c2772c6f 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -7491,6 +7491,10 @@ StmtResult
 TreeTransform::TransformCompoundStmt(CompoundStmt *S,
   bool IsStmtExpr) {
   Sema::CompoundScopeRAII CompoundScope(getSema());
+  Sema::FPFeaturesStateRAII FPSave(getSema());
+  if (S->hasStoredFPFeatures())
+getSema().resetFPOptions(
+S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
 
   const Stmt *ExprResult = S->getStmtExprResult();
   bool SubStmtInvalid = false;

diff  --git a/clang/test/SemaCXX/template-64605.cpp 
b/clang/test/SemaCXX/template-64605.cpp
new file mode 100644
index 00..b13acbf2ae566b
--- /dev/null
+++ b/clang/test/SemaCXX/template-64605.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -ast-dump -ast-dump-filter=b_64605 %s | FileCheck %s
+
+// https://github.com/llvm/llvm-project/issues/64605
+
+#pragma STDC FENV_ACCESS ON
+template 
+int b_64605() {
+  int x;
+  if ((float)0x != (float)0x1) {
+x = 1;
+  }
+  return x;
+}
+int f() { return b_64605(); }
+
+// CHECK:  ImplicitCastExpr {{.*}} 'float'  
RoundingMath=1 AllowFEnvAccess=1
+// CHECK-NEXT: IntegerLiteral {{.*}} 4294967295
+
+// CHECK:  FunctionDecl {{.*}} b_64605 'int ()' implicit_instantiation
+// CHECK-NEXT: TemplateArgument type 'void'
+
+// CHECK:  ImplicitCastExpr {{.*}} 'float'  
RoundingMath=1 AllowFEnvAccess=1
+// CHECK-NEXT: IntegerLiteral {{.*}} 4294967295



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


[PATCH] D158329: [X86] Support arch=x86-64{,-v2,-v3,-v4} for target_clones attribute

2023-08-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked an inline comment as done.
MaskRay added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:13318-13320
+Value *Idxs[] = {Builder.getInt32(0), Builder.getInt32(i - 1)};
+Value *Features = Builder.CreateAlignedLoad(
+Int32Ty, Builder.CreateGEP(ATy, CpuFeatures2, Idxs),

MaskRay wrote:
> pengfei wrote:
> > MaskRay wrote:
> > > pengfei wrote:
> > > > Do we have problem when linking with old version of libgcc?
> > > If we don't use `__cpu_features2[1..3]`, no problem with older libgcc.
> > > 
> > > The way GCC upgraded `__cpu_features2` to an array is compatible with 
> > > scalar `__cpu_features2`.
> > I assume GCC seldom links to older libgcc, but there's no guarantee Clang 
> > can link to latest libgcc.
> > And we cannot assume user won't use it once the method provided.
> > I don't have a good idea for it, but I think we should write the 
> > requirement done in release note or somewhere if we cannot find a better 
> > way.
> The way we treat `__cpu_features2` as an array is compatible with older 
> libgcc providing scalar `__cpu_features2`, as long as we don't access the 
> high bits (`FEATURE_X86_64_{BASELINE,V2,V3,V4}`).
> 
> * When `arch=x86-64` is used, this patch changes a compiler crash to (if 
> newer libgcc, work; if older libgcc, runtime crash)
> * When `arch=x86-64*` is unused, the same as before.
I think a release note isn't really necessary as the compatibility story with 
this patch is strictly better than the current state.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158329

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


[PATCH] D158329: [X86] Support arch=x86-64{,-v2,-v3,-v4} for target_clones attribute

2023-08-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:13318-13320
+Value *Idxs[] = {Builder.getInt32(0), Builder.getInt32(i - 1)};
+Value *Features = Builder.CreateAlignedLoad(
+Int32Ty, Builder.CreateGEP(ATy, CpuFeatures2, Idxs),

pengfei wrote:
> MaskRay wrote:
> > pengfei wrote:
> > > Do we have problem when linking with old version of libgcc?
> > If we don't use `__cpu_features2[1..3]`, no problem with older libgcc.
> > 
> > The way GCC upgraded `__cpu_features2` to an array is compatible with 
> > scalar `__cpu_features2`.
> I assume GCC seldom links to older libgcc, but there's no guarantee Clang can 
> link to latest libgcc.
> And we cannot assume user won't use it once the method provided.
> I don't have a good idea for it, but I think we should write the requirement 
> done in release note or somewhere if we cannot find a better way.
The way we treat `__cpu_features2` as an array is compatible with older libgcc 
providing scalar `__cpu_features2`, as long as we don't access the high bits 
(`FEATURE_X86_64_{BASELINE,V2,V3,V4}`).

* When `arch=x86-64` is used, this patch changes a compiler crash to (if newer 
libgcc, work; if older libgcc, runtime crash)
* When `arch=x86-64*` is unused, the same as before.



Comment at: compiler-rt/lib/builtins/cpu_model.c:167
+  FEATURE_WP,
+  FEATURE_LZCNT = 57,
+  FEATURE_MOVBE,

FreddyYe wrote:
> ` = 57` redundant
Thanks. Minor issue, I've fixed it locally and will only upload a new diff if 
other things need changing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158329

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


[clang] 6f31908 - [StaticAnalyzer] Modernize InvalidationInfo (NFC)

2023-08-20 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-08-20T22:08:04-07:00
New Revision: 6f31908d20131953b266f44a05b93971475dd2ad

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

LOG: [StaticAnalyzer] Modernize InvalidationInfo (NFC)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
index 3496af731aa683..f0276a57bdf98e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
@@ -64,12 +64,12 @@ class IvarInvalidationCheckerImpl {
 
   struct InvalidationInfo {
 /// Has the ivar been invalidated?
-bool IsInvalidated;
+bool IsInvalidated = false;
 
 /// The methods which can be used to invalidate the ivar.
 MethodSet InvalidationMethods;
 
-InvalidationInfo() : IsInvalidated(false) {}
+InvalidationInfo() = default;
 void addInvalidationMethod(const ObjCMethodDecl *MD) {
   InvalidationMethods.insert(MD);
 }



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


[clang] 848be08 - [StaticAnalyzer] Modernize DeleteBugVisitor (NFC)

2023-08-20 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-08-20T22:08:02-07:00
New Revision: 848be088658da0d07680e129a6a7f79a7f31d2f3

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

LOG: [StaticAnalyzer] Modernize DeleteBugVisitor (NFC)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp

Removed: 




diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
index 7c583376200803..3c142b49ff7288 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
@@ -40,7 +40,7 @@ class DeleteWithNonVirtualDtorChecker
 
   class DeleteBugVisitor : public BugReporterVisitor {
   public:
-DeleteBugVisitor() : Satisfied(false) {}
+DeleteBugVisitor() = default;
 void Profile(llvm::FoldingSetNodeID ) const override {
   static int X = 0;
   ID.AddPointer();
@@ -50,7 +50,7 @@ class DeleteWithNonVirtualDtorChecker
  PathSensitiveBugReport ) override;
 
   private:
-bool Satisfied;
+bool Satisfied = false;
   };
 
 public:



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


[clang] abed823 - [Sema] Modernize UsageInfo (NFC)

2023-08-20 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-08-20T22:07:58-07:00
New Revision: abed823dfe6b2cc337f5d20109b519db901e09af

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

LOG: [Sema] Modernize UsageInfo (NFC)

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 9f8b0ab928e84b..660c0b55df892d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -15906,9 +15906,9 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
 Usage Uses[UK_Count];
 
 /// Have we issued a diagnostic for this object already?
-bool Diagnosed;
+bool Diagnosed = false;
 
-UsageInfo() : Diagnosed(false) {}
+UsageInfo() = default;
   };
   using UsageInfoMap = llvm::SmallDenseMap;
 



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


[clang] 760e0c3 - [StaticAnalyzer] Modernize CFNumberChecker (NFC)

2023-08-20 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-08-20T22:08:01-07:00
New Revision: 760e0c353787d73a02c609d8abed7ed75baed7df

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

LOG: [StaticAnalyzer] Modernize CFNumberChecker (NFC)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
index 4a5b8913c22fd6..93679a86966f45 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -352,9 +352,9 @@ void NilArgChecker::checkPostStmt(const 
ObjCDictionaryLiteral *DL,
 namespace {
 class CFNumberChecker : public Checker< check::PreStmt > {
   mutable std::unique_ptr BT;
-  mutable IdentifierInfo *ICreate, *IGetValue;
+  mutable IdentifierInfo *ICreate = nullptr, *IGetValue = nullptr;
 public:
-  CFNumberChecker() : ICreate(nullptr), IGetValue(nullptr) {}
+  CFNumberChecker() = default;
 
   void checkPreStmt(const CallExpr *CE, CheckerContext ) const;
 };



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


[clang] 9b987e0 - [Sema] Modernize ShadowMapEntry (NFC)

2023-08-20 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-08-20T22:07:59-07:00
New Revision: 9b987e08963dc001f1447e80fa77c17b3e612d68

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

LOG: [Sema] Modernize ShadowMapEntry (NFC)

Added: 


Modified: 
clang/lib/Sema/SemaCodeComplete.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index e3a2a21386e72c..2a3de571c4c428 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -98,10 +98,10 @@ class ResultBuilder {
 
 /// When the entry contains a single declaration, this is
 /// the index associated with that entry.
-unsigned SingleDeclIndex;
+unsigned SingleDeclIndex = 0;
 
   public:
-ShadowMapEntry() : SingleDeclIndex(0) {}
+ShadowMapEntry() = default;
 ShadowMapEntry(const ShadowMapEntry &) = delete;
 ShadowMapEntry(ShadowMapEntry &) { *this = std::move(Move); }
 ShadowMapEntry =(const ShadowMapEntry &) = delete;



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


[PATCH] D158329: [X86] Support arch=x86-64{,-v2,-v3,-v4} for target_clones attribute

2023-08-20 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added inline comments.



Comment at: compiler-rt/lib/builtins/cpu_model.c:167
+  FEATURE_WP,
+  FEATURE_LZCNT = 57,
+  FEATURE_MOVBE,

` = 57` redundant


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158329

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


[PATCH] D158218: [CMake] Deprecate DEFAULT_SYSROOT and GCC_INSTALL_PREFIX

2023-08-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/CMakeLists.txt:179-183
+if(DEFAULT_SYSROOT)
+  message(WARNING "DEFAULT_SYSROOT is deprecated and will be removed. Use "
+"configuration files 
(https://clang.llvm.org/docs/UsersManual.html#configuration-files)"
+"to specify the default --sysroot=")
+endif()

bcain wrote:
> MaskRay wrote:
> > MaskRay wrote:
> > > bcain wrote:
> > > > MaskRay wrote:
> > > > > bcain wrote:
> > > > > > At one time I believe that the clang configuration files could not 
> > > > > > specify paths relative to the clang executable.  AFAICT 
> > > > > > `DEFAULT_SYSROOT` does support this.
> > > > > > 
> > > > > > But if I'm mistaken about that can we add an example to the docs at 
> > > > > > https://clang.llvm.org/docs/UsersManual.html#configuration-files 
> > > > > > illustrating how to use a relative sysroot?
> > > > > Clang configuration files just complement user-specified command line 
> > > > > options. As one can do `--sysroot=./sysroot`, one can add 
> > > > > `--sysroot=./sysroot` to a configuration file, too.
> > > > > 
> > > > > If you think having a sysroot example is useful, I can add
> > > > > 
> > > > > ```
> > > > > # Relative --sysroot
> > > > > --sysroot=./sysroot
> > > > > ```
> > > > > before
> > > > > clang/docs/UsersManual.rst:1018 `-c --target=x86_64-unknown-linux-gnu`
> > > > IIUC: when clang takes a `--sysroot=./sysroot` argument, it will 
> > > > interpret that path as a prefix to the files it wants to access.  So 
> > > > the system will treat it as relative to the environment's `cwd`, 
> > > > correct?
> > > > 
> > > > But when `DEFAULT_SYSROOT` is set to a relative path, that relative 
> > > > path is considered to be relative to `clang`.  Therefore a convenient 
> > > > feature that we take advantage of is setting it to something like 
> > > > `../target/hexagon-unknown-linux-musl` in order to have anyone who 
> > > > invokes `hexagon-unknown-linux-clang` from any path be able to find the 
> > > > includes and libraries distributed with the toolchain without having to 
> > > > specify the sysroot.
> > > > 
> > > > Maybe there's a better way to achieve this without the need for a 
> > > > relative `DEFAULT_SYSROOT` but it's been very useful and the config 
> > > > files do not seem suited to replace it.
> > > `--sysroot=` is used as a prefix to certain files, primarily libc and GCC 
> > > installations.
> > > 
> > > `-DDEFAULT_SYSROOT=...` just changes `clang/lib/Driver/Driver.cpp:203` 
> > > `SysRoot(DEFAULT_SYSROOT)`.
> > > There is no magic related to the `clang` executable path. CMake doesn't 
> > > do any magic, either.
> > Ah, sorry. There is magic: D76653 (@sbc100).
> > Ah, sorry. There is magic: D76653 (@sbc100).
> 
> Okay, so should we abandon the plan to deprecate `DEFAULT_SYSROOT`?  Or could 
> we add a corresponding feature to config files if we want to get rid of it?
The way relative `DEFAULT_SYSROOT` looks strange to me as it is not exactly 
equivalent to user-specified `--sysroot=`. I hope that there is a way to 
achieve @sbc100's goal.

I think a proper mechanism will take time, and we probably can just deprecated 
`GCC_INSTALL_PREFIX` for now.
And I wish that RHEL/CentOS can migrate to a modern practice.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158218

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


[PATCH] D158378: [Driver] move Minix header search path management to the driver

2023-08-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D158378#4602375 , @brad wrote:

> In D158378#4602289 , @MaskRay wrote:
>
>> Thank you for driving the migration!
>>
>>   case llvm::Triple::Minix:
>> AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
>> "", "", "", triple);
>>
>> The GCC 4.4.3 thing is from 3e2ee147d0ddb23592b2ec8294381b5e1801cc62 (2010). 
>> https://github.com/Stichting-MINIX-Research-Foundation/minix and 
>> https://git.minix3.org/index.cgi?p=minix.git haven't had any commit since 
>> 2018.
>> We haven't seen any actual Minix driver changes for many years. I think it 
>> unlikely works and perhaps we should remove Minix driver support.
>
> Ya, I should have noticed that. I had heard years ago that Minix had switched 
> to Clang. I installed the latest in a VM and it does come with Clang. Clang 
> 3.6.

Thanks. 3.6 is so old. Given many things like `CompilerRT-Generic` that 
unlikely works, I think it's better to remove `Minix.cpp`.
If the Minix community makes efforts to add back llvm-project support, starting 
from scratch with proper testing is likely better than the current 
nearly-untested state...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158378

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


[PATCH] D152423: [RISCV] Add function that check extension name with version

2023-08-20 Thread Piyou Chen via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4b60e1e821b4: [RISCV] Add function that check extension name 
with version (authored by BeMg).
Herald added a subscriber: sunshaoce.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152423

Files:
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/unittests/Support/RISCVISAInfoTest.cpp


Index: llvm/unittests/Support/RISCVISAInfoTest.cpp
===
--- llvm/unittests/Support/RISCVISAInfoTest.cpp
+++ llvm/unittests/Support/RISCVISAInfoTest.cpp
@@ -604,3 +604,25 @@
   EXPECT_EQ(ExtsRV64IDZce.count("zcmp"), 1U);
   EXPECT_EQ(ExtsRV64IDZce.count("zcmt"), 1U);
 }
+
+TEST(isSupportedExtensionWithVersion, AcceptsSingleExtensionWithVersion) {
+  EXPECT_TRUE(RISCVISAInfo::isSupportedExtensionWithVersion("zbb1p0"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zbb"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zfoo1p0"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zfoo"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion(""));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("c2p0zbb1p0"));
+}
+
+TEST(getTargetFeatureForExtension, RetrieveTargetFeatureFromOneExt) {
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zbb"), "zbb");
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zicond1p0"),
+"experimental-zicond");
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zicond"),
+"experimental-zicond");
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zihintntl1234p4321"),
+"");
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zfoo"), "");
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension(""), "");
+  EXPECT_EQ(RISCVISAInfo::getTargetFeatureForExtension("zbbzihintntl"), "");
+}
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -1253,3 +1253,40 @@
   }
   llvm_unreachable("Invalid XLEN");
 }
+
+bool RISCVISAInfo::isSupportedExtensionWithVersion(StringRef Ext) {
+  if (Ext.empty())
+return false;
+
+  auto Pos = findLastNonVersionCharacter(Ext) + 1;
+  StringRef Name = Ext.substr(0, Pos);
+  StringRef Vers = Ext.substr(Pos);
+  if (Vers.empty())
+return false;
+
+  unsigned Major, Minor, ConsumeLength;
+  if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
+   true, true)) {
+consumeError(std::move(E));
+return false;
+  }
+
+  return true;
+}
+
+std::string RISCVISAInfo::getTargetFeatureForExtension(StringRef Ext) {
+  if (Ext.empty())
+return std::string();
+
+  auto Pos = findLastNonVersionCharacter(Ext) + 1;
+  StringRef Name = Ext.substr(0, Pos);
+
+  if (Pos != Ext.size() && !isSupportedExtensionWithVersion(Ext))
+return std::string();
+
+  if (!isSupportedExtension(Name))
+return std::string();
+
+  return isExperimentalExtension(Name) ? "experimental-" + Name.str()
+   : Name.str();
+}
Index: llvm/include/llvm/Support/RISCVISAInfo.h
===
--- llvm/include/llvm/Support/RISCVISAInfo.h
+++ llvm/include/llvm/Support/RISCVISAInfo.h
@@ -85,10 +85,12 @@
 
   static bool isSupportedExtensionFeature(StringRef Ext);
   static bool isSupportedExtension(StringRef Ext);
+  static bool isSupportedExtensionWithVersion(StringRef Ext);
   static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
unsigned MinorVersion);
   static llvm::Expected>
   postProcessAndChecking(std::unique_ptr &);
+  static std::string getTargetFeatureForExtension(StringRef Ext);
 
 private:
   RISCVISAInfo(unsigned XLen)


Index: llvm/unittests/Support/RISCVISAInfoTest.cpp
===
--- llvm/unittests/Support/RISCVISAInfoTest.cpp
+++ llvm/unittests/Support/RISCVISAInfoTest.cpp
@@ -604,3 +604,25 @@
   EXPECT_EQ(ExtsRV64IDZce.count("zcmp"), 1U);
   EXPECT_EQ(ExtsRV64IDZce.count("zcmt"), 1U);
 }
+
+TEST(isSupportedExtensionWithVersion, AcceptsSingleExtensionWithVersion) {
+  EXPECT_TRUE(RISCVISAInfo::isSupportedExtensionWithVersion("zbb1p0"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zbb"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zfoo1p0"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("zfoo"));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion(""));
+  EXPECT_FALSE(RISCVISAInfo::isSupportedExtensionWithVersion("c2p0zbb1p0"));
+}
+
+TEST(getTargetFeatureForExtension, 

[PATCH] D112921: [clang] Enable sized deallocation by default in C++14 onwards

2023-08-20 Thread Wang Pengcheng via Phabricator via cfe-commits
wangpc updated this revision to Diff 551890.
wangpc added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112921

Files:
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/SizedDeallocation.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/lib/Driver/ToolChains/ZOS.cpp
  clang/test/AST/ast-dump-expr-json.cpp
  clang/test/AST/ast-dump-expr.cpp
  clang/test/AST/ast-dump-stmt-json.cpp
  clang/test/Analysis/cxxnewexpr-callback.cpp
  
clang/test/CXX/basic/basic.stc/basic.stc.dynamic/basic.stc.dynamic.deallocation/p2.cpp
  clang/test/CXX/expr/expr.unary/expr.new/p14.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
  clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
  clang/test/CodeGenCXX/delete-two-arg.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/new.cpp
  clang/test/CodeGenCoroutines/coro-aligned-alloc-2.cpp
  clang/test/CodeGenCoroutines/coro-aligned-alloc.cpp
  clang/test/CodeGenCoroutines/coro-alloc.cpp
  clang/test/CodeGenCoroutines/coro-cleanup.cpp
  clang/test/CodeGenCoroutines/coro-dealloc.cpp
  clang/test/CodeGenCoroutines/coro-gro.cpp
  clang/test/CodeGenCoroutines/pr56919.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/PCH/cxx1z-aligned-alloc.cpp
  clang/test/SemaCXX/MicrosoftExtensions.cpp
  clang/test/SemaCXX/builtin-operator-new-delete.cpp
  clang/test/SemaCXX/cxx1y-sized-deallocation.cpp
  clang/test/SemaCXX/unavailable_aligned_allocation.cpp
  clang/unittests/StaticAnalyzer/CallEventTest.cpp
  clang/www/cxx_status.html
  libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp

Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp
@@ -8,11 +8,13 @@
 
 // test sized operator delete replacement.
 
+// TODO(mordante) fix this test after updating clang in Docker
+// UNSUPPORTED: clang-15, clang-16, clang-17, clang-18
 // UNSUPPORTED: sanitizer-new-delete, c++03, c++11
+// XFAIL: apple-clang
 
-// NOTE: Clang does not enable sized-deallocation in C++14 and beyond by
-// default. It is only enabled when -fsized-deallocation is given.
-// XFAIL: clang, apple-clang
+// Sized deallocation was added in macOS 10.12 and aligned OSes.
+// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11}}
 
 #include 
 #include 
Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp
@@ -8,11 +8,13 @@
 
 // test sized operator delete[] replacement.
 
+// TODO(mordante) fix this test after updating clang in Docker
+// UNSUPPORTED: clang-15, clang-16, clang-17, clang-18
 // UNSUPPORTED: sanitizer-new-delete, c++03, c++11
+// XFAIL: apple-clang
 
-// NOTE: Clang does not enable sized-deallocation in C++14 and beyond by
-// default. It is only enabled when -fsized-deallocation is given.
-// XFAIL: clang, apple-clang
+// Sized deallocation was added in macOS 10.12 and aligned OSes.
+// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11}}
 
 #include 
 #include 
Index: libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
===
--- libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
+++ libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
@@ -25,6 +25,9 @@
 // GCC doesn't support the aligned-allocation flags.
 // XFAIL: gcc
 
+// TODO(mordante) fix this test after updating clang in Docker
+// UNSUPPORTED: clang-15, clang-16, clang-17, clang-18
+
 // RUN: %{build} -faligned-allocation -fsized-deallocation
 // RUN: %{run}
 // RUN: %{build} -faligned-allocation -fno-sized-deallocation -DNO_SIZE
Index: clang/www/cxx_status.html

[PATCH] D153114: [clangd] [C++20] [Modules] Support C++20 modules for clangd

2023-08-20 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

@sammccall Hi, Sam. Thanks for your high-quality comments! It is valuable. All 
the low-level inline comments are helpful. But I didn't reply them for the 
suggested direction in the higher level comments.

I'll repeat your suggestion in my mind again to avoid any misunderstandings:

While we should leave the space for future development, we should do the 
following thing in the initial patch:

> 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.

Do I understand right? If I understand correctly, I fully agree with the 
direction. We can go slowly, as long as we keep moving forward.

Then I'd like to leave the patch as-is for referencing and create new patches 
following the suggestion.


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

https://reviews.llvm.org/D153114

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


[PATCH] D158385: [tsan] Respect !nosanitize metadata and remove gcov special case

2023-08-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: Sanitizers, dvyukov, melver, vitalybuka, Enna1.
Herald added a subscriber: hiraditya.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Certain instrumentations set the !nosanitize metadata for inserted
instructions, which are generally not interested for sanitizers. Skip
tsan instrumentation like we do for asan (D126294 
)/msan/hwasan.

-fprofile-arcs instrumentation has data race unless
-fprofile-update=atomic is specified. Let's remove the the `__llvm_gcov`
special case from commit 0222adbcd25779a156399bcc16fde9f6d083a809 (2016)
as the racy instructions have the !nosanitize metadata.
(-fprofile-arcs instrumentation does not use `__llvm_gcda` as global variables.)

  std::atomic c;
  void foo() { c++; }
  int main() {
std::thread th(foo);
c++;
th.join();
  }

Tested that `clang++ --coverage -fsanitize=thread a.cc && ./a.out` does
not report spurious tsan errors.

Also remove the default CC1 option -fprofile-update=atomic for
-fsanitize=thread to make options more orthogonal.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158385

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/code-coverage-tsan.c
  clang/test/Driver/fprofile-update.c
  llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
  llvm/test/Instrumentation/ThreadSanitizer/do-not-instrument-memory-access.ll

Index: llvm/test/Instrumentation/ThreadSanitizer/do-not-instrument-memory-access.ll
===
--- llvm/test/Instrumentation/ThreadSanitizer/do-not-instrument-memory-access.ll
+++ llvm/test/Instrumentation/ThreadSanitizer/do-not-instrument-memory-access.ll
@@ -1,6 +1,6 @@
 ; This test checks that we are not instrumenting unwanted acesses to globals:
+; - Instructions with the !nosanitize metadata (e.g. -fprofile-arcs instrumented counter accesses)
 ; - Instruction profiler counter instrumentation has known intended races.
-; - The gcov counters array has a known intended race.
 ;
 ; RUN: opt < %s -passes='function(tsan),module(tsan-module)' -S | FileCheck %s
 
@@ -18,42 +18,44 @@
 
 define i32 @test_gep() sanitize_thread {
 entry:
-  %pgocount = load i64, ptr @__profc_test_gep
+  %pgocount = load i64, ptr @__profc_test_gep, !nosanitize !0
   %0 = add i64 %pgocount, 1
-  store i64 %0, ptr @__profc_test_gep
+  store i64 %0, ptr @__profc_test_gep, !nosanitize !0
 
-  %gcovcount = load i64, ptr @__llvm_gcov_ctr
+  %gcovcount = load i64, ptr @__llvm_gcov_ctr, !nosanitize !0
   %1 = add i64 %gcovcount, 1
-  store i64 %1, ptr @__llvm_gcov_ctr
+  store i64 %1, ptr @__llvm_gcov_ctr, !nosanitize !0
 
-  %gcovcount.1 = load i64, ptr @__llvm_gcov_ctr.1
+  %gcovcount.1 = load i64, ptr @__llvm_gcov_ctr.1, !nosanitize !0
   %2 = add i64 %gcovcount.1, 1
-  store i64 %2, ptr @__llvm_gcov_ctr.1
+  store i64 %2, ptr @__llvm_gcov_ctr.1, !nosanitize !0
 
   ret i32 1
 }
 
 define i32 @test_bitcast() sanitize_thread {
 entry:
-  %0 = load <2 x i64>, ptr @__profc_test_bitcast, align 8
-  %.promoted5 = load i64, ptr @__profc_test_bitcast_foo, align 8
+  %0 = load <2 x i64>, ptr @__profc_test_bitcast, align 8, !nosanitize !0
+  %.promoted5 = load i64, ptr @__profc_test_bitcast_foo, align 8, !nosanitize !0
   %1 = add i64 %.promoted5, 10
   %2 = add <2 x i64> %0, 
-  store <2 x i64> %2, ptr @__profc_test_bitcast, align 8
-  store i64 %1, ptr @__profc_test_bitcast_foo, align 8
+  store <2 x i64> %2, ptr @__profc_test_bitcast, align 8, !nosanitize !0
+  store i64 %1, ptr @__profc_test_bitcast_foo, align 8, !nosanitize !0
   ret i32 undef
 }
 
 define void @test_load() sanitize_thread {
 entry:
-  %0 = load i32, ptr @__llvm_gcov_global_state_pred
-  store i32 1, ptr @__llvm_gcov_global_state_pred
+  %0 = load i32, ptr @__llvm_gcov_global_state_pred, !nosanitize !0
+  store i32 1, ptr @__llvm_gcov_global_state_pred, !nosanitize !0
 
-  %1 = load i32, ptr @__llvm_gcda_foo
-  store i32 1, ptr @__llvm_gcda_foo
+  %1 = load i32, ptr @__llvm_gcda_foo, !nosanitize !0
+  store i32 1, ptr @__llvm_gcda_foo, !nosanitize !0
 
   ret void
 }
 
+!0 = !{}
+
 ; CHECK-NOT: {{call void @__tsan_write}}
 ; CHECK: __tsan_init
Index: llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
@@ -364,11 +364,6 @@
   getInstrProfSectionName(IPSK_cnts, OF, /*AddSegmentInfo=*/false)))
 return false;
 }
-
-// Check if the global is private gcov data.
-if (GV->getName().startswith("__llvm_gcov") ||
-GV->getName().startswith("__llvm_gcda"))
-  return false;
   }
 
   // Do not instrument accesses from different address spaces; we cannot deal
@@ -522,6 +517,9 @@
   

[PATCH] D158378: [Driver] move Minix header search path management to the driver

2023-08-20 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

In D158378#4602289 , @MaskRay wrote:

> Thank you for driving the migration!
>
>   case llvm::Triple::Minix:
> AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
> "", "", "", triple);
>
> The GCC 4.4.3 thing is from 3e2ee147d0ddb23592b2ec8294381b5e1801cc62 (2010). 
> https://github.com/Stichting-MINIX-Research-Foundation/minix and 
> https://git.minix3.org/index.cgi?p=minix.git haven't had any commit since 
> 2018.
> We haven't seen any actual Minix driver changes for many years. I think it 
> unlikely works and perhaps we should remove Minix driver support.

Ya, I should have noticed that. I had heard years ago that Minix had switched 
to Clang. I installed the latest in a VM and it does come with Clang. Clang 3.6.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158378

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


[PATCH] D157956: [clangd] don't add inlay hint for dependent type in structured binding

2023-08-20 Thread Vincent Hong via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdc10bd43a103: [clangd] dont add inlay hint for 
dependent type in structured binding (authored by v1nh1shungry).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157956

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


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1353,6 +1353,11 @@
   // FIXME: It would be nice to show "T" as the hint.
   auto $var2[[var2]] = arg;
 }
+
+template 
+void bar(T arg) {
+  auto [a, b] = arg;
+}
   )cpp");
 }
 
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -733,7 +733,8 @@
 // For structured bindings, print canonical types. This is important
 // because for bindings that use the tuple_element protocol, the
 // non-canonical types would be "tuple_element::type".
-if (auto Type = Binding->getType(); !Type.isNull())
+if (auto Type = Binding->getType();
+!Type.isNull() && !Type->isDependentType())
   addTypeHint(Binding->getLocation(), Type.getCanonicalType(),
   /*Prefix=*/": ");
   }


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1353,6 +1353,11 @@
   // FIXME: It would be nice to show "T" as the hint.
   auto $var2[[var2]] = arg;
 }
+
+template 
+void bar(T arg) {
+  auto [a, b] = arg;
+}
   )cpp");
 }
 
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -733,7 +733,8 @@
 // For structured bindings, print canonical types. This is important
 // because for bindings that use the tuple_element protocol, the
 // non-canonical types would be "tuple_element::type".
-if (auto Type = Binding->getType(); !Type.isNull())
+if (auto Type = Binding->getType();
+!Type.isNull() && !Type->isDependentType())
   addTypeHint(Binding->getLocation(), Type.getCanonicalType(),
   /*Prefix=*/": ");
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] dc10bd4 - [clangd] don't add inlay hint for dependent type in structured binding

2023-08-20 Thread Yuanjing Hong via cfe-commits

Author: Yuanjing Hong
Date: 2023-08-21T11:10:40+08:00
New Revision: dc10bd43a103d0e252c4fb4d30913f99b4f418fe

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

LOG: [clangd] don't add inlay hint for dependent type in structured binding

Currently clangd will display useless inlay hint for dependent type in
structured binding, e.g.

```
template 
void foobar(T arg) {
  auto [a/*: */, b/*: */] = arg;
}
```

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index d403269f5a68f4..56f85ee155cb23 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -733,7 +733,8 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 // For structured bindings, print canonical types. This is important
 // because for bindings that use the tuple_element protocol, the
 // non-canonical types would be "tuple_element::type".
-if (auto Type = Binding->getType(); !Type.isNull())
+if (auto Type = Binding->getType();
+!Type.isNull() && !Type->isDependentType())
   addTypeHint(Binding->getLocation(), Type.getCanonicalType(),
   /*Prefix=*/": ");
   }

diff  --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 3c1e6c826ec259..1d12db3661c9eb 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1353,6 +1353,11 @@ TEST(TypeHints, DependentType) {
   // FIXME: It would be nice to show "T" as the hint.
   auto $var2[[var2]] = arg;
 }
+
+template 
+void bar(T arg) {
+  auto [a, b] = arg;
+}
   )cpp");
 }
 



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


[PATCH] D158259: [clang][RISCV] Support operators for RVV sizeless vector types

2023-08-20 Thread Jianjian Guan via Phabricator via cfe-commits
jacquesguan marked an inline comment as done.
jacquesguan added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:14906
+// specified
+if (S.Context.areCompatibleRVVTypes(QualType(OriginalTarget, 0),
+QualType(Source, 0)) ||

craig.topper wrote:
> Why do we need this, but SVE doesn't?
Merged with the former sve function.



Comment at: clang/lib/Sema/SemaExpr.cpp:12294
 
+  if ((LHSBuiltinTy && LHSBuiltinTy->isSVEBool()) ||
+  (RHSBuiltinTy && RHSBuiltinTy->isSVEBool())) {

craig.topper wrote:
> This code looks identical to the code above it.
Removed.



Comment at: clang/lib/Sema/SemaExpr.cpp:16322
   break;
-else if (resultType->isSveVLSBuiltinType()) // SVE vectors allow + and -
+else if (resultType->isVLSBuiltinType()) // SVE vectors allow + and -
   break;

craig.topper wrote:
> Update "SVE" to mention "RVV" too?
Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158259

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


[PATCH] D78441: Delete NaCl support

2023-08-20 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

In D78441#4593287 , @dschuff wrote:

> Deprecation is progressing 
> (https://groups.google.com/a/chromium.org/g/chromium-extensions/c/v8H1UHnPotY/m/NmzrIv_VBAAJ)
>  but we are still supporting it on some platforms, (and using clang's 
> upstream support), so we aren't there yet.

Ok, it's a bit confusing with different dates in different spots. So according 
to that the mainstream OS (Win/macOS/Linux) releases of Chromium will drop 
support by Dec 2023 just leaving ChromeOS support.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78441

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


[PATCH] D157956: [clangd] don't add inlay hint for dependent type in structured binding

2023-08-20 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry added a comment.

Thank you for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157956

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


[PATCH] D157130: [RISCV] Check type size for lax conversions between RVV builtin types and VectorType::RVVFixedLengthDataVector.

2023-08-20 Thread Jianjian Guan via Phabricator via cfe-commits
jacquesguan accepted this revision.
jacquesguan added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157130

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


[PATCH] D158378: [Driver] move Minix header search path management to the driver

2023-08-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Thank you for driving the migration!

  case llvm::Triple::Minix:
AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
"", "", "", triple);

The GCC 4.4.3 thing is from 3e2ee147d0ddb23592b2ec8294381b5e1801cc62 (2010). 
https://github.com/Stichting-MINIX-Research-Foundation/minix and 
https://git.minix3.org/index.cgi?p=minix.git haven't had any commit since 2018.
We haven't seen any actual Minix driver changes for many years. I think it 
unlikely works and perhaps we should remove Minix driver support.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158378

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


[PATCH] D158046: [X86] Support -march=gracemont

2023-08-20 Thread Freddy, Ye via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6acff5390d05: [X86] Support -march=gracemont (authored by 
FreddyYe).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158046

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

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -36,6 +36,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake-s 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake_s 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=lunarlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=gracemont 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=nocona 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=core2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
@@ -98,6 +99,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=arrowlake-s 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=arrowlake_s 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=lunarlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=gracemont 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 define void @foo() {
   ret void
Index: llvm/lib/TargetParser/X86TargetParser.cpp
===
--- llvm/lib/TargetParser/X86TargetParser.cpp
+++ llvm/lib/TargetParser/X86TargetParser.cpp
@@ -430,6 +430,8 @@
   { {"arrowlake_s"}, CK_ArrowlakeS, FEATURE_AVX2, FeaturesArrowlakeS, 'p', true },
   // Lunarlake microarchitecture based processors.
   { {"lunarlake"}, CK_Lunarlake, FEATURE_AVX2, FeaturesArrowlakeS, 'p', false },
+  // Gracemont microarchitecture based processors.
+  { {"gracemont"}, CK_Gracemont, FEATURE_AVX2, FeaturesAlderlake, 'p', false },
   // Sierraforest microarchitecture based processors.
   { {"sierraforest"}, CK_Sierraforest, FEATURE_AVX2, FeaturesSierraforest, 'p', false },
   // Grandridge microarchitecture based processors.
Index: llvm/lib/TargetParser/Host.cpp
===
--- llvm/lib/TargetParser/Host.cpp
+++ llvm/lib/TargetParser/Host.cpp
@@ -822,6 +822,8 @@
 // Alderlake:
 case 0x97:
 case 0x9a:
+// Gracemont
+case 0xbe:
 // Raptorlake:
 case 0xb7:
 case 0xba:
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -1207,6 +1207,18 @@
   list ADLFeatures =
 !listconcat(TRMFeatures, ADLAdditionalFeatures);
 
+  // Gracemont
+  list GRTTuning = [TuningMacroFusion,
+  TuningSlow3OpsLEA,
+  TuningSlowDivide32,
+  TuningSlowDivide64,
+  TuningFastScalarFSQRT,
+  TuningFastVectorFSQRT,
+  TuningFast15ByteNOP,
+  TuningFastVariablePerLaneShuffle,
+  TuningPOPCNTFalseDeps,
+  TuningInsertVZEROUPPER];
+
   // Sierraforest
   list SRFAdditionalFeatures = [FeatureCMPCCXADD,
   FeatureAVXIFMA,
@@ -1728,6 +1740,9 @@
 ProcessorFeatures.SPRFeatures, ProcessorFeatures.SPRTuning>;
 def : ProcModel<"alderlake", AlderlakePModel,
 ProcessorFeatures.ADLFeatures, ProcessorFeatures.ADLTuning>;
+// FIXME: Use 

[clang] 6acff53 - [X86] Support -march=gracemont

2023-08-20 Thread Freddy Ye via cfe-commits

Author: Freddy Ye
Date: 2023-08-21T08:49:01+08:00
New Revision: 6acff5390d0504ef0e805a7266a48398fb67876c

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

LOG: [X86] Support -march=gracemont

gracemont has some different tuning features from alderlake.

Reviewed By: RKSimon

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index a80b5901d36a44..e18b459c0f51eb 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -526,6 +526,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
,
   case CK_Tremont:
 defineCPUMacros(Builder, "tremont");
 break;
+  // Gracemont and later atom-cores use P-core cpu macros.
+  case CK_Gracemont:
   case CK_Nehalem:
   case CK_Westmere:
   case CK_SandyBridge:
@@ -1420,6 +1422,7 @@ std::optional 
X86TargetInfo::getCPUCacheLineSize() const {
 case CK_Goldmont:
 case CK_GoldmontPlus:
 case CK_Tremont:
+case CK_Gracemont:
 
 case CK_Westmere:
 case CK_SandyBridge:

diff  --git a/clang/test/CodeGen/attr-cpuspecific-cpus.c 
b/clang/test/CodeGen/attr-cpuspecific-cpus.c
index fcf4d0e1b92433..f26871324e279d 100644
--- a/clang/test/CodeGen/attr-cpuspecific-cpus.c
+++ b/clang/test/CodeGen/attr-cpuspecific-cpus.c
@@ -83,3 +83,4 @@ ATTR(cpu_specific(graniterapids_d)) void CPU34(void){}
 ATTR(cpu_specific(arrowlake)) void CPU35(void){}
 ATTR(cpu_specific(arrowlake_s)) void CPU36(void){}
 ATTR(cpu_specific(lunarlake)) void CPU37(void){}
+ATTR(cpu_specific(gracemont)) void CPU38(void){}

diff  --git a/clang/test/CodeGen/attr-target-mv.c 
b/clang/test/CodeGen/attr-target-mv.c
index 03b9dc7eb8980f..261ce514763113 100644
--- a/clang/test/CodeGen/attr-target-mv.c
+++ b/clang/test/CodeGen/attr-target-mv.c
@@ -25,6 +25,7 @@ int __attribute__((target("arch=graniterapids-d"))) foo(void) 
{return 20;}
 int __attribute__((target("arch=arrowlake"))) foo(void) {return 21;}
 int __attribute__((target("arch=arrowlake-s"))) foo(void) {return 22;}
 int __attribute__((target("arch=lunarlake"))) foo(void) {return 23;}
+int __attribute__((target("arch=gracemont"))) foo(void) {return 24;}
 int __attribute__((target("default"))) foo(void) { return 2; }
 
 int bar(void) {
@@ -179,6 +180,8 @@ void calls_pr50025c(void) { pr50025c(); }
 // LINUX: ret i32 22
 // LINUX: define{{.*}} i32 @foo.arch_lunarlake()
 // LINUX: ret i32 23
+// LINUX: define{{.*}} i32 @foo.arch_gracemont()
+// LINUX: ret i32 24
 // LINUX: define{{.*}} i32 @foo()
 // LINUX: ret i32 2
 // LINUX: define{{.*}} i32 @bar()
@@ -230,6 +233,8 @@ void calls_pr50025c(void) { pr50025c(); }
 // WINDOWS: ret i32 22
 // WINDOWS: define dso_local i32 @foo.arch_lunarlake()
 // WINDOWS: ret i32 23
+// WINDOWS: define dso_local i32 @foo.arch_gracemont()
+// WINDOWS: ret i32 24
 // WINDOWS: define dso_local i32 @foo()
 // WINDOWS: ret i32 2
 // WINDOWS: define dso_local i32 @bar()

diff  --git a/clang/test/CodeGen/target-builtin-noerror.c 
b/clang/test/CodeGen/target-builtin-noerror.c
index 75fcdbbcb00822..60001fae1c0f4c 100644
--- a/clang/test/CodeGen/target-builtin-noerror.c
+++ b/clang/test/CodeGen/target-builtin-noerror.c
@@ -136,6 +136,7 @@ void verifycpustrings(void) {
   (void)__builtin_cpu_is("tigerlake");
   (void)__builtin_cpu_is("sapphirerapids");
   (void)__builtin_cpu_is("tremont");
+  (void)__builtin_cpu_is("gracemont");
   (void)__builtin_cpu_is("westmere");
   (void)__builtin_cpu_is("znver1");
   (void)__builtin_cpu_is("znver2");

diff  --git a/clang/test/Driver/x86-march.c b/clang/test/Driver/x86-march.c
index ab3107082588ca..b7134f79c5e21c 100644
--- a/clang/test/Driver/x86-march.c
+++ b/clang/test/Driver/x86-march.c
@@ -108,6 +108,10 @@
 // RUN:   | FileCheck %s -check-prefix=lunarlake
 // lunarlake: "-target-cpu" "lunarlake"
 //
+// RUN: %clang -target x86_64-unknown-unknown -c -### %s -march=gracemont 2>&1 
\
+// RUN:   | FileCheck %s -check-prefix=gracemont
+// gracemont: "-target-cpu" "gracemont"
+//
 // RUN: %clang -target x86_64-unknown-unknown -c -### %s -march=lakemont 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=lakemont
 // 

[PATCH] D158378: [Driver] move Minix header search path management to the driver

2023-08-20 Thread Brad Smith via Phabricator via cfe-commits
brad created this revision.
brad added a reviewer: MaskRay.
brad added a project: clang.
Herald added a project: All.
brad requested review of this revision.

As has been done for other OS's. Move the header path management to the driver.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158378

Files:
  clang/lib/Driver/ToolChains/Minix.cpp
  clang/lib/Driver/ToolChains/Minix.h
  clang/lib/Lex/InitHeaderSearch.cpp

Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -332,10 +332,6 @@
   case llvm::Triple::DragonFly:
 AddPath("/usr/include/c++/5.0", CXXSystem, false);
 break;
-  case llvm::Triple::Minix:
-AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
-"", "", "", triple);
-break;
   default:
 break;
   }
@@ -355,6 +351,7 @@
   case llvm::Triple::Haiku:
   case llvm::Triple::Hurd:
   case llvm::Triple::Linux:
+  case llvm::Triple::Minix:
   case llvm::Triple::Solaris:
   case llvm::Triple::WASI:
 return false;
Index: clang/lib/Driver/ToolChains/Minix.h
===
--- clang/lib/Driver/ToolChains/Minix.h
+++ clang/lib/Driver/ToolChains/Minix.h
@@ -52,6 +52,13 @@
   Minix(const Driver , const llvm::Triple ,
 const llvm::opt::ArgList );
 
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void addLibStdCxxIncludePaths(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
Index: clang/lib/Driver/ToolChains/Minix.cpp
===
--- clang/lib/Driver/ToolChains/Minix.cpp
+++ clang/lib/Driver/ToolChains/Minix.cpp
@@ -8,11 +8,13 @@
 
 #include "Minix.h"
 #include "CommonArgs.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/VirtualFileSystem.h"
 
 using namespace clang::driver;
@@ -107,6 +109,46 @@
   getFilePaths().push_back("/usr/lib");
 }
 
+void toolchains::Minix::AddClangSystemIncludeArgs(
+const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const {
+  const Driver  = getDriver();
+
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(D.ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  // Check for configure-time C include directories.
+  StringRef CIncludeDirs(C_INCLUDE_DIRS);
+  if (CIncludeDirs != "") {
+SmallVector dirs;
+CIncludeDirs.split(dirs, ":");
+for (StringRef dir : dirs) {
+  StringRef Prefix =
+  llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
+  addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
+}
+return;
+  }
+
+  addExternCSystemInclude(DriverArgs, CC1Args,
+  concat(D.SysRoot, "/usr/include"));
+}
+
+void toolchains::Minix::addLibStdCxxIncludePaths(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const {
+  addLibStdCXXIncludePaths(concat(getDriver().SysRoot, "/usr/gnu/include/c++/4.4.3"), "", "",
+   DriverArgs, CC1Args);
+}
+
 Tool *toolchains::Minix::buildAssembler() const {
   return new tools::minix::Assembler(*this);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158218: [CMake] Deprecate DEFAULT_SYSROOT and GCC_INSTALL_PREFIX

2023-08-20 Thread Brian Cain via Phabricator via cfe-commits
bcain added inline comments.



Comment at: clang/CMakeLists.txt:179-183
+if(DEFAULT_SYSROOT)
+  message(WARNING "DEFAULT_SYSROOT is deprecated and will be removed. Use "
+"configuration files 
(https://clang.llvm.org/docs/UsersManual.html#configuration-files)"
+"to specify the default --sysroot=")
+endif()

MaskRay wrote:
> MaskRay wrote:
> > bcain wrote:
> > > MaskRay wrote:
> > > > bcain wrote:
> > > > > At one time I believe that the clang configuration files could not 
> > > > > specify paths relative to the clang executable.  AFAICT 
> > > > > `DEFAULT_SYSROOT` does support this.
> > > > > 
> > > > > But if I'm mistaken about that can we add an example to the docs at 
> > > > > https://clang.llvm.org/docs/UsersManual.html#configuration-files 
> > > > > illustrating how to use a relative sysroot?
> > > > Clang configuration files just complement user-specified command line 
> > > > options. As one can do `--sysroot=./sysroot`, one can add 
> > > > `--sysroot=./sysroot` to a configuration file, too.
> > > > 
> > > > If you think having a sysroot example is useful, I can add
> > > > 
> > > > ```
> > > > # Relative --sysroot
> > > > --sysroot=./sysroot
> > > > ```
> > > > before
> > > > clang/docs/UsersManual.rst:1018 `-c --target=x86_64-unknown-linux-gnu`
> > > IIUC: when clang takes a `--sysroot=./sysroot` argument, it will 
> > > interpret that path as a prefix to the files it wants to access.  So the 
> > > system will treat it as relative to the environment's `cwd`, correct?
> > > 
> > > But when `DEFAULT_SYSROOT` is set to a relative path, that relative path 
> > > is considered to be relative to `clang`.  Therefore a convenient feature 
> > > that we take advantage of is setting it to something like 
> > > `../target/hexagon-unknown-linux-musl` in order to have anyone who 
> > > invokes `hexagon-unknown-linux-clang` from any path be able to find the 
> > > includes and libraries distributed with the toolchain without having to 
> > > specify the sysroot.
> > > 
> > > Maybe there's a better way to achieve this without the need for a 
> > > relative `DEFAULT_SYSROOT` but it's been very useful and the config files 
> > > do not seem suited to replace it.
> > `--sysroot=` is used as a prefix to certain files, primarily libc and GCC 
> > installations.
> > 
> > `-DDEFAULT_SYSROOT=...` just changes `clang/lib/Driver/Driver.cpp:203` 
> > `SysRoot(DEFAULT_SYSROOT)`.
> > There is no magic related to the `clang` executable path. CMake doesn't do 
> > any magic, either.
> Ah, sorry. There is magic: D76653 (@sbc100).
> Ah, sorry. There is magic: D76653 (@sbc100).

Okay, so should we abandon the plan to deprecate `DEFAULT_SYSROOT`?  Or could 
we add a corresponding feature to config files if we want to get rid of it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158218

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


[PATCH] D158376: [Driver] move DragonFly header search path management to the driver

2023-08-20 Thread Brad Smith via Phabricator via cfe-commits
brad updated this revision to Diff 551872.
brad added a comment.

Also use concat() in addLibStdCxxIncludePaths().


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158376

Files:
  clang/lib/Driver/ToolChains/DragonFly.cpp
  clang/lib/Driver/ToolChains/DragonFly.h
  clang/lib/Lex/InitHeaderSearch.cpp

Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -329,9 +329,6 @@
   break;
 }
 break;
-  case llvm::Triple::DragonFly:
-AddPath("/usr/include/c++/5.0", CXXSystem, false);
-break;
   case llvm::Triple::Minix:
 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
 "", "", "", triple);
@@ -345,6 +342,7 @@
 const llvm::Triple ) {
   switch (triple.getOS()) {
   case llvm::Triple::AIX:
+  case llvm::Triple::DragonFly:
   case llvm::Triple::Emscripten:
   case llvm::Triple::FreeBSD:
   case llvm::Triple::NetBSD:
Index: clang/lib/Driver/ToolChains/DragonFly.h
===
--- clang/lib/Driver/ToolChains/DragonFly.h
+++ clang/lib/Driver/ToolChains/DragonFly.h
@@ -55,6 +55,13 @@
 
   bool IsMathErrnoDefault() const override { return false; }
 
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void addLibStdCxxIncludePaths(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
Index: clang/lib/Driver/ToolChains/DragonFly.cpp
===
--- clang/lib/Driver/ToolChains/DragonFly.cpp
+++ clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -8,10 +8,12 @@
 
 #include "DragonFly.h"
 #include "CommonArgs.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -195,6 +197,46 @@
   getFilePaths().push_back("/usr/lib/gcc80");
 }
 
+void DragonFly::AddClangSystemIncludeArgs(
+const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const {
+  const Driver  = getDriver();
+
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(D.ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  // Check for configure-time C include directories.
+  StringRef CIncludeDirs(C_INCLUDE_DIRS);
+  if (CIncludeDirs != "") {
+SmallVector dirs;
+CIncludeDirs.split(dirs, ":");
+for (StringRef dir : dirs) {
+  StringRef Prefix =
+  llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
+  addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
+}
+return;
+  }
+
+  addExternCSystemInclude(DriverArgs, CC1Args,
+  concat(D.SysRoot, "/usr/include"));
+}
+
+void DragonFly::addLibStdCxxIncludePaths(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const {
+  addLibStdCXXIncludePaths(concat(getDriver().SysRoot, "/usr/include/c++/8.0"), "", "",
+   DriverArgs, CC1Args);
+}
+
 Tool *DragonFly::buildAssembler() const {
   return new tools::dragonfly::Assembler(*this);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152246: [clang][ThreadSafety] Analyze known function pointer values

2023-08-20 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

In D152246#4484366 , @tbaeder wrote:

> So, the problem with this (type of) analysis is that we don't have a perfect 
> view of the (global) program state, right? The CFG is per-function, and any 
> other function (etc.) might change a function pointer. And we don't even know 
> its initial value. Correct? The CFG-based anaylsis is just not enough to 
> reliably diagnose this sort of problem.

Exactly, the analysis is strictly intraprocedural. So we'll only see any value 
if initialization/assignment and call are in the same function. And if the 
value is uniquely determined, the question is why does the function do an 
indirect call at all? I could imagine this in something like a unit test, but 
these are not so interesting for static analysis.

So basically the code would need to look like this:

  void f() __attribute__((requires_capability(mu)));
  
  void g() {
void (*pf)() = f;
pf();
  }

But why would someone write this instead of a direct call to `f`?


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

https://reviews.llvm.org/D152246

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


[PATCH] D158329: [X86] Support arch=x86-64{,-v2,-v3,-v4} for target_clones attribute

2023-08-20 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:13318-13320
+Value *Idxs[] = {Builder.getInt32(0), Builder.getInt32(i - 1)};
+Value *Features = Builder.CreateAlignedLoad(
+Int32Ty, Builder.CreateGEP(ATy, CpuFeatures2, Idxs),

MaskRay wrote:
> pengfei wrote:
> > Do we have problem when linking with old version of libgcc?
> If we don't use `__cpu_features2[1..3]`, no problem with older libgcc.
> 
> The way GCC upgraded `__cpu_features2` to an array is compatible with scalar 
> `__cpu_features2`.
I assume GCC seldom links to older libgcc, but there's no guarantee Clang can 
link to latest libgcc.
And we cannot assume user won't use it once the method provided.
I don't have a good idea for it, but I think we should write the requirement 
done in release note or somewhere if we cannot find a better way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158329

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


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

2023-08-20 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

For me this looks good, but I'd like @NoQ to sign off on it.




Comment at: clang/lib/Analysis/CFG.cpp:1874
+if (needsAutomaticDestruction(D))
   DeclsNonTrivial.push_back(D);
 

I'm wondering if you should rename this accordingly.



Comment at: clang/lib/Analysis/CFG.cpp:1887-1889
+  bool IsCXXRecordType = (Ty->getAsCXXRecordDecl() != nullptr);
+  if (IsCXXRecordType &&
+  Ty->getAsCXXRecordDecl()->isAnyDestructorNoReturn())

Here I'd suggest to deduplicate `Ty->getAsCXXRecordDecl()`. Implicit conversion 
of pointers to bool is idiomatic in LLVM.



Comment at: clang/lib/Analysis/CFG.cpp:5307-5308
+case CFGElement::CleanupFunction:
+llvm_unreachable("getDestructorDecl should only be used with "
+ "ImplicitDtors");
 case CFGElement::AutomaticObjectDtor: {

The unindent doesn't look right to me.



Comment at: clang/lib/Analysis/CFG.cpp:5850
 
+  case CFGElement::Kind::CleanupFunction: {
+OS << "CleanupFunction ("

Braces shouldn't be needed if you don't declare any variables.



Comment at: clang/lib/Analysis/ThreadSafety.cpp:2429-2438
+
+case CFGElement::CleanupFunction: {
+  const CFGCleanupFunction  = BI.castAs();
+
+  LocksetBuilder.handleCall(nullptr, CF.getFunctionDecl(),
+SxBuilder.createVariable(CF.getVarDecl()),
+CF.getVarDecl()->getLocation());

Should this be part of a follow-up? (For which you might revive D152504.)



Comment at: clang/test/Analysis/scopes-cfg-output.cpp:1428-1429
+// CHECK-NEXT:   4: CFGScopeEnd(i)
+void cleanup_int(int *i) {
+}
+

For our purposes, a pure declaration might be enough.



Comment at: clang/test/Analysis/scopes-cfg-output.cpp:1433
+  int i __attribute__((cleanup(cleanup_int)));
+}

Ideas for more tests (apart from imitating destructor tests):

* A variable in a block, so that more statements run before the function 
returns.
* A function with multiple return paths, each of which has to run the cleanup.




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

https://reviews.llvm.org/D157385

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


[PATCH] D153701: [Clang] Implement P2718R0 "Lifetime extension in range-based for loops"

2023-08-20 Thread Yurong via Phabricator via cfe-commits
yronglin updated this revision to Diff 551871.
yronglin added a comment.

Do not spass MaterializePRValueInDiscardStatement in 
PushExpressionEvaluationContext.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153701

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/AST/ast-dump-for-range-lifetime.cpp
  clang/test/CXX/special/class.temporary/p6.cpp

Index: clang/test/CXX/special/class.temporary/p6.cpp
===
--- clang/test/CXX/special/class.temporary/p6.cpp
+++ clang/test/CXX/special/class.temporary/p6.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s --implicit-check-not='call{{.*}}dtor'
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK-CXX23,CHECK-CXX23-NEXT
 
 namespace std {
   typedef decltype(sizeof(int)) size_t;
@@ -238,3 +239,236 @@
   // CHECK: call {{.*}}dtor
   // CHECK: }
 }
+
+namespace P2718R0 {
+
+// Test basic
+struct A {
+  int a[3] = {1, 2, 3};
+  A() {}
+  ~A() {}
+  const int *begin() const { return a; }
+  const int *end() const { return a + 3; }
+  A& r() { return *this; }
+  A g() { return A(); }
+};
+
+A g() { return A(); }
+const A (const A ) { return t; }
+
+void test1() {
+  [[maybe_unused]] int sum = 0;
+  // CHECK-CXX23: void @_ZN7P2718R05test1Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for (auto e : f1(g()))
+sum += e;
+}
+
+struct B : A {};
+int ((const A *))[3];
+const A *g(const A &);
+void bar(int) {}
+
+void test2() {
+  // CHECK-CXX23: void @_ZN7P2718R05test2Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01BD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for (auto e : f(g(B(
+bar(e);
+}
+
+// Test discard statement.
+struct LockGuard {
+LockGuard() {}
+~LockGuard() {}
+};
+
+void test3() {
+  int v[] = {42, 17, 13};
+
+  // CHECK-CXX23: void @_ZN7P2718R05test3Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R09LockGuardD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for ([[maybe_unused]] int x : static_cast(LockGuard()), v)
+LockGuard guard;
+  
+  // CHECK-CXX23: for.cond.cleanup11:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R09LockGuardD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end17
+  for ([[maybe_unused]] int x : (void)LockGuard(), v)
+LockGuard guard;
+  
+  // CHECK-CXX23: for.cond.cleanup27:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R09LockGuardD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end33
+  for ([[maybe_unused]] int x : LockGuard(), v)
+LockGuard guard;
+}
+
+// Test default arg
+int (_arg_fn(const A & = A()))[3];
+void test4() {
+
+  // CHECK-CXX23: void @_ZN7P2718R05test4Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for (auto e : default_arg_fn()) 
+bar(e);
+}
+
+struct DefaultA {
+  DefaultA() {}
+  ~DefaultA() {}
+};
+
+A foo(const A&, const DefaultA  = DefaultA()) {
+  return A();
+}
+
+void test5() {
+  // CHECK-CXX23: void @_ZN7P2718R05test5Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for (auto e : default_arg_fn(foo(foo(foo(A())
+bar(e);
+}
+
+struct C : public A {
+  C() {}
+  C(int, const C &, const DefaultA & = DefaultA()) {}
+};
+
+void test6() {
+  // CHECK-CXX23: void @_ZN7P2718R05test6Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01CD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01CD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01CD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01CD1Ev(
+  // CHECK-CXX23: br label %for.end
+  for (auto e : C(0, C(0, C(0, C()
+bar(e);
+}
+
+// Test member call
+void test7() {
+  // CHECK-CXX23: void @_ZN7P2718R05test7Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void 

[PATCH] D158367: [AMDGPU] Add target feature gds/gws to clang

2023-08-20 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/TargetParser/TargetParser.cpp:289
   Features["image-insts"] = true;
+  Features["gds"] = true;
+  Features["gws"] = true;

Gds feature is unused 


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

https://reviews.llvm.org/D158367

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


[PATCH] D158376: [Driver] move DragonFly header search path management to the driver

2023-08-20 Thread Brad Smith via Phabricator via cfe-commits
brad created this revision.
brad added a reviewer: devnexen.
brad added a project: clang.
Herald added a project: All.
brad requested review of this revision.
Herald added a subscriber: MaskRay.

As has been done for other OS's. Move the header path management to the driver.

Also I noticed with https://reviews.llvm.org/D89690 that the library paths were 
updated for GCC 8, but
the C++ header path was not. So I also fixed that while here.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158376

Files:
  clang/lib/Driver/ToolChains/DragonFly.cpp
  clang/lib/Driver/ToolChains/DragonFly.h
  clang/lib/Lex/InitHeaderSearch.cpp

Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -329,9 +329,6 @@
   break;
 }
 break;
-  case llvm::Triple::DragonFly:
-AddPath("/usr/include/c++/5.0", CXXSystem, false);
-break;
   case llvm::Triple::Minix:
 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
 "", "", "", triple);
@@ -345,6 +342,7 @@
 const llvm::Triple ) {
   switch (triple.getOS()) {
   case llvm::Triple::AIX:
+  case llvm::Triple::DragonFly:
   case llvm::Triple::Emscripten:
   case llvm::Triple::FreeBSD:
   case llvm::Triple::NetBSD:
Index: clang/lib/Driver/ToolChains/DragonFly.h
===
--- clang/lib/Driver/ToolChains/DragonFly.h
+++ clang/lib/Driver/ToolChains/DragonFly.h
@@ -55,6 +55,13 @@
 
   bool IsMathErrnoDefault() const override { return false; }
 
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void addLibStdCxxIncludePaths(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
Index: clang/lib/Driver/ToolChains/DragonFly.cpp
===
--- clang/lib/Driver/ToolChains/DragonFly.cpp
+++ clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -8,10 +8,12 @@
 
 #include "DragonFly.h"
 #include "CommonArgs.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -195,6 +197,46 @@
   getFilePaths().push_back("/usr/lib/gcc80");
 }
 
+void DragonFly::AddClangSystemIncludeArgs(
+const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const {
+  const Driver  = getDriver();
+
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(D.ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  // Check for configure-time C include directories.
+  StringRef CIncludeDirs(C_INCLUDE_DIRS);
+  if (CIncludeDirs != "") {
+SmallVector dirs;
+CIncludeDirs.split(dirs, ":");
+for (StringRef dir : dirs) {
+  StringRef Prefix =
+  llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
+  addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
+}
+return;
+  }
+
+  addExternCSystemInclude(DriverArgs, CC1Args,
+  concat(D.SysRoot, "/usr/include"));
+}
+
+void DragonFly::addLibStdCxxIncludePaths(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const {
+  addLibStdCXXIncludePaths(getDriver().SysRoot + "/usr/include/c++/8.0", "", "",
+   DriverArgs, CC1Args);
+}
+
 Tool *DragonFly::buildAssembler() const {
   return new tools::dragonfly::Assembler(*this);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153156: [Clang] CWG1473: do not err on the lack of space after operator""

2023-08-20 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao added a comment.

D158372  addresses comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153156

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


[PATCH] D158372: [Clang] Treat invalid UDL as two tokens

2023-08-20 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao created this revision.
rZhBoYao added reviewers: clang-language-wg, aaron.ballman, jyknight.
Herald added a project: All.
rZhBoYao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As a language extension, if an invalid a UDL's suffix can result in macro
expansion, it is treated as if whitespace preceded it. This allows legacy
code to co-exist with new code via -Wno-reserved-user-defined-literal.
The following code results in string concat not calling literal operator.

  const char* s = "FOO"BAR;

Address comments in D153156 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158372

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Lex/Lexer.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/drs/dr17xx.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p10.cpp

Index: clang/test/CXX/lex/lex.literal/lex.ext/p10.cpp
===
--- clang/test/CXX/lex/lex.literal/lex.ext/p10.cpp
+++ clang/test/CXX/lex/lex.literal/lex.ext/p10.cpp
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -std=c++11 -verify %s
 
 using size_t = decltype(sizeof(int));
-void operator ""wibble(const char *); // expected-warning {{user-defined literal suffixes not starting with '_' are reserved; no literal will invoke this operator}}
-void operator ""wibble(const char *, size_t); // expected-warning {{user-defined literal suffixes not starting with '_' are reserved; no literal will invoke this operator}}
+void operator ""wibble(const char *); // expected-warning {{user-defined literal suffixes not starting with '_' are reserved}}
+void operator ""wibble(const char *, size_t); // expected-warning {{user-defined literal suffixes not starting with '_' are reserved}}
 
 template
 void f() {
Index: clang/test/CXX/drs/dr17xx.cpp
===
--- clang/test/CXX/drs/dr17xx.cpp
+++ clang/test/CXX/drs/dr17xx.cpp
@@ -143,7 +143,7 @@
 #if __cplusplus >= 201103L
   float operator ""_E(const char *);
   float operator ""E(const char *);
-  // expected-warning@-1 {{user-defined literal suffixes not starting with '_' are reserved; no literal will invoke this operator}}
+  // expected-warning@-1 {{user-defined literal suffixes not starting with '_' are reserved}}
 #endif
 }
 
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -489,7 +489,13 @@
 #if __cplusplus >= 201103L
   float operator ""_E(const char *);
   float operator ""E(const char *); // don't err on the lack of spaces even when the literal suffix identifier is invalid
-  // expected-warning@-1 {{user-defined literal suffixes not starting with '_' are reserved; no literal will invoke this operator}}
+  // expected-warning@-1 {{user-defined literal suffixes not starting with '_' are reserved}}
+  const char* s0 = "FOO"BAR;
+  // expected-error@-1 {{no matching literal operator for call to 'operator""BAR' with arguments of types 'const char *' and 'unsigned long', and no matching literal operator template}}
+#define BAR "BAZ"
+  const char* s1 = "FOO"BAR;
+  // expected-error@-1 {{invalid suffix on literal; C++11 requires a space between literal and a macro}}
+#undef BAR
 #endif
 }
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16571,8 +16571,7 @@
 //   contain a double underscore __ are reserved for use by C++
 //   implementations.
 Diag(FnDecl->getLocation(), diag::warn_user_literal_reserved)
-<< static_cast(Status)
-<< StringLiteralParser::isValidUDSuffix(getLangOpts(), II->getName());
+<< static_cast(Status);
   }
 
   return false;
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -1986,6 +1986,7 @@
   assert(LangOpts.CPlusPlus);
 
   // Maximally munch an identifier.
+  const char *TokStart = CurPtr;
   unsigned Size;
   char C = getCharAndSize(CurPtr, Size);
   bool Consumed = false;
@@ -2012,10 +2013,43 @@
   // that does not start with an underscore is ill-formed. We assume a suffix
   // beginning with a UCN or UTF-8 character is more likely to be a ud-suffix
   // than a macro, however, and accept that.
+  bool IsUDSuffix = false;
+  if (!Consumed) {
+if (C == '_')
+  IsUDSuffix = true;
+else if (IsStringLiteral && LangOpts.CPlusPlus14) {
+  // In C++1y, we need to look ahead a few characters to see if this is a
+  // valid suffix for a string literal or a numeric literal (this could be
+  // the 'operator""if' defining a numeric 

[PATCH] D158371: [clang-tidy] Fix DanglingHandleCheck to work in C++17 and later mode

2023-08-20 Thread Ignat Loskutov via Phabricator via cfe-commits
loskutov created this revision.
loskutov added reviewers: sbenza, PiotrZSL.
loskutov added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
loskutov requested review of this revision.
Herald added a subscriber: cfe-commits.

Due to guaranteed copy elision, not only do some nodes get removed from the AST,
but also some existing nodes change the source locations they correspond to.
Hence, the check works slightly differently in pre-C++17 and C++17-and-later 
modes
in terms of what gets highlighted.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158371

Files:
  clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
@@ -1,8 +1,12 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-dangling-handle %t -- \
+// RUN: %check_clang_tidy -std=c++11,c++14 -check-suffix=,CXX14 %s bugprone-dangling-handle %t -- \
+// RUN:   -config="{CheckOptions: \
+// RUN: {bugprone-dangling-handle.HandleClasses: \
+// RUN:   'std::basic_string_view; ::llvm::StringRef;'}}"
+
+// RUN: %check_clang_tidy -std=c++17-or-later -check-suffix=,CXX17 %s bugprone-dangling-handle %t -- \
 // RUN:   -config="{CheckOptions: \
 // RUN: {bugprone-dangling-handle.HandleClasses: \
 // RUN:   'std::basic_string_view; ::llvm::StringRef;'}}"
-// FIXME: Fix the checker to work in C++17 or later mode.
 
 namespace std {
 
@@ -84,27 +88,32 @@
 
 void Positives() {
   std::string_view view1 = std::string();
-  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: std::basic_string_view outlives its value [bugprone-dangling-handle]
+  // CHECK-MESSAGES-CXX14: [[@LINE-1]]:20: warning: std::basic_string_view outlives its value [bugprone-dangling-handle]
+  // CHECK-MESSAGES-CXX17: [[@LINE-2]]:28: warning: std::basic_string_view outlives its value [bugprone-dangling-handle]
 
   std::string_view view_2 = ReturnsAString();
-  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: std::basic_string_view outlives
+  // CHECK-MESSAGES-CXX14: [[@LINE-1]]:20: warning: std::basic_string_view outlives its value [bugprone-dangling-handle]
+  // CHECK-MESSAGES-CXX17: [[@LINE-2]]:29: warning: std::basic_string_view outlives its value [bugprone-dangling-handle]
 
   view1 = std::string();
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: std::basic_string_view outlives
 
   const std::string& str_ref = "";
   std::string_view view3 = true ? "A" : str_ref;
-  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: std::basic_string_view outlives
+  // CHECK-MESSAGES-CXX14: [[@LINE-1]]:20: warning: std::basic_string_view outlives
+  // CHECK-MESSAGES-CXX17: [[@LINE-2]]:28: warning: std::basic_string_view outlives
   view3 = true ? "A" : str_ref;
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: std::basic_string_view outlives
 
   std::string_view view4(ReturnsAString());
-  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: std::basic_string_view outlives
+  // CHECK-MESSAGES-CXX14: [[@LINE-1]]:20: warning: std::basic_string_view outlives
+  // CHECK-MESSAGES-CXX17: [[@LINE-2]]:26: warning: std::basic_string_view outlives
 }
 
 void OtherTypes() {
   llvm::StringRef ref = std::string();
-  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: llvm::StringRef outlives its value
+  // CHECK-MESSAGES-CXX14: [[@LINE-1]]:19: warning: llvm::StringRef outlives its value
+  // CHECK-MESSAGES-CXX17: [[@LINE-2]]:25: warning: llvm::StringRef outlives its value
 }
 
 const char static_array[] = "A";
Index: clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
@@ -37,8 +37,8 @@
   // temporary value. If one of them is not a temporary then it must be copied
   // into one to satisfy the type of the operator.
   const auto TemporaryTernary =
-  conditionalOperator(hasTrueExpression(cxxBindTemporaryExpr()),
-  hasFalseExpression(cxxBindTemporaryExpr()));
+  conditionalOperator(hasTrueExpression(ignoringParenImpCasts(cxxBindTemporaryExpr())),
+  hasFalseExpression(ignoringParenImpCasts(cxxBindTemporaryExpr(;
 
   return handleFrom(IsAHandle, anyOf(cxxBindTemporaryExpr(), TemporaryTernary));
 }
@@ -103,26 +103,17 @@
 void DanglingHandleCheck::registerMatchersForVariables(MatchFinder *Finder) {
   const auto ConvertedHandle = handleFromTemporaryValue(IsAHandle);
 
-  // Find 'Handle foo(ReturnsAValue());'
+  // Find 'Handle 

[PATCH] D155627: [clang][Interp] Handle SourceLocExprs

2023-08-20 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 551854.

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

https://reviews.llvm.org/D155627

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Program.cpp
  clang/test/AST/Interp/builtin-functions.cpp

Index: clang/test/AST/Interp/builtin-functions.cpp
===
--- clang/test/AST/Interp/builtin-functions.cpp
+++ clang/test/AST/Interp/builtin-functions.cpp
@@ -221,3 +221,31 @@
 namespace fabs {
   static_assert(__builtin_fabs(-14.0) == 14.0, "");
 }
+
+namespace std {
+struct source_location {
+  struct __impl {
+unsigned int _M_line;
+const char *_M_file_name;
+signed char _M_column;
+const char *_M_function_name;
+  };
+  using BuiltinT = decltype(__builtin_source_location()); // OK.
+};
+}
+
+namespace SourceLocation {
+  constexpr auto A = __builtin_source_location();
+  static_assert(A->_M_line == __LINE__ -1, "");
+  static_assert(A->_M_column == 22, "");
+  static_assert(__builtin_strcmp(A->_M_function_name, "") == 0, "");
+  static_assert(__builtin_strcmp(A->_M_file_name, __FILE__) == 0, "");
+
+  static_assert(__builtin_LINE() == __LINE__, "");
+
+  struct Foo {
+int a = __builtin_LINE();
+  };
+
+  static_assert(Foo{}.a == __LINE__, "");
+}
Index: clang/lib/AST/Interp/Program.cpp
===
--- clang/lib/AST/Interp/Program.cpp
+++ clang/lib/AST/Interp/Program.cpp
@@ -161,9 +161,12 @@
   const Expr *Init) {
   assert(!getGlobal(VD));
   bool IsStatic, IsExtern;
-  if (auto *Var = dyn_cast(VD)) {
+  if (const auto *Var = dyn_cast(VD)) {
 IsStatic = Context::shouldBeGloballyIndexed(VD);
 IsExtern = !Var->getAnyInitializer();
+  } else if (isa(VD)) {
+IsStatic = true;
+IsExtern = false;
   } else {
 IsStatic = false;
 IsExtern = true;
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -35,6 +35,7 @@
 template  class DeclScope;
 template  class OptionScope;
 template  class ArrayIndexScope;
+template  class SourceLocScope;
 
 /// Compilation context for expressions.
 template 
@@ -102,6 +103,7 @@
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E);
   bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E);
   bool VisitCXXConstructExpr(const CXXConstructExpr *E);
+  bool VisitSourceLocExpr(const SourceLocExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
@@ -154,6 +156,8 @@
 
   /// Creates and initializes a variable from the given decl.
   bool visitVarDecl(const VarDecl *VD);
+  /// Visit an APValue.
+  bool visitAPValue(const APValue , PrimType ValType, const Expr *E);
 
   /// Visits an expression and converts it to a boolean.
   bool visitBool(const Expr *E);
@@ -210,6 +214,7 @@
   friend class DeclScope;
   friend class OptionScope;
   friend class ArrayIndexScope;
+  friend class SourceLocScope;
 
   /// Emits a zero initializer.
   bool visitZeroInitializer(QualType QT, const Expr *E);
@@ -238,12 +243,14 @@
   llvm::function_ref Indirect);
 
   /// Emits an APSInt constant.
+  bool emitConst(const llvm::APSInt , PrimType Ty, const Expr *E);
   bool emitConst(const llvm::APSInt , const Expr *E);
   bool emitConst(const llvm::APInt , const Expr *E) {
 return emitConst(static_cast(Value), E);
   }
 
   /// Emits an integer constant.
+  template  bool emitConst(T Value, PrimType Ty, const Expr *E);
   template  bool emitConst(T Value, const Expr *E);
 
   /// Returns the CXXRecordDecl for the type of the given expression,
@@ -284,6 +291,9 @@
   /// Current argument index. Needed to emit ArrayInitIndexExpr.
   std::optional ArrayIndex;
 
+  /// DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
+  const Expr *SourceLocDefaultExpr = nullptr;
+
   /// Flag indicating if return value is to be discarded.
   bool DiscardResult = false;
 
@@ -443,6 +453,28 @@
   std::optional OldArrayIndex;
 };
 
+template  class SourceLocScope final {
+public:
+  SourceLocScope(ByteCodeExprGen *Ctx, const Expr *DefaultExpr)
+  : Ctx(Ctx) {
+assert(DefaultExpr);
+// We only switch if the current SourceLocDefaultExpr is null.
+if (!Ctx->SourceLocDefaultExpr) {
+  Enabled = true;
+  Ctx->SourceLocDefaultExpr = DefaultExpr;
+}
+  }
+
+  ~SourceLocScope() {
+if (Enabled)
+  Ctx->SourceLocDefaultExpr = nullptr;
+  }
+
+private:
+  ByteCodeExprGen *Ctx;
+  bool Enabled = false;
+};
+
 } // namespace interp
 } // namespace clang
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1456,6 +1456,62 @@
   return 

[PATCH] D155627: [clang][Interp] Handle SourceLocExprs

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

All the dependencies have been pushed.


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

https://reviews.llvm.org/D155627

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


[clang] 4d434f7 - [Sema] Modernize Usage (NFC)

2023-08-20 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-08-20T09:43:04-07:00
New Revision: 4d434f76967f2fea344fc9de2686a9295c16e56d

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

LOG: [Sema] Modernize Usage (NFC)

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index dc5c47e3d79648..9f8b0ab928e84b 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -15896,10 +15896,10 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
   /// Bundle together a sequencing region and the expression corresponding
   /// to a specific usage. One Usage is stored for each usage kind in 
UsageInfo.
   struct Usage {
-const Expr *UsageExpr;
+const Expr *UsageExpr = nullptr;
 SequenceTree::Seq Seq;
 
-Usage() : UsageExpr(nullptr) {}
+Usage() = default;
   };
 
   struct UsageInfo {



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


[clang] c6bcdc4 - [CodeGen] Modernize GuardInfo (NFC)

2023-08-20 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-08-20T09:43:02-07:00
New Revision: c6bcdc42c1a7bfaa44d7823bb72444925e0b383b

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

LOG: [CodeGen] Modernize GuardInfo (NFC)

Added: 


Modified: 
clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index a14efbdba76b0b..b60aa0c07deb94 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -828,9 +828,9 @@ class MicrosoftCXXABI : public CGCXXABI {
   /// Info on the global variable used to guard initialization of static 
locals.
   /// The BitIndex field is only used for externally invisible declarations.
   struct GuardInfo {
-GuardInfo() : Guard(nullptr), BitIndex(0) {}
-llvm::GlobalVariable *Guard;
-unsigned BitIndex;
+GuardInfo() = default;
+llvm::GlobalVariable *Guard = nullptr;
+unsigned BitIndex = 0;
   };
 
   /// Map from DeclContext to the current guard variable.  We assume that the



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


[clang] 477457c - [CodeGen] Modernize NullReturnState (NFC)

2023-08-20 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-08-20T09:43:01-07:00
New Revision: 477457c3a7c3ca5f6042a35e61226df0f56aec34

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

LOG: [CodeGen] Modernize NullReturnState (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CGObjCMac.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 51c87f985fdf05..f55759581fa78e 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -1713,8 +1713,8 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
 /// A helper class for performing the null-initialization of a return
 /// value.
 struct NullReturnState {
-  llvm::BasicBlock *NullBB;
-  NullReturnState() : NullBB(nullptr) {}
+  llvm::BasicBlock *NullBB = nullptr;
+  NullReturnState() = default;
 
   /// Perform a null-check of the given receiver.
   void init(CodeGenFunction , llvm::Value *receiver) {



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


[clang] f01f2de - [CodeGen] Modernize CallArgList (NFC)

2023-08-20 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-08-20T09:42:59-07:00
New Revision: f01f2de5409dadec8a31e417fb183f222d3486f6

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

LOG: [CodeGen] Modernize CallArgList (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CGCall.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.h b/clang/lib/CodeGen/CGCall.h
index aab4a678e68e67..75c4dcc400caf0 100644
--- a/clang/lib/CodeGen/CGCall.h
+++ b/clang/lib/CodeGen/CGCall.h
@@ -256,7 +256,7 @@ struct CallArg {
 /// arguments in a call.
 class CallArgList : public SmallVector {
 public:
-  CallArgList() : StackBase(nullptr) {}
+  CallArgList() = default;
 
   struct Writeback {
 /// The original argument.  Note that the argument l-value
@@ -362,7 +362,7 @@ class CallArgList : public SmallVector {
   SmallVector LifetimeCleanups;
 
   /// The stacksave call.  It dominates all of the argument evaluation.
-  llvm::CallInst *StackBase;
+  llvm::CallInst *StackBase = nullptr;
 };
 
 /// FunctionArgList - Type for representing both the decl and type



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


[clang] 7a68060 - [AST] Modernize ExternalLayout (NFC)

2023-08-20 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-08-20T09:42:57-07:00
New Revision: 7a6806073dd802e475b6fe9ae05e618927d4fd14

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

LOG: [AST] Modernize ExternalLayout (NFC)

Added: 


Modified: 
clang/lib/AST/RecordLayoutBuilder.cpp

Removed: 




diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 3f836cb96be576..8afd88ae7be27b 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -58,13 +58,13 @@ struct BaseSubobjectInfo {
 /// as DWARF, lacks all the information that was available at compile time, 
such
 /// as alignment attributes on fields and pragmas in effect.
 struct ExternalLayout {
-  ExternalLayout() : Size(0), Align(0) {}
+  ExternalLayout() = default;
 
   /// Overall record size in bits.
-  uint64_t Size;
+  uint64_t Size = 0;
 
   /// Overall record alignment in bits.
-  uint64_t Align;
+  uint64_t Align = 0;
 
   /// Record field offsets in bits.
   llvm::DenseMap FieldOffsets;



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


[clang] bd31c36 - [AST] Modernize FunctionTypeDepthState (NFC)

2023-08-20 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-08-20T09:42:56-07:00
New Revision: bd31c36fd0c8efa57dea9c078d191d01d24e929f

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

LOG: [AST] Modernize FunctionTypeDepthState (NFC)

Added: 


Modified: 
clang/lib/AST/ItaniumMangle.cpp

Removed: 




diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 153f6dc2e9cf12..53963d2a91752a 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -238,12 +238,12 @@ class CXXNameMangler {
   unsigned SeqID = 0;
 
   class FunctionTypeDepthState {
-unsigned Bits;
+unsigned Bits = 0;
 
 enum { InResultTypeMask = 1 };
 
   public:
-FunctionTypeDepthState() : Bits(0) {}
+FunctionTypeDepthState() = default;
 
 /// The number of function types we're inside.
 unsigned getDepth() const {



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


[PATCH] D153701: [Clang] Implement P2718R0 "Lifetime extension in range-based for loops"

2023-08-20 Thread Yurong via Phabricator via cfe-commits
yronglin updated this revision to Diff 551851.
yronglin added a comment.

Fix ci


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153701

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/AST/ast-dump-for-range-lifetime.cpp
  clang/test/CXX/special/class.temporary/p6.cpp

Index: clang/test/CXX/special/class.temporary/p6.cpp
===
--- clang/test/CXX/special/class.temporary/p6.cpp
+++ clang/test/CXX/special/class.temporary/p6.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s --implicit-check-not='call{{.*}}dtor'
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK-CXX23,CHECK-CXX23-NEXT
 
 namespace std {
   typedef decltype(sizeof(int)) size_t;
@@ -238,3 +239,236 @@
   // CHECK: call {{.*}}dtor
   // CHECK: }
 }
+
+namespace P2718R0 {
+
+// Test basic
+struct A {
+  int a[3] = {1, 2, 3};
+  A() {}
+  ~A() {}
+  const int *begin() const { return a; }
+  const int *end() const { return a + 3; }
+  A& r() { return *this; }
+  A g() { return A(); }
+};
+
+A g() { return A(); }
+const A (const A ) { return t; }
+
+void test1() {
+  [[maybe_unused]] int sum = 0;
+  // CHECK-CXX23: void @_ZN7P2718R05test1Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for (auto e : f1(g()))
+sum += e;
+}
+
+struct B : A {};
+int ((const A *))[3];
+const A *g(const A &);
+void bar(int) {}
+
+void test2() {
+  // CHECK-CXX23: void @_ZN7P2718R05test2Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01BD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for (auto e : f(g(B(
+bar(e);
+}
+
+// Test discard statement.
+struct LockGuard {
+LockGuard() {}
+~LockGuard() {}
+};
+
+void test3() {
+  int v[] = {42, 17, 13};
+
+  // CHECK-CXX23: void @_ZN7P2718R05test3Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R09LockGuardD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for ([[maybe_unused]] int x : static_cast(LockGuard()), v)
+LockGuard guard;
+  
+  // CHECK-CXX23: for.cond.cleanup11:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R09LockGuardD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end17
+  for ([[maybe_unused]] int x : (void)LockGuard(), v)
+LockGuard guard;
+  
+  // CHECK-CXX23: for.cond.cleanup27:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R09LockGuardD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end33
+  for ([[maybe_unused]] int x : LockGuard(), v)
+LockGuard guard;
+}
+
+// Test default arg
+int (_arg_fn(const A & = A()))[3];
+void test4() {
+
+  // CHECK-CXX23: void @_ZN7P2718R05test4Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for (auto e : default_arg_fn()) 
+bar(e);
+}
+
+struct DefaultA {
+  DefaultA() {}
+  ~DefaultA() {}
+};
+
+A foo(const A&, const DefaultA  = DefaultA()) {
+  return A();
+}
+
+void test5() {
+  // CHECK-CXX23: void @_ZN7P2718R05test5Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for (auto e : default_arg_fn(foo(foo(foo(A())
+bar(e);
+}
+
+struct C : public A {
+  C() {}
+  C(int, const C &, const DefaultA & = DefaultA()) {}
+};
+
+void test6() {
+  // CHECK-CXX23: void @_ZN7P2718R05test6Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01CD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01CD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01CD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01CD1Ev(
+  // CHECK-CXX23: br label %for.end
+  for (auto e : C(0, C(0, C(0, C()
+bar(e);
+}
+
+// Test member call
+void test7() {
+  // CHECK-CXX23: void @_ZN7P2718R05test7Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // 

[PATCH] D153701: [Clang] Implement P2718R0 "Lifetime extension in range-based for loops"

2023-08-20 Thread Yurong via Phabricator via cfe-commits
yronglin updated this revision to Diff 551845.
yronglin added a comment.

Fix ci failure, and introduce an variable in ExpressionEvaluationContextRecord 
to rewrite default argument.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153701

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/ast-dump-for-range-lifetime.cpp
  clang/test/CXX/special/class.temporary/p6.cpp

Index: clang/test/CXX/special/class.temporary/p6.cpp
===
--- clang/test/CXX/special/class.temporary/p6.cpp
+++ clang/test/CXX/special/class.temporary/p6.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s --implicit-check-not='call{{.*}}dtor'
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK-CXX23,CHECK-CXX23-NEXT
 
 namespace std {
   typedef decltype(sizeof(int)) size_t;
@@ -238,3 +239,236 @@
   // CHECK: call {{.*}}dtor
   // CHECK: }
 }
+
+namespace P2718R0 {
+
+// Test basic
+struct A {
+  int a[3] = {1, 2, 3};
+  A() {}
+  ~A() {}
+  const int *begin() const { return a; }
+  const int *end() const { return a + 3; }
+  A& r() { return *this; }
+  A g() { return A(); }
+};
+
+A g() { return A(); }
+const A (const A ) { return t; }
+
+void test1() {
+  [[maybe_unused]] int sum = 0;
+  // CHECK-CXX23: void @_ZN7P2718R05test1Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for (auto e : f1(g()))
+sum += e;
+}
+
+struct B : A {};
+int ((const A *))[3];
+const A *g(const A &);
+void bar(int) {}
+
+void test2() {
+  // CHECK-CXX23: void @_ZN7P2718R05test2Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01BD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for (auto e : f(g(B(
+bar(e);
+}
+
+// Test discard statement.
+struct LockGuard {
+LockGuard() {}
+~LockGuard() {}
+};
+
+void test3() {
+  int v[] = {42, 17, 13};
+
+  // CHECK-CXX23: void @_ZN7P2718R05test3Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R09LockGuardD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for ([[maybe_unused]] int x : static_cast(LockGuard()), v)
+LockGuard guard;
+  
+  // CHECK-CXX23: for.cond.cleanup11:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R09LockGuardD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end17
+  for ([[maybe_unused]] int x : (void)LockGuard(), v)
+LockGuard guard;
+  
+  // CHECK-CXX23: for.cond.cleanup27:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R09LockGuardD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end33
+  for ([[maybe_unused]] int x : LockGuard(), v)
+LockGuard guard;
+}
+
+// Test default arg
+int (_arg_fn(const A & = A()))[3];
+void test4() {
+
+  // CHECK-CXX23: void @_ZN7P2718R05test4Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for (auto e : default_arg_fn()) 
+bar(e);
+}
+
+struct DefaultA {
+  DefaultA() {}
+  ~DefaultA() {}
+};
+
+A foo(const A&, const DefaultA  = DefaultA()) {
+  return A();
+}
+
+void test5() {
+  // CHECK-CXX23: void @_ZN7P2718R05test5Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: br label %for.end
+  for (auto e : default_arg_fn(foo(foo(foo(A())
+bar(e);
+}
+
+struct C : public A {
+  C() {}
+  C(int, const C &, const DefaultA & = DefaultA()) {}
+};
+
+void test6() {
+  // CHECK-CXX23: void @_ZN7P2718R05test6Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01CD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01CD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01CD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R08DefaultAD1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01CD1Ev(
+  // CHECK-CXX23: br label %for.end
+  for (auto e : C(0, C(0, C(0, C()
+bar(e);
+}
+
+// Test member call
+void test7() {
+  // CHECK-CXX23: void @_ZN7P2718R05test7Ev()
+  // CHECK-CXX23: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R01AD1Ev(
+  // CHECK-CXX23-NEXT: call void 

[PATCH] D158367: [AMDGPU] Add target feature gds/gws to clang

2023-08-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: b-sumner, arsenm, foad.
Herald added subscribers: StephenFan, kerbowa, hiraditya, tpr, dstuttard, 
jvesely, kzhuravl.
Herald added a project: All.
yaxunl requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

https://reviews.llvm.org/D158367

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/test/CodeGenOpenCL/amdgpu-features-readonly.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-gws-insts.cl
  llvm/lib/TargetParser/TargetParser.cpp

Index: llvm/lib/TargetParser/TargetParser.cpp
===
--- llvm/lib/TargetParser/TargetParser.cpp
+++ llvm/lib/TargetParser/TargetParser.cpp
@@ -286,6 +286,8 @@
   Features["gfx11-insts"] = true;
   Features["atomic-fadd-rtn-insts"] = true;
   Features["image-insts"] = true;
+  Features["gds"] = true;
+  Features["gws"] = true;
   break;
 case GK_GFX1036:
 case GK_GFX1035:
@@ -311,6 +313,8 @@
   Features["image-insts"] = true;
   Features["s-memrealtime"] = true;
   Features["s-memtime-inst"] = true;
+  Features["gds"] = true;
+  Features["gws"] = true;
   break;
 case GK_GFX1012:
 case GK_GFX1011:
@@ -333,6 +337,8 @@
   Features["image-insts"] = true;
   Features["s-memrealtime"] = true;
   Features["s-memtime-inst"] = true;
+  Features["gds"] = true;
+  Features["gws"] = true;
   break;
 case GK_GFX942:
 case GK_GFX941:
@@ -362,6 +368,7 @@
   Features["s-memrealtime"] = true;
   Features["ci-insts"] = true;
   Features["s-memtime-inst"] = true;
+  Features["gws"] = true;
   break;
 case GK_GFX90A:
   Features["gfx90a-insts"] = true;
@@ -412,6 +419,8 @@
 case GK_GFX600:
   Features["image-insts"] = true;
   Features["s-memtime-inst"] = true;
+  Features["gds"] = true;
+  Features["gws"] = true;
   break;
 case GK_NONE:
   break;
Index: clang/test/CodeGenOpenCL/builtins-amdgcn-gws-insts.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-gws-insts.cl
@@ -0,0 +1,31 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx803 -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx906 -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx90a -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx90c -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx940 -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1010 -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1030 -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1100 -S -emit-llvm -o - %s | FileCheck %s
+
+typedef unsigned int uint;
+
+// CHECK-LABEL: define dso_local amdgpu_kernel void @test_builtins_amdgcn_gws_insts
+// CHECK-SAME: (i32 noundef [[A:%.*]], i32 noundef [[B:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.amdgcn.ds.gws.init(i32 [[A]], i32 [[B]])
+// CHECK-NEXT:tail call void @llvm.amdgcn.ds.gws.barrier(i32 [[A]], i32 [[B]])
+// CHECK-NEXT:tail call void @llvm.amdgcn.ds.gws.sema.v(i32 [[A]])
+// CHECK-NEXT:tail call void @llvm.amdgcn.ds.gws.sema.br(i32 [[A]], i32 [[B]])
+// CHECK-NEXT:tail call void @llvm.amdgcn.ds.gws.sema.p(i32 [[A]])
+// CHECK-NEXT:ret void
+//
+kernel void test_builtins_amdgcn_gws_insts(uint a, uint b) {
+  __builtin_amdgcn_ds_gws_init(a, b);
+  __builtin_amdgcn_ds_gws_barrier(a, b);
+  __builtin_amdgcn_ds_gws_sema_v(a);
+  __builtin_amdgcn_ds_gws_sema_br(a, b);
+  __builtin_amdgcn_ds_gws_sema_p(a);
+}
Index: clang/test/CodeGenOpenCL/amdgpu-features-readonly.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/amdgpu-features-readonly.cl
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple amdgcn -target-feature +gds -o /dev/null %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=GDS %s
+// RUN: %clang_cc1 -triple amdgcn -target-feature +gws -o /dev/null %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=GWS %s
+
+// GDS: warning: feature flag '+gds' is ignored since the feature is read only [-Winvalid-command-line-argument]
+// GWS: warning: feature flag '+gws' is ignored since the feature is read only 

[PATCH] D158360: [docs] Update the static analyzer bug reporting page

2023-08-20 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc4e4b64c1249: [docs] Update the static analyzer bug 
reporting page (authored by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158360

Files:
  clang/www/analyzer/filing_bugs.html


Index: clang/www/analyzer/filing_bugs.html
===
--- clang/www/analyzer/filing_bugs.html
+++ clang/www/analyzer/filing_bugs.html
@@ -2,6 +2,7 @@
   "http://www.w3.org/TR/html4/strict.dtd;>
 
 
+  
   Filing Bugs and Feature Requests
   
   
@@ -21,8 +22,8 @@
 
 
 
-Include the checker build (for prebuilt Mac OS X binaries) or the SVN
-revision number.
+Include the checker build (for prebuilt Mac OS X binaries) or the git hash.
+
 
 Provide a self-contained, reduced test case that exhibits the issue you are
 experiencing.
@@ -33,28 +34,11 @@
 
 
 
-Outside of Apple
+Please https://llvm.org/docs/HowToSubmitABug.html;>file
+bugs and feature requests in
+https://github.com/llvm/llvm-project/issues;>LLVM's issue tracker
+and label the report with the clang:static analyzer label.
 
-Bugzilla
-
-Please https://bugs.llvm.org/enter_bug.cgi?product=clang;>file
-bugs in LLVM's Bugzilla database against the Clang Static Analyzer
-component.
-
-Bugreporter.apple.com
-
-If you are using the analyzer to analyze code associated with an Apple NDA
-(e.g., preview versions of SDKs or seed releases of Mac OS X) please file bug
-reports to Apple's https://feedbackassistant.apple.com/welcome;>Feedback Assistant web
-site.
-
-You are free to always file bugs through this website, but this option is 
less
-attractive than filing bug reports through Bugzilla as not everyone who works 
on
-the analyzer has access to that bug database.
-
-Apple-internal Users
-
-Please file bugs in Radar against the clang - static analyzer 
component.
 
 
 


Index: clang/www/analyzer/filing_bugs.html
===
--- clang/www/analyzer/filing_bugs.html
+++ clang/www/analyzer/filing_bugs.html
@@ -2,6 +2,7 @@
   "http://www.w3.org/TR/html4/strict.dtd;>
 
 
+  
   Filing Bugs and Feature Requests
   
   
@@ -21,8 +22,8 @@
 
 
 
-Include the checker build (for prebuilt Mac OS X binaries) or the SVN
-revision number.
+Include the checker build (for prebuilt Mac OS X binaries) or the git hash.
+
 
 Provide a self-contained, reduced test case that exhibits the issue you are
 experiencing.
@@ -33,28 +34,11 @@
 
 
 
-Outside of Apple
+Please https://llvm.org/docs/HowToSubmitABug.html;>file
+bugs and feature requests in
+https://github.com/llvm/llvm-project/issues;>LLVM's issue tracker
+and label the report with the clang:static analyzer label.
 
-Bugzilla
-
-Please https://bugs.llvm.org/enter_bug.cgi?product=clang;>file
-bugs in LLVM's Bugzilla database against the Clang Static Analyzer
-component.
-
-Bugreporter.apple.com
-
-If you are using the analyzer to analyze code associated with an Apple NDA
-(e.g., preview versions of SDKs or seed releases of Mac OS X) please file bug
-reports to Apple's https://feedbackassistant.apple.com/welcome;>Feedback Assistant web
-site.
-
-You are free to always file bugs through this website, but this option is less
-attractive than filing bug reports through Bugzilla as not everyone who works on
-the analyzer has access to that bug database.
-
-Apple-internal Users
-
-Please file bugs in Radar against the clang - static analyzer component.
 
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c4e4b64 - [docs] Update the static analyzer bug reporting page

2023-08-20 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-08-20T10:49:29-04:00
New Revision: c4e4b64c1249f1fc438abb72e2115d334c5ba476

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

LOG: [docs] Update the static analyzer bug reporting page

I happened to notice this page 
(https://clang-analyzer.llvm.org/filing_bugs.html)
was a bit stale, so I've updated and simplified it a bit.

* The page is now explicitly in UTF-8 (NFC)
* We no longer talk about Bugzilla and Apple's bug reporting tools, but
instead link to GitHub's issues page
* We now link to the general LLVM documentation on how to submit a bug

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

Added: 


Modified: 
clang/www/analyzer/filing_bugs.html

Removed: 




diff  --git a/clang/www/analyzer/filing_bugs.html 
b/clang/www/analyzer/filing_bugs.html
index e802b6d9bafcca..f7183a9a0694b4 100644
--- a/clang/www/analyzer/filing_bugs.html
+++ b/clang/www/analyzer/filing_bugs.html
@@ -2,6 +2,7 @@
   "http://www.w3.org/TR/html4/strict.dtd;>
 
 
+  
   Filing Bugs and Feature Requests
   
   
@@ -21,8 +22,8 @@ Filing Bugs and Feature Requests
 
 
 
-Include the checker build (for prebuilt Mac OS X binaries) or the SVN
-revision number.
+Include the checker build (for prebuilt Mac OS X binaries) or the git hash.
+
 
 Provide a self-contained, reduced test case that exhibits the issue you are
 experiencing.
@@ -33,28 +34,11 @@ Filing Bugs and Feature Requests
 
 
 
-Outside of Apple
+Please https://llvm.org/docs/HowToSubmitABug.html;>file
+bugs and feature requests in
+https://github.com/llvm/llvm-project/issues;>LLVM's issue tracker
+and label the report with the clang:static analyzer label.
 
-Bugzilla
-
-Please https://bugs.llvm.org/enter_bug.cgi?product=clang;>file
-bugs in LLVM's Bugzilla database against the Clang Static Analyzer
-component.
-
-Bugreporter.apple.com
-
-If you are using the analyzer to analyze code associated with an Apple NDA
-(e.g., preview versions of SDKs or seed releases of Mac OS X) please file bug
-reports to Apple's https://feedbackassistant.apple.com/welcome;>Feedback Assistant web
-site.
-
-You are free to always file bugs through this website, but this option is 
less
-attractive than filing bug reports through Bugzilla as not everyone who works 
on
-the analyzer has access to that bug database.
-
-Apple-internal Users
-
-Please file bugs in Radar against the clang - static analyzer 
component.
 
 
 



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


[PATCH] D157565: [CodeGen] Add AArch64 behavior to existing MFS tests

2023-08-20 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

reverted in 3d22dac6c3b97d7bb92f243886dfb0d32a5c42e9 
 for now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157565

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


[clang] 3d22dac - Revert "[clang][test] Refine clang machine-function-split tests."

2023-08-20 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2023-08-20T10:38:29-04:00
New Revision: 3d22dac6c3b97d7bb92f243886dfb0d32a5c42e9

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

LOG: Revert "[clang][test] Refine clang machine-function-split tests."

This reverts commit b9d079d6188b50730e0a67267b7fee36008435ce.
Breaks tests on Windows, see https://reviews.llvm.org/D157565#4600939

Added: 


Modified: 
clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
clang/test/Driver/fsplit-machine-functions.c
llvm/test/CodeGen/Generic/machine-function-splitter.ll

Removed: 
clang/test/CodeGen/fsplit-machine-functions.c



diff  --git a/clang/test/CodeGen/fsplit-machine-functions.c 
b/clang/test/CodeGen/fsplit-machine-functions.c
deleted file mode 100644
index dd8e4ff333f20d..00
--- a/clang/test/CodeGen/fsplit-machine-functions.c
+++ /dev/null
@@ -1,25 +0,0 @@
-// REQUIRES: x86-registered-target
-// REQUIRES: arm-registered-target
-// REQUIRES: nvptx-registered-target
-
-// Check -fsplit-machine-functions passed to cuda device causes a warning.
-// RUN: %clang_cc1 -triple nvptx-unknown-unknown -target-cpu sm_70 \
-// RUN: -fcuda-is-device -x cuda -fsplit-machine-functions -S %s \
-// RUN: -o %t 2>&1 | FileCheck %s --check-prefix=MFS1
-// MFS1: warning: -fsplit-machine-functions is not valid for nvptx
-
-// Check -fsplit-machine-functions passed to X86 does not cause any warning.
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsplit-machine-functions \
-// RUN: -o %t -S %s && { echo "empty output causes FileCheck to fail" ; } \
-// RUN: 2>&1 | FileCheck %s --check-prefix=MFS2
-// MFS2-NOT: warning:
-
-// Check -fsplit-machine-functions passed to ARM does cause a warning.
-// RUN: %clang_cc1 -triple arm-unknown-linux-gnueabi \
-// RUN: -fsplit-machine-functions -S %s -o %t \
-// RUN: 2>&1 | FileCheck -check-prefix=MFS3 %s
-// MFS3: warning: -fsplit-machine-functions is not valid for arm
-
-int foo() {
-  return 13;
-}

diff  --git a/clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c 
b/clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
index aab1179b3e731e..f2b09e13d80b68 100644
--- a/clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
+++ b/clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
@@ -1,28 +1,68 @@
+// REQUIRES: system-linux
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
+// REQUIRES: shell
 
 // Check that -fsplit-machine-functions is passed to both x86 and cuda
 // compilation and does not cause driver error.
-// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN:   cd "$(dirname "%t")" ; \
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
 // RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s \
 // RUN: 2>&1 | FileCheck %s --check-prefix=MFS1
 // MFS1: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
 // MFS1: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
 
+// Check that -fsplit-machine-functions is passed to cuda and it
+// causes a warning.
+// RUN:   cd "$(dirname "%t")" ; \
+// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s \
+// RUN: 2>&1 | FileCheck %s --check-prefix=MFS2
+// MFS2: warning: -fsplit-machine-functions is not valid for nvptx
+
 // Check that -Xarch_host -fsplit-machine-functions is passed only to
 // native compilation.
-// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN:   cd "$(dirname "%t")" ; \
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
 // RUN: --cuda-gpu-arch=sm_70 -x cuda -Xarch_host \
 // RUN: -fsplit-machine-functions -S %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=MFS2
-// MFS2: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
-// MFS2-NOT: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
+// RUN: 2>&1 | FileCheck %s --check-prefix=MFS3
+// MFS3: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
+// MFS3-NOT: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
+
+// Check that -Xarch_host -fsplit-machine-functions does not cause any warning.
+// RUN:   cd "$(dirname "%t")" ; \
+// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN  --cuda-gpu-arch=sm_70 -x cuda -Xarch_host \
+// RUN  -fsplit-machine-functions -S %s || { echo \
+// RUN  "warning: -fsplit-machine-functions is not valid for" ; } \
+// RUN  2>&1 | FileCheck %s --check-prefix=MFS4
+// MFS4-NOT: warning: -fsplit-machine-functions is not valid for
+
+// Check that -Xarch_device -fsplit-machine-functions does cause the warning.
+// 

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

2023-08-20 Thread Arkadiy Yudintsev via Phabricator via cfe-commits
d0nc1h0t created this revision.
d0nc1h0t added a project: clang-format.
Herald added projects: All, clang.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
Herald added a comment.
d0nc1h0t requested review of this revision.

NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please 
try to ensure all code changes have a unit test (unless this is an `NFC` or 
refactoring, adding documentation etc..)

Add your unit tests in `clang/unittests/Format` and you can build with `ninja 
FormatTests`.  We recommend using the `verifyFormat(xxx)` format of unit tests 
rather than `EXPECT_EQ` as this will ensure you change is tolerant to random 
whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can 
happen if you are trying to improve the annotation phase to ensure we are 
correctly identifying the type of a token, please add a token annotator test in 
`TokenAnnotatorTest.cpp`


Fixes #64701 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158363

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -390,7 +390,7 @@
   for (auto *CompactedLine = I + J; CompactedLine <= ClosingLine;
++CompactedLine) {
 if (!(*CompactedLine)->InPPDirective)
-  (*CompactedLine)->Level -= OutdentBy;
+  (*CompactedLine)->Level -= std::min(OutdentBy, 
(*CompactedLine)->Level);
   }
 }
 return J - 1;


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -390,7 +390,7 @@
   for (auto *CompactedLine = I + J; CompactedLine <= ClosingLine;
++CompactedLine) {
 if (!(*CompactedLine)->InPPDirective)
-  (*CompactedLine)->Level -= OutdentBy;
+  (*CompactedLine)->Level -= std::min(OutdentBy, (*CompactedLine)->Level);
   }
 }
 return J - 1;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158360: [docs] Update the static analyzer bug reporting page

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

Makes sense to me, thanks!

I'm not sure though how much we wanna invest into maintaining these handwritten 
htmls. I would prefer moving away from these. It would likely also fit more 
nicely with how the other tools look like in terms of styling.
No actions expected, this is more of just expressing my position on these 
analyzer HTML files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158360

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


[PATCH] D158360: [docs] Update the static analyzer bug reporting page

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

Makes sense to me. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158360

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


[PATCH] D158361: [clang][Sema] Fix a copy/paste bug in ~Sema()

2023-08-20 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added a reviewer: saar.raz.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158361

Files:
  clang/lib/Sema/Sema.cpp


Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -483,7 +483,7 @@
 
   // Delete cached satisfactions.
   std::vector Satisfactions;
-  Satisfactions.reserve(Satisfactions.size());
+  Satisfactions.reserve(SatisfactionCache.size());
   for (auto  : SatisfactionCache)
 Satisfactions.push_back();
   for (auto *Node : Satisfactions)


Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -483,7 +483,7 @@
 
   // Delete cached satisfactions.
   std::vector Satisfactions;
-  Satisfactions.reserve(Satisfactions.size());
+  Satisfactions.reserve(SatisfactionCache.size());
   for (auto  : SatisfactionCache)
 Satisfactions.push_back();
   for (auto *Node : Satisfactions)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158360: [docs] Update the static analyzer bug reporting page

2023-08-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: NoQ, steakhal, zaks.anna, xazax.hun.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.

I happened to notice this page 
(https://clang-analyzer.llvm.org/filing_bugs.html) was a bit stale, so I've 
updated and simplified it a bit.

1. The page is now explicitly in UTF-8 (NFC)
2. We no longer talk about Bugzilla and Apple's bug reporting tools, but 
instead link to GitHub's issues page
3. We now link to the general LLVM documentation on how to submit a bug


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158360

Files:
  clang/www/analyzer/filing_bugs.html


Index: clang/www/analyzer/filing_bugs.html
===
--- clang/www/analyzer/filing_bugs.html
+++ clang/www/analyzer/filing_bugs.html
@@ -2,6 +2,7 @@
   "http://www.w3.org/TR/html4/strict.dtd;>
 
 
+  
   Filing Bugs and Feature Requests
   
   
@@ -21,8 +22,8 @@
 
 
 
-Include the checker build (for prebuilt Mac OS X binaries) or the SVN
-revision number.
+Include the checker build (for prebuilt Mac OS X binaries) or the git hash.
+
 
 Provide a self-contained, reduced test case that exhibits the issue you are
 experiencing.
@@ -33,28 +34,11 @@
 
 
 
-Outside of Apple
+Please https://llvm.org/docs/HowToSubmitABug.html;>file
+bugs and feature requests in
+https://github.com/llvm/llvm-project/issues;>LLVM's issue tracker
+and label the report with the clang:static analyzer label.
 
-Bugzilla
-
-Please https://bugs.llvm.org/enter_bug.cgi?product=clang;>file
-bugs in LLVM's Bugzilla database against the Clang Static Analyzer
-component.
-
-Bugreporter.apple.com
-
-If you are using the analyzer to analyze code associated with an Apple NDA
-(e.g., preview versions of SDKs or seed releases of Mac OS X) please file bug
-reports to Apple's https://feedbackassistant.apple.com/welcome;>Feedback Assistant web
-site.
-
-You are free to always file bugs through this website, but this option is 
less
-attractive than filing bug reports through Bugzilla as not everyone who works 
on
-the analyzer has access to that bug database.
-
-Apple-internal Users
-
-Please file bugs in Radar against the clang - static analyzer 
component.
 
 
 


Index: clang/www/analyzer/filing_bugs.html
===
--- clang/www/analyzer/filing_bugs.html
+++ clang/www/analyzer/filing_bugs.html
@@ -2,6 +2,7 @@
   "http://www.w3.org/TR/html4/strict.dtd;>
 
 
+  
   Filing Bugs and Feature Requests
   
   
@@ -21,8 +22,8 @@
 
 
 
-Include the checker build (for prebuilt Mac OS X binaries) or the SVN
-revision number.
+Include the checker build (for prebuilt Mac OS X binaries) or the git hash.
+
 
 Provide a self-contained, reduced test case that exhibits the issue you are
 experiencing.
@@ -33,28 +34,11 @@
 
 
 
-Outside of Apple
+Please https://llvm.org/docs/HowToSubmitABug.html;>file
+bugs and feature requests in
+https://github.com/llvm/llvm-project/issues;>LLVM's issue tracker
+and label the report with the clang:static analyzer label.
 
-Bugzilla
-
-Please https://bugs.llvm.org/enter_bug.cgi?product=clang;>file
-bugs in LLVM's Bugzilla database against the Clang Static Analyzer
-component.
-
-Bugreporter.apple.com
-
-If you are using the analyzer to analyze code associated with an Apple NDA
-(e.g., preview versions of SDKs or seed releases of Mac OS X) please file bug
-reports to Apple's https://feedbackassistant.apple.com/welcome;>Feedback Assistant web
-site.
-
-You are free to always file bugs through this website, but this option is less
-attractive than filing bug reports through Bugzilla as not everyone who works on
-the analyzer has access to that bug database.
-
-Apple-internal Users
-
-Please file bugs in Radar against the clang - static analyzer component.
 
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b1aa7cd - [clang][Sema][NFC] Make some locals const in getUndefinedButUsed()

2023-08-20 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-20T13:55:25+02:00
New Revision: b1aa7cd8a9f3793a04e15af813082b996519be44

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

LOG: [clang][Sema][NFC] Make some locals const in getUndefinedButUsed()

Added: 


Modified: 
clang/lib/Sema/Sema.cpp

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index ccf9b820183b0c..faf375fb8fab3e 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -825,7 +825,7 @@ void Sema::getUndefinedButUsed(
   continue;
 }
 
-if (FunctionDecl *FD = dyn_cast(ND)) {
+if (const auto *FD = dyn_cast(ND)) {
   if (FD->isDefined())
 continue;
   if (FD->isExternallyVisible() &&
@@ -836,7 +836,7 @@ void Sema::getUndefinedButUsed(
   if (FD->getBuiltinID())
 continue;
 } else {
-  auto *VD = cast(ND);
+  const auto *VD = cast(ND);
   if (VD->hasDefinition() != VarDecl::DeclarationOnly)
 continue;
   if (VD->isExternallyVisible() &&



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


[PATCH] D158065: [PowerPC] Implement builtin for mffsl

2023-08-20 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.

Thanks for implementing this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158065

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


[PATCH] D158066: [PowerPC] Fix use of FPSCR builtins in smmintrin.h

2023-08-20 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

In D158066#4593961 , @qiucf wrote:

> CC @amyk @quinnp Any comments about the naming?
>
> I see some `__builtin_ppc_xxx` are aliased into `__builtin_xxx` by 
> `defineXLCompatMacros`. But these are not XL-compatible builtins, and the 
> macros do not always work.

It should be perfectly fine to provide pre-defined macros for these to match 
GCC on PowerPC. The reason we went with the macro solution is to avoid 
polluting the builtins namespace for other targets.

Also, please add some C++ tests for these PPC wrappers so that we aren't 
surprised again when someone tries to use these in their C++ code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158066

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


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

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

Changed prior to commit:
  https://reviews.llvm.org/D156027?vs=548522=551816#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156027

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Context.cpp
  clang/test/AST/Interp/lambda.cpp
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -795,3 +795,44 @@
 
 };
 #endif
+
+namespace CompositeDefaultArgs {
+  struct Foo {
+int a;
+int b;
+constexpr Foo() : a(12), b(13) {}
+  };
+
+  class Bar {
+  public:
+bool B = false;
+
+constexpr int someFunc(Foo F = Foo()) {
+  this->B = true;
+  return 5;
+}
+  };
+
+  constexpr bool testMe() {
+Bar B;
+B.someFunc();
+return B.B;
+  }
+  static_assert(testMe(), "");
+}
+
+constexpr bool BPand(BoolPair bp) {
+  return bp.first && bp.second;
+}
+static_assert(BPand(BoolPair{true, false}) == false, "");
+
+namespace TemporaryObjectExpr {
+  struct F {
+int a;
+constexpr F() : a(12) {}
+  };
+  constexpr int foo(F f) {
+return 0;
+  }
+  static_assert(foo(F()) == 0, "");
+}
Index: clang/test/AST/Interp/lambda.cpp
===
--- clang/test/AST/Interp/lambda.cpp
+++ clang/test/AST/Interp/lambda.cpp
@@ -103,8 +103,7 @@
 
 return a;
   }
-  /// FIXME: This should work in the new interpreter.
-  static_assert(foo() == 1); // expected-error {{not an integral constant expression}}
+  static_assert(foo() == 1);
 }
 
 namespace StaticInvoker {
@@ -136,10 +135,6 @@
   }
   static_assert(sv4(12) == 12);
 
-
-
-  /// FIXME: This is broken for lambda-unrelated reasons.
-#if 0
   constexpr int sv5(int i) {
 struct F { int a; float f; };
 auto l = [](int m, F f) { return m; };
@@ -147,7 +142,6 @@
 return fp(i, F{12, 14.0});
   }
   static_assert(sv5(12) == 12);
-#endif
 
   constexpr int sv6(int i) {
 struct F { int a;
@@ -162,3 +156,26 @@
   }
   static_assert(sv6(12) == 12);
 }
+
+namespace LambdasAsParams {
+  template
+  constexpr auto call(F f) {
+return f();
+  }
+  static_assert(call([](){ return 1;}) == 1);
+  static_assert(call([](){ return 2;}) == 2);
+
+
+  constexpr unsigned L = call([](){ return 12;});
+  static_assert(L == 12);
+
+
+  constexpr float heh() {
+auto a = []() {
+  return 1.0;
+};
+
+return static_cast(a());
+  }
+  static_assert(heh() == 1.0);
+}
Index: clang/lib/AST/Interp/Context.cpp
===
--- clang/lib/AST/Interp/Context.cpp
+++ clang/lib/AST/Interp/Context.cpp
@@ -128,7 +128,7 @@
 return PT_Float;
 
   if (T->isFunctionPointerType() || T->isFunctionReferenceType() ||
-  T->isFunctionType())
+  T->isFunctionType() || T->isSpecificBuiltinType(BuiltinType::BoundMember))
 return PT_FnPtr;
 
   if (T->isReferenceType() || T->isPointerType())
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -83,6 +83,7 @@
   bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E);
   bool VisitMemberExpr(const MemberExpr *E);
   bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E);
+  bool VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E);
   bool VisitOpaqueValueExpr(const OpaqueValueExpr *E);
   bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E);
   bool VisitStringLiteral(const StringLiteral *E);
@@ -93,7 +94,6 @@
   bool VisitExprWithCleanups(const ExprWithCleanups *E);
   bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
   bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E);
-  bool VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *E);
   bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
   bool VisitTypeTraitExpr(const TypeTraitExpr *E);
   bool VisitLambdaExpr(const LambdaExpr *E);
@@ -101,6 +101,7 @@
   bool VisitCXXThrowExpr(const CXXThrowExpr *E);
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E);
   bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E);
+  bool VisitCXXConstructExpr(const CXXConstructExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
@@ -136,17 +137,21 @@
 }
 llvm_unreachable("not a primitive type");
   }
-
-  /// Evaluates an expression for side effects and discards the result.
-  bool discard(const Expr *E);
-  /// Evaluates an expression and places 

[clang] 6dfe555 - [clang][Interp] Rework initializers

2023-08-20 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-20T13:33:08+02:00
New Revision: 6dfe55569d88ff654d13e6c09267eff0cd9c9f0d

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

LOG: [clang][Interp] Rework initializers

Before this patch, we had visitRecordInitializer() and
visitArrayInitializer(), which were different from the regular visit()
in that they expected a pointer on the top of the stack, which they
initialized. For example, visitArrayInitializer handled InitListExprs by
looping over the members and initializing the elements of that pointer.

However, this had a few corner cases and problems. For example, in
visitLambdaExpr() (a lambda is always of record type), it was not clear
whether we should always create a new local variable to save the lambda
to, or not. This is why https://reviews.llvm.org/D153616 changed
things around.

This patch changes the visiting functions to:

 - visit(): Always leaves a new value on the stack. If the expression
   can be mapped to a primitive type, it's just visited and the value is
   put on the stack. If it's of composite type, this function will
   create a local variable for the expression value and call
   visitInitializer(). The pointer to the local variable will stay on
   the stack.

 - visitInitializer(): Visits the given expression, assuming there is a
   pointer on top of the stack that will be initialized by it.

 - discard(): Visit the expression for side-effects, but don't leave a
   value on the stack.

It also adds an additional Initializing flag to differentiate between the 
initializing and non-initializing case.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/Context.cpp
clang/test/AST/Interp/lambda.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 94eb1998839f4a..d8a4ca0db12fc8 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -43,18 +43,25 @@ template  class DeclScope final : public 
VariableScope {
 template  class OptionScope final {
 public:
   /// Root constructor, compiling or discarding primitives.
-  OptionScope(ByteCodeExprGen *Ctx, bool NewDiscardResult)
-  : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult) {
+  OptionScope(ByteCodeExprGen *Ctx, bool NewDiscardResult,
+  bool NewInitializing)
+  : Ctx(Ctx), OldDiscardResult(Ctx->DiscardResult),
+OldInitializing(Ctx->Initializing) {
 Ctx->DiscardResult = NewDiscardResult;
+Ctx->Initializing = NewInitializing;
   }
 
-  ~OptionScope() { Ctx->DiscardResult = OldDiscardResult; }
+  ~OptionScope() {
+Ctx->DiscardResult = OldDiscardResult;
+Ctx->Initializing = OldInitializing;
+  }
 
 private:
   /// Parent context.
   ByteCodeExprGen *Ctx;
   /// Old discard flag to restore.
   bool OldDiscardResult;
+  bool OldInitializing;
 };
 
 } // namespace interp
@@ -144,9 +151,7 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
   case CK_NoOp:
   case CK_UserDefinedConversion:
   case CK_BitCast:
-if (DiscardResult)
-  return this->discard(SubExpr);
-return this->visit(SubExpr);
+return this->delegate(SubExpr);
 
   case CK_IntegralToBoolean:
   case CK_IntegralCast: {
@@ -245,7 +250,8 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
   return this->discard(RHS);
 
 // Otherwise, visit RHS and optionally discard its value.
-return Discard(this->visit(RHS));
+return Discard(Initializing ? this->visitInitializer(RHS)
+: this->visit(RHS));
   }
 
   if (!LT || !RT || !T)
@@ -438,12 +444,38 @@ bool ByteCodeExprGen::VisitLogicalBinOp(const 
BinaryOperator *E) {
 
 template 
 bool ByteCodeExprGen::VisitImplicitValueInitExpr(const 
ImplicitValueInitExpr *E) {
-  std::optional T = classify(E);
+  QualType QT = E->getType();
 
-  if (!T)
+  if (classify(QT))
+return this->visitZeroInitializer(QT, E);
+
+  if (QT->isRecordType())
 return false;
 
-  return this->visitZeroInitializer(E->getType(), E);
+  if (QT->isArrayType()) {
+const ArrayType *AT = QT->getAsArrayTypeUnsafe();
+assert(AT);
+const auto *CAT = cast(AT);
+size_t NumElems = CAT->getSize().getZExtValue();
+
+if (std::optional ElemT = classify(CAT->getElementType())) {
+  // TODO(perf): For int and bool types, we can probably just skip this
+  //   since we memset our Block*s to 0 and so we have the desired value
+  //   without this.
+  for (size_t I = 0; I != NumElems; ++I) {
+if (!this->visitZeroInitializer(CAT->getElementType(), E))
+

[PATCH] D152132: [clang][Interp] Fix lifetime diagnostics for dead records

2023-08-20 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG39236e9c60e5: [clang][Interp] Fix lifetime diagnostics for 
dead records (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152132

Files:
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/InterpBlock.h
  clang/lib/AST/Interp/InterpState.cpp
  clang/test/AST/Interp/lifetimes.cpp


Index: clang/test/AST/Interp/lifetimes.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/lifetimes.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+struct Foo {
+  int a;
+};
+
+constexpr int dead1() { // expected-error {{never produces a constant 
expression}}
+
+  Foo *F2 = nullptr;
+  {
+Foo F{12}; // expected-note 2{{declared here}}
+F2 = 
+  } // Ends lifetime of F.
+
+  return F2->a; // expected-note 2{{read of variable whose lifetime has 
ended}} \
+// ref-note {{read of object outside its lifetime is not 
allowed in a constant expression}}
+}
+static_assert(dead1() == 1, ""); // expected-error {{not an integral constant 
expression}} \
+ // expected-note {{in call to}} \
+ // ref-error {{not an integral constant 
expression}} \
+ // ref-note {{in call to}} \
+
+
Index: clang/lib/AST/Interp/InterpState.cpp
===
--- clang/lib/AST/Interp/InterpState.cpp
+++ clang/lib/AST/Interp/InterpState.cpp
@@ -58,9 +58,13 @@
 reinterpret_cast(std::malloc(sizeof(DeadBlock) + Size));
 auto *D = new (Memory) DeadBlock(DeadBlocks, B);
 
-// Move data from one block to another.
-if (Desc->MoveFn)
+// Move data and metadata from the old block to the new (dead)block.
+if (Desc->MoveFn) {
   Desc->MoveFn(B, B->data(), D->data(), Desc);
+  if (Desc->getMetadataSize() > 0)
+std::memcpy(D->rawData(), B->rawData(), Desc->getMetadataSize());
+}
+
   } else {
 // Free storage, if necessary.
 if (Desc->DtorFn)
Index: clang/lib/AST/Interp/InterpBlock.h
===
--- clang/lib/AST/Interp/InterpBlock.h
+++ clang/lib/AST/Interp/InterpBlock.h
@@ -156,6 +156,7 @@
 
   /// Returns a pointer to the stored data.
   std::byte *data() { return B.data(); }
+  std::byte *rawData() { return B.rawData(); }
 
 private:
   friend class Block;
Index: clang/lib/AST/Interp/Descriptor.cpp
===
--- clang/lib/AST/Interp/Descriptor.cpp
+++ clang/lib/AST/Interp/Descriptor.cpp
@@ -170,9 +170,8 @@
const Descriptor *D) {
   for (const auto  : D->ElemRecord->fields()) {
 auto FieldOff = F.Offset;
-auto FieldDesc = F.Desc;
+auto *FieldDesc = F.Desc;
 
-*(reinterpret_cast(Dst + FieldOff) - 1) = FieldDesc;
 if (auto Fn = FieldDesc->MoveFn)
   Fn(B, Src + FieldOff, Dst + FieldOff, FieldDesc);
   }


Index: clang/test/AST/Interp/lifetimes.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/lifetimes.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+struct Foo {
+  int a;
+};
+
+constexpr int dead1() { // expected-error {{never produces a constant expression}}
+
+  Foo *F2 = nullptr;
+  {
+Foo F{12}; // expected-note 2{{declared here}}
+F2 = 
+  } // Ends lifetime of F.
+
+  return F2->a; // expected-note 2{{read of variable whose lifetime has ended}} \
+// ref-note {{read of object outside its lifetime is not allowed in a constant expression}}
+}
+static_assert(dead1() == 1, ""); // expected-error {{not an integral constant expression}} \
+ // expected-note {{in call to}} \
+ // ref-error {{not an integral constant expression}} \
+ // ref-note {{in call to}} \
+
+
Index: clang/lib/AST/Interp/InterpState.cpp
===
--- clang/lib/AST/Interp/InterpState.cpp
+++ clang/lib/AST/Interp/InterpState.cpp
@@ -58,9 +58,13 @@
 reinterpret_cast(std::malloc(sizeof(DeadBlock) + Size));
 auto *D = new (Memory) DeadBlock(DeadBlocks, B);
 
-// Move data from one block to another.
-if (Desc->MoveFn)
+// Move data and metadata from the old block to the new (dead)block.
+if (Desc->MoveFn) {
   Desc->MoveFn(B, B->data(), D->data(), Desc);
+  if (Desc->getMetadataSize() > 0)
+std::memcpy(D->rawData(), B->rawData(), Desc->getMetadataSize());
+}
+
 

[clang] 39236e9 - [clang][Interp] Fix lifetime diagnostics for dead records

2023-08-20 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-20T11:38:29+02:00
New Revision: 39236e9c60e50278d042304b13823e116b68ce78

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

LOG: [clang][Interp] Fix lifetime diagnostics for dead records

This used to crash the interpreter, either because we ran into the
assertion in CheckMutable() or because we accessed a Descriptor* pointer
preceding the field of a record. Those are preceded by an
InlineDescriptor though.

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

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

Modified: 
clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/InterpBlock.h
clang/lib/AST/Interp/InterpState.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index 521ad16e367195..b4c26ac88b5c6b 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -170,9 +170,8 @@ static void moveRecord(Block *B, const std::byte *Src, 
std::byte *Dst,
const Descriptor *D) {
   for (const auto  : D->ElemRecord->fields()) {
 auto FieldOff = F.Offset;
-auto FieldDesc = F.Desc;
+auto *FieldDesc = F.Desc;
 
-*(reinterpret_cast(Dst + FieldOff) - 1) = FieldDesc;
 if (auto Fn = FieldDesc->MoveFn)
   Fn(B, Src + FieldOff, Dst + FieldOff, FieldDesc);
   }

diff  --git a/clang/lib/AST/Interp/InterpBlock.h 
b/clang/lib/AST/Interp/InterpBlock.h
index 7c6e3f4706f37c..5112108e6f010a 100644
--- a/clang/lib/AST/Interp/InterpBlock.h
+++ b/clang/lib/AST/Interp/InterpBlock.h
@@ -156,6 +156,7 @@ class DeadBlock final {
 
   /// Returns a pointer to the stored data.
   std::byte *data() { return B.data(); }
+  std::byte *rawData() { return B.rawData(); }
 
 private:
   friend class Block;

diff  --git a/clang/lib/AST/Interp/InterpState.cpp 
b/clang/lib/AST/Interp/InterpState.cpp
index 2596c56b4e095c..4f050baea39e79 100644
--- a/clang/lib/AST/Interp/InterpState.cpp
+++ b/clang/lib/AST/Interp/InterpState.cpp
@@ -58,9 +58,13 @@ void InterpState::deallocate(Block *B) {
 reinterpret_cast(std::malloc(sizeof(DeadBlock) + Size));
 auto *D = new (Memory) DeadBlock(DeadBlocks, B);
 
-// Move data from one block to another.
-if (Desc->MoveFn)
+// Move data and metadata from the old block to the new (dead)block.
+if (Desc->MoveFn) {
   Desc->MoveFn(B, B->data(), D->data(), Desc);
+  if (Desc->getMetadataSize() > 0)
+std::memcpy(D->rawData(), B->rawData(), Desc->getMetadataSize());
+}
+
   } else {
 // Free storage, if necessary.
 if (Desc->DtorFn)

diff  --git a/clang/test/AST/Interp/lifetimes.cpp 
b/clang/test/AST/Interp/lifetimes.cpp
new file mode 100644
index 00..c1046e56892075
--- /dev/null
+++ b/clang/test/AST/Interp/lifetimes.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+struct Foo {
+  int a;
+};
+
+constexpr int dead1() { // expected-error {{never produces a constant 
expression}}
+
+  Foo *F2 = nullptr;
+  {
+Foo F{12}; // expected-note 2{{declared here}}
+F2 = 
+  } // Ends lifetime of F.
+
+  return F2->a; // expected-note 2{{read of variable whose lifetime has 
ended}} \
+// ref-note {{read of object outside its lifetime is not 
allowed in a constant expression}}
+}
+static_assert(dead1() == 1, ""); // expected-error {{not an integral constant 
expression}} \
+ // expected-note {{in call to}} \
+ // ref-error {{not an integral constant 
expression}} \
+ // ref-note {{in call to}} \
+
+



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


[PATCH] D144457: [clang][Interp] Handle global composite temporaries

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

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144457

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Descriptor.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/Pointer.cpp
  clang/lib/AST/Interp/Pointer.h
  clang/lib/AST/Interp/Record.h
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -114,6 +114,21 @@
 static_assert(c2.a == 100, "");
 static_assert(c2.b == 200, "");
 
+
+/// A global, composite temporary variable.
+constexpr const C  = C().get();
+
+/// Same, but with a bitfield.
+class D {
+public:
+  unsigned a : 4;
+  constexpr D() : a(15) {}
+  constexpr D get() const {
+return *this;
+  }
+};
+constexpr const D  = D().get();
+
 constexpr int getB() {
   C c;
   int  = c.b;
Index: clang/lib/AST/Interp/Record.h
===
--- clang/lib/AST/Interp/Record.h
+++ clang/lib/AST/Interp/Record.h
@@ -87,7 +87,10 @@
   }
 
   unsigned getNumBases() const { return Bases.size(); }
-  const Base *getBase(unsigned I) const { return [I]; }
+  const Base *getBase(unsigned I) const {
+assert(I < getNumBases());
+return [I];
+  }
 
   using const_virtual_iter = VirtualBaseList::const_iterator;
   llvm::iterator_range virtual_bases() const {
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -27,6 +27,7 @@
 class Block;
 class DeadBlock;
 class Pointer;
+class Context;
 enum PrimType : unsigned;
 
 class Pointer;
@@ -87,6 +88,9 @@
 return reinterpret_cast(Pointee) + Offset;
   }
 
+  /// Converts the pointer to an APValue that is an rvalue.
+  APValue toRValue(const Context ) const;
+
   /// Offsets a pointer inside an array.
   Pointer atIndex(unsigned Idx) const {
 if (Base == RootPtrMark)
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -7,9 +7,14 @@
 //===--===//
 
 #include "Pointer.h"
+#include "Boolean.h"
+#include "Context.h"
+#include "Floating.h"
 #include "Function.h"
+#include "Integral.h"
 #include "InterpBlock.h"
 #include "PrimType.h"
+#include "Record.h"
 
 using namespace clang;
 using namespace clang::interp;
@@ -217,3 +222,34 @@
 bool Pointer::hasSameArray(const Pointer , const Pointer ) {
   return hasSameBase(A, B) && A.Base == B.Base && A.getFieldDesc()->IsArray;
 }
+
+APValue Pointer::toRValue(const Context ) const {
+  // Primitives.
+  if (getFieldDesc()->isPrimitive()) {
+PrimType PT = *Ctx.classify(getType());
+TYPE_SWITCH(PT, return deref().toAPValue());
+llvm_unreachable("Unhandled PrimType?");
+  }
+
+  APValue Result;
+  // Records.
+  if (getFieldDesc()->isRecord()) {
+const Record *R = getRecord();
+Result =
+APValue(APValue::UninitStruct(), R->getNumBases(), R->getNumFields());
+
+for (unsigned I = 0; I != R->getNumFields(); ++I) {
+  const Pointer  = this->atField(R->getField(I)->Offset);
+  Result.getStructField(I) = FieldPtr.toRValue(Ctx);
+}
+
+for (unsigned I = 0; I != R->getNumBases(); ++I) {
+  const Pointer  = this->atField(R->getBase(I)->Offset);
+  Result.getStructBase(I) = BasePtr.toRValue(Ctx);
+}
+  }
+
+  // TODO: Arrays
+
+  return Result;
+}
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -353,6 +353,12 @@
 def InitGlobalTemp : AccessOpcode {
   let Args = [ArgUint32, ArgLETD];
 }
+// [Pointer] -> [Pointer]
+def InitGlobalTempComp : Opcode {
+  let Args = [ArgLETD];
+  let Types = [];
+  let HasGroup = 0;
+}
 // [Value] -> []
 def SetGlobal : AccessOpcode;
 
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -996,6 +996,19 @@
   return true;
 }
 
+/// 1) Converts the value on top of the stack to an APValue
+/// 2) Sets that APValue on \Temp
+/// 3) Initialized global with index \I with that
+inline bool InitGlobalTempComp(InterpState , CodePtr OpPC,
+   const LifetimeExtendedTemporaryDecl *Temp) {
+  assert(Temp);
+  const Pointer  = S.Stk.peek();
+  APValue *Cached = 

[clang] 8a58f0d - [clang][Interp] Handle global composite temporaries

2023-08-20 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-20T11:15:17+02:00
New Revision: 8a58f0d370b004ec0c8f4af003da6b370f17ff44

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

LOG: [clang][Interp] Handle global composite temporaries

We only did this for primitive temporaries.

Unfortunately, the existing Pointer::toAPValue() won't do here, since
we're expected to set an rvalue on the LifetimeExtendedTemporaryDecl.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Descriptor.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/lib/AST/Interp/Pointer.cpp
clang/lib/AST/Interp/Pointer.h
clang/lib/AST/Interp/Record.h
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index f9a7cf7b743ef0..94eb1998839f4a 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -891,19 +891,28 @@ bool 
ByteCodeExprGen::VisitMaterializeTemporaryExpr(
 return this->discard(SubExpr);
 
   if (E->getStorageDuration() == SD_Static) {
-if (std::optional GlobalIndex = P.createGlobal(E)) {
-  const LifetimeExtendedTemporaryDecl *TempDecl =
-  E->getLifetimeExtendedTemporaryDecl();
+std::optional GlobalIndex = P.createGlobal(E);
+if (!GlobalIndex)
+  return false;
+
+const LifetimeExtendedTemporaryDecl *TempDecl =
+E->getLifetimeExtendedTemporaryDecl();
+assert(TempDecl);
 
+if (SubExprT) {
   if (!this->visitInitializer(SubExpr))
 return false;
-
   if (!this->emitInitGlobalTemp(*SubExprT, *GlobalIndex, TempDecl, E))
 return false;
   return this->emitGetPtrGlobal(*GlobalIndex, E);
 }
 
-return false;
+// Non-primitive values.
+if (!this->emitGetPtrGlobal(*GlobalIndex, E))
+  return false;
+if (!this->visitInitializer(SubExpr))
+  return false;
+return this->emitInitGlobalTempComp(TempDecl, E);
   }
 
   // For everyhing else, use local variables.

diff  --git a/clang/lib/AST/Interp/Descriptor.h 
b/clang/lib/AST/Interp/Descriptor.h
index 4d81d757b3976c..c5b73eca4c2e9f 100644
--- a/clang/lib/AST/Interp/Descriptor.h
+++ b/clang/lib/AST/Interp/Descriptor.h
@@ -187,6 +187,8 @@ struct Descriptor final {
 
   /// Checks if the descriptor is of an array.
   bool isArray() const { return IsArray; }
+  /// Checks if the descriptor is of a record.
+  bool isRecord() const { return !IsArray && ElemRecord; }
 };
 
 /// Bitfield tracking the initialisation status of elements of primitive 
arrays.

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 79995b5a74897c..cfef45d2e8d689 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -996,6 +996,19 @@ bool InitGlobalTemp(InterpState , CodePtr OpPC, uint32_t 
I,
   return true;
 }
 
+/// 1) Converts the value on top of the stack to an APValue
+/// 2) Sets that APValue on \Temp
+/// 3) Initialized global with index \I with that
+inline bool InitGlobalTempComp(InterpState , CodePtr OpPC,
+   const LifetimeExtendedTemporaryDecl *Temp) {
+  assert(Temp);
+  const Pointer  = S.Stk.peek();
+  APValue *Cached = Temp->getOrCreateValue(true);
+
+  *Cached = P.toRValue(S.getCtx());
+  return true;
+}
+
 template ::T>
 bool InitThisField(InterpState , CodePtr OpPC, uint32_t I) {
   if (S.checkingPotentialConstantExpression())

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index a990d1ed976600..f66c9492ecd1d4 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -353,6 +353,12 @@ def InitGlobal : AccessOpcode;
 def InitGlobalTemp : AccessOpcode {
   let Args = [ArgUint32, ArgLETD];
 }
+// [Pointer] -> [Pointer]
+def InitGlobalTempComp : Opcode {
+  let Args = [ArgLETD];
+  let Types = [];
+  let HasGroup = 0;
+}
 // [Value] -> []
 def SetGlobal : AccessOpcode;
 

diff  --git a/clang/lib/AST/Interp/Pointer.cpp 
b/clang/lib/AST/Interp/Pointer.cpp
index 613521facd63c2..e04d29b8bd81be 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -7,9 +7,14 @@
 
//===--===//
 
 #include "Pointer.h"
+#include "Boolean.h"
+#include "Context.h"
+#include "Floating.h"
 #include "Function.h"
+#include "Integral.h"
 #include "InterpBlock.h"
 #include "PrimType.h"
+#include "Record.h"
 
 using namespace clang;
 using namespace clang::interp;
@@ -217,3 +222,34 @@ bool Pointer::hasSameBase(const Pointer , const Pointer 
) {
 bool Pointer::hasSameArray(const Pointer , const Pointer ) {
   

[clang] ebbedc4 - [clang][Sema][NFC] Remove TileLoc parameter from getDestructorName()

2023-08-20 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-20T11:02:12+02:00
New Revision: ebbedc46f17ddfcb51d9781daa56d5dd011c3bb2

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

LOG: [clang][Sema][NFC] Remove TileLoc parameter from getDestructorName()

It's unused.

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/TreeTransform.h

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 05a0e43b5b73d9..c992e8763057bd 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6626,11 +6626,9 @@ class Sema final {
   ParsedType getConstructorName(IdentifierInfo , SourceLocation NameLoc,
 Scope *S, CXXScopeSpec ,
 bool EnteringContext);
-  ParsedType getDestructorName(SourceLocation TildeLoc,
-   IdentifierInfo , SourceLocation NameLoc,
+  ParsedType getDestructorName(IdentifierInfo , SourceLocation NameLoc,
Scope *S, CXXScopeSpec ,
-   ParsedType ObjectType,
-   bool EnteringContext);
+   ParsedType ObjectType, bool EnteringContext);
 
   ParsedType getDestructorTypeForDecltype(const DeclSpec ,
   ParsedType ObjectType);

diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index b035bd9db9d5c8..678ecad19ecd82 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3114,10 +3114,9 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec , 
ParsedType ObjectType,
 }
 
 // Note that this is a destructor name.
-ParsedType Ty = Actions.getDestructorName(TildeLoc, *ClassName,
-  ClassNameLoc, getCurScope(),
-  SS, ObjectType,
-  EnteringContext);
+ParsedType Ty =
+Actions.getDestructorName(*ClassName, ClassNameLoc, getCurScope(), SS,
+  ObjectType, EnteringContext);
 if (!Ty)
   return true;
 

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index dfb42799c67c10..a6e0a8abf81b9a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -138,9 +138,7 @@ ParsedType Sema::getConstructorName(IdentifierInfo ,
   return ParsedType::make(T);
 }
 
-ParsedType Sema::getDestructorName(SourceLocation TildeLoc,
-   IdentifierInfo ,
-   SourceLocation NameLoc,
+ParsedType Sema::getDestructorName(IdentifierInfo , SourceLocation NameLoc,
Scope *S, CXXScopeSpec ,
ParsedType ObjectTypePtr,
bool EnteringContext) {

diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index d99c1d62223720..1f41bbb189df26 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -12587,12 +12587,9 @@ 
TreeTransform::TransformCXXPseudoDestructorExpr(
 E->getDestroyedTypeLoc());
   } else {
 // Look for a destructor known with the given name.
-ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
-  *E->getDestroyedTypeIdentifier(),
-E->getDestroyedTypeLoc(),
-/*Scope=*/nullptr,
-SS, ObjectTypePtr,
-false);
+ParsedType T = SemaRef.getDestructorName(
+*E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
+/*Scope=*/nullptr, SS, ObjectTypePtr, false);
 if (!T)
   return ExprError();
 



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


[clang] e1dfbc4 - [clang][Sema][NFC] Modernize ActOnCallExpr

2023-08-20 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-20T10:37:58+02:00
New Revision: e1dfbc4e24dde8d09aa9f0e9f2228d732e002d0a

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

LOG: [clang][Sema][NFC] Modernize ActOnCallExpr

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 2848f1d4f96904..34284a8d9381c2 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7052,15 +7052,16 @@ 
tryImplicitlyCaptureThisIfImplicitMemberFunctionAccessWithDependentArgs(
 
 // Once a call is fully resolved, warn for unqualified calls to specific
 // C++ standard functions, like move and forward.
-static void DiagnosedUnqualifiedCallsToStdFunctions(Sema , CallExpr *Call) {
+static void DiagnosedUnqualifiedCallsToStdFunctions(Sema ,
+const CallExpr *Call) {
   // We are only checking unary move and forward so exit early here.
   if (Call->getNumArgs() != 1)
 return;
 
-  Expr *E = Call->getCallee()->IgnoreParenImpCasts();
+  const Expr *E = Call->getCallee()->IgnoreParenImpCasts();
   if (!E || isa(E))
 return;
-  DeclRefExpr *DRE = dyn_cast_or_null(E);
+  const DeclRefExpr *DRE = dyn_cast_if_present(E);
   if (!DRE || !DRE->getLocation().isValid())
 return;
 
@@ -7092,22 +7093,20 @@ ExprResult Sema::ActOnCallExpr(Scope *Scope, Expr *Fn, 
SourceLocation LParenLoc,
 
   // Diagnose uses of the C++20 "ADL-only template-id call" feature in earlier
   // language modes.
-  if (auto *ULE = dyn_cast(Fn)) {
-if (ULE->hasExplicitTemplateArgs() &&
-ULE->decls_begin() == ULE->decls_end()) {
-  Diag(Fn->getExprLoc(), getLangOpts().CPlusPlus20
- ? diag::warn_cxx17_compat_adl_only_template_id
- : diag::ext_adl_only_template_id)
-  << ULE->getName();
-}
+  if (const auto *ULE = dyn_cast(Fn);
+  ULE && ULE->hasExplicitTemplateArgs() &&
+  ULE->decls_begin() == ULE->decls_end()) {
+Diag(Fn->getExprLoc(), getLangOpts().CPlusPlus20
+   ? diag::warn_cxx17_compat_adl_only_template_id
+   : diag::ext_adl_only_template_id)
+<< ULE->getName();
   }
 
   if (LangOpts.OpenMP)
 Call = ActOnOpenMPCall(Call, Scope, LParenLoc, ArgExprs, RParenLoc,
ExecConfig);
   if (LangOpts.CPlusPlus) {
-CallExpr *CE = dyn_cast(Call.get());
-if (CE)
+if (const auto *CE = dyn_cast(Call.get()))
   DiagnosedUnqualifiedCallsToStdFunctions(*this, CE);
   }
   return Call;



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


[PATCH] D157990: [clangd] Add --query-driver flag to clangd-indexer

2023-08-20 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a comment.
This revision is now accepted and ready to land.

Thanks for the patch!

My thoughts are:

- As mentioned in the issue, I think this fills a logical gap: clangd-indexer 
is an alternative way of generating a project index to clangd's background 
indexer, so if clangd has a configuration feature needed for some projects 
(such as `--query-driver`), clangd-indexer should have an equivalent ability. 
(Processing `.clangd` config files is another such gap that I think would make 
sense to fill in the future.)
- The implementation is straightforward. I don't think it's interesting enough 
to warrant spending time writing an automated test for this (especially given 
that our existing `system-include-extractor.test` is not particularly easy / 
pleasant to work with.)

I would suggest waiting a few days to see if Sam has any input, otherwise I 
think this should be good to merge. Let me know if you need me to commit it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157990

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


[PATCH] D157201: [Clang] Support qualified name as member designator in offsetof

2023-08-20 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added inline comments.



Comment at: clang/test/SemaCXX/offsetof.cpp:106
+int x3[__builtin_offsetof(struct X2, X2::static_a) == 0 ? 1 : -1]; // 
expected-error{{no member named 'static_a'}}
+int x4[__builtin_offsetof(struct X2, X2::X2) == 0 ? 1 : -1]; // 
expected-error{{no member named 'X2'}}
+

yichi170 wrote:
> cor3ntin wrote:
> > yichi170 wrote:
> > > cor3ntin wrote:
> > > > yichi170 wrote:
> > > > > hubert.reinterpretcast wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > yichi170 wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > There's one more test I'd like to see:
> > > > > > > > > ```
> > > > > > > > > struct S {
> > > > > > > > >   int Foo;
> > > > > > > > > };
> > > > > > > > > 
> > > > > > > > > template 
> > > > > > > > > void func() {
> > > > > > > > >   static_assert(__builtin_offsetof(Ty, Ty::Foo) == 0, "");
> > > > > > > > > }
> > > > > > > > > 
> > > > > > > > > void inst() {
> > > > > > > > >   func();
> > > > > > > > > }
> > > > > > > > > ```
> > > > > > > > It would get the compile error in the current patch, but I 
> > > > > > > > think it should be compiled without any error, right?
> > > > > > > Correct, that should be accepted: https://godbolt.org/z/1f6a9Yaxa
> > > > > > Should expect this to pass too:
> > > > > > ```
> > > > > > template 
> > > > > > struct Z {
> > > > > >   static_assert(!__builtin_offsetof(T, template Q::x));
> > > > > > };
> > > > > > 
> > > > > > struct A {
> > > > > >   template  using Q = T;
> > > > > >   int x;
> > > > > > };
> > > > > > 
> > > > > > Z za;
> > > > > > ```
> > > > > Wow. Does it mean we cannot simply parse the identifier, `::`, `.` 
> > > > > and brackets in `__builtin_offsetof`?
> > > > GCC seems to support that. 
> > > > 
> > > > We probably want to call `ParseOptionalCXXScopeSpecifier` and store the 
> > > > `NestedNameSpecifierLoc` we'd get from it (and then parse the (sequence 
> > > > of) identifier(s) corresponding to the member) as we do now.
> > > > 
> > > > The documentation of 
> > > > https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Offsetof.html#index-_005f_005fbuiltin_005foffsetof
> > > >  
> > > > seems inaccurate,
> > > > 
> > > > it seems to be
> > > > 
> > > > `"__builtin_offsetof" "(" typename ","  nested-name-specifier 
> > > > offsetof_member_designator ")"`
> > > > 
> > > > 
> > > > Note that you will have to take care of transforming the nested name in 
> > > > TreeTransform and handle type dependencies. Let me know if you have 
> > > > further questions,
> > > > it's more involved than what you signed for. Sorry for not spotting 
> > > > that earlier (Thanks @hubert.reinterpretcast !)
> > > Thank you for all the help! I'll take a look at it!
> > I was wrong, we need another approach.
> > 
> > I think the grammar is actually
> > ```
> > member-designator:
> >   qualified-id
> >   member-designator.qualified-id
> >   member-designator.qualified-id
> > ```
> > IE, we should support https://godbolt.org/z/eEq8snMc8
> > 
> > Unfortunately, this looks like a much bigger change that we envisioned when 
> > we tagged this as a good first issue, to the extent I'm not sure what is 
> > actually the right design is would be.
> > 
> > For each component I imagine we want to store
> > `NestedNameSpecifierLoc + DeclarationNameInfo`
> > 
> > The parser would have to produce a CXXScopeSpec + UnqualifiedId pair for 
> > each component.
> > 
> > The expression is dependent if any of the component is type dependent,
> > 
> > `OffsetOfNode` would have to change, but i think we can get away
> > Only changing the identifier case (ie the dependent case)  
> > 
> Would it be better for me to close this patch and submit a new one if I find 
> out how to implement it? I hope others won't hesitate to contribute because 
> I'm working on this. I don't want to cause any delays in the release plan!
> Would it be better for me to close this patch and submit a new one if I find 
> out how to implement it?
A possible approach is to follow the example of member reference expression in 
its dot form.

> I hope others won't hesitate to contribute because I'm working on this. I 
> don't want to cause any delays in the release plan!
No worries, 17 release has branched a month ago, so you don't have to feel 
stressed over that.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157201

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


[PATCH] D157956: [clangd] don't add inlay hint for dependent type in structured binding

2023-08-20 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a comment.
This revision is now accepted and ready to land.

Thanks!

A future enhancement to consider could be, in the following testcase:

  template 
  struct Pair {
T t;
U u;
  };
  
  template 
  void foobar(Pair arg) {
auto [a, b] = arg;
  }

to get the hints to be `T` and `U`. (Today they are ``, so the 
patch is still an improvement in this case.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157956

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