Skip to content

Commit

Permalink
Updated AsmParser deconstructor to restore saved diagnostic handlers …
Browse files Browse the repository at this point in the history
…back to srcmgr (#419)
  • Loading branch information
brendabrandy authored and aquynh committed Aug 2, 2019
1 parent 34fcbe4 commit c4de98f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/MC/MCParser/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,10 @@ AsmParser::AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
AsmParser::~AsmParser() {
assert((HadError || ActiveMacros.empty()) &&
"Unexpected active macro instantiation!");

// Restore the saved diagnostics handler and context for use during
// finalization
SrcMgr.setDiagHandler(SavedDiagHandler, SavedDiagContext);
}

void AsmParser::printMacroInstantiations() {
Expand Down
22 changes: 22 additions & 0 deletions suite/test_diag_printer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import binascii

from keystone import Ks, KS_ARCH_ARM, KS_MODE_ARM

ks = Ks(KS_ARCH_ARM, KS_MODE_ARM)

assembly_text = \
"""
sub sp, sp, #8
push {sp, lr}
bl #0xc6ab8
ldr lr, [sp, #4]
add sp, sp, #8
pop {r2, r3}
bx lr
"""

for i in range(100):
output = ks.asm(assembly_text, 0x902c4, as_bytes=True)
# print("{}: {}: {}".format(i, assembly_text, output))
output_2 = ks.asm("b #0", 0x4, as_bytes=True)
# print("{}: {}: {}".format(i, "b #0", output_2))
13 changes: 13 additions & 0 deletions suite/test_diag_printer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

for i in $(seq 1 100)
do
python test_diag_printer.py

if [ $? -ne 0 ]
then
echo "Diagnostic Handler test failed"
exit
fi
done
echo "Diagnostic Handler test pass"

0 comments on commit c4de98f

Please sign in to comment.