[PATCH] Fix for #pragma warning to work correctly with "1-4:" specifiers

Reid Kleckner rnk at google.com
Tue May 19 09:25:27 PDT 2015


Can you add a -E test that verifies that these pragmas roundtrip through the pre-processor?


================
Comment at: lib/Lex/Pragma.cpp:1075
@@ +1074,3 @@
+        bool SpecifierValid;
+        StringRef Specifier;
+        if (II) {
----------------
Make sure the SmallString has the same lifetime as Specifier.

================
Comment at: lib/Lex/Pragma.cpp:1091
@@ +1090,3 @@
+            SpecifierValid = (Value >= 1) && (Value <= 4);
+            Specifier = llvm::utostr(Value);
+          } else
----------------
utostr returns a std::string, so this would be a use-after-free. Use getSpelling() to get a StringRef that points into the original source code so we don't need memory allocation. You'll need to supply a SmallString, but 99% of the time it'll be unused.

http://reviews.llvm.org/D9856

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list