Skip to content

[AutoBump] Merge with a6bb8a70 (Jan 20) (5) #543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {

case CK_UncheckedDerivedToBase:
case CK_DerivedToBase: {
if (DiscardResult)
return this->discard(SubExpr);

if (!this->delegate(SubExpr))
return false;

Expand Down Expand Up @@ -282,6 +285,9 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
}

case CK_BaseToDerived: {
if (DiscardResult)
return this->discard(SubExpr);

if (!this->delegate(SubExpr))
return false;

Expand Down
15 changes: 15 additions & 0 deletions clang/test/AST/ByteCode/records.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1684,3 +1684,18 @@ namespace ExplicitThisInTemporary {
constexpr bool g(B b) { return &b == b.p; }
static_assert(g({}), "");
}

namespace IgnoredMemberExpr {
class A {
public:
int a;
};
class B : public A {
public:
constexpr int foo() {
a; // both-warning {{expression result unused}}
return 0;
}
};
static_assert(B{}.foo() == 0, "");
}
51 changes: 51 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ INTERCEPTOR(int, fpurge, FILE *stream) {
__rtsan_notify_intercepted_call("fpurge");
return REAL(fpurge)(stream);
}
#define RTSAN_MAYBE_INTERCEPT_FPURGE INTERCEPT_FUNCTION(fpurge)
#else
#define RTSAN_MAYBE_INTERCEPT_FPURGE
#endif

INTERCEPTOR(FILE *, fdopen, int fd, const char *mode) {
Expand Down Expand Up @@ -840,6 +843,17 @@ INTERCEPTOR(int, getsockname, int socket, struct sockaddr *sa,
#define RTSAN_MAYBE_INTERCEPT_GETSOCKNAME
#endif

#if SANITIZER_INTERCEPT_GETPEERNAME
INTERCEPTOR(int, getpeername, int socket, struct sockaddr *sa,
socklen_t *salen) {
__rtsan_notify_intercepted_call("getpeername");
return REAL(getpeername)(socket, sa, salen);
}
#define RTSAN_MAYBE_INTERCEPT_GETPEERNAME INTERCEPT_FUNCTION(getpeername)
#else
#define RTSAN_MAYBE_INTERCEPT_GETPEERNAME
#endif

INTERCEPTOR(int, bind, int socket, const struct sockaddr *address,
socklen_t address_len) {
__rtsan_notify_intercepted_call("bind");
Expand Down Expand Up @@ -879,6 +893,17 @@ INTERCEPTOR(ssize_t, sendmsg, int socket, const struct msghdr *message,
return REAL(sendmsg)(socket, message, flags);
}

#if SANITIZER_INTERCEPT_SENDMMSG
INTERCEPTOR(int, sendmmsg, int socket, struct mmsghdr *message,
unsigned int len, int flags) {
__rtsan_notify_intercepted_call("sendmmsg");
return REAL(sendmmsg)(socket, message, len, flags);
}
#define RTSAN_MAYBE_INTERCEPT_SENDMMSG INTERCEPT_FUNCTION(sendmmsg)
#else
#define RTSAN_MAYBE_INTERCEPT_SENDMMSG
#endif

INTERCEPTOR(ssize_t, sendto, int socket, const void *buffer, size_t length,
int flags, const struct sockaddr *dest_addr, socklen_t dest_len) {
__rtsan_notify_intercepted_call("sendto");
Expand All @@ -901,6 +926,17 @@ INTERCEPTOR(ssize_t, recvmsg, int socket, struct msghdr *message, int flags) {
return REAL(recvmsg)(socket, message, flags);
}

#if SANITIZER_INTERCEPT_RECVMMSG
INTERCEPTOR(int, recvmmsg, int socket, struct mmsghdr *message,
unsigned int len, int flags, struct timespec *timeout) {
__rtsan_notify_intercepted_call("recvmmsg");
return REAL(recvmmsg)(socket, message, len, flags, timeout);
}
#define RTSAN_MAYBE_INTERCEPT_RECVMMSG INTERCEPT_FUNCTION(recvmmsg)
#else
#define RTSAN_MAYBE_INTERCEPT_RECVMMSG
#endif

INTERCEPTOR(int, shutdown, int socket, int how) {
__rtsan_notify_intercepted_call("shutdown");
return REAL(shutdown)(socket, how);
Expand Down Expand Up @@ -1031,6 +1067,16 @@ INTERCEPTOR(int, pipe, int pipefd[2]) {
return REAL(pipe)(pipefd);
}

#if !SANITIZER_APPLE
INTERCEPTOR(int, pipe2, int pipefd[2], int flags) {
__rtsan_notify_intercepted_call("pipe2");
return REAL(pipe2)(pipefd, flags);
}
#define RTSAN_MAYBE_INTERCEPT_PIPE2 INTERCEPT_FUNCTION(pipe2)
#else
#define RTSAN_MAYBE_INTERCEPT_PIPE2
#endif

INTERCEPTOR(int, mkfifo, const char *pathname, mode_t mode) {
__rtsan_notify_intercepted_call("mkfifo");
return REAL(mkfifo)(pathname, mode);
Expand Down Expand Up @@ -1133,6 +1179,8 @@ void __rtsan::InitializeInterceptors() {
INTERCEPT_FUNCTION(puts);
INTERCEPT_FUNCTION(fputs);
INTERCEPT_FUNCTION(fflush);
RTSAN_MAYBE_INTERCEPT_FPURGE;
RTSAN_MAYBE_INTERCEPT_PIPE2;
INTERCEPT_FUNCTION(fdopen);
INTERCEPT_FUNCTION(freopen);
RTSAN_MAYBE_INTERCEPT_FOPENCOOKIE;
Expand Down Expand Up @@ -1194,13 +1242,16 @@ void __rtsan::InitializeInterceptors() {
INTERCEPT_FUNCTION(recv);
INTERCEPT_FUNCTION(recvfrom);
INTERCEPT_FUNCTION(recvmsg);
RTSAN_MAYBE_INTERCEPT_RECVMMSG;
INTERCEPT_FUNCTION(send);
INTERCEPT_FUNCTION(sendmsg);
RTSAN_MAYBE_INTERCEPT_SENDMMSG;
INTERCEPT_FUNCTION(sendto);
INTERCEPT_FUNCTION(shutdown);
INTERCEPT_FUNCTION(socket);
RTSAN_MAYBE_INTERCEPT_ACCEPT4;
RTSAN_MAYBE_INTERCEPT_GETSOCKNAME;
RTSAN_MAYBE_INTERCEPT_GETPEERNAME;

RTSAN_MAYBE_INTERCEPT_SELECT;
INTERCEPT_FUNCTION(pselect);
Expand Down
37 changes: 37 additions & 0 deletions compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,15 @@ TEST(TestRtsanInterceptors, SendmsgToASocketDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}

#if SANITIZER_INTERCEPT_SENDMMSG
TEST(TestRtsanInterceptors, SendmmsgOnASocketDiesWhenRealtime) {
mmsghdr msg{};
auto Func = [&]() { sendmmsg(0, &msg, 0, 0); };
ExpectRealtimeDeath(Func, "sendmmsg");
ExpectNonRealtimeSurvival(Func);
}
#endif

TEST(TestRtsanInterceptors, SendtoToASocketDiesWhenRealtime) {
sockaddr addr{};
socklen_t len{};
Expand Down Expand Up @@ -1147,6 +1156,15 @@ TEST(TestRtsanInterceptors, RecvmsgOnASocketDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}

#if SANITIZER_INTERCEPT_RECVMMSG
TEST(TestRtsanInterceptors, RecvmmsgOnASocketDiesWhenRealtime) {
mmsghdr msg{};
auto Func = [&]() { recvmmsg(0, &msg, 0, 0, nullptr); };
ExpectRealtimeDeath(Func, "recvmmsg");
ExpectNonRealtimeSurvival(Func);
}
#endif

TEST(TestRtsanInterceptors, ShutdownOnASocketDiesWhenRealtime) {
auto Func = [&]() { shutdown(0, 0); };
ExpectRealtimeDeath(Func, "shutdown");
Expand All @@ -1163,6 +1181,16 @@ TEST(TestRtsanInterceptors, GetsocknameOnASocketDiesWhenRealtime) {
}
#endif

#if SANITIZER_INTERCEPT_GETPEERNAME
TEST(TestRtsanInterceptors, GetpeernameOnASocketDiesWhenRealtime) {
sockaddr addr{};
socklen_t len{};
auto Func = [&]() { getpeername(0, &addr, &len); };
ExpectRealtimeDeath(Func, "getpeername");
ExpectNonRealtimeSurvival(Func);
}
#endif

/*
I/O Multiplexing
*/
Expand Down Expand Up @@ -1349,6 +1377,15 @@ TEST(TestRtsanInterceptors, PipeDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}

#if !SANITIZER_APPLE
TEST(TestRtsanInterceptors, Pipe2DiesWhenRealtime) {
int fds[2];
auto Func = [&fds]() { pipe2(fds, O_CLOEXEC); };
ExpectRealtimeDeath(Func, "pipe2");
ExpectNonRealtimeSurvival(Func);
}
#endif

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
TEST(TestRtsanInterceptors, SyscallDiesWhenRealtime) {
Expand Down
22 changes: 22 additions & 0 deletions llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,28 @@ bool LoongArchDAGToDAGISel::selectNonFIBaseAddr(SDValue Addr, SDValue &Base) {
return true;
}

bool LoongArchDAGToDAGISel::SelectAddrRegImm12(SDValue Addr, SDValue &Base,
SDValue &Offset) {
SDLoc DL(Addr);
MVT VT = Addr.getSimpleValueType();

// The address is the result of an ADD. Here we only consider reg+simm12.
if (CurDAG->isBaseWithConstantOffset(Addr)) {
int64_t Imm = cast<ConstantSDNode>(Addr.getOperand(1))->getSExtValue();
if (isInt<12>(Imm)) {
Base = Addr.getOperand(0);
Offset = CurDAG->getTargetConstant(SignExtend64<12>(Imm), DL, VT);
return true;
}
}

// Otherwise, we assume Addr as the base address and use constant 0 as the
// offset.
Base = Addr;
Offset = CurDAG->getTargetConstant(0, DL, VT);
return true;
}

bool LoongArchDAGToDAGISel::selectShiftMask(SDValue N, unsigned ShiftWidth,
SDValue &ShAmt) {
// Shift instructions on LoongArch only read the lower 5 or 6 bits of the
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class LoongArchDAGToDAGISel : public SelectionDAGISel {
bool SelectBaseAddr(SDValue Addr, SDValue &Base);
bool SelectAddrConstant(SDValue Addr, SDValue &Base, SDValue &Offset);
bool selectNonFIBaseAddr(SDValue Addr, SDValue &Base);
bool SelectAddrRegImm12(SDValue Addr, SDValue &Base, SDValue &Offset);

bool selectShiftMask(SDValue N, unsigned ShiftWidth, SDValue &ShAmt);
bool selectShiftMaskGRLen(SDValue N, SDValue &ShAmt) {
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom);
setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);

setOperationAction(ISD::PREFETCH, MVT::Other, Legal);

// Expand bitreverse.i16 with native-width bitrev and shift for now, before
// we get to know which of sll and revb.2h is faster.
setOperationAction(ISD::BITREVERSE, MVT::i8, Custom);
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ def HI16ForAddu16idAddiPair: SDNodeXForm<imm, [{
def BaseAddr : ComplexPattern<iPTR, 1, "SelectBaseAddr">;
def AddrConstant : ComplexPattern<iPTR, 2, "SelectAddrConstant">;
def NonFIBaseAddr : ComplexPattern<iPTR, 1, "selectNonFIBaseAddr">;
def AddrRegImm : ComplexPattern<iPTR, 2, "SelectAddrRegImm12">;

def fma_nsz : PatFrag<(ops node:$fj, node:$fk, node:$fa),
(fma node:$fj, node:$fk, node:$fa), [{
Expand Down Expand Up @@ -2011,6 +2012,14 @@ class PseudoMaskedAMMinMax
def PseudoMaskedAtomicLoadMax32 : PseudoMaskedAMMinMax;
def PseudoMaskedAtomicLoadMin32 : PseudoMaskedAMMinMax;

// Data prefetch

// TODO: Supports for preldx instruction.
def : Pat<(prefetch (AddrRegImm GPR:$rj, simm12:$imm12), (i32 0), timm, (i32 1)),
(PRELD 0, GPR:$rj, simm12:$imm12)>; // data prefetch for loads
def : Pat<(prefetch (AddrRegImm GPR:$rj, simm12:$imm12), (i32 1), timm, (i32 1)),
(PRELD 8, GPR:$rj, simm12:$imm12)>; // data prefetch for stores

/// Compare and exchange

class PseudoCmpXchg
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Target/LoongArch/LoongArchTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,10 @@ LoongArchTTIImpl::getPopcntSupport(unsigned TyWidth) {
return ST->hasExtLSX() ? TTI::PSK_FastHardware : TTI::PSK_Software;
}

unsigned LoongArchTTIImpl::getCacheLineSize() const { return 64; }

unsigned LoongArchTTIImpl::getPrefetchDistance() const { return 200; }

bool LoongArchTTIImpl::enableWritePrefetching() const { return true; }

// TODO: Implement more hooks to provide TTI machinery for LoongArch.
4 changes: 4 additions & 0 deletions llvm/lib/Target/LoongArch/LoongArchTargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class LoongArchTTIImpl : public BasicTTIImplBase<LoongArchTTIImpl> {
const char *getRegisterClassName(unsigned ClassID) const;
TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth);

unsigned getCacheLineSize() const override;
unsigned getPrefetchDistance() const override;
bool enableWritePrefetching() const override;

// TODO: Implement more hooks to provide TTI machinery for LoongArch.
};

Expand Down
67 changes: 67 additions & 0 deletions llvm/test/CodeGen/LoongArch/preld.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc --mtriple=loongarch32 < %s | FileCheck %s --check-prefix=LA32
; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s --check-prefix=LA64

declare void @llvm.prefetch(ptr, i32, i32, i32)

define void @load_prefetch_no_offset(ptr %a) {
; LA32-LABEL: load_prefetch_no_offset:
; LA32: # %bb.0: # %entry
; LA32-NEXT: preld 0, $a0, 0
; LA32-NEXT: ret
;
; LA64-LABEL: load_prefetch_no_offset:
; LA64: # %bb.0: # %entry
; LA64-NEXT: preld 0, $a0, 0
; LA64-NEXT: ret
entry:
call void @llvm.prefetch(ptr %a, i32 0, i32 3, i32 1)
ret void
}

define void @store_prefetch_no_offset(ptr %a) {
; LA32-LABEL: store_prefetch_no_offset:
; LA32: # %bb.0: # %entry
; LA32-NEXT: preld 8, $a0, 0
; LA32-NEXT: ret
;
; LA64-LABEL: store_prefetch_no_offset:
; LA64: # %bb.0: # %entry
; LA64-NEXT: preld 8, $a0, 0
; LA64-NEXT: ret
entry:
call void @llvm.prefetch(ptr %a, i32 1, i32 3, i32 1)
ret void
}

define void @load_prefetch_with_offset(ptr %a) {
; LA32-LABEL: load_prefetch_with_offset:
; LA32: # %bb.0: # %entry
; LA32-NEXT: preld 0, $a0, 200
; LA32-NEXT: ret
;
; LA64-LABEL: load_prefetch_with_offset:
; LA64: # %bb.0: # %entry
; LA64-NEXT: preld 0, $a0, 200
; LA64-NEXT: ret
entry:
%addr = getelementptr i8, ptr %a, i64 200
call void @llvm.prefetch(ptr %addr, i32 0, i32 3, i32 1)
ret void
}

define void @store_prefetch_with_offset(ptr %a) {
; LA32-LABEL: store_prefetch_with_offset:
; LA32: # %bb.0: # %entry
; LA32-NEXT: preld 8, $a0, 200
; LA32-NEXT: ret
;
; LA64-LABEL: store_prefetch_with_offset:
; LA64: # %bb.0: # %entry
; LA64-NEXT: preld 8, $a0, 200
; LA64-NEXT: ret
entry:
%addr = getelementptr i8, ptr %a, i64 200
call void @llvm.prefetch(ptr %addr, i32 1, i32 3, i32 1)
ret void
}
Loading