Skip to content

Commit bc9d690

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Fix duplicate annotation issue
Summary: Our outer annotations can sometimes end up colliding with things that we emit in a LIR instruction. For example "Boxed return wrapper" does a kPrologue instruction. This lets the outer annotation which is more interesting override the inner annotation. Reviewed By: yoney Differential Revision: D103307683 fbshipit-source-id: a832a87338f3038cca7799b51fdf81955e49f555
1 parent 99d8b33 commit bc9d690

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

cinderx/Jit/codegen/annotations.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ std::string Annotations::disassembleSection(
3737
}
3838
auto inserted =
3939
annot_bounds.emplace(begin, std::make_pair(&annot, end)).second;
40-
JIT_DCHECK(inserted, "Duplicate start address for annotation");
40+
JIT_DCHECK(
41+
inserted,
42+
"Duplicate start address for annotation {} {}",
43+
annot.str,
44+
annot_bounds[begin].first->str);
4145
}
4246

4347
Annotation* prev_annot = nullptr;

cinderx/Jit/codegen/environ.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,18 @@ struct Environ {
101101

102102
template <typename T>
103103
void addAnnotation(T&& item, asmjit::BaseNode* start_cursor) {
104+
if (suppress_annotations) {
105+
return;
106+
}
104107
annotations.add(std::forward<T>(item), as, start_cursor);
105108
}
106109

110+
// When true, addAnnotation() calls are suppressed. Set by
111+
// generateAssemblyBody() while a text annotation is active so that
112+
// translator-internal annotations (e.g. "Set up frame pointer") don't
113+
// conflict with the higher-level text annotation.
114+
bool suppress_annotations{false};
115+
107116
// Map of GenYieldPoints which need their resume_target_ setting after code-
108117
// gen is complete.
109118
UnorderedMap<GenYieldPoint*, asmjit::Label> unresolved_gen_entry_labels;

cinderx/Jit/codegen/gen_asm.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,9 @@ void emitLIRBlocks(
453453
annotation_cursor = cursor;
454454
}
455455

456+
env->suppress_annotations = !pending_annotation.empty();
456457
autogen::AutoTranslator::getInstance().translateInstr(env, instr.get());
458+
env->suppress_annotations = false;
457459

458460
if (!pending_annotation.empty()) {
459461
// Under an active annotation — don't emit per-instruction annotations.

0 commit comments

Comments
 (0)