Skip to content

Commit 58e89b3

Browse files
authored
Merge pull request swiftlang#11998 from compnerd/qualifiers
runtime: clean up last of -Wqual-cast warnings
2 parents cf78384 + 7bd2256 commit 58e89b3

File tree

8 files changed

+36
-22
lines changed

8 files changed

+36
-22
lines changed

lib/AST/RawComment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ CharSourceRange RawComment::getCharSourceRange() {
258258
return CharSourceRange();
259259
}
260260
auto End = this->Comments.back().Range.getEnd();
261-
auto Length = (char *)End.getOpaquePointerValue() -
262-
(char* )Start.getOpaquePointerValue();
261+
auto Length = static_cast<const char *>(End.getOpaquePointerValue()) -
262+
static_cast<const char *>(Start.getOpaquePointerValue());
263263
return CharSourceRange(Start, Length);
264264
}

lib/IDE/SwiftSourceDocInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,9 @@ calculateContentRange(ArrayRef<Token> Tokens) {
773773
auto StartLoc = StartTok.hasComment() ?
774774
StartTok.getCommentStart() : StartTok.getLoc();
775775
auto EndLoc = EndTok.getRange().getEnd();
776-
return CharSourceRange(StartLoc, (char*)EndLoc.getOpaquePointerValue() -
777-
(char*)StartLoc.getOpaquePointerValue());
776+
auto Length = static_cast<const char *>(EndLoc.getOpaquePointerValue()) -
777+
static_cast<const char *>(StartLoc.getOpaquePointerValue());
778+
return CharSourceRange(StartLoc, Length);
778779
}
779780

780781
bool DeclaredDecl::operator==(const DeclaredDecl& Other) {

lib/IDE/Utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ ide::replacePlaceholders(std::unique_ptr<llvm::MemoryBuffer> InputBuf,
449449
assert(Id.size() == Occur.FullPlaceholder.size());
450450

451451
unsigned Offset = Occur.FullPlaceholder.data() - InputBuf->getBufferStart();
452-
char *Ptr = (char*)NewBuf->getBufferStart() + Offset;
452+
char *Ptr = const_cast<char *>(NewBuf->getBufferStart()) + Offset;
453453
std::copy(Id.begin(), Id.end(), Ptr);
454454

455455
Occur.IdentifierReplacement = Id.str();

lib/IRGen/IRGen.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class MD5Stream : public llvm::raw_ostream {
269269
llvm::MD5 Hash;
270270

271271
void write_impl(const char *Ptr, size_t Size) override {
272-
Hash.update(ArrayRef<uint8_t>((uint8_t *)Ptr, Size));
272+
Hash.update(ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(Ptr), Size));
273273
Pos += Size;
274274
}
275275

@@ -336,12 +336,16 @@ static bool needsRecompile(StringRef OutputFilename, ArrayRef<uint8_t> HashData,
336336
if (SectionName == HashSectionName) {
337337
StringRef SectionData;
338338
Section.getContents(SectionData);
339-
ArrayRef<uint8_t> PrevHashData((uint8_t *)SectionData.data(),
340-
SectionData.size());
339+
ArrayRef<uint8_t> PrevHashData(
340+
reinterpret_cast<const uint8_t *>(SectionData.data()),
341+
SectionData.size());
341342
DEBUG(if (PrevHashData.size() == sizeof(MD5::MD5Result)) {
342343
if (DiagMutex) DiagMutex->lock();
343344
SmallString<32> HashStr;
344-
MD5::stringifyResult(*(MD5::MD5Result *)PrevHashData.data(), HashStr);
345+
MD5::stringifyResult(
346+
*reinterpret_cast<MD5::MD5Result *>(
347+
const_cast<unsigned char *>(PrevHashData.data())),
348+
HashStr);
345349
llvm::dbgs() << OutputFilename << ": prev MD5=" << HashStr <<
346350
(HashData == PrevHashData ? " skipping\n" : " recompiling\n");
347351
if (DiagMutex) DiagMutex->unlock();
@@ -590,7 +594,8 @@ static void embedBitcode(llvm::Module *M, const IRGenOptions &Opts)
590594
if (Opts.EmbedMode == IRGenEmbedMode::EmbedBitcode)
591595
llvm::WriteBitcodeToFile(M, OS);
592596

593-
ArrayRef<uint8_t> ModuleData((uint8_t*)OS.str().data(), OS.str().size());
597+
ArrayRef<uint8_t> ModuleData(
598+
reinterpret_cast<const uint8_t *>(OS.str().data()), OS.str().size());
594599
llvm::Constant *ModuleConstant =
595600
llvm::ConstantDataArray::get(M->getContext(), ModuleData);
596601
llvm::GlobalVariable *GV = new llvm::GlobalVariable(*M,
@@ -610,8 +615,9 @@ static void embedBitcode(llvm::Module *M, const IRGenOptions &Opts)
610615
}
611616

612617
// Embed command-line options.
613-
ArrayRef<uint8_t> CmdData((uint8_t*)Opts.CmdArgs.data(),
614-
Opts.CmdArgs.size());
618+
ArrayRef<uint8_t>
619+
CmdData(reinterpret_cast<const uint8_t *>(Opts.CmdArgs.data()),
620+
Opts.CmdArgs.size());
615621
llvm::Constant *CmdConstant =
616622
llvm::ConstantDataArray::get(M->getContext(), CmdData);
617623
GV = new llvm::GlobalVariable(*M, CmdConstant->getType(), true,

lib/Parse/Lexer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void Lexer::skipUpToEndOfLine() {
325325
return;
326326
default:
327327
// If this is a "high" UTF-8 character, validate it.
328-
if (*((signed char *)CurPtr) < 0) {
328+
if (*reinterpret_cast<const signed char *>(CurPtr) < 0) {
329329
const char *CharStart = CurPtr;
330330
if (validateUTF8CharacterAndAdvance(CurPtr, BufferEnd) == ~0U)
331331
diagnose(CharStart, diag::lex_invalid_utf8);

stdlib/public/runtime/ExistentialMetadataImpl.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,16 +561,17 @@ struct LLVM_LIBRARY_VISIBILITY ExistentialMetatypeBoxBase
561561

562562
template <class Container, class... A>
563563
static void storeExtraInhabitant(Container *dest, int index, A... args) {
564-
swift_storeHeapObjectExtraInhabitant((HeapObject**) dest->getValueSlot(),
564+
Metadata **MD = const_cast<Metadata **>(dest->getValueSlot());
565+
swift_storeHeapObjectExtraInhabitant(reinterpret_cast<HeapObject **>(MD),
565566
index);
566567
}
567568

568569
template <class Container, class... A>
569570
static int getExtraInhabitantIndex(const Container *src, A... args) {
571+
Metadata **MD = const_cast<Metadata **>(src->getValueSlot());
570572
return swift_getHeapObjectExtraInhabitantIndex(
571-
(HeapObject* const *) src->getValueSlot());
573+
reinterpret_cast<HeapObject *const *>(MD));
572574
}
573-
574575
};
575576

576577
/// A box implementation class for an existential metatype container

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@ const Metadata *TypeMetadataRecord::getCanonicalTypeMetadata() const {
130130
switch (getTypeKind()) {
131131
case TypeMetadataRecordKind::UniqueDirectType:
132132
return getDirectType();
133-
case TypeMetadataRecordKind::NonuniqueDirectType:
134-
return swift_getForeignTypeMetadata((ForeignTypeMetadata *)getDirectType());
133+
case TypeMetadataRecordKind::NonuniqueDirectType: {
134+
const ForeignTypeMetadata *FMD =
135+
static_cast<const ForeignTypeMetadata *>(getDirectType());
136+
return swift_getForeignTypeMetadata(const_cast<ForeignTypeMetadata *>(FMD));
137+
}
135138
case TypeMetadataRecordKind::UniqueDirectClass:
136139
if (auto *ClassMetadata =
137140
static_cast<const ::ClassMetadata *>(getDirectType()))

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,18 @@ template<> void ProtocolConformanceRecord::dump() const {
9191
/// Take the type reference inside a protocol conformance record and fetch the
9292
/// canonical metadata pointer for the type it refers to.
9393
/// Returns nil for universal or generic type references.
94-
template<> const Metadata *ProtocolConformanceRecord::getCanonicalTypeMetadata()
95-
const {
94+
template <>
95+
const Metadata *ProtocolConformanceRecord::getCanonicalTypeMetadata() const {
9696
switch (getTypeKind()) {
9797
case TypeMetadataRecordKind::UniqueDirectType:
9898
// Already unique.
9999
return getDirectType();
100-
case TypeMetadataRecordKind::NonuniqueDirectType:
100+
case TypeMetadataRecordKind::NonuniqueDirectType: {
101101
// Ask the runtime for the unique metadata record we've canonized.
102-
return swift_getForeignTypeMetadata((ForeignTypeMetadata*)getDirectType());
102+
const ForeignTypeMetadata *FMD =
103+
static_cast<const ForeignTypeMetadata *>(getDirectType());
104+
return swift_getForeignTypeMetadata(const_cast<ForeignTypeMetadata *>(FMD));
105+
}
103106
case TypeMetadataRecordKind::UniqueIndirectClass:
104107
// The class may be ObjC, in which case we need to instantiate its Swift
105108
// metadata. The class additionally may be weak-linked, so we have to check

0 commit comments

Comments
 (0)