[llvm-branch-commits] [llvm] Backport #85277 (PR #85422)

2024-03-16 Thread Brad Smith via llvm-branch-commits

brad0 wrote:

/cherry-pick 328cb9b731cb61eaa853fa6cc3bd641dd1d71b98

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


[llvm-branch-commits] [llvm] release/18.x: [Mips] Fix missing sign extension in expansion of sub-word atomic max (#77072) (PR #84566)

2024-03-16 Thread Brad Smith via llvm-branch-commits

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


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


[llvm-branch-commits] [llvm] release/18.x: [AVR] Remove earlyclobber from LDDRdPtrQ (#85277) (PR #85512)

2024-03-16 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/85512

Backport 328cb9b731cb61eaa853fa6cc3bd641dd1d71b98

Requested by: @brad0

>From a77bc691b8b47a28c1c19a48ab04cb047dd54f89 Mon Sep 17 00:00:00 2001
From: Patryk Wychowaniec 
Date: Fri, 15 Mar 2024 12:07:54 +0100
Subject: [PATCH] [AVR] Remove earlyclobber from LDDRdPtrQ (#85277)

LDDRdPtrQ was marked as `earlyclobber`, which doesn't play well with
GreedyRA (which can generate this instruction through `loadRegFromStackSlot()`).

This seems to be the same case as:

https://github.com/llvm/llvm-project/blob/a99b912c9b74f6ef91786b4dfbc25160c27d3b41/llvm/lib/Target/AVR/AVRInstrInfo.td#L1421

Closes https://github.com/llvm/llvm-project/issues/81911.

(cherry picked from commit 328cb9b731cb61eaa853fa6cc3bd641dd1d71b98)
---
 llvm/lib/Target/AVR/AVRInstrInfo.td |   2 +-
 llvm/test/CodeGen/AVR/bug-81911.ll  | 163 
 2 files changed, 164 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/AVR/bug-81911.ll

diff --git a/llvm/lib/Target/AVR/AVRInstrInfo.td 
b/llvm/lib/Target/AVR/AVRInstrInfo.td
index efaaec32ee6bb1..0a77c7c1d418a1 100644
--- a/llvm/lib/Target/AVR/AVRInstrInfo.td
+++ b/llvm/lib/Target/AVR/AVRInstrInfo.td
@@ -1398,7 +1398,7 @@ let mayLoad = 1, hasSideEffects = 0,
 
 // Load indirect with displacement operations.
 let canFoldAsLoad = 1, isReMaterializable = 1 in {
-  let Constraints = "@earlyclobber $reg" in def LDDRdPtrQ
+  def LDDRdPtrQ
   : FSTDLDD<0,
 (outs GPR8
  : $reg),
diff --git a/llvm/test/CodeGen/AVR/bug-81911.ll 
b/llvm/test/CodeGen/AVR/bug-81911.ll
new file mode 100644
index 00..2a22666a1ff927
--- /dev/null
+++ b/llvm/test/CodeGen/AVR/bug-81911.ll
@@ -0,0 +1,163 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc < %s -mtriple=avr -mcpu=atmega328 -O1 -verify-machineinstrs | 
FileCheck %s
+
+define internal i8 @main() {
+; CHECK-LABEL: main:
+; CHECK:   ; %bb.0: ; %bb0
+; CHECK-NEXT:push r2
+; CHECK-NEXT:push r3
+; CHECK-NEXT:push r4
+; CHECK-NEXT:push r5
+; CHECK-NEXT:push r6
+; CHECK-NEXT:push r7
+; CHECK-NEXT:push r8
+; CHECK-NEXT:push r9
+; CHECK-NEXT:push r10
+; CHECK-NEXT:push r11
+; CHECK-NEXT:push r12
+; CHECK-NEXT:push r13
+; CHECK-NEXT:push r14
+; CHECK-NEXT:push r15
+; CHECK-NEXT:push r16
+; CHECK-NEXT:push r17
+; CHECK-NEXT:push r28
+; CHECK-NEXT:push r29
+; CHECK-NEXT:in r28, 61
+; CHECK-NEXT:in r29, 62
+; CHECK-NEXT:sbiw r28, 13
+; CHECK-NEXT:in r0, 63
+; CHECK-NEXT:cli
+; CHECK-NEXT:out 62, r29
+; CHECK-NEXT:out 63, r0
+; CHECK-NEXT:out 61, r28
+; CHECK-NEXT:ldi r16, 0
+; CHECK-NEXT:ldi r17, 0
+; CHECK-NEXT:ldi r18, -1
+; CHECK-NEXT:;APP
+; CHECK-NEXT:ldi r24, 123
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:std Y+1, r24 ; 1-byte Folded Spill
+; CHECK-NEXT:movw r24, r28
+; CHECK-NEXT:adiw r24, 6
+; CHECK-NEXT:std Y+3, r25 ; 2-byte Folded Spill
+; CHECK-NEXT:std Y+2, r24 ; 2-byte Folded Spill
+; CHECK-NEXT:movw r8, r16
+; CHECK-NEXT:movw r6, r16
+; CHECK-NEXT:movw r4, r16
+; CHECK-NEXT:movw r2, r16
+; CHECK-NEXT:rjmp .LBB0_2
+; CHECK-NEXT:  .LBB0_1: ; %bb1
+; CHECK-NEXT:; in Loop: Header=BB0_2 Depth=1
+; CHECK-NEXT:andi r30, 1
+; CHECK-NEXT:ldd r31, Y+4 ; 1-byte Folded Reload
+; CHECK-NEXT:dec r31
+; CHECK-NEXT:cpi r30, 0
+; CHECK-NEXT:movw r8, r18
+; CHECK-NEXT:movw r6, r20
+; CHECK-NEXT:movw r4, r22
+; CHECK-NEXT:movw r2, r24
+; CHECK-NEXT:mov r18, r31
+; CHECK-NEXT:brne .LBB0_2
+; CHECK-NEXT:rjmp .LBB0_4
+; CHECK-NEXT:  .LBB0_2: ; %bb1
+; CHECK-NEXT:; =>This Inner Loop Header: Depth=1
+; CHECK-NEXT:std Y+4, r18 ; 1-byte Folded Spill
+; CHECK-NEXT:movw r18, r8
+; CHECK-NEXT:movw r20, r6
+; CHECK-NEXT:movw r22, r4
+; CHECK-NEXT:movw r24, r2
+; CHECK-NEXT:ldi r26, 10
+; CHECK-NEXT:ldi r27, 0
+; CHECK-NEXT:movw r10, r26
+; CHECK-NEXT:movw r12, r16
+; CHECK-NEXT:movw r14, r16
+; CHECK-NEXT:call __udivdi3
+; CHECK-NEXT:std Y+13, r25
+; CHECK-NEXT:std Y+12, r24
+; CHECK-NEXT:std Y+11, r23
+; CHECK-NEXT:std Y+10, r22
+; CHECK-NEXT:std Y+9, r21
+; CHECK-NEXT:std Y+8, r20
+; CHECK-NEXT:std Y+7, r19
+; CHECK-NEXT:std Y+6, r18
+; CHECK-NEXT:ldd r30, Y+2 ; 2-byte Folded Reload
+; CHECK-NEXT:ldd r31, Y+3 ; 2-byte Folded Reload
+; CHECK-NEXT:;APP
+; CHECK-NEXT:;NO_APP
+; CHECK-NEXT:ldi r30, 1
+; CHECK-NEXT:cp r8, r1
+; CHECK-NEXT:cpc r9, r1
+; CHECK-NEXT:cpc r6, r16
+; CHECK-NEXT:cpc r7, r17
+; CHECK-NEXT:cpc r4, r16
+; CHECK-NEXT:cpc r5, r17
+; CHECK-NEXT:cpc r2, r16
+; CHECK-NEXT:cpc r3, r17
+; CHECK-NEXT:breq .LBB0_3
+; CHECK-NEXT:rjmp .LBB0_1
+; CHECK-NEXT:  .LBB0_3: ; %bb1
+; CHECK-NEXT:; in Loop: Header=B

[llvm-branch-commits] [llvm] release/18.x: [AVR] Remove earlyclobber from LDDRdPtrQ (#85277) (PR #85512)

2024-03-16 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/85512
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [AVR] Remove earlyclobber from LDDRdPtrQ (#85277) (PR #85512)

2024-03-16 Thread via llvm-branch-commits

llvmbot wrote:

@benshi001 What do you think about merging this PR to the release branch?

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


[llvm-branch-commits] [llvm] Backport #85277 (PR #85422)

2024-03-16 Thread via llvm-branch-commits

llvmbot wrote:

/pull-request llvm/llvm-project#85512

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


[llvm-branch-commits] [llvm] Backport #85277 (PR #85422)

2024-03-16 Thread via llvm-branch-commits

https://github.com/llvmbot closed 
https://github.com/llvm/llvm-project/pull/85422
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [AVR] Remove earlyclobber from LDDRdPtrQ (#85277) (PR #85512)

2024-03-16 Thread Brad Smith via llvm-branch-commits

https://github.com/brad0 closed https://github.com/llvm/llvm-project/pull/85512
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] Backport #85277 (PR #85422)

2024-03-16 Thread Brad Smith via llvm-branch-commits

https://github.com/brad0 reopened 
https://github.com/llvm/llvm-project/pull/85422
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] Backport #85277 (PR #85422)

2024-03-16 Thread Brad Smith via llvm-branch-commits

brad0 wrote:

Sorry, I didn't mean to mess that up.

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


[llvm-branch-commits] [openmp] b75cbfe - Revert "[openmp] __kmp_x86_cpuid fix for i386/PIC builds. (#84626)"

2024-03-16 Thread via llvm-branch-commits

Author: David CARLIER
Date: 2024-03-16T13:39:08Z
New Revision: b75cbfe45fbbdc3d42ca99fae265cf567f0c71cd

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

LOG: Revert "[openmp] __kmp_x86_cpuid fix for i386/PIC builds. (#84626)"

This reverts commit facb89ae1228c067b2b14f32e7e70608fe50704b.

Added: 


Modified: 
openmp/runtime/src/kmp.h

Removed: 




diff  --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index 569a1ab9b477c4..885d6636abe4a8 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -1402,19 +1402,9 @@ extern void __kmp_query_cpuid(kmp_cpuinfo_t *p);
 // subleaf is only needed for cache and topology discovery and can be set to
 // zero in most cases
 static inline void __kmp_x86_cpuid(int leaf, int subleaf, struct kmp_cpuid *p) 
{
-#if KMP_ARCH_X86 && (defined(__pic__) || defined(__PIC__))
-  // on i386 arch, the ebx reg. is used by pic, thus we need to preserve from
-  // being trashed beforehand
-  __asm__ __volatile__("mov %%ebx, %%edi\n"
-   "cpuid\n"
-   "xchg %%edi, %%ebx\n"
-   : "=a"(p->eax), "=b"(p->ebx), "=c"(p->ecx), "=d"(p->edx)
-   : "a"(leaf), "c"(subleaf));
-#else
   __asm__ __volatile__("cpuid"
: "=a"(p->eax), "=b"(p->ebx), "=c"(p->ecx), "=d"(p->edx)
: "a"(leaf), "c"(subleaf));
-#endif
 }
 // Load p into FPU control word
 static inline void __kmp_load_x87_fpu_control_word(const kmp_int16 *p) {



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


[llvm-branch-commits] [openmp] fc108ac - Revert "release/18.x: [openmp] __kmp_x86_cpuid fix for i386/PIC builds. (#846…"

2024-03-16 Thread via llvm-branch-commits

Author: David CARLIER
Date: 2024-03-16T13:41:33Z
New Revision: fc108ac9e491ff488297b78a05629239ee997f40

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

LOG: Revert "release/18.x: [openmp] __kmp_x86_cpuid fix for i386/PIC builds. 
(#846…"

This reverts commit 9b3edb592debc00a5c3fbf7a71f63e07d6af44be.

Added: 


Modified: 
openmp/runtime/src/kmp.h

Removed: 




diff  --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index d51ec886cfe556..e3a1e20731bbe0 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -1403,19 +1403,9 @@ extern void __kmp_query_cpuid(kmp_cpuinfo_t *p);
 // subleaf is only needed for cache and topology discovery and can be set to
 // zero in most cases
 static inline void __kmp_x86_cpuid(int leaf, int subleaf, struct kmp_cpuid *p) 
{
-#if KMP_ARCH_X86 && (defined(__pic__) || defined(__PIC__))
-  // on i386 arch, the ebx reg. is used by pic, thus we need to preserve from
-  // being trashed beforehand
-  __asm__ __volatile__("mov %%ebx, %%edi\n"
-   "cpuid\n"
-   "xchg %%edi, %%ebx\n"
-   : "=a"(p->eax), "=b"(p->ebx), "=c"(p->ecx), "=d"(p->edx)
-   : "a"(leaf), "c"(subleaf));
-#else
   __asm__ __volatile__("cpuid"
: "=a"(p->eax), "=b"(p->ebx), "=c"(p->ecx), "=d"(p->edx)
: "a"(leaf), "c"(subleaf));
-#endif
 }
 // Load p into FPU control word
 static inline void __kmp_load_x87_fpu_control_word(const kmp_int16 *p) {



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


[llvm-branch-commits] [openmp] Revert "release/18.x: [openmp] __kmp_x86_cpuid fix for i386/PIC builds. (#84626)" (PR #85527)

2024-03-16 Thread David CARLIER via llvm-branch-commits

https://github.com/devnexen created 
https://github.com/llvm/llvm-project/pull/85527

Reverts llvm/llvm-project#85053

>From fc108ac9e491ff488297b78a05629239ee997f40 Mon Sep 17 00:00:00 2001
From: David CARLIER 
Date: Sat, 16 Mar 2024 13:41:33 +
Subject: [PATCH] =?UTF-8?q?Revert=20"release/18.x:=20[openmp]=20=5F=5Fkmp?=
 =?UTF-8?q?=5Fx86=5Fcpuid=20fix=20for=20i386/PIC=20builds.=20(#846?=
 =?UTF-8?q?=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 9b3edb592debc00a5c3fbf7a71f63e07d6af44be.
---
 openmp/runtime/src/kmp.h | 10 --
 1 file changed, 10 deletions(-)

diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index d51ec886cfe556..e3a1e20731bbe0 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -1403,19 +1403,9 @@ extern void __kmp_query_cpuid(kmp_cpuinfo_t *p);
 // subleaf is only needed for cache and topology discovery and can be set to
 // zero in most cases
 static inline void __kmp_x86_cpuid(int leaf, int subleaf, struct kmp_cpuid *p) 
{
-#if KMP_ARCH_X86 && (defined(__pic__) || defined(__PIC__))
-  // on i386 arch, the ebx reg. is used by pic, thus we need to preserve from
-  // being trashed beforehand
-  __asm__ __volatile__("mov %%ebx, %%edi\n"
-   "cpuid\n"
-   "xchg %%edi, %%ebx\n"
-   : "=a"(p->eax), "=b"(p->ebx), "=c"(p->ecx), "=d"(p->edx)
-   : "a"(leaf), "c"(subleaf));
-#else
   __asm__ __volatile__("cpuid"
: "=a"(p->eax), "=b"(p->ebx), "=c"(p->ecx), "=d"(p->edx)
: "a"(leaf), "c"(subleaf));
-#endif
 }
 // Load p into FPU control word
 static inline void __kmp_load_x87_fpu_control_word(const kmp_int16 *p) {

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


[llvm-branch-commits] [openmp] Revert "release/18.x: [openmp] __kmp_x86_cpuid fix for i386/PIC builds. (#84626)" (PR #85527)

2024-03-16 Thread Michał Górny via llvm-branch-commits

https://github.com/mgorny milestoned 
https://github.com/llvm/llvm-project/pull/85527
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [openmp] Revert "release/18.x: [openmp] __kmp_x86_cpuid fix for i386/PIC builds. (#84626)" (PR #85527)

2024-03-16 Thread David CARLIER via llvm-branch-commits

devnexen wrote:

@tstellar see [this for 
context](https://github.com/llvm/llvm-project/pull/84626#issuecomment-2001983167)

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


[llvm-branch-commits] [llvm] Lld mac fix (PR #84764)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/84764
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] release/18.x: [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (#83542) (PR #84117)

2024-03-16 Thread via llvm-branch-commits

https://github.com/llvmbot updated 
https://github.com/llvm/llvm-project/pull/84117

>From 0c1dcd675291f058d530078f9304162ea9d27cd1 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Mon, 4 Mar 2024 00:12:56 -0500
Subject: [PATCH] [clangd] [HeuristicResolver] Protect against infinite
 recursion on DependentNameTypes (#83542)

When resolving names inside templates that implement recursive
compile-time functions (e.g. waldo::type is defined in terms
of waldo::type), HeuristicResolver could get into an infinite
recursion, specifically one where resolveDependentNameType() can
be called recursively with the same DependentNameType*.

To guard against this, HeuristicResolver tracks, for each external
call into a HeuristicResolver function, the set of DependentNameTypes
that it has seen, and bails if it sees the same DependentNameType again.

To implement this, a helper class HeuristicResolverImpl is introduced
to store state that persists for the duration of an external call into
HeuristicResolver (but does not persist between such calls).

Fixes https://github.com/clangd/clangd/issues/1951

(cherry picked from commit e6e53ca8470d719882539359ebe3ad8b442a8cb0)
---
 .../clangd/HeuristicResolver.cpp  | 170 ++
 clang-tools-extra/clangd/HeuristicResolver.h  |  37 
 .../clangd/unittests/FindTargetTests.cpp  |  27 +++
 3 files changed, 165 insertions(+), 69 deletions(-)

diff --git a/clang-tools-extra/clangd/HeuristicResolver.cpp 
b/clang-tools-extra/clangd/HeuristicResolver.cpp
index 3c147b6b582bf0..26d54200eeffd2 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.cpp
+++ b/clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -16,6 +16,80 @@
 namespace clang {
 namespace clangd {
 
+namespace {
+
+// Helper class for implementing HeuristicResolver.
+// Unlike HeuristicResolver which is a long-lived class,
+// a new instance of this class is created for every external
+// call into a HeuristicResolver operation. That allows this
+// class to store state that's local to such a top-level call,
+// particularly "recursion protection sets" that keep track of
+// nodes that have already been seen to avoid infinite recursion.
+class HeuristicResolverImpl {
+public:
+  HeuristicResolverImpl(ASTContext &Ctx) : Ctx(Ctx) {}
+
+  // These functions match the public interface of HeuristicResolver
+  // (but aren't const since they may modify the recursion protection sets).
+  std::vector
+  resolveMemberExpr(const CXXDependentScopeMemberExpr *ME);
+  std::vector
+  resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE);
+  std::vector resolveTypeOfCallExpr(const CallExpr *CE);
+  std::vector resolveCalleeOfCallExpr(const CallExpr *CE);
+  std::vector
+  resolveUsingValueDecl(const UnresolvedUsingValueDecl *UUVD);
+  std::vector
+  resolveDependentNameType(const DependentNameType *DNT);
+  std::vector resolveTemplateSpecializationType(
+  const DependentTemplateSpecializationType *DTST);
+  const Type *resolveNestedNameSpecifierToType(const NestedNameSpecifier *NNS);
+  const Type *getPointeeType(const Type *T);
+
+private:
+  ASTContext &Ctx;
+
+  // Recursion protection sets
+  llvm::SmallSet SeenDependentNameTypes;
+
+  // Given a tag-decl type and a member name, heuristically resolve the
+  // name to one or more declarations.
+  // The current heuristic is simply to look up the name in the primary
+  // template. This is a heuristic because the template could potentially
+  // have specializations that declare different members.
+  // Multiple declarations could be returned if the name is overloaded
+  // (e.g. an overloaded method in the primary template).
+  // This heuristic will give the desired answer in many cases, e.g.
+  // for a call to vector::size().
+  std::vector
+  resolveDependentMember(const Type *T, DeclarationName Name,
+ llvm::function_ref Filter);
+
+  // Try to heuristically resolve the type of a possibly-dependent expression
+  // `E`.
+  const Type *resolveExprToType(const Expr *E);
+  std::vector resolveExprToDecls(const Expr *E);
+
+  // Helper function for HeuristicResolver::resolveDependentMember()
+  // which takes a possibly-dependent type `T` and heuristically
+  // resolves it to a CXXRecordDecl in which we can try name lookup.
+  CXXRecordDecl *resolveTypeToRecordDecl(const Type *T);
+
+  // This is a reimplementation of CXXRecordDecl::lookupDependentName()
+  // so that the implementation can call into other HeuristicResolver helpers.
+  // FIXME: Once HeuristicResolver is upstreamed to the clang libraries
+  // (https://github.com/clangd/clangd/discussions/1662),
+  // CXXRecordDecl::lookupDepenedentName() can be removed, and its call sites
+  // can be modified to benefit from the more comprehensive heuristics offered
+  // by HeuristicResolver instead.
+  std::vector
+  lookupDependentName(CXXRecordDecl *RD, DeclarationName Name,
+  llvm::function_ref Filter);
+  bool findOrdinaryMemberInDependentClasses(c

[llvm-branch-commits] [clang-tools-extra] 0c1dcd6 - [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (#83542)

2024-03-16 Thread via llvm-branch-commits

Author: Nathan Ridge
Date: 2024-03-16T15:26:15-07:00
New Revision: 0c1dcd675291f058d530078f9304162ea9d27cd1

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

LOG: [clangd] [HeuristicResolver] Protect against infinite recursion on 
DependentNameTypes (#83542)

When resolving names inside templates that implement recursive
compile-time functions (e.g. waldo::type is defined in terms
of waldo::type), HeuristicResolver could get into an infinite
recursion, specifically one where resolveDependentNameType() can
be called recursively with the same DependentNameType*.

To guard against this, HeuristicResolver tracks, for each external
call into a HeuristicResolver function, the set of DependentNameTypes
that it has seen, and bails if it sees the same DependentNameType again.

To implement this, a helper class HeuristicResolverImpl is introduced
to store state that persists for the duration of an external call into
HeuristicResolver (but does not persist between such calls).

Fixes https://github.com/clangd/clangd/issues/1951

(cherry picked from commit e6e53ca8470d719882539359ebe3ad8b442a8cb0)

Added: 


Modified: 
clang-tools-extra/clangd/HeuristicResolver.cpp
clang-tools-extra/clangd/HeuristicResolver.h
clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/HeuristicResolver.cpp 
b/clang-tools-extra/clangd/HeuristicResolver.cpp
index 3c147b6b582bf0..26d54200eeffd2 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.cpp
+++ b/clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -16,6 +16,80 @@
 namespace clang {
 namespace clangd {
 
+namespace {
+
+// Helper class for implementing HeuristicResolver.
+// Unlike HeuristicResolver which is a long-lived class,
+// a new instance of this class is created for every external
+// call into a HeuristicResolver operation. That allows this
+// class to store state that's local to such a top-level call,
+// particularly "recursion protection sets" that keep track of
+// nodes that have already been seen to avoid infinite recursion.
+class HeuristicResolverImpl {
+public:
+  HeuristicResolverImpl(ASTContext &Ctx) : Ctx(Ctx) {}
+
+  // These functions match the public interface of HeuristicResolver
+  // (but aren't const since they may modify the recursion protection sets).
+  std::vector
+  resolveMemberExpr(const CXXDependentScopeMemberExpr *ME);
+  std::vector
+  resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE);
+  std::vector resolveTypeOfCallExpr(const CallExpr *CE);
+  std::vector resolveCalleeOfCallExpr(const CallExpr *CE);
+  std::vector
+  resolveUsingValueDecl(const UnresolvedUsingValueDecl *UUVD);
+  std::vector
+  resolveDependentNameType(const DependentNameType *DNT);
+  std::vector resolveTemplateSpecializationType(
+  const DependentTemplateSpecializationType *DTST);
+  const Type *resolveNestedNameSpecifierToType(const NestedNameSpecifier *NNS);
+  const Type *getPointeeType(const Type *T);
+
+private:
+  ASTContext &Ctx;
+
+  // Recursion protection sets
+  llvm::SmallSet SeenDependentNameTypes;
+
+  // Given a tag-decl type and a member name, heuristically resolve the
+  // name to one or more declarations.
+  // The current heuristic is simply to look up the name in the primary
+  // template. This is a heuristic because the template could potentially
+  // have specializations that declare 
diff erent members.
+  // Multiple declarations could be returned if the name is overloaded
+  // (e.g. an overloaded method in the primary template).
+  // This heuristic will give the desired answer in many cases, e.g.
+  // for a call to vector::size().
+  std::vector
+  resolveDependentMember(const Type *T, DeclarationName Name,
+ llvm::function_ref Filter);
+
+  // Try to heuristically resolve the type of a possibly-dependent expression
+  // `E`.
+  const Type *resolveExprToType(const Expr *E);
+  std::vector resolveExprToDecls(const Expr *E);
+
+  // Helper function for HeuristicResolver::resolveDependentMember()
+  // which takes a possibly-dependent type `T` and heuristically
+  // resolves it to a CXXRecordDecl in which we can try name lookup.
+  CXXRecordDecl *resolveTypeToRecordDecl(const Type *T);
+
+  // This is a reimplementation of CXXRecordDecl::lookupDependentName()
+  // so that the implementation can call into other HeuristicResolver helpers.
+  // FIXME: Once HeuristicResolver is upstreamed to the clang libraries
+  // (https://github.com/clangd/clangd/discussions/1662),
+  // CXXRecordDecl::lookupDepenedentName() can be removed, and its call sites
+  // can be modified to benefit from the more comprehensive heuristics offered
+  // by HeuristicResolver instead.
+  std::vector
+  lookupDependentName(CXXRecordDecl *RD, Decla

[llvm-branch-commits] [clang-tools-extra] release/18.x: [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (#83542) (PR #84117)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/84117
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++] Use clang-tidy version that matches the compiler we use in the CI (PR #85305)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/85305
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] 3a06861 - [libc++] Use clang-tidy version that matches the compiler we use in the CI (#85305)

2024-03-16 Thread via llvm-branch-commits

Author: Louis Dionne
Date: 2024-03-16T15:32:44-07:00
New Revision: 3a06861272d8a0710d1880e8e3d4954a76b7f256

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

LOG: [libc++] Use clang-tidy version that matches the compiler we use in the CI 
(#85305)

This works around ODR violations in the clang-tidy plugin we use to
perform the modules tests.

Fixes #85242

Added: 


Modified: 
libcxx/test/tools/clang_tidy_checks/CMakeLists.txt

Removed: 




diff  --git a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt 
b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
index 978e7095216522..a52140e2b9938a 100644
--- a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
+++ b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
@@ -5,7 +5,7 @@
 set(LLVM_DIR_SAVE ${LLVM_DIR})
 set(Clang_DIR_SAVE ${Clang_DIR})
 
-find_package(Clang 18)
+find_package(Clang 18.1)
 if (NOT Clang_FOUND)
   find_package(Clang 17)
 endif()



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


[llvm-branch-commits] [lld] [llvm] Backport fixes for ARM64EC import libraries (PR #84590)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/84590

>From 77e1992e89d3734f20c97ad47b4675219f5b9163 Mon Sep 17 00:00:00 2001
From: Jacek Caban 
Date: Tue, 6 Feb 2024 13:47:58 +0100
Subject: [PATCH 1/5] [llvm-readobj][Object][COFF] Print COFF import library
 symbol export name. (#78769)

getExportName implementation is based on lld-link. In its current form,
it's mostly about convenience, but it will be more useful for EXPORTAS
support, for which export name is not possible to deduce from other
printed properties.
---
 lld/test/COFF/def-export-cpp.s|  1 +
 lld/test/COFF/def-export-stdcall.s| 13 ++
 lld/test/COFF/dllexport.s |  4 +++
 llvm/include/llvm/Object/COFFImportFile.h |  1 +
 llvm/lib/Object/COFFImportFile.cpp| 26 +++
 .../tools/llvm-dlltool/coff-decorated.def |  7 +
 llvm/test/tools/llvm-dlltool/coff-exports.def |  3 +++
 llvm/test/tools/llvm-dlltool/coff-noname.def  |  1 +
 .../llvm-dlltool/no-leading-underscore.def|  2 ++
 llvm/test/tools/llvm-lib/arm64ec-implib.test  |  2 ++
 .../tools/llvm-readobj/COFF/file-headers.test |  1 +
 llvm/tools/llvm-readobj/COFFImportDumper.cpp  |  3 +++
 12 files changed, 64 insertions(+)

diff --git a/lld/test/COFF/def-export-cpp.s b/lld/test/COFF/def-export-cpp.s
index e00b35b1c5b39b..370b8ddba4104b 100644
--- a/lld/test/COFF/def-export-cpp.s
+++ b/lld/test/COFF/def-export-cpp.s
@@ -10,6 +10,7 @@
 
 # IMPLIB: File: foo.dll
 # IMPLIB: Name type: undecorate
+# IMPLIB-NEXT: Export name: GetPathOnDisk
 # IMPLIB-NEXT: Symbol: __imp_?GetPathOnDisk@@YA_NPEA_W@Z
 # IMPLIB-NEXT: Symbol: ?GetPathOnDisk@@YA_NPEA_W@Z
 
diff --git a/lld/test/COFF/def-export-stdcall.s 
b/lld/test/COFF/def-export-stdcall.s
index f015e205c74a33..7e4e04c77cbe7a 100644
--- a/lld/test/COFF/def-export-stdcall.s
+++ b/lld/test/COFF/def-export-stdcall.s
@@ -6,15 +6,19 @@
 # RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix 
UNDECORATED-EXPORTS %s
 
 # UNDECORATED-IMPLIB: Name type: noprefix
+# UNDECORATED-IMPLIB-NEXT: Export name: _underscored
 # UNDECORATED-IMPLIB-NEXT: __imp___underscored
 # UNDECORATED-IMPLIB-NEXT: __underscored
 # UNDECORATED-IMPLIB: Name type: undecorate
+# UNDECORATED-IMPLIB-NEXT: Export name: fastcall
 # UNDECORATED-IMPLIB-NEXT: __imp_@fastcall@8
 # UNDECORATED-IMPLIB-NEXT: fastcall@8
 # UNDECORATED-IMPLIB: Name type: undecorate
+# UNDECORATED-IMPLIB-NEXT: Export name: stdcall
 # UNDECORATED-IMPLIB-NEXT: __imp__stdcall@8
 # UNDECORATED-IMPLIB-NEXT: _stdcall@8
 # UNDECORATED-IMPLIB: Name type: undecorate
+# UNDECORATED-IMPLIB-NEXT: Export name: vectorcall
 # UNDECORATED-IMPLIB-NEXT: __imp_vectorcall@@8
 # UNDECORATED-IMPLIB-NEXT: vectorcall@@8
 
@@ -30,12 +34,15 @@
 # RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix 
DECORATED-EXPORTS %s
 
 # DECORATED-IMPLIB: Name type: name
+# DECORATED-IMPLIB-NEXT: Export name: @fastcall@8
 # DECORATED-IMPLIB-NEXT: __imp_@fastcall@8
 # DECORATED-IMPLIB-NEXT: @fastcall@8
 # DECORATED-IMPLIB: Name type: name
+# DECORATED-IMPLIB-NEXT: Export name: _stdcall@8
 # DECORATED-IMPLIB-NEXT: __imp__stdcall@8
 # DECORATED-IMPLIB-NEXT: _stdcall@8
 # DECORATED-IMPLIB: Name type: name
+# DECORATED-IMPLIB-NEXT: Export name: vectorcall@@8
 # DECORATED-IMPLIB-NEXT: __imp_vectorcall@@8
 # DECORATED-IMPLIB-NEXT: vectorcall@@8
 
@@ -51,14 +58,17 @@
 # RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix 
DECORATED-MINGW-EXPORTS %s
 
 # DECORATED-MINGW-IMPLIB: Name type: name
+# DECORATED-MINGW-IMPLIB-NEXT: Export name: @fastcall@8
 # DECORATED-MINGW-IMPLIB-NEXT: __imp_@fastcall@8
 # DECORATED-MINGW-IMPLIB-NEXT: fastcall@8
 # DECORATED-MINGW-IMPLIB: Name type: noprefix
+# DECORATED-MINGW-IMPLIB-NEXT: Export name: stdcall@8
 # DECORATED-MINGW-IMPLIB-NEXT: __imp__stdcall@8
 # DECORATED-MINGW-IMPLIB-NEXT: _stdcall@8
 # GNU tools don't support vectorcall, but this test is just to track that
 # lld's behaviour remains consistent over time.
 # DECORATED-MINGW-IMPLIB: Name type: name
+# DECORATED-MINGW-IMPLIB-NEXT: Export name: vectorcall@@8
 # DECORATED-MINGW-IMPLIB-NEXT: __imp_vectorcall@@8
 # DECORATED-MINGW-IMPLIB-NEXT: vectorcall@@8
 
@@ -75,14 +85,17 @@
 # RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix 
MINGW-KILL-AT-EXPORTS %s
 
 # MINGW-KILL-AT-IMPLIB: Name type: noprefix
+# MINGW-KILL-AT-IMPLIB: Export name: fastcall
 # MINGW-KILL-AT-IMPLIB: __imp__fastcall
 # MINGW-KILL-AT-IMPLIB-NEXT: _fastcall
 # MINGW-KILL-AT-IMPLIB: Name type: noprefix
+# MINGW-KILL-AT-IMPLIB-NEXT: Export name: stdcall
 # MINGW-KILL-AT-IMPLIB-NEXT: __imp__stdcall
 # MINGW-KILL-AT-IMPLIB-NEXT: _stdcall
 # GNU tools don't support vectorcall, but this test is just to track that
 # lld's behaviour remains consistent over time.
 # MINGW-KILL-AT-IMPLIB: Name type: noprefix
+# MINGW-KILL-AT-IMPLIB-NEXT: Export name: vectorcall
 # MINGW-KILL-AT-IMPLIB-NEXT: __imp__vectorcall
 # MINGW-KILL-AT-IMPLIB-NEXT: 

[llvm-branch-commits] [lld] 77e1992 - [llvm-readobj][Object][COFF] Print COFF import library symbol export name. (#78769)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

Author: Jacek Caban
Date: 2024-03-16T15:55:54-07:00
New Revision: 77e1992e89d3734f20c97ad47b4675219f5b9163

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

LOG: [llvm-readobj][Object][COFF] Print COFF import library symbol export name. 
(#78769)

getExportName implementation is based on lld-link. In its current form,
it's mostly about convenience, but it will be more useful for EXPORTAS
support, for which export name is not possible to deduce from other
printed properties.

Added: 


Modified: 
lld/test/COFF/def-export-cpp.s
lld/test/COFF/def-export-stdcall.s
lld/test/COFF/dllexport.s
llvm/include/llvm/Object/COFFImportFile.h
llvm/lib/Object/COFFImportFile.cpp
llvm/test/tools/llvm-dlltool/coff-decorated.def
llvm/test/tools/llvm-dlltool/coff-exports.def
llvm/test/tools/llvm-dlltool/coff-noname.def
llvm/test/tools/llvm-dlltool/no-leading-underscore.def
llvm/test/tools/llvm-lib/arm64ec-implib.test
llvm/test/tools/llvm-readobj/COFF/file-headers.test
llvm/tools/llvm-readobj/COFFImportDumper.cpp

Removed: 




diff  --git a/lld/test/COFF/def-export-cpp.s b/lld/test/COFF/def-export-cpp.s
index e00b35b1c5b39b..370b8ddba4104b 100644
--- a/lld/test/COFF/def-export-cpp.s
+++ b/lld/test/COFF/def-export-cpp.s
@@ -10,6 +10,7 @@
 
 # IMPLIB: File: foo.dll
 # IMPLIB: Name type: undecorate
+# IMPLIB-NEXT: Export name: GetPathOnDisk
 # IMPLIB-NEXT: Symbol: __imp_?GetPathOnDisk@@YA_NPEA_W@Z
 # IMPLIB-NEXT: Symbol: ?GetPathOnDisk@@YA_NPEA_W@Z
 

diff  --git a/lld/test/COFF/def-export-stdcall.s 
b/lld/test/COFF/def-export-stdcall.s
index f015e205c74a33..7e4e04c77cbe7a 100644
--- a/lld/test/COFF/def-export-stdcall.s
+++ b/lld/test/COFF/def-export-stdcall.s
@@ -6,15 +6,19 @@
 # RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix 
UNDECORATED-EXPORTS %s
 
 # UNDECORATED-IMPLIB: Name type: noprefix
+# UNDECORATED-IMPLIB-NEXT: Export name: _underscored
 # UNDECORATED-IMPLIB-NEXT: __imp___underscored
 # UNDECORATED-IMPLIB-NEXT: __underscored
 # UNDECORATED-IMPLIB: Name type: undecorate
+# UNDECORATED-IMPLIB-NEXT: Export name: fastcall
 # UNDECORATED-IMPLIB-NEXT: __imp_@fastcall@8
 # UNDECORATED-IMPLIB-NEXT: fastcall@8
 # UNDECORATED-IMPLIB: Name type: undecorate
+# UNDECORATED-IMPLIB-NEXT: Export name: stdcall
 # UNDECORATED-IMPLIB-NEXT: __imp__stdcall@8
 # UNDECORATED-IMPLIB-NEXT: _stdcall@8
 # UNDECORATED-IMPLIB: Name type: undecorate
+# UNDECORATED-IMPLIB-NEXT: Export name: vectorcall
 # UNDECORATED-IMPLIB-NEXT: __imp_vectorcall@@8
 # UNDECORATED-IMPLIB-NEXT: vectorcall@@8
 
@@ -30,12 +34,15 @@
 # RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix 
DECORATED-EXPORTS %s
 
 # DECORATED-IMPLIB: Name type: name
+# DECORATED-IMPLIB-NEXT: Export name: @fastcall@8
 # DECORATED-IMPLIB-NEXT: __imp_@fastcall@8
 # DECORATED-IMPLIB-NEXT: @fastcall@8
 # DECORATED-IMPLIB: Name type: name
+# DECORATED-IMPLIB-NEXT: Export name: _stdcall@8
 # DECORATED-IMPLIB-NEXT: __imp__stdcall@8
 # DECORATED-IMPLIB-NEXT: _stdcall@8
 # DECORATED-IMPLIB: Name type: name
+# DECORATED-IMPLIB-NEXT: Export name: vectorcall@@8
 # DECORATED-IMPLIB-NEXT: __imp_vectorcall@@8
 # DECORATED-IMPLIB-NEXT: vectorcall@@8
 
@@ -51,14 +58,17 @@
 # RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix 
DECORATED-MINGW-EXPORTS %s
 
 # DECORATED-MINGW-IMPLIB: Name type: name
+# DECORATED-MINGW-IMPLIB-NEXT: Export name: @fastcall@8
 # DECORATED-MINGW-IMPLIB-NEXT: __imp_@fastcall@8
 # DECORATED-MINGW-IMPLIB-NEXT: fastcall@8
 # DECORATED-MINGW-IMPLIB: Name type: noprefix
+# DECORATED-MINGW-IMPLIB-NEXT: Export name: stdcall@8
 # DECORATED-MINGW-IMPLIB-NEXT: __imp__stdcall@8
 # DECORATED-MINGW-IMPLIB-NEXT: _stdcall@8
 # GNU tools don't support vectorcall, but this test is just to track that
 # lld's behaviour remains consistent over time.
 # DECORATED-MINGW-IMPLIB: Name type: name
+# DECORATED-MINGW-IMPLIB-NEXT: Export name: vectorcall@@8
 # DECORATED-MINGW-IMPLIB-NEXT: __imp_vectorcall@@8
 # DECORATED-MINGW-IMPLIB-NEXT: vectorcall@@8
 
@@ -75,14 +85,17 @@
 # RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix 
MINGW-KILL-AT-EXPORTS %s
 
 # MINGW-KILL-AT-IMPLIB: Name type: noprefix
+# MINGW-KILL-AT-IMPLIB: Export name: fastcall
 # MINGW-KILL-AT-IMPLIB: __imp__fastcall
 # MINGW-KILL-AT-IMPLIB-NEXT: _fastcall
 # MINGW-KILL-AT-IMPLIB: Name type: noprefix
+# MINGW-KILL-AT-IMPLIB-NEXT: Export name: stdcall
 # MINGW-KILL-AT-IMPLIB-NEXT: __imp__stdcall
 # MINGW-KILL-AT-IMPLIB-NEXT: _stdcall
 # GNU tools don't support vectorcall, but this test is just to track that
 # lld's behaviour remains consistent over time.
 # MINGW-KILL-AT-IMPLIB: Name type: noprefix
+# MINGW-KILL-AT-IMPLIB-NEXT: Export name: vectorcall
 # MINGW-KILL-AT-IMPLIB-NEXT: __imp__vectorcall
 # MINGW-K

[llvm-branch-commits] [llvm] 76e1800 - [llvm-lib][llvm-dlltool][Object] Add support for EXPORTAS name types. (#78772)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

Author: Jacek Caban
Date: 2024-03-16T15:55:54-07:00
New Revision: 76e1800f356513c491ac3bcebdf952842e7b5a3f

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

LOG: [llvm-lib][llvm-dlltool][Object] Add support for EXPORTAS name types. 
(#78772)

EXPORTAS is a new name type in import libraries. It's used by default on 
ARM64EC,
but it's allowed on other platforms as well.

Added: 
llvm/test/tools/llvm-lib/exportas.test

Modified: 
llvm/include/llvm/BinaryFormat/COFF.h
llvm/include/llvm/Object/COFFImportFile.h
llvm/lib/Object/COFFImportFile.cpp
llvm/lib/Object/COFFModuleDefinition.cpp
llvm/tools/llvm-readobj/COFFImportDumper.cpp

Removed: 




diff  --git a/llvm/include/llvm/BinaryFormat/COFF.h 
b/llvm/include/llvm/BinaryFormat/COFF.h
index 522ee37da6e830..72461d0d9c316a 100644
--- a/llvm/include/llvm/BinaryFormat/COFF.h
+++ b/llvm/include/llvm/BinaryFormat/COFF.h
@@ -716,7 +716,10 @@ enum ImportNameType : unsigned {
   IMPORT_NAME_NOPREFIX = 2,
   /// The import name is the public symbol name, but skipping the leading ?,
   /// @, or optionally _, and truncating at the first @.
-  IMPORT_NAME_UNDECORATE = 3
+  IMPORT_NAME_UNDECORATE = 3,
+  /// The import name is specified as a separate string in the import library
+  /// object file.
+  IMPORT_NAME_EXPORTAS = 4
 };
 
 enum class GuardFlags : uint32_t {

diff  --git a/llvm/include/llvm/Object/COFFImportFile.h 
b/llvm/include/llvm/Object/COFFImportFile.h
index 45a4a795fd1903..7c5846e9c044e3 100644
--- a/llvm/include/llvm/Object/COFFImportFile.h
+++ b/llvm/include/llvm/Object/COFFImportFile.h
@@ -92,6 +92,10 @@ struct COFFShortExport {
   /// file, this is "baz" in "EXPORTS\nfoo = bar == baz".
   std::string AliasTarget;
 
+  /// Specifies EXPORTAS name. In a .def file, this is "bar" in
+  /// "EXPORTS\nfoo EXPORTAS bar".
+  std::string ExportAs;
+
   uint16_t Ordinal = 0;
   bool Noname = false;
   bool Data = false;

diff  --git a/llvm/lib/Object/COFFImportFile.cpp 
b/llvm/lib/Object/COFFImportFile.cpp
index d7d26f4f4180c3..51e6274dcf235c 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -71,6 +71,12 @@ StringRef COFFImportFile::getExportName() const {
 name = ltrim1(name, "?@_");
 name = name.substr(0, name.find('@'));
 break;
+  case IMPORT_NAME_EXPORTAS: {
+// Skip DLL name
+name = Data.getBuffer().substr(sizeof(*hdr) + name.size() + 1);
+name = name.split('\0').second.split('\0').first;
+break;
+  }
   default:
 break;
   }
@@ -209,6 +215,7 @@ class ObjectFactory {
   // Library Format.
   NewArchiveMember createShortImport(StringRef Sym, uint16_t Ordinal,
  ImportType Type, ImportNameType NameType,
+ StringRef ExportName,
  MachineTypes Machine);
 
   // Create a weak external file which is described in PE/COFF Aux Format 3.
@@ -500,12 +507,13 @@ NewArchiveMember 
ObjectFactory::createNullThunk(std::vector &Buffer) {
   return {MemoryBufferRef{F, ImportName}};
 }
 
-NewArchiveMember ObjectFactory::createShortImport(StringRef Sym,
-  uint16_t Ordinal,
-  ImportType ImportType,
-  ImportNameType NameType,
-  MachineTypes Machine) {
+NewArchiveMember
+ObjectFactory::createShortImport(StringRef Sym, uint16_t Ordinal,
+ ImportType ImportType, ImportNameType 
NameType,
+ StringRef ExportName, MachineTypes Machine) {
   size_t ImpSize = ImportName.size() + Sym.size() + 2; // +2 for NULs
+  if (!ExportName.empty())
+ImpSize += ExportName.size() + 1;
   size_t Size = sizeof(coff_import_header) + ImpSize;
   char *Buf = Alloc.Allocate(Size);
   memset(Buf, 0, Size);
@@ -525,6 +533,10 @@ NewArchiveMember 
ObjectFactory::createShortImport(StringRef Sym,
   memcpy(P, Sym.data(), Sym.size());
   P += Sym.size() + 1;
   memcpy(P, ImportName.data(), ImportName.size());
+  if (!ExportName.empty()) {
+P += ImportName.size() + 1;
+memcpy(P, ExportName.data(), ExportName.size());
+  }
 
   return {MemoryBufferRef(StringRef(Buf, Size), ImportName)};
 }
@@ -641,27 +653,39 @@ Error writeImportLibrary(StringRef ImportName, StringRef 
Path,
   ImportType = IMPORT_CONST;
 
 StringRef SymbolName = E.SymbolName.empty() ? E.Name : E.SymbolName;
-ImportNameType NameType = E.Noname
-  ? IMPORT_ORDINAL
-  : getNameType(SymbolName, E.Name,
-Machine, MinGW);
-Expected Name = E.

[llvm-branch-commits] [llvm] 207ecd6 - [Arm64EC] Copy import descriptors to the EC Map (#84834)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

Author: Daniel Paoliello
Date: 2024-03-16T15:55:54-07:00
New Revision: 207ecd684cc6731266e12d8d2df0e3d1d9e1ff8d

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

LOG: [Arm64EC] Copy import descriptors to the EC Map (#84834)

As noted in , MSVC
places import descriptors in both the EC and regular map - that PR moved
the descriptors to ONLY the regular map, however this causes linking
errors when linking as Arm64EC:

```
bcryptprimitives.lib(bcryptprimitives.dll) : error LNK2001: unresolved external 
symbol __IMPORT_DESCRIPTOR_bcryptprimitives (EC Symbol)
```

This change copies import descriptors from the regular map to the EC
map, which fixes this linking error.

Added: 


Modified: 
llvm/include/llvm/Object/COFFImportFile.h
llvm/lib/Object/ArchiveWriter.cpp
llvm/lib/Object/COFFImportFile.cpp
llvm/test/tools/llvm-lib/arm64ec-implib.test

Removed: 




diff  --git a/llvm/include/llvm/Object/COFFImportFile.h 
b/llvm/include/llvm/Object/COFFImportFile.h
index 46a982ddb7eee6..c79ff18d3616ed 100644
--- a/llvm/include/llvm/Object/COFFImportFile.h
+++ b/llvm/include/llvm/Object/COFFImportFile.h
@@ -26,6 +26,12 @@
 namespace llvm {
 namespace object {
 
+constexpr std::string_view ImportDescriptorPrefix = "__IMPORT_DESCRIPTOR_";
+constexpr std::string_view NullImportDescriptorSymbolName =
+"__NULL_IMPORT_DESCRIPTOR";
+constexpr std::string_view NullThunkDataPrefix = "\x7f";
+constexpr std::string_view NullThunkDataSuffix = "_NULL_THUNK_DATA";
+
 class COFFImportFile : public SymbolicFile {
 private:
   enum SymbolIndex { ImpSymbol, ThunkSymbol, ECAuxSymbol, ECThunkSymbol };

diff  --git a/llvm/lib/Object/ArchiveWriter.cpp 
b/llvm/lib/Object/ArchiveWriter.cpp
index 155926a8c5949d..1a7ed2db543964 100644
--- a/llvm/lib/Object/ArchiveWriter.cpp
+++ b/llvm/lib/Object/ArchiveWriter.cpp
@@ -677,6 +677,13 @@ static bool isECObject(object::SymbolicFile &Obj) {
   return false;
 }
 
+bool isImportDescriptor(StringRef Name) {
+  return Name.starts_with(ImportDescriptorPrefix) ||
+ Name == StringRef{NullImportDescriptorSymbolName} ||
+ (Name.starts_with(NullThunkDataPrefix) &&
+  Name.ends_with(NullThunkDataSuffix));
+}
+
 static Expected> getSymbols(SymbolicFile *Obj,
   uint16_t Index,
   raw_ostream &SymNames,
@@ -704,6 +711,10 @@ static Expected> 
getSymbols(SymbolicFile *Obj,
   if (Map == &SymMap->Map) {
 Ret.push_back(SymNames.tell());
 SymNames << Name << '\0';
+// If EC is enabled, then the import descriptors are NOT put into EC
+// objects so we need to copy them to the EC map manually.
+if (SymMap->UseECMap && isImportDescriptor(Name))
+  SymMap->ECMap[Name] = Index;
   }
 } else {
   Ret.push_back(SymNames.tell());

diff  --git a/llvm/lib/Object/COFFImportFile.cpp 
b/llvm/lib/Object/COFFImportFile.cpp
index a3e5e78952c16a..99a42d8c4e06a5 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -108,7 +108,7 @@ template  static void append(std::vector 
&B, const T &Data) {
 }
 
 static void writeStringTable(std::vector &B,
- ArrayRef Strings) {
+ ArrayRef Strings) {
   // The COFF string table consists of a 4-byte value which is the size of the
   // table, including the length field itself.  This value is followed by the
   // string content itself, which is an array of null-terminated C-style
@@ -171,9 +171,6 @@ static Expected replace(StringRef S, StringRef 
From,
   return (Twine(S.substr(0, Pos)) + To + S.substr(Pos + From.size())).str();
 }
 
-static const std::string NullImportDescriptorSymbolName =
-"__NULL_IMPORT_DESCRIPTOR";
-
 namespace {
 // This class constructs various small object files necessary to support 
linking
 // symbols imported from a DLL.  The contents are pretty strictly defined and
@@ -192,8 +189,9 @@ class ObjectFactory {
 public:
   ObjectFactory(StringRef S, MachineTypes M)
   : NativeMachine(M), ImportName(S), Library(llvm::sys::path::stem(S)),
-ImportDescriptorSymbolName(("__IMPORT_DESCRIPTOR_" + Library).str()),
-NullThunkSymbolName(("\x7f" + Library + "_NULL_THUNK_DATA").str()) {}
+ImportDescriptorSymbolName((ImportDescriptorPrefix + Library).str()),
+NullThunkSymbolName(
+(NullThunkDataPrefix + Library + NullThunkDataSuffix).str()) {}
 
   // Creates an Import Descriptor.  This is a small object file which contains 
a
   // reference to the terminators and contains the library name (entry) for the

diff  --git a/llvm/test/tools/llvm-lib/arm64ec-implib.test 
b/llvm/tes

[llvm-branch-commits] [llvm] 79bc8b3 - [llvm-lib][Object] Add support for EC importlib symbols. (#81059)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

Author: Jacek Caban
Date: 2024-03-16T15:55:54-07:00
New Revision: 79bc8b32c6ed4fc6e002d6426c04d4de874b07cc

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

LOG: [llvm-lib][Object] Add support for EC importlib symbols. (#81059)

ARM64EC import libraries expose two additional symbols: mangled thunk
symbol (like `#func`) and auxiliary import symbol (like`__imp_aux_func`).
The main functional change with this patch is that those symbols are
properly added to static library ECSYMBOLS.

Added: 


Modified: 
llvm/include/llvm/Object/COFF.h
llvm/include/llvm/Object/COFFImportFile.h
llvm/lib/Object/COFFImportFile.cpp
llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
llvm/lib/Target/AArch64/Utils/AArch64BaseInfo.h
llvm/test/tools/llvm-lib/arm64ec-implib.test

Removed: 




diff  --git a/llvm/include/llvm/Object/COFF.h b/llvm/include/llvm/Object/COFF.h
index a548b2c15c5fdc..2a5c3d8913b15c 100644
--- a/llvm/include/llvm/Object/COFF.h
+++ b/llvm/include/llvm/Object/COFF.h
@@ -1362,6 +1362,47 @@ class SectionStrippedError
   SectionStrippedError() { setErrorCode(object_error::section_stripped); }
 };
 
+inline std::optional
+getArm64ECMangledFunctionName(StringRef Name) {
+  bool IsCppFn = Name[0] == '?';
+  if (IsCppFn && Name.find("$$h") != std::string::npos)
+return std::nullopt;
+  if (!IsCppFn && Name[0] == '#')
+return std::nullopt;
+
+  StringRef Prefix = "$$h";
+  size_t InsertIdx = 0;
+  if (IsCppFn) {
+InsertIdx = Name.find("@@");
+size_t ThreeAtSignsIdx = Name.find("@@@");
+if (InsertIdx != std::string::npos && InsertIdx != ThreeAtSignsIdx) {
+  InsertIdx += 2;
+} else {
+  InsertIdx = Name.find("@");
+  if (InsertIdx != std::string::npos)
+InsertIdx++;
+}
+  } else {
+Prefix = "#";
+  }
+
+  return std::optional(
+  (Name.substr(0, InsertIdx) + Prefix + Name.substr(InsertIdx)).str());
+}
+
+inline std::optional
+getArm64ECDemangledFunctionName(StringRef Name) {
+  if (Name[0] == '#')
+return std::string(Name.substr(1));
+  if (Name[0] != '?')
+return std::nullopt;
+
+  std::pair Pair = Name.split("$$h");
+  if (Pair.second.empty())
+return std::nullopt;
+  return (Pair.first + Pair.second).str();
+}
+
 } // end namespace object
 
 } // end namespace llvm

diff  --git a/llvm/include/llvm/Object/COFFImportFile.h 
b/llvm/include/llvm/Object/COFFImportFile.h
index 7c5846e9c044e3..46a982ddb7eee6 100644
--- a/llvm/include/llvm/Object/COFFImportFile.h
+++ b/llvm/include/llvm/Object/COFFImportFile.h
@@ -27,6 +27,9 @@ namespace llvm {
 namespace object {
 
 class COFFImportFile : public SymbolicFile {
+private:
+  enum SymbolIndex { ImpSymbol, ThunkSymbol, ECAuxSymbol, ECThunkSymbol };
+
 public:
   COFFImportFile(MemoryBufferRef Source)
   : SymbolicFile(ID_COFFImportFile, Source) {}
@@ -36,9 +39,23 @@ class COFFImportFile : public SymbolicFile {
   void moveSymbolNext(DataRefImpl &Symb) const override { ++Symb.p; }
 
   Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override {
-if (Symb.p == 0)
+switch (Symb.p) {
+case ImpSymbol:
   OS << "__imp_";
-OS << StringRef(Data.getBufferStart() + sizeof(coff_import_header));
+  break;
+case ECAuxSymbol:
+  OS << "__imp_aux_";
+  break;
+}
+const char *Name = Data.getBufferStart() + sizeof(coff_import_header);
+if (Symb.p != ECThunkSymbol && COFF::isArm64EC(getMachine())) {
+  if (std::optional DemangledName =
+  getArm64ECDemangledFunctionName(Name)) {
+OS << StringRef(*DemangledName);
+return Error::success();
+  }
+}
+OS << StringRef(Name);
 return Error::success();
   }
 
@@ -52,7 +69,12 @@ class COFFImportFile : public SymbolicFile {
 
   basic_symbol_iterator symbol_end() const override {
 DataRefImpl Symb;
-Symb.p = isData() ? 1 : 2;
+if (isData())
+  Symb.p = ImpSymbol + 1;
+else if (COFF::isArm64EC(getMachine()))
+  Symb.p = ECThunkSymbol + 1;
+else
+  Symb.p = ThunkSymbol + 1;
 return BasicSymbolRef(Symb, this);
   }
 

diff  --git a/llvm/lib/Object/COFFImportFile.cpp 
b/llvm/lib/Object/COFFImportFile.cpp
index 51e6274dcf235c..a3e5e78952c16a 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -684,6 +684,21 @@ Error writeImportLibrary(StringRef ImportName, StringRef 
Path,
   NameType = getNameType(SymbolName, E.Name, Machine, MinGW);
 }
 
+// On ARM64EC, use EXPORTAS to import demangled name for mangled symbols.
+if (ImportType == IMPORT_CODE && isArm64EC(Machine)) {
+  if (std::optional MangledName =
+  getArm64ECMangledFunctionName(Name)) {
+if (ExportName.empty(

[llvm-branch-commits] [lld] [llvm] Backport fixes for ARM64EC import libraries (PR #84590)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/84590
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 2f640ad - Remove support for EXPORTAS in def files to maintain ABI compatibility for COFFShortExport

2024-03-16 Thread Tom Stellard via llvm-branch-commits

Author: Daniel Paoliello
Date: 2024-03-16T15:55:54-07:00
New Revision: 2f640ad26d176a70c5e7a77c92a899e525e366d9

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

LOG: Remove support for EXPORTAS in def files to maintain ABI compatibility for 
COFFShortExport

Added: 


Modified: 
llvm/include/llvm/Object/COFFImportFile.h
llvm/lib/Object/COFFImportFile.cpp
llvm/lib/Object/COFFModuleDefinition.cpp
llvm/test/tools/llvm-lib/arm64ec-implib.test

Removed: 
llvm/test/tools/llvm-lib/exportas.test



diff  --git a/llvm/include/llvm/Object/COFFImportFile.h 
b/llvm/include/llvm/Object/COFFImportFile.h
index c79ff18d3616ed..8358197309f000 100644
--- a/llvm/include/llvm/Object/COFFImportFile.h
+++ b/llvm/include/llvm/Object/COFFImportFile.h
@@ -120,10 +120,6 @@ struct COFFShortExport {
   /// file, this is "baz" in "EXPORTS\nfoo = bar == baz".
   std::string AliasTarget;
 
-  /// Specifies EXPORTAS name. In a .def file, this is "bar" in
-  /// "EXPORTS\nfoo EXPORTAS bar".
-  std::string ExportAs;
-
   uint16_t Ordinal = 0;
   bool Noname = false;
   bool Data = false;

diff  --git a/llvm/lib/Object/COFFImportFile.cpp 
b/llvm/lib/Object/COFFImportFile.cpp
index 99a42d8c4e06a5..d3b5cf2d9f7b52 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -675,9 +675,6 @@ Error writeImportLibrary(StringRef ImportName, StringRef 
Path,
 std::string ExportName;
 if (E.Noname) {
   NameType = IMPORT_ORDINAL;
-} else if (!E.ExportAs.empty()) {
-  NameType = IMPORT_NAME_EXPORTAS;
-  ExportName = E.ExportAs;
 } else {
   NameType = getNameType(SymbolName, E.Name, Machine, MinGW);
 }

diff  --git a/llvm/lib/Object/COFFModuleDefinition.cpp 
b/llvm/lib/Object/COFFModuleDefinition.cpp
index f60dd49793685f..648f01f823d007 100644
--- a/llvm/lib/Object/COFFModuleDefinition.cpp
+++ b/llvm/lib/Object/COFFModuleDefinition.cpp
@@ -39,7 +39,6 @@ enum Kind {
   KwConstant,
   KwData,
   KwExports,
-  KwExportAs,
   KwHeapsize,
   KwLibrary,
   KwName,
@@ -119,7 +118,6 @@ class Lexer {
.Case("CONSTANT", KwConstant)
.Case("DATA", KwData)
.Case("EXPORTS", KwExports)
-   .Case("EXPORTAS", KwExportAs)
.Case("HEAPSIZE", KwHeapsize)
.Case("LIBRARY", KwLibrary)
.Case("NAME", KwName)
@@ -288,16 +286,7 @@ class Parser {
   E.AliasTarget = std::string("_").append(E.AliasTarget);
 continue;
   }
-  // EXPORTAS must be at the end of export definition
-  if (Tok.K == KwExportAs) {
-read();
-if (Tok.K == Eof)
-  return createError(
-  "unexpected end of file, EXPORTAS identifier expected");
-E.ExportAs = std::string(Tok.Value);
-  } else {
-unget();
-  }
+  unget();
   Info.Exports.push_back(E);
   return Error::success();
 }

diff  --git a/llvm/test/tools/llvm-lib/arm64ec-implib.test 
b/llvm/test/tools/llvm-lib/arm64ec-implib.test
index 52ac486da9e292..ebc1b166ee4ea6 100644
--- a/llvm/test/tools/llvm-lib/arm64ec-implib.test
+++ b/llvm/test/tools/llvm-lib/arm64ec-implib.test
@@ -100,89 +100,6 @@ Creating a new lib containing the existing lib:
 RUN: llvm-lib -machine:arm64ec test.lib -out:test2.lib
 RUN: llvm-nm --print-armap test2.lib | FileCheck -check-prefix=ARMAP %s
 
-
-RUN: llvm-lib -machine:arm64ec -def:exportas.def -out:exportas.lib
-RUN: llvm-nm --print-armap exportas.lib | FileCheck -check-prefix=EXPAS-ARMAP 
%s
-RUN: llvm-readobj exportas.lib | FileCheck -check-prefix=EXPAS-READOBJ %s
-
-EXPAS-ARMAP:  Archive EC map
-EXPAS-ARMAP-NEXT: #func1 in test.dll
-EXPAS-ARMAP-NEXT: #func2 in test.dll
-EXPAS-ARMAP-NEXT: #func3 in test.dll
-EXPAS-ARMAP-NEXT: #func4 in test.dll
-EXPAS-ARMAP-NEXT: __IMPORT_DESCRIPTOR_test in test.dll
-EXPAS-ARMAP-NEXT: __NULL_IMPORT_DESCRIPTOR in test.dll
-EXPAS-ARMAP-NEXT: __imp_aux_func1 in test.dll
-EXPAS-ARMAP-NEXT: __imp_aux_func2 in test.dll
-EXPAS-ARMAP-NEXT: __imp_aux_func3 in test.dll
-EXPAS-ARMAP-NEXT: __imp_aux_func4 in test.dll
-EXPAS-ARMAP-NEXT: __imp_data1 in test.dll
-EXPAS-ARMAP-NEXT: __imp_data2 in test.dll
-EXPAS-ARMAP-NEXT: __imp_func1 in test.dll
-EXPAS-ARMAP-NEXT: __imp_func2 in test.dll
-EXPAS-ARMAP-NEXT: __imp_func3 in test.dll
-EXPAS-ARMAP-NEXT: __imp_func4 in test.dll
-EXPAS-ARMAP-NEXT: func1 in test.dll
-EXPAS-ARMAP-NEXT: func2 in test.dll
-EXPAS-ARMAP-NEXT: func3 in test.dll
-EXPAS-ARMAP-NEXT: func4 in test.dll
-EXPAS-ARMAP-NEXT: test_NULL_THUNK_DATA in test.dll
-
-EXPAS-READOBJ:  File: test.dll
-EXPAS-READOBJ-NEXT: Format: COFF-import-file-ARM64EC
-EXPAS-READOBJ-NEXT: Type: code
-EXPAS-READOBJ-NEXT: Name type: export as
-EXPAS-READOBJ-NEXT: Export nam

[llvm-branch-commits] [llvm] release/18.x: [llvm][AArch64] Autoupgrade function attributes from Module attributes. (#82763) (PR #84039)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

@nickdesaulniers So we should not backport this?

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


[llvm-branch-commits] [lld] release/18.x: [lld][LoongArch] Fix handleUleb128 (PR #85238)

2024-03-16 Thread via llvm-branch-commits

https://github.com/llvmbot updated 
https://github.com/llvm/llvm-project/pull/85238

>From b95ea2e51bdfe20c9db6a0675ab068fa59a0b9fe Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Tue, 5 Mar 2024 22:01:07 +0800
Subject: [PATCH 1/2] [lld][test] Fix sanitizer buildbot failure

Buildbot failure:
https://lab.llvm.org/buildbot/#/builders/5/builds/41530/steps/9/logs/stdio

(cherry picked from commit d9b435c24cc8148fd97b42f6bb1124e52307)
---
 lld/test/ELF/loongarch-reloc-leb128.s | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lld/test/ELF/loongarch-reloc-leb128.s 
b/lld/test/ELF/loongarch-reloc-leb128.s
index 9e6f221e62b639..2dd327d1564ebd 100644
--- a/lld/test/ELF/loongarch-reloc-leb128.s
+++ b/lld/test/ELF/loongarch-reloc-leb128.s
@@ -99,4 +99,4 @@ w2:
 .reloc ., R_LARCH_ADD_ULEB128, w2
 .reloc ., R_LARCH_SUB_ULEB128, w1
 .fill 10, 1, 0x80
-.byte 0
+.byte 1

>From edbe7fa5fef93bb747cb58a589dc25901793774b Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Tue, 5 Mar 2024 23:19:16 +0800
Subject: [PATCH 2/2] [lld][LoongArch] Fix handleUleb128

(cherry picked from commit a41bcb3930534ef1525b4fc30e53e818b39e2b60)
---
 lld/ELF/Arch/LoongArch.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index 8a6f6db68f2909..464f5dfb320ccc 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -159,8 +159,9 @@ static bool isJirl(uint32_t insn) {
 static void handleUleb128(uint8_t *loc, uint64_t val) {
   const uint32_t maxcount = 1 + 64 / 7;
   uint32_t count;
-  uint64_t orig = decodeULEB128(loc, &count);
-  if (count > maxcount)
+  const char *error = nullptr;
+  uint64_t orig = decodeULEB128(loc, &count, nullptr, &error);
+  if (count > maxcount || (count == maxcount && error))
 errorOrWarn(getErrorLocation(loc) + "extra space for uleb128");
   uint64_t mask = count < maxcount ? (1ULL << 7 * count) - 1 : -1ULL;
   encodeULEB128((orig + val) & mask, loc, count);

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


[llvm-branch-commits] [lld] edbe7fa - [lld][LoongArch] Fix handleUleb128

2024-03-16 Thread via llvm-branch-commits

Author: Weining Lu
Date: 2024-03-16T18:28:00-07:00
New Revision: edbe7fa5fef93bb747cb58a589dc25901793774b

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

LOG: [lld][LoongArch] Fix handleUleb128

(cherry picked from commit a41bcb3930534ef1525b4fc30e53e818b39e2b60)

Added: 


Modified: 
lld/ELF/Arch/LoongArch.cpp

Removed: 




diff  --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index 8a6f6db68f2909..464f5dfb320ccc 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -159,8 +159,9 @@ static bool isJirl(uint32_t insn) {
 static void handleUleb128(uint8_t *loc, uint64_t val) {
   const uint32_t maxcount = 1 + 64 / 7;
   uint32_t count;
-  uint64_t orig = decodeULEB128(loc, &count);
-  if (count > maxcount)
+  const char *error = nullptr;
+  uint64_t orig = decodeULEB128(loc, &count, nullptr, &error);
+  if (count > maxcount || (count == maxcount && error))
 errorOrWarn(getErrorLocation(loc) + "extra space for uleb128");
   uint64_t mask = count < maxcount ? (1ULL << 7 * count) - 1 : -1ULL;
   encodeULEB128((orig + val) & mask, loc, count);



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


[llvm-branch-commits] [lld] b95ea2e - [lld][test] Fix sanitizer buildbot failure

2024-03-16 Thread via llvm-branch-commits

Author: Weining Lu
Date: 2024-03-16T18:28:00-07:00
New Revision: b95ea2e51bdfe20c9db6a0675ab068fa59a0b9fe

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

LOG: [lld][test] Fix sanitizer buildbot failure

Buildbot failure:
https://lab.llvm.org/buildbot/#/builders/5/builds/41530/steps/9/logs/stdio

(cherry picked from commit d9b435c24cc8148fd97b42f6bb1124e52307)

Added: 


Modified: 
lld/test/ELF/loongarch-reloc-leb128.s

Removed: 




diff  --git a/lld/test/ELF/loongarch-reloc-leb128.s 
b/lld/test/ELF/loongarch-reloc-leb128.s
index 9e6f221e62b639..2dd327d1564ebd 100644
--- a/lld/test/ELF/loongarch-reloc-leb128.s
+++ b/lld/test/ELF/loongarch-reloc-leb128.s
@@ -99,4 +99,4 @@ w2:
 .reloc ., R_LARCH_ADD_ULEB128, w2
 .reloc ., R_LARCH_SUB_ULEB128, w1
 .fill 10, 1, 0x80
-.byte 0
+.byte 1



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


[llvm-branch-commits] [lld] release/18.x: [lld][LoongArch] Fix handleUleb128 (PR #85238)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/85238
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] 0c1dcd6 - [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (#83542)

2024-03-16 Thread via llvm-branch-commits

Author: Nathan Ridge
Date: 2024-03-16T15:26:15-07:00
New Revision: 0c1dcd675291f058d530078f9304162ea9d27cd1

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

LOG: [clangd] [HeuristicResolver] Protect against infinite recursion on 
DependentNameTypes (#83542)

When resolving names inside templates that implement recursive
compile-time functions (e.g. waldo::type is defined in terms
of waldo::type), HeuristicResolver could get into an infinite
recursion, specifically one where resolveDependentNameType() can
be called recursively with the same DependentNameType*.

To guard against this, HeuristicResolver tracks, for each external
call into a HeuristicResolver function, the set of DependentNameTypes
that it has seen, and bails if it sees the same DependentNameType again.

To implement this, a helper class HeuristicResolverImpl is introduced
to store state that persists for the duration of an external call into
HeuristicResolver (but does not persist between such calls).

Fixes https://github.com/clangd/clangd/issues/1951

(cherry picked from commit e6e53ca8470d719882539359ebe3ad8b442a8cb0)

Added: 


Modified: 
clang-tools-extra/clangd/HeuristicResolver.cpp
clang-tools-extra/clangd/HeuristicResolver.h
clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/HeuristicResolver.cpp 
b/clang-tools-extra/clangd/HeuristicResolver.cpp
index 3c147b6b582bf0..26d54200eeffd2 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.cpp
+++ b/clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -16,6 +16,80 @@
 namespace clang {
 namespace clangd {
 
+namespace {
+
+// Helper class for implementing HeuristicResolver.
+// Unlike HeuristicResolver which is a long-lived class,
+// a new instance of this class is created for every external
+// call into a HeuristicResolver operation. That allows this
+// class to store state that's local to such a top-level call,
+// particularly "recursion protection sets" that keep track of
+// nodes that have already been seen to avoid infinite recursion.
+class HeuristicResolverImpl {
+public:
+  HeuristicResolverImpl(ASTContext &Ctx) : Ctx(Ctx) {}
+
+  // These functions match the public interface of HeuristicResolver
+  // (but aren't const since they may modify the recursion protection sets).
+  std::vector
+  resolveMemberExpr(const CXXDependentScopeMemberExpr *ME);
+  std::vector
+  resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE);
+  std::vector resolveTypeOfCallExpr(const CallExpr *CE);
+  std::vector resolveCalleeOfCallExpr(const CallExpr *CE);
+  std::vector
+  resolveUsingValueDecl(const UnresolvedUsingValueDecl *UUVD);
+  std::vector
+  resolveDependentNameType(const DependentNameType *DNT);
+  std::vector resolveTemplateSpecializationType(
+  const DependentTemplateSpecializationType *DTST);
+  const Type *resolveNestedNameSpecifierToType(const NestedNameSpecifier *NNS);
+  const Type *getPointeeType(const Type *T);
+
+private:
+  ASTContext &Ctx;
+
+  // Recursion protection sets
+  llvm::SmallSet SeenDependentNameTypes;
+
+  // Given a tag-decl type and a member name, heuristically resolve the
+  // name to one or more declarations.
+  // The current heuristic is simply to look up the name in the primary
+  // template. This is a heuristic because the template could potentially
+  // have specializations that declare 
diff erent members.
+  // Multiple declarations could be returned if the name is overloaded
+  // (e.g. an overloaded method in the primary template).
+  // This heuristic will give the desired answer in many cases, e.g.
+  // for a call to vector::size().
+  std::vector
+  resolveDependentMember(const Type *T, DeclarationName Name,
+ llvm::function_ref Filter);
+
+  // Try to heuristically resolve the type of a possibly-dependent expression
+  // `E`.
+  const Type *resolveExprToType(const Expr *E);
+  std::vector resolveExprToDecls(const Expr *E);
+
+  // Helper function for HeuristicResolver::resolveDependentMember()
+  // which takes a possibly-dependent type `T` and heuristically
+  // resolves it to a CXXRecordDecl in which we can try name lookup.
+  CXXRecordDecl *resolveTypeToRecordDecl(const Type *T);
+
+  // This is a reimplementation of CXXRecordDecl::lookupDependentName()
+  // so that the implementation can call into other HeuristicResolver helpers.
+  // FIXME: Once HeuristicResolver is upstreamed to the clang libraries
+  // (https://github.com/clangd/clangd/discussions/1662),
+  // CXXRecordDecl::lookupDepenedentName() can be removed, and its call sites
+  // can be modified to benefit from the more comprehensive heuristics offered
+  // by HeuristicResolver instead.
+  std::vector
+  lookupDependentName(CXXRecordDecl *RD, Decla

[llvm-branch-commits] [libcxx] 3a06861 - [libc++] Use clang-tidy version that matches the compiler we use in the CI (#85305)

2024-03-16 Thread via llvm-branch-commits

Author: Louis Dionne
Date: 2024-03-16T15:32:44-07:00
New Revision: 3a06861272d8a0710d1880e8e3d4954a76b7f256

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

LOG: [libc++] Use clang-tidy version that matches the compiler we use in the CI 
(#85305)

This works around ODR violations in the clang-tidy plugin we use to
perform the modules tests.

Fixes #85242

Added: 


Modified: 
libcxx/test/tools/clang_tidy_checks/CMakeLists.txt

Removed: 




diff  --git a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt 
b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
index 978e7095216522..a52140e2b9938a 100644
--- a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
+++ b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
@@ -5,7 +5,7 @@
 set(LLVM_DIR_SAVE ${LLVM_DIR})
 set(Clang_DIR_SAVE ${Clang_DIR})
 
-find_package(Clang 18)
+find_package(Clang 18.1)
 if (NOT Clang_FOUND)
   find_package(Clang 17)
 endif()



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


[llvm-branch-commits] [lld] 77e1992 - [llvm-readobj][Object][COFF] Print COFF import library symbol export name. (#78769)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

Author: Jacek Caban
Date: 2024-03-16T15:55:54-07:00
New Revision: 77e1992e89d3734f20c97ad47b4675219f5b9163

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

LOG: [llvm-readobj][Object][COFF] Print COFF import library symbol export name. 
(#78769)

getExportName implementation is based on lld-link. In its current form,
it's mostly about convenience, but it will be more useful for EXPORTAS
support, for which export name is not possible to deduce from other
printed properties.

Added: 


Modified: 
lld/test/COFF/def-export-cpp.s
lld/test/COFF/def-export-stdcall.s
lld/test/COFF/dllexport.s
llvm/include/llvm/Object/COFFImportFile.h
llvm/lib/Object/COFFImportFile.cpp
llvm/test/tools/llvm-dlltool/coff-decorated.def
llvm/test/tools/llvm-dlltool/coff-exports.def
llvm/test/tools/llvm-dlltool/coff-noname.def
llvm/test/tools/llvm-dlltool/no-leading-underscore.def
llvm/test/tools/llvm-lib/arm64ec-implib.test
llvm/test/tools/llvm-readobj/COFF/file-headers.test
llvm/tools/llvm-readobj/COFFImportDumper.cpp

Removed: 




diff  --git a/lld/test/COFF/def-export-cpp.s b/lld/test/COFF/def-export-cpp.s
index e00b35b1c5b39b..370b8ddba4104b 100644
--- a/lld/test/COFF/def-export-cpp.s
+++ b/lld/test/COFF/def-export-cpp.s
@@ -10,6 +10,7 @@
 
 # IMPLIB: File: foo.dll
 # IMPLIB: Name type: undecorate
+# IMPLIB-NEXT: Export name: GetPathOnDisk
 # IMPLIB-NEXT: Symbol: __imp_?GetPathOnDisk@@YA_NPEA_W@Z
 # IMPLIB-NEXT: Symbol: ?GetPathOnDisk@@YA_NPEA_W@Z
 

diff  --git a/lld/test/COFF/def-export-stdcall.s 
b/lld/test/COFF/def-export-stdcall.s
index f015e205c74a33..7e4e04c77cbe7a 100644
--- a/lld/test/COFF/def-export-stdcall.s
+++ b/lld/test/COFF/def-export-stdcall.s
@@ -6,15 +6,19 @@
 # RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix 
UNDECORATED-EXPORTS %s
 
 # UNDECORATED-IMPLIB: Name type: noprefix
+# UNDECORATED-IMPLIB-NEXT: Export name: _underscored
 # UNDECORATED-IMPLIB-NEXT: __imp___underscored
 # UNDECORATED-IMPLIB-NEXT: __underscored
 # UNDECORATED-IMPLIB: Name type: undecorate
+# UNDECORATED-IMPLIB-NEXT: Export name: fastcall
 # UNDECORATED-IMPLIB-NEXT: __imp_@fastcall@8
 # UNDECORATED-IMPLIB-NEXT: fastcall@8
 # UNDECORATED-IMPLIB: Name type: undecorate
+# UNDECORATED-IMPLIB-NEXT: Export name: stdcall
 # UNDECORATED-IMPLIB-NEXT: __imp__stdcall@8
 # UNDECORATED-IMPLIB-NEXT: _stdcall@8
 # UNDECORATED-IMPLIB: Name type: undecorate
+# UNDECORATED-IMPLIB-NEXT: Export name: vectorcall
 # UNDECORATED-IMPLIB-NEXT: __imp_vectorcall@@8
 # UNDECORATED-IMPLIB-NEXT: vectorcall@@8
 
@@ -30,12 +34,15 @@
 # RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix 
DECORATED-EXPORTS %s
 
 # DECORATED-IMPLIB: Name type: name
+# DECORATED-IMPLIB-NEXT: Export name: @fastcall@8
 # DECORATED-IMPLIB-NEXT: __imp_@fastcall@8
 # DECORATED-IMPLIB-NEXT: @fastcall@8
 # DECORATED-IMPLIB: Name type: name
+# DECORATED-IMPLIB-NEXT: Export name: _stdcall@8
 # DECORATED-IMPLIB-NEXT: __imp__stdcall@8
 # DECORATED-IMPLIB-NEXT: _stdcall@8
 # DECORATED-IMPLIB: Name type: name
+# DECORATED-IMPLIB-NEXT: Export name: vectorcall@@8
 # DECORATED-IMPLIB-NEXT: __imp_vectorcall@@8
 # DECORATED-IMPLIB-NEXT: vectorcall@@8
 
@@ -51,14 +58,17 @@
 # RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix 
DECORATED-MINGW-EXPORTS %s
 
 # DECORATED-MINGW-IMPLIB: Name type: name
+# DECORATED-MINGW-IMPLIB-NEXT: Export name: @fastcall@8
 # DECORATED-MINGW-IMPLIB-NEXT: __imp_@fastcall@8
 # DECORATED-MINGW-IMPLIB-NEXT: fastcall@8
 # DECORATED-MINGW-IMPLIB: Name type: noprefix
+# DECORATED-MINGW-IMPLIB-NEXT: Export name: stdcall@8
 # DECORATED-MINGW-IMPLIB-NEXT: __imp__stdcall@8
 # DECORATED-MINGW-IMPLIB-NEXT: _stdcall@8
 # GNU tools don't support vectorcall, but this test is just to track that
 # lld's behaviour remains consistent over time.
 # DECORATED-MINGW-IMPLIB: Name type: name
+# DECORATED-MINGW-IMPLIB-NEXT: Export name: vectorcall@@8
 # DECORATED-MINGW-IMPLIB-NEXT: __imp_vectorcall@@8
 # DECORATED-MINGW-IMPLIB-NEXT: vectorcall@@8
 
@@ -75,14 +85,17 @@
 # RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix 
MINGW-KILL-AT-EXPORTS %s
 
 # MINGW-KILL-AT-IMPLIB: Name type: noprefix
+# MINGW-KILL-AT-IMPLIB: Export name: fastcall
 # MINGW-KILL-AT-IMPLIB: __imp__fastcall
 # MINGW-KILL-AT-IMPLIB-NEXT: _fastcall
 # MINGW-KILL-AT-IMPLIB: Name type: noprefix
+# MINGW-KILL-AT-IMPLIB-NEXT: Export name: stdcall
 # MINGW-KILL-AT-IMPLIB-NEXT: __imp__stdcall
 # MINGW-KILL-AT-IMPLIB-NEXT: _stdcall
 # GNU tools don't support vectorcall, but this test is just to track that
 # lld's behaviour remains consistent over time.
 # MINGW-KILL-AT-IMPLIB: Name type: noprefix
+# MINGW-KILL-AT-IMPLIB-NEXT: Export name: vectorcall
 # MINGW-KILL-AT-IMPLIB-NEXT: __imp__vectorcall
 # MINGW-K

[llvm-branch-commits] [llvm] 79bc8b3 - [llvm-lib][Object] Add support for EC importlib symbols. (#81059)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

Author: Jacek Caban
Date: 2024-03-16T15:55:54-07:00
New Revision: 79bc8b32c6ed4fc6e002d6426c04d4de874b07cc

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

LOG: [llvm-lib][Object] Add support for EC importlib symbols. (#81059)

ARM64EC import libraries expose two additional symbols: mangled thunk
symbol (like `#func`) and auxiliary import symbol (like`__imp_aux_func`).
The main functional change with this patch is that those symbols are
properly added to static library ECSYMBOLS.

Added: 


Modified: 
llvm/include/llvm/Object/COFF.h
llvm/include/llvm/Object/COFFImportFile.h
llvm/lib/Object/COFFImportFile.cpp
llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
llvm/lib/Target/AArch64/Utils/AArch64BaseInfo.h
llvm/test/tools/llvm-lib/arm64ec-implib.test

Removed: 




diff  --git a/llvm/include/llvm/Object/COFF.h b/llvm/include/llvm/Object/COFF.h
index a548b2c15c5fdc..2a5c3d8913b15c 100644
--- a/llvm/include/llvm/Object/COFF.h
+++ b/llvm/include/llvm/Object/COFF.h
@@ -1362,6 +1362,47 @@ class SectionStrippedError
   SectionStrippedError() { setErrorCode(object_error::section_stripped); }
 };
 
+inline std::optional
+getArm64ECMangledFunctionName(StringRef Name) {
+  bool IsCppFn = Name[0] == '?';
+  if (IsCppFn && Name.find("$$h") != std::string::npos)
+return std::nullopt;
+  if (!IsCppFn && Name[0] == '#')
+return std::nullopt;
+
+  StringRef Prefix = "$$h";
+  size_t InsertIdx = 0;
+  if (IsCppFn) {
+InsertIdx = Name.find("@@");
+size_t ThreeAtSignsIdx = Name.find("@@@");
+if (InsertIdx != std::string::npos && InsertIdx != ThreeAtSignsIdx) {
+  InsertIdx += 2;
+} else {
+  InsertIdx = Name.find("@");
+  if (InsertIdx != std::string::npos)
+InsertIdx++;
+}
+  } else {
+Prefix = "#";
+  }
+
+  return std::optional(
+  (Name.substr(0, InsertIdx) + Prefix + Name.substr(InsertIdx)).str());
+}
+
+inline std::optional
+getArm64ECDemangledFunctionName(StringRef Name) {
+  if (Name[0] == '#')
+return std::string(Name.substr(1));
+  if (Name[0] != '?')
+return std::nullopt;
+
+  std::pair Pair = Name.split("$$h");
+  if (Pair.second.empty())
+return std::nullopt;
+  return (Pair.first + Pair.second).str();
+}
+
 } // end namespace object
 
 } // end namespace llvm

diff  --git a/llvm/include/llvm/Object/COFFImportFile.h 
b/llvm/include/llvm/Object/COFFImportFile.h
index 7c5846e9c044e3..46a982ddb7eee6 100644
--- a/llvm/include/llvm/Object/COFFImportFile.h
+++ b/llvm/include/llvm/Object/COFFImportFile.h
@@ -27,6 +27,9 @@ namespace llvm {
 namespace object {
 
 class COFFImportFile : public SymbolicFile {
+private:
+  enum SymbolIndex { ImpSymbol, ThunkSymbol, ECAuxSymbol, ECThunkSymbol };
+
 public:
   COFFImportFile(MemoryBufferRef Source)
   : SymbolicFile(ID_COFFImportFile, Source) {}
@@ -36,9 +39,23 @@ class COFFImportFile : public SymbolicFile {
   void moveSymbolNext(DataRefImpl &Symb) const override { ++Symb.p; }
 
   Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override {
-if (Symb.p == 0)
+switch (Symb.p) {
+case ImpSymbol:
   OS << "__imp_";
-OS << StringRef(Data.getBufferStart() + sizeof(coff_import_header));
+  break;
+case ECAuxSymbol:
+  OS << "__imp_aux_";
+  break;
+}
+const char *Name = Data.getBufferStart() + sizeof(coff_import_header);
+if (Symb.p != ECThunkSymbol && COFF::isArm64EC(getMachine())) {
+  if (std::optional DemangledName =
+  getArm64ECDemangledFunctionName(Name)) {
+OS << StringRef(*DemangledName);
+return Error::success();
+  }
+}
+OS << StringRef(Name);
 return Error::success();
   }
 
@@ -52,7 +69,12 @@ class COFFImportFile : public SymbolicFile {
 
   basic_symbol_iterator symbol_end() const override {
 DataRefImpl Symb;
-Symb.p = isData() ? 1 : 2;
+if (isData())
+  Symb.p = ImpSymbol + 1;
+else if (COFF::isArm64EC(getMachine()))
+  Symb.p = ECThunkSymbol + 1;
+else
+  Symb.p = ThunkSymbol + 1;
 return BasicSymbolRef(Symb, this);
   }
 

diff  --git a/llvm/lib/Object/COFFImportFile.cpp 
b/llvm/lib/Object/COFFImportFile.cpp
index 51e6274dcf235c..a3e5e78952c16a 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -684,6 +684,21 @@ Error writeImportLibrary(StringRef ImportName, StringRef 
Path,
   NameType = getNameType(SymbolName, E.Name, Machine, MinGW);
 }
 
+// On ARM64EC, use EXPORTAS to import demangled name for mangled symbols.
+if (ImportType == IMPORT_CODE && isArm64EC(Machine)) {
+  if (std::optional MangledName =
+  getArm64ECMangledFunctionName(Name)) {
+if (ExportName.empty(

[llvm-branch-commits] [llvm] 207ecd6 - [Arm64EC] Copy import descriptors to the EC Map (#84834)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

Author: Daniel Paoliello
Date: 2024-03-16T15:55:54-07:00
New Revision: 207ecd684cc6731266e12d8d2df0e3d1d9e1ff8d

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

LOG: [Arm64EC] Copy import descriptors to the EC Map (#84834)

As noted in , MSVC
places import descriptors in both the EC and regular map - that PR moved
the descriptors to ONLY the regular map, however this causes linking
errors when linking as Arm64EC:

```
bcryptprimitives.lib(bcryptprimitives.dll) : error LNK2001: unresolved external 
symbol __IMPORT_DESCRIPTOR_bcryptprimitives (EC Symbol)
```

This change copies import descriptors from the regular map to the EC
map, which fixes this linking error.

Added: 


Modified: 
llvm/include/llvm/Object/COFFImportFile.h
llvm/lib/Object/ArchiveWriter.cpp
llvm/lib/Object/COFFImportFile.cpp
llvm/test/tools/llvm-lib/arm64ec-implib.test

Removed: 




diff  --git a/llvm/include/llvm/Object/COFFImportFile.h 
b/llvm/include/llvm/Object/COFFImportFile.h
index 46a982ddb7eee6..c79ff18d3616ed 100644
--- a/llvm/include/llvm/Object/COFFImportFile.h
+++ b/llvm/include/llvm/Object/COFFImportFile.h
@@ -26,6 +26,12 @@
 namespace llvm {
 namespace object {
 
+constexpr std::string_view ImportDescriptorPrefix = "__IMPORT_DESCRIPTOR_";
+constexpr std::string_view NullImportDescriptorSymbolName =
+"__NULL_IMPORT_DESCRIPTOR";
+constexpr std::string_view NullThunkDataPrefix = "\x7f";
+constexpr std::string_view NullThunkDataSuffix = "_NULL_THUNK_DATA";
+
 class COFFImportFile : public SymbolicFile {
 private:
   enum SymbolIndex { ImpSymbol, ThunkSymbol, ECAuxSymbol, ECThunkSymbol };

diff  --git a/llvm/lib/Object/ArchiveWriter.cpp 
b/llvm/lib/Object/ArchiveWriter.cpp
index 155926a8c5949d..1a7ed2db543964 100644
--- a/llvm/lib/Object/ArchiveWriter.cpp
+++ b/llvm/lib/Object/ArchiveWriter.cpp
@@ -677,6 +677,13 @@ static bool isECObject(object::SymbolicFile &Obj) {
   return false;
 }
 
+bool isImportDescriptor(StringRef Name) {
+  return Name.starts_with(ImportDescriptorPrefix) ||
+ Name == StringRef{NullImportDescriptorSymbolName} ||
+ (Name.starts_with(NullThunkDataPrefix) &&
+  Name.ends_with(NullThunkDataSuffix));
+}
+
 static Expected> getSymbols(SymbolicFile *Obj,
   uint16_t Index,
   raw_ostream &SymNames,
@@ -704,6 +711,10 @@ static Expected> 
getSymbols(SymbolicFile *Obj,
   if (Map == &SymMap->Map) {
 Ret.push_back(SymNames.tell());
 SymNames << Name << '\0';
+// If EC is enabled, then the import descriptors are NOT put into EC
+// objects so we need to copy them to the EC map manually.
+if (SymMap->UseECMap && isImportDescriptor(Name))
+  SymMap->ECMap[Name] = Index;
   }
 } else {
   Ret.push_back(SymNames.tell());

diff  --git a/llvm/lib/Object/COFFImportFile.cpp 
b/llvm/lib/Object/COFFImportFile.cpp
index a3e5e78952c16a..99a42d8c4e06a5 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -108,7 +108,7 @@ template  static void append(std::vector 
&B, const T &Data) {
 }
 
 static void writeStringTable(std::vector &B,
- ArrayRef Strings) {
+ ArrayRef Strings) {
   // The COFF string table consists of a 4-byte value which is the size of the
   // table, including the length field itself.  This value is followed by the
   // string content itself, which is an array of null-terminated C-style
@@ -171,9 +171,6 @@ static Expected replace(StringRef S, StringRef 
From,
   return (Twine(S.substr(0, Pos)) + To + S.substr(Pos + From.size())).str();
 }
 
-static const std::string NullImportDescriptorSymbolName =
-"__NULL_IMPORT_DESCRIPTOR";
-
 namespace {
 // This class constructs various small object files necessary to support 
linking
 // symbols imported from a DLL.  The contents are pretty strictly defined and
@@ -192,8 +189,9 @@ class ObjectFactory {
 public:
   ObjectFactory(StringRef S, MachineTypes M)
   : NativeMachine(M), ImportName(S), Library(llvm::sys::path::stem(S)),
-ImportDescriptorSymbolName(("__IMPORT_DESCRIPTOR_" + Library).str()),
-NullThunkSymbolName(("\x7f" + Library + "_NULL_THUNK_DATA").str()) {}
+ImportDescriptorSymbolName((ImportDescriptorPrefix + Library).str()),
+NullThunkSymbolName(
+(NullThunkDataPrefix + Library + NullThunkDataSuffix).str()) {}
 
   // Creates an Import Descriptor.  This is a small object file which contains 
a
   // reference to the terminators and contains the library name (entry) for the

diff  --git a/llvm/test/tools/llvm-lib/arm64ec-implib.test 
b/llvm/tes

[llvm-branch-commits] [llvm] 2f640ad - Remove support for EXPORTAS in def files to maintain ABI compatibility for COFFShortExport

2024-03-16 Thread Tom Stellard via llvm-branch-commits

Author: Daniel Paoliello
Date: 2024-03-16T15:55:54-07:00
New Revision: 2f640ad26d176a70c5e7a77c92a899e525e366d9

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

LOG: Remove support for EXPORTAS in def files to maintain ABI compatibility for 
COFFShortExport

Added: 


Modified: 
llvm/include/llvm/Object/COFFImportFile.h
llvm/lib/Object/COFFImportFile.cpp
llvm/lib/Object/COFFModuleDefinition.cpp
llvm/test/tools/llvm-lib/arm64ec-implib.test

Removed: 
llvm/test/tools/llvm-lib/exportas.test



diff  --git a/llvm/include/llvm/Object/COFFImportFile.h 
b/llvm/include/llvm/Object/COFFImportFile.h
index c79ff18d3616ed..8358197309f000 100644
--- a/llvm/include/llvm/Object/COFFImportFile.h
+++ b/llvm/include/llvm/Object/COFFImportFile.h
@@ -120,10 +120,6 @@ struct COFFShortExport {
   /// file, this is "baz" in "EXPORTS\nfoo = bar == baz".
   std::string AliasTarget;
 
-  /// Specifies EXPORTAS name. In a .def file, this is "bar" in
-  /// "EXPORTS\nfoo EXPORTAS bar".
-  std::string ExportAs;
-
   uint16_t Ordinal = 0;
   bool Noname = false;
   bool Data = false;

diff  --git a/llvm/lib/Object/COFFImportFile.cpp 
b/llvm/lib/Object/COFFImportFile.cpp
index 99a42d8c4e06a5..d3b5cf2d9f7b52 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -675,9 +675,6 @@ Error writeImportLibrary(StringRef ImportName, StringRef 
Path,
 std::string ExportName;
 if (E.Noname) {
   NameType = IMPORT_ORDINAL;
-} else if (!E.ExportAs.empty()) {
-  NameType = IMPORT_NAME_EXPORTAS;
-  ExportName = E.ExportAs;
 } else {
   NameType = getNameType(SymbolName, E.Name, Machine, MinGW);
 }

diff  --git a/llvm/lib/Object/COFFModuleDefinition.cpp 
b/llvm/lib/Object/COFFModuleDefinition.cpp
index f60dd49793685f..648f01f823d007 100644
--- a/llvm/lib/Object/COFFModuleDefinition.cpp
+++ b/llvm/lib/Object/COFFModuleDefinition.cpp
@@ -39,7 +39,6 @@ enum Kind {
   KwConstant,
   KwData,
   KwExports,
-  KwExportAs,
   KwHeapsize,
   KwLibrary,
   KwName,
@@ -119,7 +118,6 @@ class Lexer {
.Case("CONSTANT", KwConstant)
.Case("DATA", KwData)
.Case("EXPORTS", KwExports)
-   .Case("EXPORTAS", KwExportAs)
.Case("HEAPSIZE", KwHeapsize)
.Case("LIBRARY", KwLibrary)
.Case("NAME", KwName)
@@ -288,16 +286,7 @@ class Parser {
   E.AliasTarget = std::string("_").append(E.AliasTarget);
 continue;
   }
-  // EXPORTAS must be at the end of export definition
-  if (Tok.K == KwExportAs) {
-read();
-if (Tok.K == Eof)
-  return createError(
-  "unexpected end of file, EXPORTAS identifier expected");
-E.ExportAs = std::string(Tok.Value);
-  } else {
-unget();
-  }
+  unget();
   Info.Exports.push_back(E);
   return Error::success();
 }

diff  --git a/llvm/test/tools/llvm-lib/arm64ec-implib.test 
b/llvm/test/tools/llvm-lib/arm64ec-implib.test
index 52ac486da9e292..ebc1b166ee4ea6 100644
--- a/llvm/test/tools/llvm-lib/arm64ec-implib.test
+++ b/llvm/test/tools/llvm-lib/arm64ec-implib.test
@@ -100,89 +100,6 @@ Creating a new lib containing the existing lib:
 RUN: llvm-lib -machine:arm64ec test.lib -out:test2.lib
 RUN: llvm-nm --print-armap test2.lib | FileCheck -check-prefix=ARMAP %s
 
-
-RUN: llvm-lib -machine:arm64ec -def:exportas.def -out:exportas.lib
-RUN: llvm-nm --print-armap exportas.lib | FileCheck -check-prefix=EXPAS-ARMAP 
%s
-RUN: llvm-readobj exportas.lib | FileCheck -check-prefix=EXPAS-READOBJ %s
-
-EXPAS-ARMAP:  Archive EC map
-EXPAS-ARMAP-NEXT: #func1 in test.dll
-EXPAS-ARMAP-NEXT: #func2 in test.dll
-EXPAS-ARMAP-NEXT: #func3 in test.dll
-EXPAS-ARMAP-NEXT: #func4 in test.dll
-EXPAS-ARMAP-NEXT: __IMPORT_DESCRIPTOR_test in test.dll
-EXPAS-ARMAP-NEXT: __NULL_IMPORT_DESCRIPTOR in test.dll
-EXPAS-ARMAP-NEXT: __imp_aux_func1 in test.dll
-EXPAS-ARMAP-NEXT: __imp_aux_func2 in test.dll
-EXPAS-ARMAP-NEXT: __imp_aux_func3 in test.dll
-EXPAS-ARMAP-NEXT: __imp_aux_func4 in test.dll
-EXPAS-ARMAP-NEXT: __imp_data1 in test.dll
-EXPAS-ARMAP-NEXT: __imp_data2 in test.dll
-EXPAS-ARMAP-NEXT: __imp_func1 in test.dll
-EXPAS-ARMAP-NEXT: __imp_func2 in test.dll
-EXPAS-ARMAP-NEXT: __imp_func3 in test.dll
-EXPAS-ARMAP-NEXT: __imp_func4 in test.dll
-EXPAS-ARMAP-NEXT: func1 in test.dll
-EXPAS-ARMAP-NEXT: func2 in test.dll
-EXPAS-ARMAP-NEXT: func3 in test.dll
-EXPAS-ARMAP-NEXT: func4 in test.dll
-EXPAS-ARMAP-NEXT: test_NULL_THUNK_DATA in test.dll
-
-EXPAS-READOBJ:  File: test.dll
-EXPAS-READOBJ-NEXT: Format: COFF-import-file-ARM64EC
-EXPAS-READOBJ-NEXT: Type: code
-EXPAS-READOBJ-NEXT: Name type: export as
-EXPAS-READOBJ-NEXT: Export nam

[llvm-branch-commits] [llvm] 76e1800 - [llvm-lib][llvm-dlltool][Object] Add support for EXPORTAS name types. (#78772)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

Author: Jacek Caban
Date: 2024-03-16T15:55:54-07:00
New Revision: 76e1800f356513c491ac3bcebdf952842e7b5a3f

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

LOG: [llvm-lib][llvm-dlltool][Object] Add support for EXPORTAS name types. 
(#78772)

EXPORTAS is a new name type in import libraries. It's used by default on 
ARM64EC,
but it's allowed on other platforms as well.

Added: 
llvm/test/tools/llvm-lib/exportas.test

Modified: 
llvm/include/llvm/BinaryFormat/COFF.h
llvm/include/llvm/Object/COFFImportFile.h
llvm/lib/Object/COFFImportFile.cpp
llvm/lib/Object/COFFModuleDefinition.cpp
llvm/tools/llvm-readobj/COFFImportDumper.cpp

Removed: 




diff  --git a/llvm/include/llvm/BinaryFormat/COFF.h 
b/llvm/include/llvm/BinaryFormat/COFF.h
index 522ee37da6e830..72461d0d9c316a 100644
--- a/llvm/include/llvm/BinaryFormat/COFF.h
+++ b/llvm/include/llvm/BinaryFormat/COFF.h
@@ -716,7 +716,10 @@ enum ImportNameType : unsigned {
   IMPORT_NAME_NOPREFIX = 2,
   /// The import name is the public symbol name, but skipping the leading ?,
   /// @, or optionally _, and truncating at the first @.
-  IMPORT_NAME_UNDECORATE = 3
+  IMPORT_NAME_UNDECORATE = 3,
+  /// The import name is specified as a separate string in the import library
+  /// object file.
+  IMPORT_NAME_EXPORTAS = 4
 };
 
 enum class GuardFlags : uint32_t {

diff  --git a/llvm/include/llvm/Object/COFFImportFile.h 
b/llvm/include/llvm/Object/COFFImportFile.h
index 45a4a795fd1903..7c5846e9c044e3 100644
--- a/llvm/include/llvm/Object/COFFImportFile.h
+++ b/llvm/include/llvm/Object/COFFImportFile.h
@@ -92,6 +92,10 @@ struct COFFShortExport {
   /// file, this is "baz" in "EXPORTS\nfoo = bar == baz".
   std::string AliasTarget;
 
+  /// Specifies EXPORTAS name. In a .def file, this is "bar" in
+  /// "EXPORTS\nfoo EXPORTAS bar".
+  std::string ExportAs;
+
   uint16_t Ordinal = 0;
   bool Noname = false;
   bool Data = false;

diff  --git a/llvm/lib/Object/COFFImportFile.cpp 
b/llvm/lib/Object/COFFImportFile.cpp
index d7d26f4f4180c3..51e6274dcf235c 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -71,6 +71,12 @@ StringRef COFFImportFile::getExportName() const {
 name = ltrim1(name, "?@_");
 name = name.substr(0, name.find('@'));
 break;
+  case IMPORT_NAME_EXPORTAS: {
+// Skip DLL name
+name = Data.getBuffer().substr(sizeof(*hdr) + name.size() + 1);
+name = name.split('\0').second.split('\0').first;
+break;
+  }
   default:
 break;
   }
@@ -209,6 +215,7 @@ class ObjectFactory {
   // Library Format.
   NewArchiveMember createShortImport(StringRef Sym, uint16_t Ordinal,
  ImportType Type, ImportNameType NameType,
+ StringRef ExportName,
  MachineTypes Machine);
 
   // Create a weak external file which is described in PE/COFF Aux Format 3.
@@ -500,12 +507,13 @@ NewArchiveMember 
ObjectFactory::createNullThunk(std::vector &Buffer) {
   return {MemoryBufferRef{F, ImportName}};
 }
 
-NewArchiveMember ObjectFactory::createShortImport(StringRef Sym,
-  uint16_t Ordinal,
-  ImportType ImportType,
-  ImportNameType NameType,
-  MachineTypes Machine) {
+NewArchiveMember
+ObjectFactory::createShortImport(StringRef Sym, uint16_t Ordinal,
+ ImportType ImportType, ImportNameType 
NameType,
+ StringRef ExportName, MachineTypes Machine) {
   size_t ImpSize = ImportName.size() + Sym.size() + 2; // +2 for NULs
+  if (!ExportName.empty())
+ImpSize += ExportName.size() + 1;
   size_t Size = sizeof(coff_import_header) + ImpSize;
   char *Buf = Alloc.Allocate(Size);
   memset(Buf, 0, Size);
@@ -525,6 +533,10 @@ NewArchiveMember 
ObjectFactory::createShortImport(StringRef Sym,
   memcpy(P, Sym.data(), Sym.size());
   P += Sym.size() + 1;
   memcpy(P, ImportName.data(), ImportName.size());
+  if (!ExportName.empty()) {
+P += ImportName.size() + 1;
+memcpy(P, ExportName.data(), ExportName.size());
+  }
 
   return {MemoryBufferRef(StringRef(Buf, Size), ImportName)};
 }
@@ -641,27 +653,39 @@ Error writeImportLibrary(StringRef ImportName, StringRef 
Path,
   ImportType = IMPORT_CONST;
 
 StringRef SymbolName = E.SymbolName.empty() ? E.Name : E.SymbolName;
-ImportNameType NameType = E.Noname
-  ? IMPORT_ORDINAL
-  : getNameType(SymbolName, E.Name,
-Machine, MinGW);
-Expected Name = E.

[llvm-branch-commits] [openmp] Revert "release/18.x: [openmp] __kmp_x86_cpuid fix for i386/PIC builds. (#84626)" (PR #85527)

2024-03-16 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/85527

>From fc108ac9e491ff488297b78a05629239ee997f40 Mon Sep 17 00:00:00 2001
From: David CARLIER 
Date: Sat, 16 Mar 2024 13:41:33 +
Subject: [PATCH] =?UTF-8?q?Revert=20"release/18.x:=20[openmp]=20=5F=5Fkmp?=
 =?UTF-8?q?=5Fx86=5Fcpuid=20fix=20for=20i386/PIC=20builds.=20(#846?=
 =?UTF-8?q?=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 9b3edb592debc00a5c3fbf7a71f63e07d6af44be.
---
 openmp/runtime/src/kmp.h | 10 --
 1 file changed, 10 deletions(-)

diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index d51ec886cfe556..e3a1e20731bbe0 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -1403,19 +1403,9 @@ extern void __kmp_query_cpuid(kmp_cpuinfo_t *p);
 // subleaf is only needed for cache and topology discovery and can be set to
 // zero in most cases
 static inline void __kmp_x86_cpuid(int leaf, int subleaf, struct kmp_cpuid *p) 
{
-#if KMP_ARCH_X86 && (defined(__pic__) || defined(__PIC__))
-  // on i386 arch, the ebx reg. is used by pic, thus we need to preserve from
-  // being trashed beforehand
-  __asm__ __volatile__("mov %%ebx, %%edi\n"
-   "cpuid\n"
-   "xchg %%edi, %%ebx\n"
-   : "=a"(p->eax), "=b"(p->ebx), "=c"(p->ecx), "=d"(p->edx)
-   : "a"(leaf), "c"(subleaf));
-#else
   __asm__ __volatile__("cpuid"
: "=a"(p->eax), "=b"(p->ebx), "=c"(p->ecx), "=d"(p->edx)
: "a"(leaf), "c"(subleaf));
-#endif
 }
 // Load p into FPU control word
 static inline void __kmp_load_x87_fpu_control_word(const kmp_int16 *p) {

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


[llvm-branch-commits] [lld] edbe7fa - [lld][LoongArch] Fix handleUleb128

2024-03-16 Thread via llvm-branch-commits

Author: Weining Lu
Date: 2024-03-16T18:28:00-07:00
New Revision: edbe7fa5fef93bb747cb58a589dc25901793774b

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

LOG: [lld][LoongArch] Fix handleUleb128

(cherry picked from commit a41bcb3930534ef1525b4fc30e53e818b39e2b60)

Added: 


Modified: 
lld/ELF/Arch/LoongArch.cpp

Removed: 




diff  --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index 8a6f6db68f2909..464f5dfb320ccc 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -159,8 +159,9 @@ static bool isJirl(uint32_t insn) {
 static void handleUleb128(uint8_t *loc, uint64_t val) {
   const uint32_t maxcount = 1 + 64 / 7;
   uint32_t count;
-  uint64_t orig = decodeULEB128(loc, &count);
-  if (count > maxcount)
+  const char *error = nullptr;
+  uint64_t orig = decodeULEB128(loc, &count, nullptr, &error);
+  if (count > maxcount || (count == maxcount && error))
 errorOrWarn(getErrorLocation(loc) + "extra space for uleb128");
   uint64_t mask = count < maxcount ? (1ULL << 7 * count) - 1 : -1ULL;
   encodeULEB128((orig + val) & mask, loc, count);



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


[llvm-branch-commits] [lld] bf2eb3b - Merge branch 'release/18.x' into revert-85053-omp_386_fix_backoirt

2024-03-16 Thread via llvm-branch-commits

Author: Tom Stellard
Date: 2024-03-16T18:31:06-07:00
New Revision: bf2eb3b190172be6ff60205231fd7c8965a25ce5

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

LOG: Merge branch 'release/18.x' into revert-85053-omp_386_fix_backoirt

Added: 


Modified: 
clang-tools-extra/clangd/HeuristicResolver.cpp
clang-tools-extra/clangd/HeuristicResolver.h
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
lld/ELF/Arch/LoongArch.cpp
lld/test/COFF/def-export-cpp.s
lld/test/COFF/def-export-stdcall.s
lld/test/COFF/dllexport.s
lld/test/ELF/loongarch-reloc-leb128.s
llvm/include/llvm/BinaryFormat/COFF.h
llvm/include/llvm/Object/COFF.h
llvm/include/llvm/Object/COFFImportFile.h
llvm/lib/Object/ArchiveWriter.cpp
llvm/lib/Object/COFFImportFile.cpp
llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
llvm/lib/Target/AArch64/Utils/AArch64BaseInfo.h
llvm/test/tools/llvm-dlltool/coff-decorated.def
llvm/test/tools/llvm-dlltool/coff-exports.def
llvm/test/tools/llvm-dlltool/coff-noname.def
llvm/test/tools/llvm-dlltool/no-leading-underscore.def
llvm/test/tools/llvm-lib/arm64ec-implib.test
llvm/test/tools/llvm-readobj/COFF/file-headers.test
llvm/tools/llvm-readobj/COFFImportDumper.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/HeuristicResolver.cpp 
b/clang-tools-extra/clangd/HeuristicResolver.cpp
index 3c147b6b582bf0..26d54200eeffd2 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.cpp
+++ b/clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -16,6 +16,80 @@
 namespace clang {
 namespace clangd {
 
+namespace {
+
+// Helper class for implementing HeuristicResolver.
+// Unlike HeuristicResolver which is a long-lived class,
+// a new instance of this class is created for every external
+// call into a HeuristicResolver operation. That allows this
+// class to store state that's local to such a top-level call,
+// particularly "recursion protection sets" that keep track of
+// nodes that have already been seen to avoid infinite recursion.
+class HeuristicResolverImpl {
+public:
+  HeuristicResolverImpl(ASTContext &Ctx) : Ctx(Ctx) {}
+
+  // These functions match the public interface of HeuristicResolver
+  // (but aren't const since they may modify the recursion protection sets).
+  std::vector
+  resolveMemberExpr(const CXXDependentScopeMemberExpr *ME);
+  std::vector
+  resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE);
+  std::vector resolveTypeOfCallExpr(const CallExpr *CE);
+  std::vector resolveCalleeOfCallExpr(const CallExpr *CE);
+  std::vector
+  resolveUsingValueDecl(const UnresolvedUsingValueDecl *UUVD);
+  std::vector
+  resolveDependentNameType(const DependentNameType *DNT);
+  std::vector resolveTemplateSpecializationType(
+  const DependentTemplateSpecializationType *DTST);
+  const Type *resolveNestedNameSpecifierToType(const NestedNameSpecifier *NNS);
+  const Type *getPointeeType(const Type *T);
+
+private:
+  ASTContext &Ctx;
+
+  // Recursion protection sets
+  llvm::SmallSet SeenDependentNameTypes;
+
+  // Given a tag-decl type and a member name, heuristically resolve the
+  // name to one or more declarations.
+  // The current heuristic is simply to look up the name in the primary
+  // template. This is a heuristic because the template could potentially
+  // have specializations that declare 
diff erent members.
+  // Multiple declarations could be returned if the name is overloaded
+  // (e.g. an overloaded method in the primary template).
+  // This heuristic will give the desired answer in many cases, e.g.
+  // for a call to vector::size().
+  std::vector
+  resolveDependentMember(const Type *T, DeclarationName Name,
+ llvm::function_ref Filter);
+
+  // Try to heuristically resolve the type of a possibly-dependent expression
+  // `E`.
+  const Type *resolveExprToType(const Expr *E);
+  std::vector resolveExprToDecls(const Expr *E);
+
+  // Helper function for HeuristicResolver::resolveDependentMember()
+  // which takes a possibly-dependent type `T` and heuristically
+  // resolves it to a CXXRecordDecl in which we can try name lookup.
+  CXXRecordDecl *resolveTypeToRecordDecl(const Type *T);
+
+  // This is a reimplementation of CXXRecordDecl::lookupDependentName()
+  // so that the implementation can call into other HeuristicResolver helpers.
+  // FIXME: Once HeuristicResolver is upstreamed to the clang libraries
+  // (https://github.com/clangd/clangd/discussions/1662),
+  // CXXRecordDecl::lookupDepenedentName() can be removed, and its call sites
+  // can be modified to benefit from the more comprehensive heuristics offered
+  // by Heu

[llvm-branch-commits] [lld] b95ea2e - [lld][test] Fix sanitizer buildbot failure

2024-03-16 Thread via llvm-branch-commits

Author: Weining Lu
Date: 2024-03-16T18:28:00-07:00
New Revision: b95ea2e51bdfe20c9db6a0675ab068fa59a0b9fe

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

LOG: [lld][test] Fix sanitizer buildbot failure

Buildbot failure:
https://lab.llvm.org/buildbot/#/builders/5/builds/41530/steps/9/logs/stdio

(cherry picked from commit d9b435c24cc8148fd97b42f6bb1124e52307)

Added: 


Modified: 
lld/test/ELF/loongarch-reloc-leb128.s

Removed: 




diff  --git a/lld/test/ELF/loongarch-reloc-leb128.s 
b/lld/test/ELF/loongarch-reloc-leb128.s
index 9e6f221e62b639..2dd327d1564ebd 100644
--- a/lld/test/ELF/loongarch-reloc-leb128.s
+++ b/lld/test/ELF/loongarch-reloc-leb128.s
@@ -99,4 +99,4 @@ w2:
 .reloc ., R_LARCH_ADD_ULEB128, w2
 .reloc ., R_LARCH_SUB_ULEB128, w1
 .fill 10, 1, 0x80
-.byte 0
+.byte 1



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


[llvm-branch-commits] [llvm] release/18.x: [InstCombine] Drop UB-implying attrs/metadata after speculating an instruction (#85542) (PR #85562)

2024-03-16 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/85562

Backport 252d01952c087cf0d141f7f281cf60efeb98be41

Requested by: @dtcxzyw

>From 7fd9979eb9cf9d93d76e12e85aa1ad847794ebbc Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Sun, 17 Mar 2024 14:15:27 +0800
Subject: [PATCH] [InstCombine] Drop UB-implying attrs/metadata after
 speculating an instruction (#85542)

When speculating an instruction in `InstCombinerImpl::FoldOpIntoSelect`,
the call may result in undefined behavior. This patch drops all
UB-implying attrs/metadata to fix this.

Fixes #85536.

(cherry picked from commit 252d01952c087cf0d141f7f281cf60efeb98be41)
---
 .../InstCombine/InstructionCombining.cpp  |  1 +
 .../InstCombine/intrinsic-select.ll   | 40 +++
 2 files changed, 41 insertions(+)

diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp 
b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 5d207dcfd18dd4..6f0cf9d9c8f187 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1455,6 +1455,7 @@ static Value *foldOperationIntoSelectOperand(Instruction 
&I, SelectInst *SI,
  Value *NewOp, InstCombiner &IC) {
   Instruction *Clone = I.clone();
   Clone->replaceUsesOfWith(SI, NewOp);
+  Clone->dropUBImplyingAttrsAndMetadata();
   IC.InsertNewInstBefore(Clone, SI->getIterator());
   return Clone;
 }
diff --git a/llvm/test/Transforms/InstCombine/intrinsic-select.ll 
b/llvm/test/Transforms/InstCombine/intrinsic-select.ll
index a203b28bcb82a8..f37226bbd5b09c 100644
--- a/llvm/test/Transforms/InstCombine/intrinsic-select.ll
+++ b/llvm/test/Transforms/InstCombine/intrinsic-select.ll
@@ -240,3 +240,43 @@ define i32 @vec_to_scalar_select_vector(<2 x i1> %b) {
   %c = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %s)
   ret i32 %c
 }
+
+define i8 @test_drop_noundef(i1 %cond, i8 %val) {
+; CHECK-LABEL: @test_drop_noundef(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[TMP0:%.*]] = call i8 @llvm.smin.i8(i8 [[VAL:%.*]], i8 0)
+; CHECK-NEXT:[[RET:%.*]] = select i1 [[COND:%.*]], i8 -1, i8 [[TMP0]]
+; CHECK-NEXT:ret i8 [[RET]]
+;
+entry:
+  %sel = select i1 %cond, i8 -1, i8 %val
+  %ret = call noundef i8 @llvm.smin.i8(i8 %sel, i8 0)
+  ret i8 %ret
+}
+
+define i1 @pr85536(i32 %a) {
+; CHECK-LABEL: @pr85536(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[CMP1:%.*]] = icmp ult i32 [[A:%.*]], 31
+; CHECK-NEXT:[[SHL1:%.*]] = shl nsw i32 -1, [[A]]
+; CHECK-NEXT:[[ZEXT:%.*]] = zext i32 [[SHL1]] to i64
+; CHECK-NEXT:[[SHL2:%.*]] = shl i64 [[ZEXT]], 48
+; CHECK-NEXT:[[SHR:%.*]] = ashr exact i64 [[SHL2]], 48
+; CHECK-NEXT:[[TMP0:%.*]] = call i64 @llvm.smin.i64(i64 [[SHR]], i64 0)
+; CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 65535
+; CHECK-NEXT:[[RET1:%.*]] = icmp eq i64 [[TMP1]], 0
+; CHECK-NEXT:[[RET:%.*]] = select i1 [[CMP1]], i1 [[RET1]], i1 false
+; CHECK-NEXT:ret i1 [[RET]]
+;
+entry:
+  %cmp1 = icmp ugt i32 %a, 30
+  %shl1 = shl nsw i32 -1, %a
+  %zext = zext i32 %shl1 to i64
+  %shl2 = shl i64 %zext, 48
+  %shr = ashr exact i64 %shl2, 48
+  %sel = select i1 %cmp1, i64 -1, i64 %shr
+  %smin = call noundef i64 @llvm.smin.i64(i64 %sel, i64 0)
+  %masked = and i64 %smin, 65535
+  %ret = icmp eq i64 %masked, 0
+  ret i1 %ret
+}

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


[llvm-branch-commits] [llvm] release/18.x: [InstCombine] Drop UB-implying attrs/metadata after speculating an instruction (#85542) (PR #85562)

2024-03-16 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/85562
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [InstCombine] Drop UB-implying attrs/metadata after speculating an instruction (#85542) (PR #85562)

2024-03-16 Thread via llvm-branch-commits

llvmbot wrote:

@nikic What do you think about merging this PR to the release branch?

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


[llvm-branch-commits] [llvm] release/18.x: [InstCombine] Drop UB-implying attrs/metadata after speculating an instruction (#85542) (PR #85562)

2024-03-16 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: None (llvmbot)


Changes

Backport 252d01952c087cf0d141f7f281cf60efeb98be41

Requested by: @dtcxzyw

---
Full diff: https://github.com/llvm/llvm-project/pull/85562.diff


2 Files Affected:

- (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+1) 
- (modified) llvm/test/Transforms/InstCombine/intrinsic-select.ll (+40) 


``diff
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp 
b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 5d207dcfd18dd4..6f0cf9d9c8f187 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1455,6 +1455,7 @@ static Value *foldOperationIntoSelectOperand(Instruction 
&I, SelectInst *SI,
  Value *NewOp, InstCombiner &IC) {
   Instruction *Clone = I.clone();
   Clone->replaceUsesOfWith(SI, NewOp);
+  Clone->dropUBImplyingAttrsAndMetadata();
   IC.InsertNewInstBefore(Clone, SI->getIterator());
   return Clone;
 }
diff --git a/llvm/test/Transforms/InstCombine/intrinsic-select.ll 
b/llvm/test/Transforms/InstCombine/intrinsic-select.ll
index a203b28bcb82a8..f37226bbd5b09c 100644
--- a/llvm/test/Transforms/InstCombine/intrinsic-select.ll
+++ b/llvm/test/Transforms/InstCombine/intrinsic-select.ll
@@ -240,3 +240,43 @@ define i32 @vec_to_scalar_select_vector(<2 x i1> %b) {
   %c = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %s)
   ret i32 %c
 }
+
+define i8 @test_drop_noundef(i1 %cond, i8 %val) {
+; CHECK-LABEL: @test_drop_noundef(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[TMP0:%.*]] = call i8 @llvm.smin.i8(i8 [[VAL:%.*]], i8 0)
+; CHECK-NEXT:[[RET:%.*]] = select i1 [[COND:%.*]], i8 -1, i8 [[TMP0]]
+; CHECK-NEXT:ret i8 [[RET]]
+;
+entry:
+  %sel = select i1 %cond, i8 -1, i8 %val
+  %ret = call noundef i8 @llvm.smin.i8(i8 %sel, i8 0)
+  ret i8 %ret
+}
+
+define i1 @pr85536(i32 %a) {
+; CHECK-LABEL: @pr85536(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[CMP1:%.*]] = icmp ult i32 [[A:%.*]], 31
+; CHECK-NEXT:[[SHL1:%.*]] = shl nsw i32 -1, [[A]]
+; CHECK-NEXT:[[ZEXT:%.*]] = zext i32 [[SHL1]] to i64
+; CHECK-NEXT:[[SHL2:%.*]] = shl i64 [[ZEXT]], 48
+; CHECK-NEXT:[[SHR:%.*]] = ashr exact i64 [[SHL2]], 48
+; CHECK-NEXT:[[TMP0:%.*]] = call i64 @llvm.smin.i64(i64 [[SHR]], i64 0)
+; CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 65535
+; CHECK-NEXT:[[RET1:%.*]] = icmp eq i64 [[TMP1]], 0
+; CHECK-NEXT:[[RET:%.*]] = select i1 [[CMP1]], i1 [[RET1]], i1 false
+; CHECK-NEXT:ret i1 [[RET]]
+;
+entry:
+  %cmp1 = icmp ugt i32 %a, 30
+  %shl1 = shl nsw i32 -1, %a
+  %zext = zext i32 %shl1 to i64
+  %shl2 = shl i64 %zext, 48
+  %shr = ashr exact i64 %shl2, 48
+  %sel = select i1 %cmp1, i64 -1, i64 %shr
+  %smin = call noundef i64 @llvm.smin.i64(i64 %sel, i64 0)
+  %masked = and i64 %smin, 65535
+  %ret = icmp eq i64 %masked, 0
+  ret i1 %ret
+}

``




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