Skip to content

Commit 01cd3d8

Browse files
Merge branch 'main' into callsite-indirect-calls
2 parents 9de4f0b + 3c52f53 commit 01cd3d8

File tree

315 files changed

+3765
-3474
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

315 files changed

+3765
-3474
lines changed

.github/workflows/release-binaries.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,6 @@ jobs:
191191
- name: Install Ninja
192192
uses: llvm/actions/install-ninja@42d80571b13f4599bbefbc7189728b64723c7f78 # main
193193

194-
- name: Setup Windows
195-
if: startsWith(runner.os, 'Windows')
196-
uses: llvm/actions/setup-windows@42d80571b13f4599bbefbc7189728b64723c7f78 # main
197-
with:
198-
arch: amd64
199-
200194
- name: Set Build Prefix
201195
id: setup-stage
202196
shell: bash

clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
269269
return;
270270
}
271271
break;
272+
case CK_BaseToDerived:
273+
if (!needsConstCast(SourceType, DestType)) {
274+
ReplaceWithNamedCast("static_cast");
275+
return;
276+
}
277+
break;
272278
default:
273279
break;
274280
}

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ Changes in existing checks
402402
adding an option to allow pointer arithmetic via prefix/postfix increment or
403403
decrement operators.
404404

405+
- Improved :doc:`google-readability-casting
406+
<clang-tidy/checks/google/readability-casting>` check by adding fix-it
407+
notes for downcasts.
408+
405409
- Improved :doc:`llvm-prefer-isa-or-dyn-cast-in-conditionals
406410
<clang-tidy/checks/llvm/prefer-isa-or-dyn-cast-in-conditionals>` check:
407411

clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ void f(int a, double b, const char *cpc, const void *cpv, X *pX) {
102102
// CHECK-FIXES: b1 = static_cast<int>(b);
103103

104104
Y *pB = (Y*)pX;
105-
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast/const_cast/reinterpret_cast [
105+
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast {{.*}}
106+
// CHECK-FIXES: Y *pB = static_cast<Y*>(pX);
106107
Y &rB = (Y&)*pX;
107-
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast/const_cast/reinterpret_cast [
108+
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast {{.*}}
109+
// CHECK-FIXES: Y &rB = static_cast<Y&>(*pX);
108110

109111
const char *pc3 = (const char*)cpv;
110112
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}}; use static_cast [

clang/lib/Serialization/ASTReader.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4087,10 +4087,14 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
40874087
std::errc::illegal_byte_sequence,
40884088
"Invalid PENDING_IMPLICIT_INSTANTIATIONS block");
40894089

4090-
for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) {
4091-
PendingInstantiations.push_back(
4092-
{ReadDeclID(F, Record, I),
4093-
ReadSourceLocation(F, Record, I).getRawEncoding()});
4090+
// For standard C++20 module, we will only reads the instantiations
4091+
// if it is the main file.
4092+
if (!F.StandardCXXModule || F.Kind == MK_MainFile) {
4093+
for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) {
4094+
PendingInstantiations.push_back(
4095+
{ReadDeclID(F, Record, I),
4096+
ReadSourceLocation(F, Record, I).getRawEncoding()});
4097+
}
40944098
}
40954099
break;
40964100

@@ -6438,10 +6442,13 @@ llvm::Error ASTReader::ReadSubmoduleBlock(ModuleFile &F,
64386442
case SUBMODULE_INITIALIZERS: {
64396443
if (!ContextObj)
64406444
break;
6441-
SmallVector<GlobalDeclID, 16> Inits;
6442-
for (unsigned I = 0; I < Record.size(); /*in loop*/)
6443-
Inits.push_back(ReadDeclID(F, Record, I));
6444-
ContextObj->addLazyModuleInitializers(CurrentModule, Inits);
6445+
// Standard C++ module has its own way to initialize variables.
6446+
if (!F.StandardCXXModule || F.Kind == MK_MainFile) {
6447+
SmallVector<GlobalDeclID, 16> Inits;
6448+
for (unsigned I = 0; I < Record.size(); /*in loop*/)
6449+
Inits.push_back(ReadDeclID(F, Record, I));
6450+
ContextObj->addLazyModuleInitializers(CurrentModule, Inits);
6451+
}
64456452
break;
64466453
}
64476454

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3247,7 +3247,7 @@ void ASTWriter::WriteSubmodules(Module *WritingModule, ASTContext *Context) {
32473247

32483248
// Emit the reachable initializers.
32493249
// The initializer may only be unreachable in reduced BMI.
3250-
if (Context) {
3250+
if (Context && !GeneratingReducedBMI) {
32513251
RecordData Inits;
32523252
for (Decl *D : Context->getModuleInitializers(Mod))
32533253
if (wasDeclEmitted(D))
@@ -5827,17 +5827,19 @@ void ASTWriter::WriteSpecialDeclRecords(Sema &SemaRef) {
58275827
Stream.EmitRecord(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES,
58285828
UnusedLocalTypedefNameCandidates);
58295829

5830-
// Write the record containing pending implicit instantiations.
5831-
RecordData PendingInstantiations;
5832-
for (const auto &I : SemaRef.PendingInstantiations) {
5833-
if (!wasDeclEmitted(I.first))
5834-
continue;
5830+
if (!GeneratingReducedBMI) {
5831+
// Write the record containing pending implicit instantiations.
5832+
RecordData PendingInstantiations;
5833+
for (const auto &I : SemaRef.PendingInstantiations) {
5834+
if (!wasDeclEmitted(I.first))
5835+
continue;
58355836

5836-
AddDeclRef(I.first, PendingInstantiations);
5837-
AddSourceLocation(I.second, PendingInstantiations);
5837+
AddDeclRef(I.first, PendingInstantiations);
5838+
AddSourceLocation(I.second, PendingInstantiations);
5839+
}
5840+
if (!PendingInstantiations.empty())
5841+
Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations);
58385842
}
5839-
if (!PendingInstantiations.empty())
5840-
Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations);
58415843

58425844
// Write the record containing declaration references of Sema.
58435845
RecordData SemaDeclRefs;

clang/test/Modules/pr166068.cppm

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 %t/flyweight.cppm -emit-reduced-module-interface -o %t/flyweight.pcm
6+
// RUN: %clang_cc1 -std=c++20 %t/account.cppm -emit-reduced-module-interface -o %t/account.pcm -fprebuilt-module-path=%t
7+
// RUN: %clang_cc1 -std=c++20 %t/core.cppm -emit-reduced-module-interface -o %t/core.pcm -fprebuilt-module-path=%t
8+
// RUN: %clang_cc1 -std=c++20 %t/core.cppm -fprebuilt-module-path=%t -emit-llvm -disable-llvm-passes -o - | FileCheck %t/core.cppm
9+
10+
//--- flyweight.cppm
11+
module;
12+
template <typename> struct flyweight_core {
13+
static bool init() { (void)__builtin_operator_new(2); return true; }
14+
static bool static_initializer;
15+
};
16+
template <typename T> bool flyweight_core<T>::static_initializer = init();
17+
export module flyweight;
18+
export template <class> void flyweight() {
19+
(void)flyweight_core<int>::static_initializer;
20+
}
21+
22+
//--- account.cppm
23+
export module account;
24+
import flyweight;
25+
export void account() {
26+
(void)::flyweight<int>;
27+
}
28+
29+
//--- core.cppm
30+
export module core;
31+
import account;
32+
33+
extern "C" void core() {}
34+
35+
// Fine enough to check it won't crash.
36+
// CHECK-NOT: init
37+
// CHECK-NOT: static_initializer
38+
// CHECK: define {{.*}}@core(

compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct MemoryMappedSegmentData {
4545
const char *current_load_cmd_addr;
4646
u32 lc_type;
4747
uptr base_virt_addr;
48+
uptr addr_mask;
4849
};
4950

5051
template <typename Section>
@@ -53,58 +54,12 @@ static void NextSectionLoad(LoadedModule *module, MemoryMappedSegmentData *data,
5354
const Section *sc = (const Section *)data->current_load_cmd_addr;
5455
data->current_load_cmd_addr += sizeof(Section);
5556

56-
uptr sec_start = sc->addr + data->base_virt_addr;
57+
uptr sec_start = (sc->addr & data->addr_mask) + data->base_virt_addr;
5758
uptr sec_end = sec_start + sc->size;
5859
module->addAddressRange(sec_start, sec_end, /*executable=*/false, isWritable,
5960
sc->sectname);
6061
}
6162

62-
static bool VerifyMemoryMapping(MemoryMappingLayout* mapping) {
63-
InternalMmapVector<LoadedModule> modules;
64-
modules.reserve(128); // matches DumpProcessMap
65-
mapping->DumpListOfModules(&modules);
66-
67-
InternalMmapVector<LoadedModule::AddressRange> segments;
68-
for (uptr i = 0; i < modules.size(); ++i) {
69-
for (auto& range : modules[i].ranges()) {
70-
segments.push_back(range);
71-
}
72-
}
73-
74-
// Verify that none of the segments overlap:
75-
// 1. Sort the segments by the start address
76-
// 2. Check that every segment starts after the previous one ends.
77-
Sort(segments.data(), segments.size(),
78-
[](LoadedModule::AddressRange& a, LoadedModule::AddressRange& b) {
79-
return a.beg < b.beg;
80-
});
81-
82-
// To avoid spam, we only print the report message once-per-process.
83-
static bool invalid_module_map_reported = false;
84-
bool well_formed = true;
85-
86-
for (size_t i = 1; i < segments.size(); i++) {
87-
uptr cur_start = segments[i].beg;
88-
uptr prev_end = segments[i - 1].end;
89-
if (cur_start < prev_end) {
90-
well_formed = false;
91-
VReport(2, "Overlapping mappings: %s start = %p, %s end = %p\n",
92-
segments[i].name, (void*)cur_start, segments[i - 1].name,
93-
(void*)prev_end);
94-
if (!invalid_module_map_reported) {
95-
Report(
96-
"WARN: Invalid dyld module map detected. This is most likely a bug "
97-
"in the sanitizer.\n");
98-
Report("WARN: Backtraces may be unreliable.\n");
99-
invalid_module_map_reported = true;
100-
}
101-
}
102-
}
103-
104-
mapping->Reset();
105-
return well_formed;
106-
}
107-
10863
void MemoryMappedSegment::AddAddressRanges(LoadedModule *module) {
10964
// Don't iterate over sections when the caller hasn't set up the
11065
// data pointer, when there are no sections, or when the segment
@@ -130,7 +85,6 @@ void MemoryMappedSegment::AddAddressRanges(LoadedModule *module) {
13085

13186
MemoryMappingLayout::MemoryMappingLayout(bool cache_enabled) {
13287
Reset();
133-
VerifyMemoryMapping(this);
13488
}
13589

13690
MemoryMappingLayout::~MemoryMappingLayout() {
@@ -236,7 +190,6 @@ typedef struct dyld_shared_cache_dylib_text_info
236190

237191
extern bool _dyld_get_shared_cache_uuid(uuid_t uuid);
238192
extern const void *_dyld_get_shared_cache_range(size_t *length);
239-
extern intptr_t _dyld_get_image_slide(const struct mach_header* mh);
240193
extern int dyld_shared_cache_iterate_text(
241194
const uuid_t cacheUuid,
242195
void (^callback)(const dyld_shared_cache_dylib_text_info *info));
@@ -305,21 +258,23 @@ static bool NextSegmentLoad(MemoryMappedSegment *segment,
305258
layout_data->current_load_cmd_count--;
306259
if (((const load_command *)lc)->cmd == kLCSegment) {
307260
const SegmentCommand* sc = (const SegmentCommand *)lc;
308-
if (strncmp(sc->segname, "__LINKEDIT", sizeof("__LINKEDIT")) == 0) {
309-
// The LINKEDIT sections are for internal linker use, and may alias
310-
// with the LINKEDIT section for other modules. (If we included them,
311-
// our memory map would contain overlappping sections.)
312-
return false;
313-
}
314-
315-
uptr base_virt_addr;
316-
if (layout_data->current_image == kDyldImageIdx)
317-
base_virt_addr = (uptr)_dyld_get_image_slide(get_dyld_hdr());
318-
else
261+
uptr base_virt_addr, addr_mask;
262+
if (layout_data->current_image == kDyldImageIdx) {
263+
base_virt_addr = (uptr)get_dyld_hdr();
264+
// vmaddr is masked with 0xfffff because on macOS versions < 10.12,
265+
// it contains an absolute address rather than an offset for dyld.
266+
// To make matters even more complicated, this absolute address
267+
// isn't actually the absolute segment address, but the offset portion
268+
// of the address is accurate when combined with the dyld base address,
269+
// and the mask will give just this offset.
270+
addr_mask = 0xfffff;
271+
} else {
319272
base_virt_addr =
320273
(uptr)_dyld_get_image_vmaddr_slide(layout_data->current_image);
274+
addr_mask = ~0;
275+
}
321276

322-
segment->start = sc->vmaddr + base_virt_addr;
277+
segment->start = (sc->vmaddr & addr_mask) + base_virt_addr;
323278
segment->end = segment->start + sc->vmsize;
324279
// Most callers don't need section information, so only fill this struct
325280
// when required.
@@ -329,6 +284,7 @@ static bool NextSegmentLoad(MemoryMappedSegment *segment,
329284
(const char *)lc + sizeof(SegmentCommand);
330285
seg_data->lc_type = kLCSegment;
331286
seg_data->base_virt_addr = base_virt_addr;
287+
seg_data->addr_mask = addr_mask;
332288
internal_strncpy(seg_data->name, sc->segname,
333289
ARRAY_SIZE(seg_data->name));
334290
}

compiler-rt/test/asan/TestCases/Darwin/asan-verify-module-map.cpp

Lines changed: 0 additions & 25 deletions
This file was deleted.

flang/include/flang/Lower/AbstractConverter.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ class AbstractConverter {
271271
virtual bool
272272
isRegisteredDummySymbol(Fortran::semantics::SymbolRef symRef) const = 0;
273273

274+
/// Get the source-level argument position (1-based) for a dummy symbol.
275+
/// Returns 0 if the symbol is not a registered dummy or position is unknown.
276+
/// Can only be used reliably during the instantiation of variables.
277+
virtual unsigned
278+
getDummyArgPosition(const Fortran::semantics::Symbol &sym) const = 0;
279+
274280
/// Returns the FunctionLikeUnit being lowered, if any.
275281
virtual const Fortran::lower::pft::FunctionLikeUnit *
276282
getCurrentFunctionUnit() const = 0;
@@ -351,6 +357,11 @@ class AbstractConverter {
351357

352358
virtual Fortran::lower::StatementContext &getFctCtx() = 0;
353359

360+
/// Generate STAT and ERRMSG from a list of StatOrErrmsg
361+
virtual std::pair<mlir::Value, mlir::Value>
362+
genStatAndErrmsg(mlir::Location loc,
363+
const std::list<Fortran::parser::StatOrErrmsg> &) = 0;
364+
354365
AbstractConverter(const Fortran::lower::LoweringOptions &loweringOptions)
355366
: loweringOptions(loweringOptions) {}
356367
virtual ~AbstractConverter() = default;

0 commit comments

Comments
 (0)