[PATCH] D155173: [clangd] Refine the workflow for diagnostic Fixits.

2023-07-18 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:671
+  // FIMXE: this is tricky
+  llvm::StringRef(LSPDiag.Message)
+  .starts_with_insensitive(Diag.Message))

hokein wrote:
> hokein wrote:
> > kadircet wrote:
> > > this is tricky indeed and conceptually really hard to achieve inside 
> > > ClangdServer layer.
> > > 
> > > what about keeping the cache in ClangdLSPServer, but changing the format? 
> > > Similar to `TweakRef`, we now have a `DiagRef`, which is 
> > > ClangdServer-native. So we can keep a cache from `(FilePath, 
> > > clangd::Diagnostic)` to `clangd::DiagRef`, and pass those `DiagRef`s to 
> > > `ClangdServer` and make sure we're doing the search for sure on the right 
> > > domain here?
> > > 
> > > this also gives us the flexibility to change the definition of a 
> > > `DiagRef` in the future.
> > I'm not a fan of keeping a cache in `ClangdLSPServer`, I'd like to remove 
> > it entirely. 
> > 
> > What do you think about this alternative? 
> > 
> > - pull out and exposed the `mainMessage` API from the `toLSPDiags`
> > - we add the `ClangdDiagnosticOptions` to the `CodeActionInputs`.
> > - when searching a diagnostic in `ClangdServer.cpp`, we check the equality 
> > by checking `mainMessage(ClangdServerDiagnostic.message, Inputs.DiagOpts) 
> > == DiagRef.Message`
> > 
> > The downside here is that we have to pay `O(N * cost of mainMessage)` to 
> > find a matched diagnostic.
> >  
> I updated the patch with the `mainMessage` approach, please take a look.
i believe this still runs into the same conceptual problems. we're trying to 
imitate the logic done by clangdlspserver when converting a clangd-native 
diagnostic into an lsp-diagnostic and all of this will break as soon as there's 
a change in that logic. so if we want to go down that path, the best option 
would be to call `toLSPDiag`every time here and make sure we imitate that logic 
properly (e.g. right now we're relying on the ranges not being remapped because 
we only store fixes for the main file diagnostics).

but i feel like this is unnecessary cost both at runtime but also as 
code-complexity wise. this is ~the same as the data/args we publish with 
commands. it's just unfortunate that `data` field in `diagnostic` didn't exist 
pre LSP 3.16, hence we can't rely on it without breaking compatibility with 
some old clients (hopefully we can do that one day), hence instead of clients 
keeping this identifier around, I am merely suggesting to keep this alive on 
the server side. as conceptually this is the only layer that can do the mapping 
back and forth.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:714-715
   // Tracks number of times a tweak has been offered.
   static constexpr trace::Metric TweakAvailable(
   "tweak_available", trace::Metric::Counter, "tweak_id");
   auto Action = [Sel, CB = std::move(CB), Filter = std::move(Filter),

hokein wrote:
> kadircet wrote:
> > can you also move this counter to global scope and use it in `::codeAction` 
> > too?
> I added a similar local counter in `codeAction` method, since this method is 
> being deprecated, and removed eventually (it doesn't seem too make much sense 
> to use a shared counter)
sorry i am confused. the counter has nothing to do with how we generated a 
tweak. it's merely counting number of times a tweak was returned. hence we 
don't need a new one (if a code action `Bar` was made available either through 
a call to `::enumerateTweaks` or `::codeAction` we should increment the same 
counter. clients won't be invoking both at the same time, they'll be using one 
or the other).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155173

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


[PATCH] D155147: [X86] Add SM3 instructions.

2023-07-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 541343.
FreddyYe added a comment.

Refine doxygen


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155147

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsX86.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/sm3intrin.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/X86/sm3-builtins.c
  clang/test/CodeGen/X86/sm3-error.c
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86InstrSSE.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/sm3-intrinsics.ll
  llvm/test/MC/Disassembler/X86/sm3-32.txt
  llvm/test/MC/Disassembler/X86/sm3-64.txt
  llvm/test/MC/X86/sm3-att-32.s
  llvm/test/MC/X86/sm3-att-64.s
  llvm/test/MC/X86/sm3-intel-32.s
  llvm/test/MC/X86/sm3-intel-64.s

Index: llvm/test/MC/X86/sm3-intel-64.s
===
--- /dev/null
+++ llvm/test/MC/X86/sm3-intel-64.s
@@ -0,0 +1,86 @@
+// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xe4]
+  vsm3msg1 xmm12, xmm13, xmm4
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x10,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x10,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rip]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0x24,0x6d,0x00,0xfe,0xff,0xff]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rcx + 2032]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xa1,0xf0,0x07,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rcx + 2032]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rdx - 2048]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xa2,0x00,0xf8,0xff,0xff]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rdx - 2048]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xe4]
+  vsm3msg2 xmm12, xmm13, xmm4
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x11,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x11,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rip]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0x24,0x6d,0x00,0xfe,0xff,0xff]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rcx + 2032]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xa1,0xf0,0x07,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rcx + 2032]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rdx - 2048]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xa2,0x00,0xf8,0xff,0xff]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rdx - 2048]
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmm4, 123
+// CHECK: encoding: [0xc4,0x63,0x11,0xde,0xe4,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmm4, 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456], 123
+// CHECK: encoding: [0xc4,0x23,0x11,0xde,0xa4,0xf5,0x00,0x00,0x00,0x10,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456], 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291], 123
+// CHECK: encoding: [0xc4,0x43,0x11,0xde,0xa4,0x80,0x23,0x01,0x00,0x00,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291], 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [rip], 123
+// CHECK: encoding: [0xc4,0x63,0x11,0xde,0x25,0x00,0x00,0x00,0x00,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmmword ptr [rip], 123
+
+// 

[PATCH] D155552: [clang][Interp] Support __null

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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D12

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


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -12,6 +12,7 @@
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
 static_assert(nullptr == nullptr, "");
+static_assert(__null == __null, "");
 static_assert(1 == 1, "");
 static_assert(1 == 3, ""); // expected-error{{failed}} ref-error{{failed}}
 
@@ -928,6 +929,7 @@
 /// Ignored MaterializeTemporaryExpr.
 struct B{ const int &a; };
 (B{12}, 0);
+__null;
 
 return 0;
   }
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -71,6 +71,7 @@
   bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E);
   bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E);
   bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
+  bool VisitGNUNullExpr(const GNUNullExpr *E);
   bool VisitCXXThisExpr(const CXXThisExpr *E);
   bool VisitUnaryOperator(const UnaryOperator *E);
   bool VisitDeclRefExpr(const DeclRefExpr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2033,6 +2033,17 @@
   return this->emitNullPtr(E);
 }
 
+template 
+bool ByteCodeExprGen::VisitGNUNullExpr(const GNUNullExpr *E) {
+  if (DiscardResult)
+return true;
+
+  assert(E->getType()->isIntegerType());
+
+  PrimType T = classifyPrim(E->getType());
+  return this->emitZero(T, E);
+}
+
 template 
 bool ByteCodeExprGen::VisitCXXThisExpr(const CXXThisExpr *E) {
   if (DiscardResult)


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -12,6 +12,7 @@
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
 static_assert(nullptr == nullptr, "");
+static_assert(__null == __null, "");
 static_assert(1 == 1, "");
 static_assert(1 == 3, ""); // expected-error{{failed}} ref-error{{failed}}
 
@@ -928,6 +929,7 @@
 /// Ignored MaterializeTemporaryExpr.
 struct B{ const int &a; };
 (B{12}, 0);
+__null;
 
 return 0;
   }
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -71,6 +71,7 @@
   bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E);
   bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E);
   bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
+  bool VisitGNUNullExpr(const GNUNullExpr *E);
   bool VisitCXXThisExpr(const CXXThisExpr *E);
   bool VisitUnaryOperator(const UnaryOperator *E);
   bool VisitDeclRefExpr(const DeclRefExpr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2033,6 +2033,17 @@
   return this->emitNullPtr(E);
 }
 
+template 
+bool ByteCodeExprGen::VisitGNUNullExpr(const GNUNullExpr *E) {
+  if (DiscardResult)
+return true;
+
+  assert(E->getType()->isIntegerType());
+
+  PrimType T = classifyPrim(E->getType());
+  return this->emitZero(T, E);
+}
+
 template 
 bool ByteCodeExprGen::VisitCXXThisExpr(const CXXThisExpr *E) {
   if (DiscardResult)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155548: [clang][ExprConst] Short-circuit ConstantExpr evaluation

2023-07-18 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

I think this does make sense. Have you notice an impact on performance?
I wonder if there are places where we should cache the result of evaluating a 
ConstantExpr, like in `ExprEvaluatorBase::VisitConstantExpr`
How often do we construct a ConstantExpr without an initial computed value?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155548

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


[PATCH] D155552: [clang][Interp] Support __null

2023-07-18 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/test/AST/Interp/literals.cpp:16
+static_assert(__null == __null, "");
 static_assert(1 == 1, "");
 static_assert(1 == 3, ""); // expected-error{{failed}} ref-error{{failed}}

Can you add a test along the lines of 

constexpr void* v = nullptr;
static_assert(__null == v);


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D12

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


[clang] 39670ae - [clang][analyzer] Add and change NoteTags in StdLibraryFunctionsChecker.

2023-07-18 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2023-07-18T09:29:15+02:00
New Revision: 39670ae3b93470b2d29fe78e6d40c5d82a05e4a1

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

LOG: [clang][analyzer] Add and change NoteTags in StdLibraryFunctionsChecker.

Change 1: ErrnoChecker notes show only messages related to errno,
not to assumption of success or failure of functions.
Change 2: StdLibraryFunctionsChecker adds its own note about success
or failure of functions, and the errno related note, independently.
Change 3: Every modeled function in StdLibraryFunctionsChecker
should have a note tag message in all "cases". This is not implemented yet,
only for file (stream) related functions.

Reviewed By: donat.nagy

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/test/Analysis/errno-stdlibraryfunctions-notes.c
clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
clang/test/Analysis/std-c-library-functions-arg-constraints.c
clang/test/Analysis/std-c-library-functions-path-notes.c
clang/test/Analysis/stream-errno-note.c
clang/test/Analysis/stream-note.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
index 51f39c606d5c12..be2fa91b994a26 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
@@ -28,6 +28,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/FormatVariadic.h"
 #include 
 
 using namespace clang;
@@ -269,12 +270,6 @@ bool isErrno(const Decl *D) {
   return false;
 }
 
-const char *describeErrnoCheckState(ErrnoCheckState CS) {
-  assert(CS == errno_modeling::MustNotBeChecked &&
- "Errno description not applicable.");
-  return "may be undefined after the call and should not be used";
-}
-
 const NoteTag *getErrnoNoteTag(CheckerContext &C, const std::string &Message) {
   return C.getNoteTag([Message](PathSensitiveBugReport &BR) -> std::string {
 const MemRegion *ErrnoR = 
BR.getErrorNode()->getState()->get();
@@ -319,18 +314,14 @@ ProgramStateRef setErrnoStdMustBeChecked(ProgramStateRef 
State,
 
 const NoteTag *getNoteTagForStdSuccess(CheckerContext &C, llvm::StringRef Fn) {
   return getErrnoNoteTag(
-  C, (Twine("Assuming that function '") + Twine(Fn) +
-  Twine("' is successful, in this case the value 'errno' ") +
-  Twine(describeErrnoCheckState(MustNotBeChecked)))
- .str());
+  C, llvm::formatv(
+ "'errno' may be undefined after successful call to '{0}'", Fn));
 }
 
 const NoteTag *getNoteTagForStdMustBeChecked(CheckerContext &C,
  llvm::StringRef Fn) {
   return getErrnoNoteTag(
-  C, (Twine("Function '") + Twine(Fn) +
-  Twine("' indicates failure only by setting of 'errno'"))
- .str());
+  C, llvm::formatv("'{0}' indicates failure only by setting 'errno'", Fn));
 }
 
 } // namespace errno_modeling

diff  --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h 
b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
index 2ca3979944e365..0707fd16d6e60a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
+++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
@@ -78,14 +78,6 @@ ProgramStateRef clearErrnoState(ProgramStateRef State);
 /// declaration.
 bool isErrno(const Decl *D);
 
-/// Produce a textual description about how \c errno is allowed to be used
-/// (in a \c ErrnoCheckState).
-/// The returned string is insertable into a longer warning message in the form
-/// "the value 'errno' <...>".
-/// Currently only the \c errno_modeling::MustNotBeChecked state is supported,
-/// others are not used by the clients.
-const char *describeErrnoCheckState(ErrnoCheckState CS);
-
 /// Create a NoteTag that displays the message if the 'errno' memory region is
 /// marked as interesting, and resets the interestingness.
 const NoteTag *getErrnoNoteTag(CheckerContext &C, const std::string &Message);

diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 0228e8278f057a..8d4fb12061c3d6 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -52,6 +52,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #inclu

[PATCH] D155546: [clang][Interp] Implement __builtin_fmin

2023-07-18 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Looks fine but where are the tests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155546

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


[clang] f12808a - [clang][analyzer] Display notes in StdLibraryFunctionsChecker only if interesting

2023-07-18 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2023-07-18T09:29:15+02:00
New Revision: f12808ab20369c85ddb602e5a78bab40d16bb83f

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

LOG: [clang][analyzer] Display notes in StdLibraryFunctionsChecker only if 
interesting

The note tag that was previously added in all cases when a standard function 
call
is found is displayed now only if the function call (return value) is 
"interesting".
This results in less unneeded notes but some of the previously good notes 
disappear
too. This is because interestingness is not always set as it should be.

Reviewed By: donat.nagy

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/test/Analysis/errno-stdlibraryfunctions-notes.c
clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
clang/test/Analysis/std-c-library-functions-arg-constraints.c
clang/test/Analysis/std-c-library-functions-path-notes.c
clang/test/Analysis/stream-errno-note.c
clang/test/Analysis/stream-note.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 8d4fb12061c3d6..1fb248b8ed0e97 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -835,6 +835,7 @@ class StdLibraryFunctionsChecker
 
 for (ArgNo ArgN : VC->getArgsToTrack()) {
   bugreporter::trackExpressionValue(N, Call.getArgExpr(ArgN), *R);
+  R->markInteresting(Call.getArgSVal(ArgN));
   // All tracked arguments are important, highlight them.
   R->addRange(Call.getArgSourceRange(ArgN));
 }
@@ -1298,6 +1299,7 @@ void StdLibraryFunctionsChecker::checkPostCall(const 
CallEvent &Call,
 // StdLibraryFunctionsChecker.
 ExplodedNode *Pred = Node;
 if (!Case.getNote().empty()) {
+  const SVal RV = Call.getReturnValue();
   // If there is a description for this execution branch (summary case),
   // use it as a note tag.
   std::string Note =
@@ -1305,7 +1307,7 @@ void StdLibraryFunctionsChecker::checkPostCall(const 
CallEvent &Call,
 cast(Call.getDecl())->getDeclName());
   if (Summary.getInvalidationKd() == EvalCallAsPure) {
 const NoteTag *Tag = C.getNoteTag(
-[Node, Note](PathSensitiveBugReport &BR) -> std::string {
+[Node, Note, RV](PathSensitiveBugReport &BR) -> std::string {
   // Try to omit the note if we know in advance which branch is
   // taken (this means, only one branch exists).
   // This check is performed inside the lambda, after other
@@ -1316,18 +1318,22 @@ void StdLibraryFunctionsChecker::checkPostCall(const 
CallEvent &Call,
   // split that was performed by another checker (and can not find
   // the successors). This is why this check is only used in the
   // EvalCallAsPure case.
-  if (Node->succ_size() > 1)
+  if (BR.isInteresting(RV) && Node->succ_size() > 1)
 return Note;
   return "";
-},
-/*IsPrunable=*/true);
+});
 Pred = C.addTransition(NewState, Pred, Tag);
   } else {
-const NoteTag *Tag = C.getNoteTag(Note, /*IsPrunable=*/true);
+const NoteTag *Tag =
+C.getNoteTag([Note, RV](PathSensitiveBugReport &BR) -> std::string 
{
+  if (BR.isInteresting(RV))
+return Note;
+  return "";
+});
 Pred = C.addTransition(NewState, Pred, Tag);
   }
   if (!Pred)
-break;
+continue;
 }
 
 // If we can get a note tag for the errno change, add this additionally to

diff  --git a/clang/test/Analysis/errno-stdlibraryfunctions-notes.c 
b/clang/test/Analysis/errno-stdlibraryfunctions-notes.c
index e520e4fa76497f..991384cc373ef3 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions-notes.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions-notes.c
@@ -14,10 +14,8 @@ void clang_analyzer_warnIfReached();
 
 void test1() {
   access("path", 0);
-  // expected-note@-1{{Assuming that 'access' fails}}
   access("path", 0);
-  // expected-note@-1{{Assuming that 'access' is successful}}
-  // expected-note@-2{{'errno' may be undefined after successful call to 
'access'}}
+  // expected-note@-1{{'errno' may be undefined after successful call to 
'access'}}
   if (errno != 0) {
 // expected-warning@-1{{An undefined value may be read from 'errno'}}
 // expected-note@-2{{An undefined value may be read from 'errno'}}
@@ -26,8 +24,7 @@ void test1

[clang] 6dccf5b - [clang][analyzer] Add all success/failure messages to StdLibraryFunctionsChecker.

2023-07-18 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2023-07-18T09:29:15+02:00
New Revision: 6dccf5b8d550911f06e492a3a75c640c05efdab3

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

LOG: [clang][analyzer] Add all success/failure messages to 
StdLibraryFunctionsChecker.

Success or failure messages are now shown at all checked functions, if the call
(return value) is interesting.
Additionally new functions are added: open, openat, socket, shutdown

Reviewed By: donat.nagy

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/test/Analysis/Inputs/std-c-library-functions-POSIX.h
clang/test/Analysis/std-c-library-functions-POSIX.c
clang/test/Analysis/std-c-library-functions-arg-constraints.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 1fb248b8ed0e97..683b0369504dc8 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2181,6 +2181,26 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(ArgumentCondition(
 0, WithinRange, Range(0, LongMax;
 
+// int open(const char *path, int oflag, ...);
+addToFunctionSummaryMap(
+"open", Signature(ArgTypes{ConstCharPtrTy, IntTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
+  GenericSuccessMsg)
+.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
+
+// int openat(int fd, const char *path, int oflag, ...);
+addToFunctionSummaryMap(
+"openat",
+Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
+  GenericSuccessMsg)
+.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
+.ArgConstraint(NotNull(ArgNo(1;
+
 // int access(const char *pathname, int amode);
 addToFunctionSummaryMap(
 "access", Signature(ArgTypes{ConstCharPtrTy, IntTy}, RetType{IntTy}),
@@ -2195,8 +2215,8 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy, IntTy},
   RetType{IntTy}),
 Summary(NoEvalCall)
-.Case(ReturnsZero, ErrnoMustNotBeChecked)
-.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant)
+.Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
 .ArgConstraint(NotNull(ArgNo(1;
 
@@ -2204,8 +2224,9 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 addToFunctionSummaryMap(
 "dup", Signature(ArgTypes{IntTy}, RetType{IntTy}),
 Summary(NoEvalCall)
-.Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked)
-.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant)
+.Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
+  GenericSuccessMsg)
+.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(
 ArgumentCondition(0, WithinRange, Range(0, IntMax;
 
@@ -2213,20 +2234,21 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 addToFunctionSummaryMap(
 "dup2", Signature(ArgTypes{IntTy, IntTy}, RetType{IntTy}),
 Summary(NoEvalCall)
-.Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked)
-.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant)
+.Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
+  GenericSuccessMsg)
+.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(ArgumentCondition(0, WithinRange, Range(0, IntMax)))
 .ArgConstraint(
 ArgumentCondition(1, WithinRange, Range(0, IntMax;
 
 // int fdatasync(int fildes);
-addToFunctionSummaryMap("fdatasync",
-Signature(ArgTypes{IntTy}, RetType{IntTy}),
-Summary(NoEvalCall)
-.Case(ReturnsZero, ErrnoMustNotBeChecked)
-.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant)
-.ArgCo

[PATCH] D153612: [clang][analyzer] Add and change NoteTags in StdLibraryFunctionsChecker.

2023-07-18 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG39670ae3b934: [clang][analyzer] Add and change NoteTags in 
StdLibraryFunctionsChecker. (authored by balazske).

Changed prior to commit:
  https://reviews.llvm.org/D153612?vs=540015&id=541353#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153612

Files:
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/errno-stdlibraryfunctions-notes.c
  clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions-path-notes.c
  clang/test/Analysis/stream-errno-note.c
  clang/test/Analysis/stream-note.c

Index: clang/test/Analysis/stream-note.c
===
--- clang/test/Analysis/stream-note.c
+++ clang/test/Analysis/stream-note.c
@@ -7,11 +7,13 @@
 
 void check_note_at_correct_open(void) {
   FILE *F1 = tmpfile(); // expected-note {{Stream opened here}}
+  // stdargs-note@-1 {{'tmpfile' is successful}}
   if (!F1)
 // expected-note@-1 {{'F1' is non-null}}
 // expected-note@-2 {{Taking false branch}}
 return;
   FILE *F2 = tmpfile();
+  // stdargs-note@-1 {{'tmpfile' is successful}}
   if (!F2) {
 // expected-note@-1 {{'F2' is non-null}}
 // expected-note@-2 {{Taking false branch}}
@@ -20,6 +22,7 @@
   }
   rewind(F2);
   fclose(F2);
+  // stdargs-note@-1 {{'fclose' fails}}
   rewind(F1);
 }
 // expected-warning@-1 {{Opened stream never closed. Potential resource leak}}
@@ -27,6 +30,7 @@
 
 void check_note_fopen(void) {
   FILE *F = fopen("file", "r"); // expected-note {{Stream opened here}}
+  // stdargs-note@-1 {{'fopen' is successful}}
   if (!F)
 // expected-note@-1 {{'F' is non-null}}
 // expected-note@-2 {{Taking false branch}}
@@ -37,11 +41,13 @@
 
 void check_note_freopen(void) {
   FILE *F = fopen("file", "r"); // expected-note {{Stream opened here}}
+  // stdargs-note@-1 {{'fopen' is successful}}
   if (!F)
 // expected-note@-1 {{'F' is non-null}}
 // expected-note@-2 {{Taking false branch}}
 return;
   F = freopen(0, "w", F); // expected-note {{Stream reopened here}}
+  // stdargs-note@-1 {{'freopen' is successful}}
   if (!F)
 // expected-note@-1 {{'F' is non-null}}
 // expected-note@-2 {{Taking false branch}}
@@ -52,6 +58,8 @@
 
 void check_note_leak_2(int c) {
   FILE *F1 = fopen("foo1.c", "r"); // expected-note {{Stream opened here}}
+  // stdargs-note@-1 {{'fopen' is successful}}
+  // stdargs-note@-2 {{'fopen' is successful}}
   if (!F1)
 // expected-note@-1 {{'F1' is non-null}}
 // expected-note@-2 {{Taking false branch}}
@@ -59,6 +67,8 @@
 // expected-note@-4 {{Taking false branch}}
 return;
   FILE *F2 = fopen("foo2.c", "r"); // expected-note {{Stream opened here}}
+  // stdargs-note@-1 {{'fopen' is successful}}
+  // stdargs-note@-2 {{'fopen' is successful}}
   if (!F2) {
 // expected-note@-1 {{'F2' is non-null}}
 // expected-note@-2 {{Taking false branch}}
@@ -84,6 +94,7 @@
 void check_track_null(void) {
   FILE *F;
   F = fopen("foo1.c", "r"); // expected-note {{Value assigned to 'F'}} expected-note {{Assuming pointer value is null}}
+  // stdargs-note@-1 {{'fopen' fails}}
   if (F != NULL) {  // expected-note {{Taking false branch}} expected-note {{'F' is equal to NULL}}
 fclose(F);
 return;
@@ -96,13 +107,16 @@
   FILE *F;
   char Buf[10];
   F = fopen("foo1.c", "r");
+  // stdargs-note@-1 {{'fopen' is successful}}
   if (F == NULL) { // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
 return;
   }
   fread(Buf, 1, 1, F);
+  // stdargs-note@-1 {{'fread' fails}}
   if (feof(F)) { // expected-note {{Taking true branch}}
 clearerr(F);
 fread(Buf, 1, 1, F);   // expected-note {{Assuming stream reaches end-of-file here}}
+// stdargs-note@-1 {{'fread' fails}}
 if (feof(F)) { // expected-note {{Taking true branch}}
   fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
   // expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
@@ -115,10 +129,12 @@
   FILE *F;
   char Buf[10];
   F = fopen("foo1.c", "r");
+  // stdargs-note@-1 {{'fopen' is successful}}
   if (F == NULL) { // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
 return;
   }
   fread(Buf, 1, 1, F);
+  // stdargs-note@-1 {{'fread' is successful}}
   if (feof(F)) { // expected-note {{Taking false branch}}
 fclose(F);
 return;
@@ -127,6 +143,7 @@
 return;
   }
   fread(Buf, 1, 1, F);   // expected-note {{Assuming stream reaches end-of-file he

[PATCH] D154423: [clang][analyzer] Add all success/failure messages to StdLibraryFunctionsChecker.

2023-07-18 Thread Balázs Kéri 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 rG6dccf5b8d550: [clang][analyzer] Add all success/failure 
messages to… (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154423

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/Inputs/std-c-library-functions-POSIX.h
  clang/test/Analysis/std-c-library-functions-POSIX.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -316,6 +316,7 @@
   // bugpath-note{{The 1st argument to 'linkat' is -22 but should be a valid file descriptor or AT_FDCWD}}
 
   // no warning for these functions if the AT_FDCWD value is used
+  (void)openat(AT_FDCWD, "path", 0);
   (void)linkat(AT_FDCWD, "from", AT_FDCWD, "to", 0);
   (void)faccessat(AT_FDCWD, "path", 0, 0);
   (void)symlinkat("oldpath", AT_FDCWD, "newpath");
Index: clang/test/Analysis/std-c-library-functions-POSIX.c
===
--- clang/test/Analysis/std-c-library-functions-POSIX.c
+++ clang/test/Analysis/std-c-library-functions-POSIX.c
@@ -1,3 +1,12 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctions \
+// RUN:   -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true \
+// RUN:   -analyzer-config alpha.unix.StdCLibraryFunctions:DisplayLoadedSummaries=true \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple i686-unknown-linux -verify
+
 // RUN: %clang_analyze_cc1 %s \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctions \
@@ -15,6 +24,8 @@
 // CHECK: Loaded summary for: int fileno(FILE *stream)
 // CHECK: Loaded summary for: long a64l(const char *str64)
 // CHECK: Loaded summary for: char *l64a(long value)
+// CHECK: Loaded summary for: int open(const char *path, int oflag, ...)
+// CHECK: Loaded summary for: int openat(int fd, const char *path, int oflag, ...)
 // CHECK: Loaded summary for: int access(const char *pathname, int amode)
 // CHECK: Loaded summary for: int faccessat(int dirfd, const char *pathname, int mode, int flags)
 // CHECK: Loaded summary for: int dup(int fildes)
@@ -82,6 +93,7 @@
 // CHECK: Loaded summary for: int execv(const char *path, char *const argv[])
 // CHECK: Loaded summary for: int execvp(const char *file, char *const argv[])
 // CHECK: Loaded summary for: int getopt(int argc, char *const argv[], const char *optstring)
+// CHECK: Loaded summary for: int socket(int domain, int type, int protocol)
 // CHECK: Loaded summary for: int accept(int socket, __SOCKADDR_ARG address, socklen_t *restrict address_len)
 // CHECK: Loaded summary for: int bind(int socket, __CONST_SOCKADDR_ARG address, socklen_t address_len)
 // CHECK: Loaded summary for: int getpeername(int socket, __SOCKADDR_ARG address, socklen_t *restrict address_len)
@@ -97,6 +109,7 @@
 // CHECK: Loaded summary for: int getsockopt(int socket, int level, int option_name, void *restrict option_value, socklen_t *restrict option_len)
 // CHECK: Loaded summary for: ssize_t send(int sockfd, const void *buf, size_t len, int flags)
 // CHECK: Loaded summary for: int socketpair(int domain, int type, int protocol, int sv[2])
+// CHECK: Loaded summary for: int shutdown(int socket, int how)
 // CHECK: Loaded summary for: int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen, int flags)
 // CHECK: Loaded summary for: int utime(const char *filename, struct utimbuf *buf)
 // CHECK: Loaded summary for: int futimens(int fd, const struct timespec times[2])
@@ -128,8 +141,12 @@
 
 #include "Inputs/std-c-library-functions-POSIX.h"
 
-// Must have at least one call expression to initialize the summary map.
-int bar(void);
-void foo(void) {
-  bar();
+void test_open(void) {
+  open(0, 0); // \
+  // expected-warning{{The 1st argument to 'open' is NULL but should not be NULL}}
+}
+
+void test_open_additional_arg(void) {
+  open(0, 0, 0); // \
+  // expected-warning{{The 1st argument to 'open' is NULL but should not be NULL}}
 }
Index: clang/test/Analysis/Inputs/std-c-library-functions-POSIX.h
===
--- clang/test/Analysis/Inputs/std-c-library-functions-POSIX.h
+++ clang/test/Analysis/Inputs/std-c-library-functions-POSIX.h
@@ -47,6 +47,8 @@
 int fileno(FILE *stream);
 long a64l(const char *str64);
 char *l64a(long v

[PATCH] D153776: [clang][analyzer] Display notes in StdLibraryFunctionsChecker only if interesting

2023-07-18 Thread Balázs Kéri 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 rGf12808ab2036: [clang][analyzer] Display notes in 
StdLibraryFunctionsChecker only if… (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153776

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/errno-stdlibraryfunctions-notes.c
  clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions-path-notes.c
  clang/test/Analysis/stream-errno-note.c
  clang/test/Analysis/stream-note.c

Index: clang/test/Analysis/stream-note.c
===
--- clang/test/Analysis/stream-note.c
+++ clang/test/Analysis/stream-note.c
@@ -13,7 +13,6 @@
 // expected-note@-2 {{Taking false branch}}
 return;
   FILE *F2 = tmpfile();
-  // stdargs-note@-1 {{'tmpfile' is successful}}
   if (!F2) {
 // expected-note@-1 {{'F2' is non-null}}
 // expected-note@-2 {{Taking false branch}}
@@ -22,7 +21,6 @@
   }
   rewind(F2);
   fclose(F2);
-  // stdargs-note@-1 {{'fclose' fails}}
   rewind(F1);
 }
 // expected-warning@-1 {{Opened stream never closed. Potential resource leak}}
@@ -59,7 +57,6 @@
 void check_note_leak_2(int c) {
   FILE *F1 = fopen("foo1.c", "r"); // expected-note {{Stream opened here}}
   // stdargs-note@-1 {{'fopen' is successful}}
-  // stdargs-note@-2 {{'fopen' is successful}}
   if (!F1)
 // expected-note@-1 {{'F1' is non-null}}
 // expected-note@-2 {{Taking false branch}}
@@ -68,7 +65,6 @@
 return;
   FILE *F2 = fopen("foo2.c", "r"); // expected-note {{Stream opened here}}
   // stdargs-note@-1 {{'fopen' is successful}}
-  // stdargs-note@-2 {{'fopen' is successful}}
   if (!F2) {
 // expected-note@-1 {{'F2' is non-null}}
 // expected-note@-2 {{Taking false branch}}
@@ -107,16 +103,13 @@
   FILE *F;
   char Buf[10];
   F = fopen("foo1.c", "r");
-  // stdargs-note@-1 {{'fopen' is successful}}
   if (F == NULL) { // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
 return;
   }
   fread(Buf, 1, 1, F);
-  // stdargs-note@-1 {{'fread' fails}}
   if (feof(F)) { // expected-note {{Taking true branch}}
 clearerr(F);
 fread(Buf, 1, 1, F);   // expected-note {{Assuming stream reaches end-of-file here}}
-// stdargs-note@-1 {{'fread' fails}}
 if (feof(F)) { // expected-note {{Taking true branch}}
   fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
   // expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
@@ -129,12 +122,10 @@
   FILE *F;
   char Buf[10];
   F = fopen("foo1.c", "r");
-  // stdargs-note@-1 {{'fopen' is successful}}
   if (F == NULL) { // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
 return;
   }
   fread(Buf, 1, 1, F);
-  // stdargs-note@-1 {{'fread' is successful}}
   if (feof(F)) { // expected-note {{Taking false branch}}
 fclose(F);
 return;
@@ -143,7 +134,6 @@
 return;
   }
   fread(Buf, 1, 1, F);   // expected-note {{Assuming stream reaches end-of-file here}}
-  // stdargs-note@-1 {{'fread' fails}}
   if (feof(F)) { // expected-note {{Taking true branch}}
 fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
 // expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
@@ -155,11 +145,9 @@
   FILE *F;
   char Buf[10];
   F = fopen("foo1.c", "r");
-  // stdargs-note@-1 {{'fopen' is successful}}
   if (F == NULL) // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
 return;
   int RRet = fread(Buf, 1, 1, F); // expected-note {{Assuming stream reaches end-of-file here}}
-  // stdargs-note@-1 {{'fread' fails}}
   if (ferror(F)) {// expected-note {{Taking false branch}}
   } else {
 fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
Index: clang/test/Analysis/stream-errno-note.c
===
--- clang/test/Analysis/stream-errno-note.c
+++ clang/test/Analysis/stream-errno-note.c
@@ -11,7 +11,6 @@
 void check_fopen(void) {
   FILE *F = fopen("xxx", "r");
   // expected-note@-1{{'errno' may be undefined after successful call to 'fopen'}}
-  // expected-note@-2{{'fopen' is successful}}
   // expected-note@+2{{'F' is non-null}}
   // expected-note@+1{{Taking false branch}}
   if (!F)
@@ -24,7 +23,6 @@
 void check_tmpfile(void) {
   FILE *F = tmpfile();
   // expected-note@-1{{'errno' may be undefined aft

[PATCH] D155445: [analyzer][docs] Add CSA release notes

2023-07-18 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 541356.
steakhal marked 2 inline comments as done.
steakhal added a comment.

In D155445#4508728 , @OikawaKirie 
wrote:

> LGTM for my part. Thx.
>
> Since I am not very familiar with other changes, I have no detailed 
> suggestions for the order.

Thanks for the feedback. Applied!

F28297746: image.png 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155445

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -903,6 +903,89 @@
   non-complete destructors when using the Microsoft ABI.
   (`#60465 `_)
 
+- Removed the deprecated
+  ``consider-single-element-arrays-as-flexible-array-members`` analyzer option.
+  Any use of this flag will result in an error.
+  Use `-fstrict-flex-arrays= 
`_
+  (`7cd1f3ad22e4 `_)
+
+- Better modeling of lifetime-extended memory regions. As a result, the
+  ``MoveChecker`` raises more true-positive reports.
+  (`feafbb9fda57 `_)
+
+- Fixed some bugs (including crashes) around the handling of constant global
+  arrays and their initializer expressions.
+  (`ffcf214b5d27 `_,
+  `558b46fde2db `_)
+
+- The ``CStringChecker`` will invalidate less if the copy operation is
+  inferable to be bounded. For example, if the arguments of ``strcpy`` are
+  known to be of certain lengths and that are in-bounds.
+
+   .. code-block:: c++
+
+struct {
+  void *ptr;
+  char arr[4];
+} x;
+x.ptr = malloc(1);
+// extent of 'arr' is 4, and writing "hi\n" (4 characters),
+// thus no buffer overflow can happen
+strcpy(x.arr, "hi\n");
+free(x.ptr); // no longer reports memory leak here
+
+  Similarly, functions like ``strsep`` now won't invalidate the object
+  containing the destination buffer, because it can never overflow.
+  Note that, ``std::copy`` is still not modeled, and as such, it will still
+  invalidate the enclosing object on call.
+  (`1bd2d335b649 `_)
+  (`#55019 `_)
+
+- Implement ``BufferOverlap`` check for ``sprint``/``snprintf``
+  The ``CStringChecker`` checks for buffer overlaps for ``sprintf`` and
+  ``snprintf``.
+  (`ce97312d109b `_)
+
+- Objective-C support was improved around checking ``_Nonnull`` and
+  ``_Nullable`` including block pointers and literal objects.
+  (`b22a5d46179b `_,
+  `77a599ae5828 `_,
+  `fa6b7dd520fc `_,
+  `993060e1d31d `_)
+
+- Let the ``StreamChecker`` detect ``NULL`` streams instead of by
+  ``StdCLibraryFunctions``.
+  ``StreamChecker`` improved on the ``fseek`` modeling for the ``SEEK_SET``,
+  ``SEEK_END``, ``SEEK_CUR`` arguments.
+  (`2eefd19613b8 `_,
+  `2c60f9c8a4fd `_)
+
+- ``StdCLibraryFunctionArgs`` was merged into the ``StdCLibraryFunctions``.
+  The diagnostics of the ``StdCLibraryFunctions`` was improved.
+  (`4f0436dd1532 `_,
+  `6012cadc400f `_,
+  `258c9bebbdfa `_,
+  `ce1fb03db817 `_,
+  `ddc5d40dd285 `_)
+
+- ``QTimer::singleShot`` now doesn't raise false-positives for memory leaks by
+  the ``MallocChecker``.
+  (`3b6a368d763e `_)
+  (`#39713 `_)
+
+- Fixed the infamous unsigned index false-positives in the
+  ``ArrayBoundCheckerV2`` checker.
+  (`8c22cbea87be `_,
+  `de2547329b41 `_)
+  (`#44493 `_)
+
+- Now, taint propagations are tracked further back until the real taint source.
+  This improves all taint-rel

[PATCH] D155445: [analyzer][docs] Add CSA release notes

2023-07-18 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:922-923
+- The ``CStringChecker`` will invalidate less if the copy operation is
+  inferable to be bounded. For example, if the argument of ``strcpy`` is known
+  to be of certain length and that is in-bounds.
+

OikawaKirie wrote:
> The lengths of both src and dst buffers need to be known.
Applied!



Comment at: clang/docs/ReleaseNotes.rst:937
+
+  Similarly, functions like ``strsep`` now won't invalidate the source buffer,
+  because it can never overflow.

OikawaKirie wrote:
> I think this may be a typo here, as we do not invalidate the source buffer 
> originally.
Exactly. Thanks!



Comment at: clang/docs/ReleaseNotes.rst:908
+  (`7cd1f3ad22e4 `_)
+- Fixed a null-pointer dereference crash inside the ``MoveChecker``.
+  (`d172b65ef001 `_)

xazax.hun wrote:
> steakhal wrote:
> > xazax.hun wrote:
> > > I think we usually do not mention crash fixes in the changelog. We have 
> > > them in almost every release and sometimes there are quite a few of them.
> > I won't mention the explicit commit where it was fixed.
> > However, downstream users might wanna know about crashes and fixes that 
> > happened in this release.
> > And speaking about past practices about release notes, I think we can 
> > improve on that TBH.
> > We can move it down on the list if you want, but I'd rather keep it.
> Is this the only crash fix we had? Moving crash fixes to the bottom of the 
> list sounds good to me. 
No, it wasn't. We also had one for init-expr global variable initializers. [[ 
https://github.com/llvm/llvm-project/commit/558b46fde2db | See ]] 
I swept that fix under the carpet of "Fixed some bugs around the handling of 
constant global arrays and their initializer expressions". I made it more 
explicit now.

However, at this point, I think it's okay to simply omit the mention of the 
null deref crash fix.
Second thoughts?



Comment at: clang/docs/ReleaseNotes.rst:920-922
+- The ``CStringChecker`` will invalidate less if the copy operation is bounded.
+  (`1bd2d335b649 `_)
+  (`#55019 `_)

OikawaKirie wrote:
> One tiny change to the abstraction.
> The ``CStringChecker`` will invalidate less if the copy operation is 
> **inferable to be** bounded.
I decided to elaborate on this a bit. Let me know if it's too thorough now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155445

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


[PATCH] D109210: [obsolete][clang-tidy] Attach fixit to warning, not note, in add_new_check.py example

2023-07-18 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL abandoned this revision.
PiotrZSL added a comment.

No longer needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109210

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


[PATCH] D154366: [clang][ExprConstant] Print template arguments when describing stack frame

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

LGTM from my side, does anyone else still have a problem?


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

https://reviews.llvm.org/D154366

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


[PATCH] D76477: [clang-tidy] Update path of main translation unit

2023-07-18 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: carlosgalvezp.
Herald added a reviewer: njames93.
Herald added a project: All.

LGTM, probably LLVM_ATTRIBUTE_UNUSED  need to be added to example before 
committing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76477

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


[PATCH] D155369: [clang][Interp] Implement __builtin_isnan()

2023-07-18 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 541362.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D155369

Files:
  clang/lib/AST/Interp/Function.cpp
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/test/Sema/constant-builtins-fmin.cpp

Index: clang/test/Sema/constant-builtins-fmin.cpp
===
--- clang/test/Sema/constant-builtins-fmin.cpp
+++ clang/test/Sema/constant-builtins-fmin.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s
 // expected-no-diagnostics
 
 constexpr double NaN = __builtin_nan("");
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -159,6 +159,17 @@
   return true;
 }
 
+/// Defined as __builtin_isnan(...), to accommodate the fact that it can
+/// take a float, double, long double, etc.
+/// But for us, that's all a Floating anyway.
+static bool interp__builtin_isnan(InterpState &S, CodePtr OpPC,
+  const InterpFrame *Frame, const Function *F) {
+  const Floating &Arg = S.Stk.peek();
+
+  S.Stk.push>(Integral<32, true>::from(Arg.isNan()));
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -220,6 +231,11 @@
   return Ret(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_isnan:
+if (interp__builtin_isnan(S, OpPC, Frame, F))
+  return Ret(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -200,6 +200,9 @@
 // Returning values
 //===--===//
 
+/// Pop arguments of builtins defined as func-name(...).
+bool popBuiltinArgs(InterpState &S, CodePtr OpPC);
+
 template ::T>
 bool Ret(InterpState &S, CodePtr &PC, APValue &Result) {
   const T &Ret = S.Stk.pop();
@@ -216,8 +219,16 @@
   }
 
   assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame");
-  if (!S.checkingPotentialConstantExpression() || S.Current->Caller)
-S.Current->popArgs();
+  if (!S.checkingPotentialConstantExpression() || S.Current->Caller) {
+// Certain builtin functions are declared as func-name(...), so the
+// parameters are checked in Sema and only available through the CallExpr.
+// The interp::Function we create for them has 0 parameters, so we need to
+// remove them from the stack by checking the CallExpr.
+if (S.Current && S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()))
+  popBuiltinArgs(S, PC);
+else
+  S.Current->popArgs();
+  }
 
   if (InterpFrame *Caller = S.Current->Caller) {
 PC = S.Current->getRetPC();
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -122,6 +122,18 @@
 namespace clang {
 namespace interp {
 
+bool popBuiltinArgs(InterpState &S, CodePtr OpPC) {
+  assert(S.Current && S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()));
+  const Expr *E = S.Current->getExpr(OpPC);
+  assert(isa(E));
+  const CallExpr *CE = cast(E);
+  for (const auto *A : llvm::reverse(CE->arguments())) {
+PrimType Ty = S.getContext().classify(A->getType()).value_or(PT_Ptr);
+TYPE_SWITCH(Ty, S.Stk.discard());
+  }
+  return true;
+}
+
 bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
   if (!Ptr.isExtern())
 return true;
Index: clang/lib/AST/Interp/Function.h
===
--- clang/lib/AST/Interp/Function.h
+++ clang/lib/AST/Interp/Function.h
@@ -171,6 +171,12 @@
 
   unsigned getBuiltinID() const { return F->getBuiltinID(); }
 
+  bool isBuiltin() const { return F->getBuiltinID() != 0; }
+
+  /// Does this function need its arguments to be classified at runtime
+  /// rather than at bytecode-compile-time?
+  bool needsRuntimeArgPop(const ASTContext &Ctx) const;
+
   unsigned getNumParams() const { return ParamTypes.size(); }
 
   unsigned getParamOffset(unsigned ParamIndex) const {
Index: clang/lib/AST/Interp/Function.cpp
===
--- clang/lib/AST/Interp/Function.cpp
+++ clang/lib/AST/Interp/Function.cpp
@@ -7,10 +7,11 @@
 //===--===//
 
 #include "Function.h"
-#include "Program.h"
 #include "Opcode.h"
+#

[PATCH] D155546: [clang][Interp] Implement __builtin_fmin

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

`clang/test/Sema/constant-builtins-fmin.cpp` actually needed quite a lot of 
builtins before it could succeed, so it's enabled in 
https://reviews.llvm.org/D155369


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155546

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


[PATCH] D155552: [clang][Interp] Support __null

2023-07-18 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 541366.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D12

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


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -12,9 +12,13 @@
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
 static_assert(nullptr == nullptr, "");
+static_assert(__null == __null, "");
 static_assert(1 == 1, "");
 static_assert(1 == 3, ""); // expected-error{{failed}} ref-error{{failed}}
 
+constexpr void* v = nullptr;
+static_assert(__null == v, "");
+
 constexpr int number = 10;
 static_assert(number == 10, "");
 static_assert(number != 10, ""); // expected-error{{failed}} \
@@ -928,6 +932,7 @@
 /// Ignored MaterializeTemporaryExpr.
 struct B{ const int &a; };
 (B{12}, 0);
+__null;
 
 return 0;
   }
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -71,6 +71,7 @@
   bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E);
   bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E);
   bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
+  bool VisitGNUNullExpr(const GNUNullExpr *E);
   bool VisitCXXThisExpr(const CXXThisExpr *E);
   bool VisitUnaryOperator(const UnaryOperator *E);
   bool VisitDeclRefExpr(const DeclRefExpr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2033,6 +2033,17 @@
   return this->emitNullPtr(E);
 }
 
+template 
+bool ByteCodeExprGen::VisitGNUNullExpr(const GNUNullExpr *E) {
+  if (DiscardResult)
+return true;
+
+  assert(E->getType()->isIntegerType());
+
+  PrimType T = classifyPrim(E->getType());
+  return this->emitZero(T, E);
+}
+
 template 
 bool ByteCodeExprGen::VisitCXXThisExpr(const CXXThisExpr *E) {
   if (DiscardResult)


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -12,9 +12,13 @@
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
 static_assert(nullptr == nullptr, "");
+static_assert(__null == __null, "");
 static_assert(1 == 1, "");
 static_assert(1 == 3, ""); // expected-error{{failed}} ref-error{{failed}}
 
+constexpr void* v = nullptr;
+static_assert(__null == v, "");
+
 constexpr int number = 10;
 static_assert(number == 10, "");
 static_assert(number != 10, ""); // expected-error{{failed}} \
@@ -928,6 +932,7 @@
 /// Ignored MaterializeTemporaryExpr.
 struct B{ const int &a; };
 (B{12}, 0);
+__null;
 
 return 0;
   }
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -71,6 +71,7 @@
   bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E);
   bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E);
   bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
+  bool VisitGNUNullExpr(const GNUNullExpr *E);
   bool VisitCXXThisExpr(const CXXThisExpr *E);
   bool VisitUnaryOperator(const UnaryOperator *E);
   bool VisitDeclRefExpr(const DeclRefExpr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2033,6 +2033,17 @@
   return this->emitNullPtr(E);
 }
 
+template 
+bool ByteCodeExprGen::VisitGNUNullExpr(const GNUNullExpr *E) {
+  if (DiscardResult)
+return true;
+
+  assert(E->getType()->isIntegerType());
+
+  PrimType T = classifyPrim(E->getType());
+  return this->emitZero(T, E);
+}
+
 template 
 bool ByteCodeExprGen::VisitCXXThisExpr(const CXXThisExpr *E) {
   if (DiscardResult)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155558: [clangd][c++20] Add concept Hover tests.

2023-07-18 Thread Jens Massberg via Phabricator via cfe-commits
massberg created this revision.
massberg added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
massberg requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Concepts aren't fully supporteb by hover yet. For the currently
supported case we add a test here to prevent regressions in the future.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D18

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -523,6 +523,32 @@
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "Foo";
}},
+  // constrained template parameter
+  {R"cpp(
+template concept Fooable = true;
+template<[[Foo^able]] T>
+void bar(T t) {}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \nconcept Fooable = true";
+   }},
+   {R"cpp(
+template concept Fooable = true;
+template
+void bar(TT t) {}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "TT";
+ HI.Type = "class";
+ HI.AccessSpecifier = "public";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "bar::";
+ HI.Kind = index::SymbolKind::TemplateTypeParm;
+ HI.Definition = "Fooable TT";
+   }},
 
   // empty macro
   {R"cpp(
@@ -3025,17 +3051,17 @@
 const char *Code;
 const std::function ExpectedBuilder;
   } Cases[] = {{R"cpp(
-  struct Foo {}; 
+  struct Foo {};
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = ""; }},
{R"cpp(
-  #include "foo.h"   
+  #include "foo.h"
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
{R"cpp(
-  #include "all.h"  
+  #include "all.h"
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
@@ -3055,7 +3081,7 @@
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
{R"cpp(
-  #include "foo.h"
+  #include "foo.h"
   Foo A;
   Foo B;
   Foo C = A ^+ B;


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -523,6 +523,32 @@
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "Foo";
}},
+  // constrained template parameter
+  {R"cpp(
+template concept Fooable = true;
+template<[[Foo^able]] T>
+void bar(T t) {}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \nconcept Fooable = true";
+   }},
+   {R"cpp(
+template concept Fooable = true;
+template
+void bar(TT t) {}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "TT";
+ HI.Type = "class";
+ HI.AccessSpecifier = "public";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "bar::";
+ HI.Kind = index::SymbolKind::TemplateTypeParm;
+ HI.Definition = "Fooable TT";
+   }},
 
   // empty macro
   {R"cpp(
@@ -3025,17 +3051,17 @@
 const char *Code;
 const std::function ExpectedBuilder;
   } Cases[] = {{R"cpp(
-  struct Foo {}; 
+  struct Foo {};
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = ""; }},
{R"cpp(
-  #include "foo.h"   
+  #include "foo.h"
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
{R"cpp(
-  #include "all.h"  
+  #include "all.h"
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
@@ -3055,7 +3081,7 @@
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
{R"cpp(
- 

[PATCH] D154786: [Clang][Driver] Pass through the --be8 endian flag to linker in BareMetal driver For Arm.

2023-07-18 Thread Simi Pallipurath via Phabricator via cfe-commits
simpal01 added a comment.

@MaskRay

[Gentle Reminder] I have implemented the requested changes. Could you please 
have a look again. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154786

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


[PATCH] D155148: [X86] Add SM4 instructions.

2023-07-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 541373.
FreddyYe marked 3 inline comments as done.
FreddyYe added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155148

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsX86.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/sm4intrin.h
  clang/test/CodeGen/X86/sm4-builtins.c
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86InstrSSE.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/sm4-intrinsics.ll
  llvm/test/MC/Disassembler/X86/sm4-32.txt
  llvm/test/MC/Disassembler/X86/sm4-64.txt
  llvm/test/MC/X86/sm4-32-att.s
  llvm/test/MC/X86/sm4-32-intel.s
  llvm/test/MC/X86/sm4-64-att.s
  llvm/test/MC/X86/sm4-64-intel.s

Index: llvm/test/MC/X86/sm4-64-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/sm4-64-intel.s
@@ -0,0 +1,114 @@
+// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK: vsm4key4 ymm12, ymm13, ymm4
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0xe4]
+  vsm4key4 ymm12, ymm13, ymm4
+
+// CHECK: vsm4key4 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0xe4]
+  vsm4key4 xmm12, xmm13, xmm4
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x16,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm4key4 ymm12, ymm13, ymmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x16,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm4key4 ymm12, ymm13, ymmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm4key4 ymm12, ymm13, ymmword ptr [rip]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [2*rbp - 1024]
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0x24,0x6d,0x00,0xfc,0xff,0xff]
+  vsm4key4 ymm12, ymm13, ymmword ptr [2*rbp - 1024]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [rcx + 4064]
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0xa1,0xe0,0x0f,0x00,0x00]
+  vsm4key4 ymm12, ymm13, ymmword ptr [rcx + 4064]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [rdx - 4096]
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0xa2,0x00,0xf0,0xff,0xff]
+  vsm4key4 ymm12, ymm13, ymmword ptr [rdx - 4096]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x12,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm4key4 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x12,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm4key4 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm4key4 xmm12, xmm13, xmmword ptr [rip]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0x24,0x6d,0x00,0xfe,0xff,0xff]
+  vsm4key4 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [rcx + 2032]
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0xa1,0xf0,0x07,0x00,0x00]
+  vsm4key4 xmm12, xmm13, xmmword ptr [rcx + 2032]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [rdx - 2048]
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0xa2,0x00,0xf8,0xff,0xff]
+  vsm4key4 xmm12, xmm13, xmmword ptr [rdx - 2048]
+
+// CHECK: vsm4rnds4 ymm12, ymm13, ymm4
+// CHECK: encoding: [0xc4,0x62,0x17,0xda,0xe4]
+  vsm4rnds4 ymm12, ymm13, ymm4
+
+// CHECK: vsm4rnds4 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x13,0xda,0xe4]
+  vsm4rnds4 xmm12, xmm13, xmm4
+
+// CHECK: vsm4rnds4 ymm12, ymm13, ymmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x17,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm4rnds4 ymm12, ymm13, ymmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm4rnds4 ymm12, ymm13, ymmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x17,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm4rnds4 ymm12, ymm13, ymmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm4rnds4 ymm12, ymm13, ymmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x17,0xda,0x25,0x00,0x00,0x00,0x00]
+  

[PATCH] D155456: [RISCV] Support -m[no-]strict-align options

2023-07-18 Thread Wang Pengcheng via Phabricator via cfe-commits
wangpc updated this revision to Diff 541374.
wangpc added a comment.

Update ReleaseNotes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155456

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-default-features.c
  clang/test/Driver/riscv-features.c


Index: clang/test/Driver/riscv-features.c
===
--- clang/test/Driver/riscv-features.c
+++ clang/test/Driver/riscv-features.c
@@ -24,6 +24,22 @@
 // DEFAULT: "-target-feature" "-save-restore"
 // DEFAULT-NOT: "-target-feature" "+save-restore"
 
+// RUN: %clang --target=riscv32-unknown-elf -### %s -munaligned-access 2>&1 | 
FileCheck %s -check-prefix=UNALIGNED-SCALAR-MEM
+// RUN: %clang --target=riscv32-unknown-elf -### %s -mno-unaligned-access 2>&1 
| FileCheck %s -check-prefix=NO-UNALIGNED-SCALAR-MEM
+// RUN: %clang --target=riscv32-unknown-elf -### %s -mno-strict-align 2>&1 | 
FileCheck %s -check-prefix=UNALIGNED-SCALAR-MEM
+// RUN: %clang --target=riscv32-unknown-elf -### %s -mstrict-align 2>&1 | 
FileCheck %s -check-prefix=NO-UNALIGNED-SCALAR-MEM
+// RUN: %clang --target=riscv32-unknown-elf -### %s -march=rv32gv 
-munaligned-access 2>&1 | FileCheck %s -check-prefix=UNALIGNED-VECTOR-MEM
+// RUN: %clang --target=riscv32-unknown-elf -### %s -march=rv32gv 
-mno-unaligned-access 2>&1 | FileCheck %s -check-prefix=NO-UNALIGNED-VECTOR-MEM
+// RUN: %clang --target=riscv32-unknown-elf -### %s -march=rv32gv 
-mno-strict-align 2>&1 | FileCheck %s -check-prefix=UNALIGNED-VECTOR-MEM
+// RUN: %clang --target=riscv32-unknown-elf -### %s -march=rv32gv 
-mstrict-align 2>&1 | FileCheck %s -check-prefix=NO-UNALIGNED-VECTOR-MEM
+
+// UNALIGNED-SCALAR-MEM: "-target-feature" "+unaligned-scalar-mem"
+// NO-UNALIGNED-SCALAR-MEM: "-target-feature" "-unaligned-scalar-mem"
+// UNALIGNED-VECTOR-MEM: "-target-feature" "+unaligned-vector-mem"
+// NO-UNALIGNED-VECTOR-MEM: "-target-feature" "-unaligned-vector-mem"
+// DEFAULT: "-target-feature" "-unaligned-scalar-mem"
+// DEFAULT-NOT: "-target-feature" "+unaligned-scalar-mem"
+
 // RUN: %clang --target=riscv32-linux -### %s -fsyntax-only 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=DEFAULT-LINUX
 // RUN: %clang --target=riscv64-linux -### %s -fsyntax-only 2>&1 \
Index: clang/test/Driver/riscv-default-features.c
===
--- clang/test/Driver/riscv-default-features.c
+++ clang/test/Driver/riscv-default-features.c
@@ -3,8 +3,10 @@
 
 // RV32: "target-features"="+32bit,+a,+c,+m,+relax,
 // RV32-SAME: -save-restore
+// RV32-SAME: -unaligned-scalar-mem
 // RV64: "target-features"="+64bit,+a,+c,+m,+relax,
 // RV64-SAME: -save-restore
+// RV64-SAME: -unaligned-scalar-mem
 
 // Dummy function
 int foo(void){
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -167,6 +167,19 @@
   else
 Features.push_back("-save-restore");
 
+  // -mno-unaligned-access is default, unless -munaligned-access is specified.
+  bool HasV = llvm::is_contained(Features, "+zve32x");
+  if (Args.hasFlag(options::OPT_munaligned_access,
+   options::OPT_mno_unaligned_access, false)) {
+Features.push_back("+unaligned-scalar-mem");
+if (HasV)
+  Features.push_back("+unaligned-vector-mem");
+  } else {
+Features.push_back("-unaligned-scalar-mem");
+if (HasV)
+  Features.push_back("-unaligned-vector-mem");
+  }
+
   // Now add any that the user explicitly requested on the command line,
   // which may override the defaults.
   handleTargetFeaturesGroup(D, Triple, Args, Features,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3811,9 +3811,9 @@
"in __riscv_v_fixed_vlen preprocessor define (RISC-V only)">;
 
 def munaligned_access : Flag<["-"], "munaligned-access">, Group,
-  HelpText<"Allow memory accesses to be unaligned (AArch32/AArch64/LoongArch 
only)">;
+  HelpText<"Allow memory accesses to be unaligned 
(AArch32/AArch64/LoongArch/RISC-V only)">;
 def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group,
-  HelpText<"Force all memory accesses to be aligned (AArch32/AArch64/LoongArch 
only)">;
+  HelpText<"Force all memory accesses to be aligned 
(AArch32/AArch64/LoongArch/RISC-V only)">;
 } // let Flags = [TargetSpecific]
 def mstrict_align : Flag<["-"], "mstrict-align">, Alias, 
Flags<[CC1Option,HelpHidden]>,
   HelpText<"Force all memory accesses to be aligned (same as 
mno-unaligned-access)">;
Index: clang/docs/ReleaseNotes.rst
==

[PATCH] D155173: [clangd] Refine the workflow for diagnostic Fixits.

2023-07-18 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 541389.
hokein marked 2 inline comments as done.
hokein added a comment.

add LSPServer cache back and repurpose for lsp <=> naive diagnostic mapping, 
per offline discussion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155173

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.h

Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -972,6 +972,7 @@
 return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message);
   }
 };
+
 bool fromJSON(const llvm::json::Value &, Diagnostic &, llvm::json::Path);
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Diagnostic &);
 
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -37,8 +37,7 @@
 #include 
 #include 
 #include 
-#include 
-#include 
+#include 
 #include 
 
 namespace clang {
@@ -351,8 +350,49 @@
 std::string Title; /// A single-line message to show in the UI.
 llvm::StringLiteral Kind;
   };
+
+  // Ref to the clangd::Diag.
+  struct DiagRef {
+Range Range;
+std::string Message;
+bool operator==(const DiagRef &Other) const {
+  return std::tie(Range, Message) == std::tie(Other.Range, Other.Message);
+}
+bool operator<(const DiagRef &Other) const {
+  return std::tie(Range, Message) < std::tie(Other.Range, Other.Message);
+}
+  };
+
+  struct CodeActionInputs {
+std::string File;
+Range Selection;
+
+/// Requested kind of actions to return.
+std::vector RequestedActionKinds;
+
+/// Diagnostics attached to the code action request.
+std::vector Diagnostics;
+
+/// Tweaks where Filter returns false will not be checked or included.
+std::function TweakFilter;
+  };
+  struct CodeActionResult {
+std::string Version;
+struct QuickFix {
+  DiagRef Diag;
+  Fix F;
+};
+std::vector QuickFixes;
+std::vector TweakRefs;
+  };
+  /// Surface code actions (quick-fixes for diagnostics, or available code
+  /// tweaks) for a given range in a file.
+  void codeAction(const CodeActionInputs &Inputs,
+  Callback CB);
+
   /// Enumerate the code tweaks available to the user at a specified point.
   /// Tweaks where Filter returns false will not be checked or included.
+  /// Deprecated, use codeAction instead.
   void enumerateTweaks(PathRef File, Range Sel,
llvm::unique_function Filter,
Callback> CB);
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -52,11 +52,16 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
 namespace {
 
+// Tracks number of times a tweak has been offered.
+static constexpr trace::Metric TweakAvailable(
+"tweak_available", trace::Metric::Counter, "tweak_id");
+
 // Update the FileIndex with new ASTs and plumb the diagnostics responses.
 struct UpdateIndexCallbacks : public ParsingCallbacks {
   UpdateIndexCallbacks(FileIndex *FIndex,
@@ -643,12 +648,66 @@
   return std::move(Result);
 }
 
+void ClangdServer::codeAction(const CodeActionInputs &Params,
+  Callback CB) {
+  auto Action = [Params, CB = std::move(CB),
+ FeatureModules(this->FeatureModules)](
+Expected InpAST) mutable {
+if (!InpAST)
+  return CB(InpAST.takeError());
+auto KindAllowed =
+[Only(Params.RequestedActionKinds)](llvm::StringRef Kind) {
+  if (Only.empty())
+return true;
+  return llvm::any_of(Only, [&](llvm::StringRef Base) {
+return Kind.consume_front(Base) &&
+   (Kind.empty() || Kind.startswith("."));
+  });
+};
+
+CodeActionResult Result;
+Result.Version = InpAST->AST.version().str();
+if (KindAllowed(CodeAction::QUICKFIX_KIND)) {
+  auto FindMatched = [&InpAST](const DiagRef &DR) -> const clangd::Diag * {
+for (const auto &Diag : InpAST->AST.getDiagnostics())
+  if (Diag.Range == DR.Range && Diag.Message == DR.Message)
+return &Diag;
+return nullptr;
+  };
+  for (const auto &Diag : Params.Diagnostics) {
+if (const auto *Match = FindMatched(Diag))
+  for (const auto &Fix : Match->Fixes)
+Result.QuickFixes.push_back({Diag, Fix});
+  }
+}
+
+// Collect Tweaks
+ 

[PATCH] D155495: [RISCV][AArch64][IRGen] Add a special case to CodeGenFunction::EmitCall for scalable vector return being coerced to fixed vector.

2023-07-18 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes accepted this revision.
c-rhodes added a comment.
This revision is now accepted and ready to land.

Thanks Craig this is a better solution, LLVM cleans up the store/load coercion 
nicely but better not to create them in the first place if possible. LGTM cheers




Comment at: clang/lib/CodeGen/CGCall.cpp:5749
+  // intrinsic to perform the conversion.
+  if (auto *FixedDst = 
dyn_cast(ConvertType(RetTy))) {
+llvm::Value *V = CI;

nit: RetIRTy


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155495

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


[clang-tools-extra] e9ab43d - [clangd][c++20] Add concept Hover tests.

2023-07-18 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-07-18T10:19:46+02:00
New Revision: e9ab43dd44cafe5a67f0a12b9ff1021d47074970

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

LOG: [clangd][c++20] Add concept Hover tests.

Concepts aren't fully supporteb by hover yet. For the currently
supported case we add a test here to prevent regressions in the future.

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 91060a517de530..2ad7f0ee55d726 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -523,6 +523,32 @@ class Foo final {})cpp";
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "Foo";
}},
+  // constrained template parameter
+  {R"cpp(
+template concept Fooable = true;
+template<[[Foo^able]] T>
+void bar(T t) {}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \nconcept Fooable = true";
+   }},
+   {R"cpp(
+template concept Fooable = true;
+template
+void bar(TT t) {}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "TT";
+ HI.Type = "class";
+ HI.AccessSpecifier = "public";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "bar::";
+ HI.Kind = index::SymbolKind::TemplateTypeParm;
+ HI.Definition = "Fooable TT";
+   }},
 
   // empty macro
   {R"cpp(
@@ -3025,17 +3051,17 @@ TEST(Hover, Providers) {
 const char *Code;
 const std::function ExpectedBuilder;
   } Cases[] = {{R"cpp(
-  struct Foo {}; 
+  struct Foo {};
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = ""; }},
{R"cpp(
-  #include "foo.h"   
+  #include "foo.h"
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
{R"cpp(
-  #include "all.h"  
+  #include "all.h"
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
@@ -3055,7 +3081,7 @@ TEST(Hover, Providers) {
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
{R"cpp(
-  #include "foo.h"
+  #include "foo.h"
   Foo A;
   Foo B;
   Foo C = A ^+ B;



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


[PATCH] D155558: [clangd][c++20] Add concept Hover tests.

2023-07-18 Thread Jens Massberg 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 rGe9ab43dd44ca: [clangd][c++20] Add concept Hover tests. 
(authored by massberg).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D18

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -523,6 +523,32 @@
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "Foo";
}},
+  // constrained template parameter
+  {R"cpp(
+template concept Fooable = true;
+template<[[Foo^able]] T>
+void bar(T t) {}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \nconcept Fooable = true";
+   }},
+   {R"cpp(
+template concept Fooable = true;
+template
+void bar(TT t) {}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "TT";
+ HI.Type = "class";
+ HI.AccessSpecifier = "public";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "bar::";
+ HI.Kind = index::SymbolKind::TemplateTypeParm;
+ HI.Definition = "Fooable TT";
+   }},
 
   // empty macro
   {R"cpp(
@@ -3025,17 +3051,17 @@
 const char *Code;
 const std::function ExpectedBuilder;
   } Cases[] = {{R"cpp(
-  struct Foo {}; 
+  struct Foo {};
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = ""; }},
{R"cpp(
-  #include "foo.h"   
+  #include "foo.h"
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
{R"cpp(
-  #include "all.h"  
+  #include "all.h"
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
@@ -3055,7 +3081,7 @@
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
{R"cpp(
-  #include "foo.h"
+  #include "foo.h"
   Foo A;
   Foo B;
   Foo C = A ^+ B;


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -523,6 +523,32 @@
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "Foo";
}},
+  // constrained template parameter
+  {R"cpp(
+template concept Fooable = true;
+template<[[Foo^able]] T>
+void bar(T t) {}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \nconcept Fooable = true";
+   }},
+   {R"cpp(
+template concept Fooable = true;
+template
+void bar(TT t) {}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "TT";
+ HI.Type = "class";
+ HI.AccessSpecifier = "public";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "bar::";
+ HI.Kind = index::SymbolKind::TemplateTypeParm;
+ HI.Definition = "Fooable TT";
+   }},
 
   // empty macro
   {R"cpp(
@@ -3025,17 +3051,17 @@
 const char *Code;
 const std::function ExpectedBuilder;
   } Cases[] = {{R"cpp(
-  struct Foo {}; 
+  struct Foo {};
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = ""; }},
{R"cpp(
-  #include "foo.h"   
+  #include "foo.h"
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
{R"cpp(
-  #include "all.h"  
+  #include "all.h"
   Foo F = Fo^o{};
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
@@ -3055,7 +3081,7 @@
 )cpp",
 [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
{R"cpp(
-  #include "foo.h"
+  #include "foo.h"
   Foo A;
   Foo B;
   Foo C = 

[PATCH] D155173: [clangd] Refine the workflow for diagnostic Fixits.

2023-07-18 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 541391.
hokein added a comment.

cleanup


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155173

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h

Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -37,8 +37,7 @@
 #include 
 #include 
 #include 
-#include 
-#include 
+#include 
 #include 
 
 namespace clang {
@@ -351,8 +350,49 @@
 std::string Title; /// A single-line message to show in the UI.
 llvm::StringLiteral Kind;
   };
+
+  // Ref to the clangd::Diag.
+  struct DiagRef {
+Range Range;
+std::string Message;
+bool operator==(const DiagRef &Other) const {
+  return std::tie(Range, Message) == std::tie(Other.Range, Other.Message);
+}
+bool operator<(const DiagRef &Other) const {
+  return std::tie(Range, Message) < std::tie(Other.Range, Other.Message);
+}
+  };
+
+  struct CodeActionInputs {
+std::string File;
+Range Selection;
+
+/// Requested kind of actions to return.
+std::vector RequestedActionKinds;
+
+/// Diagnostics attached to the code action request.
+std::vector Diagnostics;
+
+/// Tweaks where Filter returns false will not be checked or included.
+std::function TweakFilter;
+  };
+  struct CodeActionResult {
+std::string Version;
+struct QuickFix {
+  DiagRef Diag;
+  Fix F;
+};
+std::vector QuickFixes;
+std::vector TweakRefs;
+  };
+  /// Surface code actions (quick-fixes for diagnostics, or available code
+  /// tweaks) for a given range in a file.
+  void codeAction(const CodeActionInputs &Inputs,
+  Callback CB);
+
   /// Enumerate the code tweaks available to the user at a specified point.
   /// Tweaks where Filter returns false will not be checked or included.
+  /// Deprecated, use codeAction instead.
   void enumerateTweaks(PathRef File, Range Sel,
llvm::unique_function Filter,
Callback> CB);
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -52,11 +52,16 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
 namespace {
 
+// Tracks number of times a tweak has been offered.
+static constexpr trace::Metric TweakAvailable(
+"tweak_available", trace::Metric::Counter, "tweak_id");
+
 // Update the FileIndex with new ASTs and plumb the diagnostics responses.
 struct UpdateIndexCallbacks : public ParsingCallbacks {
   UpdateIndexCallbacks(FileIndex *FIndex,
@@ -643,12 +648,66 @@
   return std::move(Result);
 }
 
+void ClangdServer::codeAction(const CodeActionInputs &Params,
+  Callback CB) {
+  auto Action = [Params, CB = std::move(CB),
+ FeatureModules(this->FeatureModules)](
+Expected InpAST) mutable {
+if (!InpAST)
+  return CB(InpAST.takeError());
+auto KindAllowed =
+[Only(Params.RequestedActionKinds)](llvm::StringRef Kind) {
+  if (Only.empty())
+return true;
+  return llvm::any_of(Only, [&](llvm::StringRef Base) {
+return Kind.consume_front(Base) &&
+   (Kind.empty() || Kind.startswith("."));
+  });
+};
+
+CodeActionResult Result;
+Result.Version = InpAST->AST.version().str();
+if (KindAllowed(CodeAction::QUICKFIX_KIND)) {
+  auto FindMatched = [&InpAST](const DiagRef &DR) -> const clangd::Diag * {
+for (const auto &Diag : InpAST->AST.getDiagnostics())
+  if (Diag.Range == DR.Range && Diag.Message == DR.Message)
+return &Diag;
+return nullptr;
+  };
+  for (const auto &Diag : Params.Diagnostics) {
+if (const auto *Match = FindMatched(Diag))
+  for (const auto &Fix : Match->Fixes)
+Result.QuickFixes.push_back({Diag, Fix});
+  }
+}
+
+// Collect Tweaks
+auto Selections = tweakSelection(Params.Selection, *InpAST, /*FS=*/nullptr);
+if (!Selections)
+  return CB(Selections.takeError());
+// Don't allow a tweak to fire more than once across ambiguous selections.
+llvm::DenseSet PreparedTweaks;
+auto DeduplicatingFilter = [&](const Tweak &T) {
+  return KindAllowed(T.kind()) && Params.TweakFilter(T) &&
+ !PreparedTweaks.count(T.id());
+};
+for (const auto &Sel : *Selections) {
+  for (auto &T : prepareTweaks(*Sel, DeduplicatingFilter, FeatureModules)) {
+Result.TweakRefs.push_back(TweakRef{T->id(), T->title(), T->k

[PATCH] D155146: [X86] Add SHA512 instructions.

2023-07-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 541392.
FreddyYe marked 2 inline comments as done.
FreddyYe added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155146

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsX86.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/sha512intrin.h
  clang/test/CodeGen/X86/sha512-builtins.c
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86InstrSSE.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/sha512-intrinsics.ll
  llvm/test/MC/Disassembler/X86/sha512.txt
  llvm/test/MC/X86/sha512-att.s
  llvm/test/MC/X86/sha512-intel.s

Index: llvm/test/MC/X86/sha512-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/sha512-intel.s
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -triple i686 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK:  vsha512msg1 ymm2, xmm3
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcc,0xd3]
+   vsha512msg1 ymm2, xmm3
+
+// CHECK:  vsha512msg2 ymm2, ymm3
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcd,0xd3]
+   vsha512msg2 ymm2, ymm3
+
+// CHECK:  vsha512rnds2 ymm2, ymm3, xmm4
+// CHECK: encoding: [0xc4,0xe2,0x67,0xcb,0xd4]
+   vsha512rnds2 ymm2, ymm3, xmm4
Index: llvm/test/MC/X86/sha512-att.s
===
--- /dev/null
+++ llvm/test/MC/X86/sha512-att.s
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -triple i686 --show-encoding %s | FileCheck %s
+// RUN: llvm-mc -triple x86_64 --show-encoding %s | FileCheck %s
+
+// CHECK:  vsha512msg1 %xmm3, %ymm2
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcc,0xd3]
+   vsha512msg1 %xmm3, %ymm2
+
+// CHECK:  vsha512msg2 %ymm3, %ymm2
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcd,0xd3]
+   vsha512msg2 %ymm3, %ymm2
+
+// CHECK:  vsha512rnds2 %xmm4, %ymm3, %ymm2
+// CHECK: encoding: [0xc4,0xe2,0x67,0xcb,0xd4]
+   vsha512rnds2 %xmm4, %ymm3, %ymm2
Index: llvm/test/MC/Disassembler/X86/sha512.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/X86/sha512.txt
@@ -0,0 +1,17 @@
+# RUN: llvm-mc --disassemble %s -triple=i386 | FileCheck %s --check-prefixes=ATT
+# RUN: llvm-mc --disassemble %s -triple=x86_64 | FileCheck %s --check-prefixes=ATT
+# RUN: llvm-mc --disassemble %s -triple=i386 --output-asm-variant=1 | FileCheck %s --check-prefixes=INTEL
+# RUN: llvm-mc --disassemble %s -triple=x86_64 --output-asm-variant=1 | FileCheck %s --check-prefixes=INTEL
+
+# ATT:vsha512msg1 %xmm3, %ymm2
+# INTEL:  vsha512msg1 ymm2, xmm3
+0xc4,0xe2,0x7f,0xcc,0xd3
+
+# ATT:vsha512msg2 %ymm3, %ymm2
+# INTEL:  vsha512msg2 ymm2, ymm3
+0xc4,0xe2,0x7f,0xcd,0xd3
+
+# ATT:vsha512rnds2 %xmm4, %ymm3, %ymm2
+# INTEL:  vsha512rnds2 ymm2, ymm3, xmm4
+0xc4,0xe2,0x67,0xcb,0xd4
+
Index: llvm/test/CodeGen/X86/sha512-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/sha512-intrinsics.ll
@@ -0,0 +1,33 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -verify-machineinstrs -mtriple=x86_64-unknown-unknown --show-mc-encoding -mattr=+sha512 | FileCheck %s
+; RUN: llc < %s -verify-machineinstrs -mtriple=i686-unknown-unknown --show-mc-encoding -mattr=+sha512 | FileCheck %s
+
+define <4 x i64> @test_int_x86_vsha512msg1(<4 x i64> %A, <2 x i64> %B) {
+; CHECK-LABEL: test_int_x86_vsha512msg1:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vsha512msg1 %xmm1, %ymm0 # encoding: [0xc4,0xe2,0x7f,0xcc,0xc1]
+; CHECK-NEXT:ret{{[l|q]}} # encoding: [0xc3]
+  %ret = call <4 x i64> @llvm.x86.vsha512msg1(<4 x i64> %A, <2 x i64> %B)
+  ret <4 x i64> %ret
+}
+declare <4 x i64> @llvm.x86.vsha512msg1(<4 x i64> %A, <2 x i64> %B)
+
+define <4 x i64> @test_int_x86_vsha512msg2(<4 x i64> %A, <4 x i64> %B) {
+; CHECK-LABEL: test_int_x86_vsha512msg2:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vsha512msg2 %ymm1, %ymm0 # encoding: [0xc4,0xe2,0x7f,0xcd,0xc1]
+; CHECK-NEXT:ret{{[l|q]}} # encoding: [0xc3]
+  %ret = call <4 x i64> @llvm.x86.vsha512msg2(<4 x i64> %A, <4 x i64> %B)
+  ret <4 x i64> %ret
+}
+declare <4 x i64> @llvm.x86.vsha512msg2(<4 x i64> %A, <4 x 

[PATCH] D154588: [CSKY] Optimize implementation of intrinsic 'llvm.cttz.i32'

2023-07-18 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.

ping ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154588

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


[clang] 5b99aa5 - [ASTImporter] Fix 'isVirtual()' assert failure while import overridden methods

2023-07-18 Thread via cfe-commits

Author: dingfei
Date: 2023-07-18T16:29:56+08:00
New Revision: 5b99aa57f74e1432691f366d26a2ec21907a7a70

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

LOG: [ASTImporter] Fix 'isVirtual()' assert failure while import overridden 
methods

CXXMethodDecl::isVirtual() count the number of overridden methods.
This assertion is not true before overridden methods are fully loaded.
The body of this CXXMethodDecl can introduce deps on a derived class
which contains a method overriding this method, causing the assertion failure.

ImportOverriddenMethods() is moved before body loading to fix this issue.

Testcase is contributed by Balázs Kéri (balazske)

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

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 1f4e2b27fc4a2d..429fa5829eb4f2 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -3782,6 +3782,11 @@ ExpectedDecl 
ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
   if (Error Err = ImportTemplateInformation(D, ToFunction))
 return std::move(Err);
 
+  if (auto *FromCXXMethod = dyn_cast(D))
+if (Error Err = ImportOverriddenMethods(cast(ToFunction),
+FromCXXMethod))
+  return std::move(Err);
+
   if (D->doesThisDeclarationHaveABody()) {
 Error Err = ImportFunctionDeclBody(D, ToFunction);
 
@@ -3805,11 +3810,6 @@ ExpectedDecl 
ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
 
   addDeclToContexts(D, ToFunction);
 
-  if (auto *FromCXXMethod = dyn_cast(D))
-if (Error Err = ImportOverriddenMethods(cast(ToFunction),
-FromCXXMethod))
-  return std::move(Err);
-
   // Import the rest of the chain. I.e. import all subsequent declarations.
   for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index ecf51d1c75c7d4..91b1b868af9f85 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -2332,6 +2332,43 @@ TEST_P(ImportFunctions,
   EXPECT_EQ(ToDFOutOfClass->getPreviousDecl(), ToDFInClass);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportVirtualOverriddenMethodOnALoopTest) {
+  // B::f() calls => f1() ==> C ==> C::f()
+  // \
+  //  \ A::f()
+  //
+  // C::f()'s ImportOverriddenMethods() asserts B::isVirtual(), so B::f()'s
+  // ImportOverriddenMethods() should be completed before B::f()'s body
+  const char *Code =
+  R"(
+  void f1();
+  class A {
+virtual void f(){}
+  };
+  class B: public A {
+void f() override {
+  f1();
+}
+  };
+  class C: public B {
+void f() override {}
+  };
+  void f1() { C c; }
+  )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, cxxMethodDecl(hasName("B::f")));
+
+  auto *ToBF = Import(FromF, Lang_CXX11);
+  EXPECT_TRUE(ToBF->isVirtual());
+
+  auto *ToCF = FirstDeclMatcher().match(
+  ToBF->getTranslationUnitDecl(), cxxMethodDecl(hasName("C::f")));
+  EXPECT_TRUE(ToCF->isVirtual());
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportVariableChainInC) {
 std::string Code = "static int v; static int v = 0;";
 auto Pattern = varDecl(hasName("v"));



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


[PATCH] D154701: [ASTImporter] Fix 'isVirtual()' assert failure while importing overridden methods

2023-07-18 Thread 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 rG5b99aa57f74e: [ASTImporter] Fix 'isVirtual()' 
assert failure while import overridden methods (authored by dingfei 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154701

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -2332,6 +2332,43 @@
   EXPECT_EQ(ToDFOutOfClass->getPreviousDecl(), ToDFInClass);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportVirtualOverriddenMethodOnALoopTest) {
+  // B::f() calls => f1() ==> C ==> C::f()
+  // \
+  //  \ A::f()
+  //
+  // C::f()'s ImportOverriddenMethods() asserts B::isVirtual(), so B::f()'s
+  // ImportOverriddenMethods() should be completed before B::f()'s body
+  const char *Code =
+  R"(
+  void f1();
+  class A {
+virtual void f(){}
+  };
+  class B: public A {
+void f() override {
+  f1();
+}
+  };
+  class C: public B {
+void f() override {}
+  };
+  void f1() { C c; }
+  )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, cxxMethodDecl(hasName("B::f")));
+
+  auto *ToBF = Import(FromF, Lang_CXX11);
+  EXPECT_TRUE(ToBF->isVirtual());
+
+  auto *ToCF = FirstDeclMatcher().match(
+  ToBF->getTranslationUnitDecl(), cxxMethodDecl(hasName("C::f")));
+  EXPECT_TRUE(ToCF->isVirtual());
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportVariableChainInC) {
 std::string Code = "static int v; static int v = 0;";
 auto Pattern = varDecl(hasName("v"));
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3782,6 +3782,11 @@
   if (Error Err = ImportTemplateInformation(D, ToFunction))
 return std::move(Err);
 
+  if (auto *FromCXXMethod = dyn_cast(D))
+if (Error Err = ImportOverriddenMethods(cast(ToFunction),
+FromCXXMethod))
+  return std::move(Err);
+
   if (D->doesThisDeclarationHaveABody()) {
 Error Err = ImportFunctionDeclBody(D, ToFunction);
 
@@ -3805,11 +3810,6 @@
 
   addDeclToContexts(D, ToFunction);
 
-  if (auto *FromCXXMethod = dyn_cast(D))
-if (Error Err = ImportOverriddenMethods(cast(ToFunction),
-FromCXXMethod))
-  return std::move(Err);
-
   // Import the rest of the chain. I.e. import all subsequent declarations.
   for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -2332,6 +2332,43 @@
   EXPECT_EQ(ToDFOutOfClass->getPreviousDecl(), ToDFInClass);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportVirtualOverriddenMethodOnALoopTest) {
+  // B::f() calls => f1() ==> C ==> C::f()
+  // \
+  //  \ A::f()
+  //
+  // C::f()'s ImportOverriddenMethods() asserts B::isVirtual(), so B::f()'s
+  // ImportOverriddenMethods() should be completed before B::f()'s body
+  const char *Code =
+  R"(
+  void f1();
+  class A {
+virtual void f(){}
+  };
+  class B: public A {
+void f() override {
+  f1();
+}
+  };
+  class C: public B {
+void f() override {}
+  };
+  void f1() { C c; }
+  )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, cxxMethodDecl(hasName("B::f")));
+
+  auto *ToBF = Import(FromF, Lang_CXX11);
+  EXPECT_TRUE(ToBF->isVirtual());
+
+  auto *ToCF = FirstDeclMatcher().match(
+  ToBF->getTranslationUnitDecl(), cxxMethodDecl(hasName("C::f")));
+  EXPECT_TRUE(ToCF->isVirtual());
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportVariableChainInC) {
 std::string Code = "static int v; static int v = 0;";
 auto Pattern = varDecl(hasName("v"));
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3782,6 +3782,11 @@
   if (Error Err = ImportTemplateInformation(D, ToFunction))
 return std::move(Err);
 
+  if (auto *FromCXXMethod = dyn_cast(D))
+if (Error Err = ImportOverriddenMethods(cast(ToFunction),
+FromCXXMethod))
+  return std::move(Err);
+
   if (D->doe

[PATCH] D155548: [clang][ExprConst] Short-circuit ConstantExpr evaluation

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

In D155548#4509056 , @cor3ntin wrote:

> I think this does make sense. Have you notice an impact on performance?

No, but my local builds are debug builds and I have sanitizers enabled. 
When compiling the sqlite amalgamation, I see 1590 `ConstantExpr`s, 421 of 
which have their value already set.

> I wonder if there are places where we should cache the result of evaluating a 
> ConstantExpr, like in `ExprEvaluatorBase::VisitConstantExpr`

I thought this happens elsewhere higher up the stack. E.g., in 
`Sema::VerifyIntegerConstantExpression`,

> How often do we construct a ConstantExpr without an initial computed value?

From a quick check:

clang/lib/Sema/SemaExpr.cpp:7735:25
clang/lib/Sema/SemaExpr.cpp:17937:20
clang/lib/Sema/SemaExpr.cpp:18244:23
clang/lib/Sema/SemaExpr.cpp:20165:12

(That's the places using the `::Create` version without the value argument, I 
haven't checked `::CreateEmpty`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155548

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


[clang] ef9421d - [LoongArch] Remove useless 'invalid' and 'none' feature and arch names. NFC

2023-07-18 Thread Weining Lu via cfe-commits

Author: Weining Lu
Date: 2023-07-18T16:51:23+08:00
New Revision: ef9421dcf15fcd21ba121670ac0c7c7af15bc80f

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

LOG: [LoongArch] Remove useless 'invalid' and 'none' feature and arch names. NFC

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
llvm/include/llvm/TargetParser/LoongArchTargetParser.def
llvm/include/llvm/TargetParser/LoongArchTargetParser.h
llvm/lib/TargetParser/LoongArchTargetParser.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index fe880f796cc024..856ad58f3bd9db 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -127,10 +127,8 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
const ArgList &Args,
std::vector &Features) {
   StringRef ArchName;
-  llvm::LoongArch::ArchKind ArchKind = llvm::LoongArch::ArchKind::AK_INVALID;
   if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
-ArchKind = llvm::LoongArch::parseArch(A->getValue());
-if (ArchKind == llvm::LoongArch::ArchKind::AK_INVALID) {
+if (!llvm::LoongArch::isValidArchName(A->getValue())) {
   D.Diag(clang::diag::err_drv_invalid_arch_name) << A->getAsString(Args);
   return;
 }

diff  --git a/llvm/include/llvm/TargetParser/LoongArchTargetParser.def 
b/llvm/include/llvm/TargetParser/LoongArchTargetParser.def
index 5245d750d3ef04..b20d124953f882 100644
--- a/llvm/include/llvm/TargetParser/LoongArchTargetParser.def
+++ b/llvm/include/llvm/TargetParser/LoongArchTargetParser.def
@@ -2,8 +2,6 @@
 #define LOONGARCH_FEATURE(NAME, KIND)
 #endif
 
-LOONGARCH_FEATURE("invalid", FK_INVALID)
-LOONGARCH_FEATURE("none", FK_NONE)
 LOONGARCH_FEATURE("+64bit", FK_64BIT)
 LOONGARCH_FEATURE("+f", FK_FP32)
 LOONGARCH_FEATURE("+d", FK_FP64)
@@ -19,7 +17,6 @@ LOONGARCH_FEATURE("+ual", FK_UAL)
 #define LOONGARCH_ARCH(NAME, KIND, FEATURES)
 #endif
 
-LOONGARCH_ARCH("invalid", AK_INVALID, FK_INVALID)
 LOONGARCH_ARCH("loongarch64", AK_LOONGARCH64, FK_64BIT | FK_FP32 | FK_FP64 | 
FK_UAL)
 LOONGARCH_ARCH("la464", AK_LA464, FK_64BIT | FK_FP32 | FK_FP64 | FK_LSX | 
FK_LASX | FK_UAL)
 

diff  --git a/llvm/include/llvm/TargetParser/LoongArchTargetParser.h 
b/llvm/include/llvm/TargetParser/LoongArchTargetParser.h
index ff325a76d1356d..2aa65ec070ec38 100644
--- a/llvm/include/llvm/TargetParser/LoongArchTargetParser.h
+++ b/llvm/include/llvm/TargetParser/LoongArchTargetParser.h
@@ -23,9 +23,6 @@ class StringRef;
 namespace LoongArch {
 
 enum FeatureKind : uint32_t {
-  FK_INVALID = 0,
-  FK_NONE = 1,
-
   // 64-bit ISA is available.
   FK_64BIT = 1 << 1,
 
@@ -67,7 +64,7 @@ struct ArchInfo {
   uint32_t Features;
 };
 
-ArchKind parseArch(StringRef Arch);
+bool isValidArchName(StringRef Arch);
 bool getArchFeatures(StringRef Arch, std::vector &Features);
 
 } // namespace LoongArch

diff  --git a/llvm/lib/TargetParser/LoongArchTargetParser.cpp 
b/llvm/lib/TargetParser/LoongArchTargetParser.cpp
index faa8c314fc0096..18b04600dbc660 100644
--- a/llvm/lib/TargetParser/LoongArchTargetParser.cpp
+++ b/llvm/lib/TargetParser/LoongArchTargetParser.cpp
@@ -1,4 +1,4 @@
-//==-- LoongArch64TargetParser - Parser for LoongArch64 features --*- C++ 
-*-=//
+//===-- LoongArchTargetParser - Parser for LoongArch features --*- C++ 
-*-//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -27,12 +27,11 @@ const ArchInfo AllArchs[] = {
 #include "llvm/TargetParser/LoongArchTargetParser.def"
 };
 
-LoongArch::ArchKind LoongArch::parseArch(StringRef Arch) {
+bool LoongArch::isValidArchName(StringRef Arch) {
   for (const auto A : AllArchs)
 if (A.Name == Arch)
-  return A.Kind;
-
-  return LoongArch::ArchKind::AK_INVALID;
+  return true;
+  return false;
 }
 
 bool LoongArch::getArchFeatures(StringRef Arch,
@@ -40,7 +39,7 @@ bool LoongArch::getArchFeatures(StringRef Arch,
   for (const auto A : AllArchs) {
 if (A.Name == Arch) {
   for (const auto F : AllFeatures)
-if ((A.Features & F.Kind) == F.Kind && F.Kind != FK_INVALID)
+if ((A.Features & F.Kind) == F.Kind)
   Features.push_back(F.Name);
   return true;
 }



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


[PATCH] D142660: [AIX] supporting -X options for llvm-ranlib in AIX OS

2023-07-18 Thread James Henderson via Phabricator via cfe-commits
jhenderson added a comment.

My apologies, this patch fell off my review queue somehow.

I still have concerns about the option-parsing logic being duplicated, but I'm 
out of time to review it now. I'll try to look tomorrow.




Comment at: llvm/test/tools/llvm-ranlib/aix-X-option.test:16
+
+## Test OBJECT_MODE environment variable when adding symbol table
+# RUN: env OBJECT_MODE= llvm-ranlib t_X32.a





Comment at: llvm/test/tools/llvm-ranlib/aix-X-option.test:17
+## Test OBJECT_MODE environment variable when adding symbol table
+# RUN: env OBJECT_MODE= llvm-ranlib t_X32.a
+# RUN: env OBJECT_MODE=32 llvm-ranlib t_X32.a

Doesn't this line want an llvm-nm check after it, like the others?



Comment at: llvm/test/tools/llvm-ranlib/aix-X-option.test:31
+
+## Test -X option when adding symbol table.
+# RUN: llvm-ranlib -X32 t_X32.a





Comment at: llvm/test/tools/llvm-ranlib/aix-X-option.test:48
+
+## Test -X option will override the "OBJECT_MODE" environment variable.
+# RUN: env OBJECT_MODE=32_64 llvm-ranlib -X32 t_X32.a





Comment at: llvm/test/tools/llvm-ranlib/aix-X-option.test:55
+
+## Test invalid -X option and invalid OBJECT_MODE
+# RUN: not env OBJECT_MODE=any llvm-ranlib t_X64.a 2>&1 | FileCheck 
--implicit-check-not="error:"  --check-prefixes=INVALID-OBJECT-MODE %s

It would be better to move this block of test cases below the check patterns 
that are used for the valid cases.



Comment at: llvm/test/tools/llvm-ranlib/aix-X-option.test:62
+
+#GLOB32:  var_0x1DF in t32_1.o
+#GLOB32-NEXT: array_0x1DF in t32_1.o

Nit: here and throughout - check patterns usually have a space between '#' and 
the pattern name, e.g. "# GLOB32:"

Rather than the somewhat confusing GL64 versus GLOB64 (and similiarly for the 
32-bit case), how about "HAS64" and "NO64" (and "HAS32" and "NO32")? That being 
said, see my comment below about ordering...



Comment at: llvm/test/tools/llvm-ranlib/aix-X-option.test:67
+
+#GL64-NOT:var_0x1F7 in t64_1.o
+#GL64-NOT:array_0x1F7 in t64_1.o

I'm concerned you're going to have an ordering issue in one of the 64 bit or 32 
bit "NOT" cases. FileCheck -NOT patterns only check the region between the 
previous non-NOT pattern before the -NOT one up to the next non-NOT pattern (or 
the end of the file). So, as things stand, --check-prefixes=GLOB32,GL64 will 
verify that the 32-bit table appears and then no 64-bit table is printed AFTER 
the 32-bit table, but not whether the 64-bit table appears BEFORE the 32-bit 
table. Similarly, --check-prefixes=GLOB64,GL32 will check that the 64-bit table 
is printed and then no 32-bit table is printed after it, but not whether the 
32-bit table is printed before it.

Given that the names of the symbols are irrelevant to this test case, and 
really all that's interesting is which object they're in (since this test isn't 
about checking that the symbol tables have the correct contents - that is the 
duty of a test that doesn't make use of the -X option), could you simplify the 
input objects to have a single like-named symbol and then simply ensure the 
correct object names appear in the output? You could use --implicit-check-not 
to check that e.g. "in t64" or "in t32" don't appear in your output.

If you adopted this approach, you'd have two CHECK lines as e.g. follows:
```
# GLOB32: symbol1 in t32_1.o
# GLOB32-NEXT: symbol2 in t32_2.o

# GLOB64: symbol1 in t64_1.o
# GLOB64-NEXT: symbol2 in t64_2.o
```
And you'd have FileCheck lines that look like one of the following:
```
FileCheck --check-prefixes=GLOB32 --implicit-check-not="in t64"
FileCheck --check-prefixes=GLOB64 --implicit-check-not="in t32"
FileCheck --check-prefixes=GLOB32,GLOB64
```

By simplifying down to one symbol each, you could also pass the symbol name in 
as a yaml2obj -D value and only have one YAML file in the test.



Comment at: llvm/test/tools/llvm-ranlib/aix-X-option.test:82-85
+#GLOB1:  var_0x1DF in t32_1.o
+#GLOB1-NEXT: array_0x1DF in t32_1.o
+#GLOB1-NEXT: var_0x1F7 in t64_1.o
+#GLOB1-NEXT: array_0x1F7 in t64_1.o

These aren't used. Delete them.



Comment at: llvm/test/tools/llvm-ranlib/aix-X-option.test:87
+
+#INVALID-OBJECT-MODE: error: The OBJECT_MODE environment variable has an 
invalid setting. OBJECT_MODE must be 32, 64, or 32_64.
+#INVALID-X-OPTION: error: The specified object mode is not valid. Specify 
-X32, -X64, or -X32_64.

"value" would be better than "setting" (environment variables have values, not 
settings).

Please also re-review the coding standards regarding error messages and fix the 
two separate issues in this and the below error message.



Comment at: llvm/tools/llvm-ar/llvm-ar.cpp:74-75
+ << "  -X {32|64|32_64}  - 

[clang] e953669 - [ASTImporter] Fields are imported first and reordered for correct layout

2023-07-18 Thread via cfe-commits

Author: dingfei
Date: 2023-07-18T17:07:19+08:00
New Revision: e9536698720ec524cc8b72599363622bc1a31558

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

LOG: [ASTImporter] Fields are imported first and reordered for correct layout

Fields are imported first and reordered for correct layout.
For partially imported record, layout computation is incorrect.

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

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 429fa5829eb4f2..39c7a8fa397048 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -433,6 +433,7 @@ namespace clang {
 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
 Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To);
 
+Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl 
*To);
 Expected ImportCastPath(CastExpr *E);
 Expected ImportAPValue(const APValue &FromValue);
 
@@ -1850,52 +1851,33 @@ ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, 
bool ForceImport) {
   // 
diff erent values in two distinct translation units.
   ChildErrorHandlingStrategy HandleChildErrors(FromDC);
 
+  auto MightNeedReordering = [](const Decl *D) {
+return isa(D) || isa(D) || 
isa(D);
+  };
+
+  // Import everything that might need reordering first.
   Error ChildErrors = Error::success();
   for (auto *From : FromDC->decls()) {
+if (!MightNeedReordering(From))
+  continue;
+
 ExpectedDecl ImportedOrErr = import(From);
 
 // If we are in the process of ImportDefinition(...) for a RecordDecl we
 // want to make sure that we are also completing each FieldDecl. There
 // are currently cases where this does not happen and this is correctness
 // fix since operations such as code generation will expect this to be so.
-if (ImportedOrErr) {
-  FieldDecl *FieldFrom = dyn_cast_or_null(From);
-  Decl *ImportedDecl = *ImportedOrErr;
-  FieldDecl *FieldTo = dyn_cast_or_null(ImportedDecl);
-  if (FieldFrom && FieldTo) {
-RecordDecl *FromRecordDecl = nullptr;
-RecordDecl *ToRecordDecl = nullptr;
-// If we have a field that is an ArrayType we need to check if the 
array
-// element is a RecordDecl and if so we need to import the definition.
-if (FieldFrom->getType()->isArrayType()) {
-  // getBaseElementTypeUnsafe(...) handles multi-dimensonal arrays for 
us.
-  FromRecordDecl = 
FieldFrom->getType()->getBaseElementTypeUnsafe()->getAsRecordDecl();
-  ToRecordDecl = 
FieldTo->getType()->getBaseElementTypeUnsafe()->getAsRecordDecl();
-}
-
-if (!FromRecordDecl || !ToRecordDecl) {
-  const RecordType *RecordFrom =
-  FieldFrom->getType()->getAs();
-  const RecordType *RecordTo = FieldTo->getType()->getAs();
-
-  if (RecordFrom && RecordTo) {
-FromRecordDecl = RecordFrom->getDecl();
-ToRecordDecl = RecordTo->getDecl();
-  }
-}
-
-if (FromRecordDecl && ToRecordDecl) {
-  if (FromRecordDecl->isCompleteDefinition() &&
-  !ToRecordDecl->isCompleteDefinition()) {
-Error Err = ImportDefinition(FromRecordDecl, ToRecordDecl);
-HandleChildErrors.handleChildImportResult(ChildErrors,
-  std::move(Err));
-  }
-}
-  }
-} else {
+if (!ImportedOrErr) {
   HandleChildErrors.handleChildImportResult(ChildErrors,
 ImportedOrErr.takeError());
+  continue;
+}
+FieldDecl *FieldFrom = dyn_cast_or_null(From);
+Decl *ImportedDecl = *ImportedOrErr;
+FieldDecl *FieldTo = dyn_cast_or_null(ImportedDecl);
+if (FieldFrom && FieldTo) {
+  Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
+  HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
 }
   }
 
@@ -1910,7 +1892,7 @@ ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, 
bool ForceImport) {
   // During the import of `a` we import first the dependencies in sequence,
   // thus the order would be `c`, `b`, `a`. We will get the normal order by
   // first removing the already imported members and then adding them in the
-  // order as they apper in the "from" context.
+  // order as they appear in the "from" context.
   //
   // Keeping field order is vital because it determines structure layout.
   //
@@ -1922,9 +1904,6 @@ ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, 
bool ForceImport) {
   // interface in LLDB is implemented

[PATCH] D154764: [ASTImporter] Fields are imported first and reordered for correct layout.

2023-07-18 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe9536698720e: [ASTImporter] Fields are imported first and 
reordered for correct layout (authored by dingfei ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154764

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8007,6 +8007,27 @@
 ToDGOther);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportFieldsFirstForCorrectRecordLayoutTest) {
+  // UnaryOperator(&) triggers RecordLayout computation, which relies on
+  // correctly imported fields.
+  auto Code =
+  R"(
+  class A {
+int m() {
+  return &((A *)0)->f1 - &((A *)0)->f2;
+}
+int f1;
+int f2;
+  };
+  )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, cxxMethodDecl(hasName("A::m")));
+  Import(FromF, Lang_CXX11);
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ImportRecordWithLayoutRequestingExpr) {
   TranslationUnitDecl *FromTU = getTuDecl(
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -433,6 +433,7 @@
 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
 Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To);
 
+Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
 Expected ImportCastPath(CastExpr *E);
 Expected ImportAPValue(const APValue &FromValue);
 
@@ -1850,52 +1851,33 @@
   // different values in two distinct translation units.
   ChildErrorHandlingStrategy HandleChildErrors(FromDC);
 
+  auto MightNeedReordering = [](const Decl *D) {
+return isa(D) || isa(D) || isa(D);
+  };
+
+  // Import everything that might need reordering first.
   Error ChildErrors = Error::success();
   for (auto *From : FromDC->decls()) {
+if (!MightNeedReordering(From))
+  continue;
+
 ExpectedDecl ImportedOrErr = import(From);
 
 // If we are in the process of ImportDefinition(...) for a RecordDecl we
 // want to make sure that we are also completing each FieldDecl. There
 // are currently cases where this does not happen and this is correctness
 // fix since operations such as code generation will expect this to be so.
-if (ImportedOrErr) {
-  FieldDecl *FieldFrom = dyn_cast_or_null(From);
-  Decl *ImportedDecl = *ImportedOrErr;
-  FieldDecl *FieldTo = dyn_cast_or_null(ImportedDecl);
-  if (FieldFrom && FieldTo) {
-RecordDecl *FromRecordDecl = nullptr;
-RecordDecl *ToRecordDecl = nullptr;
-// If we have a field that is an ArrayType we need to check if the array
-// element is a RecordDecl and if so we need to import the definition.
-if (FieldFrom->getType()->isArrayType()) {
-  // getBaseElementTypeUnsafe(...) handles multi-dimensonal arrays for us.
-  FromRecordDecl = FieldFrom->getType()->getBaseElementTypeUnsafe()->getAsRecordDecl();
-  ToRecordDecl = FieldTo->getType()->getBaseElementTypeUnsafe()->getAsRecordDecl();
-}
-
-if (!FromRecordDecl || !ToRecordDecl) {
-  const RecordType *RecordFrom =
-  FieldFrom->getType()->getAs();
-  const RecordType *RecordTo = FieldTo->getType()->getAs();
-
-  if (RecordFrom && RecordTo) {
-FromRecordDecl = RecordFrom->getDecl();
-ToRecordDecl = RecordTo->getDecl();
-  }
-}
-
-if (FromRecordDecl && ToRecordDecl) {
-  if (FromRecordDecl->isCompleteDefinition() &&
-  !ToRecordDecl->isCompleteDefinition()) {
-Error Err = ImportDefinition(FromRecordDecl, ToRecordDecl);
-HandleChildErrors.handleChildImportResult(ChildErrors,
-  std::move(Err));
-  }
-}
-  }
-} else {
+if (!ImportedOrErr) {
   HandleChildErrors.handleChildImportResult(ChildErrors,
 ImportedOrErr.takeError());
+  continue;
+}
+FieldDecl *FieldFrom = dyn_cast_or_null(From);
+Decl *ImportedDecl = *ImportedOrErr;
+FieldDecl *FieldTo = dyn_cast_or_null(ImportedDecl);
+if (FieldFrom && FieldTo) {
+  Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
+  HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
 }
   }
 
@@ -1910,7 +1892,7 @@
   // During the import of `a` we import first the dependencies in sequence,
   // thus the order would be `c`, `b`, `

[clang] 2c65118 - [clang-extdef-mapping] register necessary targest for ms-style asm block

2023-07-18 Thread via cfe-commits

Author: dingfei
Date: 2023-07-18T17:09:58+08:00
New Revision: 2c651184a2b0ef1b0e24c6536e5befb65a0ae5ce

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

LOG: [clang-extdef-mapping] register necessary targest for ms-style asm block

Without targets registered gives: "error: MS-style inline assembly is not
available: Unable to find target for this triple (no targets are registered)"

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

Added: 
clang/test/Tooling/ms-asm-clang-extdef-mapping.c

Modified: 
clang/tools/clang-extdef-mapping/CMakeLists.txt
clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp

Removed: 




diff  --git a/clang/test/Tooling/ms-asm-clang-extdef-mapping.c 
b/clang/test/Tooling/ms-asm-clang-extdef-mapping.c
new file mode 100644
index 00..00632d11e3dcbc
--- /dev/null
+++ b/clang/test/Tooling/ms-asm-clang-extdef-mapping.c
@@ -0,0 +1,7 @@
+// RUN: clang-extdef-mapping "%s" -- -fasm-blocks 2>&1 | FileCheck %s
+
+void Break() {
+  __asm { int 3 }
+}
+
+// CHECK: {{c:@F@Break .*}}

diff  --git a/clang/tools/clang-extdef-mapping/CMakeLists.txt 
b/clang/tools/clang-extdef-mapping/CMakeLists.txt
index 973b68db69dff4..e3a2673efbe3e1 100644
--- a/clang/tools/clang-extdef-mapping/CMakeLists.txt
+++ b/clang/tools/clang-extdef-mapping/CMakeLists.txt
@@ -1,5 +1,8 @@
 set(LLVM_LINK_COMPONENTS
   ${LLVM_TARGETS_TO_BUILD}
+  AllTargetsAsmParsers
+  AllTargetsDescs
+  AllTargetsInfos
   support
   )
 

diff  --git a/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp 
b/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
index 9ad16dc09ce187..2d4f398f76f6d7 100644
--- a/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
+++ b/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
@@ -23,6 +23,7 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/TargetSelect.h"
 #include 
 #include 
 #include 
@@ -214,6 +215,10 @@ int main(int argc, const char **argv) {
   }
   CommonOptionsParser &OptionsParser = ExpectedParser.get();
 
+  llvm::InitializeAllTargetInfos();
+  llvm::InitializeAllTargetMCs();
+  llvm::InitializeAllAsmParsers();
+
   return HandleFiles(OptionsParser.getSourcePathList(),
  OptionsParser.getCompilations());
 }



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


[PATCH] D154983: [clang-extdef-mapping] register necessary targest for ms-style asm block

2023-07-18 Thread 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 rG2c651184a2b0: [clang-extdef-mapping] register necessary 
targest for ms-style asm block (authored by dingfei ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154983

Files:
  clang/test/Tooling/ms-asm-clang-extdef-mapping.c
  clang/tools/clang-extdef-mapping/CMakeLists.txt
  clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp


Index: clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
===
--- clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
+++ clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
@@ -23,6 +23,7 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/TargetSelect.h"
 #include 
 #include 
 #include 
@@ -214,6 +215,10 @@
   }
   CommonOptionsParser &OptionsParser = ExpectedParser.get();
 
+  llvm::InitializeAllTargetInfos();
+  llvm::InitializeAllTargetMCs();
+  llvm::InitializeAllAsmParsers();
+
   return HandleFiles(OptionsParser.getSourcePathList(),
  OptionsParser.getCompilations());
 }
Index: clang/tools/clang-extdef-mapping/CMakeLists.txt
===
--- clang/tools/clang-extdef-mapping/CMakeLists.txt
+++ clang/tools/clang-extdef-mapping/CMakeLists.txt
@@ -1,5 +1,8 @@
 set(LLVM_LINK_COMPONENTS
   ${LLVM_TARGETS_TO_BUILD}
+  AllTargetsAsmParsers
+  AllTargetsDescs
+  AllTargetsInfos
   support
   )
 
Index: clang/test/Tooling/ms-asm-clang-extdef-mapping.c
===
--- /dev/null
+++ clang/test/Tooling/ms-asm-clang-extdef-mapping.c
@@ -0,0 +1,7 @@
+// RUN: clang-extdef-mapping "%s" -- -fasm-blocks 2>&1 | FileCheck %s
+
+void Break() {
+  __asm { int 3 }
+}
+
+// CHECK: {{c:@F@Break .*}}


Index: clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
===
--- clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
+++ clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
@@ -23,6 +23,7 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/TargetSelect.h"
 #include 
 #include 
 #include 
@@ -214,6 +215,10 @@
   }
   CommonOptionsParser &OptionsParser = ExpectedParser.get();
 
+  llvm::InitializeAllTargetInfos();
+  llvm::InitializeAllTargetMCs();
+  llvm::InitializeAllAsmParsers();
+
   return HandleFiles(OptionsParser.getSourcePathList(),
  OptionsParser.getCompilations());
 }
Index: clang/tools/clang-extdef-mapping/CMakeLists.txt
===
--- clang/tools/clang-extdef-mapping/CMakeLists.txt
+++ clang/tools/clang-extdef-mapping/CMakeLists.txt
@@ -1,5 +1,8 @@
 set(LLVM_LINK_COMPONENTS
   ${LLVM_TARGETS_TO_BUILD}
+  AllTargetsAsmParsers
+  AllTargetsDescs
+  AllTargetsInfos
   support
   )
 
Index: clang/test/Tooling/ms-asm-clang-extdef-mapping.c
===
--- /dev/null
+++ clang/test/Tooling/ms-asm-clang-extdef-mapping.c
@@ -0,0 +1,7 @@
+// RUN: clang-extdef-mapping "%s" -- -fasm-blocks 2>&1 | FileCheck %s
+
+void Break() {
+  __asm { int 3 }
+}
+
+// CHECK: {{c:@F@Break .*}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155568: [clang][Interp] Make sure we push integers of the correct size

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

  Integers might not be 32 bits wide, so check the TargetInfo for their
  size.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155568

Files:
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/InterpBuiltin.cpp

Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -32,6 +32,19 @@
   return R;
 }
 
+/// Pushes \p Val to the stack, as a target-dependent 'int'.
+static void pushInt(InterpState &S, int32_t Val) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned IntWidth = TI.getIntWidth();
+
+  if (IntWidth == 32)
+S.Stk.push>(Integral<32, true>::from(Val));
+  else if (IntWidth == 16)
+S.Stk.push>(Integral<16, true>::from(Val));
+  else
+llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
 static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame) {
   const Pointer &A = getParam(Frame, 0);
@@ -67,7 +80,7 @@
   break;
   }
 
-  S.Stk.push>(Integral<32, true>::from(Result));
+  pushInt(S, Result);
   return true;
 }
 
@@ -201,7 +214,7 @@
   const InterpFrame *Frame, const Function *F) {
   const Floating &Arg = S.Stk.peek();
 
-  S.Stk.push>(Integral<32, true>::from(Arg.isNan()));
+  pushInt(S, Arg.isNan());
   return true;
 }
 
@@ -212,10 +225,9 @@
   bool IsInf = Arg.isInf();
 
   if (CheckSign)
-S.Stk.push>(
-Integral<32, true>::from(IsInf ? (Arg.isNegative() ? -1 : 1) : 0));
+pushInt(S, IsInf ? (Arg.isNegative() ? -1 : 1) : 0);
   else
-S.Stk.push>(Integral<32, true>::from(Arg.isInf()));
+pushInt(S, Arg.isInf());
   return true;
 }
 
@@ -224,7 +236,7 @@
  const Function *F) {
   const Floating &Arg = S.Stk.peek();
 
-  S.Stk.push>(Integral<32, true>::from(Arg.isFinite()));
+  pushInt(S, Arg.isFinite());
   return true;
 }
 
@@ -233,7 +245,7 @@
  const Function *F) {
   const Floating &Arg = S.Stk.peek();
 
-  S.Stk.push>(Integral<32, true>::from(Arg.isNormal()));
+  pushInt(S, Arg.isNormal());
   return true;
 }
 
@@ -250,12 +262,12 @@
 
   int32_t Result =
   static_cast((F.classify() & FPClassArg).getZExtValue());
-  S.Stk.push>(Integral<32, true>::from(Result));
+  pushInt(S, Result);
 
   return true;
 }
 
-/// Five int32 values followed by one floating value.
+/// Five int values followed by one floating value.
 static bool interp__builtin_fpclassify(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func) {
@@ -281,8 +293,9 @@
   unsigned Offset = align(primSize(PT_Float)) +
 ((1 + (4 - Index)) * align(primSize(PT_Sint32)));
 
+  // FIXME: The size of the value we're peeking here is target-dependent.
   const Integral<32, true> &I = S.Stk.peek>(Offset);
-  S.Stk.push>(I);
+  pushInt(S, static_cast(I));
   return true;
 }
 
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -95,6 +95,7 @@
   explicit operator unsigned() const { return V; }
   explicit operator int64_t() const { return V; }
   explicit operator uint64_t() const { return V; }
+  explicit operator int32_t() const { return V; }
 
   APSInt toAPSInt() const {
 return APSInt(APInt(Bits, static_cast(V), Signed), !Signed);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154786: [Clang][Driver] Pass through the --be8 endian flag to linker in BareMetal driver For Arm.

2023-07-18 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/ARM.h:77
 bool isARMAProfile(const llvm::Triple &Triple);
+bool isArmBigEndian(const llvm::Triple &Triple, const llvm::opt::ArgList 
&Args);
 

Arm the company has rebranded but for consistency with other code use the 
all-caps name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154786

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


[PATCH] D155147: [X86] Add SM3 instructions.

2023-07-18 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/lib/Headers/sm3intrin.h:31
+///
+/// This intrinsic corresponds to the \c VPDPBSSD instruction.
+///

VPDPBSSD ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155147

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


[PATCH] D155146: [X86] Add SHA512 instructions.

2023-07-18 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.

LGTM - but I'd prefer more complete 32-bit vs 64-bit test coverage (similar to 
the SM3/SM4 patches) if its possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155146

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


[PATCH] D155148: [X86] Add SM4 instructions.

2023-07-18 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/lib/Headers/sm4intrin.h:26
+///
+/// This intrinsic corresponds to the \c VPDPBSSD instruction.
+///

VPDPBSSD ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155148

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


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

2023-07-18 Thread Wang Pengcheng via Phabricator via cfe-commits
wangpc updated this revision to Diff 541415.
wangpc added a comment.

Rebase and fix libcxx tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112921

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

Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp
@@ -8,11 +8,14 @@
 
 // test sized operator delete replacement.
 
+// TODO(mordante) fix this test after updating clang in Docker
+// UNSUPPORTED: clang-17
 // UNSUPPORTED: sanitizer-new-delete, c++03, c++11
+// XFAIL: clang-15, clang-16
+// XFAIL: apple-clang
 
-// NOTE: Clang does not enable sized-deallocation in C++14 and beyond by
-// default. It is only enabled when -fsized-deallocation is given.
-// XFAIL: clang, apple-clang
+// Sized deallocation was added in macOS 10.12 and aligned OSes.
+// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11}}
 
 #include 
 #include 
Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp
@@ -8,11 +8,14 @@
 
 // test sized operator delete[] replacement.
 
+// TODO(mordante) fix this test after updating clang in Docker
+// UNSUPPORTED: clang-17
 // UNSUPPORTED: sanitizer-new-delete, c++03, c++11
+// XFAIL: clang-15, clang-16
+// XFAIL: apple-clang
 
-// NOTE: Clang does not enable sized-deallocation in C++14 and beyond by
-// default. It is only enabled when -fsized-deallocation is given.
-// XFAIL: clang, apple-clang
+// Sized deallocation was added in macOS 10.12 and aligned OSes.
+// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11}}
 
 #include 
 #include 
Index: libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
===
--- libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
+++ libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
@@ -25,6 +25,9 @@
 // GCC doesn't support the aligned-allocation flags.
 // XFAIL: gcc
 
+// TODO(mordante) fix this test after updating clang in Docker
+// UNSUPPORTED: clang-17
+
 // RUN: %{build} -faligned-allocation -fsized-deallocation
 // RUN: %{run}
 // RUN: %{build} -faligned-allocation -fno-sized-deallocation -DNO_SIZE
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1208,12 +1208,11 @@
 
 
 
-(7): In Clang 3.7 and later, sized deallocation is only enabled
-if the user passes the -fsized-deallocation flag. The user must
-supply definitions of the sized deallocation functions, either by providing them
-explicitly or by using a C++ standard library that does. libstdc++
-added these functions in version 5.0, and libc++ added th

[PATCH] D154184: [clang-format] Correctly annotate */&/&& in operator function calls

2023-07-18 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

It looks like this causes a regression in the following example:

  % cat test.cc
  struct A {
std::unique_ptr operator()(const B& b) const;
  };
  % clang-format -style=google test.cc  # should be the same as the input
  struct A {
std::unique_ptr operator()(const B & b) const;
  };

@owenpan, I'm planning to temporarily revert this until you have a chance to 
look into this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154184

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


[PATCH] D152658: [InstCombine] Change SimplifyDemandedVectorElts to use PoisonElts instead of UndefElts

2023-07-18 Thread Manuel Brito via Phabricator via cfe-commits
ManuelJBrito planned changes to this revision.
ManuelJBrito added a comment.

Hello @aqjune thanks for the comments !! Some users of 
SimplifyDemandedVectorElts might need some more tweaking to prevent regressions 
for the cases you noted. I'll work on this as soon as I can!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152658

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


[PATCH] D155529: [clang-format] Add SpaceInParensOption for __attribute__ keyword

2023-07-18 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

We should never make assumptions about what people do/don't use

F28299562: image.png 

If you have this you have to honour it.. if 'SpacesInParentheses ' was true 
then 'InAttributeSpecifiers' needs to be true by default, shouldn't there be 
something in the expanding out of SpacesInParentheses


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155529

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


[PATCH] D155572: [clang][Interp] Start implementing binary operators for complex types

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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155572

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

Index: clang/test/AST/Interp/complex.cpp
===
--- clang/test/AST/Interp/complex.cpp
+++ clang/test/AST/Interp/complex.cpp
@@ -78,3 +78,41 @@
   constexpr _Complex double F9 = {0, 0};
   static_assert(!F9, "");
 }
+
+namespace BinOps {
+namespace Add {
+  constexpr _Complex float A = { 13.0, 2.0 };
+  constexpr _Complex float B = { 2.0, 1.0  };
+  constexpr _Complex float C = A + B;
+  static_assert(__real(C) == 15.0, "");
+  static_assert(__imag(C) == 3.0, "");
+
+  constexpr _Complex float D = B + A;
+  static_assert(__real(D) == 15.0, "");
+  static_assert(__imag(D) == 3.0, "");
+
+  constexpr _Complex unsigned int I1 = { 5,  10 };
+  constexpr _Complex unsigned int I2 = { 40, 2  };
+  constexpr _Complex unsigned int I3 = I1 + I2;
+  static_assert(__real(I3) == 45, "");
+  static_assert(__imag(I3) == 12, "");
+}
+
+namespace Sub {
+  constexpr _Complex float A = { 13.0, 2.0 };
+  constexpr _Complex float B = { 2.0, 1.0  };
+  constexpr _Complex float C = A - B;
+  static_assert(__real(C) == 11.0, "");
+  static_assert(__imag(C) == 1.0, "");
+
+  constexpr _Complex float D = B - A;
+  static_assert(__real(D) == -11.0, "");
+  static_assert(__imag(D) == -1.0, "");
+
+  constexpr _Complex unsigned int I1 = { 5,  10 };
+  constexpr _Complex unsigned int I2 = { 40, 2  };
+  constexpr _Complex unsigned int I3 = I1 - I2;
+  static_assert(__real(I3) == -35, "");
+  static_assert(__imag(I3) == 8, "");
+}
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -64,6 +64,7 @@
   bool VisitBinaryOperator(const BinaryOperator *E);
   bool VisitLogicalBinOp(const BinaryOperator *E);
   bool VisitPointerArithBinOp(const BinaryOperator *E);
+  bool VisitComplexBinOp(const BinaryOperator *E);
   bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E);
   bool VisitCallExpr(const CallExpr *E);
   bool VisitBuiltinCallExpr(const CallExpr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -359,6 +359,9 @@
   if (BO->isLogicalOp())
 return this->VisitLogicalBinOp(BO);
 
+  if (BO->getType()->isAnyComplexType())
+return this->VisitComplexBinOp(BO);
+
   const Expr *LHS = BO->getLHS();
   const Expr *RHS = BO->getRHS();
 
@@ -575,6 +578,107 @@
   return true;
 }
 
+template 
+bool ByteCodeExprGen::VisitComplexBinOp(const BinaryOperator *E) {
+  // FIXME: We expect a pointer on the stack here.
+  //   we should not do that, but that's part of a bigger rework.
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+  PrimType LHSElemT = *this->classifyComplexElementType(LHS->getType());
+  PrimType RHSElemT = *this->classifyComplexElementType(RHS->getType());
+
+  unsigned LHSOffset = this->allocateLocalPrimitive(LHS, PT_Ptr, true, false);
+  unsigned RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, true, false);
+  unsigned ResultOffset = ~0u;
+  if (!this->DiscardResult)
+ResultOffset = this->allocateLocalPrimitive(E, PT_Ptr, true, false);
+
+  assert(LHSElemT == RHSElemT);
+
+  // Save result pointer in ResultOffset
+  if (!this->DiscardResult) {
+if (!this->emitDupPtr(E))
+  return false;
+if (!this->emitSetLocal(PT_Ptr, ResultOffset, E))
+  return false;
+  }
+
+  // Evaluate LHS and save value to LHSOffset.
+  if (!this->visit(LHS))
+return false;
+  if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
+return false;
+
+  // Same with RHS.
+  if (!this->visit(RHS))
+return false;
+  if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
+return false;
+
+  // Now we can get pointers to the LHS and RHS from the offsets above.
+  BinaryOperatorKind Op = E->getOpcode();
+  for (unsigned ElemIndex = 0; ElemIndex != 2; ++ElemIndex) {
+// Result pointer for the store later.
+if (!this->DiscardResult) {
+  if (!this->emitGetLocal(PT_Ptr, ResultOffset, E))
+return false;
+}
+
+if (!this->emitGetLocal(PT_Ptr, LHSOffset, E))
+  return false;
+if (!this->emitConstUint8(ElemIndex, E))
+  return false;
+if (!this->emitArrayElemPtrPopUint8(E))
+  return false;
+if (!this->emitLoadPop(LHSElemT, E))
+  return false;
+
+if (!this->emitGetLocal(PT_Ptr, RHSOffset, E))
+  return false;
+if (!this->emitConstUint8(ElemIndex,

[PATCH] D155573: [Clang] Fix the location of default init expressions

2023-07-18 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Default member initializations constructed from
a parenthesized aggregate initialization should be constructed
at the location of the left paren, to be consistent with
brace initialization.
Otherwise we get diagmostics and source_location in the wrong places.

Fixes #63903


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155573

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/source_location.cpp


Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions 
-verify %s
+// RUN: %clang_cc1 -std=c++2b -fcxx-exceptions -DUSE_CONSTEVAL -DPAREN_INIT 
-fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fms-extensions -DMS 
-fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -fms-extensions -DMS 
-DUSE_CONSTEVAL -fexceptions -verify %s
 // expected-no-diagnostics
@@ -781,3 +782,17 @@
 static_assert(f() != // intentional new line
   f());
 }
+
+#ifdef PAREN_INIT
+namespace GH63903 {
+struct S {
+int _;
+int i = SL::current().line();
+int j = __builtin_LINE();
+};
+// Ensure parent aggregate initialization is consistent with brace
+// aggregate initialization.
+static_assert(S(0).i == S{0}.i);
+static_assert(S(0).j == S{0}.i);
+}
+#endif
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5593,7 +5593,8 @@
 // C++ [dcl.init]p16.6.2.2
 //   The remaining elements are initialized with their default
 //   member initializers, if any
-ExprResult DIE = S.BuildCXXDefaultInitExpr(FD->getLocation(), FD);
+ExprResult DIE = S.BuildCXXDefaultInitExpr(
+Kind.getParenOrBraceRange().getEnd(), FD);
 if (DIE.isInvalid())
   return;
 S.checkInitializerLifetime(SubEntity, DIE.get());


Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions -verify %s
+// RUN: %clang_cc1 -std=c++2b -fcxx-exceptions -DUSE_CONSTEVAL -DPAREN_INIT -fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fms-extensions -DMS -fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -fms-extensions -DMS -DUSE_CONSTEVAL -fexceptions -verify %s
 // expected-no-diagnostics
@@ -781,3 +782,17 @@
 static_assert(f() != // intentional new line
   f());
 }
+
+#ifdef PAREN_INIT
+namespace GH63903 {
+struct S {
+int _;
+int i = SL::current().line();
+int j = __builtin_LINE();
+};
+// Ensure parent aggregate initialization is consistent with brace
+// aggregate initialization.
+static_assert(S(0).i == S{0}.i);
+static_assert(S(0).j == S{0}.i);
+}
+#endif
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5593,7 +5593,8 @@
 // C++ [dcl.init]p16.6.2.2
 //   The remaining elements are initialized with their default
 //   member initializers, if any
-ExprResult DIE = S.BuildCXXDefaultInitExpr(FD->getLocation(), FD);
+ExprResult DIE = S.BuildCXXDefaultInitExpr(
+Kind.getParenOrBraceRange().getEnd(), FD);
 if (DIE.isInvalid())
   return;
 S.checkInitializerLifetime(SubEntity, DIE.get());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154184: [clang-format] Correctly annotate */&/&& in operator function calls

2023-07-18 Thread Emilia Kond via Phabricator via cfe-commits
rymiel added a comment.

Shouldn't that regression already be handled by D155358 
?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154184

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


[PATCH] D155574: [clang][ASTImporter] Fix import of recursive field initializer.

2023-07-18 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: steakhal, martong, gamesh411, Szelethus, dkrupp.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Import of field initializers with circular reference was not working,
this is fixed now.

Fixes issue #63120


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155574

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8107,6 +8107,24 @@
   EXPECT_TRUE(ToX->getInClassInitializer());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportRecursiveFieldInitializer) {
+  const char *Code =
+  R"(
+  class A {
+int b{b};
+  };
+  )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+
+  auto *FromB =
+  FirstDeclMatcher().match(FromTU, fieldDecl(hasName("b")));
+  EXPECT_TRUE(FromB->hasInClassInitializer());
+
+  auto *ToB = Import(FromB, Lang_CXX11);
+  EXPECT_TRUE(ToB->hasInClassInitializer());
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, isNewDecl) {
   Decl *FromTU = getTuDecl(
   R"(
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3902,7 +3902,6 @@
   auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
   auto ToBitWidth = importChecked(Err, D->getBitWidth());
   auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
-  auto ToInitializer = importChecked(Err, D->getInClassInitializer());
   if (Err)
 return std::move(Err);
   const Type *ToCapturedVLAType = nullptr;
@@ -3925,12 +3924,17 @@
 return std::move(Err);
   ToField->setAccess(D->getAccess());
   ToField->setLexicalDeclContext(LexicalDC);
-  if (ToInitializer)
-ToField->setInClassInitializer(ToInitializer);
   ToField->setImplicit(D->isImplicit());
   if (ToCapturedVLAType)
 ToField->setCapturedVLAType(cast(ToCapturedVLAType));
   LexicalDC->addDeclInternal(ToField);
+  // Import initializer only after the field was created, it may have recursive
+  // reference to the field.
+  auto ToInitializer = importChecked(Err, D->getInClassInitializer());
+  if (Err)
+return std::move(Err);
+  if (ToInitializer)
+ToField->setInClassInitializer(ToInitializer);
   return ToField;
 }
 


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8107,6 +8107,24 @@
   EXPECT_TRUE(ToX->getInClassInitializer());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportRecursiveFieldInitializer) {
+  const char *Code =
+  R"(
+  class A {
+int b{b};
+  };
+  )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+
+  auto *FromB =
+  FirstDeclMatcher().match(FromTU, fieldDecl(hasName("b")));
+  EXPECT_TRUE(FromB->hasInClassInitializer());
+
+  auto *ToB = Import(FromB, Lang_CXX11);
+  EXPECT_TRUE(ToB->hasInClassInitializer());
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, isNewDecl) {
   Decl *FromTU = getTuDecl(
   R"(
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3902,7 +3902,6 @@
   auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
   auto ToBitWidth = importChecked(Err, D->getBitWidth());
   auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
-  auto ToInitializer = importChecked(Err, D->getInClassInitializer());
   if (Err)
 return std::move(Err);
   const Type *ToCapturedVLAType = nullptr;
@@ -3925,12 +3924,17 @@
 return std::move(Err);
   ToField->setAccess(D->getAccess());
   ToField->setLexicalDeclContext(LexicalDC);
-  if (ToInitializer)
-ToField->setInClassInitializer(ToInitializer);
   ToField->setImplicit(D->isImplicit());
   if (ToCapturedVLAType)
 ToField->setCapturedVLAType(cast(ToCapturedVLAType));
   LexicalDC->addDeclInternal(ToField);
+  // Import initializer only after the field was created, it may have recursive
+  // reference to the field.
+  auto ToInitializer = importChecked(Err, D->getInClassInitializer());
+  if (Err)
+return std::move(Err);
+  if (ToInitializer)
+ToField->setInClassInitializer(ToInitializer);
   return ToField;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155576: [NFC][clang-extdef-mapping] fix test failure on nonsupported targets

2023-07-18 Thread Ding Fei via Phabricator via cfe-commits
danix800 created this revision.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Specify a working target as POC


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155576

Files:
  clang/test/Tooling/ms-asm-clang-extdef-mapping.c


Index: clang/test/Tooling/ms-asm-clang-extdef-mapping.c
===
--- clang/test/Tooling/ms-asm-clang-extdef-mapping.c
+++ clang/test/Tooling/ms-asm-clang-extdef-mapping.c
@@ -1,7 +1,9 @@
-// RUN: clang-extdef-mapping "%s" -- -fasm-blocks 2>&1 | FileCheck %s
+// RUN: clang-extdef-mapping "%s" -- -fasm-blocks \
+// RUN:   -target x86_64-apple-darwin10 2>&1 | FileCheck %s
+// REQUIRES: x86-registered-target
 
 void Break() {
   __asm { int 3 }
 }
 
-// CHECK: {{c:@F@Break .*}}
+// CHECK: {{10:c:@F@Break}}


Index: clang/test/Tooling/ms-asm-clang-extdef-mapping.c
===
--- clang/test/Tooling/ms-asm-clang-extdef-mapping.c
+++ clang/test/Tooling/ms-asm-clang-extdef-mapping.c
@@ -1,7 +1,9 @@
-// RUN: clang-extdef-mapping "%s" -- -fasm-blocks 2>&1 | FileCheck %s
+// RUN: clang-extdef-mapping "%s" -- -fasm-blocks \
+// RUN:   -target x86_64-apple-darwin10 2>&1 | FileCheck %s
+// REQUIRES: x86-registered-target
 
 void Break() {
   __asm { int 3 }
 }
 
-// CHECK: {{c:@F@Break .*}}
+// CHECK: {{10:c:@F@Break}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fc43c4f - [Flang] Include logical default with default-integer-8

2023-07-18 Thread Kiran Chandramohan via cfe-commits

Author: Kiran Chandramohan
Date: 2023-07-18T11:05:25Z
New Revision: fc43c4f0181bfb7e7821e8b12fbd45e5178e884b

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

LOG: [Flang] Include logical default with default-integer-8

Other compilers include the logical default also with the
default-integer-8 setting. This patch does the same for
flang.

Reviewed By: awarzynski, sscalpone

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
flang/docs/IntrinsicTypes.md
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
flang/test/Lower/Intrinsics/get_environment_variable.f90
flang/tools/f18-parse-demo/f18-parse-demo.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 348d791b8da832..8ffb9388d330f0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5371,7 +5371,7 @@ def fopenacc : Flag<["-"], "fopenacc">, Group,
 def fdefault_double_8 : Flag<["-"],"fdefault-double-8">, Group,
   HelpText<"Set the default double precision kind to an 8 byte wide type">;
 def fdefault_integer_8 : Flag<["-"],"fdefault-integer-8">, Group,
-  HelpText<"Set the default integer kind to an 8 byte wide type">;
+  HelpText<"Set the default integer and logical kind to an 8 byte wide type">;
 def fdefault_real_8 : Flag<["-"],"fdefault-real-8">, Group,
   HelpText<"Set the default real kind to an 8 byte wide type">;
 def flarge_sizes : Flag<["-"],"flarge-sizes">, Group,

diff  --git a/flang/docs/IntrinsicTypes.md b/flang/docs/IntrinsicTypes.md
index c5f22e02c6b6d7..3706b3f3e290ad 100644
--- a/flang/docs/IntrinsicTypes.md
+++ b/flang/docs/IntrinsicTypes.md
@@ -73,8 +73,7 @@ COMPLEX 8
 
  Modifying the default kind with default-integer-8:  
 INTEGER 8
-
-There is no option to modify the default logical kind.
+LOGICAL 8
 
 Modules compiled with 
diff erent default-real and default-integer kinds
 may be freely mixed.

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 4c49f3bae6e30b..e76b67ab444cd4 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -704,6 +704,7 @@ static bool parseDialectArgs(CompilerInvocation &res, 
llvm::opt::ArgList &args,
 res.getDefaultKinds().set_defaultIntegerKind(8);
 res.getDefaultKinds().set_subscriptIntegerKind(8);
 res.getDefaultKinds().set_sizeIntegerKind(8);
+res.getDefaultKinds().set_defaultLogicalKind(8);
   }
   if (args.hasArg(clang::driver::options::OPT_fdefault_double_8)) {
 if (!args.hasArg(clang::driver::options::OPT_fdefault_real_8)) {

diff  --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index a3fe2f09c0703d..f8f1df7c8d4527 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -27,7 +27,7 @@
 ! CHECK-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! CHECK-NEXT: -fconvert=  Set endian conversion of data for 
unformatted files
 ! CHECK-NEXT: -fdefault-double-8 Set the default double precision kind to 
an 8 byte wide type
-! CHECK-NEXT: -fdefault-integer-8Set the default integer kind to an 8 byte 
wide type
+! CHECK-NEXT: -fdefault-integer-8Set the default integer and logical kind 
to an 8 byte wide type
 ! CHECK-NEXT: -fdefault-real-8   Set the default real kind to an 8 byte 
wide type
 ! CHECK-NEXT: -ffast-mathAllow aggressive, lossy floating-point 
optimizations
 ! CHECK-NEXT: -ffixed-form   Process source files in fixed form

diff  --git a/flang/test/Driver/driver-help.f90 
b/flang/test/Driver/driver-help.f90
index e9e4d08d2b8564..a80e6f55d6c1f8 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -27,7 +27,7 @@
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! HELP-NEXT: -fconvert=  Set endian conversion of data for 
unformatted files
 ! HELP-NEXT: -fdefault-double-8 Set the default double precision kind to 
an 8 byte wide type
-! HELP-NEXT: -fdefault-integer-8Set the default integer kind to an 8 byte 
wide type
+! HELP-NEXT: -fdefault-integer-8Set the default integer and logical kind 
to an 8 byte wide type
 ! HELP-NEXT: -fdefault-real-8   Set the default real kind to an 8 byte 
wide type
 ! HELP-NEXT: -ffast-mathAllow aggressive, lossy floating-point 
optimizations
 ! HELP-NEXT: -ffixed-form   Process source files in fixed form
@@ -125,7 +125,7 @@
 ! HELP-FC1-NEXT:Unparse and stop.
 ! HELP-FC1-NEXT: -fdebug-unparseUn

[PATCH] D155279: [Flang] Include logical default with default-integer-8

2023-07-18 Thread Kiran Chandramohan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfc43c4f0181b: [Flang] Include logical default with 
default-integer-8 (authored by kiranchandramohan).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D155279?vs=540336&id=541446#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155279

Files:
  clang/include/clang/Driver/Options.td
  flang/docs/IntrinsicTypes.md
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Lower/Intrinsics/get_environment_variable.f90
  flang/tools/f18-parse-demo/f18-parse-demo.cpp

Index: flang/tools/f18-parse-demo/f18-parse-demo.cpp
===
--- flang/tools/f18-parse-demo/f18-parse-demo.cpp
+++ flang/tools/f18-parse-demo/f18-parse-demo.cpp
@@ -405,6 +405,7 @@
   defaultKinds.set_defaultRealKind(8);
 } else if (arg == "-i8" || arg == "-fdefault-integer-8") {
   defaultKinds.set_defaultIntegerKind(8);
+  defaultKinds.set_defaultLogicalKind(8);
 } else if (arg == "-help" || arg == "--help" || arg == "-?") {
   llvm::errs()
   << "f18-parse-demo options:\n"
Index: flang/test/Lower/Intrinsics/get_environment_variable.f90
===
--- flang/test/Lower/Intrinsics/get_environment_variable.f90
+++ flang/test/Lower/Intrinsics/get_environment_variable.f90
@@ -82,7 +82,8 @@
 
 ! CHECK-LABEL: func @_QPname_and_trim_name_only(
 ! CHECK-SAME: %[[nameArg:.*]]: !fir.boxchar<1> {fir.bindc_name = "name"},
-! CHECK-SAME: %[[trimNameArg:.*]]: !fir.ref> {fir.bindc_name = "trim_name"}) {
+! CHECK-32-SAME: %[[trimNameArg:.*]]: !fir.ref> {fir.bindc_name = "trim_name"}) {
+! CHECK-64-SAME: %[[trimNameArg:.*]]: !fir.ref> {fir.bindc_name = "trim_name"}) {
 subroutine name_and_trim_name_only(name, trim_name)
 character(len=32) :: name
 logical :: trim_name
@@ -120,7 +121,8 @@
 ! CHECK-SAME: %[[valueArg:.*]]: !fir.boxchar<1> {fir.bindc_name = "value"},
 ! CHECK-SAME: %[[lengthArg:[^:]*]]: !fir.ref {fir.bindc_name = "length"},
 ! CHECK-SAME: %[[statusArg:.*]]: !fir.ref {fir.bindc_name = "status"},
-! CHECK-SAME: %[[trimNameArg:.*]]: !fir.ref> {fir.bindc_name = "trim_name"},
+! CHECK-32-SAME: %[[trimNameArg:.*]]: !fir.ref> {fir.bindc_name = "trim_name"},
+! CHECK-64-SAME: %[[trimNameArg:.*]]: !fir.ref> {fir.bindc_name = "trim_name"},
 ! CHECK-SAME: %[[errmsgArg:.*]]: !fir.boxchar<1> {fir.bindc_name = "errmsg"}) {
 subroutine all_arguments(name, value, length, status, trim_name, errmsg)
 character(len=32) :: name, value, errmsg
@@ -138,15 +140,17 @@
 ! CHECK-NEXT: %[[lengthBoxed:.*]] = fir.embox %[[lengthArg]] : (!fir.ref) -> !fir.box
 ! CHECK-NEXT: %[[errmsgBoxed:.*]] = fir.embox %[[errmsgCast]] : (!fir.ref>) -> !fir.box>
 ! CHECK:  %[[trimName:.*]] = fir.if %{{.*}} -> (i1) {
-! CHECK-NEXT:   %[[trimNameLoaded:.*]] = fir.load %[[trimNameArg]] : !fir.ref>
-! CHECK-NEXT:   %[[trimCast:.*]] = fir.convert %[[trimNameLoaded]] : (!fir.logical<4>) -> i1
+! CHECK-32-NEXT:   %[[trimNameLoaded:.*]] = fir.load %[[trimNameArg]] : !fir.ref>
+! CHECK-64-NEXT:   %[[trimNameLoaded:.*]] = fir.load %[[trimNameArg]] : !fir.ref>
+! CHECK-32-NEXT:   %[[trimCast:.*]] = fir.convert %[[trimNameLoaded]] : (!fir.logical<4>) -> i1
+! CHECK-64-NEXT:   %[[trimCast:.*]] = fir.convert %[[trimNameLoaded]] : (!fir.logical<8>) -> i1
 ! CHECK-NEXT:   fir.result %[[trimCast]] : i1
 ! CHECK-NEXT: } else {
 ! CHECK-NEXT:   %[[trueVal:.*]] = arith.constant true
 ! CHECK-NEXT:   fir.result %[[trueVal]] : i1
 ! CHECK-NEXT: }
 ! CHECK: %[[sourceFileString:.*]] = fir.address_of(@_QQcl.[[fileString:.*]]) : !fir.ref>
-! CHECK-NEXT: %[[sourceLine:.*]] = arith.constant [[# @LINE - 20]] : i32
+! CHECK-NEXT: %[[sourceLine:.*]] = arith.constant [[# @LINE - 22]] : i32
 ! CHECK-NEXT: %[[name:.*]] = fir.convert %[[nameBoxed]] : (!fir.box>) -> !fir.box
 ! CHECK-NEXT: %[[value:.*]] = fir.convert %[[valueBoxed]] : (!fir.box>) -> !fir.box
 ! CHECK-NEXT: %[[length:.*]] = fir.convert %[[lengthBoxed]] : (!fir.box) -> !fir.box
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -27,7 +27,7 @@
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! HELP-NEXT: -fconvert=  Set endian conversion of data for unformatted files
 ! HELP-NEXT: -fdefault-double-8 Set the default double precision kind to an 8 byte wide type
-! HELP-NEXT: -fdefault-integer-8Set the default integer kind to an 8 byte wide type
+! HELP-NEXT: -fdefault-integer-8Set the default integer and logical kind to an 8 byte wide type
 ! HELP-NEXT: -fdefault-real-8   Set the default real kind to an 8 b

[PATCH] D155574: [clang][ASTImporter] Fix import of recursive field initializer.

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

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155574

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


[PATCH] D155195: [include-cleaner] Avoid a caching issue when running --edit mode on multiple files.

2023-07-18 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbe861b64d941: [include-cleaner] Avoid a caching issue when 
running --edit mode on multiple… (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D155195?vs=539988&id=541449#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155195

Files:
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp


Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -19,6 +19,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/raw_ostream.h"
@@ -270,12 +271,24 @@
   }
 }
   }
+
+  clang::tooling::ClangTool Tool(OptionsParser->getCompilations(),
+ OptionsParser->getSourcePathList());
+  std::vector> Buffers;
+  for (const auto &File : OptionsParser->getSourcePathList()) {
+auto Content = llvm::MemoryBuffer::getFile(File);
+if (!Content) {
+  llvm::errs() << "Error: can't read file '" << File
+   << "': " << Content.getError().message() << "\n";
+  return 1;
+}
+Buffers.push_back(std::move(Content.get()));
+Tool.mapVirtualFile(File, Buffers.back()->getBuffer());
+  }
+
   auto HeaderFilter = headerFilter();
   if (!HeaderFilter)
 return 1; // error already reported.
   ActionFactory Factory(HeaderFilter);
-  return clang::tooling::ClangTool(OptionsParser->getCompilations(),
-   OptionsParser->getSourcePathList())
- .run(&Factory) ||
- Errors != 0;
+  return Tool.run(&Factory) || Errors != 0;
 }


Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -19,6 +19,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/raw_ostream.h"
@@ -270,12 +271,24 @@
   }
 }
   }
+
+  clang::tooling::ClangTool Tool(OptionsParser->getCompilations(),
+ OptionsParser->getSourcePathList());
+  std::vector> Buffers;
+  for (const auto &File : OptionsParser->getSourcePathList()) {
+auto Content = llvm::MemoryBuffer::getFile(File);
+if (!Content) {
+  llvm::errs() << "Error: can't read file '" << File
+   << "': " << Content.getError().message() << "\n";
+  return 1;
+}
+Buffers.push_back(std::move(Content.get()));
+Tool.mapVirtualFile(File, Buffers.back()->getBuffer());
+  }
+
   auto HeaderFilter = headerFilter();
   if (!HeaderFilter)
 return 1; // error already reported.
   ActionFactory Factory(HeaderFilter);
-  return clang::tooling::ClangTool(OptionsParser->getCompilations(),
-   OptionsParser->getSourcePathList())
- .run(&Factory) ||
- Errors != 0;
+  return Tool.run(&Factory) || Errors != 0;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] be861b6 - [include-cleaner] Avoid a caching issue when running --edit mode on multiple files.

2023-07-18 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-07-18T13:21:23+02:00
New Revision: be861b64d94198230d8f9889b17280e3cd215a0a

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

LOG: [include-cleaner] Avoid a caching issue when running --edit mode on 
multiple files.

Snapshot all analysing files before running the tool, this makes sure
that we analyse all files statelessly and avoid the FileManager caching issue
when running `-edit` on multiple files.

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp 
b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
index ae4d1e97414415..193fdaeeb5e4c8 100644
--- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -19,6 +19,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/raw_ostream.h"
@@ -270,12 +271,24 @@ int main(int argc, const char **argv) {
   }
 }
   }
+
+  clang::tooling::ClangTool Tool(OptionsParser->getCompilations(),
+ OptionsParser->getSourcePathList());
+  std::vector> Buffers;
+  for (const auto &File : OptionsParser->getSourcePathList()) {
+auto Content = llvm::MemoryBuffer::getFile(File);
+if (!Content) {
+  llvm::errs() << "Error: can't read file '" << File
+   << "': " << Content.getError().message() << "\n";
+  return 1;
+}
+Buffers.push_back(std::move(Content.get()));
+Tool.mapVirtualFile(File, Buffers.back()->getBuffer());
+  }
+
   auto HeaderFilter = headerFilter();
   if (!HeaderFilter)
 return 1; // error already reported.
   ActionFactory Factory(HeaderFilter);
-  return clang::tooling::ClangTool(OptionsParser->getCompilations(),
-   OptionsParser->getSourcePathList())
- .run(&Factory) ||
- Errors != 0;
+  return Tool.run(&Factory) || Errors != 0;
 }



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


[PATCH] D154184: [clang-format] Correctly annotate */&/&& in operator function calls

2023-07-18 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

In D154184#4509744 , @rymiel wrote:

> Shouldn't that regression already be handled by D155358 
> ?

Ah, I missed that. That fixes it. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154184

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


[PATCH] D155239: [clang-format] Add SpacesInParens with SpacesInParensOptions

2023-07-18 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

If you limit it to `Never` I don't see any value in the differentiation. You 
could just always use `Custom` (by dropping the custom and only having the 
nested options).

But I think having at least the `Always` option would be nice. If you want 
**always** to have a space and you set everything by hand to true, someone 
comes along and adds a new option (which then is defaulted to `false`) you 
don't get what you want.




Comment at: clang/lib/Format/Format.cpp:1035
 IO.mapOptional("SpaceInEmptyBlock", Style.SpaceInEmptyBlock);
-IO.mapOptional("SpaceInEmptyParentheses", Style.SpaceInEmptyParentheses);
 IO.mapOptional("SpacesBeforeTrailingComments",

MyDeveloperDay wrote:
> By removing the old options don’t you break everyone’s clang format file
You need to parse all of the old options, and map them to the new one, if and 
only if the old one(s) is/are set and the new is not! See below for the other 
deprecated options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155239

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


[PATCH] D155067: [clang][dataflow] Strengthen flow condition assertions.

2023-07-18 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 541454.
mboehme added a comment.

Adapted to `Formula` changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155067

Files:
  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
@@ -3586,7 +3586,8 @@
 EXPECT_TRUE(EnvThen.flowConditionImplies(BarValThen));
 
 auto &BarValElse = getFormula(*BarDecl, EnvElse);
-EXPECT_FALSE(EnvElse.flowConditionImplies(BarValElse));
+EXPECT_TRUE(
+EnvElse.flowConditionImplies(EnvElse.arena().makeNot(BarValElse)));
   });
 }
 
@@ -3617,7 +3618,8 @@
 ASSERT_THAT(BarDecl, NotNull());
 
 auto &BarValThen = getFormula(*BarDecl, EnvThen);
-EXPECT_FALSE(EnvThen.flowConditionImplies(BarValThen));
+EXPECT_TRUE(
+EnvThen.flowConditionImplies(EnvThen.arena().makeNot(BarValThen)));
 
 auto &BarValElse = getFormula(*BarDecl, EnvElse);
 EXPECT_TRUE(EnvElse.flowConditionImplies(BarValElse));


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3586,7 +3586,8 @@
 EXPECT_TRUE(EnvThen.flowConditionImplies(BarValThen));
 
 auto &BarValElse = getFormula(*BarDecl, EnvElse);
-EXPECT_FALSE(EnvElse.flowConditionImplies(BarValElse));
+EXPECT_TRUE(
+EnvElse.flowConditionImplies(EnvElse.arena().makeNot(BarValElse)));
   });
 }
 
@@ -3617,7 +3618,8 @@
 ASSERT_THAT(BarDecl, NotNull());
 
 auto &BarValThen = getFormula(*BarDecl, EnvThen);
-EXPECT_FALSE(EnvThen.flowConditionImplies(BarValThen));
+EXPECT_TRUE(
+EnvThen.flowConditionImplies(EnvThen.arena().makeNot(BarValThen)));
 
 auto &BarValElse = getFormula(*BarDecl, EnvElse);
 EXPECT_TRUE(EnvElse.flowConditionImplies(BarValElse));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155529: [clang-format] Add SpaceInParensOption for __attribute__ keyword

2023-07-18 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/include/clang/Format/Format.h:4208-4213
+/// Put a space in parentheses inside attribute specifier lists.
+/// \code
+///true:  false:
+///__attribute__(( noreturn ))vs. __attribute__((noreturn))
+/// \endcode
+bool InAttributeSpecifierLists;

gedare wrote:
> owenpan wrote:
> > This should be covered by `SpacesInParetheses`, so we really should not 
> > have a special option for `__attribute__`.
> Currently, the behavior of `SpacesInParentheses` does this:
> ```
> __attribute__( ( noreturn ) )
> ```
> In order to prevent this from happening, it is necessary to add an option to 
> disable it somehow, because I don't see that this kind of spacing should ever 
> be used by anyone, but probably someone does it, and it should be maintained 
> for backward compatibility anyway.
> Currently, the behavior of `SpacesInParentheses` does this:
> ```
> __attribute__( ( noreturn ) )
> ```
> In order to prevent this from happening, it is necessary to add an option to 
> disable it somehow, because I don't see that this kind of spacing should ever 
> be used by anyone, but probably someone does it, and it should be maintained 
> for backward compatibility anyway.

And what does clang-format do before your `SpacesInParentheses`? You should 
expand the tests to cover the attributes (if they aren't in there already).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155529

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


[PATCH] D154184: [clang-format] Correctly annotate */&/&& in operator function calls

2023-07-18 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D154184#4509744 , @rymiel wrote:

> Shouldn't that regression already be handled by D155358 
> ?

nice catch @rymiel!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154184

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


[PATCH] D155580: [trivial-auto-var-init] Do not emit initialization code for empty class

2023-07-18 Thread serge via Phabricator via cfe-commits
serge-sans-paille created this revision.
serge-sans-paille added reviewers: nickdesaulniers, jfb, aaron.ballman.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
serge-sans-paille requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Empty class still use one byte, but there is no way to read that byte
programmatically in a legitimate way. Yet trivial auto var init always
generate a store for it and there is no programmatic way to prevent the
generation of that extra store.

This patch harmonizes Clang behavior with GCC and does not generate
initialization code for empty classes under -ftrivial-auto-var-init


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155580

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/auto-var-init-empty-class.cpp
  clang/test/CodeGenCXX/auto-var-init.cpp


Index: clang/test/CodeGenCXX/auto-var-init.cpp
===
--- clang/test/CodeGenCXX/auto-var-init.cpp
+++ clang/test/CodeGenCXX/auto-var-init.cpp
@@ -43,9 +43,6 @@
 // PATTERN-NOT: undef
 // ZERO-NOT: undef
 
-// PATTERN-O0: @__const.test_empty_uninit.uninit = private unnamed_addr 
constant %struct.empty { i8 [[I8]] }, align 1
-// PATTERN-O1-NOT: @__const.test_empty_uninit.uninit
-struct empty {};
 // PATTERN-O0: @__const.test_small_uninit.uninit = private unnamed_addr 
constant %struct.small { i8 [[I8]] }, align 1
 // PATTERN-O0: @__const.test_small_custom.custom = private unnamed_addr 
constant %struct.small { i8 42 }, align 1
 // ZERO-O0: @__const.test_small_custom.custom = private unnamed_addr constant 
%struct.small { i8 42 }, align 1
@@ -586,24 +583,6 @@
 // CHECK-NOT:   !annotation
 // CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
 
-TEST_UNINIT(empty, empty);
-// CHECK-LABEL: @test_empty_uninit()
-// CHECK:   %uninit = alloca %struct.empty, align
-// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
-// PATTERN-LABEL: @test_empty_uninit()
-// PATTERN-O0: call void @llvm.memcpy{{.*}} 
@__const.test_empty_uninit.uninit{{.+}}), !annotation [[AUTO_INIT]]
-// PATTERN-O1: store i8 [[I8]], {{.*}} align 1, !annotation [[AUTO_INIT]]
-// ZERO-LABEL: @test_empty_uninit()
-// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}}), !annotation 
[[AUTO_INIT]]
-// ZERO-O1: store i8 0, {{.*}} align 1, !annotation [[AUTO_INIT]]
-
-TEST_BRACES(empty, empty);
-// CHECK-LABEL: @test_empty_braces()
-// CHECK:   %braces = alloca %struct.empty, align
-// CHECK-NEXT:  call void @llvm.memcpy
-// CHECK-NOT:   !annotation
-// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
-
 TEST_UNINIT(small, small);
 // CHECK-LABEL: @test_small_uninit()
 // CHECK:   %uninit = alloca %struct.small, align
Index: clang/test/CodeGenCXX/auto-var-init-empty-class.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/auto-var-init-empty-class.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown 
-ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ftrivial-auto-var-init=zero 
%s -emit-llvm -o - | FileCheck %s
+
+// C++ empty classes still take some memory, but there is no need to initialize
+// it has it cannot be accessed. This matches GCC behavior.
+
+struct S {
+};
+
+extern "C" void use(struct S*);
+
+// CHECK-LABEL: @empty_class(
+// CHECK:   %s = alloca
+// CHECK-NEXT:  call void @use(ptr noundef %s)
+extern "C" void empty_class(void) {
+  S s;
+  return use(&s);
+}
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1855,6 +1855,13 @@
   }
 }
 
+static bool isEmptyClass(VarDecl const &D) {
+  const Type *Ty = D.getType().getTypePtr();
+  if (const auto *CxxRecordTy = Ty->getAsCXXRecordDecl())
+return CxxRecordTy->isEmpty();
+  return false;
+}
+
 void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
   assert(emission.Variable && "emission was not valid!");
 
@@ -1903,12 +1910,18 @@
   locIsByrefHeader ? emission.getObjectAddress(*this) : emission.Addr;
 
   // Note: constexpr already initializes everything correctly.
+  // Note: empty classes still use a byte, but it's ok not to initialize it as
+  // it cannot be legitimately accessed.
   LangOptions::TrivialAutoVarInitKind trivialAutoVarInit =
   (D.isConstexpr()
? LangOptions::TrivialAutoVarInitKind::Uninitialized
: (D.getAttr()
   ? LangOptions::TrivialAutoVarInitKind::Uninitialized
-  : getContext().getLangOpts().getTrivialAutoVarInit()));
+  : (isEmptyClass(D)
+ ? LangOptions::TrivialAutoVarInitKind::Uninitialized
+ : getContext()
+   .getLangOpts()
+   .getTrivia

[PATCH] D155580: [trivial-auto-var-init] Do not emit initialization code for empty class

2023-07-18 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

Comparison with GCC behavior here: https://godbolt.org/z/xc3j9jEsf


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155580

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


[PATCH] D155173: [clangd] Refine the workflow for diagnostic Fixits.

2023-07-18 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:1014-1016
+  llvm::ArrayRef LSPDiags = Params.context.diagnostics;
+  std::map
+  ToLSPDiagsIndex;

we're already making a copy of `Params.context.diagnostics` when creating the 
`CB`.

so you might as well have a `std::map RefsToDiags;` and get rid of the extra index conversions.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.h:240
+  /// A map from LSP diagnostic to clangd-naive diagnostic.
+  typedef std::map

instead of storing `clangd::Diagnostic` as the key, can we have a 
`DiagnosticKey` struct here (we can have a helper `diagKey(const 
clangd::Diagnostic&) -> DiagnosticKey`)? to make sure we don't get into trouble 
if there are too many "big" diagnostics :)

that way we can also get rid of the custom comparator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155173

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


[PATCH] D155581: [clangd][c++20] Add concept semantic highlighting test case

2023-07-18 Thread Jens Massberg via Phabricator via cfe-commits
massberg created this revision.
massberg added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
massberg requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155581

Files:
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -657,6 +657,7 @@
   void $Function_def[[Bar]]($Concept[[Fooable]] $TemplateParameter[[auto]] 
$Parameter_def[[x]]) {}
 
   template$Bracket[[<]]$Concept[[Fooable]] auto 
$TemplateParameter_def_readonly[[x]]$Bracket[[>]] void $Function_def[[Boo]]() {}
+  bool $Variable_def[[b]] = 
$Concept[[Fooable]]$Bracket[[<]]int$Bracket[[>]];
 )cpp",
   // Dependent template name
   R"cpp(
@@ -886,10 +887,10 @@
   // Issue 1222: readonly modifier for generic parameter
   R"cpp(
 template $Bracket[[<]]typename $TemplateParameter_def[[T]]$Bracket[[>]]
-auto $Function_def[[foo]](const $TemplateParameter[[T]] 
$Parameter_def_readonly[[template_type]], 
-  const $TemplateParameter[[auto]] 
$Parameter_def_readonly[[auto_type]], 
+auto $Function_def[[foo]](const $TemplateParameter[[T]] 
$Parameter_def_readonly[[template_type]],
+  const $TemplateParameter[[auto]] 
$Parameter_def_readonly[[auto_type]],
   const int 
$Parameter_def_readonly[[explicit_type]]) {
-return $Parameter_readonly[[template_type]] 
+return $Parameter_readonly[[template_type]]
  $Operator_userDefined[[+]] $Parameter_readonly[[auto_type]]
  $Operator_userDefined[[+]] 
$Parameter_readonly[[explicit_type]];
 }
@@ -1002,7 +1003,7 @@
 template $Bracket[[<]]class $TemplateParameter_def[[T]]$Bracket[[>]]
 class $Class_def[[B]] {
   template $Bracket[[<]]class $TemplateParameter_def[[U]]$Bracket[[>]] 
void $Method_def[[foo]]($TemplateParameter[[U]]) { }
-  template$Bracket[[<]]$Bracket[[>]] void 
$Method_def[[foo]]$Bracket[[<]]int$Bracket[[>]](int) { } 
+  template$Bracket[[<]]$Bracket[[>]] void 
$Method_def[[foo]]$Bracket[[<]]int$Bracket[[>]](int) { }
   friend void 
$Function_decl[[foo]]$Bracket[[<]]$Bracket[[>]]($TemplateParameter[[T]]);
 };
   )cpp",


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -657,6 +657,7 @@
   void $Function_def[[Bar]]($Concept[[Fooable]] $TemplateParameter[[auto]] $Parameter_def[[x]]) {}
 
   template$Bracket[[<]]$Concept[[Fooable]] auto $TemplateParameter_def_readonly[[x]]$Bracket[[>]] void $Function_def[[Boo]]() {}
+  bool $Variable_def[[b]] = $Concept[[Fooable]]$Bracket[[<]]int$Bracket[[>]];
 )cpp",
   // Dependent template name
   R"cpp(
@@ -886,10 +887,10 @@
   // Issue 1222: readonly modifier for generic parameter
   R"cpp(
 template $Bracket[[<]]typename $TemplateParameter_def[[T]]$Bracket[[>]]
-auto $Function_def[[foo]](const $TemplateParameter[[T]] $Parameter_def_readonly[[template_type]], 
-  const $TemplateParameter[[auto]] $Parameter_def_readonly[[auto_type]], 
+auto $Function_def[[foo]](const $TemplateParameter[[T]] $Parameter_def_readonly[[template_type]],
+  const $TemplateParameter[[auto]] $Parameter_def_readonly[[auto_type]],
   const int $Parameter_def_readonly[[explicit_type]]) {
-return $Parameter_readonly[[template_type]] 
+return $Parameter_readonly[[template_type]]
  $Operator_userDefined[[+]] $Parameter_readonly[[auto_type]]
  $Operator_userDefined[[+]] $Parameter_readonly[[explicit_type]];
 }
@@ -1002,7 +1003,7 @@
 template $Bracket[[<]]class $TemplateParameter_def[[T]]$Bracket[[>]]
 class $Class_def[[B]] {
   template $Bracket[[<]]class $TemplateParameter_def[[U]]$Bracket[[>]] void $Method_def[[foo]]($TemplateParameter[[U]]) { }
-  template$Bracket[[<]]$Bracket[[>]] void $Method_def[[foo]]$Bracket[[<]]int$Bracket[[>]](int) { } 
+  template$Bracket[[<]]$Bracket[[>]] void $Method_def[[foo]]$Bracket[[<]]int$Bracket[[>]](int) { }
   friend void $Function_decl[[foo]]$Bracket[[<]]$Bracket[[>]]($TemplateParameter[[T]]);
 };
   )cpp",

[clang] c24f0f9 - [NFC][clang-extdef-mapping] fix test failure on unsupported targets

2023-07-18 Thread via cfe-commits

Author: dingfei
Date: 2023-07-18T19:56:50+08:00
New Revision: c24f0f9bd6f4261d3ebdb34cbf4634026be0f2dc

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

LOG: [NFC][clang-extdef-mapping] fix test failure on unsupported targets

ms-stlye asm block is not supported on targets like arm/hexagon.
Specify a working target as POC.

Introduced by https://reviews.llvm.org/D154983

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

Added: 


Modified: 
clang/test/Tooling/ms-asm-clang-extdef-mapping.c

Removed: 




diff  --git a/clang/test/Tooling/ms-asm-clang-extdef-mapping.c 
b/clang/test/Tooling/ms-asm-clang-extdef-mapping.c
index 00632d11e3dcbc..ed71628a577eac 100644
--- a/clang/test/Tooling/ms-asm-clang-extdef-mapping.c
+++ b/clang/test/Tooling/ms-asm-clang-extdef-mapping.c
@@ -1,7 +1,9 @@
-// RUN: clang-extdef-mapping "%s" -- -fasm-blocks 2>&1 | FileCheck %s
+// RUN: clang-extdef-mapping "%s" -- -fasm-blocks \
+// RUN:   -target x86_64-apple-darwin10 2>&1 | FileCheck %s
+// REQUIRES: x86-registered-target
 
 void Break() {
   __asm { int 3 }
 }
 
-// CHECK: {{c:@F@Break .*}}
+// CHECK: {{10:c:@F@Break}}



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


[PATCH] D155576: [NFC][clang-extdef-mapping] fix test failure on nonsupported targets

2023-07-18 Thread Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc24f0f9bd6f4: [NFC][clang-extdef-mapping] fix test failure 
on unsupported targets (authored by dingfei ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155576

Files:
  clang/test/Tooling/ms-asm-clang-extdef-mapping.c


Index: clang/test/Tooling/ms-asm-clang-extdef-mapping.c
===
--- clang/test/Tooling/ms-asm-clang-extdef-mapping.c
+++ clang/test/Tooling/ms-asm-clang-extdef-mapping.c
@@ -1,7 +1,9 @@
-// RUN: clang-extdef-mapping "%s" -- -fasm-blocks 2>&1 | FileCheck %s
+// RUN: clang-extdef-mapping "%s" -- -fasm-blocks \
+// RUN:   -target x86_64-apple-darwin10 2>&1 | FileCheck %s
+// REQUIRES: x86-registered-target
 
 void Break() {
   __asm { int 3 }
 }
 
-// CHECK: {{c:@F@Break .*}}
+// CHECK: {{10:c:@F@Break}}


Index: clang/test/Tooling/ms-asm-clang-extdef-mapping.c
===
--- clang/test/Tooling/ms-asm-clang-extdef-mapping.c
+++ clang/test/Tooling/ms-asm-clang-extdef-mapping.c
@@ -1,7 +1,9 @@
-// RUN: clang-extdef-mapping "%s" -- -fasm-blocks 2>&1 | FileCheck %s
+// RUN: clang-extdef-mapping "%s" -- -fasm-blocks \
+// RUN:   -target x86_64-apple-darwin10 2>&1 | FileCheck %s
+// REQUIRES: x86-registered-target
 
 void Break() {
   __asm { int 3 }
 }
 
-// CHECK: {{c:@F@Break .*}}
+// CHECK: {{10:c:@F@Break}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155580: [trivial-auto-var-init] Do not emit initialization code for empty class

2023-07-18 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:1915-1924
   LangOptions::TrivialAutoVarInitKind trivialAutoVarInit =
   (D.isConstexpr()
? LangOptions::TrivialAutoVarInitKind::Uninitialized
: (D.getAttr()
   ? LangOptions::TrivialAutoVarInitKind::Uninitialized
-  : getContext().getLangOpts().getTrivialAutoVarInit()));
+  : (isEmptyClass(D)
+ ? LangOptions::TrivialAutoVarInitKind::Uninitialized

Can we simplify the condition here? this cascade of ternaries is becoming hard 
to read.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155580

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


[PATCH] D155529: [clang-format] Add SpaceInParensOption for __attribute__ keyword

2023-07-18 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

We should never make assumptions about what people do/don't use

F28299562: image.png 

If you have this you have to honour it.. if 'SpacesInParentheses ' was true 
then 'InAttributeSpecifiers' needs to be true by default, shouldn't there be 
something in the expanding out of SpacesInParentheses


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155529

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


[PATCH] D155584: [clang][NFC] Simplify SourceLocExpr::EvaluateInContext

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

  Use ASTContext::MakeIntValue and remove the std::tie+lambda weirdness.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155584

Files:
  clang/lib/AST/Expr.cpp


Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -2301,14 +2301,17 @@
   SourceLocation Loc;
   const DeclContext *Context;
 
-  std::tie(Loc,
-   Context) = [&]() -> std::pair {
-if (auto *DIE = dyn_cast_or_null(DefaultExpr))
-  return {DIE->getUsedLocation(), DIE->getUsedContext()};
-if (auto *DAE = dyn_cast_or_null(DefaultExpr))
-  return {DAE->getUsedLocation(), DAE->getUsedContext()};
-return {this->getLocation(), this->getParentContext()};
-  }();
+  if (const auto *DIE = dyn_cast_if_present(DefaultExpr)) {
+Loc = DIE->getUsedLocation();
+Context = DIE->getUsedContext();
+  } else if (const auto *DAE =
+ dyn_cast_if_present(DefaultExpr)) {
+Loc = DAE->getUsedLocation();
+Context = DAE->getUsedContext();
+  } else {
+Loc = getLocation();
+Context = getParentContext();
+  }
 
   PresumedLoc PLoc = Ctx.getSourceManager().getPresumedLoc(
   Ctx.getSourceManager().getExpansionRange(Loc).getEnd());
@@ -2346,13 +2349,9 @@
 CurDecl ? PredefinedExpr::ComputeName(Kind, CurDecl) : 
std::string(""));
   }
   case SourceLocExpr::Line:
-  case SourceLocExpr::Column: {
-llvm::APSInt IntVal(Ctx.getIntWidth(Ctx.UnsignedIntTy),
-/*isUnsigned=*/true);
-IntVal = getIdentKind() == SourceLocExpr::Line ? PLoc.getLine()
-   : PLoc.getColumn();
-return APValue(IntVal);
-  }
+return APValue(Ctx.MakeIntValue(PLoc.getLine(), Ctx.UnsignedIntTy));
+  case SourceLocExpr::Column:
+return APValue(Ctx.MakeIntValue(PLoc.getColumn(), Ctx.UnsignedIntTy));
   case SourceLocExpr::SourceLocStruct: {
 // Fill in a std::source_location::__impl structure, by creating an
 // artificial file-scoped CompoundLiteralExpr, and returning a pointer to
@@ -2365,7 +2364,7 @@
 // the ImplDecl type is as expected.
 
 APValue Value(APValue::UninitStruct(), 0, 4);
-for (FieldDecl *F : ImplDecl->fields()) {
+for (const FieldDecl *F : ImplDecl->fields()) {
   StringRef Name = F->getName();
   if (Name == "_M_file_name") {
 SmallString<256> Path(PLoc.getFilename());
@@ -2382,16 +2381,10 @@
   PredefinedExpr::PrettyFunction, CurDecl))
 : "");
   } else if (Name == "_M_line") {
-QualType Ty = F->getType();
-llvm::APSInt IntVal(Ctx.getIntWidth(Ty),
-Ty->hasUnsignedIntegerRepresentation());
-IntVal = PLoc.getLine();
+llvm::APSInt IntVal = Ctx.MakeIntValue(PLoc.getLine(), F->getType());
 Value.getStructField(F->getFieldIndex()) = APValue(IntVal);
   } else if (Name == "_M_column") {
-QualType Ty = F->getType();
-llvm::APSInt IntVal(Ctx.getIntWidth(Ty),
-Ty->hasUnsignedIntegerRepresentation());
-IntVal = PLoc.getColumn();
+llvm::APSInt IntVal = Ctx.MakeIntValue(PLoc.getColumn(), F->getType());
 Value.getStructField(F->getFieldIndex()) = APValue(IntVal);
   }
 }


Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -2301,14 +2301,17 @@
   SourceLocation Loc;
   const DeclContext *Context;
 
-  std::tie(Loc,
-   Context) = [&]() -> std::pair {
-if (auto *DIE = dyn_cast_or_null(DefaultExpr))
-  return {DIE->getUsedLocation(), DIE->getUsedContext()};
-if (auto *DAE = dyn_cast_or_null(DefaultExpr))
-  return {DAE->getUsedLocation(), DAE->getUsedContext()};
-return {this->getLocation(), this->getParentContext()};
-  }();
+  if (const auto *DIE = dyn_cast_if_present(DefaultExpr)) {
+Loc = DIE->getUsedLocation();
+Context = DIE->getUsedContext();
+  } else if (const auto *DAE =
+ dyn_cast_if_present(DefaultExpr)) {
+Loc = DAE->getUsedLocation();
+Context = DAE->getUsedContext();
+  } else {
+Loc = getLocation();
+Context = getParentContext();
+  }
 
   PresumedLoc PLoc = Ctx.getSourceManager().getPresumedLoc(
   Ctx.getSourceManager().getExpansionRange(Loc).getEnd());
@@ -2346,13 +2349,9 @@
 CurDecl ? PredefinedExpr::ComputeName(Kind, CurDecl) : std::string(""));
   }
   case SourceLocExpr::Line:
-  case SourceLocExpr::Column: {
-llvm::APSInt IntVal(Ctx.getIntWidth(Ctx.UnsignedIntTy),
-/*isUnsigned=*/true);
-IntVal = getIdentKind() == SourceLocExpr::Line ? PLoc.getLine()
-   

[PATCH] D155584: [clang][NFC] Simplify SourceLocExpr::EvaluateInContext

2023-07-18 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.

I agree, this looks better


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155584

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


[PATCH] D155445: [analyzer][docs] Add CSA release notes

2023-07-18 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:908
+  (`7cd1f3ad22e4 `_)
+- Fixed a null-pointer dereference crash inside the ``MoveChecker``.
+  (`d172b65ef001 `_)

steakhal wrote:
> xazax.hun wrote:
> > steakhal wrote:
> > > xazax.hun wrote:
> > > > I think we usually do not mention crash fixes in the changelog. We have 
> > > > them in almost every release and sometimes there are quite a few of 
> > > > them.
> > > I won't mention the explicit commit where it was fixed.
> > > However, downstream users might wanna know about crashes and fixes that 
> > > happened in this release.
> > > And speaking about past practices about release notes, I think we can 
> > > improve on that TBH.
> > > We can move it down on the list if you want, but I'd rather keep it.
> > Is this the only crash fix we had? Moving crash fixes to the bottom of the 
> > list sounds good to me. 
> No, it wasn't. We also had one for init-expr global variable initializers. [[ 
> https://github.com/llvm/llvm-project/commit/558b46fde2db | See ]] 
> I swept that fix under the carpet of "Fixed some bugs around the handling of 
> constant global arrays and their initializer expressions". I made it more 
> explicit now.
> 
> However, at this point, I think it's okay to simply omit the mention of the 
> null deref crash fix.
> Second thoughts?
I have no strong preference, I am fine with both :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155445

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


[PATCH] D155573: [Clang] Fix the location of default init expressions

2023-07-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Should this come with a release note or is it correcting functionality added 
for this release?




Comment at: clang/test/SemaCXX/source_location.cpp:796
+static_assert(S(0).i == S{0}.i);
+static_assert(S(0).j == S{0}.i);
+}

Shouldn't this test fail because `i != j`?

Can you add a test that demonstrates we've corrected the source location 
information for diagnostics?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155573

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


[PATCH] D155573: [Clang] Fix the location of default init expressions

2023-07-18 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/test/SemaCXX/source_location.cpp:796
+static_assert(S(0).i == S{0}.i);
+static_assert(S(0).j == S{0}.i);
+}

aaron.ballman wrote:
> Shouldn't this test fail because `i != j`?
> 
> Can you add a test that demonstrates we've corrected the source location 
> information for diagnostics?
They should all be equal!

> Can you add a test that demonstrates we've corrected the source location 
> information for diagnostics?

Hum, i was planning to do that in https://reviews.llvm.org/D155175. I can try 
to think of something there!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155573

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


[PATCH] D155573: [Clang] Fix the location of default init expressions

2023-07-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/SemaCXX/source_location.cpp:796
+static_assert(S(0).i == S{0}.i);
+static_assert(S(0).j == S{0}.i);
+}

cor3ntin wrote:
> aaron.ballman wrote:
> > Shouldn't this test fail because `i != j`?
> > 
> > Can you add a test that demonstrates we've corrected the source location 
> > information for diagnostics?
> They should all be equal!
> 
> > Can you add a test that demonstrates we've corrected the source location 
> > information for diagnostics?
> 
> Hum, i was planning to do that in https://reviews.llvm.org/D155175. I can try 
> to think of something there!
> They should all be equal!

Wha? Shouldn't `i == 790 && j == 791`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155573

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


[PATCH] D61670: [RFC] [MinGW] Allow opting out from .refptr stubs

2023-07-18 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added subscribers: alvinhochun, jeremyd2019, jacek, aaron.ballman.
mstorsjo added a comment.

I'm looking to pick this up again - hopefully @rnk has time to discuss what 
would be a good way forward.

So taking it from the top; both GCC and Clang generate `.refptr` stubs when 
referencing variables that might be autoimported. The exact circumstances 
differ a little bit though.

In GCC this is done by making GCC for Windows/x86_64 default to a medium code 
model, and under this code model, references to variables without a visible 
definition get indirection via a `.refptr` stub. This doesn't happen for i386. 
By building with `-mcmodel=small`, one can opt out of them.

In Clang, we generate such `.refptr` stubs with similar heuristics (variables 
without a visible definition), but we do it for all architectures. There are 
three different reasons for wanting to do this:

- Normally, when code references a variable (in the default code model), it is 
done with a 32 bit relative (or absolute) relocation. If the variable turns out 
to end up imported from a different DLL, in a 64 bit address space it may end 
up loaded too far away for a 32 bit relocation.
- If we don't use a `.refptr` stub, the mingw runtime pseudo relocation 
mechanism needs to patch the address at runtime. If this is referenced in a 
code section, it means that the code section needs to be mapped RWX while 
patching it. Changing the memory protection to RWX is generally undesireable 
(and is disallowed outright, within the UWP app model).
- The runtime pseudo relocation format works on N-bit relative or absolute 
addresses. With the x86 instruction encoding, this turns out to work fine - an 
instruction that refers to a different memory location generally is a couple 
bytes of instruction prefix, followed by a 32 bit relative or absolute address, 
easily patchable. In the case of ARM and AArch64, there are no such 
instructions, and loading e.g. a 32 bit immediate constant is often done by a 
pair of instructions, with the actual payload bits scattered throughout the 
instructions. The runtime pseudo relocation format obviously doesn't support 
patching this.

Therefore, with Clang we generate `.refptr` stubs on all architectures. However 
it would be good to be able to opt out from them. When the variables actually 
end up autoimported, LLD has got a couple neat tricks that makes the actual 
pseudo relocations go away in most cases (when it can alias the 
`.refptr.variable` stub with the `__imp_variable` IAT entry). But for the cases 
when the variable isn't autoimported, the `.refptr` stub has to be kept, and it 
produces larger/slower code and more data than necessary. And for low level 
projects like Wine, it might be desireable to be able to tune exactly what is 
done.

So within the Clang context, it is not entirely about range (where the code 
model might be a reasonable fit), but about whether to be prepared for 
autoimports or not.

Within Clang, it is handled by marking variables we know are in the same DLL as 
`dso_local`, while variables that might be autoimported don't get that flag. 
Within LLVM, references to variables that aren't marked `dso_local` get 
indirection via a `.refptr` stub.

Possible ways of handling it would be to invent a new flag for this purpose; 
e.g. `-fno-autoimport` (with the corresponding `-fautoimport` meaning the 
default mode). That makes the use fairly clear, but its role is also a bit 
unclear; there are linker flags `--disable-auto-import` and 
`--disable-runtime-pseudo-reloc` which disable either autoimports of all sorts, 
or only autoimports that end up with an actual pseudo reloc (allowing the 
zero-cost ones that are aliased to IAT entries).

If we make the flag only affect code generation, having it named 
`-fno-autoimport` when the linker still may do something different (ending up 
with a pseudo relocation in executable code, which possibly still works fine, 
just less elegant) is unclear. If we on the other hand make the same flag imply 
either of `--disable-auto-import` or `--disable-runtime-pseudo-reloc`, then 
that name is rather clear.

If we only make it affect code generation, something like `-fdso-local` or 
`-fno-refptr` might be more precise.

If we make the flag imply linker options, then it becomes much clearer to spot 
the error, if you enabled this but the code base still would need autoimports 
somewhere. (This has happened - see 
https://code.videolan.org/videolan/dav1d/-/merge_requests/1303#note_301859, 
https://code.videolan.org/videolan/dav1d/-/merge_requests/1349 and 
https://code.videolan.org/videolan/dav1d/-/merge_requests/1361.) If we make the 
flag only affect code generation, it becomes a more clear match for projects 
using `-mcmodel=small` with GCC today.

I'm open for opinions on how to name these options, @alvinhochun @mati865 
@jeremyd2019 and @jacek. Also requesting early guidance from @aaron.ballman.


Repository:
  rC Clang

CHANGES SINCE LAST ACT

[PATCH] D155573: [Clang] Fix the location of default init expressions

2023-07-18 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 541473.
cor3ntin added a comment.

Address Aaron's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155573

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp
  clang/test/SemaCXX/source_location.cpp


Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions 
-verify %s
+// RUN: %clang_cc1 -std=c++2b -fcxx-exceptions -DUSE_CONSTEVAL -DPAREN_INIT 
-fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fms-extensions -DMS 
-fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -fms-extensions -DMS 
-DUSE_CONSTEVAL -fexceptions -verify %s
 // expected-no-diagnostics
@@ -781,3 +782,18 @@
 static_assert(f() != // intentional new line
   f());
 }
+
+#ifdef PAREN_INIT
+namespace GH63903 {
+struct S {
+int _;
+int i = SL::current().line();
+int j = __builtin_LINE();
+};
+// Ensure parent aggregate initialization is consistent with brace
+// aggregate initialization.
+static_assert(S(0).i == S{0}.i);
+static_assert(S(0).j == S{0}.j);
+static_assert(S(0).j == S{0}.i);
+}
+#endif
Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -294,3 +294,14 @@
 }
 
 }
+
+namespace GH63903 {
+  constexpr int f(); // expected-note {{declared here}}
+  struct S {
+int a = 0, b = f(); // expected-note {{undefined function 'f' cannot be 
used in a constant expression}}
+  };
+
+  // Test that errors produced by default members are produced at the location 
of the initialization
+  constexpr S s(0); // beforecxx20-warning {{aggregate initialization of type 
'const S' from a parenthesized list of values is a C++20 extension}} \
+// expected-error {{constexpr variable 's' must be 
initialized by a constant expression}}
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5593,7 +5593,8 @@
 // C++ [dcl.init]p16.6.2.2
 //   The remaining elements are initialized with their default
 //   member initializers, if any
-ExprResult DIE = S.BuildCXXDefaultInitExpr(FD->getLocation(), FD);
+ExprResult DIE = S.BuildCXXDefaultInitExpr(
+Kind.getParenOrBraceRange().getEnd(), FD);
 if (DIE.isInvalid())
   return;
 S.checkInitializerLifetime(SubEntity, DIE.get());
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -707,6 +707,9 @@
 - Fix crash when emitting diagnostic for out of order designated initializers
   in C++.
   (`#63605 `_)
+- Fix location of default member initialization in parenthesized aggregate
+  initialization.
+  (`#63903 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions -verify %s
+// RUN: %clang_cc1 -std=c++2b -fcxx-exceptions -DUSE_CONSTEVAL -DPAREN_INIT -fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fms-extensions -DMS -fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -fms-extensions -DMS -DUSE_CONSTEVAL -fexceptions -verify %s
 // expected-no-diagnostics
@@ -781,3 +782,18 @@
 static_assert(f() != // intentional new line
   f());
 }
+
+#ifdef PAREN_INIT
+namespace GH63903 {
+struct S {
+int _;
+int i = SL::current().line();
+int j = __builtin_LINE();
+};
+// Ensure parent aggregate initialization is consistent with brace
+// aggregate initialization.
+static_assert(S(0).i == S{0}.i);
+static_assert(S(0).j == S{0}.j);
+static_assert(S(0).j == S{0}.i);
+}
+#endif
Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -294,3 +294,14 @@
 }
 
 }
+
+namespace G

[PATCH] D155573: [Clang] Fix the location of default init expressions

2023-07-18 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/SemaCXX/source_location.cpp:796
+static_assert(S(0).i == S{0}.i);
+static_assert(S(0).j == S{0}.i);
+}

aaron.ballman wrote:
> cor3ntin wrote:
> > aaron.ballman wrote:
> > > Shouldn't this test fail because `i != j`?
> > > 
> > > Can you add a test that demonstrates we've corrected the source location 
> > > information for diagnostics?
> > They should all be equal!
> > 
> > > Can you add a test that demonstrates we've corrected the source location 
> > > information for diagnostics?
> > 
> > Hum, i was planning to do that in https://reviews.llvm.org/D155175. I can 
> > try to think of something there!
> > They should all be equal!
> 
> Wha? Shouldn't `i == 790 && j == 791`?
IIUC, they are evaluated as part of the constructor, so the values should be 
795 or 796. Maybe that can be changed to
```
static_assert(S(0).i == S{0}.i == 796);
```
?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155573

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


[PATCH] D155580: [trivial-auto-var-init] Do not emit initialization code for empty class

2023-07-18 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 541475.
serge-sans-paille added a comment.

switch from cascading ternary operator to cascading if for readability.


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

https://reviews.llvm.org/D155580

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/auto-var-init-empty-class.cpp
  clang/test/CodeGenCXX/auto-var-init.cpp

Index: clang/test/CodeGenCXX/auto-var-init.cpp
===
--- clang/test/CodeGenCXX/auto-var-init.cpp
+++ clang/test/CodeGenCXX/auto-var-init.cpp
@@ -43,9 +43,6 @@
 // PATTERN-NOT: undef
 // ZERO-NOT: undef
 
-// PATTERN-O0: @__const.test_empty_uninit.uninit = private unnamed_addr constant %struct.empty { i8 [[I8]] }, align 1
-// PATTERN-O1-NOT: @__const.test_empty_uninit.uninit
-struct empty {};
 // PATTERN-O0: @__const.test_small_uninit.uninit = private unnamed_addr constant %struct.small { i8 [[I8]] }, align 1
 // PATTERN-O0: @__const.test_small_custom.custom = private unnamed_addr constant %struct.small { i8 42 }, align 1
 // ZERO-O0: @__const.test_small_custom.custom = private unnamed_addr constant %struct.small { i8 42 }, align 1
@@ -586,24 +583,6 @@
 // CHECK-NOT:   !annotation
 // CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
 
-TEST_UNINIT(empty, empty);
-// CHECK-LABEL: @test_empty_uninit()
-// CHECK:   %uninit = alloca %struct.empty, align
-// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
-// PATTERN-LABEL: @test_empty_uninit()
-// PATTERN-O0: call void @llvm.memcpy{{.*}} @__const.test_empty_uninit.uninit{{.+}}), !annotation [[AUTO_INIT]]
-// PATTERN-O1: store i8 [[I8]], {{.*}} align 1, !annotation [[AUTO_INIT]]
-// ZERO-LABEL: @test_empty_uninit()
-// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}}), !annotation [[AUTO_INIT]]
-// ZERO-O1: store i8 0, {{.*}} align 1, !annotation [[AUTO_INIT]]
-
-TEST_BRACES(empty, empty);
-// CHECK-LABEL: @test_empty_braces()
-// CHECK:   %braces = alloca %struct.empty, align
-// CHECK-NEXT:  call void @llvm.memcpy
-// CHECK-NOT:   !annotation
-// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
-
 TEST_UNINIT(small, small);
 // CHECK-LABEL: @test_small_uninit()
 // CHECK:   %uninit = alloca %struct.small, align
Index: clang/test/CodeGenCXX/auto-var-init-empty-class.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/auto-var-init-empty-class.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s
+
+// C++ empty classes still take some memory, but there is no need to initialize
+// it has it cannot be accessed. This matches GCC behavior.
+
+struct S {
+};
+
+extern "C" void use(struct S*);
+
+// CHECK-LABEL: @empty_class(
+// CHECK:   %s = alloca
+// CHECK-NEXT:  call void @use(ptr noundef %s)
+extern "C" void empty_class(void) {
+  S s;
+  return use(&s);
+}
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1855,6 +1855,13 @@
   }
 }
 
+static bool isEmptyClass(VarDecl const &D) {
+  const Type *Ty = D.getType().getTypePtr();
+  if (const auto *CxxRecordTy = Ty->getAsCXXRecordDecl())
+return CxxRecordTy->isEmpty();
+  return false;
+}
+
 void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
   assert(emission.Variable && "emission was not valid!");
 
@@ -1902,13 +1909,18 @@
   const Address Loc =
   locIsByrefHeader ? emission.getObjectAddress(*this) : emission.Addr;
 
-  // Note: constexpr already initializes everything correctly.
-  LangOptions::TrivialAutoVarInitKind trivialAutoVarInit =
-  (D.isConstexpr()
-   ? LangOptions::TrivialAutoVarInitKind::Uninitialized
-   : (D.getAttr()
-  ? LangOptions::TrivialAutoVarInitKind::Uninitialized
-  : getContext().getLangOpts().getTrivialAutoVarInit()));
+  LangOptions::TrivialAutoVarInitKind trivialAutoVarInit;
+  if (D.isConstexpr())
+// Constexpr already initializes everything correctly.
+trivialAutoVarInit = LangOptions::TrivialAutoVarInitKind::Uninitialized;
+  else if (D.getAttr())
+trivialAutoVarInit = LangOptions::TrivialAutoVarInitKind::Uninitialized;
+  else if (isEmptyClass(D))
+// Empty classes still use a byte, but it's ok not to initialize it as
+// it cannot be legitimately accessed.
+trivialAutoVarInit = LangOptions::TrivialAutoVarInitKind::Uninitialized;
+  else
+trivialAutoVarInit = getContext().getLangOpts().getTrivialAutoVarInit();
 
   auto initializeWhatIsTechnicallyUninitialized = [&](Address Loc) {
 if (trivialAutoVarInit ==
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.

[PATCH] D152793: [RISCV] Add MC layer support for Zicfisslp.

2023-07-18 Thread Yeting Kuo via Phabricator via cfe-commits
fakepaper56 updated this revision to Diff 541477.
fakepaper56 added a comment.
Herald added a subscriber: wangpc.

Update instruction information and mark ssp as reserved register.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152793

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZicfisslp.td
  llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
  llvm/lib/Target/RISCV/RISCVRegisterInfo.td
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/zicfisslp-invalid.s
  llvm/test/MC/RISCV/zicfisslp-valid.s

Index: llvm/test/MC/RISCV/zicfisslp-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/zicfisslp-valid.s
@@ -0,0 +1,120 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zicfisslp,+c -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zicfisslp,+c -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zicfisslp,+c < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zicfisslp -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zicfisslp,+c < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zicfisslp -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv32 -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv64 -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+# CHECK-ASM-AND-OBJ: ssload x1
+# CHECK-ASM: encoding: [0x73,0xc0,0xc0,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfisslp' (Shadow-stack and Landing-pads)
+ssload x1
+
+# CHECK-ASM-AND-OBJ: ssload x1
+# CHECK-ASM: encoding: [0x73,0xc0,0xc0,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfisslp' (Shadow-stack and Landing-pads)
+ssload ra
+
+# CHECK-ASM-AND-OBJ: ssload x5
+# CHECK-ASM: encoding: [0x73,0xc0,0xc2,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfisslp' (Shadow-stack and Landing-pads)
+ssload x5
+
+# CHECK-ASM-AND-OBJ: ssload x5
+# CHECK-ASM: encoding: [0x73,0xc0,0xc2,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfisslp' (Shadow-stack and Landing-pads)
+ssload t0
+
+# CHECK-ASM-AND-OBJ: sspopchk x1
+# CHECK-ASM: encoding: [0xf3,0x40,0xc0,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfisslp' (Shadow-stack and Landing-pads)
+sspopchk x1
+
+# CHECK-ASM-AND-OBJ: sspopchk x1
+# CHECK-ASM: encoding: [0xf3,0x40,0xc0,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfisslp' (Shadow-stack and Landing-pads)
+sspopchk ra
+
+# CHECK-ASM-AND-OBJ: sspopchk x5
+# CHECK-ASM: encoding: [0xf3,0x42,0xc0,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfisslp' (Shadow-stack and Landing-pads)
+sspopchk x5
+
+# CHECK-ASM-AND-OBJ: sspopchk x5
+# CHECK-ASM: encoding: [0xf3,0x42,0xc0,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfisslp' (Shadow-stack and Landing-pads)
+sspopchk t0
+
+# CHECK-ASM-AND-OBJ: sspinc 4
+# CHECK-ASM: encoding: [0x73,0x40,0xd2,0x81]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfisslp' (Shadow-stack and Landing-pads)
+sspinc 4
+
+# CHECK-ASM-AND-OBJ: sspush ra
+# CHECK-ASM: encoding: [0x73,0x40,0x10,0x8a]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfisslp' (Shadow-stack and Landing-pads)
+sspush x1
+
+# CHECK-ASM-AND-OBJ: sspush ra
+# CHECK-ASM: encoding: [0x73,0x40,0x10,0x8a]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfisslp' (Shadow-stack and Landing-pads)
+sspush ra
+
+# check-asm-and-obj: sspush t0
+# check-asm: encoding: [0x73,0x40,0x50,0x8a]
+# check-no-ext: error: instruction requires the following: 'zicfisslp' (shadow-stack and landing-pads)
+sspush x5
+
+# check-asm-and-obj: sspush t0
+# check-asm: encoding: [0x73,0x40,0x50,0x8a]
+# check-no-ext: error: instruction requires the following: 'zicfisslp' (shadow-stack and landing-pads)
+sspush t0
+
+# CHECK-ASM-AND-OBJ: ssprr ra
+# CHECK-ASM: encoding: [0xf3,0x40,0x00,0x86]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zicfisslp' (Shadow-stack and Landing-pads)
+ssprr ra
+
+# CHECK-ASM-AND-OBJ: ssamoswap t0, zero, (a0)
+# CHECK-AS

[PATCH] D155573: [Clang] Fix the location of default init expressions

2023-07-18 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/test/SemaCXX/source_location.cpp:796
+static_assert(S(0).i == S{0}.i);
+static_assert(S(0).j == S{0}.i);
+}

tbaeder wrote:
> aaron.ballman wrote:
> > cor3ntin wrote:
> > > aaron.ballman wrote:
> > > > Shouldn't this test fail because `i != j`?
> > > > 
> > > > Can you add a test that demonstrates we've corrected the source 
> > > > location information for diagnostics?
> > > They should all be equal!
> > > 
> > > > Can you add a test that demonstrates we've corrected the source 
> > > > location information for diagnostics?
> > > 
> > > Hum, i was planning to do that in https://reviews.llvm.org/D155175. I can 
> > > try to think of something there!
> > > They should all be equal!
> > 
> > Wha? Shouldn't `i == 790 && j == 791`?
> IIUC, they are evaluated as part of the constructor, so the values should be 
> 795 or 796. Maybe that can be changed to
> ```
> static_assert(S(0).i == S{0}.i == 796);
> ```
> ?
This is https://cplusplus.github.io/CWG/issues/2631.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155573

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


[PATCH] D155573: [Clang] Fix the location of default init expressions

2023-07-18 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




Comment at: clang/test/SemaCXX/source_location.cpp:796
+static_assert(S(0).i == S{0}.i);
+static_assert(S(0).j == S{0}.i);
+}

cor3ntin wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > cor3ntin wrote:
> > > > aaron.ballman wrote:
> > > > > Shouldn't this test fail because `i != j`?
> > > > > 
> > > > > Can you add a test that demonstrates we've corrected the source 
> > > > > location information for diagnostics?
> > > > They should all be equal!
> > > > 
> > > > > Can you add a test that demonstrates we've corrected the source 
> > > > > location information for diagnostics?
> > > > 
> > > > Hum, i was planning to do that in https://reviews.llvm.org/D155175. I 
> > > > can try to think of something there!
> > > > They should all be equal!
> > > 
> > > Wha? Shouldn't `i == 790 && j == 791`?
> > IIUC, they are evaluated as part of the constructor, so the values should 
> > be 795 or 796. Maybe that can be changed to
> > ```
> > static_assert(S(0).i == S{0}.i == 796);
> > ```
> > ?
> This is https://cplusplus.github.io/CWG/issues/2631.html
Oh yeah! Thank you for the reminder, that makes sense now. A comment reminding 
other readers might not be a bad idea.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155573

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


[PATCH] D155457: [clang] Skip tautological comparison if the comparison involves the 'size_t' type

2023-07-18 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

In D155457#4507124 , @aaron.ballman 
wrote:

> In D155457#4507107 , @xgupta wrote:
>
>> In D155457#4506405 , @xbolva00 
>> wrote:
>>
>>> You should add a testcase which uses “expected no diagnostics”.
>>
>> There is some issue writing test
>>
>>   $ cat type-limit-compare.cpp
>>   // RUN: %clang_cc1  -fsyntax-only -Wtautological-type-limit-compare 
>> -verify %s
>>   // expected-no-diagnostics
>>   
>>   #include 
>>   #include 
>>   #include 
>>   
>>   bool foo(uint64_t Size) {
>> if (sizeof(std::size_t) < sizeof(uint64_t) &&
>>Size > 
>> static_cast(std::numeric_limits::max())) // no-warning
>>   return false;
>> return true;
>>   }
>>
>> failed with
>>
>>   $ llvm-project/clang/test/Sema/type-limit-compare.cpp:4:10: fatal error: 
>> 'cstddef' file not found
>>   4 | #include 
>> |  ^
>
> We typically do not include any system headers (STL or otherwise) as part of 
> the compiler tests; that would test whatever is found on the test system 
> instead of a consistent test. Instead, I'd recommend doing:
>
>   namespace std {
>   using size_t = decltype(sizeof(0));
>   }
>
> Similarly, you can replace `uint64_t` with `unsigned long long` and the 
> `numeric_limits` call with `__SIZE_MAX__`

I see, Thanks,  but there is another thing, writing this way compiler emits a 
warning as the check to exclude the warning is based on `size_t` so the test 
case is not passed.

  // RUN: %clang_cc1 %s -fsyntax-only -Wtautological-type-limit-compare -verify
  
  // expected-no-diagnostics
  
  typedef unsigned long long uint64_t;
  namespace std {
  using size_t = decltype(sizeof(0));
  } // namespace std
  
  bool func(uint64_t Size) {
if (sizeof(std::size_t) < sizeof(uint64_t) &&
   Size > (uint64_t)(__SIZE_MAX__))
  return false;
return true;
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155457

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


[PATCH] D155173: [clangd] Refine the workflow for diagnostic Fixits.

2023-07-18 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 541480.
hokein marked an inline comment as done.
hokein added a comment.

address comments

- introduce `DiagKey` for the caching map
- get rid of extra index conversion


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155173

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.h

Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -962,16 +962,6 @@
 };
 llvm::json::Value toJSON(const Diagnostic &);
 
-/// A LSP-specific comparator used to find diagnostic in a container like
-/// std:map.
-/// We only use the required fields of Diagnostic to do the comparison to avoid
-/// any regression issues from LSP clients (e.g. VScode), see
-/// https://git.io/vbr29
-struct LSPDiagnosticCompare {
-  bool operator()(const Diagnostic &LHS, const Diagnostic &RHS) const {
-return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message);
-  }
-};
 bool fromJSON(const llvm::json::Value &, Diagnostic &, llvm::json::Path);
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Diagnostic &);
 
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -37,8 +37,7 @@
 #include 
 #include 
 #include 
-#include 
-#include 
+#include 
 #include 
 
 namespace clang {
@@ -351,8 +350,49 @@
 std::string Title; /// A single-line message to show in the UI.
 llvm::StringLiteral Kind;
   };
+
+  // Ref to the clangd::Diag.
+  struct DiagRef {
+Range Range;
+std::string Message;
+bool operator==(const DiagRef &Other) const {
+  return std::tie(Range, Message) == std::tie(Other.Range, Other.Message);
+}
+bool operator<(const DiagRef &Other) const {
+  return std::tie(Range, Message) < std::tie(Other.Range, Other.Message);
+}
+  };
+
+  struct CodeActionInputs {
+std::string File;
+Range Selection;
+
+/// Requested kind of actions to return.
+std::vector RequestedActionKinds;
+
+/// Diagnostics attached to the code action request.
+std::vector Diagnostics;
+
+/// Tweaks where Filter returns false will not be checked or included.
+std::function TweakFilter;
+  };
+  struct CodeActionResult {
+std::string Version;
+struct QuickFix {
+  DiagRef Diag;
+  Fix F;
+};
+std::vector QuickFixes;
+std::vector TweakRefs;
+  };
+  /// Surface code actions (quick-fixes for diagnostics, or available code
+  /// tweaks) for a given range in a file.
+  void codeAction(const CodeActionInputs &Inputs,
+  Callback CB);
+
   /// Enumerate the code tweaks available to the user at a specified point.
   /// Tweaks where Filter returns false will not be checked or included.
+  /// Deprecated, use codeAction instead.
   void enumerateTweaks(PathRef File, Range Sel,
llvm::unique_function Filter,
Callback> CB);
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -52,11 +52,16 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
 namespace {
 
+// Tracks number of times a tweak has been offered.
+static constexpr trace::Metric TweakAvailable(
+"tweak_available", trace::Metric::Counter, "tweak_id");
+
 // Update the FileIndex with new ASTs and plumb the diagnostics responses.
 struct UpdateIndexCallbacks : public ParsingCallbacks {
   UpdateIndexCallbacks(FileIndex *FIndex,
@@ -643,12 +648,66 @@
   return std::move(Result);
 }
 
+void ClangdServer::codeAction(const CodeActionInputs &Params,
+  Callback CB) {
+  auto Action = [Params, CB = std::move(CB),
+ FeatureModules(this->FeatureModules)](
+Expected InpAST) mutable {
+if (!InpAST)
+  return CB(InpAST.takeError());
+auto KindAllowed =
+[Only(Params.RequestedActionKinds)](llvm::StringRef Kind) {
+  if (Only.empty())
+return true;
+  return llvm::any_of(Only, [&](llvm::StringRef Base) {
+return Kind.consume_front(Base) &&
+   (Kind.empty() || Kind.startswith("."));
+  });
+};
+
+CodeActionResult Result;
+Result.Version = InpAST->AST.version().str();
+if (KindAllowed(CodeAction::QUICKFIX_KIND)) {
+  auto FindMatched = [&InpAST](const DiagRef &DR) -> const clangd::Diag * {
+for (const auto &Diag : Inp

[PATCH] D155173: [clangd] Refine the workflow for diagnostic Fixits.

2023-07-18 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 541481.
hokein added a comment.

more cleanup


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155173

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.h

Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -962,16 +962,6 @@
 };
 llvm::json::Value toJSON(const Diagnostic &);
 
-/// A LSP-specific comparator used to find diagnostic in a container like
-/// std:map.
-/// We only use the required fields of Diagnostic to do the comparison to avoid
-/// any regression issues from LSP clients (e.g. VScode), see
-/// https://git.io/vbr29
-struct LSPDiagnosticCompare {
-  bool operator()(const Diagnostic &LHS, const Diagnostic &RHS) const {
-return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message);
-  }
-};
 bool fromJSON(const llvm::json::Value &, Diagnostic &, llvm::json::Path);
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Diagnostic &);
 
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -37,8 +37,7 @@
 #include 
 #include 
 #include 
-#include 
-#include 
+#include 
 #include 
 
 namespace clang {
@@ -351,8 +350,49 @@
 std::string Title; /// A single-line message to show in the UI.
 llvm::StringLiteral Kind;
   };
+
+  // Ref to the clangd::Diag.
+  struct DiagRef {
+Range Range;
+std::string Message;
+bool operator==(const DiagRef &Other) const {
+  return std::tie(Range, Message) == std::tie(Other.Range, Other.Message);
+}
+bool operator<(const DiagRef &Other) const {
+  return std::tie(Range, Message) < std::tie(Other.Range, Other.Message);
+}
+  };
+
+  struct CodeActionInputs {
+std::string File;
+Range Selection;
+
+/// Requested kind of actions to return.
+std::vector RequestedActionKinds;
+
+/// Diagnostics attached to the code action request.
+std::vector Diagnostics;
+
+/// Tweaks where Filter returns false will not be checked or included.
+std::function TweakFilter;
+  };
+  struct CodeActionResult {
+std::string Version;
+struct QuickFix {
+  DiagRef Diag;
+  Fix F;
+};
+std::vector QuickFixes;
+std::vector TweakRefs;
+  };
+  /// Surface code actions (quick-fixes for diagnostics, or available code
+  /// tweaks) for a given range in a file.
+  void codeAction(const CodeActionInputs &Inputs,
+  Callback CB);
+
   /// Enumerate the code tweaks available to the user at a specified point.
   /// Tweaks where Filter returns false will not be checked or included.
+  /// Deprecated, use codeAction instead.
   void enumerateTweaks(PathRef File, Range Sel,
llvm::unique_function Filter,
Callback> CB);
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -52,11 +52,16 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
 namespace {
 
+// Tracks number of times a tweak has been offered.
+static constexpr trace::Metric TweakAvailable(
+"tweak_available", trace::Metric::Counter, "tweak_id");
+
 // Update the FileIndex with new ASTs and plumb the diagnostics responses.
 struct UpdateIndexCallbacks : public ParsingCallbacks {
   UpdateIndexCallbacks(FileIndex *FIndex,
@@ -643,12 +648,66 @@
   return std::move(Result);
 }
 
+void ClangdServer::codeAction(const CodeActionInputs &Params,
+  Callback CB) {
+  auto Action = [Params, CB = std::move(CB),
+ FeatureModules(this->FeatureModules)](
+Expected InpAST) mutable {
+if (!InpAST)
+  return CB(InpAST.takeError());
+auto KindAllowed =
+[Only(Params.RequestedActionKinds)](llvm::StringRef Kind) {
+  if (Only.empty())
+return true;
+  return llvm::any_of(Only, [&](llvm::StringRef Base) {
+return Kind.consume_front(Base) &&
+   (Kind.empty() || Kind.startswith("."));
+  });
+};
+
+CodeActionResult Result;
+Result.Version = InpAST->AST.version().str();
+if (KindAllowed(CodeAction::QUICKFIX_KIND)) {
+  auto FindMatched = [&InpAST](const DiagRef &DR) -> const clangd::Diag * {
+for (const auto &Diag : InpAST->AST.getDiagnostics())
+  if (Diag.Range == DR.Range && Diag.Message == DR.Message)
+return &Diag;
+

[PATCH] D155580: [trivial-auto-var-init] Do not emit initialization code for empty class

2023-07-18 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:1913-1923
+  if (D.isConstexpr())
+// Constexpr already initializes everything correctly.
+trivialAutoVarInit = LangOptions::TrivialAutoVarInitKind::Uninitialized;
+  else if (D.getAttr())
+trivialAutoVarInit = LangOptions::TrivialAutoVarInitKind::Uninitialized;
+  else if (isEmptyClass(D))
+// Empty classes still use a byte, but it's ok not to initialize it as




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

https://reviews.llvm.org/D155580

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


[PATCH] D155147: [X86] Add SM3 instructions.

2023-07-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 541495.
FreddyYe marked an inline comment as done.
FreddyYe added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155147

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsX86.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/sm3intrin.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/X86/sm3-builtins.c
  clang/test/CodeGen/X86/sm3-error.c
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86InstrSSE.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/sm3-intrinsics.ll
  llvm/test/MC/Disassembler/X86/sm3-32.txt
  llvm/test/MC/Disassembler/X86/sm3-64.txt
  llvm/test/MC/X86/sm3-att-32.s
  llvm/test/MC/X86/sm3-att-64.s
  llvm/test/MC/X86/sm3-intel-32.s
  llvm/test/MC/X86/sm3-intel-64.s

Index: llvm/test/MC/X86/sm3-intel-64.s
===
--- /dev/null
+++ llvm/test/MC/X86/sm3-intel-64.s
@@ -0,0 +1,86 @@
+// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xe4]
+  vsm3msg1 xmm12, xmm13, xmm4
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x10,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x10,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rip]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0x24,0x6d,0x00,0xfe,0xff,0xff]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rcx + 2032]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xa1,0xf0,0x07,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rcx + 2032]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rdx - 2048]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xa2,0x00,0xf8,0xff,0xff]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rdx - 2048]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xe4]
+  vsm3msg2 xmm12, xmm13, xmm4
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x11,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x11,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rip]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0x24,0x6d,0x00,0xfe,0xff,0xff]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rcx + 2032]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xa1,0xf0,0x07,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rcx + 2032]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rdx - 2048]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xa2,0x00,0xf8,0xff,0xff]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rdx - 2048]
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmm4, 123
+// CHECK: encoding: [0xc4,0x63,0x11,0xde,0xe4,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmm4, 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456], 123
+// CHECK: encoding: [0xc4,0x23,0x11,0xde,0xa4,0xf5,0x00,0x00,0x00,0x10,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456], 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291], 123
+// CHECK: encoding: [0xc4,0x43,0x11,0xde,0xa4,0x80,0x23,0x01,0x00,0x00,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291], 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [rip], 123
+// CHECK: encoding: [0xc4,0x63,0x11,0xde,0x25,0x00,0x00,0x00,0x00,0x7b]
+  vsm3rnd

[PATCH] D155148: [X86] Add SM4 instructions.

2023-07-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 541496.
FreddyYe marked an inline comment as done.
FreddyYe added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155148

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsX86.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/sm4intrin.h
  clang/test/CodeGen/X86/sm4-builtins.c
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86InstrSSE.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/sm4-intrinsics.ll
  llvm/test/MC/Disassembler/X86/sm4-32.txt
  llvm/test/MC/Disassembler/X86/sm4-64.txt
  llvm/test/MC/X86/sm4-32-att.s
  llvm/test/MC/X86/sm4-32-intel.s
  llvm/test/MC/X86/sm4-64-att.s
  llvm/test/MC/X86/sm4-64-intel.s

Index: llvm/test/MC/X86/sm4-64-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/sm4-64-intel.s
@@ -0,0 +1,114 @@
+// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK: vsm4key4 ymm12, ymm13, ymm4
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0xe4]
+  vsm4key4 ymm12, ymm13, ymm4
+
+// CHECK: vsm4key4 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0xe4]
+  vsm4key4 xmm12, xmm13, xmm4
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x16,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm4key4 ymm12, ymm13, ymmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x16,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm4key4 ymm12, ymm13, ymmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm4key4 ymm12, ymm13, ymmword ptr [rip]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [2*rbp - 1024]
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0x24,0x6d,0x00,0xfc,0xff,0xff]
+  vsm4key4 ymm12, ymm13, ymmword ptr [2*rbp - 1024]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [rcx + 4064]
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0xa1,0xe0,0x0f,0x00,0x00]
+  vsm4key4 ymm12, ymm13, ymmword ptr [rcx + 4064]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [rdx - 4096]
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0xa2,0x00,0xf0,0xff,0xff]
+  vsm4key4 ymm12, ymm13, ymmword ptr [rdx - 4096]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x12,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm4key4 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x12,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm4key4 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm4key4 xmm12, xmm13, xmmword ptr [rip]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0x24,0x6d,0x00,0xfe,0xff,0xff]
+  vsm4key4 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [rcx + 2032]
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0xa1,0xf0,0x07,0x00,0x00]
+  vsm4key4 xmm12, xmm13, xmmword ptr [rcx + 2032]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [rdx - 2048]
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0xa2,0x00,0xf8,0xff,0xff]
+  vsm4key4 xmm12, xmm13, xmmword ptr [rdx - 2048]
+
+// CHECK: vsm4rnds4 ymm12, ymm13, ymm4
+// CHECK: encoding: [0xc4,0x62,0x17,0xda,0xe4]
+  vsm4rnds4 ymm12, ymm13, ymm4
+
+// CHECK: vsm4rnds4 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x13,0xda,0xe4]
+  vsm4rnds4 xmm12, xmm13, xmm4
+
+// CHECK: vsm4rnds4 ymm12, ymm13, ymmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x17,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm4rnds4 ymm12, ymm13, ymmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm4rnds4 ymm12, ymm13, ymmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x17,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm4rnds4 ymm12, ymm13, ymmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm4rnds4 ymm12, ymm13, ymmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x17,0xda,0x25,0x00,0x00,0x00,0x00]
+  

[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Just to clarify, this was a regression introduced during Clang 17 development 
and thus this doesn't need a release note?




Comment at: clang/include/clang/Sema/Sema.h:6568
+  CheckImmediateEscalatingFunctionDefinition(FunctionDecl *FD,
+ const sema::FunctionScopeInfo *);
 





Comment at: clang/lib/Sema/SemaDeclCXX.cpp:2441
 bool Sema::CheckImmediateEscalatingFunctionDefinition(
-FunctionDecl *FD, bool HasImmediateEscalatingExpression) {
-  if (!FD->hasBody() || !getLangOpts().CPlusPlus20 ||
-  !FD->isImmediateEscalating())
+FunctionDecl *FD, const sema::FunctionScopeInfo *FSI) {
+  if (!getLangOpts().CPlusPlus20 || !FD->isImmediateEscalating())





Comment at: clang/lib/Sema/SemaExpr.cpp:6222
+  CXXThisScopeRAII This(*this, Field->getParent(), Qualifiers(),
+Field->getParent() != nullptr);
+

Under what circumstances can we have a `FieldDecl` without a parent object? I 
think this can be `true`, right?



Comment at: clang/lib/Sema/SemaExpr.cpp:18413
+// The outer context itself becomes immediate and further errors,
+// if any, will be handled by DiagnoseImmediateEscalatingReason
+if (DR->isImmediateEscalating())





Comment at: clang/test/CodeGenCXX/cxx2c-consteval-consteval.cpp:1-2
+// RUN: %clang_cc1 -emit-llvm %s -std=c++2a -triple x86_64-unknown-linux-gnu 
-o %t.ll
+// RUN: FileCheck -input-file=%t.ll %s
+





Comment at: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp:58
+// expected-error@-1 {{call to immediate function 
'InitWithLambda::InitWithLambda' is not a constant expression}} \
+// expected-note@-1 {{in call to 'InitWithLambda()'}}
 

Helps make it more obvious this is a continuation of the previous comment.



Comment at: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp:201-202
+}
+struct SS {
+  int x = f(0); // expected-error {{call to consteval function 'GH63742::f' is 
not a constant expression}} \
+// expected-note  {{declared here}} \





Comment at: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp:219
+constexpr S2::S2(){}
+S2 s = {};
+





Comment at: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp:240
+struct SS {
+  int x = f(0); // expected-note {{undefined function 'f' cannot be used in a 
constant expression}}
+  SS() = default;





Comment at: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp:245-246
+void test() {
+[[maybe_unused]] SS s; // expected-error {{call to immediate function 
'DefaultedUse::SS::SS' is not a constant expression}} \
+   //  expected-note {{in call to 'SS()'}}
+}

I don't have a suggestion yet on how to improve this, but this diagnostic did 
catch me by surprise because nothing about the declaration of `SS s;` makes me 
think "this should be a valid constant expression", so the error felt misplaced.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155175

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


Re: [PATCH] D155580: [trivial-auto-var-init] Do not emit initialization code for empty class

2023-07-18 Thread JF Bastien via cfe-commits
On Tue, Jul 18, 2023 at 8:41 PM serge via Phabricator <
revi...@reviews.llvm.org> wrote:

> serge-sans-paille created this revision.
> serge-sans-paille added reviewers: nickdesaulniers, jfb, aaron.ballman.
> Herald added a subscriber: kristof.beyls.
> Herald added a project: All.
> serge-sans-paille requested review of this revision.
> Herald added a project: clang.
> Herald added a subscriber: cfe-commits.
>
> Empty class still use one byte, but there is no way to read that byte
> programmatically in a legitimate way. Yet trivial auto var init always
> generate a store for it and there is no programmatic way to prevent the
> generation of that extra store.



This is the same as padding, and is initialized on purpose. If it’s truly
unused then the optimizer will eliminate it… unless it can’t prove whether
the store is dead.

Does this show up in any meaningless performance case? If so, can we
optimize it away?



This patch harmonizes Clang behavior with GCC and does not generate
> initialization code for empty classes under -ftrivial-auto-var-init
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> https://reviews.llvm.org/D155580
>
> Files:
>   clang/lib/CodeGen/CGDecl.cpp
>   clang/test/CodeGenCXX/auto-var-init-empty-class.cpp
>   clang/test/CodeGenCXX/auto-var-init.cpp
>
>
> Index: clang/test/CodeGenCXX/auto-var-init.cpp
> ===
> --- clang/test/CodeGenCXX/auto-var-init.cpp
> +++ clang/test/CodeGenCXX/auto-var-init.cpp
> @@ -43,9 +43,6 @@
>  // PATTERN-NOT: undef
>  // ZERO-NOT: undef
>
> -// PATTERN-O0: @__const.test_empty_uninit.uninit = private unnamed_addr
> constant %struct.empty { i8 [[I8]] }, align 1
> -// PATTERN-O1-NOT: @__const.test_empty_uninit.uninit
> -struct empty {};
>  // PATTERN-O0: @__const.test_small_uninit.uninit = private unnamed_addr
> constant %struct.small { i8 [[I8]] }, align 1
>  // PATTERN-O0: @__const.test_small_custom.custom = private unnamed_addr
> constant %struct.small { i8 42 }, align 1
>  // ZERO-O0: @__const.test_small_custom.custom = private unnamed_addr
> constant %struct.small { i8 42 }, align 1
> @@ -586,24 +583,6 @@
>  // CHECK-NOT:   !annotation
>  // CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
>
> -TEST_UNINIT(empty, empty);
> -// CHECK-LABEL: @test_empty_uninit()
> -// CHECK:   %uninit = alloca %struct.empty, align
> -// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
> -// PATTERN-LABEL: @test_empty_uninit()
> -// PATTERN-O0: call void @llvm.memcpy{{.*}} 
> @__const.test_empty_uninit.uninit{{.+}}),
> !annotation [[AUTO_INIT]]
> -// PATTERN-O1: store i8 [[I8]], {{.*}} align 1, !annotation [[AUTO_INIT]]
> -// ZERO-LABEL: @test_empty_uninit()
> -// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}}), !annotation
> [[AUTO_INIT]]
> -// ZERO-O1: store i8 0, {{.*}} align 1, !annotation [[AUTO_INIT]]
> -
> -TEST_BRACES(empty, empty);
> -// CHECK-LABEL: @test_empty_braces()
> -// CHECK:   %braces = alloca %struct.empty, align
> -// CHECK-NEXT:  call void @llvm.memcpy
> -// CHECK-NOT:   !annotation
> -// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
> -
>  TEST_UNINIT(small, small);
>  // CHECK-LABEL: @test_small_uninit()
>  // CHECK:   %uninit = alloca %struct.small, align
> Index: clang/test/CodeGenCXX/auto-var-init-empty-class.cpp
> ===
> --- /dev/null
> +++ clang/test/CodeGenCXX/auto-var-init-empty-class.cpp
> @@ -0,0 +1,18 @@
> +// RUN: %clang_cc1 -triple x86_64-unknown-unknown
> -ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s
> +// RUN: %clang_cc1 -triple x86_64-unknown-unknown
> -ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s
> +
> +// C++ empty classes still take some memory, but there is no need to
> initialize
> +// it has it cannot be accessed. This matches GCC behavior.
> +
> +struct S {
> +};
> +
> +extern "C" void use(struct S*);
> +
> +// CHECK-LABEL: @empty_class(
> +// CHECK:   %s = alloca
> +// CHECK-NEXT:  call void @use(ptr noundef %s)
> +extern "C" void empty_class(void) {
> +  S s;
> +  return use(&s);
> +}
> Index: clang/lib/CodeGen/CGDecl.cpp
> ===
> --- clang/lib/CodeGen/CGDecl.cpp
> +++ clang/lib/CodeGen/CGDecl.cpp
> @@ -1855,6 +1855,13 @@
>}
>  }
>
> +static bool isEmptyClass(VarDecl const &D) {
> +  const Type *Ty = D.getType().getTypePtr();
> +  if (const auto *CxxRecordTy = Ty->getAsCXXRecordDecl())
> +return CxxRecordTy->isEmpty();
> +  return false;
> +}
> +
>  void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
>assert(emission.Variable && "emission was not valid!");
>
> @@ -1903,12 +1910,18 @@
>locIsByrefHeader ? emission.getObjectAddress(*this) :
> emission.Addr;
>
>// Note: constexpr already initializes everything correctly.
> +  // Note: empty classes still use a byte, but it's ok not to initialize
> it as
> +  // it cannot be legitimately acces

[PATCH] D155146: [X86] Add SHA512 instructions.

2023-07-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 541502.
FreddyYe added a comment.

Split assembly tests and cover more registers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155146

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsX86.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/sha512intrin.h
  clang/test/CodeGen/X86/sha512-builtins.c
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86InstrSSE.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/sha512-intrinsics.ll
  llvm/test/MC/Disassembler/X86/sha512-32.txt
  llvm/test/MC/Disassembler/X86/sha512-64.txt
  llvm/test/MC/X86/sha512-32-att.s
  llvm/test/MC/X86/sha512-32-intel.s
  llvm/test/MC/X86/sha512-64-att.s
  llvm/test/MC/X86/sha512-64-intel.s

Index: llvm/test/MC/X86/sha512-64-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/sha512-64-intel.s
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK: vsha512msg1 ymm12, xmm3
+// CHECK: encoding: [0xc4,0x62,0x7f,0xcc,0xe3]
+  vsha512msg1 ymm12, xmm3
+
+// CHECK: vsha512msg2 ymm12, ymm3
+// CHECK: encoding: [0xc4,0x62,0x7f,0xcd,0xe3]
+  vsha512msg2 ymm12, ymm3
+
+// CHECK: vsha512rnds2 ymm12, ymm3, xmm4
+// CHECK: encoding: [0xc4,0x62,0x67,0xcb,0xe4]
+  vsha512rnds2 ymm12, ymm3, xmm4
+
Index: llvm/test/MC/X86/sha512-64-att.s
===
--- /dev/null
+++ llvm/test/MC/X86/sha512-64-att.s
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -triple x86_64 --show-encoding %s | FileCheck %s
+
+// CHECK: vsha512msg1 %xmm3, %ymm12
+// CHECK: encoding: [0xc4,0x62,0x7f,0xcc,0xe3]
+  vsha512msg1 %xmm3, %ymm12
+
+// CHECK: vsha512msg2 %ymm3, %ymm12
+// CHECK: encoding: [0xc4,0x62,0x7f,0xcd,0xe3]
+  vsha512msg2 %ymm3, %ymm12
+
+// CHECK: vsha512rnds2 %xmm4, %ymm3, %ymm12
+// CHECK: encoding: [0xc4,0x62,0x67,0xcb,0xe4]
+  vsha512rnds2 %xmm4, %ymm3, %ymm12
+
Index: llvm/test/MC/X86/sha512-32-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/sha512-32-intel.s
@@ -0,0 +1,13 @@
+// RUN: llvm-mc -triple i686 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK:  vsha512msg1 ymm2, xmm3
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcc,0xd3]
+   vsha512msg1 ymm2, xmm3
+
+// CHECK:  vsha512msg2 ymm2, ymm3
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcd,0xd3]
+   vsha512msg2 ymm2, ymm3
+
+// CHECK:  vsha512rnds2 ymm2, ymm3, xmm4
+// CHECK: encoding: [0xc4,0xe2,0x67,0xcb,0xd4]
+   vsha512rnds2 ymm2, ymm3, xmm4
Index: llvm/test/MC/X86/sha512-32-att.s
===
--- /dev/null
+++ llvm/test/MC/X86/sha512-32-att.s
@@ -0,0 +1,13 @@
+// RUN: llvm-mc -triple i686 --show-encoding %s | FileCheck %s
+
+// CHECK:  vsha512msg1 %xmm3, %ymm2
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcc,0xd3]
+   vsha512msg1 %xmm3, %ymm2
+
+// CHECK:  vsha512msg2 %ymm3, %ymm2
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcd,0xd3]
+   vsha512msg2 %ymm3, %ymm2
+
+// CHECK:  vsha512rnds2 %xmm4, %ymm3, %ymm2
+// CHECK: encoding: [0xc4,0xe2,0x67,0xcb,0xd4]
+   vsha512rnds2 %xmm4, %ymm3, %ymm2
Index: llvm/test/MC/Disassembler/X86/sha512-64.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/X86/sha512-64.txt
@@ -0,0 +1,15 @@
+# RUN: llvm-mc --disassemble %s -triple=x86_64 | FileCheck %s --check-prefixes=ATT
+# RUN: llvm-mc --disassemble %s -triple=x86_64 -x86-asm-syntax=intel --output-asm-variant=1 | FileCheck %s --check-prefixes=INTEL
+
+# ATT:   vsha512msg1 %xmm3, %ymm12
+# INTEL: vsha512msg1 ymm12, xmm3
+0xc4,0x62,0x7f,0xcc,0xe3
+
+# ATT:   vsha512msg2 %ymm3, %ymm12
+# INTEL: vsha512msg2 ymm12, ymm3
+0xc4,0x62,0x7f,0xcd,0xe3
+
+# ATT:   vsha512rnds2 %xmm4, %ymm3, %ymm12
+# INTEL: vsha512rnds2 ymm12, ymm3, xmm4
+0xc4,0x62,0x67,0xcb,0xe4
+
Index: llvm/test/MC/Disassembler/X86/sha512-32.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/X86/sha512-32.txt
@@ -0,0 +1,15 @@
+# RUN: llvm-mc --disassemble %s -triple=i386 | FileCheck %s --check-prefixes=ATT
+# RUN: llvm-mc --disassemble %s -triple=i386 --ou

[PATCH] D155146: [X86] Add SHA512 instructions.

2023-07-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 541503.
FreddyYe added a comment.

Remove -x86-asm-syntax=intel


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155146

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsX86.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/sha512intrin.h
  clang/test/CodeGen/X86/sha512-builtins.c
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86InstrSSE.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/sha512-intrinsics.ll
  llvm/test/MC/Disassembler/X86/sha512-32.txt
  llvm/test/MC/Disassembler/X86/sha512-64.txt
  llvm/test/MC/X86/sha512-32-att.s
  llvm/test/MC/X86/sha512-32-intel.s
  llvm/test/MC/X86/sha512-64-att.s
  llvm/test/MC/X86/sha512-64-intel.s

Index: llvm/test/MC/X86/sha512-64-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/sha512-64-intel.s
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK: vsha512msg1 ymm12, xmm3
+// CHECK: encoding: [0xc4,0x62,0x7f,0xcc,0xe3]
+  vsha512msg1 ymm12, xmm3
+
+// CHECK: vsha512msg2 ymm12, ymm3
+// CHECK: encoding: [0xc4,0x62,0x7f,0xcd,0xe3]
+  vsha512msg2 ymm12, ymm3
+
+// CHECK: vsha512rnds2 ymm12, ymm3, xmm4
+// CHECK: encoding: [0xc4,0x62,0x67,0xcb,0xe4]
+  vsha512rnds2 ymm12, ymm3, xmm4
+
Index: llvm/test/MC/X86/sha512-64-att.s
===
--- /dev/null
+++ llvm/test/MC/X86/sha512-64-att.s
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -triple x86_64 --show-encoding %s | FileCheck %s
+
+// CHECK: vsha512msg1 %xmm3, %ymm12
+// CHECK: encoding: [0xc4,0x62,0x7f,0xcc,0xe3]
+  vsha512msg1 %xmm3, %ymm12
+
+// CHECK: vsha512msg2 %ymm3, %ymm12
+// CHECK: encoding: [0xc4,0x62,0x7f,0xcd,0xe3]
+  vsha512msg2 %ymm3, %ymm12
+
+// CHECK: vsha512rnds2 %xmm4, %ymm3, %ymm12
+// CHECK: encoding: [0xc4,0x62,0x67,0xcb,0xe4]
+  vsha512rnds2 %xmm4, %ymm3, %ymm12
+
Index: llvm/test/MC/X86/sha512-32-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/sha512-32-intel.s
@@ -0,0 +1,13 @@
+// RUN: llvm-mc -triple i686 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK:  vsha512msg1 ymm2, xmm3
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcc,0xd3]
+   vsha512msg1 ymm2, xmm3
+
+// CHECK:  vsha512msg2 ymm2, ymm3
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcd,0xd3]
+   vsha512msg2 ymm2, ymm3
+
+// CHECK:  vsha512rnds2 ymm2, ymm3, xmm4
+// CHECK: encoding: [0xc4,0xe2,0x67,0xcb,0xd4]
+   vsha512rnds2 ymm2, ymm3, xmm4
Index: llvm/test/MC/X86/sha512-32-att.s
===
--- /dev/null
+++ llvm/test/MC/X86/sha512-32-att.s
@@ -0,0 +1,13 @@
+// RUN: llvm-mc -triple i686 --show-encoding %s | FileCheck %s
+
+// CHECK:  vsha512msg1 %xmm3, %ymm2
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcc,0xd3]
+   vsha512msg1 %xmm3, %ymm2
+
+// CHECK:  vsha512msg2 %ymm3, %ymm2
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcd,0xd3]
+   vsha512msg2 %ymm3, %ymm2
+
+// CHECK:  vsha512rnds2 %xmm4, %ymm3, %ymm2
+// CHECK: encoding: [0xc4,0xe2,0x67,0xcb,0xd4]
+   vsha512rnds2 %xmm4, %ymm3, %ymm2
Index: llvm/test/MC/Disassembler/X86/sha512-64.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/X86/sha512-64.txt
@@ -0,0 +1,15 @@
+# RUN: llvm-mc --disassemble %s -triple=x86_64 | FileCheck %s --check-prefixes=ATT
+# RUN: llvm-mc --disassemble %s -triple=x86_64 --output-asm-variant=1 | FileCheck %s --check-prefixes=INTEL
+
+# ATT:   vsha512msg1 %xmm3, %ymm12
+# INTEL: vsha512msg1 ymm12, xmm3
+0xc4,0x62,0x7f,0xcc,0xe3
+
+# ATT:   vsha512msg2 %ymm3, %ymm12
+# INTEL: vsha512msg2 ymm12, ymm3
+0xc4,0x62,0x7f,0xcd,0xe3
+
+# ATT:   vsha512rnds2 %xmm4, %ymm3, %ymm12
+# INTEL: vsha512rnds2 ymm12, ymm3, xmm4
+0xc4,0x62,0x67,0xcb,0xe4
+
Index: llvm/test/MC/Disassembler/X86/sha512-32.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/X86/sha512-32.txt
@@ -0,0 +1,15 @@
+# RUN: llvm-mc --disassemble %s -triple=i386 | FileCheck %s --check-prefixes=ATT
+# RUN: llvm-mc --disassemble %s -triple=i386 --output-asm-variant=1 | FileCheck %s --chec

[PATCH] D155547: [analyzer] Model lifetime of a variable declared in for condition in CFG correctly

2023-07-18 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/test/Analysis/auto-obj-dtors-cfg-output.cpp:1231
   A a;
-  for (A b; A c = b; ) {
+  for (A b; A c = b; ++c.x) {
 A d;

Would there be any value in also keeping a couple of the original test cases? 
(When we have empty increment blocks). 

How about a test case where the increment operation generates multiple basic 
blocks (e.g., have a ternary)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155547

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


[clang] 7324535 - [clang][NFC] Fix typos in sema builtins test

2023-07-18 Thread Paweł Bylica via cfe-commits

Author: Paweł Bylica
Date: 2023-07-18T15:40:28+02:00
New Revision: 73245359847da385182dd3b3b2168e246a69a276

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

LOG: [clang][NFC] Fix typos in sema builtins test

Added: 


Modified: 
clang/test/Sema/constant-builtins-2.c

Removed: 




diff  --git a/clang/test/Sema/constant-builtins-2.c 
b/clang/test/Sema/constant-builtins-2.c
index 1f4d1d3c23ade5..93948201c451b4 100644
--- a/clang/test/Sema/constant-builtins-2.c
+++ b/clang/test/Sema/constant-builtins-2.c
@@ -217,13 +217,13 @@ char 
bitreverse4[__builtin_bitreverse64(0x0123456789ABCDEFULL) == 0xF7B3D591E6A2
 
 char rotateleft1[__builtin_rotateleft8(0x01, 5) == 0x20 ? 1 : -1];
 char rotateleft2[__builtin_rotateleft16(0x3210, 11) == 0x8190 ? 1 : -1];
-char rotateleft2[__builtin_rotateleft32(0x76543210, 22) == 0x841D950C ? 1 : 
-1];
-char rotateleft2[__builtin_rotateleft64(0xFEDCBA9876543210ULL, 55) == 
0x87F6E5D4C3B2A19ULL ? 1 : -1];
+char rotateleft3[__builtin_rotateleft32(0x76543210, 22) == 0x841D950C ? 1 : 
-1];
+char rotateleft4[__builtin_rotateleft64(0xFEDCBA9876543210ULL, 55) == 
0x87F6E5D4C3B2A19ULL ? 1 : -1];
 
 char rotateright1[__builtin_rotateright8(0x01, 5) == 0x08 ? 1 : -1];
 char rotateright2[__builtin_rotateright16(0x3210, 11) == 0x4206 ? 1 : -1];
-char rotateright2[__builtin_rotateright32(0x76543210, 22) == 0x50C841D9 ? 1 : 
-1];
-char rotateright2[__builtin_rotateright64(0xFEDCBA9876543210ULL, 55) == 
0xB97530ECA86421FDULL ? 1 : -1];
+char rotateright3[__builtin_rotateright32(0x76543210, 22) == 0x50C841D9 ? 1 : 
-1];
+char rotateright4[__builtin_rotateright64(0xFEDCBA9876543210ULL, 55) == 
0xB97530ECA86421FDULL ? 1 : -1];
 
 char ffs1[__builtin_ffs(0) == 0 ? 1 : -1];
 char ffs2[__builtin_ffs(1) == 1 ? 1 : -1];



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


[clang] 6236bf5 - [clang][dataflow] Strengthen flow condition assertions.

2023-07-18 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-07-18T13:41:43Z
New Revision: 6236bf53418eb23c62a73d6346f0edec914084e7

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

LOG: [clang][dataflow] Strengthen flow condition assertions.

Instead of asserting merely that the flow condition doesn't imply that a 
variable is true, make the stronger assertion that the flow condition implies 
that the variable is false.

Reviewed By: ymandel, xazax.hun

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

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index e2800452ab6bdb..291f8329a60fde 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3619,7 +3619,8 @@ TEST(TransferTest, BooleanEquality) {
 EXPECT_TRUE(EnvThen.flowConditionImplies(BarValThen));
 
 auto &BarValElse = getFormula(*BarDecl, EnvElse);
-EXPECT_FALSE(EnvElse.flowConditionImplies(BarValElse));
+EXPECT_TRUE(
+EnvElse.flowConditionImplies(EnvElse.arena().makeNot(BarValElse)));
   });
 }
 
@@ -3650,7 +3651,8 @@ TEST(TransferTest, BooleanInequality) {
 ASSERT_THAT(BarDecl, NotNull());
 
 auto &BarValThen = getFormula(*BarDecl, EnvThen);
-EXPECT_FALSE(EnvThen.flowConditionImplies(BarValThen));
+EXPECT_TRUE(
+EnvThen.flowConditionImplies(EnvThen.arena().makeNot(BarValThen)));
 
 auto &BarValElse = getFormula(*BarDecl, EnvElse);
 EXPECT_TRUE(EnvElse.flowConditionImplies(BarValElse));



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


[PATCH] D155067: [clang][dataflow] Strengthen flow condition assertions.

2023-07-18 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 rG6236bf53418e: [clang][dataflow] Strengthen flow condition 
assertions. (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155067

Files:
  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
@@ -3619,7 +3619,8 @@
 EXPECT_TRUE(EnvThen.flowConditionImplies(BarValThen));
 
 auto &BarValElse = getFormula(*BarDecl, EnvElse);
-EXPECT_FALSE(EnvElse.flowConditionImplies(BarValElse));
+EXPECT_TRUE(
+EnvElse.flowConditionImplies(EnvElse.arena().makeNot(BarValElse)));
   });
 }
 
@@ -3650,7 +3651,8 @@
 ASSERT_THAT(BarDecl, NotNull());
 
 auto &BarValThen = getFormula(*BarDecl, EnvThen);
-EXPECT_FALSE(EnvThen.flowConditionImplies(BarValThen));
+EXPECT_TRUE(
+EnvThen.flowConditionImplies(EnvThen.arena().makeNot(BarValThen)));
 
 auto &BarValElse = getFormula(*BarDecl, EnvElse);
 EXPECT_TRUE(EnvElse.flowConditionImplies(BarValElse));


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3619,7 +3619,8 @@
 EXPECT_TRUE(EnvThen.flowConditionImplies(BarValThen));
 
 auto &BarValElse = getFormula(*BarDecl, EnvElse);
-EXPECT_FALSE(EnvElse.flowConditionImplies(BarValElse));
+EXPECT_TRUE(
+EnvElse.flowConditionImplies(EnvElse.arena().makeNot(BarValElse)));
   });
 }
 
@@ -3650,7 +3651,8 @@
 ASSERT_THAT(BarDecl, NotNull());
 
 auto &BarValThen = getFormula(*BarDecl, EnvThen);
-EXPECT_FALSE(EnvThen.flowConditionImplies(BarValThen));
+EXPECT_TRUE(
+EnvThen.flowConditionImplies(EnvThen.arena().makeNot(BarValThen)));
 
 auto &BarValElse = getFormula(*BarDecl, EnvElse);
 EXPECT_TRUE(EnvElse.flowConditionImplies(BarValElse));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154368: [Clang] Fix constraint checking of non-generic lambdas.

2023-07-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:4718-4719
+def note_ovl_surrogate_constraints_not_satisfied : Note<
+"candidate surrogate function %0 not viable: constraints "
+"not satisfied">;
 def note_implicit_member_target_infer_collision : Note<

I think "candidate surrogate function" is a bit... technical for a user-facing 
diagnostic (we don't seem to use it any other diagnostics). Perhaps we should 
go with `conversion candidate function` instead as we did for 
`note_ovl_surrogate_cand`?



Comment at: clang/lib/Sema/SemaConcept.cpp:685
+  // (and may refer to its parameters), so check the call operator instead.
+  if (const CXXConversionDecl *MD = dyn_cast(FD);
+  MD && isLambdaConversionOperator(const_cast(MD)))





Comment at: clang/lib/Sema/SemaLambda.cpp:1636-1638
+  // A non-generic lambda may still be a templated entity
+  // We need to preserve constraints when converting the
+  // lambda to a function pointer. See GH63181.





Comment at: clang/lib/Sema/SemaOverload.cpp:14973
+  // conversion operator as the constraints are always the same.
+  // As the user probably do not intend to perform a surrogate call,
+  // we filter them out to produce better error diagnostics, ie to avoid




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154368

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


  1   2   3   4   >