1 /* C++ modules. Experimental!
2 Copyright (C) 2017-2021 Free Software Foundation, Inc.
3 Written by Nathan Sidwell <nathan@acm.org> while at FaceBook
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* Comments in this file have a non-negligible chance of being wrong
22 or at least inaccurate. Due to (a) my misunderstanding, (b)
23 ambiguities that I have interpretted differently to original intent
24 (c) changes in the specification, (d) my poor wording, (e) source
27 /* (Incomplete) Design Notes
29 A hash table contains all module names. Imported modules are
30 present in a modules array, which by construction places an
31 import's dependencies before the import itself. The single
32 exception is the current TU, which always occupies slot zero (even
33 when it is not a module).
35 Imported decls occupy an entity_ary, an array of binding_slots, indexed
36 by importing module and index within that module. A flat index is
37 used, as each module reserves a contiguous range of indices.
38 Initially each slot indicates the CMI section containing the
39 streamed decl. When the decl is imported it will point to the decl
42 Additionally each imported decl is mapped in the entity_map via its
43 DECL_UID to the flat index in the entity_ary. Thus we can locate
44 the index for any imported decl by using this map and then
45 de-flattening the index via a binary seach of the module vector.
46 Cross-module references are by (remapped) module number and
49 Each importable DECL contains several flags. The simple set are
50 DECL_EXPORT_P, DECL_MODULE_PURVIEW_P and DECL_MODULE_IMPORT_P. The
51 first indicates whether it is exported, the second whether it is in
52 the module purview (as opposed to the global module fragment), and
53 the third indicates whether it was an import into this TU or not.
55 The more detailed flags are DECL_MODULE_PARTITION_P,
56 DECL_MODULE_ENTITY_P & DECL_MODULE_PENDING_SPECIALIZATIONS_P. The
57 first is set in a primary interface unit on decls that were read
58 from module partitions (these will have DECL_MODULE_IMPORT_P set
59 too). Such decls will be streamed out to the primary's CMI.
60 DECL_MODULE_ENTITY_P is set when an entity is imported, even if it
61 matched a non-imported entity. Such a decl will not have
62 DECL_MODULE_IMPORT_P set, even though it has an entry in the entity
63 map and array. DECL_MODULE_PENDING_SPECIALIZATIONS_P is set on a
64 primary template, and indicates there are specializations that
65 should be streamed in before trying to specialize this template.
67 Header units are module-like.
69 For namespace-scope lookup, the decls for a particular module are
70 held located in a sparse array hanging off the binding of the name.
71 This is partitioned into two: a few fixed slots at the start
72 followed by the sparse slots afterwards. By construction we only
73 need to append new slots to the end -- there is never a need to
74 insert in the middle. The fixed slots are MODULE_SLOT_CURRENT for
75 the current TU (regardless of whether it is a module or not),
76 MODULE_SLOT_GLOBAL and MODULE_SLOT_PARTITION. These latter two
77 slots are used for merging entities across the global module and
78 module partitions respectively. MODULE_SLOT_PARTITION is only
79 present in a module. Neither of those two slots is searched during
80 name lookup -- they are internal use only. This vector is created
81 lazily once we require it, if there is only a declaration from the
82 current TU, a regular binding is present. It is converted on
85 OPTIMIZATION: Outside of the current TU, we only need ADL to work.
86 We could optimize regular lookup for the current TU by glomming all
87 the visible decls on its slot. Perhaps wait until design is a
88 little more settled though.
90 There is only one instance of each extern-linkage namespace. It
91 appears in every module slot that makes it visible. It also
92 appears in MODULE_SLOT_GLOBAL. (It is an ODR violation if they
93 collide with some other global module entity.) We also have an
94 optimization that shares the slot for adjacent modules that declare
95 the same such namespace.
97 A module interface compilation produces a Compiled Module Interface
98 (CMI). The format used is Encapsulated Lazy Records Of Numbered
99 Declarations, which is essentially ELF's section encapsulation. (As
100 all good nerds are aware, Elrond is half Elf.) Some sections are
101 named, and contain information about the module as a whole (indices
102 etc), and other sections are referenced by number. Although I
103 don't defend against actively hostile CMIs, there is some
104 checksumming involved to verify data integrity. When dumping out
105 an interface, we generate a graph of all the
106 independently-redeclarable DECLS that are needed, and the decls
107 they reference. From that we determine the strongly connected
108 components (SCC) within this TU. Each SCC is dumped to a separate
109 numbered section of the CMI. We generate a binding table section,
110 mapping each namespace&name to a defining section. This allows
113 Lazy loading employs mmap to map a read-only image of the CMI.
114 It thus only occupies address space and is paged in on demand,
115 backed by the CMI file itself. If mmap is unavailable, regular
116 FILEIO is used. Also, there's a bespoke ELF reader/writer here,
117 which implements just the section table and sections (including
118 string sections) of a 32-bit ELF in host byte-order. You can of
119 course inspect it with readelf. I figured 32-bit is sufficient,
120 for a single module. I detect running out of section numbers, but
121 do not implement the ELF overflow mechanism. At least you'll get
122 an error if that happens.
124 We do not separate declarations and definitions. My guess is that
125 if you refer to the declaration, you'll also need the definition
126 (template body, inline function, class definition etc). But this
127 does mean we can get larger SCCs than if we separated them. It is
128 unclear whether this is a win or not.
130 Notice that we embed section indices into the contents of other
131 sections. Thus random manipulation of the CMI file by ELF tools
132 may well break it. The kosher way would probably be to introduce
133 indirection via section symbols, but that would require defining a
136 Notice that lazy loading of one module's decls can cause lazy
137 loading of other decls in the same or another module. Clearly we
138 want to avoid loops. In a correct program there can be no loops in
139 the module dependency graph, and the above-mentioned SCC algorithm
140 places all intra-module circular dependencies in the same SCC. It
141 also orders the SCCs wrt each other, so dependent SCCs come first.
142 As we load dependent modules first, we know there can be no
143 reference to a higher-numbered module, and because we write out
144 dependent SCCs first, likewise for SCCs within the module. This
145 allows us to immediately detect broken references. When loading,
146 we must ensure the rest of the compiler doesn't cause some
147 unconnected load to occur (for instance, instantiate a template).
155 bytes - data streamer
156 bytes_in : bytes - scalar reader
157 bytes_out : bytes - scalar writer
160 elf_in : elf - ELROND reader
161 elf_out : elf - ELROND writer
163 trees_in : bytes_in - tree reader
164 trees_out : bytes_out - tree writer
166 depset - dependency set
167 depset::hash - hash table of depsets
168 depset::tarjan - SCC determinator
170 uidset<T> - set T's related to a UID
171 uidset<T>::hash hash table of uidset<T>
173 loc_spans - location map data
175 module_state - module object
177 slurping - data needed during loading
179 macro_import - imported macro data
180 macro_export - exported macro data
182 The ELROND objects use mmap, for both reading and writing. If mmap
183 is unavailable, fileno IO is used to read and write blocks of data.
185 The mapper object uses fileno IO to communicate with the server or
188 /* In expermental (trunk) sources, MODULE_VERSION is a #define passed
189 in from the Makefile. It records the modification date of the
190 source directory -- that's the only way to stay sane. In release
191 sources, we (plan to) use the compiler's major.minor versioning.
192 While the format might not change between at minor versions, it
193 seems simplest to tie the two together. There's no concept of
194 inter-version compatibility. */
195 #define IS_EXPERIMENTAL(V) ((V) >= (1U << 20))
196 #define MODULE_MAJOR(V) ((V) / 10000)
197 #define MODULE_MINOR(V) ((V) % 10000)
198 #define EXPERIMENT(A,B) (IS_EXPERIMENTAL (MODULE_VERSION) ? (A) : (B))
199 #ifndef MODULE_VERSION
200 // Be sure you're ready! Remove #error this before release!
201 #error "Shtopp! What are you doing? This is not ready yet."
202 #include "bversion.h"
203 #define MODULE_VERSION (BUILDING_GCC_MAJOR * 10000U + BUILDING_GCC_MINOR)
204 #elif !IS_EXPERIMENTAL (MODULE_VERSION)
205 #error "This is not the version I was looking for."
208 #define _DEFAULT_SOURCE 1 /* To get TZ field of struct tm, if available. */
210 #define INCLUDE_STRING
211 #define INCLUDE_VECTOR
213 #include "coretypes.h"
216 #include "stringpool.h"
217 #include "dumpfile.h"
220 #include "tree-iterator.h"
224 #include "libiberty.h"
225 #include "stor-layout.h"
227 #include "tree-diagnostic.h"
232 #include "langhooks.h"
233 /* This TU doesn't need or want to see the networking. */
234 #define CODY_NETWORKING 0
235 #include "mapper-client.h"
237 #if 0 // 1 for testing no mmap
238 #define MAPPED_READING 0
239 #define MAPPED_WRITING 0
241 #if HAVE_MMAP_FILE && _POSIX_MAPPED_FILES > 0
243 #define MAPPED_READING 1
244 #if HAVE_SYSCONF && defined (_SC_PAGE_SIZE)
245 /* msync, sysconf (_SC_PAGE_SIZE), ftruncate */
246 /* posix_fallocate used if available. */
247 #define MAPPED_WRITING 1
249 #define MAPPED_WRITING 0
252 #define MAPPED_READING 0
253 #define MAPPED_WRITING 0
257 /* Some open(2) flag differences, what a colourful world it is! */
258 #if defined (O_CLOEXEC)
260 #elif defined (_O_NOINHERIT)
261 /* Windows' _O_NOINHERIT matches O_CLOEXEC flag */
262 #define O_CLOEXEC _O_NOINHERIT
266 #if defined (O_BINARY)
268 #elif defined (_O_BINARY)
269 /* Windows' open(2) call defaults to text! */
270 #define O_BINARY _O_BINARY
275 static inline cpp_hashnode
*cpp_node (tree id
)
277 return CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (id
));
279 static inline tree
identifier (cpp_hashnode
*node
)
281 return HT_IDENT_TO_GCC_IDENT (HT_NODE (node
));
283 static inline const_tree
identifier (const cpp_hashnode
*node
)
285 return identifier (const_cast <cpp_hashnode
*> (node
));
288 /* During duplicate detection we need to tell some comparators that
289 these are equivalent. */
290 tree map_context_from
;
293 /* Id for dumping module information. */
296 /* We have a special module owner. */
297 #define MODULE_UNKNOWN (~0U) /* Not yet known. */
299 /* Prefix for section names. */
300 #define MOD_SNAME_PFX ".gnu.c++"
302 /* Format a version for user consumption. */
304 typedef char verstr_t
[32];
306 version2string (unsigned version
, verstr_t
&out
)
308 unsigned major
= MODULE_MAJOR (version
);
309 unsigned minor
= MODULE_MINOR (version
);
311 if (IS_EXPERIMENTAL (version
))
312 sprintf (out
, "%04u/%02u/%02u-%02u:%02u%s",
313 2000 + major
/ 10000, (major
/ 100) % 100, (major
% 100),
314 minor
/ 100, minor
% 100,
315 EXPERIMENT ("", " (experimental)"));
317 sprintf (out
, "%u.%u", major
, minor
);
320 /* Include files to note translation for. */
321 static vec
<const char *, va_heap
, vl_embed
> *note_includes
;
323 /* Traits to hash an arbitrary pointer. Entries are not deletable,
324 and removal is a noop (removal needed upon destruction). */
325 template <typename T
>
326 struct nodel_ptr_hash
: pointer_hash
<T
>, typed_noop_remove
<T
*> {
327 /* Nothing is deletable. Everything is insertable. */
328 static bool is_deleted (T
*) { return false; }
329 static void mark_deleted (T
*) { gcc_unreachable (); }
332 /* Map from pointer to signed integer. */
333 typedef simple_hashmap_traits
<nodel_ptr_hash
<void>, int> ptr_int_traits
;
334 typedef hash_map
<void *,signed,ptr_int_traits
> ptr_int_hash_map
;
336 /********************************************************************/
337 /* Basic streaming & ELF. Serialization is usually via mmap. For
338 writing we slide a buffer over the output file, syncing it
339 approproiately. For reading we simply map the whole file (as a
340 file-backed read-only map -- it's just address space, leaving the
341 OS pager to deal with getting the data to us). Some buffers need
342 to be more conventional malloc'd contents. */
344 /* Variable length buffer. */
350 /* Tools tend to moan if the dtor's not virtual. */
351 virtual ~allocator () {}
354 void grow (data
&obj
, unsigned needed
, bool exact
);
355 void shrink (data
&obj
);
358 virtual char *grow (char *ptr
, unsigned needed
);
359 virtual void shrink (char *ptr
);
363 char *buffer
; /* Buffer being transferred. */
364 /* Although size_t would be the usual size, we know we never get
365 more than 4GB of buffer -- because that's the limit of the
366 encapsulation format. And if you need bigger imports, you're
368 unsigned size
; /* Allocated size of buffer. */
369 unsigned pos
; /* Position in buffer. */
373 :buffer (NULL
), size (0), pos (0)
378 /* Make sure the derived and/or using class know what they're
380 gcc_checking_assert (!buffer
);
384 char *use (unsigned count
)
386 if (size
< pos
+ count
)
388 char *res
= &buffer
[pos
];
394 void unuse (unsigned count
)
400 static allocator simple_memory
;
403 /* The simple data allocator. */
404 data::allocator
data::simple_memory
;
406 /* Grow buffer to at least size NEEDED. */
409 data::allocator::grow (data
&obj
, unsigned needed
, bool exact
)
411 gcc_checking_assert (needed
? needed
> obj
.size
: !obj
.size
);
413 /* Pick a default size. */
414 needed
= EXPERIMENT (100, 1000);
418 obj
.buffer
= grow (obj
.buffer
, needed
);
422 obj
.pos
= obj
.size
= 0;
428 data::allocator::shrink (data
&obj
)
436 data::allocator::grow (char *ptr
, unsigned needed
)
438 return XRESIZEVAR (char, ptr
, needed
);
442 data::allocator::shrink (char *ptr
)
447 /* Byte streamer base. Buffer with read/write position and smarts
450 class bytes
: public data
{
455 uint32_t bit_val
; /* Bit buffer. */
456 unsigned bit_pos
; /* Next bit in bit buffer. */
460 :parent (), bit_val (0), bit_pos (0)
467 unsigned calc_crc (unsigned) const;
470 /* Finish bit packet. Rewind the bytes not used. */
471 unsigned bit_flush ()
473 gcc_assert (bit_pos
);
474 unsigned bytes
= (bit_pos
+ 7) / 8;
482 /* Calculate the crc32 of the buffer. Note the CRC is stored in the
483 first 4 bytes, so don't include them. */
486 bytes::calc_crc (unsigned l
) const
489 for (size_t ix
= 4; ix
< l
; ix
++)
490 crc
= crc32_byte (crc
, buffer
[ix
]);
496 /* Byte stream reader. */
498 class bytes_in
: public bytes
{
499 typedef bytes parent
;
502 bool overrun
; /* Sticky read-too-much flag. */
506 : parent (), overrun (false)
514 /* Begin reading a named section. */
515 bool begin (location_t loc
, elf_in
*src
, const char *name
);
516 /* Begin reading a numbered section with optional name. */
517 bool begin (location_t loc
, elf_in
*src
, unsigned, const char * = NULL
);
518 /* Complete reading a buffer. Propagate errors and return true on
520 bool end (elf_in
*src
);
521 /* Return true if there is unread data. */
528 /* Start reading at OFFSET. */
529 void random_access (unsigned offset
)
534 bit_pos
= bit_val
= 0;
538 void align (unsigned boundary
)
540 if (unsigned pad
= pos
& (boundary
- 1))
541 read (boundary
- pad
);
545 const char *read (unsigned count
)
547 char *ptr
= use (count
);
554 bool check_crc () const;
555 /* We store the CRC in the first 4 bytes, using host endianness. */
556 unsigned get_crc () const
558 return *(const unsigned *)&buffer
[0];
562 /* Manipulate the overrun flag. */
563 bool get_overrun () const
573 unsigned u32 (); /* Read uncompressed integer. */
576 bool b (); /* Read a bool. */
577 void bflush (); /* Completed a block of bools. */
580 void bfill (); /* Get the next block of bools. */
583 int c (); /* Read a char. */
584 int i (); /* Read a signed int. */
585 unsigned u (); /* Read an unsigned int. */
586 size_t z (); /* Read a size_t. */
587 HOST_WIDE_INT
wi (); /* Read a HOST_WIDE_INT. */
588 unsigned HOST_WIDE_INT
wu (); /* Read an unsigned HOST_WIDE_INT. */
589 const char *str (size_t * = NULL
); /* Read a string. */
590 const void *buf (size_t); /* Read a fixed-length buffer. */
591 cpp_hashnode
*cpp_node (); /* Read a cpp node. */
594 /* Verify the buffer's CRC is correct. */
597 bytes_in::check_crc () const
602 unsigned c_crc
= calc_crc (size
);
603 if (c_crc
!= get_crc ())
611 /* Byte stream writer. */
613 class bytes_out
: public bytes
{
614 typedef bytes parent
;
617 allocator
*memory
; /* Obtainer of memory. */
620 bytes_out (allocator
*memory
)
621 : parent (), memory (memory
)
629 bool streaming_p () const
631 return memory
!= NULL
;
635 void set_crc (unsigned *crc_ptr
);
638 /* Begin writing, maybe reserve space for CRC. */
639 void begin (bool need_crc
= true);
640 /* Finish writing. Spill to section by number. */
641 unsigned end (elf_out
*, unsigned, unsigned *crc_ptr
= NULL
);
644 void align (unsigned boundary
)
646 if (unsigned pad
= pos
& (boundary
- 1))
647 write (boundary
- pad
);
651 char *write (unsigned count
, bool exact
= false)
653 if (size
< pos
+ count
)
654 memory
->grow (*this, pos
+ count
, exact
);
659 void u32 (unsigned); /* Write uncompressed integer. */
662 void b (bool); /* Write bool. */
663 void bflush (); /* Finish block of bools. */
666 void c (unsigned char); /* Write unsigned char. */
667 void i (int); /* Write signed int. */
668 void u (unsigned); /* Write unsigned int. */
669 void z (size_t s
); /* Write size_t. */
670 void wi (HOST_WIDE_INT
); /* Write HOST_WIDE_INT. */
671 void wu (unsigned HOST_WIDE_INT
); /* Write unsigned HOST_WIDE_INT. */
672 void str (const char *ptr
)
674 str (ptr
, strlen (ptr
));
676 void cpp_node (const cpp_hashnode
*node
)
678 str ((const char *)NODE_NAME (node
), NODE_LEN (node
));
680 void str (const char *, size_t); /* Write string of known length. */
681 void buf (const void *, size_t); /* Write fixed length buffer. */
682 void *buf (size_t); /* Create a writable buffer */
685 /* Format a NUL-terminated raw string. */
686 void printf (const char *, ...) ATTRIBUTE_PRINTF_2
;
687 void print_time (const char *, const tm
*, const char *);
690 /* Dump instrumentation. */
691 static void instrument ();
694 /* Instrumentation. */
695 static unsigned spans
[4];
696 static unsigned lengths
[4];
700 /* Instrumentation. */
701 unsigned bytes_out::spans
[4];
702 unsigned bytes_out::lengths
[4];
703 int bytes_out::is_set
= -1;
705 /* If CRC_PTR non-null, set the CRC of the buffer. Mix the CRC into
706 that pointed to by CRC_PTR. */
709 bytes_out::set_crc (unsigned *crc_ptr
)
713 gcc_checking_assert (pos
>= 4);
715 unsigned crc
= calc_crc (pos
);
716 unsigned accum
= *crc_ptr
;
717 /* Only mix the existing *CRC_PTR if it is non-zero. */
718 accum
= accum
? crc32_unsigned (accum
, crc
) : crc
;
721 /* Buffer will be sufficiently aligned. */
722 *(unsigned *)buffer
= crc
;
726 /* Finish a set of bools. */
734 lengths
[2] += bit_flush ();
747 /* When reading, we don't know how many bools we'll read in. So read
748 4 bytes-worth, and then rewind when flushing if we didn't need them
749 all. You can't have a block of bools closer than 4 bytes to the
750 end of the buffer. */
758 /* Bools are packed into bytes. You cannot mix bools and non-bools.
759 You must call bflush before emitting another type. So batch your
762 It may be worth optimizing for most bools being zero. Some kind of
763 run-length encoding? */
766 bytes_out::b (bool x
)
774 bit_val
|= unsigned (x
) << bit_pos
++;
778 lengths
[2] += bit_flush ();
787 bool v
= (bit_val
>> bit_pos
++) & 1;
793 /* Exactly 4 bytes. Used internally for bool packing and a few other
794 places. We can't simply use uint32_t because (a) alignment and
795 (b) we need little-endian for the bool streaming rewinding to make
799 bytes_out::u32 (unsigned val
)
801 if (char *ptr
= write (4))
814 if (const char *ptr
= read (4))
816 val
|= (unsigned char)ptr
[0];
817 val
|= (unsigned char)ptr
[1] << 8;
818 val
|= (unsigned char)ptr
[2] << 16;
819 val
|= (unsigned char)ptr
[3] << 24;
825 /* Chars are unsigned and written as single bytes. */
828 bytes_out::c (unsigned char v
)
830 if (char *ptr
= write (1))
838 if (const char *ptr
= read (1))
839 v
= (unsigned char)ptr
[0];
843 /* Ints 7-bit as a byte. Otherwise a 3bit count of following bytes in
844 big-endian form. 4 bits are in the first byte. */
849 if (char *ptr
= write (1))
851 if (v
<= 0x3f && v
>= -0x40)
858 for (probe
= v
>> 8; probe
> 0x7; probe
>>= 8)
861 for (probe
= v
>> 8; probe
< -0x8; probe
>>= 8)
863 *ptr
= 0x80 | bytes
<< 4 | (probe
& 0xf);
864 if ((ptr
= write (++bytes
)))
865 for (; bytes
--; v
>>= 8)
866 ptr
[bytes
] = v
& 0xff;
875 if (const char *ptr
= read (1))
880 unsigned bytes
= (v
>> 4) & 0x7;
884 if ((ptr
= read (++bytes
)))
886 v
= (v
<< 8) | (*ptr
++ & 0xff);
896 bytes_out::u (unsigned v
)
898 if (char *ptr
= write (1))
906 for (probe
= v
>> 8; probe
> 0xf; probe
>>= 8)
908 *ptr
= 0x80 | bytes
<< 4 | probe
;
909 if ((ptr
= write (++bytes
)))
910 for (; bytes
--; v
>>= 8)
911 ptr
[bytes
] = v
& 0xff;
921 if (const char *ptr
= read (1))
926 unsigned bytes
= (v
>> 4) & 0x7;
928 if ((ptr
= read (++bytes
)))
930 v
= (v
<< 8) | (*ptr
++ & 0xff);
938 bytes_out::wi (HOST_WIDE_INT v
)
940 if (char *ptr
= write (1))
942 if (v
<= 0x3f && v
>= -0x40)
949 for (probe
= v
>> 8; probe
> 0x7; probe
>>= 8)
952 for (probe
= v
>> 8; probe
< -0x8; probe
>>= 8)
954 *ptr
= 0x80 | bytes
<< 4 | (probe
& 0xf);
955 if ((ptr
= write (++bytes
)))
956 for (; bytes
--; v
>>= 8)
957 ptr
[bytes
] = v
& 0xff;
966 if (const char *ptr
= read (1))
971 unsigned bytes
= (v
>> 4) & 0x7;
975 if ((ptr
= read (++bytes
)))
977 v
= (v
<< 8) | (*ptr
++ & 0xff);
986 /* unsigned wide ints are just written as signed wide ints. */
989 bytes_out::wu (unsigned HOST_WIDE_INT v
)
991 wi ((HOST_WIDE_INT
) v
);
994 inline unsigned HOST_WIDE_INT
997 return (unsigned HOST_WIDE_INT
) wi ();
1000 /* size_t written as unsigned or unsigned wide int. */
1003 bytes_out::z (size_t s
)
1005 if (sizeof (s
) == sizeof (unsigned))
1014 if (sizeof (size_t) == sizeof (unsigned))
1020 /* Buffer simply memcpied. */
1022 bytes_out::buf (size_t len
)
1024 align (sizeof (void *) * 2);
1029 bytes_out::buf (const void *src
, size_t len
)
1031 if (void *ptr
= buf (len
))
1032 memcpy (ptr
, src
, len
);
1036 bytes_in::buf (size_t len
)
1038 align (sizeof (void *) * 2);
1039 const char *ptr
= read (len
);
1044 /* strings as an size_t length, followed by the buffer. Make sure
1045 there's a NUL terminator on read. */
1048 bytes_out::str (const char *string
, size_t len
)
1053 gcc_checking_assert (!string
[len
]);
1054 buf (string
, len
+ 1);
1059 bytes_in::str (size_t *len_p
)
1063 /* We're about to trust some user data. */
1068 const char *str
= NULL
;
1071 str
= reinterpret_cast<const char *> (buf (len
+ 1));
1072 if (!str
|| str
[len
])
1078 return str
? str
: "";
1082 bytes_in::cpp_node ()
1085 const char *s
= str (&len
);
1088 return ::cpp_node (get_identifier_with_length (s
, len
));
1091 /* Format a string directly to the buffer, including a terminating
1092 NUL. Intended for human consumption. */
1095 bytes_out::printf (const char *format
, ...)
1098 /* Exercise buffer expansion. */
1099 size_t len
= EXPERIMENT (10, 500);
1101 while (char *ptr
= write (len
))
1103 va_start (args
, format
);
1104 size_t actual
= vsnprintf (ptr
, len
, format
, args
) + 1;
1108 unuse (len
- actual
);
1117 bytes_out::print_time (const char *kind
, const tm
*time
, const char *tz
)
1119 printf ("%stime: %4u/%02u/%02u %02u:%02u:%02u %s",
1120 kind
, time
->tm_year
+ 1900, time
->tm_mon
+ 1, time
->tm_mday
,
1121 time
->tm_hour
, time
->tm_min
, time
->tm_sec
, tz
);
1124 /* Encapsulated Lazy Records Of Named Declarations.
1125 Header: Stunningly Elf32_Ehdr-like
1126 Sections: Sectional data
1127 [1-N) : User data sections
1128 N .strtab : strings, stunningly ELF STRTAB-like
1129 Index: Section table, stunningly ELF32_Shdr-like. */
1133 /* Constants used within the format. */
1134 enum private_constants
{
1146 /* Section numbering. */
1148 SHN_LORESERVE
= 0xff00,
1149 SHN_XINDEX
= 0xffff,
1151 /* Section types. */
1152 SHT_NONE
= 0, /* No contents. */
1153 SHT_PROGBITS
= 1, /* Random bytes. */
1154 SHT_STRTAB
= 3, /* A string table. */
1156 /* Section flags. */
1157 SHF_NONE
= 0x00, /* Nothing. */
1158 SHF_STRINGS
= 0x20, /* NUL-Terminated strings. */
1160 /* I really hope we do not get CMI files larger than 4GB. */
1162 /* It is host endianness that is relevant. */
1163 MY_ENDIAN
= DATA2LSB
1164 #ifdef WORDS_BIGENDIAN
1165 ^ DATA2LSB
^ DATA2MSB
1170 /* Constants visible to users. */
1171 enum public_constants
{
1172 /* Special error codes. Breaking layering a bit. */
1173 E_BAD_DATA
= -1, /* Random unexpected data errors. */
1174 E_BAD_LAZY
= -2, /* Badly ordered laziness. */
1175 E_BAD_IMPORT
= -3 /* A nested import failed. */
1179 /* File identification. On-disk representation. */
1181 uint8_t magic
[4]; /* 0x7f, 'E', 'L', 'F' */
1182 uint8_t klass
; /* 4:CLASS32 */
1183 uint8_t data
; /* 5:DATA2[LM]SB */
1184 uint8_t version
; /* 6:EV_CURRENT */
1185 uint8_t osabi
; /* 7:OSABI_NONE */
1186 uint8_t abiver
; /* 8: 0 */
1187 uint8_t pad
[7]; /* 9-15 */
1189 /* File header. On-disk representation. */
1192 uint16_t type
; /* ET_NONE */
1193 uint16_t machine
; /* EM_NONE */
1194 uint32_t version
; /* EV_CURRENT */
1195 uint32_t entry
; /* 0 */
1196 uint32_t phoff
; /* 0 */
1197 uint32_t shoff
; /* Section Header Offset in file */
1199 uint16_t ehsize
; /* ELROND Header SIZE -- sizeof (header) */
1200 uint16_t phentsize
; /* 0 */
1201 uint16_t phnum
; /* 0 */
1202 uint16_t shentsize
; /* Section Header SIZE -- sizeof (section) */
1203 uint16_t shnum
; /* Section Header NUM */
1204 uint16_t shstrndx
; /* Section Header STRing iNDeX */
1206 /* File section. On-disk representation. */
1208 uint32_t name
; /* String table offset. */
1209 uint32_t type
; /* SHT_* */
1210 uint32_t flags
; /* SHF_* */
1211 uint32_t addr
; /* 0 */
1212 uint32_t offset
; /* OFFSET in file */
1213 uint32_t size
; /* SIZE of section */
1214 uint32_t link
; /* 0 */
1215 uint32_t info
; /* 0 */
1216 uint32_t addralign
; /* 0 */
1217 uint32_t entsize
; /* ENTry SIZE, usually 0 */
1221 data hdr
; /* The header. */
1222 data sectab
; /* The section table. */
1223 data strtab
; /* String table. */
1224 int fd
; /* File descriptor we're reading or writing. */
1225 int err
; /* Sticky error code. */
1228 /* Construct from STREAM. E is errno if STREAM NULL. */
1230 :hdr (), sectab (), strtab (), fd (fd
), err (fd
>= 0 ? 0 : e
)
1234 gcc_checking_assert (fd
< 0 && !hdr
.buffer
1235 && !sectab
.buffer
&& !strtab
.buffer
);
1239 /* Return the error, if we have an error. */
1240 int get_error () const
1244 /* Set the error, unless it's already been set. */
1245 void set_error (int e
= E_BAD_DATA
)
1250 /* Get an error string. */
1251 const char *get_error (const char *) const;
1254 /* Begin reading/writing file. Return false on error. */
1257 return !get_error ();
1259 /* Finish reading/writing file. Return false on error. */
1263 /* Return error string. */
1266 elf::get_error (const char *name
) const
1269 return "Unknown CMI mapping";
1276 return "Bad file data";
1278 return "Bad import dependency";
1280 return "Bad lazy ordering";
1282 return xstrerror (err
);
1286 /* Finish file, return true if there's an error. */
1291 /* Close the stream and free the section table. */
1292 if (fd
>= 0 && close (fd
))
1296 return !get_error ();
1299 /* ELROND reader. */
1301 class elf_in
: public elf
{
1305 /* For freezing & defrosting. */
1306 #if !defined (HOST_LACKS_INODE_NUMBERS)
1312 elf_in (int fd
, int e
)
1321 bool is_frozen () const
1323 return fd
< 0 && hdr
.pos
;
1325 bool is_freezable () const
1327 return fd
>= 0 && hdr
.pos
;
1330 bool defrost (const char *);
1332 /* If BYTES is in the mmapped area, allocate a new buffer for it. */
1333 void preserve (bytes_in
&bytes ATTRIBUTE_UNUSED
)
1336 if (hdr
.buffer
&& bytes
.buffer
>= hdr
.buffer
1337 && bytes
.buffer
< hdr
.buffer
+ hdr
.pos
)
1339 char *buf
= bytes
.buffer
;
1340 bytes
.buffer
= data::simple_memory
.grow (NULL
, bytes
.size
);
1341 memcpy (bytes
.buffer
, buf
, bytes
.size
);
1345 /* If BYTES is not in SELF's mmapped area, free it. SELF might be
1347 static void release (elf_in
*self ATTRIBUTE_UNUSED
, bytes_in
&bytes
)
1350 if (!(self
&& self
->hdr
.buffer
&& bytes
.buffer
>= self
->hdr
.buffer
1351 && bytes
.buffer
< self
->hdr
.buffer
+ self
->hdr
.pos
))
1353 data::simple_memory
.shrink (bytes
.buffer
);
1354 bytes
.buffer
= NULL
;
1359 static void grow (data
&data
, unsigned needed
)
1361 gcc_checking_assert (!data
.buffer
);
1363 data
.buffer
= XNEWVEC (char, needed
);
1367 static void shrink (data
&data
)
1370 XDELETEVEC (data
.buffer
);
1377 const section
*get_section (unsigned s
) const
1379 if (s
* sizeof (section
) < sectab
.size
)
1380 return reinterpret_cast<const section
*>
1381 (§ab
.buffer
[s
* sizeof (section
)]);
1385 unsigned get_section_limit () const
1387 return sectab
.size
/ sizeof (section
);
1391 const char *read (data
*, unsigned, unsigned);
1394 /* Read section by number. */
1395 bool read (data
*d
, const section
*s
)
1397 return s
&& read (d
, s
->offset
, s
->size
);
1400 /* Find section by name. */
1401 unsigned find (const char *name
);
1402 /* Find section by index. */
1403 const section
*find (unsigned snum
, unsigned type
= SHT_PROGBITS
);
1406 /* Release the string table, when we're done with it. */
1413 bool begin (location_t
);
1419 munmap (hdr
.buffer
, hdr
.pos
);
1424 return parent::end ();
1428 /* Return string name at OFFSET. Checks OFFSET range. Always
1429 returns non-NULL. We know offset 0 is an empty string. */
1430 const char *name (unsigned offset
)
1432 return &strtab
.buffer
[offset
< strtab
.size
? offset
: 0];
1436 /* ELROND writer. */
1438 class elf_out
: public elf
, public data::allocator
{
1440 /* Desired section alignment on disk. */
1441 static const int SECTION_ALIGN
= 16;
1444 ptr_int_hash_map identtab
; /* Map of IDENTIFIERS to strtab offsets. */
1445 unsigned pos
; /* Write position in file. */
1447 unsigned offset
; /* Offset of the mapping. */
1448 unsigned extent
; /* Length of mapping. */
1449 unsigned page_size
; /* System page size. */
1453 elf_out (int fd
, int e
)
1454 :parent (fd
, e
), identtab (500), pos (0)
1457 offset
= extent
= 0;
1458 page_size
= sysconf (_SC_PAGE_SIZE
);
1459 if (page_size
< SECTION_ALIGN
)
1460 /* Something really strange. */
1466 data::simple_memory
.shrink (hdr
);
1467 data::simple_memory
.shrink (sectab
);
1468 data::simple_memory
.shrink (strtab
);
1473 void create_mapping (unsigned ext
, bool extending
= true);
1474 void remove_mapping ();
1478 using allocator::grow
;
1479 virtual char *grow (char *, unsigned needed
);
1481 using allocator::shrink
;
1482 virtual void shrink (char *);
1486 unsigned get_section_limit () const
1488 return sectab
.pos
/ sizeof (section
);
1492 unsigned add (unsigned type
, unsigned name
= 0,
1493 unsigned off
= 0, unsigned size
= 0, unsigned flags
= SHF_NONE
);
1494 unsigned write (const data
&);
1496 unsigned write (const bytes_out
&);
1500 /* IDENTIFIER to strtab offset. */
1501 unsigned name (tree ident
);
1502 /* String literal to strtab offset. */
1503 unsigned name (const char *n
);
1504 /* Qualified name of DECL to strtab offset. */
1505 unsigned qualified_name (tree decl
, bool is_defn
);
1508 unsigned strtab_write (const char *s
, unsigned l
);
1509 void strtab_write (tree decl
, int);
1512 /* Add a section with contents or strings. */
1513 unsigned add (const bytes_out
&, bool string_p
, unsigned name
);
1516 /* Begin and end writing. */
1521 /* Begin reading section NAME (of type PROGBITS) from SOURCE.
1522 Data always checked for CRC. */
1525 bytes_in::begin (location_t loc
, elf_in
*source
, const char *name
)
1527 unsigned snum
= source
->find (name
);
1529 return begin (loc
, source
, snum
, name
);
1532 /* Begin reading section numbered SNUM with NAME (may be NULL). */
1535 bytes_in::begin (location_t loc
, elf_in
*source
, unsigned snum
, const char *name
)
1537 if (!source
->read (this, source
->find (snum
))
1538 || !size
|| !check_crc ())
1540 source
->set_error (elf::E_BAD_DATA
);
1541 source
->shrink (*this);
1543 error_at (loc
, "section %qs is missing or corrupted", name
);
1545 error_at (loc
, "section #%u is missing or corrupted", snum
);
1552 /* Finish reading a section. */
1555 bytes_in::end (elf_in
*src
)
1562 src
->shrink (*this);
1567 /* Begin writing buffer. */
1570 bytes_out::begin (bool need_crc
)
1574 memory
->grow (*this, 0, false);
1577 /* Finish writing buffer. Stream out to SINK as named section NAME.
1578 Return section number or 0 on failure. If CRC_PTR is true, crc
1579 the data. Otherwise it is a string section. */
1582 bytes_out::end (elf_out
*sink
, unsigned name
, unsigned *crc_ptr
)
1588 unsigned sec_num
= sink
->add (*this, !crc_ptr
, name
);
1589 memory
->shrink (*this);
1594 /* Close and open the file, without destroying it. */
1599 gcc_checking_assert (!is_frozen ());
1601 if (munmap (hdr
.buffer
, hdr
.pos
) < 0)
1610 elf_in::defrost (const char *name
)
1612 gcc_checking_assert (is_frozen ());
1615 fd
= open (name
, O_RDONLY
| O_CLOEXEC
| O_BINARY
);
1616 if (fd
< 0 || fstat (fd
, &stat
) < 0)
1620 bool ok
= hdr
.pos
== unsigned (stat
.st_size
);
1621 #ifndef HOST_LACKS_INODE_NUMBERS
1622 if (device
!= stat
.st_dev
1623 || inode
!= stat
.st_ino
)
1631 char *mapping
= reinterpret_cast<char *>
1632 (mmap (NULL
, hdr
.pos
, PROT_READ
, MAP_SHARED
, fd
, 0));
1633 if (mapping
== MAP_FAILED
)
1638 if (madvise (mapping
, hdr
.pos
, MADV_RANDOM
))
1641 /* These buffers are never NULL in this case. */
1642 strtab
.buffer
= mapping
+ strtab
.pos
;
1643 sectab
.buffer
= mapping
+ sectab
.pos
;
1644 hdr
.buffer
= mapping
;
1650 return !get_error ();
1653 /* Read at current position into BUFFER. Return true on success. */
1656 elf_in::read (data
*data
, unsigned pos
, unsigned length
)
1659 if (pos
+ length
> hdr
.pos
)
1665 if (pos
!= ~0u && lseek (fd
, pos
, SEEK_SET
) < 0)
1671 grow (*data
, length
);
1673 data
->buffer
= hdr
.buffer
+ pos
;
1675 if (::read (fd
, data
->buffer
, data
->size
) != ssize_t (length
))
1683 return data
->buffer
;
1686 /* Read section SNUM of TYPE. Return section pointer or NULL on error. */
1688 const elf::section
*
1689 elf_in::find (unsigned snum
, unsigned type
)
1691 const section
*sec
= get_section (snum
);
1692 if (!snum
|| !sec
|| sec
->type
!= type
)
1697 /* Find a section NAME and TYPE. Return section number, or zero on
1701 elf_in::find (const char *sname
)
1703 for (unsigned pos
= sectab
.size
; pos
-= sizeof (section
); )
1706 = reinterpret_cast<const section
*> (§ab
.buffer
[pos
]);
1708 if (0 == strcmp (sname
, name (sec
->name
)))
1709 return pos
/ sizeof (section
);
1715 /* Begin reading file. Verify header. Pull in section and string
1716 tables. Return true on success. */
1719 elf_in::begin (location_t loc
)
1721 if (!parent::begin ())
1726 if (!fstat (fd
, &stat
))
1728 #if !defined (HOST_LACKS_INODE_NUMBERS)
1729 device
= stat
.st_dev
;
1730 inode
= stat
.st_ino
;
1732 /* Never generate files > 4GB, check we've not been given one. */
1733 if (stat
.st_size
== unsigned (stat
.st_size
))
1734 size
= unsigned (stat
.st_size
);
1738 /* MAP_SHARED so that the file is backing store. If someone else
1739 concurrently writes it, they're wrong. */
1740 void *mapping
= mmap (NULL
, size
, PROT_READ
, MAP_SHARED
, fd
, 0);
1741 if (mapping
== MAP_FAILED
)
1747 /* We'll be hopping over this randomly. Some systems declare the
1748 first parm as char *, and other declare it as void *. */
1749 if (madvise (reinterpret_cast <char *> (mapping
), size
, MADV_RANDOM
))
1752 hdr
.buffer
= (char *)mapping
;
1754 read (&hdr
, 0, sizeof (header
));
1756 hdr
.pos
= size
; /* Record size of the file. */
1758 const header
*h
= reinterpret_cast<const header
*> (hdr
.buffer
);
1762 if (h
->ident
.magic
[0] != 0x7f
1763 || h
->ident
.magic
[1] != 'E'
1764 || h
->ident
.magic
[2] != 'L'
1765 || h
->ident
.magic
[3] != 'F')
1767 error_at (loc
, "not Encapsulated Lazy Records of Named Declarations");
1773 /* We expect a particular format -- the ELF is not intended to be
1775 if (h
->ident
.klass
!= MY_CLASS
1776 || h
->ident
.data
!= MY_ENDIAN
1777 || h
->ident
.version
!= EV_CURRENT
1778 || h
->type
!= ET_NONE
1779 || h
->machine
!= EM_NONE
1780 || h
->ident
.osabi
!= OSABI_NONE
)
1782 error_at (loc
, "unexpected encapsulation format or type");
1787 if (!h
->shoff
|| h
->shentsize
!= sizeof (section
))
1791 error_at (loc
, "encapsulation is malformed");
1795 unsigned strndx
= h
->shstrndx
;
1796 unsigned shnum
= h
->shnum
;
1797 if (shnum
== SHN_XINDEX
)
1799 if (!read (§ab
, h
->shoff
, sizeof (section
)))
1805 shnum
= get_section (0)->size
;
1806 /* Freeing does mean we'll re-read it in the case we're not
1807 mapping, but this is going to be rare. */
1814 if (!read (§ab
, h
->shoff
, shnum
* sizeof (section
)))
1815 goto section_table_fail
;
1817 if (strndx
== SHN_XINDEX
)
1818 strndx
= get_section (0)->link
;
1820 if (!read (&strtab
, find (strndx
, SHT_STRTAB
)))
1823 /* The string table should be at least one byte, with NUL chars
1825 if (!(strtab
.size
&& !strtab
.buffer
[0]
1826 && !strtab
.buffer
[strtab
.size
- 1]))
1830 /* Record the offsets of the section and string tables. */
1831 sectab
.pos
= h
->shoff
;
1832 strtab
.pos
= shnum
* sizeof (section
);
1840 /* Create a new mapping. */
1844 elf_out::create_mapping (unsigned ext
, bool extending
)
1846 #ifndef HAVE_POSIX_FALLOCATE
1847 #define posix_fallocate(fd,off,len) ftruncate (fd, off + len)
1849 void *mapping
= MAP_FAILED
;
1850 if (extending
&& ext
< 1024 * 1024)
1852 if (!posix_fallocate (fd
, offset
, ext
* 2))
1853 mapping
= mmap (NULL
, ext
* 2, PROT_READ
| PROT_WRITE
,
1854 MAP_SHARED
, fd
, offset
);
1855 if (mapping
!= MAP_FAILED
)
1858 if (mapping
== MAP_FAILED
)
1860 if (!extending
|| !posix_fallocate (fd
, offset
, ext
))
1861 mapping
= mmap (NULL
, ext
, PROT_READ
| PROT_WRITE
,
1862 MAP_SHARED
, fd
, offset
);
1863 if (mapping
== MAP_FAILED
)
1870 #undef posix_fallocate
1871 hdr
.buffer
= (char *)mapping
;
1876 /* Flush out the current mapping. */
1880 elf_out::remove_mapping ()
1884 /* MS_ASYNC dtrt with the removed mapping, including a
1885 subsequent overlapping remap. */
1886 if (msync (hdr
.buffer
, extent
, MS_ASYNC
)
1887 || munmap (hdr
.buffer
, extent
))
1888 /* We're somewhat screwed at this point. */
1896 /* Grow a mapping of PTR to be NEEDED bytes long. This gets
1897 interesting if the new size grows the EXTENT. */
1900 elf_out::grow (char *data
, unsigned needed
)
1904 /* First allocation, check we're aligned. */
1905 gcc_checking_assert (!(pos
& (SECTION_ALIGN
- 1)));
1907 data
= hdr
.buffer
+ (pos
- offset
);
1912 unsigned off
= data
- hdr
.buffer
;
1913 if (off
+ needed
> extent
)
1915 /* We need to grow the mapping. */
1916 unsigned lwm
= off
& ~(page_size
- 1);
1917 unsigned hwm
= (off
+ needed
+ page_size
- 1) & ~(page_size
- 1);
1919 gcc_checking_assert (hwm
> extent
);
1924 create_mapping (extent
< hwm
- lwm
? hwm
- lwm
: extent
);
1926 data
= hdr
.buffer
+ (off
- lwm
);
1929 data
= allocator::grow (data
, needed
);
1936 /* Shrinking is a NOP. */
1938 elf_out::shrink (char *)
1943 /* Write S of length L to the strtab buffer. L must include the ending
1944 NUL, if that's what you want. */
1947 elf_out::strtab_write (const char *s
, unsigned l
)
1949 if (strtab
.pos
+ l
> strtab
.size
)
1950 data::simple_memory
.grow (strtab
, strtab
.pos
+ l
, false);
1951 memcpy (strtab
.buffer
+ strtab
.pos
, s
, l
);
1952 unsigned res
= strtab
.pos
;
1957 /* Write qualified name of decl. INNER >0 if this is a definition, <0
1958 if this is a qualifier of an outer name. */
1961 elf_out::strtab_write (tree decl
, int inner
)
1963 tree ctx
= CP_DECL_CONTEXT (decl
);
1965 ctx
= TYPE_NAME (ctx
);
1966 if (ctx
!= global_namespace
)
1967 strtab_write (ctx
, -1);
1969 tree name
= DECL_NAME (decl
);
1971 name
= DECL_ASSEMBLER_NAME_RAW (decl
);
1972 strtab_write (IDENTIFIER_POINTER (name
), IDENTIFIER_LENGTH (name
));
1975 strtab_write (&"::{}"[inner
+1], 2);
1978 /* Map IDENTIFIER IDENT to strtab offset. Inserts into strtab if not
1982 elf_out::name (tree ident
)
1988 int *slot
= &identtab
.get_or_insert (ident
, &existed
);
1990 *slot
= strtab_write (IDENTIFIER_POINTER (ident
),
1991 IDENTIFIER_LENGTH (ident
) + 1);
1997 /* Map LITERAL to strtab offset. Does not detect duplicates and
1998 expects LITERAL to remain live until strtab is written out. */
2001 elf_out::name (const char *literal
)
2003 return strtab_write (literal
, strlen (literal
) + 1);
2006 /* Map a DECL's qualified name to strtab offset. Does not detect
2010 elf_out::qualified_name (tree decl
, bool is_defn
)
2012 gcc_checking_assert (DECL_P (decl
) && decl
!= global_namespace
);
2013 unsigned result
= strtab
.pos
;
2015 strtab_write (decl
, is_defn
);
2016 strtab_write ("", 1);
2021 /* Add section to file. Return section number. TYPE & NAME identify
2022 the section. OFF and SIZE identify the file location of its
2023 data. FLAGS contains additional info. */
2026 elf_out::add (unsigned type
, unsigned name
, unsigned off
, unsigned size
,
2029 gcc_checking_assert (!(off
& (SECTION_ALIGN
- 1)));
2030 if (sectab
.pos
+ sizeof (section
) > sectab
.size
)
2031 data::simple_memory
.grow (sectab
, sectab
.pos
+ sizeof (section
), false);
2032 section
*sec
= reinterpret_cast<section
*> (sectab
.buffer
+ sectab
.pos
);
2033 memset (sec
, 0, sizeof (section
));
2039 if (flags
& SHF_STRINGS
)
2042 unsigned res
= sectab
.pos
;
2043 sectab
.pos
+= sizeof (section
);
2044 return res
/ sizeof (section
);
2047 /* Pad to the next alignment boundary, then write BUFFER to disk.
2048 Return the position of the start of the write, or zero on failure. */
2051 elf_out::write (const data
&buffer
)
2054 /* HDR is always mapped. */
2055 if (&buffer
!= &hdr
)
2057 bytes_out
out (this);
2058 grow (out
, buffer
.pos
, true);
2060 memcpy (out
.buffer
, buffer
.buffer
, buffer
.pos
);
2064 /* We should have been aligned during the first allocation. */
2065 gcc_checking_assert (!(pos
& (SECTION_ALIGN
- 1)));
2067 if (::write (fd
, buffer
.buffer
, buffer
.pos
) != ssize_t (buffer
.pos
))
2076 if (unsigned padding
= -pos
& (SECTION_ALIGN
- 1))
2079 /* Align the section on disk, should help the necessary copies.
2080 fseeking to extend is non-portable. */
2081 static char zero
[SECTION_ALIGN
];
2082 if (::write (fd
, &zero
, padding
) != ssize_t (padding
))
2090 /* Write a streaming buffer. It must be using us as an allocator. */
2094 elf_out::write (const bytes_out
&buf
)
2096 gcc_checking_assert (buf
.memory
== this);
2097 /* A directly mapped buffer. */
2098 gcc_checking_assert (buf
.buffer
- hdr
.buffer
>= 0
2099 && buf
.buffer
- hdr
.buffer
+ buf
.size
<= extent
);
2103 /* Align up. We're not going to advance into the next page. */
2104 pos
+= -pos
& (SECTION_ALIGN
- 1);
2110 /* Write data and add section. STRING_P is true for a string
2111 section, false for PROGBITS. NAME identifies the section (0 is the
2112 empty name). DATA is the contents. Return section number or 0 on
2113 failure (0 is the undef section). */
2116 elf_out::add (const bytes_out
&data
, bool string_p
, unsigned name
)
2118 unsigned off
= write (data
);
2120 return add (string_p
? SHT_STRTAB
: SHT_PROGBITS
, name
,
2121 off
, data
.pos
, string_p
? SHF_STRINGS
: SHF_NONE
);
2124 /* Begin writing the file. Initialize the section table and write an
2125 empty header. Return false on failure. */
2130 if (!parent::begin ())
2133 /* Let the allocators pick a default. */
2134 data::simple_memory
.grow (strtab
, 0, false);
2135 data::simple_memory
.grow (sectab
, 0, false);
2137 /* The string table starts with an empty string. */
2140 /* Create the UNDEF section. */
2144 /* Start a mapping. */
2145 create_mapping (EXPERIMENT (page_size
,
2146 (32767 + page_size
) & ~(page_size
- 1)));
2151 /* Write an empty header. */
2152 grow (hdr
, sizeof (header
), true);
2153 header
*h
= reinterpret_cast<header
*> (hdr
.buffer
);
2154 memset (h
, 0, sizeof (header
));
2157 return !get_error ();
2160 /* Finish writing the file. Write out the string & section tables.
2161 Fill in the header. Return true on error. */
2168 /* Write the string table. */
2169 unsigned strnam
= name (".strtab");
2170 unsigned stroff
= write (strtab
);
2171 unsigned strndx
= add (SHT_STRTAB
, strnam
, stroff
, strtab
.pos
,
2174 /* Store escape values in section[0]. */
2175 if (strndx
>= SHN_LORESERVE
)
2177 reinterpret_cast<section
*> (sectab
.buffer
)->link
= strndx
;
2178 strndx
= SHN_XINDEX
;
2180 unsigned shnum
= sectab
.pos
/ sizeof (section
);
2181 if (shnum
>= SHN_LORESERVE
)
2183 reinterpret_cast<section
*> (sectab
.buffer
)->size
= shnum
;
2187 unsigned shoff
= write (sectab
);
2194 create_mapping ((sizeof (header
) + page_size
- 1) & ~(page_size
- 1),
2197 unsigned length
= pos
;
2199 if (lseek (fd
, 0, SEEK_SET
) < 0)
2205 /* Write the correct header now. */
2206 header
*h
= reinterpret_cast<header
*> (hdr
.buffer
);
2207 h
->ident
.magic
[0] = 0x7f;
2208 h
->ident
.magic
[1] = 'E'; /* Elrond */
2209 h
->ident
.magic
[2] = 'L'; /* is an */
2210 h
->ident
.magic
[3] = 'F'; /* elf. */
2211 h
->ident
.klass
= MY_CLASS
;
2212 h
->ident
.data
= MY_ENDIAN
;
2213 h
->ident
.version
= EV_CURRENT
;
2214 h
->ident
.osabi
= OSABI_NONE
;
2216 h
->machine
= EM_NONE
;
2217 h
->version
= EV_CURRENT
;
2219 h
->ehsize
= sizeof (header
);
2220 h
->shentsize
= sizeof (section
);
2222 h
->shstrndx
= strndx
;
2230 if (ftruncate (fd
, length
))
2235 data::simple_memory
.shrink (sectab
);
2236 data::simple_memory
.shrink (strtab
);
2238 return parent::end ();
2241 /********************************************************************/
2243 /* A dependency set. This is used during stream out to determine the
2244 connectivity of the graph. Every namespace-scope declaration that
2245 needs writing has a depset. The depset is filled with the (depsets
2246 of) declarations within this module that it references. For a
2247 declaration that'll generally be named types. For definitions
2248 it'll also be declarations in the body.
2250 From that we can convert the graph to a DAG, via determining the
2251 Strongly Connected Clusters. Each cluster is streamed
2252 independently, and thus we achieve lazy loading.
2254 Other decls that get a depset are namespaces themselves and
2255 unnameable declarations. */
2259 tree entity
; /* Entity, or containing namespace. */
2260 uintptr_t discriminator
; /* Flags or identifier. */
2263 /* The kinds of entity the depset could describe. The ordering is
2264 significant, see entity_kind_name. */
2267 EK_DECL
, /* A decl. */
2268 EK_SPECIALIZATION
, /* A specialization. */
2269 EK_PARTIAL
, /* A partial specialization. */
2270 EK_USING
, /* A using declaration (at namespace scope). */
2271 EK_NAMESPACE
, /* A namespace. */
2272 EK_REDIRECT
, /* Redirect to a template_decl. */
2274 EK_BINDING
= EK_EXPLICIT_HWM
, /* Implicitly encoded. */
2275 EK_FOR_BINDING
, /* A decl being inserted for a binding. */
2276 EK_INNER_DECL
, /* A decl defined outside of it's imported
2278 EK_DIRECT_HWM
= EK_PARTIAL
+ 1,
2280 EK_BITS
= 3 /* Only need to encode below EK_EXPLICIT_HWM. */
2284 /* Placement of bit fields in discriminator. */
2287 DB_ZERO_BIT
, /* Set to disambiguate identifier from flags */
2288 DB_SPECIAL_BIT
, /* First dep slot is special. */
2289 DB_KIND_BIT
, /* Kind of the entity. */
2290 DB_KIND_BITS
= EK_BITS
,
2291 DB_DEFN_BIT
= DB_KIND_BIT
+ DB_KIND_BITS
,
2292 DB_IS_MEMBER_BIT
, /* Is an out-of-class member. */
2293 DB_IS_INTERNAL_BIT
, /* It is an (erroneous)
2294 internal-linkage entity. */
2295 DB_REFS_INTERNAL_BIT
, /* Refers to an internal-linkage
2297 DB_IMPORTED_BIT
, /* An imported entity. */
2298 DB_UNREACHED_BIT
, /* A yet-to-be reached entity. */
2299 DB_HIDDEN_BIT
, /* A hidden binding. */
2300 /* The following bits are not independent, but enumerating them is
2302 DB_ALIAS_TMPL_INST_BIT
, /* An alias template instantiation. */
2303 DB_ALIAS_SPEC_BIT
, /* Specialization of an alias template
2304 (in both spec tables). */
2305 DB_TYPE_SPEC_BIT
, /* Specialization in the type table.
2307 DB_FRIEND_SPEC_BIT
, /* An instantiated template friend. */
2311 /* The first slot is special for EK_SPECIALIZATIONS it is a
2312 spec_entry pointer. It is not relevant for the SCC
2314 vec
<depset
*> deps
; /* Depsets we reference. */
2317 unsigned cluster
; /* Strongly connected cluster, later entity number */
2318 unsigned section
; /* Section written to. */
2319 /* During SCC construction, section is lowlink, until the depset is
2320 removed from the stack. See Tarjan algorithm for details. */
2323 /* Construction via factories. Destruction via hash traits. */
2324 depset (tree entity
);
2328 static depset
*make_binding (tree
, tree
);
2329 static depset
*make_entity (tree
, entity_kind
, bool = false);
2330 /* Late setting a binding name -- /then/ insert into hash! */
2331 inline void set_binding_name (tree name
)
2333 gcc_checking_assert (!get_name ());
2334 discriminator
= reinterpret_cast<uintptr_t> (name
);
2338 template<unsigned I
> void set_flag_bit ()
2340 gcc_checking_assert (I
< 2 || !is_binding ());
2341 discriminator
|= 1u << I
;
2343 template<unsigned I
> void clear_flag_bit ()
2345 gcc_checking_assert (I
< 2 || !is_binding ());
2346 discriminator
&= ~(1u << I
);
2348 template<unsigned I
> bool get_flag_bit () const
2350 gcc_checking_assert (I
< 2 || !is_binding ());
2351 return bool ((discriminator
>> I
) & 1);
2355 bool is_binding () const
2357 return !get_flag_bit
<DB_ZERO_BIT
> ();
2359 entity_kind
get_entity_kind () const
2363 return entity_kind ((discriminator
>> DB_KIND_BIT
) & ((1u << EK_BITS
) - 1));
2365 const char *entity_kind_name () const;
2368 bool has_defn () const
2370 return get_flag_bit
<DB_DEFN_BIT
> ();
2374 bool is_member () const
2376 return get_flag_bit
<DB_IS_MEMBER_BIT
> ();
2379 bool is_internal () const
2381 return get_flag_bit
<DB_IS_INTERNAL_BIT
> ();
2383 bool refs_internal () const
2385 return get_flag_bit
<DB_REFS_INTERNAL_BIT
> ();
2387 bool is_import () const
2389 return get_flag_bit
<DB_IMPORTED_BIT
> ();
2391 bool is_unreached () const
2393 return get_flag_bit
<DB_UNREACHED_BIT
> ();
2395 bool is_alias_tmpl_inst () const
2397 return get_flag_bit
<DB_ALIAS_TMPL_INST_BIT
> ();
2399 bool is_alias () const
2401 return get_flag_bit
<DB_ALIAS_SPEC_BIT
> ();
2403 bool is_hidden () const
2405 return get_flag_bit
<DB_HIDDEN_BIT
> ();
2407 bool is_type_spec () const
2409 return get_flag_bit
<DB_TYPE_SPEC_BIT
> ();
2411 bool is_friend_spec () const
2413 return get_flag_bit
<DB_FRIEND_SPEC_BIT
> ();
2417 /* We set these bit outside of depset. */
2418 void set_hidden_binding ()
2420 set_flag_bit
<DB_HIDDEN_BIT
> ();
2422 void clear_hidden_binding ()
2424 clear_flag_bit
<DB_HIDDEN_BIT
> ();
2428 bool is_special () const
2430 return get_flag_bit
<DB_SPECIAL_BIT
> ();
2434 set_flag_bit
<DB_SPECIAL_BIT
> ();
2438 tree
get_entity () const
2442 tree
get_name () const
2444 gcc_checking_assert (is_binding ());
2445 return reinterpret_cast <tree
> (discriminator
);
2449 /* Traits for a hash table of pointers to bindings. */
2451 /* Each entry is a pointer to a depset. */
2452 typedef depset
*value_type
;
2453 /* We lookup by container:maybe-identifier pair. */
2454 typedef std::pair
<tree
,tree
> compare_type
;
2456 static const bool empty_zero_p
= true;
2458 /* hash and equality for compare_type. */
2459 inline static hashval_t
hash (const compare_type
&p
)
2461 hashval_t h
= pointer_hash
<tree_node
>::hash (p
.first
);
2464 hashval_t nh
= IDENTIFIER_HASH_VALUE (p
.second
);
2465 h
= iterative_hash_hashval_t (h
, nh
);
2469 inline static bool equal (const value_type b
, const compare_type
&p
)
2471 if (b
->entity
!= p
.first
)
2475 return b
->discriminator
== reinterpret_cast<uintptr_t> (p
.second
);
2477 return !b
->is_binding ();
2480 /* (re)hasher for a binding itself. */
2481 inline static hashval_t
hash (const value_type b
)
2483 hashval_t h
= pointer_hash
<tree_node
>::hash (b
->entity
);
2484 if (b
->is_binding ())
2486 hashval_t nh
= IDENTIFIER_HASH_VALUE (b
->get_name ());
2487 h
= iterative_hash_hashval_t (h
, nh
);
2492 /* Empty via NULL. */
2493 static inline void mark_empty (value_type
&p
) {p
= NULL
;}
2494 static inline bool is_empty (value_type p
) {return !p
;}
2496 /* Nothing is deletable. Everything is insertable. */
2497 static bool is_deleted (value_type
) { return false; }
2498 static void mark_deleted (value_type
) { gcc_unreachable (); }
2500 /* We own the entities in the hash table. */
2501 static void remove (value_type p
)
2508 class hash
: public hash_table
<traits
> {
2509 typedef traits::compare_type key_t
;
2510 typedef hash_table
<traits
> parent
;
2513 vec
<depset
*> worklist
; /* Worklist of decls to walk. */
2514 hash
*chain
; /* Original table. */
2515 depset
*current
; /* Current depset being depended. */
2516 unsigned section
; /* When writing out, the section. */
2517 bool sneakoscope
; /* Detecting dark magic (of a voldemort). */
2518 bool reached_unreached
; /* We reached an unreached entity. */
2521 hash (size_t size
, hash
*c
= NULL
)
2522 : parent (size
), chain (c
), current (NULL
), section (0),
2523 sneakoscope (false), reached_unreached (false)
2525 worklist
.create (size
);
2529 worklist
.release ();
2533 bool is_key_order () const
2535 return chain
!= NULL
;
2539 depset
**entity_slot (tree entity
, bool = true);
2540 depset
**binding_slot (tree ctx
, tree name
, bool = true);
2541 depset
*maybe_add_declaration (tree decl
);
2544 depset
*find_dependency (tree entity
);
2545 depset
*find_binding (tree ctx
, tree name
);
2546 depset
*make_dependency (tree decl
, entity_kind
);
2547 void add_dependency (depset
*);
2550 void add_mergeable (depset
*);
2551 depset
*add_dependency (tree decl
, entity_kind
);
2552 void add_namespace_context (depset
*, tree ns
);
2555 static bool add_binding_entity (tree
, WMB_Flags
, void *);
2558 bool add_namespace_entities (tree ns
, bitmap partitions
);
2559 void add_specializations (bool decl_p
);
2560 void add_partial_entities (vec
<tree
, va_gc
> *);
2561 void add_class_entities (vec
<tree
, va_gc
> *);
2564 void find_dependencies ();
2565 bool finalize_dependencies ();
2566 vec
<depset
*> connect ();
2571 vec
<depset
*> result
;
2572 vec
<depset
*> stack
;
2575 tarjan (unsigned size
)
2578 result
.create (size
);
2583 gcc_assert (!stack
.length ());
2588 void connect (depset
*);
2593 depset::depset (tree entity
)
2594 :entity (entity
), discriminator (0), cluster (0), section (0)
2606 depset::entity_kind_name () const
2608 /* Same order as entity_kind. */
2609 static const char *const names
[] =
2610 {"decl", "specialization", "partial", "using",
2611 "namespace", "redirect", "binding"};
2612 entity_kind kind
= get_entity_kind ();
2613 gcc_checking_assert (kind
< sizeof (names
) / sizeof(names
[0]));
2617 /* Create a depset for a namespace binding NS::NAME. */
2619 depset
*depset::make_binding (tree ns
, tree name
)
2621 depset
*binding
= new depset (ns
);
2623 binding
->discriminator
= reinterpret_cast <uintptr_t> (name
);
2628 depset
*depset::make_entity (tree entity
, entity_kind ek
, bool is_defn
)
2630 depset
*r
= new depset (entity
);
2632 r
->discriminator
= ((1 << DB_ZERO_BIT
)
2633 | (ek
<< DB_KIND_BIT
)
2634 | is_defn
<< DB_DEFN_BIT
);
2639 /* Values keyed to some unsigned integer. This is not GTY'd, so if
2640 T is tree they must be reachable via some other path. */
2642 template<typename T
>
2645 unsigned key
; /* Entity index of the other entity. */
2648 unsigned allocp2
: 5; /* log(2) allocated pending */
2649 unsigned num
: 27; /* Number of pending. */
2651 /* Trailing array of values. */
2655 /* Even with ctors, we're very pod-like. */
2656 uintset (unsigned uid
)
2657 : key (uid
), allocp2 (0), num (0)
2660 /* Copy constructor, which is exciting because of the trailing
2662 uintset (const uintset
*from
)
2664 size_t size
= (offsetof (uintset
, values
)
2665 + sizeof (uintset::values
) * from
->num
);
2666 memmove (this, from
, size
);
2672 struct traits
: delete_ptr_hash
<uintset
> {
2673 typedef unsigned compare_type
;
2674 typedef typename delete_ptr_hash
<uintset
>::value_type value_type
;
2676 /* Hash and equality for compare_type. */
2677 inline static hashval_t
hash (const compare_type k
)
2679 return hashval_t (k
);
2681 inline static hashval_t
hash (const value_type v
)
2683 return hash (v
->key
);
2686 inline static bool equal (const value_type v
, const compare_type k
)
2693 class hash
: public hash_table
<traits
>
2695 typedef typename
traits::compare_type key_t
;
2696 typedef hash_table
<traits
> parent
;
2708 uintset
**find_slot (key_t key
, insert_option insert
)
2710 return this->find_slot_with_hash (key
, traits::hash (key
), insert
);
2714 uintset
*get (key_t key
, bool extract
= false);
2715 bool add (key_t key
, T value
);
2716 uintset
*create (key_t key
, unsigned num
, T init
= 0);
2720 /* Add VALUE to KEY's uintset, creating it if necessary. Returns true
2721 if we created the uintset. */
2723 template<typename T
>
2725 uintset
<T
>::hash::add (typename uintset
<T
>::hash::key_t key
, T value
)
2727 uintset
**slot
= this->find_slot (key
, INSERT
);
2728 uintset
*set
= *slot
;
2731 if (is_new
|| set
->num
== (1u << set
->allocp2
))
2735 unsigned n
= set
->num
* 2;
2736 size_t new_size
= (offsetof (uintset
, values
)
2737 + sizeof (uintset (0u).values
) * n
);
2738 uintset
*new_set
= new (::operator new (new_size
)) uintset (set
);
2743 set
= new (::operator new (sizeof (*set
))) uintset (key
);
2747 set
->values
[set
->num
++] = value
;
2752 template<typename T
>
2754 uintset
<T
>::hash::create (typename uintset
<T
>::hash::key_t key
, unsigned num
,
2757 unsigned p2alloc
= 0;
2758 for (unsigned v
= num
; v
!= 1; v
= (v
>> 1) | (v
& 1))
2761 size_t new_size
= (offsetof (uintset
, values
)
2762 + (sizeof (uintset (0u).values
) << p2alloc
));
2763 uintset
*set
= new (::operator new (new_size
)) uintset (key
);
2764 set
->allocp2
= p2alloc
;
2767 set
->values
[num
] = init
;
2769 uintset
**slot
= this->find_slot (key
, INSERT
);
2770 gcc_checking_assert (!*slot
);
2776 /* Locate KEY's uintset, potentially removing it from the hash table */
2778 template<typename T
>
2780 uintset
<T
>::hash::get (typename uintset
<T
>::hash::key_t key
, bool extract
)
2782 uintset
*res
= NULL
;
2784 if (uintset
**slot
= this->find_slot (key
, NO_INSERT
))
2788 /* We need to remove the pendset without deleting it. */
2789 traits::mark_deleted (*slot
);
2795 /* Entities keyed to some other entity. When we load the other
2796 entity, we mark it in some way to indicate there are further
2797 entities to load when you start looking inside it. For instance
2798 template specializations are keyed to their most general template.
2799 When we instantiate that, we need to know all the partial
2800 specializations (to pick the right template), and all the known
2801 specializations (to avoid reinstantiating it, and/or whether it's
2802 extern). The values split into two ranges. If !MSB set, indices
2803 into the entity array. If MSB set, an indirection to another
2806 typedef uintset
<unsigned> pendset
;
2807 static pendset::hash
*pending_table
;
2809 /* Some entities are attached to another entitity for ODR purposes.
2810 For example, at namespace scope, 'inline auto var = []{};', that
2811 lambda is attached to 'var', and follows its ODRness. */
2812 typedef uintset
<tree
> attachset
;
2813 static attachset::hash
*attached_table
;
2815 /********************************************************************/
2816 /* Tree streaming. The tree streaming is very specific to the tree
2817 structures themselves. A tag indicates the kind of tree being
2818 streamed. -ve tags indicate backreferences to already-streamed
2819 trees. Backreferences are auto-numbered. */
2823 tt_null
, /* NULL_TREE. */
2824 tt_fixed
, /* Fixed vector index. */
2826 tt_node
, /* By-value node. */
2827 tt_decl
, /* By-value mergeable decl. */
2828 tt_tpl_parm
, /* Template parm. */
2830 /* The ordering of the following 4 is relied upon in
2831 trees_out::tree_node. */
2832 tt_id
, /* Identifier node. */
2833 tt_conv_id
, /* Conversion operator name. */
2834 tt_anon_id
, /* Anonymous name. */
2835 tt_lambda_id
, /* Lambda name. */
2837 tt_typedef_type
, /* A (possibly implicit) typedefed type. */
2838 tt_derived_type
, /* A type derived from another type. */
2839 tt_variant_type
, /* A variant of another type. */
2841 tt_tinfo_var
, /* Typeinfo object. */
2842 tt_tinfo_typedef
, /* Typeinfo typedef. */
2843 tt_ptrmem_type
, /* Pointer to member type. */
2845 tt_parm
, /* Function parameter or result. */
2846 tt_enum_value
, /* An enum value. */
2847 tt_enum_decl
, /* An enum decl. */
2848 tt_data_member
, /* Data member/using-decl. */
2850 tt_binfo
, /* A BINFO. */
2851 tt_vtable
, /* A vtable. */
2852 tt_thunk
, /* A thunk. */
2855 tt_entity
, /* A extra-cluster entity. */
2857 tt_template
, /* The TEMPLATE_RESULT of a template. */
2861 WK_none
, /* No walk to do (a back- or fixed-ref happened). */
2862 WK_normal
, /* Normal walk (by-name if possible). */
2864 WK_value
, /* By-value walk. */
2869 MK_unique
, /* Known unique. */
2870 MK_named
, /* Found by CTX, NAME + maybe_arg types etc. */
2871 MK_field
, /* Found by CTX and index on TYPE_FIELDS */
2872 MK_vtable
, /* Found by CTX and index on TYPE_VTABLES */
2873 MK_as_base
, /* Found by CTX. */
2877 MK_enum
, /* Found by CTX, & 1stMemberNAME. */
2878 MK_attached
, /* Found by attachee & index. */
2880 MK_friend_spec
, /* Like named, but has a tmpl & args too. */
2881 MK_local_friend
, /* Found by CTX, index. */
2883 MK_indirect_lwm
= MK_enum
,
2885 /* Template specialization kinds below. These are all found via
2886 primary template and specialization args. */
2887 MK_template_mask
= 0x10, /* A template specialization. */
2889 MK_tmpl_decl_mask
= 0x4, /* In decl table. */
2890 MK_tmpl_alias_mask
= 0x2, /* Also in type table */
2892 MK_tmpl_tmpl_mask
= 0x1, /* We want TEMPLATE_DECL. */
2894 MK_type_spec
= MK_template_mask
,
2895 MK_type_tmpl_spec
= MK_type_spec
| MK_tmpl_tmpl_mask
,
2897 MK_decl_spec
= MK_template_mask
| MK_tmpl_decl_mask
,
2898 MK_decl_tmpl_spec
= MK_decl_spec
| MK_tmpl_tmpl_mask
,
2900 MK_alias_spec
= MK_decl_spec
| MK_tmpl_alias_mask
,
2904 /* This is more than a debugging array. NULLs are used to determine
2905 an invalid merge_kind number. */
2906 static char const *const merge_kind_name
[MK_hwm
] =
2908 "unique", "named", "field", "vtable", /* 0...3 */
2909 "asbase", "partial", "enum", "attached", /* 4...7 */
2911 "friend spec", "local friend", NULL
, NULL
, /* 8...11 */
2912 NULL
, NULL
, NULL
, NULL
,
2914 "type spec", "type tmpl spec", /* 16,17 type (template). */
2917 "decl spec", "decl tmpl spec", /* 20,21 decl (template). */
2918 "alias spec", NULL
, /* 22,23 alias. */
2919 NULL
, NULL
, NULL
, NULL
,
2920 NULL
, NULL
, NULL
, NULL
,
2923 /* Mergeable entity location data. */
2925 cp_ref_qualifier ref_q
: 2;
2928 tree ret
; /* Return type, if appropriate. */
2929 tree args
; /* Arg types, if appropriate. */
2931 tree constraints
; /* Constraints. */
2934 :ref_q (REF_QUAL_NONE
), index (0),
2935 ret (NULL_TREE
), args (NULL_TREE
),
2936 constraints (NULL_TREE
)
2941 struct duplicate_hash
: nodel_ptr_hash
<tree_node
>
2943 inline static hashval_t
hash (value_type decl
)
2945 if (TREE_CODE (decl
) == TREE_BINFO
)
2946 decl
= TYPE_NAME (BINFO_TYPE (decl
));
2947 return hashval_t (DECL_UID (decl
));
2951 /* Hashmap of merged duplicates. Usually decls, but can contain
2953 typedef hash_map
<tree
,uintptr_t,
2954 simple_hashmap_traits
<duplicate_hash
,uintptr_t> >
2957 /* Tree stream reader. Note that reading a stream doesn't mark the
2958 read trees with TREE_VISITED. Thus it's quite safe to have
2959 multiple concurrent readers. Which is good, because lazy
2961 class trees_in
: public bytes_in
{
2962 typedef bytes_in parent
;
2965 module_state
*state
; /* Module being imported. */
2966 vec
<tree
> back_refs
; /* Back references. */
2967 duplicate_hash_map
*duplicates
; /* Map from existings to duplicate. */
2968 vec
<tree
> post_decls
; /* Decls to post process. */
2969 unsigned unused
; /* Inhibit any interior TREE_USED
2973 trees_in (module_state
*);
2978 tree
back_ref (int);
2981 tree
start (unsigned = 0);
2984 /* Needed for binfo writing */
2985 bool core_bools (tree
);
2988 /* Stream tree_core, lang_decl_specific and lang_type_specific
2990 bool core_vals (tree
);
2991 bool lang_type_bools (tree
);
2992 bool lang_type_vals (tree
);
2993 bool lang_decl_bools (tree
);
2994 bool lang_decl_vals (tree
);
2995 bool lang_vals (tree
);
2996 bool tree_node_bools (tree
);
2997 bool tree_node_vals (tree
);
3000 tree
tpl_parm_value ();
3003 tree
chained_decls (); /* Follow DECL_CHAIN. */
3004 vec
<tree
, va_heap
> *vec_chained_decls ();
3005 vec
<tree
, va_gc
> *tree_vec (); /* vec of tree. */
3006 vec
<tree_pair_s
, va_gc
> *tree_pair_vec (); /* vec of tree_pair. */
3007 tree
tree_list (bool has_purpose
);
3010 /* Read a tree node. */
3011 tree
tree_node (bool is_use
= false);
3014 bool install_entity (tree decl
);
3015 tree
tpl_parms (unsigned &tpl_levels
);
3016 bool tpl_parms_fini (tree decl
, unsigned tpl_levels
);
3017 bool tpl_header (tree decl
, unsigned *tpl_levels
);
3018 int fn_parms_init (tree
);
3019 void fn_parms_fini (int tag
, tree fn
, tree existing
, bool has_defn
);
3020 unsigned add_indirect_tpl_parms (tree
);
3022 bool add_indirects (tree
);
3025 /* Serialize various definitions. */
3026 bool read_definition (tree decl
);
3029 bool is_matching_decl (tree existing
, tree decl
);
3030 static bool install_implicit_member (tree decl
);
3031 bool read_function_def (tree decl
, tree maybe_template
);
3032 bool read_var_def (tree decl
, tree maybe_template
);
3033 bool read_class_def (tree decl
, tree maybe_template
);
3034 bool read_enum_def (tree decl
, tree maybe_template
);
3037 tree
decl_container ();
3038 tree
key_mergeable (int tag
, merge_kind
, tree decl
, tree inner
, tree type
,
3039 tree container
, bool is_mod
);
3040 unsigned binfo_mergeable (tree
*);
3043 uintptr_t *find_duplicate (tree existing
);
3044 void register_duplicate (tree decl
, tree existing
);
3045 /* Mark as an already diagnosed bad duplicate. */
3046 void unmatched_duplicate (tree existing
)
3048 *find_duplicate (existing
) |= 1;
3052 bool is_duplicate (tree decl
)
3054 return find_duplicate (decl
) != NULL
;
3056 tree
maybe_duplicate (tree decl
)
3058 if (uintptr_t *dup
= find_duplicate (decl
))
3059 return reinterpret_cast<tree
> (*dup
& ~uintptr_t (1));
3062 tree
odr_duplicate (tree decl
, bool has_defn
);
3065 /* Return the next decl to postprocess, or NULL. */
3066 tree
post_process ()
3068 return post_decls
.length () ? post_decls
.pop () : NULL_TREE
;
3071 /* Register DECL for postprocessing. */
3072 void post_process (tree decl
)
3074 post_decls
.safe_push (decl
);
3078 void assert_definition (tree
, bool installing
);
3081 trees_in::trees_in (module_state
*state
)
3082 :parent (), state (state
), unused (0)
3085 back_refs
.create (500);
3086 post_decls
.create (0);
3089 trees_in::~trees_in ()
3091 delete (duplicates
);
3092 back_refs
.release ();
3093 post_decls
.release ();
3096 /* Tree stream writer. */
3097 class trees_out
: public bytes_out
{
3098 typedef bytes_out parent
;
3101 module_state
*state
; /* The module we are writing. */
3102 ptr_int_hash_map tree_map
; /* Trees to references */
3103 depset::hash
*dep_hash
; /* Dependency table. */
3104 int ref_num
; /* Back reference number. */
3107 int importedness
; /* Checker that imports not occurring
3112 trees_out (allocator
*, module_state
*, depset::hash
&deps
, unsigned sec
= 0);
3117 void unmark_trees ();
3120 /* Hey, let's ignore the well known STL iterator idiom. */
3122 unsigned end (elf_out
*sink
, unsigned name
, unsigned *crc_ptr
);
3128 tag_backref
= -1, /* Upper bound on the backrefs. */
3129 tag_value
= 0, /* Write by value. */
3130 tag_fixed
/* Lower bound on the fixed trees. */
3134 bool is_key_order () const
3136 return dep_hash
->is_key_order ();
3140 int insert (tree
, walk_kind
= WK_normal
);
3143 void start (tree
, bool = false);
3146 walk_kind
ref_node (tree
);
3149 void set_importing (int i ATTRIBUTE_UNUSED
)
3157 void core_bools (tree
);
3158 void core_vals (tree
);
3159 void lang_type_bools (tree
);
3160 void lang_type_vals (tree
);
3161 void lang_decl_bools (tree
);
3162 void lang_decl_vals (tree
);
3163 void lang_vals (tree
);
3164 void tree_node_bools (tree
);
3165 void tree_node_vals (tree
);
3168 void chained_decls (tree
);
3169 void vec_chained_decls (tree
);
3170 void tree_vec (vec
<tree
, va_gc
> *);
3171 void tree_pair_vec (vec
<tree_pair_s
, va_gc
> *);
3172 void tree_list (tree
, bool has_purpose
);
3175 /* Mark a node for by-value walking. */
3176 void mark_by_value (tree
);
3179 void tree_node (tree
);
3182 void install_entity (tree decl
, depset
*);
3183 void tpl_parms (tree parms
, unsigned &tpl_levels
);
3184 void tpl_parms_fini (tree decl
, unsigned tpl_levels
);
3185 void fn_parms_fini (tree
) {}
3186 unsigned add_indirect_tpl_parms (tree
);
3188 void add_indirects (tree
);
3189 void fn_parms_init (tree
);
3190 void tpl_header (tree decl
, unsigned *tpl_levels
);
3193 merge_kind
get_merge_kind (tree decl
, depset
*maybe_dep
);
3194 tree
decl_container (tree decl
);
3195 void key_mergeable (int tag
, merge_kind
, tree decl
, tree inner
,
3196 tree container
, depset
*maybe_dep
);
3197 void binfo_mergeable (tree binfo
);
3200 bool decl_node (tree
, walk_kind ref
);
3201 void type_node (tree
);
3202 void tree_value (tree
);
3203 void tpl_parm_value (tree
);
3206 void decl_value (tree
, depset
*);
3209 /* Serialize various definitions. */
3210 void write_definition (tree decl
);
3211 void mark_declaration (tree decl
, bool do_defn
);
3214 void mark_function_def (tree decl
);
3215 void mark_var_def (tree decl
);
3216 void mark_class_def (tree decl
);
3217 void mark_enum_def (tree decl
);
3218 void mark_class_member (tree decl
, bool do_defn
= true);
3219 void mark_binfos (tree type
);
3222 void write_var_def (tree decl
);
3223 void write_function_def (tree decl
);
3224 void write_class_def (tree decl
);
3225 void write_enum_def (tree decl
);
3228 static void assert_definition (tree
);
3231 static void instrument ();
3234 /* Tree instrumentation. */
3235 static unsigned tree_val_count
;
3236 static unsigned decl_val_count
;
3237 static unsigned back_ref_count
;
3238 static unsigned null_count
;
3241 /* Instrumentation counters. */
3242 unsigned trees_out::tree_val_count
;
3243 unsigned trees_out::decl_val_count
;
3244 unsigned trees_out::back_ref_count
;
3245 unsigned trees_out::null_count
;
3247 trees_out::trees_out (allocator
*mem
, module_state
*state
, depset::hash
&deps
,
3249 :parent (mem
), state (state
), tree_map (500),
3250 dep_hash (&deps
), ref_num (0), section (section
)
3257 trees_out::~trees_out ()
3261 /********************************************************************/
3262 /* Location. We're aware of the line-map concept and reproduce it
3263 here. Each imported module allocates a contiguous span of ordinary
3264 maps, and of macro maps. adhoc maps are serialized by contents,
3265 not pre-allocated. The scattered linemaps of a module are
3266 coalesced when writing. */
3269 /* I use half-open [first,second) ranges. */
3270 typedef std::pair
<unsigned,unsigned> range_t
;
3272 /* A range of locations. */
3273 typedef std::pair
<location_t
,location_t
> loc_range_t
;
3275 /* Spans of the line maps that are occupied by this TU. I.e. not
3276 within imports. Only extended when in an interface unit.
3277 Interval zero corresponds to the forced header linemap(s). This
3278 is a singleton object. */
3282 /* An interval of line maps. The line maps here represent a contiguous
3283 non-imported range. */
3285 loc_range_t ordinary
; /* Ordinary map location range. */
3286 loc_range_t macro
; /* Macro map location range. */
3287 int ordinary_delta
; /* Add to ordinary loc to get serialized loc. */
3288 int macro_delta
; /* Likewise for macro loc. */
3296 /* Do not preallocate spans, as that causes
3297 --enable-detailed-mem-stats problems. */
3307 span
&operator[] (unsigned ix
)
3309 return (*spans
)[ix
];
3311 unsigned length () const
3313 return spans
->length ();
3317 bool init_p () const
3319 return spans
!= nullptr;
3322 void init (const line_maps
*lmaps
, const line_map_ordinary
*map
);
3324 /* Slightly skewed preprocessed files can cause us to miss an
3325 initialization in some places. Fallback initializer. */
3329 init (line_table
, nullptr);
3334 SPAN_RESERVED
= 0, /* Reserved (fixed) locations. */
3335 SPAN_FIRST
= 1, /* LWM of locations to stream */
3336 SPAN_MAIN
= 2 /* Main file and onwards. */
3340 location_t
main_start () const
3342 return (*spans
)[SPAN_MAIN
].ordinary
.first
;
3346 void open (location_t
);
3350 /* Propagate imported linemaps to us, if needed. */
3351 bool maybe_propagate (module_state
*import
, location_t loc
);
3354 const span
*ordinary (location_t
);
3355 const span
*macro (location_t
);
3358 static loc_spans spans
;
3360 /********************************************************************/
3361 /* Data needed by a module during the process of loading. */
3362 struct GTY(()) slurping
{
3364 /* Remap import's module numbering to our numbering. Values are
3365 shifted by 1. Bit0 encodes if the import is direct. */
3366 vec
<unsigned, va_heap
, vl_embed
> *
3367 GTY((skip
)) remap
; /* Module owner remapping. */
3369 elf_in
*GTY((skip
)) from
; /* The elf loader. */
3371 /* This map is only for header imports themselves -- the global
3372 headers bitmap hold it for the current TU. */
3373 bitmap headers
; /* Transitive set of direct imports, including
3374 self. Used for macro visibility and
3377 /* These objects point into the mmapped area, unless we're not doing
3378 that, or we got frozen or closed. In those cases they point to
3380 bytes_in macro_defs
; /* Macro definitions. */
3381 bytes_in macro_tbl
; /* Macro table. */
3383 /* Location remapping. first->ordinary, second->macro. */
3384 range_t
GTY((skip
)) loc_deltas
;
3386 unsigned current
; /* Section currently being loaded. */
3387 unsigned remaining
; /* Number of lazy sections yet to read. */
3388 unsigned lru
; /* An LRU counter. */
3391 slurping (elf_in
*);
3395 /* Close the ELF file, if it's open. */
3407 void release_macros ();
3410 void alloc_remap (unsigned size
)
3412 gcc_assert (!remap
);
3413 vec_safe_reserve (remap
, size
);
3414 for (unsigned ix
= size
; ix
--;)
3415 remap
->quick_push (0);
3417 unsigned remap_module (unsigned owner
)
3419 if (owner
< remap
->length ())
3420 return (*remap
)[owner
] >> 1;
3425 /* GC allocation. But we must explicitly delete it. */
3426 static void *operator new (size_t x
)
3428 return ggc_alloc_atomic (x
);
3430 static void operator delete (void *p
)
3436 slurping::slurping (elf_in
*from
)
3437 : remap (NULL
), from (from
),
3438 headers (BITMAP_GGC_ALLOC ()), macro_defs (), macro_tbl (),
3440 current (~0u), remaining (0), lru (0)
3444 slurping::~slurping ()
3452 void slurping::release_macros ()
3454 if (macro_defs
.size
)
3455 elf_in::release (from
, macro_defs
);
3457 elf_in::release (from
, macro_tbl
);
3460 /* Information about location maps used during writing. */
3462 struct location_map_info
{
3468 /* Flage for extensions that end up being streamed. */
3470 enum streamed_extensions
{
3475 /********************************************************************/
3476 struct module_state_config
;
3478 /* Increasing levels of loadedness. */
3479 enum module_loadedness
{
3480 ML_NONE
, /* Not loaded. */
3481 ML_CONFIG
, /* Config loaed. */
3482 ML_PREPROCESSOR
, /* Preprocessor loaded. */
3483 ML_LANGUAGE
, /* Language loaded. */
3486 /* Increasing levels of directness (toplevel) of import. */
3487 enum module_directness
{
3488 MD_NONE
, /* Not direct. */
3489 MD_PARTITION_DIRECT
, /* Direct import of a partition. */
3490 MD_DIRECT
, /* Direct import. */
3491 MD_PURVIEW_DIRECT
, /* direct import in purview. */
3494 /* State of a particular module. */
3496 class GTY((chain_next ("%h.parent"), for_user
)) module_state
{
3498 /* We always import & export ourselves. */
3499 bitmap imports
; /* Transitive modules we're importing. */
3500 bitmap exports
; /* Subset of that, that we're exporting. */
3502 module_state
*parent
;
3503 tree name
; /* Name of the module. */
3505 slurping
*slurp
; /* Data for loading. */
3507 const char *flatname
; /* Flatname of module. */
3508 char *filename
; /* CMI Filename */
3510 /* Indices into the entity_ary. */
3511 unsigned entity_lwm
;
3512 unsigned entity_num
;
3514 /* Location ranges for this module. adhoc-locs are decomposed, so
3515 don't have a range. */
3516 loc_range_t
GTY((skip
)) ordinary_locs
;
3517 loc_range_t
GTY((skip
)) macro_locs
;
3519 /* LOC is first set too the importing location. When initially
3520 loaded it refers to a module loc whose parent is the importing
3522 location_t loc
; /* Location referring to module itself. */
3523 unsigned crc
; /* CRC we saw reading it in. */
3525 unsigned mod
; /* Module owner number. */
3526 unsigned remap
; /* Remapping during writing. */
3528 unsigned short subst
; /* Mangle subst if !0. */
3530 /* How loaded this module is. */
3531 enum module_loadedness loadedness
: 2;
3533 bool module_p
: 1; /* /The/ module of this TU. */
3534 bool header_p
: 1; /* Is a header unit. */
3535 bool interface_p
: 1; /* An interface. */
3536 bool partition_p
: 1; /* A partition. */
3538 /* How directly this module is imported. */
3539 enum module_directness directness
: 2;
3541 bool exported_p
: 1; /* directness != MD_NONE && exported. */
3542 bool cmi_noted_p
: 1; /* We've told the user about the CMI, don't
3544 bool call_init_p
: 1; /* This module's global initializer needs
3546 /* Record extensions emitted or permitted. */
3547 unsigned extensions
: SE_BITS
;
3548 /* 12 bits used, 4 bits remain */
3551 module_state (tree name
, module_state
*, bool);
3557 imports
= exports
= NULL
;
3565 elf_in
*from () const
3571 /* Kind of this module. */
3572 bool is_module () const
3576 bool is_header () const
3580 bool is_interface () const
3584 bool is_partition () const
3589 /* How this module is used in the current TU. */
3590 bool is_exported () const
3594 bool is_direct () const
3596 return directness
>= MD_DIRECT
;
3598 bool is_purview_direct () const
3600 return directness
== MD_PURVIEW_DIRECT
;
3602 bool is_partition_direct () const
3604 return directness
== MD_PARTITION_DIRECT
;
3608 /* Is this not a real module? */
3609 bool is_rooted () const
3611 return loc
!= UNKNOWN_LOCATION
;
3615 bool check_not_purview (location_t loc
);
3618 void mangle (bool include_partition
);
3621 void set_import (module_state
const *, bool is_export
);
3622 void announce (const char *) const;
3625 /* Read and write module. */
3626 void write (elf_out
*to
, cpp_reader
*);
3627 bool read_initial (cpp_reader
*);
3628 bool read_preprocessor (bool);
3629 bool read_language (bool);
3632 /* Read a section. */
3633 bool load_section (unsigned snum
, binding_slot
*mslot
);
3634 /* Lazily read a section. */
3635 bool lazy_load (unsigned index
, binding_slot
*mslot
);
3638 /* Juggle a limited number of file numbers. */
3639 static void freeze_an_elf ();
3640 bool maybe_defrost ();
3643 void maybe_completed_reading ();
3644 bool check_read (bool outermost
, bool ok
);
3647 /* The README, for human consumption. */
3648 void write_readme (elf_out
*to
, cpp_reader
*,
3649 const char *dialect
, unsigned extensions
);
3650 void write_env (elf_out
*to
);
3653 /* Import tables. */
3654 void write_imports (bytes_out
&cfg
, bool direct
);
3655 unsigned read_imports (bytes_in
&cfg
, cpp_reader
*, line_maps
*maps
);
3658 void write_imports (elf_out
*to
, unsigned *crc_ptr
);
3659 bool read_imports (cpp_reader
*, line_maps
*);
3662 void write_partitions (elf_out
*to
, unsigned, unsigned *crc_ptr
);
3663 bool read_partitions (unsigned);
3666 void write_config (elf_out
*to
, struct module_state_config
&, unsigned crc
);
3667 bool read_config (struct module_state_config
&);
3668 static void write_counts (elf_out
*to
, unsigned [], unsigned *crc_ptr
);
3669 bool read_counts (unsigned []);
3672 void note_cmi_name ();
3675 static unsigned write_bindings (elf_out
*to
, vec
<depset
*> depsets
,
3677 bool read_bindings (unsigned count
, unsigned lwm
, unsigned hwm
);
3679 static void write_namespace (bytes_out
&sec
, depset
*ns_dep
);
3680 tree
read_namespace (bytes_in
&sec
);
3682 void write_namespaces (elf_out
*to
, vec
<depset
*> spaces
,
3683 unsigned, unsigned *crc_ptr
);
3684 bool read_namespaces (unsigned);
3686 unsigned write_cluster (elf_out
*to
, depset
*depsets
[], unsigned size
,
3687 depset::hash
&, unsigned *counts
, unsigned *crc_ptr
);
3688 bool read_cluster (unsigned snum
);
3691 unsigned write_inits (elf_out
*to
, depset::hash
&, unsigned *crc_ptr
);
3692 bool read_inits (unsigned count
);
3695 void write_pendings (elf_out
*to
, vec
<depset
*> depsets
,
3696 depset::hash
&, unsigned count
, unsigned *crc_ptr
);
3697 bool read_pendings (unsigned count
);
3700 void write_entities (elf_out
*to
, vec
<depset
*> depsets
,
3701 unsigned count
, unsigned *crc_ptr
);
3702 bool read_entities (unsigned count
, unsigned lwm
, unsigned hwm
);
3705 location_map_info
write_prepare_maps (module_state_config
*);
3706 bool read_prepare_maps (const module_state_config
*);
3708 void write_ordinary_maps (elf_out
*to
, location_map_info
&,
3709 module_state_config
*, bool, unsigned *crc_ptr
);
3710 bool read_ordinary_maps ();
3711 void write_macro_maps (elf_out
*to
, location_map_info
&,
3712 module_state_config
*, unsigned *crc_ptr
);
3713 bool read_macro_maps ();
3716 void write_define (bytes_out
&, const cpp_macro
*, bool located
= true);
3717 cpp_macro
*read_define (bytes_in
&, cpp_reader
*, bool located
= true) const;
3718 unsigned write_macros (elf_out
*to
, cpp_reader
*, unsigned *crc_ptr
);
3719 bool read_macros ();
3720 void install_macros ();
3723 void import_macros ();
3726 static void undef_macro (cpp_reader
*, location_t
, cpp_hashnode
*);
3727 static cpp_macro
*deferred_macro (cpp_reader
*, location_t
, cpp_hashnode
*);
3730 static void write_location (bytes_out
&, location_t
);
3731 location_t
read_location (bytes_in
&) const;
3734 void set_flatname ();
3735 const char *get_flatname () const
3739 location_t
imported_from () const;
3742 void set_filename (const Cody::Packet
&);
3743 bool do_import (cpp_reader
*, bool outermost
);
3746 /* Hash module state by name. This cannot be a member of
3747 module_state, because of GTY restrictions. We never delete from
3748 the hash table, but ggc_ptr_hash doesn't support that
3751 struct module_state_hash
: ggc_ptr_hash
<module_state
> {
3752 typedef std::pair
<tree
,uintptr_t> compare_type
; /* {name,parent} */
3754 static inline hashval_t
hash (const value_type m
);
3755 static inline hashval_t
hash (const compare_type
&n
);
3756 static inline bool equal (const value_type existing
,
3757 const compare_type
&candidate
);
3760 module_state::module_state (tree name
, module_state
*parent
, bool partition
)
3761 : imports (BITMAP_GGC_ALLOC ()), exports (BITMAP_GGC_ALLOC ()),
3762 parent (parent
), name (name
), slurp (NULL
),
3763 flatname (NULL
), filename (NULL
),
3764 entity_lwm (~0u >> 1), entity_num (0),
3765 ordinary_locs (0, 0), macro_locs (0, 0),
3766 loc (UNKNOWN_LOCATION
),
3767 crc (0), mod (MODULE_UNKNOWN
), remap (0), subst (0)
3769 loadedness
= ML_NONE
;
3771 module_p
= header_p
= interface_p
= partition_p
= false;
3773 directness
= MD_NONE
;
3776 cmi_noted_p
= false;
3777 call_init_p
= false;
3779 partition_p
= partition
;
3782 if (name
&& TREE_CODE (name
) == STRING_CST
)
3786 const char *string
= TREE_STRING_POINTER (name
);
3787 gcc_checking_assert (string
[0] == '.'
3788 ? IS_DIR_SEPARATOR (string
[1])
3789 : IS_ABSOLUTE_PATH (string
));
3792 gcc_checking_assert (!(parent
&& header_p
));
3795 module_state::~module_state ()
3800 /* Hash module state. */
3802 module_name_hash (const_tree name
)
3804 if (TREE_CODE (name
) == STRING_CST
)
3805 return htab_hash_string (TREE_STRING_POINTER (name
));
3807 return IDENTIFIER_HASH_VALUE (name
);
3811 module_state_hash::hash (const value_type m
)
3813 hashval_t ph
= pointer_hash
<void>::hash
3814 (reinterpret_cast<void *> (reinterpret_cast<uintptr_t> (m
->parent
)
3815 | m
->is_partition ()));
3816 hashval_t nh
= module_name_hash (m
->name
);
3817 return iterative_hash_hashval_t (ph
, nh
);
3822 module_state_hash::hash (const compare_type
&c
)
3824 hashval_t ph
= pointer_hash
<void>::hash (reinterpret_cast<void *> (c
.second
));
3825 hashval_t nh
= module_name_hash (c
.first
);
3827 return iterative_hash_hashval_t (ph
, nh
);
3831 module_state_hash::equal (const value_type existing
,
3832 const compare_type
&candidate
)
3834 uintptr_t ep
= (reinterpret_cast<uintptr_t> (existing
->parent
)
3835 | existing
->is_partition ());
3836 if (ep
!= candidate
.second
)
3839 /* Identifier comparison is by pointer. If the string_csts happen
3840 to be the same object, then they're equal too. */
3841 if (existing
->name
== candidate
.first
)
3844 /* If neither are string csts, they can't be equal. */
3845 if (TREE_CODE (candidate
.first
) != STRING_CST
3846 || TREE_CODE (existing
->name
) != STRING_CST
)
3849 /* String equality. */
3850 if (TREE_STRING_LENGTH (existing
->name
)
3851 == TREE_STRING_LENGTH (candidate
.first
)
3852 && !memcmp (TREE_STRING_POINTER (existing
->name
),
3853 TREE_STRING_POINTER (candidate
.first
),
3854 TREE_STRING_LENGTH (existing
->name
)))
3860 /********************************************************************/
3864 static const char *module_mapper_name
;
3866 /* CMI repository path and workspace. */
3867 static char *cmi_repo
;
3868 static size_t cmi_repo_length
;
3869 static char *cmi_path
;
3870 static size_t cmi_path_alloc
;
3872 /* Count of available and loaded clusters. */
3873 static unsigned available_clusters
;
3874 static unsigned loaded_clusters
;
3876 /* What the current TU is. */
3877 unsigned module_kind
;
3879 /* Number of global init calls needed. */
3880 unsigned num_init_calls_needed
= 0;
3883 static const std::pair
<tree
*, unsigned> global_tree_arys
[] =
3885 std::pair
<tree
*, unsigned> (sizetype_tab
, stk_type_kind_last
),
3886 std::pair
<tree
*, unsigned> (integer_types
, itk_none
),
3887 std::pair
<tree
*, unsigned> (global_trees
, TI_MODULE_HWM
),
3888 std::pair
<tree
*, unsigned> (c_global_trees
, CTI_MODULE_HWM
),
3889 std::pair
<tree
*, unsigned> (cp_global_trees
, CPTI_MODULE_HWM
),
3890 std::pair
<tree
*, unsigned> (NULL
, 0)
3892 static GTY(()) vec
<tree
, va_gc
> *fixed_trees
;
3893 static unsigned global_crc
;
3895 /* Lazy loading can open many files concurrently, there are
3896 per-process limits on that. We pay attention to the process limit,
3897 and attempt to increase it when we run out. Otherwise we use an
3898 LRU scheme to figure out who to flush. Note that if the import
3899 graph /depth/ exceeds lazy_limit, we'll exceed the limit. */
3900 static unsigned lazy_lru
; /* LRU counter. */
3901 static unsigned lazy_open
; /* Number of open modules */
3902 static unsigned lazy_limit
; /* Current limit of open modules. */
3903 static unsigned lazy_hard_limit
; /* Hard limit on open modules. */
3904 /* Account for source, assembler and dump files & directory searches.
3905 We don't keep the source file's open, so we don't have to account
3906 for #include depth. I think dump files are opened and closed per
3908 #define LAZY_HEADROOM 15 /* File descriptor headroom. */
3910 /* Vector of module state. Indexed by OWNER. Has at least 2 slots. */
3911 static GTY(()) vec
<module_state
*, va_gc
> *modules
;
3913 /* Hash of module state, findable by {name, parent}. */
3914 static GTY(()) hash_table
<module_state_hash
> *modules_hash
;
3916 /* Map of imported entities. We map DECL_UID to index of entity
3918 typedef hash_map
<unsigned/*UID*/, unsigned/*index*/,
3919 simple_hashmap_traits
<int_hash
<unsigned,0>, unsigned>
3921 static entity_map_t
*entity_map
;
3922 /* Doesn't need GTYing, because any tree referenced here is also
3923 findable by, symbol table, specialization table, return type of
3924 reachable function. */
3925 static vec
<binding_slot
, va_heap
, vl_embed
> *entity_ary
;
3927 /* Members entities of imported classes that are defined in this TU.
3928 These are where the entity's context is not from the current TU.
3929 We need to emit the definition (but not the enclosing class).
3931 We could find these by walking ALL the imported classes that we
3932 could provide a member definition. But that's expensive,
3933 especially when you consider lazy implicit member declarations,
3934 which could be ANY imported class. */
3935 static GTY(()) vec
<tree
, va_gc
> *class_members
;
3937 /* The same problem exists for class template partial
3938 specializations. Now that we have constraints, the invariant of
3939 expecting them in the instantiation table no longer holds. One of
3940 the constrained partial specializations will be there, but the
3941 others not so much. It's not even an unconstrained partial
3942 spacialization in the table :( so any partial template declaration
3943 is added to this list too. */
3944 static GTY(()) vec
<tree
, va_gc
> *partial_specializations
;
3946 /********************************************************************/
3948 /* Our module mapper (created lazily). */
3949 module_client
*mapper
;
3951 static module_client
*make_mapper (location_t loc
);
3952 inline module_client
*get_mapper (location_t loc
)
3956 res
= make_mapper (loc
);
3960 /********************************************************************/
3962 get_clone_target (tree decl
)
3966 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
3968 tree res_orig
= DECL_CLONED_FUNCTION (DECL_TEMPLATE_RESULT (decl
));
3970 target
= DECL_TI_TEMPLATE (res_orig
);
3973 target
= DECL_CLONED_FUNCTION (decl
);
3975 gcc_checking_assert (DECL_MAYBE_IN_CHARGE_CDTOR_P (target
));
3980 /* Like FOR_EACH_CLONE, but will walk cloned templates. */
3981 #define FOR_EVERY_CLONE(CLONE, FN) \
3982 if (!DECL_MAYBE_IN_CHARGE_CDTOR_P (FN)); \
3984 for (CLONE = DECL_CHAIN (FN); \
3985 CLONE && DECL_CLONED_FUNCTION_P (CLONE); \
3986 CLONE = DECL_CHAIN (CLONE))
3988 /* It'd be nice if USE_TEMPLATE was a field of template_info
3989 (a) it'd solve the enum case dealt with below,
3990 (b) both class templates and decl templates would store this in the
3992 (c) this function wouldn't need the by-ref arg, which is annoying. */
3995 node_template_info (tree decl
, int &use
)
3997 tree ti
= NULL_TREE
;
3999 if (DECL_IMPLICIT_TYPEDEF_P (decl
))
4001 tree type
= TREE_TYPE (decl
);
4003 ti
= TYPE_TEMPLATE_INFO (type
);
4006 if (TYPE_LANG_SPECIFIC (type
))
4007 use_tpl
= CLASSTYPE_USE_TEMPLATE (type
);
4010 /* An enum, where we don't explicitly encode use_tpl.
4011 If the containing context (a type or a function), is
4012 an ({im,ex}plicit) instantiation, then this is too.
4013 If it's a partial or explicit specialization, then
4015 tree ctx
= CP_DECL_CONTEXT (decl
);
4017 ctx
= TYPE_NAME (ctx
);
4018 node_template_info (ctx
, use
);
4019 use_tpl
= use
!= 2 ? use
: 0;
4023 else if (DECL_LANG_SPECIFIC (decl
)
4024 && (TREE_CODE (decl
) == VAR_DECL
4025 || TREE_CODE (decl
) == TYPE_DECL
4026 || TREE_CODE (decl
) == FUNCTION_DECL
4027 || TREE_CODE (decl
) == FIELD_DECL
4028 || TREE_CODE (decl
) == TEMPLATE_DECL
))
4030 use_tpl
= DECL_USE_TEMPLATE (decl
);
4031 ti
= DECL_TEMPLATE_INFO (decl
);
4038 /* Find the index in entity_ary for an imported DECL. It should
4039 always be there, but bugs can cause it to be missing, and that can
4040 crash the crash reporting -- let's not do that! When streaming
4041 out we place entities from this module there too -- with negated
4045 import_entity_index (tree decl
, bool null_ok
= false)
4047 if (unsigned *slot
= entity_map
->get (DECL_UID (decl
)))
4050 gcc_checking_assert (null_ok
);
4054 /* Find the module for an imported entity at INDEX in the entity ary.
4055 There must be one. */
4057 static module_state
*
4058 import_entity_module (unsigned index
)
4060 if (index
> ~(~0u >> 1))
4061 /* This is an index for an exported entity. */
4062 return (*modules
)[0];
4065 unsigned len
= modules
->length () - pos
;
4068 unsigned half
= len
/ 2;
4069 module_state
*probe
= (*modules
)[pos
+ half
];
4070 if (index
< probe
->entity_lwm
)
4072 else if (index
< probe
->entity_lwm
+ probe
->entity_num
)
4077 len
= len
- (half
+ 1);
4084 /********************************************************************/
4085 /* A dumping machinery. */
4090 LOCATION
= TDF_LINENO
, /* -lineno:Source location streaming. */
4091 DEPEND
= TDF_GRAPH
, /* -graph:Dependency graph construction. */
4092 CLUSTER
= TDF_BLOCKS
, /* -blocks:Clusters. */
4093 TREE
= TDF_UID
, /* -uid:Tree streaming. */
4094 MERGE
= TDF_ALIAS
, /* -alias:Mergeable Entities. */
4095 ELF
= TDF_ASMNAME
, /* -asmname:Elf data. */
4096 MACRO
= TDF_VOPS
/* -vops:Macros. */
4101 typedef vec
<module_state
*, va_heap
, vl_embed
> stack_t
;
4103 FILE *stream
; /* Dump stream. */
4104 unsigned indent
; /* Local indentation. */
4105 bool bol
; /* Beginning of line. */
4106 stack_t stack
; /* Trailing array of module_state. */
4108 bool nested_name (tree
); /* Dump a name following DECL_CONTEXT. */
4117 /* Push/pop module state dumping. */
4118 unsigned push (module_state
*);
4119 void pop (unsigned);
4122 /* Change local indentation. */
4132 gcc_checking_assert (dumps
->indent
);
4138 /* Is dump enabled?. */
4139 bool operator () (int mask
= 0)
4141 if (!dumps
|| !dumps
->stream
)
4143 if (mask
&& !(mask
& flags
))
4147 /* Dump some information. */
4148 bool operator () (const char *, ...);
4152 static dumper dump
= {0, dump_flags_t (0)};
4154 /* Push to dumping M. Return previous indentation level. */
4157 dumper::push (module_state
*m
)
4159 FILE *stream
= NULL
;
4160 if (!dumps
|| !dumps
->stack
.length ())
4162 stream
= dump_begin (module_dump_id
, &flags
);
4167 if (!dumps
|| !dumps
->stack
.space (1))
4169 /* Create or extend the dump implementor. */
4170 unsigned current
= dumps
? dumps
->stack
.length () : 0;
4171 unsigned count
= current
? current
* 2 : EXPERIMENT (1, 20);
4172 size_t alloc
= (offsetof (impl
, stack
)
4173 + impl::stack_t::embedded_size (count
));
4174 dumps
= XRESIZEVAR (impl
, dumps
, alloc
);
4175 dumps
->stack
.embedded_init (count
, current
);
4178 dumps
->stream
= stream
;
4180 unsigned n
= dumps
->indent
;
4183 dumps
->stack
.quick_push (m
);
4186 module_state
*from
= NULL
;
4188 if (dumps
->stack
.length () > 1)
4189 from
= dumps
->stack
[dumps
->stack
.length () - 2];
4192 dump (from
? "Starting module %M (from %M)"
4193 : "Starting module %M", m
, from
);
4199 /* Pop from dumping. Restore indentation to N. */
4201 void dumper::pop (unsigned n
)
4206 gcc_checking_assert (dump () && !dumps
->indent
);
4207 if (module_state
*m
= dumps
->stack
[dumps
->stack
.length () - 1])
4209 module_state
*from
= (dumps
->stack
.length () > 1
4210 ? dumps
->stack
[dumps
->stack
.length () - 2] : NULL
);
4211 dump (from
? "Finishing module %M (returning to %M)"
4212 : "Finishing module %M", m
, from
);
4214 dumps
->stack
.pop ();
4216 if (!dumps
->stack
.length ())
4218 dump_end (module_dump_id
, dumps
->stream
);
4219 dumps
->stream
= NULL
;
4223 /* Dump a nested name for arbitrary tree T. Sometimes it won't have a
4227 dumper::impl::nested_name (tree t
)
4229 tree ti
= NULL_TREE
;
4231 tree name
= NULL_TREE
;
4233 if (t
&& TREE_CODE (t
) == TREE_BINFO
)
4236 if (t
&& TYPE_P (t
))
4239 if (t
&& DECL_P (t
))
4241 if (t
== global_namespace
|| DECL_TEMPLATE_PARM_P (t
))
4243 else if (tree ctx
= DECL_CONTEXT (t
))
4244 if (TREE_CODE (ctx
) == TRANSLATION_UNIT_DECL
4245 || nested_name (ctx
))
4246 fputs ("::", stream
);
4249 ti
= node_template_info (t
, use_tpl
);
4250 if (ti
&& TREE_CODE (TI_TEMPLATE (ti
)) == TEMPLATE_DECL
4251 && (DECL_TEMPLATE_RESULT (TI_TEMPLATE (ti
)) == t
))
4252 t
= TI_TEMPLATE (ti
);
4253 if (TREE_CODE (t
) == TEMPLATE_DECL
)
4254 fputs ("template ", stream
);
4256 if (DECL_LANG_SPECIFIC (t
) && DECL_MODULE_IMPORT_P (t
))
4258 /* We need to be careful here, so as to not explode on
4259 inconsistent data -- we're probably debugging, because
4260 Something Is Wrong. */
4261 unsigned index
= import_entity_index (t
, true);
4262 if (!(index
& ~(~0u >> 1)))
4263 origin
= import_entity_module (index
)->mod
;
4264 else if (index
> ~(~0u >> 1))
4265 /* An imported partition member that we're emitting. */
4271 name
= DECL_NAME (t
) ? DECL_NAME (t
)
4272 : HAS_DECL_ASSEMBLER_NAME_P (t
) ? DECL_ASSEMBLER_NAME_RAW (t
)
4279 switch (TREE_CODE (name
))
4282 fputs ("#unnamed#", stream
);
4285 case IDENTIFIER_NODE
:
4286 fwrite (IDENTIFIER_POINTER (name
), 1, IDENTIFIER_LENGTH (name
), stream
);
4290 print_hex (wi::to_wide (name
), stream
);
4294 /* If TREE_TYPE is NULL, this is a raw string. */
4295 fwrite (TREE_STRING_POINTER (name
), 1,
4296 TREE_STRING_LENGTH (name
) - (TREE_TYPE (name
) != NULL_TREE
),
4301 fputs ("#null#", stream
);
4305 const module_state
*module
= (*modules
)[origin
];
4306 fprintf (stream
, "@%s:%d", !module
? "" : !module
->name
? "(unnamed)"
4307 : module
->get_flatname (), origin
);
4309 else if (origin
== -2)
4310 fprintf (stream
, "@???");
4314 tree args
= INNERMOST_TEMPLATE_ARGS (TI_ARGS (ti
));
4315 fputs ("<", stream
);
4317 for (int ix
= 0; ix
!= TREE_VEC_LENGTH (args
); ix
++)
4320 fputs (",", stream
);
4321 nested_name (TREE_VEC_ELT (args
, ix
));
4323 fputs (">", stream
);
4329 /* Formatted dumping. FORMAT begins with '+' do not emit a trailing
4330 new line. (Normally it is appended.)
4335 %N - name -- DECL_NAME
4336 %P - context:name pair
4337 %R - unsigned:unsigned ratio
4338 %S - symbol -- DECL_ASSEMBLER_NAME
4341 --- the following are printf-like, but without its flexibility
4348 We do not implement the printf modifiers. */
4351 dumper::operator () (const char *format
, ...)
4356 bool no_nl
= format
[0] == '+';
4361 /* Module import indent. */
4362 if (unsigned depth
= dumps
->stack
.length () - 1)
4364 const char *prefix
= ">>>>";
4365 fprintf (dumps
->stream
, (depth
<= strlen (prefix
)
4366 ? &prefix
[strlen (prefix
) - depth
]
4367 : ">.%d.>"), depth
);
4371 if (unsigned indent
= dumps
->indent
)
4373 const char *prefix
= " ";
4374 fprintf (dumps
->stream
, (indent
<= strlen (prefix
)
4375 ? &prefix
[strlen (prefix
) - indent
]
4376 : " .%d. "), indent
);
4382 va_start (args
, format
);
4383 while (const char *esc
= strchr (format
, '%'))
4385 fwrite (format
, 1, (size_t)(esc
- format
), dumps
->stream
);
4393 fputc ('%', dumps
->stream
);
4396 case 'C': /* Code */
4398 tree_code code
= (tree_code
)va_arg (args
, unsigned);
4399 fputs (get_tree_code_name (code
), dumps
->stream
);
4403 case 'I': /* Identifier. */
4405 tree t
= va_arg (args
, tree
);
4406 dumps
->nested_name (t
);
4410 case 'M': /* Module. */
4412 const char *str
= "(none)";
4413 if (module_state
*m
= va_arg (args
, module_state
*))
4415 if (!m
->is_rooted ())
4418 str
= m
->get_flatname ();
4420 fputs (str
, dumps
->stream
);
4424 case 'N': /* Name. */
4426 tree t
= va_arg (args
, tree
);
4427 if (t
&& TREE_CODE (t
) == OVERLOAD
)
4429 fputc ('\'', dumps
->stream
);
4430 dumps
->nested_name (t
);
4431 fputc ('\'', dumps
->stream
);
4435 case 'P': /* Pair. */
4437 tree ctx
= va_arg (args
, tree
);
4438 tree name
= va_arg (args
, tree
);
4439 fputc ('\'', dumps
->stream
);
4440 dumps
->nested_name (ctx
);
4441 if (ctx
&& ctx
!= global_namespace
)
4442 fputs ("::", dumps
->stream
);
4443 dumps
->nested_name (name
);
4444 fputc ('\'', dumps
->stream
);
4448 case 'R': /* Ratio */
4450 unsigned a
= va_arg (args
, unsigned);
4451 unsigned b
= va_arg (args
, unsigned);
4452 fprintf (dumps
->stream
, "%.1f", (float) a
/ (b
+ !b
));
4456 case 'S': /* Symbol name */
4458 tree t
= va_arg (args
, tree
);
4459 if (t
&& TYPE_P (t
))
4461 if (t
&& HAS_DECL_ASSEMBLER_NAME_P (t
)
4462 && DECL_ASSEMBLER_NAME_SET_P (t
))
4464 fputc ('(', dumps
->stream
);
4465 fputs (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t
)),
4467 fputc (')', dumps
->stream
);
4472 case 'U': /* long unsigned. */
4474 unsigned long u
= va_arg (args
, unsigned long);
4475 fprintf (dumps
->stream
, "%lu", u
);
4479 case 'V': /* Verson. */
4481 unsigned v
= va_arg (args
, unsigned);
4484 version2string (v
, string
);
4485 fputs (string
, dumps
->stream
);
4489 case 'c': /* Character. */
4491 int c
= va_arg (args
, int);
4492 fputc (c
, dumps
->stream
);
4496 case 'd': /* Decimal Int. */
4498 int d
= va_arg (args
, int);
4499 fprintf (dumps
->stream
, "%d", d
);
4503 case 'p': /* Pointer. */
4505 void *p
= va_arg (args
, void *);
4506 fprintf (dumps
->stream
, "%p", p
);
4510 case 's': /* String. */
4512 const char *s
= va_arg (args
, char *);
4513 gcc_checking_assert (s
);
4514 fputs (s
, dumps
->stream
);
4518 case 'u': /* Unsigned. */
4520 unsigned u
= va_arg (args
, unsigned);
4521 fprintf (dumps
->stream
, "%u", u
);
4525 case 'x': /* Hex. */
4527 unsigned x
= va_arg (args
, unsigned);
4528 fprintf (dumps
->stream
, "%x", x
);
4533 fputs (format
, dumps
->stream
);
4538 fputc ('\n', dumps
->stream
);
4543 struct note_def_cache_hasher
: ggc_cache_ptr_hash
<tree_node
>
4545 static int keep_cache_entry (tree t
)
4548 /* GTY is unfortunately not clever enough to conditionalize
4552 if (ggc_marked_p (t
))
4555 unsigned n
= dump
.push (NULL
);
4556 /* This might or might not be an error. We should note its
4557 dropping whichever. */
4558 dump () && dump ("Dropping %N from note_defs table", t
);
4565 /* We should stream each definition at most once.
4566 This needs to be a cache because there are cases where a definition
4567 ends up being not retained, and we need to drop those so we don't
4568 get confused if memory is reallocated. */
4569 typedef hash_table
<note_def_cache_hasher
> note_defs_table_t
;
4570 static GTY((cache
)) note_defs_table_t
*note_defs
;
4573 trees_in::assert_definition (tree decl ATTRIBUTE_UNUSED
,
4574 bool installing ATTRIBUTE_UNUSED
)
4577 tree
*slot
= note_defs
->find_slot (decl
, installing
? INSERT
: NO_INSERT
);
4580 /* We must be inserting for the first time. */
4581 gcc_assert (!*slot
);
4585 /* If this is not the mergeable entity, it should not be in the
4586 table. If it is a non-global-module mergeable entity, it
4587 should be in the table. Global module entities could have been
4588 defined textually in the current TU and so might or might not
4590 gcc_assert (!is_duplicate (decl
)
4593 || !DECL_LANG_SPECIFIC (decl
)
4594 || !DECL_MODULE_PURVIEW_P (decl
)
4595 || (!DECL_MODULE_IMPORT_P (decl
)
4596 && header_module_p ())));
4598 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
4599 gcc_assert (!note_defs
->find_slot (DECL_TEMPLATE_RESULT (decl
), NO_INSERT
));
4604 trees_out::assert_definition (tree decl ATTRIBUTE_UNUSED
)
4607 tree
*slot
= note_defs
->find_slot (decl
, INSERT
);
4608 gcc_assert (!*slot
);
4610 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
4611 gcc_assert (!note_defs
->find_slot (DECL_TEMPLATE_RESULT (decl
), NO_INSERT
));
4615 /********************************************************************/
4622 pp_needs_newline (global_dc
->printer
) = true;
4623 diagnostic_set_last_function (global_dc
, (diagnostic_info
*) NULL
);
4628 /* Set the cmi repo. Strip trailing '/', '.' becomes NULL. */
4631 set_cmi_repo (const char *r
)
4633 XDELETEVEC (cmi_repo
);
4634 XDELETEVEC (cmi_path
);
4638 cmi_repo_length
= 0;
4643 size_t len
= strlen (r
);
4644 cmi_repo
= XNEWVEC (char, len
+ 1);
4645 memcpy (cmi_repo
, r
, len
+ 1);
4647 if (len
> 1 && IS_DIR_SEPARATOR (cmi_repo
[len
-1]))
4649 if (len
== 1 && cmi_repo
[0] == '.')
4652 cmi_repo_length
= len
;
4655 /* TO is a repo-relative name. Provide one that we may use from where
4659 maybe_add_cmi_prefix (const char *to
, size_t *len_p
= NULL
)
4661 size_t len
= len_p
|| cmi_repo_length
? strlen (to
) : 0;
4663 if (cmi_repo_length
&& !IS_ABSOLUTE_PATH (to
))
4665 if (cmi_path_alloc
< cmi_repo_length
+ len
+ 2)
4667 XDELETEVEC (cmi_path
);
4668 cmi_path_alloc
= cmi_repo_length
+ len
* 2 + 2;
4669 cmi_path
= XNEWVEC (char, cmi_path_alloc
);
4671 memcpy (cmi_path
, cmi_repo
, cmi_repo_length
);
4672 cmi_path
[cmi_repo_length
] = DIR_SEPARATOR
;
4675 memcpy (&cmi_path
[cmi_repo_length
+ 1], to
, len
+ 1);
4676 len
+= cmi_repo_length
+ 1;
4686 /* Try and create the directories of PATH. */
4689 create_dirs (char *path
)
4691 /* Try and create the missing directories. */
4692 for (char *base
= path
; *base
; base
++)
4693 if (IS_DIR_SEPARATOR (*base
))
4697 int failed
= mkdir (path
, S_IRWXU
| S_IRWXG
| S_IRWXO
);
4698 dump () && dump ("Mkdir ('%s') errno:=%u", path
, failed
? errno
: 0);
4701 /* Maybe racing with another creator (of a *different*
4708 /* Given a CLASSTYPE_DECL_LIST VALUE get the the template friend decl,
4709 if that's what this is. */
4712 friend_from_decl_list (tree frnd
)
4716 if (TREE_CODE (frnd
) != TEMPLATE_DECL
)
4718 tree tmpl
= NULL_TREE
;
4721 res
= TYPE_NAME (frnd
);
4722 if (CLASSTYPE_TEMPLATE_INFO (frnd
))
4723 tmpl
= CLASSTYPE_TI_TEMPLATE (frnd
);
4725 else if (DECL_TEMPLATE_INFO (frnd
))
4727 tmpl
= DECL_TI_TEMPLATE (frnd
);
4728 if (TREE_CODE (tmpl
) != TEMPLATE_DECL
)
4732 if (tmpl
&& DECL_TEMPLATE_RESULT (tmpl
) == res
)
4740 find_enum_member (tree ctx
, tree name
)
4742 for (tree values
= TYPE_VALUES (ctx
);
4743 values
; values
= TREE_CHAIN (values
))
4744 if (DECL_NAME (TREE_VALUE (values
)) == name
)
4745 return TREE_VALUE (values
);
4750 /********************************************************************/
4751 /* Instrumentation gathered writing bytes. */
4754 bytes_out::instrument ()
4756 dump ("Wrote %u bytes in %u blocks", lengths
[3], spans
[3]);
4757 dump ("Wrote %u bits in %u bytes", lengths
[0] + lengths
[1], lengths
[2]);
4758 for (unsigned ix
= 0; ix
< 2; ix
++)
4759 dump (" %u %s spans of %R bits", spans
[ix
],
4760 ix
? "one" : "zero", lengths
[ix
], spans
[ix
]);
4761 dump (" %u blocks with %R bits padding", spans
[2],
4762 lengths
[2] * 8 - (lengths
[0] + lengths
[1]), spans
[2]);
4765 /* Instrumentation gathered writing trees. */
4767 trees_out::instrument ()
4771 bytes_out::instrument ();
4773 dump (" %u decl trees", decl_val_count
);
4774 dump (" %u other trees", tree_val_count
);
4775 dump (" %u back references", back_ref_count
);
4776 dump (" %u null trees", null_count
);
4780 /* Setup and teardown for a tree walk. */
4785 gcc_assert (!streaming_p () || !tree_map
.elements ());
4793 trees_out::end (elf_out
*sink
, unsigned name
, unsigned *crc_ptr
)
4795 gcc_checking_assert (streaming_p ());
4798 return parent::end (sink
, name
, crc_ptr
);
4804 gcc_assert (!streaming_p ());
4807 /* Do not parent::end -- we weren't streaming. */
4811 trees_out::mark_trees ()
4813 if (size_t size
= tree_map
.elements ())
4815 /* This isn't our first rodeo, destroy and recreate the
4816 tree_map. I'm a bad bad man. Use the previous size as a
4817 guess for the next one (so not all bad). */
4818 tree_map
.~ptr_int_hash_map ();
4819 new (&tree_map
) ptr_int_hash_map (size
);
4822 /* Install the fixed trees, with +ve references. */
4823 unsigned limit
= fixed_trees
->length ();
4824 for (unsigned ix
= 0; ix
!= limit
; ix
++)
4826 tree val
= (*fixed_trees
)[ix
];
4827 bool existed
= tree_map
.put (val
, ix
+ tag_fixed
);
4828 gcc_checking_assert (!TREE_VISITED (val
) && !existed
);
4829 TREE_VISITED (val
) = true;
4835 /* Unmark the trees we encountered */
4838 trees_out::unmark_trees ()
4840 ptr_int_hash_map::iterator
end (tree_map
.end ());
4841 for (ptr_int_hash_map::iterator
iter (tree_map
.begin ()); iter
!= end
; ++iter
)
4843 tree node
= reinterpret_cast<tree
> ((*iter
).first
);
4844 int ref
= (*iter
).second
;
4845 /* We should have visited the node, and converted its mergeable
4846 reference to a regular reference. */
4847 gcc_checking_assert (TREE_VISITED (node
)
4848 && (ref
<= tag_backref
|| ref
>= tag_fixed
));
4849 TREE_VISITED (node
) = false;
4853 /* Mark DECL for by-value walking. We do this by inserting it into
4854 the tree map with a reference of zero. May be called multiple
4855 times on the same node. */
4858 trees_out::mark_by_value (tree decl
)
4860 gcc_checking_assert (DECL_P (decl
)
4861 /* Enum consts are INTEGER_CSTS. */
4862 || TREE_CODE (decl
) == INTEGER_CST
4863 || TREE_CODE (decl
) == TREE_BINFO
);
4865 if (TREE_VISITED (decl
))
4866 /* Must already be forced or fixed. */
4867 gcc_checking_assert (*tree_map
.get (decl
) >= tag_value
);
4870 bool existed
= tree_map
.put (decl
, tag_value
);
4871 gcc_checking_assert (!existed
);
4872 TREE_VISITED (decl
) = true;
4877 trees_out::get_tag (tree t
)
4879 gcc_checking_assert (TREE_VISITED (t
));
4880 return *tree_map
.get (t
);
4883 /* Insert T into the map, return its tag number. */
4886 trees_out::insert (tree t
, walk_kind walk
)
4888 gcc_checking_assert (walk
!= WK_normal
|| !TREE_VISITED (t
));
4889 int tag
= --ref_num
;
4891 int &slot
= tree_map
.get_or_insert (t
, &existed
);
4892 gcc_checking_assert (TREE_VISITED (t
) == existed
4894 || (walk
== WK_value
&& slot
== tag_value
)));
4895 TREE_VISITED (t
) = true;
4901 /* Insert T into the backreference array. Return its back reference
4905 trees_in::insert (tree t
)
4907 gcc_checking_assert (t
|| get_overrun ());
4908 back_refs
.safe_push (t
);
4909 return -(int)back_refs
.length ();
4912 /* A chained set of decls. */
4915 trees_out::chained_decls (tree decls
)
4917 for (; decls
; decls
= DECL_CHAIN (decls
))
4919 if (VAR_OR_FUNCTION_DECL_P (decls
)
4920 && DECL_LOCAL_DECL_P (decls
))
4922 /* Make sure this is the first encounter, and mark for
4924 gcc_checking_assert (!TREE_VISITED (decls
)
4925 && !DECL_TEMPLATE_INFO (decls
));
4926 mark_by_value (decls
);
4930 tree_node (NULL_TREE
);
4934 trees_in::chained_decls ()
4936 tree decls
= NULL_TREE
;
4937 for (tree
*chain
= &decls
;;)
4938 if (tree decl
= tree_node ())
4940 if (!DECL_P (decl
) || DECL_CHAIN (decl
))
4946 chain
= &DECL_CHAIN (decl
);
4954 /* A vector of decls following DECL_CHAIN. */
4957 trees_out::vec_chained_decls (tree decls
)
4963 for (tree decl
= decls
; decl
; decl
= DECL_CHAIN (decl
))
4968 for (tree decl
= decls
; decl
; decl
= DECL_CHAIN (decl
))
4970 if (DECL_IMPLICIT_TYPEDEF_P (decl
)
4971 && TYPE_NAME (TREE_TYPE (decl
)) != decl
)
4972 /* An anonynmous struct with a typedef name. An odd thing to
4974 tree_node (NULL_TREE
);
4980 vec
<tree
, va_heap
> *
4981 trees_in::vec_chained_decls ()
4983 vec
<tree
, va_heap
> *v
= NULL
;
4985 if (unsigned len
= u ())
4989 for (unsigned ix
= 0; ix
< len
; ix
++)
4991 tree decl
= tree_node ();
4992 if (decl
&& !DECL_P (decl
))
4997 v
->quick_push (decl
);
5010 /* A vector of trees. */
5013 trees_out::tree_vec (vec
<tree
, va_gc
> *v
)
5015 unsigned len
= vec_safe_length (v
);
5018 for (unsigned ix
= 0; ix
!= len
; ix
++)
5019 tree_node ((*v
)[ix
]);
5023 trees_in::tree_vec ()
5025 vec
<tree
, va_gc
> *v
= NULL
;
5026 if (unsigned len
= u ())
5029 for (unsigned ix
= 0; ix
!= len
; ix
++)
5030 v
->quick_push (tree_node ());
5035 /* A vector of tree pairs. */
5038 trees_out::tree_pair_vec (vec
<tree_pair_s
, va_gc
> *v
)
5040 unsigned len
= vec_safe_length (v
);
5044 for (unsigned ix
= 0; ix
!= len
; ix
++)
5046 tree_pair_s
const &s
= (*v
)[ix
];
5047 tree_node (s
.purpose
);
5048 tree_node (s
.value
);
5052 vec
<tree_pair_s
, va_gc
> *
5053 trees_in::tree_pair_vec ()
5055 vec
<tree_pair_s
, va_gc
> *v
= NULL
;
5056 if (unsigned len
= u ())
5059 for (unsigned ix
= 0; ix
!= len
; ix
++)
5062 s
.purpose
= tree_node ();
5063 s
.value
= tree_node ();
5071 trees_out::tree_list (tree list
, bool has_purpose
)
5073 for (; list
; list
= TREE_CHAIN (list
))
5075 gcc_checking_assert (TREE_VALUE (list
));
5076 tree_node (TREE_VALUE (list
));
5078 tree_node (TREE_PURPOSE (list
));
5080 tree_node (NULL_TREE
);
5084 trees_in::tree_list (bool has_purpose
)
5086 tree res
= NULL_TREE
;
5088 for (tree
*chain
= &res
; tree value
= tree_node ();
5089 chain
= &TREE_CHAIN (*chain
))
5091 tree purpose
= has_purpose
? tree_node () : NULL_TREE
;
5092 *chain
= build_tree_list (purpose
, value
);
5097 /* Start tree write. Write information to allocate the receiving
5101 trees_out::start (tree t
, bool code_streamed
)
5105 enum tree_code code
= TREE_CODE (t
);
5106 gcc_checking_assert (TYPE_MAIN_VARIANT (t
) == t
);
5107 /* All these types are TYPE_NON_COMMON. */
5108 gcc_checking_assert (code
== RECORD_TYPE
5109 || code
== UNION_TYPE
5110 || code
== ENUMERAL_TYPE
5111 || code
== TEMPLATE_TYPE_PARM
5112 || code
== TEMPLATE_TEMPLATE_PARM
5113 || code
== BOUND_TEMPLATE_TEMPLATE_PARM
);
5119 switch (TREE_CODE (t
))
5122 if (TREE_CODE_CLASS (TREE_CODE (t
)) == tcc_vl_exp
)
5123 u (VL_EXP_OPERAND_LENGTH (t
));
5127 u (TREE_INT_CST_NUNITS (t
));
5128 u (TREE_INT_CST_EXT_NUNITS (t
));
5129 u (TREE_INT_CST_OFFSET_NUNITS (t
));
5133 state
->extensions
|= SE_OPENMP
;
5134 u (OMP_CLAUSE_CODE (t
));
5138 str (TREE_STRING_POINTER (t
), TREE_STRING_LENGTH (t
));
5142 u (VECTOR_CST_LOG2_NPATTERNS (t
));
5143 u (VECTOR_CST_NELTS_PER_PATTERN (t
));
5147 u (BINFO_N_BASE_BINFOS (t
));
5151 u (TREE_VEC_LENGTH (t
));
5156 gcc_unreachable (); /* Not supported in C++. */
5159 case IDENTIFIER_NODE
:
5161 case TARGET_MEM_REF
:
5162 case TRANSLATION_UNIT_DECL
:
5163 /* We shouldn't meet these. */
5169 /* Start tree read. Allocate the receiving node. */
5172 trees_in::start (unsigned code
)
5182 if (code
>= MAX_TREE_CODES
)
5188 else if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
5190 unsigned ops
= u ();
5191 t
= build_vl_exp (tree_code (code
), ops
);
5194 t
= make_node (tree_code (code
));
5201 t
= make_int_cst (n
, e
);
5202 TREE_INT_CST_OFFSET_NUNITS(t
) = u ();
5208 if (!(state
->extensions
& SE_OPENMP
))
5211 unsigned omp_code
= u ();
5212 t
= build_omp_clause (UNKNOWN_LOCATION
, omp_clause_code (omp_code
));
5219 const char *chars
= str (&l
);
5220 t
= build_string (l
, chars
);
5226 unsigned log2_npats
= u ();
5227 unsigned elts_per
= u ();
5228 t
= make_vector (log2_npats
, elts_per
);
5233 t
= make_tree_binfo (u ());
5237 t
= make_tree_vec (u ());
5241 case IDENTIFIER_NODE
:
5244 case TARGET_MEM_REF
:
5245 case TRANSLATION_UNIT_DECL
:
5252 /* The structure streamers access the raw fields, because the
5253 alternative, of using the accessor macros can require using
5254 different accessors for the same underlying field, depending on the
5255 tree code. That's both confusing and annoying. */
5257 /* Read & write the core boolean flags. */
5260 trees_out::core_bools (tree t
)
5262 #define WB(X) (b (X))
5263 tree_code code
= TREE_CODE (t
);
5265 WB (t
->base
.side_effects_flag
);
5266 WB (t
->base
.constant_flag
);
5267 WB (t
->base
.addressable_flag
);
5268 WB (t
->base
.volatile_flag
);
5269 WB (t
->base
.readonly_flag
);
5270 /* base.asm_written_flag is a property of the current TU's use of
5272 WB (t
->base
.nowarning_flag
);
5273 /* base.visited read as zero (it's set for writer, because that's
5274 how we mark nodes). */
5275 /* base.used_flag is not streamed. Readers may set TREE_USED of
5277 WB (t
->base
.nothrow_flag
);
5278 WB (t
->base
.static_flag
);
5279 if (TREE_CODE_CLASS (code
) != tcc_type
)
5280 /* This is TYPE_CACHED_VALUES_P for types. */
5281 WB (t
->base
.public_flag
);
5282 WB (t
->base
.private_flag
);
5283 WB (t
->base
.protected_flag
);
5284 WB (t
->base
.deprecated_flag
);
5285 WB (t
->base
.default_def_flag
);
5292 case TARGET_MEM_REF
:
5294 /* These use different base.u fields. */
5298 WB (t
->base
.u
.bits
.lang_flag_0
);
5299 bool flag_1
= t
->base
.u
.bits
.lang_flag_1
;
5302 else if (code
== TEMPLATE_INFO
)
5303 /* This is TI_PENDING_TEMPLATE_FLAG, not relevant to reader. */
5305 else if (code
== VAR_DECL
)
5307 /* This is DECL_INITIALIZED_P. */
5308 if (DECL_CONTEXT (t
)
5309 && TREE_CODE (DECL_CONTEXT (t
)) != FUNCTION_DECL
)
5310 /* We'll set this when reading the definition. */
5314 WB (t
->base
.u
.bits
.lang_flag_2
);
5315 WB (t
->base
.u
.bits
.lang_flag_3
);
5316 WB (t
->base
.u
.bits
.lang_flag_4
);
5317 WB (t
->base
.u
.bits
.lang_flag_5
);
5318 WB (t
->base
.u
.bits
.lang_flag_6
);
5319 WB (t
->base
.u
.bits
.saturating_flag
);
5320 WB (t
->base
.u
.bits
.unsigned_flag
);
5321 WB (t
->base
.u
.bits
.packed_flag
);
5322 WB (t
->base
.u
.bits
.user_align
);
5323 WB (t
->base
.u
.bits
.nameless_flag
);
5324 WB (t
->base
.u
.bits
.atomic_flag
);
5328 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_COMMON
))
5330 WB (t
->type_common
.no_force_blk_flag
);
5331 WB (t
->type_common
.needs_constructing_flag
);
5332 WB (t
->type_common
.transparent_aggr_flag
);
5333 WB (t
->type_common
.restrict_flag
);
5334 WB (t
->type_common
.string_flag
);
5335 WB (t
->type_common
.lang_flag_0
);
5336 WB (t
->type_common
.lang_flag_1
);
5337 WB (t
->type_common
.lang_flag_2
);
5338 WB (t
->type_common
.lang_flag_3
);
5339 WB (t
->type_common
.lang_flag_4
);
5340 WB (t
->type_common
.lang_flag_5
);
5341 WB (t
->type_common
.lang_flag_6
);
5342 WB (t
->type_common
.typeless_storage
);
5345 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
5347 WB (t
->decl_common
.nonlocal_flag
);
5348 WB (t
->decl_common
.virtual_flag
);
5349 WB (t
->decl_common
.ignored_flag
);
5350 WB (t
->decl_common
.abstract_flag
);
5351 WB (t
->decl_common
.artificial_flag
);
5352 WB (t
->decl_common
.preserve_flag
);
5353 WB (t
->decl_common
.debug_expr_is_from
);
5354 WB (t
->decl_common
.lang_flag_0
);
5355 WB (t
->decl_common
.lang_flag_1
);
5356 WB (t
->decl_common
.lang_flag_2
);
5357 WB (t
->decl_common
.lang_flag_3
);
5358 WB (t
->decl_common
.lang_flag_4
);
5359 WB (t
->decl_common
.lang_flag_5
);
5360 WB (t
->decl_common
.lang_flag_6
);
5361 WB (t
->decl_common
.lang_flag_7
);
5362 WB (t
->decl_common
.lang_flag_8
);
5363 WB (t
->decl_common
.decl_flag_0
);
5366 /* DECL_EXTERNAL -> decl_flag_1
5367 == it is defined elsewhere
5368 DECL_NOT_REALLY_EXTERN -> base.not_really_extern
5369 == that was a lie, it is here */
5371 bool is_external
= t
->decl_common
.decl_flag_1
;
5373 /* decl_flag_1 is DECL_EXTERNAL. Things we emit here, might
5374 well be external from the POV of an importer. */
5375 // FIXME: Do we need to know if this is a TEMPLATE_RESULT --
5376 // a flag from the caller?
5384 && !DECL_VAR_DECLARED_INLINE_P (t
))
5390 && !DECL_DECLARED_INLINE_P (t
))
5397 WB (t
->decl_common
.decl_flag_2
);
5398 WB (t
->decl_common
.decl_flag_3
);
5399 WB (t
->decl_common
.not_gimple_reg_flag
);
5400 WB (t
->decl_common
.decl_by_reference_flag
);
5401 WB (t
->decl_common
.decl_read_flag
);
5402 WB (t
->decl_common
.decl_nonshareable_flag
);
5405 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
5407 WB (t
->decl_with_vis
.defer_output
);
5408 WB (t
->decl_with_vis
.hard_register
);
5409 WB (t
->decl_with_vis
.common_flag
);
5410 WB (t
->decl_with_vis
.in_text_section
);
5411 WB (t
->decl_with_vis
.in_constant_pool
);
5412 WB (t
->decl_with_vis
.dllimport_flag
);
5413 WB (t
->decl_with_vis
.weak_flag
);
5414 WB (t
->decl_with_vis
.seen_in_bind_expr
);
5415 WB (t
->decl_with_vis
.comdat_flag
);
5416 WB (t
->decl_with_vis
.visibility_specified
);
5417 WB (t
->decl_with_vis
.init_priority_p
);
5418 WB (t
->decl_with_vis
.shadowed_for_var_p
);
5419 WB (t
->decl_with_vis
.cxx_constructor
);
5420 WB (t
->decl_with_vis
.cxx_destructor
);
5421 WB (t
->decl_with_vis
.final
);
5422 WB (t
->decl_with_vis
.regdecl_flag
);
5425 if (CODE_CONTAINS_STRUCT (code
, TS_FUNCTION_DECL
))
5427 WB (t
->function_decl
.static_ctor_flag
);
5428 WB (t
->function_decl
.static_dtor_flag
);
5429 WB (t
->function_decl
.uninlinable
);
5430 WB (t
->function_decl
.possibly_inlined
);
5431 WB (t
->function_decl
.novops_flag
);
5432 WB (t
->function_decl
.returns_twice_flag
);
5433 WB (t
->function_decl
.malloc_flag
);
5434 WB (t
->function_decl
.declared_inline_flag
);
5435 WB (t
->function_decl
.no_inline_warning_flag
);
5436 WB (t
->function_decl
.no_instrument_function_entry_exit
);
5437 WB (t
->function_decl
.no_limit_stack
);
5438 WB (t
->function_decl
.disregard_inline_limits
);
5439 WB (t
->function_decl
.pure_flag
);
5440 WB (t
->function_decl
.looping_const_or_pure_flag
);
5442 WB (t
->function_decl
.has_debug_args_flag
);
5443 WB (t
->function_decl
.versioned_function
);
5445 /* decl_type is a (misnamed) 2 bit discriminator. */
5446 unsigned kind
= t
->function_decl
.decl_type
;
5447 WB ((kind
>> 0) & 1);
5448 WB ((kind
>> 1) & 1);
5454 trees_in::core_bools (tree t
)
5456 #define RB(X) ((X) = b ())
5457 tree_code code
= TREE_CODE (t
);
5459 RB (t
->base
.side_effects_flag
);
5460 RB (t
->base
.constant_flag
);
5461 RB (t
->base
.addressable_flag
);
5462 RB (t
->base
.volatile_flag
);
5463 RB (t
->base
.readonly_flag
);
5464 /* base.asm_written_flag is not streamed. */
5465 RB (t
->base
.nowarning_flag
);
5466 /* base.visited is not streamed. */
5467 /* base.used_flag is not streamed. */
5468 RB (t
->base
.nothrow_flag
);
5469 RB (t
->base
.static_flag
);
5470 if (TREE_CODE_CLASS (code
) != tcc_type
)
5471 RB (t
->base
.public_flag
);
5472 RB (t
->base
.private_flag
);
5473 RB (t
->base
.protected_flag
);
5474 RB (t
->base
.deprecated_flag
);
5475 RB (t
->base
.default_def_flag
);
5482 case TARGET_MEM_REF
:
5484 /* These use different base.u fields. */
5488 RB (t
->base
.u
.bits
.lang_flag_0
);
5489 RB (t
->base
.u
.bits
.lang_flag_1
);
5490 RB (t
->base
.u
.bits
.lang_flag_2
);
5491 RB (t
->base
.u
.bits
.lang_flag_3
);
5492 RB (t
->base
.u
.bits
.lang_flag_4
);
5493 RB (t
->base
.u
.bits
.lang_flag_5
);
5494 RB (t
->base
.u
.bits
.lang_flag_6
);
5495 RB (t
->base
.u
.bits
.saturating_flag
);
5496 RB (t
->base
.u
.bits
.unsigned_flag
);
5497 RB (t
->base
.u
.bits
.packed_flag
);
5498 RB (t
->base
.u
.bits
.user_align
);
5499 RB (t
->base
.u
.bits
.nameless_flag
);
5500 RB (t
->base
.u
.bits
.atomic_flag
);
5504 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_COMMON
))
5506 RB (t
->type_common
.no_force_blk_flag
);
5507 RB (t
->type_common
.needs_constructing_flag
);
5508 RB (t
->type_common
.transparent_aggr_flag
);
5509 RB (t
->type_common
.restrict_flag
);
5510 RB (t
->type_common
.string_flag
);
5511 RB (t
->type_common
.lang_flag_0
);
5512 RB (t
->type_common
.lang_flag_1
);
5513 RB (t
->type_common
.lang_flag_2
);
5514 RB (t
->type_common
.lang_flag_3
);
5515 RB (t
->type_common
.lang_flag_4
);
5516 RB (t
->type_common
.lang_flag_5
);
5517 RB (t
->type_common
.lang_flag_6
);
5518 RB (t
->type_common
.typeless_storage
);
5521 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
5523 RB (t
->decl_common
.nonlocal_flag
);
5524 RB (t
->decl_common
.virtual_flag
);
5525 RB (t
->decl_common
.ignored_flag
);
5526 RB (t
->decl_common
.abstract_flag
);
5527 RB (t
->decl_common
.artificial_flag
);
5528 RB (t
->decl_common
.preserve_flag
);
5529 RB (t
->decl_common
.debug_expr_is_from
);
5530 RB (t
->decl_common
.lang_flag_0
);
5531 RB (t
->decl_common
.lang_flag_1
);
5532 RB (t
->decl_common
.lang_flag_2
);
5533 RB (t
->decl_common
.lang_flag_3
);
5534 RB (t
->decl_common
.lang_flag_4
);
5535 RB (t
->decl_common
.lang_flag_5
);
5536 RB (t
->decl_common
.lang_flag_6
);
5537 RB (t
->decl_common
.lang_flag_7
);
5538 RB (t
->decl_common
.lang_flag_8
);
5539 RB (t
->decl_common
.decl_flag_0
);
5540 RB (t
->decl_common
.decl_flag_1
);
5541 RB (t
->decl_common
.decl_flag_2
);
5542 RB (t
->decl_common
.decl_flag_3
);
5543 RB (t
->decl_common
.not_gimple_reg_flag
);
5544 RB (t
->decl_common
.decl_by_reference_flag
);
5545 RB (t
->decl_common
.decl_read_flag
);
5546 RB (t
->decl_common
.decl_nonshareable_flag
);
5549 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
5551 RB (t
->decl_with_vis
.defer_output
);
5552 RB (t
->decl_with_vis
.hard_register
);
5553 RB (t
->decl_with_vis
.common_flag
);
5554 RB (t
->decl_with_vis
.in_text_section
);
5555 RB (t
->decl_with_vis
.in_constant_pool
);
5556 RB (t
->decl_with_vis
.dllimport_flag
);
5557 RB (t
->decl_with_vis
.weak_flag
);
5558 RB (t
->decl_with_vis
.seen_in_bind_expr
);
5559 RB (t
->decl_with_vis
.comdat_flag
);
5560 RB (t
->decl_with_vis
.visibility_specified
);
5561 RB (t
->decl_with_vis
.init_priority_p
);
5562 RB (t
->decl_with_vis
.shadowed_for_var_p
);
5563 RB (t
->decl_with_vis
.cxx_constructor
);
5564 RB (t
->decl_with_vis
.cxx_destructor
);
5565 RB (t
->decl_with_vis
.final
);
5566 RB (t
->decl_with_vis
.regdecl_flag
);
5569 if (CODE_CONTAINS_STRUCT (code
, TS_FUNCTION_DECL
))
5571 RB (t
->function_decl
.static_ctor_flag
);
5572 RB (t
->function_decl
.static_dtor_flag
);
5573 RB (t
->function_decl
.uninlinable
);
5574 RB (t
->function_decl
.possibly_inlined
);
5575 RB (t
->function_decl
.novops_flag
);
5576 RB (t
->function_decl
.returns_twice_flag
);
5577 RB (t
->function_decl
.malloc_flag
);
5578 RB (t
->function_decl
.declared_inline_flag
);
5579 RB (t
->function_decl
.no_inline_warning_flag
);
5580 RB (t
->function_decl
.no_instrument_function_entry_exit
);
5581 RB (t
->function_decl
.no_limit_stack
);
5582 RB (t
->function_decl
.disregard_inline_limits
);
5583 RB (t
->function_decl
.pure_flag
);
5584 RB (t
->function_decl
.looping_const_or_pure_flag
);
5586 RB (t
->function_decl
.has_debug_args_flag
);
5587 RB (t
->function_decl
.versioned_function
);
5589 /* decl_type is a (misnamed) 2 bit discriminator. */
5591 kind
|= unsigned (b ()) << 0;
5592 kind
|= unsigned (b ()) << 1;
5593 t
->function_decl
.decl_type
= function_decl_type (kind
);
5596 return !get_overrun ();
5600 trees_out::lang_decl_bools (tree t
)
5602 #define WB(X) (b (X))
5603 const struct lang_decl
*lang
= DECL_LANG_SPECIFIC (t
);
5605 WB (lang
->u
.base
.language
== lang_cplusplus
);
5606 WB ((lang
->u
.base
.use_template
>> 0) & 1);
5607 WB ((lang
->u
.base
.use_template
>> 1) & 1);
5608 /* Do not write lang->u.base.not_really_extern, importer will set
5609 when reading the definition (if any). */
5610 WB (lang
->u
.base
.initialized_in_class
);
5611 WB (lang
->u
.base
.threadprivate_or_deleted_p
);
5612 /* Do not write lang->u.base.anticipated_p, it is a property of the
5614 WB (lang
->u
.base
.friend_or_tls
);
5615 WB (lang
->u
.base
.unknown_bound_p
);
5616 /* Do not write lang->u.base.odr_used, importer will recalculate if
5617 they do ODR use this decl. */
5618 WB (lang
->u
.base
.concept_p
);
5619 WB (lang
->u
.base
.var_declared_inline_p
);
5620 WB (lang
->u
.base
.dependent_init_p
);
5621 WB (lang
->u
.base
.module_purview_p
);
5622 if (VAR_OR_FUNCTION_DECL_P (t
))
5623 WB (lang
->u
.base
.module_pending_p
);
5624 switch (lang
->u
.base
.selector
)
5629 case lds_fn
: /* lang_decl_fn. */
5630 WB (lang
->u
.fn
.global_ctor_p
);
5631 WB (lang
->u
.fn
.global_dtor_p
);
5632 WB (lang
->u
.fn
.static_function
);
5633 WB (lang
->u
.fn
.pure_virtual
);
5634 WB (lang
->u
.fn
.defaulted_p
);
5635 WB (lang
->u
.fn
.has_in_charge_parm_p
);
5636 WB (lang
->u
.fn
.has_vtt_parm_p
);
5637 /* There shouldn't be a pending inline at this point. */
5638 gcc_assert (!lang
->u
.fn
.pending_inline_p
);
5639 WB (lang
->u
.fn
.nonconverting
);
5640 WB (lang
->u
.fn
.thunk_p
);
5641 WB (lang
->u
.fn
.this_thunk_p
);
5642 /* Do not stream lang->u.hidden_friend_p, it is a property of
5644 WB (lang
->u
.fn
.omp_declare_reduction_p
);
5645 WB (lang
->u
.fn
.has_dependent_explicit_spec_p
);
5646 WB (lang
->u
.fn
.immediate_fn_p
);
5647 WB (lang
->u
.fn
.maybe_deleted
);
5650 case lds_decomp
: /* lang_decl_decomp. */
5654 case lds_min
: /* lang_decl_min. */
5659 case lds_ns
: /* lang_decl_ns. */
5663 case lds_parm
: /* lang_decl_parm. */
5671 trees_in::lang_decl_bools (tree t
)
5673 #define RB(X) ((X) = b ())
5674 struct lang_decl
*lang
= DECL_LANG_SPECIFIC (t
);
5676 lang
->u
.base
.language
= b () ? lang_cplusplus
: lang_c
;
5680 lang
->u
.base
.use_template
= v
;
5681 /* lang->u.base.not_really_extern is not streamed. */
5682 RB (lang
->u
.base
.initialized_in_class
);
5683 RB (lang
->u
.base
.threadprivate_or_deleted_p
);
5684 /* lang->u.base.anticipated_p is not streamed. */
5685 RB (lang
->u
.base
.friend_or_tls
);
5686 RB (lang
->u
.base
.unknown_bound_p
);
5687 /* lang->u.base.odr_used is not streamed. */
5688 RB (lang
->u
.base
.concept_p
);
5689 RB (lang
->u
.base
.var_declared_inline_p
);
5690 RB (lang
->u
.base
.dependent_init_p
);
5691 RB (lang
->u
.base
.module_purview_p
);
5692 if (VAR_OR_FUNCTION_DECL_P (t
))
5693 RB (lang
->u
.base
.module_pending_p
);
5694 switch (lang
->u
.base
.selector
)
5699 case lds_fn
: /* lang_decl_fn. */
5700 RB (lang
->u
.fn
.global_ctor_p
);
5701 RB (lang
->u
.fn
.global_dtor_p
);
5702 RB (lang
->u
.fn
.static_function
);
5703 RB (lang
->u
.fn
.pure_virtual
);
5704 RB (lang
->u
.fn
.defaulted_p
);
5705 RB (lang
->u
.fn
.has_in_charge_parm_p
);
5706 RB (lang
->u
.fn
.has_vtt_parm_p
);
5707 RB (lang
->u
.fn
.nonconverting
);
5708 RB (lang
->u
.fn
.thunk_p
);
5709 RB (lang
->u
.fn
.this_thunk_p
);
5710 /* lang->u.fn.hidden_friend_p is not streamed. */
5711 RB (lang
->u
.fn
.omp_declare_reduction_p
);
5712 RB (lang
->u
.fn
.has_dependent_explicit_spec_p
);
5713 RB (lang
->u
.fn
.immediate_fn_p
);
5714 RB (lang
->u
.fn
.maybe_deleted
);
5717 case lds_decomp
: /* lang_decl_decomp. */
5721 case lds_min
: /* lang_decl_min. */
5726 case lds_ns
: /* lang_decl_ns. */
5730 case lds_parm
: /* lang_decl_parm. */
5735 return !get_overrun ();
5739 trees_out::lang_type_bools (tree t
)
5741 #define WB(X) (b (X))
5742 const struct lang_type
*lang
= TYPE_LANG_SPECIFIC (t
);
5744 WB (lang
->has_type_conversion
);
5745 WB (lang
->has_copy_ctor
);
5746 WB (lang
->has_default_ctor
);
5747 WB (lang
->const_needs_init
);
5748 WB (lang
->ref_needs_init
);
5749 WB (lang
->has_const_copy_assign
);
5750 WB ((lang
->use_template
>> 0) & 1);
5751 WB ((lang
->use_template
>> 1) & 1);
5753 WB (lang
->has_mutable
);
5754 WB (lang
->com_interface
);
5755 WB (lang
->non_pod_class
);
5756 WB (lang
->nearly_empty_p
);
5757 WB (lang
->user_align
);
5758 WB (lang
->has_copy_assign
);
5760 WB (lang
->has_array_new
);
5762 WB ((lang
->gets_delete
>> 0) & 1);
5763 WB ((lang
->gets_delete
>> 1) & 1);
5764 // Interfaceness is recalculated upon reading. May have to revisit?
5765 // How do dllexport and dllimport interact across a module?
5766 // lang->interface_only
5767 // lang->interface_unknown
5768 WB (lang
->contains_empty_class_p
);
5769 WB (lang
->anon_aggr
);
5770 WB (lang
->non_zero_init
);
5773 WB (lang
->vec_new_uses_cookie
);
5774 WB (lang
->declared_class
);
5775 WB (lang
->diamond_shaped
);
5776 WB (lang
->repeated_base
);
5777 gcc_assert (!lang
->being_defined
);
5778 // lang->debug_requested
5779 WB (lang
->fields_readonly
);
5780 WB (lang
->ptrmemfunc_flag
);
5782 WB (lang
->lazy_default_ctor
);
5783 WB (lang
->lazy_copy_ctor
);
5784 WB (lang
->lazy_copy_assign
);
5785 WB (lang
->lazy_destructor
);
5786 WB (lang
->has_const_copy_ctor
);
5787 WB (lang
->has_complex_copy_ctor
);
5788 WB (lang
->has_complex_copy_assign
);
5789 WB (lang
->non_aggregate
);
5791 WB (lang
->has_complex_dflt
);
5792 WB (lang
->has_list_ctor
);
5793 WB (lang
->non_std_layout
);
5794 WB (lang
->is_literal
);
5795 WB (lang
->lazy_move_ctor
);
5796 WB (lang
->lazy_move_assign
);
5797 WB (lang
->has_complex_move_ctor
);
5798 WB (lang
->has_complex_move_assign
);
5800 WB (lang
->has_constexpr_ctor
);
5801 WB (lang
->unique_obj_representations
);
5802 WB (lang
->unique_obj_representations_set
);
5807 trees_in::lang_type_bools (tree t
)
5809 #define RB(X) ((X) = b ())
5810 struct lang_type
*lang
= TYPE_LANG_SPECIFIC (t
);
5812 RB (lang
->has_type_conversion
);
5813 RB (lang
->has_copy_ctor
);
5814 RB (lang
->has_default_ctor
);
5815 RB (lang
->const_needs_init
);
5816 RB (lang
->ref_needs_init
);
5817 RB (lang
->has_const_copy_assign
);
5821 lang
->use_template
= v
;
5823 RB (lang
->has_mutable
);
5824 RB (lang
->com_interface
);
5825 RB (lang
->non_pod_class
);
5826 RB (lang
->nearly_empty_p
);
5827 RB (lang
->user_align
);
5828 RB (lang
->has_copy_assign
);
5830 RB (lang
->has_array_new
);
5834 lang
->gets_delete
= v
;
5835 // lang->interface_only
5836 // lang->interface_unknown
5837 lang
->interface_unknown
= true; // Redetermine interface
5838 RB (lang
->contains_empty_class_p
);
5839 RB (lang
->anon_aggr
);
5840 RB (lang
->non_zero_init
);
5843 RB (lang
->vec_new_uses_cookie
);
5844 RB (lang
->declared_class
);
5845 RB (lang
->diamond_shaped
);
5846 RB (lang
->repeated_base
);
5847 gcc_assert (!lang
->being_defined
);
5848 gcc_assert (!lang
->debug_requested
);
5849 RB (lang
->fields_readonly
);
5850 RB (lang
->ptrmemfunc_flag
);
5852 RB (lang
->lazy_default_ctor
);
5853 RB (lang
->lazy_copy_ctor
);
5854 RB (lang
->lazy_copy_assign
);
5855 RB (lang
->lazy_destructor
);
5856 RB (lang
->has_const_copy_ctor
);
5857 RB (lang
->has_complex_copy_ctor
);
5858 RB (lang
->has_complex_copy_assign
);
5859 RB (lang
->non_aggregate
);
5861 RB (lang
->has_complex_dflt
);
5862 RB (lang
->has_list_ctor
);
5863 RB (lang
->non_std_layout
);
5864 RB (lang
->is_literal
);
5865 RB (lang
->lazy_move_ctor
);
5866 RB (lang
->lazy_move_assign
);
5867 RB (lang
->has_complex_move_ctor
);
5868 RB (lang
->has_complex_move_assign
);
5870 RB (lang
->has_constexpr_ctor
);
5871 RB (lang
->unique_obj_representations
);
5872 RB (lang
->unique_obj_representations_set
);
5874 return !get_overrun ();
5877 /* Read & write the core values and pointers. */
5880 trees_out::core_vals (tree t
)
5882 #define WU(X) (u (X))
5883 #define WT(X) (tree_node (X))
5884 tree_code code
= TREE_CODE (t
);
5886 /* First by shape of the tree. */
5888 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_MINIMAL
))
5890 /* Write this early, for better log information. */
5891 WT (t
->decl_minimal
.name
);
5892 if (!DECL_TEMPLATE_PARM_P (t
))
5893 WT (t
->decl_minimal
.context
);
5895 state
->write_location (*this, t
->decl_minimal
.locus
);
5898 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_COMMON
))
5900 /* The only types we write also have TYPE_NON_COMMON. */
5901 gcc_checking_assert (CODE_CONTAINS_STRUCT (code
, TS_TYPE_NON_COMMON
));
5903 /* We only stream the main variant. */
5904 gcc_checking_assert (TYPE_MAIN_VARIANT (t
) == t
);
5906 /* Stream the name & context first, for better log information */
5907 WT (t
->type_common
.name
);
5908 WT (t
->type_common
.context
);
5910 /* By construction we want to make sure we have the canonical
5911 and main variants already in the type table, so emit them
5913 WT (t
->type_common
.main_variant
);
5915 tree canonical
= t
->type_common
.canonical
;
5916 if (canonical
&& DECL_TEMPLATE_PARM_P (TYPE_NAME (t
)))
5917 /* We do not want to wander into different templates.
5918 Reconstructed on stream in. */
5922 /* type_common.next_variant is internally manipulated. */
5923 /* type_common.pointer_to, type_common.reference_to. */
5927 WU (t
->type_common
.precision
);
5928 WU (t
->type_common
.contains_placeholder_bits
);
5929 WU (t
->type_common
.mode
);
5930 WU (t
->type_common
.align
);
5933 if (!RECORD_OR_UNION_CODE_P (code
))
5935 WT (t
->type_common
.size
);
5936 WT (t
->type_common
.size_unit
);
5938 WT (t
->type_common
.attributes
);
5940 WT (t
->type_common
.common
.chain
); /* TYPE_STUB_DECL. */
5943 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
5947 WU (t
->decl_common
.mode
);
5948 WU (t
->decl_common
.off_align
);
5949 WU (t
->decl_common
.align
);
5952 /* For templates these hold instantiation (partial and/or
5953 specialization) information. */
5954 if (code
!= TEMPLATE_DECL
)
5956 WT (t
->decl_common
.size
);
5957 WT (t
->decl_common
.size_unit
);
5960 WT (t
->decl_common
.attributes
);
5961 // FIXME: Does this introduce cross-decl links? For instance
5962 // from instantiation to the template. If so, we'll need more
5963 // deduplication logic. I think we'll need to walk the blocks
5964 // of the owning function_decl's abstract origin in tandem, to
5965 // generate the locating data needed?
5966 WT (t
->decl_common
.abstract_origin
);
5969 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
5971 WT (t
->decl_with_vis
.assembler_name
);
5973 WU (t
->decl_with_vis
.visibility
);
5976 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_NON_COMMON
))
5978 /* Records and unions hold FIELDS, VFIELD & BINFO on these
5980 if (!RECORD_OR_UNION_CODE_P (code
) && code
!= ENUMERAL_TYPE
)
5982 // FIXME: These are from tpl_parm_value's 'type' writing.
5983 // Perhaps it should just be doing them directly?
5984 gcc_checking_assert (code
== TEMPLATE_TYPE_PARM
5985 || code
== TEMPLATE_TEMPLATE_PARM
5986 || code
== BOUND_TEMPLATE_TEMPLATE_PARM
);
5987 gcc_checking_assert (!TYPE_CACHED_VALUES_P (t
));
5988 WT (t
->type_non_common
.values
);
5989 WT (t
->type_non_common
.maxval
);
5990 WT (t
->type_non_common
.minval
);
5993 WT (t
->type_non_common
.lang_1
);
5996 if (CODE_CONTAINS_STRUCT (code
, TS_EXP
))
5998 state
->write_location (*this, t
->exp
.locus
);
6000 /* Walk in forward order, as (for instance) REQUIRES_EXPR has a
6001 bunch of unscoped parms on its first operand. It's safer to
6002 create those in order. */
6003 bool vl
= TREE_CODE_CLASS (code
) == tcc_vl_exp
;
6004 for (unsigned limit
= (vl
? VL_EXP_OPERAND_LENGTH (t
)
6005 : TREE_OPERAND_LENGTH (t
)),
6006 ix
= unsigned (vl
); ix
!= limit
; ix
++)
6007 WT (TREE_OPERAND (t
, ix
));
6010 /* The CODE_CONTAINS tables were inaccurate when I started. */
6011 gcc_checking_assert (TREE_CODE_CLASS (code
) != tcc_expression
6012 && TREE_CODE_CLASS (code
) != tcc_binary
6013 && TREE_CODE_CLASS (code
) != tcc_unary
6014 && TREE_CODE_CLASS (code
) != tcc_reference
6015 && TREE_CODE_CLASS (code
) != tcc_comparison
6016 && TREE_CODE_CLASS (code
) != tcc_statement
6017 && TREE_CODE_CLASS (code
) != tcc_vl_exp
);
6019 /* Then by CODE. Special cases and/or 1:1 tree shape
6026 case ARGUMENT_PACK_SELECT
: /* Transient during instantiation. */
6027 case DEFERRED_PARSE
: /* Expanded upon completion of
6029 case IDENTIFIER_NODE
: /* Streamed specially. */
6030 case BINDING_VECTOR
: /* Only in namespace-scope symbol
6033 case TRANSLATION_UNIT_DECL
: /* There is only one, it is a
6035 case USERDEF_LITERAL
: /* Expanded during parsing. */
6036 gcc_unreachable (); /* Should never meet. */
6040 WT (TREE_REALPART (t
));
6041 WT (TREE_IMAGPART (t
));
6045 gcc_unreachable (); /* Not supported in C++. */
6050 unsigned num
= TREE_INT_CST_EXT_NUNITS (t
);
6051 for (unsigned ix
= 0; ix
!= num
; ix
++)
6052 wu (TREE_INT_CST_ELT (t
, ix
));
6057 gcc_unreachable (); /* Not supported in C++. */
6061 buf (TREE_REAL_CST_PTR (t
), sizeof (real_value
));
6065 /* Streamed during start. */
6069 for (unsigned ix
= vector_cst_encoded_nelts (t
); ix
--;)
6070 WT (VECTOR_CST_ENCODED_ELT (t
, ix
));
6075 if (DECL_CONTEXT (t
)
6076 && TREE_CODE (DECL_CONTEXT (t
)) != FUNCTION_DECL
)
6082 if (DECL_HAS_VALUE_EXPR_P (t
))
6083 WT (DECL_VALUE_EXPR (t
));
6088 WT (t
->decl_common
.initial
);
6092 WT (t
->field_decl
.offset
);
6093 WT (t
->field_decl
.bit_field_type
);
6094 WT (t
->field_decl
.qualifier
); /* bitfield unit. */
6095 WT (t
->field_decl
.bit_offset
);
6096 WT (t
->field_decl
.fcontext
);
6097 WT (t
->decl_common
.initial
);
6103 WU (t
->label_decl
.label_decl_uid
);
6104 WU (t
->label_decl
.eh_landing_pad_nr
);
6111 /* Builtins can be streamed by value when a header declares
6113 WU (DECL_BUILT_IN_CLASS (t
));
6114 if (DECL_BUILT_IN_CLASS (t
) != NOT_BUILT_IN
)
6115 WU (DECL_UNCHECKED_FUNCTION_CODE (t
));
6118 WT (t
->function_decl
.personality
);
6119 WT (t
->function_decl
.function_specific_target
);
6120 WT (t
->function_decl
.function_specific_optimization
);
6121 WT (t
->function_decl
.vindex
);
6125 /* USING_DECL_DECLS */
6126 WT (t
->decl_common
.initial
);
6130 /* USING_DECL: USING_DECL_SCOPE */
6131 /* TYPE_DECL: DECL_ORIGINAL_TYPE */
6132 WT (t
->decl_non_common
.result
);
6135 /* Miscellaneous common nodes. */
6137 state
->write_location (*this, t
->block
.locus
);
6138 state
->write_location (*this, t
->block
.end_locus
);
6140 /* DECL_LOCAL_DECL_P decls are first encountered here and
6141 streamed by value. */
6142 chained_decls (t
->block
.vars
);
6143 /* nonlocalized_vars is a middle-end thing. */
6144 WT (t
->block
.subblocks
);
6145 WT (t
->block
.supercontext
);
6146 // FIXME: As for decl's abstract_origin, does this introduce crosslinks?
6147 WT (t
->block
.abstract_origin
);
6148 /* fragment_origin, fragment_chain are middle-end things. */
6149 WT (t
->block
.chain
);
6150 /* nonlocalized_vars, block_num & die are middle endy/debug
6161 unsigned len
= vec_safe_length (t
->constructor
.elts
);
6165 for (unsigned ix
= 0; ix
!= len
; ix
++)
6167 const constructor_elt
&elt
= (*t
->constructor
.elts
)[ix
];
6177 /* The ompcode is serialized in start. */
6179 WU (t
->omp_clause
.subcode
.map_kind
);
6180 state
->write_location (*this, t
->omp_clause
.locus
);
6182 unsigned len
= omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)];
6183 for (unsigned ix
= 0; ix
!= len
; ix
++)
6184 WT (t
->omp_clause
.ops
[ix
]);
6188 case STATEMENT_LIST
:
6189 for (tree_stmt_iterator iter
= tsi_start (t
);
6190 !tsi_end_p (iter
); tsi_next (&iter
))
6191 if (tree stmt
= tsi_stmt (iter
))
6196 case OPTIMIZATION_NODE
:
6197 case TARGET_OPTION_NODE
:
6198 // FIXME: Our representation for these two nodes is a cache of
6199 // the resulting set of options. Not a record of the options
6200 // that got changed by a particular attribute or pragma. Should
6201 // we record that, or should we record the diff from the command
6202 // line options? The latter seems the right behaviour, but is
6203 // (a) harder, and I guess could introduce strangeness if the
6204 // importer has set some incompatible set of optimization flags?
6210 WT (t
->binfo
.common
.chain
);
6211 WT (t
->binfo
.offset
);
6212 WT (t
->binfo
.inheritance
);
6213 WT (t
->binfo
.vptr_field
);
6215 WT (t
->binfo
.vtable
);
6216 WT (t
->binfo
.virtuals
);
6217 WT (t
->binfo
.vtt_subvtt
);
6218 WT (t
->binfo
.vtt_vptr
);
6220 tree_vec (BINFO_BASE_ACCESSES (t
));
6221 unsigned num
= vec_safe_length (BINFO_BASE_ACCESSES (t
));
6222 for (unsigned ix
= 0; ix
!= num
; ix
++)
6223 WT (BINFO_BASE_BINFO (t
, ix
));
6228 WT (t
->list
.purpose
);
6230 WT (t
->list
.common
.chain
);
6234 for (unsigned ix
= TREE_VEC_LENGTH (t
); ix
--;)
6235 WT (TREE_VEC_ELT (t
, ix
));
6236 /* We stash NON_DEFAULT_TEMPLATE_ARGS_COUNT on TREE_CHAIN! */
6237 gcc_checking_assert (!t
->type_common
.common
.chain
6238 || (TREE_CODE (t
->type_common
.common
.chain
)
6240 WT (t
->type_common
.common
.chain
);
6243 /* C++-specific nodes ... */
6245 WT (((lang_tree_node
*)t
)->baselink
.binfo
);
6246 WT (((lang_tree_node
*)t
)->baselink
.functions
);
6247 WT (((lang_tree_node
*)t
)->baselink
.access_binfo
);
6250 case CONSTRAINT_INFO
:
6251 WT (((lang_tree_node
*)t
)->constraint_info
.template_reqs
);
6252 WT (((lang_tree_node
*)t
)->constraint_info
.declarator_reqs
);
6253 WT (((lang_tree_node
*)t
)->constraint_info
.associated_constr
);
6256 case DEFERRED_NOEXCEPT
:
6257 WT (((lang_tree_node
*)t
)->deferred_noexcept
.pattern
);
6258 WT (((lang_tree_node
*)t
)->deferred_noexcept
.args
);
6262 WT (((lang_tree_node
*)t
)->lambda_expression
.capture_list
);
6263 WT (((lang_tree_node
*)t
)->lambda_expression
.this_capture
);
6264 WT (((lang_tree_node
*)t
)->lambda_expression
.extra_scope
);
6265 /* pending_proxies is a parse-time thing. */
6266 gcc_assert (!((lang_tree_node
*)t
)->lambda_expression
.pending_proxies
);
6267 state
->write_location
6268 (*this, ((lang_tree_node
*)t
)->lambda_expression
.locus
);
6271 WU (((lang_tree_node
*)t
)->lambda_expression
.default_capture_mode
);
6272 WU (((lang_tree_node
*)t
)->lambda_expression
.discriminator
);
6277 WT (((lang_tree_node
*)t
)->overload
.function
);
6278 WT (t
->common
.chain
);
6282 WT (((lang_tree_node
*)t
)->ptrmem
.member
);
6286 WT (((lang_tree_node
*)t
)->static_assertion
.condition
);
6287 WT (((lang_tree_node
*)t
)->static_assertion
.message
);
6288 state
->write_location
6289 (*this, ((lang_tree_node
*)t
)->static_assertion
.location
);
6293 /* Streamed with the template_decl node itself. */
6295 (TREE_VISITED (((lang_tree_node
*)t
)->template_decl
.arguments
));
6297 (TREE_VISITED (((lang_tree_node
*)t
)->template_decl
.result
)
6298 || dep_hash
->find_dependency (t
)->is_alias_tmpl_inst ());
6299 if (DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (t
))
6300 WT (DECL_CHAIN (t
));
6305 WT (((lang_tree_node
*)t
)->template_info
.tmpl
);
6306 WT (((lang_tree_node
*)t
)->template_info
.args
);
6308 const auto *ac
= (((lang_tree_node
*)t
)
6309 ->template_info
.deferred_access_checks
);
6310 unsigned len
= vec_safe_length (ac
);
6315 for (unsigned ix
= 0; ix
!= len
; ix
++)
6317 const auto &m
= (*ac
)[ix
];
6321 state
->write_location (*this, m
.loc
);
6327 case TEMPLATE_PARM_INDEX
:
6330 WU (((lang_tree_node
*)t
)->tpi
.index
);
6331 WU (((lang_tree_node
*)t
)->tpi
.level
);
6332 WU (((lang_tree_node
*)t
)->tpi
.orig_level
);
6334 WT (((lang_tree_node
*)t
)->tpi
.decl
);
6335 /* TEMPLATE_PARM_DESCENDANTS (AKA TREE_CHAIN) is an internal
6336 cache, do not stream. */
6340 WT (((lang_tree_node
*)t
)->trait_expression
.type1
);
6341 WT (((lang_tree_node
*)t
)->trait_expression
.type2
);
6343 WU (((lang_tree_node
*)t
)->trait_expression
.kind
);
6347 if (CODE_CONTAINS_STRUCT (code
, TS_TYPED
))
6349 /* We want to stream the type of a expression-like nodes /after/
6350 we've streamed the operands. The type often contains (bits
6351 of the) types of the operands, and with things like decltype
6352 and noexcept in play, we really want to stream the decls
6353 defining the type before we try and stream the type on its
6354 own. Otherwise we can find ourselves trying to read in a
6355 decl, when we're already partially reading in a component of
6356 its type. And that's bad. */
6357 tree type
= t
->typed
.type
;
6366 /* We fill in the template's type separately. */
6371 if (DECL_ORIGINAL_TYPE (t
) && t
== TYPE_NAME (type
))
6372 /* This is a typedef. We set its type separately. */
6377 if (type
&& !ENUM_FIXED_UNDERLYING_TYPE_P (t
))
6379 /* Type is a restricted range integer type derived from the
6380 integer_types. Find the right one. */
6381 prec
= TYPE_PRECISION (type
);
6382 tree name
= DECL_NAME (TYPE_NAME (type
));
6384 for (unsigned itk
= itk_none
; itk
--;)
6385 if (integer_types
[itk
]
6386 && DECL_NAME (TYPE_NAME (integer_types
[itk
])) == name
)
6388 type
= integer_types
[itk
];
6391 gcc_assert (type
!= t
->typed
.type
);
6397 if (prec
&& streaming_p ())
6405 // Streaming in a reference to a decl can cause that decl to be
6406 // TREE_USED, which is the mark_used behaviour we need most of the
6407 // time. The trees_in::unused can be incremented to inhibit this,
6408 // which is at least needed for vtables.
6411 trees_in::core_vals (tree t
)
6413 #define RU(X) ((X) = u ())
6414 #define RUC(T,X) ((X) = T (u ()))
6415 #define RT(X) ((X) = tree_node ())
6416 #define RTU(X) ((X) = tree_node (true))
6417 tree_code code
= TREE_CODE (t
);
6419 /* First by tree shape. */
6420 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_MINIMAL
))
6422 RT (t
->decl_minimal
.name
);
6423 if (!DECL_TEMPLATE_PARM_P (t
))
6424 RT (t
->decl_minimal
.context
);
6426 /* Don't zap the locus just yet, we don't record it correctly
6427 and thus lose all location information. */
6428 t
->decl_minimal
.locus
= state
->read_location (*this);
6431 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_COMMON
))
6433 RT (t
->type_common
.name
);
6434 RT (t
->type_common
.context
);
6436 RT (t
->type_common
.main_variant
);
6437 RT (t
->type_common
.canonical
);
6439 /* type_common.next_variant is internally manipulated. */
6440 /* type_common.pointer_to, type_common.reference_to. */
6442 RU (t
->type_common
.precision
);
6443 RU (t
->type_common
.contains_placeholder_bits
);
6444 RUC (machine_mode
, t
->type_common
.mode
);
6445 RU (t
->type_common
.align
);
6447 if (!RECORD_OR_UNION_CODE_P (code
))
6449 RT (t
->type_common
.size
);
6450 RT (t
->type_common
.size_unit
);
6452 RT (t
->type_common
.attributes
);
6454 RT (t
->type_common
.common
.chain
); /* TYPE_STUB_DECL. */
6457 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
6459 RUC (machine_mode
, t
->decl_common
.mode
);
6460 RU (t
->decl_common
.off_align
);
6461 RU (t
->decl_common
.align
);
6463 if (code
!= TEMPLATE_DECL
)
6465 RT (t
->decl_common
.size
);
6466 RT (t
->decl_common
.size_unit
);
6469 RT (t
->decl_common
.attributes
);
6470 RT (t
->decl_common
.abstract_origin
);
6473 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
6475 RT (t
->decl_with_vis
.assembler_name
);
6476 RUC (symbol_visibility
, t
->decl_with_vis
.visibility
);
6479 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_NON_COMMON
))
6481 /* Records and unions hold FIELDS, VFIELD & BINFO on these
6483 if (!RECORD_OR_UNION_CODE_P (code
) && code
!= ENUMERAL_TYPE
)
6485 /* This is not clobbering TYPE_CACHED_VALUES, because this
6486 is a type that doesn't have any. */
6487 gcc_checking_assert (!TYPE_CACHED_VALUES_P (t
));
6488 RT (t
->type_non_common
.values
);
6489 RT (t
->type_non_common
.maxval
);
6490 RT (t
->type_non_common
.minval
);
6493 RT (t
->type_non_common
.lang_1
);
6496 if (CODE_CONTAINS_STRUCT (code
, TS_EXP
))
6498 t
->exp
.locus
= state
->read_location (*this);
6500 bool vl
= TREE_CODE_CLASS (code
) == tcc_vl_exp
;
6501 for (unsigned limit
= (vl
? VL_EXP_OPERAND_LENGTH (t
)
6502 : TREE_OPERAND_LENGTH (t
)),
6503 ix
= unsigned (vl
); ix
!= limit
; ix
++)
6504 RTU (TREE_OPERAND (t
, ix
));
6507 /* Then by CODE. Special cases and/or 1:1 tree shape
6514 case ARGUMENT_PACK_SELECT
:
6515 case DEFERRED_PARSE
:
6516 case IDENTIFIER_NODE
:
6517 case BINDING_VECTOR
:
6519 case TRANSLATION_UNIT_DECL
:
6520 case USERDEF_LITERAL
:
6521 return false; /* Should never meet. */
6525 RT (TREE_REALPART (t
));
6526 RT (TREE_IMAGPART (t
));
6530 /* Not suported in C++. */
6535 unsigned num
= TREE_INT_CST_EXT_NUNITS (t
);
6536 for (unsigned ix
= 0; ix
!= num
; ix
++)
6537 TREE_INT_CST_ELT (t
, ix
) = wu ();
6542 /* Not suported in C++. */
6546 if (const void *bytes
= buf (sizeof (real_value
)))
6547 TREE_REAL_CST_PTR (t
)
6548 = reinterpret_cast<real_value
*> (memcpy (ggc_alloc
<real_value
> (),
6549 bytes
, sizeof (real_value
)));
6553 /* Streamed during start. */
6557 for (unsigned ix
= vector_cst_encoded_nelts (t
); ix
--;)
6558 RT (VECTOR_CST_ENCODED_ELT (t
, ix
));
6563 if (DECL_CONTEXT (t
)
6564 && TREE_CODE (DECL_CONTEXT (t
)) != FUNCTION_DECL
)
6570 if (DECL_HAS_VALUE_EXPR_P (t
))
6572 /* The DECL_VALUE hash table is a cache, thus if we're
6573 reading a duplicate (which we end up discarding), the
6574 value expr will also be cleaned up at the next gc. */
6575 tree val
= tree_node ();
6576 SET_DECL_VALUE_EXPR (t
, val
);
6582 RT (t
->decl_common
.initial
);
6586 RT (t
->field_decl
.offset
);
6587 RT (t
->field_decl
.bit_field_type
);
6588 RT (t
->field_decl
.qualifier
);
6589 RT (t
->field_decl
.bit_offset
);
6590 RT (t
->field_decl
.fcontext
);
6591 RT (t
->decl_common
.initial
);
6595 RU (t
->label_decl
.label_decl_uid
);
6596 RU (t
->label_decl
.eh_landing_pad_nr
);
6601 unsigned bltin
= u ();
6602 t
->function_decl
.built_in_class
= built_in_class (bltin
);
6603 if (bltin
!= NOT_BUILT_IN
)
6606 DECL_UNCHECKED_FUNCTION_CODE (t
) = built_in_function (bltin
);
6609 RT (t
->function_decl
.personality
);
6610 RT (t
->function_decl
.function_specific_target
);
6611 RT (t
->function_decl
.function_specific_optimization
);
6612 RT (t
->function_decl
.vindex
);
6617 /* USING_DECL_DECLS */
6618 RT (t
->decl_common
.initial
);
6622 /* USING_DECL: USING_DECL_SCOPE */
6623 /* TYPE_DECL: DECL_ORIGINAL_TYPE */
6624 RT (t
->decl_non_common
.result
);
6627 /* Miscellaneous common nodes. */
6629 t
->block
.locus
= state
->read_location (*this);
6630 t
->block
.end_locus
= state
->read_location (*this);
6631 t
->block
.vars
= chained_decls ();
6632 /* nonlocalized_vars is middle-end. */
6633 RT (t
->block
.subblocks
);
6634 RT (t
->block
.supercontext
);
6635 RT (t
->block
.abstract_origin
);
6636 /* fragment_origin, fragment_chain are middle-end. */
6637 RT (t
->block
.chain
);
6638 /* nonlocalized_vars, block_num, die are middle endy/debug
6643 RUC (internal_fn
, t
->base
.u
.ifn
);
6647 if (unsigned len
= u ())
6649 vec_alloc (t
->constructor
.elts
, len
);
6650 for (unsigned ix
= 0; ix
!= len
; ix
++)
6652 constructor_elt elt
;
6656 t
->constructor
.elts
->quick_push (elt
);
6663 RU (t
->omp_clause
.subcode
.map_kind
);
6664 t
->omp_clause
.locus
= state
->read_location (*this);
6666 unsigned len
= omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)];
6667 for (unsigned ix
= 0; ix
!= len
; ix
++)
6668 RT (t
->omp_clause
.ops
[ix
]);
6672 case STATEMENT_LIST
:
6674 tree_stmt_iterator iter
= tsi_start (t
);
6675 for (tree stmt
; RT (stmt
);)
6676 tsi_link_after (&iter
, stmt
, TSI_CONTINUE_LINKING
);
6680 case OPTIMIZATION_NODE
:
6681 case TARGET_OPTION_NODE
:
6682 /* Not yet implemented, see trees_out::core_vals. */
6687 RT (t
->binfo
.common
.chain
);
6688 RT (t
->binfo
.offset
);
6689 RT (t
->binfo
.inheritance
);
6690 RT (t
->binfo
.vptr_field
);
6692 /* Do not mark the vtables as USED in the address expressions
6695 RT (t
->binfo
.vtable
);
6696 RT (t
->binfo
.virtuals
);
6697 RT (t
->binfo
.vtt_subvtt
);
6698 RT (t
->binfo
.vtt_vptr
);
6701 BINFO_BASE_ACCESSES (t
) = tree_vec ();
6702 if (!get_overrun ())
6704 unsigned num
= vec_safe_length (BINFO_BASE_ACCESSES (t
));
6705 for (unsigned ix
= 0; ix
!= num
; ix
++)
6706 BINFO_BASE_APPEND (t
, tree_node ());
6711 RT (t
->list
.purpose
);
6713 RT (t
->list
.common
.chain
);
6717 for (unsigned ix
= TREE_VEC_LENGTH (t
); ix
--;)
6718 RT (TREE_VEC_ELT (t
, ix
));
6719 RT (t
->type_common
.common
.chain
);
6722 /* C++-specific nodes ... */
6724 RT (((lang_tree_node
*)t
)->baselink
.binfo
);
6725 RTU (((lang_tree_node
*)t
)->baselink
.functions
);
6726 RT (((lang_tree_node
*)t
)->baselink
.access_binfo
);
6729 case CONSTRAINT_INFO
:
6730 RT (((lang_tree_node
*)t
)->constraint_info
.template_reqs
);
6731 RT (((lang_tree_node
*)t
)->constraint_info
.declarator_reqs
);
6732 RT (((lang_tree_node
*)t
)->constraint_info
.associated_constr
);
6735 case DEFERRED_NOEXCEPT
:
6736 RT (((lang_tree_node
*)t
)->deferred_noexcept
.pattern
);
6737 RT (((lang_tree_node
*)t
)->deferred_noexcept
.args
);
6741 RT (((lang_tree_node
*)t
)->lambda_expression
.capture_list
);
6742 RT (((lang_tree_node
*)t
)->lambda_expression
.this_capture
);
6743 RT (((lang_tree_node
*)t
)->lambda_expression
.extra_scope
);
6744 /* lambda_expression.pending_proxies is NULL */
6745 ((lang_tree_node
*)t
)->lambda_expression
.locus
6746 = state
->read_location (*this);
6747 RUC (cp_lambda_default_capture_mode_type
,
6748 ((lang_tree_node
*)t
)->lambda_expression
.default_capture_mode
);
6749 RU (((lang_tree_node
*)t
)->lambda_expression
.discriminator
);
6753 RT (((lang_tree_node
*)t
)->overload
.function
);
6754 RT (t
->common
.chain
);
6758 RT (((lang_tree_node
*)t
)->ptrmem
.member
);
6762 RT (((lang_tree_node
*)t
)->static_assertion
.condition
);
6763 RT (((lang_tree_node
*)t
)->static_assertion
.message
);
6764 ((lang_tree_node
*)t
)->static_assertion
.location
6765 = state
->read_location (*this);
6769 /* Streamed when reading the raw template decl itself. */
6770 gcc_assert (((lang_tree_node
*)t
)->template_decl
.arguments
);
6771 gcc_assert (((lang_tree_node
*)t
)->template_decl
.result
);
6772 if (DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (t
))
6773 RT (DECL_CHAIN (t
));
6777 RT (((lang_tree_node
*)t
)->template_info
.tmpl
);
6778 RT (((lang_tree_node
*)t
)->template_info
.args
);
6779 if (unsigned len
= u ())
6781 auto &ac
= (((lang_tree_node
*)t
)
6782 ->template_info
.deferred_access_checks
);
6783 vec_alloc (ac
, len
);
6784 for (unsigned ix
= 0; ix
!= len
; ix
++)
6786 deferred_access_check m
;
6791 m
.loc
= state
->read_location (*this);
6797 case TEMPLATE_PARM_INDEX
:
6798 RU (((lang_tree_node
*)t
)->tpi
.index
);
6799 RU (((lang_tree_node
*)t
)->tpi
.level
);
6800 RU (((lang_tree_node
*)t
)->tpi
.orig_level
);
6801 RT (((lang_tree_node
*)t
)->tpi
.decl
);
6805 RT (((lang_tree_node
*)t
)->trait_expression
.type1
);
6806 RT (((lang_tree_node
*)t
)->trait_expression
.type2
);
6807 RUC (cp_trait_kind
, ((lang_tree_node
*)t
)->trait_expression
.kind
);
6811 if (CODE_CONTAINS_STRUCT (code
, TS_TYPED
))
6813 tree type
= tree_node ();
6815 if (type
&& code
== ENUMERAL_TYPE
&& !ENUM_FIXED_UNDERLYING_TYPE_P (t
))
6817 unsigned precision
= u ();
6819 type
= build_distinct_type_copy (type
);
6820 TYPE_PRECISION (type
) = precision
;
6821 set_min_and_max_values_for_integral_type (type
, precision
,
6825 if (code
!= TEMPLATE_DECL
)
6826 t
->typed
.type
= type
;
6832 return !get_overrun ();
6836 trees_out::lang_decl_vals (tree t
)
6838 const struct lang_decl
*lang
= DECL_LANG_SPECIFIC (t
);
6839 #define WU(X) (u (X))
6840 #define WT(X) (tree_node (X))
6841 /* Module index already written. */
6842 switch (lang
->u
.base
.selector
)
6847 case lds_fn
: /* lang_decl_fn. */
6850 if (DECL_NAME (t
) && IDENTIFIER_OVL_OP_P (DECL_NAME (t
)))
6851 WU (lang
->u
.fn
.ovl_op_code
);
6854 if (DECL_CLASS_SCOPE_P (t
))
6855 WT (lang
->u
.fn
.context
);
6857 if (lang
->u
.fn
.thunk_p
)
6859 /* The thunked-to function. */
6860 WT (lang
->u
.fn
.befriending_classes
);
6862 wi (lang
->u
.fn
.u5
.fixed_offset
);
6865 WT (lang
->u
.fn
.u5
.cloned_function
);
6867 if (FNDECL_USED_AUTO (t
))
6868 WT (lang
->u
.fn
.u
.saved_auto_return_type
);
6872 case lds_decomp
: /* lang_decl_decomp. */
6873 WT (lang
->u
.decomp
.base
);
6876 case lds_min
: /* lang_decl_min. */
6878 WT (lang
->u
.min
.template_info
);
6880 tree access
= lang
->u
.min
.access
;
6882 /* DECL_ACCESS needs to be maintained by the definition of the
6883 (derived) class that changes the access. The other users
6884 of DECL_ACCESS need to write it here. */
6885 if (!DECL_THUNK_P (t
)
6886 && (DECL_CONTEXT (t
) && TYPE_P (DECL_CONTEXT (t
))))
6893 case lds_ns
: /* lang_decl_ns. */
6896 case lds_parm
: /* lang_decl_parm. */
6899 WU (lang
->u
.parm
.level
);
6900 WU (lang
->u
.parm
.index
);
6909 trees_in::lang_decl_vals (tree t
)
6911 struct lang_decl
*lang
= DECL_LANG_SPECIFIC (t
);
6912 #define RU(X) ((X) = u ())
6913 #define RT(X) ((X) = tree_node ())
6915 /* Module index already read. */
6916 switch (lang
->u
.base
.selector
)
6921 case lds_fn
: /* lang_decl_fn. */
6922 if (DECL_NAME (t
) && IDENTIFIER_OVL_OP_P (DECL_NAME (t
)))
6924 unsigned code
= u ();
6926 /* Check consistency. */
6927 if (code
>= OVL_OP_MAX
6928 || (ovl_op_info
[IDENTIFIER_ASSIGN_OP_P (DECL_NAME (t
))][code
]
6929 .ovl_op_code
) == OVL_OP_ERROR_MARK
)
6932 lang
->u
.fn
.ovl_op_code
= code
;
6935 if (DECL_CLASS_SCOPE_P (t
))
6936 RT (lang
->u
.fn
.context
);
6938 if (lang
->u
.fn
.thunk_p
)
6940 RT (lang
->u
.fn
.befriending_classes
);
6941 lang
->u
.fn
.u5
.fixed_offset
= wi ();
6944 RT (lang
->u
.fn
.u5
.cloned_function
);
6946 if (FNDECL_USED_AUTO (t
))
6947 RT (lang
->u
.fn
.u
.saved_auto_return_type
);
6950 case lds_decomp
: /* lang_decl_decomp. */
6951 RT (lang
->u
.decomp
.base
);
6954 case lds_min
: /* lang_decl_min. */
6956 RT (lang
->u
.min
.template_info
);
6957 RT (lang
->u
.min
.access
);
6960 case lds_ns
: /* lang_decl_ns. */
6963 case lds_parm
: /* lang_decl_parm. */
6964 RU (lang
->u
.parm
.level
);
6965 RU (lang
->u
.parm
.index
);
6970 return !get_overrun ();
6973 /* Most of the value contents of lang_type is streamed in
6977 trees_out::lang_type_vals (tree t
)
6979 const struct lang_type
*lang
= TYPE_LANG_SPECIFIC (t
);
6980 #define WU(X) (u (X))
6981 #define WT(X) (tree_node (X))
6989 trees_in::lang_type_vals (tree t
)
6991 struct lang_type
*lang
= TYPE_LANG_SPECIFIC (t
);
6992 #define RU(X) ((X) = u ())
6993 #define RT(X) ((X) = tree_node ())
6997 return !get_overrun ();
7000 /* Write out the bools of T, including information about any
7001 LANG_SPECIFIC information. Including allocation of any lang
7005 trees_out::tree_node_bools (tree t
)
7007 gcc_checking_assert (streaming_p ());
7009 /* We should never stream a namespace. */
7010 gcc_checking_assert (TREE_CODE (t
) != NAMESPACE_DECL
7011 || DECL_NAMESPACE_ALIAS (t
));
7015 switch (TREE_CODE_CLASS (TREE_CODE (t
)))
7017 case tcc_declaration
:
7019 bool specific
= DECL_LANG_SPECIFIC (t
) != NULL
;
7021 if (specific
&& VAR_P (t
))
7022 b (DECL_DECOMPOSITION_P (t
));
7024 lang_decl_bools (t
);
7030 bool specific
= (TYPE_MAIN_VARIANT (t
) == t
7031 && TYPE_LANG_SPECIFIC (t
) != NULL
);
7032 gcc_assert (TYPE_LANG_SPECIFIC (t
)
7033 == TYPE_LANG_SPECIFIC (TYPE_MAIN_VARIANT (t
)));
7037 lang_type_bools (t
);
7049 trees_in::tree_node_bools (tree t
)
7051 bool ok
= core_bools (t
);
7054 switch (TREE_CODE_CLASS (TREE_CODE (t
)))
7056 case tcc_declaration
:
7059 bool decomp
= VAR_P (t
) && b ();
7061 ok
= maybe_add_lang_decl_raw (t
, decomp
);
7063 ok
= lang_decl_bools (t
);
7070 ok
= maybe_add_lang_type_raw (t
);
7072 ok
= lang_type_bools (t
);
7081 if (!ok
|| get_overrun ())
7088 /* Write out the lang-specifc vals of node T. */
7091 trees_out::lang_vals (tree t
)
7093 switch (TREE_CODE_CLASS (TREE_CODE (t
)))
7095 case tcc_declaration
:
7096 if (DECL_LANG_SPECIFIC (t
))
7101 if (TYPE_MAIN_VARIANT (t
) == t
&& TYPE_LANG_SPECIFIC (t
))
7111 trees_in::lang_vals (tree t
)
7115 switch (TREE_CODE_CLASS (TREE_CODE (t
)))
7117 case tcc_declaration
:
7118 if (DECL_LANG_SPECIFIC (t
))
7119 ok
= lang_decl_vals (t
);
7123 if (TYPE_LANG_SPECIFIC (t
))
7124 ok
= lang_type_vals (t
);
7126 TYPE_LANG_SPECIFIC (t
) = TYPE_LANG_SPECIFIC (TYPE_MAIN_VARIANT (t
));
7136 /* Write out the value fields of node T. */
7139 trees_out::tree_node_vals (tree t
)
7146 trees_in::tree_node_vals (tree t
)
7148 bool ok
= core_vals (t
);
7156 /* If T is a back reference, fixed reference or NULL, write out it's
7157 code and return WK_none. Otherwise return WK_value if we must write
7158 by value, or WK_normal otherwise. */
7161 trees_out::ref_node (tree t
)
7167 /* NULL_TREE -> tt_null. */
7174 if (!TREE_VISITED (t
))
7177 /* An already-visited tree. It must be in the map. */
7178 int val
= get_tag (t
);
7180 if (val
== tag_value
)
7181 /* An entry we should walk into. */
7186 if (val
<= tag_backref
)
7188 /* Back reference -> -ve number */
7193 else if (val
>= tag_fixed
)
7195 /* Fixed reference -> tt_fixed */
7198 i (tt_fixed
), u (val
);
7206 && dump ("Wrote %s:%d %C:%N%S", kind
, val
, TREE_CODE (t
), t
, t
);
7212 trees_in::back_ref (int tag
)
7214 tree res
= NULL_TREE
;
7216 if (tag
< 0 && unsigned (~tag
) < back_refs
.length ())
7217 res
= back_refs
[~tag
];
7220 /* Checking TREE_CODE is a dereference, so we know this is not a
7221 wild pointer. Checking the code provides evidence we've not
7222 corrupted something. */
7223 || TREE_CODE (res
) >= MAX_TREE_CODES
)
7226 dump (dumper::TREE
) && dump ("Read backref:%d found %C:%N%S", tag
,
7227 TREE_CODE (res
), res
, res
);
7232 trees_out::add_indirect_tpl_parms (tree parms
)
7235 for (; parms
; parms
= TREE_CHAIN (parms
), len
++)
7237 if (TREE_VISITED (parms
))
7240 int tag
= insert (parms
);
7243 && dump ("Indirect:%d template's parameter %u %C:%N",
7244 tag
, len
, TREE_CODE (parms
), parms
);
7254 trees_in::add_indirect_tpl_parms (tree parms
)
7256 unsigned len
= u ();
7257 for (unsigned ix
= 0; ix
!= len
; parms
= TREE_CHAIN (parms
), ix
++)
7259 int tag
= insert (parms
);
7261 && dump ("Indirect:%d template's parameter %u %C:%N",
7262 tag
, ix
, TREE_CODE (parms
), parms
);
7268 /* We've just found DECL by name. Insert nodes that come with it, but
7269 cannot be found by name, so we'll not accidentally walk into them. */
7272 trees_out::add_indirects (tree decl
)
7276 // FIXME:OPTIMIZATION We'll eventually want default fn parms of
7277 // templates and perhaps default template parms too. The former can
7278 // be referenced from instantiations (as they are lazily
7279 // instantiated). Also (deferred?) exception specifications of
7280 // templates. See the note about PARM_DECLs in trees_out::decl_node.
7282 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
7284 count
+= add_indirect_tpl_parms (DECL_TEMPLATE_PARMS (decl
));
7286 inner
= DECL_TEMPLATE_RESULT (decl
);
7287 int tag
= insert (inner
);
7290 && dump ("Indirect:%d template's result %C:%N",
7291 tag
, TREE_CODE (inner
), inner
);
7295 if (TREE_CODE (inner
) == TYPE_DECL
)
7297 /* Make sure the type is in the map too. Otherwise we get
7298 different RECORD_TYPEs for the same type, and things go
7300 tree type
= TREE_TYPE (inner
);
7301 gcc_checking_assert (DECL_ORIGINAL_TYPE (inner
)
7302 || TYPE_NAME (type
) == inner
);
7303 int tag
= insert (type
);
7305 dump (dumper::TREE
) && dump ("Indirect:%d decl's type %C:%N", tag
,
7306 TREE_CODE (type
), type
);
7313 dump (dumper::TREE
) && dump ("Inserted %u indirects", count
);
7318 trees_in::add_indirects (tree decl
)
7323 if (TREE_CODE (inner
) == TEMPLATE_DECL
)
7325 count
+= add_indirect_tpl_parms (DECL_TEMPLATE_PARMS (decl
));
7327 inner
= DECL_TEMPLATE_RESULT (decl
);
7328 int tag
= insert (inner
);
7330 && dump ("Indirect:%d templates's result %C:%N", tag
,
7331 TREE_CODE (inner
), inner
);
7335 if (TREE_CODE (inner
) == TYPE_DECL
)
7337 tree type
= TREE_TYPE (inner
);
7338 gcc_checking_assert (DECL_ORIGINAL_TYPE (inner
)
7339 || TYPE_NAME (type
) == inner
);
7340 int tag
= insert (type
);
7342 && dump ("Indirect:%d decl's type %C:%N", tag
, TREE_CODE (type
), type
);
7346 dump (dumper::TREE
) && dump ("Inserted %u indirects", count
);
7347 return count
== u ();
7350 /* Stream a template parameter. There are 4.5 kinds of parameter:
7351 a) Template - TEMPLATE_DECL->TYPE_DECL->TEMPLATE_TEMPLATE_PARM
7352 TEMPLATE_TYPE_PARM_INDEX TPI
7353 b) Type - TYPE_DECL->TEMPLATE_TYPE_PARM TEMPLATE_TYPE_PARM_INDEX TPI
7354 c.1) NonTYPE - PARM_DECL DECL_INITIAL TPI We meet this first
7355 c.2) NonTYPE - CONST_DECL DECL_INITIAL Same TPI
7356 d) BoundTemplate - TYPE_DECL->BOUND_TEMPLATE_TEMPLATE_PARM
7357 TEMPLATE_TYPE_PARM_INDEX->TPI
7358 TEMPLATE_TEMPLATE_PARM_INFO->TEMPLATE_INFO
7360 All of these point to a TEMPLATE_PARM_INDEX, and #B also has a TEMPLATE_INFO
7364 trees_out::tpl_parm_value (tree parm
)
7366 gcc_checking_assert (DECL_P (parm
) && DECL_TEMPLATE_PARM_P (parm
));
7368 int parm_tag
= insert (parm
);
7372 dump (dumper::TREE
) && dump ("Writing template parm:%d %C:%N",
7373 parm_tag
, TREE_CODE (parm
), parm
);
7375 tree_node_bools (parm
);
7379 if (TREE_CODE (inner
) == TEMPLATE_DECL
)
7381 inner
= DECL_TEMPLATE_RESULT (inner
);
7382 int inner_tag
= insert (inner
);
7385 dump (dumper::TREE
) && dump ("Writing inner template parm:%d %C:%N",
7386 inner_tag
, TREE_CODE (inner
), inner
);
7388 tree_node_bools (inner
);
7392 tree type
= NULL_TREE
;
7393 if (TREE_CODE (inner
) == TYPE_DECL
)
7395 type
= TREE_TYPE (inner
);
7396 int type_tag
= insert (type
);
7399 dump (dumper::TREE
) && dump ("Writing template parm type:%d %C:%N",
7400 type_tag
, TREE_CODE (type
), type
);
7402 tree_node_bools (type
);
7408 /* This is a template-template parameter. */
7409 unsigned tpl_levels
= 0;
7410 tpl_header (parm
, &tpl_levels
);
7411 tpl_parms_fini (parm
, tpl_levels
);
7414 tree_node_vals (parm
);
7416 tree_node_vals (inner
);
7419 tree_node_vals (type
);
7420 if (DECL_NAME (inner
) == auto_identifier
7421 || DECL_NAME (inner
) == decltype_auto_identifier
)
7423 /* Placeholder auto. */
7424 tree_node (DECL_INITIAL (inner
));
7425 tree_node (DECL_SIZE_UNIT (inner
));
7430 dump (dumper::TREE
) && dump ("Wrote template parm:%d %C:%N",
7431 parm_tag
, TREE_CODE (parm
), parm
);
7435 trees_in::tpl_parm_value ()
7437 tree parm
= start ();
7438 if (!parm
|| !tree_node_bools (parm
))
7441 int parm_tag
= insert (parm
);
7442 dump (dumper::TREE
) && dump ("Reading template parm:%d %C:%N",
7443 parm_tag
, TREE_CODE (parm
), parm
);
7446 if (TREE_CODE (inner
) == TEMPLATE_DECL
)
7449 if (!inner
|| !tree_node_bools (inner
))
7451 int inner_tag
= insert (inner
);
7452 dump (dumper::TREE
) && dump ("Reading inner template parm:%d %C:%N",
7453 inner_tag
, TREE_CODE (inner
), inner
);
7454 DECL_TEMPLATE_RESULT (parm
) = inner
;
7457 tree type
= NULL_TREE
;
7458 if (TREE_CODE (inner
) == TYPE_DECL
)
7461 if (!type
|| !tree_node_bools (type
))
7463 int type_tag
= insert (type
);
7464 dump (dumper::TREE
) && dump ("Reading template parm type:%d %C:%N",
7465 type_tag
, TREE_CODE (type
), type
);
7467 TREE_TYPE (inner
) = TREE_TYPE (parm
) = type
;
7468 TYPE_NAME (type
) = parm
;
7473 /* A template template parameter. */
7474 unsigned tpl_levels
= 0;
7475 tpl_header (parm
, &tpl_levels
);
7476 tpl_parms_fini (parm
, tpl_levels
);
7479 tree_node_vals (parm
);
7481 tree_node_vals (inner
);
7484 tree_node_vals (type
);
7485 if (DECL_NAME (inner
) == auto_identifier
7486 || DECL_NAME (inner
) == decltype_auto_identifier
)
7488 /* Placeholder auto. */
7489 DECL_INITIAL (inner
) = tree_node ();
7490 DECL_SIZE_UNIT (inner
) = tree_node ();
7492 if (TYPE_CANONICAL (type
))
7494 gcc_checking_assert (TYPE_CANONICAL (type
) == type
);
7495 TYPE_CANONICAL (type
) = canonical_type_parameter (type
);
7499 dump (dumper::TREE
) && dump ("Read template parm:%d %C:%N",
7500 parm_tag
, TREE_CODE (parm
), parm
);
7506 trees_out::install_entity (tree decl
, depset
*dep
)
7508 gcc_checking_assert (streaming_p ());
7510 /* Write the entity index, so we can insert it as soon as we
7511 know this is new. */
7512 u (dep
? dep
->cluster
+ 1 : 0);
7513 if (CHECKING_P
&& dep
)
7515 /* Add it to the entity map, such that we can tell it is
7518 unsigned *slot
= &entity_map
->get_or_insert
7519 (DECL_UID (decl
), &existed
);
7521 /* If it existed, it should match. */
7522 gcc_checking_assert (decl
== (*entity_ary
)[*slot
]);
7523 *slot
= ~dep
->cluster
;
7528 trees_in::install_entity (tree decl
)
7530 unsigned entity_index
= u ();
7534 if (entity_index
> state
->entity_num
)
7540 /* Insert the real decl into the entity ary. */
7541 unsigned ident
= state
->entity_lwm
+ entity_index
- 1;
7542 binding_slot
&elt
= (*entity_ary
)[ident
];
7544 /* See module_state::read_pendings for how this got set. */
7545 int pending
= elt
.get_lazy () & 3;
7549 /* And into the entity map, if it's not already there. */
7550 if (!DECL_LANG_SPECIFIC (decl
)
7551 || !DECL_MODULE_ENTITY_P (decl
))
7553 retrofit_lang_decl (decl
);
7554 DECL_MODULE_ENTITY_P (decl
) = true;
7556 /* Insert into the entity hash (it cannot already be there). */
7558 unsigned &slot
= entity_map
->get_or_insert (DECL_UID (decl
), &existed
);
7559 gcc_checking_assert (!existed
);
7562 else if (pending
!= 0)
7564 unsigned key_ident
= import_entity_index (decl
);
7566 if (!pending_table
->add (key_ident
, ~ident
))
7570 if (!pending_table
->add (~key_ident
, ~ident
))
7575 DECL_MODULE_PENDING_SPECIALIZATIONS_P (decl
) = true;
7579 DECL_MODULE_PENDING_MEMBERS_P (decl
) = true;
7580 gcc_checking_assert (TREE_CODE (decl
) != TEMPLATE_DECL
);
7586 static bool has_definition (tree decl
);
7588 /* DECL is a decl node that must be written by value. DEP is the
7592 trees_out::decl_value (tree decl
, depset
*dep
)
7594 /* We should not be writing clones or template parms. */
7595 gcc_checking_assert (DECL_P (decl
)
7596 && !DECL_CLONED_FUNCTION_P (decl
)
7597 && !DECL_TEMPLATE_PARM_P (decl
));
7599 /* We should never be writing non-typedef ptrmemfuncs by value. */
7600 gcc_checking_assert (TREE_CODE (decl
) != TYPE_DECL
7601 || DECL_ORIGINAL_TYPE (decl
)
7602 || !TYPE_PTRMEMFUNC_P (TREE_TYPE (decl
)));
7604 merge_kind mk
= get_merge_kind (decl
, dep
);
7608 /* Never start in the middle of a template. */
7610 if (tree ti
= node_template_info (decl
, use_tpl
))
7611 gcc_checking_assert (TREE_CODE (TI_TEMPLATE (ti
)) == OVERLOAD
7612 || TREE_CODE (TI_TEMPLATE (ti
)) == FIELD_DECL
7613 || (DECL_TEMPLATE_RESULT (TI_TEMPLATE (ti
))
7619 /* A new node -> tt_decl. */
7625 if (mk
!= MK_unique
)
7627 if (!(mk
& MK_template_mask
) && !state
->is_header ())
7629 /* Tell the importer whether this is a global module entity,
7630 or a module entity. This bool merges into the next block
7631 of bools. Sneaky. */
7632 tree o
= get_originating_module_decl (decl
);
7633 bool is_mod
= false;
7635 if (dep
&& dep
->is_alias_tmpl_inst ())
7636 /* Alias template instantiations are templatey, but
7639 else if (DECL_LANG_SPECIFIC (o
) && DECL_MODULE_PURVIEW_P (o
))
7643 b (dep
&& dep
->has_defn ());
7645 tree_node_bools (decl
);
7648 int tag
= insert (decl
, WK_value
);
7651 && dump ("Writing %s:%d %C:%N%S", merge_kind_name
[mk
], tag
,
7652 TREE_CODE (decl
), decl
, decl
);
7656 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
7658 if (dep
&& dep
->is_alias_tmpl_inst ())
7662 inner
= DECL_TEMPLATE_RESULT (decl
);
7663 inner_tag
= insert (inner
, WK_value
);
7668 int code
= inner
? TREE_CODE (inner
) : 0;
7672 start (inner
, true);
7673 tree_node_bools (inner
);
7675 && dump ("Writing %s:%d %C:%N%S", merge_kind_name
[mk
], inner_tag
,
7676 TREE_CODE (inner
), inner
, inner
);
7681 tree type
= NULL_TREE
;
7683 tree stub_decl
= NULL_TREE
;
7685 if (inner
&& TREE_CODE (inner
) == TYPE_DECL
)
7687 type
= TREE_TYPE (inner
);
7688 bool has_type
= (type
== TYPE_MAIN_VARIANT (type
)
7689 && TYPE_NAME (type
) == inner
);
7692 u (has_type
? TREE_CODE (type
) : 0);
7696 type_tag
= insert (type
, WK_value
);
7700 tree_node_bools (type
);
7702 && dump ("Writing type:%d %C:%N", type_tag
,
7703 TREE_CODE (type
), type
);
7706 stub_decl
= TYPE_STUB_DECL (type
);
7707 bool has_stub
= inner
!= stub_decl
;
7709 u (has_stub
? TREE_CODE (stub_decl
) : 0);
7712 stub_tag
= insert (stub_decl
);
7715 start (stub_decl
, true);
7716 tree_node_bools (stub_decl
);
7718 && dump ("Writing stub_decl:%d %C:%N", stub_tag
,
7719 TREE_CODE (stub_decl
), stub_decl
);
7723 stub_decl
= NULL_TREE
;
7726 /* Regular typedef. */
7730 /* Stream the container, we want it correctly canonicalized before
7731 we start emitting keys for this decl. */
7732 tree container
= decl_container (decl
);
7734 unsigned tpl_levels
= 0;
7736 tpl_header (decl
, &tpl_levels
);
7737 if (inner
&& TREE_CODE (inner
) == FUNCTION_DECL
)
7738 fn_parms_init (inner
);
7740 /* Now write out the merging information, and then really
7741 install the tag values. */
7742 key_mergeable (tag
, mk
, decl
, inner
, container
, dep
);
7745 dump (dumper::MERGE
)
7746 && dump ("Wrote:%d's %s merge key %C:%N", tag
,
7747 merge_kind_name
[mk
], TREE_CODE (decl
), decl
);
7749 if (inner
&& TREE_CODE (inner
) == FUNCTION_DECL
)
7750 fn_parms_fini (inner
);
7752 if (!is_key_order ())
7753 tree_node_vals (decl
);
7757 if (!is_key_order ())
7758 tree_node_vals (inner
);
7759 tpl_parms_fini (decl
, tpl_levels
);
7763 /* A template alias instantiation. */
7764 inner
= DECL_TEMPLATE_RESULT (decl
);
7765 if (!is_key_order ())
7769 && dump ("Wrote(%d) alias template %C:%N",
7770 get_tag (inner
), TREE_CODE (inner
), inner
);
7774 if (type
&& !is_key_order ())
7776 tree_node_vals (type
);
7778 tree_node_vals (stub_decl
);
7781 if (!is_key_order ())
7782 tree_node (get_constraints (decl
));
7786 /* Do not stray outside this section. */
7787 gcc_checking_assert (!dep
|| dep
->section
== dep_hash
->section
);
7789 /* Write the entity index, so we can insert it as soon as we
7790 know this is new. */
7791 install_entity (decl
, dep
);
7795 && VAR_OR_FUNCTION_DECL_P (inner
)
7796 && DECL_LANG_SPECIFIC (inner
)
7797 && DECL_MODULE_ATTACHMENTS_P (inner
)
7798 && !is_key_order ())
7800 /* Stream the attached entities. */
7801 attachset
*set
= attached_table
->get (DECL_UID (inner
));
7802 unsigned num
= set
->num
;
7805 for (unsigned ix
= 0; ix
!= num
; ix
++)
7807 tree attached
= set
->values
[ix
];
7808 tree_node (attached
);
7810 dump (dumper::MERGE
)
7811 && dump ("Written %d[%u] attached decl %N", tag
, ix
, attached
);
7815 bool is_typedef
= (!type
&& inner
7816 && TREE_CODE (inner
) == TYPE_DECL
7817 && DECL_ORIGINAL_TYPE (inner
)
7818 && TYPE_NAME (TREE_TYPE (inner
)) == inner
);
7821 /* A typedef type. */
7822 int type_tag
= insert (TREE_TYPE (inner
));
7825 && dump ("Cloned:%d typedef %C:%N", type_tag
,
7826 TREE_CODE (TREE_TYPE (inner
)), TREE_TYPE (inner
));
7829 if (streaming_p () && DECL_MAYBE_IN_CHARGE_CDTOR_P (decl
))
7832 = (DECL_CHAIN (decl
) && DECL_CLONED_FUNCTION_P (DECL_CHAIN (decl
)));
7833 bool needs_vtt_parm_p
7834 = (cloned_p
&& CLASSTYPE_VBASECLASSES (DECL_CONTEXT (decl
)));
7835 bool omit_inherited_parms_p
7836 = (cloned_p
&& DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl
)
7837 && base_ctor_omit_inherited_parms (decl
));
7838 unsigned flags
= (int (cloned_p
) << 0
7839 | int (needs_vtt_parm_p
) << 1
7840 | int (omit_inherited_parms_p
) << 2);
7842 dump (dumper::TREE
) && dump ("CDTOR %N is %scloned",
7843 decl
, cloned_p
? "" : "not ");
7847 dump (dumper::TREE
) && dump ("Written decl:%d %C:%N", tag
,
7848 TREE_CODE (decl
), decl
);
7850 if (!inner
|| NAMESPACE_SCOPE_P (inner
))
7851 gcc_checking_assert (!inner
7852 || !dep
== (VAR_OR_FUNCTION_DECL_P (inner
)
7853 && DECL_LOCAL_DECL_P (inner
)));
7854 else if ((TREE_CODE (inner
) == TYPE_DECL
7855 && TYPE_NAME (TREE_TYPE (inner
)) == inner
7857 || TREE_CODE (inner
) == FUNCTION_DECL
)
7859 bool write_defn
= !dep
&& has_definition (decl
);
7863 write_definition (decl
);
7868 trees_in::decl_value ()
7871 bool is_mod
= false;
7872 bool has_defn
= false;
7873 unsigned mk_u
= u ();
7874 if (mk_u
>= MK_hwm
|| !merge_kind_name
[mk_u
])
7880 unsigned saved_unused
= unused
;
7883 merge_kind mk
= merge_kind (mk_u
);
7885 tree decl
= start ();
7888 if (mk
!= MK_unique
)
7890 if (!(mk
& MK_template_mask
) && !state
->is_header ())
7891 /* See note in trees_out about where this bool is sequenced. */
7897 if (!tree_node_bools (decl
))
7901 /* Insert into map. */
7902 tag
= insert (decl
);
7905 && dump ("Reading:%d %C", tag
, TREE_CODE (decl
));
7909 if (decl
&& TREE_CODE (decl
) == TEMPLATE_DECL
)
7915 DECL_TEMPLATE_RESULT (decl
) = error_mark_node
;
7919 inner
= start (code
);
7920 if (inner
&& tree_node_bools (inner
))
7921 DECL_TEMPLATE_RESULT (decl
) = inner
;
7925 inner_tag
= insert (inner
);
7928 && dump ("Reading:%d %C", inner_tag
, TREE_CODE (inner
));
7932 tree type
= NULL_TREE
;
7934 tree stub_decl
= NULL_TREE
;
7936 if (decl
&& inner
&& TREE_CODE (inner
) == TYPE_DECL
)
7938 if (unsigned type_code
= u ())
7940 type
= start (type_code
);
7941 if (type
&& tree_node_bools (type
))
7943 TREE_TYPE (inner
) = type
;
7944 TYPE_NAME (type
) = inner
;
7949 type_tag
= insert (type
);
7952 && dump ("Reading type:%d %C", type_tag
, TREE_CODE (type
));
7954 if (unsigned stub_code
= u ())
7956 stub_decl
= start (stub_code
);
7957 if (stub_decl
&& tree_node_bools (stub_decl
))
7959 TREE_TYPE (stub_decl
) = type
;
7960 TYPE_STUB_DECL (type
) = stub_decl
;
7965 stub_tag
= insert (stub_decl
);
7968 && dump ("Reading stub_decl:%d %C", stub_tag
,
7969 TREE_CODE (stub_decl
));
7978 back_refs
[~inner_tag
] = NULL_TREE
;
7980 back_refs
[~type_tag
] = NULL_TREE
;
7982 back_refs
[~stub_tag
] = NULL_TREE
;
7984 back_refs
[~tag
] = NULL_TREE
;
7987 unused
= saved_unused
;
7991 /* Read the container, to ensure it's already been streamed in. */
7992 tree container
= decl_container ();
7993 unsigned tpl_levels
= 0;
7995 /* Figure out if this decl is already known about. */
7999 if (!tpl_header (decl
, &tpl_levels
))
8001 if (inner
&& TREE_CODE (inner
) == FUNCTION_DECL
)
8002 parm_tag
= fn_parms_init (inner
);
8004 tree existing
= key_mergeable (tag
, mk
, decl
, inner
, type
, container
, is_mod
);
8005 tree existing_inner
= existing
;
8008 if (existing
== error_mark_node
)
8011 if (TREE_CODE (STRIP_TEMPLATE (existing
)) == TYPE_DECL
)
8013 tree etype
= TREE_TYPE (existing
);
8014 if (TYPE_LANG_SPECIFIC (etype
)
8015 && COMPLETE_TYPE_P (etype
)
8016 && !CLASSTYPE_MEMBER_VEC (etype
))
8017 /* Give it a member vec, we're likely gonna be looking
8019 set_class_bindings (etype
, -1);
8022 /* Install the existing decl into the back ref array. */
8023 register_duplicate (decl
, existing
);
8024 back_refs
[~tag
] = existing
;
8027 existing_inner
= DECL_TEMPLATE_RESULT (existing
);
8028 back_refs
[~inner_tag
] = existing_inner
;
8033 tree existing_type
= TREE_TYPE (existing
);
8034 back_refs
[~type_tag
] = existing_type
;
8036 back_refs
[~stub_tag
] = TYPE_STUB_DECL (existing_type
);
8041 fn_parms_fini (parm_tag
, inner
, existing_inner
, has_defn
);
8043 if (!tree_node_vals (decl
))
8048 gcc_checking_assert (DECL_TEMPLATE_RESULT (decl
) == inner
);
8050 if (!tree_node_vals (inner
))
8053 if (!tpl_parms_fini (decl
, tpl_levels
))
8058 inner
= tree_node ();
8059 DECL_TEMPLATE_RESULT (decl
) = inner
;
8060 TREE_TYPE (decl
) = TREE_TYPE (inner
);
8062 && dump ("Read alias template %C:%N", TREE_CODE (inner
), inner
);
8066 if (type
&& (!tree_node_vals (type
)
8067 || (stub_decl
&& !tree_node_vals (stub_decl
))))
8070 tree constraints
= tree_node ();
8072 dump (dumper::TREE
) && dump ("Read:%d %C:%N", tag
, TREE_CODE (decl
), decl
);
8074 /* Regular typedefs will have a NULL TREE_TYPE at this point. */
8075 bool is_typedef
= (!type
&& inner
8076 && TREE_CODE (inner
) == TYPE_DECL
8077 && DECL_ORIGINAL_TYPE (inner
)
8078 && !TREE_TYPE (inner
));
8081 /* Frob it to be ready for cloning. */
8082 TREE_TYPE (inner
) = DECL_ORIGINAL_TYPE (inner
);
8083 DECL_ORIGINAL_TYPE (inner
) = NULL_TREE
;
8086 existing
= back_refs
[~tag
];
8087 bool installed
= install_entity (existing
);
8088 bool is_new
= existing
== decl
;
8091 && VAR_OR_FUNCTION_DECL_P (inner
)
8092 && DECL_LANG_SPECIFIC (inner
)
8093 && DECL_MODULE_ATTACHMENTS_P (inner
))
8095 /* Read and maybe install the attached entities. */
8097 = attached_table
->get (DECL_UID (STRIP_TEMPLATE (existing
)));
8098 unsigned num
= u ();
8099 if (!is_new
== !set
)
8102 set
= attached_table
->create (DECL_UID (inner
), num
, NULL_TREE
);
8103 for (unsigned ix
= 0; !get_overrun () && ix
!= num
; ix
++)
8105 tree attached
= tree_node ();
8106 dump (dumper::MERGE
)
8107 && dump ("Read %d[%u] %s attached decl %N", tag
, ix
,
8108 is_new
? "new" : "matched", attached
);
8110 set
->values
[ix
] = attached
;
8111 else if (set
->values
[ix
] != attached
)
8118 /* A newly discovered node. */
8119 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (decl
))
8120 /* Mark this identifier as naming a virtual function --
8121 lookup_overrides relies on this optimization. */
8122 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl
)) = true;
8126 /* Mark the entity as imported and add it to the entity
8128 retrofit_lang_decl (decl
);
8129 DECL_MODULE_IMPORT_P (decl
) = true;
8132 retrofit_lang_decl (inner
);
8133 DECL_MODULE_IMPORT_P (inner
) = true;
8138 set_constraints (decl
, constraints
);
8140 if (TREE_CODE (decl
) == INTEGER_CST
&& !TREE_OVERFLOW (decl
))
8142 decl
= cache_integer_cst (decl
, true);
8143 back_refs
[~tag
] = decl
;
8147 set_underlying_type (inner
);
8150 /* Set the TEMPLATE_DECL's type. */
8151 TREE_TYPE (decl
) = TREE_TYPE (inner
);
8153 /* The late insertion of an alias here or an implicit member
8154 (next block), is ok, because we ensured that all imports were
8155 loaded up before we started this cluster. Thus an insertion
8156 from some other import cannot have happened between the
8157 merged insertion above and these insertions down here. */
8158 if (mk
== MK_alias_spec
)
8160 /* Insert into type table. */
8161 tree ti
= DECL_TEMPLATE_INFO (inner
);
8163 {TI_TEMPLATE (ti
), TI_ARGS (ti
), TREE_TYPE (inner
)};
8164 tree texist
= match_mergeable_specialization (false, &elt
);
8169 if (DECL_ARTIFICIAL (decl
)
8170 && TREE_CODE (decl
) == FUNCTION_DECL
8171 && !DECL_TEMPLATE_INFO (decl
)
8172 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
8173 && TYPE_SIZE (DECL_CONTEXT (decl
))
8174 && !DECL_THUNK_P (decl
))
8175 /* A new implicit member function, when the class is
8176 complete. This means the importee declared it, and
8177 we must now add it to the class. Note that implicit
8178 member fns of template instantiations do not themselves
8179 look like templates. */
8180 if (!install_implicit_member (inner
))
8185 /* DECL is the to-be-discarded decl. Its internal pointers will
8186 be to the EXISTING's structure. Frob it to point to its
8187 own other structures, so loading its definition will alter
8188 it, and not the existing decl. */
8189 dump (dumper::MERGE
) && dump ("Deduping %N", existing
);
8192 DECL_TEMPLATE_RESULT (decl
) = inner
;
8196 /* Point at the to-be-discarded type & decl. */
8197 TYPE_NAME (type
) = inner
;
8198 TREE_TYPE (inner
) = type
;
8200 TYPE_STUB_DECL (type
) = stub_decl
? stub_decl
: inner
;
8202 TREE_TYPE (stub_decl
) = type
;
8206 /* Set the TEMPLATE_DECL's type. */
8207 TREE_TYPE (decl
) = TREE_TYPE (inner
);
8209 if (!is_matching_decl (existing
, decl
))
8210 unmatched_duplicate (existing
);
8212 /* And our result is the existing node. */
8218 /* Insert the type into the array now. */
8219 tag
= insert (TREE_TYPE (decl
));
8221 && dump ("Cloned:%d typedef %C:%N",
8222 tag
, TREE_CODE (TREE_TYPE (decl
)), TREE_TYPE (decl
));
8225 unused
= saved_unused
;
8227 if (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl
))
8229 unsigned flags
= u ();
8233 bool cloned_p
= flags
& 1;
8234 dump (dumper::TREE
) && dump ("CDTOR %N is %scloned",
8235 decl
, cloned_p
? "" : "not ");
8237 build_cdtor_clones (decl
, flags
& 2, flags
& 4,
8238 /* Update the member vec, if there is
8239 one (we're in a different cluster
8240 to the class defn). */
8241 CLASSTYPE_MEMBER_VEC (DECL_CONTEXT (decl
)));
8246 && !NAMESPACE_SCOPE_P (inner
)
8247 && ((TREE_CODE (inner
) == TYPE_DECL
8248 && TYPE_NAME (TREE_TYPE (inner
)) == inner
8250 || TREE_CODE (inner
) == FUNCTION_DECL
)
8252 read_definition (decl
);
8257 /* DECL is an unnameable member of CTX. Return a suitable identifying
8261 get_field_ident (tree ctx
, tree decl
)
8263 gcc_checking_assert (TREE_CODE (decl
) == USING_DECL
8264 || !DECL_NAME (decl
)
8265 || IDENTIFIER_ANON_P (DECL_NAME (decl
)));
8268 for (tree fields
= TYPE_FIELDS (ctx
);
8269 fields
; fields
= DECL_CHAIN (fields
))
8274 if (DECL_CONTEXT (fields
) == ctx
8275 && (TREE_CODE (fields
) == USING_DECL
8276 || (TREE_CODE (fields
) == FIELD_DECL
8277 && (!DECL_NAME (fields
)
8278 || IDENTIFIER_ANON_P (DECL_NAME (fields
))))))
8279 /* Count this field. */
8286 lookup_field_ident (tree ctx
, unsigned ix
)
8288 for (tree fields
= TYPE_FIELDS (ctx
);
8289 fields
; fields
= DECL_CHAIN (fields
))
8290 if (DECL_CONTEXT (fields
) == ctx
8291 && (TREE_CODE (fields
) == USING_DECL
8292 || (TREE_CODE (fields
) == FIELD_DECL
8293 && (!DECL_NAME (fields
)
8294 || IDENTIFIER_ANON_P (DECL_NAME (fields
))))))
8301 /* Reference DECL. REF indicates the walk kind we are performing.
8302 Return true if we should write this decl by value. */
8305 trees_out::decl_node (tree decl
, walk_kind ref
)
8307 gcc_checking_assert (DECL_P (decl
) && !DECL_TEMPLATE_PARM_P (decl
)
8308 && DECL_CONTEXT (decl
));
8310 if (ref
== WK_value
)
8312 depset
*dep
= dep_hash
->find_dependency (decl
);
8313 decl_value (decl
, dep
);
8317 switch (TREE_CODE (decl
))
8323 gcc_checking_assert (!DECL_LOCAL_DECL_P (decl
));
8327 /* Unlike PARM_DECLs, RESULT_DECLs are only generated and
8328 referenced when we're inside the function itself. */
8335 tree_node (DECL_CONTEXT (decl
));
8338 /* That must have put this in the map. */
8339 walk_kind ref
= ref_node (decl
);
8341 // FIXME:OPTIMIZATION We can wander into bits of the
8342 // template this was instantiated from. For instance
8343 // deferred noexcept and default parms. Currently we'll
8344 // end up cloning those bits of tree. It would be nice
8345 // to reference those specific nodes. I think putting
8346 // those things in the map when we reference their
8347 // template by name. See the note in add_indirects.
8351 && dump ("Wrote %s reference %N",
8352 TREE_CODE (decl
) == PARM_DECL
? "parameter" : "result",
8359 /* This describes a USING_DECL to the ME's debug machinery. It
8360 originates from the fortran FE, and has nothing to do with
8369 /* If I end up cloning enum decls, implementing C++20 using
8370 E::v, this will need tweaking. */
8373 tree ctx
= DECL_CONTEXT (decl
);
8374 gcc_checking_assert (TREE_CODE (ctx
) == ENUMERAL_TYPE
);
8376 tree_node (DECL_NAME (decl
));
8378 int tag
= insert (decl
);
8381 && dump ("Wrote enum decl:%d %C:%N", tag
, TREE_CODE (decl
), decl
);
8387 if (TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
8396 tree ctx
= DECL_CONTEXT (decl
);
8399 tree name
= NULL_TREE
;
8401 if (TREE_CODE (decl
) == USING_DECL
)
8405 name
= DECL_NAME (decl
);
8406 if (name
&& IDENTIFIER_ANON_P (name
))
8411 if (!name
&& streaming_p ())
8413 unsigned ix
= get_field_ident (ctx
, decl
);
8417 int tag
= insert (decl
);
8420 && dump ("Wrote member:%d %C:%N", tag
, TREE_CODE (decl
), decl
);
8426 gcc_checking_assert (!DECL_LOCAL_DECL_P (decl
));
8427 if (DECL_VTABLE_OR_VTT_P (decl
))
8429 /* VTT or VTABLE, they are all on the vtables list. */
8430 tree ctx
= CP_DECL_CONTEXT (decl
);
8431 tree vtable
= CLASSTYPE_VTABLES (ctx
);
8432 for (unsigned ix
= 0; ; vtable
= DECL_CHAIN (vtable
), ix
++)
8435 gcc_checking_assert (DECL_VIRTUAL_P (decl
));
8441 && dump ("Writing vtable %N[%u]", ctx
, ix
);
8449 if (DECL_TINFO_P (decl
))
8452 /* A typeinfo, tt_tinfo_typedef or tt_tinfo_var. */
8453 bool is_var
= TREE_CODE (decl
) == VAR_DECL
;
8454 tree type
= TREE_TYPE (decl
);
8455 unsigned ix
= get_pseudo_tinfo_index (type
);
8458 i (is_var
? tt_tinfo_var
: tt_tinfo_typedef
);
8464 /* We also need the type it is for and mangled name, so
8465 the reader doesn't need to complete the type (which
8466 would break section ordering). The type it is for is
8467 stashed on the name's TREE_TYPE. */
8468 tree name
= DECL_NAME (decl
);
8470 type
= TREE_TYPE (name
);
8474 int tag
= insert (decl
);
8477 && dump ("Wrote tinfo_%s:%d %u %N", is_var
? "var" : "type",
8482 tag
= insert (type
);
8485 && dump ("Wrote tinfo_type:%d %u %N", tag
, ix
, type
);
8492 if (DECL_TINFO_P (decl
))
8497 if (DECL_THUNK_P (decl
))
8499 /* Thunks are similar to binfos -- write the thunked-to decl and
8500 then thunk-specific key info. */
8504 i (THUNK_FIXED_OFFSET (decl
));
8508 while (DECL_THUNK_P (target
))
8509 target
= THUNK_TARGET (target
);
8511 tree_node (THUNK_VIRTUAL_OFFSET (decl
));
8512 int tag
= insert (decl
);
8515 && dump ("Wrote:%d thunk %N to %N", tag
, DECL_NAME (decl
), target
);
8519 if (DECL_CLONED_FUNCTION_P (decl
))
8521 tree target
= get_clone_target (decl
);
8526 tree_node (DECL_NAME (decl
));
8527 int tag
= insert (decl
);
8530 && dump ("Wrote:%d clone %N of %N", tag
, DECL_NAME (decl
), target
);
8534 /* Everything left should be a thing that is in the entity table.
8535 Mostly things that can be defined outside of their (original
8536 declaration) context. */
8537 gcc_checking_assert (TREE_CODE (decl
) == TEMPLATE_DECL
8538 || TREE_CODE (decl
) == VAR_DECL
8539 || TREE_CODE (decl
) == FUNCTION_DECL
8540 || TREE_CODE (decl
) == TYPE_DECL
8541 || TREE_CODE (decl
) == USING_DECL
8542 || TREE_CODE (decl
) == CONCEPT_DECL
8543 || TREE_CODE (decl
) == NAMESPACE_DECL
);
8546 tree ti
= node_template_info (decl
, use_tpl
);
8547 tree tpl
= NULL_TREE
;
8549 /* If this is the TEMPLATE_DECL_RESULT of a TEMPLATE_DECL, get the
8550 TEMPLATE_DECL. Note TI_TEMPLATE is not a TEMPLATE_DECL for
8551 (some) friends, so we need to check that. */
8552 // FIXME: Should local friend template specializations be by value?
8553 // They don't get idents so we'll never know they're imported, but I
8554 // think we can only reach them from the TU that defines the
8555 // befriending class?
8556 if (ti
&& TREE_CODE (TI_TEMPLATE (ti
)) == TEMPLATE_DECL
8557 && DECL_TEMPLATE_RESULT (TI_TEMPLATE (ti
)) == decl
)
8559 tpl
= TI_TEMPLATE (ti
);
8565 && dump ("Writing implicit template %C:%N%S",
8566 TREE_CODE (tpl
), tpl
, tpl
);
8570 /* Streaming TPL caused us to visit DECL and maybe its type. */
8571 gcc_checking_assert (TREE_VISITED (decl
));
8572 if (DECL_IMPLICIT_TYPEDEF_P (decl
))
8573 gcc_checking_assert (TREE_VISITED (TREE_TYPE (decl
)));
8577 tree ctx
= CP_DECL_CONTEXT (decl
);
8580 dep
= dep_hash
->find_dependency (decl
);
8581 else if (TREE_CODE (ctx
) != FUNCTION_DECL
8582 || TREE_CODE (decl
) == TEMPLATE_DECL
8583 || (dep_hash
->sneakoscope
&& DECL_IMPLICIT_TYPEDEF_P (decl
))
8584 || (DECL_LANG_SPECIFIC (decl
)
8585 && DECL_MODULE_IMPORT_P (decl
)))
8586 dep
= dep_hash
->add_dependency (decl
,
8587 TREE_CODE (decl
) == NAMESPACE_DECL
8588 && !DECL_NAMESPACE_ALIAS (decl
)
8589 ? depset::EK_NAMESPACE
: depset::EK_DECL
);
8593 /* Some internal entity of context. Do by value. */
8594 decl_value (decl
, NULL
);
8598 if (dep
->get_entity_kind () == depset::EK_REDIRECT
)
8600 /* The DECL_TEMPLATE_RESULT of a partial specialization.
8601 Write the partial specialization's template. */
8602 depset
*redirect
= dep
->deps
[0];
8603 gcc_checking_assert (redirect
->get_entity_kind () == depset::EK_PARTIAL
);
8604 tpl
= redirect
->get_entity ();
8605 goto partial_template
;
8610 /* Locate the entity. */
8611 unsigned index
= dep
->cluster
;
8612 unsigned import
= 0;
8614 if (dep
->is_import ())
8615 import
= dep
->section
;
8616 else if (CHECKING_P
)
8617 /* It should be what we put there. */
8618 gcc_checking_assert (index
== ~import_entity_index (decl
));
8622 gcc_assert (!import
== (importedness
< 0));
8629 int tag
= insert (decl
);
8630 if (streaming_p () && dump (dumper::TREE
))
8632 char const *kind
= "import";
8633 module_state
*from
= (*modules
)[0];
8634 if (dep
->is_import ())
8635 /* Rediscover the unremapped index. */
8636 from
= import_entity_module (import_entity_index (decl
));
8639 tree o
= get_originating_module_decl (decl
);
8640 kind
= (DECL_LANG_SPECIFIC (o
) && DECL_MODULE_PURVIEW_P (o
)
8641 ? "purview" : "GMF");
8643 dump ("Wrote %s:%d %C:%N@%M", kind
,
8644 tag
, TREE_CODE (decl
), decl
, from
);
8647 add_indirects (decl
);
8653 trees_out::type_node (tree type
)
8655 gcc_assert (TYPE_P (type
));
8657 tree root
= (TYPE_NAME (type
)
8658 ? TREE_TYPE (TYPE_NAME (type
)) : TYPE_MAIN_VARIANT (type
));
8663 i (tt_variant_type
);
8668 if (TREE_CODE (type
) == FUNCTION_TYPE
8669 || TREE_CODE (type
) == METHOD_TYPE
)
8671 int quals
= type_memfn_quals (type
);
8672 int rquals
= type_memfn_rqual (type
);
8673 tree raises
= TYPE_RAISES_EXCEPTIONS (type
);
8674 bool late
= TYPE_HAS_LATE_RETURN_TYPE (type
);
8676 if (raises
!= TYPE_RAISES_EXCEPTIONS (root
)
8677 || rquals
!= type_memfn_rqual (root
)
8678 || quals
!= type_memfn_quals (root
)
8679 || late
!= TYPE_HAS_LATE_RETURN_TYPE (root
))
8680 flags
= rquals
| (int (late
) << 2) | (quals
<< 3);
8684 if (TYPE_USER_ALIGN (type
))
8685 flags
= exact_log2 (TYPE_ALIGN (type
));
8693 else if (TREE_CODE (type
) == FUNCTION_TYPE
8694 || TREE_CODE (type
) == METHOD_TYPE
)
8696 tree raises
= TYPE_RAISES_EXCEPTIONS (type
);
8697 if (raises
== TYPE_RAISES_EXCEPTIONS (root
))
8698 raises
= error_mark_node
;
8702 tree_node (TYPE_ATTRIBUTES (type
));
8707 int rquals
= cp_type_quals (root
);
8708 int quals
= cp_type_quals (type
);
8709 if (quals
== rquals
)
8714 if (ref_node (type
) != WK_none
)
8716 int tag
= insert (type
);
8721 && dump ("Wrote:%d variant type %C", tag
, TREE_CODE (type
));
8727 if (tree name
= TYPE_NAME (type
))
8728 if ((TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
))
8729 || DECL_TEMPLATE_PARM_P (name
)
8730 || TREE_CODE (type
) == RECORD_TYPE
8731 || TREE_CODE (type
) == UNION_TYPE
8732 || TREE_CODE (type
) == ENUMERAL_TYPE
)
8734 /* We can meet template parms that we didn't meet in the
8735 tpl_parms walk, because we're referring to a derived type
8736 that was previously constructed from equivalent template
8740 i (tt_typedef_type
);
8742 && dump ("Writing %stypedef %C:%N",
8743 DECL_IMPLICIT_TYPEDEF_P (name
) ? "implicit " : "",
8744 TREE_CODE (name
), name
);
8748 dump (dumper::TREE
) && dump ("Wrote typedef %C:%N%S",
8749 TREE_CODE (name
), name
, name
);
8750 gcc_checking_assert (TREE_VISITED (type
));
8754 if (TYPE_PTRMEMFUNC_P (type
))
8756 /* This is a distinct type node, masquerading as a structure. */
8757 tree fn_type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
8760 tree_node (fn_type
);
8761 int tag
= insert (type
);
8763 dump (dumper::TREE
) && dump ("Written:%d ptrmem type", tag
);
8769 u (tt_derived_type
);
8770 u (TREE_CODE (type
));
8773 tree_node (TREE_TYPE (type
));
8774 switch (TREE_CODE (type
))
8777 /* We should never meet a type here that is indescribable in
8778 terms of other types. */
8782 tree_node (TYPE_DOMAIN (type
));
8784 /* Dependent arrays are constructed with TYPE_DEPENENT_P
8786 u (TYPE_DEPENDENT_P (type
));
8790 /* No additional data. */
8794 /* A non-standard boolean type. */
8796 u (TYPE_PRECISION (type
));
8800 if (TREE_TYPE (type
))
8802 /* A range type (representing an array domain). */
8803 tree_node (TYPE_MIN_VALUE (type
));
8804 tree_node (TYPE_MAX_VALUE (type
));
8808 /* A new integral type (representing a bitfield). */
8811 unsigned prec
= TYPE_PRECISION (type
);
8812 bool unsigned_p
= TYPE_UNSIGNED (type
);
8814 u ((prec
<< 1) | unsigned_p
);
8822 gcc_checking_assert (type_memfn_rqual (type
) == REF_QUAL_NONE
);
8824 tree arg_types
= TYPE_ARG_TYPES (type
);
8825 if (TREE_CODE (type
) == METHOD_TYPE
)
8827 tree_node (TREE_TYPE (TREE_VALUE (arg_types
)));
8828 arg_types
= TREE_CHAIN (arg_types
);
8830 tree_node (arg_types
);
8835 tree_node (TYPE_OFFSET_BASETYPE (type
));
8839 /* No additional data. */
8842 case REFERENCE_TYPE
:
8844 u (TYPE_REF_IS_RVALUE (type
));
8849 case UNDERLYING_TYPE
:
8850 tree_node (TYPE_VALUES_RAW (type
));
8851 if (TREE_CODE (type
) == DECLTYPE_TYPE
)
8852 /* We stash a whole bunch of things into decltype's
8855 tree_node_bools (type
);
8858 case TYPE_ARGUMENT_PACK
:
8859 /* No additional data. */
8862 case TYPE_PACK_EXPANSION
:
8864 u (PACK_EXPANSION_LOCAL_P (type
));
8865 tree_node (PACK_EXPANSION_PARAMETER_PACKS (type
));
8870 tree_node (TYPE_CONTEXT (type
));
8871 tree_node (DECL_NAME (TYPE_NAME (type
)));
8872 tree_node (TYPENAME_TYPE_FULLNAME (type
));
8875 enum tag_types tag_type
= none_type
;
8876 if (TYPENAME_IS_ENUM_P (type
))
8877 tag_type
= enum_type
;
8878 else if (TYPENAME_IS_CLASS_P (type
))
8879 tag_type
= class_type
;
8885 case UNBOUND_CLASS_TEMPLATE
:
8887 tree decl
= TYPE_NAME (type
);
8888 tree_node (DECL_CONTEXT (decl
));
8889 tree_node (DECL_NAME (decl
));
8890 tree_node (DECL_TEMPLATE_PARMS (decl
));
8897 poly_uint64 nunits
= TYPE_VECTOR_SUBPARTS (type
);
8898 /* to_constant asserts that only coeff[0] is of interest. */
8899 wu (static_cast<unsigned HOST_WIDE_INT
> (nunits
.to_constant ()));
8904 /* We may have met the type during emitting the above. */
8905 if (ref_node (type
) != WK_none
)
8907 int tag
= insert (type
);
8912 && dump ("Wrote:%d derived type %C", tag
, TREE_CODE (type
));
8919 /* T is (mostly*) a non-mergeable node that must be written by value.
8920 The mergeable case is a BINFO, which are as-if DECLSs. */
8923 trees_out::tree_value (tree t
)
8925 /* We should never be writing a type by value. tree_type should
8926 have streamed it, or we're going via its TYPE_DECL. */
8927 gcc_checking_assert (!TYPE_P (t
));
8930 /* No template, type, var or function, except anonymous
8931 non-context vars. */
8932 gcc_checking_assert ((TREE_CODE (t
) != TEMPLATE_DECL
8933 && TREE_CODE (t
) != TYPE_DECL
8934 && (TREE_CODE (t
) != VAR_DECL
8935 || (!DECL_NAME (t
) && !DECL_CONTEXT (t
)))
8936 && TREE_CODE (t
) != FUNCTION_DECL
));
8940 /* A new node -> tt_node. */
8944 tree_node_bools (t
);
8947 if (TREE_CODE (t
) == TREE_BINFO
)
8948 /* Binfos are decl-like and need merging information. */
8949 binfo_mergeable (t
);
8951 int tag
= insert (t
, WK_value
);
8954 && dump ("Writing tree:%d %C:%N", tag
, TREE_CODE (t
), t
);
8959 dump (dumper::TREE
) && dump ("Written tree:%d %C:%N", tag
, TREE_CODE (t
), t
);
8963 trees_in::tree_value ()
8966 if (!t
|| !tree_node_bools (t
))
8970 if (TREE_CODE (t
) == TREE_BINFO
)
8973 unsigned ix
= binfo_mergeable (&type
);
8974 if (TYPE_BINFO (type
))
8976 /* We already have a definition, this must be a duplicate. */
8977 dump (dumper::MERGE
)
8978 && dump ("Deduping binfo %N[%u]", type
, ix
);
8979 existing
= TYPE_BINFO (type
);
8980 while (existing
&& ix
)
8981 existing
= TREE_CHAIN (existing
);
8983 register_duplicate (t
, existing
);
8985 /* Error, mismatch -- diagnose in read_class_def's
8991 /* Insert into map. */
8992 int tag
= insert (existing
);
8994 && dump ("Reading tree:%d %C", tag
, TREE_CODE (t
));
8996 if (!tree_node_vals (t
))
8998 back_refs
[~tag
] = NULL_TREE
;
9004 dump (dumper::TREE
) && dump ("Read tree:%d %C:%N", tag
, TREE_CODE (t
), t
);
9006 if (TREE_CODE (existing
) == INTEGER_CST
&& !TREE_OVERFLOW (existing
))
9008 existing
= cache_integer_cst (t
, true);
9009 back_refs
[~tag
] = existing
;
9015 /* Stream out tree node T. We automatically create local back
9016 references, which is essentially a single pass lisp
9017 self-referential structure pretty-printer. */
9020 trees_out::tree_node (tree t
)
9023 walk_kind ref
= ref_node (t
);
9027 if (ref
!= WK_normal
)
9030 if (TREE_CODE (t
) == IDENTIFIER_NODE
)
9032 /* An identifier node -> tt_id, tt_conv_id, tt_anon_id, tt_lambda_id. */
9034 if (IDENTIFIER_ANON_P (t
))
9035 code
= IDENTIFIER_LAMBDA_P (t
) ? tt_lambda_id
: tt_anon_id
;
9036 else if (IDENTIFIER_CONV_OP_P (t
))
9042 if (code
== tt_conv_id
)
9044 tree type
= TREE_TYPE (t
);
9045 gcc_checking_assert (type
|| t
== conv_op_identifier
);
9048 else if (code
== tt_id
&& streaming_p ())
9049 str (IDENTIFIER_POINTER (t
), IDENTIFIER_LENGTH (t
));
9051 int tag
= insert (t
);
9054 /* We know the ordering of the 4 id tags. */
9055 static const char *const kinds
[] =
9056 {"", "conv_op ", "anon ", "lambda "};
9058 && dump ("Written:%d %sidentifier:%N", tag
,
9059 kinds
[code
- tt_id
],
9060 code
== tt_conv_id
? TREE_TYPE (t
) : t
);
9065 if (TREE_CODE (t
) == TREE_BINFO
)
9067 /* A BINFO -> tt_binfo.
9068 We must do this by reference. We stream the binfo tree
9069 itself when streaming its owning RECORD_TYPE. That we got
9070 here means the dominating type is not in this SCC. */
9073 binfo_mergeable (t
);
9074 gcc_checking_assert (!TREE_VISITED (t
));
9075 int tag
= insert (t
);
9077 dump (dumper::TREE
) && dump ("Inserting binfo:%d %N", tag
, t
);
9081 if (TREE_CODE (t
) == INTEGER_CST
9082 && !TREE_OVERFLOW (t
)
9083 && TREE_CODE (TREE_TYPE (t
)) == ENUMERAL_TYPE
)
9085 /* An integral constant of enumeral type. See if it matches one
9086 of the enumeration values. */
9087 for (tree values
= TYPE_VALUES (TREE_TYPE (t
));
9088 values
; values
= TREE_CHAIN (values
))
9090 tree decl
= TREE_VALUE (values
);
9091 if (tree_int_cst_equal (DECL_INITIAL (decl
), t
))
9096 dump (dumper::TREE
) && dump ("Written enum value %N", decl
);
9100 /* It didn't match. We'll write it a an explicit INTEGER_CST
9112 if (DECL_TEMPLATE_PARM_P (t
))
9118 if (!DECL_CONTEXT (t
))
9120 /* There are a few cases of decls with no context. We'll write
9121 these by value, but first assert they are cases we expect. */
9122 gcc_checking_assert (ref
== WK_normal
);
9123 switch (TREE_CODE (t
))
9125 default: gcc_unreachable ();
9128 /* CASE_LABEL_EXPRs contain uncontexted LABEL_DECLs. */
9129 gcc_checking_assert (!DECL_NAME (t
));
9133 /* AGGR_INIT_EXPRs cons up anonymous uncontexted VAR_DECLs. */
9134 gcc_checking_assert (!DECL_NAME (t
)
9135 && DECL_ARTIFICIAL (t
));
9139 /* REQUIRES_EXPRs have a tree list of uncontexted
9140 PARM_DECLS. It'd be nice if they had a
9141 distinguishing flag to double check. */
9149 if (DECL_P (t
) && !decl_node (t
, ref
))
9152 /* Otherwise by value */
9157 /* And, breath out. */
9161 /* Stream in a tree node. */
9164 trees_in::tree_node (bool is_use
)
9171 tree res
= NULL_TREE
;
9175 /* backref, pull it out of the map. */
9176 res
= back_ref (tag
);
9184 /* A fixed ref, find it in the fixed_ref array. */
9186 unsigned fix
= u ();
9187 if (fix
< (*fixed_trees
).length ())
9189 res
= (*fixed_trees
)[fix
];
9190 dump (dumper::TREE
) && dump ("Read fixed:%u %C:%N%S", fix
,
9191 TREE_CODE (res
), res
, res
);
9201 tree fn
= tree_node ();
9202 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
9206 && dump ("Read %s reference %N",
9207 TREE_CODE (res
) == PARM_DECL
? "parameter" : "result",
9213 /* A new node. Stream it in. */
9214 res
= tree_value ();
9218 /* A new decl. Stream it in. */
9219 res
= decl_value ();
9223 /* A template parameter. Stream it in. */
9224 res
= tpl_parm_value ();
9228 /* An identifier node. */
9231 const char *chars
= str (&l
);
9232 res
= get_identifier_with_length (chars
, l
);
9233 int tag
= insert (res
);
9235 && dump ("Read identifier:%d %N", tag
, res
);
9240 /* A conversion operator. Get the type and recreate the
9243 tree type
= tree_node ();
9244 if (!get_overrun ())
9246 res
= type
? make_conv_op_name (type
) : conv_op_identifier
;
9247 int tag
= insert (res
);
9249 && dump ("Created conv_op:%d %S for %N", tag
, res
, type
);
9256 /* An anonymous or lambda id. */
9258 res
= make_anon_name ();
9259 if (tag
== tt_lambda_id
)
9260 IDENTIFIER_LAMBDA_P (res
) = true;
9261 int tag
= insert (res
);
9263 && dump ("Read %s identifier:%d %N",
9264 IDENTIFIER_LAMBDA_P (res
) ? "lambda" : "anon", tag
, res
);
9268 case tt_typedef_type
:
9273 && dump ("Read %stypedef %C:%N",
9274 DECL_IMPLICIT_TYPEDEF_P (res
) ? "implicit " : "",
9275 TREE_CODE (res
), res
);
9276 res
= TREE_TYPE (res
);
9280 case tt_derived_type
:
9281 /* A type derived from some other type. */
9283 enum tree_code code
= tree_code (u ());
9294 tree domain
= tree_node ();
9296 if (!get_overrun ())
9297 res
= build_cplus_array_type (res
, domain
, dep
);
9302 if (!get_overrun ())
9303 res
= build_complex_type (res
);
9308 unsigned precision
= u ();
9309 if (!get_overrun ())
9310 res
= build_nonstandard_boolean_type (precision
);
9317 /* A range type (representing an array domain). */
9318 tree min
= tree_node ();
9319 tree max
= tree_node ();
9321 if (!get_overrun ())
9322 res
= build_range_type (res
, min
, max
);
9326 /* A new integral type (representing a bitfield). */
9327 unsigned enc
= u ();
9328 if (!get_overrun ())
9329 res
= build_nonstandard_integer_type (enc
>> 1, enc
& 1);
9336 tree klass
= code
== METHOD_TYPE
? tree_node () : NULL_TREE
;
9337 tree args
= tree_node ();
9338 if (!get_overrun ())
9341 res
= build_method_type_directly (klass
, res
, args
);
9343 res
= build_function_type (res
, args
);
9350 tree base
= tree_node ();
9351 if (!get_overrun ())
9352 res
= build_offset_type (base
, res
);
9357 if (!get_overrun ())
9358 res
= build_pointer_type (res
);
9361 case REFERENCE_TYPE
:
9363 bool rval
= bool (u ());
9364 if (!get_overrun ())
9365 res
= cp_build_reference_type (res
, rval
);
9371 case UNDERLYING_TYPE
:
9373 tree expr
= tree_node ();
9374 if (!get_overrun ())
9376 res
= cxx_make_type (code
);
9377 TYPE_VALUES_RAW (res
) = expr
;
9378 if (code
== DECLTYPE_TYPE
)
9379 tree_node_bools (res
);
9380 SET_TYPE_STRUCTURAL_EQUALITY (res
);
9385 case TYPE_ARGUMENT_PACK
:
9386 if (!get_overrun ())
9388 tree pack
= cxx_make_type (TYPE_ARGUMENT_PACK
);
9389 SET_ARGUMENT_PACK_ARGS (pack
, res
);
9394 case TYPE_PACK_EXPANSION
:
9397 tree param_packs
= tree_node ();
9398 if (!get_overrun ())
9400 tree expn
= cxx_make_type (TYPE_PACK_EXPANSION
);
9401 SET_TYPE_STRUCTURAL_EQUALITY (expn
);
9402 SET_PACK_EXPANSION_PATTERN (expn
, res
);
9403 PACK_EXPANSION_PARAMETER_PACKS (expn
) = param_packs
;
9404 PACK_EXPANSION_LOCAL_P (expn
) = local
;
9412 tree ctx
= tree_node ();
9413 tree name
= tree_node ();
9414 tree fullname
= tree_node ();
9415 enum tag_types tag_type
= tag_types (u ());
9417 if (!get_overrun ())
9418 res
= build_typename_type (ctx
, name
, fullname
, tag_type
);
9422 case UNBOUND_CLASS_TEMPLATE
:
9424 tree ctx
= tree_node ();
9425 tree name
= tree_node ();
9426 tree parms
= tree_node ();
9428 if (!get_overrun ())
9429 res
= make_unbound_class_template_raw (ctx
, name
, parms
);
9435 unsigned HOST_WIDE_INT nunits
= wu ();
9436 if (!get_overrun ())
9437 res
= build_vector_type (res
, static_cast<poly_int64
> (nunits
));
9448 && dump ("Created:%d derived type %C", tag
, code
);
9451 res
= back_ref (tag
);
9455 case tt_variant_type
:
9456 /* Variant of some type. */
9464 else if (TREE_CODE (res
) == FUNCTION_TYPE
9465 || TREE_CODE (res
) == METHOD_TYPE
)
9467 cp_ref_qualifier rqual
= cp_ref_qualifier (flags
& 3);
9468 bool late
= (flags
>> 2) & 1;
9469 cp_cv_quals quals
= cp_cv_quals (flags
>> 3);
9471 tree raises
= tree_node ();
9472 if (raises
== error_mark_node
)
9473 raises
= TYPE_RAISES_EXCEPTIONS (res
);
9475 res
= build_cp_fntype_variant (res
, rqual
, raises
, late
);
9476 if (TREE_CODE (res
) == FUNCTION_TYPE
)
9477 res
= apply_memfn_quals (res
, quals
, rqual
);
9481 res
= build_aligned_type (res
, 1u << flags
);
9482 TYPE_USER_ALIGN (res
) = true;
9485 if (tree attribs
= tree_node ())
9486 res
= cp_build_type_attribute_variant (res
, attribs
);
9489 if (quals
>= 0 && !get_overrun ())
9490 res
= cp_build_qualified_type (res
, quals
);
9498 && dump ("Created:%d variant type %C", tag
, TREE_CODE (res
));
9501 res
= back_ref (tag
);
9506 case tt_tinfo_typedef
:
9507 /* A tinfo var or typedef. */
9509 bool is_var
= tag
== tt_tinfo_var
;
9511 tree type
= NULL_TREE
;
9515 tree name
= tree_node ();
9516 type
= tree_node ();
9518 if (!get_overrun ())
9519 res
= get_tinfo_decl_direct (type
, name
, int (ix
));
9523 if (!get_overrun ())
9525 type
= get_pseudo_tinfo_type (ix
);
9526 res
= TYPE_NAME (type
);
9531 int tag
= insert (res
);
9533 && dump ("Created tinfo_%s:%d %S:%u for %N",
9534 is_var
? "var" : "decl", tag
, res
, ix
, type
);
9537 tag
= insert (type
);
9539 && dump ("Created tinfo_type:%d %u %N", tag
, ix
, type
);
9545 case tt_ptrmem_type
:
9546 /* A pointer to member function. */
9548 tree type
= tree_node ();
9549 if (type
&& TREE_CODE (type
) == POINTER_TYPE
9550 && TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
)
9552 res
= build_ptrmemfunc_type (type
);
9553 int tag
= insert (res
);
9554 dump (dumper::TREE
) && dump ("Created:%d ptrmem type", tag
);
9562 /* An enum const value. */
9564 if (tree decl
= tree_node ())
9566 dump (dumper::TREE
) && dump ("Read enum value %N", decl
);
9567 res
= DECL_INITIAL (decl
);
9578 tree ctx
= tree_node ();
9579 tree name
= tree_node ();
9582 && TREE_CODE (ctx
) == ENUMERAL_TYPE
)
9583 res
= find_enum_member (ctx
, name
);
9589 int tag
= insert (res
);
9591 && dump ("Read enum decl:%d %C:%N", tag
, TREE_CODE (res
), res
);
9596 case tt_data_member
:
9597 /* A data member. */
9599 tree ctx
= tree_node ();
9600 tree name
= tree_node ();
9603 && RECORD_OR_UNION_TYPE_P (ctx
))
9606 res
= lookup_class_binding (ctx
, name
);
9608 res
= lookup_field_ident (ctx
, u ());
9611 || TREE_CODE (res
) != FIELD_DECL
9612 || DECL_CONTEXT (res
) != ctx
)
9620 int tag
= insert (res
);
9622 && dump ("Read member:%d %C:%N", tag
, TREE_CODE (res
), res
);
9628 /* A BINFO. Walk the tree of the dominating type. */
9631 unsigned ix
= binfo_mergeable (&type
);
9634 res
= TYPE_BINFO (type
);
9635 for (; ix
&& res
; res
= TREE_CHAIN (res
))
9644 /* Insert binfo into backreferences. */
9646 dump (dumper::TREE
) && dump ("Read binfo:%d %N", tag
, res
);
9653 tree ctx
= tree_node ();
9654 dump (dumper::TREE
) && dump ("Reading vtable %N[%u]", ctx
, ix
);
9655 if (TREE_CODE (ctx
) == RECORD_TYPE
&& TYPE_LANG_SPECIFIC (ctx
))
9656 for (res
= CLASSTYPE_VTABLES (ctx
); res
; res
= DECL_CHAIN (res
))
9667 tree target
= tree_node ();
9668 tree virt
= tree_node ();
9670 for (tree thunk
= DECL_THUNKS (target
);
9671 thunk
; thunk
= DECL_CHAIN (thunk
))
9672 if (THUNK_FIXED_OFFSET (thunk
) == fixed
9673 && !THUNK_VIRTUAL_OFFSET (thunk
) == !virt
9675 || tree_int_cst_equal (virt
, THUNK_VIRTUAL_OFFSET (thunk
))))
9681 int tag
= insert (res
);
9684 && dump ("Read:%d thunk %N to %N", tag
, DECL_NAME (res
), target
);
9692 tree target
= tree_node ();
9693 tree name
= tree_node ();
9695 if (DECL_P (target
) && DECL_MAYBE_IN_CHARGE_CDTOR_P (target
))
9698 FOR_EVERY_CLONE (clone
, target
)
9699 if (DECL_NAME (clone
) == name
)
9708 int tag
= insert (res
);
9711 && dump ("Read:%d clone %N of %N", tag
, DECL_NAME (res
), target
);
9718 /* Index into the entity table. Perhaps not loaded yet! */
9720 unsigned origin
= state
->slurp
->remap_module (u ());
9721 unsigned ident
= u ();
9722 module_state
*from
= (*modules
)[origin
];
9724 if (!origin
|| ident
>= from
->entity_num
)
9726 if (!get_overrun ())
9728 binding_slot
*slot
= &(*entity_ary
)[from
->entity_lwm
+ ident
];
9729 if (slot
->is_lazy ())
9730 if (!from
->lazy_load (ident
, slot
))
9737 const char *kind
= (origin
!= state
->mod
? "Imported" : "Named");
9738 int tag
= insert (res
);
9740 && dump ("%s:%d %C:%N@%M", kind
, tag
, TREE_CODE (res
),
9741 res
, (*modules
)[origin
]);
9743 if (!add_indirects (res
))
9754 if (tree tpl
= tree_node ())
9756 res
= DECL_TEMPLATE_RESULT (tpl
);
9758 && dump ("Read template %C:%N", TREE_CODE (res
), res
);
9763 if (is_use
&& !unused
&& res
&& DECL_P (res
) && !TREE_USED (res
))
9765 /* Mark decl used as mark_used does -- we cannot call
9766 mark_used in the middle of streaming, we only need a subset
9767 of its functionality. */
9768 TREE_USED (res
) = true;
9770 /* And for structured bindings also the underlying decl. */
9771 if (DECL_DECOMPOSITION_P (res
) && DECL_DECOMP_BASE (res
))
9772 TREE_USED (DECL_DECOMP_BASE (res
)) = true;
9774 if (DECL_CLONED_FUNCTION_P (res
))
9775 TREE_USED (DECL_CLONED_FUNCTION (res
)) = true;
9783 trees_out::tpl_parms (tree parms
, unsigned &tpl_levels
)
9788 if (TREE_VISITED (parms
))
9794 tpl_parms (TREE_CHAIN (parms
), tpl_levels
);
9796 tree vec
= TREE_VALUE (parms
);
9797 unsigned len
= TREE_VEC_LENGTH (vec
);
9799 int tag
= insert (parms
);
9804 && dump ("Writing template parms:%d level:%N length:%d",
9805 tag
, TREE_PURPOSE (parms
), len
);
9807 tree_node (TREE_PURPOSE (parms
));
9809 for (unsigned ix
= 0; ix
!= len
; ix
++)
9811 tree parm
= TREE_VEC_ELT (vec
, ix
);
9812 tree decl
= TREE_VALUE (parm
);
9814 gcc_checking_assert (DECL_TEMPLATE_PARM_P (decl
));
9816 switch (TREE_CODE (decl
))
9818 default: gcc_unreachable ();
9821 gcc_assert ((TREE_CODE (TREE_TYPE (decl
)) == TEMPLATE_TEMPLATE_PARM
)
9822 && (TREE_CODE (DECL_TEMPLATE_RESULT (decl
)) == TYPE_DECL
)
9823 && (TYPE_NAME (TREE_TYPE (decl
)) == decl
));
9827 gcc_assert ((TREE_CODE (TREE_TYPE (decl
)) == TEMPLATE_TYPE_PARM
)
9828 && (TYPE_NAME (TREE_TYPE (decl
)) == decl
));
9832 gcc_assert ((TREE_CODE (DECL_INITIAL (decl
)) == TEMPLATE_PARM_INDEX
)
9833 && (TREE_CODE (TEMPLATE_PARM_DECL (DECL_INITIAL (decl
)))
9835 && (DECL_TEMPLATE_PARM_P
9836 (TEMPLATE_PARM_DECL (DECL_INITIAL (decl
)))));
9841 tree_node (TEMPLATE_PARM_CONSTRAINTS (parm
));
9848 trees_in::tpl_parms (unsigned &tpl_levels
)
9850 tree parms
= NULL_TREE
;
9852 while (int len
= i ())
9856 parms
= back_ref (len
);
9861 parms
= tree_cons (NULL_TREE
, NULL_TREE
, parms
);
9862 int tag
= insert (parms
);
9863 TREE_PURPOSE (parms
) = tree_node ();
9866 && dump ("Reading template parms:%d level:%N length:%d",
9867 tag
, TREE_PURPOSE (parms
), len
);
9869 tree vec
= make_tree_vec (len
);
9870 for (int ix
= 0; ix
!= len
; ix
++)
9872 tree decl
= tree_node ();
9876 tree parm
= build_tree_list (NULL
, decl
);
9877 TEMPLATE_PARM_CONSTRAINTS (parm
) = tree_node ();
9879 TREE_VEC_ELT (vec
, ix
) = parm
;
9882 TREE_VALUE (parms
) = vec
;
9890 trees_out::tpl_parms_fini (tree tmpl
, unsigned tpl_levels
)
9892 for (tree parms
= DECL_TEMPLATE_PARMS (tmpl
);
9893 tpl_levels
--; parms
= TREE_CHAIN (parms
))
9895 tree vec
= TREE_VALUE (parms
);
9897 tree_node (TREE_TYPE (vec
));
9898 tree dflt
= error_mark_node
;
9899 for (unsigned ix
= TREE_VEC_LENGTH (vec
); ix
--;)
9901 tree parm
= TREE_VEC_ELT (vec
, ix
);
9904 dflt
= TREE_PURPOSE (parm
);
9910 tree decl
= TREE_VALUE (parm
);
9911 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
9913 tree ctx
= DECL_CONTEXT (decl
);
9914 tree inner
= DECL_TEMPLATE_RESULT (decl
);
9915 tree tpi
= (TREE_CODE (inner
) == TYPE_DECL
9916 ? TEMPLATE_TYPE_PARM_INDEX (TREE_TYPE (decl
))
9917 : DECL_INITIAL (inner
));
9918 bool original
= (TEMPLATE_PARM_LEVEL (tpi
)
9919 == TEMPLATE_PARM_ORIG_LEVEL (tpi
));
9920 /* Original template template parms have a context
9921 of their owning template. Reduced ones do not. */
9922 gcc_checking_assert (original
? ctx
== tmpl
: !ctx
);
9930 trees_in::tpl_parms_fini (tree tmpl
, unsigned tpl_levels
)
9932 for (tree parms
= DECL_TEMPLATE_PARMS (tmpl
);
9933 tpl_levels
--; parms
= TREE_CHAIN (parms
))
9935 tree vec
= TREE_VALUE (parms
);
9936 tree dflt
= error_mark_node
;
9938 TREE_TYPE (vec
) = tree_node ();
9939 for (unsigned ix
= TREE_VEC_LENGTH (vec
); ix
--;)
9941 tree parm
= TREE_VEC_ELT (vec
, ix
);
9944 dflt
= tree_node ();
9947 TREE_PURPOSE (parm
) = dflt
;
9950 tree decl
= TREE_VALUE (parm
);
9951 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
9953 tree inner
= DECL_TEMPLATE_RESULT (decl
);
9954 tree tpi
= (TREE_CODE (inner
) == TYPE_DECL
9955 ? TEMPLATE_TYPE_PARM_INDEX (TREE_TYPE (decl
))
9956 : DECL_INITIAL (inner
));
9957 bool original
= (TEMPLATE_PARM_LEVEL (tpi
)
9958 == TEMPLATE_PARM_ORIG_LEVEL (tpi
));
9959 /* Original template template parms have a context
9960 of their owning template. Reduced ones do not. */
9962 DECL_CONTEXT (decl
) = tmpl
;
9969 /* PARMS is a LIST, one node per level.
9970 TREE_VALUE is a TREE_VEC of parm info for that level.
9971 each ELT is a TREE_LIST
9972 TREE_VALUE is PARM_DECL, TYPE_DECL or TEMPLATE_DECL
9973 TREE_PURPOSE is the default value. */
9976 trees_out::tpl_header (tree tpl
, unsigned *tpl_levels
)
9978 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
9979 tpl_parms (parms
, *tpl_levels
);
9986 tree_node (TEMPLATE_PARMS_CONSTRAINTS (parms
));
9990 trees_in::tpl_header (tree tpl
, unsigned *tpl_levels
)
9992 tree parms
= tpl_parms (*tpl_levels
);
9996 DECL_TEMPLATE_PARMS (tpl
) = parms
;
9999 TEMPLATE_PARMS_CONSTRAINTS (parms
) = tree_node ();
10004 /* Stream skeleton parm nodes, with their flags, type & parm indices.
10005 All the parms will have consecutive tags. */
10008 trees_out::fn_parms_init (tree fn
)
10010 /* First init them. */
10011 int base_tag
= ref_num
- 1;
10013 for (tree parm
= DECL_ARGUMENTS (fn
);
10014 parm
; parm
= DECL_CHAIN (parm
), ix
++)
10016 if (streaming_p ())
10019 tree_node_bools (parm
);
10021 int tag
= insert (parm
);
10022 gcc_checking_assert (base_tag
- ix
== tag
);
10024 /* Mark the end. */
10025 if (streaming_p ())
10028 /* Now stream their contents. */
10030 for (tree parm
= DECL_ARGUMENTS (fn
);
10031 parm
; parm
= DECL_CHAIN (parm
), ix
++)
10033 if (streaming_p ())
10034 dump (dumper::TREE
)
10035 && dump ("Writing parm:%d %u (%N) of %N",
10036 base_tag
- ix
, ix
, parm
, fn
);
10037 tree_node_vals (parm
);
10041 /* Build skeleton parm nodes, read their flags, type & parm indices. */
10044 trees_in::fn_parms_init (tree fn
)
10046 int base_tag
= ~(int)back_refs
.length ();
10048 tree
*parm_ptr
= &DECL_ARGUMENTS (fn
);
10050 for (; int code
= u (); ix
++)
10052 tree parm
= start (code
);
10053 if (!tree_node_bools (parm
))
10056 int tag
= insert (parm
);
10057 gcc_checking_assert (base_tag
- ix
== tag
);
10059 parm_ptr
= &DECL_CHAIN (parm
);
10063 for (tree parm
= DECL_ARGUMENTS (fn
);
10064 parm
; parm
= DECL_CHAIN (parm
), ix
++)
10066 dump (dumper::TREE
)
10067 && dump ("Reading parm:%d %u (%N) of %N",
10068 base_tag
- ix
, ix
, parm
, fn
);
10069 if (!tree_node_vals (parm
))
10076 /* Read the remaining parm node data. Replace with existing (if
10077 non-null) in the map. */
10080 trees_in::fn_parms_fini (int tag
, tree fn
, tree existing
, bool is_defn
)
10082 tree existing_parm
= existing
? DECL_ARGUMENTS (existing
) : NULL_TREE
;
10083 tree parms
= DECL_ARGUMENTS (fn
);
10085 for (tree parm
= parms
; parm
; parm
= DECL_CHAIN (parm
), ix
++)
10089 if (is_defn
&& !DECL_SAVED_TREE (existing
))
10091 /* If we're about to become the definition, set the
10092 names of the parms from us. */
10093 DECL_NAME (existing_parm
) = DECL_NAME (parm
);
10094 DECL_SOURCE_LOCATION (existing_parm
) = DECL_SOURCE_LOCATION (parm
);
10097 back_refs
[~tag
] = existing_parm
;
10098 existing_parm
= DECL_CHAIN (existing_parm
);
10104 /* DEP is the depset of some decl we're streaming by value. Determine
10105 the merging behaviour. */
10108 trees_out::get_merge_kind (tree decl
, depset
*dep
)
10112 if (VAR_OR_FUNCTION_DECL_P (decl
))
10114 /* Any var or function with template info should have DEP. */
10115 gcc_checking_assert (!DECL_LANG_SPECIFIC (decl
)
10116 || !DECL_TEMPLATE_INFO (decl
));
10117 if (DECL_LOCAL_DECL_P (decl
))
10121 /* Either unique, or some member of a class that cannot have an
10122 out-of-class definition. For instance a FIELD_DECL. */
10123 tree ctx
= CP_DECL_CONTEXT (decl
);
10124 if (TREE_CODE (ctx
) == FUNCTION_DECL
)
10126 /* USING_DECLs cannot have DECL_TEMPLATE_INFO -- this isn't
10127 permitting them to have one. */
10128 gcc_checking_assert (TREE_CODE (decl
) == USING_DECL
10129 || !DECL_LANG_SPECIFIC (decl
)
10130 || !DECL_TEMPLATE_INFO (decl
));
10135 if (TREE_CODE (decl
) == TEMPLATE_DECL
10136 && DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (decl
))
10137 return MK_local_friend
;
10139 gcc_checking_assert (TYPE_P (ctx
));
10140 if (TREE_CODE (decl
) == USING_DECL
)
10143 if (TREE_CODE (decl
) == FIELD_DECL
)
10145 if (DECL_NAME (decl
))
10147 /* Anonymous FIELD_DECLs have a NULL name. */
10148 gcc_checking_assert (!IDENTIFIER_ANON_P (DECL_NAME (decl
)));
10152 if (!DECL_NAME (decl
)
10153 && !RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl
))
10154 && !DECL_BIT_FIELD_REPRESENTATIVE (decl
))
10156 /* The underlying storage unit for a bitfield. We do not
10157 need to dedup it, because it's only reachable through
10158 the bitfields it represents. And those are deduped. */
10159 // FIXME: Is that assertion correct -- do we ever fish it
10160 // out and put it in an expr?
10161 gcc_checking_assert ((TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
10162 ? TREE_CODE (TREE_TYPE (TREE_TYPE (decl
)))
10163 : TREE_CODE (TREE_TYPE (decl
)))
10171 if (TREE_CODE (decl
) == CONST_DECL
)
10174 if (TREE_CODE (decl
) == VAR_DECL
10175 && DECL_VTABLE_OR_VTT_P (decl
))
10178 if (DECL_THUNK_P (decl
))
10179 /* Thunks are unique-enough, because they're only referenced
10180 from the vtable. And that's either new (so we want the
10181 thunks), or it's a duplicate (so it will be dropped). */
10184 /* There should be no other cases. */
10185 gcc_unreachable ();
10188 gcc_checking_assert (TREE_CODE (decl
) != FIELD_DECL
10189 && TREE_CODE (decl
) != USING_DECL
10190 && TREE_CODE (decl
) != CONST_DECL
);
10192 if (is_key_order ())
10194 /* When doing the mergeablilty graph, there's an indirection to
10195 the actual depset. */
10196 gcc_assert (dep
->is_special ());
10197 dep
= dep
->deps
[0];
10200 gcc_checking_assert (decl
== dep
->get_entity ());
10202 merge_kind mk
= MK_named
;
10203 switch (dep
->get_entity_kind ())
10206 gcc_unreachable ();
10208 case depset::EK_PARTIAL
:
10212 case depset::EK_DECL
:
10214 tree ctx
= CP_DECL_CONTEXT (decl
);
10216 switch (TREE_CODE (ctx
))
10219 gcc_unreachable ();
10221 case FUNCTION_DECL
:
10222 // FIXME: This can occur for (a) voldemorty TYPE_DECLS
10223 // (which are returned from a function), or (b)
10224 // block-scope class definitions in template functions.
10225 // These are as unique as the containing function. While
10226 // on read-back we can discover if the CTX was a
10227 // duplicate, we don't have a mechanism to get from the
10228 // existing CTX to the existing version of this decl.
10229 gcc_checking_assert
10230 (DECL_IMPLICIT_TYPEDEF_P (STRIP_TEMPLATE (decl
)));
10237 if (DECL_NAME (decl
) == as_base_identifier
)
10239 else if (IDENTIFIER_ANON_P (DECL_NAME (decl
)))
10243 case NAMESPACE_DECL
:
10244 if (DECL_IMPLICIT_TYPEDEF_P (STRIP_TEMPLATE (decl
))
10245 && LAMBDA_TYPE_P (TREE_TYPE (decl
)))
10247 = LAMBDA_EXPR_EXTRA_SCOPE (CLASSTYPE_LAMBDA_EXPR
10248 (TREE_TYPE (decl
))))
10249 if (TREE_CODE (scope
) == VAR_DECL
10250 && DECL_MODULE_ATTACHMENTS_P (scope
))
10256 if (TREE_CODE (decl
) == TEMPLATE_DECL
10257 && DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (decl
))
10258 mk
= MK_local_friend
;
10259 else if (IDENTIFIER_ANON_P (DECL_NAME (decl
)))
10261 if (DECL_IMPLICIT_TYPEDEF_P (decl
)
10262 && UNSCOPED_ENUM_P (TREE_TYPE (decl
))
10263 && TYPE_VALUES (TREE_TYPE (decl
)))
10264 /* Keyed by first enum value, and underlying type. */
10267 /* No way to merge it, it is an ODR land-mine. */
10274 case depset::EK_SPECIALIZATION
:
10276 gcc_checking_assert (dep
->is_special ());
10277 spec_entry
*entry
= reinterpret_cast <spec_entry
*> (dep
->deps
[0]);
10279 if (TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
10280 /* An block-scope classes of templates are themselves
10282 gcc_checking_assert (DECL_IMPLICIT_TYPEDEF_P (decl
));
10284 if (dep
->is_friend_spec ())
10285 mk
= MK_friend_spec
;
10286 else if (dep
->is_type_spec ())
10288 else if (dep
->is_alias ())
10289 mk
= MK_alias_spec
;
10293 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
10295 tree res
= DECL_TEMPLATE_RESULT (decl
);
10296 if (!(mk
& MK_tmpl_decl_mask
))
10297 res
= TREE_TYPE (res
);
10299 if (res
== entry
->spec
)
10300 /* We check we can get back to the template during
10302 mk
= merge_kind (mk
| MK_tmpl_tmpl_mask
);
10312 /* The container of DECL -- not necessarily its context! */
10315 trees_out::decl_container (tree decl
)
10318 tree tpl
= NULL_TREE
;
10319 if (tree template_info
= node_template_info (decl
, use_tpl
))
10320 tpl
= TI_TEMPLATE (template_info
);
10324 /* Stream the template we're instantiated from. */
10327 tree container
= NULL_TREE
;
10328 if (TREE_CODE (decl
) == TEMPLATE_DECL
10329 && DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (decl
))
10330 container
= DECL_CHAIN (decl
);
10332 container
= CP_DECL_CONTEXT (decl
);
10334 if (TYPE_P (container
))
10335 container
= TYPE_NAME (container
);
10337 tree_node (container
);
10343 trees_in::decl_container ()
10345 /* The maybe-template. */
10346 (void)tree_node ();
10348 tree container
= tree_node ();
10353 /* Write out key information about a mergeable DEP. Does not write
10354 the contents of DEP itself. The context has already been
10355 written. The container has already been streamed. */
10358 trees_out::key_mergeable (int tag
, merge_kind mk
, tree decl
, tree inner
,
10359 tree container
, depset
*dep
)
10361 if (dep
&& is_key_order ())
10363 gcc_checking_assert (dep
->is_special ());
10364 dep
= dep
->deps
[0];
10367 if (streaming_p ())
10368 dump (dumper::MERGE
)
10369 && dump ("Writing:%d's %s merge key (%s) %C:%N", tag
, merge_kind_name
[mk
],
10370 dep
? dep
->entity_kind_name () : "contained",
10371 TREE_CODE (decl
), decl
);
10373 /* Now write the locating information. */
10374 if (mk
& MK_template_mask
)
10376 /* Specializations are located via their originating template,
10377 and the set of template args they specialize. */
10378 gcc_checking_assert (dep
&& dep
->is_special ());
10379 spec_entry
*entry
= reinterpret_cast <spec_entry
*> (dep
->deps
[0]);
10381 tree_node (entry
->tmpl
);
10382 tree_node (entry
->args
);
10383 if (streaming_p ())
10384 u (get_mergeable_specialization_flags (entry
->tmpl
, decl
));
10385 if (mk
& MK_tmpl_decl_mask
)
10386 if (flag_concepts
&& TREE_CODE (inner
) == VAR_DECL
)
10388 /* Variable template partial specializations might need
10389 constraints (see spec_hasher::equal). It's simpler to
10390 write NULL when we don't need them. */
10391 tree constraints
= NULL_TREE
;
10393 if (uses_template_parms (entry
->args
))
10394 constraints
= get_constraints (inner
);
10395 tree_node (constraints
);
10400 /* Make sure we can locate the decl. */
10401 tree existing
= match_mergeable_specialization
10402 (bool (mk
& MK_tmpl_decl_mask
), entry
, false);
10404 gcc_assert (existing
);
10405 if (mk
& MK_tmpl_decl_mask
)
10407 if (mk
& MK_tmpl_alias_mask
)
10408 /* It should be in both tables. */
10409 gcc_assert (match_mergeable_specialization (false, entry
, false)
10410 == TREE_TYPE (existing
));
10411 else if (mk
& MK_tmpl_tmpl_mask
)
10412 if (tree ti
= DECL_TEMPLATE_INFO (existing
))
10413 existing
= TI_TEMPLATE (ti
);
10417 if (!(mk
& MK_tmpl_tmpl_mask
))
10418 existing
= TYPE_NAME (existing
);
10419 else if (tree ti
= CLASSTYPE_TEMPLATE_INFO (existing
))
10420 existing
= TI_TEMPLATE (ti
);
10423 /* The walkabout should have found ourselves. */
10424 gcc_assert (existing
== decl
);
10427 else if (mk
!= MK_unique
)
10430 tree name
= DECL_NAME (decl
);
10435 gcc_unreachable ();
10438 case MK_friend_spec
:
10439 if (IDENTIFIER_CONV_OP_P (name
))
10440 name
= conv_op_identifier
;
10442 if (inner
&& TREE_CODE (inner
) == FUNCTION_DECL
)
10444 /* Functions are distinguished by parameter types. */
10445 tree fn_type
= TREE_TYPE (inner
);
10447 key
.ref_q
= type_memfn_rqual (fn_type
);
10448 key
.args
= TYPE_ARG_TYPES (fn_type
);
10450 if (tree reqs
= get_constraints (inner
))
10452 if (cxx_dialect
< cxx20
)
10453 reqs
= CI_ASSOCIATED_CONSTRAINTS (reqs
);
10455 reqs
= CI_DECLARATOR_REQS (reqs
);
10456 key
.constraints
= reqs
;
10459 if (IDENTIFIER_CONV_OP_P (name
)
10461 && !(name
== fun_identifier
10462 /* In case the user names something _FUN */
10463 && LAMBDA_TYPE_P (DECL_CONTEXT (inner
)))))
10464 /* And a function template, or conversion operator needs
10465 the return type. Except for the _FUN thunk of a
10466 generic lambda, which has a recursive decl_type'd
10468 // FIXME: What if the return type is a voldemort?
10469 key
.ret
= fndecl_declared_return_type (inner
);
10472 if (mk
== MK_friend_spec
)
10474 gcc_checking_assert (dep
&& dep
->is_special ());
10475 spec_entry
*entry
= reinterpret_cast <spec_entry
*> (dep
->deps
[0]);
10477 tree_node (entry
->tmpl
);
10478 tree_node (entry
->args
);
10479 if (streaming_p ())
10480 u (get_mergeable_specialization_flags (entry
->tmpl
, decl
));
10487 if (TREE_CODE (inner
) != FIELD_DECL
)
10490 gcc_checking_assert (!name
|| !IDENTIFIER_ANON_P (name
));
10492 for (tree field
= TYPE_FIELDS (TREE_TYPE (container
));
10493 ; field
= DECL_CHAIN (field
))
10495 tree finner
= STRIP_TEMPLATE (field
);
10496 if (TREE_CODE (finner
) == TREE_CODE (inner
))
10498 if (finner
== inner
)
10509 tree vtable
= CLASSTYPE_VTABLES (TREE_TYPE (container
));
10510 for (unsigned ix
= 0; ; vtable
= DECL_CHAIN (vtable
), ix
++)
10511 if (vtable
== decl
)
10521 gcc_checking_assert
10522 (decl
== TYPE_NAME (CLASSTYPE_AS_BASE (TREE_TYPE (container
))));
10525 case MK_local_friend
:
10527 /* Find by index on the class's DECL_LIST */
10529 for (tree decls
= CLASSTYPE_DECL_LIST (TREE_CHAIN (decl
));
10530 decls
; decls
= TREE_CHAIN (decls
))
10531 if (!TREE_PURPOSE (decls
))
10533 tree frnd
= friend_from_decl_list (TREE_VALUE (decls
));
10545 /* Anonymous enums are located by their first identifier,
10546 and underlying type. */
10547 tree type
= TREE_TYPE (decl
);
10549 gcc_checking_assert (UNSCOPED_ENUM_P (type
));
10550 /* Using the type name drops the bit precision we might
10551 have been using on the enum. */
10552 key
.ret
= TYPE_NAME (ENUM_UNDERLYING_TYPE (type
));
10553 if (tree values
= TYPE_VALUES (type
))
10554 name
= DECL_NAME (TREE_VALUE (values
));
10560 gcc_checking_assert (LAMBDA_TYPE_P (TREE_TYPE (inner
)));
10561 tree scope
= LAMBDA_EXPR_EXTRA_SCOPE (CLASSTYPE_LAMBDA_EXPR
10562 (TREE_TYPE (inner
)));
10563 gcc_checking_assert (TREE_CODE (scope
) == VAR_DECL
);
10564 attachset
*root
= attached_table
->get (DECL_UID (scope
));
10565 unsigned ix
= root
->num
;
10566 /* If we don't find it, we'll write a really big number
10567 that the reader will ignore. */
10569 if (root
->values
[ix
] == inner
)
10572 /* Use the attached-to decl as the 'name'. */
10580 key
.constraints
= get_constraints (inner
);
10581 key
.ret
= CLASSTYPE_TI_TEMPLATE (TREE_TYPE (inner
));
10582 key
.args
= CLASSTYPE_TI_ARGS (TREE_TYPE (inner
));
10588 if (streaming_p ())
10590 unsigned code
= (key
.ref_q
<< 0) | (key
.index
<< 2);
10595 tree_node (key
.ret
);
10596 else if (mk
== MK_partial
10597 || (mk
== MK_named
&& inner
10598 && TREE_CODE (inner
) == FUNCTION_DECL
))
10600 tree_node (key
.ret
);
10601 tree arg
= key
.args
;
10602 if (mk
== MK_named
)
10603 while (arg
&& arg
!= void_list_node
)
10605 tree_node (TREE_VALUE (arg
));
10606 arg
= TREE_CHAIN (arg
);
10609 tree_node (key
.constraints
);
10614 /* DECL is a new declaration that may be duplicated in OVL. Use RET &
10615 ARGS to find its clone, or NULL. If DECL's DECL_NAME is NULL, this
10616 has been found by a proxy. It will be an enum type located by it's
10619 We're conservative with matches, so ambiguous decls will be
10620 registered as different, then lead to a lookup error if the two
10621 modules are both visible. Perhaps we want to do something similar
10622 to duplicate decls to get ODR errors on loading? We already have
10623 some special casing for namespaces. */
10626 check_mergeable_decl (merge_kind mk
, tree decl
, tree ovl
, merge_key
const &key
)
10628 tree found
= NULL_TREE
;
10629 for (ovl_iterator
iter (ovl
); !found
&& iter
; ++iter
)
10631 tree match
= *iter
;
10633 tree d_inner
= decl
;
10634 tree m_inner
= match
;
10637 if (TREE_CODE (d_inner
) != TREE_CODE (m_inner
))
10639 if (TREE_CODE (match
) == NAMESPACE_DECL
10640 && !DECL_NAMESPACE_ALIAS (match
))
10641 /* Namespaces are never overloaded. */
10647 switch (TREE_CODE (d_inner
))
10649 case TEMPLATE_DECL
:
10650 if (template_heads_equivalent_p (d_inner
, m_inner
))
10652 d_inner
= DECL_TEMPLATE_RESULT (d_inner
);
10653 m_inner
= DECL_TEMPLATE_RESULT (m_inner
);
10654 if (d_inner
== error_mark_node
10655 && TYPE_DECL_ALIAS_P (m_inner
))
10664 case FUNCTION_DECL
:
10665 map_context_from
= d_inner
;
10666 map_context_to
= m_inner
;
10667 if (tree m_type
= TREE_TYPE (m_inner
))
10669 || same_type_p (key
.ret
, fndecl_declared_return_type (m_inner
)))
10670 && type_memfn_rqual (m_type
) == key
.ref_q
10671 && compparms (key
.args
, TYPE_ARG_TYPES (m_type
))
10672 /* Reject if old is a "C" builtin and new is not "C".
10673 Matches decls_match behaviour. */
10674 && (!DECL_IS_UNDECLARED_BUILTIN (m_inner
)
10675 || !DECL_EXTERN_C_P (m_inner
)
10676 || DECL_EXTERN_C_P (d_inner
)))
10678 tree m_reqs
= get_constraints (m_inner
);
10681 if (cxx_dialect
< cxx20
)
10682 m_reqs
= CI_ASSOCIATED_CONSTRAINTS (m_reqs
);
10684 m_reqs
= CI_DECLARATOR_REQS (m_reqs
);
10687 if (cp_tree_equal (key
.constraints
, m_reqs
))
10690 map_context_from
= map_context_to
= NULL_TREE
;
10694 if (DECL_IMPLICIT_TYPEDEF_P (d_inner
)
10695 == DECL_IMPLICIT_TYPEDEF_P (m_inner
))
10697 if (!IDENTIFIER_ANON_P (DECL_NAME (m_inner
)))
10699 else if (mk
== MK_enum
10700 && (TYPE_NAME (ENUM_UNDERLYING_TYPE (TREE_TYPE (m_inner
)))
10715 /* DECL, INNER & TYPE are a skeleton set of nodes for a decl. Only
10716 the bools have been filled in. Read its merging key and merge it.
10717 Returns the existing decl if there is one. */
10720 trees_in::key_mergeable (int tag
, merge_kind mk
, tree decl
, tree inner
,
10721 tree type
, tree container
, bool is_mod
)
10723 const char *kind
= "new";
10724 tree existing
= NULL_TREE
;
10726 if (mk
& MK_template_mask
)
10729 spec
.tmpl
= tree_node ();
10730 spec
.args
= tree_node ();
10731 unsigned flags
= u ();
10733 DECL_NAME (decl
) = DECL_NAME (spec
.tmpl
);
10734 DECL_CONTEXT (decl
) = DECL_CONTEXT (spec
.tmpl
);
10735 DECL_NAME (inner
) = DECL_NAME (decl
);
10736 DECL_CONTEXT (inner
) = DECL_CONTEXT (decl
);
10739 if (mk
& MK_tmpl_tmpl_mask
)
10742 return error_mark_node
;
10745 tree constr
= NULL_TREE
;
10746 bool is_decl
= mk
& MK_tmpl_decl_mask
;
10749 if (flag_concepts
&& TREE_CODE (inner
) == VAR_DECL
)
10751 constr
= tree_node ();
10753 set_constraints (inner
, constr
);
10758 if (mk
== MK_type_spec
&& inner
!= decl
)
10759 return error_mark_node
;
10762 existing
= match_mergeable_specialization (is_decl
, &spec
);
10764 /* We'll add these back later, if this is the new decl. */
10765 remove_constraints (inner
);
10768 add_mergeable_specialization (spec
.tmpl
, spec
.args
, decl
, flags
);
10769 else if (mk
& MK_tmpl_decl_mask
)
10771 /* A declaration specialization. */
10772 if (mk
& MK_tmpl_tmpl_mask
)
10773 if (tree ti
= DECL_TEMPLATE_INFO (existing
))
10775 tree tmpl
= TI_TEMPLATE (ti
);
10776 if (DECL_TEMPLATE_RESULT (tmpl
) == existing
)
10782 /* A type specialization. */
10783 if (!(mk
& MK_tmpl_tmpl_mask
))
10784 existing
= TYPE_NAME (existing
);
10785 else if (tree ti
= CLASSTYPE_TEMPLATE_INFO (existing
))
10787 tree tmpl
= TI_TEMPLATE (ti
);
10788 if (DECL_TEMPLATE_RESULT (tmpl
) == TYPE_NAME (existing
))
10793 else if (mk
== MK_unique
)
10797 tree name
= tree_node ();
10800 unsigned code
= u ();
10801 key
.ref_q
= cp_ref_qualifier ((code
>> 0) & 3);
10802 key
.index
= code
>> 2;
10805 key
.ret
= tree_node ();
10806 else if (mk
== MK_partial
10807 || ((mk
== MK_named
|| mk
== MK_friend_spec
)
10808 && inner
&& TREE_CODE (inner
) == FUNCTION_DECL
))
10810 key
.ret
= tree_node ();
10811 tree arg
, *arg_ptr
= &key
.args
;
10812 while ((arg
= tree_node ())
10813 && arg
!= void_list_node
10814 && mk
!= MK_partial
)
10816 *arg_ptr
= tree_cons (NULL_TREE
, arg
, NULL_TREE
);
10817 arg_ptr
= &TREE_CHAIN (*arg_ptr
);
10820 key
.constraints
= tree_node ();
10823 if (get_overrun ())
10824 return error_mark_node
;
10826 if (mk
< MK_indirect_lwm
)
10828 DECL_NAME (decl
) = name
;
10829 DECL_CONTEXT (decl
) = FROB_CONTEXT (container
);
10833 DECL_NAME (inner
) = DECL_NAME (decl
);
10834 DECL_CONTEXT (inner
) = DECL_CONTEXT (decl
);
10837 if (mk
== MK_partial
)
10839 for (tree spec
= DECL_TEMPLATE_SPECIALIZATIONS (key
.ret
);
10840 spec
; spec
= TREE_CHAIN (spec
))
10842 tree tmpl
= TREE_VALUE (spec
);
10843 if (template_args_equal (key
.args
,
10844 CLASSTYPE_TI_ARGS (TREE_TYPE (tmpl
)))
10845 && cp_tree_equal (key
.constraints
,
10847 (DECL_TEMPLATE_RESULT (tmpl
))))
10854 add_mergeable_specialization (key
.ret
, key
.args
, decl
, 2);
10857 switch (TREE_CODE (container
))
10860 gcc_unreachable ();
10862 case NAMESPACE_DECL
:
10863 if (mk
== MK_attached
)
10865 if (DECL_LANG_SPECIFIC (name
)
10866 && VAR_OR_FUNCTION_DECL_P (name
)
10867 && DECL_MODULE_ATTACHMENTS_P (name
))
10868 if (attachset
*set
= attached_table
->get (DECL_UID (name
)))
10869 if (key
.index
< set
->num
)
10871 existing
= set
->values
[key
.index
];
10874 gcc_checking_assert
10875 (DECL_IMPLICIT_TYPEDEF_P (existing
));
10878 = CLASSTYPE_TI_TEMPLATE (TREE_TYPE (existing
));
10882 else if (is_mod
&& !(state
->is_module () || state
->is_partition ()))
10886 gcc_checking_assert (mk
== MK_named
|| mk
== MK_enum
);
10888 tree
*vslot
= mergeable_namespace_slots (container
, name
,
10890 existing
= check_mergeable_decl (mk
, decl
, *vslot
, key
);
10892 add_mergeable_namespace_entity (vslot
, decl
);
10895 /* Note that we now have duplicates to deal with in
10898 BINDING_VECTOR_PARTITION_DUPS_P (mvec
) = true;
10900 BINDING_VECTOR_GLOBAL_DUPS_P (mvec
) = true;
10905 case FUNCTION_DECL
:
10906 // FIXME: What about a voldemort? how do we find what it
10907 // duplicates? Do we have to number vmorts relative to
10908 // their containing function? But how would that work
10909 // when matching an in-TU declaration?
10914 if (is_mod
&& !(state
->is_module () || state
->is_partition ())
10915 /* Implicit member functions can come from
10917 && !(DECL_ARTIFICIAL (decl
)
10918 && TREE_CODE (decl
) == FUNCTION_DECL
10919 && !DECL_THUNK_P (decl
)))
10923 tree ctx
= TREE_TYPE (container
);
10925 /* For some reason templated enumeral types are not marked
10926 as COMPLETE_TYPE_P, even though they have members.
10927 This may well be a bug elsewhere. */
10928 if (TREE_CODE (ctx
) == ENUMERAL_TYPE
)
10929 existing
= find_enum_member (ctx
, name
);
10930 else if (COMPLETE_TYPE_P (ctx
))
10935 gcc_unreachable ();
10938 existing
= lookup_class_binding (ctx
, name
);
10942 if (TREE_CODE (inner
) == TEMPLATE_DECL
10943 && !DECL_MEMBER_TEMPLATE_P (inner
))
10944 inner
= DECL_TEMPLATE_RESULT (inner
);
10946 existing
= check_mergeable_decl
10947 (mk
, inner
, existing
, key
);
10949 if (!existing
&& DECL_ALIAS_TEMPLATE_P (decl
))
10950 {} // FIXME: Insert into specialization
10951 // tables, we'll need the arguments for that!
10957 unsigned ix
= key
.index
;
10958 for (tree field
= TYPE_FIELDS (ctx
);
10959 field
; field
= DECL_CHAIN (field
))
10961 tree finner
= STRIP_TEMPLATE (field
);
10962 if (TREE_CODE (finner
) == TREE_CODE (inner
))
10974 unsigned ix
= key
.index
;
10975 for (tree vtable
= CLASSTYPE_VTABLES (ctx
);
10976 vtable
; vtable
= DECL_CHAIN (vtable
))
10987 tree as_base
= CLASSTYPE_AS_BASE (ctx
);
10988 if (as_base
&& as_base
!= ctx
)
10989 existing
= TYPE_NAME (as_base
);
10993 case MK_local_friend
:
10995 unsigned ix
= key
.index
;
10996 for (tree decls
= CLASSTYPE_DECL_LIST (ctx
);
10997 decls
; decls
= TREE_CHAIN (decls
))
10998 if (!TREE_PURPOSE (decls
) && !ix
--)
11001 = friend_from_decl_list (TREE_VALUE (decls
));
11008 if (existing
&& mk
< MK_indirect_lwm
&& mk
!= MK_partial
11009 && TREE_CODE (decl
) == TEMPLATE_DECL
11010 && !DECL_MEMBER_TEMPLATE_P (decl
))
11013 if (DECL_IMPLICIT_TYPEDEF_P (existing
))
11014 ti
= TYPE_TEMPLATE_INFO (TREE_TYPE (existing
));
11016 ti
= DECL_TEMPLATE_INFO (existing
);
11017 existing
= TI_TEMPLATE (ti
);
11023 if (mk
== MK_friend_spec
)
11026 spec
.tmpl
= tree_node ();
11027 spec
.args
= tree_node ();
11029 unsigned flags
= u ();
11031 tree e
= match_mergeable_specialization (true, &spec
);
11033 add_mergeable_specialization (spec
.tmpl
, spec
.args
,
11034 existing
? existing
: decl
, flags
);
11035 else if (e
!= existing
)
11040 dump (dumper::MERGE
)
11041 && dump ("Read:%d's %s merge key (%s) %C:%N", tag
, merge_kind_name
[mk
],
11042 existing
? "matched" : kind
, TREE_CODE (decl
), decl
);
11048 trees_out::binfo_mergeable (tree binfo
)
11051 while (tree parent
= BINFO_INHERITANCE_CHAIN (dom
))
11053 tree type
= BINFO_TYPE (dom
);
11054 gcc_checking_assert (TYPE_BINFO (type
) == dom
);
11056 if (streaming_p ())
11059 for (; dom
!= binfo
; dom
= TREE_CHAIN (dom
))
11066 trees_in::binfo_mergeable (tree
*type
)
11068 *type
= tree_node ();
11072 /* DECL is a just streamed mergeable decl that should match EXISTING. Check
11073 it does and issue an appropriate diagnostic if not. Merge any
11074 bits from DECL to EXISTING. This is stricter matching than
11075 decls_match, because we can rely on ODR-sameness, and we cannot use
11076 decls_match because it can cause instantiations of constraints. */
11079 trees_in::is_matching_decl (tree existing
, tree decl
)
11081 // FIXME: We should probably do some duplicate decl-like stuff here
11082 // (beware, default parms should be the same?) Can we just call
11083 // duplicate_decls and teach it how to handle the module-specific
11084 // permitted/required duplications?
11086 // We know at this point that the decls have matched by key, so we
11087 // can elide some of the checking
11088 gcc_checking_assert (TREE_CODE (existing
) == TREE_CODE (decl
));
11091 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
11093 inner
= DECL_TEMPLATE_RESULT (decl
);
11094 gcc_checking_assert (TREE_CODE (DECL_TEMPLATE_RESULT (existing
))
11095 == TREE_CODE (inner
));
11098 gcc_checking_assert (!map_context_from
);
11099 /* This mapping requres the new decl on the lhs and the existing
11100 entity on the rhs of the comparitors below. */
11101 map_context_from
= inner
;
11102 map_context_to
= STRIP_TEMPLATE (existing
);
11104 if (TREE_CODE (inner
) == FUNCTION_DECL
)
11106 tree e_ret
= fndecl_declared_return_type (existing
);
11107 tree d_ret
= fndecl_declared_return_type (decl
);
11109 if (decl
!= inner
&& DECL_NAME (inner
) == fun_identifier
11110 && LAMBDA_TYPE_P (DECL_CONTEXT (inner
)))
11111 /* This has a recursive type that will compare different. */;
11112 else if (!same_type_p (d_ret
, e_ret
))
11115 tree e_type
= TREE_TYPE (existing
);
11116 tree d_type
= TREE_TYPE (decl
);
11118 if (DECL_EXTERN_C_P (decl
) != DECL_EXTERN_C_P (existing
))
11121 for (tree e_args
= TYPE_ARG_TYPES (e_type
),
11122 d_args
= TYPE_ARG_TYPES (d_type
);
11123 e_args
!= d_args
&& (e_args
|| d_args
);
11124 e_args
= TREE_CHAIN (e_args
), d_args
= TREE_CHAIN (d_args
))
11126 if (!(e_args
&& d_args
))
11129 if (!same_type_p (TREE_VALUE (d_args
), TREE_VALUE (e_args
)))
11132 // FIXME: Check default values
11135 /* If EXISTING has an undeduced or uninstantiated exception
11136 specification, but DECL does not, propagate the exception
11137 specification. Otherwise we end up asserting or trying to
11138 instantiate it in the middle of loading. */
11139 tree e_spec
= TYPE_RAISES_EXCEPTIONS (e_type
);
11140 tree d_spec
= TYPE_RAISES_EXCEPTIONS (d_type
);
11141 if (DEFERRED_NOEXCEPT_SPEC_P (e_spec
))
11143 if (!DEFERRED_NOEXCEPT_SPEC_P (d_spec
)
11144 || (UNEVALUATED_NOEXCEPT_SPEC_P (e_spec
)
11145 && !UNEVALUATED_NOEXCEPT_SPEC_P (d_spec
)))
11147 dump (dumper::MERGE
)
11148 && dump ("Propagating instantiated noexcept to %N", existing
);
11149 TREE_TYPE (existing
) = d_type
;
11151 /* Propagate to existing clones. */
11153 FOR_EACH_CLONE (clone
, existing
)
11155 if (TREE_TYPE (clone
) == e_type
)
11156 TREE_TYPE (clone
) = d_type
;
11159 = build_exception_variant (TREE_TYPE (clone
), d_spec
);
11163 else if (!DEFERRED_NOEXCEPT_SPEC_P (d_spec
)
11164 && !comp_except_specs (d_spec
, e_spec
, ce_type
))
11167 /* Using cp_tree_equal because we can meet TYPE_ARGUMENT_PACKs
11168 here. I suspect the entities that directly do that are things
11169 that shouldn't go to duplicate_decls (FIELD_DECLs etc). */
11170 else if (!cp_tree_equal (TREE_TYPE (decl
), TREE_TYPE (existing
)))
11173 map_context_from
= map_context_to
= NULL_TREE
;
11174 if (DECL_IS_UNDECLARED_BUILTIN (existing
))
11175 /* Just like duplicate_decls, presum the user knows what
11176 they're doing in overriding a builtin. */
11177 TREE_TYPE (existing
) = TREE_TYPE (decl
);
11180 // FIXME:QOI Might be template specialization from a module,
11181 // not necessarily global module
11182 error_at (DECL_SOURCE_LOCATION (decl
),
11183 "conflicting global module declaration %#qD", decl
);
11184 inform (DECL_SOURCE_LOCATION (existing
),
11185 "existing declaration %#qD", existing
);
11190 map_context_from
= map_context_to
= NULL_TREE
;
11192 if (DECL_IS_UNDECLARED_BUILTIN (existing
)
11193 && !DECL_IS_UNDECLARED_BUILTIN (decl
))
11195 /* We're matching a builtin that the user has yet to declare.
11196 We are the one! This is very much duplicate-decl
11198 DECL_SOURCE_LOCATION (existing
) = DECL_SOURCE_LOCATION (decl
);
11199 if (TREE_CODE (decl
) != TYPE_DECL
)
11201 /* Propagate exceptions etc. */
11202 TREE_TYPE (existing
) = TREE_TYPE (decl
);
11203 TREE_NOTHROW (existing
) = TREE_NOTHROW (decl
);
11205 /* This is actually an import! */
11206 DECL_MODULE_IMPORT_P (existing
) = true;
11209 existing
->base
= decl
->base
;
11211 if (TREE_CODE (decl
) == FUNCTION_DECL
)
11214 memcpy (&existing
->decl_common
.size
,
11215 &decl
->decl_common
.size
,
11216 (offsetof (tree_decl_common
, pt_uid
)
11217 - offsetof (tree_decl_common
, size
)));
11218 auto bltin_class
= DECL_BUILT_IN_CLASS (decl
);
11219 existing
->function_decl
.built_in_class
= bltin_class
;
11220 auto fncode
= DECL_UNCHECKED_FUNCTION_CODE (decl
);
11221 DECL_UNCHECKED_FUNCTION_CODE (existing
) = fncode
;
11222 if (existing
->function_decl
.built_in_class
== BUILT_IN_NORMAL
)
11224 if (builtin_decl_explicit_p (built_in_function (fncode
)))
11227 case BUILT_IN_STPCPY
:
11228 set_builtin_decl_implicit_p
11229 (built_in_function (fncode
), true);
11232 set_builtin_decl_declared_p
11233 (built_in_function (fncode
), true);
11236 copy_attributes_to_builtin (decl
);
11241 if (VAR_OR_FUNCTION_DECL_P (decl
)
11242 && DECL_TEMPLATE_INSTANTIATED (decl
))
11243 /* Don't instantiate again! */
11244 DECL_TEMPLATE_INSTANTIATED (existing
) = true;
11246 tree e_inner
= inner
== decl
? existing
: DECL_TEMPLATE_RESULT (existing
);
11248 if (TREE_CODE (inner
) == FUNCTION_DECL
11249 && DECL_DECLARED_INLINE_P (inner
))
11250 DECL_DECLARED_INLINE_P (e_inner
) = true;
11251 if (!DECL_EXTERNAL (inner
))
11252 DECL_EXTERNAL (e_inner
) = false;
11254 // FIXME: Check default tmpl and fn parms here
11259 /* FN is an implicit member function that we've discovered is new to
11260 the class. Add it to the TYPE_FIELDS chain and the method vector.
11261 Reset the appropriate classtype lazy flag. */
11264 trees_in::install_implicit_member (tree fn
)
11266 tree ctx
= DECL_CONTEXT (fn
);
11267 tree name
= DECL_NAME (fn
);
11268 /* We know these are synthesized, so the set of expected prototypes
11269 is quite restricted. We're not validating correctness, just
11270 distinguishing beteeen the small set of possibilities. */
11271 tree parm_type
= TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (fn
));
11272 if (IDENTIFIER_CTOR_P (name
))
11274 if (CLASSTYPE_LAZY_DEFAULT_CTOR (ctx
)
11275 && VOID_TYPE_P (parm_type
))
11276 CLASSTYPE_LAZY_DEFAULT_CTOR (ctx
) = false;
11277 else if (!TYPE_REF_P (parm_type
))
11279 else if (CLASSTYPE_LAZY_COPY_CTOR (ctx
)
11280 && !TYPE_REF_IS_RVALUE (parm_type
))
11281 CLASSTYPE_LAZY_COPY_CTOR (ctx
) = false;
11282 else if (CLASSTYPE_LAZY_MOVE_CTOR (ctx
))
11283 CLASSTYPE_LAZY_MOVE_CTOR (ctx
) = false;
11287 else if (IDENTIFIER_DTOR_P (name
))
11289 if (CLASSTYPE_LAZY_DESTRUCTOR (ctx
))
11290 CLASSTYPE_LAZY_DESTRUCTOR (ctx
) = false;
11293 if (DECL_VIRTUAL_P (fn
))
11294 /* A virtual dtor should have been created when the class
11295 became complete. */
11298 else if (name
== assign_op_identifier
)
11300 if (!TYPE_REF_P (parm_type
))
11302 else if (CLASSTYPE_LAZY_COPY_ASSIGN (ctx
)
11303 && !TYPE_REF_IS_RVALUE (parm_type
))
11304 CLASSTYPE_LAZY_COPY_ASSIGN (ctx
) = false;
11305 else if (CLASSTYPE_LAZY_MOVE_ASSIGN (ctx
))
11306 CLASSTYPE_LAZY_MOVE_ASSIGN (ctx
) = false;
11313 dump (dumper::MERGE
) && dump ("Adding implicit member %N", fn
);
11315 DECL_CHAIN (fn
) = TYPE_FIELDS (ctx
);
11316 TYPE_FIELDS (ctx
) = fn
;
11318 add_method (ctx
, fn
, false);
11320 /* Propagate TYPE_FIELDS. */
11321 fixup_type_variants (ctx
);
11326 /* Return non-zero if DECL has a definition that would be interesting to
11330 has_definition (tree decl
)
11332 bool is_tmpl
= TREE_CODE (decl
) == TEMPLATE_DECL
;
11334 decl
= DECL_TEMPLATE_RESULT (decl
);
11336 switch (TREE_CODE (decl
))
11341 case FUNCTION_DECL
:
11342 if (!DECL_SAVED_TREE (decl
))
11346 if (DECL_DECLARED_INLINE_P (decl
))
11349 if (DECL_THIS_STATIC (decl
)
11350 && (header_module_p ()
11351 || (!DECL_LANG_SPECIFIC (decl
) || !DECL_MODULE_PURVIEW_P (decl
))))
11352 /* GM static function. */
11355 if (DECL_TEMPLATE_INFO (decl
))
11357 int use_tpl
= DECL_USE_TEMPLATE (decl
);
11359 // FIXME: Partial specializations have definitions too.
11367 tree type
= TREE_TYPE (decl
);
11368 if (type
== TYPE_MAIN_VARIANT (type
)
11369 && decl
== TYPE_NAME (type
)
11370 && (TREE_CODE (type
) == ENUMERAL_TYPE
11371 ? TYPE_VALUES (type
) : TYPE_FIELDS (type
)))
11377 if (DECL_LANG_SPECIFIC (decl
)
11378 && DECL_TEMPLATE_INFO (decl
)
11379 && DECL_USE_TEMPLATE (decl
) < 2)
11380 return DECL_INITIAL (decl
);
11383 if (!DECL_INITIALIZED_P (decl
))
11386 if (header_module_p ()
11387 || (!DECL_LANG_SPECIFIC (decl
) || !DECL_MODULE_PURVIEW_P (decl
)))
11388 /* GM static variable. */
11391 if (!TREE_CONSTANT (decl
))
11399 if (DECL_INITIAL (decl
))
11409 trees_in::find_duplicate (tree existing
)
11414 return duplicates
->get (existing
);
11417 /* We're starting to read a duplicate DECL. EXISTING is the already
11421 trees_in::register_duplicate (tree decl
, tree existing
)
11424 duplicates
= new duplicate_hash_map (40);
11427 uintptr_t &slot
= duplicates
->get_or_insert (existing
, &existed
);
11428 gcc_checking_assert (!existed
);
11429 slot
= reinterpret_cast<uintptr_t> (decl
);
11432 /* We've read a definition of MAYBE_EXISTING. If not a duplicate,
11433 return MAYBE_EXISTING (into which the definition should be
11434 installed). Otherwise return NULL if already known bad, or the
11435 duplicate we read (for ODR checking, or extracting addtional merge
11439 trees_in::odr_duplicate (tree maybe_existing
, bool has_defn
)
11441 tree res
= NULL_TREE
;
11443 if (uintptr_t *dup
= find_duplicate (maybe_existing
))
11446 res
= reinterpret_cast<tree
> (*dup
);
11449 res
= maybe_existing
;
11451 assert_definition (maybe_existing
, res
&& !has_defn
);
11453 // FIXME: We probably need to return the template, so that the
11454 // template header can be checked?
11455 return res
? STRIP_TEMPLATE (res
) : NULL_TREE
;
11458 /* The following writer functions rely on the current behaviour of
11459 depset::hash::add_dependency making the decl and defn depset nodes
11460 depend on eachother. That way we don't have to worry about seeding
11461 the tree map with named decls that cannot be looked up by name (I.e
11462 template and function parms). We know the decl and definition will
11463 be in the same cluster, which is what we want. */
11466 trees_out::write_function_def (tree decl
)
11468 tree_node (DECL_RESULT (decl
));
11469 tree_node (DECL_INITIAL (decl
));
11470 tree_node (DECL_SAVED_TREE (decl
));
11471 tree_node (DECL_FRIEND_CONTEXT (decl
));
11473 constexpr_fundef
*cexpr
= retrieve_constexpr_fundef (decl
);
11477 if (cexpr
->result
== error_mark_node
)
11478 /* We'll stream the RESULT_DECL naturally during the
11479 serialization. We never need to fish it back again, so
11483 tag
= insert (cexpr
->result
);
11485 if (streaming_p ())
11489 dump (dumper::TREE
)
11490 && dump ("Constexpr:%d result %N", tag
, cexpr
->result
);
11495 for (tree parm
= cexpr
->parms
; parm
; parm
= DECL_CHAIN (parm
), ix
++)
11497 tag
= insert (parm
);
11498 if (streaming_p ())
11499 dump (dumper::TREE
)
11500 && dump ("Constexpr:%d parm:%u %N", tag
, ix
, parm
);
11502 tree_node (cexpr
->body
);
11505 if (streaming_p ())
11507 unsigned flags
= 0;
11509 if (DECL_NOT_REALLY_EXTERN (decl
))
11517 trees_out::mark_function_def (tree
)
11522 trees_in::read_function_def (tree decl
, tree maybe_template
)
11524 dump () && dump ("Reading function definition %N", decl
);
11525 tree result
= tree_node ();
11526 tree initial
= tree_node ();
11527 tree saved
= tree_node ();
11528 tree context
= tree_node ();
11529 constexpr_fundef cexpr
;
11531 tree maybe_dup
= odr_duplicate (maybe_template
, DECL_SAVED_TREE (decl
));
11532 bool installing
= maybe_dup
&& !DECL_SAVED_TREE (decl
);
11535 for (auto parm
= DECL_ARGUMENTS (maybe_dup
); parm
; parm
= DECL_CHAIN (parm
))
11536 DECL_CONTEXT (parm
) = decl
;
11538 if (int wtag
= i ())
11541 cexpr
.result
= error_mark_node
;
11543 cexpr
.result
= copy_decl (result
);
11544 tag
= insert (cexpr
.result
);
11548 dump (dumper::TREE
)
11549 && dump ("Constexpr:%d result %N", tag
, cexpr
.result
);
11551 cexpr
.parms
= NULL_TREE
;
11552 tree
*chain
= &cexpr
.parms
;
11554 for (tree parm
= DECL_ARGUMENTS (maybe_dup
? maybe_dup
: decl
);
11555 parm
; parm
= DECL_CHAIN (parm
), ix
++)
11557 tree p
= copy_decl (parm
);
11559 dump (dumper::TREE
)
11560 && dump ("Constexpr:%d parm:%u %N", tag
, ix
, p
);
11562 chain
= &DECL_CHAIN (p
);
11564 cexpr
.body
= tree_node ();
11568 cexpr
.decl
= NULL_TREE
;
11570 unsigned flags
= u ();
11572 if (get_overrun ())
11577 DECL_NOT_REALLY_EXTERN (decl
) = flags
& 1;
11578 DECL_RESULT (decl
) = result
;
11579 DECL_INITIAL (decl
) = initial
;
11580 DECL_SAVED_TREE (decl
) = saved
;
11582 DECL_ARGUMENTS (decl
) = DECL_ARGUMENTS (maybe_dup
);
11585 SET_DECL_FRIEND_CONTEXT (decl
, context
);
11587 register_constexpr_fundef (cexpr
);
11588 post_process (maybe_template
);
11590 else if (maybe_dup
)
11592 // FIXME:QOI Check matching defn
11598 /* Also for CONCEPT_DECLs. */
11601 trees_out::write_var_def (tree decl
)
11603 tree init
= DECL_INITIAL (decl
);
11607 tree dyn_init
= NULL_TREE
;
11609 if (DECL_NONTRIVIALLY_INITIALIZED_P (decl
))
11611 dyn_init
= value_member (decl
,
11612 CP_DECL_THREAD_LOCAL_P (decl
)
11613 ? tls_aggregates
: static_aggregates
);
11614 gcc_checking_assert (dyn_init
);
11615 /* Mark it so write_inits knows this is needed. */
11616 TREE_LANG_FLAG_0 (dyn_init
) = true;
11617 dyn_init
= TREE_PURPOSE (dyn_init
);
11619 tree_node (dyn_init
);
11624 trees_out::mark_var_def (tree
)
11629 trees_in::read_var_def (tree decl
, tree maybe_template
)
11631 /* Do not mark the virtual table entries as used. */
11632 bool vtable
= TREE_CODE (decl
) == VAR_DECL
&& DECL_VTABLE_OR_VTT_P (decl
);
11634 tree init
= tree_node ();
11635 tree dyn_init
= init
? NULL_TREE
: tree_node ();
11638 if (get_overrun ())
11641 bool initialized
= (VAR_P (decl
) ? bool (DECL_INITIALIZED_P (decl
))
11642 : bool (DECL_INITIAL (decl
)));
11643 tree maybe_dup
= odr_duplicate (maybe_template
, initialized
);
11644 bool installing
= maybe_dup
&& !initialized
;
11647 if (DECL_EXTERNAL (decl
))
11648 DECL_NOT_REALLY_EXTERN (decl
) = true;
11650 DECL_INITIALIZED_P (decl
) = true;
11651 DECL_INITIAL (decl
) = init
;
11654 else if (CP_DECL_THREAD_LOCAL_P (decl
))
11655 tls_aggregates
= tree_cons (dyn_init
, decl
, tls_aggregates
);
11657 static_aggregates
= tree_cons (dyn_init
, decl
, static_aggregates
);
11659 else if (maybe_dup
)
11661 // FIXME:QOI Check matching defn
11667 /* If MEMBER doesn't have an independent life outside the class,
11668 return it (or it's TEMPLATE_DECL). Otherwise NULL. */
11671 member_owned_by_class (tree member
)
11673 gcc_assert (DECL_P (member
));
11675 /* Clones are owned by their origin. */
11676 if (DECL_CLONED_FUNCTION_P (member
))
11679 if (TREE_CODE (member
) == FIELD_DECL
)
11680 /* FIELD_DECLS can have template info in some cases. We always
11681 want the FIELD_DECL though, as there's never a TEMPLATE_DECL
11686 if (tree ti
= node_template_info (member
, use_tpl
))
11688 // FIXME: Don't bail on things that CANNOT have their own
11689 // template header. No, make sure they're in the same cluster.
11693 if (DECL_TEMPLATE_RESULT (TI_TEMPLATE (ti
)) == member
)
11694 member
= TI_TEMPLATE (ti
);
11700 trees_out::write_class_def (tree defn
)
11702 gcc_assert (DECL_P (defn
));
11703 if (streaming_p ())
11704 dump () && dump ("Writing class definition %N", defn
);
11706 tree type
= TREE_TYPE (defn
);
11707 tree_node (TYPE_SIZE (type
));
11708 tree_node (TYPE_SIZE_UNIT (type
));
11709 tree_node (TYPE_VFIELD (type
));
11710 tree_node (TYPE_BINFO (type
));
11712 vec_chained_decls (TYPE_FIELDS (type
));
11714 /* Every class but __as_base has a type-specific. */
11715 gcc_checking_assert (!TYPE_LANG_SPECIFIC (type
) == IS_FAKE_BASE_TYPE (type
));
11717 if (TYPE_LANG_SPECIFIC (type
))
11720 vec
<tree
, va_gc
> *v
= CLASSTYPE_MEMBER_VEC (type
);
11723 gcc_checking_assert (!streaming_p ());
11724 /* Force a class vector. */
11725 v
= set_class_bindings (type
, -1);
11726 gcc_checking_assert (v
);
11729 unsigned len
= v
->length ();
11730 if (streaming_p ())
11732 for (unsigned ix
= 0; ix
!= len
; ix
++)
11735 if (TREE_CODE (m
) == TYPE_DECL
11736 && DECL_ARTIFICIAL (m
)
11737 && TYPE_STUB_DECL (TREE_TYPE (m
)) == m
)
11738 /* This is a using-decl for a type, or an anonymous
11739 struct (maybe with a typedef name). Write the type. */
11744 tree_node (CLASSTYPE_LAMBDA_EXPR (type
));
11746 /* TYPE_CONTAINS_VPTR_P looks at the vbase vector, which the
11747 reader won't know at this point. */
11748 int has_vptr
= TYPE_CONTAINS_VPTR_P (type
);
11750 if (streaming_p ())
11752 unsigned nvbases
= vec_safe_length (CLASSTYPE_VBASECLASSES (type
));
11759 tree_vec (CLASSTYPE_PURE_VIRTUALS (type
));
11760 tree_pair_vec (CLASSTYPE_VCALL_INDICES (type
));
11761 tree_node (CLASSTYPE_KEY_METHOD (type
));
11765 if (TYPE_LANG_SPECIFIC (type
))
11767 tree_node (CLASSTYPE_PRIMARY_BINFO (type
));
11769 tree as_base
= CLASSTYPE_AS_BASE (type
);
11771 as_base
= TYPE_NAME (as_base
);
11772 tree_node (as_base
);
11774 /* Write the vtables. */
11775 tree vtables
= CLASSTYPE_VTABLES (type
);
11776 vec_chained_decls (vtables
);
11777 for (; vtables
; vtables
= TREE_CHAIN (vtables
))
11778 write_definition (vtables
);
11780 /* Write the friend classes. */
11781 tree_list (CLASSTYPE_FRIEND_CLASSES (type
), false);
11783 /* Write the friend functions. */
11784 for (tree friends
= DECL_FRIENDLIST (defn
);
11785 friends
; friends
= TREE_CHAIN (friends
))
11787 /* Name of these friends. */
11788 tree_node (TREE_PURPOSE (friends
));
11789 tree_list (TREE_VALUE (friends
), false);
11791 /* End of friend fns. */
11792 tree_node (NULL_TREE
);
11794 /* Write the decl list. */
11795 tree_list (CLASSTYPE_DECL_LIST (type
), true);
11797 if (TYPE_CONTAINS_VPTR_P (type
))
11799 /* Write the thunks. */
11800 for (tree decls
= TYPE_FIELDS (type
);
11801 decls
; decls
= DECL_CHAIN (decls
))
11802 if (TREE_CODE (decls
) == FUNCTION_DECL
11803 && DECL_VIRTUAL_P (decls
)
11804 && DECL_THUNKS (decls
))
11807 /* Thunks are always unique, so chaining is ok. */
11808 chained_decls (DECL_THUNKS (decls
));
11810 tree_node (NULL_TREE
);
11816 trees_out::mark_class_member (tree member
, bool do_defn
)
11818 gcc_assert (DECL_P (member
));
11820 member
= member_owned_by_class (member
);
11822 mark_declaration (member
, do_defn
&& has_definition (member
));
11826 trees_out::mark_class_def (tree defn
)
11828 gcc_assert (DECL_P (defn
));
11829 tree type
= TREE_TYPE (defn
);
11830 /* Mark the class members that are not type-decls and cannot have
11831 independent definitions. */
11832 for (tree member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
11833 if (TREE_CODE (member
) == FIELD_DECL
11834 || TREE_CODE (member
) == USING_DECL
11835 /* A cloned enum-decl from 'using enum unrelated;' */
11836 || (TREE_CODE (member
) == CONST_DECL
11837 && DECL_CONTEXT (member
) == type
))
11839 mark_class_member (member
);
11840 if (TREE_CODE (member
) == FIELD_DECL
)
11841 if (tree repr
= DECL_BIT_FIELD_REPRESENTATIVE (member
))
11842 mark_declaration (repr
, false);
11845 /* Mark the binfo hierarchy. */
11846 for (tree child
= TYPE_BINFO (type
); child
; child
= TREE_CHAIN (child
))
11847 mark_by_value (child
);
11849 if (TYPE_LANG_SPECIFIC (type
))
11851 for (tree vtable
= CLASSTYPE_VTABLES (type
);
11852 vtable
; vtable
= TREE_CHAIN (vtable
))
11853 mark_declaration (vtable
, true);
11855 if (TYPE_CONTAINS_VPTR_P (type
))
11856 /* Mark the thunks, they belong to the class definition,
11857 /not/ the thunked-to function. */
11858 for (tree decls
= TYPE_FIELDS (type
);
11859 decls
; decls
= DECL_CHAIN (decls
))
11860 if (TREE_CODE (decls
) == FUNCTION_DECL
)
11861 for (tree thunks
= DECL_THUNKS (decls
);
11862 thunks
; thunks
= DECL_CHAIN (thunks
))
11863 mark_declaration (thunks
, false);
11867 /* Nop sorting, needed for resorting the member vec. */
11870 nop (void *, void *)
11875 trees_in::read_class_def (tree defn
, tree maybe_template
)
11877 gcc_assert (DECL_P (defn
));
11878 dump () && dump ("Reading class definition %N", defn
);
11879 tree type
= TREE_TYPE (defn
);
11880 tree size
= tree_node ();
11881 tree size_unit
= tree_node ();
11882 tree vfield
= tree_node ();
11883 tree binfo
= tree_node ();
11884 vec
<tree
, va_gc
> *vbase_vec
= NULL
;
11885 vec
<tree
, va_gc
> *member_vec
= NULL
;
11886 vec
<tree
, va_gc
> *pure_virts
= NULL
;
11887 vec
<tree_pair_s
, va_gc
> *vcall_indices
= NULL
;
11888 tree key_method
= NULL_TREE
;
11889 tree lambda
= NULL_TREE
;
11891 /* Read the fields. */
11892 vec
<tree
, va_heap
> *fields
= vec_chained_decls ();
11894 if (TYPE_LANG_SPECIFIC (type
))
11896 if (unsigned len
= u ())
11898 vec_alloc (member_vec
, len
);
11899 for (unsigned ix
= 0; ix
!= len
; ix
++)
11901 tree m
= tree_node ();
11902 if (get_overrun ())
11905 m
= TYPE_STUB_DECL (m
);
11906 member_vec
->quick_push (m
);
11909 lambda
= tree_node ();
11911 if (!get_overrun ())
11913 unsigned nvbases
= u ();
11916 vec_alloc (vbase_vec
, nvbases
);
11917 for (tree child
= binfo
; child
; child
= TREE_CHAIN (child
))
11918 if (BINFO_VIRTUAL_P (child
))
11919 vbase_vec
->quick_push (child
);
11923 if (!get_overrun ())
11925 int has_vptr
= i ();
11928 pure_virts
= tree_vec ();
11929 vcall_indices
= tree_pair_vec ();
11930 key_method
= tree_node ();
11935 tree maybe_dup
= odr_duplicate (maybe_template
, TYPE_SIZE (type
));
11936 bool installing
= maybe_dup
&& !TYPE_SIZE (type
);
11939 if (DECL_EXTERNAL (defn
) && TYPE_LANG_SPECIFIC (type
))
11941 /* We don't deal with not-really-extern, because, for a
11942 module you want the import to be the interface, and for a
11943 header-unit, you're doing it wrong. */
11944 CLASSTYPE_INTERFACE_UNKNOWN (type
) = false;
11945 CLASSTYPE_INTERFACE_ONLY (type
) = true;
11948 if (maybe_dup
!= defn
)
11950 // FIXME: This is needed on other defns too, almost
11951 // duplicate-decl like? See is_matching_decl too.
11952 /* Copy flags from the duplicate. */
11953 tree type_dup
= TREE_TYPE (maybe_dup
);
11956 TYPE_MODE_RAW (type
) = TYPE_MODE_RAW (type_dup
);
11957 SET_DECL_MODE (defn
, DECL_MODE (maybe_dup
));
11958 TREE_ADDRESSABLE (type
) = TREE_ADDRESSABLE (type_dup
);
11959 DECL_SIZE (defn
) = DECL_SIZE (maybe_dup
);
11960 DECL_SIZE_UNIT (defn
) = DECL_SIZE_UNIT (maybe_dup
);
11961 DECL_ALIGN_RAW (defn
) = DECL_ALIGN_RAW (maybe_dup
);
11962 DECL_WARN_IF_NOT_ALIGN_RAW (defn
)
11963 = DECL_WARN_IF_NOT_ALIGN_RAW (maybe_dup
);
11964 DECL_USER_ALIGN (defn
) = DECL_USER_ALIGN (maybe_dup
);
11967 TYPE_POLYMORPHIC_P (type
) = TYPE_POLYMORPHIC_P (type_dup
);
11968 TYPE_HAS_USER_CONSTRUCTOR (type
)
11969 = TYPE_HAS_USER_CONSTRUCTOR (type_dup
);
11970 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
11971 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type_dup
);
11973 if (auto ls
= TYPE_LANG_SPECIFIC (type_dup
))
11975 if (TYPE_LANG_SPECIFIC (type
))
11977 CLASSTYPE_BEFRIENDING_CLASSES (type_dup
)
11978 = CLASSTYPE_BEFRIENDING_CLASSES (type
);
11979 CLASSTYPE_TYPEINFO_VAR (type_dup
)
11980 = CLASSTYPE_TYPEINFO_VAR (type
);
11982 for (tree v
= type
; v
; v
= TYPE_NEXT_VARIANT (v
))
11983 TYPE_LANG_SPECIFIC (v
) = ls
;
11987 TYPE_SIZE (type
) = size
;
11988 TYPE_SIZE_UNIT (type
) = size_unit
;
11992 tree
*chain
= &TYPE_FIELDS (type
);
11993 unsigned len
= fields
->length ();
11994 for (unsigned ix
= 0; ix
!= len
; ix
++)
11996 tree decl
= (*fields
)[ix
];
12000 /* An anonymous struct with typedef name. */
12001 tree tdef
= (*fields
)[ix
+1];
12002 decl
= TYPE_STUB_DECL (TREE_TYPE (tdef
));
12003 gcc_checking_assert (IDENTIFIER_ANON_P (DECL_NAME (decl
))
12007 gcc_checking_assert (!*chain
== !DECL_CLONED_FUNCTION_P (decl
));
12009 chain
= &DECL_CHAIN (decl
);
12011 if (TREE_CODE (decl
) == USING_DECL
12012 && TREE_CODE (USING_DECL_SCOPE (decl
)) == RECORD_TYPE
)
12014 /* Reconstruct DECL_ACCESS. */
12015 tree decls
= USING_DECL_DECLS (decl
);
12016 tree access
= declared_access (decl
);
12018 for (ovl_iterator
iter (decls
); iter
; ++iter
)
12022 retrofit_lang_decl (d
);
12023 tree list
= DECL_ACCESS (d
);
12025 if (!purpose_member (type
, list
))
12026 DECL_ACCESS (d
) = tree_cons (type
, access
, list
);
12032 TYPE_VFIELD (type
) = vfield
;
12033 TYPE_BINFO (type
) = binfo
;
12035 if (TYPE_LANG_SPECIFIC (type
))
12037 CLASSTYPE_LAMBDA_EXPR (type
) = lambda
;
12039 CLASSTYPE_MEMBER_VEC (type
) = member_vec
;
12040 CLASSTYPE_PURE_VIRTUALS (type
) = pure_virts
;
12041 CLASSTYPE_VCALL_INDICES (type
) = vcall_indices
;
12043 CLASSTYPE_KEY_METHOD (type
) = key_method
;
12045 CLASSTYPE_VBASECLASSES (type
) = vbase_vec
;
12047 /* Resort the member vector. */
12048 resort_type_member_vec (member_vec
, NULL
, nop
, NULL
);
12051 else if (maybe_dup
)
12053 // FIXME:QOI Check matching defn
12056 if (TYPE_LANG_SPECIFIC (type
))
12058 tree primary
= tree_node ();
12059 tree as_base
= tree_node ();
12062 as_base
= TREE_TYPE (as_base
);
12064 /* Read the vtables. */
12065 vec
<tree
, va_heap
> *vtables
= vec_chained_decls ();
12068 unsigned len
= vtables
->length ();
12069 for (unsigned ix
= 0; ix
!= len
; ix
++)
12071 tree vtable
= (*vtables
)[ix
];
12072 read_var_def (vtable
, vtable
);
12076 tree friend_classes
= tree_list (false);
12077 tree friend_functions
= NULL_TREE
;
12078 for (tree
*chain
= &friend_functions
;
12079 tree name
= tree_node (); chain
= &TREE_CHAIN (*chain
))
12081 tree val
= tree_list (false);
12082 *chain
= build_tree_list (name
, val
);
12084 tree decl_list
= tree_list (true);
12088 CLASSTYPE_PRIMARY_BINFO (type
) = primary
;
12089 CLASSTYPE_AS_BASE (type
) = as_base
;
12093 if (!CLASSTYPE_KEY_METHOD (type
)
12094 /* Sneaky user may have defined it inline
12096 || DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (type
)))
12097 vec_safe_push (keyed_classes
, type
);
12098 unsigned len
= vtables
->length ();
12099 tree
*chain
= &CLASSTYPE_VTABLES (type
);
12100 for (unsigned ix
= 0; ix
!= len
; ix
++)
12102 tree vtable
= (*vtables
)[ix
];
12103 gcc_checking_assert (!*chain
);
12105 chain
= &DECL_CHAIN (vtable
);
12108 CLASSTYPE_FRIEND_CLASSES (type
) = friend_classes
;
12109 DECL_FRIENDLIST (defn
) = friend_functions
;
12110 CLASSTYPE_DECL_LIST (type
) = decl_list
;
12112 for (; friend_classes
; friend_classes
= TREE_CHAIN (friend_classes
))
12114 tree f
= TREE_VALUE (friend_classes
);
12118 CLASSTYPE_BEFRIENDING_CLASSES (f
)
12119 = tree_cons (NULL_TREE
, type
,
12120 CLASSTYPE_BEFRIENDING_CLASSES (f
));
12121 dump () && dump ("Class %N befriending %C:%N",
12122 type
, TREE_CODE (f
), f
);
12126 for (; friend_functions
;
12127 friend_functions
= TREE_CHAIN (friend_functions
))
12128 for (tree friend_decls
= TREE_VALUE (friend_functions
);
12129 friend_decls
; friend_decls
= TREE_CHAIN (friend_decls
))
12131 tree f
= TREE_VALUE (friend_decls
);
12133 DECL_BEFRIENDING_CLASSES (f
)
12134 = tree_cons (NULL_TREE
, type
, DECL_BEFRIENDING_CLASSES (f
));
12135 dump () && dump ("Class %N befriending %C:%N",
12136 type
, TREE_CODE (f
), f
);
12140 if (TYPE_CONTAINS_VPTR_P (type
))
12141 /* Read and install the thunks. */
12142 while (tree vfunc
= tree_node ())
12144 tree thunks
= chained_decls ();
12146 SET_DECL_THUNKS (vfunc
, thunks
);
12149 vec_free (vtables
);
12152 /* Propagate to all variants. */
12154 fixup_type_variants (type
);
12156 /* IS_FAKE_BASE_TYPE is inaccurate at this point, because if this is
12157 the fake base, we've not hooked it into the containing class's
12158 data structure yet. Fortunately it has a unique name. */
12160 && DECL_NAME (defn
) != as_base_identifier
12161 && (!CLASSTYPE_TEMPLATE_INFO (type
)
12162 || !uses_template_parms (TI_ARGS (CLASSTYPE_TEMPLATE_INFO (type
)))))
12163 /* Emit debug info. It'd be nice to know if the interface TU
12164 already emitted this. */
12165 rest_of_type_compilation (type
, !LOCAL_CLASS_P (type
));
12169 return !get_overrun ();
12173 trees_out::write_enum_def (tree decl
)
12175 tree type
= TREE_TYPE (decl
);
12177 tree_node (TYPE_VALUES (type
));
12178 tree_node (TYPE_MIN_VALUE (type
));
12179 tree_node (TYPE_MAX_VALUE (type
));
12183 trees_out::mark_enum_def (tree decl
)
12185 tree type
= TREE_TYPE (decl
);
12187 for (tree values
= TYPE_VALUES (type
); values
; values
= TREE_CHAIN (values
))
12189 tree cst
= TREE_VALUE (values
);
12190 mark_by_value (cst
);
12191 /* We must mark the init to avoid circularity in tt_enum_int. */
12192 if (tree init
= DECL_INITIAL (cst
))
12193 if (TREE_CODE (init
) == INTEGER_CST
)
12194 mark_by_value (init
);
12199 trees_in::read_enum_def (tree defn
, tree maybe_template
)
12201 tree type
= TREE_TYPE (defn
);
12202 tree values
= tree_node ();
12203 tree min
= tree_node ();
12204 tree max
= tree_node ();
12206 if (get_overrun ())
12209 tree maybe_dup
= odr_duplicate (maybe_template
, TYPE_VALUES (type
));
12210 bool installing
= maybe_dup
&& !TYPE_VALUES (type
);
12214 TYPE_VALUES (type
) = values
;
12215 TYPE_MIN_VALUE (type
) = min
;
12216 TYPE_MAX_VALUE (type
) = max
;
12218 rest_of_type_compilation (type
, DECL_NAMESPACE_SCOPE_P (defn
));
12220 else if (maybe_dup
)
12222 tree known
= TYPE_VALUES (type
);
12223 for (; known
&& values
;
12224 known
= TREE_CHAIN (known
), values
= TREE_CHAIN (values
))
12226 tree known_decl
= TREE_VALUE (known
);
12227 tree new_decl
= TREE_VALUE (values
);
12229 if (DECL_NAME (known_decl
) != DECL_NAME (new_decl
))
12232 new_decl
= maybe_duplicate (new_decl
);
12234 if (!cp_tree_equal (DECL_INITIAL (known_decl
),
12235 DECL_INITIAL (new_decl
)))
12239 if (known
|| values
)
12242 if (!cp_tree_equal (TYPE_MIN_VALUE (type
), min
)
12243 || !cp_tree_equal (TYPE_MAX_VALUE (type
), max
))
12246 error_at (DECL_SOURCE_LOCATION (maybe_dup
),
12247 "definition of %qD does not match", maybe_dup
);
12248 inform (DECL_SOURCE_LOCATION (defn
),
12249 "existing definition %qD", defn
);
12251 tree known_decl
= NULL_TREE
, new_decl
= NULL_TREE
;
12254 known_decl
= TREE_VALUE (known
);
12256 new_decl
= maybe_duplicate (TREE_VALUE (values
));
12258 if (known_decl
&& new_decl
)
12260 inform (DECL_SOURCE_LOCATION (new_decl
),
12261 "... this enumerator %qD", new_decl
);
12262 inform (DECL_SOURCE_LOCATION (known_decl
),
12263 "enumerator %qD does not match ...", known_decl
);
12265 else if (known_decl
|| new_decl
)
12267 tree extra
= known_decl
? known_decl
: new_decl
;
12268 inform (DECL_SOURCE_LOCATION (extra
),
12269 "additional enumerators beginning with %qD", extra
);
12272 inform (DECL_SOURCE_LOCATION (maybe_dup
),
12273 "enumeration range differs");
12276 unmatched_duplicate (maybe_template
);
12283 /* Write out the body of DECL. See above circularity note. */
12286 trees_out::write_definition (tree decl
)
12288 if (streaming_p ())
12290 assert_definition (decl
);
12292 && dump ("Writing definition %C:%N", TREE_CODE (decl
), decl
);
12295 dump (dumper::DEPEND
)
12296 && dump ("Depending definition %C:%N", TREE_CODE (decl
), decl
);
12299 switch (TREE_CODE (decl
))
12302 gcc_unreachable ();
12304 case TEMPLATE_DECL
:
12305 decl
= DECL_TEMPLATE_RESULT (decl
);
12308 case FUNCTION_DECL
:
12309 write_function_def (decl
);
12314 tree type
= TREE_TYPE (decl
);
12315 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
12316 && TYPE_NAME (type
) == decl
);
12317 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
12318 write_enum_def (decl
);
12320 write_class_def (decl
);
12326 write_var_def (decl
);
12331 /* Mark a declaration for by-value walking. If DO_DEFN is true, mark
12335 trees_out::mark_declaration (tree decl
, bool do_defn
)
12337 mark_by_value (decl
);
12339 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
12340 decl
= DECL_TEMPLATE_RESULT (decl
);
12345 switch (TREE_CODE (decl
))
12348 gcc_unreachable ();
12350 case FUNCTION_DECL
:
12351 mark_function_def (decl
);
12356 tree type
= TREE_TYPE (decl
);
12357 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
12358 && TYPE_NAME (type
) == decl
);
12359 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
12360 mark_enum_def (decl
);
12362 mark_class_def (decl
);
12368 mark_var_def (decl
);
12373 /* Read in the body of DECL. See above circularity note. */
12376 trees_in::read_definition (tree decl
)
12378 dump () && dump ("Reading definition %C %N", TREE_CODE (decl
), decl
);
12380 tree maybe_template
= decl
;
12383 switch (TREE_CODE (decl
))
12388 case TEMPLATE_DECL
:
12389 decl
= DECL_TEMPLATE_RESULT (decl
);
12392 case FUNCTION_DECL
:
12393 return read_function_def (decl
, maybe_template
);
12397 tree type
= TREE_TYPE (decl
);
12398 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
12399 && TYPE_NAME (type
) == decl
);
12400 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
12401 return read_enum_def (decl
, maybe_template
);
12403 return read_class_def (decl
, maybe_template
);
12409 return read_var_def (decl
, maybe_template
);
12415 /* Lookup an maybe insert a slot for depset for KEY. */
12418 depset::hash::entity_slot (tree entity
, bool insert
)
12420 traits::compare_type
key (entity
, NULL
);
12421 depset
**slot
= find_slot_with_hash (key
, traits::hash (key
),
12422 insert
? INSERT
: NO_INSERT
);
12428 depset::hash::binding_slot (tree ctx
, tree name
, bool insert
)
12430 traits::compare_type
key (ctx
, name
);
12431 depset
**slot
= find_slot_with_hash (key
, traits::hash (key
),
12432 insert
? INSERT
: NO_INSERT
);
12438 depset::hash::find_dependency (tree decl
)
12440 depset
**slot
= entity_slot (decl
, false);
12442 return slot
? *slot
: NULL
;
12446 depset::hash::find_binding (tree ctx
, tree name
)
12448 depset
**slot
= binding_slot (ctx
, name
, false);
12450 return slot
? *slot
: NULL
;
12453 /* DECL is a newly discovered dependency. Create the depset, if it
12454 doesn't already exist. Add it to the worklist if so.
12456 DECL will be an OVL_USING_P OVERLOAD, if it's from a binding that's
12459 We do not have to worry about adding the same dependency more than
12460 once. First it's harmless, but secondly the TREE_VISITED marking
12461 prevents us wanting to do it anyway. */
12464 depset::hash::make_dependency (tree decl
, entity_kind ek
)
12466 /* Make sure we're being told consistent information. */
12467 gcc_checking_assert ((ek
== EK_NAMESPACE
)
12468 == (TREE_CODE (decl
) == NAMESPACE_DECL
12469 && !DECL_NAMESPACE_ALIAS (decl
)));
12470 gcc_checking_assert (ek
!= EK_BINDING
&& ek
!= EK_REDIRECT
);
12471 gcc_checking_assert (TREE_CODE (decl
) != FIELD_DECL
12472 && (TREE_CODE (decl
) != USING_DECL
12473 || TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
));
12474 gcc_checking_assert (!is_key_order ());
12475 if (ek
== EK_USING
)
12476 gcc_checking_assert (TREE_CODE (decl
) == OVERLOAD
);
12478 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
12480 /* The template should have copied these from its result decl. */
12481 tree res
= DECL_TEMPLATE_RESULT (decl
);
12483 gcc_checking_assert (DECL_MODULE_EXPORT_P (decl
)
12484 == DECL_MODULE_EXPORT_P (res
));
12485 if (DECL_LANG_SPECIFIC (res
))
12487 gcc_checking_assert (DECL_MODULE_PURVIEW_P (decl
)
12488 == DECL_MODULE_PURVIEW_P (res
));
12489 gcc_checking_assert ((DECL_MODULE_IMPORT_P (decl
)
12490 == DECL_MODULE_IMPORT_P (res
)));
12494 depset
**slot
= entity_slot (decl
, true);
12495 depset
*dep
= *slot
;
12496 bool for_binding
= ek
== EK_FOR_BINDING
;
12500 if (DECL_IMPLICIT_TYPEDEF_P (decl
)
12501 /* ... not an enum, for instance. */
12502 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl
))
12503 && TYPE_LANG_SPECIFIC (TREE_TYPE (decl
))
12504 && CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl
)) == 2)
12506 /* A partial or explicit specialization. Partial
12507 specializations might not be in the hash table, because
12508 there can be multiple differently-constrained variants.
12510 template<typename T> class silly;
12511 template<typename T> requires true class silly {};
12513 We need to find them, insert their TEMPLATE_DECL in the
12514 dep_hash, and then convert the dep we just found into a
12517 tree ti
= TYPE_TEMPLATE_INFO (TREE_TYPE (decl
));
12518 tree tmpl
= TI_TEMPLATE (ti
);
12519 tree partial
= NULL_TREE
;
12520 for (tree spec
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
12521 spec
; spec
= TREE_CHAIN (spec
))
12522 if (DECL_TEMPLATE_RESULT (TREE_VALUE (spec
)) == decl
)
12524 partial
= TREE_VALUE (spec
);
12530 /* Eagerly create an empty redirect. The following
12531 make_dependency call could cause hash reallocation,
12532 and invalidate slot's value. */
12533 depset
*redirect
= make_entity (decl
, EK_REDIRECT
);
12535 /* Redirects are never reached -- always snap to their target. */
12536 redirect
->set_flag_bit
<DB_UNREACHED_BIT
> ();
12540 depset
*tmpl_dep
= make_dependency (partial
, EK_PARTIAL
);
12541 gcc_checking_assert (tmpl_dep
->get_entity_kind () == EK_PARTIAL
);
12543 redirect
->deps
.safe_push (tmpl_dep
);
12549 bool has_def
= ek
!= EK_USING
&& has_definition (decl
);
12550 if (ek
> EK_BINDING
)
12553 /* The only OVERLOADS we should see are USING decls from
12555 *slot
= dep
= make_entity (decl
, ek
, has_def
);
12557 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
12559 if (DECL_ALIAS_TEMPLATE_P (decl
) && DECL_TEMPLATE_INFO (decl
))
12560 dep
->set_flag_bit
<DB_ALIAS_TMPL_INST_BIT
> ();
12561 else if (CHECKING_P
)
12562 /* The template_result should otherwise not be in the
12563 table, or be an empty redirect (created above). */
12564 if (auto *eslot
= entity_slot (DECL_TEMPLATE_RESULT (decl
), false))
12565 gcc_checking_assert ((*eslot
)->get_entity_kind () == EK_REDIRECT
12566 && !(*eslot
)->deps
.length ());
12570 && DECL_LANG_SPECIFIC (decl
)
12571 && DECL_MODULE_IMPORT_P (decl
))
12573 /* Store the module number and index in cluster/section, so
12574 we don't have to look them up again. */
12575 unsigned index
= import_entity_index (decl
);
12576 module_state
*from
= import_entity_module (index
);
12577 /* Remap will be zero for imports from partitions, which we
12578 want to treat as-if declared in this TU. */
12581 dep
->cluster
= index
- from
->entity_lwm
;
12582 dep
->section
= from
->remap
;
12583 dep
->set_flag_bit
<DB_IMPORTED_BIT
> ();
12588 && !dep
->is_import ()
12589 && TREE_CODE (CP_DECL_CONTEXT (decl
)) == NAMESPACE_DECL
12590 && !(TREE_CODE (decl
) == TEMPLATE_DECL
12591 && DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (decl
)))
12593 tree ctx
= CP_DECL_CONTEXT (decl
);
12594 tree not_tmpl
= STRIP_TEMPLATE (decl
);
12596 if (!TREE_PUBLIC (ctx
))
12597 /* Member of internal namespace. */
12598 dep
->set_flag_bit
<DB_IS_INTERNAL_BIT
> ();
12599 else if (VAR_OR_FUNCTION_DECL_P (not_tmpl
)
12600 && DECL_THIS_STATIC (not_tmpl
))
12602 /* An internal decl. This is ok in a GM entity. */
12603 if (!(header_module_p ()
12604 || !DECL_LANG_SPECIFIC (not_tmpl
)
12605 || !DECL_MODULE_PURVIEW_P (not_tmpl
)))
12606 dep
->set_flag_bit
<DB_IS_INTERNAL_BIT
> ();
12611 if (!dep
->is_import ())
12612 worklist
.safe_push (dep
);
12615 dump (dumper::DEPEND
)
12616 && dump ("%s on %s %C:%N found",
12617 ek
== EK_REDIRECT
? "Redirect"
12618 : for_binding
? "Binding" : "Dependency",
12619 dep
->entity_kind_name (), TREE_CODE (decl
), decl
);
12624 /* DEP is a newly discovered dependency. Append it to current's
12628 depset::hash::add_dependency (depset
*dep
)
12630 gcc_checking_assert (current
&& !is_key_order ());
12631 current
->deps
.safe_push (dep
);
12633 if (dep
->is_internal () && !current
->is_internal ())
12634 current
->set_flag_bit
<DB_REFS_INTERNAL_BIT
> ();
12636 if (current
->get_entity_kind () == EK_USING
12637 && DECL_IMPLICIT_TYPEDEF_P (dep
->get_entity ())
12638 && TREE_CODE (TREE_TYPE (dep
->get_entity ())) == ENUMERAL_TYPE
)
12640 /* CURRENT is an unwrapped using-decl and DECL is an enum's
12641 implicit typedef. Is CURRENT a member of the enum? */
12642 tree c_decl
= OVL_FUNCTION (current
->get_entity ());
12644 if (TREE_CODE (c_decl
) == CONST_DECL
12645 && (current
->deps
[0]->get_entity ()
12646 == CP_DECL_CONTEXT (dep
->get_entity ())))
12647 /* Make DECL depend on CURRENT. */
12648 dep
->deps
.safe_push (current
);
12651 if (dep
->is_unreached ())
12653 /* The dependency is reachable now. */
12654 reached_unreached
= true;
12655 dep
->clear_flag_bit
<DB_UNREACHED_BIT
> ();
12656 dump (dumper::DEPEND
)
12657 && dump ("Reaching unreached %s %C:%N", dep
->entity_kind_name (),
12658 TREE_CODE (dep
->get_entity ()), dep
->get_entity ());
12663 depset::hash::add_dependency (tree decl
, entity_kind ek
)
12667 if (is_key_order ())
12669 dep
= find_dependency (decl
);
12672 current
->deps
.safe_push (dep
);
12673 dump (dumper::MERGE
)
12674 && dump ("Key dependency on %s %C:%N found",
12675 dep
->entity_kind_name (), TREE_CODE (decl
), decl
);
12679 /* It's not a mergeable decl, look for it in the original
12681 dep
= chain
->find_dependency (decl
);
12682 gcc_checking_assert (dep
);
12687 dep
= make_dependency (decl
, ek
);
12688 if (dep
->get_entity_kind () != EK_REDIRECT
)
12689 add_dependency (dep
);
12696 depset::hash::add_namespace_context (depset
*dep
, tree ns
)
12698 depset
*ns_dep
= make_dependency (ns
, depset::EK_NAMESPACE
);
12699 dep
->deps
.safe_push (ns_dep
);
12701 /* Mark it as special if imported so we don't walk connect when
12703 if (!dep
->is_binding () && ns_dep
->is_import ())
12704 dep
->set_special ();
12707 struct add_binding_data
12712 depset::hash
*hash
;
12713 bool met_namespace
;
12717 depset::hash::add_binding_entity (tree decl
, WMB_Flags flags
, void *data_
)
12719 auto data
= static_cast <add_binding_data
*> (data_
);
12721 if (TREE_CODE (decl
) != NAMESPACE_DECL
|| DECL_NAMESPACE_ALIAS (decl
))
12725 if (TREE_CODE (inner
) == CONST_DECL
12726 && TREE_CODE (DECL_CONTEXT (inner
)) == ENUMERAL_TYPE
)
12727 inner
= TYPE_NAME (DECL_CONTEXT (inner
));
12728 else if (TREE_CODE (inner
) == TEMPLATE_DECL
)
12729 inner
= DECL_TEMPLATE_RESULT (inner
);
12731 if (!DECL_LANG_SPECIFIC (inner
) || !DECL_MODULE_PURVIEW_P (inner
))
12732 /* Ignore global module fragment entities. */
12735 if (VAR_OR_FUNCTION_DECL_P (inner
)
12736 && DECL_THIS_STATIC (inner
))
12738 if (!header_module_p ())
12739 /* Ignore internal-linkage entitites. */
12743 if ((TREE_CODE (decl
) == VAR_DECL
12744 || TREE_CODE (decl
) == TYPE_DECL
)
12745 && DECL_TINFO_P (decl
))
12746 /* Ignore TINFO things. */
12749 if (!(flags
& WMB_Using
) && CP_DECL_CONTEXT (decl
) != data
->ns
)
12751 /* A using that lost its wrapper or an unscoped enum
12753 flags
= WMB_Flags (flags
| WMB_Using
);
12754 if (DECL_MODULE_EXPORT_P (TREE_CODE (decl
) == CONST_DECL
12755 ? TYPE_NAME (TREE_TYPE (decl
))
12756 : STRIP_TEMPLATE (decl
)))
12757 flags
= WMB_Flags (flags
| WMB_Export
);
12760 if (!data
->binding
)
12761 /* No binding to check. */;
12762 else if (flags
& WMB_Using
)
12764 /* Look in the binding to see if we already have this
12766 for (unsigned ix
= data
->binding
->deps
.length (); --ix
;)
12768 depset
*d
= data
->binding
->deps
[ix
];
12769 if (d
->get_entity_kind () == EK_USING
12770 && OVL_FUNCTION (d
->get_entity ()) == decl
)
12772 if (!(flags
& WMB_Hidden
))
12773 d
->clear_hidden_binding ();
12774 if (flags
& WMB_Export
)
12775 OVL_EXPORT_P (d
->get_entity ()) = true;
12780 else if (flags
& WMB_Dups
)
12782 /* Look in the binding to see if we already have this decl. */
12783 for (unsigned ix
= data
->binding
->deps
.length (); --ix
;)
12785 depset
*d
= data
->binding
->deps
[ix
];
12786 if (d
->get_entity () == decl
)
12788 if (!(flags
& WMB_Hidden
))
12789 d
->clear_hidden_binding ();
12795 /* We're adding something. */
12796 if (!data
->binding
)
12798 data
->binding
= make_binding (data
->ns
, DECL_NAME (decl
));
12799 data
->hash
->add_namespace_context (data
->binding
, data
->ns
);
12801 depset
**slot
= data
->hash
->binding_slot (data
->ns
,
12802 DECL_NAME (decl
), true);
12803 gcc_checking_assert (!*slot
);
12804 *slot
= data
->binding
;
12807 if (flags
& WMB_Using
)
12809 decl
= ovl_make (decl
, NULL_TREE
);
12810 if (flags
& WMB_Export
)
12811 OVL_EXPORT_P (decl
) = true;
12814 depset
*dep
= data
->hash
->make_dependency
12815 (decl
, flags
& WMB_Using
? EK_USING
: EK_FOR_BINDING
);
12816 if (flags
& WMB_Hidden
)
12817 dep
->set_hidden_binding ();
12818 data
->binding
->deps
.safe_push (dep
);
12819 /* Binding and contents are mutually dependent. */
12820 dep
->deps
.safe_push (data
->binding
);
12824 else if (DECL_NAME (decl
) && !data
->met_namespace
)
12826 /* Namespace, walk exactly once. */
12827 gcc_checking_assert (TREE_PUBLIC (decl
));
12828 data
->met_namespace
= true;
12829 if (data
->hash
->add_namespace_entities (decl
, data
->partitions
)
12830 || DECL_MODULE_EXPORT_P (decl
))
12832 data
->hash
->make_dependency (decl
, depset::EK_NAMESPACE
);
12840 /* Recursively find all the namespace bindings of NS.
12841 Add a depset for every binding that contains an export or
12842 module-linkage entity. Add a defining depset for every such decl
12843 that we need to write a definition. Such defining depsets depend
12844 on the binding depset. Returns true if we contain something
12845 explicitly exported. */
12848 depset::hash::add_namespace_entities (tree ns
, bitmap partitions
)
12850 dump () && dump ("Looking for writables in %N", ns
);
12853 unsigned count
= 0;
12854 add_binding_data data
;
12856 data
.partitions
= partitions
;
12859 hash_table
<named_decl_hash
>::iterator end
12860 (DECL_NAMESPACE_BINDINGS (ns
)->end ());
12861 for (hash_table
<named_decl_hash
>::iterator iter
12862 (DECL_NAMESPACE_BINDINGS (ns
)->begin ()); iter
!= end
; ++iter
)
12864 data
.binding
= nullptr;
12865 data
.met_namespace
= false;
12866 if (walk_module_binding (*iter
, partitions
, add_binding_entity
, &data
))
12871 dump () && dump ("Found %u entries", count
);
12878 depset::hash::add_partial_entities (vec
<tree
, va_gc
> *partial_classes
)
12880 for (unsigned ix
= 0; ix
!= partial_classes
->length (); ix
++)
12882 tree inner
= (*partial_classes
)[ix
];
12884 depset
*dep
= make_dependency (inner
, depset::EK_DECL
);
12886 if (dep
->get_entity_kind () == depset::EK_REDIRECT
)
12887 /* We should have recorded the template as a partial
12889 gcc_checking_assert (dep
->deps
[0]->get_entity_kind ()
12890 == depset::EK_PARTIAL
);
12892 /* It was an explicit specialization, not a partial one. */
12893 gcc_checking_assert (dep
->get_entity_kind ()
12894 == depset::EK_SPECIALIZATION
);
12898 /* Add the members of imported classes that we defined in this TU.
12899 This will also include lazily created implicit member function
12900 declarations. (All others will be definitions.) */
12903 depset::hash::add_class_entities (vec
<tree
, va_gc
> *class_members
)
12905 for (unsigned ix
= 0; ix
!= class_members
->length (); ix
++)
12907 tree defn
= (*class_members
)[ix
];
12908 depset
*dep
= make_dependency (defn
, EK_INNER_DECL
);
12910 if (dep
->get_entity_kind () == EK_REDIRECT
)
12911 dep
= dep
->deps
[0];
12913 /* Only non-instantiations need marking as members. */
12914 if (dep
->get_entity_kind () == EK_DECL
)
12915 dep
->set_flag_bit
<DB_IS_MEMBER_BIT
> ();
12919 /* We add the partial & explicit specializations, and the explicit
12923 specialization_add (bool decl_p
, spec_entry
*entry
, void *data_
)
12925 vec
<spec_entry
*> *data
= reinterpret_cast <vec
<spec_entry
*> *> (data_
);
12929 /* We exclusively use decls to locate things. Make sure there's
12930 no mismatch between the two specialization tables we keep.
12931 pt.c optimizes instantiation lookup using a complicated
12932 heuristic. We don't attempt to replicate that algorithm, but
12933 observe its behaviour and reproduce it upon read back. */
12935 gcc_checking_assert (DECL_ALIAS_TEMPLATE_P (entry
->tmpl
)
12936 || TREE_CODE (entry
->spec
) == ENUMERAL_TYPE
12937 || DECL_CLASS_TEMPLATE_P (entry
->tmpl
));
12939 /* Only alias templates can appear in both tables (and
12940 if they're in the type table they must also be in the decl table). */
12941 gcc_checking_assert
12942 (!match_mergeable_specialization (true, entry
, false)
12943 == (decl_p
|| !DECL_ALIAS_TEMPLATE_P (entry
->tmpl
)));
12945 else if (VAR_OR_FUNCTION_DECL_P (entry
->spec
))
12946 gcc_checking_assert (!DECL_LOCAL_DECL_P (entry
->spec
));
12948 data
->safe_push (entry
);
12951 /* Arbitrary stable comparison. */
12954 specialization_cmp (const void *a_
, const void *b_
)
12956 const spec_entry
*ea
= *reinterpret_cast<const spec_entry
*const *> (a_
);
12957 const spec_entry
*eb
= *reinterpret_cast<const spec_entry
*const *> (b_
);
12971 /* This can happen with friend specializations. Just order by
12972 entry address. See note in depset_cmp. */
12973 return ea
< eb
? -1 : +1;
12975 return DECL_UID (a
) < DECL_UID (b
) ? -1 : +1;
12978 /* We add all kinds of specialializations. Implicit specializations
12979 should only streamed and walked if they are reachable from
12980 elsewhere. Hence the UNREACHED flag. This is making the
12981 assumption that it is cheaper to reinstantiate them on demand
12982 elsewhere, rather than stream them in when we instantiate their
12983 general template. Also, if we do stream them, we can only do that
12984 if they are not internal (which they can become if they themselves
12985 touch an internal entity?). */
12988 depset::hash::add_specializations (bool decl_p
)
12990 vec
<spec_entry
*> data
;
12992 walk_specializations (decl_p
, specialization_add
, &data
);
12993 data
.qsort (specialization_cmp
);
12994 while (data
.length ())
12996 spec_entry
*entry
= data
.pop ();
12997 tree spec
= entry
->spec
;
12999 bool is_alias
= false;
13000 bool is_friend
= false;
13002 if (decl_p
&& DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (entry
->tmpl
))
13003 /* A friend of a template. This is keyed to the
13007 if (!decl_p
&& DECL_ALIAS_TEMPLATE_P (entry
->tmpl
))
13009 spec
= TYPE_NAME (spec
);
13013 if (decl_p
|| is_alias
)
13015 if (tree ti
= DECL_TEMPLATE_INFO (spec
))
13017 tree tmpl
= TI_TEMPLATE (ti
);
13019 use_tpl
= DECL_USE_TEMPLATE (spec
);
13020 if (spec
== DECL_TEMPLATE_RESULT (tmpl
))
13023 gcc_checking_assert (DECL_USE_TEMPLATE (spec
) == use_tpl
);
13025 else if (is_friend
)
13027 if (TI_TEMPLATE (ti
) != entry
->tmpl
13028 || !template_args_equal (TI_ARGS (ti
), entry
->tmpl
))
13029 goto template_friend
;
13035 gcc_checking_assert (is_friend
);
13036 /* This is a friend of a template class, but not the one
13037 that generated entry->spec itself (i.e. it's an
13038 equivalent clone). We do not need to record
13045 if (TREE_CODE (spec
) == ENUMERAL_TYPE
)
13047 tree ctx
= DECL_CONTEXT (TYPE_NAME (spec
));
13050 use_tpl
= CLASSTYPE_USE_TEMPLATE (ctx
);
13052 use_tpl
= DECL_USE_TEMPLATE (ctx
);
13055 use_tpl
= CLASSTYPE_USE_TEMPLATE (spec
);
13057 tree ti
= TYPE_TEMPLATE_INFO (spec
);
13058 tree tmpl
= TI_TEMPLATE (ti
);
13060 spec
= TYPE_NAME (spec
);
13061 if (spec
== DECL_TEMPLATE_RESULT (tmpl
))
13064 use_tpl
= DECL_USE_TEMPLATE (spec
);
13068 bool needs_reaching
= false;
13070 /* Implicit instantiations only walked if we reach them. */
13071 needs_reaching
= true;
13072 else if (!DECL_LANG_SPECIFIC (spec
)
13073 || !DECL_MODULE_PURVIEW_P (spec
))
13074 /* Likewise, GMF explicit or partial specializations. */
13075 needs_reaching
= true;
13077 #if false && CHECKING_P
13078 /* The instantiation isn't always on
13079 DECL_TEMPLATE_INSTANTIATIONS, */
13080 // FIXME: we probably need to remember this information?
13081 /* Verify the specialization is on the
13082 DECL_TEMPLATE_INSTANTIATIONS of the template. */
13083 for (tree cons
= DECL_TEMPLATE_INSTANTIATIONS (entry
->tmpl
);
13084 cons
; cons
= TREE_CHAIN (cons
))
13085 if (TREE_VALUE (cons
) == entry
->spec
)
13087 gcc_assert (entry
->args
== TREE_PURPOSE (cons
));
13090 gcc_unreachable ();
13094 depset
*dep
= make_dependency (spec
, depset::EK_SPECIALIZATION
);
13095 if (dep
->is_special ())
13097 /* An already located specialization, this must be the TYPE
13098 corresponding to an alias_decl we found in the decl
13100 spec_entry
*other
= reinterpret_cast <spec_entry
*> (dep
->deps
[0]);
13101 gcc_checking_assert (!decl_p
&& is_alias
&& !dep
->is_type_spec ());
13102 gcc_checking_assert (other
->tmpl
== entry
->tmpl
13103 && template_args_equal (other
->args
, entry
->args
)
13104 && TREE_TYPE (other
->spec
) == entry
->spec
);
13105 dep
->set_flag_bit
<DB_ALIAS_SPEC_BIT
> ();
13109 gcc_checking_assert (decl_p
|| !is_alias
);
13110 if (dep
->get_entity_kind () == depset::EK_REDIRECT
)
13111 dep
= dep
->deps
[0];
13112 else if (dep
->get_entity_kind () == depset::EK_SPECIALIZATION
)
13114 dep
->set_special ();
13115 dep
->deps
.safe_push (reinterpret_cast<depset
*> (entry
));
13117 dep
->set_flag_bit
<DB_TYPE_SPEC_BIT
> ();
13120 if (needs_reaching
)
13121 dep
->set_flag_bit
<DB_UNREACHED_BIT
> ();
13123 dep
->set_flag_bit
<DB_FRIEND_SPEC_BIT
> ();
13129 /* Add a depset into the mergeable hash. */
13132 depset::hash::add_mergeable (depset
*mergeable
)
13134 gcc_checking_assert (is_key_order ());
13135 entity_kind ek
= mergeable
->get_entity_kind ();
13136 tree decl
= mergeable
->get_entity ();
13137 gcc_checking_assert (ek
< EK_DIRECT_HWM
);
13139 depset
**slot
= entity_slot (decl
, true);
13140 gcc_checking_assert (!*slot
);
13141 depset
*dep
= make_entity (decl
, ek
);
13144 worklist
.safe_push (dep
);
13146 /* So we can locate the mergeable depset this depset refers to,
13147 mark the first dep. */
13148 dep
->set_special ();
13149 dep
->deps
.safe_push (mergeable
);
13152 /* Iteratively find dependencies. During the walk we may find more
13153 entries on the same binding that need walking. */
13156 depset::hash::find_dependencies ()
13158 trees_out
walker (NULL
, NULL
, *this);
13159 vec
<depset
*> unreached
;
13160 unreached
.create (worklist
.length ());
13164 reached_unreached
= false;
13165 while (worklist
.length ())
13167 depset
*item
= worklist
.pop ();
13169 gcc_checking_assert (!item
->is_binding ());
13170 if (item
->is_unreached ())
13171 unreached
.quick_push (item
);
13175 tree decl
= current
->get_entity ();
13176 dump (is_key_order () ? dumper::MERGE
: dumper::DEPEND
)
13177 && dump ("Dependencies of %s %C:%N",
13178 is_key_order () ? "key-order"
13179 : current
->entity_kind_name (), TREE_CODE (decl
), decl
);
13182 if (current
->get_entity_kind () == EK_USING
)
13183 walker
.tree_node (OVL_FUNCTION (decl
));
13184 else if (TREE_VISITED (decl
))
13185 /* A global tree. */;
13186 else if (TREE_CODE (decl
) == NAMESPACE_DECL
13187 && !DECL_NAMESPACE_ALIAS (decl
))
13188 add_namespace_context (current
, CP_DECL_CONTEXT (decl
));
13191 walker
.mark_declaration (decl
, current
->has_defn ());
13193 // FIXME: Perhaps p1815 makes this redundant? Or at
13194 // least simplifies it. Voldemort types are only
13195 // ever emissable when containing (inline) function
13196 // definition is emitted?
13197 /* Turn the Sneakoscope on when depending the decl. */
13198 sneakoscope
= true;
13199 walker
.decl_value (decl
, current
);
13200 sneakoscope
= false;
13201 if (current
->has_defn ())
13202 walker
.write_definition (decl
);
13206 if (!walker
.is_key_order ()
13207 && TREE_CODE (decl
) == TEMPLATE_DECL
13208 && !DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (decl
))
13209 /* Mark all the explicit & partial specializations as
13211 for (tree cons
= DECL_TEMPLATE_INSTANTIATIONS (decl
);
13212 cons
; cons
= TREE_CHAIN (cons
))
13214 tree spec
= TREE_VALUE (cons
);
13216 spec
= TYPE_NAME (spec
);
13218 node_template_info (spec
, use_tpl
);
13221 depset
*spec_dep
= find_dependency (spec
);
13222 if (spec_dep
->get_entity_kind () == EK_REDIRECT
)
13223 spec_dep
= spec_dep
->deps
[0];
13224 if (spec_dep
->is_unreached ())
13226 reached_unreached
= true;
13227 spec_dep
->clear_flag_bit
<DB_UNREACHED_BIT
> ();
13228 dump (dumper::DEPEND
)
13229 && dump ("Reaching unreached specialization"
13230 " %C:%N", TREE_CODE (spec
), spec
);
13240 if (!reached_unreached
)
13243 /* It's possible the we reached the unreached before we
13244 processed it in the above loop, so we'll be doing this an
13245 extra time. However, to avoid that we have to do some
13246 bit shuffling that also involves a scan of the list.
13247 Swings & roundabouts I guess. */
13248 std::swap (worklist
, unreached
);
13251 unreached
.release ();
13254 /* Compare two entries of a single binding. TYPE_DECL before
13255 non-exported before exported. */
13258 binding_cmp (const void *a_
, const void *b_
)
13260 depset
*a
= *(depset
*const *)a_
;
13261 depset
*b
= *(depset
*const *)b_
;
13263 tree a_ent
= a
->get_entity ();
13264 tree b_ent
= b
->get_entity ();
13265 gcc_checking_assert (a_ent
!= b_ent
13266 && !a
->is_binding ()
13267 && !b
->is_binding ());
13269 /* Implicit typedefs come first. */
13270 bool a_implicit
= DECL_IMPLICIT_TYPEDEF_P (a_ent
);
13271 bool b_implicit
= DECL_IMPLICIT_TYPEDEF_P (b_ent
);
13272 if (a_implicit
|| b_implicit
)
13274 /* A binding with two implicit type decls? That's unpossible! */
13275 gcc_checking_assert (!(a_implicit
&& b_implicit
));
13276 return a_implicit
? -1 : +1; /* Implicit first. */
13279 /* Hidden before non-hidden. */
13280 bool a_hidden
= a
->is_hidden ();
13281 bool b_hidden
= b
->is_hidden ();
13282 if (a_hidden
!= b_hidden
)
13283 return a_hidden
? -1 : +1;
13285 bool a_using
= a
->get_entity_kind () == depset::EK_USING
;
13289 a_export
= OVL_EXPORT_P (a_ent
);
13290 a_ent
= OVL_FUNCTION (a_ent
);
13293 a_export
= DECL_MODULE_EXPORT_P (TREE_CODE (a_ent
) == CONST_DECL
13294 ? TYPE_NAME (TREE_TYPE (a_ent
))
13295 : STRIP_TEMPLATE (a_ent
));
13297 bool b_using
= b
->get_entity_kind () == depset::EK_USING
;
13301 b_export
= OVL_EXPORT_P (b_ent
);
13302 b_ent
= OVL_FUNCTION (b_ent
);
13305 b_export
= DECL_MODULE_EXPORT_P (TREE_CODE (b_ent
) == CONST_DECL
13306 ? TYPE_NAME (TREE_TYPE (b_ent
))
13307 : STRIP_TEMPLATE (b_ent
));
13309 /* Non-exports before exports. */
13310 if (a_export
!= b_export
)
13311 return a_export
? +1 : -1;
13313 /* At this point we don't care, but want a stable sort. */
13315 if (a_using
!= b_using
)
13317 return a_using
? -1 : +1;
13319 return DECL_UID (a_ent
) < DECL_UID (b_ent
) ? -1 : +1;
13322 /* Sort the bindings, issue errors about bad internal refs. */
13325 depset::hash::finalize_dependencies ()
13328 depset::hash::iterator
end (this->end ());
13329 for (depset::hash::iterator
iter (begin ()); iter
!= end
; ++iter
)
13331 depset
*dep
= *iter
;
13332 if (dep
->is_binding ())
13334 /* Keep the containing namespace dep first. */
13335 gcc_checking_assert (dep
->deps
.length () > 1
13336 && (dep
->deps
[0]->get_entity_kind ()
13338 && (dep
->deps
[0]->get_entity ()
13339 == dep
->get_entity ()));
13340 if (dep
->deps
.length () > 2)
13341 gcc_qsort (&dep
->deps
[1], dep
->deps
.length () - 1,
13342 sizeof (dep
->deps
[1]), binding_cmp
);
13344 else if (dep
->refs_internal ())
13346 for (unsigned ix
= dep
->deps
.length (); ix
--;)
13348 depset
*rdep
= dep
->deps
[ix
];
13349 if (rdep
->is_internal ())
13351 // FIXME:QOI Better location information? We're
13352 // losing, so it doesn't matter about efficiency
13353 tree decl
= dep
->get_entity ();
13354 error_at (DECL_SOURCE_LOCATION (decl
),
13355 "%q#D references internal linkage entity %q#D",
13356 decl
, rdep
->get_entity ());
13367 /* Core of TARJAN's algorithm to find Strongly Connected Components
13368 within a graph. See https://en.wikipedia.org/wiki/
13369 Tarjan%27s_strongly_connected_components_algorithm for details.
13371 We use depset::section as lowlink. Completed nodes have
13372 depset::cluster containing the cluster number, with the top
13375 A useful property is that the output vector is a reverse
13376 topological sort of the resulting DAG. In our case that means
13377 dependent SCCs are found before their dependers. We make use of
13381 depset::tarjan::connect (depset
*v
)
13383 gcc_checking_assert (v
->is_binding ()
13384 || !(v
->is_unreached () || v
->is_import ()));
13386 v
->cluster
= v
->section
= ++index
;
13387 stack
.safe_push (v
);
13389 /* Walk all our dependencies, ignore a first marked slot */
13390 for (unsigned ix
= v
->is_special (); ix
!= v
->deps
.length (); ix
++)
13392 depset
*dep
= v
->deps
[ix
];
13394 if (dep
->is_binding () || !dep
->is_import ())
13396 unsigned lwm
= dep
->cluster
;
13400 /* A new node. Connect it. */
13402 lwm
= dep
->section
;
13405 if (dep
->section
&& v
->section
> lwm
)
13410 if (v
->section
== v
->cluster
)
13412 /* Root of a new SCC. Push all the members onto the result list. */
13413 unsigned num
= v
->cluster
;
13420 result
.quick_push (p
);
13426 /* Compare two depsets. The specific ordering is unimportant, we're
13427 just trying to get consistency. */
13430 depset_cmp (const void *a_
, const void *b_
)
13432 depset
*a
= *(depset
*const *)a_
;
13433 depset
*b
= *(depset
*const *)b_
;
13435 depset::entity_kind a_kind
= a
->get_entity_kind ();
13436 depset::entity_kind b_kind
= b
->get_entity_kind ();
13438 if (a_kind
!= b_kind
)
13439 /* Different entity kinds, order by that. */
13440 return a_kind
< b_kind
? -1 : +1;
13442 tree a_decl
= a
->get_entity ();
13443 tree b_decl
= b
->get_entity ();
13444 if (a_kind
== depset::EK_USING
)
13446 /* If one is a using, the other must be too. */
13447 a_decl
= OVL_FUNCTION (a_decl
);
13448 b_decl
= OVL_FUNCTION (b_decl
);
13451 if (a_decl
!= b_decl
)
13452 /* Different entities, order by their UID. */
13453 return DECL_UID (a_decl
) < DECL_UID (b_decl
) ? -1 : +1;
13455 if (a_kind
== depset::EK_BINDING
)
13457 /* Both are bindings. Order by identifier hash. */
13458 gcc_checking_assert (a
->get_name () != b
->get_name ());
13459 return (IDENTIFIER_HASH_VALUE (a
->get_name ())
13460 < IDENTIFIER_HASH_VALUE (b
->get_name ())
13464 /* They are the same decl. This can happen with two using decls
13465 pointing to the same target. The best we can aim for is
13466 consistently telling qsort how to order them. Hopefully we'll
13467 never have to debug a case that depends on this. Oh, who am I
13468 kidding? Good luck. */
13469 gcc_checking_assert (a_kind
== depset::EK_USING
);
13471 /* Order by depset address. Not the best, but it is something. */
13472 return a
< b
? -1 : +1;
13475 /* Sort the clusters in SCC such that those that depend on one another
13476 are placed later. */
13478 // FIXME: I am not convinced this is needed and, if needed,
13479 // sufficient. We emit the decls in this order but that emission
13480 // could walk into later decls (from the body of the decl, or default
13481 // arg-like things). Why doesn't that walk do the right thing? And
13482 // if it DTRT why do we need to sort here -- won't things naturally
13483 // work? I think part of the issue is that when we're going to refer
13484 // to an entity by name, and that entity is in the same cluster as us,
13485 // we need to actually walk that entity, if we've not already walked
13488 sort_cluster (depset::hash
*original
, depset
*scc
[], unsigned size
)
13490 depset::hash
table (size
, original
);
13494 /* Place bindings last, usings before that. It's not strictly
13495 necessary, but it does make things neater. Says Mr OCD. */
13496 unsigned bind_lwm
= size
;
13497 unsigned use_lwm
= size
;
13498 for (unsigned ix
= 0; ix
!= use_lwm
;)
13500 depset
*dep
= scc
[ix
];
13501 switch (dep
->get_entity_kind ())
13503 case depset::EK_BINDING
:
13504 /* Move to end. No increment. Notice this could be moving
13505 a using decl, which we'll then move again. */
13506 if (--bind_lwm
!= ix
)
13508 scc
[ix
] = scc
[bind_lwm
];
13509 scc
[bind_lwm
] = dep
;
13511 if (use_lwm
> bind_lwm
)
13516 /* We must have copied a using, so move it too. */
13518 gcc_checking_assert (dep
->get_entity_kind () == depset::EK_USING
);
13521 case depset::EK_USING
:
13522 if (--use_lwm
!= ix
)
13524 scc
[ix
] = scc
[use_lwm
];
13525 scc
[use_lwm
] = dep
;
13529 case depset::EK_DECL
:
13530 case depset::EK_SPECIALIZATION
:
13531 case depset::EK_PARTIAL
:
13532 table
.add_mergeable (dep
);
13537 gcc_unreachable ();
13541 gcc_checking_assert (use_lwm
<= bind_lwm
);
13542 dump (dumper::MERGE
) && dump ("Ordering %u/%u depsets", use_lwm
, size
);
13544 table
.find_dependencies ();
13546 vec
<depset
*> order
= table
.connect ();
13547 gcc_checking_assert (order
.length () == use_lwm
);
13549 /* Now rewrite entries [0,lwm), in the dependency order we
13550 discovered. Usually each entity is in its own cluster. Rarely,
13551 we can get multi-entity clusters, in which case all but one must
13552 only be reached from within the cluster. This happens for
13555 template<typename T>
13556 auto Foo (const T &arg) -> TPL<decltype (arg)>;
13558 The instantiation of TPL will be in the specialization table, and
13559 refer to Foo via arg. But we can only get to that specialization
13560 from Foo's declaration, so we only need to treat Foo as mergable
13561 (We'll do structural comparison of TPL<decltype (arg)>).
13563 Finding the single cluster entry dep is very tricky and
13564 expensive. Let's just not do that. It's harmless in this case
13567 unsigned cluster
= ~0u;
13568 for (unsigned ix
= 0; ix
!= order
.length (); ix
++)
13570 gcc_checking_assert (order
[ix
]->is_special ());
13571 depset
*dep
= order
[ix
]->deps
[0];
13573 dump (dumper::MERGE
)
13574 && dump ("Mergeable %u is %N%s", ix
, dep
->get_entity (),
13575 order
[ix
]->cluster
== cluster
? " (tight)" : "");
13576 cluster
= order
[ix
]->cluster
;
13579 gcc_checking_assert (pos
== use_lwm
);
13582 dump (dumper::MERGE
) && dump ("Ordered %u keys", pos
);
13586 /* Reduce graph to SCCS clusters. SCCS will be populated with the
13587 depsets in dependency order. Each depset's CLUSTER field contains
13588 its cluster number. Each SCC has a unique cluster number, and are
13589 contiguous in SCCS. Cluster numbers are otherwise arbitrary. */
13592 depset::hash::connect ()
13594 tarjan
connector (size ());
13595 vec
<depset
*> deps
;
13596 deps
.create (size ());
13597 iterator
end (this->end ());
13598 for (iterator
iter (begin ()); iter
!= end
; ++iter
)
13600 depset
*item
= *iter
;
13602 entity_kind kind
= item
->get_entity_kind ();
13603 if (kind
== EK_BINDING
13604 || !(kind
== EK_REDIRECT
13605 || item
->is_unreached ()
13606 || item
->is_import ()))
13607 deps
.quick_push (item
);
13610 /* Iteration over the hash table is an unspecified ordering. While
13611 that has advantages, it causes 2 problems. Firstly repeatable
13612 builds are tricky. Secondly creating testcases that check
13613 dependencies are correct by making sure a bad ordering would
13614 happen if that was wrong. */
13615 deps
.qsort (depset_cmp
);
13617 while (deps
.length ())
13619 depset
*v
= deps
.pop ();
13620 dump (dumper::CLUSTER
) &&
13622 ? dump ("Connecting binding %P", v
->get_entity (), v
->get_name ())
13623 : dump ("Connecting %s %s %C:%N",
13624 is_key_order () ? "key-order"
13625 : !v
->has_defn () ? "declaration" : "definition",
13626 v
->entity_kind_name (), TREE_CODE (v
->get_entity ()),
13627 v
->get_entity ()));
13629 connector
.connect (v
);
13633 return connector
.result
;
13636 /* Load the entities referred to by this pendset. */
13639 pendset_lazy_load (pendset
*pendings
, bool specializations_p
)
13643 for (unsigned ix
= 0; ok
&& ix
!= pendings
->num
; ix
++)
13645 unsigned index
= pendings
->values
[ix
];
13646 if (index
& ~(~0u >> 1))
13648 /* An indirection. */
13649 if (specializations_p
)
13651 pendset
*other
= pending_table
->get (index
, true);
13652 if (!pendset_lazy_load (other
, specializations_p
))
13657 module_state
*module
= import_entity_module (index
);
13658 binding_slot
*slot
= &(*entity_ary
)[index
];
13659 if (!slot
->is_lazy ())
13660 dump () && dump ("Specialiation %M[%u] already loaded",
13661 module
, index
- module
->entity_lwm
);
13662 else if (!module
->lazy_load (index
- module
->entity_lwm
, slot
))
13667 /* We own set, so delete it now. */
13673 /* Initialize location spans. */
13676 loc_spans::init (const line_maps
*lmaps
, const line_map_ordinary
*map
)
13678 gcc_checking_assert (!init_p ());
13679 spans
= new vec
<span
> ();
13680 spans
->reserve (20);
13683 interval
.ordinary
.first
= 0;
13684 interval
.macro
.second
= MAX_LOCATION_T
+ 1;
13685 interval
.ordinary_delta
= interval
.macro_delta
= 0;
13687 /* A span for reserved fixed locs. */
13688 interval
.ordinary
.second
13689 = MAP_START_LOCATION (LINEMAPS_ORDINARY_MAP_AT (line_table
, 0));
13690 interval
.macro
.first
= interval
.macro
.second
;
13691 dump (dumper::LOCATION
)
13692 && dump ("Fixed span %u ordinary:[%u,%u) macro:[%u,%u)", spans
->length (),
13693 interval
.ordinary
.first
, interval
.ordinary
.second
,
13694 interval
.macro
.first
, interval
.macro
.second
);
13695 spans
->quick_push (interval
);
13697 /* A span for command line & forced headers. */
13698 interval
.ordinary
.first
= interval
.ordinary
.second
;
13699 interval
.macro
.second
= interval
.macro
.first
;
13702 interval
.ordinary
.second
= map
->start_location
;
13703 interval
.macro
.first
= LINEMAPS_MACRO_LOWEST_LOCATION (lmaps
);
13705 dump (dumper::LOCATION
)
13706 && dump ("Pre span %u ordinary:[%u,%u) macro:[%u,%u)", spans
->length (),
13707 interval
.ordinary
.first
, interval
.ordinary
.second
,
13708 interval
.macro
.first
, interval
.macro
.second
);
13709 spans
->quick_push (interval
);
13711 /* Start an interval for the main file. */
13712 interval
.ordinary
.first
= interval
.ordinary
.second
;
13713 interval
.macro
.second
= interval
.macro
.first
;
13714 dump (dumper::LOCATION
)
13715 && dump ("Main span %u ordinary:[%u,*) macro:[*,%u)", spans
->length (),
13716 interval
.ordinary
.first
, interval
.macro
.second
);
13717 spans
->quick_push (interval
);
13720 /* Reopen the span, if we want the about-to-be-inserted set of maps to
13721 be propagated in our own location table. I.e. we are the primary
13722 interface and we're importing a partition. */
13725 loc_spans::maybe_propagate (module_state
*import
,
13726 location_t loc
= UNKNOWN_LOCATION
)
13728 bool opened
= (module_interface_p () && !module_partition_p ()
13729 && import
->is_partition ());
13735 /* Open a new linemap interval. The just-created ordinary map is the
13736 first map of the interval. */
13739 loc_spans::open (location_t hwm
= UNKNOWN_LOCATION
)
13741 if (hwm
== UNKNOWN_LOCATION
)
13742 hwm
= MAP_START_LOCATION (LINEMAPS_LAST_ORDINARY_MAP (line_table
));
13745 interval
.ordinary
.first
= interval
.ordinary
.second
= hwm
;
13746 interval
.macro
.first
= interval
.macro
.second
13747 = LINEMAPS_MACRO_LOWEST_LOCATION (line_table
);
13748 interval
.ordinary_delta
= interval
.macro_delta
= 0;
13749 dump (dumper::LOCATION
)
13750 && dump ("Opening span %u ordinary:[%u,... macro:...,%u)",
13751 spans
->length (), interval
.ordinary
.first
,
13752 interval
.macro
.second
);
13753 spans
->safe_push (interval
);
13756 /* Close out the current linemap interval. The last maps are within
13760 loc_spans::close ()
13762 span
&interval
= spans
->last ();
13764 interval
.ordinary
.second
13765 = ((line_table
->highest_location
+ (1 << line_table
->default_range_bits
))
13766 & ~((1u << line_table
->default_range_bits
) - 1));
13767 interval
.macro
.first
= LINEMAPS_MACRO_LOWEST_LOCATION (line_table
);
13768 dump (dumper::LOCATION
)
13769 && dump ("Closing span %u ordinary:[%u,%u) macro:[%u,%u)",
13770 spans
->length () - 1,
13771 interval
.ordinary
.first
,interval
.ordinary
.second
,
13772 interval
.macro
.first
, interval
.macro
.second
);
13775 /* Given an ordinary location LOC, return the lmap_interval it resides
13776 in. NULL if it is not in an interval. */
13778 const loc_spans::span
*
13779 loc_spans::ordinary (location_t loc
)
13781 unsigned len
= spans
->length ();
13785 unsigned half
= len
/ 2;
13786 const span
&probe
= (*spans
)[pos
+ half
];
13787 if (loc
< probe
.ordinary
.first
)
13789 else if (loc
< probe
.ordinary
.second
)
13794 len
= len
- (half
+ 1);
13800 /* Likewise, given a macro location LOC, return the lmap interval it
13803 const loc_spans::span
*
13804 loc_spans::macro (location_t loc
)
13806 unsigned len
= spans
->length ();
13810 unsigned half
= len
/ 2;
13811 const span
&probe
= (*spans
)[pos
+ half
];
13812 if (loc
>= probe
.macro
.second
)
13814 else if (loc
>= probe
.macro
.first
)
13819 len
= len
- (half
+ 1);
13825 /* Return the ordinary location closest to FROM. */
13828 ordinary_loc_of (line_maps
*lmaps
, location_t from
)
13830 while (!IS_ORDINARY_LOC (from
))
13832 if (IS_ADHOC_LOC (from
))
13833 from
= get_location_from_adhoc_loc (lmaps
, from
);
13834 if (IS_MACRO_LOC (from
))
13836 /* Find the ordinary location nearest FROM. */
13837 const line_map
*map
= linemap_lookup (lmaps
, from
);
13838 const line_map_macro
*mac_map
= linemap_check_macro (map
);
13839 from
= MACRO_MAP_EXPANSION_POINT_LOCATION (mac_map
);
13845 static module_state
**
13846 get_module_slot (tree name
, module_state
*parent
, bool partition
, bool insert
)
13848 module_state_hash::compare_type
ct (name
, uintptr_t (parent
) | partition
);
13849 hashval_t hv
= module_state_hash::hash (ct
);
13851 return modules_hash
->find_slot_with_hash (ct
, hv
, insert
? INSERT
: NO_INSERT
);
13854 static module_state
*
13855 get_primary (module_state
*parent
)
13857 while (parent
->is_partition ())
13858 parent
= parent
->parent
;
13861 // Implementation unit has null name
13862 parent
= parent
->parent
;
13867 /* Find or create module NAME & PARENT in the hash table. */
13870 get_module (tree name
, module_state
*parent
, bool partition
)
13875 parent
= get_primary ((*modules
)[0]);
13877 if (!parent
->is_partition () && !parent
->flatname
)
13878 parent
->set_flatname ();
13881 module_state
**slot
= get_module_slot (name
, parent
, partition
, true);
13882 module_state
*state
= *slot
;
13885 state
= (new (ggc_alloc
<module_state
> ())
13886 module_state (name
, parent
, partition
));
13892 /* Process string name PTR into a module_state. */
13894 static module_state
*
13895 get_module (const char *ptr
)
13897 if (ptr
[0] == '.' ? IS_DIR_SEPARATOR (ptr
[1]) : IS_ABSOLUTE_PATH (ptr
))
13898 /* A header name. */
13899 return get_module (build_string (strlen (ptr
), ptr
));
13901 bool partition
= false;
13902 module_state
*mod
= NULL
;
13904 for (const char *probe
= ptr
;; probe
++)
13905 if (!*probe
|| *probe
== '.' || *probe
== ':')
13910 mod
= get_module (get_identifier_with_length (ptr
, probe
- ptr
),
13923 else if (!(ISALPHA (*probe
) || *probe
== '_'
13924 || (probe
!= ptr
&& ISDIGIT (*probe
))))
13930 /* Create a new mapper connecting to OPTION. */
13933 make_mapper (location_t loc
)
13935 timevar_start (TV_MODULE_MAPPER
);
13936 const char *option
= module_mapper_name
;
13938 option
= getenv ("CXX_MODULE_MAPPER");
13940 mapper
= module_client::open_module_client
13941 (loc
, option
, &set_cmi_repo
,
13942 (save_decoded_options
[0].opt_index
== OPT_SPECIAL_program_name
)
13943 && save_decoded_options
[0].arg
!= progname
13944 ? save_decoded_options
[0].arg
: nullptr);
13946 timevar_stop (TV_MODULE_MAPPER
);
13951 /* If THIS is the current purview, issue an import error and return false. */
13954 module_state::check_not_purview (location_t from
)
13956 module_state
*imp
= (*modules
)[0];
13957 if (imp
&& !imp
->name
)
13961 /* Cannot import the current module. */
13962 error_at (from
, "cannot import module in its own purview");
13963 inform (loc
, "module %qs declared here", get_flatname ());
13969 /* Module name substitutions. */
13970 static vec
<module_state
*,va_heap
> substs
;
13973 module_state::mangle (bool include_partition
)
13976 mangle_module_substitution (subst
- 1);
13980 parent
->mangle (include_partition
);
13981 if (include_partition
|| !is_partition ())
13984 // Partitions are significant for global initializer functions
13985 if (is_partition () && !parent
->is_partition ())
13987 substs
.safe_push (this);
13988 subst
= substs
.length ();
13989 mangle_identifier (p
, name
);
13995 mangle_module (int mod
, bool include_partition
)
13997 module_state
*imp
= (*modules
)[mod
];
14000 /* Set when importing the primary module interface. */
14003 imp
->mangle (include_partition
);
14006 /* Clean up substitutions. */
14008 mangle_module_fini ()
14010 while (substs
.length ())
14011 substs
.pop ()->subst
= 0;
14014 /* Announce WHAT about the module. */
14017 module_state::announce (const char *what
) const
14021 fprintf (stderr
, " %s:%s", what
, get_flatname ());
14026 /* A human-readable README section. The contents of this section to
14027 not contribute to the CRC, so the contents can change per
14028 compilation. That allows us to embed CWD, hostname, build time and
14029 what not. It is a STRTAB that may be extracted with:
14030 readelf -pgnu.c++.README $(module).gcm */
14033 module_state::write_readme (elf_out
*to
, cpp_reader
*reader
,
14034 const char *dialect
, unsigned extensions
)
14036 bytes_out
readme (to
);
14038 readme
.begin (false);
14040 readme
.printf ("GNU C++ %smodule%s%s",
14041 is_header () ? "header " : is_partition () ? "" : "primary ",
14043 : is_interface () ? " interface" : " implementation",
14044 is_partition () ? " partition" : "");
14046 /* Compiler's version. */
14047 readme
.printf ("compiler: %s", version_string
);
14049 /* Module format version. */
14051 version2string (MODULE_VERSION
, string
);
14052 readme
.printf ("version: %s", string
);
14054 /* Module information. */
14055 readme
.printf ("module: %s", get_flatname ());
14056 readme
.printf ("source: %s", main_input_filename
);
14057 readme
.printf ("dialect: %s", dialect
);
14059 readme
.printf ("extensions: %s",
14060 extensions
& SE_OPENMP
? "-fopenmp" : "");
14062 /* The following fields could be expected to change between
14063 otherwise identical compilations. Consider a distributed build
14064 system. We should have a way of overriding that. */
14065 if (char *cwd
= getcwd (NULL
, 0))
14067 readme
.printf ("cwd: %s", cwd
);
14070 readme
.printf ("repository: %s", cmi_repo
? cmi_repo
: ".");
14074 if (!gethostname (hostname
, sizeof (hostname
)))
14075 readme
.printf ("host: %s", hostname
);
14079 /* This of course will change! */
14081 auto kind
= cpp_get_date (reader
, &stampy
);
14082 if (kind
!= CPP_time_kind::UNKNOWN
)
14086 time
= gmtime (&stampy
);
14087 readme
.print_time ("build", time
, "UTC");
14089 if (kind
== CPP_time_kind::DYNAMIC
)
14091 time
= localtime (&stampy
);
14092 readme
.print_time ("local", time
,
14093 #if defined (__USE_MISC) || defined (__USE_BSD) /* Is there a better way? */
14103 /* Its direct imports. */
14104 for (unsigned ix
= 1; ix
< modules
->length (); ix
++)
14106 module_state
*state
= (*modules
)[ix
];
14108 if (state
->is_direct ())
14109 readme
.printf ("%s: %s %s", state
->exported_p
? "export" : "import",
14110 state
->get_flatname (), state
->filename
);
14113 readme
.end (to
, to
->name (MOD_SNAME_PFX
".README"), NULL
);
14116 /* Sort environment var names in reverse order. */
14119 env_var_cmp (const void *a_
, const void *b_
)
14121 const unsigned char *a
= *(const unsigned char *const *)a_
;
14122 const unsigned char *b
= *(const unsigned char *const *)b_
;
14124 for (unsigned ix
= 0; ; ix
++)
14126 bool a_end
= !a
[ix
] || a
[ix
] == '=';
14127 if (a
[ix
] == b
[ix
])
14134 bool b_end
= !b
[ix
] || b
[ix
] == '=';
14136 if (!a_end
&& !b_end
)
14137 return a
[ix
] < b
[ix
] ? +1 : -1;
14138 if (a_end
&& b_end
)
14140 return a_end
? +1 : -1;
14147 /* Write the environment. It is a STRTAB that may be extracted with:
14148 readelf -pgnu.c++.ENV $(module).gcm */
14151 module_state::write_env (elf_out
*to
)
14153 vec
<const char *> vars
;
14156 extern char **environ
;
14157 while (const char *var
= environ
[vars
.length ()])
14158 vars
.safe_push (var
);
14159 vars
.qsort (env_var_cmp
);
14161 bytes_out
env (to
);
14163 while (vars
.length ())
14164 env
.printf ("%s", vars
.pop ());
14165 env
.end (to
, to
->name (MOD_SNAME_PFX
".ENV"), NULL
);
14170 /* Write the direct or indirect imports.
14176 s:filename (direct)
14177 u:exported (direct)
14182 module_state::write_imports (bytes_out
&sec
, bool direct
)
14184 unsigned count
= 0;
14186 for (unsigned ix
= 1; ix
< modules
->length (); ix
++)
14188 module_state
*imp
= (*modules
)[ix
];
14190 if (imp
->remap
&& imp
->is_direct () == direct
)
14194 gcc_assert (!direct
|| count
);
14197 for (unsigned ix
= 1; ix
< modules
->length (); ix
++)
14199 module_state
*imp
= (*modules
)[ix
];
14201 if (imp
->remap
&& imp
->is_direct () == direct
)
14203 dump () && dump ("Writing %simport:%u->%u %M (crc=%x)",
14204 !direct
? "indirect "
14205 : imp
->exported_p
? "exported " : "",
14206 ix
, imp
->remap
, imp
, imp
->crc
);
14207 sec
.u (imp
->remap
);
14208 sec
.str (imp
->get_flatname ());
14209 sec
.u32 (imp
->crc
);
14212 write_location (sec
, imp
->imported_from ());
14213 sec
.str (imp
->filename
);
14214 int exportedness
= 0;
14215 if (imp
->exported_p
)
14217 else if (!imp
->is_purview_direct ())
14219 sec
.i (exportedness
);
14225 /* READER, LMAPS != NULL == direct imports,
14226 == NUL == indirect imports. */
14229 module_state::read_imports (bytes_in
&sec
, cpp_reader
*reader
, line_maps
*lmaps
)
14231 unsigned count
= sec
.u ();
14232 unsigned loaded
= 0;
14236 unsigned ix
= sec
.u ();
14237 if (ix
>= slurp
->remap
->length () || !ix
|| (*slurp
->remap
)[ix
])
14239 sec
.set_overrun ();
14243 const char *name
= sec
.str (NULL
);
14244 module_state
*imp
= get_module (name
);
14245 unsigned crc
= sec
.u32 ();
14246 int exportedness
= 0;
14248 /* If the import is a partition, it must be the same primary
14249 module as this TU. */
14250 if (imp
&& imp
->is_partition () &&
14251 (!named_module_p ()
14252 || (get_primary ((*modules
)[0]) != get_primary (imp
))))
14256 sec
.set_overrun ();
14257 if (sec
.get_overrun ())
14262 /* A direct import, maybe load it. */
14263 location_t floc
= read_location (sec
);
14264 const char *fname
= sec
.str (NULL
);
14265 exportedness
= sec
.i ();
14267 if (sec
.get_overrun ())
14270 if (!imp
->check_not_purview (loc
))
14273 if (imp
->loadedness
== ML_NONE
)
14277 if (!imp
->get_flatname ())
14278 imp
->set_flatname ();
14280 unsigned n
= dump
.push (imp
);
14282 if (!imp
->filename
&& fname
)
14283 imp
->filename
= xstrdup (fname
);
14285 if (imp
->is_partition ())
14286 dump () && dump ("Importing elided partition %M", imp
);
14288 if (!imp
->do_import (reader
, false))
14295 if (is_partition ())
14297 if (!imp
->is_direct ())
14298 imp
->directness
= MD_PARTITION_DIRECT
;
14299 if (exportedness
> 0)
14300 imp
->exported_p
= true;
14305 /* An indirect import, find it, it should already be here. */
14306 if (imp
->loadedness
== ML_NONE
)
14308 error_at (loc
, "indirect import %qs is not already loaded", name
);
14313 if (imp
->crc
!= crc
)
14314 error_at (loc
, "import %qs has CRC mismatch", imp
->get_flatname ());
14316 (*slurp
->remap
)[ix
] = (imp
->mod
<< 1) | (lmaps
!= NULL
);
14318 if (lmaps
&& exportedness
>= 0)
14319 set_import (imp
, bool (exportedness
));
14320 dump () && dump ("Found %simport:%u %M->%u", !lmaps
? "indirect "
14321 : exportedness
> 0 ? "exported "
14322 : exportedness
< 0 ? "gmf" : "", ix
, imp
,
14330 /* Write the import table to MOD_SNAME_PFX.imp. */
14333 module_state::write_imports (elf_out
*to
, unsigned *crc_ptr
)
14335 dump () && dump ("Writing imports");
14338 bytes_out
sec (to
);
14341 write_imports (sec
, true);
14342 write_imports (sec
, false);
14344 sec
.end (to
, to
->name (MOD_SNAME_PFX
".imp"), crc_ptr
);
14349 module_state::read_imports (cpp_reader
*reader
, line_maps
*lmaps
)
14353 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".imp"))
14356 dump () && dump ("Reading %u imports", slurp
->remap
->length () - 1);
14359 /* Read the imports. */
14360 unsigned direct
= read_imports (sec
, reader
, lmaps
);
14361 unsigned indirect
= read_imports (sec
, NULL
, NULL
);
14362 if (direct
+ indirect
+ 1 != slurp
->remap
->length ())
14363 from ()->set_error (elf::E_BAD_IMPORT
);
14366 if (!sec
.end (from ()))
14371 /* We're the primary module interface, but have partitions. Document
14372 them so that non-partition module implementation units know which
14373 have already been loaded. */
14376 module_state::write_partitions (elf_out
*to
, unsigned count
, unsigned *crc_ptr
)
14378 dump () && dump ("Writing %u elided partitions", count
);
14381 bytes_out
sec (to
);
14384 for (unsigned ix
= 1; ix
!= modules
->length (); ix
++)
14386 module_state
*imp
= (*modules
)[ix
];
14387 if (imp
->is_partition ())
14389 dump () && dump ("Writing elided partition %M (crc=%x)",
14391 sec
.str (imp
->get_flatname ());
14392 sec
.u32 (imp
->crc
);
14393 write_location (sec
, imp
->is_direct ()
14394 ? imp
->imported_from () : UNKNOWN_LOCATION
);
14395 sec
.str (imp
->filename
);
14399 sec
.end (to
, to
->name (MOD_SNAME_PFX
".prt"), crc_ptr
);
14404 module_state::read_partitions (unsigned count
)
14407 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".prt"))
14410 dump () && dump ("Reading %u elided partitions", count
);
14415 const char *name
= sec
.str (NULL
);
14416 unsigned crc
= sec
.u32 ();
14417 location_t floc
= read_location (sec
);
14418 const char *fname
= sec
.str (NULL
);
14420 if (sec
.get_overrun ())
14423 dump () && dump ("Reading elided partition %s (crc=%x)", name
, crc
);
14425 module_state
*imp
= get_module (name
);
14426 if (!imp
|| !imp
->is_partition () || imp
->is_rooted ()
14427 || get_primary (imp
) != this)
14429 sec
.set_overrun ();
14433 /* Attach the partition without loading it. We'll have to load
14434 for real if it's indirectly imported. */
14437 if (!imp
->filename
&& fname
[0])
14438 imp
->filename
= xstrdup (fname
);
14442 if (!sec
.end (from ()))
14447 /* Counter indices. */
14448 enum module_state_counts
14461 /* Data for config reading and writing. */
14462 struct module_state_config
{
14463 const char *dialect_str
;
14464 unsigned num_imports
;
14465 unsigned num_partitions
;
14466 unsigned ordinary_locs
;
14467 unsigned macro_locs
;
14468 unsigned ordinary_loc_align
;
14471 module_state_config ()
14472 :dialect_str (get_dialect ()),
14473 num_imports (0), num_partitions (0),
14474 ordinary_locs (0), macro_locs (0), ordinary_loc_align (0)
14478 static void release ()
14480 XDELETEVEC (dialect
);
14485 static const char *get_dialect ();
14486 static char *dialect
;
14489 char *module_state_config::dialect
;
14491 /* Generate a string of the significant compilation options.
14492 Generally assume the user knows what they're doing, in the same way
14493 that object files can be mixed. */
14496 module_state_config::get_dialect ()
14499 dialect
= concat (get_cxx_dialect_name (cxx_dialect
),
14500 /* C++ implies these, only show if disabled. */
14501 flag_exceptions
? "" : "/no-exceptions",
14502 flag_rtti
? "" : "/no-rtti",
14503 flag_new_inheriting_ctors
? "" : "/old-inheriting-ctors",
14504 /* C++ 20 implies concepts. */
14505 cxx_dialect
< cxx20
&& flag_concepts
? "/concepts" : "",
14506 flag_coroutines
? "/coroutines" : "",
14507 flag_module_implicit_inline
? "/implicit-inline" : "",
14513 /* Contents of a cluster. */
14515 ct_decl
, /* A decl. */
14516 ct_defn
, /* A definition. */
14517 ct_bind
, /* A binding. */
14521 /* Binding modifiers. */
14524 cbf_export
= 0x1, /* An exported decl. */
14525 cbf_hidden
= 0x2, /* A hidden (friend) decl. */
14526 cbf_using
= 0x4, /* A using decl. */
14527 cbf_wrapped
= 0x8, /* ... that is wrapped. */
14530 /* Write the cluster of depsets in SCC[0-SIZE). */
14533 module_state::write_cluster (elf_out
*to
, depset
*scc
[], unsigned size
,
14534 depset::hash
&table
, unsigned *counts
,
14537 dump () && dump ("Writing section:%u %u depsets", table
.section
, size
);
14540 trees_out
sec (to
, this, table
, table
.section
);
14543 /* Determine entity numbers, mark for writing. */
14544 dump (dumper::CLUSTER
) && dump ("Cluster members:") && (dump
.indent (), true);
14545 for (unsigned ix
= 0; ix
!= size
; ix
++)
14547 depset
*b
= scc
[ix
];
14549 switch (b
->get_entity_kind ())
14552 gcc_unreachable ();
14554 case depset::EK_BINDING
:
14555 dump (dumper::CLUSTER
)
14556 && dump ("[%u]=%s %P", ix
, b
->entity_kind_name (),
14557 b
->get_entity (), b
->get_name ());
14558 for (unsigned jx
= b
->deps
.length (); jx
--;)
14560 depset
*dep
= b
->deps
[jx
];
14562 gcc_checking_assert (dep
->get_entity_kind () == depset::EK_USING
14563 || TREE_VISITED (dep
->get_entity ()));
14565 gcc_checking_assert (dep
->get_entity_kind ()
14566 == depset::EK_NAMESPACE
14567 && dep
->get_entity () == b
->get_entity ());
14571 case depset::EK_DECL
:
14572 if (b
->is_member ())
14574 case depset::EK_SPECIALIZATION
: /* Yowzer! */
14575 case depset::EK_PARTIAL
: /* Hey, let's do it again! */
14576 counts
[MSC_pendings
]++;
14578 b
->cluster
= counts
[MSC_entities
]++;
14579 sec
.mark_declaration (b
->get_entity (), b
->has_defn ());
14582 case depset::EK_USING
:
14583 gcc_checking_assert (!b
->is_import ()
14584 && !b
->is_unreached ());
14585 dump (dumper::CLUSTER
)
14586 && dump ("[%u]=%s %s %N", ix
, b
->entity_kind_name (),
14587 b
->has_defn () ? "definition" : "declaration",
14592 dump (dumper::CLUSTER
) && (dump
.outdent (), true);
14594 /* Ensure every imported decl is referenced before we start
14595 streaming. This ensures that we never encounter the
14596 situation where this cluster instantiates some implicit
14597 member that importing some other decl causes to be
14599 sec
.set_importing (+1);
14600 for (unsigned ix
= 0; ix
!= size
; ix
++)
14602 depset
*b
= scc
[ix
];
14603 for (unsigned jx
= (b
->get_entity_kind () == depset::EK_BINDING
14604 || b
->is_special ()) ? 1 : 0;
14605 jx
!= b
->deps
.length (); jx
++)
14607 depset
*dep
= b
->deps
[jx
];
14609 if (!dep
->is_binding ()
14610 && dep
->is_import () && !TREE_VISITED (dep
->get_entity ()))
14612 tree import
= dep
->get_entity ();
14614 sec
.tree_node (import
);
14615 dump (dumper::CLUSTER
) && dump ("Seeded import %N", import
);
14619 sec
.tree_node (NULL_TREE
);
14620 /* We're done importing now. */
14621 sec
.set_importing (-1);
14623 /* Write non-definitions. */
14624 for (unsigned ix
= 0; ix
!= size
; ix
++)
14626 depset
*b
= scc
[ix
];
14627 tree decl
= b
->get_entity ();
14628 switch (b
->get_entity_kind ())
14631 gcc_unreachable ();
14634 case depset::EK_BINDING
:
14636 gcc_assert (TREE_CODE (decl
) == NAMESPACE_DECL
);
14637 dump () && dump ("Depset:%u binding %C:%P", ix
, TREE_CODE (decl
),
14638 decl
, b
->get_name ());
14640 sec
.tree_node (decl
);
14641 sec
.tree_node (b
->get_name ());
14643 /* Write in reverse order, so reading will see the exports
14644 first, thus building the overload chain will be
14646 for (unsigned jx
= b
->deps
.length (); --jx
;)
14648 depset
*dep
= b
->deps
[jx
];
14649 tree bound
= dep
->get_entity ();
14650 unsigned flags
= 0;
14651 if (dep
->get_entity_kind () == depset::EK_USING
)
14654 bound
= OVL_FUNCTION (bound
);
14655 if (!(TREE_CODE (bound
) == CONST_DECL
14656 && UNSCOPED_ENUM_P (TREE_TYPE (bound
))
14657 && decl
== TYPE_NAME (TREE_TYPE (bound
))))
14659 /* An unscope enumerator in its enumeration's
14660 scope is not a using. */
14661 flags
|= cbf_using
;
14662 if (OVL_USING_P (ovl
))
14663 flags
|= cbf_wrapped
;
14665 if (OVL_EXPORT_P (ovl
))
14666 flags
|= cbf_export
;
14670 /* An implicit typedef must be at one. */
14671 gcc_assert (!DECL_IMPLICIT_TYPEDEF_P (bound
) || jx
== 1);
14672 if (dep
->is_hidden ())
14673 flags
|= cbf_hidden
;
14674 else if (DECL_MODULE_EXPORT_P (STRIP_TEMPLATE (bound
)))
14675 flags
|= cbf_export
;
14678 gcc_checking_assert (DECL_P (bound
));
14681 sec
.tree_node (bound
);
14684 /* Terminate the list. */
14689 case depset::EK_USING
:
14690 dump () && dump ("Depset:%u %s %C:%N", ix
, b
->entity_kind_name (),
14691 TREE_CODE (decl
), decl
);
14694 case depset::EK_SPECIALIZATION
:
14695 case depset::EK_PARTIAL
:
14696 case depset::EK_DECL
:
14697 dump () && dump ("Depset:%u %s entity:%u %C:%N", ix
,
14698 b
->entity_kind_name (), b
->cluster
,
14699 TREE_CODE (decl
), decl
);
14702 sec
.tree_node (decl
);
14704 dump () && dump ("Wrote declaration entity:%u %C:%N",
14705 b
->cluster
, TREE_CODE (decl
), decl
);
14710 depset
*namer
= NULL
;
14712 /* Write out definitions */
14713 for (unsigned ix
= 0; ix
!= size
; ix
++)
14715 depset
*b
= scc
[ix
];
14716 tree decl
= b
->get_entity ();
14717 switch (b
->get_entity_kind ())
14722 case depset::EK_SPECIALIZATION
:
14723 case depset::EK_PARTIAL
:
14724 case depset::EK_DECL
:
14728 if (b
->has_defn ())
14731 sec
.tree_node (decl
);
14732 dump () && dump ("Writing definition %N", decl
);
14733 sec
.write_definition (decl
);
14735 if (!namer
->has_defn ())
14742 /* We don't find the section by name. Use depset's decl's name for
14743 human friendliness. */
14745 tree naming_decl
= NULL_TREE
;
14748 naming_decl
= namer
->get_entity ();
14749 if (namer
->get_entity_kind () == depset::EK_USING
)
14750 /* This unfortunately names the section from the target of the
14751 using decl. But the name is only a guide, so Do Not Care. */
14752 naming_decl
= OVL_FUNCTION (naming_decl
);
14753 if (DECL_IMPLICIT_TYPEDEF_P (naming_decl
))
14754 /* Lose any anonymousness. */
14755 naming_decl
= TYPE_NAME (TREE_TYPE (naming_decl
));
14756 name
= to
->qualified_name (naming_decl
, namer
->has_defn ());
14759 unsigned bytes
= sec
.pos
;
14760 unsigned snum
= sec
.end (to
, name
, crc_ptr
);
14762 for (unsigned ix
= size
; ix
--;)
14763 gcc_checking_assert (scc
[ix
]->section
== snum
);
14766 dump () && dump ("Wrote section:%u named-by:%N", table
.section
, naming_decl
);
14771 /* Read a cluster from section SNUM. */
14774 module_state::read_cluster (unsigned snum
)
14776 trees_in
sec (this);
14778 if (!sec
.begin (loc
, from (), snum
))
14781 dump () && dump ("Reading section:%u", snum
);
14784 /* We care about structural equality. */
14785 comparing_specializations
++;
14787 /* First seed the imports. */
14788 while (tree import
= sec
.tree_node ())
14789 dump (dumper::CLUSTER
) && dump ("Seeded import %N", import
);
14791 while (!sec
.get_overrun () && sec
.more_p ())
14793 unsigned ct
= sec
.u ();
14797 sec
.set_overrun ();
14801 /* A set of namespace bindings. */
14803 tree ns
= sec
.tree_node ();
14804 tree name
= sec
.tree_node ();
14805 tree decls
= NULL_TREE
;
14806 tree visible
= NULL_TREE
;
14807 tree type
= NULL_TREE
;
14808 bool dedup
= false;
14810 /* We rely on the bindings being in the reverse order of
14811 the resulting overload set. */
14814 int flags
= sec
.i ();
14818 if ((flags
& cbf_hidden
)
14819 && (flags
& (cbf_using
| cbf_export
)))
14820 sec
.set_overrun ();
14822 tree decl
= sec
.tree_node ();
14823 if (sec
.get_overrun ())
14826 if (decls
&& TREE_CODE (decl
) == TYPE_DECL
)
14829 if (type
|| !DECL_IMPLICIT_TYPEDEF_P (decl
))
14830 sec
.set_overrun ();
14836 || (flags
& (cbf_hidden
| cbf_wrapped
))
14837 || DECL_FUNCTION_TEMPLATE_P (decl
))
14839 decls
= ovl_make (decl
, decls
);
14840 if (flags
& cbf_using
)
14843 OVL_USING_P (decls
) = true;
14844 if (flags
& cbf_export
)
14845 OVL_EXPORT_P (decls
) = true;
14848 if (flags
& cbf_hidden
)
14849 OVL_HIDDEN_P (decls
) = true;
14851 OVL_DEDUP_P (decls
) = true;
14856 if (flags
& cbf_export
14857 || (!(flags
& cbf_hidden
)
14858 && (is_module () || is_partition ())))
14864 sec
.set_overrun ();
14866 if (sec
.get_overrun ())
14869 dump () && dump ("Binding of %P", ns
, name
);
14870 if (!set_module_binding (ns
, name
, mod
,
14872 : is_module () || is_partition () ? 1
14874 decls
, type
, visible
))
14875 sec
.set_overrun ();
14878 && CP_DECL_CONTEXT (type
) == ns
14879 && !sec
.is_duplicate (type
))
14880 add_module_decl (ns
, name
, type
);
14882 for (ovl_iterator
iter (decls
); iter
; ++iter
)
14883 if (!iter
.using_p ())
14886 if (CP_DECL_CONTEXT (decl
) == ns
14887 && !sec
.is_duplicate (decl
))
14888 add_module_decl (ns
, name
, decl
);
14896 tree decl
= sec
.tree_node ();
14897 dump () && dump ("Read declaration of %N", decl
);
14903 tree decl
= sec
.tree_node ();
14904 dump () && dump ("Reading definition of %N", decl
);
14905 sec
.read_definition (decl
);
14911 /* When lazy loading is in effect, we can be in the middle of
14912 parsing or instantiating a function. Save it away.
14913 push_function_context does too much work. */
14914 tree old_cfd
= current_function_decl
;
14915 struct function
*old_cfun
= cfun
;
14916 while (tree decl
= sec
.post_process ())
14918 bool abstract
= false;
14919 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
14922 decl
= DECL_TEMPLATE_RESULT (decl
);
14925 current_function_decl
= decl
;
14926 allocate_struct_function (decl
, abstract
);
14927 cfun
->language
= ggc_cleared_alloc
<language_function
> ();
14928 cfun
->language
->base
.x_stmt_tree
.stmts_are_full_exprs_p
= 1;
14932 else if (DECL_ABSTRACT_P (decl
))
14934 bool cloned
= maybe_clone_body (decl
);
14936 from ()->set_error ();
14940 bool aggr
= aggregate_value_p (DECL_RESULT (decl
), decl
);
14941 #ifdef PCC_STATIC_STRUCT_RETURN
14942 cfun
->returns_pcc_struct
= aggr
;
14944 cfun
->returns_struct
= aggr
;
14946 if (DECL_COMDAT (decl
))
14947 // FIXME: Comdat grouping?
14948 comdat_linkage (decl
);
14949 note_vague_linkage_fn (decl
);
14950 cgraph_node::finalize_function (decl
, true);
14954 /* Look, function.c's interface to cfun does too much for us, we
14955 just need to restore the old value. I do not want to go
14956 redesigning that API right now. */
14959 current_function_decl
= old_cfd
;
14960 comparing_specializations
--;
14963 dump () && dump ("Read section:%u", snum
);
14967 if (!sec
.end (from ()))
14974 module_state::write_namespace (bytes_out
&sec
, depset
*dep
)
14976 unsigned ns_num
= dep
->cluster
;
14977 unsigned ns_import
= 0;
14979 if (dep
->is_import ())
14980 ns_import
= dep
->section
;
14981 else if (dep
->get_entity () != global_namespace
)
14989 module_state::read_namespace (bytes_in
&sec
)
14991 unsigned ns_import
= sec
.u ();
14992 unsigned ns_num
= sec
.u ();
14993 tree ns
= NULL_TREE
;
14995 if (ns_import
|| ns_num
)
15000 if (unsigned origin
= slurp
->remap_module (ns_import
))
15002 module_state
*from
= (*modules
)[origin
];
15003 if (ns_num
< from
->entity_num
)
15005 binding_slot
&slot
= (*entity_ary
)[from
->entity_lwm
+ ns_num
];
15007 if (!slot
.is_lazy ())
15012 sec
.set_overrun ();
15015 ns
= global_namespace
;
15020 /* SPACES is a sorted vector of namespaces. Write out the namespaces
15021 to MOD_SNAME_PFX.nms section. */
15024 module_state::write_namespaces (elf_out
*to
, vec
<depset
*> spaces
,
15025 unsigned num
, unsigned *crc_p
)
15027 dump () && dump ("Writing namespaces");
15030 bytes_out
sec (to
);
15033 for (unsigned ix
= 0; ix
!= num
; ix
++)
15035 depset
*b
= spaces
[ix
];
15036 tree ns
= b
->get_entity ();
15038 gcc_checking_assert (TREE_CODE (ns
) == NAMESPACE_DECL
);
15040 bool export_p
= DECL_MODULE_EXPORT_P (ns
);
15041 bool inline_p
= DECL_NAMESPACE_INLINE_P (ns
);
15042 bool public_p
= TREE_PUBLIC (ns
);
15044 /* We should only be naming public namespaces, or our own
15045 private ones. Internal linkage ones never get to be written
15046 out -- because that means something erroneously referred to a
15047 member. However, Davis Herring's paper probably changes that
15048 by permitting them to be written out, but then an error if on
15049 touches them. (Certain cases cannot be detected until that
15051 gcc_checking_assert (public_p
|| !DECL_MODULE_IMPORT_P (ns
));
15052 unsigned flags
= 0;
15059 dump () && dump ("Writing namespace:%u %N%s%s%s",
15060 b
->cluster
, ns
, export_p
? ", export" : "",
15061 public_p
? ", public" : "",
15062 inline_p
? ", inline" : "");
15063 sec
.u (b
->cluster
);
15064 sec
.u (to
->name (DECL_NAME (ns
)));
15065 write_namespace (sec
, b
->deps
[0]);
15067 /* Don't use bools, because this can be near the end of the
15068 section, and it won't save anything anyway. */
15070 write_location (sec
, DECL_SOURCE_LOCATION (ns
));
15073 sec
.end (to
, to
->name (MOD_SNAME_PFX
".nms"), crc_p
);
15077 /* Read the namespace hierarchy from MOD_SNAME_PFX.namespace. Fill in
15078 SPACES from that data. */
15081 module_state::read_namespaces (unsigned num
)
15085 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".nms"))
15088 dump () && dump ("Reading namespaces");
15091 for (unsigned ix
= 0; ix
!= num
; ix
++)
15093 unsigned entity_index
= sec
.u ();
15094 unsigned name
= sec
.u ();
15096 tree parent
= read_namespace (sec
);
15098 /* See comment in write_namespace about why not bits. */
15099 unsigned flags
= sec
.u ();
15100 location_t src_loc
= read_location (sec
);
15102 if (entity_index
>= entity_num
|| !parent
)
15103 sec
.set_overrun ();
15104 if (sec
.get_overrun ())
15107 tree id
= name
? get_identifier (from ()->name (name
)) : NULL_TREE
;
15108 bool public_p
= flags
& 4;
15109 bool inline_p
= flags
& 2;
15110 bool export_p
= flags
& 1;
15112 dump () && dump ("Read namespace:%u %P%s%s%s",
15113 entity_index
, parent
, id
, export_p
? ", export" : "",
15114 public_p
? ", public" : "",
15115 inline_p
? ", inline" : "");
15116 bool visible_p
= (export_p
15117 || (public_p
&& (is_partition () || is_module ())));
15118 tree inner
= add_imported_namespace (parent
, id
, mod
,
15119 src_loc
, visible_p
, inline_p
);
15120 if (export_p
&& is_partition ())
15121 DECL_MODULE_EXPORT_P (inner
) = true;
15123 /* Install the namespace. */
15124 (*entity_ary
)[entity_lwm
+ entity_index
] = inner
;
15125 if (DECL_MODULE_IMPORT_P (inner
))
15128 unsigned *slot
= &entity_map
->get_or_insert
15129 (DECL_UID (inner
), &existed
);
15131 /* If it existed, it should match. */
15132 gcc_checking_assert (inner
== (*entity_ary
)[*slot
]);
15134 *slot
= entity_lwm
+ entity_index
;
15138 if (!sec
.end (from ()))
15143 /* Write the binding TABLE to MOD_SNAME_PFX.bnd */
15146 module_state::write_bindings (elf_out
*to
, vec
<depset
*> sccs
, unsigned *crc_p
)
15148 dump () && dump ("Writing binding table");
15152 bytes_out
sec (to
);
15155 for (unsigned ix
= 0; ix
!= sccs
.length (); ix
++)
15157 depset
*b
= sccs
[ix
];
15158 if (b
->is_binding ())
15160 tree ns
= b
->get_entity ();
15161 dump () && dump ("Bindings %P section:%u", ns
, b
->get_name (),
15163 sec
.u (to
->name (b
->get_name ()));
15164 write_namespace (sec
, b
->deps
[0]);
15165 sec
.u (b
->section
);
15170 sec
.end (to
, to
->name (MOD_SNAME_PFX
".bnd"), crc_p
);
15176 /* Read the binding table from MOD_SNAME_PFX.bind. */
15179 module_state::read_bindings (unsigned num
, unsigned lwm
, unsigned hwm
)
15183 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".bnd"))
15186 dump () && dump ("Reading binding table");
15188 for (; !sec
.get_overrun () && num
--;)
15190 const char *name
= from ()->name (sec
.u ());
15191 tree ns
= read_namespace (sec
);
15192 unsigned snum
= sec
.u ();
15194 if (!ns
|| !name
|| (snum
- lwm
) >= (hwm
- lwm
))
15195 sec
.set_overrun ();
15196 if (!sec
.get_overrun ())
15198 tree id
= get_identifier (name
);
15199 dump () && dump ("Bindings %P section:%u", ns
, id
, snum
);
15200 if (mod
&& !import_module_binding (ns
, id
, mod
, snum
))
15206 if (!sec
.end (from ()))
15211 /* Write the entity table to MOD_SNAME_PFX.ent
15213 Each entry is a section number. */
15216 module_state::write_entities (elf_out
*to
, vec
<depset
*> depsets
,
15217 unsigned count
, unsigned *crc_p
)
15219 dump () && dump ("Writing entities");
15222 bytes_out
sec (to
);
15225 unsigned current
= 0;
15226 for (unsigned ix
= 0; ix
< depsets
.length (); ix
++)
15228 depset
*d
= depsets
[ix
];
15230 switch (d
->get_entity_kind ())
15235 case depset::EK_NAMESPACE
:
15236 if (!d
->is_import () && d
->get_entity () != global_namespace
)
15238 gcc_checking_assert (d
->cluster
== current
);
15244 case depset::EK_DECL
:
15245 case depset::EK_SPECIALIZATION
:
15246 case depset::EK_PARTIAL
:
15247 gcc_checking_assert (!d
->is_unreached ()
15248 && !d
->is_import ()
15249 && d
->cluster
== current
15252 sec
.u (d
->section
);
15256 gcc_assert (count
== current
);
15257 sec
.end (to
, to
->name (MOD_SNAME_PFX
".ent"), crc_p
);
15262 module_state::read_entities (unsigned count
, unsigned lwm
, unsigned hwm
)
15264 trees_in
sec (this);
15266 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".ent"))
15269 dump () && dump ("Reading entities");
15272 vec_safe_reserve (entity_ary
, count
);
15274 for (ix
= 0; ix
!= count
; ix
++)
15276 unsigned snum
= sec
.u ();
15277 if (snum
&& (snum
- lwm
) >= (hwm
- lwm
))
15278 sec
.set_overrun ();
15279 if (sec
.get_overrun ())
15283 slot
.u
.binding
= NULL_TREE
;
15285 slot
.set_lazy (snum
<< 2);
15286 entity_ary
->quick_push (slot
);
15291 if (!sec
.end (from ()))
15296 /* Write the pending table to MOD_SNAME_PFX.pnd
15298 Specializations & partials are keyed to their primary template.
15299 Members are keyed to their context.
15301 For specializations & partials, primary templates are keyed to the
15302 (namespace name) of their originating decl (because that's the only
15303 handle we have). */
15306 module_state::write_pendings (elf_out
*to
, vec
<depset
*> depsets
,
15307 depset::hash
&table
,
15308 unsigned count
, unsigned *crc_p
)
15310 dump () && dump ("Writing %u pendings", count
);
15313 trees_out
sec (to
, this, table
);
15316 for (unsigned ix
= 0; ix
< depsets
.length (); ix
++)
15318 depset
*d
= depsets
[ix
];
15319 depset::entity_kind kind
= d
->get_entity_kind ();
15320 tree key
= NULL_TREE
;
15321 bool is_spec
= false;
15324 if (kind
== depset::EK_SPECIALIZATION
)
15327 key
= reinterpret_cast <spec_entry
*> (d
->deps
[0])->tmpl
;
15329 else if (kind
== depset::EK_PARTIAL
)
15332 key
= CLASSTYPE_TI_TEMPLATE (TREE_TYPE (d
->get_entity ()));
15334 else if (kind
== depset::EK_DECL
&& d
->is_member ())
15336 tree ctx
= DECL_CONTEXT (d
->get_entity ());
15337 key
= TYPE_NAME (ctx
);
15338 if (tree ti
= CLASSTYPE_TEMPLATE_INFO (ctx
))
15339 if (DECL_TEMPLATE_RESULT (TI_TEMPLATE (ti
)) == key
)
15340 key
= TI_TEMPLATE (ti
);
15343 // FIXME:OPTIMIZATION More than likely when there is one pending
15344 // member, there will be others. All written in the same
15345 // section and keyed to the same class. We only need to record
15346 // one of them. The same is not true for specializations
15350 gcc_checking_assert (!d
->is_import ());
15353 /* Key the entity to its key. */
15354 depset
*key_dep
= table
.find_dependency (key
);
15355 if (key_dep
->get_entity_kind () == depset::EK_REDIRECT
)
15356 key_dep
= key_dep
->deps
[0];
15357 unsigned key_origin
15358 = key_dep
->is_import () ? key_dep
->section
: 0;
15359 sec
.u (key_origin
);
15360 sec
.u (key_dep
->cluster
);
15361 sec
.u (d
->cluster
);
15362 dump () && dump ("%s %N entity:%u keyed to %M[%u] %N",
15363 is_spec
? "Specialization" : "Member",
15365 d
->cluster
, (*modules
)[key_origin
],
15366 key_dep
->cluster
, key
);
15371 /* Key the general template to the originating decl. */
15372 tree origin
= get_originating_module_decl (key
);
15373 sec
.tree_node (CP_DECL_CONTEXT (origin
));
15374 sec
.tree_node (DECL_NAME (origin
));
15376 unsigned origin_ident
= import_entity_index (origin
);
15377 module_state
*origin_from
= this;
15378 if (!(origin_ident
& ~(~0u>>1)))
15379 origin_from
= import_entity_module (origin_ident
);
15380 sec
.u (origin_from
->remap
);
15383 sec
.tree_node (NULL
);
15387 gcc_assert (!count
);
15388 sec
.end (to
, to
->name (MOD_SNAME_PFX
".pnd"), crc_p
);
15393 module_state::read_pendings (unsigned count
)
15395 trees_in
sec (this);
15397 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".pnd"))
15400 dump () && dump ("Reading %u pendings", count
);
15403 for (unsigned ix
= 0; ix
!= count
; ix
++)
15405 unsigned key_origin
= slurp
->remap_module (sec
.u ());
15406 unsigned key_index
= sec
.u ();
15407 unsigned ent_index
= sec
.u ();
15408 module_state
*from
= (*modules
)[key_origin
];
15409 tree ns
= sec
.tree_node ();
15412 || key_index
>= from
->entity_num
|| ent_index
>= entity_num
15413 || (ns
&& TREE_CODE (ns
) != NAMESPACE_DECL
))
15414 sec
.set_overrun ();
15416 if (sec
.get_overrun ())
15419 bool loaded
= false;
15420 dump () && dump ("%s keyed to %M[%u] entity:%u",
15421 ns
? "Specialization" : "Member",
15422 from
, key_index
, ent_index
);
15423 unsigned key_ident
= from
->entity_lwm
+ key_index
;
15424 if (pending_table
->add (ns
? key_ident
: ~key_ident
,
15425 ent_index
+ entity_lwm
))
15427 binding_slot
&slot
= (*entity_ary
)[key_ident
];
15428 if (slot
.is_lazy ())
15429 slot
.or_lazy (ns
? 1 : 2);
15437 if (key
&& TREE_CODE (key
) == TEMPLATE_DECL
)
15438 DECL_MODULE_PENDING_SPECIALIZATIONS_P (key
) = true;
15440 sec
.set_overrun ();
15444 if (key
&& TREE_CODE (key
) == TYPE_DECL
)
15445 DECL_MODULE_PENDING_MEMBERS_P (key
) = true;
15447 sec
.set_overrun ();
15454 /* We also need to mark the namespace binding of the
15455 originating template, so we know to set its pending
15456 specializations flag, when we load it. */
15457 tree name
= sec
.tree_node ();
15458 unsigned origin
= slurp
->remap_module (sec
.u ());
15459 if (!origin
|| !name
|| TREE_CODE (name
) != IDENTIFIER_NODE
)
15460 sec
.set_overrun ();
15461 if (sec
.get_overrun ())
15464 module_state
*origin_from
= (*modules
)[origin
];
15466 && (origin_from
->is_header ()
15467 || (origin_from
->is_partition ()
15468 || origin_from
->is_module ())))
15469 note_pending_specializations (ns
, name
, origin_from
->is_header ());
15474 if (!sec
.end (from ()))
15479 /* Return true if module MOD cares about lazy specializations keyed to
15480 possibly duplicated entity bindings. */
15483 lazy_specializations_p (unsigned mod
, bool header_p
, bool partition_p
)
15485 module_state
*module
= (*modules
)[mod
];
15487 if (module
->is_header ())
15490 if (module
->is_module () || module
->is_partition ())
15491 return partition_p
;
15496 /* Read & write locations. */
15500 LK_IMPORT_ORDINARY
,
15506 static const module_state
*
15507 module_for_ordinary_loc (location_t loc
)
15510 unsigned len
= modules
->length () - pos
;
15514 unsigned half
= len
/ 2;
15515 module_state
*probe
= (*modules
)[pos
+ half
];
15516 if (loc
< probe
->ordinary_locs
.first
)
15518 else if (loc
< probe
->ordinary_locs
.second
)
15523 len
= len
- (half
+ 1);
15530 static const module_state
*
15531 module_for_macro_loc (location_t loc
)
15534 unsigned len
= modules
->length () - pos
;
15538 unsigned half
= len
/ 2;
15539 module_state
*probe
= (*modules
)[pos
+ half
];
15540 if (loc
>= probe
->macro_locs
.second
)
15542 else if (loc
>= probe
->macro_locs
.first
)
15547 len
= len
- (half
+ 1);
15555 module_state::imported_from () const
15557 location_t from
= loc
;
15558 line_map_ordinary
const *fmap
15559 = linemap_check_ordinary (linemap_lookup (line_table
, from
));
15561 if (MAP_MODULE_P (fmap
))
15562 from
= linemap_included_from (fmap
);
15567 /* If we're not streaming, record that we need location LOC.
15568 Otherwise stream it. */
15571 module_state::write_location (bytes_out
&sec
, location_t loc
)
15573 if (!sec
.streaming_p ())
15574 /* This is where we should note we use this location. See comment
15575 about write_ordinary_maps. */
15578 if (loc
< RESERVED_LOCATION_COUNT
)
15580 dump (dumper::LOCATION
) && dump ("Reserved location %u", unsigned (loc
));
15581 sec
.u (LK_RESERVED
+ loc
);
15583 else if (IS_ADHOC_LOC (loc
))
15585 dump (dumper::LOCATION
) && dump ("Adhoc location");
15587 location_t locus
= get_location_from_adhoc_loc (line_table
, loc
);
15588 write_location (sec
, locus
);
15589 source_range range
= get_range_from_loc (line_table
, loc
);
15590 if (range
.m_start
== locus
)
15592 range
.m_start
= UNKNOWN_LOCATION
;
15593 write_location (sec
, range
.m_start
);
15594 write_location (sec
, range
.m_finish
);
15596 else if (IS_MACRO_LOC (loc
))
15598 if (const loc_spans::span
*span
= spans
.macro (loc
))
15600 unsigned off
= MAX_LOCATION_T
- loc
;
15602 off
-= span
->macro_delta
;
15606 dump (dumper::LOCATION
)
15607 && dump ("Macro location %u output %u", loc
, off
);
15609 else if (const module_state
*import
= module_for_macro_loc (loc
))
15611 unsigned off
= import
->macro_locs
.second
- loc
- 1;
15612 sec
.u (LK_IMPORT_MACRO
);
15613 sec
.u (import
->remap
);
15615 dump (dumper::LOCATION
)
15616 && dump ("Imported macro location %u output %u:%u",
15617 loc
, import
->remap
, off
);
15620 gcc_unreachable ();
15622 else if (IS_ORDINARY_LOC (loc
))
15624 if (const loc_spans::span
*span
= spans
.ordinary (loc
))
15626 unsigned off
= loc
;
15628 off
+= span
->ordinary_delta
;
15629 sec
.u (LK_ORDINARY
);
15632 dump (dumper::LOCATION
)
15633 && dump ("Ordinary location %u output %u", loc
, off
);
15635 else if (const module_state
*import
= module_for_ordinary_loc (loc
))
15637 unsigned off
= loc
- import
->ordinary_locs
.first
;
15638 sec
.u (LK_IMPORT_ORDINARY
);
15639 sec
.u (import
->remap
);
15641 dump (dumper::LOCATION
)
15642 && dump ("Imported ordinary location %u output %u:%u",
15643 import
->remap
, import
->remap
, off
);
15646 gcc_unreachable ();
15649 gcc_unreachable ();
15653 module_state::read_location (bytes_in
&sec
) const
15655 location_t locus
= UNKNOWN_LOCATION
;
15656 unsigned kind
= sec
.u ();
15661 if (kind
< LK_RESERVED
+ RESERVED_LOCATION_COUNT
)
15662 locus
= location_t (kind
- LK_RESERVED
);
15664 sec
.set_overrun ();
15665 dump (dumper::LOCATION
)
15666 && dump ("Reserved location %u", unsigned (locus
));
15672 dump (dumper::LOCATION
) && dump ("Adhoc location");
15673 locus
= read_location (sec
);
15674 source_range range
;
15675 range
.m_start
= read_location (sec
);
15676 if (range
.m_start
== UNKNOWN_LOCATION
)
15677 range
.m_start
= locus
;
15678 range
.m_finish
= read_location (sec
);
15679 if (locus
!= loc
&& range
.m_start
!= loc
&& range
.m_finish
!= loc
)
15680 locus
= get_combined_adhoc_loc (line_table
, locus
, range
, NULL
);
15686 unsigned off
= sec
.u ();
15688 if (macro_locs
.first
)
15690 location_t adjusted
= MAX_LOCATION_T
- off
;
15691 adjusted
-= slurp
->loc_deltas
.second
;
15692 if (adjusted
< macro_locs
.first
)
15693 sec
.set_overrun ();
15694 else if (adjusted
< macro_locs
.second
)
15697 sec
.set_overrun ();
15701 dump (dumper::LOCATION
)
15702 && dump ("Macro %u becoming %u", off
, locus
);
15708 unsigned off
= sec
.u ();
15709 if (ordinary_locs
.second
)
15711 location_t adjusted
= off
;
15713 adjusted
+= slurp
->loc_deltas
.first
;
15714 if (adjusted
>= ordinary_locs
.second
)
15715 sec
.set_overrun ();
15716 else if (adjusted
>= ordinary_locs
.first
)
15718 else if (adjusted
< spans
.main_start ())
15724 dump (dumper::LOCATION
)
15725 && dump ("Ordinary location %u becoming %u", off
, locus
);
15729 case LK_IMPORT_MACRO
:
15730 case LK_IMPORT_ORDINARY
:
15732 unsigned mod
= sec
.u ();
15733 unsigned off
= sec
.u ();
15734 const module_state
*import
= NULL
;
15736 if (!mod
&& !slurp
->remap
)
15737 /* This is an early read of a partition location during the
15738 read of our ordinary location map. */
15742 mod
= slurp
->remap_module (mod
);
15744 sec
.set_overrun ();
15746 import
= (*modules
)[mod
];
15751 if (kind
== LK_IMPORT_MACRO
)
15753 if (!import
->macro_locs
.first
)
15754 locus
= import
->loc
;
15755 else if (off
< import
->macro_locs
.second
- macro_locs
.first
)
15756 locus
= import
->macro_locs
.second
- off
- 1;
15758 sec
.set_overrun ();
15762 if (!import
->ordinary_locs
.second
)
15763 locus
= import
->loc
;
15764 else if (off
< (import
->ordinary_locs
.second
15765 - import
->ordinary_locs
.first
))
15766 locus
= import
->ordinary_locs
.first
+ off
;
15768 sec
.set_overrun ();
15778 /* Prepare the span adjustments. */
15780 // FIXME:QOI I do not prune the unreachable locations. Modules with
15781 // textually-large GMFs could well cause us to run out of locations.
15782 // Regular single-file modules could also be affected. We should
15783 // determine which locations we need to represent, so that we do not
15784 // grab more locations than necessary. An example is in
15785 // write_macro_maps where we work around macro expansions that are not
15786 // covering any locations -- the macro expands to nothing. Perhaps we
15787 // should decompose locations so that we can have a more graceful
15788 // degradation upon running out?
15791 module_state::write_prepare_maps (module_state_config
*)
15793 dump () && dump ("Preparing locations");
15796 dump () && dump ("Reserved locations [%u,%u) macro [%u,%u)",
15797 spans
[loc_spans::SPAN_RESERVED
].ordinary
.first
,
15798 spans
[loc_spans::SPAN_RESERVED
].ordinary
.second
,
15799 spans
[loc_spans::SPAN_RESERVED
].macro
.first
,
15800 spans
[loc_spans::SPAN_RESERVED
].macro
.second
);
15802 location_map_info info
;
15804 info
.num_maps
.first
= info
.num_maps
.second
= 0;
15806 /* Figure the alignment of ordinary location spans. */
15807 unsigned max_range
= 0;
15808 for (unsigned ix
= loc_spans::SPAN_FIRST
; ix
!= spans
.length (); ix
++)
15810 loc_spans::span
&span
= spans
[ix
];
15811 line_map_ordinary
const *omap
15812 = linemap_check_ordinary (linemap_lookup (line_table
,
15813 span
.ordinary
.first
));
15815 /* We should exactly match up. */
15816 gcc_checking_assert (MAP_START_LOCATION (omap
) == span
.ordinary
.first
);
15818 line_map_ordinary
const *fmap
= omap
;
15819 for (; MAP_START_LOCATION (omap
) < span
.ordinary
.second
; omap
++)
15821 /* We should never find a module linemap in an interval. */
15822 gcc_checking_assert (!MAP_MODULE_P (omap
));
15824 if (max_range
< omap
->m_range_bits
)
15825 max_range
= omap
->m_range_bits
;
15828 unsigned count
= omap
- fmap
;
15829 info
.num_maps
.first
+= count
;
15831 if (span
.macro
.first
!= span
.macro
.second
)
15833 count
= linemap_lookup_macro_index (line_table
, span
.macro
.first
) + 1;
15834 count
-= linemap_lookup_macro_index (line_table
,
15835 span
.macro
.second
- 1);
15836 dump (dumper::LOCATION
) && dump ("Span:%u %u macro maps", ix
, count
);
15837 info
.num_maps
.second
+= count
;
15841 /* Adjust the maps. Ordinary ones ascend, and we must maintain
15842 alignment. Macro ones descend, but are unaligned. */
15843 location_t ord_off
= spans
[loc_spans::SPAN_FIRST
].ordinary
.first
;
15844 location_t mac_off
= spans
[loc_spans::SPAN_FIRST
].macro
.second
;
15845 location_t range_mask
= (1u << max_range
) - 1;
15847 dump () && dump ("Ordinary maps range bits:%u, preserve:%x, zero:%u",
15848 max_range
, ord_off
& range_mask
, ord_off
& ~range_mask
);
15850 for (unsigned ix
= loc_spans::SPAN_FIRST
; ix
!= spans
.length (); ix
++)
15852 loc_spans::span
&span
= spans
[ix
];
15854 span
.macro_delta
= mac_off
- span
.macro
.second
;
15855 mac_off
-= span
.macro
.second
- span
.macro
.first
;
15856 dump () && dump ("Macro span:%u [%u,%u):%u->%d(%u)", ix
,
15857 span
.macro
.first
, span
.macro
.second
,
15858 span
.macro
.second
- span
.macro
.first
,
15859 span
.macro_delta
, span
.macro
.first
+ span
.macro_delta
);
15861 line_map_ordinary
const *omap
15862 = linemap_check_ordinary (linemap_lookup (line_table
,
15863 span
.ordinary
.first
));
15864 location_t base
= MAP_START_LOCATION (omap
);
15866 /* Preserve the low MAX_RANGE bits of base by incrementing ORD_OFF. */
15867 unsigned low_bits
= base
& range_mask
;
15868 if ((ord_off
& range_mask
) > low_bits
)
15869 low_bits
+= range_mask
+ 1;
15870 ord_off
= (ord_off
& ~range_mask
) + low_bits
;
15871 span
.ordinary_delta
= ord_off
- base
;
15873 for (; MAP_START_LOCATION (omap
) < span
.ordinary
.second
; omap
++)
15875 location_t start_loc
= MAP_START_LOCATION (omap
);
15876 unsigned to
= start_loc
+ span
.ordinary_delta
;
15877 location_t end_loc
= MAP_START_LOCATION (omap
+ 1);
15879 dump () && dump ("Ordinary span:%u [%u,%u):%u->%d(%u)", ix
, start_loc
,
15880 end_loc
, end_loc
- start_loc
,
15881 span
.ordinary_delta
, to
);
15883 /* There should be no change in the low order bits. */
15884 gcc_checking_assert (((start_loc
^ to
) & range_mask
) == 0);
15886 /* The ending serialized value. */
15887 ord_off
= span
.ordinary
.second
+ span
.ordinary_delta
;
15890 dump () && dump ("Ordinary hwm:%u macro lwm:%u", ord_off
, mac_off
);
15894 info
.max_range
= max_range
;
15900 module_state::read_prepare_maps (const module_state_config
*cfg
)
15902 location_t ordinary
= line_table
->highest_location
+ 1;
15903 ordinary
= ((ordinary
+ (1u << cfg
->ordinary_loc_align
))
15904 & ~((1u << cfg
->ordinary_loc_align
) - 1));
15905 ordinary
+= cfg
->ordinary_locs
;
15907 location_t macro
= LINEMAPS_MACRO_LOWEST_LOCATION (line_table
);
15908 macro
-= cfg
->macro_locs
;
15910 if (ordinary
< LINE_MAP_MAX_LOCATION_WITH_COLS
15911 && macro
>= LINE_MAP_MAX_LOCATION
)
15912 /* OK, we have enough locations. */
15915 ordinary_locs
.first
= ordinary_locs
.second
= 0;
15916 macro_locs
.first
= macro_locs
.second
= 0;
15918 static bool informed
= false;
15921 /* Just give the notice once. */
15923 inform (loc
, "unable to represent further imported source locations");
15929 /* Write the location maps. This also determines the shifts for the
15933 module_state::write_ordinary_maps (elf_out
*to
, location_map_info
&info
,
15934 module_state_config
*cfg
, bool has_partitions
,
15937 dump () && dump ("Writing ordinary location maps");
15940 vec
<const char *> filenames
;
15941 filenames
.create (20);
15943 /* Determine the unique filenames. */
15944 // FIXME:QOI We should find the set of filenames when working out
15945 // which locations we actually need. See write_prepare_maps.
15946 for (unsigned ix
= loc_spans::SPAN_FIRST
; ix
!= spans
.length (); ix
++)
15948 loc_spans::span
&span
= spans
[ix
];
15949 line_map_ordinary
const *omap
15950 = linemap_check_ordinary (linemap_lookup (line_table
,
15951 span
.ordinary
.first
));
15953 /* We should exactly match up. */
15954 gcc_checking_assert (MAP_START_LOCATION (omap
) == span
.ordinary
.first
);
15956 for (; MAP_START_LOCATION (omap
) < span
.ordinary
.second
; omap
++)
15958 const char *fname
= ORDINARY_MAP_FILE_NAME (omap
);
15960 /* We should never find a module linemap in an interval. */
15961 gcc_checking_assert (!MAP_MODULE_P (omap
));
15963 /* We expect very few filenames, so just an array. */
15964 for (unsigned jx
= filenames
.length (); jx
--;)
15966 const char *name
= filenames
[jx
];
15967 if (0 == strcmp (name
, fname
))
15969 /* Reset the linemap's name, because for things like
15970 preprocessed input we could have multple
15971 instances of the same name, and we'd rather not
15973 const_cast<line_map_ordinary
*> (omap
)->to_file
= name
;
15979 filenames
.safe_push (fname
);
15983 bytes_out
sec (to
);
15986 /* Write the filenames. */
15987 unsigned len
= filenames
.length ();
15989 dump () && dump ("%u source file names", len
);
15990 for (unsigned ix
= 0; ix
!= len
; ix
++)
15992 const char *fname
= filenames
[ix
];
15993 dump (dumper::LOCATION
) && dump ("Source file[%u]=%s", ix
, fname
);
15997 location_t offset
= spans
[loc_spans::SPAN_FIRST
].ordinary
.first
;
15998 location_t range_mask
= (1u << info
.max_range
) - 1;
16000 dump () && dump ("Ordinary maps:%u, range bits:%u, preserve:%x, zero:%u",
16001 info
.num_maps
.first
, info
.max_range
, offset
& range_mask
,
16002 offset
& ~range_mask
);
16003 sec
.u (info
.num_maps
.first
); /* Num maps. */
16004 sec
.u (info
.max_range
); /* Maximum range bits */
16005 sec
.u (offset
& range_mask
); /* Bits to preserve. */
16006 sec
.u (offset
& ~range_mask
);
16008 for (unsigned ix
= loc_spans::SPAN_FIRST
; ix
!= spans
.length (); ix
++)
16010 loc_spans::span
&span
= spans
[ix
];
16011 line_map_ordinary
const *omap
16012 = linemap_check_ordinary (linemap_lookup (line_table
,
16013 span
.ordinary
.first
));
16014 for (; MAP_START_LOCATION (omap
) < span
.ordinary
.second
; omap
++)
16016 location_t start_loc
= MAP_START_LOCATION (omap
);
16017 unsigned to
= start_loc
+ span
.ordinary_delta
;
16019 dump (dumper::LOCATION
)
16020 && dump ("Span:%u ordinary [%u,%u)->%u", ix
, start_loc
,
16021 MAP_START_LOCATION (omap
+ 1), to
);
16023 /* There should be no change in the low order bits. */
16024 gcc_checking_assert (((start_loc
^ to
) & range_mask
) == 0);
16027 /* Making accessors just for here, seems excessive. */
16028 sec
.u (omap
->reason
);
16029 sec
.u (omap
->sysp
);
16030 sec
.u (omap
->m_range_bits
);
16031 sec
.u (omap
->m_column_and_range_bits
- omap
->m_range_bits
);
16033 const char *fname
= ORDINARY_MAP_FILE_NAME (omap
);
16034 for (unsigned ix
= 0; ix
!= filenames
.length (); ix
++)
16035 if (filenames
[ix
] == fname
)
16040 sec
.u (ORDINARY_MAP_STARTING_LINE_NUMBER (omap
));
16042 /* Write the included from location, which means reading it
16043 while reading in the ordinary maps. So we'd better not
16044 be getting ahead of ourselves. */
16045 location_t from
= linemap_included_from (omap
);
16046 gcc_checking_assert (from
< MAP_START_LOCATION (omap
));
16047 if (from
!= UNKNOWN_LOCATION
&& has_partitions
)
16049 /* A partition's span will have a from pointing at a
16050 MODULE_INC. Find that map's from. */
16051 line_map_ordinary
const *fmap
16052 = linemap_check_ordinary (linemap_lookup (line_table
, from
));
16053 if (MAP_MODULE_P (fmap
))
16054 from
= linemap_included_from (fmap
);
16056 write_location (sec
, from
);
16058 /* The ending serialized value. */
16059 offset
= MAP_START_LOCATION (omap
) + span
.ordinary_delta
;
16061 dump () && dump ("Ordinary location hwm:%u", offset
);
16064 // Record number of locations and alignment.
16065 cfg
->ordinary_loc_align
= info
.max_range
;
16066 cfg
->ordinary_locs
= offset
;
16068 filenames
.release ();
16070 sec
.end (to
, to
->name (MOD_SNAME_PFX
".olm"), crc_p
);
16075 module_state::write_macro_maps (elf_out
*to
, location_map_info
&info
,
16076 module_state_config
*cfg
, unsigned *crc_p
)
16078 dump () && dump ("Writing macro location maps");
16081 bytes_out
sec (to
);
16084 dump () && dump ("Macro maps:%u", info
.num_maps
.second
);
16085 sec
.u (info
.num_maps
.second
);
16087 location_t offset
= spans
[loc_spans::SPAN_FIRST
].macro
.second
;
16090 unsigned macro_num
= 0;
16091 for (unsigned ix
= loc_spans::SPAN_FIRST
; ix
!= spans
.length (); ix
++)
16093 loc_spans::span
&span
= spans
[ix
];
16094 if (span
.macro
.first
== span
.macro
.second
)
16097 for (unsigned first
16098 = linemap_lookup_macro_index (line_table
, span
.macro
.second
- 1);
16099 first
< LINEMAPS_MACRO_USED (line_table
);
16102 line_map_macro
const *mmap
16103 = LINEMAPS_MACRO_MAP_AT (line_table
, first
);
16104 location_t start_loc
= MAP_START_LOCATION (mmap
);
16105 if (start_loc
< span
.macro
.first
)
16107 if (macro_num
== info
.num_maps
.second
)
16109 /* We're ending on an empty macro expansion. The
16110 preprocessor doesn't prune such things. */
16111 // FIXME:QOI This is an example of the non-pruning of
16112 // locations. See write_prepare_maps.
16113 gcc_checking_assert (!mmap
->n_tokens
);
16118 sec
.u (mmap
->n_tokens
);
16119 sec
.cpp_node (mmap
->macro
);
16120 write_location (sec
, mmap
->expansion
);
16121 const location_t
*locs
= mmap
->macro_locations
;
16122 /* There are lots of identical runs. */
16123 location_t prev
= UNKNOWN_LOCATION
;
16124 unsigned count
= 0;
16126 for (unsigned jx
= mmap
->n_tokens
* 2; jx
--;)
16128 location_t tok_loc
= locs
[jx
];
16129 if (tok_loc
== prev
)
16138 write_location (sec
, tok_loc
);
16141 dump (dumper::LOCATION
)
16142 && dump ("Span:%u macro:%u %I %u/%u*2 locations [%u,%u)->%u",
16143 ix
, macro_num
, identifier (mmap
->macro
),
16144 runs
, mmap
->n_tokens
,
16145 start_loc
, start_loc
+ mmap
->n_tokens
,
16146 start_loc
+ span
.macro_delta
);
16148 offset
-= mmap
->n_tokens
;
16149 gcc_checking_assert (offset
== start_loc
+ span
.macro_delta
);
16152 dump () && dump ("Macro location lwm:%u", offset
);
16154 gcc_assert (macro_num
== info
.num_maps
.second
);
16156 cfg
->macro_locs
= MAX_LOCATION_T
+ 1 - offset
;
16158 sec
.end (to
, to
->name (MOD_SNAME_PFX
".mlm"), crc_p
);
16163 module_state::read_ordinary_maps ()
16167 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".olm"))
16169 dump () && dump ("Reading ordinary location maps");
16172 /* Read the filename table. */
16173 unsigned len
= sec
.u ();
16174 dump () && dump ("%u source file names", len
);
16175 vec
<const char *> filenames
;
16176 filenames
.create (len
);
16177 for (unsigned ix
= 0; ix
!= len
; ix
++)
16180 const char *buf
= sec
.str (&l
);
16181 char *fname
= XNEWVEC (char, l
+ 1);
16182 memcpy (fname
, buf
, l
+ 1);
16183 dump (dumper::LOCATION
) && dump ("Source file[%u]=%s", ix
, fname
);
16184 /* We leak these names into the line-map table. But it
16185 doesn't own them. */
16186 filenames
.quick_push (fname
);
16189 unsigned num_ordinary
= sec
.u ();
16190 unsigned max_range
= sec
.u ();
16191 unsigned low_bits
= sec
.u ();
16192 location_t zero
= sec
.u ();
16193 location_t range_mask
= (1u << max_range
) - 1;
16195 dump () && dump ("Ordinary maps:%u, range bits:%u, preserve:%x, zero:%u",
16196 num_ordinary
, max_range
, low_bits
, zero
);
16198 location_t offset
= line_table
->highest_location
+ 1;
16199 /* Ensure offset doesn't go backwards at the start. */
16200 if ((offset
& range_mask
) > low_bits
)
16201 offset
+= range_mask
+ 1;
16202 offset
= (offset
& ~range_mask
);
16204 bool propagated
= spans
.maybe_propagate (this, offset
+ low_bits
);
16206 line_map_ordinary
*maps
= static_cast<line_map_ordinary
*>
16207 (line_map_new_raw (line_table
, false, num_ordinary
));
16209 location_t lwm
= offset
;
16210 slurp
->loc_deltas
.first
= offset
- zero
;
16211 ordinary_locs
.first
= zero
+ low_bits
+ slurp
->loc_deltas
.first
;
16212 dump () && dump ("Ordinary loc delta %d", slurp
->loc_deltas
.first
);
16214 for (unsigned ix
= 0; ix
!= num_ordinary
&& !sec
.get_overrun (); ix
++)
16216 line_map_ordinary
*map
= &maps
[ix
];
16217 unsigned hwm
= sec
.u ();
16219 /* Record the current HWM so that the below read_location is
16221 ordinary_locs
.second
= hwm
+ slurp
->loc_deltas
.first
;
16222 map
->start_location
= hwm
+ (offset
- zero
);
16223 if (map
->start_location
< lwm
)
16224 sec
.set_overrun ();
16225 lwm
= map
->start_location
;
16226 dump (dumper::LOCATION
) && dump ("Map:%u %u->%u", ix
, hwm
, lwm
);
16227 map
->reason
= lc_reason (sec
.u ());
16228 map
->sysp
= sec
.u ();
16229 map
->m_range_bits
= sec
.u ();
16230 map
->m_column_and_range_bits
= map
->m_range_bits
+ sec
.u ();
16232 unsigned fnum
= sec
.u ();
16233 map
->to_file
= (fnum
< filenames
.length () ? filenames
[fnum
] : "");
16234 map
->to_line
= sec
.u ();
16236 /* Root the outermost map at our location. */
16237 location_t from
= read_location (sec
);
16238 map
->included_from
= from
!= UNKNOWN_LOCATION
? from
: loc
;
16241 location_t hwm
= sec
.u ();
16242 ordinary_locs
.second
= hwm
+ slurp
->loc_deltas
.first
;
16244 /* highest_location is the one handed out, not the next one to
16246 line_table
->highest_location
= ordinary_locs
.second
- 1;
16248 if (line_table
->highest_location
>= LINE_MAP_MAX_LOCATION_WITH_COLS
)
16249 /* We shouldn't run out of locations, as we checked before
16251 sec
.set_overrun ();
16252 dump () && dump ("Ordinary location hwm:%u", ordinary_locs
.second
);
16257 filenames
.release ();
16260 if (!sec
.end (from ()))
16267 module_state::read_macro_maps ()
16271 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".mlm"))
16273 dump () && dump ("Reading macro location maps");
16276 unsigned num_macros
= sec
.u ();
16277 location_t zero
= sec
.u ();
16278 dump () && dump ("Macro maps:%u zero:%u", num_macros
, zero
);
16280 bool propagated
= spans
.maybe_propagate (this);
16282 location_t offset
= LINEMAPS_MACRO_LOWEST_LOCATION (line_table
);
16283 slurp
->loc_deltas
.second
= zero
- offset
;
16284 macro_locs
.second
= zero
- slurp
->loc_deltas
.second
;
16285 dump () && dump ("Macro loc delta %d", slurp
->loc_deltas
.second
);
16287 for (unsigned ix
= 0; ix
!= num_macros
&& !sec
.get_overrun (); ix
++)
16289 unsigned lwm
= sec
.u ();
16290 /* Record the current LWM so that the below read_location is
16292 macro_locs
.first
= lwm
- slurp
->loc_deltas
.second
;
16294 unsigned n_tokens
= sec
.u ();
16295 cpp_hashnode
*node
= sec
.cpp_node ();
16296 location_t exp_loc
= read_location (sec
);
16298 const line_map_macro
*macro
16299 = linemap_enter_macro (line_table
, node
, exp_loc
, n_tokens
);
16301 /* We shouldn't run out of locations, as we checked that we
16302 had enough before starting. */
16305 location_t
*locs
= macro
->macro_locations
;
16306 location_t tok_loc
= UNKNOWN_LOCATION
;
16307 unsigned count
= sec
.u ();
16309 for (unsigned jx
= macro
->n_tokens
* 2; jx
-- && !sec
.get_overrun ();)
16311 while (!count
-- && !sec
.get_overrun ())
16314 tok_loc
= read_location (sec
);
16317 locs
[jx
] = tok_loc
;
16320 sec
.set_overrun ();
16321 dump (dumper::LOCATION
)
16322 && dump ("Macro:%u %I %u/%u*2 locations [%u,%u)",
16323 ix
, identifier (node
), runs
, n_tokens
,
16324 MAP_START_LOCATION (macro
),
16325 MAP_START_LOCATION (macro
) + n_tokens
);
16327 location_t lwm
= sec
.u ();
16328 macro_locs
.first
= lwm
- slurp
->loc_deltas
.second
;
16330 dump () && dump ("Macro location lwm:%u", macro_locs
.first
);
16336 if (!sec
.end (from ()))
16342 /* Serialize the definition of MACRO. */
16345 module_state::write_define (bytes_out
&sec
, const cpp_macro
*macro
, bool located
)
16347 sec
.u (macro
->count
);
16349 sec
.b (macro
->fun_like
);
16350 sec
.b (macro
->variadic
);
16351 sec
.b (macro
->syshdr
);
16355 write_location (sec
, macro
->line
);
16356 if (macro
->fun_like
)
16358 sec
.u (macro
->paramc
);
16359 const cpp_hashnode
*const *parms
= macro
->parm
.params
;
16360 for (unsigned ix
= 0; ix
!= macro
->paramc
; ix
++)
16361 sec
.cpp_node (parms
[ix
]);
16365 for (unsigned ix
= 0; ix
!= macro
->count
; ix
++)
16367 const cpp_token
*token
= ¯o
->exp
.tokens
[ix
];
16369 write_location (sec
, token
->src_loc
);
16370 sec
.u (token
->type
);
16371 sec
.u (token
->flags
);
16372 switch (cpp_token_val_index (token
))
16375 gcc_unreachable ();
16377 case CPP_TOKEN_FLD_ARG_NO
:
16378 /* An argument reference. */
16379 sec
.u (token
->val
.macro_arg
.arg_no
);
16380 sec
.cpp_node (token
->val
.macro_arg
.spelling
);
16383 case CPP_TOKEN_FLD_NODE
:
16384 /* An identifier. */
16385 sec
.cpp_node (token
->val
.node
.node
);
16386 if (token
->val
.node
.spelling
== token
->val
.node
.node
)
16387 /* The spelling will usually be the same. so optimize
16391 sec
.cpp_node (token
->val
.node
.spelling
);
16394 case CPP_TOKEN_FLD_NONE
:
16397 case CPP_TOKEN_FLD_STR
:
16398 /* A string, number or comment. Not always NUL terminated,
16399 we stream out in a single contatenation with embedded
16400 NULs as that's a safe default. */
16401 len
+= token
->val
.str
.len
+ 1;
16402 sec
.u (token
->val
.str
.len
);
16405 case CPP_TOKEN_FLD_SOURCE
:
16406 case CPP_TOKEN_FLD_TOKEN_NO
:
16407 case CPP_TOKEN_FLD_PRAGMA
:
16408 /* These do not occur inside a macro itself. */
16409 gcc_unreachable ();
16415 char *ptr
= reinterpret_cast<char *> (sec
.buf (len
));
16417 for (unsigned ix
= 0; ix
!= macro
->count
; ix
++)
16419 const cpp_token
*token
= ¯o
->exp
.tokens
[ix
];
16420 if (cpp_token_val_index (token
) == CPP_TOKEN_FLD_STR
)
16422 memcpy (ptr
+ len
, token
->val
.str
.text
,
16423 token
->val
.str
.len
);
16424 len
+= token
->val
.str
.len
;
16431 /* Read a macro definition. */
16434 module_state::read_define (bytes_in
&sec
, cpp_reader
*reader
, bool located
) const
16436 unsigned count
= sec
.u ();
16437 /* We rely on knowing cpp_reader's hash table is ident_hash, and
16438 it's subobject allocator is stringpool_ggc_alloc and that is just
16439 a wrapper for ggc_alloc_atomic. */
16441 = (cpp_macro
*)ggc_alloc_atomic (sizeof (cpp_macro
)
16442 + sizeof (cpp_token
) * (count
- !!count
));
16443 memset (macro
, 0, sizeof (cpp_macro
) + sizeof (cpp_token
) * (count
- !!count
));
16445 macro
->count
= count
;
16446 macro
->kind
= cmk_macro
;
16447 macro
->imported_p
= true;
16449 macro
->fun_like
= sec
.b ();
16450 macro
->variadic
= sec
.b ();
16451 macro
->syshdr
= sec
.b ();
16454 macro
->line
= located
? read_location (sec
) : loc
;
16456 if (macro
->fun_like
)
16458 unsigned paramc
= sec
.u ();
16459 cpp_hashnode
**params
16460 = (cpp_hashnode
**)ggc_alloc_atomic (sizeof (cpp_hashnode
*) * paramc
);
16461 macro
->paramc
= paramc
;
16462 macro
->parm
.params
= params
;
16463 for (unsigned ix
= 0; ix
!= paramc
; ix
++)
16464 params
[ix
] = sec
.cpp_node ();
16468 for (unsigned ix
= 0; ix
!= count
&& !sec
.get_overrun (); ix
++)
16470 cpp_token
*token
= ¯o
->exp
.tokens
[ix
];
16471 token
->src_loc
= located
? read_location (sec
) : loc
;
16472 token
->type
= cpp_ttype (sec
.u ());
16473 token
->flags
= sec
.u ();
16474 switch (cpp_token_val_index (token
))
16477 sec
.set_overrun ();
16480 case CPP_TOKEN_FLD_ARG_NO
:
16481 /* An argument reference. */
16483 unsigned arg_no
= sec
.u ();
16484 if (arg_no
- 1 >= macro
->paramc
)
16485 sec
.set_overrun ();
16486 token
->val
.macro_arg
.arg_no
= arg_no
;
16487 token
->val
.macro_arg
.spelling
= sec
.cpp_node ();
16491 case CPP_TOKEN_FLD_NODE
:
16492 /* An identifier. */
16493 token
->val
.node
.node
= sec
.cpp_node ();
16494 token
->val
.node
.spelling
= sec
.cpp_node ();
16495 if (!token
->val
.node
.spelling
)
16496 token
->val
.node
.spelling
= token
->val
.node
.node
;
16499 case CPP_TOKEN_FLD_NONE
:
16502 case CPP_TOKEN_FLD_STR
:
16503 /* A string, number or comment. */
16504 token
->val
.str
.len
= sec
.u ();
16505 len
+= token
->val
.str
.len
+ 1;
16511 if (const char *ptr
= reinterpret_cast<const char *> (sec
.buf (len
)))
16513 /* There should be a final NUL. */
16515 sec
.set_overrun ();
16516 /* cpp_alloc_token_string will add a final NUL. */
16517 const unsigned char *buf
16518 = cpp_alloc_token_string (reader
, (const unsigned char *)ptr
, len
- 1);
16520 for (unsigned ix
= 0; ix
!= count
&& !sec
.get_overrun (); ix
++)
16522 cpp_token
*token
= ¯o
->exp
.tokens
[ix
];
16523 if (cpp_token_val_index (token
) == CPP_TOKEN_FLD_STR
)
16525 token
->val
.str
.text
= buf
+ len
;
16526 len
+= token
->val
.str
.len
;
16528 sec
.set_overrun ();
16533 if (sec
.get_overrun ())
16538 /* Exported macro data. */
16539 struct macro_export
{
16541 location_t undef_loc
;
16544 :def (NULL
), undef_loc (UNKNOWN_LOCATION
)
16549 /* Imported macro data. */
16550 class macro_import
{
16553 #if defined (WORDS_BIGENDIAN) && SIZEOF_VOID_P == 8
16556 /* We need to ensure we don't use the LSB for representation, as
16557 that's the union discriminator below. */
16560 #if !(defined (WORDS_BIGENDIAN) && SIZEOF_VOID_P == 8)
16573 /* Not a regular ctor, because we put it in a union, and that's
16574 not allowed in C++ 98. */
16575 static slot
ctor (unsigned module
, unsigned defness
)
16577 gcc_checking_assert (defness
);
16579 s
.bits
= defness
| (module
<< L_MODULE_SHIFT
);
16585 unsigned get_defness () const
16587 return bits
& L_BOTH
;
16589 unsigned get_module () const
16591 return bits
>> L_MODULE_SHIFT
;
16593 void become_undef ()
16595 bits
&= ~unsigned (L_DEF
);
16596 bits
|= unsigned (L_UNDEF
);
16601 typedef vec
<slot
, va_heap
, vl_embed
> ary_t
;
16603 /* Discriminated by bits 0|1 != 0. The expected case is that
16604 there will be exactly one slot per macro, hence the effort of
16617 bool single_p () const
16619 return u
.single
.bits
& slot::L_BOTH
;
16621 bool occupied_p () const
16623 return u
.ary
!= NULL
;
16627 unsigned length () const
16629 gcc_checking_assert (occupied_p ());
16630 return single_p () ? 1 : u
.ary
->length ();
16632 slot
&operator[] (unsigned ix
)
16634 gcc_checking_assert (occupied_p ());
16637 gcc_checking_assert (!ix
);
16641 return (*u
.ary
)[ix
];
16646 slot
&append (unsigned module
, unsigned defness
);
16649 /* O is a new import to append to the list for. If we're an empty
16650 set, initialize us. */
16652 macro_import::slot
&
16653 macro_import::append (unsigned module
, unsigned defness
)
16655 if (!occupied_p ())
16657 u
.single
= slot::ctor (module
, defness
);
16662 bool single
= single_p ();
16663 ary_t
*m
= single
? NULL
: u
.ary
;
16664 vec_safe_reserve (m
, 1 + single
);
16666 m
->quick_push (u
.single
);
16668 return *u
.ary
->quick_push (slot::ctor (module
, defness
));
16672 /* We're going to export something. Make sure the first import slot
16675 macro_import::slot
&
16676 macro_import::exported ()
16678 if (occupied_p () && !(*this)[0].get_module ())
16680 slot
&res
= (*this)[0];
16681 res
.bits
|= slot::L_DEF
;
16685 slot
*a
= &append (0, slot::L_DEF
);
16688 slot
&f
= (*this)[0];
16695 /* The import (&exported) macros. cpp_hasnode's deferred field
16696 indexes this array (offset by 1, so zero means 'not present'. */
16698 static vec
<macro_import
, va_heap
, vl_embed
> *macro_imports
;
16700 /* The exported macros. A macro_import slot's zeroth element's offset
16701 indexes this array. If the zeroth slot is not for module zero,
16702 there is no export. */
16704 static vec
<macro_export
, va_heap
, vl_embed
> *macro_exports
;
16706 /* The reachable set of header imports from this TU. */
16708 static GTY(()) bitmap headers
;
16710 /* Get the (possibly empty) macro imports for NODE. */
16712 static macro_import
&
16713 get_macro_imports (cpp_hashnode
*node
)
16715 if (node
->deferred
)
16716 return (*macro_imports
)[node
->deferred
- 1];
16718 vec_safe_reserve (macro_imports
, 1);
16719 node
->deferred
= macro_imports
->length () + 1;
16720 return *vec_safe_push (macro_imports
, macro_import ());
16723 /* Get the macro export for export EXP of NODE. */
16725 static macro_export
&
16726 get_macro_export (macro_import::slot
&slot
)
16728 if (slot
.offset
>= 0)
16729 return (*macro_exports
)[slot
.offset
];
16731 vec_safe_reserve (macro_exports
, 1);
16732 slot
.offset
= macro_exports
->length ();
16733 return *macro_exports
->quick_push (macro_export ());
16736 /* If NODE is an exportable macro, add it to the export set. */
16739 maybe_add_macro (cpp_reader
*, cpp_hashnode
*node
, void *data_
)
16741 bool exporting
= false;
16743 if (cpp_user_macro_p (node
))
16744 if (cpp_macro
*macro
= node
->value
.macro
)
16745 /* Ignore imported, builtins, command line and forced header macros. */
16746 if (!macro
->imported_p
16747 && !macro
->lazy
&& macro
->line
>= spans
.main_start ())
16749 gcc_checking_assert (macro
->kind
== cmk_macro
);
16750 /* I don't want to deal with this corner case, that I suspect is
16751 a devil's advocate reading of the standard. */
16752 gcc_checking_assert (!macro
->extra_tokens
);
16754 macro_import::slot
&slot
= get_macro_imports (node
).exported ();
16755 macro_export
&exp
= get_macro_export (slot
);
16760 if (!exporting
&& node
->deferred
)
16762 macro_import
&imports
= (*macro_imports
)[node
->deferred
- 1];
16763 macro_import::slot
&slot
= imports
[0];
16764 if (!slot
.get_module ())
16766 gcc_checking_assert (slot
.get_defness ());
16772 static_cast<vec
<cpp_hashnode
*> *> (data_
)->safe_push (node
);
16774 return 1; /* Don't stop. */
16777 /* Order cpp_hashnodes A_ and B_ by their exported macro locations. */
16780 macro_loc_cmp (const void *a_
, const void *b_
)
16782 const cpp_hashnode
*node_a
= *(const cpp_hashnode
*const *)a_
;
16783 macro_import
&import_a
= (*macro_imports
)[node_a
->deferred
- 1];
16784 const macro_export
&export_a
= (*macro_exports
)[import_a
[0].offset
];
16785 location_t loc_a
= export_a
.def
? export_a
.def
->line
: export_a
.undef_loc
;
16787 const cpp_hashnode
*node_b
= *(const cpp_hashnode
*const *)b_
;
16788 macro_import
&import_b
= (*macro_imports
)[node_b
->deferred
- 1];
16789 const macro_export
&export_b
= (*macro_exports
)[import_b
[0].offset
];
16790 location_t loc_b
= export_b
.def
? export_b
.def
->line
: export_b
.undef_loc
;
16794 else if (loc_a
> loc_b
)
16800 /* Write out the exported defines. This is two sections, one
16801 containing the definitions, the other a table of node names. */
16804 module_state::write_macros (elf_out
*to
, cpp_reader
*reader
, unsigned *crc_p
)
16806 dump () && dump ("Writing macros");
16809 vec
<cpp_hashnode
*> macros
;
16810 macros
.create (100);
16811 cpp_forall_identifiers (reader
, maybe_add_macro
, ¯os
);
16813 dump (dumper::MACRO
) && dump ("No more than %u macros", macros
.length ());
16815 macros
.qsort (macro_loc_cmp
);
16817 /* Write the defs */
16818 bytes_out
sec (to
);
16821 unsigned count
= 0;
16822 for (unsigned ix
= macros
.length (); ix
--;)
16824 cpp_hashnode
*node
= macros
[ix
];
16825 macro_import::slot
&slot
= (*macro_imports
)[node
->deferred
- 1][0];
16826 gcc_assert (!slot
.get_module () && slot
.get_defness ());
16828 macro_export
&mac
= (*macro_exports
)[slot
.offset
];
16829 gcc_assert (!!(slot
.get_defness () & macro_import::slot::L_UNDEF
)
16830 == (mac
.undef_loc
!= UNKNOWN_LOCATION
)
16831 && !!(slot
.get_defness () & macro_import::slot::L_DEF
)
16832 == (mac
.def
!= NULL
));
16834 if (IDENTIFIER_KEYWORD_P (identifier (node
)))
16836 warning_at (mac
.def
->line
, 0,
16837 "not exporting %<#define %E%> as it is a keyword",
16838 identifier (node
));
16844 slot
.offset
= sec
.pos
;
16845 dump (dumper::MACRO
)
16846 && dump ("Writing macro %s%s%s %I at %u",
16847 slot
.get_defness () & macro_import::slot::L_UNDEF
16849 slot
.get_defness () == macro_import::slot::L_BOTH
16851 slot
.get_defness () & macro_import::slot::L_DEF
16853 identifier (node
), slot
.offset
);
16854 if (mac
.undef_loc
!= UNKNOWN_LOCATION
)
16855 write_location (sec
, mac
.undef_loc
);
16857 write_define (sec
, mac
.def
);
16859 sec
.end (to
, to
->name (MOD_SNAME_PFX
".def"), crc_p
);
16863 /* Write the table. */
16864 bytes_out
sec (to
);
16868 for (unsigned ix
= macros
.length (); ix
--;)
16870 const cpp_hashnode
*node
= macros
[ix
];
16871 macro_import::slot
&slot
= (*macro_imports
)[node
->deferred
- 1][0];
16875 sec
.cpp_node (node
);
16876 sec
.u (slot
.get_defness ());
16877 sec
.u (slot
.offset
);
16880 sec
.end (to
, to
->name (MOD_SNAME_PFX
".mac"), crc_p
);
16889 module_state::read_macros ()
16891 /* Get the def section. */
16892 if (!slurp
->macro_defs
.begin (loc
, from (), MOD_SNAME_PFX
".def"))
16895 /* Get the tbl section, if there are defs. */
16896 if (slurp
->macro_defs
.more_p ()
16897 && !slurp
->macro_tbl
.begin (loc
, from (), MOD_SNAME_PFX
".mac"))
16903 /* Install the macro name table. */
16906 module_state::install_macros ()
16908 bytes_in
&sec
= slurp
->macro_tbl
;
16912 dump () && dump ("Reading macro table %M", this);
16915 unsigned count
= sec
.u ();
16916 dump () && dump ("%u macros", count
);
16919 cpp_hashnode
*node
= sec
.cpp_node ();
16920 macro_import
&imp
= get_macro_imports (node
);
16921 unsigned flags
= sec
.u () & macro_import::slot::L_BOTH
;
16923 sec
.set_overrun ();
16925 if (sec
.get_overrun ())
16928 macro_import::slot
&slot
= imp
.append (mod
, flags
);
16929 slot
.offset
= sec
.u ();
16931 dump (dumper::MACRO
)
16932 && dump ("Read %s macro %s%s%s %I at %u",
16933 imp
.length () > 1 ? "add" : "new",
16934 flags
& macro_import::slot::L_UNDEF
? "#undef" : "",
16935 flags
== macro_import::slot::L_BOTH
? " & " : "",
16936 flags
& macro_import::slot::L_DEF
? "#define" : "",
16937 identifier (node
), slot
.offset
);
16939 /* We'll leak an imported definition's TOKEN_FLD_STR's data
16940 here. But that only happens when we've had to resolve the
16941 deferred macro before this import -- why are you doing
16943 if (cpp_macro
*cur
= cpp_set_deferred_macro (node
))
16944 if (!cur
->imported_p
)
16946 macro_import::slot
&slot
= imp
.exported ();
16947 macro_export
&exp
= get_macro_export (slot
);
16949 dump (dumper::MACRO
)
16950 && dump ("Saving current #define %I", identifier (node
));
16954 /* We're now done with the table. */
16955 elf_in::release (slurp
->from
, sec
);
16960 /* Import the transitive macros. */
16963 module_state::import_macros ()
16965 bitmap_ior_into (headers
, slurp
->headers
);
16967 bitmap_iterator bititer
;
16969 EXECUTE_IF_SET_IN_BITMAP (slurp
->headers
, 0, bitnum
, bititer
)
16970 (*modules
)[bitnum
]->install_macros ();
16973 /* NODE is being undefined at LOC. Record it in the export table, if
16977 module_state::undef_macro (cpp_reader
*, location_t loc
, cpp_hashnode
*node
)
16979 if (!node
->deferred
)
16980 /* The macro is not imported, so our undef is irrelevant. */
16983 unsigned n
= dump
.push (NULL
);
16985 macro_import::slot
&slot
= (*macro_imports
)[node
->deferred
- 1].exported ();
16986 macro_export
&exp
= get_macro_export (slot
);
16988 exp
.undef_loc
= loc
;
16989 slot
.become_undef ();
16992 dump (dumper::MACRO
) && dump ("Recording macro #undef %I", identifier (node
));
16997 /* NODE is a deferred macro node. Determine the definition and return
16998 it, with NULL if undefined. May issue diagnostics.
17000 This can leak memory, when merging declarations -- the string
17001 contents (TOKEN_FLD_STR) of each definition are allocated in
17002 unreclaimable cpp objstack. Only one will win. However, I do not
17003 expect this to be common -- mostly macros have a single point of
17004 definition. Perhaps we could restore the objstack to its position
17005 after the first imported definition (if that wins)? The macros
17006 themselves are GC'd. */
17009 module_state::deferred_macro (cpp_reader
*reader
, location_t loc
,
17010 cpp_hashnode
*node
)
17012 macro_import
&imports
= (*macro_imports
)[node
->deferred
- 1];
17014 unsigned n
= dump
.push (NULL
);
17015 dump (dumper::MACRO
) && dump ("Deferred macro %I", identifier (node
));
17017 bitmap
visible (BITMAP_GGC_ALLOC ());
17019 if (!((imports
[0].get_defness () & macro_import::slot::L_UNDEF
)
17020 && !imports
[0].get_module ()))
17022 /* Calculate the set of visible header imports. */
17023 bitmap_copy (visible
, headers
);
17024 for (unsigned ix
= imports
.length (); ix
--;)
17026 const macro_import::slot
&slot
= imports
[ix
];
17027 unsigned mod
= slot
.get_module ();
17028 if ((slot
.get_defness () & macro_import::slot::L_UNDEF
)
17029 && bitmap_bit_p (visible
, mod
))
17031 bitmap arg
= mod
? (*modules
)[mod
]->slurp
->headers
: headers
;
17032 bitmap_and_compl_into (visible
, arg
);
17033 bitmap_set_bit (visible
, mod
);
17037 bitmap_set_bit (visible
, 0);
17039 /* Now find the macros that are still visible. */
17040 bool failed
= false;
17041 cpp_macro
*def
= NULL
;
17042 vec
<macro_export
> defs
;
17043 defs
.create (imports
.length ());
17044 for (unsigned ix
= imports
.length (); ix
--;)
17046 const macro_import::slot
&slot
= imports
[ix
];
17047 unsigned mod
= slot
.get_module ();
17048 if (bitmap_bit_p (visible
, mod
))
17050 macro_export
*pushed
= NULL
;
17053 const module_state
*imp
= (*modules
)[mod
];
17054 bytes_in
&sec
= imp
->slurp
->macro_defs
;
17055 if (!sec
.get_overrun ())
17057 dump (dumper::MACRO
)
17058 && dump ("Reading macro %s%s%s %I module %M at %u",
17059 slot
.get_defness () & macro_import::slot::L_UNDEF
17061 slot
.get_defness () == macro_import::slot::L_BOTH
17063 slot
.get_defness () & macro_import::slot::L_DEF
17065 identifier (node
), imp
, slot
.offset
);
17066 sec
.random_access (slot
.offset
);
17069 if (slot
.get_defness () & macro_import::slot::L_UNDEF
)
17070 exp
.undef_loc
= imp
->read_location (sec
);
17071 if (slot
.get_defness () & macro_import::slot::L_DEF
)
17072 exp
.def
= imp
->read_define (sec
, reader
);
17073 if (sec
.get_overrun ())
17074 error_at (loc
, "macro definitions of %qE corrupted",
17077 pushed
= defs
.quick_push (exp
);
17081 pushed
= defs
.quick_push ((*macro_exports
)[slot
.offset
]);
17082 if (pushed
&& pushed
->def
)
17086 else if (cpp_compare_macros (def
, pushed
->def
))
17094 /* If LOC is the first loc, this is the end of file check, which
17096 if (loc
== MAP_START_LOCATION (LINEMAPS_ORDINARY_MAP_AT (line_table
, 0)))
17097 warning_at (loc
, OPT_Winvalid_imported_macros
,
17098 "inconsistent imported macro definition %qE",
17099 identifier (node
));
17101 error_at (loc
, "inconsistent imported macro definition %qE",
17102 identifier (node
));
17103 for (unsigned ix
= defs
.length (); ix
--;)
17105 macro_export
&exp
= defs
[ix
];
17107 inform (exp
.undef_loc
, "%<#undef %E%>", identifier (node
));
17109 inform (exp
.def
->line
, "%<#define %s%>",
17110 cpp_macro_definition (reader
, node
, exp
.def
));
17122 /* Stream the static aggregates. Sadly some headers (ahem:
17123 iostream) contain static vars, and rely on them to run global
17126 module_state::write_inits (elf_out
*to
, depset::hash
&table
, unsigned *crc_ptr
)
17128 if (!static_aggregates
&& !tls_aggregates
)
17131 dump () && dump ("Writing initializers");
17134 static_aggregates
= nreverse (static_aggregates
);
17135 tls_aggregates
= nreverse (tls_aggregates
);
17137 unsigned count
= 0;
17138 trees_out
sec (to
, this, table
, ~0u);
17141 tree list
= static_aggregates
;
17142 for (int passes
= 0; passes
!= 2; passes
++)
17144 for (tree init
= list
; init
; init
= TREE_CHAIN (init
), count
++)
17145 if (TREE_LANG_FLAG_0 (init
))
17147 tree decl
= TREE_VALUE (init
);
17149 dump ("Initializer:%u for %N", count
, decl
);
17150 sec
.tree_node (decl
);
17153 list
= tls_aggregates
;
17156 sec
.end (to
, to
->name (MOD_SNAME_PFX
".ini"), crc_ptr
);
17163 module_state::read_inits (unsigned count
)
17165 trees_in
sec (this);
17166 if (!sec
.begin (loc
, from (), from ()->find (MOD_SNAME_PFX
".ini")))
17168 dump () && dump ("Reading %u initializers", count
);
17171 for (unsigned ix
= 0; ix
!= count
; ix
++)
17173 /* Merely referencing the decl causes its initializer to be read
17174 and added to the correct list. */
17175 tree decl
= sec
.tree_node ();
17177 if (sec
.get_overrun ())
17180 dump ("Initializer:%u for %N", count
, decl
);
17183 if (!sec
.end (from ()))
17189 module_state::write_counts (elf_out
*to
, unsigned counts
[MSC_HWM
],
17192 bytes_out
cfg (to
);
17196 for (unsigned ix
= MSC_HWM
; ix
--;)
17197 cfg
.u (counts
[ix
]);
17201 dump ("Cluster sections are [%u,%u)",
17202 counts
[MSC_sec_lwm
], counts
[MSC_sec_hwm
]);
17203 dump ("Bindings %u", counts
[MSC_bindings
]);
17204 dump ("Pendings %u", counts
[MSC_pendings
]);
17205 dump ("Entities %u", counts
[MSC_entities
]);
17206 dump ("Namespaces %u", counts
[MSC_namespaces
]);
17207 dump ("Macros %u", counts
[MSC_macros
]);
17208 dump ("Initializers %u", counts
[MSC_inits
]);
17211 cfg
.end (to
, to
->name (MOD_SNAME_PFX
".cnt"), crc_ptr
);
17215 module_state::read_counts (unsigned counts
[MSC_HWM
])
17219 if (!cfg
.begin (loc
, from (), MOD_SNAME_PFX
".cnt"))
17222 for (unsigned ix
= MSC_HWM
; ix
--;)
17223 counts
[ix
] = cfg
.u ();
17227 dump ("Declaration sections are [%u,%u)",
17228 counts
[MSC_sec_lwm
], counts
[MSC_sec_hwm
]);
17229 dump ("Bindings %u", counts
[MSC_bindings
]);
17230 dump ("Pendings %u", counts
[MSC_pendings
]);
17231 dump ("Entities %u", counts
[MSC_entities
]);
17232 dump ("Namespaces %u", counts
[MSC_namespaces
]);
17233 dump ("Macros %u", counts
[MSC_macros
]);
17234 dump ("Initializers %u", counts
[MSC_inits
]);
17237 return cfg
.end (from ());
17240 /* Tool configuration: MOD_SNAME_PFX .config
17242 This is data that confirms current state (or fails). */
17245 module_state::write_config (elf_out
*to
, module_state_config
&config
,
17246 unsigned inner_crc
)
17248 bytes_out
cfg (to
);
17252 /* Write version and inner crc as u32 values, for easier
17253 debug inspection. */
17254 dump () && dump ("Writing version=%V, inner_crc=%x",
17255 MODULE_VERSION
, inner_crc
);
17256 cfg
.u32 (unsigned (MODULE_VERSION
));
17257 cfg
.u32 (inner_crc
);
17259 cfg
.u (to
->name (is_header () ? "" : get_flatname ()));
17261 /* Configuration. */
17262 dump () && dump ("Writing target='%s', host='%s'",
17263 TARGET_MACHINE
, HOST_MACHINE
);
17264 unsigned target
= to
->name (TARGET_MACHINE
);
17265 unsigned host
= (!strcmp (TARGET_MACHINE
, HOST_MACHINE
)
17266 ? target
: to
->name (HOST_MACHINE
));
17270 cfg
.str (config
.dialect_str
);
17271 cfg
.u (extensions
);
17273 /* Global tree information. We write the globals crc separately,
17274 rather than mix it directly into the overall crc, as it is used
17275 to ensure data match between instances of the compiler, not
17276 integrity of the file. */
17277 dump () && dump ("Writing globals=%u, crc=%x",
17278 fixed_trees
->length (), global_crc
);
17279 cfg
.u (fixed_trees
->length ());
17280 cfg
.u32 (global_crc
);
17282 if (is_partition ())
17283 cfg
.u (is_interface ());
17285 cfg
.u (config
.num_imports
);
17286 cfg
.u (config
.num_partitions
);
17288 cfg
.u (config
.ordinary_locs
);
17289 cfg
.u (config
.macro_locs
);
17290 cfg
.u (config
.ordinary_loc_align
);
17292 /* Now generate CRC, we'll have incorporated the inner CRC because
17293 of its serialization above. */
17294 cfg
.end (to
, to
->name (MOD_SNAME_PFX
".cfg"), &crc
);
17295 dump () && dump ("Writing CRC=%x", crc
);
17299 module_state::note_cmi_name ()
17301 if (!cmi_noted_p
&& filename
)
17303 cmi_noted_p
= true;
17304 inform (loc
, "compiled module file is %qs",
17305 maybe_add_cmi_prefix (filename
));
17310 module_state::read_config (module_state_config
&config
)
17314 if (!cfg
.begin (loc
, from (), MOD_SNAME_PFX
".cfg"))
17317 /* Check version. */
17318 unsigned my_ver
= MODULE_VERSION
;
17319 unsigned their_ver
= cfg
.u32 ();
17320 dump () && dump (my_ver
== their_ver
? "Version %V"
17321 : "Expecting %V found %V", my_ver
, their_ver
);
17322 if (their_ver
!= my_ver
)
17324 /* The compiler versions differ. Close enough? */
17325 verstr_t my_string
, their_string
;
17327 version2string (my_ver
, my_string
);
17328 version2string (their_ver
, their_string
);
17330 /* Reject when either is non-experimental or when experimental
17331 major versions differ. */
17332 bool reject_p
= ((!IS_EXPERIMENTAL (my_ver
)
17333 || !IS_EXPERIMENTAL (their_ver
)
17334 || MODULE_MAJOR (my_ver
) != MODULE_MAJOR (their_ver
))
17335 /* The 'I know what I'm doing' switch. */
17336 && !flag_module_version_ignore
);
17337 bool inform_p
= true;
17340 cfg
.set_overrun ();
17341 error_at (loc
, "compiled module is %sversion %s",
17342 IS_EXPERIMENTAL (their_ver
) ? "experimental " : "",
17346 inform_p
= warning_at (loc
, 0, "compiled module is %sversion %s",
17347 IS_EXPERIMENTAL (their_ver
) ? "experimental " : "",
17352 inform (loc
, "compiler is %sversion %s%s%s",
17353 IS_EXPERIMENTAL (my_ver
) ? "experimental " : "",
17355 reject_p
? "" : flag_module_version_ignore
17356 ? ", be it on your own head!" : ", close enough?",
17357 reject_p
? "" : " \xc2\xaf\\_(\xe3\x83\x84)_/\xc2\xaf");
17365 /* We wrote the inner crc merely to merge it, so simply read it
17366 back and forget it. */
17369 /* Check module name. */
17371 const char *their_name
= from ()->name (cfg
.u ());
17372 const char *our_name
= "";
17375 our_name
= get_flatname ();
17377 /* Header units can be aliased, so name checking is
17379 if (0 != strcmp (their_name
, our_name
))
17382 their_name
[0] && our_name
[0] ? G_("module %qs found")
17384 ? G_("header module expected, module %qs found")
17385 : G_("module %qs expected, header module found"),
17386 their_name
[0] ? their_name
: our_name
);
17387 cfg
.set_overrun ();
17392 /* Check the CRC after the above sanity checks, so that the user is
17395 unsigned e_crc
= crc
;
17396 crc
= cfg
.get_crc ();
17397 dump () && dump ("Reading CRC=%x", crc
);
17398 if (!is_direct () && crc
!= e_crc
)
17400 error_at (loc
, "module %qs CRC mismatch", get_flatname ());
17401 cfg
.set_overrun ();
17406 /* Check target & host. */
17408 const char *their_target
= from ()->name (cfg
.u ());
17409 const char *their_host
= from ()->name (cfg
.u ());
17410 dump () && dump ("Read target='%s', host='%s'", their_target
, their_host
);
17411 if (strcmp (their_target
, TARGET_MACHINE
)
17412 || strcmp (their_host
, HOST_MACHINE
))
17414 error_at (loc
, "target & host is %qs:%qs, expected %qs:%qs",
17415 their_target
, TARGET_MACHINE
, their_host
, HOST_MACHINE
);
17416 cfg
.set_overrun ();
17421 /* Check compilation dialect. This must match. */
17423 const char *their_dialect
= cfg
.str ();
17424 if (strcmp (their_dialect
, config
.dialect_str
))
17426 error_at (loc
, "language dialect differs %qs, expected %qs",
17427 their_dialect
, config
.dialect_str
);
17428 cfg
.set_overrun ();
17433 /* Check for extensions. If they set any, we must have them set
17436 unsigned ext
= cfg
.u ();
17437 unsigned allowed
= (flag_openmp
? SE_OPENMP
: 0);
17439 if (unsigned bad
= ext
& ~allowed
)
17441 if (bad
& SE_OPENMP
)
17442 error_at (loc
, "module contains OpenMP, use %<-fopenmp%> to enable");
17443 cfg
.set_overrun ();
17449 /* Check global trees. */
17451 unsigned their_fixed_length
= cfg
.u ();
17452 unsigned their_fixed_crc
= cfg
.u32 ();
17453 dump () && dump ("Read globals=%u, crc=%x",
17454 their_fixed_length
, their_fixed_crc
);
17455 if (!flag_preprocess_only
17456 && (their_fixed_length
!= fixed_trees
->length ()
17457 || their_fixed_crc
!= global_crc
))
17459 error_at (loc
, "fixed tree mismatch");
17460 cfg
.set_overrun ();
17465 /* All non-partitions are interfaces. */
17466 interface_p
= !is_partition () || cfg
.u ();
17468 config
.num_imports
= cfg
.u ();
17469 config
.num_partitions
= cfg
.u ();
17471 config
.ordinary_locs
= cfg
.u ();
17472 config
.macro_locs
= cfg
.u ();
17473 config
.ordinary_loc_align
= cfg
.u ();
17476 return cfg
.end (from ());
17479 /* Use ELROND format to record the following sections:
17480 qualified-names : binding value(s)
17481 MOD_SNAME_PFX.README : human readable, strings
17482 MOD_SNAME_PFX.ENV : environment strings, strings
17483 MOD_SNAME_PFX.nms : namespace hierarchy
17484 MOD_SNAME_PFX.bnd : binding table
17485 MOD_SNAME_PFX.spc : specialization table
17486 MOD_SNAME_PFX.imp : import table
17487 MOD_SNAME_PFX.ent : entity table
17488 MOD_SNAME_PFX.prt : partitions table
17489 MOD_SNAME_PFX.olm : ordinary line maps
17490 MOD_SNAME_PFX.mlm : macro line maps
17491 MOD_SNAME_PFX.def : macro definitions
17492 MOD_SNAME_PFX.mac : macro index
17493 MOD_SNAME_PFX.ini : inits
17494 MOD_SNAME_PFX.cnt : counts
17495 MOD_SNAME_PFX.cfg : config data
17499 module_state::write (elf_out
*to
, cpp_reader
*reader
)
17501 /* Figure out remapped module numbers, which might elide
17503 bitmap partitions
= NULL
;
17504 if (!is_header () && !is_partition ())
17505 partitions
= BITMAP_GGC_ALLOC ();
17507 unsigned mod_hwm
= 1;
17508 for (unsigned ix
= 1; ix
!= modules
->length (); ix
++)
17510 module_state
*imp
= (*modules
)[ix
];
17512 /* Promote any non-partition direct import from a partition, unless
17513 we're a partition. */
17514 if (!is_partition () && !imp
->is_partition ()
17515 && imp
->is_partition_direct ())
17516 imp
->directness
= MD_PURVIEW_DIRECT
;
17518 /* Write any import that is not a partition, unless we're a
17520 if (!partitions
|| !imp
->is_partition ())
17521 imp
->remap
= mod_hwm
++;
17524 dump () && dump ("Partition %M %u", imp
, ix
);
17525 bitmap_set_bit (partitions
, ix
);
17527 /* All interface partitions must be exported. */
17528 if (imp
->is_interface () && !bitmap_bit_p (exports
, imp
->mod
))
17530 error_at (imp
->loc
, "interface partition is not exported");
17531 bitmap_set_bit (exports
, imp
->mod
);
17534 /* All the partition entities should have been loaded when
17535 loading the partition. */
17537 for (unsigned jx
= 0; jx
!= imp
->entity_num
; jx
++)
17539 binding_slot
*slot
= &(*entity_ary
)[imp
->entity_lwm
+ jx
];
17540 gcc_checking_assert (!slot
->is_lazy ());
17545 if (partitions
&& bitmap_empty_p (partitions
))
17546 /* No partitions present. */
17547 partitions
= nullptr;
17549 /* Find the set of decls we must write out. */
17550 depset::hash
table (DECL_NAMESPACE_BINDINGS (global_namespace
)->size () * 8);
17551 /* Add the specializations before the writables, so that we can
17552 detect injected friend specializations. */
17553 table
.add_specializations (true);
17554 table
.add_specializations (false);
17555 if (partial_specializations
)
17557 table
.add_partial_entities (partial_specializations
);
17558 partial_specializations
= NULL
;
17560 table
.add_namespace_entities (global_namespace
, partitions
);
17563 table
.add_class_entities (class_members
);
17564 class_members
= NULL
;
17567 /* Now join everything up. */
17568 table
.find_dependencies ();
17570 if (!table
.finalize_dependencies ())
17577 /* We're done verifying at-most once reading, reset to verify
17578 at-most once writing. */
17579 note_defs
= note_defs_table_t::create_ggc (1000);
17582 /* Determine Strongy Connected Components. */
17583 vec
<depset
*> sccs
= table
.connect ();
17586 module_state_config config
;
17587 location_map_info map_info
= write_prepare_maps (&config
);
17588 unsigned counts
[MSC_HWM
];
17590 config
.num_imports
= mod_hwm
;
17591 config
.num_partitions
= modules
->length () - mod_hwm
;
17592 memset (counts
, 0, sizeof (counts
));
17594 /* depset::cluster is the cluster number,
17595 depset::section is unspecified scratch value.
17597 The following loops make use of the tarjan property that
17598 dependencies will be earlier in the SCCS array. */
17600 /* This first loop determines the number of depsets in each SCC, and
17601 also the number of namespaces we're dealing with. During the
17602 loop, the meaning of a couple of depset fields now change:
17604 depset::cluster -> size_of cluster, if first of cluster & !namespace
17605 depset::section -> section number of cluster (if !namespace). */
17607 unsigned n_spaces
= 0;
17608 counts
[MSC_sec_lwm
] = counts
[MSC_sec_hwm
] = to
->get_section_limit ();
17609 for (unsigned size
, ix
= 0; ix
< sccs
.length (); ix
+= size
)
17611 depset
**base
= &sccs
[ix
];
17613 if (base
[0]->get_entity_kind () == depset::EK_NAMESPACE
)
17620 /* Count the members in this cluster. */
17621 for (size
= 1; ix
+ size
< sccs
.length (); size
++)
17622 if (base
[size
]->cluster
!= base
[0]->cluster
)
17625 for (unsigned jx
= 0; jx
!= size
; jx
++)
17627 /* Set the section number. */
17628 base
[jx
]->cluster
= ~(~0u >> 1); /* A bad value. */
17629 base
[jx
]->section
= counts
[MSC_sec_hwm
];
17632 /* Save the size in the first member's cluster slot. */
17633 base
[0]->cluster
= size
;
17635 counts
[MSC_sec_hwm
]++;
17639 /* Write the clusters. Namespace decls are put in the spaces array.
17640 The meaning of depset::cluster changes to provide the
17641 unnamed-decl count of the depset's decl (and remains zero for
17642 non-decls and non-unnamed). */
17643 unsigned bytes
= 0;
17644 vec
<depset
*> spaces
;
17645 spaces
.create (n_spaces
);
17647 for (unsigned size
, ix
= 0; ix
< sccs
.length (); ix
+= size
)
17649 depset
**base
= &sccs
[ix
];
17651 if (base
[0]->get_entity_kind () == depset::EK_NAMESPACE
)
17653 tree decl
= base
[0]->get_entity ();
17654 if (decl
== global_namespace
)
17655 base
[0]->cluster
= 0;
17656 else if (!base
[0]->is_import ())
17658 base
[0]->cluster
= counts
[MSC_entities
]++;
17659 spaces
.quick_push (base
[0]);
17660 counts
[MSC_namespaces
]++;
17663 /* Add it to the entity map, such that we can tell it is
17666 unsigned *slot
= &entity_map
->get_or_insert
17667 (DECL_UID (decl
), &existed
);
17669 /* It must have come from a partition. */
17670 gcc_checking_assert
17671 (import_entity_module (*slot
)->is_partition ());
17672 *slot
= ~base
[0]->cluster
;
17674 dump (dumper::CLUSTER
) && dump ("Cluster namespace %N", decl
);
17680 size
= base
[0]->cluster
;
17682 /* Cluster is now used to number entities. */
17683 base
[0]->cluster
= ~(~0u >> 1); /* A bad value. */
17685 sort_cluster (&table
, base
, size
);
17687 /* Record the section for consistency checking during stream
17688 out -- we don't want to start writing decls in different
17690 table
.section
= base
[0]->section
;
17691 bytes
+= write_cluster (to
, base
, size
, table
, counts
, &crc
);
17696 /* We'd better have written as many sections and found as many
17697 namespaces as we predicted. */
17698 gcc_assert (counts
[MSC_sec_hwm
] == to
->get_section_limit ()
17699 && spaces
.length () == counts
[MSC_namespaces
]);
17701 /* Write the entitites. None happens if we contain namespaces or
17703 if (counts
[MSC_entities
])
17704 write_entities (to
, sccs
, counts
[MSC_entities
], &crc
);
17706 /* Write the namespaces. */
17707 if (counts
[MSC_namespaces
])
17708 write_namespaces (to
, spaces
, counts
[MSC_namespaces
], &crc
);
17710 /* Write the bindings themselves. */
17711 counts
[MSC_bindings
] = write_bindings (to
, sccs
, &crc
);
17713 /* Write the unnamed. */
17714 if (counts
[MSC_pendings
])
17715 write_pendings (to
, sccs
, table
, counts
[MSC_pendings
], &crc
);
17717 /* Write the import table. */
17718 if (config
.num_imports
> 1)
17719 write_imports (to
, &crc
);
17721 /* Write elided partition table. */
17722 if (config
.num_partitions
)
17723 write_partitions (to
, config
.num_partitions
, &crc
);
17725 /* Write the line maps. */
17726 write_ordinary_maps (to
, map_info
, &config
, config
.num_partitions
, &crc
);
17727 write_macro_maps (to
, map_info
, &config
, &crc
);
17731 counts
[MSC_macros
] = write_macros (to
, reader
, &crc
);
17732 counts
[MSC_inits
] = write_inits (to
, table
, &crc
);
17735 unsigned clusters
= counts
[MSC_sec_hwm
] - counts
[MSC_sec_lwm
];
17736 dump () && dump ("Wrote %u clusters, average %u bytes/cluster",
17737 clusters
, (bytes
+ clusters
/ 2) / (clusters
+ !clusters
));
17739 write_counts (to
, counts
, &crc
);
17741 /* And finish up. */
17742 write_config (to
, config
, crc
);
17747 /* Human-readable info. */
17748 write_readme (to
, reader
, config
.dialect_str
, extensions
);
17750 // FIXME:QOI: Have a command line switch to control more detailed
17751 // information (which might leak data you do not want to leak).
17752 // Perhaps (some of) the write_readme contents should also be
17757 trees_out::instrument ();
17758 dump () && dump ("Wrote %u sections", to
->get_section_limit ());
17761 /* Initial read of a CMI. Checks config, loads up imports and line
17765 module_state::read_initial (cpp_reader
*reader
)
17767 module_state_config config
;
17770 if (ok
&& !from ()->begin (loc
))
17773 if (ok
&& !read_config (config
))
17776 bool have_locs
= ok
&& read_prepare_maps (&config
);
17778 /* Ordinary maps before the imports. */
17779 if (have_locs
&& !read_ordinary_maps ())
17782 /* Allocate the REMAP vector. */
17783 slurp
->alloc_remap (config
.num_imports
);
17787 /* Read the import table. Decrement current to stop this CMI
17788 from being evicted during the import. */
17790 if (config
.num_imports
> 1 && !read_imports (reader
, line_table
))
17795 /* Read the elided partition table, if we're the primary partition. */
17796 if (ok
&& config
.num_partitions
&& is_module ()
17797 && !read_partitions (config
.num_partitions
))
17800 /* Determine the module's number. */
17801 gcc_checking_assert (mod
== MODULE_UNKNOWN
);
17802 gcc_checking_assert (this != (*modules
)[0]);
17804 /* We'll run out of other resources before we run out of module
17806 mod
= modules
->length ();
17807 vec_safe_push (modules
, this);
17809 /* We always import and export ourselves. */
17810 bitmap_set_bit (imports
, mod
);
17811 bitmap_set_bit (exports
, mod
);
17814 (*slurp
->remap
)[0] = mod
<< 1;
17815 dump () && dump ("Assigning %M module number %u", this, mod
);
17817 /* We should not have been frozen during the importing done by
17819 gcc_assert (!from ()->is_frozen ());
17821 /* Macro maps after the imports. */
17822 if (ok
&& have_locs
&& !read_macro_maps ())
17825 gcc_assert (slurp
->current
== ~0u);
17829 /* Read a preprocessor state. */
17832 module_state::read_preprocessor (bool outermost
)
17834 gcc_checking_assert (is_header () && slurp
17835 && slurp
->remap_module (0) == mod
);
17837 if (loadedness
== ML_PREPROCESSOR
)
17838 return !(from () && from ()->get_error ());
17842 /* Read direct header imports. */
17843 unsigned len
= slurp
->remap
->length ();
17844 for (unsigned ix
= 1; ok
&& ix
!= len
; ix
++)
17846 unsigned map
= (*slurp
->remap
)[ix
];
17849 module_state
*import
= (*modules
)[map
>> 1];
17850 if (import
->is_header ())
17852 ok
= import
->read_preprocessor (false);
17853 bitmap_ior_into (slurp
->headers
, import
->slurp
->headers
);
17858 /* Record as a direct header. */
17860 bitmap_set_bit (slurp
->headers
, mod
);
17862 if (ok
&& !read_macros ())
17865 loadedness
= ML_PREPROCESSOR
;
17866 announce ("macros");
17868 if (flag_preprocess_only
)
17869 /* We're done with the string table. */
17870 from ()->release ();
17872 return check_read (outermost
, ok
);
17875 static unsigned lazy_snum
;
17878 recursive_lazy (unsigned snum
= ~0u)
17882 error_at (input_location
, "recursive lazy load");
17890 /* Read language state. */
17893 module_state::read_language (bool outermost
)
17895 gcc_checking_assert (!lazy_snum
);
17897 if (loadedness
== ML_LANGUAGE
)
17898 return !(slurp
&& from () && from ()->get_error ());
17900 gcc_checking_assert (slurp
&& slurp
->current
== ~0u
17901 && slurp
->remap_module (0) == mod
);
17905 /* Read direct imports. */
17906 unsigned len
= slurp
->remap
->length ();
17907 for (unsigned ix
= 1; ok
&& ix
!= len
; ix
++)
17909 unsigned map
= (*slurp
->remap
)[ix
];
17912 module_state
*import
= (*modules
)[map
>> 1];
17913 if (!import
->read_language (false))
17918 unsigned counts
[MSC_HWM
];
17920 if (ok
&& !read_counts (counts
))
17923 function_depth
++; /* Prevent unexpected GCs. */
17925 /* Read the entity table. */
17926 entity_lwm
= vec_safe_length (entity_ary
);
17927 if (ok
&& counts
[MSC_entities
]
17928 && !read_entities (counts
[MSC_entities
],
17929 counts
[MSC_sec_lwm
], counts
[MSC_sec_hwm
]))
17932 /* Read the namespace hierarchy. */
17933 if (ok
&& counts
[MSC_namespaces
]
17934 && !read_namespaces (counts
[MSC_namespaces
]))
17937 if (ok
&& !read_bindings (counts
[MSC_bindings
],
17938 counts
[MSC_sec_lwm
], counts
[MSC_sec_hwm
]))
17942 if (ok
&& counts
[MSC_pendings
] && !read_pendings (counts
[MSC_pendings
]))
17947 slurp
->remaining
= counts
[MSC_sec_hwm
] - counts
[MSC_sec_lwm
];
17948 available_clusters
+= counts
[MSC_sec_hwm
] - counts
[MSC_sec_lwm
];
17951 if (!flag_module_lazy
17952 || (is_partition ()
17953 && module_interface_p ()
17954 && !module_partition_p ()))
17956 /* Read the sections in forward order, so that dependencies are read
17957 first. See note about tarjan_connect. */
17962 unsigned hwm
= counts
[MSC_sec_hwm
];
17963 for (unsigned ix
= counts
[MSC_sec_lwm
]; ok
&& ix
!= hwm
; ix
++)
17965 if (!load_section (ix
, NULL
))
17975 if (ok
&& CHECKING_P
)
17976 for (unsigned ix
= 0; ix
!= entity_num
; ix
++)
17977 gcc_assert (!(*entity_ary
)[ix
+ entity_lwm
].is_lazy ());
17980 // If the import is a header-unit, we need to register initializers
17981 // of any static objects it contains (looking at you _Ioinit).
17982 // Notice, the ordering of these initializers will be that of a
17983 // dynamic initializer at this point in the current TU. (Other
17984 // instances of these objects in other TUs will be initialized as
17985 // part of that TU's global initializers.)
17986 if (ok
&& counts
[MSC_inits
] && !read_inits (counts
[MSC_inits
]))
17991 announce (flag_module_lazy
? "lazy" : "imported");
17992 loadedness
= ML_LANGUAGE
;
17994 gcc_assert (slurp
->current
== ~0u);
17996 /* We're done with the string table. */
17997 from ()->release ();
17999 return check_read (outermost
, ok
);
18003 module_state::maybe_defrost ()
18006 if (from ()->is_frozen ())
18008 if (lazy_open
>= lazy_limit
)
18010 dump () && dump ("Defrosting '%s'", filename
);
18011 ok
= from ()->defrost (maybe_add_cmi_prefix (filename
));
18018 /* Load section SNUM, dealing with laziness. It doesn't matter if we
18019 have multiple concurrent loads, because we do not use TREE_VISITED
18020 when reading back in. */
18023 module_state::load_section (unsigned snum
, binding_slot
*mslot
)
18025 if (from ()->get_error ())
18028 if (snum
>= slurp
->current
)
18029 from ()->set_error (elf::E_BAD_LAZY
);
18030 else if (maybe_defrost ())
18032 unsigned old_current
= slurp
->current
;
18033 slurp
->current
= snum
;
18034 slurp
->lru
= 0; /* Do not swap out. */
18035 slurp
->remaining
--;
18036 read_cluster (snum
);
18037 slurp
->lru
= ++lazy_lru
;
18038 slurp
->current
= old_current
;
18041 if (mslot
&& mslot
->is_lazy ())
18043 /* Oops, the section didn't set this slot. */
18044 from ()->set_error (elf::E_BAD_DATA
);
18045 *mslot
= NULL_TREE
;
18048 bool ok
= !from ()->get_error ();
18051 error_at (loc
, "failed to read compiled module cluster %u: %s",
18052 snum
, from ()->get_error (filename
));
18056 maybe_completed_reading ();
18062 module_state::maybe_completed_reading ()
18064 if (loadedness
== ML_LANGUAGE
&& slurp
->current
== ~0u && !slurp
->remaining
)
18067 /* We no longer need the macros, all tokenizing has been done. */
18068 slurp
->release_macros ();
18076 /* After a reading operation, make sure things are still ok. If not,
18077 emit an error and clean up. */
18080 module_state::check_read (bool outermost
, bool ok
)
18082 gcc_checking_assert (!outermost
|| slurp
->current
== ~0u);
18085 from ()->set_error ();
18087 if (int e
= from ()->get_error ())
18089 error_at (loc
, "failed to read compiled module: %s",
18090 from ()->get_error (filename
));
18099 inform (loc
, "consider using %<-fno-module-lazy%>,"
18100 " increasing %<-param-lazy-modules=%u%> value,"
18101 " or increasing the per-process file descriptor limit",
18102 param_lazy_modules
);
18103 else if (e
== ENOENT
)
18104 inform (loc
, "imports must be built before being imported");
18107 fatal_error (loc
, "returning to the gate for a mechanical issue");
18112 maybe_completed_reading ();
18117 /* Return the IDENTIFIER_NODE naming module IX. This is the name
18121 module_name (unsigned ix
, bool header_ok
)
18125 module_state
*imp
= (*modules
)[ix
];
18127 if (ix
&& !imp
->name
)
18130 if (header_ok
|| !imp
->is_header ())
18131 return imp
->get_flatname ();
18137 /* Return the bitmap describing what modules are imported. Remember,
18138 we always import ourselves. */
18141 get_import_bitmap ()
18143 return (*modules
)[0]->imports
;
18146 /* Return the visible imports and path of instantiation for an
18147 instantiation at TINST. If TINST is nullptr, we're not in an
18148 instantiation, and thus will return the visible imports of the
18149 current TU (and NULL *PATH_MAP_P). We cache the information on
18150 the tinst level itself. */
18153 path_of_instantiation (tinst_level
*tinst
, bitmap
*path_map_p
)
18155 gcc_checking_assert (modules_p ());
18159 /* Not inside an instantiation, just the regular case. */
18160 *path_map_p
= nullptr;
18161 return get_import_bitmap ();
18167 bitmap visible
= path_of_instantiation (tinst
->next
, path_map_p
);
18168 bitmap path_map
= *path_map_p
;
18172 path_map
= BITMAP_GGC_ALLOC ();
18173 bitmap_set_bit (path_map
, 0);
18176 tree decl
= tinst
->tldcl
;
18177 if (TREE_CODE (decl
) == TREE_LIST
)
18178 decl
= TREE_PURPOSE (decl
);
18180 decl
= TYPE_NAME (decl
);
18182 if (unsigned mod
= get_originating_module (decl
))
18183 if (!bitmap_bit_p (path_map
, mod
))
18185 /* This is brand new information! */
18186 bitmap new_path
= BITMAP_GGC_ALLOC ();
18187 bitmap_copy (new_path
, path_map
);
18188 bitmap_set_bit (new_path
, mod
);
18189 path_map
= new_path
;
18191 bitmap imports
= (*modules
)[mod
]->imports
;
18192 if (bitmap_intersect_compl_p (imports
, visible
))
18194 /* IMPORTS contains additional modules to VISIBLE. */
18195 bitmap new_visible
= BITMAP_GGC_ALLOC ();
18197 bitmap_ior (new_visible
, visible
, imports
);
18198 visible
= new_visible
;
18202 tinst
->path
= path_map
;
18203 tinst
->visible
= visible
;
18206 *path_map_p
= tinst
->path
;
18207 return tinst
->visible
;
18210 /* Return the bitmap describing what modules are visible along the
18211 path of instantiation. If we're not an instantiation, this will be
18212 the visible imports of the TU. *PATH_MAP_P is filled in with the
18213 modules owning the instantiation path -- we see the module-linkage
18214 entities of those modules. */
18217 visible_instantiation_path (bitmap
*path_map_p
)
18222 return path_of_instantiation (current_instantiation (), path_map_p
);
18225 /* We've just directly imported IMPORT. Update our import/export
18226 bitmaps. IS_EXPORT is true if we're reexporting the OTHER. */
18229 module_state::set_import (module_state
const *import
, bool is_export
)
18231 gcc_checking_assert (this != import
);
18233 /* We see IMPORT's exports (which includes IMPORT). If IMPORT is
18234 the primary interface or a partition we'll see its imports. */
18235 bitmap_ior_into (imports
, import
->is_module () || import
->is_partition ()
18236 ? import
->imports
: import
->exports
);
18239 /* We'll export OTHER's exports. */
18240 bitmap_ior_into (exports
, import
->exports
);
18243 /* Return the declaring entity of DECL. That is the decl determining
18244 how to decorate DECL with module information. Returns NULL_TREE if
18245 it's the global module. */
18248 get_originating_module_decl (tree decl
)
18250 /* An enumeration constant. */
18251 if (TREE_CODE (decl
) == CONST_DECL
18252 && DECL_CONTEXT (decl
)
18253 && (TREE_CODE (DECL_CONTEXT (decl
)) == ENUMERAL_TYPE
))
18254 decl
= TYPE_NAME (DECL_CONTEXT (decl
));
18255 else if (TREE_CODE (decl
) == FIELD_DECL
18256 || TREE_CODE (decl
) == USING_DECL
)
18258 decl
= DECL_CONTEXT (decl
);
18259 if (TREE_CODE (decl
) != FUNCTION_DECL
)
18260 decl
= TYPE_NAME (decl
);
18263 gcc_checking_assert (TREE_CODE (decl
) == TEMPLATE_DECL
18264 || TREE_CODE (decl
) == FUNCTION_DECL
18265 || TREE_CODE (decl
) == TYPE_DECL
18266 || TREE_CODE (decl
) == VAR_DECL
18267 || TREE_CODE (decl
) == CONCEPT_DECL
18268 || TREE_CODE (decl
) == NAMESPACE_DECL
);
18272 /* Uninstantiated template friends are owned by the befriending
18273 class -- not their context. */
18274 if (TREE_CODE (decl
) == TEMPLATE_DECL
18275 && DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (decl
))
18276 decl
= TYPE_NAME (DECL_CHAIN (decl
));
18279 if (tree ti
= node_template_info (decl
, use
))
18281 decl
= TI_TEMPLATE (ti
);
18282 if (TREE_CODE (decl
) != TEMPLATE_DECL
)
18284 /* A friend template specialization. */
18285 gcc_checking_assert (OVL_P (decl
));
18286 return global_namespace
;
18291 tree ctx
= CP_DECL_CONTEXT (decl
);
18292 if (TREE_CODE (ctx
) == NAMESPACE_DECL
)
18297 ctx
= TYPE_NAME (ctx
);
18300 /* Some kind of internal type. */
18301 gcc_checking_assert (DECL_ARTIFICIAL (decl
));
18302 return global_namespace
;
18313 get_originating_module (tree decl
, bool for_mangle
)
18315 tree owner
= get_originating_module_decl (decl
);
18317 if (!DECL_LANG_SPECIFIC (owner
))
18318 return for_mangle
? -1 : 0;
18321 && (DECL_MODULE_EXPORT_P (owner
) || !DECL_MODULE_PURVIEW_P (owner
)))
18324 if (!DECL_MODULE_IMPORT_P (owner
))
18327 return get_importing_module (owner
);
18331 get_importing_module (tree decl
, bool flexible
)
18333 unsigned index
= import_entity_index (decl
, flexible
);
18334 if (index
== ~(~0u >> 1))
18336 module_state
*module
= import_entity_module (index
);
18338 return module
->mod
;
18341 /* Is it permissible to redeclare DECL. */
18344 module_may_redeclare (tree decl
)
18346 module_state
*me
= (*modules
)[0];
18347 module_state
*them
= me
;
18348 if (DECL_LANG_SPECIFIC (decl
) && DECL_MODULE_IMPORT_P (decl
))
18350 /* We can be given the TEMPLATE_RESULT. We want the
18353 if (tree ti
= node_template_info (decl
, use_tpl
))
18355 tree tmpl
= TI_TEMPLATE (ti
);
18356 if (DECL_TEMPLATE_RESULT (tmpl
) == decl
)
18358 // FIXME: What about partial specializations? We need to
18359 // look at the specialization list in that case. Unless our
18360 // caller's given us the right thing. An alternative would
18361 // be to put both the template and the result into the
18362 // entity hash, but that seems expensive?
18364 unsigned index
= import_entity_index (decl
);
18365 them
= import_entity_module (index
);
18368 if (them
->is_header ())
18370 if (!header_module_p ())
18371 return !module_purview_p ();
18373 if (DECL_SOURCE_LOCATION (decl
) == BUILTINS_LOCATION
)
18374 /* This is a builtin, being declared in header-unit. We
18375 now need to mark it as an export. */
18376 DECL_MODULE_EXPORT_P (decl
) = true;
18378 /* If it came from a header, it's in the global module. */
18383 return ((DECL_LANG_SPECIFIC (decl
) && DECL_MODULE_PURVIEW_P (decl
))
18384 == module_purview_p ());
18389 /* We can't have found a GMF entity from a named module. */
18390 gcc_checking_assert (DECL_LANG_SPECIFIC (decl
)
18391 && DECL_MODULE_PURVIEW_P (decl
));
18393 return me
&& get_primary (them
) == get_primary (me
);
18396 /* DECL is being created by this TU. Record it came from here. We
18397 record module purview, so we can see if partial or explicit
18398 specialization needs to be written out, even though its purviewness
18399 comes from the most general template. */
18402 set_instantiating_module (tree decl
)
18404 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
18405 || TREE_CODE (decl
) == VAR_DECL
18406 || TREE_CODE (decl
) == TYPE_DECL
18407 || TREE_CODE (decl
) == CONCEPT_DECL
18408 || TREE_CODE (decl
) == TEMPLATE_DECL
18409 || (TREE_CODE (decl
) == NAMESPACE_DECL
18410 && DECL_NAMESPACE_ALIAS (decl
)));
18415 if (!DECL_LANG_SPECIFIC (decl
) && module_purview_p ())
18416 retrofit_lang_decl (decl
);
18417 if (DECL_LANG_SPECIFIC (decl
))
18419 DECL_MODULE_PURVIEW_P (decl
) = module_purview_p ();
18420 /* If this was imported, we'll still be in the entity_hash. */
18421 DECL_MODULE_IMPORT_P (decl
) = false;
18422 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
18424 tree res
= DECL_TEMPLATE_RESULT (decl
);
18425 retrofit_lang_decl (res
);
18426 DECL_MODULE_PURVIEW_P (res
) = DECL_MODULE_PURVIEW_P (decl
);
18427 DECL_MODULE_IMPORT_P (res
) = false;
18432 /* If DECL is a class member, whose class is not defined in this TU
18433 (it was imported), remember this decl. */
18436 set_defining_module (tree decl
)
18438 gcc_checking_assert (!DECL_LANG_SPECIFIC (decl
)
18439 || !DECL_MODULE_IMPORT_P (decl
));
18441 if (module_has_cmi_p ())
18443 tree ctx
= DECL_CONTEXT (decl
);
18445 && (TREE_CODE (ctx
) == RECORD_TYPE
|| TREE_CODE (ctx
) == UNION_TYPE
)
18446 && DECL_LANG_SPECIFIC (TYPE_NAME (ctx
))
18447 && DECL_MODULE_IMPORT_P (TYPE_NAME (ctx
)))
18449 /* This entity's context is from an import. We may need to
18450 record this entity to make sure we emit it in the CMI.
18451 Template specializations are in the template hash tables,
18452 so we don't need to record them here as well. */
18454 tree ti
= node_template_info (decl
, use_tpl
);
18459 gcc_checking_assert (!use_tpl
);
18460 /* Get to the TEMPLATE_DECL. */
18461 decl
= TI_TEMPLATE (ti
);
18464 /* Record it on the class_members list. */
18465 vec_safe_push (class_members
, decl
);
18468 else if (DECL_IMPLICIT_TYPEDEF_P (decl
)
18469 && CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (decl
)))
18470 /* This is a partial or explicit specialization. */
18471 vec_safe_push (partial_specializations
, decl
);
18476 set_originating_module (tree decl
, bool friend_p ATTRIBUTE_UNUSED
)
18478 set_instantiating_module (decl
);
18480 if (TREE_CODE (CP_DECL_CONTEXT (decl
)) != NAMESPACE_DECL
)
18483 gcc_checking_assert (friend_p
|| decl
== get_originating_module_decl (decl
));
18485 if (!module_exporting_p ())
18488 // FIXME: Check ill-formed linkage
18489 DECL_MODULE_EXPORT_P (decl
) = true;
18492 /* DECL is attached to ROOT for odr purposes. */
18495 maybe_attach_decl (tree ctx
, tree decl
)
18500 // FIXME: For now just deal with lambdas attached to var decls.
18501 // This might be sufficient?
18502 if (TREE_CODE (ctx
) != VAR_DECL
)
18505 gcc_checking_assert (DECL_NAMESPACE_SCOPE_P (ctx
));
18507 if (!attached_table
)
18508 attached_table
= new attachset::hash (EXPERIMENT (1, 400));
18510 if (attached_table
->add (DECL_UID (ctx
), decl
))
18512 retrofit_lang_decl (ctx
);
18513 DECL_MODULE_ATTACHMENTS_P (ctx
) = true;
18517 /* Create the flat name string. It is simplest to have it handy. */
18520 module_state::set_flatname ()
18522 gcc_checking_assert (!flatname
);
18525 auto_vec
<tree
,5> ids
;
18527 char const *primary
= NULL
;
18528 size_t pfx_len
= 0;
18530 for (module_state
*probe
= this;
18532 probe
= probe
->parent
)
18533 if (is_partition () && !probe
->is_partition ())
18535 primary
= probe
->get_flatname ();
18536 pfx_len
= strlen (primary
);
18541 ids
.safe_push (probe
->name
);
18542 len
+= IDENTIFIER_LENGTH (probe
->name
) + 1;
18545 char *flat
= XNEWVEC (char, pfx_len
+ len
+ is_partition ());
18550 memcpy (flat
, primary
, pfx_len
);
18555 for (unsigned len
= 0; ids
.length ();)
18559 tree elt
= ids
.pop ();
18560 unsigned l
= IDENTIFIER_LENGTH (elt
);
18561 memcpy (flat
+ len
, IDENTIFIER_POINTER (elt
), l
+ 1);
18565 else if (is_header ())
18566 flatname
= TREE_STRING_POINTER (name
);
18568 flatname
= IDENTIFIER_POINTER (name
);
18571 /* Read the CMI file for a module. */
18574 module_state::do_import (cpp_reader
*reader
, bool outermost
)
18576 gcc_assert (global_namespace
== current_scope () && loadedness
== ML_NONE
);
18578 loc
= linemap_module_loc (line_table
, loc
, get_flatname ());
18580 if (lazy_open
>= lazy_limit
)
18587 const char *file
= maybe_add_cmi_prefix (filename
);
18588 dump () && dump ("CMI is %s", file
);
18589 fd
= open (file
, O_RDONLY
| O_CLOEXEC
| O_BINARY
);
18593 gcc_checking_assert (!slurp
);
18594 slurp
= new slurping (new elf_in (fd
, e
));
18597 if (!from ()->get_error ())
18599 announce ("importing");
18600 loadedness
= ML_CONFIG
;
18602 ok
= read_initial (reader
);
18603 slurp
->lru
= ++lazy_lru
;
18606 gcc_assert (slurp
->current
== ~0u);
18608 return check_read (outermost
, ok
);
18611 /* Attempt to increase the file descriptor limit. */
18614 try_increase_lazy (unsigned want
)
18616 gcc_checking_assert (lazy_open
>= lazy_limit
);
18618 /* If we're increasing, saturate at hard limit. */
18619 if (want
> lazy_hard_limit
&& lazy_limit
< lazy_hard_limit
)
18620 want
= lazy_hard_limit
;
18623 if ((!lazy_limit
|| !param_lazy_modules
)
18625 && want
<= lazy_hard_limit
)
18627 struct rlimit rlimit
;
18628 rlimit
.rlim_cur
= want
+ LAZY_HEADROOM
;
18629 rlimit
.rlim_max
= lazy_hard_limit
+ LAZY_HEADROOM
;
18630 if (!setrlimit (RLIMIT_NOFILE
, &rlimit
))
18635 return lazy_open
< lazy_limit
;
18638 /* Pick a victim module to freeze its reader. */
18641 module_state::freeze_an_elf ()
18643 if (try_increase_lazy (lazy_open
* 2))
18646 module_state
*victim
= NULL
;
18647 for (unsigned ix
= modules
->length (); ix
--;)
18649 module_state
*candidate
= (*modules
)[ix
];
18650 if (candidate
&& candidate
->slurp
&& candidate
->slurp
->lru
18651 && candidate
->from ()->is_freezable ()
18652 && (!victim
|| victim
->slurp
->lru
> candidate
->slurp
->lru
))
18653 victim
= candidate
;
18658 dump () && dump ("Freezing '%s'", victim
->filename
);
18659 if (victim
->slurp
->macro_defs
.size
)
18660 /* Save the macro definitions to a buffer. */
18661 victim
->from ()->preserve (victim
->slurp
->macro_defs
);
18662 if (victim
->slurp
->macro_tbl
.size
)
18663 /* Save the macro definitions to a buffer. */
18664 victim
->from ()->preserve (victim
->slurp
->macro_tbl
);
18665 victim
->from ()->freeze ();
18669 dump () && dump ("No module available for freezing");
18672 /* Load the lazy slot *MSLOT, INDEX'th slot of the module. */
18675 module_state::lazy_load (unsigned index
, binding_slot
*mslot
)
18677 unsigned n
= dump
.push (this);
18679 gcc_checking_assert (function_depth
);
18681 unsigned cookie
= mslot
->get_lazy ();
18682 unsigned snum
= cookie
>> 2;
18683 dump () && dump ("Loading entity %M[%u] section:%u", this, index
, snum
);
18685 bool ok
= load_section (snum
, mslot
);
18692 /* Load MOD's binding for NS::ID into *MSLOT. *MSLOT contains the
18693 lazy cookie. OUTER is true if this is the outermost lazy, (used
18694 for diagnostics). */
18697 lazy_load_binding (unsigned mod
, tree ns
, tree id
, binding_slot
*mslot
)
18699 int count
= errorcount
+ warningcount
;
18701 timevar_start (TV_MODULE_IMPORT
);
18703 /* Stop GC happening, even in outermost loads (because our caller
18704 could well be building up a lookup set). */
18707 gcc_checking_assert (mod
);
18708 module_state
*module
= (*modules
)[mod
];
18709 unsigned n
= dump
.push (module
);
18711 unsigned snum
= mslot
->get_lazy ();
18712 dump () && dump ("Lazily binding %P@%N section:%u", ns
, id
,
18713 module
->name
, snum
);
18715 bool ok
= !recursive_lazy (snum
);
18718 ok
= module
->load_section (snum
, mslot
);
18726 timevar_stop (TV_MODULE_IMPORT
);
18729 fatal_error (input_location
,
18730 module
->is_header ()
18731 ? G_("failed to load binding %<%E%s%E%>")
18732 : G_("failed to load binding %<%E%s%E@%s%>"),
18733 ns
, &"::"[ns
== global_namespace
? 2 : 0], id
,
18734 module
->get_flatname ());
18736 if (count
!= errorcount
+ warningcount
)
18737 inform (input_location
,
18738 module
->is_header ()
18739 ? G_("during load of binding %<%E%s%E%>")
18740 : G_("during load of binding %<%E%s%E@%s%>"),
18741 ns
, &"::"[ns
== global_namespace
? 2 : 0], id
,
18742 module
->get_flatname ());
18745 /* Load any pending specializations of TMPL. Called just before
18746 instantiating TMPL. */
18749 lazy_load_specializations (tree tmpl
)
18751 gcc_checking_assert (DECL_MODULE_PENDING_SPECIALIZATIONS_P (tmpl
)
18752 && DECL_MODULE_ENTITY_P (tmpl
));
18754 int count
= errorcount
+ warningcount
;
18756 timevar_start (TV_MODULE_IMPORT
);
18757 bool ok
= !recursive_lazy ();
18760 unsigned ident
= import_entity_index (tmpl
);
18761 if (pendset
*set
= pending_table
->get (ident
, true))
18763 function_depth
++; /* Prevent GC */
18764 unsigned n
= dump
.push (NULL
);
18766 && dump ("Reading %u pending specializations keyed to %M[%u] %N",
18767 set
->num
, import_entity_module (ident
),
18768 ident
- import_entity_module (ident
)->entity_lwm
, tmpl
);
18769 if (!pendset_lazy_load (set
, true))
18778 timevar_stop (TV_MODULE_IMPORT
);
18781 fatal_error (input_location
, "failed to load specializations keyed to %qD",
18784 if (count
!= errorcount
+ warningcount
)
18785 inform (input_location
,
18786 "during load of specializations keyed to %qD", tmpl
);
18790 lazy_load_members (tree decl
)
18792 gcc_checking_assert (DECL_MODULE_PENDING_MEMBERS_P (decl
));
18793 if (!DECL_MODULE_ENTITY_P (decl
))
18795 // FIXME: I can't help feeling that DECL_TEMPLATE_RESULT should
18796 // be inserted into the entity map, or perhaps have the same
18797 // DECL_UID as the template, so I don't have to do this dance
18798 // here and elsewhere. It also simplifies when DECL is a
18799 // partial specialization. (also noted elsewhere as an issue)
18800 tree ti
= CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (decl
));
18801 tree tmpl
= TI_TEMPLATE (ti
);
18802 gcc_checking_assert (DECL_TEMPLATE_RESULT (tmpl
) == decl
);
18806 timevar_start (TV_MODULE_IMPORT
);
18807 unsigned ident
= import_entity_index (decl
);
18808 if (pendset
*set
= pending_table
->get (~ident
, true))
18810 function_depth
++; /* Prevent GC */
18811 unsigned n
= dump
.push (NULL
);
18812 dump () && dump ("Reading %u pending members keyed to %M[%u] %N",
18813 set
->num
, import_entity_module (ident
),
18814 ident
- import_entity_module (ident
)->entity_lwm
, decl
);
18815 pendset_lazy_load (set
, false);
18820 timevar_stop (TV_MODULE_IMPORT
);
18824 direct_import (module_state
*import
, cpp_reader
*reader
)
18826 timevar_start (TV_MODULE_IMPORT
);
18827 unsigned n
= dump
.push (import
);
18829 gcc_checking_assert (import
->is_direct () && import
->is_rooted ());
18830 if (import
->loadedness
== ML_NONE
)
18831 if (!import
->do_import (reader
, true))
18832 gcc_unreachable ();
18834 if (import
->loadedness
< ML_LANGUAGE
)
18836 if (!attached_table
)
18837 attached_table
= new attachset::hash (EXPERIMENT (1, 400));
18838 import
->read_language (true);
18841 (*modules
)[0]->set_import (import
, import
->exported_p
);
18844 timevar_stop (TV_MODULE_IMPORT
);
18847 /* Import module IMPORT. */
18850 import_module (module_state
*import
, location_t from_loc
, bool exporting_p
,
18851 tree
, cpp_reader
*reader
)
18853 if (!import
->check_not_purview (from_loc
))
18856 if (!import
->is_header () && current_lang_depth ())
18857 /* Only header units should appear inside language
18858 specifications. The std doesn't specify this, but I think
18859 that's an error in resolving US 033, because language linkage
18860 is also our escape clause to getting things into the global
18861 module, so we don't want to confuse things by having to think
18862 about whether 'extern "C++" { import foo; }' puts foo's
18863 contents into the global module all of a sudden. */
18864 warning (0, "import of named module %qs inside language-linkage block",
18865 import
->get_flatname ());
18867 if (exporting_p
|| module_exporting_p ())
18868 import
->exported_p
= true;
18870 if (import
->loadedness
!= ML_NONE
)
18872 from_loc
= ordinary_loc_of (line_table
, from_loc
);
18873 linemap_module_reparent (line_table
, import
->loc
, from_loc
);
18875 gcc_checking_assert (!import
->module_p
);
18876 gcc_checking_assert (import
->is_direct () && import
->is_rooted ());
18878 direct_import (import
, reader
);
18881 /* Declare the name of the current module to be NAME. EXPORTING_p is
18882 true if this TU is the exporting module unit. */
18885 declare_module (module_state
*module
, location_t from_loc
, bool exporting_p
,
18886 tree
, cpp_reader
*reader
)
18888 gcc_assert (global_namespace
== current_scope ());
18890 module_state
*current
= (*modules
)[0];
18891 if (module_purview_p () || module
->loadedness
!= ML_NONE
)
18893 error_at (from_loc
, module_purview_p ()
18894 ? G_("module already declared")
18895 : G_("module already imported"));
18896 if (module_purview_p ())
18898 inform (module
->loc
, module_purview_p ()
18899 ? G_("module %qs declared here")
18900 : G_("module %qs imported here"),
18901 module
->get_flatname ());
18905 gcc_checking_assert (module
->module_p
);
18906 gcc_checking_assert (module
->is_direct () && module
->is_rooted ());
18908 /* Yer a module, 'arry. */
18909 module_kind
&= ~MK_GLOBAL
;
18910 module_kind
|= MK_MODULE
;
18912 if (module
->is_partition () || exporting_p
)
18914 gcc_checking_assert (module
->get_flatname ());
18916 if (module
->is_partition ())
18917 module_kind
|= MK_PARTITION
;
18921 module
->interface_p
= true;
18922 module_kind
|= MK_INTERFACE
;
18925 if (module
->is_header ())
18926 module_kind
|= MK_GLOBAL
| MK_EXPORTING
;
18928 /* Copy the importing information we may have already done. We
18929 do not need to separate out the imports that only happen in
18930 the GMF, inspite of what the literal wording of the std
18931 might imply. See p2191, the core list had a discussion
18932 where the module implementors agreed that the GMF of a named
18933 module is invisible to importers. */
18934 module
->imports
= current
->imports
;
18937 (*modules
)[0] = module
;
18941 module
->interface_p
= true;
18942 current
->parent
= module
; /* So mangler knows module identity. */
18943 direct_import (module
, reader
);
18947 /* +1, we're the primary or a partition. Therefore emitting a
18948 globally-callable idemportent initializer function.
18949 -1, we have direct imports. Therefore emitting calls to their
18953 module_initializer_kind ()
18957 if (module_has_cmi_p () && !header_module_p ())
18959 else if (num_init_calls_needed
)
18965 /* Emit calls to each direct import's global initializer. Including
18966 direct imports of directly imported header units. The initializers
18967 of (static) entities in header units will be called by their
18968 importing modules (for the instance contained within that), or by
18969 the current TU (for the instances we've brought in). Of course
18970 such header unit behaviour is evil, but iostream went through that
18971 door some time ago. */
18974 module_add_import_initializers ()
18976 unsigned calls
= 0;
18979 tree fntype
= build_function_type (void_type_node
, void_list_node
);
18980 releasing_vec args
; // There are no args
18982 for (unsigned ix
= modules
->length (); --ix
;)
18984 module_state
*import
= (*modules
)[ix
];
18985 if (import
->call_init_p
)
18987 tree name
= mangle_module_global_init (ix
);
18988 tree fndecl
= build_lang_decl (FUNCTION_DECL
, name
, fntype
);
18990 DECL_CONTEXT (fndecl
) = FROB_CONTEXT (global_namespace
);
18991 SET_DECL_ASSEMBLER_NAME (fndecl
, name
);
18992 TREE_PUBLIC (fndecl
) = true;
18993 determine_visibility (fndecl
);
18995 tree call
= cp_build_function_call_vec (fndecl
, &args
,
18996 tf_warning_or_error
);
18997 finish_expr_stmt (call
);
19004 gcc_checking_assert (calls
== num_init_calls_needed
);
19007 /* NAME & LEN are a preprocessed header name, possibly including the
19008 surrounding "" or <> characters. Return the raw string name of the
19009 module to which it refers. This will be an absolute path, or begin
19010 with ./, so it is immediately distinguishable from a (non-header
19011 unit) module name. If READER is non-null, ask the preprocessor to
19012 locate the header to which it refers using the appropriate include
19013 path. Note that we do never do \ processing of the string, as that
19014 matches the preprocessor's behaviour. */
19016 static const char *
19017 canonicalize_header_name (cpp_reader
*reader
, location_t loc
, bool unquoted
,
19018 const char *str
, size_t &len_r
)
19020 size_t len
= len_r
;
19021 static char *buf
= 0;
19022 static size_t alloc
= 0;
19026 gcc_checking_assert (len
>= 2
19027 && ((reader
&& str
[0] == '<' && str
[len
-1] == '>')
19028 || (str
[0] == '"' && str
[len
-1] == '"')));
19035 gcc_assert (!unquoted
);
19040 buf
= XRESIZEVEC (char, buf
, alloc
);
19042 memcpy (buf
, str
, len
);
19045 if (const char *hdr
19046 = cpp_find_header_unit (reader
, buf
, str
[-1] == '<', loc
))
19048 len
= strlen (hdr
);
19055 if (!(str
[0] == '.' ? IS_DIR_SEPARATOR (str
[1]) : IS_ABSOLUTE_PATH (str
)))
19058 if (len
+ 3 > alloc
)
19061 buf
= XRESIZEVEC (char, buf
, alloc
);
19065 buf
[1] = DIR_SEPARATOR
;
19066 memmove (buf
+ 2, str
, len
);
19076 /* Set the CMI name from a cody packet. Issue an error if
19079 void module_state::set_filename (const Cody::Packet
&packet
)
19081 gcc_checking_assert (!filename
);
19082 if (packet
.GetCode () == Cody::Client::PC_PATHNAME
)
19083 filename
= xstrdup (packet
.GetString ().c_str ());
19086 gcc_checking_assert (packet
.GetCode () == Cody::Client::PC_ERROR
);
19087 error_at (loc
, "unknown Compiled Module Interface: %s",
19088 packet
.GetString ().c_str ());
19092 /* Figure out whether to treat HEADER as an include or an import. */
19095 maybe_translate_include (cpp_reader
*reader
, line_maps
*lmaps
, location_t loc
,
19101 cpp_get_callbacks (reader
)->translate_include
= NULL
;
19105 if (!spans
.init_p ())
19106 /* Before the main file, don't divert. */
19111 dump () && dump ("Checking include translation '%s'", path
);
19112 auto *mapper
= get_mapper (cpp_main_loc (reader
));
19114 size_t len
= strlen (path
);
19115 path
= canonicalize_header_name (NULL
, loc
, true, path
, len
);
19116 auto packet
= mapper
->IncludeTranslate (path
, Cody::Flags::None
, len
);
19118 if (packet
.GetCode () == Cody::Client::PC_BOOL
)
19119 xlate
= -int (packet
.GetInteger ());
19120 else if (packet
.GetCode () == Cody::Client::PC_PATHNAME
)
19122 /* Record the CMI name for when we do the import. */
19123 module_state
*import
= get_module (build_string (len
, path
));
19124 import
->set_filename (packet
);
19129 gcc_checking_assert (packet
.GetCode () == Cody::Client::PC_ERROR
);
19130 error_at (loc
, "cannot determine %<#include%> translation of %s: %s",
19131 path
, packet
.GetString ().c_str ());
19135 if (note_include_translate_yes
&& xlate
> 1)
19137 else if (note_include_translate_no
&& xlate
== 0)
19139 else if (note_includes
)
19141 /* We do not expect the note_includes vector to be large, so O(N)
19143 for (unsigned ix
= note_includes
->length (); !note
&& ix
--;)
19145 const char *hdr
= (*note_includes
)[ix
];
19146 size_t hdr_len
= strlen (hdr
);
19147 if ((hdr_len
== len
19148 || (hdr_len
< len
&& IS_DIR_SEPARATOR (path
[len
- hdr_len
- 1])))
19149 && !memcmp (hdr
, path
+ len
- hdr_len
, hdr_len
))
19156 ? G_("include %qs translated to import")
19157 : G_("include %qs processed textually") , path
);
19159 dump () && dump (xlate
? "Translating include to import"
19160 : "Keeping include as include");
19166 /* Create the translation text. */
19167 loc
= ordinary_loc_of (lmaps
, loc
);
19168 const line_map_ordinary
*map
19169 = linemap_check_ordinary (linemap_lookup (lmaps
, loc
));
19170 unsigned col
= SOURCE_COLUMN (map
, loc
);
19171 col
-= (col
!= 0); /* Columns are 1-based. */
19173 unsigned alloc
= len
+ col
+ 60;
19174 char *res
= XNEWVEC (char, alloc
);
19176 strcpy (res
, "__import");
19177 unsigned actual
= 8;
19180 /* Pad out so the filename appears at the same position. */
19181 memset (res
+ actual
, ' ', col
- actual
);
19184 /* No need to encode characters, that's not how header names are
19186 actual
+= snprintf (res
+ actual
, alloc
- actual
,
19187 "\"%s\" [[__translated]];\n", path
);
19188 gcc_checking_assert (actual
< alloc
);
19190 /* cpplib will delete the buffer. */
19195 begin_header_unit (cpp_reader
*reader
)
19197 /* Set the module header name from the main_input_filename. */
19198 const char *main
= main_input_filename
;
19199 size_t len
= strlen (main
);
19200 main
= canonicalize_header_name (NULL
, 0, true, main
, len
);
19201 module_state
*module
= get_module (build_string (len
, main
));
19203 preprocess_module (module
, cpp_main_loc (reader
), false, false, true, reader
);
19206 /* We've just properly entered the main source file. I.e. after the
19207 command line, builtins and forced headers. Record the line map and
19208 location of this map. Note we may be called more than once. The
19209 first call sticks. */
19212 module_begin_main_file (cpp_reader
*reader
, line_maps
*lmaps
,
19213 const line_map_ordinary
*map
)
19215 gcc_checking_assert (lmaps
== line_table
);
19216 if (modules_p () && !spans
.init_p ())
19218 unsigned n
= dump
.push (NULL
);
19219 spans
.init (lmaps
, map
);
19221 if (flag_header_unit
&& !cpp_get_options (reader
)->preprocessed
)
19223 /* Tell the preprocessor this is an include file. */
19224 cpp_retrofit_as_include (reader
);
19225 begin_header_unit (reader
);
19230 /* We've just lexed a module-specific control line for MODULE. Mark
19231 the module as a direct import, and possibly load up its macro
19232 state. Returns the primary module, if this is a module
19234 /* Perhaps we should offer a preprocessing mode where we read the
19235 directives from the header unit, rather than require the header's
19239 preprocess_module (module_state
*module
, location_t from_loc
,
19240 bool in_purview
, bool is_import
, bool is_export
,
19241 cpp_reader
*reader
)
19246 /* It's already been mentioned, so ignore its module-ness. */
19250 /* Record it is the module. */
19251 module
->module_p
= true;
19254 module
->exported_p
= true;
19255 module
->interface_p
= true;
19260 if (module
->directness
< MD_DIRECT
+ in_purview
)
19262 /* Mark as a direct import. */
19263 module
->directness
= module_directness (MD_DIRECT
+ in_purview
);
19265 /* Set the location to be most informative for users. */
19266 from_loc
= ordinary_loc_of (line_table
, from_loc
);
19267 if (module
->loadedness
!= ML_NONE
)
19268 linemap_module_reparent (line_table
, module
->loc
, from_loc
);
19271 module
->loc
= from_loc
;
19272 if (!module
->flatname
)
19273 module
->set_flatname ();
19278 && !module
->is_module () && module
->is_header ()
19279 && module
->loadedness
< ML_PREPROCESSOR
19280 && (!cpp_get_options (reader
)->preprocessed
19281 || cpp_get_options (reader
)->directives_only
))
19283 timevar_start (TV_MODULE_IMPORT
);
19284 unsigned n
= dump
.push (module
);
19286 if (module
->loadedness
== ML_NONE
)
19288 unsigned pre_hwm
= 0;
19290 /* Preserve the state of the line-map. */
19291 pre_hwm
= LINEMAPS_ORDINARY_USED (line_table
);
19292 /* We only need to close the span, if we're going to emit a
19293 CMI. But that's a little tricky -- our token scanner
19294 needs to be smarter -- and this isn't much state.
19295 Remember, we've not parsed anything at this point, so
19296 our module state flags are inadequate. */
19297 spans
.maybe_init ();
19300 if (!module
->filename
)
19302 auto *mapper
= get_mapper (cpp_main_loc (reader
));
19303 auto packet
= mapper
->ModuleImport (module
->get_flatname ());
19304 module
->set_filename (packet
);
19306 module
->do_import (reader
, true);
19308 /* Restore the line-map state. */
19309 linemap_module_restore (line_table
, pre_hwm
);
19313 if (module
->loadedness
< ML_PREPROCESSOR
)
19314 if (module
->read_preprocessor (true))
19315 module
->import_macros ();
19318 timevar_stop (TV_MODULE_IMPORT
);
19321 return is_import
? NULL
: get_primary (module
);
19324 /* We've completed phase-4 translation. Emit any dependency
19325 information for the not-yet-loaded direct imports, and fill in
19326 their file names. We'll have already loaded up the direct header
19330 preprocessed_module (cpp_reader
*reader
)
19332 auto *mapper
= get_mapper (cpp_main_loc (reader
));
19334 spans
.maybe_init ();
19337 /* Stupid GTY doesn't grok a typedef here. And using type = is, too
19339 #define iterator hash_table<module_state_hash>::iterator
19340 /* using iterator = hash_table<module_state_hash>::iterator; */
19342 /* Walk the module hash, asking for the names of all unknown
19343 direct imports and informing of an export (if that's what we
19344 are). Notice these are emitted even when preprocessing as they
19345 inform the server of dependency edges. */
19346 timevar_start (TV_MODULE_MAPPER
);
19349 dump () && dump ("Resolving direct import names");
19351 if (!flag_preprocess_only
19352 || bool (mapper
->get_flags () & Cody::Flags::NameOnly
)
19353 || cpp_get_deps (reader
))
19356 iterator end
= modules_hash
->end ();
19357 for (iterator iter
= modules_hash
->begin (); iter
!= end
; ++iter
)
19359 module_state
*module
= *iter
;
19360 if (module
->is_direct () && !module
->filename
)
19363 = (flag_preprocess_only
? Cody::Flags::None
19364 : Cody::Flags::NameOnly
);
19366 if (module
->module_p
19367 && (module
->is_partition () || module
->exported_p
))
19368 mapper
->ModuleExport (module
->get_flatname (), flags
);
19370 mapper
->ModuleImport (module
->get_flatname (), flags
);
19374 auto response
= mapper
->Uncork ();
19375 auto r_iter
= response
.begin ();
19376 for (iterator iter
= modules_hash
->begin (); iter
!= end
; ++iter
)
19378 module_state
*module
= *iter
;
19380 if (module
->is_direct () && !module
->filename
)
19382 Cody::Packet
const &p
= *r_iter
;
19385 module
->set_filename (p
);
19392 timevar_stop (TV_MODULE_MAPPER
);
19394 if (mkdeps
*deps
= cpp_get_deps (reader
))
19396 /* Walk the module hash, informing the dependency machinery. */
19397 iterator end
= modules_hash
->end ();
19398 for (iterator iter
= modules_hash
->begin (); iter
!= end
; ++iter
)
19400 module_state
*module
= *iter
;
19402 if (module
->is_direct ())
19404 if (module
->is_module ()
19405 && (module
->is_interface () || module
->is_partition ()))
19406 deps_add_module_target (deps
, module
->get_flatname (),
19407 maybe_add_cmi_prefix (module
->filename
),
19408 module
->is_header());
19410 deps_add_module_dep (deps
, module
->get_flatname ());
19415 if (flag_header_unit
&& !flag_preprocess_only
)
19417 iterator end
= modules_hash
->end ();
19418 for (iterator iter
= modules_hash
->begin (); iter
!= end
; ++iter
)
19420 module_state
*module
= *iter
;
19421 if (module
->is_module ())
19423 declare_module (module
, cpp_main_loc (reader
), true, NULL
, reader
);
19431 /* VAL is a global tree, add it to the global vec if it is
19432 interesting. Add some of its targets, if they too are
19433 interesting. We do not add identifiers, as they can be re-found
19434 via the identifier hash table. There is a cost to the number of
19438 maybe_add_global (tree val
, unsigned &crc
)
19442 if (val
&& !(identifier_p (val
) || TREE_VISITED (val
)))
19444 TREE_VISITED (val
) = true;
19445 crc
= crc32_unsigned (crc
, fixed_trees
->length ());
19446 vec_safe_push (fixed_trees
, val
);
19449 if (CODE_CONTAINS_STRUCT (TREE_CODE (val
), TS_TYPED
))
19450 v
+= maybe_add_global (TREE_TYPE (val
), crc
);
19451 if (CODE_CONTAINS_STRUCT (TREE_CODE (val
), TS_TYPE_COMMON
))
19452 v
+= maybe_add_global (TYPE_NAME (val
), crc
);
19458 /* Initialize module state. Create the hash table, determine the
19459 global trees. Create the module for current TU. */
19462 init_modules (cpp_reader
*reader
)
19464 /* PCH should not be reachable because of lang-specs, but the
19465 user could have overriden that. */
19467 fatal_error (input_location
,
19468 "C++ modules are incompatible with precompiled headers");
19470 if (cpp_get_options (reader
)->traditional
)
19471 fatal_error (input_location
,
19472 "C++ modules are incompatible with traditional preprocessing");
19474 if (flag_preprocess_only
)
19476 cpp_options
*cpp_opts
= cpp_get_options (reader
);
19478 || (cpp_opts
->deps
.style
!= DEPS_NONE
19479 && !cpp_opts
->deps
.need_preprocessor_output
))
19481 warning (0, flag_dump_macros
== 'M'
19482 ? G_("macro debug output may be incomplete with modules")
19483 : G_("module dependencies require preprocessing"));
19484 if (cpp_opts
->deps
.style
!= DEPS_NONE
)
19485 inform (input_location
, "you should use the %<-%s%> option",
19486 cpp_opts
->deps
.style
== DEPS_SYSTEM
? "MD" : "MMD");
19490 /* :: is always exported. */
19491 DECL_MODULE_EXPORT_P (global_namespace
) = true;
19493 modules_hash
= hash_table
<module_state_hash
>::create_ggc (31);
19494 vec_safe_reserve (modules
, 20);
19496 /* Create module for current TU. */
19497 module_state
*current
19498 = new (ggc_alloc
<module_state
> ()) module_state (NULL_TREE
, NULL
, false);
19500 bitmap_set_bit (current
->imports
, 0);
19501 modules
->quick_push (current
);
19503 gcc_checking_assert (!fixed_trees
);
19505 headers
= BITMAP_GGC_ALLOC ();
19508 for (unsigned ix
= 0; ix
!= note_includes
->length (); ix
++)
19510 const char *hdr
= (*note_includes
)[ix
];
19511 size_t len
= strlen (hdr
);
19513 bool system
= hdr
[0] == '<';
19514 bool user
= hdr
[0] == '"';
19515 bool delimed
= system
|| user
;
19517 if (len
<= (delimed
? 2 : 0)
19518 || (delimed
&& hdr
[len
-1] != (system
? '>' : '"')))
19519 error ("invalid header name %qs", hdr
);
19521 hdr
= canonicalize_header_name (delimed
? reader
: NULL
,
19522 0, !delimed
, hdr
, len
);
19523 char *path
= XNEWVEC (char, len
+ 1);
19524 memcpy (path
, hdr
, len
);
19527 (*note_includes
)[ix
] = path
;
19532 /* Determine lazy handle bound. */
19534 unsigned limit
= 1000;
19536 struct rlimit rlimit
;
19537 if (!getrlimit (RLIMIT_NOFILE
, &rlimit
))
19539 lazy_hard_limit
= (rlimit
.rlim_max
< 1000000
19540 ? unsigned (rlimit
.rlim_max
) : 1000000);
19541 lazy_hard_limit
= (lazy_hard_limit
> LAZY_HEADROOM
19542 ? lazy_hard_limit
- LAZY_HEADROOM
: 0);
19543 if (rlimit
.rlim_cur
< limit
)
19544 limit
= unsigned (rlimit
.rlim_cur
);
19547 limit
= limit
> LAZY_HEADROOM
? limit
- LAZY_HEADROOM
: 1;
19549 if (unsigned parm
= param_lazy_modules
)
19551 if (parm
<= limit
|| !lazy_hard_limit
|| !try_increase_lazy (parm
))
19555 lazy_limit
= limit
;
19561 version2string (MODULE_VERSION
, ver
);
19562 dump ("Source: %s", main_input_filename
);
19563 dump ("Compiler: %s", version_string
);
19564 dump ("Modules: %s", ver
);
19565 dump ("Checking: %s",
19568 #elif ENABLE_ASSERT_CHECKING
19574 dump ("Compiled by: "
19576 "GCC %d.%d, %s", __GNUC__
, __GNUC_MINOR__
,
19577 #ifdef __OPTIMIZE__
19586 dump ("Reading: %s", MAPPED_READING
? "mmap" : "fileio");
19587 dump ("Writing: %s", MAPPED_WRITING
? "mmap" : "fileio");
19588 dump ("Lazy limit: %u", lazy_limit
);
19589 dump ("Lazy hard limit: %u", lazy_hard_limit
);
19593 /* Construct the global tree array. This is an array of unique
19594 global trees (& types). Do this now, rather than lazily, as
19595 some global trees are lazily created and we don't want that to
19596 mess with our syndrome of fixed trees. */
19598 vec_alloc (fixed_trees
, 200);
19600 dump () && dump ("+Creating globals");
19601 /* Insert the TRANSLATION_UNIT_DECL. */
19602 TREE_VISITED (DECL_CONTEXT (global_namespace
)) = true;
19603 fixed_trees
->quick_push (DECL_CONTEXT (global_namespace
));
19604 for (unsigned jx
= 0; global_tree_arys
[jx
].first
; jx
++)
19606 const tree
*ptr
= global_tree_arys
[jx
].first
;
19607 unsigned limit
= global_tree_arys
[jx
].second
;
19609 for (unsigned ix
= 0; ix
!= limit
; ix
++, ptr
++)
19611 !(ix
& 31) && dump ("") && dump ("+\t%u:%u:", jx
, ix
);
19612 unsigned v
= maybe_add_global (*ptr
, crc
);
19613 dump () && dump ("+%u", v
);
19616 global_crc
= crc32_unsigned (crc
, fixed_trees
->length ());
19617 dump ("") && dump ("Created %u unique globals, crc=%x",
19618 fixed_trees
->length (), global_crc
);
19619 for (unsigned ix
= fixed_trees
->length (); ix
--;)
19620 TREE_VISITED ((*fixed_trees
)[ix
]) = false;
19624 if (!flag_module_lazy
)
19625 /* Get the mapper now, if we're not being lazy. */
19626 get_mapper (cpp_main_loc (reader
));
19628 if (!flag_preprocess_only
)
19630 pending_table
= new pendset::hash (EXPERIMENT (1, 400));
19632 entity_map
= new entity_map_t (EXPERIMENT (1, 400));
19633 vec_safe_reserve (entity_ary
, EXPERIMENT (1, 400));
19637 note_defs
= note_defs_table_t::create_ggc (1000);
19640 if (flag_header_unit
&& cpp_get_options (reader
)->preprocessed
)
19641 begin_header_unit (reader
);
19643 /* Collect here to make sure things are tagged correctly (when
19644 aggressively GC'd). */
19648 /* If NODE is a deferred macro, load it. */
19651 load_macros (cpp_reader
*reader
, cpp_hashnode
*node
, void *)
19653 location_t main_loc
19654 = MAP_START_LOCATION (LINEMAPS_ORDINARY_MAP_AT (line_table
, 0));
19656 if (cpp_user_macro_p (node
)
19657 && !node
->value
.macro
)
19659 cpp_macro
*macro
= cpp_get_deferred_macro (reader
, node
, main_loc
);
19660 dump () && dump ("Loaded macro #%s %I",
19661 macro
? "define" : "undef", identifier (node
));
19667 /* At the end of tokenizing, we no longer need the macro tables of
19668 imports. But the user might have requested some checking. */
19671 maybe_check_all_macros (cpp_reader
*reader
)
19673 if (!warn_imported_macros
)
19676 /* Force loading of any remaining deferred macros. This will
19677 produce diagnostics if they are ill-formed. */
19678 unsigned n
= dump
.push (NULL
);
19679 cpp_forall_identifiers (reader
, load_macros
, NULL
);
19683 /* Write the CMI, if we're a module interface. */
19686 finish_module_processing (cpp_reader
*reader
)
19688 if (header_module_p ())
19689 module_kind
&= ~MK_EXPORTING
;
19691 if (!modules
|| !(*modules
)[0]->name
)
19693 if (flag_module_only
)
19694 warning (0, "%<-fmodule-only%> used for non-interface");
19696 else if (!flag_syntax_only
)
19701 timevar_start (TV_MODULE_EXPORT
);
19703 /* Force a valid but empty line map at the end. This simplifies
19704 the line table preparation and writing logic. */
19705 linemap_add (line_table
, LC_ENTER
, false, "", 0);
19707 /* We write to a tmpname, and then atomically rename. */
19708 const char *path
= NULL
;
19709 char *tmp_name
= NULL
;
19710 module_state
*state
= (*modules
)[0];
19712 unsigned n
= dump
.push (state
);
19713 state
->announce ("creating");
19714 if (state
->filename
)
19717 path
= maybe_add_cmi_prefix (state
->filename
, &len
);
19718 tmp_name
= XNEWVEC (char, len
+ 3);
19719 memcpy (tmp_name
, path
, len
);
19720 strcpy (&tmp_name
[len
], "~");
19723 for (unsigned again
= 2; ; again
--)
19725 fd
= open (tmp_name
,
19726 O_RDWR
| O_CREAT
| O_TRUNC
| O_CLOEXEC
| O_BINARY
,
19727 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IWGRP
|S_IROTH
|S_IWOTH
);
19729 if (fd
>= 0 || !again
|| e
!= ENOENT
)
19731 create_dirs (tmp_name
);
19733 dump () && dump ("CMI is %s", path
);
19737 warning_at (state
->loc
, 0, "not writing module %qs due to errors",
19738 state
->get_flatname ());
19741 elf_out
to (fd
, e
);
19744 auto loc
= input_location
;
19745 /* So crashes finger point the module decl. */
19746 input_location
= state
->loc
;
19747 state
->write (&to
, reader
);
19748 input_location
= loc
;
19752 /* Some OS's do not replace NEWNAME if it already
19753 exists. This'll have a race condition in erroneous
19754 concurrent builds. */
19756 if (rename (tmp_name
, path
))
19758 dump () && dump ("Rename ('%s','%s') errno=%u", errno
);
19759 to
.set_error (errno
);
19763 if (to
.get_error ())
19765 error_at (state
->loc
, "failed to write compiled module: %s",
19766 to
.get_error (state
->filename
));
19767 state
->note_cmi_name ();
19773 auto *mapper
= get_mapper (cpp_main_loc (reader
));
19775 mapper
->ModuleCompiled (state
->get_flatname ());
19779 /* We failed, attempt to erase all evidence we even tried. */
19782 XDELETEVEC (tmp_name
);
19786 timevar_stop (TV_MODULE_EXPORT
);
19793 unsigned n
= dump
.push (NULL
);
19794 dump () && dump ("Imported %u modules", modules
->length () - 1);
19795 dump () && dump ("Containing %u clusters", available_clusters
);
19796 dump () && dump ("Loaded %u clusters (%u%%)", loaded_clusters
,
19797 (loaded_clusters
* 100 + available_clusters
/ 2) /
19798 (available_clusters
+ !available_clusters
));
19802 if (modules
&& !header_module_p ())
19804 /* Determine call_init_p. We need the same bitmap allocation
19805 scheme as for the imports member. */
19806 function_depth
++; /* Disable GC. */
19807 bitmap
indirect_imports (BITMAP_GGC_ALLOC ());
19809 /* Because indirect imports are before their direct import, and
19810 we're scanning the array backwards, we only need one pass! */
19811 for (unsigned ix
= modules
->length (); --ix
;)
19813 module_state
*import
= (*modules
)[ix
];
19815 if (!import
->is_header ()
19816 && !bitmap_bit_p (indirect_imports
, ix
))
19818 /* Everything this imports is therefore indirectly
19820 bitmap_ior_into (indirect_imports
, import
->imports
);
19821 /* We don't have to worry about the self-import bit,
19822 because of the single pass. */
19824 import
->call_init_p
= true;
19825 num_init_calls_needed
++;
19835 /* We're done with the macro tables now. */
19836 vec_free (macro_exports
);
19837 vec_free (macro_imports
);
19840 /* We're now done with everything but the module names. */
19841 set_cmi_repo (NULL
);
19844 timevar_start (TV_MODULE_MAPPER
);
19845 module_client::close_module_client (0, mapper
);
19847 timevar_stop (TV_MODULE_MAPPER
);
19849 module_state_config::release ();
19856 for (unsigned ix
= modules
->length (); --ix
;)
19857 if (module_state
*state
= (*modules
)[ix
])
19860 /* No need to lookup modules anymore. */
19861 modules_hash
= NULL
;
19863 /* Or entity array. We still need the entity map to find import numbers. */
19867 /* Or remember any pending entities. */
19868 delete pending_table
;
19869 pending_table
= NULL
;
19871 /* Or any attachments -- Let it go! */
19872 delete attached_table
;
19873 attached_table
= NULL
;
19875 /* Allow a GC, we've possibly made much data unreachable. */
19879 /* If CODE is a module option, handle it & return true. Otherwise
19880 return false. For unknown reasons I cannot get the option
19881 generation machinery to set fmodule-mapper or -fmodule-header to
19882 make a string type option variable. */
19885 handle_module_option (unsigned code
, const char *str
, int)
19887 auto hdr
= CMS_header
;
19889 switch (opt_code (code
))
19891 case OPT_fmodule_mapper_
:
19892 module_mapper_name
= str
;
19895 case OPT_fmodule_header_
:
19897 if (!strcmp (str
, "user"))
19899 else if (!strcmp (str
, "system"))
19902 error ("unknown header kind %qs", str
);
19906 case OPT_fmodule_header
:
19907 flag_header_unit
= hdr
;
19911 case OPT_flang_info_include_translate_
:
19912 vec_safe_push (note_includes
, str
);
19920 /* Set preprocessor callbacks and options for modules. */
19923 module_preprocess_options (cpp_reader
*reader
)
19925 gcc_checking_assert (!lang_hooks
.preprocess_undef
);
19928 auto *cb
= cpp_get_callbacks (reader
);
19930 cb
->translate_include
= maybe_translate_include
;
19931 cb
->user_deferred_macro
= module_state::deferred_macro
;
19932 if (flag_header_unit
)
19934 /* If the preprocessor hook is already in use, that
19935 implementation will call the undef langhook. */
19937 lang_hooks
.preprocess_undef
= module_state::undef_macro
;
19939 cb
->undef
= module_state::undef_macro
;
19941 auto *opt
= cpp_get_options (reader
);
19942 opt
->module_directives
= true;
19943 opt
->main_search
= cpp_main_search (flag_header_unit
);
19947 #include "gt-cp-module.h"