[clang] 3c8ead2 - [clang][dataflow] Eliminate code duplication in Environment::createValueUnlessSelfReferential().

2023-04-06 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-04-06T07:01:44Z
New Revision: 3c8ead2662ac4a223467007c340c9f9a4b2b38af

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

LOG: [clang][dataflow] Eliminate code duplication in 
Environment::createValueUnlessSelfReferential().

Reviewed By: sammccall

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index faeabdcbeed66..ee8f6c5b8f574 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -688,9 +688,9 @@ Value *Environment::createValueUnlessSelfReferential(
 return &create();
   }
 
-  if (Type->isReferenceType()) {
+  if (Type->isReferenceType() || Type->isPointerType()) {
 CreatedValuesCount++;
-QualType PointeeType = Type->castAs()->getPointeeType();
+QualType PointeeType = Type->getPointeeType();
 auto &PointeeLoc = createStorageLocation(PointeeType);
 
 if (Visited.insert(PointeeType.getCanonicalType()).second) {
@@ -702,24 +702,10 @@ Value *Environment::createValueUnlessSelfReferential(
 setValue(PointeeLoc, *PointeeVal);
 }
 
-return &create(PointeeLoc);
-  }
-
-  if (Type->isPointerType()) {
-CreatedValuesCount++;
-QualType PointeeType = Type->castAs()->getPointeeType();
-auto &PointeeLoc = createStorageLocation(PointeeType);
-
-if (Visited.insert(PointeeType.getCanonicalType()).second) {
-  Value *PointeeVal = createValueUnlessSelfReferential(
-  PointeeType, Visited, Depth, CreatedValuesCount);
-  Visited.erase(PointeeType.getCanonicalType());
-
-  if (PointeeVal != nullptr)
-setValue(PointeeLoc, *PointeeVal);
-}
-
-return &create(PointeeLoc);
+if (Type->isReferenceType())
+  return &create(PointeeLoc);
+else
+  return &create(PointeeLoc);
   }
 
   if (Type->isStructureOrClassType() || Type->isUnionType()) {



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


[PATCH] D147601: [clang][dataflow] Eliminate code duplication in Environment::createValueUnlessSelfReferential().

2023-04-06 Thread Martin Böhme 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 rG3c8ead2662ac: [clang][dataflow] Eliminate code duplication 
in Environment… (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147601

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


Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -688,9 +688,9 @@
 return &create();
   }
 
-  if (Type->isReferenceType()) {
+  if (Type->isReferenceType() || Type->isPointerType()) {
 CreatedValuesCount++;
-QualType PointeeType = Type->castAs()->getPointeeType();
+QualType PointeeType = Type->getPointeeType();
 auto &PointeeLoc = createStorageLocation(PointeeType);
 
 if (Visited.insert(PointeeType.getCanonicalType()).second) {
@@ -702,24 +702,10 @@
 setValue(PointeeLoc, *PointeeVal);
 }
 
-return &create(PointeeLoc);
-  }
-
-  if (Type->isPointerType()) {
-CreatedValuesCount++;
-QualType PointeeType = Type->castAs()->getPointeeType();
-auto &PointeeLoc = createStorageLocation(PointeeType);
-
-if (Visited.insert(PointeeType.getCanonicalType()).second) {
-  Value *PointeeVal = createValueUnlessSelfReferential(
-  PointeeType, Visited, Depth, CreatedValuesCount);
-  Visited.erase(PointeeType.getCanonicalType());
-
-  if (PointeeVal != nullptr)
-setValue(PointeeLoc, *PointeeVal);
-}
-
-return &create(PointeeLoc);
+if (Type->isReferenceType())
+  return &create(PointeeLoc);
+else
+  return &create(PointeeLoc);
   }
 
   if (Type->isStructureOrClassType() || Type->isUnionType()) {


Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -688,9 +688,9 @@
 return &create();
   }
 
-  if (Type->isReferenceType()) {
+  if (Type->isReferenceType() || Type->isPointerType()) {
 CreatedValuesCount++;
-QualType PointeeType = Type->castAs()->getPointeeType();
+QualType PointeeType = Type->getPointeeType();
 auto &PointeeLoc = createStorageLocation(PointeeType);
 
 if (Visited.insert(PointeeType.getCanonicalType()).second) {
@@ -702,24 +702,10 @@
 setValue(PointeeLoc, *PointeeVal);
 }
 
-return &create(PointeeLoc);
-  }
-
-  if (Type->isPointerType()) {
-CreatedValuesCount++;
-QualType PointeeType = Type->castAs()->getPointeeType();
-auto &PointeeLoc = createStorageLocation(PointeeType);
-
-if (Visited.insert(PointeeType.getCanonicalType()).second) {
-  Value *PointeeVal = createValueUnlessSelfReferential(
-  PointeeType, Visited, Depth, CreatedValuesCount);
-  Visited.erase(PointeeType.getCanonicalType());
-
-  if (PointeeVal != nullptr)
-setValue(PointeeLoc, *PointeeVal);
-}
-
-return &create(PointeeLoc);
+if (Type->isReferenceType())
+  return &create(PointeeLoc);
+else
+  return &create(PointeeLoc);
   }
 
   if (Type->isStructureOrClassType() || Type->isUnionType()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 616c806 - [C++20] [Coroutines] Handle function-try-block in SemaCoroutine

2023-04-06 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-04-06T15:11:34+08:00
New Revision: 616c8067071316a9e17524b14b3ab0e04a511e71

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

LOG: [C++20] [Coroutines] Handle function-try-block in SemaCoroutine

In https://reviews.llvm.org/D146758, we handled the rare case that the
coroutine has a function-try-block. But it will be better to handle it
in the Sema part. This patch handles the preprocess.

Added: 


Modified: 
clang/include/clang/AST/StmtCXX.h
clang/lib/CodeGen/CGCoroutine.cpp
clang/lib/Sema/SemaCoroutine.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Removed: 




diff  --git a/clang/include/clang/AST/StmtCXX.h 
b/clang/include/clang/AST/StmtCXX.h
index 288ffc28f40ee..60fc3f3a63f49 100644
--- a/clang/include/clang/AST/StmtCXX.h
+++ b/clang/include/clang/AST/StmtCXX.h
@@ -375,9 +375,10 @@ class CoroutineBodyStmt final
   }
 
   /// Retrieve the body of the coroutine as written. This will be either
-  /// a CompoundStmt or a TryStmt.
-  Stmt *getBody() const {
-return getStoredStmts()[SubStmt::Body];
+  /// a CompoundStmt. If the coroutine is in function-try-block, we will
+  /// wrap the CXXTryStmt into a CompoundStmt to keep consistency.
+  CompoundStmt *getBody() const {
+return cast(getStoredStmts()[SubStmt::Body]);
   }
 
   Stmt *getPromiseDeclStmt() const {

diff  --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 90ab82ed88a11..da3da5e600104 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -593,18 +593,6 @@ static void emitBodyAndFallthrough(CodeGenFunction &CGF,
   CGF.EmitStmt(OnFallthrough);
 }
 
-static CompoundStmt *CoroutineStmtBuilder(ASTContext &Context,
-  const CoroutineBodyStmt &S) {
-  Stmt *Stmt = S.getBody();
-  if (CompoundStmt *Body = dyn_cast(Stmt))
-return Body;
-  // We are about to create a `CXXTryStmt` which requires a `CompoundStmt`.
-  // If the function body is not a `CompoundStmt` yet then we have to create
-  // a new one. This happens for cases like the "function-try-block" syntax.
-  return CompoundStmt::Create(Context, {Stmt}, FPOptionsOverride(),
-  SourceLocation(), SourceLocation());
-}
-
 void CodeGenFunction::EmitCoroutineBody(const CoroutineBodyStmt &S) {
   auto *NullPtr = llvm::ConstantPointerNull::get(Builder.getInt8PtrTy());
   auto &TI = CGM.getContext().getTargetInfo();
@@ -733,8 +721,8 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt &S) {
   auto Loc = S.getBeginLoc();
   CXXCatchStmt Catch(Loc, /*exDecl=*/nullptr,
  CurCoro.Data->ExceptionHandler);
-  CompoundStmt *Body = CoroutineStmtBuilder(getContext(), S);
-  auto *TryStmt = CXXTryStmt::Create(getContext(), Loc, Body, &Catch);
+  auto *TryStmt =
+  CXXTryStmt::Create(getContext(), Loc, S.getBody(), &Catch);
 
   EnterCXXTryStmt(*TryStmt);
   emitBodyAndFallthrough(*this, S, TryStmt->getTryBlock());

diff  --git a/clang/lib/Sema/SemaCoroutine.cpp 
b/clang/lib/Sema/SemaCoroutine.cpp
index e87f2a78e2394..deb67337a2aec 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -1137,6 +1137,18 @@ void Sema::CheckCompletedCoroutineBody(FunctionDecl *FD, 
Stmt *&Body) {
   Body = CoroutineBodyStmt::Create(Context, Builder);
 }
 
+static CompoundStmt *buildCoroutineBody(Stmt *Body, ASTContext &Context) {
+  if (auto *CS = dyn_cast(Body))
+return CS;
+
+  // The body of the coroutine may be a try statement if it is in
+  // 'function-try-block' syntax. Here we wrap it into a compound
+  // statement for consistency.
+  assert(isa(Body) && "Unimaged coroutine body type");
+  return CompoundStmt::Create(Context, {Body}, FPOptionsOverride(),
+  SourceLocation(), SourceLocation());
+}
+
 CoroutineStmtBuilder::CoroutineStmtBuilder(Sema &S, FunctionDecl &FD,
sema::FunctionScopeInfo &Fn,
Stmt *Body)
@@ -1144,7 +1156,7 @@ CoroutineStmtBuilder::CoroutineStmtBuilder(Sema &S, 
FunctionDecl &FD,
   IsPromiseDependentType(
   !Fn.CoroutinePromise ||
   Fn.CoroutinePromise->getType()->isDependentType()) {
-  this->Body = Body;
+  this->Body = buildCoroutineBody(Body, S.getASTContext());
 
   for (auto KV : Fn.CoroutineParameterMoves)
 this->ParamMovesVector.push_back(KV.second);

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index e6d2bb46dfcd3..89954711804aa 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTM

[PATCH] D147684: [clangd] Add batch fixes for include-cleaner diagnostics

2023-04-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added subscribers: arphaman, mgrang.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

For each unused-include/missing-include diagnostic, we provide fix-all
alternative to them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147684

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -44,8 +44,8 @@
 using ::testing::Pointee;
 using ::testing::UnorderedElementsAre;
 
-Matcher withFix(::testing::Matcher FixMatcher) {
-  return Field(&Diag::Fixes, ElementsAre(FixMatcher));
+Matcher withFix(std::vector<::testing::Matcher> FixMatcheres) {
+  return Field(&Diag::Fixes, testing::UnorderedElementsAreArray(FixMatcheres));
 }
 
 MATCHER_P2(Diag, Range, Message,
@@ -59,6 +59,8 @@
   return arg.Message == Message && arg.Edits.size() == 1 &&
  arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement;
 }
+MATCHER_P(FixMessage, Message, "") { return arg.Message == Message; }
+
 
 std::string guard(llvm::StringRef Code) {
   return "#pragma once\n" + Code.str();
@@ -254,42 +256,69 @@
   UnorderedElementsAre(
   AllOf(Diag(MainFile.range("b"),
  "No header providing \"b\" is directly included"),
-withFix(Fix(MainFile.range("insert_b"), "#include \"b.h\"\n",
-"#include \"b.h\""))),
+withFix({Fix(MainFile.range("insert_b"), "#include \"b.h\"\n",
+ "#include \"b.h\""),
+ FixMessage("add all missing #includes"),
+ FixMessage("add all missing #includes and remove all "
+"unused ones")})),
   AllOf(Diag(MainFile.range("bar"),
  "No header providing \"ns::Bar\" is directly included"),
-withFix(Fix(MainFile.range("insert_d"),
-"#include \"dir/d.h\"\n", "#include \"dir/d.h\""))),
+withFix({Fix(MainFile.range("insert_d"),
+ "#include \"dir/d.h\"\n", "#include \"dir/d.h\""),
+ FixMessage("add all missing #includes"),
+ FixMessage("add all missing #includes and remove all "
+"unused ones")})),
   AllOf(Diag(MainFile.range("f"),
  "No header providing \"f\" is directly included"),
-withFix(Fix(MainFile.range("insert_f"), "#include \n",
-"#include "))),
+withFix({Fix(MainFile.range("insert_f"), "#include \n",
+ "#include "),
+ FixMessage("add all missing #includes"),
+ FixMessage("add all missing #includes and remove all "
+"unused ones")})),
   AllOf(
   Diag(MainFile.range("foobar"),
"No header providing \"foobar\" is directly included"),
-  withFix(Fix(MainFile.range("insert_foobar"),
-  "#include \"public.h\"\n", "#include \"public.h\""))),
+  withFix({Fix(MainFile.range("insert_foobar"),
+   "#include \"public.h\"\n", "#include \"public.h\""),
+   FixMessage("add all missing #includes"),
+   FixMessage("add all missing #includes and remove all "
+  "unused ones")})),
   AllOf(
   Diag(MainFile.range("vector"),
"No header providing \"std::vector\" is directly included"),
-  withFix(Fix(MainFile.range("insert_vector"),
-  "#include \n", "#include "))),
+  withFix({Fix(MainFile.range("insert_vector"),
+   "#include \n", "#include "),
+   FixMessage("add all missing #includes"),
+   FixMessage("add all missing #includes and remove all "
+  "unused ones")})),
   AllOf(Diag(MainFile.range("FOO"),
  "No header providing \"FOO\" is directly included"),
-withFix(Fix(MainFile.range("insert_foo"),
-"#include \"foo.h\"\n", "#include \"foo.h\""))),
+withFix({Fix(MainFile.range("insert_foo"),
+ "#include \"foo.h\"\n", "#include \"foo.h\""),
+ FixMessage("ad

[PATCH] D147684: [clangd] Add batch fixes for include-cleaner diagnostics

2023-04-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

The UI in VSCode looks like

- unused-include:

F27034770: image.png 

- missing-include:

F27034749: image.png 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147684

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


[PATCH] D141824: [clang-repl] Add a command to load dynamic libraries

2023-04-06 Thread Han Zhu via Phabricator via cfe-commits
zhuhan0 added subscribers: ayermolo, zhuhan0.
zhuhan0 added a comment.

Hi @argentite, we build llvm in a custom distro which is missing some C startup 
code, and this fails with errors like:

  /abc/bin/ld: cannot find crti.o: No such file or directory
  /abc/bin/ld: cannot find crtbeginS.o: No such file or directory
  /abc/bin/ld: cannot find -lgcc
  /abc/bin/ld: cannot find -lgcc_s
  /abc/bin/ld: cannot find -lc
  /abc/bin/ld: cannot find -lgcc
  /abc/bin/ld: cannot find -lgcc_s
  /abc/bin/ld: cannot find crtendS.o: No such file or directory
  /abc/bin/ld: cannot find crtn.o: No such file or directory

This seems to be the first clang test that involves actual linking. If the 
intention is to test loading a dynamic library, could you commit the library in 
the Inputs directory instead of building it from source?
cc @ayermolo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141824

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


[PATCH] D147603: [clang][dataflow] Use `isRecordType()` where appropriate.

2023-04-06 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added a comment.

Failing CodeGen test in premerge check appears to be a pre-existing failure. 
(I'm not touching anything related to CodeGen here.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147603

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


[clang] effdfa7 - [clang][dataflow] Use `isRecordType()` where appropriate.

2023-04-06 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-04-06T07:26:24Z
New Revision: effdfa7d5f49b00b4c0d36f7c6835b519b0f46bb

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

LOG: [clang][dataflow] Use `isRecordType()` where appropriate.

This is less verbose than checking for class, struct, and union individually,
and I believe it's also more efficient (not that that should be the overriding
concern).

Reviewed By: sammccall, xazax.hun

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
index 4d8a42c1390c2..1fbc3759747e8 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -45,8 +45,7 @@ DataflowAnalysisContext::getReferencedFields(QualType Type) {
 }
 
 StorageLocation &DataflowAnalysisContext::createStorageLocation(QualType Type) 
{
-  if (!Type.isNull() &&
-  (Type->isStructureOrClassType() || Type->isUnionType())) {
+  if (!Type.isNull() && Type->isRecordType()) {
 llvm::DenseMap FieldLocs;
 // During context-sensitive analysis, a struct may be allocated in one
 // function, but its field accessed in a function lower in the stack than

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index ee8f6c5b8f574..6a6343b5f169b 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -608,7 +608,7 @@ void Environment::setValue(const StorageLocation &Loc, 
Value &Val) {
 auto &AggregateLoc = *cast(&Loc);
 
 const QualType Type = AggregateLoc.getType();
-assert(Type->isStructureOrClassType() || Type->isUnionType());
+assert(Type->isRecordType());
 
 for (const FieldDecl *Field : DACtx->getReferencedFields(Type)) {
   assert(Field != nullptr);
@@ -708,7 +708,7 @@ Value *Environment::createValueUnlessSelfReferential(
   return &create(PointeeLoc);
   }
 
-  if (Type->isStructureOrClassType() || Type->isUnionType()) {
+  if (Type->isRecordType()) {
 CreatedValuesCount++;
 llvm::DenseMap FieldValues;
 for (const FieldDecl *Field : DACtx->getReferencedFields(Type)) {



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


[PATCH] D147603: [clang][dataflow] Use `isRecordType()` where appropriate.

2023-04-06 Thread Martin Böhme 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 rGeffdfa7d5f49: [clang][dataflow] Use `isRecordType()` where 
appropriate. (authored by mboehme).

Changed prior to commit:
  https://reviews.llvm.org/D147603?vs=511062&id=511298#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147603

Files:
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp


Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -608,7 +608,7 @@
 auto &AggregateLoc = *cast(&Loc);
 
 const QualType Type = AggregateLoc.getType();
-assert(Type->isStructureOrClassType() || Type->isUnionType());
+assert(Type->isRecordType());
 
 for (const FieldDecl *Field : DACtx->getReferencedFields(Type)) {
   assert(Field != nullptr);
@@ -708,7 +708,7 @@
   return &create(PointeeLoc);
   }
 
-  if (Type->isStructureOrClassType() || Type->isUnionType()) {
+  if (Type->isRecordType()) {
 CreatedValuesCount++;
 llvm::DenseMap FieldValues;
 for (const FieldDecl *Field : DACtx->getReferencedFields(Type)) {
Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -45,8 +45,7 @@
 }
 
 StorageLocation &DataflowAnalysisContext::createStorageLocation(QualType Type) 
{
-  if (!Type.isNull() &&
-  (Type->isStructureOrClassType() || Type->isUnionType())) {
+  if (!Type.isNull() && Type->isRecordType()) {
 llvm::DenseMap FieldLocs;
 // During context-sensitive analysis, a struct may be allocated in one
 // function, but its field accessed in a function lower in the stack than


Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -608,7 +608,7 @@
 auto &AggregateLoc = *cast(&Loc);
 
 const QualType Type = AggregateLoc.getType();
-assert(Type->isStructureOrClassType() || Type->isUnionType());
+assert(Type->isRecordType());
 
 for (const FieldDecl *Field : DACtx->getReferencedFields(Type)) {
   assert(Field != nullptr);
@@ -708,7 +708,7 @@
   return &create(PointeeLoc);
   }
 
-  if (Type->isStructureOrClassType() || Type->isUnionType()) {
+  if (Type->isRecordType()) {
 CreatedValuesCount++;
 llvm::DenseMap FieldValues;
 for (const FieldDecl *Field : DACtx->getReferencedFields(Type)) {
Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -45,8 +45,7 @@
 }
 
 StorageLocation &DataflowAnalysisContext::createStorageLocation(QualType Type) {
-  if (!Type.isNull() &&
-  (Type->isStructureOrClassType() || Type->isUnionType())) {
+  if (!Type.isNull() && Type->isRecordType()) {
 llvm::DenseMap FieldLocs;
 // During context-sensitive analysis, a struct may be allocated in one
 // function, but its field accessed in a function lower in the stack than
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 92417f2 - [clang][Interp] Record initialization via conditional operator

2023-04-06 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-06T09:44:02+02:00
New Revision: 92417f2d4b1706326717cc5e782f3aa77a7157bb

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

LOG: [clang][Interp] Record initialization via conditional operator

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/AST/Interp/constexpr-nqueens.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e620b4f9b2f63..2f9f99cc06489 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -560,32 +560,8 @@ bool ByteCodeExprGen::VisitOpaqueValueExpr(const 
OpaqueValueExpr *E) {
 template 
 bool ByteCodeExprGen::VisitAbstractConditionalOperator(
 const AbstractConditionalOperator *E) {
-  const Expr *Condition = E->getCond();
-  const Expr *TrueExpr = E->getTrueExpr();
-  const Expr *FalseExpr = E->getFalseExpr();
-
-  LabelTy LabelEnd = this->getLabel();   // Label after the operator.
-  LabelTy LabelFalse = this->getLabel(); // Label for the false expr.
-
-  if (!this->visit(Condition))
-return false;
-  if (!this->jumpFalse(LabelFalse))
-return false;
-
-  if (!this->visit(TrueExpr))
-return false;
-  if (!this->jump(LabelEnd))
-return false;
-
-  this->emitLabel(LabelFalse);
-
-  if (!this->visit(FalseExpr))
-return false;
-
-  this->fallthrough(LabelEnd);
-  this->emitLabel(LabelEnd);
-
-  return true;
+  return this->visitConditional(
+  E, [this](const Expr *E) { return this->visit(E); });
 }
 
 template 
@@ -921,6 +897,41 @@ bool ByteCodeExprGen::visitBool(const Expr *E) {
   }
 }
 
+/// Visit a conditional operator, i.e. `A ? B : C`.
+/// \V determines what function to call for the B and C expressions.
+template 
+bool ByteCodeExprGen::visitConditional(
+const AbstractConditionalOperator *E,
+llvm::function_ref V) {
+
+  const Expr *Condition = E->getCond();
+  const Expr *TrueExpr = E->getTrueExpr();
+  const Expr *FalseExpr = E->getFalseExpr();
+
+  LabelTy LabelEnd = this->getLabel();   // Label after the operator.
+  LabelTy LabelFalse = this->getLabel(); // Label for the false expr.
+
+  if (!this->visit(Condition))
+return false;
+  if (!this->jumpFalse(LabelFalse))
+return false;
+
+  if (!V(TrueExpr))
+return false;
+  if (!this->jump(LabelEnd))
+return false;
+
+  this->emitLabel(LabelFalse);
+
+  if (!V(FalseExpr))
+return false;
+
+  this->fallthrough(LabelEnd);
+  this->emitLabel(LabelEnd);
+
+  return true;
+}
+
 template 
 bool ByteCodeExprGen::visitZeroInitializer(PrimType T, const Expr *E) 
{
   switch (T) {
@@ -1429,6 +1440,10 @@ bool 
ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) {
 return this->visitInitializer(CE->getSubExpr());
   } else if (const auto *CE = dyn_cast(Initializer)) {
 return this->visitInitializer(CE->getSubExpr());
+  } else if (const auto *ACO =
+ dyn_cast(Initializer)) {
+return this->visitConditional(
+ACO, [this](const Expr *E) { return this->visitRecordInitializer(E); 
});
   }
 
   return false;

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 46a926bfb5f01..85588c6ecd3c1 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -181,6 +181,9 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 return this->emitPopPtr(I);
   }
 
+  bool visitConditional(const AbstractConditionalOperator *E,
+llvm::function_ref V);
+
   /// Creates a local primitive value.
   unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsMutable,
   bool IsExtended = false);

diff  --git a/clang/test/AST/Interp/constexpr-nqueens.cpp 
b/clang/test/AST/Interp/constexpr-nqueens.cpp
index 5aeb7afcd79ce..c71092af069bb 100644
--- a/clang/test/AST/Interp/constexpr-nqueens.cpp
+++ b/clang/test/AST/Interp/constexpr-nqueens.cpp
@@ -17,7 +17,8 @@ struct Board {
   constexpr Board(uint64_t State, bool Failed = false) :
 Failed(Failed) {}
   constexpr Board addQueen(int Row, int Col) const {
-return Board(State | ((uint64_t)Row << (Col * 4))); // ref-note {{read of 
uninitialized object}}
+return Board(State | ((uint64_t)Row << (Col * 4))); // ref-note {{read of 
uninitialized object}} \
+// expected-note 
{{read of object outside its lifetime}}
   }
   constexpr int getQueenRow(int Col) const {
 return (State >> (Col * 4)) & 0xf;
@@ -47,17 +48,22 @@ constexpr Board tryBoard(const Board 

[PATCH] D141497: [clang][Interp] Record initialization via conditional operator

2023-04-06 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG92417f2d4b17: [clang][Interp] Record initialization via 
conditional operator (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141497

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/constexpr-nqueens.cpp
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -368,3 +368,14 @@
   constexpr piecewise_construct_t piecewise_construct =
 piecewise_construct_t();
 };
+
+namespace ConditionalInit {
+  struct S { int a; };
+
+  constexpr S getS(bool b) {
+return b ? S{12} : S{13};
+  }
+
+  static_assert(getS(true).a == 12, "");
+  static_assert(getS(false).a == 13, "");
+};
Index: clang/test/AST/Interp/constexpr-nqueens.cpp
===
--- clang/test/AST/Interp/constexpr-nqueens.cpp
+++ clang/test/AST/Interp/constexpr-nqueens.cpp
@@ -17,7 +17,8 @@
   constexpr Board(uint64_t State, bool Failed = false) :
 Failed(Failed) {}
   constexpr Board addQueen(int Row, int Col) const {
-return Board(State | ((uint64_t)Row << (Col * 4))); // ref-note {{read of uninitialized object}}
+return Board(State | ((uint64_t)Row << (Col * 4))); // ref-note {{read of uninitialized object}} \
+// expected-note {{read of object outside its lifetime}}
   }
   constexpr int getQueenRow(int Col) const {
 return (State >> (Col * 4)) & 0xf;
@@ -47,17 +48,22 @@
 constexpr Board buildBoardScan(int N, int Col, int Row, const Board &B) {
   return Row == N ? Board(0, true) :
  B.ok(Row, Col) ?
- tryBoard(buildBoardRecurse(N, Col + 1, B.addQueen(Row, Col)), // ref-note {{in call to '&Board()->addQueen(0, 0)}}
+ tryBoard(buildBoardRecurse(N, Col + 1, B.addQueen(Row, Col)), // ref-note {{in call to '&Board()->addQueen(0, 0)}} \
+   // expected-note {{in call to '&Board()->addQueen(0, 0)}}
   N, Col, Row+1, B) :
  buildBoardScan(N, Col, Row + 1, B);
 }
 constexpr Board buildBoardRecurse(int N, int Col, const Board &B) {
-  return Col == N ? B : buildBoardScan(N, Col, 0, B); // ref-note {{in call to 'buildBoardScan(8, 0, 0, Board())'}}
+  return Col == N ? B : buildBoardScan(N, Col, 0, B); // ref-note {{in call to 'buildBoardScan(8, 0, 0, Board())'}} \
+  // expected-note {{in call to 'buildBoardScan(8, 0, 0, Board())'}}
+
 }
 constexpr Board buildBoard(int N) {
-  return buildBoardRecurse(N, 0, Board()); // ref-note {{in call to 'buildBoardRecurse(8, 0, Board())'}}
+  return buildBoardRecurse(N, 0, Board()); // ref-note {{in call to 'buildBoardRecurse(8, 0, Board())'}} \
+   // expected-note {{in call to 'buildBoardRecurse(8, 0, Board())'}}
 }
 
 constexpr Board q8 = buildBoard(8); // ref-error {{must be initialized by a constant expression}} \
 // ref-note {{in call to 'buildBoard(8)'}} \
-// expected-error {{must be initialized by a constant expression}}
+// expected-error {{must be initialized by a constant expression}} \
+// expected-note {{in call to 'buildBoard(8)'}}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -181,6 +181,9 @@
 return this->emitPopPtr(I);
   }
 
+  bool visitConditional(const AbstractConditionalOperator *E,
+llvm::function_ref V);
+
   /// Creates a local primitive value.
   unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsMutable,
   bool IsExtended = false);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -560,32 +560,8 @@
 template 
 bool ByteCodeExprGen::VisitAbstractConditionalOperator(
 const AbstractConditionalOperator *E) {
-  const Expr *Condition = E->getCond();
-  const Expr *TrueExpr = E->getTrueExpr();
-  const Expr *FalseExpr = E->getFalseExpr();
-
-  LabelTy LabelEnd = this->getLabel();   // Label after the operator.
-  LabelTy LabelFalse = this->getLabel(); // Label for the false expr.
-
-  if (!this->visit(Condition))
-return false;
-  if (!this->jumpFalse(LabelFalse))
-return false;
-
-  if (!this->

[libunwind] a017aef - [libunwind] Fix a typo in a debug log message. NFC.

2023-04-06 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2023-04-06T11:07:41+03:00
New Revision: a017aefeac9c7128b5fd702098381abc09508e45

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

LOG: [libunwind] Fix a typo in a debug log message. NFC.

This typo (unw_step instead of unw_get_proc_info) has been around since
the initial public commit of libunwind.

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

Added: 


Modified: 
libunwind/src/Unwind-EHABI.cpp
libunwind/src/Unwind-seh.cpp
libunwind/src/UnwindLevel1.c

Removed: 




diff  --git a/libunwind/src/Unwind-EHABI.cpp b/libunwind/src/Unwind-EHABI.cpp
index 95701823bc097..f387c5d3db4e6 100644
--- a/libunwind/src/Unwind-EHABI.cpp
+++ b/libunwind/src/Unwind-EHABI.cpp
@@ -709,7 +709,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t 
*cursor,
 // Update info about this frame.
 unw_proc_info_t frameInfo;
 if (__unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) {
-  _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): __unw_step "
+  _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): 
__unw_get_proc_info "
  "failed => _URC_END_OF_STACK",
  (void *)exception_object);
   return _URC_FATAL_PHASE2_ERROR;

diff  --git a/libunwind/src/Unwind-seh.cpp b/libunwind/src/Unwind-seh.cpp
index d08c29c21383b..5c87975cffb30 100644
--- a/libunwind/src/Unwind-seh.cpp
+++ b/libunwind/src/Unwind-seh.cpp
@@ -238,7 +238,7 @@ unwind_phase2_forced(unw_context_t *uc,
 // Update info about this frame.
 unw_proc_info_t frameInfo;
 if (__unw_get_proc_info(&cursor2, &frameInfo) != UNW_ESUCCESS) {
-  _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): __unw_step "
+  _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): 
__unw_get_proc_info "
  "failed => _URC_END_OF_STACK",
  (void *)exception_object);
   return _URC_FATAL_PHASE2_ERROR;

diff  --git a/libunwind/src/UnwindLevel1.c b/libunwind/src/UnwindLevel1.c
index 7e9adf64246df..05d0f2cb0a0a7 100644
--- a/libunwind/src/UnwindLevel1.c
+++ b/libunwind/src/UnwindLevel1.c
@@ -321,7 +321,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t 
*cursor,
 unw_proc_info_t frameInfo;
 if (__unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) {
   _LIBUNWIND_TRACE_UNWINDING(
-  "unwind_phase2_forced(ex_obj=%p): __unw_step_stage2 "
+  "unwind_phase2_forced(ex_obj=%p): __unw_get_proc_info "
   "failed => _URC_END_OF_STACK",
   (void *)exception_object);
   return _URC_FATAL_PHASE2_ERROR;



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


[libunwind] 16857c4 - [libcxxabi, libunwind] [test] Quote the python path properly for LIB*_EXECUTOR

2023-04-06 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2023-04-06T11:07:41+03:00
New Revision: 16857c4a30da502297ad3ac731ae3fb1a9e5d611

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

LOG: [libcxxabi, libunwind] [test] Quote the python path properly for 
LIB*_EXECUTOR

This is the same as c218c80c730a14a1cbcebd588b18220a879702c6,
but for libcxxabi and libunwind.

This fixes running tests on Windows with Python installed in
e.g. "C:\Program Files\Python38".

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

Added: 


Modified: 
libcxxabi/test/CMakeLists.txt
libunwind/test/CMakeLists.txt

Removed: 




diff  --git a/libcxxabi/test/CMakeLists.txt b/libcxxabi/test/CMakeLists.txt
index 5da584a2c9cf3..d639292d7a7e3 100644
--- a/libcxxabi/test/CMakeLists.txt
+++ b/libcxxabi/test/CMakeLists.txt
@@ -8,7 +8,7 @@ macro(pythonize_bool var)
 endmacro()
 
 pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
-set(LIBCXXABI_EXECUTOR "${Python3_EXECUTABLE} 
${LIBCXXABI_LIBCXX_PATH}/utils/run.py" CACHE STRING
+set(LIBCXXABI_EXECUTOR "\\\"${Python3_EXECUTABLE}\\\" 
${LIBCXXABI_LIBCXX_PATH}/utils/run.py" CACHE STRING
 "Executor to use when running tests.")
 
 if (LIBCXXABI_ENABLE_SHARED)

diff  --git a/libunwind/test/CMakeLists.txt b/libunwind/test/CMakeLists.txt
index 0a09553e692da..e6bd526904425 100644
--- a/libunwind/test/CMakeLists.txt
+++ b/libunwind/test/CMakeLists.txt
@@ -10,7 +10,7 @@ endmacro()
 pythonize_bool(LIBUNWIND_ENABLE_CET)
 pythonize_bool(LIBUNWIND_ENABLE_THREADS)
 pythonize_bool(LIBUNWIND_USES_ARM_EHABI)
-set(LIBUNWIND_EXECUTOR "${Python3_EXECUTABLE} 
${LIBUNWIND_LIBCXX_PATH}/utils/run.py" CACHE STRING
+set(LIBUNWIND_EXECUTOR "\\\"${Python3_EXECUTABLE}\\\" 
${LIBUNWIND_LIBCXX_PATH}/utils/run.py" CACHE STRING
 "Executor to use when running tests.")
 
 set(AUTO_GEN_COMMENT "## Autogenerated by libunwind configuration.\n# Do not 
edit!")



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


[libunwind] a33d5a9 - [libunwind] Fflush stderr after each log message

2023-04-06 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2023-04-06T11:07:41+03:00
New Revision: a33d5a9939aa3c0bcdb0f951c0bc4b96071bda2c

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

LOG: [libunwind] Fflush stderr after each log message

In most configs, stderr is line buffered by default, but in some
cases on Windows (running in git bash, or running in Wine) stderr
can end up fully buffered.

See 2ec75a0869ab01fa9caf310e8a31eb7716182d30 for a similar change
for the output from lit itself.

This has no effect on libunwind when the log messages aren't enabled
via the environment variables.

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

Added: 


Modified: 
libunwind/src/config.h

Removed: 




diff  --git a/libunwind/src/config.h b/libunwind/src/config.h
index 4bbac951624f9..6707d591361df 100644
--- a/libunwind/src/config.h
+++ b/libunwind/src/config.h
@@ -162,10 +162,14 @@
 #define _LIBUNWIND_LOG0(msg)
 #define _LIBUNWIND_LOG(msg, ...)
 #else
-#define _LIBUNWIND_LOG0(msg)   \
-  fprintf(stderr, "libunwind: " msg "\n")
-#define _LIBUNWIND_LOG(msg, ...)   
\
-  fprintf(stderr, "libunwind: " msg "\n", __VA_ARGS__)
+#define _LIBUNWIND_LOG0(msg) do {  
\
+fprintf(stderr, "libunwind: " msg "\n");   
\
+fflush(stderr);
\
+  } while (0)
+#define _LIBUNWIND_LOG(msg, ...) do {  
\
+fprintf(stderr, "libunwind: " msg "\n", __VA_ARGS__);  
\
+fflush(stderr);
\
+  } while (0)
 #endif
 
 #if defined(NDEBUG)



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


[libunwind] b25e989 - [libunwind] [test] Add a mingw specific test config file

2023-04-06 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2023-04-06T11:07:41+03:00
New Revision: b25e989e68372ab604e6da1934e51344880db87c

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

LOG: [libunwind] [test] Add a mingw specific test config file

This matches how it is done for libcxx and libcxxabi.

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

Added: 
libunwind/test/configs/llvm-libunwind-mingw.cfg.in

Modified: 
libunwind/CMakeLists.txt

Removed: 




diff  --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 647b1c41955b5..6f12a160307d1 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -67,7 +67,9 @@ if(LIBUNWIND_SYSROOT OR LIBUNWIND_TARGET_TRIPLE OR 
LIBUNWIND_GCC_TOOLCHAIN)
   message(WARNING "LIBUNWIND_SYSROOT, LIBUNWIND_TARGET_TRIPLE and 
LIBUNWIND_GCC_TOOLCHAIN are not supported anymore, please use the native CMake 
equivalents instead")
 endif()
 
-if (LIBUNWIND_ENABLE_SHARED)
+if(MINGW)
+  set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-mingw.cfg.in")
+elseif (LIBUNWIND_ENABLE_SHARED)
   set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-shared.cfg.in")
 else()
   set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-static.cfg.in")

diff  --git a/libunwind/test/configs/llvm-libunwind-mingw.cfg.in 
b/libunwind/test/configs/llvm-libunwind-mingw.cfg.in
new file mode 100644
index 0..99d0aac9015ca
--- /dev/null
+++ b/libunwind/test/configs/llvm-libunwind-mingw.cfg.in
@@ -0,0 +1,25 @@
+# This testing configuration handles running the test suite against LLVM's 
libunwind
+# using either a DLL or a static library, with MinGW/Clang on Windows.
+
+lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
+
+config.substitutions.append(('%{flags}', ''))
+config.substitutions.append(('%{compile_flags}',
+'-nostdinc++ -I %{include} -funwind-tables'
+))
+config.substitutions.append(('%{link_flags}',
+'-L %{lib} -lunwind'
+))
+config.substitutions.append(('%{exec}',
+'%{executor} --execdir %T --env PATH=%{lib} -- '
+))
+
+import os, site
+site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils'))
+import libcxx.test.params, libcxx.test.config
+libcxx.test.config.configure(
+libcxx.test.params.DEFAULT_PARAMETERS,
+libcxx.test.features.DEFAULT_FEATURES,
+config,
+lit_config
+)



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


[PATCH] D147686: [clangd] Fix a nullptr-dereference crash in computeIncludeCleanerFindings.

2023-04-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Be more robust, we shuold not crash  when we cannot find the corresponding 
token from the
tokenbuffer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147686

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -442,6 +442,22 @@
   EXPECT_EQ(RefRange, Findings[1].SymRefRange);
 }
 
+TEST(IncludeCleaner, NoCrash) {
+  TestTU TU;
+  TU.Code = R"cpp(
+#include "all.h"
+void test() {
+  1s;
+}
+)cpp";
+  TU.AdditionalFiles["foo.h"] =
+  guard("int operator\"\"s(unsigned long long) { return 0; }");
+  TU.AdditionalFiles["all.h"] = guard("#include \"foo.h\"");
+  ParsedAST AST = TU.build();
+  auto Findings = computeIncludeCleanerFindings(AST);
+  EXPECT_THAT(Findings.MissingIncludes, IsEmpty());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -405,10 +405,12 @@
 // through an #include.
 while (SM.getFileID(Loc) != SM.getMainFileID())
   Loc = SM.getIncludeLoc(SM.getFileID(Loc));
-const auto *Token = AST.getTokens().spelledTokenAt(Loc);
-MissingIncludeDiagInfo DiagInfo{Ref.Target, Token->range(SM),
-Providers};
-MissingIncludes.push_back(std::move(DiagInfo));
+
+if (const auto *Token = AST.getTokens().spelledTokenAt(Loc)) {
+  MissingIncludeDiagInfo DiagInfo{Ref.Target, Token->range(SM),
+  Providers};
+  MissingIncludes.push_back(std::move(DiagInfo));
+}
   });
   std::vector UnusedIncludes =
   getUnused(AST, Used, /*ReferencedPublicHeaders*/ {});


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -442,6 +442,22 @@
   EXPECT_EQ(RefRange, Findings[1].SymRefRange);
 }
 
+TEST(IncludeCleaner, NoCrash) {
+  TestTU TU;
+  TU.Code = R"cpp(
+#include "all.h"
+void test() {
+  1s;
+}
+)cpp";
+  TU.AdditionalFiles["foo.h"] =
+  guard("int operator\"\"s(unsigned long long) { return 0; }");
+  TU.AdditionalFiles["all.h"] = guard("#include \"foo.h\"");
+  ParsedAST AST = TU.build();
+  auto Findings = computeIncludeCleanerFindings(AST);
+  EXPECT_THAT(Findings.MissingIncludes, IsEmpty());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -405,10 +405,12 @@
 // through an #include.
 while (SM.getFileID(Loc) != SM.getMainFileID())
   Loc = SM.getIncludeLoc(SM.getFileID(Loc));
-const auto *Token = AST.getTokens().spelledTokenAt(Loc);
-MissingIncludeDiagInfo DiagInfo{Ref.Target, Token->range(SM),
-Providers};
-MissingIncludes.push_back(std::move(DiagInfo));
+
+if (const auto *Token = AST.getTokens().spelledTokenAt(Loc)) {
+  MissingIncludeDiagInfo DiagInfo{Ref.Target, Token->range(SM),
+  Providers};
+  MissingIncludes.push_back(std::move(DiagInfo));
+}
   });
   std::vector UnusedIncludes =
   getUnused(AST, Used, /*ReferencedPublicHeaders*/ {});
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147686: [clangd] Fix a nullptr-dereference crash in computeIncludeCleanerFindings.

2023-04-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 511319.
hokein added a comment.

add a comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147686

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -442,6 +442,23 @@
   EXPECT_EQ(RefRange, Findings[1].SymRefRange);
 }
 
+TEST(IncludeCleaner, NoCrash) {
+  TestTU TU;
+  TU.Code = R"cpp(
+#include "all.h"
+void test() {
+  1s;
+}
+)cpp";
+  TU.AdditionalFiles["foo.h"] =
+  guard("int operator\"\"s(unsigned long long) { return 0; }");
+  TU.AdditionalFiles["all.h"] = guard("#include \"foo.h\"");
+  ParsedAST AST = TU.build();
+  auto Findings = computeIncludeCleanerFindings(AST);
+  // FIXME: this is not ideal, but at least we don't crash.
+  EXPECT_THAT(Findings.MissingIncludes, IsEmpty());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -405,10 +405,12 @@
 // through an #include.
 while (SM.getFileID(Loc) != SM.getMainFileID())
   Loc = SM.getIncludeLoc(SM.getFileID(Loc));
-const auto *Token = AST.getTokens().spelledTokenAt(Loc);
-MissingIncludeDiagInfo DiagInfo{Ref.Target, Token->range(SM),
-Providers};
-MissingIncludes.push_back(std::move(DiagInfo));
+
+if (const auto *Token = AST.getTokens().spelledTokenAt(Loc)) {
+  MissingIncludeDiagInfo DiagInfo{Ref.Target, Token->range(SM),
+  Providers};
+  MissingIncludes.push_back(std::move(DiagInfo));
+}
   });
   std::vector UnusedIncludes =
   getUnused(AST, Used, /*ReferencedPublicHeaders*/ {});


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -442,6 +442,23 @@
   EXPECT_EQ(RefRange, Findings[1].SymRefRange);
 }
 
+TEST(IncludeCleaner, NoCrash) {
+  TestTU TU;
+  TU.Code = R"cpp(
+#include "all.h"
+void test() {
+  1s;
+}
+)cpp";
+  TU.AdditionalFiles["foo.h"] =
+  guard("int operator\"\"s(unsigned long long) { return 0; }");
+  TU.AdditionalFiles["all.h"] = guard("#include \"foo.h\"");
+  ParsedAST AST = TU.build();
+  auto Findings = computeIncludeCleanerFindings(AST);
+  // FIXME: this is not ideal, but at least we don't crash.
+  EXPECT_THAT(Findings.MissingIncludes, IsEmpty());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -405,10 +405,12 @@
 // through an #include.
 while (SM.getFileID(Loc) != SM.getMainFileID())
   Loc = SM.getIncludeLoc(SM.getFileID(Loc));
-const auto *Token = AST.getTokens().spelledTokenAt(Loc);
-MissingIncludeDiagInfo DiagInfo{Ref.Target, Token->range(SM),
-Providers};
-MissingIncludes.push_back(std::move(DiagInfo));
+
+if (const auto *Token = AST.getTokens().spelledTokenAt(Loc)) {
+  MissingIncludeDiagInfo DiagInfo{Ref.Target, Token->range(SM),
+  Providers};
+  MissingIncludes.push_back(std::move(DiagInfo));
+}
   });
   std::vector UnusedIncludes =
   getUnused(AST, Used, /*ReferencedPublicHeaders*/ {});
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4016e5d - [clang][Interp][NFC] Call emit*Ptr directly

2023-04-06 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-06T10:25:57+02:00
New Revision: 4016e5d9499e3cbcde32dbfe1d0a5085a9b16c96

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

LOG: [clang][Interp][NFC] Call emit*Ptr directly

Instead of the version that uses a switch statement to figure this out.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 2f9f99cc0648..a1f6f72c9bfc 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1881,13 +1881,13 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
 return this->emitGetPtrLocal(Offset, E);
   } else if (auto GlobalIndex = P.getGlobal(D)) {
 if (IsReference)
-  return this->emitGetGlobal(PT_Ptr, *GlobalIndex, E);
+  return this->emitGetGlobalPtr(*GlobalIndex, E);
 
 return this->emitGetPtrGlobal(*GlobalIndex, E);
   } else if (const auto *PVD = dyn_cast(D)) {
 if (auto It = this->Params.find(PVD); It != this->Params.end()) {
   if (IsReference)
-return this->emitGetParam(PT_Ptr, It->second, E);
+return this->emitGetParamPtr(It->second, E);
   return this->emitGetPtrParam(It->second, E);
 }
   }



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


[PATCH] D143467: [PowerPC] Add target feature requirement to builtins

2023-04-06 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf added inline comments.



Comment at: clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-test.c:47
 
-int test_test_data_class_f() {
-// CHECK-LABEL:   @test_test_data_class_f
-// CHECK: [[TMP:%.*]] = call i32 
@llvm.ppc.test.data.class.f32(float %0, i32 127)
-// CHECK-NEXT:ret i32 [[TMP]]
-// CHECK-NONPWR9-ERR: error: this builtin is only valid on POWER9 or later CPUs
-// CHECK-NOVSX-ERR: error: this builtin requires VSX to be enabled
-  return __test_data_class(f, 127);
+// CHECK-NOVSX-ERR: error: '__builtin_ppc_compare_exp_uo' needs target feature 
isa-v30-instructions,vsx
+// CHECK-NOVSX-ERR: error: '__builtin_ppc_compare_exp_lt' needs target feature 
isa-v30-instructions,vsx

qiucf wrote:
> stefanp wrote:
> > nit:
> > Should this be 
> > ```
> > ... needs target feature vsx
> > ```
> > Instead of listing them both?
> > 
> > Fixing this might be more trouble than it's worth because you would have to 
> > edit `CodeGenFunction::checkTargetFeatures`. I just thought I would mention 
> > it.
> Yes. That can be done in another patch.
After checking the source code, I found it might be too complex to filter 
existing features out. Because it actually has a syntax to support 'and'/'or' 
of feature requirements: 
https://github.com/llvm/llvm-project/blob/4016e5d/clang/lib/Basic/BuiltinTargetFeatures.h#L22_L31


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143467

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


[clang] 47ee851 - [clang][Interp][NFC] Context: Add getFloatSemantics()

2023-04-06 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-06T10:39:49+02:00
New Revision: 47ee8519ec2620ffe376d9b28cba8a2a0a73214a

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

LOG: [clang][Interp][NFC] Context: Add getFloatSemantics()

We use this quite a bit, so add some convenience API for it.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index a1f6f72c9bfc..3c0992e4fee0 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -92,8 +92,7 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
   case CK_FloatingCast: {
 if (!this->visit(SubExpr))
   return false;
-const auto *TargetSemantics =
-&Ctx.getASTContext().getFloatTypeSemantics(CE->getType());
+const auto *TargetSemantics = &Ctx.getFloatSemantics(CE->getType());
 return this->emitCastFP(TargetSemantics, getRoundingMode(CE), CE);
   }
 
@@ -105,8 +104,7 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
 if (!this->visit(SubExpr))
   return false;
 
-const auto *TargetSemantics =
-&Ctx.getASTContext().getFloatTypeSemantics(CE->getType());
+const auto *TargetSemantics = &Ctx.getFloatSemantics(CE->getType());
 llvm::RoundingMode RM = getRoundingMode(CE);
 return this->emitCastIntegralFloating(*FromT, TargetSemantics, RM, CE);
   }
@@ -601,8 +599,7 @@ bool 
ByteCodeExprGen::VisitFloatCompoundAssignOperator(
 
   // If necessary, convert LHS to its computation type.
   if (LHS->getType() != LHSComputationType) {
-const auto *TargetSemantics =
-&Ctx.getASTContext().getFloatTypeSemantics(LHSComputationType);
+const auto *TargetSemantics = &Ctx.getFloatSemantics(LHSComputationType);
 
 if (!this->emitCastFP(TargetSemantics, RM, E))
   return false;
@@ -635,8 +632,7 @@ bool 
ByteCodeExprGen::VisitFloatCompoundAssignOperator(
 
   // If necessary, convert result to LHS's type.
   if (LHS->getType() != ResultType) {
-const auto *TargetSemantics =
-&Ctx.getASTContext().getFloatTypeSemantics(LHS->getType());
+const auto *TargetSemantics = &Ctx.getFloatSemantics(LHS->getType());
 
 if (!this->emitCastFP(TargetSemantics, RM, E))
   return false;

diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index 6ede05e0f4c4..ed7ed41b1b24 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -133,6 +133,12 @@ unsigned Context::getCharBit() const {
   return Ctx.getTargetInfo().getCharWidth();
 }
 
+/// Simple wrapper around getFloatTypeSemantics() to make code a
+/// little shorter.
+const llvm::fltSemantics &Context::getFloatSemantics(QualType T) const {
+  return Ctx.getFloatTypeSemantics(T);
+}
+
 bool Context::Run(State &Parent, Function *Func, APValue &Result) {
   InterpState State(Parent, *P, Stk, *this);
   State.Current = new InterpFrame(State, Func, /*Caller=*/nullptr, {});

diff  --git a/clang/lib/AST/Interp/Context.h b/clang/lib/AST/Interp/Context.h
index e49422e64b87..cbae7fcf2860 100644
--- a/clang/lib/AST/Interp/Context.h
+++ b/clang/lib/AST/Interp/Context.h
@@ -57,6 +57,8 @@ class Context final {
   InterpStack &getStack() { return Stk; }
   /// Returns CHAR_BIT.
   unsigned getCharBit() const;
+  /// Return the floating-point semantics for T.
+  const llvm::fltSemantics &getFloatSemantics(QualType T) const;
 
   /// Classifies an expression.
   std::optional classify(QualType T) const;



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


[PATCH] D137782: [clang-tidy]bugprone-fold-init-type

2023-04-06 Thread Clement Courbet via Phabricator via cfe-commits
courbet added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137782

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


[clang] 70e5a2a - [clang][Interp] Fix zero-initializing of floating types

2023-04-06 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-06T10:52:01+02:00
New Revision: 70e5a2a94354fd7cec577d3e0c3892cc5e7ef07a

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

LOG: [clang][Interp] Fix zero-initializing of floating types

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 3c0992e4fee0..6ced8ca4d07f 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -953,8 +953,10 @@ bool 
ByteCodeExprGen::visitZeroInitializer(PrimType T, const Expr *E) {
 return this->emitNullPtr(E);
   case PT_FnPtr:
 return this->emitNullFnPtr(E);
-  case PT_Float:
-assert(false);
+  case PT_Float: {
+return this->emitConstFloat(
+APFloat::getZero(Ctx.getFloatSemantics(E->getType())), E);
+  }
   }
   llvm_unreachable("unknown primitive type");
 }

diff  --git a/clang/test/AST/Interp/floats.cpp 
b/clang/test/AST/Interp/floats.cpp
index 7b9328c4d118..3b392d3b6727 100644
--- a/clang/test/AST/Interp/floats.cpp
+++ b/clang/test/AST/Interp/floats.cpp
@@ -78,3 +78,17 @@ namespace compound {
   }
   static_assert(f2() == __FLT_MAX__, "");
 }
+
+namespace ZeroInit {
+  template
+  struct A {
+int a;
+FloatT f;
+  };
+
+  constexpr A a{12};
+  static_assert(a.f == 0.0f);
+
+  constexpr A b{12};
+  static_assert(a.f == 0.0);
+};



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


[PATCH] D146788: [clang][Interp] Fix zero-initializing of floating types

2023-04-06 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 rG70e5a2a94354: [clang][Interp] Fix zero-initializing of 
floating types (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146788

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/floats.cpp


Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -78,3 +78,17 @@
   }
   static_assert(f2() == __FLT_MAX__, "");
 }
+
+namespace ZeroInit {
+  template
+  struct A {
+int a;
+FloatT f;
+  };
+
+  constexpr A a{12};
+  static_assert(a.f == 0.0f);
+
+  constexpr A b{12};
+  static_assert(a.f == 0.0);
+};
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -953,8 +953,10 @@
 return this->emitNullPtr(E);
   case PT_FnPtr:
 return this->emitNullFnPtr(E);
-  case PT_Float:
-assert(false);
+  case PT_Float: {
+return this->emitConstFloat(
+APFloat::getZero(Ctx.getFloatSemantics(E->getType())), E);
+  }
   }
   llvm_unreachable("unknown primitive type");
 }


Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -78,3 +78,17 @@
   }
   static_assert(f2() == __FLT_MAX__, "");
 }
+
+namespace ZeroInit {
+  template
+  struct A {
+int a;
+FloatT f;
+  };
+
+  constexpr A a{12};
+  static_assert(a.f == 0.0f);
+
+  constexpr A b{12};
+  static_assert(a.f == 0.0);
+};
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -953,8 +953,10 @@
 return this->emitNullPtr(E);
   case PT_FnPtr:
 return this->emitNullFnPtr(E);
-  case PT_Float:
-assert(false);
+  case PT_Float: {
+return this->emitConstFloat(
+APFloat::getZero(Ctx.getFloatSemantics(E->getType())), E);
+  }
   }
   llvm_unreachable("unknown primitive type");
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145965: [C++20][Modules] Fix incorrect visibilities in implementation units.

2023-04-06 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 511327.
iains added a comment.

rebased, addressed review comments (patch still needs refactoring)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145965

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaLookup.cpp
  clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
  clang/test/CXX/module/basic/basic.def.odr/p4.cppm
  clang/test/CXX/module/basic/basic.link/p2.cppm
  clang/test/CXX/module/module.import/p2.cpp
  clang/test/CXX/module/module.interface/p2.cpp
  clang/test/CXX/module/module.interface/p7.cpp
  clang/test/CXX/module/module.reach/ex1.cpp
  clang/test/CXX/module/module.reach/p2.cpp
  clang/test/CXX/module/module.reach/p5.cpp
  clang/test/Modules/Reachability-template-default-arg.cpp
  clang/test/Modules/cxx20-10-1-ex2.cpp
  clang/test/Modules/deduction-guide3.cppm
  clang/test/Modules/diagnose-missing-import.m

Index: clang/test/Modules/diagnose-missing-import.m
===
--- clang/test/Modules/diagnose-missing-import.m
+++ clang/test/Modules/diagnose-missing-import.m
@@ -6,9 +6,9 @@
 
 void foo(void) {
   XYZLogEvent(xyzRiskyCloseOpenParam, xyzRiskyCloseOpenParam); // expected-error {{call to undeclared function 'XYZLogEvent'; ISO C99 and later do not support implicit function declarations}} \
-  expected-error {{declaration of 'XYZLogEvent' must be imported}} \
-  expected-error {{declaration of 'xyzRiskyCloseOpenParam' must be imported from module 'NCI.A'}} \
-  expected-error {{declaration of 'xyzRiskyCloseOpenParam' must be imported from module 'NCI.A'}}
+  expected-error {{declaration of 'XYZLogEvent' is internal to 'NCI.A'}} \
+  expected-error {{declaration of 'xyzRiskyCloseOpenParam' is internal to 'NCI.A'}} \
+  expected-error {{declaration of 'xyzRiskyCloseOpenParam' is internal to 'NCI.A'}}
 }
 
 // expected-note@Inputs/diagnose-missing-import/a.h:5 {{declaration here is not visible}}
Index: clang/test/Modules/deduction-guide3.cppm
===
--- clang/test/Modules/deduction-guide3.cppm
+++ clang/test/Modules/deduction-guide3.cppm
@@ -19,8 +19,8 @@
 //--- Use.cpp
 import Templ;
 void func() {
-Templ t(5); // expected-error {{declaration of 'Templ' must be imported from module 'Templ' before it is required}}
+Templ t(5); // expected-error {{declaration of 'Templ' is private to module 'Templ'}}
 // expected-error@-1 {{unknown type name 'Templ'}}
-// expected-n...@templ.cppm:3 {{declaration here is not visible}}
+// expected-n...@templ.cppm:3 {{export the declaration to make it available}}
 }
 
Index: clang/test/Modules/cxx20-10-1-ex2.cpp
===
--- clang/test/Modules/cxx20-10-1-ex2.cpp
+++ clang/test/Modules/cxx20-10-1-ex2.cpp
@@ -53,8 +53,8 @@
 //--- std10-1-ex2-tu6.cpp
 import B;
 // error, n is module-local and this is not a module.
-int &c = n; // expected-error {{declaration of 'n' must be imported}}
-// expected-note@* {{declaration here is not visible}}
+int &c = n; // expected-error {{declaration of 'n' is private to module 'B'}}
+// expected-note@* {{export the declaration to make it available}}
 
 //--- std10-1-ex2-tu7.cpp
 // expected-no-diagnostics
Index: clang/test/Modules/Reachability-template-default-arg.cpp
===
--- clang/test/Modules/Reachability-template-default-arg.cpp
+++ clang/test/Modules/Reachability-template-default-arg.cpp
@@ -18,6 +18,6 @@
 import template_default_arg;
 void bar() {
   A<> a0;
-  A a1; // expected-error {{declaration of 't' must be imported from module 'template_default_arg' before it is required}}
-   // expected-note@* {{declaration here is not visible}}
+  A a1; // expected-error {{declaration of 't' is private to module 'template_default_arg'}}
+   // expected-note@* {{export the declaration to make it available}}
 }
Index: clang/test/CXX/module/module.reach/p5.cpp
===
--- clang/test/CXX/module/module.reach/p5.cpp
+++ clang/test/CXX/module/module.reach/p5.cpp
@@ -14,5 +14,5 @@
 export module B;
 import A;
 Y y; // OK, definition of X is reachable
-X x; // expected-error {{declaration of 'X' must be imported from module 'A' before it is required

[PATCH] D145965: [C++20][Modules] Fix incorrect visibilities in implementation units.

2023-04-06 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

in the end, we have to deal with the following cases:

1. decls in the same TU (including GMF and PMF)
2. decls in the current named module (excluding GMF)
3. decls on an instantiation path (which can include internal-linkage entities)
4. decls that are needed by an exported entity from a *differennt" named module 
[e.g. a module-linkage entity that is used by some exported  content].


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145965

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


[PATCH] D145965: [C++20][Modules] Fix incorrect visibilities in implementation units.

2023-04-06 Thread Iain Sandoe via Phabricator via cfe-commits
iains marked 2 inline comments as done.
iains added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:2356
+  /// Determine whether the module M is part of the current named module.
+  bool isPartOfCurrentNamedModule(const Module *M) const {
+if (!M || M->isGlobalModule())

ChuanqiXu wrote:
> While I am not a native speaker, I feel `isSameModuleWithCurrentTU` may be a 
> better name.
actually, as noted, both cases are needed. So I have made that clear by 
splitting the function into two.



Comment at: clang/lib/Sema/SemaLookup.cpp:5821-5832
+  } else if (Decl->hasLinkage() &&
+ Decl->getFormalLinkage() == Linkage::ModuleLinkage) {
+Diag(UseLoc, diag::err_module_private_use)
+<< (int)MIK << Decl << Modules[0]->getFullModuleName();
+Diag(Decl->getBeginLoc(), diag::note_suggest_export)
+<< (int)MIK
+<< FixItHint::CreateInsertion(Decl->getBeginLoc(), "export");

ChuanqiXu wrote:
> I feel like this can be another change. I'm a little bit confused since I 
> feel the patch did multiple things at the same time again..
sure, we can refactor; the current patch is a placeholder to allow work to 
continue on `p1815`.



Comment at: clang/lib/Sema/SemaLookup.cpp:2101
+  if (isVisible(SemaRef, ND)) {
+if (SemaRef.getLangOpts().CPlusPlusModules && ND->isFromASTFile()) {
+  // The module that owns the decl is visible; However

ChuanqiXu wrote:
> iains wrote:
> > ChuanqiXu wrote:
> > > Let's not use `isFromASTFile()`. It is a low level API without higher 
> > > level semantics. I think it is good enough to check the module of ND.
> > lookup is very heavily used; the purpose of the isFromAST() check is to 
> > short-circuit the more expensive checks when we know that a decl must be in 
> > the same TU (i.e. it is not from an AST file).  
> > 
> > If we can find a suitable inexpensive check that has better semantics, I am 
> > fine to change this,
> > 
> It looks good enough to me to check that `ND` lives in a module. And from 
> what I profiled, the lookup process is not hot really.
OK, we can always revisit performance later,



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145965

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


[clang] 03a9a1e - [Sema] Fix reporting of invalid shader attribute on HLSL entry function

2023-04-06 Thread Richard Sandiford via cfe-commits

Author: Richard Sandiford
Date: 2023-04-06T10:56:01+01:00
New Revision: 03a9a1e664de58fb52ce93e9fb73f61e75a5359a

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

LOG: [Sema] Fix reporting of invalid shader attribute on HLSL entry function

If the HLSL entry function had a shader attribute that conflicted
with the pipeline stage specified in the target triple, Clang
would emit:

   error: (null) attribute parameters do not match the previous declaration
   conflicting attribute is here

(where the second line doesn't reference an attribute).

This was because the code constructed a dummy attribute that had
only a source location, but no kind or syntax.

Noticed while doing some changes to the attribute handling.

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

Added: 
clang/test/SemaHLSL/entry_shader.hlsl

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index eedc8c18f93dc..c852aeeb401ff 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11752,6 +11752,8 @@ def err_hlsl_attr_invalid_type : Error<
"attribute %0 only applies to a field or parameter of type '%1'">;
 def err_hlsl_attr_invalid_ast_node : Error<
"attribute %0 only applies to %1">;
+def err_hlsl_entry_shader_attr_mismatch : Error<
+   "%0 attribute on entry function does not match the pipeline stage">;
 def err_hlsl_numthreads_argument_oor : Error<"argument '%select{X|Y|Z}0' to 
numthreads attribute cannot exceed %1">;
 def err_hlsl_numthreads_invalid : Error<"total number of threads cannot exceed 
%0">;
 def err_hlsl_missing_numthreads : Error<"missing numthreads attribute for %0 
shader entry">;

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 7596b51bf0545..0feb0ab48f3a8 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10205,14 +10205,19 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator 
&D, DeclContext *DC,
   CheckHLSLEntryPoint(NewFD);
   if (!NewFD->isInvalidDecl()) {
 auto Env = TargetInfo.getTriple().getEnvironment();
-AttributeCommonInfo AL(NewFD->getBeginLoc());
 HLSLShaderAttr::ShaderType ShaderType =
 static_cast(
 hlsl::getStageFromEnvironment(Env));
 // To share code with HLSLShaderAttr, add HLSLShaderAttr to entry
 // function.
-if (HLSLShaderAttr *Attr = mergeHLSLShaderAttr(NewFD, AL, ShaderType))
-  NewFD->addAttr(Attr);
+if (HLSLShaderAttr *NT = NewFD->getAttr()) {
+  if (NT->getType() != ShaderType)
+Diag(NT->getLocation(), diag::err_hlsl_entry_shader_attr_mismatch)
+<< NT;
+} else {
+  NewFD->addAttr(HLSLShaderAttr::Create(Context, ShaderType,
+NewFD->getBeginLoc()));
+}
   }
 }
 // HLSL does not support specifying an address space on a function return

diff  --git a/clang/test/SemaHLSL/entry_shader.hlsl 
b/clang/test/SemaHLSL/entry_shader.hlsl
new file mode 100644
index 0..a47e2563e0d1a
--- /dev/null
+++ b/clang/test/SemaHLSL/entry_shader.hlsl
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"anyHit"' -verify
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"compute"'
+
+// expected-error@+1 {{'shader' attribute on entry function does not match the 
pipeline stage}}
+[numthreads(1,1,1), shader(SHADER)]
+void foo() {
+
+}



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


[PATCH] D147657: [Sema] Fix reporting of invalid shader attribute on HLSL entry function

2023-04-06 Thread Richard Sandiford 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 rG03a9a1e664de: [Sema] Fix reporting of invalid shader 
attribute on HLSL entry function (authored by rsandifo-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147657

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaHLSL/entry_shader.hlsl


Index: clang/test/SemaHLSL/entry_shader.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/entry_shader.hlsl
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"anyHit"' -verify
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry 
foo  -o - %s -DSHADER='"compute"'
+
+// expected-error@+1 {{'shader' attribute on entry function does not match the 
pipeline stage}}
+[numthreads(1,1,1), shader(SHADER)]
+void foo() {
+
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -10205,14 +10205,19 @@
   CheckHLSLEntryPoint(NewFD);
   if (!NewFD->isInvalidDecl()) {
 auto Env = TargetInfo.getTriple().getEnvironment();
-AttributeCommonInfo AL(NewFD->getBeginLoc());
 HLSLShaderAttr::ShaderType ShaderType =
 static_cast(
 hlsl::getStageFromEnvironment(Env));
 // To share code with HLSLShaderAttr, add HLSLShaderAttr to entry
 // function.
-if (HLSLShaderAttr *Attr = mergeHLSLShaderAttr(NewFD, AL, ShaderType))
-  NewFD->addAttr(Attr);
+if (HLSLShaderAttr *NT = NewFD->getAttr()) {
+  if (NT->getType() != ShaderType)
+Diag(NT->getLocation(), diag::err_hlsl_entry_shader_attr_mismatch)
+<< NT;
+} else {
+  NewFD->addAttr(HLSLShaderAttr::Create(Context, ShaderType,
+NewFD->getBeginLoc()));
+}
   }
 }
 // HLSL does not support specifying an address space on a function return
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11752,6 +11752,8 @@
"attribute %0 only applies to a field or parameter of type '%1'">;
 def err_hlsl_attr_invalid_ast_node : Error<
"attribute %0 only applies to %1">;
+def err_hlsl_entry_shader_attr_mismatch : Error<
+   "%0 attribute on entry function does not match the pipeline stage">;
 def err_hlsl_numthreads_argument_oor : Error<"argument '%select{X|Y|Z}0' to 
numthreads attribute cannot exceed %1">;
 def err_hlsl_numthreads_invalid : Error<"total number of threads cannot exceed 
%0">;
 def err_hlsl_missing_numthreads : Error<"missing numthreads attribute for %0 
shader entry">;


Index: clang/test/SemaHLSL/entry_shader.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/entry_shader.hlsl
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry foo  -o - %s -DSHADER='"anyHit"' -verify
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry foo  -o - %s -DSHADER='"compute"'
+
+// expected-error@+1 {{'shader' attribute on entry function does not match the pipeline stage}}
+[numthreads(1,1,1), shader(SHADER)]
+void foo() {
+
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -10205,14 +10205,19 @@
   CheckHLSLEntryPoint(NewFD);
   if (!NewFD->isInvalidDecl()) {
 auto Env = TargetInfo.getTriple().getEnvironment();
-AttributeCommonInfo AL(NewFD->getBeginLoc());
 HLSLShaderAttr::ShaderType ShaderType =
 static_cast(
 hlsl::getStageFromEnvironment(Env));
 // To share code with HLSLShaderAttr, add HLSLShaderAttr to entry
 // function.
-if (HLSLShaderAttr *Attr = mergeHLSLShaderAttr(NewFD, AL, ShaderType))
-  NewFD->addAttr(Attr);
+if (HLSLShaderAttr *NT = NewFD->getAttr()) {
+  if (NT->getType() != ShaderType)
+Diag(NT->getLocation(), diag::err_hlsl_entry_shader_attr_mismatch)
+<< NT;
+} else {
+  NewFD->addAttr(HLSLShaderAttr::Create(Context, ShaderType,
+NewFD->getBeginLoc()));
+}
   }
 }
 // HLSL does not support specifying an address space on a function return
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===

[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-04-06 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

I'll submit later today then if nobody has any other objections

Will add a release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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


[clang] 7d9511b - [clang][Interp] Add missing static_assert messages

2023-04-06 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-06T12:03:45+02:00
New Revision: 7d9511b2e33f1981cd846dd2493c6d96ece2c77e

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

LOG: [clang][Interp] Add missing static_assert messages

This broke build bots, e.g:
https://lab.llvm.org/buildbot/#/builders/139/builds/38697

Added: 


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

Removed: 




diff  --git a/clang/test/AST/Interp/floats.cpp 
b/clang/test/AST/Interp/floats.cpp
index 3b392d3b6727b..71f585ee70a9c 100644
--- a/clang/test/AST/Interp/floats.cpp
+++ b/clang/test/AST/Interp/floats.cpp
@@ -87,8 +87,8 @@ namespace ZeroInit {
   };
 
   constexpr A a{12};
-  static_assert(a.f == 0.0f);
+  static_assert(a.f == 0.0f, "");
 
   constexpr A b{12};
-  static_assert(a.f == 0.0);
+  static_assert(a.f == 0.0, "");
 };



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


[PATCH] D137782: [clang-tidy]bugprone-fold-init-type

2023-04-06 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Missing ReleaseNotes,




Comment at: clang-tools-extra/clang-tidy/bugprone/FoldInitTypeCheck.cpp:41
+returns(hasCanonicalType(
+referenceType(pointee(BuiltinTypeWithId(ID),
+// `value_type operator*();`

referenceType(pointee -> references



Comment at: clang-tools-extra/clang-tidy/bugprone/FoldInitTypeCheck.cpp:43
+// `value_type operator*();`
+returns(hasCanonicalType(BuiltinTypeWithId(ID))),
+// `auto operator*();`, `decltype(auto) operator*();`

BuiltinTypeWithId already got hasCanonicalType, no need to duplicate



Comment at: clang-tools-extra/clang-tidy/bugprone/FoldInitTypeCheck.cpp:45
+// `auto operator*();`, `decltype(auto) operator*();`
+returns(hasCanonicalType(autoType(
+hasDeducedType(BuiltinTypeWithId(ID);

maybe:
```
returns(qualType(hasCanonicalType(anyOf(BuiltinTypeWithId(ID), 
references(BuiltinTypeWithId(ID)), 
autoType(hasDeducedType(BuiltinTypeWithId(ID)))
```
instead of having anyOf on top level.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137782

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


[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-04-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

This breaks the following innocent looking out-of-line definition with two 
levels of constrained template parameters:

  template  concept Result = true;
  
  template 
  class CoFuture final {
template  explicit CoFuture();
  };
  
  template 
  template 
  CoFuture::CoFuture() {}

See godbolt .

We found this during our compiler releases, not sure if there is a quick 
forward fix or we will need to rollback.
@alexander-shaposhnikov could you take a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

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


[clang] 55bbcbf - [clang] Reset track of immediate function context when entering new function

2023-04-06 Thread Mariya Podchishchaeva via cfe-commits

Author: Mariya Podchishchaeva
Date: 2023-04-06T06:35:26-04:00
New Revision: 55bbcbf511b4df0dfe524b2d06fc561a939c6b16

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

LOG: [clang] Reset track of immediate function context when entering new 
function

Due to not resetting that, clang still thinks that it is in immediate
function context even if it already entered non-consteval function.
This caused consteval functions reaching codegen in some cases.

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

Reviewed By: cor3ntin, aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGenCXX/cxx20-consteval-crash.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c07f23af4a629..03bbebaf1249c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -279,6 +279,9 @@ Bug Fixes in This Version
 - Fix crash when generating code coverage information for `PseudoObjectExpr` 
in 
   Clang AST.
   (`#45481 `_)
+- Fix the assertion hit when a template consteval function appears in a nested
+  consteval/constexpr call chain.
+  (`#61142 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0feb0ab48f3a8..6c6bf78ffc9c8 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15180,6 +15180,15 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope 
*FnBodyScope, Decl *D,
 FD->isConsteval() ? 
ExpressionEvaluationContext::ImmediateFunctionContext
   : ExprEvalContexts.back().Context);
 
+  // Each ExpressionEvaluationContextRecord also keeps track of whether the
+  // context is nested in an immediate function context, so smaller contexts
+  // that appear inside immediate functions (like variable initializers) are
+  // considered to be inside an immediate function context even though by
+  // themselves they are not immediate function contexts. But when a new
+  // function is entered, we need to reset this tracking, since the entered
+  // function might be not an immediate function.
+  ExprEvalContexts.back().InImmediateFunctionContext = FD->isConsteval();
+
   // Check for defining attributes before the check for redefinition.
   if (const auto *Attr = FD->getAttr()) {
 Diag(Attr->getLocation(), diag::err_alias_is_definition) << FD << 0;

diff  --git a/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp 
b/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
index ebd7eafaf7156..1639f0ef82d03 100644
--- a/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
+++ b/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
@@ -116,3 +116,27 @@ void method() {
 }
 
 } // namespace GH60166
+
+namespace GH61142 {
+
+template 
+struct Test {
+  constexpr static void bar() {
+foo();
+  }
+  consteval static void foo() {};
+};
+
+consteval void a() {
+  Test::bar();
+}
+
+void b() {
+  Test::bar();
+}
+
+// Make sure consteval function is not emitted.
+// CHECK-NOT: call {{.*}}foo{{.*}}()
+// CHECK-NOT: define {{.*}}foo{{.*}}()
+
+} // namespace GH61142



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


[PATCH] D147531: [clang] Reset track of immediate function context when entering new function

2023-04-06 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG55bbcbf511b4: [clang] Reset track of immediate function 
context when entering new function (authored by Fznamznon).

Changed prior to commit:
  https://reviews.llvm.org/D147531?vs=510843&id=511357#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147531

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCXX/cxx20-consteval-crash.cpp


Index: clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
===
--- clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
+++ clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
@@ -116,3 +116,27 @@
 }
 
 } // namespace GH60166
+
+namespace GH61142 {
+
+template 
+struct Test {
+  constexpr static void bar() {
+foo();
+  }
+  consteval static void foo() {};
+};
+
+consteval void a() {
+  Test::bar();
+}
+
+void b() {
+  Test::bar();
+}
+
+// Make sure consteval function is not emitted.
+// CHECK-NOT: call {{.*}}foo{{.*}}()
+// CHECK-NOT: define {{.*}}foo{{.*}}()
+
+} // namespace GH61142
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -15180,6 +15180,15 @@
 FD->isConsteval() ? 
ExpressionEvaluationContext::ImmediateFunctionContext
   : ExprEvalContexts.back().Context);
 
+  // Each ExpressionEvaluationContextRecord also keeps track of whether the
+  // context is nested in an immediate function context, so smaller contexts
+  // that appear inside immediate functions (like variable initializers) are
+  // considered to be inside an immediate function context even though by
+  // themselves they are not immediate function contexts. But when a new
+  // function is entered, we need to reset this tracking, since the entered
+  // function might be not an immediate function.
+  ExprEvalContexts.back().InImmediateFunctionContext = FD->isConsteval();
+
   // Check for defining attributes before the check for redefinition.
   if (const auto *Attr = FD->getAttr()) {
 Diag(Attr->getLocation(), diag::err_alias_is_definition) << FD << 0;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -279,6 +279,9 @@
 - Fix crash when generating code coverage information for `PseudoObjectExpr` 
in 
   Clang AST.
   (`#45481 `_)
+- Fix the assertion hit when a template consteval function appears in a nested
+  consteval/constexpr call chain.
+  (`#61142 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
===
--- clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
+++ clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
@@ -116,3 +116,27 @@
 }
 
 } // namespace GH60166
+
+namespace GH61142 {
+
+template 
+struct Test {
+  constexpr static void bar() {
+foo();
+  }
+  consteval static void foo() {};
+};
+
+consteval void a() {
+  Test::bar();
+}
+
+void b() {
+  Test::bar();
+}
+
+// Make sure consteval function is not emitted.
+// CHECK-NOT: call {{.*}}foo{{.*}}()
+// CHECK-NOT: define {{.*}}foo{{.*}}()
+
+} // namespace GH61142
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -15180,6 +15180,15 @@
 FD->isConsteval() ? ExpressionEvaluationContext::ImmediateFunctionContext
   : ExprEvalContexts.back().Context);
 
+  // Each ExpressionEvaluationContextRecord also keeps track of whether the
+  // context is nested in an immediate function context, so smaller contexts
+  // that appear inside immediate functions (like variable initializers) are
+  // considered to be inside an immediate function context even though by
+  // themselves they are not immediate function contexts. But when a new
+  // function is entered, we need to reset this tracking, since the entered
+  // function might be not an immediate function.
+  ExprEvalContexts.back().InImmediateFunctionContext = FD->isConsteval();
+
   // Check for defining attributes before the check for redefinition.
   if (const auto *Attr = FD->getAttr()) {
 Diag(Attr->getLocation(), diag::err_alias_is_definition) << FD << 0;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -279,6 +279,9 @@
 - Fix crash when generating code coverage information for `PseudoObjectExpr` in 
   Clang AST.
   (`#45481 

[PATCH] D146987: [Assignment Tracking] Enable by default

2023-04-06 Thread Orlando Cazalet-Hyams via Phabricator via cfe-commits
Orlando added a comment.

In D146987#4237124 , @haowei wrote:

> This patch (which enables assignment tracking) and D147312 
>  breaks llvm runtime build for 
> `runtimes-armv7-unknown-linux-gnueabihf`
>
> ...
>
> Example of failed build: 
> https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8785108885903505089/overview
>
> Please take a look. And please revert this change if it takes a while to fix. 
> Thanks.

That should be fixed by D147696 , thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146987

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


[PATCH] D147626: [clang] Do not crash when initializing union with flexible array member

2023-04-06 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:808
   unsigned NumElems = numStructUnionElements(ILE->getType());
-  if (RDecl->hasFlexibleArrayMember())
+  if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember())
 ++NumElems;

shafik wrote:
> Fznamznon wrote:
> > Just for some context, numStructUnionElements checks that there is a 
> > flexible array member and returns number_of_initializable_fields-1 for 
> > structs. For unions it just returns 1 or 0, so flexible array member caused 
> > adding one more element to initlistexpr that was never properly handled.
> > 
> > Instead of doing this change, we could probably never enter initialization 
> > since the record (union) declaration is not valid, but that is not the case 
> > even for other types of errors in code, for example, I've tried declaring 
> > field of struct with a typo:
> > 
> > ```
> > struct { cha x[]; } r = {1}; 
> > ```
> > Initialization is still performed by clang.
> > Also, it seems MSVC considers flexible array member inside union as valid, 
> > so the test code is probably not always invalid.
> I am not sure what to think here, looking at gcc documentation for this 
> extension: https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html 
> 
> and using the following code:
> 
> ```
> struct f1 {
>   int x; int y[];
> } f1 = { 1, { 2, 3, 4 } }; // #1
> 
> struct f2 {
>   struct f1 f1; int data[3];
> } f2 = { { 1 }, { 2, 3, 4 } }; // #2
> 
> struct { char x[]; } r = {1};  // #3
> ```
> 
> gcc rejects 2 and 3 even though 2 comes from their documentation. Clang warns 
> on 2 and MSVC rejects 2
> 
> CC @aaron.ballman @rsmith 
Yes, I also had a feeling that we probably need to refine how these extensions 
are supported by clang, that is probably a bit out of scope of the fix though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147626

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


[PATCH] D147686: [clangd] Fix a nullptr-dereference crash in computeIncludeCleanerFindings.

2023-04-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

could you give some more details about the crash, so that we actually now where 
to fix it? e.g. is it token buffers missing the spelled token at that offset 
somehow ? or is it AST reporting a weird source locations for user-defined 
literals and we need to do some sort of post processing (or maybe it should've 
been filtered all together). as doing it like this will imply us completely 
eating such diagnostics.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147686

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


[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-04-06 Thread Pavel Kosov via Phabricator via cfe-commits
kpdev42 updated this revision to Diff 511362.
kpdev42 added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/test/API/types/TestEmptyBase.py
  lldb/test/API/types/empty_base_type.cpp

Index: lldb/test/API/types/empty_base_type.cpp
===
--- /dev/null
+++ lldb/test/API/types/empty_base_type.cpp
@@ -0,0 +1,29 @@
+struct C
+{
+ long c,d;
+};
+
+struct D
+{
+};
+
+struct B
+{
+  [[no_unique_address]] D x;
+};
+
+struct E
+{
+  [[no_unique_address]] D x;
+};
+
+
+struct A : B,E,C
+{
+ long a,b;
+} _a;
+
+
+int main() {
+  return _a.a; // Set breakpoint here.
+}
Index: lldb/test/API/types/TestEmptyBase.py
===
--- /dev/null
+++ lldb/test/API/types/TestEmptyBase.py
@@ -0,0 +1,42 @@
+"""
+Test that recursive types are handled correctly.
+"""
+
+
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+
+class EmptyBaseTestCase(TestBase):
+
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+
+# Find the line number to break for main.c.
+self.line = line_number('empty_base_type.cpp',
+'// Set breakpoint here.')
+
+self.sources = {
+'CXX_SOURCES': 'empty_base_type.cpp'}
+
+def test(self):
+"""Test that recursive structs are displayed correctly."""
+self.build(dictionary=self.sources)
+self.setTearDownCleanup(dictionary=self.sources)
+self.run_expr()
+
+def run_expr(self):
+self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
+
+lldbutil.run_break_set_by_file_and_line(
+self,
+"empty_base_type.cpp",
+self.line,
+num_expected_locations=-1,
+loc_exact=True)
+
+self.runCmd("run", RUN_SUCCEEDED)
+self.runCmd("expression _a")
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1460,8 +1460,6 @@
   if (!result)
 return;
 
-  base_classes.push_back(std::move(result));
-
   if (is_virtual) {
 // Do not specify any offset for virtual inheritance. The DWARF
 // produced by clang doesn't give us a constant offset, but gives
@@ -1476,10 +1474,33 @@
 // be removed from LayoutRecordType() in the external
 // AST source in clang.
   } else {
+// DWARF doesn't have any representation for [[no_unique_address]]
+// attribute. Empty base classes with [[no_unique_address]] fields
+// confuse lldb and prevent construction of object memory layout.
+// To fix this we scan base classes in reverse order to determine
+// overlapping offsets. Wnen found we consider such class as empty
+// base with all fields having [[no_unique_address]] attribute.
+for (auto it = base_classes.rbegin(); it != base_classes.rend(); ++it) {
+  clang::CXXRecordDecl *prev_base_decl =
+  (*it)->getType()->getAsCXXRecordDecl();
+  // We've already marked this class, exit.
+  if (prev_base_decl->isEmpty())
+break;
+  auto it_layout = layout_info.base_offsets.find(prev_base_decl);
+  assert(it_layout != layout_info.base_offsets.end());
+  // We found a normal base class, exit.
+  if (it_layout->second.getQuantity() < member_byte_offset)
+break;
+  prev_base_decl->markEmpty();
+  for (auto *field : prev_base_decl->fields())
+field->addAttr(clang::NoUniqueAddressAttr::Create(
+ast->getASTContext(), clang::SourceRange()));
+}
 layout_info.base_offsets.insert(std::make_pair(
 ast->GetAsCXXRecordDecl(base_class_clang_type.GetOpaqueQualType()),
 clang::CharUnits::fromQuantity(member_byte_offset)));
   }
+  base_classes.push_back(std::move(result));
 }
 
 TypeSP DWARFASTParserClang::UpdateSymbolContextScopeForType(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147698: [clang][dataflow] Add support for new and delete expressions.

2023-04-06 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

To model the fact that values get deleted by a delete expression, this also
necessitates adding `DataflowEnvironment::unsetValue(StorageLocation &)` and
`StructValue::unsetValue(ValueDecl &)`.

Modeling object deletion in this way isn't perfect. In the framework, a value
that isn't present typically simply means "we didn't compute a value for this
storage location or struct field". Still, removing the values still seems better
than leaving them in place.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147698

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -5170,4 +5170,94 @@
   });
 }
 
+TEST(TransferTest, NewAndDeleteExpressions) {
+  std::string Code = R"(
+void target() {
+  int *p = new int(42);
+  // [[after_new]]
+  delete p;
+  // [[after_delete]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &EnvAfterNew =
+getEnvironmentAtAnnotation(Results, "after_new");
+const Environment &EnvAfterDelete =
+getEnvironmentAtAnnotation(Results, "after_delete");
+
+auto &PAfterNew =
+getValueForDecl(ASTCtx, EnvAfterNew, "p");
+auto &PAfterDelete =
+getValueForDecl(ASTCtx, EnvAfterNew, "p");
+
+EXPECT_EQ(&PAfterNew, &PAfterDelete);
+
+EXPECT_THAT(EnvAfterNew.getValue(PAfterNew.getPointeeLoc()), NotNull());
+EXPECT_THAT(EnvAfterDelete.getValue(PAfterDelete.getPointeeLoc()),
+IsNull());
+  });
+}
+
+TEST(TransferTest, NewAndDeleteExpressions_Structs) {
+  std::string Code = R"(
+struct Inner {
+  int InnerField;
+};
+
+struct Outer {
+  Inner OuterField;
+};
+
+void target() {
+  Outer *p = new Outer;
+  // Access the fields to make sure the analysis actually generates children
+  // for them in the `AggregateStorageLoc` and `StructValue`.
+  p->OuterField.InnerField;
+  // [[after_new]]
+  delete p;
+  // [[after_delete]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &EnvAfterNew =
+getEnvironmentAtAnnotation(Results, "after_new");
+const Environment &EnvAfterDelete =
+getEnvironmentAtAnnotation(Results, "after_delete");
+
+const ValueDecl *OuterField = findValueDecl(ASTCtx, "OuterField");
+const ValueDecl *InnerField = findValueDecl(ASTCtx, "InnerField");
+
+auto &PAfterNew =
+getValueForDecl(ASTCtx, EnvAfterNew, "p");
+auto &PAfterDelete =
+getValueForDecl(ASTCtx, EnvAfterNew, "p");
+
+EXPECT_EQ(&PAfterNew, &PAfterDelete);
+
+// Storage locations always exist. (They _can't_ be different because
+// PAfterNew is identical to PAfterDelete.)
+auto &OuterLoc =
+cast(PAfterNew.getPointeeLoc());
+auto &OuterFieldLoc =
+cast(OuterLoc.getChild(*OuterField));
+auto &InnerFieldLoc = OuterFieldLoc.getChild(*InnerField);
+
+// Values for the struct and all fields exist after the new.
+EXPECT_THAT(EnvAfterNew.getValue(OuterLoc), NotNull());
+EXPECT_THAT(EnvAfterNew.getValue(OuterFieldLoc), NotNull());
+EXPECT_THAT(EnvAfterNew.getValue(InnerFieldLoc), NotNull());
+
+// But the values no longer exist after the delete.
+EXPECT_THAT(EnvAfterDelete.getValue(OuterLoc), IsNull());
+EXPECT_THAT(EnvAfterDelete.getValue(OuterFieldLoc), IsNull());
+EXPECT_THAT(EnvAfterDelete.getValue(InnerFieldLoc), IsNull());
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -469,6 +469,27 @@
 Env.setValue(Loc, Env.create(*ThisPointeeLoc));
   }
 
+  void VisitCXXNewExpr(const CXXNewExpr *S) {
+auto &Loc = Env.createStorageLocation(*S);
+Env.setStorageLocation(*S, Loc);
+if (Value *Val = Env.createValue(S->getType()))
+  Env.setValue(Loc, *Val);
+  }
+
+  void VisitCX

[clang] ef1b22a - [clang][ClangScanDeps][test] Remove the file before overwriting it

2023-04-06 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2023-04-06T13:51:57+02:00
New Revision: ef1b22a20fd4d8c0cfea64089d4e732dd95dc265

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

LOG: [clang][ClangScanDeps][test] Remove the file before overwriting it

Remove the file copied from the source tree before overwriting it. If
the source code is stored with readonly (0444) permissions, then
the copied files are also readonly and attempting to overwrite them
fails.

Added: 


Modified: 
clang/test/ClangScanDeps/modules-pch.c

Removed: 




diff  --git a/clang/test/ClangScanDeps/modules-pch.c 
b/clang/test/ClangScanDeps/modules-pch.c
index aa568e5aaab4d..0f61dd5ecf18c 100644
--- a/clang/test/ClangScanDeps/modules-pch.c
+++ b/clang/test/ClangScanDeps/modules-pch.c
@@ -7,6 +7,7 @@
 
 // Scan dependencies of the PCH:
 //
+// RUN: rm -f %t/cdb_pch.json
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_pch.json > %t/cdb_pch.json
 // RUN: clang-scan-deps -compilation-database %t/cdb_pch.json -format 
experimental-full \
 // RUN:   -module-files-dir %t/build > %t/result_pch.json
@@ -94,6 +95,7 @@
 
 // Scan dependencies of the TU:
 //
+// RUN: rm -f %t/cdb_tu.json
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu.json > %t/cdb_tu.json
 // RUN: clang-scan-deps -compilation-database %t/cdb_tu.json -format 
experimental-full \
 // RUN:   -module-files-dir %t/build > %t/result_tu.json
@@ -142,6 +144,7 @@
 
 // Scan dependencies of the TU that has common modules with the PCH:
 //
+// RUN: rm -f %t/cdb_tu_with_common.json
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu_with_common.json > 
%t/cdb_tu_with_common.json
 // RUN: clang-scan-deps -compilation-database %t/cdb_tu_with_common.json 
-format experimental-full \
 // RUN:   -module-files-dir %t/build > %t/result_tu_with_common.json



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


[PATCH] D147686: [clangd] Fix a nullptr-dereference crash in computeIncludeCleanerFindings.

2023-04-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D147686#4248330 , @kadircet wrote:

> could you give some more details about the crash, so that we actually now 
> where to fix it? e.g. is it token buffers missing the spelled token at that 
> offset somehow ? or is it AST reporting a weird source locations for 
> user-defined literals and we need to do some sort of post processing (or 
> maybe it should've been filtered all together). as doing it like this will 
> imply us completely eating such diagnostics.

sorry, for not giving more details. See the other comment.




Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:450
+void test() {
+  1s;
+}

here is the `UserDefinedLiteral` AST node:

```
`-UserDefinedLiteral 0x5556682e4500  'int'
  |-ImplicitCastExpr 0x5556682e44e8  'int (*)(unsigned long long)' 

  | `-DeclRefExpr 0x5556682e44a0  'int (unsigned long long)' lvalue 
Function 0x5556682e4290 'operator""s' 'int (unsigned long long)'
  `-IntegerLiteral 0x5556682e4480  'unsigned long long' 1
```

The source location of the `UserDefinedLiteral` points to `^1s`, while the 
source location of the inner `DeclRefExpr` points to `1^s` (1 offset shift). In 
the token buffer, we only have a single spelled token `1s`, thus 
`AST.getTokens().spelledTokenAt` can not find any token that starts at `1^s` 
source loc.



Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:458
+  auto Findings = computeIncludeCleanerFindings(AST);
+  EXPECT_THAT(Findings.MissingIncludes, IsEmpty());
+}

T


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147686

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


[PATCH] D144943: [clang][Interp] Implement bitcasts (WIP)

2023-04-06 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 511386.

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

https://reviews.llvm.org/D144943

Files:
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Descriptor.h
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/Pointer.cpp
  clang/lib/AST/Interp/Pointer.h
  clang/lib/AST/Interp/PrimType.h
  clang/test/AST/Interp/builtin-bit-cast.cpp
  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
@@ -90,6 +90,11 @@
 static_assert(p != nullptr, "");
 static_assert(*p == 10, "");
 
+constexpr const void *cp = (void *)p;
+// FIXME: This should be an error in the new interpreter.
+constexpr const int *pm = (int*)cp; // ref-error {{ must be initialized by a constant expression}} \
+// ref-note {{cast from 'const void *' is not allowed}}
+
 constexpr const int* getIntPointer() {
   return &m;
 }
Index: clang/test/AST/Interp/builtin-bit-cast.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/builtin-bit-cast.cpp
@@ -0,0 +1,228 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify -std=c++2a -fsyntax-only %s
+// RUN: %clang_cc1 -verify=ref -std=c++2a -fsyntax-only %s
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple aarch64_be-linux-gnu -fexperimental-new-constant-interpreter %s
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple aarch64_be-linux-gnu -fexperimental-new-constant-interpreter %s
+
+
+/// ref-no-diagnostics
+
+
+/// FIXME: This is a version of clang/test/SemaCXX/builtin-bit-cast.cpp with
+///   the currently supported subset of operations. They should *all* be
+///   supported though.
+
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#  define LITTLE_END 1
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#  define LITTLE_END 0
+#else
+#  error "huh?"
+#endif
+
+template  struct is_same {
+  static constexpr bool value = false;
+};
+template  struct is_same {
+  static constexpr bool value = true;
+};
+
+static_assert(sizeof(int) == 4);
+static_assert(sizeof(long long) == 8);
+
+template 
+constexpr To bit_cast(const From &from) {
+  static_assert(sizeof(To) == sizeof(From));
+  return __builtin_bit_cast(To, from);
+}
+
+template 
+constexpr bool round_trip(const Init &init) {
+  return bit_cast(bit_cast(init)) == init;
+}
+
+static_assert(round_trip((int)-1));
+static_assert(round_trip((int)0x12345678));
+static_assert(round_trip((int)0x87654321));
+static_assert(round_trip((int)0x0C05FEFE));
+static_assert(round_trip((int)0x0C05FEFE));
+
+constexpr unsigned char input[] = {0xCA, 0xFE, 0xBA, 0xBE};
+constexpr unsigned expected = LITTLE_END ? 0xBEBAFECA : 0xCAFEBABE;
+static_assert(bit_cast(input) == expected);
+
+constexpr short S[] = {10, 20};
+constexpr int I = __builtin_bit_cast(int, S);
+static_assert(I == (LITTLE_END ? 1310730 : 655380));
+
+
+struct int_splicer {
+  unsigned x;
+  unsigned y;
+
+  constexpr int_splicer() : x(1), y(2) {}
+  constexpr int_splicer(unsigned x, unsigned y) : x(x), y(y) {}
+
+  constexpr bool operator==(const int_splicer &other) const {
+return other.x == x && other.y == y;
+  }
+};
+
+constexpr int_splicer splice(0x0C05FEFE, 0xCAFEBABE);
+
+static_assert(bit_cast(splice) == (LITTLE_END
+   ? 0xCAFEBABE0C05FEFE
+   : 0x0C05FEFECAFEBABE));
+
+constexpr int_splicer IS = bit_cast(0xCAFEBABE0C05FEFE);
+static_assert(bit_cast(0xCAFEBABE0C05FEFE).x == (LITTLE_END
+  ? 0x0C05FEFE
+  : 0xCAFEBABE));
+
+static_assert(round_trip(splice));
+static_assert(round_trip(splice));
+
+struct base2 {
+};
+
+struct base3 {
+  unsigned z;
+  constexpr base3() : z(3) {}
+};
+
+struct bases : int_splicer, base2, base3 {
+  unsigned doublez;
+  constexpr bases() : doublez(4) {}
+};
+
+struct tuple4 {
+  unsigned x, y, z, doublez;
+
+  constexpr bool operator==(tuple4 const &other) const {
+return x == other.x && y == other.y &&
+   z == other.z && doublez == other.doublez;
+  }
+};
+constexpr bases b;// = {{1, 2}, {}, {3}, 4};
+constexpr tuple4 t4 = bit_cast(b);
+
+// Regardless of endianness, this should hold:
+static_assert(t4.x == 1);
+static_assert(t4.y == 2);
+static_assert(t4.z == 3);
+static_assert(t4.doublez == 4);
+//static_assert(t4 == tuple4{1, 2, 3, 4});
+static_assert(round_trip(b));
+
+
+namespace WithBases {
+  struct Base {
+char A[3] = {1,2,

[PATCH] D147655: Implement mangling rules for C++20 concepts and requires-expressions.

2023-04-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added inline comments.



Comment at: clang/include/clang/AST/ExprConcepts.h:502
ArrayRef LocalParameters,
+   SourceLocation RParenLoc,
ArrayRef Requirements,

rsmith wrote:
> erichkeane wrote:
> > Is this an unrelated change?  Are paren locations required for mangling?
> `requires (params) { blah; }` has a different mangling from `requires { blah; 
> }` -- in particular, the former introduces a new level of function 
> parameters, so references to enclosing function parameters are numbered 
> differently in the two. This applies even if `params` is empty or `void` 
> (`requires () { ... }` and `requires (void) { ... }` are both valid).
> 
> We previously generated the same AST for `requires { ... }` and `requires () 
> { ... }`, which meant we couldn't mangle this correctly. Tracking the parens 
> (or at least their existence) fixes that (and also improves the AST fidelity 
> for tooling).
>>Tracking the parens (or at least their existence) fixes tha
it seems you test that via the `LParenLoc`, which is why I'm surprised about 
the addition of the `RParenLoc`?  I have no problem with the addition of the 
`RParenLoc` for the below reason, but was trying to figure out the significance 
toward the mangling.

>>and also improves the AST fidelity for tooling
This I definitely get, was just trying to figure out why it was in a patch for 
mangling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147655

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


[PATCH] D147661: [Sema] Tweak merging of availability attributes

2023-04-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I think the change is probably fine, but can you add an AST-dump test for this 
one?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147661

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


[PATCH] D147572: [Clang][OpenMP] Fix failure with team-wide allocated variable

2023-04-06 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/test/OpenMP/target_team_variable_codegen.cpp:33
+//.
+// CHECK-NVIDIA: @local_a = internal addrspace(3) global [10 x i32] 
zeroinitializer, align 4
+//.

jhuber6 wrote:
> Shouldn't the Nvidia version also be undefined? Not sure why this should vary 
> depending on the target.
Perhaps NVIDIA code path can tolerate a zeroinitializer? I don't want to change 
it if it's not needed. I am basing this check on the code path for AMD GPUs and 
the initial bug that was reported.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147572

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


[PATCH] D147708: [NFC][clang] Fix static analyzer tool remarks about large copies by values

2023-04-06 Thread Soumi Manna via Phabricator via cfe-commits
Manna created this revision.
Manna added reviewers: erichkeane, aaron.ballman.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
arphaman, a.sidorin, baloghadamsoftware.
Herald added a project: All.
Manna requested review of this revision.
Herald added a project: clang.

Reported by Coverity:

Big parameter passed by value
Copying large values is inefficient, consider passing by reference; Low, 
medium, and high size thresholds for detection can be adjusted.

1. Inside "SemaConcept.cpp" file, in 
subsumes, clang::​NamedDecl *, 
llvm::​ArrayRef)::​[lambda(clang::​AtomicConstraint const 
&, clang::​AtomicConstraint const &) (instance 
2)]>(llvm::​SmallVector, 
4u>, llvm::​SmallVector, 
4u>, T1): A large function call parameter exceeding the low threshold is passed 
by value.

  i. pass_by_value: Passing parameter PDNF of type NormalForm (size 144 bytes) 
by value, which exceeds the low threshold of 128 bytes. ii. pass_by_value: 
Passing parameter QCNF of type NormalForm (size 144 bytes) by value, which 
exceeds the low threshold of 128 bytes.

2. Inside "CodeGenAction.cpp" file, in 
clang::​reportOptRecordError(llvm::​Error, clang::​DiagnosticsEngine &, 
clang::​CodeGenOptions): A very large function call parameter exceeding the 
high threshold is passed by value.

i. pass_by_value: Passing parameter CodeGenOpts of type clang::CodeGenOptions 
const (size 1560 bytes) by value, which exceeds the high threshold of 512 bytes.

3. Inside "CodeCompleteConsumer.cpp" file, in 
clang::​PrintingCodeCompleteConsumer::​ProcessCodeCompleteResults(clang::​Sema 
&, clang::​CodeCompletionContext, clang::​CodeCompletionResult *, unsigned 
int): A large function call parameter exceeding the low threshold is passed by 
value.

i. pass_by_value: Passing parameter Context of type 
clang::CodeCompletionContext (size 200 bytes) by value, which exceeds the low 
threshold of 128 bytes.

4. Inside "GlobalModuleIndex.cpp" file, in 
clang::​GlobalModuleIndex::​GlobalModuleIndex(std::​unique_ptr>, llvm::​BitstreamCursor): A large 
function call parameter exceeding the medium threshold is passed by value.

i. pass_by_value: Passing parameter Cursor of type llvm::BitstreamCursor (size 
352 bytes) by value, which exceeds the medium threshold of 256 bytes.

5. Inside "CGNonTrivialStruct.cpp" file, in ::​getParamAddrs<1ull, 
<0ull...>>(std::​integer_sequence, 
std::​array, clang::​CodeGen::​FunctionArgList, 
clang::​CodeGen::​CodeGenFunction *): A large function call parameter exceeding 
the low threshold is passed by value.

i. pass_by_value: Passing parameter Args of type 
clang::CodeGen::FunctionArgList (size 144 bytes) by value, which exceeds the 
low threshold of 128 bytes.

6. Inside "CodeGenModule.cpp" file, in 
clang::​CodeGen::​CodeGenModule::​EmitBackendOptionsMetadata(clang::​CodeGenOptions):
 A very large function call parameter exceeding the high threshold is passed by 
value.

i. pass_by_value: Passing parameter CodeGenOpts of type clang::CodeGenOptions 
const (size 2008 bytes) by value, which exceeds the high threshold of 512 bytes.

7. Inside "SemaCodeComplete.cpp" file, in 
HandleCodeCompleteResults(clang::​Sema *, clang::​CodeCompleteConsumer *, 
clang::​CodeCompletionContext, clang::​CodeCompletionResult *, unsigned int): A 
large function call parameter exceeding the low threshold is passed by value.

i. pass_by_value: Passing parameter Context of type 
clang::CodeCompletionContext (size 200 bytes) by value, which exceeds the low 
threshold of 128 bytes.

8. Inside "CGGPUBuiltin.cpp" file, in 
::​containsNonScalarVarargs(clang::​CodeGen::​CodeGenFunction *, 
clang::​CodeGen::​CallArgList): A very large function call parameter exceeding 
the high threshold is passed by value.

i. pass_by_value: Passing parameter Args of type clang::CodeGen::CallArgList 
(size 1176 bytes) by value, which exceeds the high threshold of 512 bytes.

9. Inside "ASTUnit.cpp" file, in 
::​AugmentedCodeCompleteConsumer::​ProcessCodeCompleteResults(clang::​Sema
 &, clang::​CodeCompletionContext, clang::​CodeCompletionResult *, unsigned 
int): A large function call parameter exceeding the low threshold is passed by 
value.

i. pass_by_value: Passing parameter Context of type 
clang::CodeCompletionContext (size 200 bytes) by value, which exceeds the low 
threshold of 128 bytes.

10. Inside "SemaConcept.cpp" file, in 
::​SatisfactionStackRAII::​SatisfactionStackRAII(clang::​Sema &, 
clang::​NamedDecl const *, llvm::​FoldingSetNodeID): A large function call 
parameter exceeding the low threshold is passed by value.

i. pass_by_value: Passing parameter FSNID of type llvm::FoldingSetNodeID (size 
144 bytes) by value, which exceeds the low threshold of 128 bytes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147708

Files:
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  clang/lib/CodeGen/CGNonTrivialStruct.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/ASTUnit.c

[PATCH] D98416: [clang-tidy] Fix cppcoreguidelines-narrowing-conversions false positive

2023-04-06 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: PiotrZSL.
Herald added a project: All.

LGTM, is there anything that should be fixed before merging?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98416

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


[PATCH] D147615: [clang][Sema][NFC] Save token name instead of the full token

2023-04-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM! There shouldn't be any lifetime issues from this, as @shafik pointed out, 
the pointer originates in a static array defined in `TokenKinds.cpp`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147615

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


[clang] 91a0740 - Reapply "[Assignment Tracking] Enable by default"

2023-04-06 Thread via cfe-commits

Author: OCHyams
Date: 2023-04-06T15:29:18+01:00
New Revision: 91a0740474e3c4fe0bde8ff5699115bf808ca23f

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

LOG: Reapply "[Assignment Tracking] Enable by default"

Re-land D146987.

This reverts commit 43825d19318695be48abe6f042369da00fbb808b (revert)
which reverts aa32490bfe0b957c4f5583e14304f5e34b2b9bce (original commit).

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/CodeGen/assignment-tracking/flag.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5e008fc9b26ee..0e3c7b708071f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5815,7 +5815,7 @@ def experimental_assignment_tracking_EQ : Joined<["-"], 
"fexperimental-assignmen
   Group, CodeGenOpts<"EnableAssignmentTracking">,
   NormalizedValuesScope<"CodeGenOptions::AssignmentTrackingOpts">,
   Values<"disabled,enabled,forced">, 
NormalizedValues<["Disabled","Enabled","Forced"]>,
-  MarshallingInfoEnum, "Disabled">;
+  MarshallingInfoEnum, "Enabled">;
 
 } // let Flags = [CC1Option, NoDriverOption]
 

diff  --git a/clang/test/CodeGen/assignment-tracking/flag.cpp 
b/clang/test/CodeGen/assignment-tracking/flag.cpp
index aa1f054dae4d7..3bd974fe07c6c 100644
--- a/clang/test/CodeGen/assignment-tracking/flag.cpp
+++ b/clang/test/CodeGen/assignment-tracking/flag.cpp
@@ -8,10 +8,10 @@
 // RUN: -emit-llvm  %s -o - -fexperimental-assignment-tracking=disabled 
-O1\
 // RUN: | FileCheck %s --check-prefixes=DISABLE
 
- Disabled by default:
+ Enabled by default:
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   
\
 // RUN: -emit-llvm  %s -o - -O1
\
-// RUN: | FileCheck %s --check-prefixes=DISABLE
+// RUN: | FileCheck %s --check-prefixes=ENABLE
 
  Disabled at O0 unless forced.
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   
\



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


[PATCH] D147708: [NFC][clang] Fix static analyzer tool remarks about large copies by values

2023-04-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Build failures seem relevant.




Comment at: clang/lib/CodeGen/CGGPUBuiltin.cpp:128
 
-bool containsNonScalarVarargs(CodeGenFunction *CGF, CallArgList Args) {
+bool containsNonScalarVarargs(CodeGenFunction *CGF, CallArgList &Args) {
   return llvm::any_of(llvm::drop_begin(Args), [&](const CallArg &A) {

This shouldn't be the SmallVector, this should be an ArrayRef unless they need 
to modify it  (or a `llvm::SmallVectorImpl` of the type if they do).

Also, anything that you're changing to be a 'reference' from a copy changes 
semantics unless you make it a const-ref.



Comment at: clang/lib/CodeGen/CGNonTrivialStruct.cpp:326
 std::array 
Alignments,
-FunctionArgList Args,
+FunctionArgList &Args,
 CodeGenFunction *CGF) {

Same comment here, if this doesn't need to modify the Args, it should be an 
`ArrayRef`, else a `SmallVectorImpl`.



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:89
   static void reportOptRecordError(Error E, DiagnosticsEngine &Diags,
-   const CodeGenOptions CodeGenOpts) {
+   const CodeGenOptions &CodeGenOpts) {
 handleAllErrors(

This one makes sense, contains a couple std::strings.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:993
 void CodeGenModule::EmitBackendOptionsMetadata(
-const CodeGenOptions CodeGenOpts) {
+const CodeGenOptions &CodeGenOpts) {
   if (getTriple().isRISCV()) {

Same here.



Comment at: clang/lib/Frontend/ASTUnit.cpp:2067
 void AugmentedCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &S,
-CodeCompletionContext Context,
+CodeCompletionContext &Context,
 CodeCompletionResult *Results,

Should this be const-ref?  Since we couldn't modify the original before, and 
now this allows us to modify the original.



Comment at: clang/lib/Sema/CodeCompleteConsumer.cpp:641
 void PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(
-Sema &SemaRef, CodeCompletionContext Context, CodeCompletionResult 
*Results,
-unsigned NumResults) {
+Sema &SemaRef, CodeCompletionContext &Context,
+CodeCompletionResult *Results, unsigned NumResults) {

Same above re: const.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4151
   CodeCompleteConsumer *CodeCompleter,
-  CodeCompletionContext Context,
+  CodeCompletionContext &Context,
   CodeCompletionResult *Results,

Same above re: cosnt.



Comment at: clang/lib/Sema/SemaConcept.cpp:163
   SatisfactionStackRAII(Sema &SemaRef, const NamedDecl *ND,
-llvm::FoldingSetNodeID FSNID)
+llvm::FoldingSetNodeID &FSNID)
   : SemaRef(SemaRef) {

const.



Comment at: clang/lib/Sema/SemaConcept.cpp:1373
 template
-static bool subsumes(NormalForm PDNF, NormalForm QCNF,
+static bool subsumes(NormalForm &PDNF, NormalForm &QCNF,
  AtomicSubsumptionEvaluator E) {

const on these.



Comment at: clang/lib/Sema/SemaInit.cpp:5290
   // initialize.
-  auto ProcessEntities = [&](auto Range) -> bool {
+  auto ProcessEntities = [&](auto &Range) -> bool {
 bool IsUnionType = Entity.getType()->isUnionType();

This should probably do the work to be an ArrayRef with a deduced type.  In 
fact, the deduction probably isn't necessary, since every collection is an 
`IniitializedEntity`.



Comment at: clang/lib/Serialization/GlobalModuleIndex.cpp:130
 std::unique_ptr IndexBuffer,
-llvm::BitstreamCursor Cursor)
+llvm::BitstreamCursor &Cursor)
 : Buffer(std::move(IndexBuffer)), IdentifierIndex(), 
NumIdentifierLookups(),

This probably should NOT happen.  The point of this type is to contain a state 
for this type, and this would be a breaking change, since it would result in 
the cursor in the containing type being modified.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147708

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


[PATCH] D147655: Implement mangling rules for C++20 concepts and requires-expressions.

2023-04-06 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

I agree it doesn't affect too much code, but people do instantiate templates 
manually sometimes. IIUC, linking against shared libraries would break if that 
library does explicit instantiations of constrained functions. That concerns me 
a bit.

Also, do you know if GCC developers are planning on implementing this change as 
well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147655

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


[PATCH] D147626: [clang] Do not crash when initializing union with flexible array member

2023-04-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:808
   unsigned NumElems = numStructUnionElements(ILE->getType());
-  if (RDecl->hasFlexibleArrayMember())
+  if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember())
 ++NumElems;

Fznamznon wrote:
> shafik wrote:
> > Fznamznon wrote:
> > > Just for some context, numStructUnionElements checks that there is a 
> > > flexible array member and returns number_of_initializable_fields-1 for 
> > > structs. For unions it just returns 1 or 0, so flexible array member 
> > > caused adding one more element to initlistexpr that was never properly 
> > > handled.
> > > 
> > > Instead of doing this change, we could probably never enter 
> > > initialization since the record (union) declaration is not valid, but 
> > > that is not the case even for other types of errors in code, for example, 
> > > I've tried declaring field of struct with a typo:
> > > 
> > > ```
> > > struct { cha x[]; } r = {1}; 
> > > ```
> > > Initialization is still performed by clang.
> > > Also, it seems MSVC considers flexible array member inside union as 
> > > valid, so the test code is probably not always invalid.
> > I am not sure what to think here, looking at gcc documentation for this 
> > extension: https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html 
> > 
> > and using the following code:
> > 
> > ```
> > struct f1 {
> >   int x; int y[];
> > } f1 = { 1, { 2, 3, 4 } }; // #1
> > 
> > struct f2 {
> >   struct f1 f1; int data[3];
> > } f2 = { { 1 }, { 2, 3, 4 } }; // #2
> > 
> > struct { char x[]; } r = {1};  // #3
> > ```
> > 
> > gcc rejects 2 and 3 even though 2 comes from their documentation. Clang 
> > warns on 2 and MSVC rejects 2
> > 
> > CC @aaron.ballman @rsmith 
> Yes, I also had a feeling that we probably need to refine how these 
> extensions are supported by clang, that is probably a bit out of scope of the 
> fix though.
The GCC extension differs based on C vs C++: https://godbolt.org/z/E14Yz37To
As does the extension in Clang, but differently than GCC: 
https://godbolt.org/z/zYznaYPf5

So I agree that there's work to be done on this extension, but it's outside of 
the scope of the crash fix for this patch. For this patch, GCC rejects allowing 
a flexible array member in a union in both C and C++, but it looks like Clang 
rejects in C and perhaps accepts in C++: https://godbolt.org/z/bTsPn3G7b So how 
about we add a C++ test case for this as well -- if that still crashes, that 
should be fixed, but if the code is accepted, we should either decide we want 
to start rejecting it or we should ensure the codegen for it is correct.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147626

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


[PATCH] D141307: Add -f[no-]loop-versioning option

2023-04-06 Thread Mats Petersson via Phabricator via cfe-commits
Leporacanthicus updated this revision to Diff 511416.
Leporacanthicus added a comment.

Rebase only


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141307

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CodeGenOptions.def
  flang/include/flang/Tools/CLOptions.inc
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Driver/version-loops.f90

Index: flang/test/Driver/version-loops.f90
===
--- /dev/null
+++ flang/test/Driver/version-loops.f90
@@ -0,0 +1,54 @@
+! Test that flang-new forwards the -f{no-,}version-loops-for-stride 
+! options corredly to flang-new -fc1 for different variants of optimisation
+! and explicit flags.
+
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
+! RUN:   -O3 \
+! RUN:   | FileCheck %s
+  
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
+! RUN:   -O2 \
+! RUN:   | FileCheck %s --check-prefix=CHECK-O2
+
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
+! RUN:   -O2 -fversion-loops-for-stride \
+! RUN:   | FileCheck %s --check-prefix=CHECK-O2-with
+  
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
+! RUN:   -O4 \
+! RUN:   | FileCheck %s --check-prefix=CHECK-O4
+  
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
+! RUN:   -Ofast \
+! RUN:   | FileCheck %s --check-prefix=CHECK-Ofast
+  
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
+! RUN:   -Ofast -fno-version-loops-for-stride \
+! RUN:   | FileCheck %s --check-prefix=CHECK-Ofast-no
+
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
+! RUN:   -O3 -fno-version-loops-for-stride \
+! RUN:   | FileCheck %s --check-prefix=CHECK-O3-no
+  
+! CHECK: "-fversion-loops-for-stride"
+! CHECK: "-O3"
+
+! CHECK-O2-NOT: "-fversion-loops-for-stride"
+! CHECK-O2: "-O2"  
+
+! CHECK-O2-with: "-fversion-loops-for-stride"
+! CHECK-O2-with: "-O2"  
+  
+! CHECK-O4: "-fversion-loops-for-stride"
+! CHECK-O4: "-O3"
+
+! CHECK-Ofast: "-ffast-math"
+! CHECK-Ofast: "-fversion-loops-for-stride"
+! CHECK-Ofast: "-O3"
+
+! CHECK-Ofast-no: "-ffast-math"
+! CHECK-Ofast-no-NOT: "-fversion-loops-for-stride"
+! CHECK-Ofast-no: "-O3"
+
+! CHECK-O3-no-NOT: "-fversion-loops-for-stride"
+! CHECK-O3-no: "-O3"
Index: flang/test/Driver/frontend-forwarding.f90
===
--- flang/test/Driver/frontend-forwarding.f90
+++ flang/test/Driver/frontend-forwarding.f90
@@ -15,6 +15,8 @@
 ! RUN: -fassociative-math \
 ! RUN: -freciprocal-math \
 ! RUN: -fpass-plugin=Bye%pluginext \
+! RUN: -fversion-loops-for-stride \
+! RUN: -mllvm -print-before-all\
 ! RUN: -mllvm -print-before-all \
 ! RUN: -save-temps=obj \
 ! RUN: -P \
@@ -34,5 +36,6 @@
 ! CHECK: "-freciprocal-math"
 ! CHECK: "-fconvert=little-endian"
 ! CHECK: "-fpass-plugin=Bye
+! CHECK: "-fversion-loops-for-stride"  
 ! CHECK: "-mllvm" "-print-before-all"
 ! CHECK: "-save-temps=obj"
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -48,6 +48,8 @@
 ! HELP-NEXT: -fno-integrated-as  Disable the integrated assembler
 ! HELP-NEXT: -fno-signed-zeros  Allow optimizations that ignore the sign of floating point zeros
 ! HELP-NEXT: -fno-stack-arrays  Allocate array temporaries on the heap (default)
+! HELP-NEXT: -fno-version-loops-for-stride
+! HELP-NEXT:Do not create unit-strided loops (default)
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-NEXT: -fpass-plugin= Load pass plugin from a dynamic shared object file (only with new pass manager).
@@ -55,6 +57,8 @@
 ! HELP-NEXT: -fstack-arrays Attempt to allocate array temporaries on the stack, no matter their size
 ! HELP-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
 ! HELP-NEXT: -funderscoring Appends one trailing underscore to external names
+! HELP-NEXT: -fversion-loops-for-stride
+! HELP-NEXT:Create unit-strided versions of loops
 ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
 ! HELP-NEXT: -gline-tables-only Emit debug line number tables only
 ! HELP-NEXT: -g Generate source-level debug information
@@ -143,6 +147,8 @@
 ! HELP-FC1-NEXT: -fno-reformat  Dump the cooked character stream in -E mode
 ! HELP-FC1-NEXT: -fno-signed-zeros  Allow optimizations that ignore the sign of floating point zeros
 ! HELP-FC1-NEXT: -fno-stack-arrays  Allocate array temporaries on the heap (default)
+! HELP-FC1

[PATCH] D147666: [OPENMP] Adds /lib to rpath to avoid need to set LD_LIBRARY_PATH to find plugins.

2023-04-06 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

Sorry Greg, we can't have this back in trunk. It's now value add for the ROCm 
toolchain, and some llvm releases had this feature, but no longer.

The consensus in the OpenMP weekly meeting was to require users to hack around 
with linker flags or environment variables to get a working program. This makes 
Fedora's packaging scripts happy.

I do not like this but was comprehensively outvoted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147666

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


[clang] 090b2e2 - [AttrDocs] Enhance musttail attribute documentation

2023-04-06 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2023-04-06T16:51:33+02:00
New Revision: 090b2e27efb2bd2859913f0e9c15effe2a88982b

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

LOG: [AttrDocs] Enhance musttail attribute documentation

Based on info from https://github.com/llvm/llvm-project/issues/54964

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 02f0b6e622771..dae12624a822b 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -603,6 +603,9 @@ Any variables in scope, including all arguments to the 
function and the
 return value must be trivially destructible. The calling convention of the
 caller and callee must match, and they must not be variadic functions or have
 old style K&R C function declarations.
+
+``clang::musttail`` provides assurances that the tail call can be optimized on
+all targets, not just one.
   }];
 }
 



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


[PATCH] D146520: [clang-tidy] Fix checks filter with warnings-as-errors

2023-04-06 Thread Tiago Macarios via Phabricator via cfe-commits
tiagoma added a comment.

Applying this patch seems to fix issues with C++20 as well. See 
https://github.com/llvm/llvm-project/issues/61969
Can we get it in?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146520

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


[PATCH] D147714: [Attr] Introduce [[clang::nonportable_musttail]] as less strict version of [[clang::musttail]]

2023-04-06 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 created this revision.
xbolva00 added reviewers: aaron.ballman, efriedma, haberman.
Herald added a project: All.
xbolva00 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As noted in https://github.com/llvm/llvm-project/issues/54964 , musttail 
provide assurances that the tail call can be optimized on all targets.

But some users could care only one specific target and if they use musttail 
attribute, they may see an Clang error about signatures mismatch. This mismatch 
is often a not a real problem in practice and LLVM can still emit tail call.

So... Introduce [[clang::nonportable_musttail]] which is a less strict version 
of [[clang::musttail]] (no checking if signatures fully match).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147714

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaStmt.cpp
  clang/test/SemaCXX/attr-musttail.cpp

Index: clang/test/SemaCXX/attr-musttail.cpp
===
--- clang/test/SemaCXX/attr-musttail.cpp
+++ clang/test/SemaCXX/attr-musttail.cpp
@@ -6,6 +6,7 @@
   [[clang::musttail(1, 2)]] return ReturnsInt1(); // expected-error {{'musttail' attribute takes no arguments}}
   [[clang::musttail]] return 5;   // expected-error {{'musttail' attribute requires that the return value is the result of a function call}}
   [[clang::musttail]] return ReturnsInt1();
+  [[clang::nonportable_musttail]] return ReturnsInt1();
 }
 
 void NoFunctionCall() {
@@ -20,6 +21,11 @@
   return NoParams();  // expected-error {{cannot perform a tail call to function 'NoParams' because its signature is incompatible with the calling function}}
 }
 
+void TestParamArityMismatchNonPortable(int x) {
+  [[clang::nonportable_musttail]]
+  return NoParams();
+}
+
 void LongParam(long x); // expected-note {{target function has type mismatch at 1st parameter (expected 'long' but has 'int')}}
 void TestParamTypeMismatch(int x) {
   [[clang::musttail]]  // expected-note {{tail call required by 'musttail' attribute here}}
@@ -267,3 +273,17 @@
 void TestCallNonValue() {
   [[clang::musttail]] return ns; // expected-error {{unexpected namespace name 'ns': expected expression}}
 }
+
+struct Foo {
+  int foo(int) { return 0; }
+};
+
+struct Bar {
+  Foo foo;
+  int bar(int);
+};
+
+int Bar::bar(int x) {
+  [[clang::nonportable_musttail]]
+  return foo.foo(x);
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -586,7 +586,7 @@
   // attributes lands.
   for (const auto *A : Attrs) {
 if (A->getKind() == attr::MustTail) {
-  if (!checkAndRewriteMustTailAttr(SubStmt, *A)) {
+  if (!checkAndRewriteMustTailAttr(SubStmt, *cast(A))) {
 return SubStmt;
   }
   setFunctionHasMustTail();
@@ -608,7 +608,7 @@
   return SubStmt;
 }
 
-bool Sema::checkAndRewriteMustTailAttr(Stmt *St, const Attr &MTA) {
+bool Sema::checkAndRewriteMustTailAttr(Stmt *St, const MustTailAttr &MTA) {
   ReturnStmt *R = cast(St);
   Expr *E = R->getRetValue();
 
@@ -633,7 +633,7 @@
   return true;
 }
 
-bool Sema::checkMustTailAttr(const Stmt *St, const Attr &MTA) {
+bool Sema::checkMustTailAttr(const Stmt *St, const MustTailAttr &MTA) {
   assert(!CurContext->isDependentContext() &&
  "musttail cannot be checked from a dependent context");
 
@@ -846,6 +846,9 @@
 return true;
   };
 
+  if (MTA.isNonPortableMustTail())
+return true;
+
   PartialDiagnostic PD = PDiag(diag::note_musttail_mismatch);
   if (!CheckTypesMatch(CallerType, CalleeType, PD)) {
 if (const auto *ND = dyn_cast_or_null(CE->getCalleeDecl()))
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -12351,12 +12351,12 @@
   /// issuing a diagnostic and returning false if not. In the success case,
   /// the statement is rewritten to remove implicit nodes from the return
   /// value.
-  bool checkAndRewriteMustTailAttr(Stmt *St, const Attr &MTA);
+  bool checkAndRewriteMustTailAttr(Stmt *St, const MustTailAttr &MTA);
 
 private:
   /// Check whether the given statement can have musttail applied to it,
   /// issuing a diagnostic and returning false if not.
-  bool checkMustTailAttr(const Stmt *St, const Attr &MTA);
+  bool checkMustTailAttr(const Stmt *St, const MustTailAttr &MTA);
 
 public:
   /// Check to see if a given expression could have '.c_str()' called on it.
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1470,8 +1470,9 @@
 }
 
 def MustTail : StmtAttr {
-  let Spellings = [Clang<"musttail">];
+  let Spellings = [Clang<"musttail">, Clang<"nonportabl

[PATCH] D137782: [clang-tidy]bugprone-fold-init-type

2023-04-06 Thread Clement Courbet via Phabricator via cfe-commits
courbet updated this revision to Diff 511424.
courbet marked 2 inline comments as done.
courbet added a comment.

- Address review comments
- Add release notes.

Thanks !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137782

Files:
  clang-tools-extra/clang-tidy/bugprone/FoldInitTypeCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/fold-init-type.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/fold-init-type.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/fold-init-type.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/fold-init-type.cpp
@@ -1,39 +1,67 @@
-// RUN: %check_clang_tidy %s bugprone-fold-init-type %t
+// RUN: %check_clang_tidy %s bugprone-fold-init-type -std=c++17 %t
 
 namespace std {
 template 
-T accumulate(InputIt first, InputIt last, T init);
+T accumulate(InputIt first, InputIt last, T init) {
+  // When `InputIt::operator*` returns a deduced `auto` type that refers to a
+  // dependent type, the return type is deduced only if `InputIt::operator*`
+  // is instantiated. In practice this happens somewhere in the implementation
+  // of `accumulate`. For tests, do it here.
+  (void)*first;
+}
 
 template 
-T reduce(InputIt first, InputIt last, T init);
+T reduce(InputIt first, InputIt last, T init) { (void)*first; }
 template 
 T reduce(ExecutionPolicy &&policy,
- InputIt first, InputIt last, T init);
+ InputIt first, InputIt last, T init) { (void)*first; }
 
 struct parallel_execution_policy {};
 constexpr parallel_execution_policy par{};
 
 template 
 T inner_product(InputIt1 first1, InputIt1 last1,
-InputIt2 first2, T value);
+InputIt2 first2, T value) { (void)*first1; (void)*first2; }
 
 template 
 T inner_product(ExecutionPolicy &&policy, InputIt1 first1, InputIt1 last1,
-InputIt2 first2, T value);
+InputIt2 first2, T value) { (void)*first1; (void)*first2; }
 
 } // namespace std
 
 struct FloatIterator {
-  typedef float value_type;
+  const float &operator*() const;
 };
+
+struct DerivedFloatIterator : public FloatIterator {
+};
+
+template  struct ByValueTemplateIterator {
+  ValueType operator*() const;
+};
+
+template  struct ByRefTemplateIterator {
+  ValueType &operator*();
+};
+
+template  struct ByRefTemplateIteratorWithAlias {
+  using reference = const ValueType&;
+  reference operator*();
+};
+
+template  struct AutoByValueTemplateIterator {
+  auto operator*() const { return ValueType{}; }
+};
+
+template  struct AutoByRefTemplateIterator {
+  decltype(auto) operator*() const { return value_; }
+  ValueType value_;
+};
+
 template 
-struct TypedefTemplateIterator { typedef ValueType value_type; };
-template 
-struct UsingTemplateIterator { using value_type = ValueType; };
-template 
-struct DependentTypedefTemplateIterator { typedef typename ValueType::value_type value_type; };
-template 
-struct DependentUsingTemplateIterator : public TypedefTemplateIterator { using typename TypedefTemplateIterator::value_type; };
+struct InheritingByConstRefTemplateIterator
+: public ByRefTemplateIterator {};
+
 using TypedeffedIterator = FloatIterator;
 
 // Positives.
@@ -51,39 +79,57 @@
 }
 
 int accumulatePositive3() {
+  DerivedFloatIterator it;
+  return std::accumulate(it, it, 0);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'float' into type 'int'
+}
+
+int accumulatePositive4() {
   double a[1] = {0.0};
   return std::accumulate(a, a + 1, 0.0f);
   // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'double' into type 'float'
 }
 
-int accumulatePositive4() {
-  TypedefTemplateIterator it;
+int accumulatePositive5() {
+  ByValueTemplateIterator it;
   return std::accumulate(it, it, 0);
   // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'unsigned int' into type 'int'
 }
 
-int accumulatePositive5() {
-  UsingTemplateIterator it;
+int accumulatePositive6() {
+  ByRefTemplateIterator it;
   return std::accumulate(it, it, 0);
   // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'unsigned int' into type 'int'
 }
 
-int accumulatePositive6() {
-  DependentTypedefTemplateIterator> it;
+int accumulatePositive7() {
+  AutoByValueTemplateIterator it;
   return std::accumulate(it, it, 0);
   // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'unsigned int' into type 'int'
 }
 
-int accumulatePositive7() {
+int accumulatePositive8() {
   TypedeffedIterator it;
   return std::accumulate(it, it, 0);
   // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'float' into type 'int'
 }
 
-int accumulatePositive8() {
-  DependentUsingTemplateIterator it;
+int accumulatePositive9() {
+  InheritingByConstRefTemplateIterator it;
+  return std::accumulate(it, it, 0);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'uns

[PATCH] D147661: [Sema] Tweak merging of availability attributes

2023-04-06 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm updated this revision to Diff 511425.
rsandifo-arm added a comment.

Add AST dump test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147661

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/attr-availability-maccatalyst-dump.c


Index: clang/test/Sema/attr-availability-maccatalyst-dump.c
===
--- /dev/null
+++ clang/test/Sema/attr-availability-maccatalyst-dump.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 "-triple" "x86_64-apple-ios13.1-macabi" -std=c2x 
-fsyntax-only -ast-dump %s | FileCheck %s
+
+void foo() __attribute__((availability(ios,introduced=2.0)));
+void bar [[clang::availability(ios,introduced=2.0)]] ();
+
+// CHECK: FunctionDecl 0x{{[^ ]*}} <{{[^:]*}}:3:1, col:60> col:6 foo
+// CHECK: AvailabilityAttr 0x{{[^ ]*}}  Implicit maccatalyst 
13.1 0 0 "" "" 2
+// CHECK: FunctionDecl 0x{{[^ ]*}} <{{[^:]*}}:4:1, col:55> col:6 bar
+// CHECK: AvailabilityAttr 0x{{[^ ]*}}  Implicit maccatalyst 
13.1 0 0 "" "" 2
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2775,7 +2775,7 @@
 return V;
   };
   AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
-  ND, AL.getRange(), NewII, true /*Implicit*/,
+  ND, AL, NewII, true /*Implicit*/,
   MinMacCatalystVersion(Introduced.Version),
   MinMacCatalystVersion(Deprecated.Version),
   MinMacCatalystVersion(Obsoleted.Version), IsUnavailable, Str,
@@ -2817,7 +2817,7 @@
 return V ? *V : VersionTuple();
   };
   AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
-  ND, AL.getRange(), NewII, true /*Implicit*/,
+  ND, AL, NewII, true /*Implicit*/,
   VersionOrEmptyVersion(NewIntroduced),
   VersionOrEmptyVersion(NewDeprecated),
   VersionOrEmptyVersion(NewObsoleted), /*IsUnavailable=*/false, 
Str,


Index: clang/test/Sema/attr-availability-maccatalyst-dump.c
===
--- /dev/null
+++ clang/test/Sema/attr-availability-maccatalyst-dump.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 "-triple" "x86_64-apple-ios13.1-macabi" -std=c2x -fsyntax-only -ast-dump %s | FileCheck %s
+
+void foo() __attribute__((availability(ios,introduced=2.0)));
+void bar [[clang::availability(ios,introduced=2.0)]] ();
+
+// CHECK: FunctionDecl 0x{{[^ ]*}} <{{[^:]*}}:3:1, col:60> col:6 foo
+// CHECK: AvailabilityAttr 0x{{[^ ]*}}  Implicit maccatalyst 13.1 0 0 "" "" 2
+// CHECK: FunctionDecl 0x{{[^ ]*}} <{{[^:]*}}:4:1, col:55> col:6 bar
+// CHECK: AvailabilityAttr 0x{{[^ ]*}}  Implicit maccatalyst 13.1 0 0 "" "" 2
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2775,7 +2775,7 @@
 return V;
   };
   AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
-  ND, AL.getRange(), NewII, true /*Implicit*/,
+  ND, AL, NewII, true /*Implicit*/,
   MinMacCatalystVersion(Introduced.Version),
   MinMacCatalystVersion(Deprecated.Version),
   MinMacCatalystVersion(Obsoleted.Version), IsUnavailable, Str,
@@ -2817,7 +2817,7 @@
 return V ? *V : VersionTuple();
   };
   AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
-  ND, AL.getRange(), NewII, true /*Implicit*/,
+  ND, AL, NewII, true /*Implicit*/,
   VersionOrEmptyVersion(NewIntroduced),
   VersionOrEmptyVersion(NewDeprecated),
   VersionOrEmptyVersion(NewObsoleted), /*IsUnavailable=*/false, Str,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147661: [Sema] Tweak merging of availability attributes

2023-04-06 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm added a comment.

In D147661#4248574 , @erichkeane 
wrote:

> I think the change is probably fine,

Thanks!

> but can you add an AST-dump test for this one?

Sure.  How does this look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147661

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


[PATCH] D139837: [Clang] Implements CTAD for aggregates P1816R0 and P2082R1

2023-04-06 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@ychen Hey! Are you still working on this? Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139837

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


[PATCH] D147714: [Attr] Introduce [[clang::nonportable_musttail]] as less strict version of [[clang::musttail]]

2023-04-06 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 511427.
xbolva00 added a comment.

Mention it in attribute documentation.


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

https://reviews.llvm.org/D147714

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaStmt.cpp
  clang/test/SemaCXX/attr-musttail.cpp

Index: clang/test/SemaCXX/attr-musttail.cpp
===
--- clang/test/SemaCXX/attr-musttail.cpp
+++ clang/test/SemaCXX/attr-musttail.cpp
@@ -6,6 +6,7 @@
   [[clang::musttail(1, 2)]] return ReturnsInt1(); // expected-error {{'musttail' attribute takes no arguments}}
   [[clang::musttail]] return 5;   // expected-error {{'musttail' attribute requires that the return value is the result of a function call}}
   [[clang::musttail]] return ReturnsInt1();
+  [[clang::nonportable_musttail]] return ReturnsInt1();
 }
 
 void NoFunctionCall() {
@@ -20,6 +21,11 @@
   return NoParams();  // expected-error {{cannot perform a tail call to function 'NoParams' because its signature is incompatible with the calling function}}
 }
 
+void TestParamArityMismatchNonPortable(int x) {
+  [[clang::nonportable_musttail]]
+  return NoParams();
+}
+
 void LongParam(long x); // expected-note {{target function has type mismatch at 1st parameter (expected 'long' but has 'int')}}
 void TestParamTypeMismatch(int x) {
   [[clang::musttail]]  // expected-note {{tail call required by 'musttail' attribute here}}
@@ -267,3 +273,17 @@
 void TestCallNonValue() {
   [[clang::musttail]] return ns; // expected-error {{unexpected namespace name 'ns': expected expression}}
 }
+
+struct Foo {
+  int foo(int) { return 0; }
+};
+
+struct Bar {
+  Foo foo;
+  int bar(int);
+};
+
+int Bar::bar(int x) {
+  [[clang::nonportable_musttail]]
+  return foo.foo(x);
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -586,7 +586,7 @@
   // attributes lands.
   for (const auto *A : Attrs) {
 if (A->getKind() == attr::MustTail) {
-  if (!checkAndRewriteMustTailAttr(SubStmt, *A)) {
+  if (!checkAndRewriteMustTailAttr(SubStmt, *cast(A))) {
 return SubStmt;
   }
   setFunctionHasMustTail();
@@ -608,7 +608,7 @@
   return SubStmt;
 }
 
-bool Sema::checkAndRewriteMustTailAttr(Stmt *St, const Attr &MTA) {
+bool Sema::checkAndRewriteMustTailAttr(Stmt *St, const MustTailAttr &MTA) {
   ReturnStmt *R = cast(St);
   Expr *E = R->getRetValue();
 
@@ -633,7 +633,7 @@
   return true;
 }
 
-bool Sema::checkMustTailAttr(const Stmt *St, const Attr &MTA) {
+bool Sema::checkMustTailAttr(const Stmt *St, const MustTailAttr &MTA) {
   assert(!CurContext->isDependentContext() &&
  "musttail cannot be checked from a dependent context");
 
@@ -846,6 +846,9 @@
 return true;
   };
 
+  if (MTA.isNonPortableMustTail())
+return true;
+
   PartialDiagnostic PD = PDiag(diag::note_musttail_mismatch);
   if (!CheckTypesMatch(CallerType, CalleeType, PD)) {
 if (const auto *ND = dyn_cast_or_null(CE->getCalleeDecl()))
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -12351,12 +12351,12 @@
   /// issuing a diagnostic and returning false if not. In the success case,
   /// the statement is rewritten to remove implicit nodes from the return
   /// value.
-  bool checkAndRewriteMustTailAttr(Stmt *St, const Attr &MTA);
+  bool checkAndRewriteMustTailAttr(Stmt *St, const MustTailAttr &MTA);
 
 private:
   /// Check whether the given statement can have musttail applied to it,
   /// issuing a diagnostic and returning false if not.
-  bool checkMustTailAttr(const Stmt *St, const Attr &MTA);
+  bool checkMustTailAttr(const Stmt *St, const MustTailAttr &MTA);
 
 public:
   /// Check to see if a given expression could have '.c_str()' called on it.
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -605,7 +605,8 @@
 old style K&R C function declarations.
 
 ``clang::musttail`` provides assurances that the tail call can be optimized on
-all targets, not just one.
+all targets, not just one. If you care about one target and you do not need
+these assurances, use ``clang::nonportable_musttail``.
   }];
 }
 
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1470,8 +1470,9 @@
 }
 
 def MustTail : StmtAttr {
-  let Spellings = [Clang<"musttail">];
+  let Spellings = [Clang<"musttail">, Clang<"nonportable_musttail">];
   let Documentation = [MustTailDocs];
+  let Accessors 

[clang] 64fba20 - Revert (2) "[Assignment Tracking] Enable by default"

2023-04-06 Thread via cfe-commits

Author: OCHyams
Date: 2023-04-06T16:32:58+01:00
New Revision: 64fba207a683a355d9059cd57adb8a139c2f5dda

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

LOG: Revert (2) "[Assignment Tracking] Enable by default"

Revert D146987 for the 2nd time.

This reverts commit 91a0740474e3c4fe0bde8ff5699115bf808ca23f

Buildbot: https://lab.llvm.org/buildbot/#/builders/70/builds/36007

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/CodeGen/assignment-tracking/flag.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0e3c7b708071..5e008fc9b26e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5815,7 +5815,7 @@ def experimental_assignment_tracking_EQ : Joined<["-"], 
"fexperimental-assignmen
   Group, CodeGenOpts<"EnableAssignmentTracking">,
   NormalizedValuesScope<"CodeGenOptions::AssignmentTrackingOpts">,
   Values<"disabled,enabled,forced">, 
NormalizedValues<["Disabled","Enabled","Forced"]>,
-  MarshallingInfoEnum, "Enabled">;
+  MarshallingInfoEnum, "Disabled">;
 
 } // let Flags = [CC1Option, NoDriverOption]
 

diff  --git a/clang/test/CodeGen/assignment-tracking/flag.cpp 
b/clang/test/CodeGen/assignment-tracking/flag.cpp
index 3bd974fe07c6..aa1f054dae4d 100644
--- a/clang/test/CodeGen/assignment-tracking/flag.cpp
+++ b/clang/test/CodeGen/assignment-tracking/flag.cpp
@@ -8,10 +8,10 @@
 // RUN: -emit-llvm  %s -o - -fexperimental-assignment-tracking=disabled 
-O1\
 // RUN: | FileCheck %s --check-prefixes=DISABLE
 
- Enabled by default:
+ Disabled by default:
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   
\
 // RUN: -emit-llvm  %s -o - -O1
\
-// RUN: | FileCheck %s --check-prefixes=ENABLE
+// RUN: | FileCheck %s --check-prefixes=DISABLE
 
  Disabled at O0 unless forced.
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   
\



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


[PATCH] D147554: [clang] Mark CWG562 as N/A

2023-04-06 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147554

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


[PATCH] D147549: [clang] Add test for CWG255

2023-04-06 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147549

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


[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-04-06 Thread Felipe de Azevedo Piovezan via Phabricator via cfe-commits
fdeazeve added a comment.

I did some local testing, and this no longer seems to crash for me. Hopefully 
the bots will be fine too


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144651

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


[PATCH] D146399: [AIX][Clang][K] Create `-K` Option for AIX.

2023-04-06 Thread Michael Francis via Phabricator via cfe-commits
francii updated this revision to Diff 511431.
francii added a comment.

Add unsupported target test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146399

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/aix-ld.c
  clang/test/Driver/unsupported-target-K.c


Index: clang/test/Driver/unsupported-target-K.c
===
--- /dev/null
+++ clang/test/Driver/unsupported-target-K.c
@@ -0,0 +1,8 @@
+// Check powerpc64-unknown-linux-gnu. -K not supported.
+// RUN: %clang %s 2>&1 -### \
+// RUN:--target=powerpc64-unknown-linux-gnu \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:-K \
+// RUN:   | FileCheck --check-prefixes=CHECK-K-SUPPORT %s
+// CHECK-K-SUPPORT: clang: error: unsupported option '-K' for target 
'powerpc64-unknown-linux-gnu'
Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -1077,3 +1077,27 @@
 // RUN:-fopenmp=libfoo \
 // RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP-FOO %s
 // CHECK-FOPENMP-FOO: error: unsupported argument 'libfoo' to option 
'-fopenmp='
+
+// Check powerpc-ibm-aix7.1.0.0. -K is a passthrough linker option.
+// RUN: %clang %s 2>&1 -### \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:-K \
+// RUN:   | FileCheck --check-prefixes=CHECK-K %s
+// CHECK-K: "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-K: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-K: "{{.*}}ld{{(.exe)?}}"
+// CHECK-K: "[[SYSROOT]]/usr/lib{{/|}}crt0.o"
+// CHECK-K: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
+// CHECK-K: "-K"
+
+// Check powerpc-ibm-aix7.1.0.0. -K unused when not linking.
+// RUN: %clang %s 2>&1 -### \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:-K \
+// RUN:-c \
+// RUN:   | FileCheck --check-prefixes=CHECK-K-UNUSED %s
+// CHECK-K-UNUSED: clang: warning: -K: 'linker' input unused 
[-Wunused-command-line-argument]
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6328,6 +6328,10 @@
 }
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_K); A && !TC.getTriple().isOSAIX())
+D.Diag(diag::err_drv_unsupported_opt_for_target)
+<< A->getAsString(Args) << TripleStr;
+
   if (Args.getLastArg(options::OPT_fapple_kext) ||
   (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))
 CmdArgs.push_back("-fapple-kext");
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3405,6 +3405,7 @@
   HelpText<"Overlay the virtual filesystem described by file over the real 
file system. "
"Additionally, pass this overlay file to the linker if it supports 
it">;
 def imultilib : Separate<["-"], "imultilib">, Group;
+def K : Flag<["-"], "K">, Flags<[LinkerInput]>;
 def keep__private__externs : Flag<["-"], "keep_private_externs">;
 def l : JoinedOrSeparate<["-"], "l">, Flags<[LinkerInput, RenderJoined]>,
 Group;


Index: clang/test/Driver/unsupported-target-K.c
===
--- /dev/null
+++ clang/test/Driver/unsupported-target-K.c
@@ -0,0 +1,8 @@
+// Check powerpc64-unknown-linux-gnu. -K not supported.
+// RUN: %clang %s 2>&1 -### \
+// RUN:--target=powerpc64-unknown-linux-gnu \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:-K \
+// RUN:   | FileCheck --check-prefixes=CHECK-K-SUPPORT %s
+// CHECK-K-SUPPORT: clang: error: unsupported option '-K' for target 'powerpc64-unknown-linux-gnu'
Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -1077,3 +1077,27 @@
 // RUN:-fopenmp=libfoo \
 // RUN:   | FileCheck --check-prefixes=CHECK-FOPENMP-FOO %s
 // CHECK-FOPENMP-FOO: error: unsupported argument 'libfoo' to option '-fopenmp='
+
+// Check powerpc-ibm-aix7.1.0.0. -K is a passthrough linker option.
+// RUN: %clang %s 2>&1 -### \
+// RUN:--target=powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:--unwindlib=libunwind \
+// RUN:-K \
+// RUN:   | FileCheck --check-prefixes=CHECK-K %s
+// CHECK-K: "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-

[PATCH] D146897: [clang:diagnostics] Turning off warn_self_assignment_overloaded for user-defined compound assignments

2023-04-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:14134
 return;
-
+
 Sema.Diag(Loc, diag::warn_identity_field_assign) << 0;

Spurious whitespace change.



Comment at: clang/test/SemaCXX/warn-self-assign-field-overloaded.cpp:71-91
+this->a *= a;
+this->a /= a; // expected-warning {{assigning field to itself}}
+this->a %= a; // expected-warning {{assigning field to itself}}
+this->a += a;
+this->a -= a; // expected-warning {{assigning field to itself}}
+this->a <<= a;
+this->a >>= a;

The behavior of this diagnostic is almost inscrutable without really sitting 
down to think about it... and I'm not even certain I get the logic for it 
despite thinking about it heavily for a while now. I think my confusion boils 
down to this diagnostic trying to diagnose two different kinds of problems.

Situation 1 is where there's a possible typo and the user meant a different 
object:
```
a /= a;
this->a /= this->a;

// Less-contrived example
a00 /= a01;
a01 /= a02;
a02 /= a02; // Oops, typo!
```
(Note, I think `this->a` and `a` should be handled the same in this case 
because there are coding styles out there that mandate adding `this->` to any 
member lookup, so there's no reason to think that `this->a /= this->a;` is any 
less of a typo than `a /= a;`.)

Situation 2 is where the user is trying to work around the user-unfriendly 
lookup rules of C++, or there is a typo, but got confused because lookup found 
the same object on both sides:
```
this->a /= a;
a /= this->a;

// Less-contrived example
int a;
struct S {
  int a;

  void foo() {
// Divide the member variable by the global variable
this->a /= a; // Oops, that's not how this works in practice
  }

  void bar(int ab) {
// Divide the member variable by the parameter
this->a /= a; // Oops, typo, meant to use 'ab' instead
  }
};
```

So I'm surprised that we'd want to silence the warnings on `a /= a;` as we're 
doing here. Frankly, I think we should be silent on `a *= a;` because that's an 
extremely common way to square a variable, but diagnose almost all the other 
cases with a "did you mean?" diagnostic. `a -= a;` and `a %= a;` are bad ways 
to write `a = 0`, `a += a;` is a bad way to write `a *= 2;` (but might be 
common enough we want to silence it as well), and `a /= a;` is a bad way to 
write `a = 1;` (The bitwise operators may still be reasonable to silence the 
warning on, but even `a &= a;` and `a |= a;` seems like weird no-ops...)

All that said, my understanding of the crux of #42469 is that we wanted to 
silence the warning whenever the operator being used is overloaded because we 
have no idea whether self-assign is intended in that case. So I would expect 
these cases to all consistently not diagnose because they're all using the 
overloaded operator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146897

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


[PATCH] D146463: [CodeGen][RISCV] Change Shadow Call Stack Register to X3

2023-04-06 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

Ok, looks like the consensus I thought we had isn't quite there on the psABI 
thread - Andrew Waterman has some concerns. We should let that discussion play 
out some more.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146463

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


[PATCH] D147572: [Clang][OpenMP] Fix failure with team-wide allocated variable

2023-04-06 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: clang/test/OpenMP/target_team_variable_codegen.cpp:33
+//.
+// CHECK-NVIDIA: @local_a = internal addrspace(3) global [10 x i32] 
zeroinitializer, align 4
+//.

doru1004 wrote:
> jhuber6 wrote:
> > Shouldn't the Nvidia version also be undefined? Not sure why this should 
> > vary depending on the target.
> Perhaps NVIDIA code path can tolerate a zeroinitializer? I don't want to 
> change it if it's not needed. I am basing this check on the code path for AMD 
> GPUs and the initial bug that was reported.
for AS 3 we should make it always poison.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147572

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


[PATCH] D147572: [Clang][OpenMP] Fix failure with team-wide allocated variable

2023-04-06 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/test/OpenMP/target_team_variable_codegen.cpp:33
+//.
+// CHECK-NVIDIA: @local_a = internal addrspace(3) global [10 x i32] 
zeroinitializer, align 4
+//.

jdoerfert wrote:
> doru1004 wrote:
> > jhuber6 wrote:
> > > Shouldn't the Nvidia version also be undefined? Not sure why this should 
> > > vary depending on the target.
> > Perhaps NVIDIA code path can tolerate a zeroinitializer? I don't want to 
> > change it if it's not needed. I am basing this check on the code path for 
> > AMD GPUs and the initial bug that was reported.
> for AS 3 we should make it always poison.
We should probably change this in `HeadToShared` in `OpenMPOpt` as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147572

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


[PATCH] D147717: [C++20][NFC] Claim full support for consteval again

2023-04-06 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

After resolving several outstanding issues now is the time to mark it as
fully supported.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147717

Files:
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/www/cxx_status.html


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1120,14 +1120,7 @@
 
   Immediate functions (consteval)
   https://wg21.link/p1073r3";>P1073R3
-  
-Clang 15 (Partial)
-  Clang still incorrectly defers some consteval executions to runtime,
-  resulting in CodeGen crashes. Additionally, Clang does not properly
-  handle default arguments in consteval functions under all
-  circumstances.
-
-  
+  Clang 17
 

 https://wg21.link/p1937r2";>P1937R2
Index: clang/test/Lexer/cxx-features.cpp
===
--- clang/test/Lexer/cxx-features.cpp
+++ clang/test/Lexer/cxx-features.cpp
@@ -78,8 +78,7 @@
 #error "wrong value for __cpp_conditional_explicit"
 #endif
 
-#if check(consteval, 0, 0, 0, 0, 0, 0)
-// FIXME: 201811 in C++20
+#if check(consteval, 0, 0, 0, 0, 201811, 201811)
 #error "wrong value for __cpp_consteval"
 #endif
 
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -681,7 +681,7 @@
 // Refer to the discussion of this at https://reviews.llvm.org/D128619.
 Builder.defineMacro("__cpp_concepts", "201907L");
 Builder.defineMacro("__cpp_conditional_explicit", "201806L");
-//Builder.defineMacro("__cpp_consteval", "201811L");
+Builder.defineMacro("__cpp_consteval", "201811L");
 Builder.defineMacro("__cpp_constexpr_dynamic_alloc", "201907L");
 Builder.defineMacro("__cpp_constinit", "201907L");
 Builder.defineMacro("__cpp_impl_coroutine", "201902L");


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1120,14 +1120,7 @@
 
   Immediate functions (consteval)
   https://wg21.link/p1073r3";>P1073R3
-  
-Clang 15 (Partial)
-  Clang still incorrectly defers some consteval executions to runtime,
-  resulting in CodeGen crashes. Additionally, Clang does not properly
-  handle default arguments in consteval functions under all
-  circumstances.
-
-  
+  Clang 17
 

 https://wg21.link/p1937r2";>P1937R2
Index: clang/test/Lexer/cxx-features.cpp
===
--- clang/test/Lexer/cxx-features.cpp
+++ clang/test/Lexer/cxx-features.cpp
@@ -78,8 +78,7 @@
 #error "wrong value for __cpp_conditional_explicit"
 #endif
 
-#if check(consteval, 0, 0, 0, 0, 0, 0)
-// FIXME: 201811 in C++20
+#if check(consteval, 0, 0, 0, 0, 201811, 201811)
 #error "wrong value for __cpp_consteval"
 #endif
 
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -681,7 +681,7 @@
 // Refer to the discussion of this at https://reviews.llvm.org/D128619.
 Builder.defineMacro("__cpp_concepts", "201907L");
 Builder.defineMacro("__cpp_conditional_explicit", "201806L");
-//Builder.defineMacro("__cpp_consteval", "201811L");
+Builder.defineMacro("__cpp_consteval", "201811L");
 Builder.defineMacro("__cpp_constexpr_dynamic_alloc", "201907L");
 Builder.defineMacro("__cpp_constinit", "201907L");
 Builder.defineMacro("__cpp_impl_coroutine", "201902L");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147717: [C++20][NFC] Claim full support for consteval again

2023-04-06 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

LGTM.
Thanks for completing this :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147717

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


[PATCH] D147717: [C++20][NFC] Claim full support for consteval again

2023-04-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a subscriber: cjdb.
erichkeane added a comment.

@cjdb has been running some GDB test suites against our compiler: I am 
wondering if we could ask him to try the consteval ones too before we set this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147717

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


[PATCH] D146376: Update static_assert message for redundant cases

2023-04-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from a small nit with the release notes. Do you need someone to land 
this on your behalf? If so, please rebase the patch so it applies cleanly to 
trunk and upload it again, and let me know what name and email address you 
would like used for patch attribution.




Comment at: clang/docs/ReleaseNotes.rst:183
+- Clang now avoids unnecessary diagnostic warnings for obvious expressions in
+  the case of binary operators with logical OR operations.
+  (`#57906 `_)




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146376

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


[PATCH] D147572: [Clang][OpenMP] Fix failure with team-wide allocated variable

2023-04-06 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/test/OpenMP/target_team_variable_codegen.cpp:33
+//.
+// CHECK-NVIDIA: @local_a = internal addrspace(3) global [10 x i32] 
zeroinitializer, align 4
+//.

jhuber6 wrote:
> jdoerfert wrote:
> > doru1004 wrote:
> > > jhuber6 wrote:
> > > > Shouldn't the Nvidia version also be undefined? Not sure why this 
> > > > should vary depending on the target.
> > > Perhaps NVIDIA code path can tolerate a zeroinitializer? I don't want to 
> > > change it if it's not needed. I am basing this check on the code path for 
> > > AMD GPUs and the initial bug that was reported.
> > for AS 3 we should make it always poison.
> We should probably change this in `HeadToShared` in `OpenMPOpt` as well.
Happy to remove the guard and have it always use poison for both NVIDIA and AMD.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147572

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


[PATCH] D147661: [Sema] Tweak merging of availability attributes

2023-04-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

This test doesn't show a change in behavior.  See:

https://godbolt.org/z/vrWM1bTPE

  |-FunctionDecl 0xdbfa5a20 <:3:1, col:60> col:6 foo 'void (void)'
  | |-AvailabilityAttr 0xdbfa5ac8  ios 2.0 0 0 "" "" 0
  | `-AvailabilityAttr 0xdbfa5b80  Implicit maccatalyst 
13.1 0 0 "" "" 2
  `-FunctionDecl 0xdbfa5c80  col:6 bar 'void (void)'
|-AvailabilityAttr 0xdbfa5d28  ios 2.0 0 0 "" "" 0
`-AvailabilityAttr 0xdbfa5de0  Implicit maccatalyst 
13.1 0 0 "" "" 2


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147661

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


[PATCH] D147572: [Clang][OpenMP] Fix failure with team-wide allocated variable

2023-04-06 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 updated this revision to Diff 511436.

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

https://reviews.llvm.org/D147572

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/OpenMP/target_team_variable_codegen.cpp


Index: clang/test/OpenMP/target_team_variable_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_team_variable_codegen.cpp
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals --prefix-filecheck-ir-name _ --global-value-regex 
"llvm.compiler.used" "_[0-9a-zA-Z]+A[0-9a-zA-Z]+pi[0-9a-zA-Z]+" 
"_[0-9a-zA-Z]+anotherPi" --version 2
+// REQUIRES: amdgpu-registered-target
+
+
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host-amd.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple amdgcn-amd-amdhsa 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-target-debug 
-fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-amd.bc -o - | 
FileCheck %s --check-prefix=CHECK-AMD
+
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host-nvidia.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown 
-fopenmp-targets=nvptx64-unknown-unknown -emit-llvm %s -fopenmp-target-debug 
-fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-nvidia.bc -o - | 
FileCheck %s --check-prefix=CHECK-NVIDIA
+
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+typedef enum omp_allocator_handle_t {
+  omp_null_allocator = 0,
+  omp_default_mem_alloc = 1,
+  omp_large_cap_mem_alloc = 2,
+  omp_const_mem_alloc = 3,
+  omp_high_bw_mem_alloc = 4,
+  omp_low_lat_mem_alloc = 5,
+  omp_cgroup_mem_alloc = 6,
+  omp_pteam_mem_alloc = 7,
+  omp_thread_mem_alloc = 8,
+  KMP_ALLOCATOR_MAX_HANDLE = __UINTPTR_MAX__
+} omp_allocator_handle_t;
+
+//.
+// CHECK-AMD: @local_a = internal addrspace(3) global [10 x i32] poison, align 
4
+//.
+// CHECK-NVIDIA: @local_a = internal addrspace(3) global [10 x i32] 
zeroinitializer, align 4
+//.
+int main()
+{
+   int N = 1;
+   int *a = new int[N];
+#pragma omp target data map(tofrom:a[:N])
+   {
+#pragma omp target teams distribute parallel for
+for(int i = 0; i < N; i++)
+{
+  int local_a[10];
+#pragma omp allocate(local_a) allocator(omp_pteam_mem_alloc)
+  for(int j = 0; j < 10; j++)
+   local_a[j] = a[(i + j) % N];
+  a[i] = local_a[0];
+}
+   }
+  return a[17];
+}
+
+#endif
+ NOTE: These prefixes are unused and the list is autogenerated. Do not add 
tests below this line:
+// CHECK-AMD: {{.*}}
+// CHECK-NVIDIA: {{.*}}
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -3351,7 +3351,7 @@
 llvm::Type *VarTy = CGF.ConvertTypeForMem(VD->getType());
 auto *GV = new llvm::GlobalVariable(
 CGM.getModule(), VarTy, /*isConstant=*/false,
-llvm::GlobalValue::InternalLinkage, 
llvm::Constant::getNullValue(VarTy),
+llvm::GlobalValue::InternalLinkage, llvm::PoisonValue::get(VarTy),
 VD->getName(),
 /*InsertBefore=*/nullptr, llvm::GlobalValue::NotThreadLocal,
 CGM.getContext().getTargetAddressSpace(AS));


Index: clang/test/OpenMP/target_team_variable_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_team_variable_codegen.cpp
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals --prefix-filecheck-ir-name _ --global-value-regex "llvm.compiler.used" "_[0-9a-zA-Z]+A[0-9a-zA-Z]+pi[0-9a-zA-Z]+" "_[0-9a-zA-Z]+anotherPi" --version 2
+// REQUIRES: amdgpu-registered-target
+
+
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host-amd.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-target-debug -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-amd.bc -o - | FileCheck %s --check-prefix=CHECK-AMD
+
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host-nvidia.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-unknown-unknown -emit-llvm %s -fopenmp-target-debug -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-nvidia.bc -o - | FileCheck %s --chec

[PATCH] D147572: [Clang][OpenMP] Fix failure with team-wide allocated variable

2023-04-06 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 updated this revision to Diff 511444.

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

https://reviews.llvm.org/D147572

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/OpenMP/target_team_variable_codegen.cpp


Index: clang/test/OpenMP/target_team_variable_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_team_variable_codegen.cpp
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals --prefix-filecheck-ir-name _ --global-value-regex 
"llvm.compiler.used" "_[0-9a-zA-Z]+A[0-9a-zA-Z]+pi[0-9a-zA-Z]+" 
"_[0-9a-zA-Z]+anotherPi" --version 2
+// REQUIRES: amdgpu-registered-target
+
+
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host-amd.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple amdgcn-amd-amdhsa 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-target-debug 
-fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-amd.bc -o - | 
FileCheck %s --check-prefix=CHECK-AMD
+
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host-nvidia.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown 
-fopenmp-targets=nvptx64-unknown-unknown -emit-llvm %s -fopenmp-target-debug 
-fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-nvidia.bc -o - | 
FileCheck %s --check-prefix=CHECK-NVIDIA
+
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+typedef enum omp_allocator_handle_t {
+  omp_null_allocator = 0,
+  omp_default_mem_alloc = 1,
+  omp_large_cap_mem_alloc = 2,
+  omp_const_mem_alloc = 3,
+  omp_high_bw_mem_alloc = 4,
+  omp_low_lat_mem_alloc = 5,
+  omp_cgroup_mem_alloc = 6,
+  omp_pteam_mem_alloc = 7,
+  omp_thread_mem_alloc = 8,
+  KMP_ALLOCATOR_MAX_HANDLE = __UINTPTR_MAX__
+} omp_allocator_handle_t;
+
+//.
+// CHECK-AMD: @local_a = internal addrspace(3) global [10 x i32] poison, align 
4
+//.
+// CHECK-NVIDIA: @local_a = internal addrspace(3) global [10 x i32] poison, 
align 4
+//.
+int main()
+{
+   int N = 1;
+   int *a = new int[N];
+#pragma omp target data map(tofrom:a[:N])
+   {
+#pragma omp target teams distribute parallel for
+for(int i = 0; i < N; i++)
+{
+  int local_a[10];
+#pragma omp allocate(local_a) allocator(omp_pteam_mem_alloc)
+  for(int j = 0; j < 10; j++)
+   local_a[j] = a[(i + j) % N];
+  a[i] = local_a[0];
+}
+   }
+  return a[17];
+}
+
+#endif
+ NOTE: These prefixes are unused and the list is autogenerated. Do not add 
tests below this line:
+// CHECK-AMD: {{.*}}
+// CHECK-NVIDIA: {{.*}}
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -3351,7 +3351,7 @@
 llvm::Type *VarTy = CGF.ConvertTypeForMem(VD->getType());
 auto *GV = new llvm::GlobalVariable(
 CGM.getModule(), VarTy, /*isConstant=*/false,
-llvm::GlobalValue::InternalLinkage, 
llvm::Constant::getNullValue(VarTy),
+llvm::GlobalValue::InternalLinkage, llvm::PoisonValue::get(VarTy),
 VD->getName(),
 /*InsertBefore=*/nullptr, llvm::GlobalValue::NotThreadLocal,
 CGM.getContext().getTargetAddressSpace(AS));


Index: clang/test/OpenMP/target_team_variable_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_team_variable_codegen.cpp
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals --prefix-filecheck-ir-name _ --global-value-regex "llvm.compiler.used" "_[0-9a-zA-Z]+A[0-9a-zA-Z]+pi[0-9a-zA-Z]+" "_[0-9a-zA-Z]+anotherPi" --version 2
+// REQUIRES: amdgpu-registered-target
+
+
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host-amd.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-target-debug -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-amd.bc -o - | FileCheck %s --check-prefix=CHECK-AMD
+
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host-nvidia.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-unknown-unknown -emit-llvm %s -fopenmp-target-debug -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-nvidia.bc -o - | FileCheck %s --check-prefix=

[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-04-06 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:1481
+// To fix this we scan base classes in reverse order to determine
+// overlapping offsets. Wnen found we consider such class as empty
+// base with all fields having [[no_unique_address]] attribute.





Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:1483
+// base with all fields having [[no_unique_address]] attribute.
+for (auto it = base_classes.rbegin(); it != base_classes.rend(); ++it) {
+  clang::CXXRecordDecl *prev_base_decl =

The main problem I still see with this is that if we have something like:
```
struct A : C, B {

};
```

then we mark `C`'s fields as empty and leave `B` as is. This still leads to the 
same crash later on.

Perhaps we should mark we could check the size of the struct and decide based 
on that which one is the "empty" one



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:1498
+ast->getASTContext(), clang::SourceRange()));
+}
 layout_info.base_offsets.insert(std::make_pair(

I think it would still be nice to have this as a private helper function on 
`DWARFASTParserClang`. But don't feel very strongly about it so feel free to 
ignore



Comment at: lldb/test/API/types/TestEmptyBase.py:2
+"""
+Test that recursive types are handled correctly.
+"""

Description needs fixing



Comment at: lldb/test/API/types/TestEmptyBase.py:22
+
+self.sources = {
+'CXX_SOURCES': 'empty_base_type.cpp'}

Ideally this test would live in `lldb/test/API/lang/cpp/no_unique_address/`

The usual structure is that we have a `Makefile` in the same directory which 
consists of:
```
CXX_SOURCES := main.cpp
   
include Makefile.rules 
```

Then in the `test(self)` you just call `self.build()`. You don't need the 
`setUp(self)` and `setTearDownCleanup(...)` calls then.

Check 
`lldb/test/API/commands/expression/inline-namespace/TestInlineNamespace.py` for 
example.



Comment at: lldb/test/API/types/empty_base_type.cpp:1
+struct C
+{

Can we add more test cases. E.g.,:

```
struct A : C, B {
 ...
};
```



Comment at: lldb/test/API/types/empty_base_type.cpp:3
+{
+ long c,d;
+};

Just for sanity checking in the test



Comment at: lldb/test/API/types/empty_base_type.cpp:23
+{
+ long a,b;
+} _a;

same as above


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D147722: [Concepts] Fix Function Template Concepts comparisons

2023-04-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: clang-language-wg, alexander-shaposhnikov.
Herald added a project: All.
erichkeane requested review of this revision.

As reported in GH61959, the patch for https://reviews.llvm.org/D146178
 regressed some comparisons of non-out-of-line function constraints.
 This patch fixes it by making sure we skip the list of template
 arguments from a partial specialization (where they don't really
 matter!).

There was 1 other workaround that was made for checking deduced
arguments that this removes part of.

Fixes: #61959


https://reviews.llvm.org/D147722

Files:
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaTemplate/concepts.cpp


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -825,3 +825,34 @@
   template U> friend constexpr auto decltype(L)::operator()() 
const;
 };
 } // namespace TemplateInsideNonTemplateClass
+
+namespace GH61959 {
+template 
+concept C = (sizeof(T0) >= 4);
+
+template
+struct Orig { };
+
+template
+struct Orig {
+  template requires C
+  void f() { }
+
+  template requires true
+  void f() { }
+};
+
+template  struct Mod {};
+
+template 
+struct Mod {
+  template  requires C
+  constexpr static int f() { return 1; }
+
+  template  requires C
+  constexpr static int f() { return 2; }
+};
+
+static_assert(Mod::f() == 1);
+static_assert(Mod::f() == 2);
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -310,6 +310,16 @@
 if (const auto *VarTemplSpec =
 dyn_cast(CurDecl)) {
   R = HandleVarTemplateSpec(VarTemplSpec, Result, SkipForSpecialization);
+} else if (const auto *PartialClassTemplSpec =
+   dyn_cast(CurDecl)) {
+  // We don't want the arguments from the Partial Specialization, since
+  // anything instantiating here cannot access the arguments from the
+  // specialized template anyway, so any substitution we would do with 
these
+  // partially specialized arguments would 'wrong' and confuse constraint
+  // instantiation. We only do this in the case of a constraint check, 
since
+  // code elsewhere actually uses these and replaces them later with what
+  // they mean.
+  R = Response::UseNextDecl(PartialClassTemplSpec);
 } else if (const auto *ClassTemplSpec =
dyn_cast(CurDecl)) {
   R = HandleClassTemplateSpec(ClassTemplSpec, Result,
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2851,11 +2851,6 @@
 VarTemplatePartialSpecializationDecl *Spec) {
   return !Spec->isClassScopeExplicitSpecialization();
 }
-template <>
-bool DeducedArgsNeedReplacement(
-ClassTemplatePartialSpecializationDecl *Spec) {
-  return !Spec->isClassScopeExplicitSpecialization();
-}
 
 template 
 static Sema::TemplateDeductionResult


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -825,3 +825,34 @@
   template U> friend constexpr auto decltype(L)::operator()() const;
 };
 } // namespace TemplateInsideNonTemplateClass
+
+namespace GH61959 {
+template 
+concept C = (sizeof(T0) >= 4);
+
+template
+struct Orig { };
+
+template
+struct Orig {
+  template requires C
+  void f() { }
+
+  template requires true
+  void f() { }
+};
+
+template  struct Mod {};
+
+template 
+struct Mod {
+  template  requires C
+  constexpr static int f() { return 1; }
+
+  template  requires C
+  constexpr static int f() { return 2; }
+};
+
+static_assert(Mod::f() == 1);
+static_assert(Mod::f() == 2);
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -310,6 +310,16 @@
 if (const auto *VarTemplSpec =
 dyn_cast(CurDecl)) {
   R = HandleVarTemplateSpec(VarTemplSpec, Result, SkipForSpecialization);
+} else if (const auto *PartialClassTemplSpec =
+   dyn_cast(CurDecl)) {
+  // We don't want the arguments from the Partial Specialization, since
+  // anything instantiating here cannot access the arguments from the
+  // specialized template anyway, so any substitution we would do with these
+  // partially specialized arguments would 'wrong' and confuse constraint
+  // instantiation. We only do this in the case of a constraint check, since
+  // code elsewhere actually uses th

[PATCH] D147717: [C++20][NFC] Claim full support for consteval again

2023-04-06 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

In D147717#4248989 , @erichkeane 
wrote:

> @cjdb has been running some GDB test suites against our compiler: I am 
> wondering if we could ask him to try the consteval ones too before we set 
> this?

This is probably a good idea.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147717

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


[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-04-06 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:1483
+// base with all fields having [[no_unique_address]] attribute.
+for (auto it = base_classes.rbegin(); it != base_classes.rend(); ++it) {
+  clang::CXXRecordDecl *prev_base_decl =

Michael137 wrote:
> The main problem I still see with this is that if we have something like:
> ```
> struct A : C, B {
> 
> };
> ```
> 
> then we mark `C`'s fields as empty and leave `B` as is. This still leads to 
> the same crash later on.
> 
> Perhaps we should mark we could check the size of the struct and decide based 
> on that which one is the "empty" one
Interestingly there was a discussion on the DWARF mailing list about this some 
time ago: 
https://www.mail-archive.com/dwarf-discuss@lists.dwarfstd.org/msg00880.html

There might be room to changing the emitted DWARF to make it easier to 
determine the empty structure. I will gauge opinions on this thread later today


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-04-06 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: lldb/test/API/types/TestEmptyBase.py:25-42
+def test(self):
+"""Test that recursive structs are displayed correctly."""
+self.build(dictionary=self.sources)
+self.setTearDownCleanup(dictionary=self.sources)
+self.run_expr()
+
+def run_expr(self):




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D146463: [CodeGen][RISCV] Change Shadow Call Stack Register to X3

2023-04-06 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 511458.
paulkirth added a comment.

Fix formatting and update documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146463

Files:
  clang/docs/ShadowCallStack.rst
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/test/shadowcallstack/lit.cfg.py
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/test/CodeGen/RISCV/reserved-regs.ll
  llvm/test/CodeGen/RISCV/saverestore-scs.ll
  llvm/test/CodeGen/RISCV/shadowcallstack.ll

Index: llvm/test/CodeGen/RISCV/shadowcallstack.ll
===
--- llvm/test/CodeGen/RISCV/shadowcallstack.ll
+++ llvm/test/CodeGen/RISCV/shadowcallstack.ll
@@ -1,7 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=riscv32 -mattr=+reserve-x18 -verify-machineinstrs < %s \
+; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
 ; RUN:   | FileCheck %s --check-prefix=RV32
-; RUN: llc -mtriple=riscv64 -mattr=+reserve-x18 -verify-machineinstrs < %s \
+; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
 ; RUN:   | FileCheck %s --check-prefix=RV64
 
 define void @f1() shadowcallstack {
@@ -34,9 +34,9 @@
 define i32 @f3() shadowcallstack {
 ; RV32-LABEL: f3:
 ; RV32:   # %bb.0:
-; RV32-NEXT:sw ra, 0(s2)
-; RV32-NEXT:addi s2, s2, 4
-; RV32-NEXT:.cfi_escape 0x16, 0x12, 0x02, 0x82, 0x7c #
+; RV32-NEXT:sw ra, 0(gp)
+; RV32-NEXT:addi gp, gp, 4
+; RV32-NEXT:.cfi_escape 0x16, 0x03, 0x02, 0x73, 0x7c #
 ; RV32-NEXT:addi sp, sp, -16
 ; RV32-NEXT:.cfi_def_cfa_offset 16
 ; RV32-NEXT:sw ra, 12(sp) # 4-byte Folded Spill
@@ -44,16 +44,16 @@
 ; RV32-NEXT:call bar@plt
 ; RV32-NEXT:lw ra, 12(sp) # 4-byte Folded Reload
 ; RV32-NEXT:addi sp, sp, 16
-; RV32-NEXT:lw ra, -4(s2)
-; RV32-NEXT:addi s2, s2, -4
-; RV32-NEXT:.cfi_restore s2
+; RV32-NEXT:lw ra, -4(gp)
+; RV32-NEXT:addi gp, gp, -4
+; RV32-NEXT:.cfi_restore gp
 ; RV32-NEXT:ret
 ;
 ; RV64-LABEL: f3:
 ; RV64:   # %bb.0:
-; RV64-NEXT:sd ra, 0(s2)
-; RV64-NEXT:addi s2, s2, 8
-; RV64-NEXT:.cfi_escape 0x16, 0x12, 0x02, 0x82, 0x78 #
+; RV64-NEXT:sd ra, 0(gp)
+; RV64-NEXT:addi gp, gp, 8
+; RV64-NEXT:.cfi_escape 0x16, 0x03, 0x02, 0x73, 0x78 #
 ; RV64-NEXT:addi sp, sp, -16
 ; RV64-NEXT:.cfi_def_cfa_offset 16
 ; RV64-NEXT:sd ra, 8(sp) # 8-byte Folded Spill
@@ -61,9 +61,9 @@
 ; RV64-NEXT:call bar@plt
 ; RV64-NEXT:ld ra, 8(sp) # 8-byte Folded Reload
 ; RV64-NEXT:addi sp, sp, 16
-; RV64-NEXT:ld ra, -8(s2)
-; RV64-NEXT:addi s2, s2, -8
-; RV64-NEXT:.cfi_restore s2
+; RV64-NEXT:ld ra, -8(gp)
+; RV64-NEXT:addi gp, gp, -8
+; RV64-NEXT:.cfi_restore gp
 ; RV64-NEXT:ret
   %res = call i32 @bar()
   %res1 = add i32 %res, 1
@@ -73,72 +73,72 @@
 define i32 @f4() shadowcallstack {
 ; RV32-LABEL: f4:
 ; RV32:   # %bb.0:
-; RV32-NEXT:sw ra, 0(s2)
-; RV32-NEXT:addi s2, s2, 4
-; RV32-NEXT:.cfi_escape 0x16, 0x12, 0x02, 0x82, 0x7c #
+; RV32-NEXT:sw ra, 0(gp)
+; RV32-NEXT:addi gp, gp, 4
+; RV32-NEXT:.cfi_escape 0x16, 0x03, 0x02, 0x73, 0x7c #
 ; RV32-NEXT:addi sp, sp, -16
 ; RV32-NEXT:.cfi_def_cfa_offset 16
 ; RV32-NEXT:sw ra, 12(sp) # 4-byte Folded Spill
 ; RV32-NEXT:sw s0, 8(sp) # 4-byte Folded Spill
 ; RV32-NEXT:sw s1, 4(sp) # 4-byte Folded Spill
-; RV32-NEXT:sw s3, 0(sp) # 4-byte Folded Spill
+; RV32-NEXT:sw s2, 0(sp) # 4-byte Folded Spill
 ; RV32-NEXT:.cfi_offset ra, -4
 ; RV32-NEXT:.cfi_offset s0, -8
 ; RV32-NEXT:.cfi_offset s1, -12
-; RV32-NEXT:.cfi_offset s3, -16
+; RV32-NEXT:.cfi_offset s2, -16
 ; RV32-NEXT:call bar@plt
 ; RV32-NEXT:mv s0, a0
 ; RV32-NEXT:call bar@plt
 ; RV32-NEXT:mv s1, a0
 ; RV32-NEXT:call bar@plt
-; RV32-NEXT:mv s3, a0
+; RV32-NEXT:mv s2, a0
 ; RV32-NEXT:call bar@plt
 ; RV32-NEXT:add s0, s0, s1
-; RV32-NEXT:add a0, s3, a0
+; RV32-NEXT:add a0, s2, a0
 ; RV32-NEXT:add a0, s0, a0
 ; RV32-NEXT:lw ra, 12(sp) # 4-byte Folded Reload
 ; RV32-NEXT:lw s0, 8(sp) # 4-byte Folded Reload
 ; RV32-NEXT:lw s1, 4(sp) # 4-byte Folded Reload
-; RV32-NEXT:lw s3, 0(sp) # 4-byte Folded Reload
+; RV32-NEXT:lw s2, 0(sp) # 4-byte Folded Reload
 ; RV32-NEXT:addi sp, sp, 16
-; RV32-NEXT:lw ra, -4(s2)
-; RV32-NEXT:addi s2, s2, -4
-; RV32-NEXT:.cfi_restore s2
+; RV32-NEXT:lw ra, -4(gp)
+; RV32-NEXT:addi gp, gp, -4
+; RV32-NEXT:.cfi_restore gp
 ; RV32-NEXT:ret
 ;
 ; RV64-LABEL: f4:
 ; RV64:   # %bb.0:
-; RV64-NEXT:sd ra, 0(s2)
-; RV64-NEXT:addi 

[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-06 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik updated this revision to Diff 511460.
philnik marked 4 inline comments as done.
philnik added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147175

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp
  libcxx/include/__algorithm/equal.h
  libcxx/include/__string/constexpr_c_functions.h
  libcxx/include/__type_traits/is_equality_comparable.h
  libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp

Index: libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
===
--- libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
+++ libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
@@ -13,32 +13,32 @@
 enum Enum : int {};
 enum class EnumClass : int {};
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
 struct S {
   char c;
@@ -51,8 +51,8 @@
 struct VirtualBase : virtual S {};
 struct NonVirtualBase : S, S2 {};
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
 // This is trivially_equality_comparable, but we can't detect it currently
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
Index: libcxx/include/__type_traits/is_equality_comparable.h
===
--- libcxx/include/__type_traits/is_equality_comparable.h
+++ libcxx/include/__type_traits/is_equality_comparable.h
@@ -43,14 +43,14 @@
 //   always compared.
 
 template 
-struct __is_trivially_equality_comparable
+struct __libcpp_is_trivially_equality_comparable
 : integral_constant::value && is_inte

[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-06 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

In D147175#4246513 , @aaron.ballman 
wrote:

> Ah, I like this approach -- it keeps things roughly in sync with checking for 
> unique object representations, which is great. I spotted a few questions, but 
> in general this is heading in the right direction. You should also add a 
> release note to clang/docs/ReleaseNotes.rst so that users know there's a new 
> builtin coming.
>
> I suppose one thing to double-check: do you know of any other STL 
> implementations that might be using this identifier as part of their 
> implementation details? (We've had issues in the past where we accidentally 
> stole a reserved identifier that was being used by libstdc++ and it caused 
> issues.)

Neither libstdc++ nor the MSVC STL use the `__is_trivially_equality_comparable` 
AFAICT. A sourcegraph search also exclusively finds libc++: 
https://sourcegraph.com/search?q=context%3Aglobal+__is_trivially_equality_comparable&patternType=standard&sm=1&groupBy=repo
 (which only started using it in this release cycle, so it shouldn't be a 
problem).




Comment at: clang/lib/AST/Type.cpp:2598-2599
+static bool HasDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
+  if (Decl->isUnion())
+return false;
+

aaron.ballman wrote:
> Hmmm, is this correct? I thought there was a defaulted equality comparison 
> operator in this case, but it's defined as deleted.
> 
> http://eel.is/c++draft/class.compare.default#2
> 
> Perhaps this function is looking for a usable defaulted equality comparison 
> operator and not just "does it have one at all"?
Yes, this is looking for a usable one. I've renamed it. (Maybe someone has an 
idea for a better name?)



Comment at: clang/lib/AST/Type.cpp:2616-2617
+  }) &&
+ llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
+   if (!FD->getType()->isRecordType())
+ return true;

aaron.ballman wrote:
> Do we have to look for fields with references per 
> http://eel.is/c++draft/class.compare.default#2 ?
Good catch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147175

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


[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-04-06 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

FYI, this bugfix was attempted back in 2021 here: 
https://reviews.llvm.org/D101237


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D146971: [Sema] Populate declarations inside TypeLocs for some invalid types

2023-04-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 511462.
ilya-biryukov added a comment.

- Add assertions for removed null checks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146971

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Index/complete-blocks.m

Index: clang/test/Index/complete-blocks.m
===
--- clang/test/Index/complete-blocks.m
+++ clang/test/Index/complete-blocks.m
@@ -85,4 +85,4 @@
 // CHECK-CC8: ObjCInstanceMethodDecl:{ResultType id}{TypedText method7:}{Placeholder ^int(int x, int y)b} (35)
 
 // RUN: c-index-test -code-completion-at=%s:59:6 %s | FileCheck -check-prefix=CHECK-CC9 %s
-// CHECK-CC9: ObjCInstanceMethodDecl:{ResultType void}{TypedText foo:}{Placeholder ^int *(int)arg} (35)
+// CHECK-CC9: ObjCInstanceMethodDecl:{ResultType void}{TypedText foo:}{Placeholder ^int *(float)arg} (35)
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -4979,6 +4979,12 @@
   // Walk the DeclTypeInfo, building the recursive type as we go.
   // DeclTypeInfos are ordered from the identifier out, which is
   // opposite of what we want :).
+
+  // Track if the produced type matches the structure of the declarator.
+  // This is used later to decide if we can fill `TypeLoc` from
+  // `DeclaratorChunk`s. E.g. it must be false if Clang recovers from
+  // an error by replacing the type with `int`.
+  bool AreDeclaratorChunksValid = true;
   for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {
 unsigned chunkIndex = e - i - 1;
 state.setCurrentChunkIndex(chunkIndex);
@@ -5172,6 +5178,7 @@
: diag::err_deduced_return_type);
 T = Context.IntTy;
 D.setInvalidType(true);
+AreDeclaratorChunksValid = false;
   } else {
 S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(),
diag::warn_cxx11_compat_deduced_return_type);
@@ -5182,6 +5189,8 @@
 S.Diag(D.getBeginLoc(), diag::err_trailing_return_in_parens)
 << T << D.getSourceRange();
 D.setInvalidType(true);
+// FIXME: recover and fill decls in `TypeLoc`s.
+AreDeclaratorChunksValid = false;
   } else if (D.getName().getKind() ==
  UnqualifiedIdKind::IK_DeductionGuideName) {
 if (T != Context.DependentTy) {
@@ -5189,6 +5198,8 @@
  diag::err_deduction_guide_with_complex_decl)
   << D.getSourceRange();
   D.setInvalidType(true);
+  // FIXME: recover and fill decls in `TypeLoc`s.
+  AreDeclaratorChunksValid = false;
 }
   } else if (D.getContext() != DeclaratorContext::LambdaExpr &&
  (T.hasQualifiers() || !isa(T) ||
@@ -5199,6 +5210,8 @@
diag::err_trailing_return_without_auto)
 << T << D.getDeclSpec().getSourceRange();
 D.setInvalidType(true);
+// FIXME: recover and fill decls in `TypeLoc`s.
+AreDeclaratorChunksValid = false;
   }
   T = S.GetTypeFromParser(FTI.getTrailingReturnType(), &TInfo);
   if (T.isNull()) {
@@ -5239,6 +5252,7 @@
 S.Diag(DeclType.Loc, diagID) << T->isFunctionType() << T;
 T = Context.IntTy;
 D.setInvalidType(true);
+AreDeclaratorChunksValid = false;
   }
 
   // Do not allow returning half FP value.
@@ -5305,6 +5319,8 @@
   ObjCObjectPointerTypeLoc TLoc = TLB.push(T);
   TLoc.setStarLoc(FixitLoc);
   TInfo = TLB.getTypeSourceInfo(Context, T);
+} else {
+  AreDeclaratorChunksValid = false;
 }
 
 D.setInvalidType(true);
@@ -5425,6 +5441,7 @@
   T = (!LangOpts.requiresStrictPrototypes() && !LangOpts.OpenCL)
   ? Context.getFunctionNoProtoType(T, EI)
   : Context.IntTy;
+  AreDeclaratorChunksValid = false;
   break;
 }
 
@@ -5659,9 +5676,13 @@
   if (!ClsType.isNull())
 T = S.BuildMemberPointerType(T, ClsType, DeclType.Loc,
  D.getIdentifier());
+  else
+AreDeclaratorChunksValid = false;
+
   if (T.isNull()) {
 T = Context.IntTy;
 D.setInvalidType(true);
+AreDeclaratorChunksValid = false;
   } else if (DeclType.Mem.TypeQuals) {
 T = S.BuildQualifiedType(T, DeclType.Loc, DeclType.Mem.TypeQuals);
   }
@@ -5679,6 +5700,7 @@
 if (T.isNull()) {
   D.setInvalidType(true);
   T = Context.IntTy;
+  AreDeclaratorChunksValid = false;
 }
 
 // See if there are any a

[PATCH] D146971: [Sema] Populate declarations inside TypeLocs for some invalid types

2023-04-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 511463.
ilya-biryukov added a comment.

- Another forgotten non-null assertion


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146971

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Index/complete-blocks.m

Index: clang/test/Index/complete-blocks.m
===
--- clang/test/Index/complete-blocks.m
+++ clang/test/Index/complete-blocks.m
@@ -85,4 +85,4 @@
 // CHECK-CC8: ObjCInstanceMethodDecl:{ResultType id}{TypedText method7:}{Placeholder ^int(int x, int y)b} (35)
 
 // RUN: c-index-test -code-completion-at=%s:59:6 %s | FileCheck -check-prefix=CHECK-CC9 %s
-// CHECK-CC9: ObjCInstanceMethodDecl:{ResultType void}{TypedText foo:}{Placeholder ^int *(int)arg} (35)
+// CHECK-CC9: ObjCInstanceMethodDecl:{ResultType void}{TypedText foo:}{Placeholder ^int *(float)arg} (35)
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -4979,6 +4979,12 @@
   // Walk the DeclTypeInfo, building the recursive type as we go.
   // DeclTypeInfos are ordered from the identifier out, which is
   // opposite of what we want :).
+
+  // Track if the produced type matches the structure of the declarator.
+  // This is used later to decide if we can fill `TypeLoc` from
+  // `DeclaratorChunk`s. E.g. it must be false if Clang recovers from
+  // an error by replacing the type with `int`.
+  bool AreDeclaratorChunksValid = true;
   for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {
 unsigned chunkIndex = e - i - 1;
 state.setCurrentChunkIndex(chunkIndex);
@@ -5172,6 +5178,7 @@
: diag::err_deduced_return_type);
 T = Context.IntTy;
 D.setInvalidType(true);
+AreDeclaratorChunksValid = false;
   } else {
 S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(),
diag::warn_cxx11_compat_deduced_return_type);
@@ -5182,6 +5189,8 @@
 S.Diag(D.getBeginLoc(), diag::err_trailing_return_in_parens)
 << T << D.getSourceRange();
 D.setInvalidType(true);
+// FIXME: recover and fill decls in `TypeLoc`s.
+AreDeclaratorChunksValid = false;
   } else if (D.getName().getKind() ==
  UnqualifiedIdKind::IK_DeductionGuideName) {
 if (T != Context.DependentTy) {
@@ -5189,6 +5198,8 @@
  diag::err_deduction_guide_with_complex_decl)
   << D.getSourceRange();
   D.setInvalidType(true);
+  // FIXME: recover and fill decls in `TypeLoc`s.
+  AreDeclaratorChunksValid = false;
 }
   } else if (D.getContext() != DeclaratorContext::LambdaExpr &&
  (T.hasQualifiers() || !isa(T) ||
@@ -5199,6 +5210,8 @@
diag::err_trailing_return_without_auto)
 << T << D.getDeclSpec().getSourceRange();
 D.setInvalidType(true);
+// FIXME: recover and fill decls in `TypeLoc`s.
+AreDeclaratorChunksValid = false;
   }
   T = S.GetTypeFromParser(FTI.getTrailingReturnType(), &TInfo);
   if (T.isNull()) {
@@ -5239,6 +5252,7 @@
 S.Diag(DeclType.Loc, diagID) << T->isFunctionType() << T;
 T = Context.IntTy;
 D.setInvalidType(true);
+AreDeclaratorChunksValid = false;
   }
 
   // Do not allow returning half FP value.
@@ -5305,6 +5319,8 @@
   ObjCObjectPointerTypeLoc TLoc = TLB.push(T);
   TLoc.setStarLoc(FixitLoc);
   TInfo = TLB.getTypeSourceInfo(Context, T);
+} else {
+  AreDeclaratorChunksValid = false;
 }
 
 D.setInvalidType(true);
@@ -5425,6 +5441,7 @@
   T = (!LangOpts.requiresStrictPrototypes() && !LangOpts.OpenCL)
   ? Context.getFunctionNoProtoType(T, EI)
   : Context.IntTy;
+  AreDeclaratorChunksValid = false;
   break;
 }
 
@@ -5659,9 +5676,13 @@
   if (!ClsType.isNull())
 T = S.BuildMemberPointerType(T, ClsType, DeclType.Loc,
  D.getIdentifier());
+  else
+AreDeclaratorChunksValid = false;
+
   if (T.isNull()) {
 T = Context.IntTy;
 D.setInvalidType(true);
+AreDeclaratorChunksValid = false;
   } else if (DeclType.Mem.TypeQuals) {
 T = S.BuildQualifiedType(T, DeclType.Loc, DeclType.Mem.TypeQuals);
   }
@@ -5679,6 +5700,7 @@
 if (T.isNull()) {
   D.setInvalidType(true);
   T = Context.IntTy;
+  AreDeclaratorChunksValid = false;
 }
 
 // See if there are any att

[PATCH] D147661: [Sema] Tweak merging of availability attributes

2023-04-06 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm added a comment.

In D147661#4249004 , @erichkeane 
wrote:

> This test doesn't show a change in behavior.

Yeah.  Is there a way to force the syntax and spelling fields to be dumped, 
even for implicit attributes?  I was struggling to find one, which is why I 
wasn't sure this made a difference in practice.

The patch is supposed to be a minor clean-up, since similar calls in 
surrounding code uses `AL` rather than `AL.getRange()`.  The reason I 
originally hit this was that the series I'm working on removes the:

  AttributeCommonInfo(SourceRange)
  AttributeCommonInfo(SourceLocation)

constructors (but keeps the ability to use `FooAttr::CreateImplicit` without 
more than a source range).  It might be easier to explain why that seemed a 
good idea alongside the patches themselves.

The two main uses of these constructors outside tablegen-generated code were 
the two in this patch and the one in https://reviews.llvm.org/D147657.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147661

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


[PATCH] D146971: [Sema] Populate declarations inside TypeLocs for some invalid types

2023-04-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Sorry for taking so long to land this, it fell off my radar.

In D146971#4227482 , @aaron.ballman 
wrote:

> LGTM, though the change should come with a release note. Suggestion you can 
> take or leave as you see fit: should we turn the places where we removed the 
> null pointer check into assertions that the pointer is nonnull? Or are we 
> hoping the crash will be sufficient to tell us when we've missed a case?

Added the check. I think they're useful, at the very least if folks hit them 
they a better chance of finding this change and reaching out to the right 
people.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146971

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


[clang] f27b77e - [Sema] Populate declarations inside TypeLocs for some invalid types

2023-04-06 Thread Ilya Biryukov via cfe-commits

Author: Ilya Biryukov
Date: 2023-04-06T19:02:41+02:00
New Revision: f27b77e5c59a1a907fa45eeb5f2e279a5c8bd17d

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

LOG: [Sema] Populate declarations inside TypeLocs for some invalid types

This also reverts 282cae0b9a602267ad7ef622f770066491332a11 as the
particular crash is now handled by the new code.

Before this change Clang would always leave declarations inside the
type-locs as `null` if the declarator had an invalid type. This patch
populates declarations even for invalid types if the structure of the
type and the type-locs match.

There are certain cases that may still cause crashes. These happen when
Clang recovers the type in a way that is not reflected in the
declarator's structure, e.g. adding a pointer when it was not present in
the code for ObjC interfaces or ignoring pointers written in the code
in C++ with auto return type (`auto* foo() -> int`). Those cases look
fixable with a better recovery strategy and I plan to follow up with
more patches to address those.

The first attempt caused 31 tests from `check-clang` to crash due to
different structure of the types and type-locs after certain errors. The
good news is that the failure is localized and mismatch in structures is
discovered by assertions inside `DeclaratorLocFiller`. Some notable
cases caught by existing tests:
- Invalid chunks when type is fully ignored and replace with int or now.
  Crashed in `C/C2x/n2838.c`.
- Invalid return types in lambdas. Crashed in `CXX/drs/dr6xx.cpp`.
- Invalid member pointers. Crashed in 
`CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3-generic-lambda-1y.cpp`
- ObjC recovery that adds pointers. Crashed in `SemaObjC/blocks.m`

This change also updates the output of `Index/complete-blocks.m`.
Not entirely sure what causes the change, but the new function signature
is closer to the source code, so this seems like an improvement.

Reviewed By: aaron.ballman, erichkeane

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

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaType.cpp
clang/test/Index/complete-blocks.m

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 16f29be4947fb..f66eb9fcf13dc 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -15884,10 +15884,7 @@ bool 
Sema::CheckParmsForFunctionDef(ArrayRef Parameters,
 bool CheckParameterNames) {
   bool HasInvalidParm = false;
   for (ParmVarDecl *Param : Parameters) {
-if (!Param) {
-  HasInvalidParm = true;
-  continue;
-}
+assert(Param && "null in a parameter list");
 // C99 6.7.5.3p4: the parameters in a parameter type list in a
 // function declarator that is part of a function definition of
 // that function shall not have incomplete type.

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 312b6f801c1f0..511e87f229254 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -1712,8 +1712,6 @@ static bool CheckConstexprDestructorSubobjects(Sema 
&SemaRef,
 
 /// Check whether a function's parameter types are all literal types. If so,
 /// return true. If not, produce a suitable diagnostic and return false.
-/// If any ParamDecl is null, return false without producing a diagnostic.
-/// The code creating null parameters is responsible for producing a 
diagnostic.
 static bool CheckConstexprParameterTypes(Sema &SemaRef,
  const FunctionDecl *FD,
  Sema::CheckConstexprKind Kind) {
@@ -1723,8 +1721,7 @@ static bool CheckConstexprParameterTypes(Sema &SemaRef,
   e = FT->param_type_end();
i != e; ++i, ++ArgIndex) {
 const ParmVarDecl *PD = FD->getParamDecl(ArgIndex);
-if (!PD)
-  return false;
+assert(PD && "null in a parameter list");
 SourceLocation ParamLoc = PD->getLocation();
 if (CheckLiteralType(SemaRef, Kind, ParamLoc, *i,
  diag::err_constexpr_non_literal_param, ArgIndex + 1,

diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index a809968b66032..7f9bec2f7627e 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -956,8 +956,7 @@ void Sema::CompleteLambdaCallOperator(
 CheckParmsForFunctionDef(Params, /*CheckParameterNames=*/false);
 Method->setParams(Params);
 for (auto P : Method->parameters()) {
-  if (!P)
-continue;
+  assert(P && "null in a parameter list")

[PATCH] D146971: [Sema] Populate declarations inside TypeLocs for some invalid types

2023-04-06 Thread Ilya Biryukov 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 rGf27b77e5c59a: [Sema] Populate declarations inside TypeLocs 
for some invalid types (authored by ilya-biryukov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146971

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Index/complete-blocks.m

Index: clang/test/Index/complete-blocks.m
===
--- clang/test/Index/complete-blocks.m
+++ clang/test/Index/complete-blocks.m
@@ -85,4 +85,4 @@
 // CHECK-CC8: ObjCInstanceMethodDecl:{ResultType id}{TypedText method7:}{Placeholder ^int(int x, int y)b} (35)
 
 // RUN: c-index-test -code-completion-at=%s:59:6 %s | FileCheck -check-prefix=CHECK-CC9 %s
-// CHECK-CC9: ObjCInstanceMethodDecl:{ResultType void}{TypedText foo:}{Placeholder ^int *(int)arg} (35)
+// CHECK-CC9: ObjCInstanceMethodDecl:{ResultType void}{TypedText foo:}{Placeholder ^int *(float)arg} (35)
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -4979,6 +4979,12 @@
   // Walk the DeclTypeInfo, building the recursive type as we go.
   // DeclTypeInfos are ordered from the identifier out, which is
   // opposite of what we want :).
+
+  // Track if the produced type matches the structure of the declarator.
+  // This is used later to decide if we can fill `TypeLoc` from
+  // `DeclaratorChunk`s. E.g. it must be false if Clang recovers from
+  // an error by replacing the type with `int`.
+  bool AreDeclaratorChunksValid = true;
   for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {
 unsigned chunkIndex = e - i - 1;
 state.setCurrentChunkIndex(chunkIndex);
@@ -5172,6 +5178,7 @@
: diag::err_deduced_return_type);
 T = Context.IntTy;
 D.setInvalidType(true);
+AreDeclaratorChunksValid = false;
   } else {
 S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(),
diag::warn_cxx11_compat_deduced_return_type);
@@ -5182,6 +5189,8 @@
 S.Diag(D.getBeginLoc(), diag::err_trailing_return_in_parens)
 << T << D.getSourceRange();
 D.setInvalidType(true);
+// FIXME: recover and fill decls in `TypeLoc`s.
+AreDeclaratorChunksValid = false;
   } else if (D.getName().getKind() ==
  UnqualifiedIdKind::IK_DeductionGuideName) {
 if (T != Context.DependentTy) {
@@ -5189,6 +5198,8 @@
  diag::err_deduction_guide_with_complex_decl)
   << D.getSourceRange();
   D.setInvalidType(true);
+  // FIXME: recover and fill decls in `TypeLoc`s.
+  AreDeclaratorChunksValid = false;
 }
   } else if (D.getContext() != DeclaratorContext::LambdaExpr &&
  (T.hasQualifiers() || !isa(T) ||
@@ -5199,6 +5210,8 @@
diag::err_trailing_return_without_auto)
 << T << D.getDeclSpec().getSourceRange();
 D.setInvalidType(true);
+// FIXME: recover and fill decls in `TypeLoc`s.
+AreDeclaratorChunksValid = false;
   }
   T = S.GetTypeFromParser(FTI.getTrailingReturnType(), &TInfo);
   if (T.isNull()) {
@@ -5239,6 +5252,7 @@
 S.Diag(DeclType.Loc, diagID) << T->isFunctionType() << T;
 T = Context.IntTy;
 D.setInvalidType(true);
+AreDeclaratorChunksValid = false;
   }
 
   // Do not allow returning half FP value.
@@ -5305,6 +5319,8 @@
   ObjCObjectPointerTypeLoc TLoc = TLB.push(T);
   TLoc.setStarLoc(FixitLoc);
   TInfo = TLB.getTypeSourceInfo(Context, T);
+} else {
+  AreDeclaratorChunksValid = false;
 }
 
 D.setInvalidType(true);
@@ -5425,6 +5441,7 @@
   T = (!LangOpts.requiresStrictPrototypes() && !LangOpts.OpenCL)
   ? Context.getFunctionNoProtoType(T, EI)
   : Context.IntTy;
+  AreDeclaratorChunksValid = false;
   break;
 }
 
@@ -5659,9 +5676,13 @@
   if (!ClsType.isNull())
 T = S.BuildMemberPointerType(T, ClsType, DeclType.Loc,
  D.getIdentifier());
+  else
+AreDeclaratorChunksValid = false;
+
   if (T.isNull()) {
 T = Context.IntTy;
 D.setInvalidType(true);
+AreDeclaratorChunksValid = false;
   } else if (DeclType.Mem.TypeQuals) {
 T = S.BuildQualifiedType(T, DeclType.Loc, DeclType.Mem.TypeQuals);
   }
@@ -5679,6 +5700,7 @@
 if (T.isNull()) {
  

[PATCH] D147661: [Sema] Tweak merging of availability attributes

2023-04-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D147661#4249244 , @rsandifo-arm 
wrote:

> In D147661#4249004 , @erichkeane 
> wrote:
>
>> This test doesn't show a change in behavior.
>
> Yeah.  Is there a way to force the syntax and spelling fields to be dumped, 
> even for implicit attributes?  I was struggling to find one, which is why I 
> wasn't sure this made a difference in practice.
>
> The patch is supposed to be a minor clean-up, since similar calls in 
> surrounding code uses `AL` rather than `AL.getRange()`.  The reason I 
> originally hit this was that the series I'm working on removes the:
>
>   AttributeCommonInfo(SourceRange)
>   AttributeCommonInfo(SourceLocation)
>
> constructors (but keeps the ability to use `FooAttr::CreateImplicit` without 
> more than a source range).  It might be easier to explain why that seemed a 
> good idea alongside the patches themselves.
>
> The two main uses of these constructors outside tablegen-generated code were 
> the two in this patch and the one in https://reviews.llvm.org/D147657.

Ah, hrm... I don't have a really good idea of how to test this now then.  
Typically you'd have to do manual dump logic for an attribute like this i 
think?  Perhaps @aaron.ballman knows better.  I see the value to this, but I 
guess I want to see if we can capture the change somehow in a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147661

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


[PATCH] D146463: [CodeGen][RISCV] Change Shadow Call Stack Register to X3

2023-04-06 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 511466.
paulkirth marked 2 inline comments as done.
paulkirth added a comment.

Remove extra line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146463

Files:
  clang/docs/ShadowCallStack.rst
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/test/shadowcallstack/lit.cfg.py
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/test/CodeGen/RISCV/reserved-regs.ll
  llvm/test/CodeGen/RISCV/saverestore-scs.ll
  llvm/test/CodeGen/RISCV/shadowcallstack.ll

Index: llvm/test/CodeGen/RISCV/shadowcallstack.ll
===
--- llvm/test/CodeGen/RISCV/shadowcallstack.ll
+++ llvm/test/CodeGen/RISCV/shadowcallstack.ll
@@ -1,7 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=riscv32 -mattr=+reserve-x18 -verify-machineinstrs < %s \
+; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
 ; RUN:   | FileCheck %s --check-prefix=RV32
-; RUN: llc -mtriple=riscv64 -mattr=+reserve-x18 -verify-machineinstrs < %s \
+; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
 ; RUN:   | FileCheck %s --check-prefix=RV64
 
 define void @f1() shadowcallstack {
@@ -34,9 +34,9 @@
 define i32 @f3() shadowcallstack {
 ; RV32-LABEL: f3:
 ; RV32:   # %bb.0:
-; RV32-NEXT:sw ra, 0(s2)
-; RV32-NEXT:addi s2, s2, 4
-; RV32-NEXT:.cfi_escape 0x16, 0x12, 0x02, 0x82, 0x7c #
+; RV32-NEXT:sw ra, 0(gp)
+; RV32-NEXT:addi gp, gp, 4
+; RV32-NEXT:.cfi_escape 0x16, 0x03, 0x02, 0x73, 0x7c #
 ; RV32-NEXT:addi sp, sp, -16
 ; RV32-NEXT:.cfi_def_cfa_offset 16
 ; RV32-NEXT:sw ra, 12(sp) # 4-byte Folded Spill
@@ -44,16 +44,16 @@
 ; RV32-NEXT:call bar@plt
 ; RV32-NEXT:lw ra, 12(sp) # 4-byte Folded Reload
 ; RV32-NEXT:addi sp, sp, 16
-; RV32-NEXT:lw ra, -4(s2)
-; RV32-NEXT:addi s2, s2, -4
-; RV32-NEXT:.cfi_restore s2
+; RV32-NEXT:lw ra, -4(gp)
+; RV32-NEXT:addi gp, gp, -4
+; RV32-NEXT:.cfi_restore gp
 ; RV32-NEXT:ret
 ;
 ; RV64-LABEL: f3:
 ; RV64:   # %bb.0:
-; RV64-NEXT:sd ra, 0(s2)
-; RV64-NEXT:addi s2, s2, 8
-; RV64-NEXT:.cfi_escape 0x16, 0x12, 0x02, 0x82, 0x78 #
+; RV64-NEXT:sd ra, 0(gp)
+; RV64-NEXT:addi gp, gp, 8
+; RV64-NEXT:.cfi_escape 0x16, 0x03, 0x02, 0x73, 0x78 #
 ; RV64-NEXT:addi sp, sp, -16
 ; RV64-NEXT:.cfi_def_cfa_offset 16
 ; RV64-NEXT:sd ra, 8(sp) # 8-byte Folded Spill
@@ -61,9 +61,9 @@
 ; RV64-NEXT:call bar@plt
 ; RV64-NEXT:ld ra, 8(sp) # 8-byte Folded Reload
 ; RV64-NEXT:addi sp, sp, 16
-; RV64-NEXT:ld ra, -8(s2)
-; RV64-NEXT:addi s2, s2, -8
-; RV64-NEXT:.cfi_restore s2
+; RV64-NEXT:ld ra, -8(gp)
+; RV64-NEXT:addi gp, gp, -8
+; RV64-NEXT:.cfi_restore gp
 ; RV64-NEXT:ret
   %res = call i32 @bar()
   %res1 = add i32 %res, 1
@@ -73,72 +73,72 @@
 define i32 @f4() shadowcallstack {
 ; RV32-LABEL: f4:
 ; RV32:   # %bb.0:
-; RV32-NEXT:sw ra, 0(s2)
-; RV32-NEXT:addi s2, s2, 4
-; RV32-NEXT:.cfi_escape 0x16, 0x12, 0x02, 0x82, 0x7c #
+; RV32-NEXT:sw ra, 0(gp)
+; RV32-NEXT:addi gp, gp, 4
+; RV32-NEXT:.cfi_escape 0x16, 0x03, 0x02, 0x73, 0x7c #
 ; RV32-NEXT:addi sp, sp, -16
 ; RV32-NEXT:.cfi_def_cfa_offset 16
 ; RV32-NEXT:sw ra, 12(sp) # 4-byte Folded Spill
 ; RV32-NEXT:sw s0, 8(sp) # 4-byte Folded Spill
 ; RV32-NEXT:sw s1, 4(sp) # 4-byte Folded Spill
-; RV32-NEXT:sw s3, 0(sp) # 4-byte Folded Spill
+; RV32-NEXT:sw s2, 0(sp) # 4-byte Folded Spill
 ; RV32-NEXT:.cfi_offset ra, -4
 ; RV32-NEXT:.cfi_offset s0, -8
 ; RV32-NEXT:.cfi_offset s1, -12
-; RV32-NEXT:.cfi_offset s3, -16
+; RV32-NEXT:.cfi_offset s2, -16
 ; RV32-NEXT:call bar@plt
 ; RV32-NEXT:mv s0, a0
 ; RV32-NEXT:call bar@plt
 ; RV32-NEXT:mv s1, a0
 ; RV32-NEXT:call bar@plt
-; RV32-NEXT:mv s3, a0
+; RV32-NEXT:mv s2, a0
 ; RV32-NEXT:call bar@plt
 ; RV32-NEXT:add s0, s0, s1
-; RV32-NEXT:add a0, s3, a0
+; RV32-NEXT:add a0, s2, a0
 ; RV32-NEXT:add a0, s0, a0
 ; RV32-NEXT:lw ra, 12(sp) # 4-byte Folded Reload
 ; RV32-NEXT:lw s0, 8(sp) # 4-byte Folded Reload
 ; RV32-NEXT:lw s1, 4(sp) # 4-byte Folded Reload
-; RV32-NEXT:lw s3, 0(sp) # 4-byte Folded Reload
+; RV32-NEXT:lw s2, 0(sp) # 4-byte Folded Reload
 ; RV32-NEXT:addi sp, sp, 16
-; RV32-NEXT:lw ra, -4(s2)
-; RV32-NEXT:addi s2, s2, -4
-; RV32-NEXT:.cfi_restore s2
+; RV32-NEXT:lw ra, -4(gp)
+; RV32-NEXT:addi gp, gp, -4
+; RV32-NEXT:.cfi_restore gp
 ; RV32-NEXT:ret
 ;
 ; RV64-LABEL: f4:
 ; RV64:   # %bb.0:
-; RV64-NEXT:sd ra, 0(s2)

[PATCH] D147714: [Attr] Introduce [[clang::nonportable_musttail]] as less strict version of [[clang::musttail]]

2023-04-06 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a subscriber: nickdesaulniers.
efriedma added a comment.

Any thoughts on diagnostics here?  If I'm not mistaken, with this patch, if you 
request an impossible tail call, you get a crash with very little useful 
information.  (Although, see 
https://discourse.llvm.org/t/rfc-improving-clangs-middle-and-back-end-diagnostics/69261
 )


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

https://reviews.llvm.org/D147714

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


[PATCH] D146897: [clang:diagnostics] Turning off warn_self_assignment_overloaded for user-defined compound assignments

2023-04-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Yeah, I feel there are three ideas here:

- Clang should warn about self simple assignment in all cases, because it's 
probably a mistake.  We can assume it's a mistake because it's reasonable to 
assume that the simple assignment operator behaves like a value assignment, 
even if it's user-defined, and overwriting a value with itself is a pointless 
operation.
- Clang should warn about self compound assignment when the type is arithmetic 
for these specific operators where algebraically `x OP x` would yield a 
constant value, because it's probably a mistake.  This is because we know the 
exact behavior of the operator, and producing a constant value by cancellation 
is a pointless operation.
- Clang should warn about inconsistent use of `this` on self compound 
assignment for all operators, because it's probably a mistake.  This is because 
the implication of writing the member reference two different ways is that 
there are two different variables in play, but in fact there are not.

The third idea seems like a valuable warning, but it's basically a *different* 
warning and shouldn't be lumped into this one.  I understand the instinct to 
carve it out here so that we don't regress on warning about it, but I think we 
should just do it separately.  And we should do it much more generally, because 
there's no reason that logic is limited to just these specific compound 
operators, or in fact to any individual operator; we should probably warn about 
all inconsistent references to the same variable within a single statement. 
(I'd draw the line at statement boundaries, though, because requiring 
function-wide consistency could be really noisy.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146897

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


[PATCH] D147714: [Attr] Introduce [[clang::nonportable_musttail]] as less strict version of [[clang::musttail]]

2023-04-06 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

In D147714#4249274 , @efriedma wrote:

> Any thoughts on diagnostics here?  If I'm not mistaken, with this patch, if 
> you request an impossible tail call, you get a crash with very little useful 
> information.  (Although, see 
> https://discourse.llvm.org/t/rfc-improving-clangs-middle-and-back-end-diagnostics/69261
>  )

Yes, something like:

  fatal error: error in backend: failed to perform tail call elimination on a 
call site marked musttail

It seems it would be possible to return also "reason" from 
IsEligibleForTailCallOptimization. On the other hand, 
IsEligibleForTailCallOptimization is implemented by many backends, so quite a 
lot of work, so for now maybe we could improve it atleast for X86 / ARM?


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

https://reviews.llvm.org/D147714

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


[PATCH] D147481: [M68k] Add basic Clang supports for M68881/2

2023-04-06 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 511477.
myhsu marked 2 inline comments as done.
myhsu added a comment.

- Explicit add `isa-68882` even for newer (>=68040) CPUs. Such that's it's a 
lot easier to conditionally add related macro definitions with 
TargetOptions::FeatureMap
- Add cases to test the absent of HAVE_68881 macro definitions


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

https://reviews.llvm.org/D147481

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/Driver/ToolChains/Arch/M68k.cpp
  clang/lib/Driver/ToolChains/Arch/M68k.h
  clang/test/Driver/m68k-features.cpp
  clang/test/Driver/m68k-macros.cpp

Index: clang/test/Driver/m68k-macros.cpp
===
--- clang/test/Driver/m68k-macros.cpp
+++ clang/test/Driver/m68k-macros.cpp
@@ -1,10 +1,19 @@
 // Check macro definitions
-// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s
+
+// Since '__HAVE_68881__' sorted before most of the 'mc680x0' macros, we need to put it here.
+// CHECK-MX881: #define __HAVE_68881__ 1
+// CHECK-NOMX881-NOT: #define __HAVE_68881__ 1
+
+// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefixes=CHECK-MX,CHECK-NOMX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68000 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68000 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
 // CHECK-MX: #define __mc68000 1
 // CHECK-MX: #define __mc68000__ 1
 // CHECK-MX: #define mc68000 1
 
-// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefixes=CHECK-MX10,CHECK-NOMX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68010 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s
 // CHECK-MX10: #define __mc68000 1
 // CHECK-MX10: #define __mc68000__ 1
 // CHECK-MX10: #define __mc68010 1
@@ -12,7 +21,8 @@
 // CHECK-MX10: #define mc68000 1
 // CHECK-MX10: #define mc68010 1
 
-// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s
+// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefixes=CHECK-MX20,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68020 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX20: #define __mc68000 1
 // CHECK-MX20: #define __mc68000__ 1
 // CHECK-MX20: #define __mc68020 1
@@ -20,7 +30,8 @@
 // CHECK-MX20: #define mc68000 1
 // CHECK-MX20: #define mc68020 1
 
-// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s
+// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefixes=CHECK-MX30,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68030 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX30: #define __mc68000 1
 // CHECK-MX30: #define __mc68000__ 1
 // CHECK-MX30: #define __mc68030 1
@@ -28,7 +39,8 @@
 // CHECK-MX30: #define mc68000 1
 // CHECK-MX30: #define mc68030 1
 
-// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefix=CHECK-MX40 %s
+// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefixes=CHECK-MX40,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68040 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX40: #define __mc68000 1
 // CHECK-MX40: #define __mc68000__ 1
 // CHECK-MX40: #define __mc68040 1
@@ -36,7 +48,8 @@
 // CHECK-MX40: #define mc68000 1
 // CHECK-MX40: #define mc68040 1
 
-// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefix=CHECK-MX60 %s
+// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefixes=CHECK-MX60,CHECK-MX881 %s
+// RUN: %clang -target m68k-unknown-linux -m68060 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s
 // CHECK-MX60: #define __mc68000 1
 // CHECK-MX60: #define __mc68000__ 1
 // CHECK-MX60: #define __mc68060 1
Index: clang/test/Driver/m68k-features.cpp
===
--- clang/test/Driver/m68k-features.cpp
+++ clang/test/Driver/m68k-features.cpp
@@ -59,3 +59,23 @@
 // RUN: FileCheck --check-prefix=CHECK-FIXED-D7 < %t %s
 // CHECK-FIXED-D7: "-target-feature" "+reserve-d7"
 
+//  Floating point 
+// RUN: %clang -target m68k -m68000 -mhard-float -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+// RUN: %clang -target m68k -m68000 -m68881 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s
+
+// RUN: %clang -target m68k -m68010 -

  1   2   >