]> granicus.if.org Git - clang/commitdiff
Improve our handling of NULL after an escaping '\' in a string
authorDouglas Gregor <dgregor@apple.com>
Sun, 30 May 2010 22:59:50 +0000 (22:59 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sun, 30 May 2010 22:59:50 +0000 (22:59 +0000)
literal. Fixes <rdar://problem/8044135>.

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

lib/Lex/Lexer.cpp
test/Index/complete-exprs.c

index cd153e147b5d44dc13a763d5e57f4d631de2a384..4f2e29e80d44ecab54a6efa5a0e6408d9a455b0a 100644 (file)
@@ -753,11 +753,15 @@ void Lexer::LexStringLiteral(Token &Result, const char *CurPtr, bool Wide) {
   char C = getAndAdvanceChar(CurPtr, Result);
   while (C != '"') {
     // Skip escaped characters.
+    bool Escaped = false;
     if (C == '\\') {
       // Skip the escaped character.
       C = getAndAdvanceChar(CurPtr, Result);
-    } else if (C == '\n' || C == '\r' ||             // Newline.
-               (C == 0 && CurPtr-1 == BufferEnd)) {  // End of file.
+      Escaped = true;
+    } 
+    
+    if ((!Escaped && (C == '\n' || C == '\r')) ||             // Newline.
+        (C == 0 && CurPtr-1 == BufferEnd)) {  // End of file.
       if (!isLexingRawMode() && !Features.AsmPreprocessor)
         Diag(BufferPtr, diag::err_unterminated_string);
       FormTokenWithChars(Result, CurPtr-1, tok::unknown);
@@ -765,6 +769,7 @@ void Lexer::LexStringLiteral(Token &Result, const char *CurPtr, bool Wide) {
     } else if (C == 0) {
       NulCharacter = CurPtr-1;
     }
+
     C = getAndAdvanceChar(CurPtr, Result);
   }
 
index fe30d3329707b99aa113ce33100ffcc70cfdd0a4..b7bed8c5fde8047f9566d04043cf2bfad101f1e5 100644 (file)
@@ -10,6 +10,8 @@ int test(int i, int j, int k, int l) {
 struct X f1 = { 17 };
 void f2() { f1(17); }
 
+const char *str = "Hello, \nWorld";
+
 // RUN: c-index-test -code-completion-at=%s:7:9 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s
 // CHECK-CC1: macro definition:{TypedText __VERSION__} (70)
 // CHECK-CC1: FunctionDecl:{ResultType int}{TypedText f}{LeftParen (}{Placeholder int}{RightParen )} (12)
@@ -35,3 +37,6 @@ void f2() { f1(17); }
 // CHECK-CC4: FunctionDecl:{ResultType int}{TypedText f}{LeftParen (}{Placeholder int}{RightParen )} (50)
 // CHECK-CC4: VarDecl:{ResultType struct X}{TypedText f1} (50)
 
+// RUN: c-index-test -code-completion-at=%s:13:28 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC5 %s
+// CHECK-CC5: NotImplemented:{TypedText void} (40)
+// CHECK-CC5: NotImplemented:{TypedText volatile} (40)