AsmParser: Don't crash on short hex constants for fp128 types
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 9 Dec 2014 19:10:03 +0000 (19:10 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 9 Dec 2014 19:10:03 +0000 (19:10 +0000)
If we see 0xL01, treat it like 0xL00000000000000000000000000000001
instead of crashing.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223811 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/LLLexer.cpp
test/Assembler/short-hexpair.ll [new file with mode: 0644]

index 614a283241ec09a0c89e2cf5a03448036b6e407b..d2ed616e782159aa018aaa156583a8babae6d9ea 100644 (file)
@@ -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/test/Assembler/short-hexpair.ll b/test/Assembler/short-hexpair.ll
new file mode 100644 (file)
index 0000000..067ea30
--- /dev/null
@@ -0,0 +1,4 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+@x = global fp128 0xL01
+; CHECK: @x = global fp128 0xL00000000000000000000000000000001