[cfe-commits] patch: serialize Sema::UndefinedInternals in PCH

Douglas Gregor dgregor at apple.com
Fri Jan 25 14:41:32 PST 2013


On Jan 25, 2013, at 2:22 PM, Nick Lewycky <nlewycky at google.com> wrote:

> On 25 January 2013 10:18, Douglas Gregor <dgregor at apple.com> wrote:
> 
> On Jan 25, 2013, at 2:32 AM, Nick Lewycky <nlewycky at google.com> wrote:
> 
> > This patch fixes a problem where the PCH fails to faithfully represent the state of Sema, causing it to drop some -Wundefined-internal diagnostics across PCH boundaries.
> >
> > While there I noticed that KnownNamespaces was being emitted in an indeterminate order and added code to sort them deterministically.
> >
> > Please review!
> 
> (Quoting patches on a phone is awful)
> 
> Serialization bits look good.
> 
> Rather than sorting based on source location, how about just changing Sema's data structures for both of these to MapVectors?
> 
> Done.
> 
> Also, I'd rather not renumber the record codes. It's fine to just append to the list, because order is irrelevant.
> 
> Done.
> 
> Updated patch attached. Please review!

Index: test/PCH/undefined-internal.c
===================================================================
--- test/PCH/undefined-internal.c	(revision 0)
+++ test/PCH/undefined-internal.c	(revision 0)
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -emit-pch %S/Inputs/undefined-internal-1.h -o %t
+// RUN: %clang_cc1 -include-pch %t %s -verify
+
+static void g() {}
+
+// expected-warning at 1{{function 'f' has internal linkage but is not defined}}
+// expected-note at 4{{used here}}
Index: test/PCH/Inputs/undefined-internal-1.h
===================================================================
--- test/PCH/Inputs/undefined-internal-1.h	(revision 0)
+++ test/PCH/Inputs/undefined-internal-1.h	(revision 0)
@@ -0,0 +1,6 @@
+static void f();
+static void g();
+void h() {
+  f();
+  g();
+}

You can use #define tricks to collapse this into a single .c file, rather than having a separate .h file, e.g.,

// RUN: %clang_cc1 -emit-pch %s -o %t
// RUN: %clang_cc1 -include-pch %t %s -verify
#ifndef HEADER_H
#define HEADER_H
static void f();
static void g();
void h() {
  f();
  g();
}
#else
static void g()

// expected-warning at NNN{{function 'f' has internal linkage but is not defined}}
// expected-note at MMM{{used here}}
#endif

With that tweak, LGTM.

	- Doug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130125/d6088632/attachment.html>


More information about the cfe-commits mailing list