llvm.org GIT mirror llvm / 7184f49
YAMLIO: Encode ambiguous hex strings explicitly YAMLIO would turn a BinaryRef into the string 0000000004000000. However, the leading zero causes parsers to interpret it as being an octal number instead of a hexadecimal one. Instead, escape such strings as needed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205839 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 6 years ago
3 changed file(s) with 15 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
560560 this->outputUpToEndOfLine("''");
561561 return;
562562 }
563 bool isOctalString = S.front() == '0' &&
564 S.find_first_not_of('0') != StringRef::npos &&
565 !S.startswith_lower("0x");
563566 if (S.find_first_not_of(ScalarSafeChars) == StringRef::npos &&
564 !isspace(S.front()) && !isspace(S.back())) {
567 !isspace(S.front()) && !isspace(S.back()) && !isOctalString) {
565568 // If the string consists only of safe characters, print it out without
566569 // quotes.
567570 this->outputUpToEndOfLine(S);
3737 #CFG: Type: Data
3838
3939 ## 4: 06 (bad)
40 #CFG: Content: 06
40 #CFG: Content: '06'
4141
4242 #CFG: - StartAddress: 0x0000000000000005
4343 #CFG: Size: 1
301301 llvm::StringRef str3;
302302 llvm::StringRef str4;
303303 llvm::StringRef str5;
304 llvm::StringRef str6;
304305 std::string stdstr1;
305306 std::string stdstr2;
306307 std::string stdstr3;
307308 std::string stdstr4;
308309 std::string stdstr5;
310 std::string stdstr6;
309311 };
310312
311313 namespace llvm {
318320 io.mapRequired("str3", st.str3);
319321 io.mapRequired("str4", st.str4);
320322 io.mapRequired("str5", st.str5);
323 io.mapRequired("str6", st.str6);
321324 io.mapRequired("stdstr1", st.stdstr1);
322325 io.mapRequired("stdstr2", st.stdstr2);
323326 io.mapRequired("stdstr3", st.stdstr3);
324327 io.mapRequired("stdstr4", st.stdstr4);
325328 io.mapRequired("stdstr5", st.stdstr5);
329 io.mapRequired("stdstr6", st.stdstr6);
326330 }
327331 };
328332 }
337341 map.str3 = "`ccc";
338342 map.str4 = "@ddd";
339343 map.str5 = "";
344 map.str6 = "0000000004000000";
340345 map.stdstr1 = "'eee";
341346 map.stdstr2 = "\"fff";
342347 map.stdstr3 = "`ggg";
343348 map.stdstr4 = "@hhh";
344349 map.stdstr5 = "";
350 map.stdstr6 = "0000000004000000";
345351
346352 llvm::raw_string_ostream ostr(intermediate);
347353 Output yout(ostr);
354360 EXPECT_NE(llvm::StringRef::npos, flowOut.find("'`ccc'"));
355361 EXPECT_NE(llvm::StringRef::npos, flowOut.find("'@ddd'"));
356362 EXPECT_NE(llvm::StringRef::npos, flowOut.find("''\n"));
363 EXPECT_NE(llvm::StringRef::npos, flowOut.find("'0000000004000000'\n"));
357364 EXPECT_NE(std::string::npos, flowOut.find("'''eee"));
358365 EXPECT_NE(std::string::npos, flowOut.find("'\"fff'"));
359366 EXPECT_NE(std::string::npos, flowOut.find("'`ggg'"));
360367 EXPECT_NE(std::string::npos, flowOut.find("'@hhh'"));
361368 EXPECT_NE(std::string::npos, flowOut.find("''\n"));
369 EXPECT_NE(std::string::npos, flowOut.find("'0000000004000000'\n"));
362370
363371 {
364372 Input yin(intermediate);
371379 EXPECT_TRUE(map.str3.equals("`ccc"));
372380 EXPECT_TRUE(map.str4.equals("@ddd"));
373381 EXPECT_TRUE(map.str5.equals(""));
382 EXPECT_TRUE(map.str6.equals("0000000004000000"));
374383 EXPECT_TRUE(map.stdstr1 == "'eee");
375384 EXPECT_TRUE(map.stdstr2 == "\"fff");
376385 EXPECT_TRUE(map.stdstr3 == "`ggg");
377386 EXPECT_TRUE(map.stdstr4 == "@hhh");
378387 EXPECT_TRUE(map.stdstr5 == "");
388 EXPECT_TRUE(map.stdstr6 == "0000000004000000");
379389 }
380390 }
381391