[PATCH] D21074: Correct invalid end location in diagnostics for some identifiers.
Erik Verbruggen via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 7 07:34:45 PDT 2016
erikjv created this revision.
erikjv added reviewers: bkramer, klimek.
erikjv added a subscriber: cfe-commits.
Declaration names in DeclSpec had only their start set to a valid
location, so when the type specifier was missing, only the carret would
be shown at the first character of the name of a member declaration. Now
the whole identifier is underlined, which is useful for IDEs using
libclang.
Also, when the lookup for an identifier-expression failed, the end
location for that identifier was invalid.
Fixes PR25374.
http://reviews.llvm.org/D21074
Files:
lib/Lex/Lexer.cpp
test/Lexer/preamble.c
test/Lexer/preamble2.c
Index: test/Lexer/preamble2.c
===================================================================
--- /dev/null
+++ test/Lexer/preamble2.c
@@ -0,0 +1,19 @@
+// Preamble detection test: header with an include guard.
+#ifndef HEADER_H
+#define HEADER_H
+#include "foo"
+int bar;
+#endif
+
+// This test checks for detection of the preamble of a file, which
+// includes all of the starting comments and #includes.
+
+// RUN: %clang_cc1 -print-preamble %s > %t
+// RUN: echo END. >> %t
+// RUN: FileCheck < %t %s
+
+// CHECK: // Preamble detection test: header with an include guard.
+// CHECK-NEXT: #ifndef HEADER_H
+// CHECK-NEXT: #define HEADER_H
+// CHECK-NEXT: #include "foo"
+// CHECK-NEXT: END.
Index: test/Lexer/preamble.c
===================================================================
--- test/Lexer/preamble.c
+++ test/Lexer/preamble.c
@@ -9,15 +9,12 @@
#pragma unknown
#endif
#ifdef WIBBLE
-#include "honk"
-#else
-int foo();
+#include "foo"
+int bar;
#endif
// This test checks for detection of the preamble of a file, which
-// includes all of the starting comments and #includes. Note that any
-// changes to the preamble part of this file must be mirrored in
-// Inputs/preamble.txt, since we diff against it.
+// includes all of the starting comments and #includes.
// RUN: %clang_cc1 -print-preamble %s > %t
// RUN: echo END. >> %t
@@ -33,4 +30,6 @@
// CHECK-NEXT: #endif
// CHECK-NEXT: #pragma unknown
// CHECK-NEXT: #endif
+// CHECK-NEXT: #ifdef WIBBLE
+// CHECK-NEXT: #include "foo"
// CHECK-NEXT: END.
Index: lib/Lex/Lexer.cpp
===================================================================
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -552,7 +552,7 @@
bool InPreprocessorDirective = false;
Token TheTok;
Token IfStartTok;
- unsigned IfCount = 0;
+ int IfCount = 0;
SourceLocation ActiveCommentLoc;
unsigned MaxLineOffset = 0;
@@ -656,8 +656,10 @@
case PDK_EndIf:
// Mismatched #endif. The preamble ends here.
- if (IfCount == 0)
+ if (IfCount == 0) {
+ --IfCount;
break;
+ }
--IfCount;
continue;
@@ -682,7 +684,8 @@
} while (true);
SourceLocation End;
- if (IfCount)
+ if (IfCount < 0) // This allows for open #ifs, so a header with an include
+ // guard will have a preamble generated for it.
End = IfStartTok.getLocation();
else if (ActiveCommentLoc.isValid())
End = ActiveCommentLoc; // don't truncate a decl comment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21074.59885.patch
Type: text/x-patch
Size: 2537 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160607/935075ba/attachment-0001.bin>
More information about the cfe-commits
mailing list