Skip to content

Commit 4938c62

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:9c5003cc0c70 into amd-gfx:606d2d42f73e
Local branch amd-gfx 606d2d4 Merged main:81e3e7e5d455 into amd-gfx:207601c46e4e Remote branch main 9c5003c [RISCV] Implement RISCVInstrInfo::getMemOperandsWithOffsetWidth (llvm#73681)
2 parents 606d2d4 + 9c5003c commit 4938c62

39 files changed

+1496
-1093
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7073,7 +7073,7 @@ Parameters annotated with `in` or with no annotation are passed by value from
70737073
the caller to the callee.
70747074

70757075
Parameters annotated with `out` are written to the argument after the callee
7076-
returns (Note: arguments values passed into `out` parameters _are not_ copied
7076+
returns (Note: arguments values passed into `out` parameters *are not* copied
70777077
into the callee).
70787078

70797079
Parameters annotated with `inout` are copied into the callee via a temporary,

clang/lib/CodeGen/CGCoroutine.cpp

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,48 @@ static SmallString<32> buildSuspendPrefixStr(CGCoroData &Coro, AwaitKind Kind) {
129129
return Prefix;
130130
}
131131

132-
static bool memberCallExpressionCanThrow(const Expr *E) {
133-
if (const auto *CE = dyn_cast<CXXMemberCallExpr>(E))
134-
if (const auto *Proto =
135-
CE->getMethodDecl()->getType()->getAs<FunctionProtoType>())
136-
if (isNoexceptExceptionSpec(Proto->getExceptionSpecType()) &&
137-
Proto->canThrow() == CT_Cannot)
138-
return false;
139-
return true;
132+
// Check if function can throw based on prototype noexcept, also works for
133+
// destructors which are implicitly noexcept but can be marked noexcept(false).
134+
static bool FunctionCanThrow(const FunctionDecl *D) {
135+
const auto *Proto = D->getType()->getAs<FunctionProtoType>();
136+
if (!Proto) {
137+
// Function proto is not found, we conservatively assume throwing.
138+
return true;
139+
}
140+
return !isNoexceptExceptionSpec(Proto->getExceptionSpecType()) ||
141+
Proto->canThrow() != CT_Cannot;
142+
}
143+
144+
static bool ResumeStmtCanThrow(const Stmt *S) {
145+
if (const auto *CE = dyn_cast<CallExpr>(S)) {
146+
const auto *Callee = CE->getDirectCallee();
147+
if (!Callee)
148+
// We don't have direct callee. Conservatively assume throwing.
149+
return true;
150+
151+
if (FunctionCanThrow(Callee))
152+
return true;
153+
154+
// Fall through to visit the children.
155+
}
156+
157+
if (const auto *TE = dyn_cast<CXXBindTemporaryExpr>(S)) {
158+
// Special handling of CXXBindTemporaryExpr here as calling of Dtor of the
159+
// temporary is not part of `children()` as covered in the fall through.
160+
// We need to mark entire statement as throwing if the destructor of the
161+
// temporary throws.
162+
const auto *Dtor = TE->getTemporary()->getDestructor();
163+
if (FunctionCanThrow(Dtor))
164+
return true;
165+
166+
// Fall through to visit the children.
167+
}
168+
169+
for (const auto *child : S->children())
170+
if (ResumeStmtCanThrow(child))
171+
return true;
172+
173+
return false;
140174
}
141175

142176
// Emit suspend expression which roughly looks like:
@@ -233,7 +267,7 @@ static LValueOrRValue emitSuspendExpression(CodeGenFunction &CGF, CGCoroData &Co
233267
// is marked as 'noexcept', we avoid generating this additional IR.
234268
CXXTryStmt *TryStmt = nullptr;
235269
if (Coro.ExceptionHandler && Kind == AwaitKind::Init &&
236-
memberCallExpressionCanThrow(S.getResumeExpr())) {
270+
ResumeStmtCanThrow(S.getResumeExpr())) {
237271
Coro.ResumeEHVar =
238272
CGF.CreateTempAlloca(Builder.getInt1Ty(), Prefix + Twine("resume.eh"));
239273
Builder.CreateFlagStore(true, Coro.ResumeEHVar);

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2032,7 +2032,7 @@ void ASTDeclReader::ReadCXXDefinitionData(
20322032
break;
20332033
case LCK_ByCopy:
20342034
case LCK_ByRef:
2035-
auto *Var = readDeclAs<VarDecl>();
2035+
auto *Var = readDeclAs<ValueDecl>();
20362036
SourceLocation EllipsisLoc = readSourceLocation();
20372037
new (ToCapture) Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc);
20382038
ToCapture++;

clang/test/CodeGenCoroutines/coro-init-await-nontrivial-return.cpp

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ struct NontrivialType {
77
~NontrivialType() {}
88
};
99

10+
struct NontrivialTypeWithThrowingDtor {
11+
~NontrivialTypeWithThrowingDtor() noexcept(false) {}
12+
};
13+
14+
namespace can_throw {
1015
struct Task {
1116
struct promise_type;
1217
using handle_type = std::coroutine_handle<promise_type>;
@@ -38,9 +43,66 @@ Task coro_create() {
3843
co_return;
3944
}
4045

41-
// CHECK-LABEL: define{{.*}} ptr @_Z11coro_createv(
46+
// CHECK-LABEL: define{{.*}} ptr @_ZN9can_throw11coro_createEv(
4247
// CHECK: init.ready:
4348
// CHECK-NEXT: store i1 true, ptr {{.*}}
44-
// CHECK-NEXT: call void @_ZN4Task23initial_suspend_awaiter12await_resumeEv(
49+
// CHECK-NEXT: call void @_ZN9can_throw4Task23initial_suspend_awaiter12await_resumeEv(
4550
// CHECK-NEXT: call void @_ZN14NontrivialTypeD1Ev(
4651
// CHECK-NEXT: store i1 false, ptr {{.*}}
52+
}
53+
54+
template <typename R>
55+
struct NoexceptResumeTask {
56+
struct promise_type;
57+
using handle_type = std::coroutine_handle<promise_type>;
58+
59+
struct initial_suspend_awaiter {
60+
bool await_ready() {
61+
return false;
62+
}
63+
64+
void await_suspend(handle_type h) {}
65+
66+
R await_resume() noexcept { return {}; }
67+
};
68+
69+
struct promise_type {
70+
void return_void() {}
71+
void unhandled_exception() {}
72+
initial_suspend_awaiter initial_suspend() { return {}; }
73+
std::suspend_never final_suspend() noexcept { return {}; }
74+
NoexceptResumeTask get_return_object() {
75+
return NoexceptResumeTask{handle_type::from_promise(*this)};
76+
}
77+
};
78+
79+
handle_type handler;
80+
};
81+
82+
namespace no_throw {
83+
using InitNoThrowTask = NoexceptResumeTask<NontrivialType>;
84+
85+
InitNoThrowTask coro_create() {
86+
co_return;
87+
}
88+
89+
// CHECK-LABEL: define{{.*}} ptr @_ZN8no_throw11coro_createEv(
90+
// CHECK: init.ready:
91+
// CHECK-NEXT: call void @_ZN18NoexceptResumeTaskI14NontrivialTypeE23initial_suspend_awaiter12await_resumeEv(
92+
// CHECK-NEXT: call void @_ZN14NontrivialTypeD1Ev(
93+
}
94+
95+
namespace throwing_dtor {
96+
using InitTaskWithThrowingDtor = NoexceptResumeTask<NontrivialTypeWithThrowingDtor>;
97+
98+
InitTaskWithThrowingDtor coro_create() {
99+
co_return;
100+
}
101+
102+
// CHECK-LABEL: define{{.*}} ptr @_ZN13throwing_dtor11coro_createEv(
103+
// CHECK: init.ready:
104+
// CHECK-NEXT: store i1 true, ptr {{.*}}
105+
// CHECK-NEXT: call void @_ZN18NoexceptResumeTaskI30NontrivialTypeWithThrowingDtorE23initial_suspend_awaiter12await_resumeEv(
106+
// CHECK-NEXT: call void @_ZN30NontrivialTypeWithThrowingDtorD1Ev(
107+
// CHECK-NEXT: store i1 false, ptr {{.*}}
108+
}

clang/test/Modules/pr72828.cppm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Test that we can handle capturing structured bindings.
2+
//
3+
// RUN: rm -fr %t
4+
// RUN: mkdir %t
5+
//
6+
// RUN: %clang_cc1 -std=c++23 -triple %itanium_abi_triple \
7+
// RUN: %s -emit-module-interface -o %t/m.pcm
8+
// RUN: %clang_cc1 -std=c++23 -triple %itanium_abi_triple \
9+
// RUN: -S -emit-llvm -disable-llvm-passes %t/m.pcm \
10+
// RUN: -o - | FileCheck %s
11+
12+
export module m;
13+
14+
struct s {
15+
int m;
16+
};
17+
18+
void f() {
19+
auto [x] = s();
20+
[x] {};
21+
}
22+
23+
// Check that we can generate the LLVM IR expectedly.
24+
// CHECK: define{{.*}}@_ZGIW1m

compiler-rt/include/sanitizer/memprof_interface.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ const char *SANITIZER_CDECL __memprof_default_options(void);
5959
/// \returns 0 on success.
6060
int SANITIZER_CDECL __memprof_profile_dump(void);
6161

62+
/// Closes the existing file descriptor, if it is valid and not stdout or
63+
/// stderr, and resets the internal state such that the profile filename is
64+
/// reopened on the next profile dump attempt. This can be used to enable
65+
/// multiple rounds of profiling on the same binary.
66+
void SANITIZER_CDECL __memprof_profile_reset(void);
67+
6268
#ifdef __cplusplus
6369
} // extern "C"
6470
#endif

compiler-rt/lib/memprof/memprof_allocator.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,3 +738,13 @@ int __memprof_profile_dump() {
738738
// detected during the dumping process.
739739
return 0;
740740
}
741+
742+
void __memprof_profile_reset() {
743+
if (report_file.fd != kInvalidFd && report_file.fd != kStdoutFd &&
744+
report_file.fd != kStderrFd) {
745+
CloseFile(report_file.fd);
746+
// Setting the file descriptor to kInvalidFd ensures that we will reopen the
747+
// file when invoking Write again.
748+
report_file.fd = kInvalidFd;
749+
}
750+
}

compiler-rt/lib/memprof/memprof_interface_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ extern uptr __memprof_shadow_memory_dynamic_address;
4949
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE extern char
5050
__memprof_profile_filename[1];
5151
SANITIZER_INTERFACE_ATTRIBUTE int __memprof_profile_dump();
52+
SANITIZER_INTERFACE_ATTRIBUTE void __memprof_profile_reset();
5253

5354
SANITIZER_INTERFACE_ATTRIBUTE void __memprof_load(uptr p);
5455
SANITIZER_INTERFACE_ATTRIBUTE void __memprof_store(uptr p);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Test to ensure that multiple rounds of dumping, using the
2+
// __memprof_profile_reset interface to close the initial file
3+
// and cause the profile to be reopened, works as expected.
4+
5+
// RUN: %clangxx_memprof %s -o %t
6+
7+
// RUN: rm -f %t.log.*
8+
// RUN: %env_memprof_opts=print_text=true:log_path=%t.log %run %t
9+
10+
// Check both outputs, starting with the renamed initial dump, then remove it so
11+
// that the second glob matches a single file.
12+
// RUN: FileCheck %s < %t.log.*.sv
13+
// RUN: rm -f %t.log.*.sv
14+
// RUN: FileCheck %s < %t.log.*
15+
// CHECK: Memory allocation stack id
16+
17+
#include <sanitizer/memprof_interface.h>
18+
#include <stdio.h>
19+
20+
#include <stdlib.h>
21+
#include <string.h>
22+
#include <string>
23+
int main(int argc, char **argv) {
24+
char *x = (char *)malloc(10);
25+
memset(x, 0, 10);
26+
free(x);
27+
__memprof_profile_dump();
28+
// Save the initial dump in a different file.
29+
std::string origname = __sanitizer_get_report_path();
30+
std::string svname = origname + ".sv";
31+
rename(origname.c_str(), svname.c_str());
32+
// This should cause the current file descriptor to be closed and the
33+
// the internal state reset so that the profile filename is reopened
34+
// on the next write.
35+
__memprof_profile_reset();
36+
// This will dump to origname again.
37+
__memprof_profile_dump();
38+
return 0;
39+
}

libc/cmake/modules/LLVMLibCFlagRules.cmake

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ endfunction(get_fq_dep_list_without_flag)
132132
# Special flags
133133
set(FMA_OPT_FLAG "FMA_OPT")
134134
set(ROUND_OPT_FLAG "ROUND_OPT")
135-
# SSE2 is the baseline for x86_64, so we add a negative flag to disable it if needed.
136-
set(DISABLE_SSE2_OPT_FLAG "DISABLE_SSE2_OPT")
135+
# This flag will define macros that gated away vectorization code such that
136+
# one can always test the fallback generic code path.
137+
set(PREFER_GENERIC_FLAG "PREFER_GENERIC")
137138

138139
# Skip FMA_OPT flag for targets that don't support fma.
139140
if(NOT((LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "FMA")) OR
@@ -145,8 +146,3 @@ endif()
145146
if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE4_2")))
146147
set(SKIP_FLAG_EXPANSION_ROUND_OPT TRUE)
147148
endif()
148-
149-
# Skip DISABLE_SSE2_OPT flag for targets that don't support SSE2.
150-
if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE2")))
151-
set(SKIP_FLAG_EXPANSION_DISABLE_SSE2_OPT TRUE)
152-
endif()

libc/cmake/modules/LLVMLibCObjectRules.cmake

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ function(_get_common_compile_options output_var flags)
1818
set(ADD_SSE4_2_FLAG TRUE)
1919
endif()
2020

21-
list(FIND flags ${DISABLE_SSE2_OPT_FLAG} no_sse2)
22-
if(${no_sse2} LESS 0)
23-
list(FIND flags "${DISABLE_SSE2_OPT_FLAG}__ONLY" no_sse2)
21+
list(FIND flags ${PREFER_GENERIC_FLAG} prefer_generic)
22+
if(${prefer_generic} LESS 0)
23+
list(FIND flags "${PREFER_GENERIC_FLAG}__ONLY" prefer_generic)
2424
endif()
25-
if((${no_sse2} GREATER -1) AND (LIBC_CPU_FEATURES MATCHES "SSE2"))
26-
set(DISABLE_SSE2_FLAG TRUE)
25+
if(${prefer_generic} GREATER -1)
26+
set(ADD_PREFER_GENERIC_FLAG TRUE)
2727
endif()
2828

2929
set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT} ${ARGN})
@@ -66,17 +66,17 @@ function(_get_common_compile_options output_var flags)
6666
if(ADD_SSE4_2_FLAG)
6767
list(APPEND compile_options "-msse4.2")
6868
endif()
69-
if(DISABLE_SSE2_FLAG)
70-
list(APPEND compile_options "-mno-sse2")
69+
if(ADD_PREFER_GENERIC_FLAG)
70+
list(APPEND compile_options "-D__LIBC_PREFER_GENERIC")
7171
endif()
7272
elseif(MSVC)
7373
list(APPEND compile_options "/EHs-c-")
7474
list(APPEND compile_options "/GR-")
7575
if(ADD_FMA_FLAG)
7676
list(APPEND compile_options "/arch:AVX2")
7777
endif()
78-
if(DISABLE_SSE2_FLAG)
79-
list(APPEND compile_options "/arch:SSE")
78+
if(ADD_PREFER_GENERIC_FLAG)
79+
list(APPEND compile_options "/D__LIBC_PREFER_GENERIC")
8080
endif()
8181
endif()
8282
if (LIBC_TARGET_ARCHITECTURE_IS_GPU)

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,6 @@ set(TARGET_LIBC_ENTRYPOINTS
130130
#libc.src.stdio.scanf
131131
#libc.src.stdio.fscanf
132132

133-
# search.h entrypoints
134-
libc.src.search.hcreate
135-
libc.src.search.hcreate_r
136-
libc.src.search.hsearch
137-
libc.src.search.hsearch_r
138-
libc.src.search.hdestroy
139-
libc.src.search.hdestroy_r
140-
141133
# sys/mman.h entrypoints
142134
libc.src.sys.mman.madvise
143135
libc.src.sys.mman.mmap
@@ -459,6 +451,14 @@ if(LLVM_LIBC_FULL_BUILD)
459451
libc.src.signal.sigfillset
460452
libc.src.signal.signal
461453

454+
# search.h entrypoints
455+
libc.src.search.hcreate
456+
libc.src.search.hcreate_r
457+
libc.src.search.hsearch
458+
libc.src.search.hsearch_r
459+
libc.src.search.hdestroy
460+
libc.src.search.hdestroy_r
461+
462462
# threads.h entrypoints
463463
libc.src.threads.call_once
464464
libc.src.threads.cnd_broadcast

libc/config/linux/arm/entrypoints.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,7 @@ set(TARGET_LIBC_ENTRYPOINTS
8888
libc.src.stdlib.strtoll
8989
libc.src.stdlib.strtoul
9090
libc.src.stdlib.strtoull
91-
92-
# search.h entrypoints
93-
libc.src.search.hcreate
94-
libc.src.search.hcreate_r
95-
libc.src.search.hsearch
96-
libc.src.search.hsearch_r
97-
libc.src.search.hdestroy
98-
libc.src.search.hdestroy_r
99-
91+
10092
# sys/mman.h entrypoints
10193
libc.src.sys.mman.mmap
10294
libc.src.sys.mman.munmap

0 commit comments

Comments
 (0)