[lld] [clang] [clang-tools-extra] [llvm] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-11 Thread Clement Courbet via cfe-commits


@@ -112,9 +116,11 @@ class Counter {
   PerfEvent Event;
   int FileDescriptor = -1;
   bool IsDummyEvent;
+  std::vector ValidationEvents;

legrosbuffle wrote:

OK, let's rename `Counter` to `CounterGroup`, but let's at least create a 
(private) abstraction for an event and attached FD, to avoid the aligned arrays 
code duplication in `Counter::initRealEvent`:

```
  struct ConfiguredEvent {
llvm::Error init(const pid_t ProcessID, const int GroupFd) {
  constexpr  int Cpu = -1; // measure any processor.
  constexpr int GroupFd = -1; // no grouping of counters.
  constexpr uint32_t Flags = 0;
  perf_event_attr AttrCopy = *Event.attribute();
  FileDescriptor = perf_event_open(, ProcessID, Cpu, GroupFd, 
Flags);
  if (FileDescriptor == -1) {
return ...;
  }
};
PerfEvent Event;
int FileDescriptor = -1;
  };
  // The main event, configured as an ungrouped event.
  ConfiguredEvent MainEvent;
  bool IsDummyEvent;
  // A set of optional validation events grouped into the file descriptor for
  // `MainEvent` using `PERF_IOC_FLAG_GROUP`.
  std::vector ValidationEvents;
```

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


[clang] 9d97247 - [clang] Fix color consistency in C paper tracking web page

2024-01-11 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2024-01-11T10:23:37+01:00
New Revision: 9d97247e26eaca29bf27c842e08bd983a34fab93

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

LOG: [clang] Fix color consistency in C paper tracking web page

Added: 


Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index fe56bc791ccbe1..b9e0650ddca242 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -9,7 +9,7 @@
 .none { background-color: #FF }
 .partial { background-color: #FFE0B0 }
 .unreleased { background-color: #99 }
-.unknown { background-color: #DDAEF7 }
+.unknown { background-color: #EBCAFE }
 .full { background-color: #CCFF99 }
 .na { background-color: #DD }
 :target { background-color: #BB; outline: #55 solid thin; }



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


[clang] [llvm] [clang][Driver] Don't ignore -gmodules .gch files (PR #77711)

2024-01-11 Thread via cfe-commits

zmodem wrote:

Thanks for looking into this. I wasn't aware of `-gmodules` relying on "gch 
probing" when I wrote the previous patch.

It seems unfortunate to make `maybeHasClangPchSignature` so broad as to return 
true for any file format that we recognize. Would it be possible to at least 
tighten it to only consider the kind of object files which could have a 
clangast section? Or is that list too long? What does the code that reads these 
files look like, could we leverage that somehow?

An alternative would be turn the logic around, and only ignore GCC PCH files (I 
believe they all start with the file magic `gpch`). However I do think that the 
current approach of "whitelisting" the kind of file we're looking for is better.

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


[clang] [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker (PR #77580)

2024-01-11 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/77580

>From cb79cad6837dba5d33476c65923ec714507a3fef Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Wed, 10 Jan 2024 19:00:27 +0800
Subject: [PATCH 1/5] [clang][analyzer] Support 'tello' and 'fseeko' in the
 StreamChecker

---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp |  4 +
 .../Analysis/Inputs/system-header-simulator.h |  3 +
 clang/test/Analysis/stream-error.c| 82 +++
 3 files changed, 89 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index fbfa101257d5e1..f6e6f3122f3aa7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -268,8 +268,12 @@ class StreamChecker : public Checker= 0)) {
+clang_analyzer_eval(Ret == -1L); // expected-warning {{TRUE}}
+  }
+  fclose(F);
+}
+
+void error_ftello(void) {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  off_t Ret = ftello(F);
+  if (!(Ret == -1)) {
+clang_analyzer_eval(Ret >= 0);   // expected-warning {{TRUE}}
+  }
+  fclose(F);
+}
+
 void error_fflush_after_fclose(void) {
   FILE *F = tmpfile();
   int Ret;

>From ac08796261b3970d9a99c4ac6a2c0e7331620944 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Thu, 11 Jan 2024 09:44:08 +0800
Subject: [PATCH 2/5] [clang][analyzer] Support 'tello' and 'fseeko' in the
 StreamChecker

---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 10 ++---
 clang/test/Analysis/stream-error.c| 39 ++-
 2 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index f6e6f3122f3aa7..742426a628e065 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -1117,10 +1117,10 @@ void StreamChecker::evalFtell(const FnDescription 
*Desc, const CallEvent ,
   NonLoc RetVal = makeRetVal(C, CE).castAs();
   ProgramStateRef StateNotFailed =
   State->BindExpr(CE, C.getLocationContext(), RetVal);
-  auto Cond = SVB.evalBinOp(State, BO_GE, RetVal,
-SVB.makeZeroVal(C.getASTContext().LongTy),
-SVB.getConditionType())
-  .getAs();
+  auto Cond =
+  SVB.evalBinOp(State, BO_GE, RetVal, 
SVB.makeZeroVal(Call.getResultType()),
+SVB.getConditionType())
+  .getAs();
   if (!Cond)
 return;
   StateNotFailed = StateNotFailed->assume(*Cond, true);
@@ -1128,7 +1128,7 @@ void StreamChecker::evalFtell(const FnDescription *Desc, 
const CallEvent ,
 return;
 
   ProgramStateRef StateFailed = State->BindExpr(
-  CE, C.getLocationContext(), SVB.makeIntVal(-1, 
C.getASTContext().LongTy));
+  CE, C.getLocationContext(), SVB.makeIntVal(-1, Call.getResultType()));
 
   // This function does not affect the stream state.
   // Still we add success and failure state with the appropriate return value.
diff --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index 1b14fc2eee2003..5cd6ef4bb7424d 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -348,9 +348,6 @@ void error_fseek_0(void) {
   } else {
 clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
 clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
-// Error flags should not change.
-clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
-clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
   }
   fclose(F);
 }
@@ -368,12 +365,6 @@ void error_fseeko_0(void) {
 // expected-warning@-2 {{TRUE}}
 clang_analyzer_eval(IsFEof);
 // expected-warning@-1 {{FALSE}}
-// Error flags should not change.
-clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
-if (IsFError)
-  clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
-else
-  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
   } else {
 clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
 clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
@@ -388,21 +379,33 @@ void error_ftell(void) {
   FILE *F = fopen("file", "r");
   if (!F)
 return;
-  long Ret = ftell(F);
-  if (!(Ret >= 0)) {
-clang_analyzer_eval(Ret == -1L); // expected-warning {{TRUE}}
-  }
+  long rc = ftell(F);
+  if (rc >= 0)
+clang_analyzer_warnIfReached();  // expected-warning {{REACHABLE}}
+  else
+clang_analyzer_eval(rc == -1);   // expected-warning {{TRUE}}
+  clang_analyzer_eval(feof(F) && ferror(F)); // expected-warning {{FALSE}}
+  StreamTesterChecker_make_feof_stream(F);
+  rc = ftell(F);
+  clang_analyzer_eval(feof(F));  // expected-warning {{TRUE}}
+  clang_analyzer_eval(ferror(F));// expected-warning {{FALSE}}
+  

[clang] [clang][Interp] Implement IntegralAP::{div, rem} (PR #72614)

2024-01-11 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [llvm] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-11 Thread Nemanja Ivanovic via cfe-commits

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

My comments have been addressed, so this LGTM. I'll of course defer to @asb and 
@topperc for final approval.

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


[clang] [llvm] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-11 Thread Nemanja Ivanovic via cfe-commits


@@ -985,9 +1003,10 @@ void 
RISCVFrameLowering::determineCalleeSaves(MachineFunction ,
 };
 
 for (auto Reg : CSRegs)
-  SavedRegs.set(Reg);
+  if (Reg < RISCV::X16 || !Subtarget.isRVE())

nemanjai wrote:

Sounds good. Maybe just a little comment here to demonstrate to the user that 
this isn't an omission but a conscious decision.

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-11 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

Update: 

Previously we will always try to load the specializations with the
corresponding arguments before finding the specializations. This
requires to hash the template arguments.

This patch tries to improve this by trying to load the specializations
only if we can't find it locally.

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-11 Thread Chuanqi Xu via cfe-commits

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

>From 50fd47f2bfda527807f8cc5e46425050246868aa Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 3 Jan 2024 11:33:17 +0800
Subject: [PATCH 1/3] Load Specializations Lazily

---
 clang/include/clang/AST/DeclTemplate.h|  35 ++--
 clang/include/clang/AST/ExternalASTSource.h   |   6 +
 clang/include/clang/AST/ODRHash.h |   3 +
 .../clang/Sema/MultiplexExternalSemaSource.h  |   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/include/clang/Serialization/ASTReader.h |  28 +++
 clang/include/clang/Serialization/ASTWriter.h |   6 +
 clang/lib/AST/DeclTemplate.cpp|  67 +---
 clang/lib/AST/ExternalASTSource.cpp   |   5 +
 clang/lib/AST/ODRHash.cpp |   2 +
 .../lib/Sema/MultiplexExternalSemaSource.cpp  |   6 +
 clang/lib/Serialization/ASTReader.cpp | 125 +-
 clang/lib/Serialization/ASTReaderDecl.cpp |  35 +++-
 clang/lib/Serialization/ASTReaderInternals.h  |  80 +
 clang/lib/Serialization/ASTWriter.cpp | 144 +++-
 clang/lib/Serialization/ASTWriterDecl.cpp |  78 ++---
 clang/test/Modules/odr_hash.cpp   |   4 +-
 clang/unittests/Serialization/CMakeLists.txt  |   1 +
 .../Serialization/LoadSpecLazily.cpp  | 159 ++
 19 files changed, 728 insertions(+), 65 deletions(-)
 create mode 100644 clang/unittests/Serialization/LoadSpecLazily.cpp

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 832ad2de6b08a8..4699dd17bc182c 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -525,8 +525,11 @@ class FunctionTemplateSpecializationInfo final
 return Function.getInt();
   }
 
+  void loadExternalRedecls();
+
 public:
   friend TrailingObjects;
+  friend class ASTReader;
 
   static FunctionTemplateSpecializationInfo *
   Create(ASTContext , FunctionDecl *FD, FunctionTemplateDecl *Template,
@@ -789,13 +792,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 return SpecIterator(isEnd ? Specs.end() : Specs.begin());
   }
 
-  void loadLazySpecializationsImpl() const;
+  void loadExternalSpecializations() const;
 
   template 
   typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector ,
  void *, ProfileArguments &&...ProfileArgs);
 
+  void loadLazySpecializationsWithArgs(ArrayRef 
TemplateArgs);
+
   template 
   void addSpecializationImpl(llvm::FoldingSetVector ,
  EntryType *Entry, void *InsertPos);
@@ -814,9 +819,13 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 /// If non-null, points to an array of specializations (including
 /// partial specializations) known only by their external declaration IDs.
 ///
+/// These specializations needs to be loaded at once in
+/// loadExternalSpecializations to complete the redecl chain or be 
preparing
+/// for template resolution.
+///
 /// The first value in the array is the number of specializations/partial
 /// specializations that follow.
-uint32_t *LazySpecializations = nullptr;
+uint32_t *ExternalSpecializations = nullptr;
 
 /// The set of "injected" template arguments used within this
 /// template.
@@ -850,6 +859,8 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   friend class ASTDeclWriter;
   friend class ASTReader;
   template  friend class RedeclarableTemplate;
+  friend class ClassTemplateSpecializationDecl;
+  friend class VarTemplateSpecializationDecl;
 
   /// Retrieves the canonical declaration of this template.
   RedeclarableTemplateDecl *getCanonicalDecl() override {
@@ -977,6 +988,7 @@ SpecEntryTraits {
 class FunctionTemplateDecl : public RedeclarableTemplateDecl {
 protected:
   friend class FunctionDecl;
+  friend class FunctionTemplateSpecializationInfo;
 
   /// Data that is common to all of the declarations of a given
   /// function template.
@@ -1012,13 +1024,13 @@ class FunctionTemplateDecl : public 
RedeclarableTemplateDecl {
   void addSpecialization(FunctionTemplateSpecializationInfo* Info,
  void *InsertPos);
 
+  /// Load any lazily-loaded specializations from the external source.
+  void LoadLazySpecializations() const;
+
 public:
   friend class ASTDeclReader;
   friend class ASTDeclWriter;
 
-  /// Load any lazily-loaded specializations from the external source.
-  void LoadLazySpecializations() const;
-
   /// Get the underlying function declaration of the template.
   FunctionDecl *getTemplatedDecl() const {
 return static_cast(TemplatedDecl);
@@ -1839,6 +1851,8 @@ class ClassTemplateSpecializationDecl
   LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
   unsigned SpecializationKind : 3;
 
+  void loadExternalRedecls();
+
 protected:
   ClassTemplateSpecializationDecl(ASTContext , Kind DK, 

[compiler-rt] [flang] [openmp] [clang-tools-extra] [mlir] [clang] [lldb] [llvm] [lld] [libunwind] [BranchFolding] Fix missing predecessors of landing-pad (PR #77608)

2024-01-11 Thread Phoebe Wang via cfe-commits


@@ -1624,6 +1632,15 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) 
{
 } else {
   DidChange = true;
   PMBB->ReplaceUsesOfBlockWith(MBB, CurTBB);
+  // Add rest successors of MBB to successors of CurTBB. Those
+  // successors are not directly reachable via MBB, so it should be
+  // landing-pad.
+  for (auto SI = MBB->succ_begin(), SE = MBB->succ_end(); SI != SE;
+   ++SI)
+if (*SI != CurTBB && !CurTBB->isSuccessor(*SI)) {
+  assert((*SI)->isEHPad() && "Bad CFG");
+  CurTBB->copySuccessor(MBB, SI);

phoebewang wrote:

I see we assert for `(*SI)->isEHPad()`, but `bb.6` is not a EHPad. Did I 
misunderstand something here?
BTW, can we use `SI->isEHPad()` directly?

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


[clang-tools-extra] [clangd] Handle lambda scopes inside Node::getDeclContext() (PR #76329)

2024-01-11 Thread Younan Zhang via cfe-commits

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


[clang-tools-extra] 9ef2ac3 - [clangd] Handle lambda scopes inside Node::getDeclContext() (#76329)

2024-01-11 Thread via cfe-commits

Author: Younan Zhang
Date: 2024-01-11T16:59:18+08:00
New Revision: 9ef2ac3ad1bd5aa9e589f63047e8abeac11ad1b2

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

LOG: [clangd] Handle lambda scopes inside Node::getDeclContext() (#76329)

We used to consider the `DeclContext` for selection nodes inside a
lambda as the enclosing scope of the lambda expression, rather than the
lambda itself.

For example,

```cpp
void foo();
auto lambda = [] {
  return ^foo();
};
```

where `N` is the selection node for the expression `foo()`,
`N.getDeclContext()` returns the `TranslationUnitDecl` previously, which
IMO is wrong, since the method `operator()` of the lambda is closer.

Incidentally, this fixes a glitch in add-using-declaration tweaks.
(Thanks @HighCommander4 for the test case.)

Added: 


Modified: 
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Selection.cpp 
b/clang-tools-extra/clangd/Selection.cpp
index 8c6d5750ecefdb..277cb8769a1b12 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -1113,6 +1113,9 @@ const DeclContext ::Node::getDeclContext() 
const {
   return *DC;
   return *Current->getLexicalDeclContext();
 }
+if (const auto *LE = CurrentNode->ASTNode.get())
+  if (CurrentNode != this)
+return *LE->getCallOperator();
   }
   llvm_unreachable("A tree must always be rooted at TranslationUnitDecl.");
 }

diff  --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp 
b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index 4c019a1524f3c3..754e8c287c5148 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -880,6 +880,19 @@ TEST(SelectionTest, DeclContextIsLexical) {
   }
 }
 
+TEST(SelectionTest, DeclContextLambda) {
+  llvm::Annotations Test(R"cpp(
+void foo();
+auto lambda = [] {
+  return $1^foo();
+};
+  )cpp");
+  auto AST = TestTU::withCode(Test.code()).build();
+  auto ST = SelectionTree::createRight(AST.getASTContext(), AST.getTokens(),
+   Test.point("1"), Test.point("1"));
+  EXPECT_TRUE(ST.commonAncestor()->getDeclContext().isFunctionOrMethod());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
index 1fd2487378d705..c2dd8e1bb8eefa 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
@@ -309,6 +309,29 @@ namespace foo { void fun(); }
 void foo::fun() {
   ff();
 })cpp"},
+  // Inside a lambda.
+  {
+  R"cpp(
+namespace NS {
+void unrelated();
+void foo();
+}
+
+auto L = [] {
+  using NS::unrelated;
+  NS::f^oo();
+};)cpp",
+  R"cpp(
+namespace NS {
+void unrelated();
+void foo();
+}
+
+auto L = [] {
+  using NS::foo;using NS::unrelated;
+  foo();
+};)cpp",
+  },
   // If all other using are fully qualified, add ::
   {R"cpp(
 #include "test.hpp"



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


[clang-tools-extra] [clangd] Handle lambda scopes inside Node::getDeclContext() (PR #76329)

2024-01-11 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

The CI failure on windows seems irrelevant, so I'm landing it anyway.

```
FAILED: tools/clang/tools/extra/clangd/CompletionModel.h 
tools/clang/tools/extra/clangd/CompletionModel.cpp
cmd.exe /C "cd /D C:\ws\src\build\tools\clang\tools\extra\clangd && 
C:\Python39\python.exe 
C:/ws/src/clang-tools-extra/clangd/quality/CompletionModelCodegen.py --model 
C:/ws/src/clang-tools-extra/clangd/quality/model --output_dir 
C:/ws/src/build/tools/clang/tools/extra/clangd --filename CompletionModel 
--cpp_class clang::clangd::Example"
C:\Python39\python.exe: can't open file 
'C:\ws\src\clang-tools-extra\clangd\quality\CompletionModelCodegen.py': [Errno 
22] Invalid argument
```

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


[clang] [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker (PR #77580)

2024-01-11 Thread Balázs Kéri via cfe-commits


@@ -268,8 +268,12 @@ class StreamChecker : public Checkerhttps://github.com/llvm/llvm-project/pull/77580
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker (PR #77580)

2024-01-11 Thread Balázs Kéri via cfe-commits


@@ -324,6 +343,60 @@ void error_fseek_0(void) {
   fclose(F);
 }
 
+void error_fseeko_0(void) {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  int rc = fseeko(F, 0, SEEK_SET);
+  if (rc) {
+int IsFEof = feof(F), IsFError = ferror(F);
+// Get ferror or no error, but not feof.
+clang_analyzer_eval(IsFError);
+// expected-warning@-1 {{FALSE}}
+// expected-warning@-2 {{TRUE}}
+clang_analyzer_eval(IsFEof);
+// expected-warning@-1 {{FALSE}}
+  } else {
+clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  }
+  fclose(F);
+}
+
+void error_ftell(void) {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  long rc = ftell(F);
+  if (rc >= 0)
+clang_analyzer_warnIfReached();  // expected-warning {{REACHABLE}}
+  else
+clang_analyzer_eval(rc == -1);   // expected-warning {{TRUE}}
+  clang_analyzer_eval(feof(F) && ferror(F)); // expected-warning {{FALSE}}
+  StreamTesterChecker_make_feof_stream(F);
+  rc = ftell(F);
+  clang_analyzer_eval(feof(F));  // expected-warning {{TRUE}}
+  clang_analyzer_eval(ferror(F));// expected-warning {{FALSE}}
+  StreamTesterChecker_make_ferror_stream(F);
+  rc = ftell(F);
+  clang_analyzer_eval(feof(F));  // expected-warning {{FALSE}}
+  clang_analyzer_eval(ferror(F));// expected-warning {{TRUE}}
+  fclose(F);
+}
+
+void error_ftello(void) {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  long rc = ftello(F);
+  if (rc >= 0)
+clang_analyzer_warnIfReached();  // expected-warning {{REACHABLE}}
+  else
+clang_analyzer_eval(rc == -1);   // expected-warning {{TRUE}}
+  clang_analyzer_eval(feof(F) && ferror(F)); // expected-warning {{FALSE}}

balazske wrote:

To be exact, this test should be a copy of the previous test, only with 
`ftello` (and use of `off_t`).

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


[clang] [Clang][SemaCXX] improve sema check of clang::musttail attribute (PR #77727)

2024-01-11 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/77727

>From 75e9a81a5aa4042197201450fa676b8036a3d2cd Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Thu, 11 Jan 2024 13:02:21 +0800
Subject: [PATCH] [Clang][SemaCXX] improve sema check of clang::musttail
 attribute

---
 clang/docs/HLSL/FunctionCalls.rst| 2 +-
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
 clang/lib/Sema/SemaStmt.cpp  | 6 ++
 clang/test/SemaCXX/PR76631.cpp   | 9 +
 4 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/PR76631.cpp

diff --git a/clang/docs/HLSL/FunctionCalls.rst 
b/clang/docs/HLSL/FunctionCalls.rst
index 996ddd6944b1ce..7317de2163f897 100644
--- a/clang/docs/HLSL/FunctionCalls.rst
+++ b/clang/docs/HLSL/FunctionCalls.rst
@@ -144,7 +144,7 @@ undefined behavior in HLSL, and any use of the argument 
after the call is a use
 of an undefined value which may be illegal in the target (DXIL programs with
 used or potentially used ``undef`` or ``poison`` values fail validation).
 
-Clang Implementation 
+Clang Implementation
 
 
 .. note::
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1a79892e40030a..1006e7d65dd868 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3113,6 +3113,8 @@ def err_musttail_scope : Error<
   "cannot perform a tail call from this return statement">;
 def err_musttail_no_variadic : Error<
   "%0 attribute may not be used with variadic functions">;
+def err_musttail_no_return : Error<
+  "%0 attribute may not be used with no-return-attribute functions">;
 
 def err_nsobject_attribute : Error<
   "'NSObject' attribute is for pointer types only">;
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 21efe25ed84a3d..9e7c8c7e4e8c12 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -786,6 +786,12 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr 
) {
 return false;
   }
 
+  const auto *CalleeDecl = CE->getCalleeDecl();
+  if (CalleeDecl && CalleeDecl->hasAttr()) {
+Diag(St->getBeginLoc(), diag::err_musttail_no_return) << 
+return false;
+  }
+
   // Caller and callee must match in whether they have a "this" parameter.
   if (CallerType.This.isNull() != CalleeType.This.isNull()) {
 if (const auto *ND = dyn_cast_or_null(CE->getCalleeDecl())) {
diff --git a/clang/test/SemaCXX/PR76631.cpp b/clang/test/SemaCXX/PR76631.cpp
new file mode 100644
index 00..947fa3fc2635e6
--- /dev/null
+++ b/clang/test/SemaCXX/PR76631.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -std=c++11 -fsyntax-only %s
+
+[[noreturn]] void throw_int() {
+  throw int(); // expected-error {{cannot use 'throw' with exceptions 
disabled}}
+}
+
+void throw_int_wrapper() {
+  [[clang::musttail]] return throw_int(); // expected-error {{'musttail' 
attribute may not be used with no-return-attribute functions}}
+}

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


[lldb] [openmp] [clang] [clang-tools-extra] [lld] [libunwind] [mlir] [llvm] [flang] [compiler-rt] [BranchFolding] Fix missing predecessors of landing-pad (PR #77608)

2024-01-11 Thread Phoebe Wang via cfe-commits


@@ -1363,6 +1363,14 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) 
{
 MachineBasicBlock *Pred = *(MBB->pred_end()-1);
 Pred->ReplaceUsesOfBlockWith(MBB, &*FallThrough);
   }
+  // Add rest successors of MBB to successors of FallThrough. Those
+  // successors are not directly reachable via MBB, so it should be
+  // landing-pad.
+  for (auto SI = MBB->succ_begin(), SE = MBB->succ_end(); SI != SE; ++SI)
+if (*SI != &*FallThrough && !FallThrough->isSuccessor(*SI)) {
+  assert((*SI)->isEHPad() && "Bad CFG");
+  FallThrough->copySuccessor(MBB, SI);
+}

phoebewang wrote:

This doesn't answer the questions. My questions are:

- Why can't put the code in `ReplaceUsesOfBlockWith`? The `isSuccessor` can 
make sure the same BB won't add again;
- Is it possible the added BB might be removed latter. We don't have a 
mechanism to remove the dead successors. Would it be a problem if we keep an 
edge to dead BBs?

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


[clang] [Clang][SemaCXX] improve sema check of clang::musttail attribute (PR #77727)

2024-01-11 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/77727

>From cdc04d0b5b934c4dc4c8294dd000539275bf4222 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Thu, 11 Jan 2024 13:02:21 +0800
Subject: [PATCH] [Clang][SemaCXX] improve sema check of clang::musttail
 attribute

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
 clang/lib/Sema/SemaStmt.cpp  | 6 ++
 clang/test/SemaCXX/PR76631.cpp   | 9 +
 3 files changed, 17 insertions(+)
 create mode 100644 clang/test/SemaCXX/PR76631.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1a79892e40030a..1006e7d65dd868 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3113,6 +3113,8 @@ def err_musttail_scope : Error<
   "cannot perform a tail call from this return statement">;
 def err_musttail_no_variadic : Error<
   "%0 attribute may not be used with variadic functions">;
+def err_musttail_no_return : Error<
+  "%0 attribute may not be used with no-return-attribute functions">;
 
 def err_nsobject_attribute : Error<
   "'NSObject' attribute is for pointer types only">;
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 21efe25ed84a3d..9e7c8c7e4e8c12 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -786,6 +786,12 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr 
) {
 return false;
   }
 
+  const auto *CalleeDecl = CE->getCalleeDecl();
+  if (CalleeDecl && CalleeDecl->hasAttr()) {
+Diag(St->getBeginLoc(), diag::err_musttail_no_return) << 
+return false;
+  }
+
   // Caller and callee must match in whether they have a "this" parameter.
   if (CallerType.This.isNull() != CalleeType.This.isNull()) {
 if (const auto *ND = dyn_cast_or_null(CE->getCalleeDecl())) {
diff --git a/clang/test/SemaCXX/PR76631.cpp b/clang/test/SemaCXX/PR76631.cpp
new file mode 100644
index 00..947fa3fc2635e6
--- /dev/null
+++ b/clang/test/SemaCXX/PR76631.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -std=c++11 -fsyntax-only %s
+
+[[noreturn]] void throw_int() {
+  throw int(); // expected-error {{cannot use 'throw' with exceptions 
disabled}}
+}
+
+void throw_int_wrapper() {
+  [[clang::musttail]] return throw_int(); // expected-error {{'musttail' 
attribute may not be used with no-return-attribute functions}}
+}

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


[clang] [Clang][SemaCXX] improve sema check of clang::musttail attribute (PR #77727)

2024-01-11 Thread Qizhi Hu via cfe-commits

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


[clang] [Clang] Set writable and dead_on_unwind attributes on sret arguments (PR #77116)

2024-01-11 Thread Nikita Popov via cfe-commits

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


[clang] [llvm] [Clang][RISCV] Move getVScaleRange logic into libLLVMFrontendDriver. NFC (PR #77327)

2024-01-11 Thread Luke Lau via cfe-commits

lukel97 wrote:

Closing for now as deduplication the clang/flang frontend logic most likely 
requires more thought and discussion

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


[llvm] [clang] [Clang][RISCV] Move getVScaleRange logic into libLLVMFrontendDriver. NFC (PR #77327)

2024-01-11 Thread Luke Lau via cfe-commits

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


[clang] [clang-format] Add SpaceInParensOption for __attribute__ keyword (PR #77522)

2024-01-11 Thread Owen Pan via cfe-commits

owenca wrote:

> The __attribute((specifier-list)) currently is formatted based on the 
> SpacesInParensOptions.Other (previously, SpacesInParentheses). This change 
> allows finer control over addition of spaces between the consecutive parens, 
> and between the inner parens and the list of attribute specifiers.
> 
> Differential Revision: https://reviews.llvm.org/D155529
> 
> This is migrated from Phabricator, see more discussion there.

I expressed my opinion there:

> I would have no problem if this new option is extended to handle all double 
> parens, e.g. if (( i = j )), decltype(( x )), etc.

So I still prefer that we have a boolean suboption (e.g. 
`ConsecutiveParentheses`) that covers all double parens.

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


[clang] [llvm] [RISCV] Add support for new unprivileged extensions defined in profiles spec (PR #77458)

2024-01-11 Thread Luke Lau via cfe-commits

lukel97 wrote:

Rebased on top of 79889fedc57707e99740abc1f48e6c5601d5a3f3

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


[clang] [llvm] [RISCV] Add support for new unprivileged extensions defined in profiles spec (PR #77458)

2024-01-11 Thread Luke Lau via cfe-commits

https://github.com/lukel97 updated 
https://github.com/llvm/llvm-project/pull/77458

>From 8de2b22ba2723fccf16ca4d2a863f84fd1b66493 Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Tue, 9 Jan 2024 19:42:10 +0700
Subject: [PATCH 1/7] [RISCV] Add support for new unprivileged extensions
 defined in profiles spec

This adds minimal support for 7 new extensions that were defined as a part of
the RISC-V Profiles specification here:
https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc#7-new-isa-extensions

As stated in the specification, these extensions don't add any new features but
describe existing features. So this patch only adds parsing and subtarget
features.
---
 llvm/lib/Support/RISCVISAInfo.cpp  |  7 +++
 llvm/lib/Target/RISCV/RISCVFeatures.td | 26 ++
 llvm/test/CodeGen/RISCV/attributes.ll  | 14 ++
 3 files changed, 47 insertions(+)

diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 390d950486a795..bac7fa1b8f07da 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -88,6 +88,8 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
 {"xtheadvdot", {1, 0}},
 {"xventanacondops", {1, 0}},
 
+{"za128rs", {1, 0}},
+{"za64rs", {1, 0}},
 {"zawrs", {1, 0}},
 
 {"zba", {1, 0}},
@@ -116,9 +118,14 @@ static const RISCVSupportedExtension SupportedExtensions[] 
= {
 {"zhinx", {1, 0}},
 {"zhinxmin", {1, 0}},
 
+{"zic64b", {1, 0}},
 {"zicbom", {1, 0}},
 {"zicbop", {1, 0}},
 {"zicboz", {1, 0}},
+{"ziccamoa", {1, 0}},
+{"ziccif", {1, 0}},
+{"zicclsm", {1, 0}},
+{"ziccrse", {1, 0}},
 {"zicntr", {2, 0}},
 {"zicsr", {2, 0}},
 {"zifencei", {2, 0}},
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 279509575bb52a..1d34fb2c4b5cf6 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -86,6 +86,22 @@ def HasStdExtZifencei : 
Predicate<"Subtarget->hasStdExtZifencei()">,
AssemblerPredicate<(all_of 
FeatureStdExtZifencei),
"'Zifencei' (fence.i)">;
 
+def FeatureStdExtZiccamoa
+: SubtargetFeature<"ziccamoa", "HasStdExtZiccamoa", "true",
+   "'Ziccamoa' (Main Memory Supports All Atomics in A)">;
+
+def FeatureStdExtZiccif
+: SubtargetFeature<"ziccif", "HasStdExtZiccif", "true",
+   "'Ziccif' (Main Memory Supports Instruction Fetch with 
Atomicity Requirement)">;
+
+def FeatureStdExtZicclsm
+: SubtargetFeature<"zicclsm", "HasStdExtZicclsm", "true",
+   "'Zicclsm' (Main Memory Supports Misaligned 
Loads/Stores)">;
+
+def FeatureStdExtZiccrse
+: SubtargetFeature<"ziccrse", "HasStdExtZiccrse", "true",
+   "'Ziccrse' (Main Memory Supports Forward Progress on 
LR/SC Sequences)">;
+
 def FeatureStdExtZicntr
 : SubtargetFeature<"zicntr", "HasStdExtZicntr", "true",
"'Zicntr' (Base Counters and Timers)",
@@ -510,6 +526,10 @@ def HasStdExtZfhOrZvfh
"'Zfh' (Half-Precision Floating-Point) or "
"'Zvfh' (Vector Half-Precision 
Floating-Point)">;
 
+def FeatureStdExtZic64b
+: SubtargetFeature<"zic64b", "HasStdExtZic64b", "true",
+   "'Zic64b' (Cache Block Size Is 64 Bytes)">;
+
 def FeatureStdExtZicbom
 : SubtargetFeature<"zicbom", "HasStdExtZicbom", "true",
"'Zicbom' (Cache-Block Management Instructions)">;
@@ -554,6 +574,12 @@ def HasStdExtZtso : 
Predicate<"Subtarget->hasStdExtZtso()">,
   "'Ztso' (Memory Model - Total Store Order)">;
 def NotHasStdExtZtso : Predicate<"!Subtarget->hasStdExtZtso()">;
 
+def FeatureStdExtZa164rs : SubtargetFeature<"za64rs", "HasStdExtZa64rs", 
"true",
+"'Za64rs' (Reservation Set Size of 
at Most 64 Bytes)">;
+
+def FeatureStdExtZa128rs : SubtargetFeature<"za128rs", "HasStdExtZa128rs", 
"true",
+"'Za128rs' (Reservation Set Size 
of at Most 128 Bytes)">;
+
 def FeatureStdExtZawrs : SubtargetFeature<"zawrs", "HasStdExtZawrs", "true",
   "'Zawrs' (Wait on Reservation Set)">;
 def HasStdExtZawrs : Predicate<"Subtarget->hasStdExtZawrs()">,
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index 9a6e78c09ad8c3..8373ead932a695 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -130,6 +130,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zkn,+zkr,+zkt %s -o - | FileCheck 
--check-prefixes=CHECK,RV64COMBINEINTOZK %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zbkb,+zbkc,+zbkx,+zkne,+zknd,+zknh %s -o - 
| FileCheck --check-prefixes=CHECK,RV64COMBINEINTOZKN %s
 ; RUN: llc 

[lld] [clang] [llvm] [RISCV] Deduplicate version struct in RISCVISAInfo. NFC (PR #77645)

2024-01-11 Thread Luke Lau via cfe-commits

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


[clang] 79889fe - [RISCV] Deduplicate version struct in RISCVISAInfo. NFC (#77645)

2024-01-11 Thread via cfe-commits

Author: Luke Lau
Date: 2024-01-11T15:07:24+07:00
New Revision: 79889fedc57707e99740abc1f48e6c5601d5a3f3

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

LOG: [RISCV] Deduplicate version struct in RISCVISAInfo. NFC (#77645)

We have two structs for representing the version of an extension in
RISCVISAInfo, RISCVExtensionInfo and RISCVExtensionVersion, both
with the exact same fields. This patch deduplicates them.

Added: 


Modified: 
clang/lib/Basic/Targets/RISCV.cpp
lld/ELF/Arch/RISCV.cpp
llvm/include/llvm/Support/RISCVISAInfo.h
llvm/lib/Support/RISCVISAInfo.cpp
llvm/unittests/Support/RISCVISAInfoTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index daaa8639ae8358..fb312b6cf26e02 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -163,9 +163,8 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
,
 auto ExtName = Extension.first;
 auto ExtInfo = Extension.second;
 
-Builder.defineMacro(
-Twine("__riscv_", ExtName),
-Twine(getVersionValue(ExtInfo.MajorVersion, ExtInfo.MinorVersion)));
+Builder.defineMacro(Twine("__riscv_", ExtName),
+Twine(getVersionValue(ExtInfo.Major, ExtInfo.Minor)));
   }
 
   if (ISAInfo->hasExtension("m") || ISAInfo->hasExtension("zmmul"))

diff  --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 62498ded1a2b16..8906de07373547 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -957,8 +957,8 @@ static void mergeArch(RISCVISAInfo::OrderedExtensionMap 
,
   } else {
 for (const auto  : info.getExtensions()) {
   if (auto it = mergedExts.find(ext.first); it != mergedExts.end()) {
-if (std::tie(it->second.MajorVersion, it->second.MinorVersion) >=
-std::tie(ext.second.MajorVersion, ext.second.MinorVersion))
+if (std::tie(it->second.Major, it->second.Minor) >=
+std::tie(ext.second.Major, ext.second.Minor))
   continue;
   }
   mergedExts[ext.first] = ext.second;

diff  --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 97f1051b0540a7..46df93d7522602 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -18,11 +18,6 @@
 #include 
 
 namespace llvm {
-struct RISCVExtensionInfo {
-  unsigned MajorVersion;
-  unsigned MinorVersion;
-};
-
 void riscvExtensionsHelp(StringMap DescMap);
 
 class RISCVISAInfo {
@@ -30,6 +25,12 @@ class RISCVISAInfo {
   RISCVISAInfo(const RISCVISAInfo &) = delete;
   RISCVISAInfo =(const RISCVISAInfo &) = delete;
 
+  /// Represents the major and version number components of a RISC-V extension.
+  struct ExtensionVersion {
+unsigned Major;
+unsigned Minor;
+  };
+
   static bool compareExtension(const std::string , const std::string );
 
   /// Helper class for OrderedExtensionMap.
@@ -41,7 +42,7 @@ class RISCVISAInfo {
 
   /// OrderedExtensionMap is std::map, it's specialized to keep entries
   /// in canonical order of extension.
-  typedef std::map
+  typedef std::map
   OrderedExtensionMap;
 
   RISCVISAInfo(unsigned XLen, OrderedExtensionMap )
@@ -104,8 +105,7 @@ class RISCVISAInfo {
 
   OrderedExtensionMap Exts;
 
-  void addExtension(StringRef ExtName, unsigned MajorVersion,
-unsigned MinorVersion);
+  void addExtension(StringRef ExtName, ExtensionVersion Version);
 
   Error checkDependency();
 

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 70f531e40b90e6..390d950486a795 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -24,16 +24,11 @@
 using namespace llvm;
 
 namespace {
-/// Represents the major and version number components of a RISC-V extension
-struct RISCVExtensionVersion {
-  unsigned Major;
-  unsigned Minor;
-};
 
 struct RISCVSupportedExtension {
   const char *Name;
   /// Supported version.
-  RISCVExtensionVersion Version;
+  RISCVISAInfo::ExtensionVersion Version;
 
   bool operator<(const RISCVSupportedExtension ) const {
 return StringRef(Name) < StringRef(RHS.Name);
@@ -50,161 +45,161 @@ static const char *RISCVGImplications[] = {
 
 // NOTE: This table should be sorted alphabetically by extension name.
 static const RISCVSupportedExtension SupportedExtensions[] = {
-{"a", RISCVExtensionVersion{2, 1}},
-{"c", RISCVExtensionVersion{2, 0}},
-{"d", RISCVExtensionVersion{2, 2}},
-{"e", RISCVExtensionVersion{2, 0}},
-{"f", RISCVExtensionVersion{2, 2}},
-{"h", RISCVExtensionVersion{1, 0}},
-{"i", RISCVExtensionVersion{2, 1}},
-{"m", RISCVExtensionVersion{2, 0}},
-
-{"smaia", 

[clang] [llvm] [RISCV] Add support for new unprivileged extensions defined in profiles spec (PR #77458)

2024-01-11 Thread Luke Lau via cfe-commits

https://github.com/lukel97 updated 
https://github.com/llvm/llvm-project/pull/77458

>From 53993a1f1eaf0f6dc336d45a94b8638c4119ba2e Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Tue, 9 Jan 2024 19:42:10 +0700
Subject: [PATCH 1/7] [RISCV] Add support for new unprivileged extensions
 defined in profiles spec

This adds minimal support for 7 new extensions that were defined as a part of
the RISC-V Profiles specification here:
https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc#7-new-isa-extensions

As stated in the specification, these extensions don't add any new features but
describe existing features. So this patch only adds parsing and subtarget
features.
---
 llvm/lib/Support/RISCVISAInfo.cpp  |  7 +++
 llvm/lib/Target/RISCV/RISCVFeatures.td | 26 ++
 llvm/test/CodeGen/RISCV/attributes.ll  | 14 ++
 3 files changed, 47 insertions(+)

diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 70f531e40b90e6..c5c8f86a72d9d7 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -93,6 +93,8 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
 {"xtheadvdot", RISCVExtensionVersion{1, 0}},
 {"xventanacondops", RISCVExtensionVersion{1, 0}},
 
+{"za128rs", RISCVExtensionVersion{1, 0}},
+{"za64rs", RISCVExtensionVersion{1, 0}},
 {"zawrs", RISCVExtensionVersion{1, 0}},
 
 {"zba", RISCVExtensionVersion{1, 0}},
@@ -121,9 +123,14 @@ static const RISCVSupportedExtension SupportedExtensions[] 
= {
 {"zhinx", RISCVExtensionVersion{1, 0}},
 {"zhinxmin", RISCVExtensionVersion{1, 0}},
 
+{"zic64b", RISCVExtensionVersion{1, 0}},
 {"zicbom", RISCVExtensionVersion{1, 0}},
 {"zicbop", RISCVExtensionVersion{1, 0}},
 {"zicboz", RISCVExtensionVersion{1, 0}},
+{"ziccamoa", RISCVExtensionVersion{1, 0}},
+{"ziccif", RISCVExtensionVersion{1, 0}},
+{"zicclsm", RISCVExtensionVersion{1, 0}},
+{"ziccrse", RISCVExtensionVersion{1, 0}},
 {"zicntr", RISCVExtensionVersion{2, 0}},
 {"zicsr", RISCVExtensionVersion{2, 0}},
 {"zifencei", RISCVExtensionVersion{2, 0}},
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index bb7a3291085d43..17ed2a3aa2c57c 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -86,6 +86,22 @@ def HasStdExtZifencei : 
Predicate<"Subtarget->hasStdExtZifencei()">,
AssemblerPredicate<(all_of 
FeatureStdExtZifencei),
"'Zifencei' (fence.i)">;
 
+def FeatureStdExtZiccamoa
+: SubtargetFeature<"ziccamoa", "HasStdExtZiccamoa", "true",
+   "'Ziccamoa' (Main Memory Supports All Atomics in A)">;
+
+def FeatureStdExtZiccif
+: SubtargetFeature<"ziccif", "HasStdExtZiccif", "true",
+   "'Ziccif' (Main Memory Supports Instruction Fetch with 
Atomicity Requirement)">;
+
+def FeatureStdExtZicclsm
+: SubtargetFeature<"zicclsm", "HasStdExtZicclsm", "true",
+   "'Zicclsm' (Main Memory Supports Misaligned 
Loads/Stores)">;
+
+def FeatureStdExtZiccrse
+: SubtargetFeature<"ziccrse", "HasStdExtZiccrse", "true",
+   "'Ziccrse' (Main Memory Supports Forward Progress on 
LR/SC Sequences)">;
+
 def FeatureStdExtZicntr
 : SubtargetFeature<"zicntr", "HasStdExtZicntr", "true",
"'Zicntr' (Base Counters and Timers)",
@@ -510,6 +526,10 @@ def HasStdExtZfhOrZvfh
"'Zfh' (Half-Precision Floating-Point) or "
"'Zvfh' (Vector Half-Precision 
Floating-Point)">;
 
+def FeatureStdExtZic64b
+: SubtargetFeature<"zic64b", "HasStdExtZic64b", "true",
+   "'Zic64b' (Cache Block Size Is 64 Bytes)">;
+
 def FeatureStdExtZicbom
 : SubtargetFeature<"zicbom", "HasStdExtZicbom", "true",
"'Zicbom' (Cache-Block Management Instructions)">;
@@ -554,6 +574,12 @@ def HasStdExtZtso : 
Predicate<"Subtarget->hasStdExtZtso()">,
   "'Ztso' (Memory Model - Total Store Order)">;
 def NotHasStdExtZtso : Predicate<"!Subtarget->hasStdExtZtso()">;
 
+def FeatureStdExtZa164rs : SubtargetFeature<"za64rs", "HasStdExtZa64rs", 
"true",
+"'Za64rs' (Reservation Set Size of 
at Most 64 Bytes)">;
+
+def FeatureStdExtZa128rs : SubtargetFeature<"za128rs", "HasStdExtZa128rs", 
"true",
+"'Za128rs' (Reservation Set Size 
of at Most 128 Bytes)">;
+
 def FeatureStdExtZawrs : SubtargetFeature<"zawrs", "HasStdExtZawrs", "true",
   "'Zawrs' (Wait on Reservation Set)">;
 def HasStdExtZawrs : Predicate<"Subtarget->hasStdExtZawrs()">,
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index 

[clang] e3993e0 - [clang][Interp] Implement __builtin_addressof (#77303)

2024-01-11 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-01-11T09:02:24+01:00
New Revision: e3993e044ec5925e59c131f798f823a9f16f0433

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

LOG: [clang][Interp] Implement __builtin_addressof (#77303)

We don't need to do anything here, since the input is already a Pointer.
The only complexity is that we pre-classify the parameters as PT_Ptr,
but they might end up being of a different pointer type, e.g. PT_FnPtr.

Added: 


Modified: 
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/AST/Interp/functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 21ea2503b94bff..9de0926b9dba9c 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -134,6 +134,18 @@ void cleanupAfterFunctionCall(InterpState , CodePtr 
OpPC) {
   if (CurFunc->isUnevaluatedBuiltin())
 return;
 
+  // Some builtin functions require us to only look at the call site, since
+  // the classified parameter types do not match.
+  if (CurFunc->isBuiltin()) {
+const auto *CE =
+cast(S.Current->Caller->getExpr(S.Current->getRetPC()));
+for (int32_t I = CE->getNumArgs() - 1; I >= 0; --I) {
+  const Expr *A = CE->getArg(I);
+  popArg(S, A);
+}
+return;
+  }
+
   if (S.Current->Caller && CurFunc->isVariadic()) {
 // CallExpr we're look for is at the return PC of the current function, 
i.e.
 // in the caller.

diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index b55b1569a25983..754ca96b0c645e 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -164,6 +164,8 @@ static bool retPrimValue(InterpState , CodePtr OpPC, 
APValue ,
   case X:  
\
 return Ret(S, OpPC, Result);
   switch (*T) {
+RET_CASE(PT_Ptr);
+RET_CASE(PT_FnPtr);
 RET_CASE(PT_Float);
 RET_CASE(PT_Bool);
 RET_CASE(PT_Sint8);
@@ -613,15 +615,34 @@ static bool interp__builtin_ffs(InterpState , CodePtr 
OpPC,
   return true;
 }
 
+static bool interp__builtin_addressof(InterpState , CodePtr OpPC,
+  const InterpFrame *Frame,
+  const Function *Func,
+  const CallExpr *Call) {
+  PrimType PtrT =
+  S.getContext().classify(Call->getArg(0)->getType()).value_or(PT_Ptr);
+
+  if (PtrT == PT_FnPtr) {
+const FunctionPointer  = S.Stk.peek();
+S.Stk.push(Arg);
+  } else if (PtrT == PT_Ptr) {
+const Pointer  = S.Stk.peek();
+S.Stk.push(Arg);
+  } else {
+assert(false && "Unsupported pointer type passed to 
__builtin_addressof()");
+  }
+  return true;
+}
+
 bool InterpretBuiltin(InterpState , CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
 
-  QualType ReturnType = Call->getCallReturnType(S.getCtx());
-  std::optional ReturnT = S.getContext().classify(ReturnType);
+  std::optional ReturnT = S.getContext().classify(Call->getType());
+
   // If classify failed, we assume void.
-  assert(ReturnT || ReturnType->isVoidType());
+  assert(ReturnT || Call->getType()->isVoidType());
 
   switch (F->getBuiltinID()) {
   case Builtin::BI__builtin_is_constant_evaluated:
@@ -820,6 +841,12 @@ bool InterpretBuiltin(InterpState , CodePtr OpPC, const 
Function *F,
 if (!interp__builtin_ffs(S, OpPC, Frame, F, Call))
   return false;
 break;
+  case Builtin::BIaddressof:
+  case Builtin::BI__addressof:
+  case Builtin::BI__builtin_addressof:
+if (!interp__builtin_addressof(S, OpPC, Frame, F, Call))
+  return false;
+break;
 
   default:
 return false;

diff  --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index 179a195098b132..75f3c5d192b2cf 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -389,3 +389,27 @@ namespace Packs {
   static_assert(foo() == 2, "");
   static_assert(foo<>() == 0, "");
 }
+
+namespace AddressOf {
+  struct S {} s;
+  static_assert(__builtin_addressof(s) == , "");
+
+  struct T { constexpr T *operator&() const { return nullptr; } int n; } t;
+  constexpr T *pt = __builtin_addressof(t);
+  static_assert(>n == , "");
+
+  struct U { int n : 5; } u;
+  int *pbf = __builtin_addressof(u.n); // expected-error {{address of 
bit-field requested}} \
+   // ref-error {{address of bit-field 
requested}}
+
+  S *ptmp = __builtin_addressof(S{}); // expected-error {{taking the address 
of a temporary}} \
+  // expected-warning 

[clang] [clang][Interp] Implement __builtin_addressof (PR #77303)

2024-01-11 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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


<    1   2   3   4   5   6