diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h index ce20bdc5c235a..66d79c753d699 100644 --- a/bolt/include/bolt/Core/MCPlusBuilder.h +++ b/bolt/include/bolt/Core/MCPlusBuilder.h @@ -1181,7 +1181,7 @@ class MCPlusBuilder { /// Set the label of \p Inst. This label will be emitted right before \p Inst /// is emitted to MCStreamer. - bool setLabel(MCInst &Inst, MCSymbol *Label, AllocatorIdTy AllocatorId = 0); + bool setLabel(MCInst &Inst, MCSymbol *Label) const; /// Return MCSymbol that represents a target of this instruction at a given /// operand number \p OpNum. If there's no symbol associated with @@ -1816,6 +1816,8 @@ class MCPlusBuilder { const ValueType &addAnnotation(MCInst &Inst, unsigned Index, const ValueType &Val, AllocatorIdTy AllocatorId = 0) { + assert(Index >= MCPlus::MCAnnotation::kGeneric && + "Generic annotation type expected."); assert(!hasAnnotation(Inst, Index)); AnnotationAllocator &Allocator = getAnnotationAllocator(AllocatorId); auto *A = new (Allocator.ValueAllocator) diff --git a/bolt/lib/Core/MCPlusBuilder.cpp b/bolt/lib/Core/MCPlusBuilder.cpp index 79422c554abd2..8c8ebe7d9830d 100644 --- a/bolt/lib/Core/MCPlusBuilder.cpp +++ b/bolt/lib/Core/MCPlusBuilder.cpp @@ -267,15 +267,15 @@ bool MCPlusBuilder::clearOffset(MCInst &Inst) const { } MCSymbol *MCPlusBuilder::getLabel(const MCInst &Inst) const { - if (auto Label = tryGetAnnotationAs(Inst, MCAnnotation::kLabel)) - return *Label; + if (std::optional Label = + getAnnotationOpValue(Inst, MCAnnotation::kLabel)) + return reinterpret_cast(*Label); return nullptr; } -bool MCPlusBuilder::setLabel(MCInst &Inst, MCSymbol *Label, - AllocatorIdTy AllocatorId) { - getOrCreateAnnotationAs(Inst, MCAnnotation::kLabel, AllocatorId) = - Label; +bool MCPlusBuilder::setLabel(MCInst &Inst, MCSymbol *Label) const { + setAnnotationOpValue(Inst, MCAnnotation::kLabel, + reinterpret_cast(Label)); return true; }