From 2defbada38d1a8fe8c215aa162b26e4db19e69b3 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 9 Dec 2014 19:10:03 +0000 Subject: [PATCH] AsmParser: Don't crash on short hex constants for fp128 types If we see 0xL01, treat it like 0xL00000000000000000000000000000001 instead of crashing. llvm-svn: 223811 --- llvm/lib/AsmParser/LLLexer.cpp | 12 +++++++----- llvm/test/Assembler/short-hexpair.ll | 4 ++++ 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 llvm/test/Assembler/short-hexpair.ll diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp index 614a283241ec..d2ed616e7821 100644 --- a/llvm/lib/AsmParser/LLLexer.cpp +++ b/llvm/lib/AsmParser/LLLexer.cpp @@ -78,13 +78,15 @@ uint64_t LLLexer::HexIntToVal(const char *Buffer, const char *End) { void LLLexer::HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]) { Pair[0] = 0; - for (int i=0; i<16; i++, Buffer++) { - assert(Buffer != End); - Pair[0] *= 16; - Pair[0] += hexDigitValue(*Buffer); + if (End - Buffer >= 16) { + for (int i = 0; i < 16; i++, Buffer++) { + assert(Buffer != End); + Pair[0] *= 16; + Pair[0] += hexDigitValue(*Buffer); + } } Pair[1] = 0; - for (int i=0; i<16 && Buffer != End; i++, Buffer++) { + for (int i = 0; i < 16 && Buffer != End; i++, Buffer++) { Pair[1] *= 16; Pair[1] += hexDigitValue(*Buffer); } diff --git a/llvm/test/Assembler/short-hexpair.ll b/llvm/test/Assembler/short-hexpair.ll new file mode 100644 index 000000000000..067ea30b0ddb --- /dev/null +++ b/llvm/test/Assembler/short-hexpair.ll @@ -0,0 +1,4 @@ +; RUN: llvm-as < %s | llvm-dis | FileCheck %s + +@x = global fp128 0xL01 +; CHECK: @x = global fp128 0xL00000000000000000000000000000001