diff mbox

Fix -imacros (PR c/57653)

Message ID 20140723174908.GH30336@redhat.com
State New
Headers show

Commit Message

Marek Polacek July 23, 2014, 5:49 p.m. UTC
On Thu, Jul 17, 2014 at 02:40:27AM -0600, Jeff Law wrote:
> I was really hoping someone could add tests from the old (2004?) thread
> between DJ and Per to ensure we weren't regressing any of those cases while
> fixing 57653.  In fact, I think I'd pre-approved with those tests added ;-)

All I could find was a test (mentioned twice by DJ) that was crashing with
-imacros and an empty .h and .c file.  I added it in the following.
I'm keeping the test I already had in the previous patch, because it
tests something that is fixed with this patch.

Bootstrapped/regtested on x86_64-linux, applying to trunk.

2014-07-23  Marek Polacek  <polacek@redhat.com>

	PR c/57653
	* c-opts.c (c_finish_options): If -imacros is in effect, return.

	* c-c++-common/pr57653.c: New test.
	* c-c++-common/pr57653.h: New file.
	* c-c++-common/pr57653-2.c: New test.
	* c-c++-common/pr57653-2.h: New file.


	Marek

Comments

Jeff Law July 25, 2014, 9:16 p.m. UTC | #1
On 07/23/14 11:49, Marek Polacek wrote:
> On Thu, Jul 17, 2014 at 02:40:27AM -0600, Jeff Law wrote:
>> I was really hoping someone could add tests from the old (2004?) thread
>> between DJ and Per to ensure we weren't regressing any of those cases while
>> fixing 57653.  In fact, I think I'd pre-approved with those tests added ;-)
>
> All I could find was a test (mentioned twice by DJ) that was crashing with
> -imacros and an empty .h and .c file.  I added it in the following.
> I'm keeping the test I already had in the previous patch, because it
> tests something that is fixed with this patch.
>
> Bootstrapped/regtested on x86_64-linux, applying to trunk.
>
> 2014-07-23  Marek Polacek  <polacek@redhat.com>
>
> 	PR c/57653
> 	* c-opts.c (c_finish_options): If -imacros is in effect, return.
>
> 	* c-c++-common/pr57653.c: New test.
> 	* c-c++-common/pr57653.h: New file.
> 	* c-c++-common/pr57653-2.c: New test.
> 	* c-c++-common/pr57653-2.h: New file.
Perfect.  Thanks for picking up the ball on this one.


Jeff
diff mbox

Patch

diff --git gcc/c-family/c-opts.c gcc/c-family/c-opts.c
index 968b703..3f8e6e6 100644
--- gcc/c-family/c-opts.c
+++ gcc/c-family/c-opts.c
@@ -1438,6 +1438,12 @@  c_finish_options (void)
 static void
 push_command_line_include (void)
 {
+  /* This can happen if disabled by -imacros for example.
+     Punt so that we don't set "<command-line>" as the filename for
+     the header.  */
+  if (include_cursor > deferred_count)
+    return;
+
   if (!done_preinclude)
     {
       done_preinclude = true;
diff --git gcc/testsuite/c-c++-common/pr57653-2.c gcc/testsuite/c-c++-common/pr57653-2.c
index e69de29..086f6be 100644
--- gcc/testsuite/c-c++-common/pr57653-2.c
+++ gcc/testsuite/c-c++-common/pr57653-2.c
@@ -0,0 +1,4 @@ 
+/* { dg-do preprocess } */
+/* { dg-options "-imacros ${srcdir}/c-c++-common/pr57653-2.h" } */
+
+/* Empty.  */
diff --git gcc/testsuite/c-c++-common/pr57653-2.h gcc/testsuite/c-c++-common/pr57653-2.h
index e69de29..8b13789 100644
--- gcc/testsuite/c-c++-common/pr57653-2.h
+++ gcc/testsuite/c-c++-common/pr57653-2.h
@@ -0,0 +1 @@ 
+
diff --git gcc/testsuite/c-c++-common/pr57653-3.c gcc/testsuite/c-c++-common/pr57653-3.c
deleted file mode 100644
index e69de29..0000000
diff --git gcc/testsuite/c-c++-common/pr57653.c gcc/testsuite/c-c++-common/pr57653.c
index e69de29..620471e 100644
--- gcc/testsuite/c-c++-common/pr57653.c
+++ gcc/testsuite/c-c++-common/pr57653.c
@@ -0,0 +1,6 @@ 
+/* { dg-do compile } */
+/* { dg-options "-imacros ${srcdir}/c-c++-common/pr57653.h" } */
+
+__attribute__((used)) static const char s[] = F;
+
+/* { dg-final { scan-assembler-not "command-line" } } */
diff --git gcc/testsuite/c-c++-common/pr57653.h gcc/testsuite/c-c++-common/pr57653.h
index e69de29..5a93388 100644
--- gcc/testsuite/c-c++-common/pr57653.h
+++ gcc/testsuite/c-c++-common/pr57653.h
@@ -0,0 +1 @@ 
+#define F __FILE__