Commit eba6da37 authored by Marco Bubke's avatar Marco Bubke
Browse files

Clang: Fix aliasing



Task-number: QTCREATORBUG-15888
Change-Id: I0f2e28e9e0da53481c03707ab0a9abf728c7419f
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
Reviewed-by: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent 1ea64043
......@@ -43,7 +43,7 @@
namespace ClangBackEnd {
enum class DiagnosticSeverity // one to one mapping of the clang enum numbers
enum class DiagnosticSeverity : quint32 // one to one mapping of the clang enum numbers
{
Ignored = 0,
Note = 1,
......@@ -75,7 +75,7 @@ enum class HighlightingType : quint8
Declaration
};
enum class CompletionCorrection
enum class CompletionCorrection : quint32
{
NoCorrection,
DotToArrowCorrection
......
......@@ -56,15 +56,10 @@ quint64 CodeCompletedMessage::ticketNumber() const
return ticketNumber_;
}
quint32 &CodeCompletedMessage::neededCorrectionAsInt()
{
return reinterpret_cast<quint32&>(neededCorrection_);
}
QDataStream &operator<<(QDataStream &out, const CodeCompletedMessage &message)
{
out << message.codeCompletions_;
out << quint32(message.neededCorrection_);
out << static_cast<quint32>(message.neededCorrection_);
out << message.ticketNumber_;
return out;
......@@ -72,10 +67,14 @@ QDataStream &operator<<(QDataStream &out, const CodeCompletedMessage &message)
QDataStream &operator>>(QDataStream &in, CodeCompletedMessage &message)
{
quint32 neededCorrection;
in >> message.codeCompletions_;
in >> message.neededCorrectionAsInt();
in >> neededCorrection;
in >> message.ticketNumber_;
message.neededCorrection_ = static_cast<CompletionCorrection>(neededCorrection);
return in;
}
......
......@@ -49,9 +49,6 @@ public:
quint64 ticketNumber() const;
private:
quint32 &neededCorrectionAsInt();
private:
CodeCompletions codeCompletions_;
quint64 ticketNumber_ = 0;
......
......@@ -115,24 +115,14 @@ const Utf8String &CodeCompletion::briefComment() const
return briefComment_;
}
quint32 &CodeCompletion::completionKindAsInt()
{
return reinterpret_cast<quint32&>(completionKind_);
}
quint32 &CodeCompletion::availabilityAsInt()
{
return reinterpret_cast<quint32&>(availability_);
}
QDataStream &operator<<(QDataStream &out, const CodeCompletion &message)
{
out << message.text_;
out << message.briefComment_;
out << message.chunks_;
out << message.priority_;
out << message.completionKind_;
out << message.availability_;
out << static_cast<quint32>(message.completionKind_);
out << static_cast<quint32>(message.availability_);
out << message.hasParameters_;
return out;
......@@ -140,14 +130,20 @@ QDataStream &operator<<(QDataStream &out, const CodeCompletion &message)
QDataStream &operator>>(QDataStream &in, CodeCompletion &message)
{
quint32 completionKind;
quint32 availability;
in >> message.text_;
in >> message.briefComment_;
in >> message.chunks_;
in >> message.priority_;
in >> message.completionKindAsInt();
in >> message.availabilityAsInt();
in >> completionKind;
in >> availability;
in >> message.hasParameters_;
message.completionKind_ = static_cast<CodeCompletion::Kind>(completionKind);
message.availability_ = static_cast<CodeCompletion::Availability>(availability);
return in;
}
......
......@@ -103,10 +103,6 @@ public:
void setBriefComment(const Utf8String &briefComment);
const Utf8String &briefComment() const;
private:
quint32 &completionKindAsInt();
quint32 &availabilityAsInt();
private:
Utf8String text_;
Utf8String briefComment_;
......
......@@ -56,14 +56,9 @@ bool CodeCompletionChunk::isOptional() const
return isOptional_;
}
quint8 &CodeCompletionChunk::kindAsInt()
{
return reinterpret_cast<quint8&>(kind_);
}
QDataStream &operator<<(QDataStream &out, const CodeCompletionChunk &chunk)
{
out << quint8(chunk.kind_);
out << static_cast<quint8>(chunk.kind_);
out << chunk.text_;
out << chunk.isOptional_;
......@@ -72,10 +67,14 @@ QDataStream &operator<<(QDataStream &out, const CodeCompletionChunk &chunk)
QDataStream &operator>>(QDataStream &in, CodeCompletionChunk &chunk)
{
in >> chunk.kindAsInt();
quint8 kind;
in >> kind;
in >> chunk.text_;
in >> chunk.isOptional_;
chunk.kind_ = static_cast<CodeCompletionChunk::Kind>(kind);
return in;
}
......
......@@ -77,9 +77,6 @@ public:
const Utf8String &text() const;
bool isOptional() const;
private:
quint8 &kindAsInt();
private:
Utf8String text_;
Kind kind_ = Invalid;
......
......@@ -97,11 +97,6 @@ const QVector<DiagnosticContainer> &DiagnosticContainer::children() const
return children_;
}
quint32 &DiagnosticContainer::severityAsInt()
{
return reinterpret_cast<quint32&>(severity_);
}
QDataStream &operator<<(QDataStream &out, const DiagnosticContainer &container)
{
out << container.text_;
......@@ -109,7 +104,7 @@ QDataStream &operator<<(QDataStream &out, const DiagnosticContainer &container)
out << container.enableOption_;
out << container.disableOption_;
out << container.location_;
out << quint32(container.severity_);
out << static_cast<quint32>(container.severity_);
out << container.ranges_;
out << container.fixIts_;
out << container.children_;
......@@ -119,16 +114,20 @@ QDataStream &operator<<(QDataStream &out, const DiagnosticContainer &container)
QDataStream &operator>>(QDataStream &in, DiagnosticContainer &container)
{
quint32 severity;
in >> container.text_;
in >> container.category_;
in >> container.enableOption_;
in >> container.disableOption_;
in >> container.location_;
in >> container.severityAsInt();
in >> severity;
in >> container.ranges_;
in >> container.fixIts_;
in >> container.children_;
container.severity_ = static_cast<DiagnosticSeverity>(severity);
return in;
}
......
......@@ -61,9 +61,6 @@ public:
const QVector<FixItContainer> &fixIts() const;
const QVector<DiagnosticContainer> &children() const;
private:
quint32 &severityAsInt();
private:
SourceLocationContainer location_;
QVector<SourceRangeContainer> ranges_;
......
......@@ -74,14 +74,21 @@ HighlightingTypes HighlightingMarkContainer::types() const
return types_;
}
QDataStream &operator<<(QDataStream &out, HighlightingType highlightingType)
{
out << static_cast<const quint8>(highlightingType);
return out;
}
QDataStream &operator<<(QDataStream &out, HighlightingTypes highlightingTypes)
{
out << reinterpret_cast<const quint8&>(highlightingTypes.mainHighlightingType);
out << highlightingTypes.mainHighlightingType;
out << highlightingTypes.mixinHighlightingTypes.size();
for (HighlightingType type : highlightingTypes.mixinHighlightingTypes)
out << reinterpret_cast<const quint8&>(type);
out << type;
return out;
}
......@@ -96,16 +103,27 @@ QDataStream &operator<<(QDataStream &out, const HighlightingMarkContainer &conta
return out;
}
QDataStream &operator>>(QDataStream &in, HighlightingType &highlightingType)
{
quint8 highlightingTypeInt;
in >> highlightingTypeInt;
highlightingType = static_cast<HighlightingType>(highlightingTypeInt);
return in;
}
QDataStream &operator>>(QDataStream &in, HighlightingTypes &highlightingTypes)
{
in >> reinterpret_cast<quint8&>(highlightingTypes.mainHighlightingType);
in >> highlightingTypes.mainHighlightingType ;
quint8 size;
in >> size;
for (int counter = 0; counter < size; ++counter) {
HighlightingType type;
in >> reinterpret_cast<quint8&>(type);
in >> type;
highlightingTypes.mixinHighlightingTypes.push_back(type);
}
......
......@@ -79,7 +79,7 @@ public:
friend
QDataStream &operator<<(QDataStream &out, const MessageEnvelop &messageEnvelop)
{
out << reinterpret_cast<const quint8&>(messageEnvelop.messageType_);
out << static_cast<const quint8>(messageEnvelop.messageType_);
out << messageEnvelop.data;
return out;
......@@ -88,9 +88,13 @@ public:
friend
QDataStream &operator>>(QDataStream &in, MessageEnvelop &messageEnvelop)
{
in >> reinterpret_cast<quint8&>(messageEnvelop.messageType_);
quint8 messageType;
in >> messageType;
in >> messageEnvelop.data;
messageEnvelop.messageType_ = static_cast<MessageType>(messageType);
return in;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment