[llvm] r205914 - Revert "Revert "YAMLIO: Encode ambiguous hex strings explicitly""

Michael Spencer bigcheesegs at gmail.com
Wed Apr 9 15:30:59 PDT 2014


On Wed, Apr 9, 2014 at 6:04 PM, David Majnemer <david.majnemer at gmail.com> wrote:
> Author: majnemer
> Date: Wed Apr  9 12:04:27 2014
> New Revision: 205914
>
> URL: http://llvm.org/viewvc/llvm-project?rev=205914&view=rev
> Log:
> Revert "Revert "YAMLIO: Encode ambiguous hex strings explicitly""
>
> Don't quote octal compatible strings if they are only two wide, they
> aren't ambiguous.
>
> This reverts commit r205857 which reverted r205857.
>
> Modified:
>     llvm/trunk/lib/Support/YAMLTraits.cpp
>     llvm/trunk/test/Object/obj2yaml.test
>     llvm/trunk/unittests/Support/YAMLIOTest.cpp
>
> Modified: llvm/trunk/lib/Support/YAMLTraits.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/YAMLTraits.cpp?rev=205914&r1=205913&r2=205914&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/YAMLTraits.cpp (original)
> +++ llvm/trunk/lib/Support/YAMLTraits.cpp Wed Apr  9 12:04:27 2014
> @@ -561,8 +561,9 @@ void Output::scalarString(StringRef &S)
>      this->outputUpToEndOfLine("''");
>      return;
>    }
> +  bool isOctalString = S.front() == '0' && S.size() > 2 && !S.startswith("0x");

wat. This makes no sense. 08 is not even valid in YAML 1.1. The
problem here is that Output::scalarString is being used for all output
types. This isn't right. We need to change things so that it is only
used for !!str types.

When it is used for !!str types, it needs to add quotes for anything
that would not be parsed as a !!str type.

- Michael Spencer

>    if (S.find_first_not_of(ScalarSafeChars) == StringRef::npos &&
> -      !isspace(S.front()) && !isspace(S.back())) {
> +      !isspace(S.front()) && !isspace(S.back()) && !isOctalString) {
>      // If the string consists only of safe characters, print it out without
>      // quotes.
>      this->outputUpToEndOfLine(S);
>
> Modified: llvm/trunk/test/Object/obj2yaml.test
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/obj2yaml.test?rev=205914&r1=205913&r2=205914&view=diff
> ==============================================================================
> --- llvm/trunk/test/Object/obj2yaml.test (original)
> +++ llvm/trunk/test/Object/obj2yaml.test Wed Apr  9 12:04:27 2014
> @@ -115,7 +115,7 @@ COFF-X86-64-NEXT:     SectionData: 48656
>  COFF-X86-64:        - Name: '.CRT$XCU'
>  COFF-X86-64-NEXT:     Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
>  COFF-X86-64-NEXT:     Alignment: 8
> -COFF-X86-64-NEXT:     SectionData:  0000000000000000
> +COFF-X86-64-NEXT:     SectionData:  '0000000000000000'
>
>  COFF-X86-64:     Relocations:
>  COFF-X86-64-NEXT:       - VirtualAddress: 0
>
> Modified: llvm/trunk/unittests/Support/YAMLIOTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/YAMLIOTest.cpp?rev=205914&r1=205913&r2=205914&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/Support/YAMLIOTest.cpp (original)
> +++ llvm/trunk/unittests/Support/YAMLIOTest.cpp Wed Apr  9 12:04:27 2014
> @@ -302,11 +302,13 @@ struct StringTypes {
>    llvm::StringRef str3;
>    llvm::StringRef str4;
>    llvm::StringRef str5;
> +  llvm::StringRef str6;
>    std::string stdstr1;
>    std::string stdstr2;
>    std::string stdstr3;
>    std::string stdstr4;
>    std::string stdstr5;
> +  std::string stdstr6;
>  };
>
>  namespace llvm {
> @@ -319,11 +321,13 @@ namespace yaml {
>        io.mapRequired("str3",      st.str3);
>        io.mapRequired("str4",      st.str4);
>        io.mapRequired("str5",      st.str5);
> +      io.mapRequired("str6",      st.str6);
>        io.mapRequired("stdstr1",   st.stdstr1);
>        io.mapRequired("stdstr2",   st.stdstr2);
>        io.mapRequired("stdstr3",   st.stdstr3);
>        io.mapRequired("stdstr4",   st.stdstr4);
>        io.mapRequired("stdstr5",   st.stdstr5);
> +      io.mapRequired("stdstr6",   st.stdstr6);
>      }
>    };
>  }
> @@ -338,11 +342,13 @@ TEST(YAMLIO, TestReadWriteStringTypes) {
>      map.str3 = "`ccc";
>      map.str4 = "@ddd";
>      map.str5 = "";
> +    map.str6 = "0000000004000000";
>      map.stdstr1 = "'eee";
>      map.stdstr2 = "\"fff";
>      map.stdstr3 = "`ggg";
>      map.stdstr4 = "@hhh";
>      map.stdstr5 = "";
> +    map.stdstr6 = "0000000004000000";
>
>      llvm::raw_string_ostream ostr(intermediate);
>      Output yout(ostr);
> @@ -355,11 +361,13 @@ TEST(YAMLIO, TestReadWriteStringTypes) {
>    EXPECT_NE(llvm::StringRef::npos, flowOut.find("'`ccc'"));
>    EXPECT_NE(llvm::StringRef::npos, flowOut.find("'@ddd'"));
>    EXPECT_NE(llvm::StringRef::npos, flowOut.find("''\n"));
> +  EXPECT_NE(llvm::StringRef::npos, flowOut.find("'0000000004000000'\n"));
>    EXPECT_NE(std::string::npos, flowOut.find("'''eee"));
>    EXPECT_NE(std::string::npos, flowOut.find("'\"fff'"));
>    EXPECT_NE(std::string::npos, flowOut.find("'`ggg'"));
>    EXPECT_NE(std::string::npos, flowOut.find("'@hhh'"));
>    EXPECT_NE(std::string::npos, flowOut.find("''\n"));
> +  EXPECT_NE(std::string::npos, flowOut.find("'0000000004000000'\n"));
>
>    {
>      Input yin(intermediate);
> @@ -372,11 +380,13 @@ TEST(YAMLIO, TestReadWriteStringTypes) {
>      EXPECT_TRUE(map.str3.equals("`ccc"));
>      EXPECT_TRUE(map.str4.equals("@ddd"));
>      EXPECT_TRUE(map.str5.equals(""));
> +    EXPECT_TRUE(map.str6.equals("0000000004000000"));
>      EXPECT_TRUE(map.stdstr1 == "'eee");
>      EXPECT_TRUE(map.stdstr2 == "\"fff");
>      EXPECT_TRUE(map.stdstr3 == "`ggg");
>      EXPECT_TRUE(map.stdstr4 == "@hhh");
>      EXPECT_TRUE(map.stdstr5 == "");
> +    EXPECT_TRUE(map.stdstr6 == "0000000004000000");
>    }
>  }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list