[2/2] libcpp: Fix incorrect line information for traditional cpp and #include [PR100904]
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gcc_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gcc_check--master-arm |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_simplebootstrap_build--master-aarch64-bootstrap |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 |
success
|
Test passed
|
Commit Message
After r7-1651-gac81cf0b2bf5efdd7, the location for the error for #include would
be the location on the token. Except in traditional cpp, the location information
for directives is all messed up because first libcpp processes the directive line in traditional
and copies it to a new buffer and then does the lexing using the ISO lexer. This means the location
information for the tokens are wrong and should just grab the location of the directive line instead.
This patch does exactly that. Uses directive line location for traditional cpp when parsing the include.
Bootstrapped and tested on x86_64-linux-gnu.
PR preprocessor/100904
libcpp/ChangeLog:
* directives.cc (parse_include): Use the directive line location
for the location in traditional cpp mode instead of the location
of the token.
gcc/testsuite/ChangeLog:
* gcc.dg/cpp/missing-header-trad-1.c: New test.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
---
gcc/testsuite/gcc.dg/cpp/missing-header-trad-1.c | 10 ++++++++++
libcpp/directives.cc | 9 ++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/cpp/missing-header-trad-1.c
new file mode 100644
@@ -0,0 +1,10 @@
+/* { dg-do preprocess } */
+/* { dg-options "-traditional-cpp" } */
+
+/* PR preprocessor/100904 */
+/* Make sure we error out on the correct line
+ for traditional cpp. */
+
+#include "nonexistent.h" /* { dg-error "-: nonexistent.h" } */
+
+/* { dg-message "terminated" "terminated" { target *-*-* } 0 } */
@@ -841,7 +841,14 @@ parse_include (cpp_reader *pfile, int *pangle_brackets,
/* Allow macro expansion. */
header = get_token_no_padding (pfile);
- *location = header->src_loc;
+
+ /* The location for traditional is the directive line as the
+ token line information for the temporary buffer. */
+ if (CPP_OPTION (pfile, traditional))
+ *location = pfile->directive_line;
+ else
+ *location = header->src_loc;
+
if ((header->type == CPP_STRING && header->val.str.text[0] != 'R')
|| header->type == CPP_HEADER_NAME)
{