OSDN Git Service

Properly initialize cpp_context in destringize_and_run
authordodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 2 May 2012 16:55:19 +0000 (16:55 +0000)
committerdodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 2 May 2012 16:55:19 +0000 (16:55 +0000)
destringize_and_run forgets to initialize all the fields of the
cpp_context that it pushes.  Later _cpp_pop_context then gets confused
when it accesses context->tokens_kind via the call to macro_of_context
on context->prev.

The first hunk of this patch is the real obvious fix.  The second hunk
is just an assert that I am adding to err on the safe side.

Tested by on x86_64-unknown-linux-gnu against trunk by running the
test gcc.dg/gomp/macro-4.c under Valgrind, and bootstrapped.

libcpp/

* directives.c (destringize_and_run): Properly initialize the new
context.
* macro.c (_cpp_pop_context): Assert that we shouldn't try to pop
the initial base context, which has the same life time as the
current instance of cpp_file.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@187054 138bc75d-0d04-0410-961f-82ee72b054a4

libcpp/ChangeLog
libcpp/directives.c
libcpp/macro.c

index 2dc1190..7365c4e 100644 (file)
@@ -1,3 +1,12 @@
+2012-05-02  Dodji Seketeli  <dodji@redhat.com>
+
+       Properly initialize cpp_context in destringize_and_run
+       * directives.c (destringize_and_run): Properly initialize the new
+       context.
+       * macro.c (_cpp_pop_context): Assert that we shouldn't try to pop
+       the initial base context, which has the same life time as the
+       current instance of cpp_file.
+
 2012-04-30  Manuel López-Ibáñez  <manu@gcc.gnu.org>
            Dodji Seketeli  <dodji@seketeli.org>
 
index 0510c6e..e46280e 100644 (file)
@@ -1741,10 +1741,7 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in)
   saved_cur_token = pfile->cur_token;
   saved_cur_run = pfile->cur_run;
 
-  pfile->context = XNEW (cpp_context);
-  pfile->context->c.macro = 0;
-  pfile->context->prev = 0;
-  pfile->context->next = 0;
+  pfile->context = XCNEW (cpp_context);
 
   /* Inline run_directive, since we need to delay the _cpp_pop_buffer
      until we've read all of the tokens that we want.  */
index ab3e8f6..c4e2a23 100644 (file)
@@ -2152,6 +2152,10 @@ _cpp_pop_context (cpp_reader *pfile)
 {
   cpp_context *context = pfile->context;
 
+  /* We should not be popping the base context.  */
+  if (context == &pfile->base_context)
+    abort ();
+
   if (context->c.macro)
     {
       cpp_hashnode *macro;