[PATCH] D136154: [clang-format] Fix the continuation indenter

2022-10-22 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D136154#3867328 , @MyDeveloperDay 
wrote:

> Can we log a GitHub issue I can’t see what you are trying to fix

@hel-ableton Can you log an issue for this and add a link to it in `SUMMARY`?

In D136154#3867441 , @hel-ableton 
wrote:

> I'll attach too screenshots, the diffs are going from with the fix to without 
> the fix.

Can you include a minimal test case that reproduces the issue with the latest 
clang-format? Please also include your .clang-format file.

In D136154#3871389 , @hel-ableton 
wrote:

> ...oh and one more process question: why is that I write answers to your 
> comments and then they seem to be "drafts". I don't know how to submit them, 
> and hope you get to see them anyway.

After you write a `New Inline Comment`, click the `Save Draft` button. Then 
click the `Submit` button near the bottom of the screen.


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

https://reviews.llvm.org/D136154

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


[PATCH] D80392: [mips][mc][clang] Use pc-relative relocations in .eh_frame

2022-10-22 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa added a comment.
Herald added a subscriber: StephenFan.
Herald added a project: All.

I don't think that we need that option: what we need to do is to update the old 
tools.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80392

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


[clang-tools-extra] 6ed4a54 - [clangd] Make file limit for textDocument/rename configurable

2022-10-22 Thread Christian Kandeler via cfe-commits

Author: Christian Kandeler
Date: 2022-10-22T10:17:41+02:00
New Revision: 6ed4a543b8b3ab38ddb30cf4c15b70ed11266388

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

LOG: [clangd] Make file limit for textDocument/rename configurable

Without this, clients are unable to rename often-used symbols in larger
projects.

Reviewed By: kadircet

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

Added: 


Modified: 
clang-tools-extra/clangd/tool/ClangdMain.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp 
b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 68c0a51a2d74d..53b6653c51f20 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -327,6 +327,14 @@ opt ReferencesLimit{
 init(1000),
 };
 
+opt RenameFileLimit{
+"rename-file-limit",
+cat(Features),
+desc("Limit the number of files to be affected by symbol renaming. "
+ "0 means no limit (default=50)"),
+init(50),
+};
+
 list TweakList{
 "tweaks",
 cat(Features),
@@ -891,6 +899,7 @@ clangd accepts flags on the commandline, and in the 
CLANGD_FLAGS environment var
   Opts.BackgroundIndex = EnableBackgroundIndex;
   Opts.BackgroundIndexPriority = BackgroundIndexPriority;
   Opts.ReferencesLimit = ReferencesLimit;
+  Opts.Rename.LimitFiles = RenameFileLimit;
   auto PAI = createProjectAwareIndex(loadExternalIndex, Sync);
   if (StaticIdx) {
 IdxStack.emplace_back(std::move(StaticIdx));



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


[PATCH] D136454: [clangd] Make file limit for textDocument/rename configurable

2022-10-22 Thread Christian Kandeler via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6ed4a543b8b3: [clangd] Make file limit for 
textDocument/rename configurable (authored by ckandeler).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136454

Files:
  clang-tools-extra/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -327,6 +327,14 @@
 init(1000),
 };
 
+opt RenameFileLimit{
+"rename-file-limit",
+cat(Features),
+desc("Limit the number of files to be affected by symbol renaming. "
+ "0 means no limit (default=50)"),
+init(50),
+};
+
 list TweakList{
 "tweaks",
 cat(Features),
@@ -891,6 +899,7 @@
   Opts.BackgroundIndex = EnableBackgroundIndex;
   Opts.BackgroundIndexPriority = BackgroundIndexPriority;
   Opts.ReferencesLimit = ReferencesLimit;
+  Opts.Rename.LimitFiles = RenameFileLimit;
   auto PAI = createProjectAwareIndex(loadExternalIndex, Sync);
   if (StaticIdx) {
 IdxStack.emplace_back(std::move(StaticIdx));


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -327,6 +327,14 @@
 init(1000),
 };
 
+opt RenameFileLimit{
+"rename-file-limit",
+cat(Features),
+desc("Limit the number of files to be affected by symbol renaming. "
+ "0 means no limit (default=50)"),
+init(50),
+};
+
 list TweakList{
 "tweaks",
 cat(Features),
@@ -891,6 +899,7 @@
   Opts.BackgroundIndex = EnableBackgroundIndex;
   Opts.BackgroundIndexPriority = BackgroundIndexPriority;
   Opts.ReferencesLimit = ReferencesLimit;
+  Opts.Rename.LimitFiles = RenameFileLimit;
   auto PAI = createProjectAwareIndex(loadExternalIndex, Sync);
   if (StaticIdx) {
 IdxStack.emplace_back(std::move(StaticIdx));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c01ac37 - [clang][Interp][NFC] Add assertions to VM entry points

2022-10-22 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-22T10:19:42+02:00
New Revision: c01ac372fc3308e4c6c31361e44e604410cd1573

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

LOG: [clang][Interp][NFC] Add assertions to VM entry points

Assert that the previous call left the stack empty, as well as that
successful interpretations leave an empty stack.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index a43ced4f856c..495d019714ba 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -27,6 +27,7 @@ Context::Context(ASTContext &Ctx) : Ctx(Ctx), P(new 
Program(*this)) {}
 Context::~Context() {}
 
 bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) {
+  assert(Stk.empty());
   Function *Func = P->getFunction(FD);
   if (!Func) {
 if (auto R = ByteCodeStmtGen(*this, *P).compileFunc(FD)) {
@@ -45,14 +46,28 @@ bool Context::isPotentialConstantExpr(State &Parent, const 
FunctionDecl *FD) {
 }
 
 bool Context::evaluateAsRValue(State &Parent, const Expr *E, APValue &Result) {
+  assert(Stk.empty());
   ByteCodeExprGen C(*this, *P, Parent, Stk, Result);
-  return Check(Parent, C.interpretExpr(E));
+  if (Check(Parent, C.interpretExpr(E))) {
+assert(Stk.empty());
+return true;
+  }
+
+  Stk.clear();
+  return false;
 }
 
 bool Context::evaluateAsInitializer(State &Parent, const VarDecl *VD,
 APValue &Result) {
+  assert(Stk.empty());
   ByteCodeExprGen C(*this, *P, Parent, Stk, Result);
-  return Check(Parent, C.interpretDecl(VD));
+  if (Check(Parent, C.interpretDecl(VD))) {
+assert(Stk.empty());
+return true;
+  }
+
+  Stk.clear();
+  return false;
 }
 
 const LangOptions &Context::getLangOpts() const { return Ctx.getLangOpts(); }

diff  --git a/clang/lib/AST/Interp/InterpStack.h 
b/clang/lib/AST/Interp/InterpStack.h
index 7c338aa3e0ab..3adaad96515e 100644
--- a/clang/lib/AST/Interp/InterpStack.h
+++ b/clang/lib/AST/Interp/InterpStack.h
@@ -75,6 +75,9 @@ class InterpStack final {
   /// Clears the stack without calling any destructors.
   void clear();
 
+  // Returns whether the stack is empty.
+  bool empty() const { return StackSize == 0; }
+
 private:
   /// All stack slots are aligned to the native pointer alignment for storage.
   /// The size of an object is rounded up to a pointer alignment multiple.



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


[clang] 7a66e6e - [clang][Interp][NFC] Unify Div/Rem operation checks

2022-10-22 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-22T10:19:42+02:00
New Revision: 7a66e6e19bd42bdb53dcca9156f2ca52c5931f7e

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

LOG: [clang][Interp][NFC] Unify Div/Rem operation checks

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index c9a508448e314..c7cf9b3838691 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -91,6 +91,27 @@ bool CheckThis(InterpState &S, CodePtr OpPC, const Pointer 
&This);
 /// Checks if a method is pure virtual.
 bool CheckPure(InterpState &S, CodePtr OpPC, const CXXMethodDecl *MD);
 
+/// Checks if Div/Rem operation on LHS and RHS is valid.
+template 
+bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS) {
+  if (RHS.isZero()) {
+const SourceInfo &Loc = S.Current->getSource(OpPC);
+S.FFDiag(Loc, diag::note_expr_divide_by_zero);
+return false;
+  }
+
+  if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
+APSInt LHSInt = LHS.toAPSInt();
+SmallString<32> Trunc;
+(-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
+const SourceInfo &Loc = S.Current->getSource(OpPC);
+const Expr *E = S.Current->getExpr(OpPC);
+S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType();
+return false;
+  }
+  return true;
+}
+
 template  inline bool IsTrue(const T &V) { return !V.isZero(); }
 
 
//===--===//
@@ -195,21 +216,8 @@ bool Rem(InterpState &S, CodePtr OpPC) {
   const T &RHS = S.Stk.pop();
   const T &LHS = S.Stk.pop();
 
-  if (RHS.isZero()) {
-const SourceInfo &Loc = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_expr_divide_by_zero);
+  if (!CheckDivRem(S, OpPC, LHS, RHS))
 return false;
-  }
-
-  if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
-APSInt LHSInt = LHS.toAPSInt();
-SmallString<32> Trunc;
-(-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
-const SourceInfo &Loc = S.Current->getSource(OpPC);
-const Expr *E = S.Current->getExpr(OpPC);
-S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType();
-return false;
-  }
 
   const unsigned Bits = RHS.bitWidth() * 2;
   T Result;
@@ -228,21 +236,8 @@ bool Div(InterpState &S, CodePtr OpPC) {
   const T &RHS = S.Stk.pop();
   const T &LHS = S.Stk.pop();
 
-  if (RHS.isZero()) {
-const SourceInfo &Loc = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_expr_divide_by_zero);
+  if (!CheckDivRem(S, OpPC, LHS, RHS))
 return false;
-  }
-
-  if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
-APSInt LHSInt = LHS.toAPSInt();
-SmallString<32> Trunc;
-(-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
-const SourceInfo &Loc = S.Current->getSource(OpPC);
-const Expr *E = S.Current->getExpr(OpPC);
-S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType();
-return false;
-  }
 
   const unsigned Bits = RHS.bitWidth() * 2;
   T Result;



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


[clang] d78a395 - [clang][Interp][NFC] Add two more array tests

2022-10-22 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-22T10:19:42+02:00
New Revision: d78a3957ea35eda2a50530d7afed9c7cc30a0d18

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

LOG: [clang][Interp][NFC] Add two more array tests

Added: 


Modified: 
clang/test/AST/Interp/arrays.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/arrays.cpp 
b/clang/test/AST/Interp/arrays.cpp
index d41999414f5b6..1269e9dbb2b14 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -87,16 +87,18 @@ static_assert(DI[1] == 50, "");
 static_assert(DI[2] == 30, "");
 static_assert(DI[3] == 40, "");
 
-/// FIXME: The example below tests ImplicitValueInitExprs, but we can't
-///   currently evaluate other parts of it.
-#if 0
+constexpr int addThreeElements(const int v[3]) {
+  return v[0] + v[1] + v[2];
+}
+constexpr int is[] = {10, 20, 30 };
+static_assert(addThreeElements(is) == 60);
+
 struct fred {
   char s [6];
   int n;
 };
 
 struct fred y [] = { [0] = { .s[0] = 'q' } };
-#endif
 #pragma clang diagnostic pop
 
 namespace indices {



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


[clang] c29f063 - [clang][Interp] Add a missing static_assert message

2022-10-22 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-22T10:32:05+02:00
New Revision: c29f0638c1e17635ad0c0f2fc37bd16c81db1a9b

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

LOG: [clang][Interp] Add a missing static_assert message

This broke a builder:
https://lab.llvm.org/buildbot/#builders/139/builds/29923

Added: 


Modified: 
clang/test/AST/Interp/arrays.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/arrays.cpp 
b/clang/test/AST/Interp/arrays.cpp
index 1269e9dbb2b1..17829189f85e 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -91,7 +91,7 @@ constexpr int addThreeElements(const int v[3]) {
   return v[0] + v[1] + v[2];
 }
 constexpr int is[] = {10, 20, 30 };
-static_assert(addThreeElements(is) == 60);
+static_assert(addThreeElements(is) == 60, "");
 
 struct fred {
   char s [6];



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


[clang] 4abd868 - [clang][Interp][NFC] Trim InterpFrame includes

2022-10-22 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-22T10:32:05+02:00
New Revision: 4abd8683043811792dcbc597abaa02bb482bb959

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

LOG: [clang][Interp][NFC] Trim InterpFrame includes

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index a2320f0d2076..427de28f2419 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -8,11 +8,12 @@
 
 #include "InterpFrame.h"
 #include "Function.h"
-#include "Interp.h"
 #include "InterpStack.h"
+#include "InterpState.h"
 #include "Pointer.h"
 #include "PrimType.h"
 #include "Program.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclCXX.h"
 
 using namespace clang;



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


[clang] d49fe7c - [clang][Interp][NFC] Add another failing test case

2022-10-22 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-22T10:32:05+02:00
New Revision: d49fe7c95bdf35dcb39068550a7c4039769de414

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

LOG: [clang][Interp][NFC] Add another failing test case

Function parameters need to be checked before the function is called.

Added: 


Modified: 
clang/test/AST/Interp/cxx20.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 1b1a613b34b6..036e7f914bbe 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -77,4 +77,12 @@ constexpr int initializedLocal() {
   return a;
 }
 static_assert(initializedLocal() == 20);
+
+/// Similar here, but the uninitialized local is passed as a function 
parameter.
+constexpr int inc(int a) { return a + 1; }
+constexpr int f() {
+int i;
+return inc(i);
+}
+static_assert(f());
 #endif



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


[clang] 8013ab4 - [clang][Interp][NFC] Simplify creating parameter descriptors

2022-10-22 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-22T10:32:05+02:00
New Revision: 8013ab4f98c2ed3bb11dcb83179664cb595c31bb

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

LOG: [clang][Interp][NFC] Simplify creating parameter descriptors

... using value_or instead of the if-else statement.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index d653da31d162..13284703bba1 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -56,13 +56,7 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
   // Assign descriptors to all parameters.
   // Composite objects are lowered to pointers.
   for (const ParmVarDecl *PD : FuncDecl->parameters()) {
-PrimType Ty;
-if (llvm::Optional T = Ctx.classify(PD->getType())) {
-  Ty = *T;
-} else {
-  Ty = PT_Ptr;
-}
-
+PrimType Ty = Ctx.classify(PD->getType()).value_or(PT_Ptr);
 Descriptor *Desc = P.createDescriptor(PD, Ty);
 ParamDescriptors.insert({ParamOffset, {Ty, Desc}});
 Params.insert({PD, ParamOffset});



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


[clang] cc79ddb - [clang][Interp] Check instance pointers before calling functions on them

2022-10-22 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-22T10:32:05+02:00
New Revision: cc79ddb52c310be50d2ed0e0307b695cc7c142ce

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

LOG: [clang][Interp] Check instance pointers before calling functions on them

Remove the double Call() implementation to reduce code duplication. Then
fix Function::getSource() so we can diagnose instance pointers being
null.

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

Added: 


Modified: 
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/Function.cpp
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index 0638a68297ed..dc0e15c82fc0 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -102,14 +102,6 @@ template  bool EvalEmitter::emitRet(const 
SourceInfo &Info) {
   return ReturnValue(S.Stk.pop(), Result);
 }
 
-template 
-bool EvalEmitter::emitCall(const Function *Func, const SourceInfo &Info) {
-
-  S.Current = new InterpFrame(S, Func, {});
-  // Result of call will be on the stack and needs to be handled by the caller.
-  return Interpret(S, Result);
-}
-
 bool EvalEmitter::emitCallVoid(const Function *Func, const SourceInfo &Info) {
   APValue VoidResult;
   InterpFrame *before = S.Current;

diff  --git a/clang/lib/AST/Interp/Function.cpp 
b/clang/lib/AST/Interp/Function.cpp
index a6dfd50d6300..40001faad411 100644
--- a/clang/lib/AST/Interp/Function.cpp
+++ b/clang/lib/AST/Interp/Function.cpp
@@ -30,11 +30,12 @@ Function::ParamDescriptor 
Function::getParamDescriptor(unsigned Offset) const {
 }
 
 SourceInfo Function::getSource(CodePtr PC) const {
+  assert(PC >= getCodeBegin() && "PC does not belong to this function");
+  assert(PC <= getCodeEnd() && "PC Does not belong to this function");
   unsigned Offset = PC - getCodeBegin();
   using Elem = std::pair;
   auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first());
-  if (It == SrcMap.end() || It->first != Offset)
-llvm::report_fatal_error("missing source location");
+  assert(It != SrcMap.end());
   return It->second;
 }
 

diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 1bc2baf8abf6..ad94f2ac6ccd 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -53,16 +53,6 @@ static bool Ret(InterpState &S, CodePtr &PC, APValue 
&Result) {
   return true;
 }
 
-template ::T>
-static bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
-  S.Current = new InterpFrame(S, const_cast(Func), PC);
-  APValue CallResult;
-  // Note that we cannot assert(CallResult.hasValue()) here since
-  // Ret() above only sets the APValue if the curent frame doesn't
-  // have a caller set.
-  return Interpret(S, CallResult);
-}
-
 static bool CallVoid(InterpState &S, CodePtr &PC, const Function *Func) {
   APValue VoidResult;
   S.Current = new InterpFrame(S, const_cast(Func), PC);

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index c7cf9b383869..42dff23cd6a6 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -114,6 +114,9 @@ bool CheckDivRem(InterpState &S, CodePtr OpPC, const T 
&LHS, const T &RHS) {
 
 template  inline bool IsTrue(const T &V) { return !V.isZero(); }
 
+/// Interpreter entry point.
+bool Interpret(InterpState &S, APValue &Result);
+
 
//===--===//
 // Add, Sub, Mul
 
//===--===//
@@ -1103,6 +1106,35 @@ inline bool ExpandPtr(InterpState &S, CodePtr OpPC) {
   return true;
 }
 
+template ::T>
+static bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
+  auto NewFrame = std::make_unique(S, Func, PC);
+  if (Func->hasThisPointer()) {
+if (!CheckInvoke(S, PC, NewFrame->getThis())) {
+  return false;
+}
+// TODO: CheckCallable
+  }
+
+  InterpFrame *FrameBefore = S.Current;
+  S.Current = NewFrame.get();
+
+  APValue CallResult;
+  // Note that we cannot assert(CallResult.hasValue()) here since
+  // Ret() above only sets the APValue if the curent frame doesn't
+  // have a caller set.
+  if (Interpret(S, CallResult)) {
+NewFrame.release(); // Frame was delete'd already.
+assert(S.Current == FrameBefore);
+return true;
+  }
+
+  // Interpreting the function failed somehow. Reset to
+  // previous state.
+  S.Current = FrameBefore;
+  return false;
+}
+
 
//===--===//
 // Read opcode arguments
 
//===---

[clang] 0e754cf - [clang][Interp][NFC] Unify Call() implementations

2022-10-22 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-22T10:32:05+02:00
New Revision: 0e754cfadc9487282d9b6119c41962c5c6c3660f

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

LOG: [clang][Interp][NFC] Unify Call() implementations

The type parameter we used to pass to call() was unused. Use the same
implementation for void and value-returning function calls.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index c785d3cafdad..a5969bb9f318 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -786,7 +786,7 @@ bool ByteCodeExprGen::visitRecordInitializer(const 
Expr *Initializer) {
 return false;
 }
 
-return this->emitCallVoid(Func, Initializer);
+return this->emitCall(Func, Initializer);
   } else if (const auto *InitList = dyn_cast(Initializer)) {
 const Record *R = getRecord(InitList->getType());
 
@@ -982,18 +982,10 @@ bool ByteCodeExprGen::VisitCallExpr(const 
CallExpr *E) {
 return false;
 }
 
-// Primitive return value, just call it.
-if (T)
-  return this->emitCall(*T, Func, E);
-
-// Void Return value, easy.
-if (ReturnType->isVoidType())
-  return this->emitCallVoid(Func, E);
-
-// Non-primitive return value with Return Value Optimization,
-// we already have a pointer on the stack to write the result into.
-if (Func->hasRVO())
-  return this->emitCallVoid(Func, E);
+// In any case call the function. The return value will end up on the 
stack and
+// if the function has RVO, we already have the pointer on the stack to 
write
+// the result into.
+return this->emitCall(Func, E);
   } else {
 assert(false && "We don't support non-FunctionDecl callees right now.");
   }

diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index dc0e15c82fc0..22e8695b9211 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -102,17 +102,6 @@ template  bool EvalEmitter::emitRet(const 
SourceInfo &Info) {
   return ReturnValue(S.Stk.pop(), Result);
 }
 
-bool EvalEmitter::emitCallVoid(const Function *Func, const SourceInfo &Info) {
-  APValue VoidResult;
-  InterpFrame *before = S.Current;
-  (void)before;
-  S.Current = new InterpFrame(S, Func, {});
-  bool Success = Interpret(S, VoidResult);
-  assert(VoidResult.isAbsent());
-  assert(S.Current == before);
-  return Success;
-}
-
 bool EvalEmitter::emitRetVoid(const SourceInfo &Info) { return true; }
 
 bool EvalEmitter::emitRetValue(const SourceInfo &Info) {

diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index ad94f2ac6ccd..e9bda12a9d0b 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -53,15 +53,6 @@ static bool Ret(InterpState &S, CodePtr &PC, APValue 
&Result) {
   return true;
 }
 
-static bool CallVoid(InterpState &S, CodePtr &PC, const Function *Func) {
-  APValue VoidResult;
-  S.Current = new InterpFrame(S, const_cast(Func), PC);
-  bool Success = Interpret(S, VoidResult);
-  assert(VoidResult.isAbsent());
-
-  return Success;
-}
-
 static bool RetVoid(InterpState &S, CodePtr &PC, APValue &Result) {
   S.CallStackDepth--;
 

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 42dff23cd6a6..73b1bc9bb406 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1106,8 +1106,7 @@ inline bool ExpandPtr(InterpState &S, CodePtr OpPC) {
   return true;
 }
 
-template ::T>
-static bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
+inline bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
   auto NewFrame = std::make_unique(S, Func, PC);
   if (Func->hasThisPointer()) {
 if (!CheckInvoke(S, PC, NewFrame->getThis())) {

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 52591da8a6b5..f9d2a5997625 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -159,17 +159,9 @@ def NoRet : Opcode {}
 
 
 def Call : Opcode {
-  let Args = [ArgFunction];
-  let Types = [AllTypeClass];
-  let ChangesPC = 1;
-  let HasGroup = 1;
-}
-
-def CallVoid : Opcode {
   let Args = [ArgFunction];
   let Types = [];
   let ChangesPC = 1;
-  let HasCustomEval = 1;
 }
 
 
//===--===//



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.ll

[PATCH] D135513: [clang][Interp] Check instance pointers before calling functions on them

2022-10-22 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 rGcc79ddb52c31: [clang][Interp] Check instance pointers before 
calling functions on them (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135513

Files:
  clang/lib/AST/Interp/EvalEmitter.cpp
  clang/lib/AST/Interp/Function.cpp
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  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
@@ -156,11 +156,14 @@
 
   constexpr int foo() { // ref-error {{never produces a constant expression}}
 S *s = nullptr;
-return s->get12(); // ref-note 2{{member call on dereferenced null pointer}}
+return s->get12(); // ref-note 2{{member call on dereferenced null pointer}} \
+   // expected-note {{member call on dereferenced null pointer}}
+
   }
-  // FIXME: The new interpreter doesn't reject this currently.
   static_assert(foo() == 12, ""); // ref-error {{not an integral constant expression}} \
-  // ref-note {{in call to 'foo()'}}
+  // ref-note {{in call to 'foo()'}} \
+  // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to 'foo()'}}
 };
 
 struct FourBoolPairs {
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -162,7 +162,6 @@
   let Args = [ArgFunction];
   let Types = [AllTypeClass];
   let ChangesPC = 1;
-  let HasCustomEval = 1;
   let HasGroup = 1;
 }
 
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -114,6 +114,9 @@
 
 template  inline bool IsTrue(const T &V) { return !V.isZero(); }
 
+/// Interpreter entry point.
+bool Interpret(InterpState &S, APValue &Result);
+
 //===--===//
 // Add, Sub, Mul
 //===--===//
@@ -1103,6 +1106,35 @@
   return true;
 }
 
+template ::T>
+static bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
+  auto NewFrame = std::make_unique(S, Func, PC);
+  if (Func->hasThisPointer()) {
+if (!CheckInvoke(S, PC, NewFrame->getThis())) {
+  return false;
+}
+// TODO: CheckCallable
+  }
+
+  InterpFrame *FrameBefore = S.Current;
+  S.Current = NewFrame.get();
+
+  APValue CallResult;
+  // Note that we cannot assert(CallResult.hasValue()) here since
+  // Ret() above only sets the APValue if the curent frame doesn't
+  // have a caller set.
+  if (Interpret(S, CallResult)) {
+NewFrame.release(); // Frame was delete'd already.
+assert(S.Current == FrameBefore);
+return true;
+  }
+
+  // Interpreting the function failed somehow. Reset to
+  // previous state.
+  S.Current = FrameBefore;
+  return false;
+}
+
 //===--===//
 // Read opcode arguments
 //===--===//
@@ -1116,9 +1148,6 @@
   }
 }
 
-/// Interpreter entry point.
-bool Interpret(InterpState &S, APValue &Result);
-
 } // namespace interp
 } // namespace clang
 
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -53,16 +53,6 @@
   return true;
 }
 
-template ::T>
-static bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
-  S.Current = new InterpFrame(S, const_cast(Func), PC);
-  APValue CallResult;
-  // Note that we cannot assert(CallResult.hasValue()) here since
-  // Ret() above only sets the APValue if the curent frame doesn't
-  // have a caller set.
-  return Interpret(S, CallResult);
-}
-
 static bool CallVoid(InterpState &S, CodePtr &PC, const Function *Func) {
   APValue VoidResult;
   S.Current = new InterpFrame(S, const_cast(Func), PC);
Index: clang/lib/AST/Interp/Function.cpp
===
--- clang/lib/AST/Interp/Function.cpp
+++ clang/lib/AST/Interp/Function.cpp
@@ -30,11 +30,12 @@
 }
 
 SourceInfo Function::getSource(CodePtr PC) const {
+  assert(PC >= getCodeBegin() && "PC does not belong to this function");
+  assert(PC <= getCodeEnd() && "PC Does not belong to this function");
   unsigned Offset = PC - getCodeBegin();
   using Elem = std::pair;
   auto It = llv

[PATCH] D135858: [clang][Interp] Support pointer arithmetic in binary operators

2022-10-22 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 469875.
tbaeder added a comment.

Ping


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

https://reviews.llvm.org/D135858

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

Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -37,6 +37,56 @@
 static_assert(getElement(1) == 4, "");
 static_assert(getElement(5) == 36, "");
 
+constexpr int data[] = {5, 4, 3, 2, 1};
+constexpr int getElement(const int *Arr, int index) {
+  return *(Arr + index);
+}
+
+static_assert(getElement(data, 1) == 4, "");
+static_assert(getElement(data, 4) == 1, "");
+
+constexpr int getElementFromEnd(const int *Arr, int size, int index) {
+  return *(Arr + size - index - 1);
+}
+static_assert(getElementFromEnd(data, 5, 0) == 1, "");
+static_assert(getElementFromEnd(data, 5, 4) == 5, "");
+
+
+constexpr static int arr[2] = {1,2};
+constexpr static int arr2[2] = {3,4};
+constexpr int *p1 = nullptr;
+constexpr int *p2 = p1 + 1; // expected-error {{must be initialized by a constant expression}} \
+// expected-note {{cannot perform pointer arithmetic on null pointer}} \
+// ref-error {{must be initialized by a constant expression}} \
+// ref-note {{cannot perform pointer arithmetic on null pointer}}
+constexpr int *p3 = p1 + 0;
+constexpr int *p4 = p1 - 0;
+constexpr int *p5 =  0 + p1;
+constexpr int *p6 =  0 - p1; // expected-error {{invalid operands to binary expression}} \
+ // ref-error {{invalid operands to binary expression}}
+
+constexpr int const * ap1 = &arr[0];
+constexpr int const * ap2 = ap1 + 3; // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{cannot refer to element 3 of array of 2}} \
+ // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{cannot refer to element 3 of array of 2}}
+
+constexpr auto ap3 = arr - 1; // expected-error {{must be initialized by a constant expression}} \
+  // expected-note {{cannot refer to element -1}} \
+  // ref-error {{must be initialized by a constant expression}} \
+  // ref-note {{cannot refer to element -1}}
+constexpr int k1 = &arr[1] - &arr[0];
+static_assert(k1 == 1, "");
+static_assert((&arr[0] - &arr[1]) == -1, "");
+
+constexpr int k2 = &arr2[1] - &arr[0]; // expected-error {{must be initialized by a constant expression}} \
+   // ref-error {{must be initialized by a constant expression}}
+
+static_assert((arr + 0) == arr, "");
+static_assert(&arr[0] == arr, "");
+static_assert(*(&arr[0]) == 1, "");
+static_assert(*(&arr[1]) == 2, "");
+
 
 template
 constexpr T getElementOf(T* array, int i) {
@@ -52,7 +102,6 @@
 static_assert(getElementOfArray(foo[2], 3) == &m, "");
 
 
-constexpr int data[] = {5, 4, 3, 2, 1};
 static_assert(data[0] == 4, ""); // expected-error{{failed}} \
  // expected-note{{5 == 4}} \
  // ref-error{{failed}} \
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -201,5 +201,5 @@
 }
 
 bool Pointer::hasSameArray(const Pointer &A, const Pointer &B) {
-  return A.Base == B.Base && A.getFieldDesc()->IsArray;
+  return hasSameBase(A, B) && A.Base == B.Base && A.getFieldDesc()->IsArray;
 }
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -390,6 +390,12 @@
 // [Pointer, Integral] -> [Pointer]
 def SubOffset : AluOpcode;
 
+// Pointer, Pointer] - [Integral]
+def SubPtr : Opcode {
+  let Types = [IntegerTypeClass];
+  let HasGroup = 1;
+}
+
 //===--===//
 // Binary operators.
 //===--===//
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -350,6 +350,16 @@
   } else {
 unsigned VL = LHS.getByteOffset();
 unsigned VR = RHS.getByteOffset();
+
+// In our Pointer class, a pointer to an array and a pointer to the first
+// element in the same array are NOT equal. They have the same Base value,
+// but a different Offse

[PATCH] D136528: [clang][Interp] Implement add and sub compound assign operators

2022-10-22 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
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/D136528

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

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -408,5 +408,22 @@
 
 return -1;
   }
+
+  constexpr int getTwo() {
+int i = 1;
+return (i += 1);
+  }
+  static_assert(getTwo() == 2, "");
+
+  constexpr int sub(int a) {
+return (a -= 2);
+  }
+  static_assert(sub(7) == 5, "");
+
+  constexpr int subAll(int a) {
+return (a -= a);
+  }
+  static_assert(subAll(213) == 0);
+
 };
 #endif
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -89,6 +89,7 @@
   bool VisitCharacterLiteral(const CharacterLiteral *E);
   bool VisitExprWithCleanups(const ExprWithCleanups *E);
   bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
+  bool VisitCompoundAssignOperator(const CompoundAssignOperator *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -564,6 +564,57 @@
   return false;
 }
 
+template 
+bool ByteCodeExprGen::VisitCompoundAssignOperator(
+const CompoundAssignOperator *E) {
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+  Optional LT = classify(E->getLHS()->getType());
+  Optional RT = classify(E->getRHS()->getType());
+
+  if (!LT || !RT)
+return false;
+
+  assert(!E->getType()->isPointerType() &&
+ "Support pointer arithmethic in compound assignment operators");
+
+  // Get LHS pointer, load its value and get RHS value.
+  if (!visit(LHS))
+return false;
+  if (!this->emitLoad(*LT, E))
+return false;
+  if (!visit(RHS))
+return false;
+
+  // Perform operation.
+  switch (E->getOpcode()) {
+  case BO_AddAssign:
+if (!this->emitAdd(*LT, E))
+  return false;
+break;
+  case BO_SubAssign:
+if (!this->emitSub(*LT, E))
+  return false;
+break;
+
+  case BO_MulAssign:
+  case BO_DivAssign:
+  case BO_RemAssign:
+  case BO_ShlAssign:
+  case BO_ShrAssign:
+  case BO_AndAssign:
+  case BO_XorAssign:
+  case BO_OrAssign:
+  default:
+llvm_unreachable("Unimplemented compound assign operator");
+  }
+
+  // And store the result in LHS.
+  if (DiscardResult)
+return this->emitStorePop(*LT, E);
+  return this->emitStore(*LT, E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) {
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136355: [clang][Sema] Fix caret position to be on the non null parameter

2022-10-22 Thread Arthur Grillo Queiroz Cabral via Phabricator via cfe-commits
Grillo added a comment.

In D136355#3875265 , @aaron.ballman 
wrote:

> LGTM aside from a tiny grammar nit. Thank you for the fix! If you'd like me 
> to commit this on your behalf, I can fix up the release note myself when 
> landing, but please let me know what name and email address you'd like me to 
> use for patch attribution.

If you could that would be great! My name and email is Arthur Grillo 
.

Best Regards,

- Arthur Grillo


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

https://reviews.llvm.org/D136355

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


[PATCH] D134958: [clang][Interp] Support __builtin_clz calls

2022-10-22 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder added a comment.

Let's shelve this until later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134958

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2022-10-22 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski updated this revision to Diff 469901.
calebzulawski added a comment.

Change tests to specifically remove `SDKROOT` environment variable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-sdkroot.c

Index: clang/test/Driver/darwin-sdkroot.c
===
--- clang/test/Driver/darwin-sdkroot.c
+++ clang/test/Driver/darwin-sdkroot.c
@@ -1,4 +1,5 @@
-// Check that SDKROOT is used to define the default for -isysroot on Darwin.
+// Check that SDKROOT is used to define the default for -isysroot on Darwin,
+// or that we call `xcrun --show-sdk-path` if SDKROOT is not in the environment.
 //
 // RUN: rm -rf %t.tmpdir
 // RUN: mkdir -p %t.tmpdir
@@ -39,6 +40,25 @@
 //
 // This test do pass using GnuWin32 env.exe.
 
+// Check that we default to running `xcrun --show-sdk-path` if there is no
+// SDKROOT defined in the environment.
+//
+// RUN: env -u SDKROOT %clang -target x86_64-apple-darwin -c %s -### 2> %t.log
+// RUN: FileCheck --check-prefix=CHECK-XCRUN < %t.log %s
+//
+// CHECK-XCRUN: clang
+// CHECK-XCRUN: "-cc1"
+// CHECK-XCRUN: "-isysroot" "{{.*MacOSX[0-9\.]*\.sdk}}"
+
+// Check once again that we default to running `xcrun`, this time with another target.
+//
+// RUN: env -u SDKROOT %clang -target arm64-apple-ios -c %s -### 2> %t.log
+// RUN: FileCheck --check-prefix=CHECK-XCRUN-IOS < %t.log %s
+//
+// CHECK-XCRUN-IOS: clang
+// CHECK-XCRUN-IOS: "-cc1"
+// CHECK-XCRUN-IOS: "-isysroot" "{{.*iPhoneOS[0-9\.]*\.sdk}}"
+
 // Check if clang set the correct deployment target from -sysroot
 //
 // RUN: rm -rf %t/SDKs/iPhoneOS8.0.0.sdk
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -18,15 +18,22 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/ProfileData/InstrProf.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include  // ::getenv
+#include   // std::unique_ptr
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -2074,21 +2081,77 @@
 void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
   const OptTable &Opts = getDriver().getOpts();
 
-  // Support allowing the SDKROOT environment variable used by xcrun and other
-  // Xcode tools to define the default sysroot, by making it the default for
-  // isysroot.
+  // On Apple platforms, C and C++ Standard Library headers are not provided
+  // with the base system. Instead, they are provided in various SDKs for the
+  // different Apple platforms. Clang needs to know where that SDK lives, and
+  // there are a couple ways this can be achieved:
+  //
+  // (1) If `-isysroot ` is passed explicitly, use that.
   if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
 // Warn if the path does not exist.
 if (!getVFS().exists(A->getValue()))
   getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue();
-  } else {
-if (char *env = ::getenv("SDKROOT")) {
-  // We only use this value as the default if it is an absolute path,
-  // exists, and it is not the root path.
-  if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
-  StringRef(env) != "/") {
-Args.append(Args.MakeSeparateArg(
-nullptr, Opts.getOption(options::OPT_isysroot), env));
+  }
+
+  // (2) If the SDKROOT environment variable is defined and points to a valid
+  // path, use that. $SDKROOT is set by `xcrun` and other Xcode tools, so
+  // running `xcrun clang` will work by going through this path.
+  else if (char *env = ::getenv("SDKROOT")) {
+// We only use this value as the default if it is an absolute path,
+// exists, and it is not the root path.
+if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
+StringRef(env) != "/") {
+  Args.append(Args.MakeSeparateArg(
+  nullptr, Opts.getOption(options::OPT_isysroot), env));
+}
+  }
+
+  // (3) Otherwise, we try to guess the path of the default SDK by running
+  // `xcrun --show-sdk-path`. This won't always be correct, but if the
+  //  user wants to use the non-default SDK, they should specify it
+  //  explicitly with methods (1) or (2) above.
+  else {
+llvm::SmallString<64> O

[clang] bdd11bb - [clang][LTO][NFC] Adding More Tests for AIX Options

2022-10-22 Thread Qiongsi Wu via cfe-commits

Author: Qiongsi Wu
Date: 2022-10-22T11:09:03-04:00
New Revision: bdd11bbace5ee74036912a534ff5a7e07dd102de

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

LOG: [clang][LTO][NFC] Adding More Tests for AIX Options

This patch adds more tests for AIX. It follows https://reviews.llvm.org/D134820 
which added a minimal set of tests for the newly added AIX options. These new 
tests were originally created by https://reviews.llvm.org/D119109. Since we do 
not plan to land https://reviews.llvm.org/D119109 in its current shape to add 
the AIX specific options, we incorporate the relevant tests developed.

Reviewed By: w2yehia

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

Added: 


Modified: 
clang/test/Driver/lto-aix.c

Removed: 




diff  --git a/clang/test/Driver/lto-aix.c b/clang/test/Driver/lto-aix.c
index 1689c2638410f..88e7eaa4d5df0 100644
--- a/clang/test/Driver/lto-aix.c
+++ b/clang/test/Driver/lto-aix.c
@@ -5,7 +5,33 @@
 // LTOPATH: "-bplugin:{{.*}}libLTO.{{so|dll|dylib}}"
 // MCPUOPTLEVEL: "-bplugin_opt:-mcpu={{.*}}" "-bplugin_opt:-O3"
 //
+// More opt level option tests
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -O -### 2>&1 | FileCheck --check-prefix=O1 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -O1 -### 2>&1 | FileCheck --check-prefix=O1 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -Og -### 2>&1 | FileCheck --check-prefix=O1 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -O2 -### 2>&1 | FileCheck --check-prefix=O2 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -Os -### 2>&1 | FileCheck --check-prefix=O2 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -Oz -### 2>&1 | FileCheck --check-prefix=O2 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -O3 -### 2>&1 | FileCheck --check-prefix=O3 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -Ofast -### 2>&1 | FileCheck --check-prefix=O3 %s
+//
+// O1: "-bplugin_opt:-O1"
+// O2: "-bplugin_opt:-O2"
+// O3: "-bplugin_opt:-O3"
+//
 // Test debugging options
+// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld -gdbx 2>&1 \
+// RUN:   | FileCheck -check-prefix=DBX %s
+// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld -g 2>&1 \
+// RUN:   | FileCheck -check-prefix=NODEBUGGER-TUNE %s
 // RUN: %clang --target=powerpc-ibm-aix-xcoff -### %s -flto -g 2>&1 \
 // RUN:   | FileCheck -check-prefixes=STRICT,NODEBUGGER-TUNE %s
 // RUN: %clang --target=powerpc64-ibm-aix-xcoff -### %s -flto -g 2>&1 \



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


[PATCH] D135885: [clang][LTO][NFC] Adding More Tests for AIX Options

2022-10-22 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbdd11bbace5e: [clang][LTO][NFC] Adding More Tests for AIX 
Options (authored by Qiongsi Wu ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135885

Files:
  clang/test/Driver/lto-aix.c


Index: clang/test/Driver/lto-aix.c
===
--- clang/test/Driver/lto-aix.c
+++ clang/test/Driver/lto-aix.c
@@ -5,7 +5,33 @@
 // LTOPATH: "-bplugin:{{.*}}libLTO.{{so|dll|dylib}}"
 // MCPUOPTLEVEL: "-bplugin_opt:-mcpu={{.*}}" "-bplugin_opt:-O3"
 //
+// More opt level option tests
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -O -### 2>&1 | FileCheck --check-prefix=O1 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -O1 -### 2>&1 | FileCheck --check-prefix=O1 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -Og -### 2>&1 | FileCheck --check-prefix=O1 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -O2 -### 2>&1 | FileCheck --check-prefix=O2 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -Os -### 2>&1 | FileCheck --check-prefix=O2 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -Oz -### 2>&1 | FileCheck --check-prefix=O2 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -O3 -### 2>&1 | FileCheck --check-prefix=O3 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -Ofast -### 2>&1 | FileCheck --check-prefix=O3 %s
+//
+// O1: "-bplugin_opt:-O1"
+// O2: "-bplugin_opt:-O2"
+// O3: "-bplugin_opt:-O3"
+//
 // Test debugging options
+// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld -gdbx 2>&1 \
+// RUN:   | FileCheck -check-prefix=DBX %s
+// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld -g 2>&1 \
+// RUN:   | FileCheck -check-prefix=NODEBUGGER-TUNE %s
 // RUN: %clang --target=powerpc-ibm-aix-xcoff -### %s -flto -g 2>&1 \
 // RUN:   | FileCheck -check-prefixes=STRICT,NODEBUGGER-TUNE %s
 // RUN: %clang --target=powerpc64-ibm-aix-xcoff -### %s -flto -g 2>&1 \


Index: clang/test/Driver/lto-aix.c
===
--- clang/test/Driver/lto-aix.c
+++ clang/test/Driver/lto-aix.c
@@ -5,7 +5,33 @@
 // LTOPATH: "-bplugin:{{.*}}libLTO.{{so|dll|dylib}}"
 // MCPUOPTLEVEL: "-bplugin_opt:-mcpu={{.*}}" "-bplugin_opt:-O3"
 //
+// More opt level option tests
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -O -### 2>&1 | FileCheck --check-prefix=O1 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -O1 -### 2>&1 | FileCheck --check-prefix=O1 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -Og -### 2>&1 | FileCheck --check-prefix=O1 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -O2 -### 2>&1 | FileCheck --check-prefix=O2 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -Os -### 2>&1 | FileCheck --check-prefix=O2 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -Oz -### 2>&1 | FileCheck --check-prefix=O2 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -O3 -### 2>&1 | FileCheck --check-prefix=O3 %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -Ofast -### 2>&1 | FileCheck --check-prefix=O3 %s
+//
+// O1: "-bplugin_opt:-O1"
+// O2: "-bplugin_opt:-O2"
+// O3: "-bplugin_opt:-O3"
+//
 // Test debugging options
+// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld -gdbx 2>&1 \
+// RUN:   | FileCheck -check-prefix=DBX %s
+// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld -g 2>&1 \
+// RUN:   | FileCheck -check-prefix=NODEBUGGER-TUNE %s
 // RUN: %clang --target=powerpc-ibm-aix-xcoff -### %s -flto -g 2>&1 \
 // RUN:   | FileCheck -check-prefixes=STRICT,NODEBUGGER-TUNE %s
 // RUN: %clang --target=powerpc64-ibm-aix-xcoff -### %s -flto -g 2>&1 \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2022-10-22 Thread Thorsten via Phabricator via cfe-commits
tschuett added inline comments.



Comment at: clang/lib/Driver/ToolChains/Darwin.cpp:2120
+Optional SDKName = None;
+if (getTriple().isWatchOS()) {
+  if (getTriple().isSimulatorEnvironment())

Will there be an enum over the Apple variants to make this less error prone and 
future proof? I want a switch statement.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2022-10-22 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski updated this revision to Diff 469909.
calebzulawski added a comment.

Use switch when detecting OS.  Limit sdkroot test to darwin platforms.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-sdkroot.c

Index: clang/test/Driver/darwin-sdkroot.c
===
--- clang/test/Driver/darwin-sdkroot.c
+++ clang/test/Driver/darwin-sdkroot.c
@@ -1,4 +1,7 @@
-// Check that SDKROOT is used to define the default for -isysroot on Darwin.
+// REQUIRES: system-darwin
+
+// Check that SDKROOT is used to define the default for -isysroot on Darwin,
+// or that we call `xcrun --show-sdk-path` if SDKROOT is not in the environment.
 //
 // RUN: rm -rf %t.tmpdir
 // RUN: mkdir -p %t.tmpdir
@@ -39,6 +42,25 @@
 //
 // This test do pass using GnuWin32 env.exe.
 
+// Check that we default to running `xcrun --show-sdk-path` if there is no
+// SDKROOT defined in the environment.
+//
+// RUN: env -u SDKROOT %clang -target x86_64-apple-darwin -c %s -### 2> %t.log
+// RUN: FileCheck --check-prefix=CHECK-XCRUN < %t.log %s
+//
+// CHECK-XCRUN: clang
+// CHECK-XCRUN: "-cc1"
+// CHECK-XCRUN: "-isysroot" "{{.*MacOSX[0-9\.]*\.sdk}}"
+
+// Check once again that we default to running `xcrun`, this time with another target.
+//
+// RUN: env -u SDKROOT %clang -target arm64-apple-ios -c %s -### 2> %t.log
+// RUN: FileCheck --check-prefix=CHECK-XCRUN-IOS < %t.log %s
+//
+// CHECK-XCRUN-IOS: clang
+// CHECK-XCRUN-IOS: "-cc1"
+// CHECK-XCRUN-IOS: "-isysroot" "{{.*iPhoneOS[0-9\.]*\.sdk}}"
+
 // Check if clang set the correct deployment target from -sysroot
 //
 // RUN: rm -rf %t/SDKs/iPhoneOS8.0.0.sdk
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -18,15 +18,22 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/ProfileData/InstrProf.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include  // ::getenv
+#include   // std::unique_ptr
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -2074,21 +2081,89 @@
 void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
   const OptTable &Opts = getDriver().getOpts();
 
-  // Support allowing the SDKROOT environment variable used by xcrun and other
-  // Xcode tools to define the default sysroot, by making it the default for
-  // isysroot.
+  // On Apple platforms, C and C++ Standard Library headers are not provided
+  // with the base system. Instead, they are provided in various SDKs for the
+  // different Apple platforms. Clang needs to know where that SDK lives, and
+  // there are a couple ways this can be achieved:
+  //
+  // (1) If `-isysroot ` is passed explicitly, use that.
   if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
 // Warn if the path does not exist.
 if (!getVFS().exists(A->getValue()))
   getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue();
-  } else {
-if (char *env = ::getenv("SDKROOT")) {
-  // We only use this value as the default if it is an absolute path,
-  // exists, and it is not the root path.
-  if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
-  StringRef(env) != "/") {
-Args.append(Args.MakeSeparateArg(
-nullptr, Opts.getOption(options::OPT_isysroot), env));
+  }
+
+  // (2) If the SDKROOT environment variable is defined and points to a valid
+  // path, use that. $SDKROOT is set by `xcrun` and other Xcode tools, so
+  // running `xcrun clang` will work by going through this path.
+  else if (char *env = ::getenv("SDKROOT")) {
+// We only use this value as the default if it is an absolute path,
+// exists, and it is not the root path.
+if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
+StringRef(env) != "/") {
+  Args.append(Args.MakeSeparateArg(
+  nullptr, Opts.getOption(options::OPT_isysroot), env));
+}
+  }
+
+  // (3) Otherwise, we try to guess the path of the default SDK by running
+  // `xcrun --show-sdk-path`. This won't always be correct, but if the
+  //  user wants to use the non-default SDK, they should specify it
+  //  explicitly with methods (1) or (2) above.
+  el

[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2022-10-22 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski added inline comments.



Comment at: clang/lib/Driver/ToolChains/Darwin.cpp:2120
+Optional SDKName = None;
+if (getTriple().isWatchOS()) {
+  if (getTriple().isSimulatorEnvironment())

tschuett wrote:
> Will there be an enum over the Apple variants to make this less error prone 
> and future proof? I want a switch statement.
It doesn't look like there is any enum available that _only_ contains Apple OS 
variants, but I did change this to a switch-case over the OS in general.  Also, 
I noticed I missed DriverKit, so I added it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2022-10-22 Thread Carlo Cabrera via Phabricator via cfe-commits
carlocab added inline comments.



Comment at: clang/lib/Driver/ToolChains/Darwin.cpp:2147
+default:
+  // We shouldn't get here, unless the target OS doesn't have an SDK.
+  break;

`llvm_unreachable`? Or `assert`, at least.



Comment at: clang/test/Driver/darwin-sdkroot.c:1
-// Check that SDKROOT is used to define the default for -isysroot on Darwin.
+// REQUIRES: system-darwin
+

I'm not sure this is the right move here, since there are a number of other 
test cases in this file that don't require `system-darwin`. We probably do want 
those tests to run on more buildbots to make sure problems with them are caught 
sooner rather than later.

Maybe we can check that `/usr/bin/xcrun` is executable instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2022-10-22 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski added inline comments.



Comment at: clang/lib/Driver/ToolChains/Darwin.cpp:2147
+default:
+  // We shouldn't get here, unless the target OS doesn't have an SDK.
+  break;

carlocab wrote:
> `llvm_unreachable`? Or `assert`, at least.
I'm not sure that's correct--what if you target something like 
`x86_64-unknown-none`?  I figured it would be safest to fall back to the 
previous behavior of simply not providing a sysroot.



Comment at: clang/test/Driver/darwin-sdkroot.c:1
-// Check that SDKROOT is used to define the default for -isysroot on Darwin.
+// REQUIRES: system-darwin
+

carlocab wrote:
> I'm not sure this is the right move here, since there are a number of other 
> test cases in this file that don't require `system-darwin`. We probably do 
> want those tests to run on more buildbots to make sure problems with them are 
> caught sooner rather than later.
> 
> Maybe we can check that `/usr/bin/xcrun` is executable instead?
That would work, but I'm not sure how to exclude a particular test if it's not 
found.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D136532: [clang][Interp] Implement left and right shifts

2022-10-22 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add a test case based on `test/SemaCXX/shift.cpp`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136532

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

Index: clang/test/AST/Interp/shifts.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/shifts.cpp
@@ -0,0 +1,103 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++17 -verify=cxx17 %s
+// RUN: %clang_cc1 -std=c++20 -verify=ref %s
+// RUN: %clang_cc1 -std=c++17 -verify=ref-cxx17 %s
+
+#define CHAR_BIT (sizeof(char) * 8)
+#define WORD_BIT (sizeof(int) * 8)
+#define INT_MAX (__INT_MAX__)
+#define INT_MIN (~__INT_MAX__)
+
+
+namespace shifts {
+  constexpr void test() { // ref-error {{constexpr function never produces a constant expression}} \
+  // ref-cxx17-error {{constexpr function never produces a constant expression}}
+
+char c; // cxx17-warning {{uninitialized variable}} \
+// ref-cxx17-warning {{uninitialized variable}}
+
+c = 0 << 0;
+c = 0 << 1;
+c = 1 << 0;
+c = 1 << -0;
+c = 1 >> -0;
+c = 1 << -1; // expected-warning {{shift count is negative}} \
+ // cxx17-warning {{shift count is negative}} \
+ // ref-warning {{shift count is negative}} \
+ // ref-note {{negative shift count -1}} \
+ // ref-cxx17-warning {{shift count is negative}} \
+ // ref-cxx17-note {{negative shift count -1}}
+
+c = 1 >> -1; // expected-warning {{shift count is negative}} \
+ // cxx17-warning {{shift count is negative}} \
+ // ref-warning {{shift count is negative}} \
+ // ref-cxx17-warning {{shift count is negative}}
+c = 1 << (unsigned)-1; // expected-warning {{shift count >= width of type}} \
+   // FIXME: 'implicit conversion' warning missing in the new interpreter. \
+   // cxx17-warning {{shift count >= width of type}} \
+   // ref-warning {{shift count >= width of type}} \
+   // ref-warning {{implicit conversion}} \
+   // ref-cxx17-warning {{shift count >= width of type}} \
+   // ref-cxx17-warning {{implicit conversion}}
+c = 1 >> (unsigned)-1; // expected-warning {{shift count >= width of type}} \
+   // cxx17-warning {{shift count >= width of type}} \
+   // ref-warning {{shift count >= width of type}} \
+   // ref-cxx17-warning {{shift count >= width of type}}
+c = 1 << c;
+// FIXME: Enable this.
+#if 0
+//c <<= 0;
+//c >>= 0;
+//c <<= 1;
+//c >>= 1;
+//c <<= -1; // expected-warning {{shift count is negative}}
+//c >>= -1; // expected-warning {{shift count is negative}}
+//c <<= 99; // expected-warning {{shift count >= width of type}}
+//c >>= 99; // expected-warning {{shift count >= width of type}}
+//c <<= CHAR_BIT; // expected-warning {{shift count >= width of type}}
+//c >>= CHAR_BIT; // expected-warning {{shift count >= width of type}}
+//c <<= CHAR_BIT+1; // expected-warning {{shift count >= width of type}}
+//c >>= CHAR_BIT+1; // expected-warning {{shift count >= width of type}}
+#endif
+(void)((long)c << CHAR_BIT);
+
+int i; // cxx17-warning {{uninitialized variable}} \
+   // ref-cxx17-warning {{uninitialized variable}}
+i = 1 << (WORD_BIT - 2);
+i = 2 << (WORD_BIT - 1); // cxx17-warning {{bits to represent, but 'int' only has}} \
+ // ref-cxx17-warning {{bits to represent, but 'int' only has}}
+i = 1 << (WORD_BIT - 1); // cxx17-warning-not {{sets the sign bit of the shift expression}}
+i = -1 << (WORD_BIT - 1); // cxx17-warning {{shifting a negative signed value is undefined}} \
+  // ref-cxx17-warning {{shifting a negative signed value is undefined}}
+i = -1 << 0; // cxx17-warning {{shifting a negative signed value is undefined}} \
+ // ref-cxx17-warning {{shifting a negative signed value is undefined}}
+i = 0 << (WORD_BIT - 1);
+i = (char)1 << (WORD_BIT - 2);
+
+unsigned u; // cxx17-warning {{uninitialized variable}} \
+// ref-cxx17-warning {{uninitialized variable}}
+u = 1U << (WORD_BIT - 1);
+u = 5U << (WORD_BIT - 1);
+
+long long int lli; // cxx17-warning {{uninitialized variable}} \
+ 

[PATCH] D134453: Disambiguate type names when printing NTTP types

2022-10-22 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

I think the type printer's purpose is for printing types for diagnostics, not 
for generating a lossless representation of types as strings, as the ast dumper 
does.
So packing so much information in them that hurts readability would be against 
that purpose.
I do agree with everyone here that the provided example is one where we are 
unhelpful and provide too little information.

When printing types for diagnostics we roughly want to:

1. Point the user to the relevant type which is being diagnosed, as in the 
source code. When we have a TypeLoc, and that would otherwise be more 
presentable for the given diagnostic, we can point to the type with a caret. 
Otherwise, we try to print the type as closely as we can to what was written, 
so that the user can connect the diagnostic with something that was done in 
source code.
2. Give some sort of explanatory analysis, revealing implicit / context 
sensitive information which might be relevant.

I think that for the motivating example, we completely fail to provide 1), we 
don't have a TypeLoc, and we only have a canonical type.
I think fixing 1) is the most pressing issue, and is not addressed by this 
patch.
Ideally, long term, we can remove all instances where we try to print canonical 
types for diagnostic purposes, and not have the type printer deal with that, 
simplifying things.

For the short term, we have canonical types, and we need the type printer to 
deal with them reasonably.
I agree that the way MSVC is presenting these canonicalized NTTPs of class type 
looks the most sensible here.

But by fixing 1), we have more options. We can do something like:

  no known conversion from 'NDArray<[...], W (aka 'Width{}')>' to 'const 
NDArray<[...], H (aka 'Height{}')>' for 1st argument

Or perhaps instead of the aka, we can generate notes which place a caret in 
source code for each of W and H.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134453

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


[PATCH] D136533: Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

2022-10-22 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added projects: clang, libc++.
Herald added subscribers: libcxx-commits, cfe-commits.
Herald added a reviewer: libc++.

Fixes GH58547.

Signed-off-by: Matheus Izvekov 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136533

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
  
libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp

Index: libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp
===
--- libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp
+++ libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp
@@ -23,7 +23,10 @@
 int main(int, char**)
 {
 std::allocator a;
-TEST_IGNORE_NODISCARD a.allocate(3, nullptr); // expected-warning {{'allocate' is deprecated}}
+TEST_IGNORE_NODISCARD a.allocate(3, nullptr);
+// expected-warning@-1 {{'allocate' is deprecated}}
+// expected-warning@*:* {{'pointer' is deprecated}}
+// expected-warning@*:* {{'const_pointer' is deprecated}}
 
 return 0;
 }
Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
+++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
@@ -58,3 +58,17 @@
   FunS2 f;// No warning, entire function is deprecated, so usage here should be fine.
 
 }
+
+namespace GH58547 {
+struct A {
+  using ta [[deprecated]] = int; // expected-note 2{{marked deprecated here}}
+};
+
+using t1 = typename A::ta; // expected-warning {{'ta' is deprecated}}
+
+template  struct B {
+  using tb = typename B1::ta; // expected-warning {{'ta' is deprecated}}
+};
+
+template struct B; // expected-note {{requested here}}
+} // namespace GH58547
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -10958,20 +10958,15 @@
   //
   // FIXME: That's not strictly true: mem-initializer-id lookup does not
   // ignore functions, but that appears to be an oversight.
-  auto *LookupRD = dyn_cast_or_null(Ctx);
-  auto *FoundRD = dyn_cast(Type);
-  if (Keyword == ETK_Typename && LookupRD && FoundRD &&
-  FoundRD->isInjectedClassName() &&
-  declaresSameEntity(LookupRD, cast(FoundRD->getParent(
-Diag(IILoc, diag::ext_out_of_line_qualified_id_type_names_constructor)
-<< &II << 1 << 0 /*'typename' keyword used*/;
-
+  QualType T =
+  getTypeDeclType(Ctx,
+  Keyword == ETK_Typename ? TypeAccessKind::Typename
+  : TypeAccessKind::Explicit,
+  Type, IILoc);
   // We found a type. Build an ElaboratedType, since the
   // typename-specifier was just sugar.
-  MarkAnyDeclReferenced(Type->getLocation(), Type, /*OdrUse=*/false);
-  return Context.getElaboratedType(Keyword,
-   QualifierLoc.getNestedNameSpecifier(),
-   Context.getTypeDeclType(Type));
+  return Context.getElaboratedType(
+  Keyword, QualifierLoc.getNestedNameSpecifier(), T);
 }
 
 // C++ [dcl.type.simple]p2:
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -169,6 +169,25 @@
   return false;
 }
 
+QualType Sema::getTypeDeclType(DeclContext *LookupCtx, TypeAccessKind AK,
+   TypeDecl *TD, SourceLocation NameLoc) {
+  auto *LookupRD = dyn_cast_or_null(LookupCtx);
+  auto *FoundRD = dyn_cast(TD);
+  if (AK != TypeAccessKind::Explicit && LookupRD && FoundRD &&
+  FoundRD->isInjectedClassName() &&
+  declaresSameEntity(LookupRD, cast(FoundRD->getParent(
+Diag(NameLoc,
+ AK == TypeAccessKind::Typename
+ ? diag::ext_out_of_line_qualified_id_type_names_constructor
+ : diag::err_out_of_line_qualified_id_type_names_constructor)
+<< TD->getIdentifier() << /*Type*/ 1
+<< 0 /*if any keyword was present, it was 'typename'*/;
+
+  DiagnoseUseOfDecl(TD, NameLoc);
+  MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
+  return Context.getTypeDeclType(TD);
+}
+
 namespace {
 enum class UnqualifiedTypeNameLookupResult {
   NotFound,
@@ -332,10 +351,11 @@
  bool IsClassTemplateDeductionContext,
  

[PATCH] D136336: [clang-format] Mark pragma region lines as StringLiterals

2022-10-22 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

Can you add a test to `TokenAnnotatorTest.cpp`?




Comment at: clang/unittests/Format/FormatTest.cpp:19973-19974
+  verifyFormat("#pragma region TEST(FOO: NOSPACE)", Style);
+  EXPECT_EQ("#pragma region TEST(FOO: NOSPACE)",
+format("#pragma region TEST(FOO: NOSPACE)", Style));
+

Redundant?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136336

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


[PATCH] D136437: [clang-format] Insert closing braces after an unaffected line

2022-10-22 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D136437#3874832 , @MyDeveloperDay 
wrote:

> Does this need a unit test? or are we good?

I will add the tests from https://github.com/llvm/llvm-project/issues/58161 in 
another patch after moving InsertBraces tests out of FormatTest.cpp, which 
doesn't support line range tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136437

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


[PATCH] D136437: [clang-format] Insert closing braces after an unaffected line

2022-10-22 Thread Owen Pan via Phabricator via cfe-commits
owenpan planned changes to this revision.
owenpan added a comment.

The assertions failed on the new examples 
 in 
#58161.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136437

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


[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

2022-10-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang.

The magic number 50 was removed in D134942 , 
as a behavior change for
performance reason.

While it reduces the number of SLocEntry, it increases the usage of
SourceLocation address space usage, which is critical for compiling
large TU.

This fixes a regression caused in D134942  -- 
clang failed to compile one of
our internal files, complaining the file is too large to process because clang
runs out of source location space (we spend 40% more address space!)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136539

Files:
  clang/lib/Lex/TokenLexer.cpp


Index: clang/lib/Lex/TokenLexer.cpp
===
--- clang/lib/Lex/TokenLexer.cpp
+++ clang/lib/Lex/TokenLexer.cpp
@@ -993,14 +993,25 @@
   llvm::MutableArrayRef All(begin_tokens, end_tokens);
   llvm::MutableArrayRef Partition;
 
+  // The maximum distance between two consecutive tokens in a partition.
+  // This is am important trick to avoid using too much SourceLocation address
+  // space!
+  const static int MaxDistance = 50;
   // Partition the tokens by their FileID.
   // This is a hot function, and calling getFileID can be expensive, the
   // implementation is optimized by reducing the number of getFileID.
   if (BeginLoc.isFileID()) {
 // Consecutive tokens not written in macros must be from the same file.
 // (Neither #include nor eof can occur inside a macro argument.)
+SourceLocation LastLoc = BeginLoc;
 Partition = All.take_while([&](const Token &T) {
-  return T.getLocation().isFileID();
+  if (T.getLocation().isFileID()) {
+unsigned distance =
+T.getLocation().getRawEncoding() - LastLoc.getRawEncoding();
+LastLoc = T.getLocation();
+return distance <= MaxDistance;
+  }
+  return false;
 });
   } else {
 // Call getFileID once to calculate the bounds, and use the cheaper
@@ -1008,8 +1019,15 @@
 FileID BeginFID = SM.getFileID(BeginLoc);
 SourceLocation Limit =
 SM.getComposedLoc(BeginFID, SM.getFileIDSize(BeginFID));
+SourceLocation LastLoc = BeginLoc;
 Partition = All.take_while([&](const Token &T) {
-  return T.getLocation() >= BeginLoc && T.getLocation() < Limit;
+  if (T.getLocation() >= BeginLoc && T.getLocation() < Limit) {
+unsigned distance =
+T.getLocation().getRawEncoding() - LastLoc.getRawEncoding();
+LastLoc = T.getLocation();
+return distance <= MaxDistance;
+  }
+  return false;
 });
   }
   assert(!Partition.empty());


Index: clang/lib/Lex/TokenLexer.cpp
===
--- clang/lib/Lex/TokenLexer.cpp
+++ clang/lib/Lex/TokenLexer.cpp
@@ -993,14 +993,25 @@
   llvm::MutableArrayRef All(begin_tokens, end_tokens);
   llvm::MutableArrayRef Partition;
 
+  // The maximum distance between two consecutive tokens in a partition.
+  // This is am important trick to avoid using too much SourceLocation address
+  // space!
+  const static int MaxDistance = 50;
   // Partition the tokens by their FileID.
   // This is a hot function, and calling getFileID can be expensive, the
   // implementation is optimized by reducing the number of getFileID.
   if (BeginLoc.isFileID()) {
 // Consecutive tokens not written in macros must be from the same file.
 // (Neither #include nor eof can occur inside a macro argument.)
+SourceLocation LastLoc = BeginLoc;
 Partition = All.take_while([&](const Token &T) {
-  return T.getLocation().isFileID();
+  if (T.getLocation().isFileID()) {
+unsigned distance =
+T.getLocation().getRawEncoding() - LastLoc.getRawEncoding();
+LastLoc = T.getLocation();
+return distance <= MaxDistance;
+  }
+  return false;
 });
   } else {
 // Call getFileID once to calculate the bounds, and use the cheaper
@@ -1008,8 +1019,15 @@
 FileID BeginFID = SM.getFileID(BeginLoc);
 SourceLocation Limit =
 SM.getComposedLoc(BeginFID, SM.getFileIDSize(BeginFID));
+SourceLocation LastLoc = BeginLoc;
 Partition = All.take_while([&](const Token &T) {
-  return T.getLocation() >= BeginLoc && T.getLocation() < Limit;
+  if (T.getLocation() >= BeginLoc && T.getLocation() < Limit) {
+unsigned distance =
+T.getLocation().getRawEncoding() - LastLoc.getRawEncoding();
+LastLoc = T.getLocation();
+return distance <= MaxDistance;
+  }
+  return false;
 });
   }
   assert(!Partition.empty());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135404: [clang-tidy] Add a checker for converting into C++17 variable template type traits

2022-10-22 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

friendly ping @njames93
FWIW I ran this over the LLVM codebase and have seen no crashes or false 
positives.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135404

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2022-10-22 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski updated this revision to Diff 469940.
calebzulawski added a comment.

Fix formatting, error on unrecognized OS, skip tests if xcrun isn't present.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-sdkroot.c

Index: clang/test/Driver/darwin-sdkroot.c
===
--- clang/test/Driver/darwin-sdkroot.c
+++ clang/test/Driver/darwin-sdkroot.c
@@ -1,4 +1,5 @@
-// Check that SDKROOT is used to define the default for -isysroot on Darwin.
+// Check that SDKROOT is used to define the default for -isysroot on Darwin,
+// or that we call `xcrun --show-sdk-path` if SDKROOT is not in the environment.
 //
 // RUN: rm -rf %t.tmpdir
 // RUN: mkdir -p %t.tmpdir
@@ -39,6 +40,25 @@
 //
 // This test do pass using GnuWin32 env.exe.
 
+// Check that we default to running `xcrun --show-sdk-path` if there is no
+// SDKROOT defined in the environment.
+//
+// RUN: env -u SDKROOT %clang -target x86_64-apple-darwin -c %s -### 2> %t.log
+// RUN: if test -f /usr/bin/xcrun; then FileCheck --check-prefix=CHECK-XCRUN < %t.log %s; fi
+//
+// CHECK-XCRUN: clang
+// CHECK-XCRUN: "-cc1"
+// CHECK-XCRUN: "-isysroot" "{{.*MacOSX[0-9\.]*\.sdk}}"
+
+// Check once again that we default to running `xcrun`, this time with another target.
+//
+// RUN: env -u SDKROOT %clang -target arm64-apple-ios -c %s -### 2> %t.log
+// RUN: if test -f /usr/bin/xcrun; then FileCheck --check-prefix=CHECK-XCRUN-IOS < %t.log %s; fi
+//
+// CHECK-XCRUN-IOS: clang
+// CHECK-XCRUN-IOS: "-cc1"
+// CHECK-XCRUN-IOS: "-isysroot" "{{.*iPhoneOS[0-9\.]*\.sdk}}"
+
 // Check if clang set the correct deployment target from -sysroot
 //
 // RUN: rm -rf %t/SDKs/iPhoneOS8.0.0.sdk
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -18,15 +18,22 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/ProfileData/InstrProf.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include  // ::getenv
+#include   // std::unique_ptr
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -2074,21 +2081,90 @@
 void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
   const OptTable &Opts = getDriver().getOpts();
 
-  // Support allowing the SDKROOT environment variable used by xcrun and other
-  // Xcode tools to define the default sysroot, by making it the default for
-  // isysroot.
+  // On Apple platforms, C and C++ Standard Library headers are not provided
+  // with the base system. Instead, they are provided in various SDKs for the
+  // different Apple platforms. Clang needs to know where that SDK lives, and
+  // there are a couple ways this can be achieved:
+  //
+  // (1) If `-isysroot ` is passed explicitly, use that.
   if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
 // Warn if the path does not exist.
 if (!getVFS().exists(A->getValue()))
   getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue();
-  } else {
-if (char *env = ::getenv("SDKROOT")) {
-  // We only use this value as the default if it is an absolute path,
-  // exists, and it is not the root path.
-  if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
-  StringRef(env) != "/") {
-Args.append(Args.MakeSeparateArg(
-nullptr, Opts.getOption(options::OPT_isysroot), env));
+  }
+
+  // (2) If the SDKROOT environment variable is defined and points to a valid
+  // path, use that. $SDKROOT is set by `xcrun` and other Xcode tools, so
+  // running `xcrun clang` will work by going through this path.
+  else if (char *env = ::getenv("SDKROOT")) {
+// We only use this value as the default if it is an absolute path,
+// exists, and it is not the root path.
+if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
+StringRef(env) != "/") {
+  Args.append(Args.MakeSeparateArg(
+  nullptr, Opts.getOption(options::OPT_isysroot), env));
+}
+  }
+
+  // (3) Otherwise, we try to guess the path of the default SDK by running
+  // `xcrun --show-sdk-path`. This won't always be correct, but if the
+  //  user wants to use the non-default SDK, they should specify it
+  // 

[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2022-10-22 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski marked an inline comment as done.
calebzulawski added inline comments.



Comment at: clang/lib/Driver/ToolChains/Darwin.cpp:2147
+default:
+  // We shouldn't get here, unless the target OS doesn't have an SDK.
+  break;

calebzulawski wrote:
> carlocab wrote:
> > `llvm_unreachable`? Or `assert`, at least.
> I'm not sure that's correct--what if you target something like 
> `x86_64-unknown-none`?  I figured it would be safest to fall back to the 
> previous behavior of simply not providing a sysroot.
Realizing this is never hit for non-darwin targets anyway, added the 
`llvm_unreachable`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

2022-10-22 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136539

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


[PATCH] D136103: OpenMP asynchronous memory copy support

2022-10-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

> we used both kmp relevent data structure/types and APIs, so should I wrap all 
> those relevant code into several tool functions and put them into separate 
> header file?

IMO we can put all KMP related code into one header and include it where 
needed. For the others, the API header has to be included anyway.


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

https://reviews.llvm.org/D136103

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2022-10-22 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski updated this revision to Diff 469948.
calebzulawski added a comment.

Fix test using `RUN` in `CHECK` prefix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-sdkroot.c

Index: clang/test/Driver/darwin-sdkroot.c
===
--- clang/test/Driver/darwin-sdkroot.c
+++ clang/test/Driver/darwin-sdkroot.c
@@ -1,4 +1,5 @@
-// Check that SDKROOT is used to define the default for -isysroot on Darwin.
+// Check that SDKROOT is used to define the default for -isysroot on Darwin,
+// or that we call `xcrun --show-sdk-path` if SDKROOT is not in the environment.
 //
 // RUN: rm -rf %t.tmpdir
 // RUN: mkdir -p %t.tmpdir
@@ -39,6 +40,25 @@
 //
 // This test do pass using GnuWin32 env.exe.
 
+// Check that we default to running `xcrun --show-sdk-path` if there is no
+// SDKROOT defined in the environment.
+//
+// RUN: env -u SDKROOT %clang -target x86_64-apple-darwin -c %s -### 2> %t.log
+// RUN: if test -f /usr/bin/xcrun; then FileCheck --check-prefix=CHECK-XC < %t.log %s; fi
+//
+// CHECK-XC: clang
+// CHECK-XC: "-cc1"
+// CHECK-XC: "-isysroot" "{{.*MacOSX[0-9\.]*\.sdk}}"
+
+// Check once again that we default to running `xcrun`, this time with another target.
+//
+// RUN: env -u SDKROOT %clang -target arm64-apple-ios -c %s -### 2> %t.log
+// RUN: if test -f /usr/bin/xcrun; then FileCheck --check-prefix=CHECK-XC-IOS < %t.log %s; fi
+//
+// CHECK-XC-IOS: clang
+// CHECK-XC-IOS: "-cc1"
+// CHECK-XC-IOS: "-isysroot" "{{.*iPhoneOS[0-9\.]*\.sdk}}"
+
 // Check if clang set the correct deployment target from -sysroot
 //
 // RUN: rm -rf %t/SDKs/iPhoneOS8.0.0.sdk
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -18,15 +18,22 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/ProfileData/InstrProf.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include  // ::getenv
+#include   // std::unique_ptr
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -2074,21 +2081,90 @@
 void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
   const OptTable &Opts = getDriver().getOpts();
 
-  // Support allowing the SDKROOT environment variable used by xcrun and other
-  // Xcode tools to define the default sysroot, by making it the default for
-  // isysroot.
+  // On Apple platforms, C and C++ Standard Library headers are not provided
+  // with the base system. Instead, they are provided in various SDKs for the
+  // different Apple platforms. Clang needs to know where that SDK lives, and
+  // there are a couple ways this can be achieved:
+  //
+  // (1) If `-isysroot ` is passed explicitly, use that.
   if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
 // Warn if the path does not exist.
 if (!getVFS().exists(A->getValue()))
   getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue();
-  } else {
-if (char *env = ::getenv("SDKROOT")) {
-  // We only use this value as the default if it is an absolute path,
-  // exists, and it is not the root path.
-  if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
-  StringRef(env) != "/") {
-Args.append(Args.MakeSeparateArg(
-nullptr, Opts.getOption(options::OPT_isysroot), env));
+  }
+
+  // (2) If the SDKROOT environment variable is defined and points to a valid
+  // path, use that. $SDKROOT is set by `xcrun` and other Xcode tools, so
+  // running `xcrun clang` will work by going through this path.
+  else if (char *env = ::getenv("SDKROOT")) {
+// We only use this value as the default if it is an absolute path,
+// exists, and it is not the root path.
+if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
+StringRef(env) != "/") {
+  Args.append(Args.MakeSeparateArg(
+  nullptr, Opts.getOption(options::OPT_isysroot), env));
+}
+  }
+
+  // (3) Otherwise, we try to guess the path of the default SDK by running
+  // `xcrun --show-sdk-path`. This won't always be correct, but if the
+  //  user wants to use the non-default SDK, they should specify it
+  //  explicitly with methods (1) or (2) above.
+  else {
+llvm

[PATCH] D133863: [RISCV] Add MC support of RISCV zcmt Extension

2022-10-22 Thread Xinlong Wu via Phabricator via cfe-commits
VincentWu updated this revision to Diff 469947.
VincentWu marked 12 inline comments as done.
VincentWu edited the summary of this revision.
VincentWu added a comment.

- update the document
- Throw an error when `+c` and `+zcmt` are both specified
- test CSR


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133863

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoC.td
  llvm/lib/Target/RISCV/RISCVSchedRocket.td
  llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/lib/Target/RISCV/RISCVSystemOperands.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcmt-invalid.s
  llvm/test/MC/RISCV/rv32zcmt-valid.s
  llvm/test/MC/RISCV/rvzcmt-user-csr-name.s

Index: llvm/test/MC/RISCV/rvzcmt-user-csr-name.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvzcmt-user-csr-name.s
@@ -0,0 +1,29 @@
+# RUN: llvm-mc %s -triple=riscv32 -riscv-no-aliases -mattr=+experimental-zcmt -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-INST,CHECK-ENC %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-zcmt < %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zcmt - \
+# RUN: | FileCheck -check-prefix=CHECK-INST-ALIAS %s
+#
+# RUN: llvm-mc %s -triple=riscv64 -riscv-no-aliases -mattr=+experimental-zcmt -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-INST,CHECK-ENC %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+experimental-zcmt < %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zcmt - \
+# RUN: | FileCheck -check-prefix=CHECK-INST-ALIAS %s
+
+##
+# Jump Vector Table CSR
+##
+
+# jvt
+# name
+# CHECK-INST: csrrs t1, jvt, zero
+# CHECK-ENC:  encoding: [0x73,0x23,0x70,0x01]
+# CHECK-INST-ALIAS: csrr t1, jvt
+# uimm12
+# CHECK-INST: csrrs t2, jvt, zero
+# CHECK-ENC:  encoding: [0xf3,0x23,0x70,0x01]
+# CHECK-INST-ALIAS: csrr t2, jvt
+# name
+csrrs t1, jvt, zero
+# uimm12
+csrrs t2, 0x017, zero
Index: llvm/test/MC/RISCV/rv32zcmt-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcmt-valid.s
@@ -0,0 +1,39 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zcmt\
+# RUN:  -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zcmt\
+# RUN:  -mattr=m < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zcmt\
+# RUN:  -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-OBJ,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zcmt\
+# RUN:  -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zcmt\
+# RUN:  -mattr=m < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zcmt\
+# RUN:  -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-OBJ,CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv32 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+# CHECK-ASM-AND-OBJ: cm.jt 1
+# CHECK-ASM: encoding: [0x06,0xa0]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcmt' (table jump instuctions for code-size reduction){{$}}
+cm.jt 1
+
+# CHECK-ASM: cm.jalt 1
+# CHECK-OBJ: cm.jt 1
+# CHECK-ASM: encoding: [0x06,0xa0]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcmt' (table jump instuctions for code-size reduction){{$}}
+cm.jalt 1
+
+# CHECK-ASM-AND-OBJ: cm.jalt 32
+# CHECK-ASM: encoding: [0x82,0xa0]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcmt' (table jump instuctions for code-size reduction){{$}}
+cm.jalt 32
Index: llvm/test/MC/RISCV/rv32zcmt-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcmt-invalid.s
@@ -0,0 +1,10 @@
+# RUN: not llvm-mc -triple=riscv32 -mattr=+experimental-zcmt -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-ERROR %s
+# RUN: not llvm-mc -triple=riscv64 -mattr=+experimental-zcmt -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-ERROR %s
+
+# CHECK-ERROR: error: immediate must be an integer in the range [0, 31]
+cm.jt 64
+
+# CHECK-ERROR: error: immediate must be an integer in the range [

[PATCH] D133863: [RISCV] Add MC support of RISCV zcmt Extension

2022-10-22 Thread Xinlong Wu via Phabricator via cfe-commits
VincentWu added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCV.td:366
+   "'Zcmt' (table jump instuctions for code-size 
reduction)", 
+   [FeatureExtZca]>; // TODO: add Zicsr as another 
dependence
+def HasStdExtZcmt : Predicate<"Subtarget->hasStdExtZcmt() && 
!Subtarget->hasStdExtC()">,

jrtc27 wrote:
> This is an odd implication, Zcmt works just fine without Zca?
the [[ 
https://github.com/riscv/riscv-code-size-reduction/releases/tag/v1.0.0-RC5.7 | 
spec ]] says:
> The Zcmt extension depends on the Zca and Zicsr extensions.

I think maybe `zcmt` needs to be aligned using `c.nop`?  That might be one of 
the reasons why `zcmt` required `zca`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133863

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


[PATCH] D136103: OpenMP asynchronous memory copy support

2022-10-22 Thread Jisheng Zhao via Phabricator via cfe-commits
jz10 added a comment.

Regarding this, can we just move those two helper functions to private.h ?


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

https://reviews.llvm.org/D136103

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


[PATCH] D136022: [clang] Add time profile for constant evaluation

2022-10-22 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

Hi @Izaron, several of our internal tests that run tests using `-ftime-trace` 
started crashing when run which I bisected back to your change. I have filed 
issue #58551  for it, can 
you take a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136022

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


[PATCH] D136022: [clang] Add time profile for constant evaluation

2022-10-22 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added a comment.

In D136022#3877399 , @dyung wrote:

> Hi @Izaron, several of our internal tests that run tests using `-ftime-trace` 
> started crashing when run which I bisected back to your change. I have filed 
> issue #58551  for it, can 
> you take a look?

Hi! Thank you for filling the issue! I will fix it as soon as I can!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136022

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2022-10-22 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski updated this revision to Diff 469953.
calebzulawski added a comment.

Try to fix windows test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-sdkroot.c

Index: clang/test/Driver/darwin-sdkroot.c
===
--- clang/test/Driver/darwin-sdkroot.c
+++ clang/test/Driver/darwin-sdkroot.c
@@ -1,4 +1,5 @@
-// Check that SDKROOT is used to define the default for -isysroot on Darwin.
+// Check that SDKROOT is used to define the default for -isysroot on Darwin,
+// or that we call `xcrun --show-sdk-path` if SDKROOT is not in the environment.
 //
 // RUN: rm -rf %t.tmpdir
 // RUN: mkdir -p %t.tmpdir
@@ -39,6 +40,25 @@
 //
 // This test do pass using GnuWin32 env.exe.
 
+// Check that we default to running `xcrun --show-sdk-path` if there is no
+// SDKROOT defined in the environment.
+//
+// RUN: env -u SDKROOT %clang -target x86_64-apple-darwin -c %s -### 2> %t.log
+// RUN: if [[ -f "/usr/bin/xcrun" ]]; then FileCheck --check-prefix=CHECK-XC < %t.log %s; fi
+//
+// CHECK-XC: clang
+// CHECK-XC: "-cc1"
+// CHECK-XC: "-isysroot" "{{.*MacOSX[0-9\.]*\.sdk}}"
+
+// Check once again that we default to running `xcrun`, this time with another target.
+//
+// RUN: env -u SDKROOT %clang -target arm64-apple-ios -c %s -### 2> %t.log
+// RUN: if [[ -f "/usr/bin/xcrun" ]]; then FileCheck --check-prefix=CHECK-XC-IOS < %t.log %s; fi
+//
+// CHECK-XC-IOS: clang
+// CHECK-XC-IOS: "-cc1"
+// CHECK-XC-IOS: "-isysroot" "{{.*iPhoneOS[0-9\.]*\.sdk}}"
+
 // Check if clang set the correct deployment target from -sysroot
 //
 // RUN: rm -rf %t/SDKs/iPhoneOS8.0.0.sdk
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -18,15 +18,22 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/ProfileData/InstrProf.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include  // ::getenv
+#include   // std::unique_ptr
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -2074,21 +2081,90 @@
 void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
   const OptTable &Opts = getDriver().getOpts();
 
-  // Support allowing the SDKROOT environment variable used by xcrun and other
-  // Xcode tools to define the default sysroot, by making it the default for
-  // isysroot.
+  // On Apple platforms, C and C++ Standard Library headers are not provided
+  // with the base system. Instead, they are provided in various SDKs for the
+  // different Apple platforms. Clang needs to know where that SDK lives, and
+  // there are a couple ways this can be achieved:
+  //
+  // (1) If `-isysroot ` is passed explicitly, use that.
   if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
 // Warn if the path does not exist.
 if (!getVFS().exists(A->getValue()))
   getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue();
-  } else {
-if (char *env = ::getenv("SDKROOT")) {
-  // We only use this value as the default if it is an absolute path,
-  // exists, and it is not the root path.
-  if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
-  StringRef(env) != "/") {
-Args.append(Args.MakeSeparateArg(
-nullptr, Opts.getOption(options::OPT_isysroot), env));
+  }
+
+  // (2) If the SDKROOT environment variable is defined and points to a valid
+  // path, use that. $SDKROOT is set by `xcrun` and other Xcode tools, so
+  // running `xcrun clang` will work by going through this path.
+  else if (char *env = ::getenv("SDKROOT")) {
+// We only use this value as the default if it is an absolute path,
+// exists, and it is not the root path.
+if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
+StringRef(env) != "/") {
+  Args.append(Args.MakeSeparateArg(
+  nullptr, Opts.getOption(options::OPT_isysroot), env));
+}
+  }
+
+  // (3) Otherwise, we try to guess the path of the default SDK by running
+  // `xcrun --show-sdk-path`. This won't always be correct, but if the
+  //  user wants to use the non-default SDK, they should specify it
+  //  explicitly with methods (1) or (2) above.
+  else {
+llvm::SmallSt

[PATCH] D136474: [CodeView][clang] Add flag to disable emitting command line into CodeView

2022-10-22 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 469954.
aeubanks added a comment.

default to off


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136474

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/debug-info-codeview-buildinfo.c
  clang/test/Driver/gcodeview-command-line.c

Index: clang/test/Driver/gcodeview-command-line.c
===
--- /dev/null
+++ clang/test/Driver/gcodeview-command-line.c
@@ -0,0 +1,19 @@
+// Note: %s must be preceded by --, otherwise it may be interpreted as a
+// command-line option, e.g. on Mac where %s is commonly under /Users.
+
+// CMD: "-gcodeview-command-line"
+// NO_CMD-NOT: "-gcodeview-command-line"
+
+// default
+// RUN: %clang_cl /Z7 -### -- %s 2>&1 | FileCheck -check-prefix=NO_CMD %s
+// enabled
+// RUN: %clang_cl /Z7 -gno-codeview-command-line -gcodeview-command-line -### -- %s 2>&1 | FileCheck -check-prefix=CMD %s
+// disabled
+// RUN: %clang_cl /Z7 -gcodeview-command-line -gno-codeview-command-line -### -- %s 2>&1 | FileCheck -check-prefix=NO_CMD %s
+
+// enabled, no /Z7
+// RUN: %clang_cl -gcodeview-command-line -### -- %s 2>&1 | FileCheck -check-prefix=NO_CMD %s
+
+// GCC-style driver
+// RUN: %clang -g -gcodeview -gno-codeview-command-line -gcodeview-command-line -### -- %s 2>&1 | FileCheck -check-prefix=CMD %s
+// RUN: %clang -g -gcodeview -gcodeview-command-line -gno-codeview-command-line -### -- %s 2>&1 | FileCheck -check-prefix=NO_CMD %s
Index: clang/test/CodeGen/debug-info-codeview-buildinfo.c
===
--- clang/test/CodeGen/debug-info-codeview-buildinfo.c
+++ clang/test/CodeGen/debug-info-codeview-buildinfo.c
@@ -1,8 +1,12 @@
 // REQUIRES: x86-registered-target
-// RUN: %clang_cl --target=i686-windows-msvc /c /Z7 /Fo%t.obj -- %s
+// RUN: %clang_cl -gcodeview-command-line --target=i686-windows-msvc /c /Z7 /Fo%t.obj -- %s
 // RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s
 // RUN: %clang_cl --target=i686-windows-msvc /c /Z7 /Fo%t.obj -fdebug-compilation-dir=. -- %s
 // RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix RELATIVE
+// RUN: %clang_cl --target=i686-windows-msvc /c /Z7 /Fo%t.obj -- %s
+// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix DISABLE
+// RUN: %clang_cl -gno-codeview-command-line --target=i686-windows-msvc /c /Z7 /Fo%t.obj -- %s
+// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix DISABLE
 
 int main(void) { return 42; }
 
@@ -14,13 +18,21 @@
 // CHECK: 0x[[TOOL:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String: [[TOOLVAL:.+[\\/]clang.*]]
 // CHECK: 0x[[CMDLINE:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String: "-cc1
 // CHECK: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
-// CHECK:  0x[[PWD]]: `[[PWDVAL]]`
-// CHECK:  0x[[TOOL]]: `[[TOOLVAL]]`
-// CHECK:  0x[[FILEPATH]]: `[[FILEPATHVAL]]`
-// CHECK:  0x[[ZIPDB]]: ``
-// CHECK:  0x[[CMDLINE]]: `"-cc1
+// CHECK-NEXT:  0x[[PWD]]: `[[PWDVAL]]`
+// CHECK-NEXT:  0x[[TOOL]]: `[[TOOLVAL]]`
+// CHECK-NEXT:  0x[[FILEPATH]]: `[[FILEPATHVAL]]`
+// CHECK-NEXT:  0x[[ZIPDB]]: ``
+// CHECK-NEXT:  0x[[CMDLINE]]: `"-cc1
 
 // RELATIVE:   Types (.debug$T)
 // RELATIVE: 
 // RELATIVE: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
 // RELATIVE:  0x{{.+}}: `.`
+
+// DISABLE-NOT: cc1
+// DISABLE: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
+// DISABLE-NEXT:  0x{{.+}}: `{{.*}}`
+// DISABLE-NEXT:  : ``
+// DISABLE-NEXT:  0x{{.+}}: `{{.*}}`
+// DISABLE-NEXT:  0x{{.+}}: ``
+// DISABLE-NEXT:  : ``
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4542,8 +4542,10 @@
   }
 
   // Store the command-line for using in the CodeView backend.
-  Res.getCodeGenOpts().Argv0 = Argv0;
-  append_range(Res.getCodeGenOpts().CommandLineArgs, CommandLineArgs);
+  if (Res.getCodeGenOpts().CodeViewCommandLine) {
+Res.getCodeGenOpts().Argv0 = Argv0;
+append_range(Res.getCodeGenOpts().CommandLineArgs, CommandLineArgs);
+  }
 
   FixupInvocation(Res, Diags, Args, DashX);
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4346,10 +4346,12 @@
 CmdArgs.push_back("-gcodeview");
 
 // Emit codeview type hashes if requested.
-if (Args.hasFlag(options::OPT_gcodeview_ghash,
- options::OPT_gno_codeview_ghash, f

[PATCH] D136474: [CodeView][clang] Add flag to disable emitting command line into CodeView

2022-10-22 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:4354
+
+// Emit codeview command line if requested.
+if (Args.hasFlag(options::OPT_gcodeview_command_line,

aganea wrote:
> aeubanks wrote:
> > MaskRay wrote:
> > > This needs a test in clang/test/Driver/
> > > 
> > > Use `addOptInFlag`
> > `addOptIn/OutFlag` doesn't work here with the semantics I want
> > 
> > For -cc1, `-gcodeview-command-line` should control whether or not we use 
> > this feature, defaulting to not performing this feature.
> > But on the driver level, not specifying anything should pass 
> > `-gcodeview-command-line` by default (assuming `EmitCodeView`).
> > 
> > But perhaps this is confusing and we should default to 
> > `-gcodeview-command-line` everywhere?
> Is there a reason for having divergent initial values? `true` below but 
> `-gcodeview-command-line` being `false`? They should be the same. The other 
> question is, MSVC emits LF_BUILDINFO by default (if /Z7 is on). Not sure if 
> we should be compatible out-of-the-box or if we should favor good cache hits? 
> I have no problem specifying the flag on the cmd-line if it isn't on by 
> default.
> 
> +@stefan_reinalter 
the reason was to keep compatibility with msvc by emitting the command line by 
default, but I also wanted the -cc1 value to determine whether or not we 
actually did this

anyway, I've turned this feature off by default for now, open to reverting back 
to turning it on by default if people want that


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136474

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


[clang] c9447c6 - [Clang] fold expression is considered atomic during constraints normalization

2022-10-22 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-10-22T20:48:57-07:00
New Revision: c9447c62966e5ec60ec277e4a7d75420224f53f6

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

LOG: [Clang] fold expression is considered atomic during constraints 
normalization

`|| fold` is not disjunction; `&& fold` is not conjunction. Both are atomic per
current wording. See http://cplusplus.github.io/concepts-ts/ts-active.html#28.

D128750 accidentally tried to partially addresss this which is not desirable.
This patch reverts that part and associated test cases.

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 9809ccb2ccc00..484c02498f20b 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1110,14 +1110,8 @@ NormalizedConstraint::fromConstraintExpr(Sema &S, 
NamedDecl *D, const Expr *E) {
 
   // C++2a [temp.param]p4:
   // [...] If T is not a pack, then E is E', otherwise E is (E' && ...).
-  //
-  // Using the pattern suffices because the partial ordering rules guarantee
-  // the template paramaters are equivalent.
-  if (auto *FoldE = dyn_cast(E)) {
-assert(FoldE->isRightFold() && FoldE->getOperator() == BO_LAnd);
-assert(E->IgnoreParenImpCasts() == E);
-E = FoldE->getPattern();
-  }
+  // Fold expression is considered atomic constraints per current wording.
+  // See http://cplusplus.github.io/concepts-ts/ts-active.html#28
 
   if (LogicalBinOp BO = E) {
 auto LHS = fromConstraintExpr(S, D, BO.getLHS());

diff  --git a/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp 
b/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
index bdd1c376243bb..d6e6d73d05ed5 100644
--- a/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
@@ -44,23 +44,8 @@ template
 void foo(T, U);
 
-// check auto template parameter pack.
-template class U,
- C auto... Z>
-void foo2(T, U) = delete;
-template class U,
- D auto... Z>
-void foo2(T, U) = delete;
-template class U,
- E auto... Z>
-void foo2(T, U);
-
 void bar(S s, S2 s2) {
   foo(0, s);
-  foo2(0, s2);
 }
 
 template void bar2();
@@ -110,8 +95,9 @@ template struct Y4; // expected-error 
{{class template partial s
 template struct W1;
 template struct W1 {};
 
-template struct W2;
-template struct W2 {};
+// See http://cplusplus.github.io/concepts-ts/ts-active.html#28
+// template struct W2;
+// template struct W2 {};
 
 template
 concept C1 = C && C;
@@ -121,8 +107,9 @@ concept D1 = D && C;
 template auto T> struct W3;
 template auto T> struct W3 {};
 
-template auto... T> struct W4;
-template auto... T> struct W4 {};
+// See http://cplusplus.github.io/concepts-ts/ts-active.html#28
+// template auto... T> struct W4;
+// template auto... T> struct W4 {};
 
 // FIXME: enable once Clang support non-trivial auto on NTTP.
 // template struct W5;
@@ -133,9 +120,9 @@ template auto... T> struct W4 {};
 // template struct W6 {};
 
 struct W1<0> w1;
-struct W2<0> w2;
+// struct W2<0> w2;
 struct W3<0> w3;
-struct W4<0> w4;
+// struct W4<0> w4;
 // FIXME: enable once Clang support non-trivial auto on NTTP.
 // struct W5<(int*)nullptr> w5;
 // struct W6 w6;



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


[PATCH] D136090: Handle errors in expansion of response files

2022-10-22 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 469957.
sepavloff added a comment.

Small changes proposed by reviewers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136090

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/test/Driver/config-file-errs.c
  clang/tools/driver/driver.cpp
  clang/unittests/Driver/ToolChainTest.cpp
  flang/tools/flang-driver/driver.cpp
  llvm/include/llvm/Support/CommandLine.h
  llvm/lib/Support/CommandLine.cpp
  llvm/unittests/Support/CommandLineTest.cpp

Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -871,7 +871,7 @@
   llvm::BumpPtrAllocator A;
   llvm::cl::ExpansionContext ECtx(A, llvm::cl::TokenizeGNUCommandLine);
   ECtx.setVFS(&FS).setCurrentDir(TestRoot).setRelativeNames(true);
-  ASSERT_TRUE(ECtx.expandResponseFiles(Argv));
+  ASSERT_FALSE((bool)ECtx.expandResponseFiles(Argv));
   EXPECT_THAT(Argv, testing::Pointwise(
 StringEquality(),
 {"test/test", "-flag_1", "-option_1", "-option_2",
@@ -933,7 +933,14 @@
 #endif
   llvm::cl::ExpansionContext ECtx(A, Tokenizer);
   ECtx.setVFS(&FS).setCurrentDir(TestRoot);
-  ASSERT_FALSE(ECtx.expandResponseFiles(Argv));
+  llvm::Error Err = ECtx.expandResponseFiles(Argv);
+  ASSERT_TRUE((bool)Err);
+  SmallString<128> FilePath = SelfFilePath;
+  std::error_code EC = FS.makeAbsolute(FilePath);
+  ASSERT_FALSE((bool)EC);
+  std::string ExpectedMessage =
+  std::string("recursive expansion of: '") + std::string(FilePath) + "'";
+  ASSERT_TRUE(toString(std::move(Err)) == ExpectedMessage);
 
   EXPECT_THAT(Argv,
   testing::Pointwise(StringEquality(),
@@ -971,7 +978,7 @@
   BumpPtrAllocator A;
   llvm::cl::ExpansionContext ECtx(A, cl::TokenizeGNUCommandLine);
   ECtx.setVFS(&FS).setCurrentDir(TestRoot);
-  ASSERT_FALSE(ECtx.expandResponseFiles(Argv));
+  ASSERT_FALSE((bool)ECtx.expandResponseFiles(Argv));
 
   // ASSERT instead of EXPECT to prevent potential out-of-bounds access.
   ASSERT_EQ(Argv.size(), 1 + NON_RSP_AT_ARGS + 2);
@@ -1005,7 +1012,7 @@
   BumpPtrAllocator A;
   llvm::cl::ExpansionContext ECtx(A, cl::TokenizeGNUCommandLine);
   ECtx.setVFS(&FS).setCurrentDir(TestRoot).setRelativeNames(true);
-  ASSERT_TRUE(ECtx.expandResponseFiles(Argv));
+  ASSERT_FALSE((bool)ECtx.expandResponseFiles(Argv));
   EXPECT_THAT(Argv,
   testing::Pointwise(StringEquality(), {"test/test", "-flag"}));
 }
@@ -1025,7 +1032,7 @@
   llvm::cl::ExpansionContext ECtx(A, cl::TokenizeWindowsCommandLine);
   ECtx.setVFS(&FS).setCurrentDir(TestRoot).setMarkEOLs(true).setRelativeNames(
   true);
-  ASSERT_TRUE(ECtx.expandResponseFiles(Argv));
+  ASSERT_FALSE((bool)ECtx.expandResponseFiles(Argv));
   const char *Expected[] = {"clang", "-Xclang", "-Wno-whatever", nullptr,
 "input.cpp"};
   ASSERT_EQ(std::size(Expected), Argv.size());
@@ -1038,6 +1045,30 @@
   }
 }
 
+TEST(CommandLineTest, BadResponseFile) {
+  BumpPtrAllocator A;
+  StringSaver Saver(A);
+  TempDir ADir("dir", /*Unique*/ true);
+  SmallString<128> AFilePath = ADir.path();
+  llvm::sys::path::append(AFilePath, "file.rsp");
+  std::string AFileExp = std::string("@") + std::string(AFilePath.str());
+  SmallVector Argv = {"clang", AFileExp.c_str()};
+
+  bool Res = cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv);
+  ASSERT_TRUE(Res);
+  ASSERT_EQ(2U, Argv.size());
+  ASSERT_STREQ(Argv[0], "clang");
+  ASSERT_STREQ(Argv[1], AFileExp.c_str());
+
+  std::string ADirExp = std::string("@") + std::string(ADir.path());
+  Argv = {"clang", ADirExp.c_str()};
+  Res = cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv);
+  ASSERT_FALSE(Res);
+  ASSERT_EQ(2U, Argv.size());
+  ASSERT_STREQ(Argv[0], "clang");
+  ASSERT_STREQ(Argv[1], ADirExp.c_str());
+}
+
 TEST(CommandLineTest, SetDefaultValue) {
   cl::ResetCommandLineParser();
 
@@ -1145,9 +1176,9 @@
 
   llvm::BumpPtrAllocator A;
   llvm::cl::ExpansionContext ECtx(A, cl::tokenizeConfigFile);
-  bool Result = ECtx.readConfigFile(ConfigFile.path(), Argv);
+  llvm::Error Result = ECtx.readConfigFile(ConfigFile.path(), Argv);
 
-  EXPECT_TRUE(Result);
+  EXPECT_FALSE((bool)Result);
   EXPECT_EQ(Argv.size(), 13U);
   EXPECT_STREQ(Argv[0], "-option_1");
   EXPECT_STREQ(Argv[1],
Index: llvm/lib/Support/CommandLine.cpp
===
--- llvm/lib/Support/CommandLine.cpp
+++ llvm/lib/Support/CommandLine.cpp
@@ -1153,14 +1153,14 @@
 }
 
 // FName must be an absolute path.
-llvm::Error
-ExpansionContext::expandResponseFile(StringRef FName,
- SmallVectorImpl &NewArgv) {
+Error ExpansionCont

[PATCH] D136090: Handle errors in expansion of response files

2022-10-22 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: llvm/lib/Support/CommandLine.cpp:1188
+  // macros.
+  if (!RelativeNames && !InConfigFile)
 return Error::success();

rovka wrote:
> Why do you need to add `!InConfigFile` here and below? 
It is not necessary, because now configuration file is expanded with the flag 
`RelativeNames` set. It however seems more correct to check for `InConfigFile` 
also, hopefully it make code a bit clearly.



Comment at: llvm/lib/Support/CommandLine.cpp:1204
+StringRef FileName;
+if (ArgStr[0] == '@') {
+  FileName = ArgStr.drop_front(1);

rovka wrote:
> Nit: Why reverse this branch? The code around it `continue`s early, so it's 
> easier to read if this `continue`s early too.
You are right. Initially this patch was combined with D136354, where additional 
checks was added. I changed this code to be more natural.



Comment at: llvm/lib/Support/CommandLine.cpp:1205
+if (ArgStr[0] == '@') {
+  FileName = ArgStr.drop_front(1);
+  if (!llvm::sys::path::is_relative(FileName))

mgorny wrote:
> Also, I think you can use `consume_front()` here.
Yes, changed code accordingly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136090

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


[PATCH] D136545: [Clang] use non-template function declaration for constraints partial ordering

2022-10-22 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen created this revision.
ychen added reviewers: erichkeane, royjacobson, mizvekov.
Herald added a project: All.
ychen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Per wordings in

- https://eel.is/c++draft/over.match#best.general-2.6
- https://eel.is/c++draft/temp.constr.order
- https://eel.is/c++draft/temp.constr#atomic-1

constraints partial ordering should use the unsubstituted template
parameters of the constrained entity, not the instantiated entity.

Fix #56154


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136545

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/over/over.match/over.match.best/p2.cpp
  clang/test/CXX/temp/temp.constr/temp.constr.order/non-template-functions.cpp


Index: 
clang/test/CXX/temp/temp.constr/temp.constr.order/non-template-functions.cpp
===
--- /dev/null
+++ clang/test/CXX/temp/temp.constr/temp.constr.order/non-template-functions.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -std=c++2a -x c++ -verify %s
+// expected-no-diagnostics
+
+namespace PR56154 {
+  template  concept C0 = (N == 0);
+  template  concept C0x = C0;
+  template  concept C00 = C0x && C0;
+
+  template
+  struct A {
+ void f() requires C00;
+ void f() requires C0x;
+  };
+  void h(A<0, 0> a) {
+   a.f();
+  }
+}
Index: clang/test/CXX/over/over.match/over.match.best/p2.cpp
===
--- clang/test/CXX/over/over.match/over.match.best/p2.cpp
+++ clang/test/CXX/over/over.match/over.match.best/p2.cpp
@@ -7,8 +7,7 @@
 bool operator<(const A&) const & requires X; // #1
 int operator<=>(const A&) const & requires X && X = delete; // #2
   };
-  bool k1 = A() < A(); // not ordered by constraints: prefer 
non-rewritten form
-  bool k2 = A() < A(); // prefer more-constrained 'operator<=>'
+  bool k = A() < A(); // prefer more-constrained 'operator<=>'
   // expected-error@-1 {{deleted}}
   // expected-note@#1 {{candidate}}
   // expected-note@#2 {{candidate function has been explicitly deleted}}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -10033,13 +10033,20 @@
   //  parameter-type-lists, and F1 is more constrained than F2 [...],
   if (!Cand1IsSpecialization && !Cand2IsSpecialization &&
   sameFunctionParameterTypeLists(S, Cand1, Cand2)) {
-Expr *RC1 = Cand1.Function->getTrailingRequiresClause();
-Expr *RC2 = Cand2.Function->getTrailingRequiresClause();
+FunctionDecl *Function1 = Cand1.Function;
+FunctionDecl *Function2 = Cand2.Function;
+if (FunctionDecl *MF = Function1->getInstantiatedFromMemberFunction())
+  Function1 = MF;
+if (FunctionDecl *MF = Function2->getInstantiatedFromMemberFunction())
+  Function2 = MF;
+
+Expr *RC1 = Function1->getTrailingRequiresClause();
+Expr *RC2 = Function2->getTrailingRequiresClause();
 if (RC1 && RC2) {
   bool AtLeastAsConstrained1, AtLeastAsConstrained2;
-  if (S.IsAtLeastAsConstrained(Cand1.Function, {RC1}, Cand2.Function, 
{RC2},
+  if (S.IsAtLeastAsConstrained(Function1, {RC1}, Function2, {RC2},
AtLeastAsConstrained1) ||
-  S.IsAtLeastAsConstrained(Cand2.Function, {RC2}, Cand1.Function, 
{RC1},
+  S.IsAtLeastAsConstrained(Function2, {RC2}, Function1, {RC1},
AtLeastAsConstrained2))
 return false;
   if (AtLeastAsConstrained1 != AtLeastAsConstrained2)


Index: clang/test/CXX/temp/temp.constr/temp.constr.order/non-template-functions.cpp
===
--- /dev/null
+++ clang/test/CXX/temp/temp.constr/temp.constr.order/non-template-functions.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -std=c++2a -x c++ -verify %s
+// expected-no-diagnostics
+
+namespace PR56154 {
+  template  concept C0 = (N == 0);
+  template  concept C0x = C0;
+  template  concept C00 = C0x && C0;
+
+  template
+  struct A {
+ void f() requires C00;
+ void f() requires C0x;
+  };
+  void h(A<0, 0> a) {
+   a.f();
+  }
+}
Index: clang/test/CXX/over/over.match/over.match.best/p2.cpp
===
--- clang/test/CXX/over/over.match/over.match.best/p2.cpp
+++ clang/test/CXX/over/over.match/over.match.best/p2.cpp
@@ -7,8 +7,7 @@
 bool operator<(const A&) const & requires X; // #1
 int operator<=>(const A&) const & requires X && X = delete; // #2
   };
-  bool k1 = A() < A(); // not ordered by constraints: prefer non-rewritten form
-  bool k2 = A() < A(); // prefer more-constrained 'operator<=>'
+  bool k = A() < A(); // prefer more-constrained 'operator<=>'
   // expected-error@-1 {{deleted}}
   // expected-note@#1 {{candidate}}
   // expected-note@#2 {{candidate function ha

[PATCH] D136545: [Clang] use non-template function declaration for constraints partial ordering

2022-10-22 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/test/CXX/over/over.match/over.match.best/p2.cpp:10
   };
-  bool k1 = A() < A(); // not ordered by constraints: prefer 
non-rewritten form
-  bool k2 = A() < A(); // prefer more-constrained 'operator<=>'

Remove this case because it compiles by accident. 
https://eel.is/c++draft/over.match#best.general-2.6 take precedence over 
https://eel.is/c++draft/over.match#best.general-2.8.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136545

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


[PATCH] D136546: [clang][unittest] Resolve ClangSupportTest link time errors

2022-10-22 Thread John McIver via Phabricator via cfe-commits
jmciver created this revision.
Herald added a project: All.
jmciver added reviewers: Izaron, Ericson2314, thieta, tstellar.
jmciver published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Resolves undefined references to vtable for clang::ASTConsumer,
PCHContainerOperations::PCHContainerOperations(), and
CodeGenOptions::CodeGenOptions().


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136546

Files:
  clang/unittests/Support/CMakeLists.txt


Index: clang/unittests/Support/CMakeLists.txt
===
--- clang/unittests/Support/CMakeLists.txt
+++ clang/unittests/Support/CMakeLists.txt
@@ -8,5 +8,8 @@
 
 clang_target_link_libraries(ClangSupportTests
   PRIVATE
+  clangAST
+  clangBasic
   clangFrontend
+  clangSerialization
   )


Index: clang/unittests/Support/CMakeLists.txt
===
--- clang/unittests/Support/CMakeLists.txt
+++ clang/unittests/Support/CMakeLists.txt
@@ -8,5 +8,8 @@
 
 clang_target_link_libraries(ClangSupportTests
   PRIVATE
+  clangAST
+  clangBasic
   clangFrontend
+  clangSerialization
   )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136090: Handle errors in expansion of response files

2022-10-22 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:1029
 if (llvm::sys::path::is_relative(CfgFilePath)) {
-  if (getVFS().makeAbsolute(CfgFilePath))
-return true;
-  auto Status = getVFS().status(CfgFilePath);
-  if (!Status ||
-  Status->getType() != llvm::sys::fs::file_type::regular_file) {
-Diag(diag::err_drv_config_file_not_exist) << CfgFilePath;
+  if (std::error_code EC = getVFS().makeAbsolute(CfgFilePath)) {
+Diag(diag::err_drv_cannot_open_config_file)

Either I'm missing something or you're not using `EC`.



Comment at: clang/lib/Driver/Driver.cpp:1041
+}
+if (Status->getType() != llvm::sys::fs::file_type::regular_file) {
+  Diag(diag::err_drv_cannot_open_config_file)

Not necessarily a goal for this patch but wouldn't this check fit better in 
`readConfigFile()`?



Comment at: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp:67-69
+  if (Err) {
+llvm::errs() << Err;
+  }

The braces seem unnecessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136090

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


[PATCH] D136545: [Clang] use non-template function declaration for constraints partial ordering

2022-10-22 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 469963.
ychen added a comment.

- add a release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136545

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/over/over.match/over.match.best/p2.cpp
  clang/test/CXX/temp/temp.constr/temp.constr.order/non-template-functions.cpp


Index: 
clang/test/CXX/temp/temp.constr/temp.constr.order/non-template-functions.cpp
===
--- /dev/null
+++ clang/test/CXX/temp/temp.constr/temp.constr.order/non-template-functions.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -std=c++2a -x c++ -verify %s
+// expected-no-diagnostics
+
+namespace PR56154 {
+  template  concept C0 = (N == 0);
+  template  concept C0x = C0;
+  template  concept C00 = C0x && C0;
+
+  template
+  struct A {
+ void f() requires C00;
+ void f() requires C0x;
+  };
+  void h(A<0, 0> a) {
+   a.f();
+  }
+}
Index: clang/test/CXX/over/over.match/over.match.best/p2.cpp
===
--- clang/test/CXX/over/over.match/over.match.best/p2.cpp
+++ clang/test/CXX/over/over.match/over.match.best/p2.cpp
@@ -7,8 +7,7 @@
 bool operator<(const A&) const & requires X; // #1
 int operator<=>(const A&) const & requires X && X = delete; // #2
   };
-  bool k1 = A() < A(); // not ordered by constraints: prefer 
non-rewritten form
-  bool k2 = A() < A(); // prefer more-constrained 'operator<=>'
+  bool k = A() < A(); // prefer more-constrained 'operator<=>'
   // expected-error@-1 {{deleted}}
   // expected-note@#1 {{candidate}}
   // expected-note@#2 {{candidate function has been explicitly deleted}}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -10033,13 +10033,20 @@
   //  parameter-type-lists, and F1 is more constrained than F2 [...],
   if (!Cand1IsSpecialization && !Cand2IsSpecialization &&
   sameFunctionParameterTypeLists(S, Cand1, Cand2)) {
-Expr *RC1 = Cand1.Function->getTrailingRequiresClause();
-Expr *RC2 = Cand2.Function->getTrailingRequiresClause();
+FunctionDecl *Function1 = Cand1.Function;
+FunctionDecl *Function2 = Cand2.Function;
+if (FunctionDecl *MF = Function1->getInstantiatedFromMemberFunction())
+  Function1 = MF;
+if (FunctionDecl *MF = Function2->getInstantiatedFromMemberFunction())
+  Function2 = MF;
+
+Expr *RC1 = Function1->getTrailingRequiresClause();
+Expr *RC2 = Function2->getTrailingRequiresClause();
 if (RC1 && RC2) {
   bool AtLeastAsConstrained1, AtLeastAsConstrained2;
-  if (S.IsAtLeastAsConstrained(Cand1.Function, {RC1}, Cand2.Function, 
{RC2},
+  if (S.IsAtLeastAsConstrained(Function1, {RC1}, Function2, {RC2},
AtLeastAsConstrained1) ||
-  S.IsAtLeastAsConstrained(Cand2.Function, {RC2}, Cand1.Function, 
{RC1},
+  S.IsAtLeastAsConstrained(Function2, {RC2}, Function1, {RC1},
AtLeastAsConstrained2))
 return false;
   if (AtLeastAsConstrained1 != AtLeastAsConstrained2)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -255,6 +255,8 @@
 - Reject non-type template arguments formed by casting a non-zero integer
   to a pointer in pre-C++17 modes, instead of treating them as null
   pointers.
+- Fix an issue when performing constraints partial ordering on non-template
+  functions.  `Issue 56154 
`_
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/CXX/temp/temp.constr/temp.constr.order/non-template-functions.cpp
===
--- /dev/null
+++ clang/test/CXX/temp/temp.constr/temp.constr.order/non-template-functions.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -std=c++2a -x c++ -verify %s
+// expected-no-diagnostics
+
+namespace PR56154 {
+  template  concept C0 = (N == 0);
+  template  concept C0x = C0;
+  template  concept C00 = C0x && C0;
+
+  template
+  struct A {
+ void f() requires C00;
+ void f() requires C0x;
+  };
+  void h(A<0, 0> a) {
+   a.f();
+  }
+}
Index: clang/test/CXX/over/over.match/over.match.best/p2.cpp
===
--- clang/test/CXX/over/over.match/over.match.best/p2.cpp
+++ clang/test/CXX/over/over.match/over.match.best/p2.cpp
@@ -7,8 +7,7 @@
 bool operator<(const A&) const & requires X; // #1
 int operator<=>(const A&) const & requires X && X = delete; // #2
   };
-  bool k1 = A() < A(); // not ordered by constraints: prefer non-rewritten form
-  bool k2 = A() < 

[PATCH] D136546: [clang][unittest] Resolve ClangSupportTest link time errors

2022-10-22 Thread John McIver via Phabricator via cfe-commits
jmciver added a comment.

Added GitHub issue 58553 , 
which provides the full error message and repeatability information.

If this patch is accepted can someone please commit on my behalf?

- User name: `John McIver`
- User email: `john.mciver@gmail.com`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136546

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