1 /* C++ modules. Experimental!
2 Copyright (C) 2017-2022 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_MODULE_EXPORT_P, DECL_MODULE_PURVIEW_P, DECL_MODULE_ATTACH_P
51 and DECL_MODULE_IMPORT_P. The first indicates whether it is
52 exported, the second whether it is in module or header-unit
53 purview. The third indicates it is attached to the named module in
54 whose purview it resides and the fourth indicates whether it was an
55 import into this TU or not. DECL_MODULE_ATTACH_P will be false for
56 all decls in a header-unit, and for those in a named module inside
57 a linkage declaration.
59 The more detailed flags are DECL_MODULE_PARTITION_P,
60 DECL_MODULE_ENTITY_P. The first is set in a primary interface unit
61 on decls that were read from module partitions (these will have
62 DECL_MODULE_IMPORT_P set too). Such decls will be streamed out to
63 the primary's CMI. DECL_MODULE_ENTITY_P is set when an entity is
64 imported, even if it matched a non-imported entity. Such a decl
65 will not have DECL_MODULE_IMPORT_P set, even though it has an entry
66 in the entity map and array.
68 Header units are module-like.
70 For namespace-scope lookup, the decls for a particular module are
71 held located in a sparse array hanging off the binding of the name.
72 This is partitioned into two: a few fixed slots at the start
73 followed by the sparse slots afterwards. By construction we only
74 need to append new slots to the end -- there is never a need to
75 insert in the middle. The fixed slots are MODULE_SLOT_CURRENT for
76 the current TU (regardless of whether it is a module or not),
77 MODULE_SLOT_GLOBAL and MODULE_SLOT_PARTITION. These latter two
78 slots are used for merging entities across the global module and
79 module partitions respectively. MODULE_SLOT_PARTITION is only
80 present in a module. Neither of those two slots is searched during
81 name lookup -- they are internal use only. This vector is created
82 lazily once we require it, if there is only a declaration from the
83 current TU, a regular binding is present. It is converted on
86 OPTIMIZATION: Outside of the current TU, we only need ADL to work.
87 We could optimize regular lookup for the current TU by glomming all
88 the visible decls on its slot. Perhaps wait until design is a
89 little more settled though.
91 There is only one instance of each extern-linkage namespace. It
92 appears in every module slot that makes it visible. It also
93 appears in MODULE_SLOT_GLOBAL. (It is an ODR violation if they
94 collide with some other global module entity.) We also have an
95 optimization that shares the slot for adjacent modules that declare
96 the same such namespace.
98 A module interface compilation produces a Compiled Module Interface
99 (CMI). The format used is Encapsulated Lazy Records Of Numbered
100 Declarations, which is essentially ELF's section encapsulation. (As
101 all good nerds are aware, Elrond is half Elf.) Some sections are
102 named, and contain information about the module as a whole (indices
103 etc), and other sections are referenced by number. Although I
104 don't defend against actively hostile CMIs, there is some
105 checksumming involved to verify data integrity. When dumping out
106 an interface, we generate a graph of all the
107 independently-redeclarable DECLS that are needed, and the decls
108 they reference. From that we determine the strongly connected
109 components (SCC) within this TU. Each SCC is dumped to a separate
110 numbered section of the CMI. We generate a binding table section,
111 mapping each namespace&name to a defining section. This allows
114 Lazy loading employs mmap to map a read-only image of the CMI.
115 It thus only occupies address space and is paged in on demand,
116 backed by the CMI file itself. If mmap is unavailable, regular
117 FILEIO is used. Also, there's a bespoke ELF reader/writer here,
118 which implements just the section table and sections (including
119 string sections) of a 32-bit ELF in host byte-order. You can of
120 course inspect it with readelf. I figured 32-bit is sufficient,
121 for a single module. I detect running out of section numbers, but
122 do not implement the ELF overflow mechanism. At least you'll get
123 an error if that happens.
125 We do not separate declarations and definitions. My guess is that
126 if you refer to the declaration, you'll also need the definition
127 (template body, inline function, class definition etc). But this
128 does mean we can get larger SCCs than if we separated them. It is
129 unclear whether this is a win or not.
131 Notice that we embed section indices into the contents of other
132 sections. Thus random manipulation of the CMI file by ELF tools
133 may well break it. The kosher way would probably be to introduce
134 indirection via section symbols, but that would require defining a
137 Notice that lazy loading of one module's decls can cause lazy
138 loading of other decls in the same or another module. Clearly we
139 want to avoid loops. In a correct program there can be no loops in
140 the module dependency graph, and the above-mentioned SCC algorithm
141 places all intra-module circular dependencies in the same SCC. It
142 also orders the SCCs wrt each other, so dependent SCCs come first.
143 As we load dependent modules first, we know there can be no
144 reference to a higher-numbered module, and because we write out
145 dependent SCCs first, likewise for SCCs within the module. This
146 allows us to immediately detect broken references. When loading,
147 we must ensure the rest of the compiler doesn't cause some
148 unconnected load to occur (for instance, instantiate a template).
156 bytes - data streamer
157 bytes_in : bytes - scalar reader
158 bytes_out : bytes - scalar writer
161 elf_in : elf - ELROND reader
162 elf_out : elf - ELROND writer
164 trees_in : bytes_in - tree reader
165 trees_out : bytes_out - tree writer
167 depset - dependency set
168 depset::hash - hash table of depsets
169 depset::tarjan - SCC determinator
171 uidset<T> - set T's related to a UID
172 uidset<T>::hash hash table of uidset<T>
174 loc_spans - location map data
176 module_state - module object
178 slurping - data needed during loading
180 macro_import - imported macro data
181 macro_export - exported macro data
183 The ELROND objects use mmap, for both reading and writing. If mmap
184 is unavailable, fileno IO is used to read and write blocks of data.
186 The mapper object uses fileno IO to communicate with the server or
189 /* In expermental (trunk) sources, MODULE_VERSION is a #define passed
190 in from the Makefile. It records the modification date of the
191 source directory -- that's the only way to stay sane. In release
192 sources, we (plan to) use the compiler's major.minor versioning.
193 While the format might not change between at minor versions, it
194 seems simplest to tie the two together. There's no concept of
195 inter-version compatibility. */
196 #define IS_EXPERIMENTAL(V) ((V) >= (1U << 20))
197 #define MODULE_MAJOR(V) ((V) / 10000)
198 #define MODULE_MINOR(V) ((V) % 10000)
199 #define EXPERIMENT(A,B) (IS_EXPERIMENTAL (MODULE_VERSION) ? (A) : (B))
200 #ifndef MODULE_VERSION
201 #include "bversion.h"
202 #define MODULE_VERSION (BUILDING_GCC_MAJOR * 10000U + BUILDING_GCC_MINOR)
203 #elif !IS_EXPERIMENTAL (MODULE_VERSION)
204 #error "This is not the version I was looking for."
207 #define _DEFAULT_SOURCE 1 /* To get TZ field of struct tm, if available. */
209 #define INCLUDE_MEMORY
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
));
280 static inline tree
identifier (const cpp_hashnode
*node
)
282 /* HT_NODE() expands to node->ident that HT_IDENT_TO_GCC_IDENT()
283 then subtracts a nonzero constant, deriving a pointer to
284 a different member than ident. That's strictly undefined
285 and detected by -Warray-bounds. Suppress it. See PR 101372. */
286 #pragma GCC diagnostic push
287 #pragma GCC diagnostic ignored "-Warray-bounds"
288 return HT_IDENT_TO_GCC_IDENT (HT_NODE (const_cast<cpp_hashnode
*> (node
)));
289 #pragma GCC diagnostic pop
292 /* Id for dumping module information. */
295 /* We have a special module owner. */
296 #define MODULE_UNKNOWN (~0U) /* Not yet known. */
298 /* Prefix for section names. */
299 #define MOD_SNAME_PFX ".gnu.c++"
301 /* Format a version for user consumption. */
303 typedef char verstr_t
[32];
305 version2string (unsigned version
, verstr_t
&out
)
307 unsigned major
= MODULE_MAJOR (version
);
308 unsigned minor
= MODULE_MINOR (version
);
310 if (IS_EXPERIMENTAL (version
))
311 sprintf (out
, "%04u/%02u/%02u-%02u:%02u%s",
312 2000 + major
/ 10000, (major
/ 100) % 100, (major
% 100),
313 minor
/ 100, minor
% 100,
314 EXPERIMENT ("", " (experimental)"));
316 sprintf (out
, "%u.%u", major
, minor
);
319 /* Include files to note translation for. */
320 static vec
<const char *, va_heap
, vl_embed
> *note_includes
;
322 /* Modules to note CMI pathames. */
323 static vec
<const char *, va_heap
, vl_embed
> *note_cmis
;
325 /* Traits to hash an arbitrary pointer. Entries are not deletable,
326 and removal is a noop (removal needed upon destruction). */
327 template <typename T
>
328 struct nodel_ptr_hash
: pointer_hash
<T
>, typed_noop_remove
<T
*> {
329 /* Nothing is deletable. Everything is insertable. */
330 static bool is_deleted (T
*) { return false; }
331 static void mark_deleted (T
*) { gcc_unreachable (); }
334 /* Map from pointer to signed integer. */
335 typedef simple_hashmap_traits
<nodel_ptr_hash
<void>, int> ptr_int_traits
;
336 typedef hash_map
<void *,signed,ptr_int_traits
> ptr_int_hash_map
;
338 /********************************************************************/
339 /* Basic streaming & ELF. Serialization is usually via mmap. For
340 writing we slide a buffer over the output file, syncing it
341 approproiately. For reading we simply map the whole file (as a
342 file-backed read-only map -- it's just address space, leaving the
343 OS pager to deal with getting the data to us). Some buffers need
344 to be more conventional malloc'd contents. */
346 /* Variable length buffer. */
352 /* Tools tend to moan if the dtor's not virtual. */
353 virtual ~allocator () {}
356 void grow (data
&obj
, unsigned needed
, bool exact
);
357 void shrink (data
&obj
);
360 virtual char *grow (char *ptr
, unsigned needed
);
361 virtual void shrink (char *ptr
);
365 char *buffer
; /* Buffer being transferred. */
366 /* Although size_t would be the usual size, we know we never get
367 more than 4GB of buffer -- because that's the limit of the
368 encapsulation format. And if you need bigger imports, you're
370 unsigned size
; /* Allocated size of buffer. */
371 unsigned pos
; /* Position in buffer. */
375 :buffer (NULL
), size (0), pos (0)
380 /* Make sure the derived and/or using class know what they're
382 gcc_checking_assert (!buffer
);
386 char *use (unsigned count
)
388 if (size
< pos
+ count
)
390 char *res
= &buffer
[pos
];
396 void unuse (unsigned count
)
402 static allocator simple_memory
;
405 /* The simple data allocator. */
406 data::allocator
data::simple_memory
;
408 /* Grow buffer to at least size NEEDED. */
411 data::allocator::grow (data
&obj
, unsigned needed
, bool exact
)
413 gcc_checking_assert (needed
? needed
> obj
.size
: !obj
.size
);
415 /* Pick a default size. */
416 needed
= EXPERIMENT (100, 1000);
420 obj
.buffer
= grow (obj
.buffer
, needed
);
424 obj
.pos
= obj
.size
= 0;
430 data::allocator::shrink (data
&obj
)
438 data::allocator::grow (char *ptr
, unsigned needed
)
440 return XRESIZEVAR (char, ptr
, needed
);
444 data::allocator::shrink (char *ptr
)
449 /* Byte streamer base. Buffer with read/write position and smarts
452 class bytes
: public data
{
457 uint32_t bit_val
; /* Bit buffer. */
458 unsigned bit_pos
; /* Next bit in bit buffer. */
462 :parent (), bit_val (0), bit_pos (0)
469 unsigned calc_crc (unsigned) const;
472 /* Finish bit packet. Rewind the bytes not used. */
473 unsigned bit_flush ()
475 gcc_assert (bit_pos
);
476 unsigned bytes
= (bit_pos
+ 7) / 8;
484 /* Calculate the crc32 of the buffer. Note the CRC is stored in the
485 first 4 bytes, so don't include them. */
488 bytes::calc_crc (unsigned l
) const
491 for (size_t ix
= 4; ix
< l
; ix
++)
492 crc
= crc32_byte (crc
, buffer
[ix
]);
498 /* Byte stream reader. */
500 class bytes_in
: public bytes
{
501 typedef bytes parent
;
504 bool overrun
; /* Sticky read-too-much flag. */
508 : parent (), overrun (false)
516 /* Begin reading a named section. */
517 bool begin (location_t loc
, elf_in
*src
, const char *name
);
518 /* Begin reading a numbered section with optional name. */
519 bool begin (location_t loc
, elf_in
*src
, unsigned, const char * = NULL
);
520 /* Complete reading a buffer. Propagate errors and return true on
522 bool end (elf_in
*src
);
523 /* Return true if there is unread data. */
530 /* Start reading at OFFSET. */
531 void random_access (unsigned offset
)
536 bit_pos
= bit_val
= 0;
540 void align (unsigned boundary
)
542 if (unsigned pad
= pos
& (boundary
- 1))
543 read (boundary
- pad
);
547 const char *read (unsigned count
)
549 char *ptr
= use (count
);
556 bool check_crc () const;
557 /* We store the CRC in the first 4 bytes, using host endianness. */
558 unsigned get_crc () const
560 return *(const unsigned *)&buffer
[0];
564 /* Manipulate the overrun flag. */
565 bool get_overrun () const
575 unsigned u32 (); /* Read uncompressed integer. */
578 bool b (); /* Read a bool. */
579 void bflush (); /* Completed a block of bools. */
582 void bfill (); /* Get the next block of bools. */
585 int c (); /* Read a char. */
586 int i (); /* Read a signed int. */
587 unsigned u (); /* Read an unsigned int. */
588 size_t z (); /* Read a size_t. */
589 HOST_WIDE_INT
wi (); /* Read a HOST_WIDE_INT. */
590 unsigned HOST_WIDE_INT
wu (); /* Read an unsigned HOST_WIDE_INT. */
591 const char *str (size_t * = NULL
); /* Read a string. */
592 const void *buf (size_t); /* Read a fixed-length buffer. */
593 cpp_hashnode
*cpp_node (); /* Read a cpp node. */
596 /* Verify the buffer's CRC is correct. */
599 bytes_in::check_crc () const
604 unsigned c_crc
= calc_crc (size
);
605 if (c_crc
!= get_crc ())
613 /* Byte stream writer. */
615 class bytes_out
: public bytes
{
616 typedef bytes parent
;
619 allocator
*memory
; /* Obtainer of memory. */
622 bytes_out (allocator
*memory
)
623 : parent (), memory (memory
)
631 bool streaming_p () const
633 return memory
!= NULL
;
637 void set_crc (unsigned *crc_ptr
);
640 /* Begin writing, maybe reserve space for CRC. */
641 void begin (bool need_crc
= true);
642 /* Finish writing. Spill to section by number. */
643 unsigned end (elf_out
*, unsigned, unsigned *crc_ptr
= NULL
);
646 void align (unsigned boundary
)
648 if (unsigned pad
= pos
& (boundary
- 1))
649 write (boundary
- pad
);
653 char *write (unsigned count
, bool exact
= false)
655 if (size
< pos
+ count
)
656 memory
->grow (*this, pos
+ count
, exact
);
661 void u32 (unsigned); /* Write uncompressed integer. */
664 void b (bool); /* Write bool. */
665 void bflush (); /* Finish block of bools. */
668 void c (unsigned char); /* Write unsigned char. */
669 void i (int); /* Write signed int. */
670 void u (unsigned); /* Write unsigned int. */
671 void z (size_t s
); /* Write size_t. */
672 void wi (HOST_WIDE_INT
); /* Write HOST_WIDE_INT. */
673 void wu (unsigned HOST_WIDE_INT
); /* Write unsigned HOST_WIDE_INT. */
674 void str (const char *ptr
)
676 str (ptr
, strlen (ptr
));
678 void cpp_node (const cpp_hashnode
*node
)
680 str ((const char *)NODE_NAME (node
), NODE_LEN (node
));
682 void str (const char *, size_t); /* Write string of known length. */
683 void buf (const void *, size_t); /* Write fixed length buffer. */
684 void *buf (size_t); /* Create a writable buffer */
687 /* Format a NUL-terminated raw string. */
688 void printf (const char *, ...) ATTRIBUTE_PRINTF_2
;
689 void print_time (const char *, const tm
*, const char *);
692 /* Dump instrumentation. */
693 static void instrument ();
696 /* Instrumentation. */
697 static unsigned spans
[4];
698 static unsigned lengths
[4];
702 /* Instrumentation. */
703 unsigned bytes_out::spans
[4];
704 unsigned bytes_out::lengths
[4];
705 int bytes_out::is_set
= -1;
707 /* If CRC_PTR non-null, set the CRC of the buffer. Mix the CRC into
708 that pointed to by CRC_PTR. */
711 bytes_out::set_crc (unsigned *crc_ptr
)
715 gcc_checking_assert (pos
>= 4);
717 unsigned crc
= calc_crc (pos
);
718 unsigned accum
= *crc_ptr
;
719 /* Only mix the existing *CRC_PTR if it is non-zero. */
720 accum
= accum
? crc32_unsigned (accum
, crc
) : crc
;
723 /* Buffer will be sufficiently aligned. */
724 *(unsigned *)buffer
= crc
;
728 /* Finish a set of bools. */
736 lengths
[2] += bit_flush ();
749 /* When reading, we don't know how many bools we'll read in. So read
750 4 bytes-worth, and then rewind when flushing if we didn't need them
751 all. You can't have a block of bools closer than 4 bytes to the
752 end of the buffer. */
760 /* Bools are packed into bytes. You cannot mix bools and non-bools.
761 You must call bflush before emitting another type. So batch your
764 It may be worth optimizing for most bools being zero. Some kind of
765 run-length encoding? */
768 bytes_out::b (bool x
)
776 bit_val
|= unsigned (x
) << bit_pos
++;
780 lengths
[2] += bit_flush ();
789 bool v
= (bit_val
>> bit_pos
++) & 1;
795 /* Exactly 4 bytes. Used internally for bool packing and a few other
796 places. We can't simply use uint32_t because (a) alignment and
797 (b) we need little-endian for the bool streaming rewinding to make
801 bytes_out::u32 (unsigned val
)
803 if (char *ptr
= write (4))
816 if (const char *ptr
= read (4))
818 val
|= (unsigned char)ptr
[0];
819 val
|= (unsigned char)ptr
[1] << 8;
820 val
|= (unsigned char)ptr
[2] << 16;
821 val
|= (unsigned char)ptr
[3] << 24;
827 /* Chars are unsigned and written as single bytes. */
830 bytes_out::c (unsigned char v
)
832 if (char *ptr
= write (1))
840 if (const char *ptr
= read (1))
841 v
= (unsigned char)ptr
[0];
845 /* Ints 7-bit as a byte. Otherwise a 3bit count of following bytes in
846 big-endian form. 4 bits are in the first byte. */
851 if (char *ptr
= write (1))
853 if (v
<= 0x3f && v
>= -0x40)
860 for (probe
= v
>> 8; probe
> 0x7; probe
>>= 8)
863 for (probe
= v
>> 8; probe
< -0x8; probe
>>= 8)
865 *ptr
= 0x80 | bytes
<< 4 | (probe
& 0xf);
866 if ((ptr
= write (++bytes
)))
867 for (; bytes
--; v
>>= 8)
868 ptr
[bytes
] = v
& 0xff;
877 if (const char *ptr
= read (1))
882 unsigned bytes
= (v
>> 4) & 0x7;
886 /* unsigned necessary due to left shifts of -ve values. */
887 unsigned uv
= unsigned (v
);
888 if ((ptr
= read (++bytes
)))
890 uv
= (uv
<< 8) | (*ptr
++ & 0xff);
901 bytes_out::u (unsigned v
)
903 if (char *ptr
= write (1))
911 for (probe
= v
>> 8; probe
> 0xf; probe
>>= 8)
913 *ptr
= 0x80 | bytes
<< 4 | probe
;
914 if ((ptr
= write (++bytes
)))
915 for (; bytes
--; v
>>= 8)
916 ptr
[bytes
] = v
& 0xff;
926 if (const char *ptr
= read (1))
931 unsigned bytes
= (v
>> 4) & 0x7;
933 if ((ptr
= read (++bytes
)))
935 v
= (v
<< 8) | (*ptr
++ & 0xff);
943 bytes_out::wi (HOST_WIDE_INT v
)
945 if (char *ptr
= write (1))
947 if (v
<= 0x3f && v
>= -0x40)
954 for (probe
= v
>> 8; probe
> 0x7; probe
>>= 8)
957 for (probe
= v
>> 8; probe
< -0x8; probe
>>= 8)
959 *ptr
= 0x80 | bytes
<< 4 | (probe
& 0xf);
960 if ((ptr
= write (++bytes
)))
961 for (; bytes
--; v
>>= 8)
962 ptr
[bytes
] = v
& 0xff;
971 if (const char *ptr
= read (1))
976 unsigned bytes
= (v
>> 4) & 0x7;
980 /* unsigned necessary due to left shifts of -ve values. */
981 unsigned HOST_WIDE_INT uv
= (unsigned HOST_WIDE_INT
) v
;
982 if ((ptr
= read (++bytes
)))
984 uv
= (uv
<< 8) | (*ptr
++ & 0xff);
985 v
= (HOST_WIDE_INT
) uv
;
994 /* unsigned wide ints are just written as signed wide ints. */
997 bytes_out::wu (unsigned HOST_WIDE_INT v
)
999 wi ((HOST_WIDE_INT
) v
);
1002 inline unsigned HOST_WIDE_INT
1005 return (unsigned HOST_WIDE_INT
) wi ();
1008 /* size_t written as unsigned or unsigned wide int. */
1011 bytes_out::z (size_t s
)
1013 if (sizeof (s
) == sizeof (unsigned))
1022 if (sizeof (size_t) == sizeof (unsigned))
1028 /* Buffer simply memcpied. */
1030 bytes_out::buf (size_t len
)
1032 align (sizeof (void *) * 2);
1037 bytes_out::buf (const void *src
, size_t len
)
1039 if (void *ptr
= buf (len
))
1040 memcpy (ptr
, src
, len
);
1044 bytes_in::buf (size_t len
)
1046 align (sizeof (void *) * 2);
1047 const char *ptr
= read (len
);
1052 /* strings as an size_t length, followed by the buffer. Make sure
1053 there's a NUL terminator on read. */
1056 bytes_out::str (const char *string
, size_t len
)
1061 gcc_checking_assert (!string
[len
]);
1062 buf (string
, len
+ 1);
1067 bytes_in::str (size_t *len_p
)
1071 /* We're about to trust some user data. */
1076 const char *str
= NULL
;
1079 str
= reinterpret_cast<const char *> (buf (len
+ 1));
1080 if (!str
|| str
[len
])
1086 return str
? str
: "";
1090 bytes_in::cpp_node ()
1093 const char *s
= str (&len
);
1096 return ::cpp_node (get_identifier_with_length (s
, len
));
1099 /* Format a string directly to the buffer, including a terminating
1100 NUL. Intended for human consumption. */
1103 bytes_out::printf (const char *format
, ...)
1106 /* Exercise buffer expansion. */
1107 size_t len
= EXPERIMENT (10, 500);
1109 while (char *ptr
= write (len
))
1111 va_start (args
, format
);
1112 size_t actual
= vsnprintf (ptr
, len
, format
, args
) + 1;
1116 unuse (len
- actual
);
1125 bytes_out::print_time (const char *kind
, const tm
*time
, const char *tz
)
1127 printf ("%stime: %4u/%02u/%02u %02u:%02u:%02u %s",
1128 kind
, time
->tm_year
+ 1900, time
->tm_mon
+ 1, time
->tm_mday
,
1129 time
->tm_hour
, time
->tm_min
, time
->tm_sec
, tz
);
1132 /* Encapsulated Lazy Records Of Named Declarations.
1133 Header: Stunningly Elf32_Ehdr-like
1134 Sections: Sectional data
1135 [1-N) : User data sections
1136 N .strtab : strings, stunningly ELF STRTAB-like
1137 Index: Section table, stunningly ELF32_Shdr-like. */
1141 /* Constants used within the format. */
1142 enum private_constants
{
1154 /* Section numbering. */
1156 SHN_LORESERVE
= 0xff00,
1157 SHN_XINDEX
= 0xffff,
1159 /* Section types. */
1160 SHT_NONE
= 0, /* No contents. */
1161 SHT_PROGBITS
= 1, /* Random bytes. */
1162 SHT_STRTAB
= 3, /* A string table. */
1164 /* Section flags. */
1165 SHF_NONE
= 0x00, /* Nothing. */
1166 SHF_STRINGS
= 0x20, /* NUL-Terminated strings. */
1168 /* I really hope we do not get CMI files larger than 4GB. */
1170 /* It is host endianness that is relevant. */
1171 MY_ENDIAN
= DATA2LSB
1172 #ifdef WORDS_BIGENDIAN
1173 ^ DATA2LSB
^ DATA2MSB
1178 /* Constants visible to users. */
1179 enum public_constants
{
1180 /* Special error codes. Breaking layering a bit. */
1181 E_BAD_DATA
= -1, /* Random unexpected data errors. */
1182 E_BAD_LAZY
= -2, /* Badly ordered laziness. */
1183 E_BAD_IMPORT
= -3 /* A nested import failed. */
1187 /* File identification. On-disk representation. */
1189 uint8_t magic
[4]; /* 0x7f, 'E', 'L', 'F' */
1190 uint8_t klass
; /* 4:CLASS32 */
1191 uint8_t data
; /* 5:DATA2[LM]SB */
1192 uint8_t version
; /* 6:EV_CURRENT */
1193 uint8_t osabi
; /* 7:OSABI_NONE */
1194 uint8_t abiver
; /* 8: 0 */
1195 uint8_t pad
[7]; /* 9-15 */
1197 /* File header. On-disk representation. */
1200 uint16_t type
; /* ET_NONE */
1201 uint16_t machine
; /* EM_NONE */
1202 uint32_t version
; /* EV_CURRENT */
1203 uint32_t entry
; /* 0 */
1204 uint32_t phoff
; /* 0 */
1205 uint32_t shoff
; /* Section Header Offset in file */
1207 uint16_t ehsize
; /* ELROND Header SIZE -- sizeof (header) */
1208 uint16_t phentsize
; /* 0 */
1209 uint16_t phnum
; /* 0 */
1210 uint16_t shentsize
; /* Section Header SIZE -- sizeof (section) */
1211 uint16_t shnum
; /* Section Header NUM */
1212 uint16_t shstrndx
; /* Section Header STRing iNDeX */
1214 /* File section. On-disk representation. */
1216 uint32_t name
; /* String table offset. */
1217 uint32_t type
; /* SHT_* */
1218 uint32_t flags
; /* SHF_* */
1219 uint32_t addr
; /* 0 */
1220 uint32_t offset
; /* OFFSET in file */
1221 uint32_t size
; /* SIZE of section */
1222 uint32_t link
; /* 0 */
1223 uint32_t info
; /* 0 */
1224 uint32_t addralign
; /* 0 */
1225 uint32_t entsize
; /* ENTry SIZE, usually 0 */
1229 data hdr
; /* The header. */
1230 data sectab
; /* The section table. */
1231 data strtab
; /* String table. */
1232 int fd
; /* File descriptor we're reading or writing. */
1233 int err
; /* Sticky error code. */
1236 /* Construct from STREAM. E is errno if STREAM NULL. */
1238 :hdr (), sectab (), strtab (), fd (fd
), err (fd
>= 0 ? 0 : e
)
1242 gcc_checking_assert (fd
< 0 && !hdr
.buffer
1243 && !sectab
.buffer
&& !strtab
.buffer
);
1247 /* Return the error, if we have an error. */
1248 int get_error () const
1252 /* Set the error, unless it's already been set. */
1253 void set_error (int e
= E_BAD_DATA
)
1258 /* Get an error string. */
1259 const char *get_error (const char *) const;
1262 /* Begin reading/writing file. Return false on error. */
1265 return !get_error ();
1267 /* Finish reading/writing file. Return false on error. */
1271 /* Return error string. */
1274 elf::get_error (const char *name
) const
1277 return "Unknown CMI mapping";
1284 return "Bad file data";
1286 return "Bad import dependency";
1288 return "Bad lazy ordering";
1290 return xstrerror (err
);
1294 /* Finish file, return true if there's an error. */
1299 /* Close the stream and free the section table. */
1300 if (fd
>= 0 && close (fd
))
1304 return !get_error ();
1307 /* ELROND reader. */
1309 class elf_in
: public elf
{
1313 /* For freezing & defrosting. */
1314 #if !defined (HOST_LACKS_INODE_NUMBERS)
1320 elf_in (int fd
, int e
)
1329 bool is_frozen () const
1331 return fd
< 0 && hdr
.pos
;
1333 bool is_freezable () const
1335 return fd
>= 0 && hdr
.pos
;
1338 bool defrost (const char *);
1340 /* If BYTES is in the mmapped area, allocate a new buffer for it. */
1341 void preserve (bytes_in
&bytes ATTRIBUTE_UNUSED
)
1344 if (hdr
.buffer
&& bytes
.buffer
>= hdr
.buffer
1345 && bytes
.buffer
< hdr
.buffer
+ hdr
.pos
)
1347 char *buf
= bytes
.buffer
;
1348 bytes
.buffer
= data::simple_memory
.grow (NULL
, bytes
.size
);
1349 memcpy (bytes
.buffer
, buf
, bytes
.size
);
1353 /* If BYTES is not in SELF's mmapped area, free it. SELF might be
1355 static void release (elf_in
*self ATTRIBUTE_UNUSED
, bytes_in
&bytes
)
1358 if (!(self
&& self
->hdr
.buffer
&& bytes
.buffer
>= self
->hdr
.buffer
1359 && bytes
.buffer
< self
->hdr
.buffer
+ self
->hdr
.pos
))
1361 data::simple_memory
.shrink (bytes
.buffer
);
1362 bytes
.buffer
= NULL
;
1367 static void grow (data
&data
, unsigned needed
)
1369 gcc_checking_assert (!data
.buffer
);
1371 data
.buffer
= XNEWVEC (char, needed
);
1375 static void shrink (data
&data
)
1378 XDELETEVEC (data
.buffer
);
1385 const section
*get_section (unsigned s
) const
1387 if (s
* sizeof (section
) < sectab
.size
)
1388 return reinterpret_cast<const section
*>
1389 (§ab
.buffer
[s
* sizeof (section
)]);
1393 unsigned get_section_limit () const
1395 return sectab
.size
/ sizeof (section
);
1399 const char *read (data
*, unsigned, unsigned);
1402 /* Read section by number. */
1403 bool read (data
*d
, const section
*s
)
1405 return s
&& read (d
, s
->offset
, s
->size
);
1408 /* Find section by name. */
1409 unsigned find (const char *name
);
1410 /* Find section by index. */
1411 const section
*find (unsigned snum
, unsigned type
= SHT_PROGBITS
);
1414 /* Release the string table, when we're done with it. */
1421 bool begin (location_t
);
1427 munmap (hdr
.buffer
, hdr
.pos
);
1432 return parent::end ();
1436 /* Return string name at OFFSET. Checks OFFSET range. Always
1437 returns non-NULL. We know offset 0 is an empty string. */
1438 const char *name (unsigned offset
)
1440 return &strtab
.buffer
[offset
< strtab
.size
? offset
: 0];
1444 /* ELROND writer. */
1446 class elf_out
: public elf
, public data::allocator
{
1448 /* Desired section alignment on disk. */
1449 static const int SECTION_ALIGN
= 16;
1452 ptr_int_hash_map identtab
; /* Map of IDENTIFIERS to strtab offsets. */
1453 unsigned pos
; /* Write position in file. */
1455 unsigned offset
; /* Offset of the mapping. */
1456 unsigned extent
; /* Length of mapping. */
1457 unsigned page_size
; /* System page size. */
1461 elf_out (int fd
, int e
)
1462 :parent (fd
, e
), identtab (500), pos (0)
1465 offset
= extent
= 0;
1466 page_size
= sysconf (_SC_PAGE_SIZE
);
1467 if (page_size
< SECTION_ALIGN
)
1468 /* Something really strange. */
1474 data::simple_memory
.shrink (hdr
);
1475 data::simple_memory
.shrink (sectab
);
1476 data::simple_memory
.shrink (strtab
);
1481 void create_mapping (unsigned ext
, bool extending
= true);
1482 void remove_mapping ();
1486 using allocator::grow
;
1487 char *grow (char *, unsigned needed
) final override
;
1489 using allocator::shrink
;
1490 void shrink (char *) final override
;
1494 unsigned get_section_limit () const
1496 return sectab
.pos
/ sizeof (section
);
1500 unsigned add (unsigned type
, unsigned name
= 0,
1501 unsigned off
= 0, unsigned size
= 0, unsigned flags
= SHF_NONE
);
1502 unsigned write (const data
&);
1504 unsigned write (const bytes_out
&);
1508 /* IDENTIFIER to strtab offset. */
1509 unsigned name (tree ident
);
1510 /* String literal to strtab offset. */
1511 unsigned name (const char *n
);
1512 /* Qualified name of DECL to strtab offset. */
1513 unsigned qualified_name (tree decl
, bool is_defn
);
1516 unsigned strtab_write (const char *s
, unsigned l
);
1517 void strtab_write (tree decl
, int);
1520 /* Add a section with contents or strings. */
1521 unsigned add (const bytes_out
&, bool string_p
, unsigned name
);
1524 /* Begin and end writing. */
1529 /* Begin reading section NAME (of type PROGBITS) from SOURCE.
1530 Data always checked for CRC. */
1533 bytes_in::begin (location_t loc
, elf_in
*source
, const char *name
)
1535 unsigned snum
= source
->find (name
);
1537 return begin (loc
, source
, snum
, name
);
1540 /* Begin reading section numbered SNUM with NAME (may be NULL). */
1543 bytes_in::begin (location_t loc
, elf_in
*source
, unsigned snum
, const char *name
)
1545 if (!source
->read (this, source
->find (snum
))
1546 || !size
|| !check_crc ())
1548 source
->set_error (elf::E_BAD_DATA
);
1549 source
->shrink (*this);
1551 error_at (loc
, "section %qs is missing or corrupted", name
);
1553 error_at (loc
, "section #%u is missing or corrupted", snum
);
1560 /* Finish reading a section. */
1563 bytes_in::end (elf_in
*src
)
1570 src
->shrink (*this);
1575 /* Begin writing buffer. */
1578 bytes_out::begin (bool need_crc
)
1582 memory
->grow (*this, 0, false);
1585 /* Finish writing buffer. Stream out to SINK as named section NAME.
1586 Return section number or 0 on failure. If CRC_PTR is true, crc
1587 the data. Otherwise it is a string section. */
1590 bytes_out::end (elf_out
*sink
, unsigned name
, unsigned *crc_ptr
)
1596 unsigned sec_num
= sink
->add (*this, !crc_ptr
, name
);
1597 memory
->shrink (*this);
1602 /* Close and open the file, without destroying it. */
1607 gcc_checking_assert (!is_frozen ());
1609 if (munmap (hdr
.buffer
, hdr
.pos
) < 0)
1618 elf_in::defrost (const char *name
)
1620 gcc_checking_assert (is_frozen ());
1623 fd
= open (name
, O_RDONLY
| O_CLOEXEC
| O_BINARY
);
1624 if (fd
< 0 || fstat (fd
, &stat
) < 0)
1628 bool ok
= hdr
.pos
== unsigned (stat
.st_size
);
1629 #ifndef HOST_LACKS_INODE_NUMBERS
1630 if (device
!= stat
.st_dev
1631 || inode
!= stat
.st_ino
)
1639 char *mapping
= reinterpret_cast<char *>
1640 (mmap (NULL
, hdr
.pos
, PROT_READ
, MAP_SHARED
, fd
, 0));
1641 if (mapping
== MAP_FAILED
)
1646 if (madvise (mapping
, hdr
.pos
, MADV_RANDOM
))
1649 /* These buffers are never NULL in this case. */
1650 strtab
.buffer
= mapping
+ strtab
.pos
;
1651 sectab
.buffer
= mapping
+ sectab
.pos
;
1652 hdr
.buffer
= mapping
;
1658 return !get_error ();
1661 /* Read at current position into BUFFER. Return true on success. */
1664 elf_in::read (data
*data
, unsigned pos
, unsigned length
)
1667 if (pos
+ length
> hdr
.pos
)
1673 if (pos
!= ~0u && lseek (fd
, pos
, SEEK_SET
) < 0)
1679 grow (*data
, length
);
1681 data
->buffer
= hdr
.buffer
+ pos
;
1683 if (::read (fd
, data
->buffer
, data
->size
) != ssize_t (length
))
1691 return data
->buffer
;
1694 /* Read section SNUM of TYPE. Return section pointer or NULL on error. */
1696 const elf::section
*
1697 elf_in::find (unsigned snum
, unsigned type
)
1699 const section
*sec
= get_section (snum
);
1700 if (!snum
|| !sec
|| sec
->type
!= type
)
1705 /* Find a section NAME and TYPE. Return section number, or zero on
1709 elf_in::find (const char *sname
)
1711 for (unsigned pos
= sectab
.size
; pos
-= sizeof (section
); )
1714 = reinterpret_cast<const section
*> (§ab
.buffer
[pos
]);
1716 if (0 == strcmp (sname
, name (sec
->name
)))
1717 return pos
/ sizeof (section
);
1723 /* Begin reading file. Verify header. Pull in section and string
1724 tables. Return true on success. */
1727 elf_in::begin (location_t loc
)
1729 if (!parent::begin ())
1734 if (!fstat (fd
, &stat
))
1736 #if !defined (HOST_LACKS_INODE_NUMBERS)
1737 device
= stat
.st_dev
;
1738 inode
= stat
.st_ino
;
1740 /* Never generate files > 4GB, check we've not been given one. */
1741 if (stat
.st_size
== unsigned (stat
.st_size
))
1742 size
= unsigned (stat
.st_size
);
1746 /* MAP_SHARED so that the file is backing store. If someone else
1747 concurrently writes it, they're wrong. */
1748 void *mapping
= mmap (NULL
, size
, PROT_READ
, MAP_SHARED
, fd
, 0);
1749 if (mapping
== MAP_FAILED
)
1755 /* We'll be hopping over this randomly. Some systems declare the
1756 first parm as char *, and other declare it as void *. */
1757 if (madvise (reinterpret_cast <char *> (mapping
), size
, MADV_RANDOM
))
1760 hdr
.buffer
= (char *)mapping
;
1762 read (&hdr
, 0, sizeof (header
));
1764 hdr
.pos
= size
; /* Record size of the file. */
1766 const header
*h
= reinterpret_cast<const header
*> (hdr
.buffer
);
1770 if (h
->ident
.magic
[0] != 0x7f
1771 || h
->ident
.magic
[1] != 'E'
1772 || h
->ident
.magic
[2] != 'L'
1773 || h
->ident
.magic
[3] != 'F')
1775 error_at (loc
, "not Encapsulated Lazy Records of Named Declarations");
1781 /* We expect a particular format -- the ELF is not intended to be
1783 if (h
->ident
.klass
!= MY_CLASS
1784 || h
->ident
.data
!= MY_ENDIAN
1785 || h
->ident
.version
!= EV_CURRENT
1786 || h
->type
!= ET_NONE
1787 || h
->machine
!= EM_NONE
1788 || h
->ident
.osabi
!= OSABI_NONE
)
1790 error_at (loc
, "unexpected encapsulation format or type");
1795 if (!h
->shoff
|| h
->shentsize
!= sizeof (section
))
1799 error_at (loc
, "encapsulation is malformed");
1803 unsigned strndx
= h
->shstrndx
;
1804 unsigned shnum
= h
->shnum
;
1805 if (shnum
== SHN_XINDEX
)
1807 if (!read (§ab
, h
->shoff
, sizeof (section
)))
1813 shnum
= get_section (0)->size
;
1814 /* Freeing does mean we'll re-read it in the case we're not
1815 mapping, but this is going to be rare. */
1822 if (!read (§ab
, h
->shoff
, shnum
* sizeof (section
)))
1823 goto section_table_fail
;
1825 if (strndx
== SHN_XINDEX
)
1826 strndx
= get_section (0)->link
;
1828 if (!read (&strtab
, find (strndx
, SHT_STRTAB
)))
1831 /* The string table should be at least one byte, with NUL chars
1833 if (!(strtab
.size
&& !strtab
.buffer
[0]
1834 && !strtab
.buffer
[strtab
.size
- 1]))
1838 /* Record the offsets of the section and string tables. */
1839 sectab
.pos
= h
->shoff
;
1840 strtab
.pos
= shnum
* sizeof (section
);
1848 /* Create a new mapping. */
1852 elf_out::create_mapping (unsigned ext
, bool extending
)
1854 #ifndef HAVE_POSIX_FALLOCATE
1855 #define posix_fallocate(fd,off,len) ftruncate (fd, off + len)
1857 void *mapping
= MAP_FAILED
;
1858 if (extending
&& ext
< 1024 * 1024)
1860 if (!posix_fallocate (fd
, offset
, ext
* 2))
1861 mapping
= mmap (NULL
, ext
* 2, PROT_READ
| PROT_WRITE
,
1862 MAP_SHARED
, fd
, offset
);
1863 if (mapping
!= MAP_FAILED
)
1866 if (mapping
== MAP_FAILED
)
1868 if (!extending
|| !posix_fallocate (fd
, offset
, ext
))
1869 mapping
= mmap (NULL
, ext
, PROT_READ
| PROT_WRITE
,
1870 MAP_SHARED
, fd
, offset
);
1871 if (mapping
== MAP_FAILED
)
1878 #undef posix_fallocate
1879 hdr
.buffer
= (char *)mapping
;
1884 /* Flush out the current mapping. */
1888 elf_out::remove_mapping ()
1892 /* MS_ASYNC dtrt with the removed mapping, including a
1893 subsequent overlapping remap. */
1894 if (msync (hdr
.buffer
, extent
, MS_ASYNC
)
1895 || munmap (hdr
.buffer
, extent
))
1896 /* We're somewhat screwed at this point. */
1904 /* Grow a mapping of PTR to be NEEDED bytes long. This gets
1905 interesting if the new size grows the EXTENT. */
1908 elf_out::grow (char *data
, unsigned needed
)
1912 /* First allocation, check we're aligned. */
1913 gcc_checking_assert (!(pos
& (SECTION_ALIGN
- 1)));
1915 data
= hdr
.buffer
+ (pos
- offset
);
1920 unsigned off
= data
- hdr
.buffer
;
1921 if (off
+ needed
> extent
)
1923 /* We need to grow the mapping. */
1924 unsigned lwm
= off
& ~(page_size
- 1);
1925 unsigned hwm
= (off
+ needed
+ page_size
- 1) & ~(page_size
- 1);
1927 gcc_checking_assert (hwm
> extent
);
1932 create_mapping (extent
< hwm
- lwm
? hwm
- lwm
: extent
);
1934 data
= hdr
.buffer
+ (off
- lwm
);
1937 data
= allocator::grow (data
, needed
);
1944 /* Shrinking is a NOP. */
1946 elf_out::shrink (char *)
1951 /* Write S of length L to the strtab buffer. L must include the ending
1952 NUL, if that's what you want. */
1955 elf_out::strtab_write (const char *s
, unsigned l
)
1957 if (strtab
.pos
+ l
> strtab
.size
)
1958 data::simple_memory
.grow (strtab
, strtab
.pos
+ l
, false);
1959 memcpy (strtab
.buffer
+ strtab
.pos
, s
, l
);
1960 unsigned res
= strtab
.pos
;
1965 /* Write qualified name of decl. INNER >0 if this is a definition, <0
1966 if this is a qualifier of an outer name. */
1969 elf_out::strtab_write (tree decl
, int inner
)
1971 tree ctx
= CP_DECL_CONTEXT (decl
);
1973 ctx
= TYPE_NAME (ctx
);
1974 if (ctx
!= global_namespace
)
1975 strtab_write (ctx
, -1);
1977 tree name
= DECL_NAME (decl
);
1979 name
= DECL_ASSEMBLER_NAME_RAW (decl
);
1980 strtab_write (IDENTIFIER_POINTER (name
), IDENTIFIER_LENGTH (name
));
1983 strtab_write (&"::{}"[inner
+1], 2);
1986 /* Map IDENTIFIER IDENT to strtab offset. Inserts into strtab if not
1990 elf_out::name (tree ident
)
1996 int *slot
= &identtab
.get_or_insert (ident
, &existed
);
1998 *slot
= strtab_write (IDENTIFIER_POINTER (ident
),
1999 IDENTIFIER_LENGTH (ident
) + 1);
2005 /* Map LITERAL to strtab offset. Does not detect duplicates and
2006 expects LITERAL to remain live until strtab is written out. */
2009 elf_out::name (const char *literal
)
2011 return strtab_write (literal
, strlen (literal
) + 1);
2014 /* Map a DECL's qualified name to strtab offset. Does not detect
2018 elf_out::qualified_name (tree decl
, bool is_defn
)
2020 gcc_checking_assert (DECL_P (decl
) && decl
!= global_namespace
);
2021 unsigned result
= strtab
.pos
;
2023 strtab_write (decl
, is_defn
);
2024 strtab_write ("", 1);
2029 /* Add section to file. Return section number. TYPE & NAME identify
2030 the section. OFF and SIZE identify the file location of its
2031 data. FLAGS contains additional info. */
2034 elf_out::add (unsigned type
, unsigned name
, unsigned off
, unsigned size
,
2037 gcc_checking_assert (!(off
& (SECTION_ALIGN
- 1)));
2038 if (sectab
.pos
+ sizeof (section
) > sectab
.size
)
2039 data::simple_memory
.grow (sectab
, sectab
.pos
+ sizeof (section
), false);
2040 section
*sec
= reinterpret_cast<section
*> (sectab
.buffer
+ sectab
.pos
);
2041 memset (sec
, 0, sizeof (section
));
2047 if (flags
& SHF_STRINGS
)
2050 unsigned res
= sectab
.pos
;
2051 sectab
.pos
+= sizeof (section
);
2052 return res
/ sizeof (section
);
2055 /* Pad to the next alignment boundary, then write BUFFER to disk.
2056 Return the position of the start of the write, or zero on failure. */
2059 elf_out::write (const data
&buffer
)
2062 /* HDR is always mapped. */
2063 if (&buffer
!= &hdr
)
2065 bytes_out
out (this);
2066 grow (out
, buffer
.pos
, true);
2068 memcpy (out
.buffer
, buffer
.buffer
, buffer
.pos
);
2072 /* We should have been aligned during the first allocation. */
2073 gcc_checking_assert (!(pos
& (SECTION_ALIGN
- 1)));
2075 if (::write (fd
, buffer
.buffer
, buffer
.pos
) != ssize_t (buffer
.pos
))
2084 if (unsigned padding
= -pos
& (SECTION_ALIGN
- 1))
2087 /* Align the section on disk, should help the necessary copies.
2088 fseeking to extend is non-portable. */
2089 static char zero
[SECTION_ALIGN
];
2090 if (::write (fd
, &zero
, padding
) != ssize_t (padding
))
2098 /* Write a streaming buffer. It must be using us as an allocator. */
2102 elf_out::write (const bytes_out
&buf
)
2104 gcc_checking_assert (buf
.memory
== this);
2105 /* A directly mapped buffer. */
2106 gcc_checking_assert (buf
.buffer
- hdr
.buffer
>= 0
2107 && buf
.buffer
- hdr
.buffer
+ buf
.size
<= extent
);
2111 /* Align up. We're not going to advance into the next page. */
2112 pos
+= -pos
& (SECTION_ALIGN
- 1);
2118 /* Write data and add section. STRING_P is true for a string
2119 section, false for PROGBITS. NAME identifies the section (0 is the
2120 empty name). DATA is the contents. Return section number or 0 on
2121 failure (0 is the undef section). */
2124 elf_out::add (const bytes_out
&data
, bool string_p
, unsigned name
)
2126 unsigned off
= write (data
);
2128 return add (string_p
? SHT_STRTAB
: SHT_PROGBITS
, name
,
2129 off
, data
.pos
, string_p
? SHF_STRINGS
: SHF_NONE
);
2132 /* Begin writing the file. Initialize the section table and write an
2133 empty header. Return false on failure. */
2138 if (!parent::begin ())
2141 /* Let the allocators pick a default. */
2142 data::simple_memory
.grow (strtab
, 0, false);
2143 data::simple_memory
.grow (sectab
, 0, false);
2145 /* The string table starts with an empty string. */
2148 /* Create the UNDEF section. */
2152 /* Start a mapping. */
2153 create_mapping (EXPERIMENT (page_size
,
2154 (32767 + page_size
) & ~(page_size
- 1)));
2159 /* Write an empty header. */
2160 grow (hdr
, sizeof (header
), true);
2161 header
*h
= reinterpret_cast<header
*> (hdr
.buffer
);
2162 memset (h
, 0, sizeof (header
));
2165 return !get_error ();
2168 /* Finish writing the file. Write out the string & section tables.
2169 Fill in the header. Return true on error. */
2176 /* Write the string table. */
2177 unsigned strnam
= name (".strtab");
2178 unsigned stroff
= write (strtab
);
2179 unsigned strndx
= add (SHT_STRTAB
, strnam
, stroff
, strtab
.pos
,
2182 /* Store escape values in section[0]. */
2183 if (strndx
>= SHN_LORESERVE
)
2185 reinterpret_cast<section
*> (sectab
.buffer
)->link
= strndx
;
2186 strndx
= SHN_XINDEX
;
2188 unsigned shnum
= sectab
.pos
/ sizeof (section
);
2189 if (shnum
>= SHN_LORESERVE
)
2191 reinterpret_cast<section
*> (sectab
.buffer
)->size
= shnum
;
2195 unsigned shoff
= write (sectab
);
2202 create_mapping ((sizeof (header
) + page_size
- 1) & ~(page_size
- 1),
2205 unsigned length
= pos
;
2207 if (lseek (fd
, 0, SEEK_SET
) < 0)
2213 /* Write the correct header now. */
2214 header
*h
= reinterpret_cast<header
*> (hdr
.buffer
);
2215 h
->ident
.magic
[0] = 0x7f;
2216 h
->ident
.magic
[1] = 'E'; /* Elrond */
2217 h
->ident
.magic
[2] = 'L'; /* is an */
2218 h
->ident
.magic
[3] = 'F'; /* elf. */
2219 h
->ident
.klass
= MY_CLASS
;
2220 h
->ident
.data
= MY_ENDIAN
;
2221 h
->ident
.version
= EV_CURRENT
;
2222 h
->ident
.osabi
= OSABI_NONE
;
2224 h
->machine
= EM_NONE
;
2225 h
->version
= EV_CURRENT
;
2227 h
->ehsize
= sizeof (header
);
2228 h
->shentsize
= sizeof (section
);
2230 h
->shstrndx
= strndx
;
2238 if (ftruncate (fd
, length
))
2243 data::simple_memory
.shrink (sectab
);
2244 data::simple_memory
.shrink (strtab
);
2246 return parent::end ();
2249 /********************************************************************/
2251 /* A dependency set. This is used during stream out to determine the
2252 connectivity of the graph. Every namespace-scope declaration that
2253 needs writing has a depset. The depset is filled with the (depsets
2254 of) declarations within this module that it references. For a
2255 declaration that'll generally be named types. For definitions
2256 it'll also be declarations in the body.
2258 From that we can convert the graph to a DAG, via determining the
2259 Strongly Connected Clusters. Each cluster is streamed
2260 independently, and thus we achieve lazy loading.
2262 Other decls that get a depset are namespaces themselves and
2263 unnameable declarations. */
2267 tree entity
; /* Entity, or containing namespace. */
2268 uintptr_t discriminator
; /* Flags or identifier. */
2271 /* The kinds of entity the depset could describe. The ordering is
2272 significant, see entity_kind_name. */
2275 EK_DECL
, /* A decl. */
2276 EK_SPECIALIZATION
, /* A specialization. */
2277 EK_PARTIAL
, /* A partial specialization. */
2278 EK_USING
, /* A using declaration (at namespace scope). */
2279 EK_NAMESPACE
, /* A namespace. */
2280 EK_REDIRECT
, /* Redirect to a template_decl. */
2282 EK_BINDING
= EK_EXPLICIT_HWM
, /* Implicitly encoded. */
2283 EK_FOR_BINDING
, /* A decl being inserted for a binding. */
2284 EK_INNER_DECL
, /* A decl defined outside of its imported
2286 EK_DIRECT_HWM
= EK_PARTIAL
+ 1,
2288 EK_BITS
= 3 /* Only need to encode below EK_EXPLICIT_HWM. */
2292 /* Placement of bit fields in discriminator. */
2295 DB_ZERO_BIT
, /* Set to disambiguate identifier from flags */
2296 DB_SPECIAL_BIT
, /* First dep slot is special. */
2297 DB_KIND_BIT
, /* Kind of the entity. */
2298 DB_KIND_BITS
= EK_BITS
,
2299 DB_DEFN_BIT
= DB_KIND_BIT
+ DB_KIND_BITS
,
2300 DB_IS_MEMBER_BIT
, /* Is an out-of-class member. */
2301 DB_IS_INTERNAL_BIT
, /* It is an (erroneous)
2302 internal-linkage entity. */
2303 DB_REFS_INTERNAL_BIT
, /* Refers to an internal-linkage
2305 DB_IMPORTED_BIT
, /* An imported entity. */
2306 DB_UNREACHED_BIT
, /* A yet-to-be reached entity. */
2307 DB_HIDDEN_BIT
, /* A hidden binding. */
2308 /* The following bits are not independent, but enumerating them is
2310 DB_ALIAS_TMPL_INST_BIT
, /* An alias template instantiation. */
2311 DB_ALIAS_SPEC_BIT
, /* Specialization of an alias template
2312 (in both spec tables). */
2313 DB_TYPE_SPEC_BIT
, /* Specialization in the type table.
2315 DB_FRIEND_SPEC_BIT
, /* An instantiated template friend. */
2319 /* The first slot is special for EK_SPECIALIZATIONS it is a
2320 spec_entry pointer. It is not relevant for the SCC
2322 vec
<depset
*> deps
; /* Depsets we reference. */
2325 unsigned cluster
; /* Strongly connected cluster, later entity number */
2326 unsigned section
; /* Section written to. */
2327 /* During SCC construction, section is lowlink, until the depset is
2328 removed from the stack. See Tarjan algorithm for details. */
2331 /* Construction via factories. Destruction via hash traits. */
2332 depset (tree entity
);
2336 static depset
*make_binding (tree
, tree
);
2337 static depset
*make_entity (tree
, entity_kind
, bool = false);
2338 /* Late setting a binding name -- /then/ insert into hash! */
2339 inline void set_binding_name (tree name
)
2341 gcc_checking_assert (!get_name ());
2342 discriminator
= reinterpret_cast<uintptr_t> (name
);
2346 template<unsigned I
> void set_flag_bit ()
2348 gcc_checking_assert (I
< 2 || !is_binding ());
2349 discriminator
|= 1u << I
;
2351 template<unsigned I
> void clear_flag_bit ()
2353 gcc_checking_assert (I
< 2 || !is_binding ());
2354 discriminator
&= ~(1u << I
);
2356 template<unsigned I
> bool get_flag_bit () const
2358 gcc_checking_assert (I
< 2 || !is_binding ());
2359 return bool ((discriminator
>> I
) & 1);
2363 bool is_binding () const
2365 return !get_flag_bit
<DB_ZERO_BIT
> ();
2367 entity_kind
get_entity_kind () const
2371 return entity_kind ((discriminator
>> DB_KIND_BIT
) & ((1u << EK_BITS
) - 1));
2373 const char *entity_kind_name () const;
2376 bool has_defn () const
2378 return get_flag_bit
<DB_DEFN_BIT
> ();
2382 /* This class-member is defined here, but the class was imported. */
2383 bool is_member () const
2385 gcc_checking_assert (get_entity_kind () == EK_DECL
);
2386 return get_flag_bit
<DB_IS_MEMBER_BIT
> ();
2389 bool is_internal () const
2391 return get_flag_bit
<DB_IS_INTERNAL_BIT
> ();
2393 bool refs_internal () const
2395 return get_flag_bit
<DB_REFS_INTERNAL_BIT
> ();
2397 bool is_import () const
2399 return get_flag_bit
<DB_IMPORTED_BIT
> ();
2401 bool is_unreached () const
2403 return get_flag_bit
<DB_UNREACHED_BIT
> ();
2405 bool is_alias_tmpl_inst () const
2407 return get_flag_bit
<DB_ALIAS_TMPL_INST_BIT
> ();
2409 bool is_alias () const
2411 return get_flag_bit
<DB_ALIAS_SPEC_BIT
> ();
2413 bool is_hidden () const
2415 return get_flag_bit
<DB_HIDDEN_BIT
> ();
2417 bool is_type_spec () const
2419 return get_flag_bit
<DB_TYPE_SPEC_BIT
> ();
2421 bool is_friend_spec () const
2423 return get_flag_bit
<DB_FRIEND_SPEC_BIT
> ();
2427 /* We set these bit outside of depset. */
2428 void set_hidden_binding ()
2430 set_flag_bit
<DB_HIDDEN_BIT
> ();
2432 void clear_hidden_binding ()
2434 clear_flag_bit
<DB_HIDDEN_BIT
> ();
2438 bool is_special () const
2440 return get_flag_bit
<DB_SPECIAL_BIT
> ();
2444 set_flag_bit
<DB_SPECIAL_BIT
> ();
2448 tree
get_entity () const
2452 tree
get_name () const
2454 gcc_checking_assert (is_binding ());
2455 return reinterpret_cast <tree
> (discriminator
);
2459 /* Traits for a hash table of pointers to bindings. */
2461 /* Each entry is a pointer to a depset. */
2462 typedef depset
*value_type
;
2463 /* We lookup by container:maybe-identifier pair. */
2464 typedef std::pair
<tree
,tree
> compare_type
;
2466 static const bool empty_zero_p
= true;
2468 /* hash and equality for compare_type. */
2469 inline static hashval_t
hash (const compare_type
&p
)
2471 hashval_t h
= pointer_hash
<tree_node
>::hash (p
.first
);
2474 hashval_t nh
= IDENTIFIER_HASH_VALUE (p
.second
);
2475 h
= iterative_hash_hashval_t (h
, nh
);
2479 inline static bool equal (const value_type b
, const compare_type
&p
)
2481 if (b
->entity
!= p
.first
)
2485 return b
->discriminator
== reinterpret_cast<uintptr_t> (p
.second
);
2487 return !b
->is_binding ();
2490 /* (re)hasher for a binding itself. */
2491 inline static hashval_t
hash (const value_type b
)
2493 hashval_t h
= pointer_hash
<tree_node
>::hash (b
->entity
);
2494 if (b
->is_binding ())
2496 hashval_t nh
= IDENTIFIER_HASH_VALUE (b
->get_name ());
2497 h
= iterative_hash_hashval_t (h
, nh
);
2502 /* Empty via NULL. */
2503 static inline void mark_empty (value_type
&p
) {p
= NULL
;}
2504 static inline bool is_empty (value_type p
) {return !p
;}
2506 /* Nothing is deletable. Everything is insertable. */
2507 static bool is_deleted (value_type
) { return false; }
2508 static void mark_deleted (value_type
) { gcc_unreachable (); }
2510 /* We own the entities in the hash table. */
2511 static void remove (value_type p
)
2518 class hash
: public hash_table
<traits
> {
2519 typedef traits::compare_type key_t
;
2520 typedef hash_table
<traits
> parent
;
2523 vec
<depset
*> worklist
; /* Worklist of decls to walk. */
2524 hash
*chain
; /* Original table. */
2525 depset
*current
; /* Current depset being depended. */
2526 unsigned section
; /* When writing out, the section. */
2527 bool sneakoscope
; /* Detecting dark magic (of a voldemort). */
2528 bool reached_unreached
; /* We reached an unreached entity. */
2531 hash (size_t size
, hash
*c
= NULL
)
2532 : parent (size
), chain (c
), current (NULL
), section (0),
2533 sneakoscope (false), reached_unreached (false)
2535 worklist
.create (size
);
2539 worklist
.release ();
2543 bool is_key_order () const
2545 return chain
!= NULL
;
2549 depset
**entity_slot (tree entity
, bool = true);
2550 depset
**binding_slot (tree ctx
, tree name
, bool = true);
2551 depset
*maybe_add_declaration (tree decl
);
2554 depset
*find_dependency (tree entity
);
2555 depset
*find_binding (tree ctx
, tree name
);
2556 depset
*make_dependency (tree decl
, entity_kind
);
2557 void add_dependency (depset
*);
2560 void add_mergeable (depset
*);
2561 depset
*add_dependency (tree decl
, entity_kind
);
2562 void add_namespace_context (depset
*, tree ns
);
2565 static bool add_binding_entity (tree
, WMB_Flags
, void *);
2568 bool add_namespace_entities (tree ns
, bitmap partitions
);
2569 void add_specializations (bool decl_p
);
2570 void add_partial_entities (vec
<tree
, va_gc
> *);
2571 void add_class_entities (vec
<tree
, va_gc
> *);
2574 void find_dependencies (module_state
*);
2575 bool finalize_dependencies ();
2576 vec
<depset
*> connect ();
2581 vec
<depset
*> result
;
2582 vec
<depset
*> stack
;
2585 tarjan (unsigned size
)
2588 result
.create (size
);
2593 gcc_assert (!stack
.length ());
2598 void connect (depset
*);
2603 depset::depset (tree entity
)
2604 :entity (entity
), discriminator (0), cluster (0), section (0)
2616 depset::entity_kind_name () const
2618 /* Same order as entity_kind. */
2619 static const char *const names
[] =
2620 {"decl", "specialization", "partial", "using",
2621 "namespace", "redirect", "binding"};
2622 entity_kind kind
= get_entity_kind ();
2623 gcc_checking_assert (kind
< ARRAY_SIZE (names
));
2627 /* Create a depset for a namespace binding NS::NAME. */
2629 depset
*depset::make_binding (tree ns
, tree name
)
2631 depset
*binding
= new depset (ns
);
2633 binding
->discriminator
= reinterpret_cast <uintptr_t> (name
);
2638 depset
*depset::make_entity (tree entity
, entity_kind ek
, bool is_defn
)
2640 depset
*r
= new depset (entity
);
2642 r
->discriminator
= ((1 << DB_ZERO_BIT
)
2643 | (ek
<< DB_KIND_BIT
)
2644 | is_defn
<< DB_DEFN_BIT
);
2657 struct default_hash_traits
<pending_key
>
2659 using value_type
= pending_key
;
2661 static const bool empty_zero_p
= false;
2662 static hashval_t
hash (const value_type
&k
)
2664 hashval_t h
= IDENTIFIER_HASH_VALUE (k
.id
);
2665 h
= iterative_hash_hashval_t (DECL_UID (k
.ns
), h
);
2669 static bool equal (const value_type
&k
, const value_type
&l
)
2671 return k
.ns
== l
.ns
&& k
.id
== l
.id
;
2673 static void mark_empty (value_type
&k
)
2675 k
.ns
= k
.id
= NULL_TREE
;
2677 static void mark_deleted (value_type
&k
)
2680 gcc_checking_assert (k
.id
);
2682 static bool is_empty (const value_type
&k
)
2684 return k
.ns
== NULL_TREE
&& k
.id
== NULL_TREE
;
2686 static bool is_deleted (const value_type
&k
)
2688 return k
.ns
== NULL_TREE
&& k
.id
!= NULL_TREE
;
2690 static void remove (value_type
&)
2695 typedef hash_map
<pending_key
, auto_vec
<unsigned>> pending_map_t
;
2697 /* Not-loaded entities that are keyed to a namespace-scope
2698 identifier. See module_state::write_pendings for details. */
2699 pending_map_t
*pending_table
;
2701 /* Decls that need some post processing once a batch of lazy loads has
2703 vec
<tree
, va_heap
, vl_embed
> *post_load_decls
;
2705 /* Some entities are keyed to another entitity for ODR purposes.
2706 For example, at namespace scope, 'inline auto var = []{};', that
2707 lambda is keyed to 'var', and follows its ODRness. */
2708 typedef hash_map
<tree
, auto_vec
<tree
>> keyed_map_t
;
2709 static keyed_map_t
*keyed_table
;
2711 /********************************************************************/
2712 /* Tree streaming. The tree streaming is very specific to the tree
2713 structures themselves. A tag indicates the kind of tree being
2714 streamed. -ve tags indicate backreferences to already-streamed
2715 trees. Backreferences are auto-numbered. */
2719 tt_null
, /* NULL_TREE. */
2720 tt_fixed
, /* Fixed vector index. */
2722 tt_node
, /* By-value node. */
2723 tt_decl
, /* By-value mergeable decl. */
2724 tt_tpl_parm
, /* Template parm. */
2726 /* The ordering of the following 4 is relied upon in
2727 trees_out::tree_node. */
2728 tt_id
, /* Identifier node. */
2729 tt_conv_id
, /* Conversion operator name. */
2730 tt_anon_id
, /* Anonymous name. */
2731 tt_lambda_id
, /* Lambda name. */
2733 tt_typedef_type
, /* A (possibly implicit) typedefed type. */
2734 tt_derived_type
, /* A type derived from another type. */
2735 tt_variant_type
, /* A variant of another type. */
2737 tt_tinfo_var
, /* Typeinfo object. */
2738 tt_tinfo_typedef
, /* Typeinfo typedef. */
2739 tt_ptrmem_type
, /* Pointer to member type. */
2740 tt_nttp_var
, /* NTTP_OBJECT VAR_DECL. */
2742 tt_parm
, /* Function parameter or result. */
2743 tt_enum_value
, /* An enum value. */
2744 tt_enum_decl
, /* An enum decl. */
2745 tt_data_member
, /* Data member/using-decl. */
2747 tt_binfo
, /* A BINFO. */
2748 tt_vtable
, /* A vtable. */
2749 tt_thunk
, /* A thunk. */
2752 tt_entity
, /* A extra-cluster entity. */
2754 tt_template
, /* The TEMPLATE_RESULT of a template. */
2758 WK_none
, /* No walk to do (a back- or fixed-ref happened). */
2759 WK_normal
, /* Normal walk (by-name if possible). */
2761 WK_value
, /* By-value walk. */
2766 MK_unique
, /* Known unique. */
2767 MK_named
, /* Found by CTX, NAME + maybe_arg types etc. */
2768 MK_field
, /* Found by CTX and index on TYPE_FIELDS */
2769 MK_vtable
, /* Found by CTX and index on TYPE_VTABLES */
2770 MK_as_base
, /* Found by CTX. */
2774 MK_enum
, /* Found by CTX, & 1stMemberNAME. */
2775 MK_keyed
, /* Found by key & index. */
2777 MK_friend_spec
, /* Like named, but has a tmpl & args too. */
2778 MK_local_friend
, /* Found by CTX, index. */
2780 MK_indirect_lwm
= MK_enum
,
2782 /* Template specialization kinds below. These are all found via
2783 primary template and specialization args. */
2784 MK_template_mask
= 0x10, /* A template specialization. */
2786 MK_tmpl_decl_mask
= 0x4, /* In decl table. */
2787 MK_tmpl_alias_mask
= 0x2, /* Also in type table */
2789 MK_tmpl_tmpl_mask
= 0x1, /* We want TEMPLATE_DECL. */
2791 MK_type_spec
= MK_template_mask
,
2792 MK_decl_spec
= MK_template_mask
| MK_tmpl_decl_mask
,
2793 MK_alias_spec
= MK_decl_spec
| MK_tmpl_alias_mask
,
2797 /* This is more than a debugging array. NULLs are used to determine
2798 an invalid merge_kind number. */
2799 static char const *const merge_kind_name
[MK_hwm
] =
2801 "unique", "named", "field", "vtable", /* 0...3 */
2802 "asbase", "partial", "enum", "attached", /* 4...7 */
2804 "friend spec", "local friend", NULL
, NULL
, /* 8...11 */
2805 NULL
, NULL
, NULL
, NULL
,
2807 "type spec", "type tmpl spec", /* 16,17 type (template). */
2810 "decl spec", "decl tmpl spec", /* 20,21 decl (template). */
2811 "alias spec", "alias tmpl spec", /* 22,23 alias (template). */
2812 NULL
, NULL
, NULL
, NULL
,
2813 NULL
, NULL
, NULL
, NULL
,
2816 /* Mergeable entity location data. */
2818 cp_ref_qualifier ref_q
: 2;
2821 tree ret
; /* Return type, if appropriate. */
2822 tree args
; /* Arg types, if appropriate. */
2824 tree constraints
; /* Constraints. */
2827 :ref_q (REF_QUAL_NONE
), index (0),
2828 ret (NULL_TREE
), args (NULL_TREE
),
2829 constraints (NULL_TREE
)
2834 /* Hashmap of merged duplicates. Usually decls, but can contain
2836 typedef hash_map
<tree
,uintptr_t,
2837 simple_hashmap_traits
<nodel_ptr_hash
<tree_node
>,uintptr_t> >
2840 /* Tree stream reader. Note that reading a stream doesn't mark the
2841 read trees with TREE_VISITED. Thus it's quite safe to have
2842 multiple concurrent readers. Which is good, because lazy
2844 class trees_in
: public bytes_in
{
2845 typedef bytes_in parent
;
2848 module_state
*state
; /* Module being imported. */
2849 vec
<tree
> back_refs
; /* Back references. */
2850 duplicate_hash_map
*duplicates
; /* Map from existings to duplicate. */
2851 vec
<tree
> post_decls
; /* Decls to post process. */
2852 unsigned unused
; /* Inhibit any interior TREE_USED
2856 trees_in (module_state
*);
2861 tree
back_ref (int);
2864 tree
start (unsigned = 0);
2867 /* Needed for binfo writing */
2868 bool core_bools (tree
);
2871 /* Stream tree_core, lang_decl_specific and lang_type_specific
2873 bool core_vals (tree
);
2874 bool lang_type_bools (tree
);
2875 bool lang_type_vals (tree
);
2876 bool lang_decl_bools (tree
);
2877 bool lang_decl_vals (tree
);
2878 bool lang_vals (tree
);
2879 bool tree_node_bools (tree
);
2880 bool tree_node_vals (tree
);
2883 tree
tpl_parm_value ();
2886 tree
chained_decls (); /* Follow DECL_CHAIN. */
2887 vec
<tree
, va_heap
> *vec_chained_decls ();
2888 vec
<tree
, va_gc
> *tree_vec (); /* vec of tree. */
2889 vec
<tree_pair_s
, va_gc
> *tree_pair_vec (); /* vec of tree_pair. */
2890 tree
tree_list (bool has_purpose
);
2893 /* Read a tree node. */
2894 tree
tree_node (bool is_use
= false);
2897 bool install_entity (tree decl
);
2898 tree
tpl_parms (unsigned &tpl_levels
);
2899 bool tpl_parms_fini (tree decl
, unsigned tpl_levels
);
2900 bool tpl_header (tree decl
, unsigned *tpl_levels
);
2901 int fn_parms_init (tree
);
2902 void fn_parms_fini (int tag
, tree fn
, tree existing
, bool has_defn
);
2903 unsigned add_indirect_tpl_parms (tree
);
2905 bool add_indirects (tree
);
2908 /* Serialize various definitions. */
2909 bool read_definition (tree decl
);
2912 bool is_matching_decl (tree existing
, tree decl
, bool is_typedef
);
2913 static bool install_implicit_member (tree decl
);
2914 bool read_function_def (tree decl
, tree maybe_template
);
2915 bool read_var_def (tree decl
, tree maybe_template
);
2916 bool read_class_def (tree decl
, tree maybe_template
);
2917 bool read_enum_def (tree decl
, tree maybe_template
);
2920 tree
decl_container ();
2921 tree
key_mergeable (int tag
, merge_kind
, tree decl
, tree inner
, tree type
,
2922 tree container
, bool is_attached
);
2923 unsigned binfo_mergeable (tree
*);
2926 uintptr_t *find_duplicate (tree existing
);
2927 void register_duplicate (tree decl
, tree existing
);
2928 /* Mark as an already diagnosed bad duplicate. */
2929 void unmatched_duplicate (tree existing
)
2931 *find_duplicate (existing
) |= 1;
2935 bool is_duplicate (tree decl
)
2937 return find_duplicate (decl
) != NULL
;
2939 tree
maybe_duplicate (tree decl
)
2941 if (uintptr_t *dup
= find_duplicate (decl
))
2942 return reinterpret_cast<tree
> (*dup
& ~uintptr_t (1));
2945 tree
odr_duplicate (tree decl
, bool has_defn
);
2948 /* Return the next decl to postprocess, or NULL. */
2949 tree
post_process ()
2951 return post_decls
.length () ? post_decls
.pop () : NULL_TREE
;
2954 /* Register DECL for postprocessing. */
2955 void post_process (tree decl
)
2957 post_decls
.safe_push (decl
);
2961 void assert_definition (tree
, bool installing
);
2964 trees_in::trees_in (module_state
*state
)
2965 :parent (), state (state
), unused (0)
2968 back_refs
.create (500);
2969 post_decls
.create (0);
2972 trees_in::~trees_in ()
2974 delete (duplicates
);
2975 back_refs
.release ();
2976 post_decls
.release ();
2979 /* Tree stream writer. */
2980 class trees_out
: public bytes_out
{
2981 typedef bytes_out parent
;
2984 module_state
*state
; /* The module we are writing. */
2985 ptr_int_hash_map tree_map
; /* Trees to references */
2986 depset::hash
*dep_hash
; /* Dependency table. */
2987 int ref_num
; /* Back reference number. */
2990 int importedness
; /* Checker that imports not occurring
2991 inappropriately. +ve imports ok,
2992 -ve imports not ok. */
2996 trees_out (allocator
*, module_state
*, depset::hash
&deps
, unsigned sec
= 0);
3001 void unmark_trees ();
3004 /* Hey, let's ignore the well known STL iterator idiom. */
3006 unsigned end (elf_out
*sink
, unsigned name
, unsigned *crc_ptr
);
3012 tag_backref
= -1, /* Upper bound on the backrefs. */
3013 tag_value
= 0, /* Write by value. */
3014 tag_fixed
/* Lower bound on the fixed trees. */
3018 bool is_key_order () const
3020 return dep_hash
->is_key_order ();
3024 int insert (tree
, walk_kind
= WK_normal
);
3027 void start (tree
, bool = false);
3030 walk_kind
ref_node (tree
);
3033 void set_importing (int i ATTRIBUTE_UNUSED
)
3041 void core_bools (tree
);
3042 void core_vals (tree
);
3043 void lang_type_bools (tree
);
3044 void lang_type_vals (tree
);
3045 void lang_decl_bools (tree
);
3046 void lang_decl_vals (tree
);
3047 void lang_vals (tree
);
3048 void tree_node_bools (tree
);
3049 void tree_node_vals (tree
);
3052 void chained_decls (tree
);
3053 void vec_chained_decls (tree
);
3054 void tree_vec (vec
<tree
, va_gc
> *);
3055 void tree_pair_vec (vec
<tree_pair_s
, va_gc
> *);
3056 void tree_list (tree
, bool has_purpose
);
3059 /* Mark a node for by-value walking. */
3060 void mark_by_value (tree
);
3063 void tree_node (tree
);
3066 void install_entity (tree decl
, depset
*);
3067 void tpl_parms (tree parms
, unsigned &tpl_levels
);
3068 void tpl_parms_fini (tree decl
, unsigned tpl_levels
);
3069 void fn_parms_fini (tree
) {}
3070 unsigned add_indirect_tpl_parms (tree
);
3072 void add_indirects (tree
);
3073 void fn_parms_init (tree
);
3074 void tpl_header (tree decl
, unsigned *tpl_levels
);
3077 merge_kind
get_merge_kind (tree decl
, depset
*maybe_dep
);
3078 tree
decl_container (tree decl
);
3079 void key_mergeable (int tag
, merge_kind
, tree decl
, tree inner
,
3080 tree container
, depset
*maybe_dep
);
3081 void binfo_mergeable (tree binfo
);
3084 bool decl_node (tree
, walk_kind ref
);
3085 void type_node (tree
);
3086 void tree_value (tree
);
3087 void tpl_parm_value (tree
);
3090 void decl_value (tree
, depset
*);
3093 /* Serialize various definitions. */
3094 void write_definition (tree decl
);
3095 void mark_declaration (tree decl
, bool do_defn
);
3098 void mark_function_def (tree decl
);
3099 void mark_var_def (tree decl
);
3100 void mark_class_def (tree decl
);
3101 void mark_enum_def (tree decl
);
3102 void mark_class_member (tree decl
, bool do_defn
= true);
3103 void mark_binfos (tree type
);
3106 void write_var_def (tree decl
);
3107 void write_function_def (tree decl
);
3108 void write_class_def (tree decl
);
3109 void write_enum_def (tree decl
);
3112 static void assert_definition (tree
);
3115 static void instrument ();
3118 /* Tree instrumentation. */
3119 static unsigned tree_val_count
;
3120 static unsigned decl_val_count
;
3121 static unsigned back_ref_count
;
3122 static unsigned null_count
;
3125 /* Instrumentation counters. */
3126 unsigned trees_out::tree_val_count
;
3127 unsigned trees_out::decl_val_count
;
3128 unsigned trees_out::back_ref_count
;
3129 unsigned trees_out::null_count
;
3131 trees_out::trees_out (allocator
*mem
, module_state
*state
, depset::hash
&deps
,
3133 :parent (mem
), state (state
), tree_map (500),
3134 dep_hash (&deps
), ref_num (0), section (section
)
3141 trees_out::~trees_out ()
3145 /********************************************************************/
3146 /* Location. We're aware of the line-map concept and reproduce it
3147 here. Each imported module allocates a contiguous span of ordinary
3148 maps, and of macro maps. adhoc maps are serialized by contents,
3149 not pre-allocated. The scattered linemaps of a module are
3150 coalesced when writing. */
3153 /* I use half-open [first,second) ranges. */
3154 typedef std::pair
<unsigned,unsigned> range_t
;
3156 /* A range of locations. */
3157 typedef std::pair
<location_t
,location_t
> loc_range_t
;
3159 /* Spans of the line maps that are occupied by this TU. I.e. not
3160 within imports. Only extended when in an interface unit.
3161 Interval zero corresponds to the forced header linemap(s). This
3162 is a singleton object. */
3166 /* An interval of line maps. The line maps here represent a contiguous
3167 non-imported range. */
3169 loc_range_t ordinary
; /* Ordinary map location range. */
3170 loc_range_t macro
; /* Macro map location range. */
3171 int ordinary_delta
; /* Add to ordinary loc to get serialized loc. */
3172 int macro_delta
; /* Likewise for macro loc. */
3180 /* Do not preallocate spans, as that causes
3181 --enable-detailed-mem-stats problems. */
3191 span
&operator[] (unsigned ix
)
3193 return (*spans
)[ix
];
3195 unsigned length () const
3197 return spans
->length ();
3201 bool init_p () const
3203 return spans
!= nullptr;
3206 void init (const line_maps
*lmaps
, const line_map_ordinary
*map
);
3208 /* Slightly skewed preprocessed files can cause us to miss an
3209 initialization in some places. Fallback initializer. */
3213 init (line_table
, nullptr);
3218 SPAN_RESERVED
= 0, /* Reserved (fixed) locations. */
3219 SPAN_FIRST
= 1, /* LWM of locations to stream */
3220 SPAN_MAIN
= 2 /* Main file and onwards. */
3224 location_t
main_start () const
3226 return (*spans
)[SPAN_MAIN
].ordinary
.first
;
3230 void open (location_t
);
3234 /* Propagate imported linemaps to us, if needed. */
3235 bool maybe_propagate (module_state
*import
, location_t loc
);
3238 const span
*ordinary (location_t
);
3239 const span
*macro (location_t
);
3242 static loc_spans spans
;
3244 /* Information about ordinary locations we stream out. */
3247 const line_map_ordinary
*src
; // line map we're based on
3248 unsigned offset
; // offset to this line
3249 unsigned span
; // number of locs we span
3250 unsigned remap
; // serialization
3252 static int compare (const void *a_
, const void *b_
)
3254 auto *a
= static_cast<const ord_loc_info
*> (a_
);
3255 auto *b
= static_cast<const ord_loc_info
*> (b_
);
3257 if (a
->src
!= b
->src
)
3258 return a
->src
< b
->src
? -1 : +1;
3260 // Ensure no overlap
3261 gcc_checking_assert (a
->offset
+ a
->span
<= b
->offset
3262 || b
->offset
+ b
->span
<= a
->offset
);
3264 gcc_checking_assert (a
->offset
!= b
->offset
);
3265 return a
->offset
< b
->offset
? -1 : +1;
3268 struct ord_loc_traits
3270 typedef ord_loc_info value_type
;
3271 typedef value_type compare_type
;
3273 static const bool empty_zero_p
= false;
3275 static hashval_t
hash (const value_type
&v
)
3277 auto h
= pointer_hash
<const line_map_ordinary
>::hash (v
.src
);
3278 return iterative_hash_hashval_t (v
.offset
, h
);
3280 static bool equal (const value_type
&v
, const compare_type p
)
3282 return v
.src
== p
.src
&& v
.offset
== p
.offset
;
3285 static void mark_empty (value_type
&v
)
3289 static bool is_empty (value_type
&v
)
3294 static bool is_deleted (value_type
&) { return false; }
3295 static void mark_deleted (value_type
&) { gcc_unreachable (); }
3297 static void remove (value_type
&) {}
3299 /* Table keyed by ord_loc_info, used for noting. */
3300 static hash_table
<ord_loc_traits
> *ord_loc_table
;
3301 /* Sorted vector, used for writing. */
3302 static vec
<ord_loc_info
> *ord_loc_remap
;
3304 /* Information about macro locations we stream out. */
3305 struct macro_loc_info
3307 const line_map_macro
*src
; // original expansion
3308 unsigned remap
; // serialization
3310 static int compare (const void *a_
, const void *b_
)
3312 auto *a
= static_cast<const macro_loc_info
*> (a_
);
3313 auto *b
= static_cast<const macro_loc_info
*> (b_
);
3315 gcc_checking_assert (MAP_START_LOCATION (a
->src
)
3316 != MAP_START_LOCATION (b
->src
));
3317 if (MAP_START_LOCATION (a
->src
) < MAP_START_LOCATION (b
->src
))
3323 struct macro_loc_traits
3325 typedef macro_loc_info value_type
;
3326 typedef const line_map_macro
*compare_type
;
3328 static const bool empty_zero_p
= false;
3330 static hashval_t
hash (compare_type p
)
3332 return pointer_hash
<const line_map_macro
>::hash (p
);
3334 static hashval_t
hash (const value_type
&v
)
3336 return hash (v
.src
);
3338 static bool equal (const value_type
&v
, const compare_type p
)
3343 static void mark_empty (value_type
&v
)
3347 static bool is_empty (value_type
&v
)
3352 static bool is_deleted (value_type
&) { return false; }
3353 static void mark_deleted (value_type
&) { gcc_unreachable (); }
3355 static void remove (value_type
&) {}
3357 /* Table keyed by line_map_macro, used for noting. */
3358 static hash_table
<macro_loc_traits
> *macro_loc_table
;
3359 /* Sorted vector, used for writing. */
3360 static vec
<macro_loc_info
> *macro_loc_remap
;
3362 /* Indirection to allow bsearching imports by ordinary location. */
3363 static vec
<module_state
*> *ool
;
3365 /********************************************************************/
3366 /* Data needed by a module during the process of loading. */
3367 struct GTY(()) slurping
{
3369 /* Remap import's module numbering to our numbering. Values are
3370 shifted by 1. Bit0 encodes if the import is direct. */
3371 vec
<unsigned, va_heap
, vl_embed
> *
3372 GTY((skip
)) remap
; /* Module owner remapping. */
3374 elf_in
*GTY((skip
)) from
; /* The elf loader. */
3376 /* This map is only for header imports themselves -- the global
3377 headers bitmap hold it for the current TU. */
3378 bitmap headers
; /* Transitive set of direct imports, including
3379 self. Used for macro visibility and
3382 /* These objects point into the mmapped area, unless we're not doing
3383 that, or we got frozen or closed. In those cases they point to
3385 bytes_in macro_defs
; /* Macro definitions. */
3386 bytes_in macro_tbl
; /* Macro table. */
3388 /* Location remapping. first->ordinary, second->macro. */
3389 range_t
GTY((skip
)) loc_deltas
;
3391 unsigned current
; /* Section currently being loaded. */
3392 unsigned remaining
; /* Number of lazy sections yet to read. */
3393 unsigned lru
; /* An LRU counter. */
3396 slurping (elf_in
*);
3400 /* Close the ELF file, if it's open. */
3412 void release_macros ();
3415 void alloc_remap (unsigned size
)
3417 gcc_assert (!remap
);
3418 vec_safe_reserve (remap
, size
);
3419 for (unsigned ix
= size
; ix
--;)
3420 remap
->quick_push (0);
3422 unsigned remap_module (unsigned owner
)
3424 if (owner
< remap
->length ())
3425 return (*remap
)[owner
] >> 1;
3430 /* GC allocation. But we must explicitly delete it. */
3431 static void *operator new (size_t x
)
3433 return ggc_alloc_atomic (x
);
3435 static void operator delete (void *p
)
3441 slurping::slurping (elf_in
*from
)
3442 : remap (NULL
), from (from
),
3443 headers (BITMAP_GGC_ALLOC ()), macro_defs (), macro_tbl (),
3445 current (~0u), remaining (0), lru (0)
3449 slurping::~slurping ()
3457 void slurping::release_macros ()
3459 if (macro_defs
.size
)
3460 elf_in::release (from
, macro_defs
);
3462 elf_in::release (from
, macro_tbl
);
3465 /* Flags for extensions that end up being streamed. */
3467 enum streamed_extensions
{
3472 /* Counter indices. */
3473 enum module_state_counts
3486 /********************************************************************/
3487 struct module_state_config
;
3489 /* Increasing levels of loadedness. */
3490 enum module_loadedness
{
3491 ML_NONE
, /* Not loaded. */
3492 ML_CONFIG
, /* Config loaed. */
3493 ML_PREPROCESSOR
, /* Preprocessor loaded. */
3494 ML_LANGUAGE
, /* Language loaded. */
3497 /* Increasing levels of directness (toplevel) of import. */
3498 enum module_directness
{
3499 MD_NONE
, /* Not direct. */
3500 MD_PARTITION_DIRECT
, /* Direct import of a partition. */
3501 MD_DIRECT
, /* Direct import. */
3502 MD_PURVIEW_DIRECT
, /* direct import in purview. */
3505 /* State of a particular module. */
3507 class GTY((chain_next ("%h.parent"), for_user
)) module_state
{
3509 /* We always import & export ourselves. */
3510 bitmap imports
; /* Transitive modules we're importing. */
3511 bitmap exports
; /* Subset of that, that we're exporting. */
3513 module_state
*parent
;
3514 tree name
; /* Name of the module. */
3516 slurping
*slurp
; /* Data for loading. */
3518 const char *flatname
; /* Flatname of module. */
3519 char *filename
; /* CMI Filename */
3521 /* Indices into the entity_ary. */
3522 unsigned entity_lwm
;
3523 unsigned entity_num
;
3525 /* Location ranges for this module. adhoc-locs are decomposed, so
3526 don't have a range. */
3527 loc_range_t
GTY((skip
)) ordinary_locs
;
3528 loc_range_t
GTY((skip
)) macro_locs
; // [lwm,num)
3530 /* LOC is first set too the importing location. When initially
3531 loaded it refers to a module loc whose parent is the importing
3533 location_t loc
; /* Location referring to module itself. */
3534 unsigned crc
; /* CRC we saw reading it in. */
3536 unsigned mod
; /* Module owner number. */
3537 unsigned remap
; /* Remapping during writing. */
3539 unsigned short subst
; /* Mangle subst if !0. */
3541 /* How loaded this module is. */
3542 enum module_loadedness loadedness
: 2;
3544 bool module_p
: 1; /* /The/ module of this TU. */
3545 bool header_p
: 1; /* Is a header unit. */
3546 bool interface_p
: 1; /* An interface. */
3547 bool partition_p
: 1; /* A partition. */
3549 /* How directly this module is imported. */
3550 enum module_directness directness
: 2;
3552 bool exported_p
: 1; /* directness != MD_NONE && exported. */
3553 bool cmi_noted_p
: 1; /* We've told the user about the CMI, don't
3555 bool active_init_p
: 1; /* This module's global initializer needs
3557 bool inform_cmi_p
: 1; /* Inform of a read/write. */
3558 bool visited_p
: 1; /* A walk-once flag. */
3559 /* Record extensions emitted or permitted. */
3560 unsigned extensions
: SE_BITS
;
3561 /* 14 bits used, 2 bits remain */
3564 module_state (tree name
, module_state
*, bool);
3570 imports
= exports
= NULL
;
3578 elf_in
*from () const
3584 /* Kind of this module. */
3585 bool is_module () const
3589 bool is_header () const
3593 bool is_interface () const
3597 bool is_partition () const
3602 /* How this module is used in the current TU. */
3603 bool is_exported () const
3607 bool is_direct () const
3609 return directness
>= MD_DIRECT
;
3611 bool is_purview_direct () const
3613 return directness
== MD_PURVIEW_DIRECT
;
3615 bool is_partition_direct () const
3617 return directness
== MD_PARTITION_DIRECT
;
3621 /* Is this a real module? */
3622 bool has_location () const
3624 return loc
!= UNKNOWN_LOCATION
;
3628 bool check_not_purview (location_t loc
);
3631 void mangle (bool include_partition
);
3634 void set_import (module_state
const *, bool is_export
);
3635 void announce (const char *) const;
3638 /* Read and write module. */
3639 void write_begin (elf_out
*to
, cpp_reader
*,
3640 module_state_config
&, unsigned &crc
);
3641 void write_end (elf_out
*to
, cpp_reader
*,
3642 module_state_config
&, unsigned &crc
);
3643 bool read_initial (cpp_reader
*);
3644 bool read_preprocessor (bool);
3645 bool read_language (bool);
3648 /* Read a section. */
3649 bool load_section (unsigned snum
, binding_slot
*mslot
);
3650 /* Lazily read a section. */
3651 bool lazy_load (unsigned index
, binding_slot
*mslot
);
3654 /* Juggle a limited number of file numbers. */
3655 static void freeze_an_elf ();
3656 bool maybe_defrost ();
3659 void maybe_completed_reading ();
3660 bool check_read (bool outermost
, bool ok
);
3663 /* The README, for human consumption. */
3664 void write_readme (elf_out
*to
, cpp_reader
*, const char *dialect
);
3665 void write_env (elf_out
*to
);
3668 /* Import tables. */
3669 void write_imports (bytes_out
&cfg
, bool direct
);
3670 unsigned read_imports (bytes_in
&cfg
, cpp_reader
*, line_maps
*maps
);
3673 void write_imports (elf_out
*to
, unsigned *crc_ptr
);
3674 bool read_imports (cpp_reader
*, line_maps
*);
3677 void write_partitions (elf_out
*to
, unsigned, unsigned *crc_ptr
);
3678 bool read_partitions (unsigned);
3681 void write_config (elf_out
*to
, struct module_state_config
&, unsigned crc
);
3682 bool read_config (struct module_state_config
&);
3683 static void write_counts (elf_out
*to
, unsigned [MSC_HWM
], unsigned *crc_ptr
);
3684 bool read_counts (unsigned *);
3687 void note_cmi_name ();
3690 static unsigned write_bindings (elf_out
*to
, vec
<depset
*> depsets
,
3692 bool read_bindings (unsigned count
, unsigned lwm
, unsigned hwm
);
3694 static void write_namespace (bytes_out
&sec
, depset
*ns_dep
);
3695 tree
read_namespace (bytes_in
&sec
);
3697 void write_namespaces (elf_out
*to
, vec
<depset
*> spaces
,
3698 unsigned, unsigned *crc_ptr
);
3699 bool read_namespaces (unsigned);
3701 void intercluster_seed (trees_out
&sec
, unsigned index
, depset
*dep
);
3702 unsigned write_cluster (elf_out
*to
, depset
*depsets
[], unsigned size
,
3703 depset::hash
&, unsigned *counts
, unsigned *crc_ptr
);
3704 bool read_cluster (unsigned snum
);
3707 unsigned write_inits (elf_out
*to
, depset::hash
&, unsigned *crc_ptr
);
3708 bool read_inits (unsigned count
);
3711 unsigned write_pendings (elf_out
*to
, vec
<depset
*> depsets
,
3712 depset::hash
&, unsigned *crc_ptr
);
3713 bool read_pendings (unsigned count
);
3716 void write_entities (elf_out
*to
, vec
<depset
*> depsets
,
3717 unsigned count
, unsigned *crc_ptr
);
3718 bool read_entities (unsigned count
, unsigned lwm
, unsigned hwm
);
3721 void write_init_maps ();
3722 range_t
write_prepare_maps (module_state_config
*, bool);
3723 bool read_prepare_maps (const module_state_config
*);
3725 void write_ordinary_maps (elf_out
*to
, range_t
&,
3726 bool, unsigned *crc_ptr
);
3727 bool read_ordinary_maps (unsigned, unsigned);
3728 void write_macro_maps (elf_out
*to
, range_t
&, unsigned *crc_ptr
);
3729 bool read_macro_maps (unsigned);
3732 void write_define (bytes_out
&, const cpp_macro
*);
3733 cpp_macro
*read_define (bytes_in
&, cpp_reader
*) const;
3734 vec
<cpp_hashnode
*> *prepare_macros (cpp_reader
*);
3735 unsigned write_macros (elf_out
*to
, vec
<cpp_hashnode
*> *, unsigned *crc_ptr
);
3736 bool read_macros ();
3737 void install_macros ();
3740 void import_macros ();
3743 static void undef_macro (cpp_reader
*, location_t
, cpp_hashnode
*);
3744 static cpp_macro
*deferred_macro (cpp_reader
*, location_t
, cpp_hashnode
*);
3747 static bool note_location (location_t
);
3748 static void write_location (bytes_out
&, location_t
);
3749 location_t
read_location (bytes_in
&) const;
3752 void set_flatname ();
3753 const char *get_flatname () const
3757 location_t
imported_from () const;
3760 void set_filename (const Cody::Packet
&);
3761 bool do_import (cpp_reader
*, bool outermost
);
3764 /* Hash module state by name. This cannot be a member of
3765 module_state, because of GTY restrictions. We never delete from
3766 the hash table, but ggc_ptr_hash doesn't support that
3769 struct module_state_hash
: ggc_ptr_hash
<module_state
> {
3770 typedef std::pair
<tree
,uintptr_t> compare_type
; /* {name,parent} */
3772 static inline hashval_t
hash (const value_type m
);
3773 static inline hashval_t
hash (const compare_type
&n
);
3774 static inline bool equal (const value_type existing
,
3775 const compare_type
&candidate
);
3778 module_state::module_state (tree name
, module_state
*parent
, bool partition
)
3779 : imports (BITMAP_GGC_ALLOC ()), exports (BITMAP_GGC_ALLOC ()),
3780 parent (parent
), name (name
), slurp (NULL
),
3781 flatname (NULL
), filename (NULL
),
3782 entity_lwm (~0u >> 1), entity_num (0),
3783 ordinary_locs (0, 0), macro_locs (0, 0),
3784 loc (UNKNOWN_LOCATION
),
3785 crc (0), mod (MODULE_UNKNOWN
), remap (0), subst (0)
3787 loadedness
= ML_NONE
;
3789 module_p
= header_p
= interface_p
= partition_p
= false;
3791 directness
= MD_NONE
;
3794 cmi_noted_p
= false;
3795 active_init_p
= false;
3797 partition_p
= partition
;
3799 inform_cmi_p
= false;
3803 if (name
&& TREE_CODE (name
) == STRING_CST
)
3807 const char *string
= TREE_STRING_POINTER (name
);
3808 gcc_checking_assert (string
[0] == '.'
3809 ? IS_DIR_SEPARATOR (string
[1])
3810 : IS_ABSOLUTE_PATH (string
));
3813 gcc_checking_assert (!(parent
&& header_p
));
3816 module_state::~module_state ()
3821 /* Hash module state. */
3823 module_name_hash (const_tree name
)
3825 if (TREE_CODE (name
) == STRING_CST
)
3826 return htab_hash_string (TREE_STRING_POINTER (name
));
3828 return IDENTIFIER_HASH_VALUE (name
);
3832 module_state_hash::hash (const value_type m
)
3834 hashval_t ph
= pointer_hash
<void>::hash
3835 (reinterpret_cast<void *> (reinterpret_cast<uintptr_t> (m
->parent
)
3836 | m
->is_partition ()));
3837 hashval_t nh
= module_name_hash (m
->name
);
3838 return iterative_hash_hashval_t (ph
, nh
);
3843 module_state_hash::hash (const compare_type
&c
)
3845 hashval_t ph
= pointer_hash
<void>::hash (reinterpret_cast<void *> (c
.second
));
3846 hashval_t nh
= module_name_hash (c
.first
);
3848 return iterative_hash_hashval_t (ph
, nh
);
3852 module_state_hash::equal (const value_type existing
,
3853 const compare_type
&candidate
)
3855 uintptr_t ep
= (reinterpret_cast<uintptr_t> (existing
->parent
)
3856 | existing
->is_partition ());
3857 if (ep
!= candidate
.second
)
3860 /* Identifier comparison is by pointer. If the string_csts happen
3861 to be the same object, then they're equal too. */
3862 if (existing
->name
== candidate
.first
)
3865 /* If neither are string csts, they can't be equal. */
3866 if (TREE_CODE (candidate
.first
) != STRING_CST
3867 || TREE_CODE (existing
->name
) != STRING_CST
)
3870 /* String equality. */
3871 if (TREE_STRING_LENGTH (existing
->name
)
3872 == TREE_STRING_LENGTH (candidate
.first
)
3873 && !memcmp (TREE_STRING_POINTER (existing
->name
),
3874 TREE_STRING_POINTER (candidate
.first
),
3875 TREE_STRING_LENGTH (existing
->name
)))
3881 /********************************************************************/
3885 static const char *module_mapper_name
;
3887 /* Deferred import queue (FIFO). */
3888 static vec
<module_state
*, va_heap
, vl_embed
> *pending_imports
;
3890 /* CMI repository path and workspace. */
3891 static char *cmi_repo
;
3892 static size_t cmi_repo_length
;
3893 static char *cmi_path
;
3894 static size_t cmi_path_alloc
;
3896 /* Count of available and loaded clusters. */
3897 static unsigned available_clusters
;
3898 static unsigned loaded_clusters
;
3900 /* What the current TU is. */
3901 unsigned module_kind
;
3904 static const std::pair
<tree
*, unsigned> global_tree_arys
[] =
3906 std::pair
<tree
*, unsigned> (sizetype_tab
, stk_type_kind_last
),
3907 std::pair
<tree
*, unsigned> (integer_types
, itk_none
),
3908 std::pair
<tree
*, unsigned> (global_trees
, TI_MODULE_HWM
),
3909 std::pair
<tree
*, unsigned> (c_global_trees
, CTI_MODULE_HWM
),
3910 std::pair
<tree
*, unsigned> (cp_global_trees
, CPTI_MODULE_HWM
),
3911 std::pair
<tree
*, unsigned> (NULL
, 0)
3913 static GTY(()) vec
<tree
, va_gc
> *fixed_trees
;
3914 static unsigned global_crc
;
3916 /* Lazy loading can open many files concurrently, there are
3917 per-process limits on that. We pay attention to the process limit,
3918 and attempt to increase it when we run out. Otherwise we use an
3919 LRU scheme to figure out who to flush. Note that if the import
3920 graph /depth/ exceeds lazy_limit, we'll exceed the limit. */
3921 static unsigned lazy_lru
; /* LRU counter. */
3922 static unsigned lazy_open
; /* Number of open modules */
3923 static unsigned lazy_limit
; /* Current limit of open modules. */
3924 static unsigned lazy_hard_limit
; /* Hard limit on open modules. */
3925 /* Account for source, assembler and dump files & directory searches.
3926 We don't keep the source file's open, so we don't have to account
3927 for #include depth. I think dump files are opened and closed per
3929 #define LAZY_HEADROOM 15 /* File descriptor headroom. */
3931 /* Vector of module state. Indexed by OWNER. Has at least 2 slots. */
3932 static GTY(()) vec
<module_state
*, va_gc
> *modules
;
3934 /* Hash of module state, findable by {name, parent}. */
3935 static GTY(()) hash_table
<module_state_hash
> *modules_hash
;
3937 /* Map of imported entities. We map DECL_UID to index of entity
3939 typedef hash_map
<unsigned/*UID*/, unsigned/*index*/,
3940 simple_hashmap_traits
<int_hash
<unsigned,0>, unsigned>
3942 static entity_map_t
*entity_map
;
3943 /* Doesn't need GTYing, because any tree referenced here is also
3944 findable by, symbol table, specialization table, return type of
3945 reachable function. */
3946 static vec
<binding_slot
, va_heap
, vl_embed
> *entity_ary
;
3948 /* Members entities of imported classes that are defined in this TU.
3949 These are where the entity's context is not from the current TU.
3950 We need to emit the definition (but not the enclosing class).
3952 We could find these by walking ALL the imported classes that we
3953 could provide a member definition. But that's expensive,
3954 especially when you consider lazy implicit member declarations,
3955 which could be ANY imported class. */
3956 static GTY(()) vec
<tree
, va_gc
> *class_members
;
3958 /* The same problem exists for class template partial
3959 specializations. Now that we have constraints, the invariant of
3960 expecting them in the instantiation table no longer holds. One of
3961 the constrained partial specializations will be there, but the
3962 others not so much. It's not even an unconstrained partial
3963 spacialization in the table :( so any partial template declaration
3964 is added to this list too. */
3965 static GTY(()) vec
<tree
, va_gc
> *partial_specializations
;
3967 /********************************************************************/
3969 /* Our module mapper (created lazily). */
3970 module_client
*mapper
;
3972 static module_client
*make_mapper (location_t loc
);
3973 inline module_client
*get_mapper (location_t loc
)
3977 res
= make_mapper (loc
);
3981 /********************************************************************/
3983 get_clone_target (tree decl
)
3987 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
3989 tree res_orig
= DECL_CLONED_FUNCTION (DECL_TEMPLATE_RESULT (decl
));
3991 target
= DECL_TI_TEMPLATE (res_orig
);
3994 target
= DECL_CLONED_FUNCTION (decl
);
3996 gcc_checking_assert (DECL_MAYBE_IN_CHARGE_CDTOR_P (target
));
4001 /* Like FOR_EACH_CLONE, but will walk cloned templates. */
4002 #define FOR_EVERY_CLONE(CLONE, FN) \
4003 if (!DECL_MAYBE_IN_CHARGE_CDTOR_P (FN)); \
4005 for (CLONE = DECL_CHAIN (FN); \
4006 CLONE && DECL_CLONED_FUNCTION_P (CLONE); \
4007 CLONE = DECL_CHAIN (CLONE))
4009 /* It'd be nice if USE_TEMPLATE was a field of template_info
4010 (a) it'd solve the enum case dealt with below,
4011 (b) both class templates and decl templates would store this in the
4013 (c) this function wouldn't need the by-ref arg, which is annoying. */
4016 node_template_info (tree decl
, int &use
)
4018 tree ti
= NULL_TREE
;
4020 if (DECL_IMPLICIT_TYPEDEF_P (decl
))
4022 tree type
= TREE_TYPE (decl
);
4024 ti
= TYPE_TEMPLATE_INFO (type
);
4027 if (TYPE_LANG_SPECIFIC (type
))
4028 use_tpl
= CLASSTYPE_USE_TEMPLATE (type
);
4031 /* An enum, where we don't explicitly encode use_tpl.
4032 If the containing context (a type or a function), is
4033 an ({im,ex}plicit) instantiation, then this is too.
4034 If it's a partial or explicit specialization, then
4036 tree ctx
= CP_DECL_CONTEXT (decl
);
4038 ctx
= TYPE_NAME (ctx
);
4039 node_template_info (ctx
, use
);
4040 use_tpl
= use
!= 2 ? use
: 0;
4044 else if (DECL_LANG_SPECIFIC (decl
)
4045 && (TREE_CODE (decl
) == VAR_DECL
4046 || TREE_CODE (decl
) == TYPE_DECL
4047 || TREE_CODE (decl
) == FUNCTION_DECL
4048 || TREE_CODE (decl
) == FIELD_DECL
4049 || TREE_CODE (decl
) == CONCEPT_DECL
4050 || TREE_CODE (decl
) == TEMPLATE_DECL
))
4052 use_tpl
= DECL_USE_TEMPLATE (decl
);
4053 ti
= DECL_TEMPLATE_INFO (decl
);
4060 /* Find the index in entity_ary for an imported DECL. It should
4061 always be there, but bugs can cause it to be missing, and that can
4062 crash the crash reporting -- let's not do that! When streaming
4063 out we place entities from this module there too -- with negated
4067 import_entity_index (tree decl
, bool null_ok
= false)
4069 if (unsigned *slot
= entity_map
->get (DECL_UID (decl
)))
4072 gcc_checking_assert (null_ok
);
4076 /* Find the module for an imported entity at INDEX in the entity ary.
4077 There must be one. */
4079 static module_state
*
4080 import_entity_module (unsigned index
)
4082 if (index
> ~(~0u >> 1))
4083 /* This is an index for an exported entity. */
4084 return (*modules
)[0];
4086 /* Do not include the current TU (not an off-by-one error). */
4088 unsigned len
= modules
->length () - pos
;
4091 unsigned half
= len
/ 2;
4092 module_state
*probe
= (*modules
)[pos
+ half
];
4093 if (index
< probe
->entity_lwm
)
4095 else if (index
< probe
->entity_lwm
+ probe
->entity_num
)
4100 len
= len
- (half
+ 1);
4107 /********************************************************************/
4108 /* A dumping machinery. */
4113 LOCATION
= TDF_LINENO
, /* -lineno:Source location streaming. */
4114 DEPEND
= TDF_GRAPH
, /* -graph:Dependency graph construction. */
4115 CLUSTER
= TDF_BLOCKS
, /* -blocks:Clusters. */
4116 TREE
= TDF_UID
, /* -uid:Tree streaming. */
4117 MERGE
= TDF_ALIAS
, /* -alias:Mergeable Entities. */
4118 ELF
= TDF_ASMNAME
, /* -asmname:Elf data. */
4119 MACRO
= TDF_VOPS
/* -vops:Macros. */
4124 typedef vec
<module_state
*, va_heap
, vl_embed
> stack_t
;
4126 FILE *stream
; /* Dump stream. */
4127 unsigned indent
; /* Local indentation. */
4128 bool bol
; /* Beginning of line. */
4129 stack_t stack
; /* Trailing array of module_state. */
4131 bool nested_name (tree
); /* Dump a name following DECL_CONTEXT. */
4140 /* Push/pop module state dumping. */
4141 unsigned push (module_state
*);
4142 void pop (unsigned);
4145 /* Change local indentation. */
4155 gcc_checking_assert (dumps
->indent
);
4161 /* Is dump enabled?. */
4162 bool operator () (int mask
= 0)
4164 if (!dumps
|| !dumps
->stream
)
4166 if (mask
&& !(mask
& flags
))
4170 /* Dump some information. */
4171 bool operator () (const char *, ...);
4175 static dumper dump
= {0, dump_flags_t (0)};
4177 /* Push to dumping M. Return previous indentation level. */
4180 dumper::push (module_state
*m
)
4182 FILE *stream
= NULL
;
4183 if (!dumps
|| !dumps
->stack
.length ())
4185 stream
= dump_begin (module_dump_id
, &flags
);
4190 if (!dumps
|| !dumps
->stack
.space (1))
4192 /* Create or extend the dump implementor. */
4193 unsigned current
= dumps
? dumps
->stack
.length () : 0;
4194 unsigned count
= current
? current
* 2 : EXPERIMENT (1, 20);
4195 size_t alloc
= (offsetof (impl
, stack
)
4196 + impl::stack_t::embedded_size (count
));
4197 dumps
= XRESIZEVAR (impl
, dumps
, alloc
);
4198 dumps
->stack
.embedded_init (count
, current
);
4201 dumps
->stream
= stream
;
4203 unsigned n
= dumps
->indent
;
4206 dumps
->stack
.quick_push (m
);
4209 module_state
*from
= NULL
;
4211 if (dumps
->stack
.length () > 1)
4212 from
= dumps
->stack
[dumps
->stack
.length () - 2];
4215 dump (from
? "Starting module %M (from %M)"
4216 : "Starting module %M", m
, from
);
4222 /* Pop from dumping. Restore indentation to N. */
4224 void dumper::pop (unsigned n
)
4229 gcc_checking_assert (dump () && !dumps
->indent
);
4230 if (module_state
*m
= dumps
->stack
[dumps
->stack
.length () - 1])
4232 module_state
*from
= (dumps
->stack
.length () > 1
4233 ? dumps
->stack
[dumps
->stack
.length () - 2] : NULL
);
4234 dump (from
? "Finishing module %M (returning to %M)"
4235 : "Finishing module %M", m
, from
);
4237 dumps
->stack
.pop ();
4239 if (!dumps
->stack
.length ())
4241 dump_end (module_dump_id
, dumps
->stream
);
4242 dumps
->stream
= NULL
;
4246 /* Dump a nested name for arbitrary tree T. Sometimes it won't have a
4250 dumper::impl::nested_name (tree t
)
4252 tree ti
= NULL_TREE
;
4254 tree name
= NULL_TREE
;
4256 if (t
&& TREE_CODE (t
) == TREE_BINFO
)
4259 if (t
&& TYPE_P (t
))
4262 if (t
&& DECL_P (t
))
4264 if (t
== global_namespace
|| DECL_TEMPLATE_PARM_P (t
))
4266 else if (tree ctx
= DECL_CONTEXT (t
))
4267 if (TREE_CODE (ctx
) == TRANSLATION_UNIT_DECL
4268 || nested_name (ctx
))
4269 fputs ("::", stream
);
4272 ti
= node_template_info (t
, use_tpl
);
4273 if (ti
&& TREE_CODE (TI_TEMPLATE (ti
)) == TEMPLATE_DECL
4274 && (DECL_TEMPLATE_RESULT (TI_TEMPLATE (ti
)) == t
))
4275 t
= TI_TEMPLATE (ti
);
4277 if (TREE_CODE (t
) == TEMPLATE_DECL
)
4279 fputs ("template ", stream
);
4280 not_tmpl
= DECL_TEMPLATE_RESULT (t
);
4284 && DECL_P (not_tmpl
)
4285 && DECL_LANG_SPECIFIC (not_tmpl
)
4286 && DECL_MODULE_IMPORT_P (not_tmpl
))
4288 /* We need to be careful here, so as to not explode on
4289 inconsistent data -- we're probably debugging, because
4290 Something Is Wrong. */
4291 unsigned index
= import_entity_index (t
, true);
4292 if (!(index
& ~(~0u >> 1)))
4293 origin
= import_entity_module (index
)->mod
;
4294 else if (index
> ~(~0u >> 1))
4295 /* An imported partition member that we're emitting. */
4301 name
= DECL_NAME (t
) ? DECL_NAME (t
)
4302 : HAS_DECL_ASSEMBLER_NAME_P (t
) ? DECL_ASSEMBLER_NAME_RAW (t
)
4309 switch (TREE_CODE (name
))
4312 fputs ("#unnamed#", stream
);
4315 case IDENTIFIER_NODE
:
4316 fwrite (IDENTIFIER_POINTER (name
), 1, IDENTIFIER_LENGTH (name
), stream
);
4320 print_hex (wi::to_wide (name
), stream
);
4324 /* If TREE_TYPE is NULL, this is a raw string. */
4325 fwrite (TREE_STRING_POINTER (name
), 1,
4326 TREE_STRING_LENGTH (name
) - (TREE_TYPE (name
) != NULL_TREE
),
4331 fputs ("#null#", stream
);
4335 const module_state
*module
= (*modules
)[origin
];
4336 fprintf (stream
, "@%s:%d", !module
? "" : !module
->name
? "(unnamed)"
4337 : module
->get_flatname (), origin
);
4339 else if (origin
== -2)
4340 fprintf (stream
, "@???");
4344 tree args
= INNERMOST_TEMPLATE_ARGS (TI_ARGS (ti
));
4345 fputs ("<", stream
);
4347 for (int ix
= 0; ix
!= TREE_VEC_LENGTH (args
); ix
++)
4350 fputs (",", stream
);
4351 nested_name (TREE_VEC_ELT (args
, ix
));
4353 fputs (">", stream
);
4359 /* Formatted dumping. FORMAT begins with '+' do not emit a trailing
4360 new line. (Normally it is appended.)
4365 %N - name -- DECL_NAME
4366 %P - context:name pair
4367 %R - unsigned:unsigned ratio
4368 %S - symbol -- DECL_ASSEMBLER_NAME
4371 --- the following are printf-like, but without its flexibility
4378 We do not implement the printf modifiers. */
4381 dumper::operator () (const char *format
, ...)
4386 bool no_nl
= format
[0] == '+';
4391 /* Module import indent. */
4392 if (unsigned depth
= dumps
->stack
.length () - 1)
4394 const char *prefix
= ">>>>";
4395 fprintf (dumps
->stream
, (depth
<= strlen (prefix
)
4396 ? &prefix
[strlen (prefix
) - depth
]
4397 : ">.%d.>"), depth
);
4401 if (unsigned indent
= dumps
->indent
)
4403 const char *prefix
= " ";
4404 fprintf (dumps
->stream
, (indent
<= strlen (prefix
)
4405 ? &prefix
[strlen (prefix
) - indent
]
4406 : " .%d. "), indent
);
4412 va_start (args
, format
);
4413 while (const char *esc
= strchr (format
, '%'))
4415 fwrite (format
, 1, (size_t)(esc
- format
), dumps
->stream
);
4423 fputc ('%', dumps
->stream
);
4426 case 'C': /* Code */
4428 tree_code code
= (tree_code
)va_arg (args
, unsigned);
4429 fputs (get_tree_code_name (code
), dumps
->stream
);
4433 case 'I': /* Identifier. */
4435 tree t
= va_arg (args
, tree
);
4436 dumps
->nested_name (t
);
4440 case 'M': /* Module. */
4442 const char *str
= "(none)";
4443 if (module_state
*m
= va_arg (args
, module_state
*))
4445 if (!m
->has_location ())
4448 str
= m
->get_flatname ();
4450 fputs (str
, dumps
->stream
);
4454 case 'N': /* Name. */
4456 tree t
= va_arg (args
, tree
);
4457 while (t
&& TREE_CODE (t
) == OVERLOAD
)
4458 t
= OVL_FUNCTION (t
);
4459 fputc ('\'', dumps
->stream
);
4460 dumps
->nested_name (t
);
4461 fputc ('\'', dumps
->stream
);
4465 case 'P': /* Pair. */
4467 tree ctx
= va_arg (args
, tree
);
4468 tree name
= va_arg (args
, tree
);
4469 fputc ('\'', dumps
->stream
);
4470 dumps
->nested_name (ctx
);
4471 if (ctx
&& ctx
!= global_namespace
)
4472 fputs ("::", dumps
->stream
);
4473 dumps
->nested_name (name
);
4474 fputc ('\'', dumps
->stream
);
4478 case 'R': /* Ratio */
4480 unsigned a
= va_arg (args
, unsigned);
4481 unsigned b
= va_arg (args
, unsigned);
4482 fprintf (dumps
->stream
, "%.1f", (float) a
/ (b
+ !b
));
4486 case 'S': /* Symbol name */
4488 tree t
= va_arg (args
, tree
);
4489 if (t
&& TYPE_P (t
))
4491 if (t
&& HAS_DECL_ASSEMBLER_NAME_P (t
)
4492 && DECL_ASSEMBLER_NAME_SET_P (t
))
4494 fputc ('(', dumps
->stream
);
4495 fputs (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t
)),
4497 fputc (')', dumps
->stream
);
4502 case 'U': /* long unsigned. */
4504 unsigned long u
= va_arg (args
, unsigned long);
4505 fprintf (dumps
->stream
, "%lu", u
);
4509 case 'V': /* Verson. */
4511 unsigned v
= va_arg (args
, unsigned);
4514 version2string (v
, string
);
4515 fputs (string
, dumps
->stream
);
4519 case 'c': /* Character. */
4521 int c
= va_arg (args
, int);
4522 fputc (c
, dumps
->stream
);
4526 case 'd': /* Decimal Int. */
4528 int d
= va_arg (args
, int);
4529 fprintf (dumps
->stream
, "%d", d
);
4533 case 'p': /* Pointer. */
4535 void *p
= va_arg (args
, void *);
4536 fprintf (dumps
->stream
, "%p", p
);
4540 case 's': /* String. */
4542 const char *s
= va_arg (args
, char *);
4543 gcc_checking_assert (s
);
4544 fputs (s
, dumps
->stream
);
4548 case 'u': /* Unsigned. */
4550 unsigned u
= va_arg (args
, unsigned);
4551 fprintf (dumps
->stream
, "%u", u
);
4555 case 'x': /* Hex. */
4557 unsigned x
= va_arg (args
, unsigned);
4558 fprintf (dumps
->stream
, "%x", x
);
4563 fputs (format
, dumps
->stream
);
4568 fputc ('\n', dumps
->stream
);
4573 struct note_def_cache_hasher
: ggc_cache_ptr_hash
<tree_node
>
4575 static int keep_cache_entry (tree t
)
4578 /* GTY is unfortunately not clever enough to conditionalize
4582 if (ggc_marked_p (t
))
4585 unsigned n
= dump
.push (NULL
);
4586 /* This might or might not be an error. We should note its
4587 dropping whichever. */
4588 dump () && dump ("Dropping %N from note_defs table", t
);
4595 /* We should stream each definition at most once.
4596 This needs to be a cache because there are cases where a definition
4597 ends up being not retained, and we need to drop those so we don't
4598 get confused if memory is reallocated. */
4599 typedef hash_table
<note_def_cache_hasher
> note_defs_table_t
;
4600 static GTY((cache
)) note_defs_table_t
*note_defs
;
4603 trees_in::assert_definition (tree decl ATTRIBUTE_UNUSED
,
4604 bool installing ATTRIBUTE_UNUSED
)
4607 tree
*slot
= note_defs
->find_slot (decl
, installing
? INSERT
: NO_INSERT
);
4608 tree not_tmpl
= STRIP_TEMPLATE (decl
);
4611 /* We must be inserting for the first time. */
4612 gcc_assert (!*slot
);
4616 /* If this is not the mergeable entity, it should not be in the
4617 table. If it is a non-global-module mergeable entity, it
4618 should be in the table. Global module entities could have been
4619 defined textually in the current TU and so might or might not
4621 gcc_assert (!is_duplicate (decl
)
4624 || !DECL_LANG_SPECIFIC (not_tmpl
)
4625 || !DECL_MODULE_PURVIEW_P (not_tmpl
)
4626 || (!DECL_MODULE_IMPORT_P (not_tmpl
)
4627 && header_module_p ())));
4629 if (not_tmpl
!= decl
)
4630 gcc_assert (!note_defs
->find_slot (not_tmpl
, NO_INSERT
));
4635 trees_out::assert_definition (tree decl ATTRIBUTE_UNUSED
)
4638 tree
*slot
= note_defs
->find_slot (decl
, INSERT
);
4639 gcc_assert (!*slot
);
4641 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
4642 gcc_assert (!note_defs
->find_slot (DECL_TEMPLATE_RESULT (decl
), NO_INSERT
));
4646 /********************************************************************/
4653 pp_needs_newline (global_dc
->printer
) = true;
4654 diagnostic_set_last_function (global_dc
, (diagnostic_info
*) NULL
);
4659 /* Set the cmi repo. Strip trailing '/', '.' becomes NULL. */
4662 set_cmi_repo (const char *r
)
4664 XDELETEVEC (cmi_repo
);
4665 XDELETEVEC (cmi_path
);
4669 cmi_repo_length
= 0;
4674 size_t len
= strlen (r
);
4675 cmi_repo
= XNEWVEC (char, len
+ 1);
4676 memcpy (cmi_repo
, r
, len
+ 1);
4678 if (len
> 1 && IS_DIR_SEPARATOR (cmi_repo
[len
-1]))
4680 if (len
== 1 && cmi_repo
[0] == '.')
4683 cmi_repo_length
= len
;
4686 /* TO is a repo-relative name. Provide one that we may use from where
4690 maybe_add_cmi_prefix (const char *to
, size_t *len_p
= NULL
)
4692 size_t len
= len_p
|| cmi_repo_length
? strlen (to
) : 0;
4694 if (cmi_repo_length
&& !IS_ABSOLUTE_PATH (to
))
4696 if (cmi_path_alloc
< cmi_repo_length
+ len
+ 2)
4698 XDELETEVEC (cmi_path
);
4699 cmi_path_alloc
= cmi_repo_length
+ len
* 2 + 2;
4700 cmi_path
= XNEWVEC (char, cmi_path_alloc
);
4702 memcpy (cmi_path
, cmi_repo
, cmi_repo_length
);
4703 cmi_path
[cmi_repo_length
] = DIR_SEPARATOR
;
4706 memcpy (&cmi_path
[cmi_repo_length
+ 1], to
, len
+ 1);
4707 len
+= cmi_repo_length
+ 1;
4717 /* Try and create the directories of PATH. */
4720 create_dirs (char *path
)
4722 /* Try and create the missing directories. */
4723 for (char *base
= path
; *base
; base
++)
4724 if (IS_DIR_SEPARATOR (*base
))
4728 int failed
= mkdir (path
, S_IRWXU
| S_IRWXG
| S_IRWXO
);
4729 dump () && dump ("Mkdir ('%s') errno:=%u", path
, failed
? errno
: 0);
4732 /* Maybe racing with another creator (of a *different*
4739 /* Given a CLASSTYPE_DECL_LIST VALUE get the template friend decl,
4740 if that's what this is. */
4743 friend_from_decl_list (tree frnd
)
4747 if (TREE_CODE (frnd
) != TEMPLATE_DECL
)
4749 tree tmpl
= NULL_TREE
;
4752 res
= TYPE_NAME (frnd
);
4753 if (CLASS_TYPE_P (frnd
)
4754 && CLASSTYPE_TEMPLATE_INFO (frnd
))
4755 tmpl
= CLASSTYPE_TI_TEMPLATE (frnd
);
4757 else if (DECL_TEMPLATE_INFO (frnd
))
4759 tmpl
= DECL_TI_TEMPLATE (frnd
);
4760 if (TREE_CODE (tmpl
) != TEMPLATE_DECL
)
4764 if (tmpl
&& DECL_TEMPLATE_RESULT (tmpl
) == res
)
4772 find_enum_member (tree ctx
, tree name
)
4774 for (tree values
= TYPE_VALUES (ctx
);
4775 values
; values
= TREE_CHAIN (values
))
4776 if (DECL_NAME (TREE_VALUE (values
)) == name
)
4777 return TREE_VALUE (values
);
4782 /********************************************************************/
4783 /* Instrumentation gathered writing bytes. */
4786 bytes_out::instrument ()
4788 dump ("Wrote %u bytes in %u blocks", lengths
[3], spans
[3]);
4789 dump ("Wrote %u bits in %u bytes", lengths
[0] + lengths
[1], lengths
[2]);
4790 for (unsigned ix
= 0; ix
< 2; ix
++)
4791 dump (" %u %s spans of %R bits", spans
[ix
],
4792 ix
? "one" : "zero", lengths
[ix
], spans
[ix
]);
4793 dump (" %u blocks with %R bits padding", spans
[2],
4794 lengths
[2] * 8 - (lengths
[0] + lengths
[1]), spans
[2]);
4797 /* Instrumentation gathered writing trees. */
4799 trees_out::instrument ()
4803 bytes_out::instrument ();
4805 dump (" %u decl trees", decl_val_count
);
4806 dump (" %u other trees", tree_val_count
);
4807 dump (" %u back references", back_ref_count
);
4808 dump (" %u null trees", null_count
);
4812 /* Setup and teardown for a tree walk. */
4817 gcc_assert (!streaming_p () || !tree_map
.elements ());
4825 trees_out::end (elf_out
*sink
, unsigned name
, unsigned *crc_ptr
)
4827 gcc_checking_assert (streaming_p ());
4830 return parent::end (sink
, name
, crc_ptr
);
4836 gcc_assert (!streaming_p ());
4839 /* Do not parent::end -- we weren't streaming. */
4843 trees_out::mark_trees ()
4845 if (size_t size
= tree_map
.elements ())
4847 /* This isn't our first rodeo, destroy and recreate the
4848 tree_map. I'm a bad bad man. Use the previous size as a
4849 guess for the next one (so not all bad). */
4850 tree_map
.~ptr_int_hash_map ();
4851 new (&tree_map
) ptr_int_hash_map (size
);
4854 /* Install the fixed trees, with +ve references. */
4855 unsigned limit
= fixed_trees
->length ();
4856 for (unsigned ix
= 0; ix
!= limit
; ix
++)
4858 tree val
= (*fixed_trees
)[ix
];
4859 bool existed
= tree_map
.put (val
, ix
+ tag_fixed
);
4860 gcc_checking_assert (!TREE_VISITED (val
) && !existed
);
4861 TREE_VISITED (val
) = true;
4867 /* Unmark the trees we encountered */
4870 trees_out::unmark_trees ()
4872 ptr_int_hash_map::iterator
end (tree_map
.end ());
4873 for (ptr_int_hash_map::iterator
iter (tree_map
.begin ()); iter
!= end
; ++iter
)
4875 tree node
= reinterpret_cast<tree
> ((*iter
).first
);
4876 int ref
= (*iter
).second
;
4877 /* We should have visited the node, and converted its mergeable
4878 reference to a regular reference. */
4879 gcc_checking_assert (TREE_VISITED (node
)
4880 && (ref
<= tag_backref
|| ref
>= tag_fixed
));
4881 TREE_VISITED (node
) = false;
4885 /* Mark DECL for by-value walking. We do this by inserting it into
4886 the tree map with a reference of zero. May be called multiple
4887 times on the same node. */
4890 trees_out::mark_by_value (tree decl
)
4892 gcc_checking_assert (DECL_P (decl
)
4893 /* Enum consts are INTEGER_CSTS. */
4894 || TREE_CODE (decl
) == INTEGER_CST
4895 || TREE_CODE (decl
) == TREE_BINFO
);
4897 if (TREE_VISITED (decl
))
4898 /* Must already be forced or fixed. */
4899 gcc_checking_assert (*tree_map
.get (decl
) >= tag_value
);
4902 bool existed
= tree_map
.put (decl
, tag_value
);
4903 gcc_checking_assert (!existed
);
4904 TREE_VISITED (decl
) = true;
4909 trees_out::get_tag (tree t
)
4911 gcc_checking_assert (TREE_VISITED (t
));
4912 return *tree_map
.get (t
);
4915 /* Insert T into the map, return its tag number. */
4918 trees_out::insert (tree t
, walk_kind walk
)
4920 gcc_checking_assert (walk
!= WK_normal
|| !TREE_VISITED (t
));
4921 int tag
= --ref_num
;
4923 int &slot
= tree_map
.get_or_insert (t
, &existed
);
4924 gcc_checking_assert (TREE_VISITED (t
) == existed
4926 || (walk
== WK_value
&& slot
== tag_value
)));
4927 TREE_VISITED (t
) = true;
4933 /* Insert T into the backreference array. Return its back reference
4937 trees_in::insert (tree t
)
4939 gcc_checking_assert (t
|| get_overrun ());
4940 back_refs
.safe_push (t
);
4941 return -(int)back_refs
.length ();
4944 /* A chained set of decls. */
4947 trees_out::chained_decls (tree decls
)
4949 for (; decls
; decls
= DECL_CHAIN (decls
))
4951 if (VAR_OR_FUNCTION_DECL_P (decls
)
4952 && DECL_LOCAL_DECL_P (decls
))
4954 /* Make sure this is the first encounter, and mark for
4956 gcc_checking_assert (!TREE_VISITED (decls
)
4957 && !DECL_TEMPLATE_INFO (decls
));
4958 mark_by_value (decls
);
4962 tree_node (NULL_TREE
);
4966 trees_in::chained_decls ()
4968 tree decls
= NULL_TREE
;
4969 for (tree
*chain
= &decls
;;)
4970 if (tree decl
= tree_node ())
4972 if (!DECL_P (decl
) || DECL_CHAIN (decl
))
4978 chain
= &DECL_CHAIN (decl
);
4986 /* A vector of decls following DECL_CHAIN. */
4989 trees_out::vec_chained_decls (tree decls
)
4995 for (tree decl
= decls
; decl
; decl
= DECL_CHAIN (decl
))
5000 for (tree decl
= decls
; decl
; decl
= DECL_CHAIN (decl
))
5002 if (DECL_IMPLICIT_TYPEDEF_P (decl
)
5003 && TYPE_NAME (TREE_TYPE (decl
)) != decl
)
5004 /* An anonynmous struct with a typedef name. An odd thing to
5006 tree_node (NULL_TREE
);
5012 vec
<tree
, va_heap
> *
5013 trees_in::vec_chained_decls ()
5015 vec
<tree
, va_heap
> *v
= NULL
;
5017 if (unsigned len
= u ())
5021 for (unsigned ix
= 0; ix
< len
; ix
++)
5023 tree decl
= tree_node ();
5024 if (decl
&& !DECL_P (decl
))
5029 v
->quick_push (decl
);
5042 /* A vector of trees. */
5045 trees_out::tree_vec (vec
<tree
, va_gc
> *v
)
5047 unsigned len
= vec_safe_length (v
);
5050 for (unsigned ix
= 0; ix
!= len
; ix
++)
5051 tree_node ((*v
)[ix
]);
5055 trees_in::tree_vec ()
5057 vec
<tree
, va_gc
> *v
= NULL
;
5058 if (unsigned len
= u ())
5061 for (unsigned ix
= 0; ix
!= len
; ix
++)
5062 v
->quick_push (tree_node ());
5067 /* A vector of tree pairs. */
5070 trees_out::tree_pair_vec (vec
<tree_pair_s
, va_gc
> *v
)
5072 unsigned len
= vec_safe_length (v
);
5076 for (unsigned ix
= 0; ix
!= len
; ix
++)
5078 tree_pair_s
const &s
= (*v
)[ix
];
5079 tree_node (s
.purpose
);
5080 tree_node (s
.value
);
5084 vec
<tree_pair_s
, va_gc
> *
5085 trees_in::tree_pair_vec ()
5087 vec
<tree_pair_s
, va_gc
> *v
= NULL
;
5088 if (unsigned len
= u ())
5091 for (unsigned ix
= 0; ix
!= len
; ix
++)
5094 s
.purpose
= tree_node ();
5095 s
.value
= tree_node ();
5103 trees_out::tree_list (tree list
, bool has_purpose
)
5105 for (; list
; list
= TREE_CHAIN (list
))
5107 gcc_checking_assert (TREE_VALUE (list
));
5108 tree_node (TREE_VALUE (list
));
5110 tree_node (TREE_PURPOSE (list
));
5112 tree_node (NULL_TREE
);
5116 trees_in::tree_list (bool has_purpose
)
5118 tree res
= NULL_TREE
;
5120 for (tree
*chain
= &res
; tree value
= tree_node ();
5121 chain
= &TREE_CHAIN (*chain
))
5123 tree purpose
= has_purpose
? tree_node () : NULL_TREE
;
5124 *chain
= build_tree_list (purpose
, value
);
5129 /* Start tree write. Write information to allocate the receiving
5133 trees_out::start (tree t
, bool code_streamed
)
5137 enum tree_code code
= TREE_CODE (t
);
5138 gcc_checking_assert (TYPE_MAIN_VARIANT (t
) == t
);
5139 /* All these types are TYPE_NON_COMMON. */
5140 gcc_checking_assert (code
== RECORD_TYPE
5141 || code
== UNION_TYPE
5142 || code
== ENUMERAL_TYPE
5143 || code
== TEMPLATE_TYPE_PARM
5144 || code
== TEMPLATE_TEMPLATE_PARM
5145 || code
== BOUND_TEMPLATE_TEMPLATE_PARM
);
5151 switch (TREE_CODE (t
))
5154 if (TREE_CODE_CLASS (TREE_CODE (t
)) == tcc_vl_exp
)
5155 u (VL_EXP_OPERAND_LENGTH (t
));
5159 u (TREE_INT_CST_NUNITS (t
));
5160 u (TREE_INT_CST_EXT_NUNITS (t
));
5161 u (TREE_INT_CST_OFFSET_NUNITS (t
));
5165 state
->extensions
|= SE_OPENMP
;
5166 u (OMP_CLAUSE_CODE (t
));
5170 str (TREE_STRING_POINTER (t
), TREE_STRING_LENGTH (t
));
5174 u (VECTOR_CST_LOG2_NPATTERNS (t
));
5175 u (VECTOR_CST_NELTS_PER_PATTERN (t
));
5179 u (BINFO_N_BASE_BINFOS (t
));
5183 u (TREE_VEC_LENGTH (t
));
5188 gcc_unreachable (); /* Not supported in C++. */
5191 case IDENTIFIER_NODE
:
5193 case TARGET_MEM_REF
:
5194 case TRANSLATION_UNIT_DECL
:
5195 /* We shouldn't meet these. */
5201 /* Start tree read. Allocate the receiving node. */
5204 trees_in::start (unsigned code
)
5214 if (code
>= MAX_TREE_CODES
)
5220 else if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
5222 unsigned ops
= u ();
5223 t
= build_vl_exp (tree_code (code
), ops
);
5226 t
= make_node (tree_code (code
));
5233 t
= make_int_cst (n
, e
);
5234 TREE_INT_CST_OFFSET_NUNITS(t
) = u ();
5240 if (!(state
->extensions
& SE_OPENMP
))
5243 unsigned omp_code
= u ();
5244 t
= build_omp_clause (UNKNOWN_LOCATION
, omp_clause_code (omp_code
));
5251 const char *chars
= str (&l
);
5252 t
= build_string (l
, chars
);
5258 unsigned log2_npats
= u ();
5259 unsigned elts_per
= u ();
5260 t
= make_vector (log2_npats
, elts_per
);
5265 t
= make_tree_binfo (u ());
5269 t
= make_tree_vec (u ());
5273 case IDENTIFIER_NODE
:
5276 case TARGET_MEM_REF
:
5277 case TRANSLATION_UNIT_DECL
:
5284 /* The structure streamers access the raw fields, because the
5285 alternative, of using the accessor macros can require using
5286 different accessors for the same underlying field, depending on the
5287 tree code. That's both confusing and annoying. */
5289 /* Read & write the core boolean flags. */
5292 trees_out::core_bools (tree t
)
5294 #define WB(X) (b (X))
5295 tree_code code
= TREE_CODE (t
);
5297 WB (t
->base
.side_effects_flag
);
5298 WB (t
->base
.constant_flag
);
5299 WB (t
->base
.addressable_flag
);
5300 WB (t
->base
.volatile_flag
);
5301 WB (t
->base
.readonly_flag
);
5302 /* base.asm_written_flag is a property of the current TU's use of
5304 WB (t
->base
.nowarning_flag
);
5305 /* base.visited read as zero (it's set for writer, because that's
5306 how we mark nodes). */
5307 /* base.used_flag is not streamed. Readers may set TREE_USED of
5309 WB (t
->base
.nothrow_flag
);
5310 WB (t
->base
.static_flag
);
5311 if (TREE_CODE_CLASS (code
) != tcc_type
)
5312 /* This is TYPE_CACHED_VALUES_P for types. */
5313 WB (t
->base
.public_flag
);
5314 WB (t
->base
.private_flag
);
5315 WB (t
->base
.protected_flag
);
5316 WB (t
->base
.deprecated_flag
);
5317 WB (t
->base
.default_def_flag
);
5324 case TARGET_MEM_REF
:
5326 /* These use different base.u fields. */
5330 WB (t
->base
.u
.bits
.lang_flag_0
);
5331 bool flag_1
= t
->base
.u
.bits
.lang_flag_1
;
5334 else if (code
== TEMPLATE_INFO
)
5335 /* This is TI_PENDING_TEMPLATE_FLAG, not relevant to reader. */
5337 else if (code
== VAR_DECL
)
5339 /* This is DECL_INITIALIZED_P. */
5340 if (TREE_CODE (DECL_CONTEXT (t
)) != FUNCTION_DECL
)
5341 /* We'll set this when reading the definition. */
5345 WB (t
->base
.u
.bits
.lang_flag_2
);
5346 WB (t
->base
.u
.bits
.lang_flag_3
);
5347 WB (t
->base
.u
.bits
.lang_flag_4
);
5348 WB (t
->base
.u
.bits
.lang_flag_5
);
5349 WB (t
->base
.u
.bits
.lang_flag_6
);
5350 WB (t
->base
.u
.bits
.saturating_flag
);
5351 WB (t
->base
.u
.bits
.unsigned_flag
);
5352 WB (t
->base
.u
.bits
.packed_flag
);
5353 WB (t
->base
.u
.bits
.user_align
);
5354 WB (t
->base
.u
.bits
.nameless_flag
);
5355 WB (t
->base
.u
.bits
.atomic_flag
);
5359 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_COMMON
))
5361 WB (t
->type_common
.no_force_blk_flag
);
5362 WB (t
->type_common
.needs_constructing_flag
);
5363 WB (t
->type_common
.transparent_aggr_flag
);
5364 WB (t
->type_common
.restrict_flag
);
5365 WB (t
->type_common
.string_flag
);
5366 WB (t
->type_common
.lang_flag_0
);
5367 WB (t
->type_common
.lang_flag_1
);
5368 WB (t
->type_common
.lang_flag_2
);
5369 WB (t
->type_common
.lang_flag_3
);
5370 WB (t
->type_common
.lang_flag_4
);
5371 WB (t
->type_common
.lang_flag_5
);
5372 WB (t
->type_common
.lang_flag_6
);
5373 WB (t
->type_common
.typeless_storage
);
5376 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
5378 WB (t
->decl_common
.nonlocal_flag
);
5379 WB (t
->decl_common
.virtual_flag
);
5380 WB (t
->decl_common
.ignored_flag
);
5381 WB (t
->decl_common
.abstract_flag
);
5382 WB (t
->decl_common
.artificial_flag
);
5383 WB (t
->decl_common
.preserve_flag
);
5384 WB (t
->decl_common
.debug_expr_is_from
);
5385 WB (t
->decl_common
.lang_flag_0
);
5386 WB (t
->decl_common
.lang_flag_1
);
5387 WB (t
->decl_common
.lang_flag_2
);
5388 WB (t
->decl_common
.lang_flag_3
);
5389 WB (t
->decl_common
.lang_flag_4
);
5390 WB (t
->decl_common
.lang_flag_5
);
5391 WB (t
->decl_common
.lang_flag_6
);
5392 WB (t
->decl_common
.lang_flag_7
);
5393 WB (t
->decl_common
.lang_flag_8
);
5394 WB (t
->decl_common
.decl_flag_0
);
5397 /* DECL_EXTERNAL -> decl_flag_1
5398 == it is defined elsewhere
5399 DECL_NOT_REALLY_EXTERN -> base.not_really_extern
5400 == that was a lie, it is here */
5402 bool is_external
= t
->decl_common
.decl_flag_1
;
5404 /* decl_flag_1 is DECL_EXTERNAL. Things we emit here, might
5405 well be external from the POV of an importer. */
5406 // FIXME: Do we need to know if this is a TEMPLATE_RESULT --
5407 // a flag from the caller?
5415 && !(TREE_STATIC (t
)
5416 && DECL_FUNCTION_SCOPE_P (t
)
5417 && DECL_DECLARED_INLINE_P (DECL_CONTEXT (t
)))
5418 && !DECL_VAR_DECLARED_INLINE_P (t
))
5424 && !DECL_DECLARED_INLINE_P (t
))
5431 WB (t
->decl_common
.decl_flag_2
);
5432 WB (t
->decl_common
.decl_flag_3
);
5433 WB (t
->decl_common
.not_gimple_reg_flag
);
5434 WB (t
->decl_common
.decl_by_reference_flag
);
5435 WB (t
->decl_common
.decl_read_flag
);
5436 WB (t
->decl_common
.decl_nonshareable_flag
);
5437 WB (t
->decl_common
.decl_not_flexarray
);
5440 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
5442 WB (t
->decl_with_vis
.defer_output
);
5443 WB (t
->decl_with_vis
.hard_register
);
5444 WB (t
->decl_with_vis
.common_flag
);
5445 WB (t
->decl_with_vis
.in_text_section
);
5446 WB (t
->decl_with_vis
.in_constant_pool
);
5447 WB (t
->decl_with_vis
.dllimport_flag
);
5448 WB (t
->decl_with_vis
.weak_flag
);
5449 WB (t
->decl_with_vis
.seen_in_bind_expr
);
5450 WB (t
->decl_with_vis
.comdat_flag
);
5451 WB (t
->decl_with_vis
.visibility_specified
);
5452 WB (t
->decl_with_vis
.init_priority_p
);
5453 WB (t
->decl_with_vis
.shadowed_for_var_p
);
5454 WB (t
->decl_with_vis
.cxx_constructor
);
5455 WB (t
->decl_with_vis
.cxx_destructor
);
5456 WB (t
->decl_with_vis
.final
);
5457 WB (t
->decl_with_vis
.regdecl_flag
);
5460 if (CODE_CONTAINS_STRUCT (code
, TS_FUNCTION_DECL
))
5462 WB (t
->function_decl
.static_ctor_flag
);
5463 WB (t
->function_decl
.static_dtor_flag
);
5464 WB (t
->function_decl
.uninlinable
);
5465 WB (t
->function_decl
.possibly_inlined
);
5466 WB (t
->function_decl
.novops_flag
);
5467 WB (t
->function_decl
.returns_twice_flag
);
5468 WB (t
->function_decl
.malloc_flag
);
5469 WB (t
->function_decl
.declared_inline_flag
);
5470 WB (t
->function_decl
.no_inline_warning_flag
);
5471 WB (t
->function_decl
.no_instrument_function_entry_exit
);
5472 WB (t
->function_decl
.no_limit_stack
);
5473 WB (t
->function_decl
.disregard_inline_limits
);
5474 WB (t
->function_decl
.pure_flag
);
5475 WB (t
->function_decl
.looping_const_or_pure_flag
);
5477 WB (t
->function_decl
.has_debug_args_flag
);
5478 WB (t
->function_decl
.versioned_function
);
5480 /* decl_type is a (misnamed) 2 bit discriminator. */
5481 unsigned kind
= t
->function_decl
.decl_type
;
5482 WB ((kind
>> 0) & 1);
5483 WB ((kind
>> 1) & 1);
5489 trees_in::core_bools (tree t
)
5491 #define RB(X) ((X) = b ())
5492 tree_code code
= TREE_CODE (t
);
5494 RB (t
->base
.side_effects_flag
);
5495 RB (t
->base
.constant_flag
);
5496 RB (t
->base
.addressable_flag
);
5497 RB (t
->base
.volatile_flag
);
5498 RB (t
->base
.readonly_flag
);
5499 /* base.asm_written_flag is not streamed. */
5500 RB (t
->base
.nowarning_flag
);
5501 /* base.visited is not streamed. */
5502 /* base.used_flag is not streamed. */
5503 RB (t
->base
.nothrow_flag
);
5504 RB (t
->base
.static_flag
);
5505 if (TREE_CODE_CLASS (code
) != tcc_type
)
5506 RB (t
->base
.public_flag
);
5507 RB (t
->base
.private_flag
);
5508 RB (t
->base
.protected_flag
);
5509 RB (t
->base
.deprecated_flag
);
5510 RB (t
->base
.default_def_flag
);
5517 case TARGET_MEM_REF
:
5519 /* These use different base.u fields. */
5523 RB (t
->base
.u
.bits
.lang_flag_0
);
5524 RB (t
->base
.u
.bits
.lang_flag_1
);
5525 RB (t
->base
.u
.bits
.lang_flag_2
);
5526 RB (t
->base
.u
.bits
.lang_flag_3
);
5527 RB (t
->base
.u
.bits
.lang_flag_4
);
5528 RB (t
->base
.u
.bits
.lang_flag_5
);
5529 RB (t
->base
.u
.bits
.lang_flag_6
);
5530 RB (t
->base
.u
.bits
.saturating_flag
);
5531 RB (t
->base
.u
.bits
.unsigned_flag
);
5532 RB (t
->base
.u
.bits
.packed_flag
);
5533 RB (t
->base
.u
.bits
.user_align
);
5534 RB (t
->base
.u
.bits
.nameless_flag
);
5535 RB (t
->base
.u
.bits
.atomic_flag
);
5539 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_COMMON
))
5541 RB (t
->type_common
.no_force_blk_flag
);
5542 RB (t
->type_common
.needs_constructing_flag
);
5543 RB (t
->type_common
.transparent_aggr_flag
);
5544 RB (t
->type_common
.restrict_flag
);
5545 RB (t
->type_common
.string_flag
);
5546 RB (t
->type_common
.lang_flag_0
);
5547 RB (t
->type_common
.lang_flag_1
);
5548 RB (t
->type_common
.lang_flag_2
);
5549 RB (t
->type_common
.lang_flag_3
);
5550 RB (t
->type_common
.lang_flag_4
);
5551 RB (t
->type_common
.lang_flag_5
);
5552 RB (t
->type_common
.lang_flag_6
);
5553 RB (t
->type_common
.typeless_storage
);
5556 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
5558 RB (t
->decl_common
.nonlocal_flag
);
5559 RB (t
->decl_common
.virtual_flag
);
5560 RB (t
->decl_common
.ignored_flag
);
5561 RB (t
->decl_common
.abstract_flag
);
5562 RB (t
->decl_common
.artificial_flag
);
5563 RB (t
->decl_common
.preserve_flag
);
5564 RB (t
->decl_common
.debug_expr_is_from
);
5565 RB (t
->decl_common
.lang_flag_0
);
5566 RB (t
->decl_common
.lang_flag_1
);
5567 RB (t
->decl_common
.lang_flag_2
);
5568 RB (t
->decl_common
.lang_flag_3
);
5569 RB (t
->decl_common
.lang_flag_4
);
5570 RB (t
->decl_common
.lang_flag_5
);
5571 RB (t
->decl_common
.lang_flag_6
);
5572 RB (t
->decl_common
.lang_flag_7
);
5573 RB (t
->decl_common
.lang_flag_8
);
5574 RB (t
->decl_common
.decl_flag_0
);
5575 RB (t
->decl_common
.decl_flag_1
);
5576 RB (t
->decl_common
.decl_flag_2
);
5577 RB (t
->decl_common
.decl_flag_3
);
5578 RB (t
->decl_common
.not_gimple_reg_flag
);
5579 RB (t
->decl_common
.decl_by_reference_flag
);
5580 RB (t
->decl_common
.decl_read_flag
);
5581 RB (t
->decl_common
.decl_nonshareable_flag
);
5582 RB (t
->decl_common
.decl_not_flexarray
);
5585 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
5587 RB (t
->decl_with_vis
.defer_output
);
5588 RB (t
->decl_with_vis
.hard_register
);
5589 RB (t
->decl_with_vis
.common_flag
);
5590 RB (t
->decl_with_vis
.in_text_section
);
5591 RB (t
->decl_with_vis
.in_constant_pool
);
5592 RB (t
->decl_with_vis
.dllimport_flag
);
5593 RB (t
->decl_with_vis
.weak_flag
);
5594 RB (t
->decl_with_vis
.seen_in_bind_expr
);
5595 RB (t
->decl_with_vis
.comdat_flag
);
5596 RB (t
->decl_with_vis
.visibility_specified
);
5597 RB (t
->decl_with_vis
.init_priority_p
);
5598 RB (t
->decl_with_vis
.shadowed_for_var_p
);
5599 RB (t
->decl_with_vis
.cxx_constructor
);
5600 RB (t
->decl_with_vis
.cxx_destructor
);
5601 RB (t
->decl_with_vis
.final
);
5602 RB (t
->decl_with_vis
.regdecl_flag
);
5605 if (CODE_CONTAINS_STRUCT (code
, TS_FUNCTION_DECL
))
5607 RB (t
->function_decl
.static_ctor_flag
);
5608 RB (t
->function_decl
.static_dtor_flag
);
5609 RB (t
->function_decl
.uninlinable
);
5610 RB (t
->function_decl
.possibly_inlined
);
5611 RB (t
->function_decl
.novops_flag
);
5612 RB (t
->function_decl
.returns_twice_flag
);
5613 RB (t
->function_decl
.malloc_flag
);
5614 RB (t
->function_decl
.declared_inline_flag
);
5615 RB (t
->function_decl
.no_inline_warning_flag
);
5616 RB (t
->function_decl
.no_instrument_function_entry_exit
);
5617 RB (t
->function_decl
.no_limit_stack
);
5618 RB (t
->function_decl
.disregard_inline_limits
);
5619 RB (t
->function_decl
.pure_flag
);
5620 RB (t
->function_decl
.looping_const_or_pure_flag
);
5622 RB (t
->function_decl
.has_debug_args_flag
);
5623 RB (t
->function_decl
.versioned_function
);
5625 /* decl_type is a (misnamed) 2 bit discriminator. */
5627 kind
|= unsigned (b ()) << 0;
5628 kind
|= unsigned (b ()) << 1;
5629 t
->function_decl
.decl_type
= function_decl_type (kind
);
5632 return !get_overrun ();
5636 trees_out::lang_decl_bools (tree t
)
5638 #define WB(X) (b (X))
5639 const struct lang_decl
*lang
= DECL_LANG_SPECIFIC (t
);
5641 WB (lang
->u
.base
.language
== lang_cplusplus
);
5642 WB ((lang
->u
.base
.use_template
>> 0) & 1);
5643 WB ((lang
->u
.base
.use_template
>> 1) & 1);
5644 /* Do not write lang->u.base.not_really_extern, importer will set
5645 when reading the definition (if any). */
5646 WB (lang
->u
.base
.initialized_in_class
);
5647 WB (lang
->u
.base
.threadprivate_or_deleted_p
);
5648 /* Do not write lang->u.base.anticipated_p, it is a property of the
5650 WB (lang
->u
.base
.friend_or_tls
);
5651 WB (lang
->u
.base
.unknown_bound_p
);
5652 /* Do not write lang->u.base.odr_used, importer will recalculate if
5653 they do ODR use this decl. */
5654 WB (lang
->u
.base
.concept_p
);
5655 WB (lang
->u
.base
.var_declared_inline_p
);
5656 WB (lang
->u
.base
.dependent_init_p
);
5657 /* When building a header unit, everthing is marked as purview, (so
5658 we know which decls to write). But when we import them we do not
5659 want to mark them as in module purview. */
5660 WB (lang
->u
.base
.module_purview_p
&& !header_module_p ());
5661 WB (lang
->u
.base
.module_attach_p
);
5662 if (VAR_OR_FUNCTION_DECL_P (t
))
5663 WB (lang
->u
.base
.module_keyed_decls_p
);
5664 switch (lang
->u
.base
.selector
)
5669 case lds_fn
: /* lang_decl_fn. */
5670 WB (lang
->u
.fn
.global_ctor_p
);
5671 WB (lang
->u
.fn
.global_dtor_p
);
5672 WB (lang
->u
.fn
.static_function
);
5673 WB (lang
->u
.fn
.pure_virtual
);
5674 WB (lang
->u
.fn
.defaulted_p
);
5675 WB (lang
->u
.fn
.has_in_charge_parm_p
);
5676 WB (lang
->u
.fn
.has_vtt_parm_p
);
5677 /* There shouldn't be a pending inline at this point. */
5678 gcc_assert (!lang
->u
.fn
.pending_inline_p
);
5679 WB (lang
->u
.fn
.nonconverting
);
5680 WB (lang
->u
.fn
.thunk_p
);
5681 WB (lang
->u
.fn
.this_thunk_p
);
5682 /* Do not stream lang->u.hidden_friend_p, it is a property of
5684 WB (lang
->u
.fn
.omp_declare_reduction_p
);
5685 WB (lang
->u
.fn
.has_dependent_explicit_spec_p
);
5686 WB (lang
->u
.fn
.immediate_fn_p
);
5687 WB (lang
->u
.fn
.maybe_deleted
);
5690 case lds_decomp
: /* lang_decl_decomp. */
5694 case lds_min
: /* lang_decl_min. */
5699 case lds_ns
: /* lang_decl_ns. */
5703 case lds_parm
: /* lang_decl_parm. */
5711 trees_in::lang_decl_bools (tree t
)
5713 #define RB(X) ((X) = b ())
5714 struct lang_decl
*lang
= DECL_LANG_SPECIFIC (t
);
5716 lang
->u
.base
.language
= b () ? lang_cplusplus
: lang_c
;
5720 lang
->u
.base
.use_template
= v
;
5721 /* lang->u.base.not_really_extern is not streamed. */
5722 RB (lang
->u
.base
.initialized_in_class
);
5723 RB (lang
->u
.base
.threadprivate_or_deleted_p
);
5724 /* lang->u.base.anticipated_p is not streamed. */
5725 RB (lang
->u
.base
.friend_or_tls
);
5726 RB (lang
->u
.base
.unknown_bound_p
);
5727 /* lang->u.base.odr_used is not streamed. */
5728 RB (lang
->u
.base
.concept_p
);
5729 RB (lang
->u
.base
.var_declared_inline_p
);
5730 RB (lang
->u
.base
.dependent_init_p
);
5731 RB (lang
->u
.base
.module_purview_p
);
5732 RB (lang
->u
.base
.module_attach_p
);
5733 if (VAR_OR_FUNCTION_DECL_P (t
))
5734 RB (lang
->u
.base
.module_keyed_decls_p
);
5735 switch (lang
->u
.base
.selector
)
5740 case lds_fn
: /* lang_decl_fn. */
5741 RB (lang
->u
.fn
.global_ctor_p
);
5742 RB (lang
->u
.fn
.global_dtor_p
);
5743 RB (lang
->u
.fn
.static_function
);
5744 RB (lang
->u
.fn
.pure_virtual
);
5745 RB (lang
->u
.fn
.defaulted_p
);
5746 RB (lang
->u
.fn
.has_in_charge_parm_p
);
5747 RB (lang
->u
.fn
.has_vtt_parm_p
);
5748 RB (lang
->u
.fn
.nonconverting
);
5749 RB (lang
->u
.fn
.thunk_p
);
5750 RB (lang
->u
.fn
.this_thunk_p
);
5751 /* lang->u.fn.hidden_friend_p is not streamed. */
5752 RB (lang
->u
.fn
.omp_declare_reduction_p
);
5753 RB (lang
->u
.fn
.has_dependent_explicit_spec_p
);
5754 RB (lang
->u
.fn
.immediate_fn_p
);
5755 RB (lang
->u
.fn
.maybe_deleted
);
5758 case lds_decomp
: /* lang_decl_decomp. */
5762 case lds_min
: /* lang_decl_min. */
5767 case lds_ns
: /* lang_decl_ns. */
5771 case lds_parm
: /* lang_decl_parm. */
5776 return !get_overrun ();
5780 trees_out::lang_type_bools (tree t
)
5782 #define WB(X) (b (X))
5783 const struct lang_type
*lang
= TYPE_LANG_SPECIFIC (t
);
5785 WB (lang
->has_type_conversion
);
5786 WB (lang
->has_copy_ctor
);
5787 WB (lang
->has_default_ctor
);
5788 WB (lang
->const_needs_init
);
5789 WB (lang
->ref_needs_init
);
5790 WB (lang
->has_const_copy_assign
);
5791 WB ((lang
->use_template
>> 0) & 1);
5792 WB ((lang
->use_template
>> 1) & 1);
5794 WB (lang
->has_mutable
);
5795 WB (lang
->com_interface
);
5796 WB (lang
->non_pod_class
);
5797 WB (lang
->nearly_empty_p
);
5798 WB (lang
->user_align
);
5799 WB (lang
->has_copy_assign
);
5801 WB (lang
->has_array_new
);
5803 WB ((lang
->gets_delete
>> 0) & 1);
5804 WB ((lang
->gets_delete
>> 1) & 1);
5805 // Interfaceness is recalculated upon reading. May have to revisit?
5806 // How do dllexport and dllimport interact across a module?
5807 // lang->interface_only
5808 // lang->interface_unknown
5809 WB (lang
->contains_empty_class_p
);
5810 WB (lang
->anon_aggr
);
5811 WB (lang
->non_zero_init
);
5814 WB (lang
->vec_new_uses_cookie
);
5815 WB (lang
->declared_class
);
5816 WB (lang
->diamond_shaped
);
5817 WB (lang
->repeated_base
);
5818 gcc_assert (!lang
->being_defined
);
5819 // lang->debug_requested
5820 WB (lang
->fields_readonly
);
5821 WB (lang
->ptrmemfunc_flag
);
5823 WB (lang
->lazy_default_ctor
);
5824 WB (lang
->lazy_copy_ctor
);
5825 WB (lang
->lazy_copy_assign
);
5826 WB (lang
->lazy_destructor
);
5827 WB (lang
->has_const_copy_ctor
);
5828 WB (lang
->has_complex_copy_ctor
);
5829 WB (lang
->has_complex_copy_assign
);
5830 WB (lang
->non_aggregate
);
5832 WB (lang
->has_complex_dflt
);
5833 WB (lang
->has_list_ctor
);
5834 WB (lang
->non_std_layout
);
5835 WB (lang
->is_literal
);
5836 WB (lang
->lazy_move_ctor
);
5837 WB (lang
->lazy_move_assign
);
5838 WB (lang
->has_complex_move_ctor
);
5839 WB (lang
->has_complex_move_assign
);
5841 WB (lang
->has_constexpr_ctor
);
5842 WB (lang
->unique_obj_representations
);
5843 WB (lang
->unique_obj_representations_set
);
5848 trees_in::lang_type_bools (tree t
)
5850 #define RB(X) ((X) = b ())
5851 struct lang_type
*lang
= TYPE_LANG_SPECIFIC (t
);
5853 RB (lang
->has_type_conversion
);
5854 RB (lang
->has_copy_ctor
);
5855 RB (lang
->has_default_ctor
);
5856 RB (lang
->const_needs_init
);
5857 RB (lang
->ref_needs_init
);
5858 RB (lang
->has_const_copy_assign
);
5862 lang
->use_template
= v
;
5864 RB (lang
->has_mutable
);
5865 RB (lang
->com_interface
);
5866 RB (lang
->non_pod_class
);
5867 RB (lang
->nearly_empty_p
);
5868 RB (lang
->user_align
);
5869 RB (lang
->has_copy_assign
);
5871 RB (lang
->has_array_new
);
5875 lang
->gets_delete
= v
;
5876 // lang->interface_only
5877 // lang->interface_unknown
5878 lang
->interface_unknown
= true; // Redetermine interface
5879 RB (lang
->contains_empty_class_p
);
5880 RB (lang
->anon_aggr
);
5881 RB (lang
->non_zero_init
);
5884 RB (lang
->vec_new_uses_cookie
);
5885 RB (lang
->declared_class
);
5886 RB (lang
->diamond_shaped
);
5887 RB (lang
->repeated_base
);
5888 gcc_assert (!lang
->being_defined
);
5889 gcc_assert (!lang
->debug_requested
);
5890 RB (lang
->fields_readonly
);
5891 RB (lang
->ptrmemfunc_flag
);
5893 RB (lang
->lazy_default_ctor
);
5894 RB (lang
->lazy_copy_ctor
);
5895 RB (lang
->lazy_copy_assign
);
5896 RB (lang
->lazy_destructor
);
5897 RB (lang
->has_const_copy_ctor
);
5898 RB (lang
->has_complex_copy_ctor
);
5899 RB (lang
->has_complex_copy_assign
);
5900 RB (lang
->non_aggregate
);
5902 RB (lang
->has_complex_dflt
);
5903 RB (lang
->has_list_ctor
);
5904 RB (lang
->non_std_layout
);
5905 RB (lang
->is_literal
);
5906 RB (lang
->lazy_move_ctor
);
5907 RB (lang
->lazy_move_assign
);
5908 RB (lang
->has_complex_move_ctor
);
5909 RB (lang
->has_complex_move_assign
);
5911 RB (lang
->has_constexpr_ctor
);
5912 RB (lang
->unique_obj_representations
);
5913 RB (lang
->unique_obj_representations_set
);
5915 return !get_overrun ();
5918 /* Read & write the core values and pointers. */
5921 trees_out::core_vals (tree t
)
5923 #define WU(X) (u (X))
5924 #define WT(X) (tree_node (X))
5925 tree_code code
= TREE_CODE (t
);
5927 /* First by shape of the tree. */
5929 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_MINIMAL
))
5931 /* Write this early, for better log information. */
5932 WT (t
->decl_minimal
.name
);
5933 if (!DECL_TEMPLATE_PARM_P (t
))
5934 WT (t
->decl_minimal
.context
);
5937 state
->write_location (*this, t
->decl_minimal
.locus
);
5940 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_COMMON
))
5942 /* The only types we write also have TYPE_NON_COMMON. */
5943 gcc_checking_assert (CODE_CONTAINS_STRUCT (code
, TS_TYPE_NON_COMMON
));
5945 /* We only stream the main variant. */
5946 gcc_checking_assert (TYPE_MAIN_VARIANT (t
) == t
);
5948 /* Stream the name & context first, for better log information */
5949 WT (t
->type_common
.name
);
5950 WT (t
->type_common
.context
);
5952 /* By construction we want to make sure we have the canonical
5953 and main variants already in the type table, so emit them
5955 WT (t
->type_common
.main_variant
);
5957 tree canonical
= t
->type_common
.canonical
;
5958 if (canonical
&& DECL_TEMPLATE_PARM_P (TYPE_NAME (t
)))
5959 /* We do not want to wander into different templates.
5960 Reconstructed on stream in. */
5964 /* type_common.next_variant is internally manipulated. */
5965 /* type_common.pointer_to, type_common.reference_to. */
5969 WU (t
->type_common
.precision
);
5970 WU (t
->type_common
.contains_placeholder_bits
);
5971 WU (t
->type_common
.mode
);
5972 WU (t
->type_common
.align
);
5975 if (!RECORD_OR_UNION_CODE_P (code
))
5977 WT (t
->type_common
.size
);
5978 WT (t
->type_common
.size_unit
);
5980 WT (t
->type_common
.attributes
);
5982 WT (t
->type_common
.common
.chain
); /* TYPE_STUB_DECL. */
5985 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
5989 WU (t
->decl_common
.mode
);
5990 WU (t
->decl_common
.off_align
);
5991 WU (t
->decl_common
.align
);
5994 /* For templates these hold instantiation (partial and/or
5995 specialization) information. */
5996 if (code
!= TEMPLATE_DECL
)
5998 WT (t
->decl_common
.size
);
5999 WT (t
->decl_common
.size_unit
);
6002 WT (t
->decl_common
.attributes
);
6003 // FIXME: Does this introduce cross-decl links? For instance
6004 // from instantiation to the template. If so, we'll need more
6005 // deduplication logic. I think we'll need to walk the blocks
6006 // of the owning function_decl's abstract origin in tandem, to
6007 // generate the locating data needed?
6008 WT (t
->decl_common
.abstract_origin
);
6011 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
6013 WT (t
->decl_with_vis
.assembler_name
);
6015 WU (t
->decl_with_vis
.visibility
);
6018 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_NON_COMMON
))
6020 if (code
== ENUMERAL_TYPE
)
6022 /* These fields get set even for opaque enums that lack a
6023 definition, so we stream them directly for each ENUMERAL_TYPE.
6024 We stream TYPE_VALUES as part of the definition. */
6025 WT (t
->type_non_common
.maxval
);
6026 WT (t
->type_non_common
.minval
);
6028 /* Records and unions hold FIELDS, VFIELD & BINFO on these
6030 else if (!RECORD_OR_UNION_CODE_P (code
))
6032 // FIXME: These are from tpl_parm_value's 'type' writing.
6033 // Perhaps it should just be doing them directly?
6034 gcc_checking_assert (code
== TEMPLATE_TYPE_PARM
6035 || code
== TEMPLATE_TEMPLATE_PARM
6036 || code
== BOUND_TEMPLATE_TEMPLATE_PARM
);
6037 gcc_checking_assert (!TYPE_CACHED_VALUES_P (t
));
6038 WT (t
->type_non_common
.values
);
6039 WT (t
->type_non_common
.maxval
);
6040 WT (t
->type_non_common
.minval
);
6043 WT (t
->type_non_common
.lang_1
);
6046 if (CODE_CONTAINS_STRUCT (code
, TS_EXP
))
6049 state
->write_location (*this, t
->exp
.locus
);
6051 /* Walk in forward order, as (for instance) REQUIRES_EXPR has a
6052 bunch of unscoped parms on its first operand. It's safer to
6053 create those in order. */
6054 bool vl
= TREE_CODE_CLASS (code
) == tcc_vl_exp
;
6055 for (unsigned limit
= (vl
? VL_EXP_OPERAND_LENGTH (t
)
6056 : TREE_OPERAND_LENGTH (t
)),
6057 ix
= unsigned (vl
); ix
!= limit
; ix
++)
6058 WT (TREE_OPERAND (t
, ix
));
6061 /* The CODE_CONTAINS tables were inaccurate when I started. */
6062 gcc_checking_assert (TREE_CODE_CLASS (code
) != tcc_expression
6063 && TREE_CODE_CLASS (code
) != tcc_binary
6064 && TREE_CODE_CLASS (code
) != tcc_unary
6065 && TREE_CODE_CLASS (code
) != tcc_reference
6066 && TREE_CODE_CLASS (code
) != tcc_comparison
6067 && TREE_CODE_CLASS (code
) != tcc_statement
6068 && TREE_CODE_CLASS (code
) != tcc_vl_exp
);
6070 /* Then by CODE. Special cases and/or 1:1 tree shape
6077 case ARGUMENT_PACK_SELECT
: /* Transient during instantiation. */
6078 case DEFERRED_PARSE
: /* Expanded upon completion of
6080 case IDENTIFIER_NODE
: /* Streamed specially. */
6081 case BINDING_VECTOR
: /* Only in namespace-scope symbol
6084 case TRANSLATION_UNIT_DECL
: /* There is only one, it is a
6086 case USERDEF_LITERAL
: /* Expanded during parsing. */
6087 gcc_unreachable (); /* Should never meet. */
6091 WT (TREE_REALPART (t
));
6092 WT (TREE_IMAGPART (t
));
6096 gcc_unreachable (); /* Not supported in C++. */
6101 unsigned num
= TREE_INT_CST_EXT_NUNITS (t
);
6102 for (unsigned ix
= 0; ix
!= num
; ix
++)
6103 wu (TREE_INT_CST_ELT (t
, ix
));
6108 gcc_unreachable (); /* Not supported in C++. */
6112 buf (TREE_REAL_CST_PTR (t
), sizeof (real_value
));
6116 /* Streamed during start. */
6120 for (unsigned ix
= vector_cst_encoded_nelts (t
); ix
--;)
6121 WT (VECTOR_CST_ENCODED_ELT (t
, ix
));
6126 if (DECL_CONTEXT (t
)
6127 && TREE_CODE (DECL_CONTEXT (t
)) != FUNCTION_DECL
)
6133 if (DECL_HAS_VALUE_EXPR_P (t
))
6134 WT (DECL_VALUE_EXPR (t
));
6139 WT (t
->decl_common
.initial
);
6143 WT (t
->field_decl
.offset
);
6144 WT (t
->field_decl
.bit_field_type
);
6145 WT (t
->field_decl
.qualifier
); /* bitfield unit. */
6146 WT (t
->field_decl
.bit_offset
);
6147 WT (t
->field_decl
.fcontext
);
6148 WT (t
->decl_common
.initial
);
6154 WU (t
->label_decl
.label_decl_uid
);
6155 WU (t
->label_decl
.eh_landing_pad_nr
);
6162 /* Builtins can be streamed by value when a header declares
6164 WU (DECL_BUILT_IN_CLASS (t
));
6165 if (DECL_BUILT_IN_CLASS (t
) != NOT_BUILT_IN
)
6166 WU (DECL_UNCHECKED_FUNCTION_CODE (t
));
6169 WT (t
->function_decl
.personality
);
6170 WT (t
->function_decl
.function_specific_target
);
6171 WT (t
->function_decl
.function_specific_optimization
);
6172 WT (t
->function_decl
.vindex
);
6174 if (DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (t
))
6175 WT (lookup_explicit_specifier (t
));
6179 /* USING_DECL_DECLS */
6180 WT (t
->decl_common
.initial
);
6184 /* USING_DECL: USING_DECL_SCOPE */
6185 /* TYPE_DECL: DECL_ORIGINAL_TYPE */
6186 WT (t
->decl_non_common
.result
);
6189 /* Miscellaneous common nodes. */
6193 state
->write_location (*this, t
->block
.locus
);
6194 state
->write_location (*this, t
->block
.end_locus
);
6197 /* DECL_LOCAL_DECL_P decls are first encountered here and
6198 streamed by value. */
6199 chained_decls (t
->block
.vars
);
6200 /* nonlocalized_vars is a middle-end thing. */
6201 WT (t
->block
.subblocks
);
6202 WT (t
->block
.supercontext
);
6203 // FIXME: As for decl's abstract_origin, does this introduce crosslinks?
6204 WT (t
->block
.abstract_origin
);
6205 /* fragment_origin, fragment_chain are middle-end things. */
6206 WT (t
->block
.chain
);
6207 /* nonlocalized_vars, block_num & die are middle endy/debug
6218 unsigned len
= vec_safe_length (t
->constructor
.elts
);
6222 for (unsigned ix
= 0; ix
!= len
; ix
++)
6224 const constructor_elt
&elt
= (*t
->constructor
.elts
)[ix
];
6234 /* The ompcode is serialized in start. */
6236 WU (t
->omp_clause
.subcode
.map_kind
);
6238 state
->write_location (*this, t
->omp_clause
.locus
);
6240 unsigned len
= omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)];
6241 for (unsigned ix
= 0; ix
!= len
; ix
++)
6242 WT (t
->omp_clause
.ops
[ix
]);
6246 case STATEMENT_LIST
:
6247 for (tree stmt
: tsi_range (t
))
6253 case OPTIMIZATION_NODE
:
6254 case TARGET_OPTION_NODE
:
6255 // FIXME: Our representation for these two nodes is a cache of
6256 // the resulting set of options. Not a record of the options
6257 // that got changed by a particular attribute or pragma. Should
6258 // we record that, or should we record the diff from the command
6259 // line options? The latter seems the right behaviour, but is
6260 // (a) harder, and I guess could introduce strangeness if the
6261 // importer has set some incompatible set of optimization flags?
6267 WT (t
->binfo
.common
.chain
);
6268 WT (t
->binfo
.offset
);
6269 WT (t
->binfo
.inheritance
);
6270 WT (t
->binfo
.vptr_field
);
6272 WT (t
->binfo
.vtable
);
6273 WT (t
->binfo
.virtuals
);
6274 WT (t
->binfo
.vtt_subvtt
);
6275 WT (t
->binfo
.vtt_vptr
);
6277 tree_vec (BINFO_BASE_ACCESSES (t
));
6278 unsigned num
= vec_safe_length (BINFO_BASE_ACCESSES (t
));
6279 for (unsigned ix
= 0; ix
!= num
; ix
++)
6280 WT (BINFO_BASE_BINFO (t
, ix
));
6285 WT (t
->list
.purpose
);
6287 WT (t
->list
.common
.chain
);
6291 for (unsigned ix
= TREE_VEC_LENGTH (t
); ix
--;)
6292 WT (TREE_VEC_ELT (t
, ix
));
6293 /* We stash NON_DEFAULT_TEMPLATE_ARGS_COUNT on TREE_CHAIN! */
6294 gcc_checking_assert (!t
->type_common
.common
.chain
6295 || (TREE_CODE (t
->type_common
.common
.chain
)
6297 WT (t
->type_common
.common
.chain
);
6300 /* C++-specific nodes ... */
6302 WT (((lang_tree_node
*)t
)->baselink
.binfo
);
6303 WT (((lang_tree_node
*)t
)->baselink
.functions
);
6304 WT (((lang_tree_node
*)t
)->baselink
.access_binfo
);
6307 case CONSTRAINT_INFO
:
6308 WT (((lang_tree_node
*)t
)->constraint_info
.template_reqs
);
6309 WT (((lang_tree_node
*)t
)->constraint_info
.declarator_reqs
);
6310 WT (((lang_tree_node
*)t
)->constraint_info
.associated_constr
);
6313 case DEFERRED_NOEXCEPT
:
6314 WT (((lang_tree_node
*)t
)->deferred_noexcept
.pattern
);
6315 WT (((lang_tree_node
*)t
)->deferred_noexcept
.args
);
6319 WT (((lang_tree_node
*)t
)->lambda_expression
.capture_list
);
6320 WT (((lang_tree_node
*)t
)->lambda_expression
.this_capture
);
6321 WT (((lang_tree_node
*)t
)->lambda_expression
.extra_scope
);
6322 /* pending_proxies is a parse-time thing. */
6323 gcc_assert (!((lang_tree_node
*)t
)->lambda_expression
.pending_proxies
);
6325 state
->write_location
6326 (*this, ((lang_tree_node
*)t
)->lambda_expression
.locus
);
6329 WU (((lang_tree_node
*)t
)->lambda_expression
.default_capture_mode
);
6330 WU (((lang_tree_node
*)t
)->lambda_expression
.discriminator_scope
);
6331 WU (((lang_tree_node
*)t
)->lambda_expression
.discriminator_sig
);
6336 WT (((lang_tree_node
*)t
)->overload
.function
);
6337 WT (t
->common
.chain
);
6341 WT (((lang_tree_node
*)t
)->ptrmem
.member
);
6345 WT (((lang_tree_node
*)t
)->static_assertion
.condition
);
6346 WT (((lang_tree_node
*)t
)->static_assertion
.message
);
6348 state
->write_location
6349 (*this, ((lang_tree_node
*)t
)->static_assertion
.location
);
6353 /* Streamed with the template_decl node itself. */
6355 (TREE_VISITED (((lang_tree_node
*)t
)->template_decl
.arguments
));
6357 (TREE_VISITED (((lang_tree_node
*)t
)->template_decl
.result
)
6358 || dep_hash
->find_dependency (t
)->is_alias_tmpl_inst ());
6359 if (DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (t
))
6360 WT (DECL_CHAIN (t
));
6365 WT (((lang_tree_node
*)t
)->template_info
.tmpl
);
6366 WT (((lang_tree_node
*)t
)->template_info
.args
);
6368 const auto *ac
= (((lang_tree_node
*)t
)
6369 ->template_info
.deferred_access_checks
);
6370 unsigned len
= vec_safe_length (ac
);
6375 for (unsigned ix
= 0; ix
!= len
; ix
++)
6377 const auto &m
= (*ac
)[ix
];
6382 state
->write_location (*this, m
.loc
);
6388 case TEMPLATE_PARM_INDEX
:
6391 WU (((lang_tree_node
*)t
)->tpi
.index
);
6392 WU (((lang_tree_node
*)t
)->tpi
.level
);
6393 WU (((lang_tree_node
*)t
)->tpi
.orig_level
);
6395 WT (((lang_tree_node
*)t
)->tpi
.decl
);
6396 /* TEMPLATE_PARM_DESCENDANTS (AKA TREE_CHAIN) is an internal
6397 cache, do not stream. */
6401 WT (((lang_tree_node
*)t
)->trait_expression
.type1
);
6402 WT (((lang_tree_node
*)t
)->trait_expression
.type2
);
6404 WU (((lang_tree_node
*)t
)->trait_expression
.kind
);
6408 if (CODE_CONTAINS_STRUCT (code
, TS_TYPED
))
6410 /* We want to stream the type of a expression-like nodes /after/
6411 we've streamed the operands. The type often contains (bits
6412 of the) types of the operands, and with things like decltype
6413 and noexcept in play, we really want to stream the decls
6414 defining the type before we try and stream the type on its
6415 own. Otherwise we can find ourselves trying to read in a
6416 decl, when we're already partially reading in a component of
6417 its type. And that's bad. */
6418 tree type
= t
->typed
.type
;
6427 /* We fill in the template's type separately. */
6432 if (DECL_ORIGINAL_TYPE (t
) && t
== TYPE_NAME (type
))
6433 /* This is a typedef. We set its type separately. */
6438 if (type
&& !ENUM_FIXED_UNDERLYING_TYPE_P (t
))
6440 /* Type is a restricted range integer type derived from the
6441 integer_types. Find the right one. */
6442 prec
= TYPE_PRECISION (type
);
6443 tree name
= DECL_NAME (TYPE_NAME (type
));
6445 for (unsigned itk
= itk_none
; itk
--;)
6446 if (integer_types
[itk
]
6447 && DECL_NAME (TYPE_NAME (integer_types
[itk
])) == name
)
6449 type
= integer_types
[itk
];
6452 gcc_assert (type
!= t
->typed
.type
);
6458 if (prec
&& streaming_p ())
6466 // Streaming in a reference to a decl can cause that decl to be
6467 // TREE_USED, which is the mark_used behaviour we need most of the
6468 // time. The trees_in::unused can be incremented to inhibit this,
6469 // which is at least needed for vtables.
6472 trees_in::core_vals (tree t
)
6474 #define RU(X) ((X) = u ())
6475 #define RUC(T,X) ((X) = T (u ()))
6476 #define RT(X) ((X) = tree_node ())
6477 #define RTU(X) ((X) = tree_node (true))
6478 tree_code code
= TREE_CODE (t
);
6480 /* First by tree shape. */
6481 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_MINIMAL
))
6483 RT (t
->decl_minimal
.name
);
6484 if (!DECL_TEMPLATE_PARM_P (t
))
6485 RT (t
->decl_minimal
.context
);
6487 /* Don't zap the locus just yet, we don't record it correctly
6488 and thus lose all location information. */
6489 t
->decl_minimal
.locus
= state
->read_location (*this);
6492 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_COMMON
))
6494 RT (t
->type_common
.name
);
6495 RT (t
->type_common
.context
);
6497 RT (t
->type_common
.main_variant
);
6498 RT (t
->type_common
.canonical
);
6500 /* type_common.next_variant is internally manipulated. */
6501 /* type_common.pointer_to, type_common.reference_to. */
6503 RU (t
->type_common
.precision
);
6504 RU (t
->type_common
.contains_placeholder_bits
);
6505 RUC (machine_mode
, t
->type_common
.mode
);
6506 RU (t
->type_common
.align
);
6508 if (!RECORD_OR_UNION_CODE_P (code
))
6510 RT (t
->type_common
.size
);
6511 RT (t
->type_common
.size_unit
);
6513 RT (t
->type_common
.attributes
);
6515 RT (t
->type_common
.common
.chain
); /* TYPE_STUB_DECL. */
6518 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
6520 RUC (machine_mode
, t
->decl_common
.mode
);
6521 RU (t
->decl_common
.off_align
);
6522 RU (t
->decl_common
.align
);
6524 if (code
!= TEMPLATE_DECL
)
6526 RT (t
->decl_common
.size
);
6527 RT (t
->decl_common
.size_unit
);
6530 RT (t
->decl_common
.attributes
);
6531 RT (t
->decl_common
.abstract_origin
);
6534 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
6536 RT (t
->decl_with_vis
.assembler_name
);
6537 RUC (symbol_visibility
, t
->decl_with_vis
.visibility
);
6540 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_NON_COMMON
))
6542 if (code
== ENUMERAL_TYPE
)
6544 /* These fields get set even for opaque enums that lack a
6545 definition, so we stream them directly for each ENUMERAL_TYPE.
6546 We stream TYPE_VALUES as part of the definition. */
6547 RT (t
->type_non_common
.maxval
);
6548 RT (t
->type_non_common
.minval
);
6550 /* Records and unions hold FIELDS, VFIELD & BINFO on these
6552 else if (!RECORD_OR_UNION_CODE_P (code
))
6554 /* This is not clobbering TYPE_CACHED_VALUES, because this
6555 is a type that doesn't have any. */
6556 gcc_checking_assert (!TYPE_CACHED_VALUES_P (t
));
6557 RT (t
->type_non_common
.values
);
6558 RT (t
->type_non_common
.maxval
);
6559 RT (t
->type_non_common
.minval
);
6562 RT (t
->type_non_common
.lang_1
);
6565 if (CODE_CONTAINS_STRUCT (code
, TS_EXP
))
6567 t
->exp
.locus
= state
->read_location (*this);
6569 bool vl
= TREE_CODE_CLASS (code
) == tcc_vl_exp
;
6570 for (unsigned limit
= (vl
? VL_EXP_OPERAND_LENGTH (t
)
6571 : TREE_OPERAND_LENGTH (t
)),
6572 ix
= unsigned (vl
); ix
!= limit
; ix
++)
6573 RTU (TREE_OPERAND (t
, ix
));
6576 /* Then by CODE. Special cases and/or 1:1 tree shape
6583 case ARGUMENT_PACK_SELECT
:
6584 case DEFERRED_PARSE
:
6585 case IDENTIFIER_NODE
:
6586 case BINDING_VECTOR
:
6588 case TRANSLATION_UNIT_DECL
:
6589 case USERDEF_LITERAL
:
6590 return false; /* Should never meet. */
6594 RT (TREE_REALPART (t
));
6595 RT (TREE_IMAGPART (t
));
6599 /* Not suported in C++. */
6604 unsigned num
= TREE_INT_CST_EXT_NUNITS (t
);
6605 for (unsigned ix
= 0; ix
!= num
; ix
++)
6606 TREE_INT_CST_ELT (t
, ix
) = wu ();
6611 /* Not suported in C++. */
6615 if (const void *bytes
= buf (sizeof (real_value
)))
6616 memcpy (TREE_REAL_CST_PTR (t
), bytes
, sizeof (real_value
));
6620 /* Streamed during start. */
6624 for (unsigned ix
= vector_cst_encoded_nelts (t
); ix
--;)
6625 RT (VECTOR_CST_ENCODED_ELT (t
, ix
));
6630 if (DECL_CONTEXT (t
)
6631 && TREE_CODE (DECL_CONTEXT (t
)) != FUNCTION_DECL
)
6637 if (DECL_HAS_VALUE_EXPR_P (t
))
6639 /* The DECL_VALUE hash table is a cache, thus if we're
6640 reading a duplicate (which we end up discarding), the
6641 value expr will also be cleaned up at the next gc. */
6642 tree val
= tree_node ();
6643 SET_DECL_VALUE_EXPR (t
, val
);
6649 RT (t
->decl_common
.initial
);
6653 RT (t
->field_decl
.offset
);
6654 RT (t
->field_decl
.bit_field_type
);
6655 RT (t
->field_decl
.qualifier
);
6656 RT (t
->field_decl
.bit_offset
);
6657 RT (t
->field_decl
.fcontext
);
6658 RT (t
->decl_common
.initial
);
6662 RU (t
->label_decl
.label_decl_uid
);
6663 RU (t
->label_decl
.eh_landing_pad_nr
);
6668 unsigned bltin
= u ();
6669 t
->function_decl
.built_in_class
= built_in_class (bltin
);
6670 if (bltin
!= NOT_BUILT_IN
)
6673 DECL_UNCHECKED_FUNCTION_CODE (t
) = built_in_function (bltin
);
6676 RT (t
->function_decl
.personality
);
6677 RT (t
->function_decl
.function_specific_target
);
6678 RT (t
->function_decl
.function_specific_optimization
);
6679 RT (t
->function_decl
.vindex
);
6681 if (DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (t
))
6685 store_explicit_specifier (t
, spec
);
6691 /* USING_DECL_DECLS */
6692 RT (t
->decl_common
.initial
);
6696 /* USING_DECL: USING_DECL_SCOPE */
6697 /* TYPE_DECL: DECL_ORIGINAL_TYPE */
6698 RT (t
->decl_non_common
.result
);
6701 /* Miscellaneous common nodes. */
6703 t
->block
.locus
= state
->read_location (*this);
6704 t
->block
.end_locus
= state
->read_location (*this);
6705 t
->block
.vars
= chained_decls ();
6706 /* nonlocalized_vars is middle-end. */
6707 RT (t
->block
.subblocks
);
6708 RT (t
->block
.supercontext
);
6709 RT (t
->block
.abstract_origin
);
6710 /* fragment_origin, fragment_chain are middle-end. */
6711 RT (t
->block
.chain
);
6712 /* nonlocalized_vars, block_num, die are middle endy/debug
6717 RUC (internal_fn
, t
->base
.u
.ifn
);
6721 if (unsigned len
= u ())
6723 vec_alloc (t
->constructor
.elts
, len
);
6724 for (unsigned ix
= 0; ix
!= len
; ix
++)
6726 constructor_elt elt
;
6730 t
->constructor
.elts
->quick_push (elt
);
6737 RU (t
->omp_clause
.subcode
.map_kind
);
6738 t
->omp_clause
.locus
= state
->read_location (*this);
6740 unsigned len
= omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)];
6741 for (unsigned ix
= 0; ix
!= len
; ix
++)
6742 RT (t
->omp_clause
.ops
[ix
]);
6746 case STATEMENT_LIST
:
6748 tree_stmt_iterator iter
= tsi_start (t
);
6749 for (tree stmt
; RT (stmt
);)
6750 tsi_link_after (&iter
, stmt
, TSI_CONTINUE_LINKING
);
6754 case OPTIMIZATION_NODE
:
6755 case TARGET_OPTION_NODE
:
6756 /* Not yet implemented, see trees_out::core_vals. */
6761 RT (t
->binfo
.common
.chain
);
6762 RT (t
->binfo
.offset
);
6763 RT (t
->binfo
.inheritance
);
6764 RT (t
->binfo
.vptr_field
);
6766 /* Do not mark the vtables as USED in the address expressions
6769 RT (t
->binfo
.vtable
);
6770 RT (t
->binfo
.virtuals
);
6771 RT (t
->binfo
.vtt_subvtt
);
6772 RT (t
->binfo
.vtt_vptr
);
6775 BINFO_BASE_ACCESSES (t
) = tree_vec ();
6776 if (!get_overrun ())
6778 unsigned num
= vec_safe_length (BINFO_BASE_ACCESSES (t
));
6779 for (unsigned ix
= 0; ix
!= num
; ix
++)
6780 BINFO_BASE_APPEND (t
, tree_node ());
6785 RT (t
->list
.purpose
);
6787 RT (t
->list
.common
.chain
);
6791 for (unsigned ix
= TREE_VEC_LENGTH (t
); ix
--;)
6792 RT (TREE_VEC_ELT (t
, ix
));
6793 RT (t
->type_common
.common
.chain
);
6796 /* C++-specific nodes ... */
6798 RT (((lang_tree_node
*)t
)->baselink
.binfo
);
6799 RTU (((lang_tree_node
*)t
)->baselink
.functions
);
6800 RT (((lang_tree_node
*)t
)->baselink
.access_binfo
);
6803 case CONSTRAINT_INFO
:
6804 RT (((lang_tree_node
*)t
)->constraint_info
.template_reqs
);
6805 RT (((lang_tree_node
*)t
)->constraint_info
.declarator_reqs
);
6806 RT (((lang_tree_node
*)t
)->constraint_info
.associated_constr
);
6809 case DEFERRED_NOEXCEPT
:
6810 RT (((lang_tree_node
*)t
)->deferred_noexcept
.pattern
);
6811 RT (((lang_tree_node
*)t
)->deferred_noexcept
.args
);
6815 RT (((lang_tree_node
*)t
)->lambda_expression
.capture_list
);
6816 RT (((lang_tree_node
*)t
)->lambda_expression
.this_capture
);
6817 RT (((lang_tree_node
*)t
)->lambda_expression
.extra_scope
);
6818 /* lambda_expression.pending_proxies is NULL */
6819 ((lang_tree_node
*)t
)->lambda_expression
.locus
6820 = state
->read_location (*this);
6821 RUC (cp_lambda_default_capture_mode_type
,
6822 ((lang_tree_node
*)t
)->lambda_expression
.default_capture_mode
);
6823 RU (((lang_tree_node
*)t
)->lambda_expression
.discriminator_scope
);
6824 RU (((lang_tree_node
*)t
)->lambda_expression
.discriminator_sig
);
6828 RT (((lang_tree_node
*)t
)->overload
.function
);
6829 RT (t
->common
.chain
);
6833 RT (((lang_tree_node
*)t
)->ptrmem
.member
);
6837 RT (((lang_tree_node
*)t
)->static_assertion
.condition
);
6838 RT (((lang_tree_node
*)t
)->static_assertion
.message
);
6839 ((lang_tree_node
*)t
)->static_assertion
.location
6840 = state
->read_location (*this);
6844 /* Streamed when reading the raw template decl itself. */
6845 gcc_assert (((lang_tree_node
*)t
)->template_decl
.arguments
);
6846 gcc_assert (((lang_tree_node
*)t
)->template_decl
.result
);
6847 if (DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (t
))
6848 RT (DECL_CHAIN (t
));
6852 RT (((lang_tree_node
*)t
)->template_info
.tmpl
);
6853 RT (((lang_tree_node
*)t
)->template_info
.args
);
6854 if (unsigned len
= u ())
6856 auto &ac
= (((lang_tree_node
*)t
)
6857 ->template_info
.deferred_access_checks
);
6858 vec_alloc (ac
, len
);
6859 for (unsigned ix
= 0; ix
!= len
; ix
++)
6861 deferred_access_check m
;
6866 m
.loc
= state
->read_location (*this);
6872 case TEMPLATE_PARM_INDEX
:
6873 RU (((lang_tree_node
*)t
)->tpi
.index
);
6874 RU (((lang_tree_node
*)t
)->tpi
.level
);
6875 RU (((lang_tree_node
*)t
)->tpi
.orig_level
);
6876 RT (((lang_tree_node
*)t
)->tpi
.decl
);
6880 RT (((lang_tree_node
*)t
)->trait_expression
.type1
);
6881 RT (((lang_tree_node
*)t
)->trait_expression
.type2
);
6882 RUC (cp_trait_kind
, ((lang_tree_node
*)t
)->trait_expression
.kind
);
6886 if (CODE_CONTAINS_STRUCT (code
, TS_TYPED
))
6888 tree type
= tree_node ();
6890 if (type
&& code
== ENUMERAL_TYPE
&& !ENUM_FIXED_UNDERLYING_TYPE_P (t
))
6892 unsigned precision
= u ();
6894 type
= build_distinct_type_copy (type
);
6895 TYPE_PRECISION (type
) = precision
;
6896 set_min_and_max_values_for_integral_type (type
, precision
,
6900 if (code
!= TEMPLATE_DECL
)
6901 t
->typed
.type
= type
;
6907 return !get_overrun ();
6911 trees_out::lang_decl_vals (tree t
)
6913 const struct lang_decl
*lang
= DECL_LANG_SPECIFIC (t
);
6914 #define WU(X) (u (X))
6915 #define WT(X) (tree_node (X))
6916 /* Module index already written. */
6917 switch (lang
->u
.base
.selector
)
6922 case lds_fn
: /* lang_decl_fn. */
6925 if (DECL_NAME (t
) && IDENTIFIER_OVL_OP_P (DECL_NAME (t
)))
6926 WU (lang
->u
.fn
.ovl_op_code
);
6929 if (DECL_CLASS_SCOPE_P (t
))
6930 WT (lang
->u
.fn
.context
);
6932 if (lang
->u
.fn
.thunk_p
)
6934 /* The thunked-to function. */
6935 WT (lang
->u
.fn
.befriending_classes
);
6937 wi (lang
->u
.fn
.u5
.fixed_offset
);
6940 WT (lang
->u
.fn
.u5
.cloned_function
);
6942 if (FNDECL_USED_AUTO (t
))
6943 WT (lang
->u
.fn
.u
.saved_auto_return_type
);
6947 case lds_decomp
: /* lang_decl_decomp. */
6948 WT (lang
->u
.decomp
.base
);
6951 case lds_min
: /* lang_decl_min. */
6953 WT (lang
->u
.min
.template_info
);
6955 tree access
= lang
->u
.min
.access
;
6957 /* DECL_ACCESS needs to be maintained by the definition of the
6958 (derived) class that changes the access. The other users
6959 of DECL_ACCESS need to write it here. */
6960 if (!DECL_THUNK_P (t
)
6961 && (DECL_CONTEXT (t
) && TYPE_P (DECL_CONTEXT (t
))))
6968 case lds_ns
: /* lang_decl_ns. */
6971 case lds_parm
: /* lang_decl_parm. */
6974 WU (lang
->u
.parm
.level
);
6975 WU (lang
->u
.parm
.index
);
6984 trees_in::lang_decl_vals (tree t
)
6986 struct lang_decl
*lang
= DECL_LANG_SPECIFIC (t
);
6987 #define RU(X) ((X) = u ())
6988 #define RT(X) ((X) = tree_node ())
6990 /* Module index already read. */
6991 switch (lang
->u
.base
.selector
)
6996 case lds_fn
: /* lang_decl_fn. */
6997 if (DECL_NAME (t
) && IDENTIFIER_OVL_OP_P (DECL_NAME (t
)))
6999 unsigned code
= u ();
7001 /* Check consistency. */
7002 if (code
>= OVL_OP_MAX
7003 || (ovl_op_info
[IDENTIFIER_ASSIGN_OP_P (DECL_NAME (t
))][code
]
7004 .ovl_op_code
) == OVL_OP_ERROR_MARK
)
7007 lang
->u
.fn
.ovl_op_code
= code
;
7010 if (DECL_CLASS_SCOPE_P (t
))
7011 RT (lang
->u
.fn
.context
);
7013 if (lang
->u
.fn
.thunk_p
)
7015 RT (lang
->u
.fn
.befriending_classes
);
7016 lang
->u
.fn
.u5
.fixed_offset
= wi ();
7019 RT (lang
->u
.fn
.u5
.cloned_function
);
7021 if (FNDECL_USED_AUTO (t
))
7022 RT (lang
->u
.fn
.u
.saved_auto_return_type
);
7025 case lds_decomp
: /* lang_decl_decomp. */
7026 RT (lang
->u
.decomp
.base
);
7029 case lds_min
: /* lang_decl_min. */
7031 RT (lang
->u
.min
.template_info
);
7032 RT (lang
->u
.min
.access
);
7035 case lds_ns
: /* lang_decl_ns. */
7038 case lds_parm
: /* lang_decl_parm. */
7039 RU (lang
->u
.parm
.level
);
7040 RU (lang
->u
.parm
.index
);
7045 return !get_overrun ();
7048 /* Most of the value contents of lang_type is streamed in
7052 trees_out::lang_type_vals (tree t
)
7054 const struct lang_type
*lang
= TYPE_LANG_SPECIFIC (t
);
7055 #define WU(X) (u (X))
7056 #define WT(X) (tree_node (X))
7064 trees_in::lang_type_vals (tree t
)
7066 struct lang_type
*lang
= TYPE_LANG_SPECIFIC (t
);
7067 #define RU(X) ((X) = u ())
7068 #define RT(X) ((X) = tree_node ())
7072 return !get_overrun ();
7075 /* Write out the bools of T, including information about any
7076 LANG_SPECIFIC information. Including allocation of any lang
7080 trees_out::tree_node_bools (tree t
)
7082 gcc_checking_assert (streaming_p ());
7084 /* We should never stream a namespace. */
7085 gcc_checking_assert (TREE_CODE (t
) != NAMESPACE_DECL
7086 || DECL_NAMESPACE_ALIAS (t
));
7090 switch (TREE_CODE_CLASS (TREE_CODE (t
)))
7092 case tcc_declaration
:
7094 bool specific
= DECL_LANG_SPECIFIC (t
) != NULL
;
7096 if (specific
&& VAR_P (t
))
7097 b (DECL_DECOMPOSITION_P (t
));
7099 lang_decl_bools (t
);
7105 bool specific
= (TYPE_MAIN_VARIANT (t
) == t
7106 && TYPE_LANG_SPECIFIC (t
) != NULL
);
7107 gcc_assert (TYPE_LANG_SPECIFIC (t
)
7108 == TYPE_LANG_SPECIFIC (TYPE_MAIN_VARIANT (t
)));
7112 lang_type_bools (t
);
7124 trees_in::tree_node_bools (tree t
)
7126 bool ok
= core_bools (t
);
7129 switch (TREE_CODE_CLASS (TREE_CODE (t
)))
7131 case tcc_declaration
:
7134 bool decomp
= VAR_P (t
) && b ();
7136 ok
= maybe_add_lang_decl_raw (t
, decomp
);
7138 ok
= lang_decl_bools (t
);
7145 ok
= maybe_add_lang_type_raw (t
);
7147 ok
= lang_type_bools (t
);
7156 if (!ok
|| get_overrun ())
7163 /* Write out the lang-specifc vals of node T. */
7166 trees_out::lang_vals (tree t
)
7168 switch (TREE_CODE_CLASS (TREE_CODE (t
)))
7170 case tcc_declaration
:
7171 if (DECL_LANG_SPECIFIC (t
))
7176 if (TYPE_MAIN_VARIANT (t
) == t
&& TYPE_LANG_SPECIFIC (t
))
7186 trees_in::lang_vals (tree t
)
7190 switch (TREE_CODE_CLASS (TREE_CODE (t
)))
7192 case tcc_declaration
:
7193 if (DECL_LANG_SPECIFIC (t
))
7194 ok
= lang_decl_vals (t
);
7198 if (TYPE_LANG_SPECIFIC (t
))
7199 ok
= lang_type_vals (t
);
7201 TYPE_LANG_SPECIFIC (t
) = TYPE_LANG_SPECIFIC (TYPE_MAIN_VARIANT (t
));
7211 /* Write out the value fields of node T. */
7214 trees_out::tree_node_vals (tree t
)
7221 trees_in::tree_node_vals (tree t
)
7223 bool ok
= core_vals (t
);
7231 /* If T is a back reference, fixed reference or NULL, write out its
7232 code and return WK_none. Otherwise return WK_value if we must write
7233 by value, or WK_normal otherwise. */
7236 trees_out::ref_node (tree t
)
7242 /* NULL_TREE -> tt_null. */
7249 if (!TREE_VISITED (t
))
7252 /* An already-visited tree. It must be in the map. */
7253 int val
= get_tag (t
);
7255 if (val
== tag_value
)
7256 /* An entry we should walk into. */
7261 if (val
<= tag_backref
)
7263 /* Back reference -> -ve number */
7268 else if (val
>= tag_fixed
)
7270 /* Fixed reference -> tt_fixed */
7273 i (tt_fixed
), u (val
);
7281 && dump ("Wrote %s:%d %C:%N%S", kind
, val
, TREE_CODE (t
), t
, t
);
7287 trees_in::back_ref (int tag
)
7289 tree res
= NULL_TREE
;
7291 if (tag
< 0 && unsigned (~tag
) < back_refs
.length ())
7292 res
= back_refs
[~tag
];
7295 /* Checking TREE_CODE is a dereference, so we know this is not a
7296 wild pointer. Checking the code provides evidence we've not
7297 corrupted something. */
7298 || TREE_CODE (res
) >= MAX_TREE_CODES
)
7301 dump (dumper::TREE
) && dump ("Read backref:%d found %C:%N%S", tag
,
7302 TREE_CODE (res
), res
, res
);
7307 trees_out::add_indirect_tpl_parms (tree parms
)
7310 for (; parms
; parms
= TREE_CHAIN (parms
), len
++)
7312 if (TREE_VISITED (parms
))
7315 int tag
= insert (parms
);
7318 && dump ("Indirect:%d template's parameter %u %C:%N",
7319 tag
, len
, TREE_CODE (parms
), parms
);
7329 trees_in::add_indirect_tpl_parms (tree parms
)
7331 unsigned len
= u ();
7332 for (unsigned ix
= 0; ix
!= len
; parms
= TREE_CHAIN (parms
), ix
++)
7334 int tag
= insert (parms
);
7336 && dump ("Indirect:%d template's parameter %u %C:%N",
7337 tag
, ix
, TREE_CODE (parms
), parms
);
7343 /* We've just found DECL by name. Insert nodes that come with it, but
7344 cannot be found by name, so we'll not accidentally walk into them. */
7347 trees_out::add_indirects (tree decl
)
7351 // FIXME:OPTIMIZATION We'll eventually want default fn parms of
7352 // templates and perhaps default template parms too. The former can
7353 // be referenced from instantiations (as they are lazily
7354 // instantiated). Also (deferred?) exception specifications of
7355 // templates. See the note about PARM_DECLs in trees_out::decl_node.
7357 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
7359 count
+= add_indirect_tpl_parms (DECL_TEMPLATE_PARMS (decl
));
7361 inner
= DECL_TEMPLATE_RESULT (decl
);
7362 int tag
= insert (inner
);
7365 && dump ("Indirect:%d template's result %C:%N",
7366 tag
, TREE_CODE (inner
), inner
);
7370 if (TREE_CODE (inner
) == TYPE_DECL
)
7372 /* Make sure the type is in the map too. Otherwise we get
7373 different RECORD_TYPEs for the same type, and things go
7375 tree type
= TREE_TYPE (inner
);
7376 gcc_checking_assert (DECL_ORIGINAL_TYPE (inner
)
7377 || TYPE_NAME (type
) == inner
);
7378 int tag
= insert (type
);
7380 dump (dumper::TREE
) && dump ("Indirect:%d decl's type %C:%N", tag
,
7381 TREE_CODE (type
), type
);
7388 dump (dumper::TREE
) && dump ("Inserted %u indirects", count
);
7393 trees_in::add_indirects (tree decl
)
7398 if (TREE_CODE (inner
) == TEMPLATE_DECL
)
7400 count
+= add_indirect_tpl_parms (DECL_TEMPLATE_PARMS (decl
));
7402 inner
= DECL_TEMPLATE_RESULT (decl
);
7403 int tag
= insert (inner
);
7405 && dump ("Indirect:%d templates's result %C:%N", tag
,
7406 TREE_CODE (inner
), inner
);
7410 if (TREE_CODE (inner
) == TYPE_DECL
)
7412 tree type
= TREE_TYPE (inner
);
7413 gcc_checking_assert (DECL_ORIGINAL_TYPE (inner
)
7414 || TYPE_NAME (type
) == inner
);
7415 int tag
= insert (type
);
7417 && dump ("Indirect:%d decl's type %C:%N", tag
, TREE_CODE (type
), type
);
7421 dump (dumper::TREE
) && dump ("Inserted %u indirects", count
);
7422 return count
== u ();
7425 /* Stream a template parameter. There are 4.5 kinds of parameter:
7426 a) Template - TEMPLATE_DECL->TYPE_DECL->TEMPLATE_TEMPLATE_PARM
7427 TEMPLATE_TYPE_PARM_INDEX TPI
7428 b) Type - TYPE_DECL->TEMPLATE_TYPE_PARM TEMPLATE_TYPE_PARM_INDEX TPI
7429 c.1) NonTYPE - PARM_DECL DECL_INITIAL TPI We meet this first
7430 c.2) NonTYPE - CONST_DECL DECL_INITIAL Same TPI
7431 d) BoundTemplate - TYPE_DECL->BOUND_TEMPLATE_TEMPLATE_PARM
7432 TEMPLATE_TYPE_PARM_INDEX->TPI
7433 TEMPLATE_TEMPLATE_PARM_INFO->TEMPLATE_INFO
7435 All of these point to a TEMPLATE_PARM_INDEX, and #B also has a TEMPLATE_INFO
7439 trees_out::tpl_parm_value (tree parm
)
7441 gcc_checking_assert (DECL_P (parm
) && DECL_TEMPLATE_PARM_P (parm
));
7443 int parm_tag
= insert (parm
);
7447 dump (dumper::TREE
) && dump ("Writing template parm:%d %C:%N",
7448 parm_tag
, TREE_CODE (parm
), parm
);
7450 tree_node_bools (parm
);
7454 if (TREE_CODE (inner
) == TEMPLATE_DECL
)
7456 inner
= DECL_TEMPLATE_RESULT (inner
);
7457 int inner_tag
= insert (inner
);
7460 dump (dumper::TREE
) && dump ("Writing inner template parm:%d %C:%N",
7461 inner_tag
, TREE_CODE (inner
), inner
);
7463 tree_node_bools (inner
);
7467 tree type
= NULL_TREE
;
7468 if (TREE_CODE (inner
) == TYPE_DECL
)
7470 type
= TREE_TYPE (inner
);
7471 int type_tag
= insert (type
);
7474 dump (dumper::TREE
) && dump ("Writing template parm type:%d %C:%N",
7475 type_tag
, TREE_CODE (type
), type
);
7477 tree_node_bools (type
);
7483 /* This is a template-template parameter. */
7484 unsigned tpl_levels
= 0;
7485 tpl_header (parm
, &tpl_levels
);
7486 tpl_parms_fini (parm
, tpl_levels
);
7489 tree_node_vals (parm
);
7491 tree_node_vals (inner
);
7494 tree_node_vals (type
);
7495 if (DECL_NAME (inner
) == auto_identifier
7496 || DECL_NAME (inner
) == decltype_auto_identifier
)
7498 /* Placeholder auto. */
7499 tree_node (DECL_INITIAL (inner
));
7500 tree_node (DECL_SIZE_UNIT (inner
));
7505 dump (dumper::TREE
) && dump ("Wrote template parm:%d %C:%N",
7506 parm_tag
, TREE_CODE (parm
), parm
);
7510 trees_in::tpl_parm_value ()
7512 tree parm
= start ();
7513 if (!parm
|| !tree_node_bools (parm
))
7516 int parm_tag
= insert (parm
);
7517 dump (dumper::TREE
) && dump ("Reading template parm:%d %C:%N",
7518 parm_tag
, TREE_CODE (parm
), parm
);
7521 if (TREE_CODE (inner
) == TEMPLATE_DECL
)
7524 if (!inner
|| !tree_node_bools (inner
))
7526 int inner_tag
= insert (inner
);
7527 dump (dumper::TREE
) && dump ("Reading inner template parm:%d %C:%N",
7528 inner_tag
, TREE_CODE (inner
), inner
);
7529 DECL_TEMPLATE_RESULT (parm
) = inner
;
7532 tree type
= NULL_TREE
;
7533 if (TREE_CODE (inner
) == TYPE_DECL
)
7536 if (!type
|| !tree_node_bools (type
))
7538 int type_tag
= insert (type
);
7539 dump (dumper::TREE
) && dump ("Reading template parm type:%d %C:%N",
7540 type_tag
, TREE_CODE (type
), type
);
7542 TREE_TYPE (inner
) = TREE_TYPE (parm
) = type
;
7543 TYPE_NAME (type
) = parm
;
7548 /* A template template parameter. */
7549 unsigned tpl_levels
= 0;
7550 tpl_header (parm
, &tpl_levels
);
7551 tpl_parms_fini (parm
, tpl_levels
);
7554 tree_node_vals (parm
);
7556 tree_node_vals (inner
);
7559 tree_node_vals (type
);
7560 if (DECL_NAME (inner
) == auto_identifier
7561 || DECL_NAME (inner
) == decltype_auto_identifier
)
7563 /* Placeholder auto. */
7564 DECL_INITIAL (inner
) = tree_node ();
7565 DECL_SIZE_UNIT (inner
) = tree_node ();
7567 if (TYPE_CANONICAL (type
))
7569 gcc_checking_assert (TYPE_CANONICAL (type
) == type
);
7570 TYPE_CANONICAL (type
) = canonical_type_parameter (type
);
7574 dump (dumper::TREE
) && dump ("Read template parm:%d %C:%N",
7575 parm_tag
, TREE_CODE (parm
), parm
);
7581 trees_out::install_entity (tree decl
, depset
*dep
)
7583 gcc_checking_assert (streaming_p ());
7585 /* Write the entity index, so we can insert it as soon as we
7586 know this is new. */
7587 u (dep
? dep
->cluster
+ 1 : 0);
7588 if (CHECKING_P
&& dep
)
7590 /* Add it to the entity map, such that we can tell it is
7593 unsigned *slot
= &entity_map
->get_or_insert
7594 (DECL_UID (decl
), &existed
);
7596 /* If it existed, it should match. */
7597 gcc_checking_assert (decl
== (*entity_ary
)[*slot
]);
7598 *slot
= ~dep
->cluster
;
7603 trees_in::install_entity (tree decl
)
7605 unsigned entity_index
= u ();
7609 if (entity_index
> state
->entity_num
)
7615 /* Insert the real decl into the entity ary. */
7616 unsigned ident
= state
->entity_lwm
+ entity_index
- 1;
7617 (*entity_ary
)[ident
] = decl
;
7619 /* And into the entity map, if it's not already there. */
7620 tree not_tmpl
= STRIP_TEMPLATE (decl
);
7621 if (!DECL_LANG_SPECIFIC (not_tmpl
)
7622 || !DECL_MODULE_ENTITY_P (not_tmpl
))
7624 retrofit_lang_decl (not_tmpl
);
7625 DECL_MODULE_ENTITY_P (not_tmpl
) = true;
7627 /* Insert into the entity hash (it cannot already be there). */
7629 unsigned &slot
= entity_map
->get_or_insert (DECL_UID (decl
), &existed
);
7630 gcc_checking_assert (!existed
);
7637 static bool has_definition (tree decl
);
7639 /* DECL is a decl node that must be written by value. DEP is the
7643 trees_out::decl_value (tree decl
, depset
*dep
)
7645 /* We should not be writing clones or template parms. */
7646 gcc_checking_assert (DECL_P (decl
)
7647 && !DECL_CLONED_FUNCTION_P (decl
)
7648 && !DECL_TEMPLATE_PARM_P (decl
));
7650 /* We should never be writing non-typedef ptrmemfuncs by value. */
7651 gcc_checking_assert (TREE_CODE (decl
) != TYPE_DECL
7652 || DECL_ORIGINAL_TYPE (decl
)
7653 || !TYPE_PTRMEMFUNC_P (TREE_TYPE (decl
)));
7655 merge_kind mk
= get_merge_kind (decl
, dep
);
7659 /* Never start in the middle of a template. */
7661 if (tree ti
= node_template_info (decl
, use_tpl
))
7662 gcc_checking_assert (TREE_CODE (TI_TEMPLATE (ti
)) == OVERLOAD
7663 || TREE_CODE (TI_TEMPLATE (ti
)) == FIELD_DECL
7664 || (DECL_TEMPLATE_RESULT (TI_TEMPLATE (ti
))
7670 /* A new node -> tt_decl. */
7676 if (mk
!= MK_unique
)
7678 if (!(mk
& MK_template_mask
) && !state
->is_header ())
7680 /* Tell the importer whether this is a global module entity,
7681 or a module entity. This bool merges into the next block
7682 of bools. Sneaky. */
7683 tree o
= get_originating_module_decl (decl
);
7684 bool is_attached
= false;
7686 tree not_tmpl
= STRIP_TEMPLATE (o
);
7687 if (DECL_LANG_SPECIFIC (not_tmpl
)
7688 && DECL_MODULE_ATTACH_P (not_tmpl
))
7693 b (dep
&& dep
->has_defn ());
7695 tree_node_bools (decl
);
7698 int tag
= insert (decl
, WK_value
);
7701 && dump ("Writing %s:%d %C:%N%S", merge_kind_name
[mk
], tag
,
7702 TREE_CODE (decl
), decl
, decl
);
7706 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
7708 inner
= DECL_TEMPLATE_RESULT (decl
);
7709 inner_tag
= insert (inner
, WK_value
);
7713 int code
= TREE_CODE (inner
);
7715 start (inner
, true);
7716 tree_node_bools (inner
);
7718 && dump ("Writing %s:%d %C:%N%S", merge_kind_name
[mk
], inner_tag
,
7719 TREE_CODE (inner
), inner
, inner
);
7723 tree type
= NULL_TREE
;
7725 tree stub_decl
= NULL_TREE
;
7727 if (TREE_CODE (inner
) == TYPE_DECL
)
7729 type
= TREE_TYPE (inner
);
7730 bool has_type
= (type
== TYPE_MAIN_VARIANT (type
)
7731 && TYPE_NAME (type
) == inner
);
7734 u (has_type
? TREE_CODE (type
) : 0);
7738 type_tag
= insert (type
, WK_value
);
7742 tree_node_bools (type
);
7744 && dump ("Writing type:%d %C:%N", type_tag
,
7745 TREE_CODE (type
), type
);
7748 stub_decl
= TYPE_STUB_DECL (type
);
7749 bool has_stub
= inner
!= stub_decl
;
7751 u (has_stub
? TREE_CODE (stub_decl
) : 0);
7754 stub_tag
= insert (stub_decl
);
7757 start (stub_decl
, true);
7758 tree_node_bools (stub_decl
);
7760 && dump ("Writing stub_decl:%d %C:%N", stub_tag
,
7761 TREE_CODE (stub_decl
), stub_decl
);
7765 stub_decl
= NULL_TREE
;
7768 /* Regular typedef. */
7772 /* Stream the container, we want it correctly canonicalized before
7773 we start emitting keys for this decl. */
7774 tree container
= decl_container (decl
);
7776 unsigned tpl_levels
= 0;
7778 tpl_header (decl
, &tpl_levels
);
7779 if (TREE_CODE (inner
) == FUNCTION_DECL
)
7780 fn_parms_init (inner
);
7782 /* Now write out the merging information, and then really
7783 install the tag values. */
7784 key_mergeable (tag
, mk
, decl
, inner
, container
, dep
);
7787 dump (dumper::MERGE
)
7788 && dump ("Wrote:%d's %s merge key %C:%N", tag
,
7789 merge_kind_name
[mk
], TREE_CODE (decl
), decl
);
7791 if (TREE_CODE (inner
) == FUNCTION_DECL
)
7792 fn_parms_fini (inner
);
7794 if (!is_key_order ())
7795 tree_node_vals (decl
);
7799 if (!is_key_order ())
7800 tree_node_vals (inner
);
7801 tpl_parms_fini (decl
, tpl_levels
);
7804 if (type
&& !is_key_order ())
7806 tree_node_vals (type
);
7808 tree_node_vals (stub_decl
);
7811 if (!is_key_order ())
7813 if (mk
& MK_template_mask
7815 || mk
== MK_friend_spec
)
7817 if (mk
!= MK_partial
)
7819 // FIXME: We should make use of the merge-key by
7820 // exposing it outside of key_mergeable. But this gets
7822 auto *entry
= reinterpret_cast <spec_entry
*> (dep
->deps
[0]);
7825 u (get_mergeable_specialization_flags (entry
->tmpl
, decl
));
7826 tree_node (entry
->tmpl
);
7827 tree_node (entry
->args
);
7831 tree ti
= get_template_info (inner
);
7832 tree_node (TI_TEMPLATE (ti
));
7833 tree_node (TI_ARGS (ti
));
7836 tree_node (get_constraints (decl
));
7841 /* Do not stray outside this section. */
7842 gcc_checking_assert (!dep
|| dep
->section
== dep_hash
->section
);
7844 /* Write the entity index, so we can insert it as soon as we
7845 know this is new. */
7846 install_entity (decl
, dep
);
7849 if (VAR_OR_FUNCTION_DECL_P (inner
)
7850 && DECL_LANG_SPECIFIC (inner
)
7851 && DECL_MODULE_KEYED_DECLS_P (inner
)
7852 && !is_key_order ())
7854 /* Stream the keyed entities. */
7855 auto *attach_vec
= keyed_table
->get (inner
);
7856 unsigned num
= attach_vec
->length ();
7859 for (unsigned ix
= 0; ix
!= num
; ix
++)
7861 tree attached
= (*attach_vec
)[ix
];
7862 tree_node (attached
);
7864 dump (dumper::MERGE
)
7865 && dump ("Written %d[%u] attached decl %N", tag
, ix
, attached
);
7869 bool is_typedef
= false;
7870 if (!type
&& TREE_CODE (inner
) == TYPE_DECL
)
7872 tree t
= TREE_TYPE (inner
);
7873 unsigned tdef_flags
= 0;
7874 if (DECL_ORIGINAL_TYPE (inner
)
7875 && TYPE_NAME (TREE_TYPE (inner
)) == inner
)
7878 if (TYPE_STRUCTURAL_EQUALITY_P (t
)
7879 && TYPE_DEPENDENT_P_VALID (t
)
7880 && TYPE_DEPENDENT_P (t
))
7888 /* A typedef type. */
7889 int type_tag
= insert (t
);
7892 && dump ("Cloned:%d %s %C:%N", type_tag
,
7893 tdef_flags
& 2 ? "depalias" : "typedef",
7900 if (streaming_p () && DECL_MAYBE_IN_CHARGE_CDTOR_P (decl
))
7903 = (DECL_CHAIN (decl
) && DECL_CLONED_FUNCTION_P (DECL_CHAIN (decl
)));
7904 bool needs_vtt_parm_p
7905 = (cloned_p
&& CLASSTYPE_VBASECLASSES (DECL_CONTEXT (decl
)));
7906 bool omit_inherited_parms_p
7907 = (cloned_p
&& DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl
)
7908 && base_ctor_omit_inherited_parms (decl
));
7909 unsigned flags
= (int (cloned_p
) << 0
7910 | int (needs_vtt_parm_p
) << 1
7911 | int (omit_inherited_parms_p
) << 2);
7913 dump (dumper::TREE
) && dump ("CDTOR %N is %scloned",
7914 decl
, cloned_p
? "" : "not ");
7918 dump (dumper::TREE
) && dump ("Written decl:%d %C:%N", tag
,
7919 TREE_CODE (decl
), decl
);
7921 if (NAMESPACE_SCOPE_P (inner
))
7922 gcc_checking_assert (!dep
== (VAR_OR_FUNCTION_DECL_P (inner
)
7923 && DECL_LOCAL_DECL_P (inner
)));
7924 else if ((TREE_CODE (inner
) == TYPE_DECL
7926 && TYPE_NAME (TREE_TYPE (inner
)) == inner
)
7927 || TREE_CODE (inner
) == FUNCTION_DECL
)
7929 bool write_defn
= !dep
&& has_definition (decl
);
7933 write_definition (decl
);
7938 trees_in::decl_value ()
7941 bool is_attached
= false;
7942 bool has_defn
= false;
7943 unsigned mk_u
= u ();
7944 if (mk_u
>= MK_hwm
|| !merge_kind_name
[mk_u
])
7950 unsigned saved_unused
= unused
;
7953 merge_kind mk
= merge_kind (mk_u
);
7955 tree decl
= start ();
7958 if (mk
!= MK_unique
)
7960 if (!(mk
& MK_template_mask
) && !state
->is_header ())
7961 /* See note in trees_out about where this bool is sequenced. */
7967 if (!tree_node_bools (decl
))
7971 /* Insert into map. */
7972 tag
= insert (decl
);
7975 && dump ("Reading:%d %C", tag
, TREE_CODE (decl
));
7979 if (decl
&& TREE_CODE (decl
) == TEMPLATE_DECL
)
7982 inner
= start (code
);
7983 if (inner
&& tree_node_bools (inner
))
7984 DECL_TEMPLATE_RESULT (decl
) = inner
;
7988 inner_tag
= insert (inner
);
7991 && dump ("Reading:%d %C", inner_tag
, TREE_CODE (inner
));
7994 tree type
= NULL_TREE
;
7996 tree stub_decl
= NULL_TREE
;
7998 if (decl
&& TREE_CODE (inner
) == TYPE_DECL
)
8000 if (unsigned type_code
= u ())
8002 type
= start (type_code
);
8003 if (type
&& tree_node_bools (type
))
8005 TREE_TYPE (inner
) = type
;
8006 TYPE_NAME (type
) = inner
;
8011 type_tag
= insert (type
);
8014 && dump ("Reading type:%d %C", type_tag
, TREE_CODE (type
));
8016 if (unsigned stub_code
= u ())
8018 stub_decl
= start (stub_code
);
8019 if (stub_decl
&& tree_node_bools (stub_decl
))
8021 TREE_TYPE (stub_decl
) = type
;
8022 TYPE_STUB_DECL (type
) = stub_decl
;
8027 stub_tag
= insert (stub_decl
);
8030 && dump ("Reading stub_decl:%d %C", stub_tag
,
8031 TREE_CODE (stub_decl
));
8040 back_refs
[~inner_tag
] = NULL_TREE
;
8042 back_refs
[~type_tag
] = NULL_TREE
;
8044 back_refs
[~stub_tag
] = NULL_TREE
;
8046 back_refs
[~tag
] = NULL_TREE
;
8049 unused
= saved_unused
;
8053 /* Read the container, to ensure it's already been streamed in. */
8054 tree container
= decl_container ();
8055 unsigned tpl_levels
= 0;
8057 /* Figure out if this decl is already known about. */
8061 if (!tpl_header (decl
, &tpl_levels
))
8063 if (TREE_CODE (inner
) == FUNCTION_DECL
)
8064 parm_tag
= fn_parms_init (inner
);
8066 tree existing
= key_mergeable (tag
, mk
, decl
, inner
, type
, container
,
8068 tree existing_inner
= existing
;
8071 if (existing
== error_mark_node
)
8074 if (TREE_CODE (STRIP_TEMPLATE (existing
)) == TYPE_DECL
)
8076 tree etype
= TREE_TYPE (existing
);
8077 if (TYPE_LANG_SPECIFIC (etype
)
8078 && COMPLETE_TYPE_P (etype
)
8079 && !CLASSTYPE_MEMBER_VEC (etype
))
8080 /* Give it a member vec, we're likely gonna be looking
8082 set_class_bindings (etype
, -1);
8085 /* Install the existing decl into the back ref array. */
8086 register_duplicate (decl
, existing
);
8087 back_refs
[~tag
] = existing
;
8090 existing_inner
= DECL_TEMPLATE_RESULT (existing
);
8091 back_refs
[~inner_tag
] = existing_inner
;
8096 tree existing_type
= TREE_TYPE (existing
);
8097 back_refs
[~type_tag
] = existing_type
;
8099 back_refs
[~stub_tag
] = TYPE_STUB_DECL (existing_type
);
8104 fn_parms_fini (parm_tag
, inner
, existing_inner
, has_defn
);
8106 if (!tree_node_vals (decl
))
8111 gcc_checking_assert (DECL_TEMPLATE_RESULT (decl
) == inner
);
8113 if (!tree_node_vals (inner
))
8116 if (!tpl_parms_fini (decl
, tpl_levels
))
8120 if (type
&& (!tree_node_vals (type
)
8121 || (stub_decl
&& !tree_node_vals (stub_decl
))))
8125 unsigned spec_flags
= 0;
8126 if (mk
& MK_template_mask
8128 || mk
== MK_friend_spec
)
8130 if (mk
== MK_partial
)
8135 spec
.tmpl
= tree_node ();
8136 spec
.args
= tree_node ();
8138 /* Hold constraints on the spec field, for a short while. */
8139 spec
.spec
= tree_node ();
8141 dump (dumper::TREE
) && dump ("Read:%d %C:%N", tag
, TREE_CODE (decl
), decl
);
8143 existing
= back_refs
[~tag
];
8144 bool installed
= install_entity (existing
);
8145 bool is_new
= existing
== decl
;
8147 if (VAR_OR_FUNCTION_DECL_P (inner
)
8148 && DECL_LANG_SPECIFIC (inner
)
8149 && DECL_MODULE_KEYED_DECLS_P (inner
))
8151 /* Read and maybe install the attached entities. */
8153 auto &set
= keyed_table
->get_or_insert (STRIP_TEMPLATE (existing
),
8155 unsigned num
= u ();
8156 if (is_new
== existed
)
8160 for (unsigned ix
= 0; !get_overrun () && ix
!= num
; ix
++)
8162 tree attached
= tree_node ();
8163 dump (dumper::MERGE
)
8164 && dump ("Read %d[%u] %s attached decl %N", tag
, ix
,
8165 is_new
? "new" : "matched", attached
);
8167 set
.quick_push (attached
);
8168 else if (set
[ix
] != attached
)
8173 /* Regular typedefs will have a NULL TREE_TYPE at this point. */
8174 unsigned tdef_flags
= 0;
8175 bool is_typedef
= false;
8176 if (!type
&& TREE_CODE (inner
) == TYPE_DECL
)
8185 /* A newly discovered node. */
8186 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (decl
))
8187 /* Mark this identifier as naming a virtual function --
8188 lookup_overrides relies on this optimization. */
8189 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl
)) = true;
8193 /* Mark the entity as imported. */
8194 retrofit_lang_decl (inner
);
8195 DECL_MODULE_IMPORT_P (inner
) = true;
8199 set_constraints (decl
, spec
.spec
);
8201 if (TREE_CODE (decl
) == INTEGER_CST
&& !TREE_OVERFLOW (decl
))
8203 decl
= cache_integer_cst (decl
, true);
8204 back_refs
[~tag
] = decl
;
8209 /* Frob it to be ready for cloning. */
8210 TREE_TYPE (inner
) = DECL_ORIGINAL_TYPE (inner
);
8211 DECL_ORIGINAL_TYPE (inner
) = NULL_TREE
;
8212 set_underlying_type (inner
);
8215 /* Match instantiate_alias_template's handling. */
8216 tree type
= TREE_TYPE (inner
);
8217 TYPE_DEPENDENT_P (type
) = true;
8218 TYPE_DEPENDENT_P_VALID (type
) = true;
8219 SET_TYPE_STRUCTURAL_EQUALITY (type
);
8224 /* Set the TEMPLATE_DECL's type. */
8225 TREE_TYPE (decl
) = TREE_TYPE (inner
);
8227 /* Add to specialization tables now that constraints etc are
8229 if (mk
== MK_partial
)
8231 bool is_type
= TREE_CODE (inner
) == TYPE_DECL
;
8232 spec
.spec
= is_type
? type
: inner
;
8233 add_mergeable_specialization (!is_type
, false,
8234 &spec
, decl
, spec_flags
);
8236 else if (mk
& MK_template_mask
)
8238 bool is_type
= !(mk
& MK_tmpl_decl_mask
);
8239 spec
.spec
= is_type
? type
: mk
& MK_tmpl_tmpl_mask
? inner
: decl
;
8240 add_mergeable_specialization (!is_type
,
8241 !is_type
&& mk
& MK_tmpl_alias_mask
,
8242 &spec
, decl
, spec_flags
);
8245 if (NAMESPACE_SCOPE_P (decl
)
8246 && (mk
== MK_named
|| mk
== MK_unique
8247 || mk
== MK_enum
|| mk
== MK_friend_spec
)
8248 && !(VAR_OR_FUNCTION_DECL_P (decl
) && DECL_LOCAL_DECL_P (decl
)))
8249 add_module_namespace_decl (CP_DECL_CONTEXT (decl
), decl
);
8251 if (DECL_ARTIFICIAL (decl
)
8252 && TREE_CODE (decl
) == FUNCTION_DECL
8253 && !DECL_TEMPLATE_INFO (decl
)
8254 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
8255 && TYPE_SIZE (DECL_CONTEXT (decl
))
8256 && !DECL_THUNK_P (decl
))
8257 /* A new implicit member function, when the class is
8258 complete. This means the importee declared it, and
8259 we must now add it to the class. Note that implicit
8260 member fns of template instantiations do not themselves
8261 look like templates. */
8262 if (!install_implicit_member (inner
))
8267 /* DECL is the to-be-discarded decl. Its internal pointers will
8268 be to the EXISTING's structure. Frob it to point to its
8269 own other structures, so loading its definition will alter
8270 it, and not the existing decl. */
8271 dump (dumper::MERGE
) && dump ("Deduping %N", existing
);
8274 DECL_TEMPLATE_RESULT (decl
) = inner
;
8278 /* Point at the to-be-discarded type & decl. */
8279 TYPE_NAME (type
) = inner
;
8280 TREE_TYPE (inner
) = type
;
8282 TYPE_STUB_DECL (type
) = stub_decl
? stub_decl
: inner
;
8284 TREE_TYPE (stub_decl
) = type
;
8288 /* Set the TEMPLATE_DECL's type. */
8289 TREE_TYPE (decl
) = TREE_TYPE (inner
);
8291 if (!is_matching_decl (existing
, decl
, is_typedef
))
8292 unmatched_duplicate (existing
);
8294 if (TREE_CODE (inner
) == FUNCTION_DECL
)
8296 tree e_inner
= STRIP_TEMPLATE (existing
);
8297 for (auto parm
= DECL_ARGUMENTS (inner
);
8298 parm
; parm
= DECL_CHAIN (parm
))
8299 DECL_CONTEXT (parm
) = e_inner
;
8302 /* And our result is the existing node. */
8306 if (mk
== MK_friend_spec
)
8308 tree e
= match_mergeable_specialization (true, &spec
);
8312 add_mergeable_specialization (true, false, &spec
, decl
, spec_flags
);
8314 else if (e
!= existing
)
8320 /* Insert the type into the array now. */
8321 tag
= insert (TREE_TYPE (decl
));
8323 && dump ("Cloned:%d typedef %C:%N",
8324 tag
, TREE_CODE (TREE_TYPE (decl
)), TREE_TYPE (decl
));
8327 unused
= saved_unused
;
8329 if (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl
))
8331 unsigned flags
= u ();
8335 bool cloned_p
= flags
& 1;
8336 dump (dumper::TREE
) && dump ("CDTOR %N is %scloned",
8337 decl
, cloned_p
? "" : "not ");
8339 build_cdtor_clones (decl
, flags
& 2, flags
& 4,
8340 /* Update the member vec, if there is
8341 one (we're in a different cluster
8342 to the class defn). */
8343 CLASSTYPE_MEMBER_VEC (DECL_CONTEXT (decl
)));
8347 if (!NAMESPACE_SCOPE_P (inner
)
8348 && ((TREE_CODE (inner
) == TYPE_DECL
8350 && TYPE_NAME (TREE_TYPE (inner
)) == inner
)
8351 || TREE_CODE (inner
) == FUNCTION_DECL
)
8353 read_definition (decl
);
8358 /* DECL is an unnameable member of CTX. Return a suitable identifying
8362 get_field_ident (tree ctx
, tree decl
)
8364 gcc_checking_assert (TREE_CODE (decl
) == USING_DECL
8365 || !DECL_NAME (decl
)
8366 || IDENTIFIER_ANON_P (DECL_NAME (decl
)));
8369 for (tree fields
= TYPE_FIELDS (ctx
);
8370 fields
; fields
= DECL_CHAIN (fields
))
8375 if (DECL_CONTEXT (fields
) == ctx
8376 && (TREE_CODE (fields
) == USING_DECL
8377 || (TREE_CODE (fields
) == FIELD_DECL
8378 && (!DECL_NAME (fields
)
8379 || IDENTIFIER_ANON_P (DECL_NAME (fields
))))))
8380 /* Count this field. */
8387 lookup_field_ident (tree ctx
, unsigned ix
)
8389 for (tree fields
= TYPE_FIELDS (ctx
);
8390 fields
; fields
= DECL_CHAIN (fields
))
8391 if (DECL_CONTEXT (fields
) == ctx
8392 && (TREE_CODE (fields
) == USING_DECL
8393 || (TREE_CODE (fields
) == FIELD_DECL
8394 && (!DECL_NAME (fields
)
8395 || IDENTIFIER_ANON_P (DECL_NAME (fields
))))))
8402 /* Reference DECL. REF indicates the walk kind we are performing.
8403 Return true if we should write this decl by value. */
8406 trees_out::decl_node (tree decl
, walk_kind ref
)
8408 gcc_checking_assert (DECL_P (decl
) && !DECL_TEMPLATE_PARM_P (decl
)
8409 && DECL_CONTEXT (decl
));
8411 if (ref
== WK_value
)
8413 depset
*dep
= dep_hash
->find_dependency (decl
);
8414 decl_value (decl
, dep
);
8418 switch (TREE_CODE (decl
))
8424 gcc_checking_assert (!DECL_LOCAL_DECL_P (decl
));
8428 /* Unlike PARM_DECLs, RESULT_DECLs are only generated and
8429 referenced when we're inside the function itself. */
8436 tree_node (DECL_CONTEXT (decl
));
8439 /* That must have put this in the map. */
8440 walk_kind ref
= ref_node (decl
);
8442 // FIXME:OPTIMIZATION We can wander into bits of the
8443 // template this was instantiated from. For instance
8444 // deferred noexcept and default parms. Currently we'll
8445 // end up cloning those bits of tree. It would be nice
8446 // to reference those specific nodes. I think putting
8447 // those things in the map when we reference their
8448 // template by name. See the note in add_indirects.
8452 && dump ("Wrote %s reference %N",
8453 TREE_CODE (decl
) == PARM_DECL
? "parameter" : "result",
8460 /* This describes a USING_DECL to the ME's debug machinery. It
8461 originates from the fortran FE, and has nothing to do with
8470 /* If I end up cloning enum decls, implementing C++20 using
8471 E::v, this will need tweaking. */
8474 tree ctx
= DECL_CONTEXT (decl
);
8475 gcc_checking_assert (TREE_CODE (ctx
) == ENUMERAL_TYPE
);
8477 tree_node (DECL_NAME (decl
));
8479 int tag
= insert (decl
);
8482 && dump ("Wrote enum decl:%d %C:%N", tag
, TREE_CODE (decl
), decl
);
8488 if (TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
8497 tree ctx
= DECL_CONTEXT (decl
);
8500 tree name
= NULL_TREE
;
8502 if (TREE_CODE (decl
) == USING_DECL
)
8506 name
= DECL_NAME (decl
);
8507 if (name
&& IDENTIFIER_ANON_P (name
))
8512 if (!name
&& streaming_p ())
8514 unsigned ix
= get_field_ident (ctx
, decl
);
8518 int tag
= insert (decl
);
8521 && dump ("Wrote member:%d %C:%N", tag
, TREE_CODE (decl
), decl
);
8527 gcc_checking_assert (!DECL_LOCAL_DECL_P (decl
));
8528 if (DECL_VTABLE_OR_VTT_P (decl
))
8530 /* VTT or VTABLE, they are all on the vtables list. */
8531 tree ctx
= CP_DECL_CONTEXT (decl
);
8532 tree vtable
= CLASSTYPE_VTABLES (ctx
);
8533 for (unsigned ix
= 0; ; vtable
= DECL_CHAIN (vtable
), ix
++)
8536 gcc_checking_assert (DECL_VIRTUAL_P (decl
));
8542 && dump ("Writing vtable %N[%u]", ctx
, ix
);
8550 if (DECL_TINFO_P (decl
))
8553 /* A typeinfo, tt_tinfo_typedef or tt_tinfo_var. */
8554 bool is_var
= TREE_CODE (decl
) == VAR_DECL
;
8555 tree type
= TREE_TYPE (decl
);
8556 unsigned ix
= get_pseudo_tinfo_index (type
);
8559 i (is_var
? tt_tinfo_var
: tt_tinfo_typedef
);
8565 /* We also need the type it is for and mangled name, so
8566 the reader doesn't need to complete the type (which
8567 would break section ordering). The type it is for is
8568 stashed on the name's TREE_TYPE. */
8569 tree name
= DECL_NAME (decl
);
8571 type
= TREE_TYPE (name
);
8575 int tag
= insert (decl
);
8578 && dump ("Wrote tinfo_%s:%d %u %N", is_var
? "var" : "type",
8583 tag
= insert (type
);
8586 && dump ("Wrote tinfo_type:%d %u %N", tag
, ix
, type
);
8591 if (DECL_NTTP_OBJECT_P (decl
))
8593 /* A NTTP parm object. */
8596 tree_node (tparm_object_argument (decl
));
8597 tree_node (DECL_NAME (decl
));
8598 int tag
= insert (decl
);
8601 && dump ("Wrote nttp object:%d %N", tag
, DECL_NAME (decl
));
8608 if (DECL_TINFO_P (decl
))
8613 if (DECL_THUNK_P (decl
))
8615 /* Thunks are similar to binfos -- write the thunked-to decl and
8616 then thunk-specific key info. */
8620 i (THUNK_FIXED_OFFSET (decl
));
8624 while (DECL_THUNK_P (target
))
8625 target
= THUNK_TARGET (target
);
8627 tree_node (THUNK_VIRTUAL_OFFSET (decl
));
8628 int tag
= insert (decl
);
8631 && dump ("Wrote:%d thunk %N to %N", tag
, DECL_NAME (decl
), target
);
8635 if (DECL_CLONED_FUNCTION_P (decl
))
8637 tree target
= get_clone_target (decl
);
8642 tree_node (DECL_NAME (decl
));
8643 int tag
= insert (decl
);
8646 && dump ("Wrote:%d clone %N of %N", tag
, DECL_NAME (decl
), target
);
8650 /* Everything left should be a thing that is in the entity table.
8651 Mostly things that can be defined outside of their (original
8652 declaration) context. */
8653 gcc_checking_assert (TREE_CODE (decl
) == TEMPLATE_DECL
8654 || TREE_CODE (decl
) == VAR_DECL
8655 || TREE_CODE (decl
) == FUNCTION_DECL
8656 || TREE_CODE (decl
) == TYPE_DECL
8657 || TREE_CODE (decl
) == USING_DECL
8658 || TREE_CODE (decl
) == CONCEPT_DECL
8659 || TREE_CODE (decl
) == NAMESPACE_DECL
);
8662 tree ti
= node_template_info (decl
, use_tpl
);
8663 tree tpl
= NULL_TREE
;
8665 /* If this is the TEMPLATE_DECL_RESULT of a TEMPLATE_DECL, get the
8666 TEMPLATE_DECL. Note TI_TEMPLATE is not a TEMPLATE_DECL for
8667 (some) friends, so we need to check that. */
8668 // FIXME: Should local friend template specializations be by value?
8669 // They don't get idents so we'll never know they're imported, but I
8670 // think we can only reach them from the TU that defines the
8671 // befriending class?
8672 if (ti
&& TREE_CODE (TI_TEMPLATE (ti
)) == TEMPLATE_DECL
8673 && DECL_TEMPLATE_RESULT (TI_TEMPLATE (ti
)) == decl
)
8675 tpl
= TI_TEMPLATE (ti
);
8681 && dump ("Writing implicit template %C:%N%S",
8682 TREE_CODE (tpl
), tpl
, tpl
);
8686 /* Streaming TPL caused us to visit DECL and maybe its type. */
8687 gcc_checking_assert (TREE_VISITED (decl
));
8688 if (DECL_IMPLICIT_TYPEDEF_P (decl
))
8689 gcc_checking_assert (TREE_VISITED (TREE_TYPE (decl
)));
8693 tree ctx
= CP_DECL_CONTEXT (decl
);
8696 dep
= dep_hash
->find_dependency (decl
);
8697 else if (TREE_CODE (ctx
) != FUNCTION_DECL
8698 || TREE_CODE (decl
) == TEMPLATE_DECL
8699 || (dep_hash
->sneakoscope
&& DECL_IMPLICIT_TYPEDEF_P (decl
))
8700 || (DECL_LANG_SPECIFIC (decl
)
8701 && DECL_MODULE_IMPORT_P (decl
)))
8703 auto kind
= (TREE_CODE (decl
) == NAMESPACE_DECL
8704 && !DECL_NAMESPACE_ALIAS (decl
)
8705 ? depset::EK_NAMESPACE
: depset::EK_DECL
);
8706 dep
= dep_hash
->add_dependency (decl
, kind
);
8711 /* Some internal entity of context. Do by value. */
8712 decl_value (decl
, NULL
);
8716 if (dep
->get_entity_kind () == depset::EK_REDIRECT
)
8718 /* The DECL_TEMPLATE_RESULT of a partial specialization.
8719 Write the partial specialization's template. */
8720 depset
*redirect
= dep
->deps
[0];
8721 gcc_checking_assert (redirect
->get_entity_kind () == depset::EK_PARTIAL
);
8722 tpl
= redirect
->get_entity ();
8723 goto partial_template
;
8728 /* Locate the entity. */
8729 unsigned index
= dep
->cluster
;
8730 unsigned import
= 0;
8732 if (dep
->is_import ())
8733 import
= dep
->section
;
8734 else if (CHECKING_P
)
8735 /* It should be what we put there. */
8736 gcc_checking_assert (index
== ~import_entity_index (decl
));
8739 gcc_assert (!import
|| importedness
>= 0);
8746 int tag
= insert (decl
);
8747 if (streaming_p () && dump (dumper::TREE
))
8749 char const *kind
= "import";
8750 module_state
*from
= (*modules
)[0];
8751 if (dep
->is_import ())
8752 /* Rediscover the unremapped index. */
8753 from
= import_entity_module (import_entity_index (decl
));
8756 tree o
= get_originating_module_decl (decl
);
8757 o
= STRIP_TEMPLATE (o
);
8758 kind
= (DECL_LANG_SPECIFIC (o
) && DECL_MODULE_PURVIEW_P (o
)
8759 ? "purview" : "GMF");
8761 dump ("Wrote %s:%d %C:%N@%M", kind
,
8762 tag
, TREE_CODE (decl
), decl
, from
);
8765 add_indirects (decl
);
8771 trees_out::type_node (tree type
)
8773 gcc_assert (TYPE_P (type
));
8775 tree root
= (TYPE_NAME (type
)
8776 ? TREE_TYPE (TYPE_NAME (type
)) : TYPE_MAIN_VARIANT (type
));
8781 i (tt_variant_type
);
8786 if (TREE_CODE (type
) == FUNCTION_TYPE
8787 || TREE_CODE (type
) == METHOD_TYPE
)
8789 int quals
= type_memfn_quals (type
);
8790 int rquals
= type_memfn_rqual (type
);
8791 tree raises
= TYPE_RAISES_EXCEPTIONS (type
);
8792 bool late
= TYPE_HAS_LATE_RETURN_TYPE (type
);
8794 if (raises
!= TYPE_RAISES_EXCEPTIONS (root
)
8795 || rquals
!= type_memfn_rqual (root
)
8796 || quals
!= type_memfn_quals (root
)
8797 || late
!= TYPE_HAS_LATE_RETURN_TYPE (root
))
8798 flags
= rquals
| (int (late
) << 2) | (quals
<< 3);
8802 if (TYPE_USER_ALIGN (type
))
8803 flags
= TYPE_ALIGN_RAW (type
);
8811 else if (TREE_CODE (type
) == FUNCTION_TYPE
8812 || TREE_CODE (type
) == METHOD_TYPE
)
8814 tree raises
= TYPE_RAISES_EXCEPTIONS (type
);
8815 if (raises
== TYPE_RAISES_EXCEPTIONS (root
))
8816 raises
= error_mark_node
;
8820 tree_node (TYPE_ATTRIBUTES (type
));
8825 int rquals
= cp_type_quals (root
);
8826 int quals
= cp_type_quals (type
);
8827 if (quals
== rquals
)
8832 if (ref_node (type
) != WK_none
)
8834 int tag
= insert (type
);
8839 && dump ("Wrote:%d variant type %C", tag
, TREE_CODE (type
));
8845 if (tree name
= TYPE_NAME (type
))
8846 if ((TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
))
8847 || DECL_TEMPLATE_PARM_P (name
)
8848 || TREE_CODE (type
) == RECORD_TYPE
8849 || TREE_CODE (type
) == UNION_TYPE
8850 || TREE_CODE (type
) == ENUMERAL_TYPE
)
8852 /* We can meet template parms that we didn't meet in the
8853 tpl_parms walk, because we're referring to a derived type
8854 that was previously constructed from equivalent template
8858 i (tt_typedef_type
);
8860 && dump ("Writing %stypedef %C:%N",
8861 DECL_IMPLICIT_TYPEDEF_P (name
) ? "implicit " : "",
8862 TREE_CODE (name
), name
);
8866 dump (dumper::TREE
) && dump ("Wrote typedef %C:%N%S",
8867 TREE_CODE (name
), name
, name
);
8868 gcc_checking_assert (TREE_VISITED (type
));
8872 if (TYPE_PTRMEMFUNC_P (type
))
8874 /* This is a distinct type node, masquerading as a structure. */
8875 tree fn_type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
8878 tree_node (fn_type
);
8879 int tag
= insert (type
);
8881 dump (dumper::TREE
) && dump ("Written:%d ptrmem type", tag
);
8887 u (tt_derived_type
);
8888 u (TREE_CODE (type
));
8891 tree_node (TREE_TYPE (type
));
8892 switch (TREE_CODE (type
))
8895 /* We should never meet a type here that is indescribable in
8896 terms of other types. */
8900 tree_node (TYPE_DOMAIN (type
));
8902 /* Dependent arrays are constructed with TYPE_DEPENENT_P
8904 u (TYPE_DEPENDENT_P (type
));
8908 /* No additional data. */
8912 /* A non-standard boolean type. */
8914 u (TYPE_PRECISION (type
));
8918 if (TREE_TYPE (type
))
8920 /* A range type (representing an array domain). */
8921 tree_node (TYPE_MIN_VALUE (type
));
8922 tree_node (TYPE_MAX_VALUE (type
));
8926 /* A new integral type (representing a bitfield). */
8929 unsigned prec
= TYPE_PRECISION (type
);
8930 bool unsigned_p
= TYPE_UNSIGNED (type
);
8932 u ((prec
<< 1) | unsigned_p
);
8940 gcc_checking_assert (type_memfn_rqual (type
) == REF_QUAL_NONE
);
8942 tree arg_types
= TYPE_ARG_TYPES (type
);
8943 if (TREE_CODE (type
) == METHOD_TYPE
)
8945 tree_node (TREE_TYPE (TREE_VALUE (arg_types
)));
8946 arg_types
= TREE_CHAIN (arg_types
);
8948 tree_node (arg_types
);
8953 tree_node (TYPE_OFFSET_BASETYPE (type
));
8957 /* No additional data. */
8960 case REFERENCE_TYPE
:
8962 u (TYPE_REF_IS_RVALUE (type
));
8967 case DEPENDENT_OPERATOR_TYPE
:
8968 tree_node (TYPE_VALUES_RAW (type
));
8969 if (TREE_CODE (type
) == DECLTYPE_TYPE
)
8970 /* We stash a whole bunch of things into decltype's
8973 tree_node_bools (type
);
8977 tree_node (TRAIT_TYPE_KIND_RAW (type
));
8978 tree_node (TRAIT_TYPE_TYPE1 (type
));
8979 tree_node (TRAIT_TYPE_TYPE2 (type
));
8982 case TYPE_ARGUMENT_PACK
:
8983 /* No additional data. */
8986 case TYPE_PACK_EXPANSION
:
8988 u (PACK_EXPANSION_LOCAL_P (type
));
8989 tree_node (PACK_EXPANSION_PARAMETER_PACKS (type
));
8990 tree_node (PACK_EXPANSION_EXTRA_ARGS (type
));
8995 tree_node (TYPE_CONTEXT (type
));
8996 tree_node (DECL_NAME (TYPE_NAME (type
)));
8997 tree_node (TYPENAME_TYPE_FULLNAME (type
));
9000 enum tag_types tag_type
= none_type
;
9001 if (TYPENAME_IS_ENUM_P (type
))
9002 tag_type
= enum_type
;
9003 else if (TYPENAME_IS_CLASS_P (type
))
9004 tag_type
= class_type
;
9010 case UNBOUND_CLASS_TEMPLATE
:
9012 tree decl
= TYPE_NAME (type
);
9013 tree_node (DECL_CONTEXT (decl
));
9014 tree_node (DECL_NAME (decl
));
9015 tree_node (DECL_TEMPLATE_PARMS (decl
));
9022 poly_uint64 nunits
= TYPE_VECTOR_SUBPARTS (type
);
9023 /* to_constant asserts that only coeff[0] is of interest. */
9024 wu (static_cast<unsigned HOST_WIDE_INT
> (nunits
.to_constant ()));
9029 /* We may have met the type during emitting the above. */
9030 if (ref_node (type
) != WK_none
)
9032 int tag
= insert (type
);
9037 && dump ("Wrote:%d derived type %C", tag
, TREE_CODE (type
));
9044 /* T is (mostly*) a non-mergeable node that must be written by value.
9045 The mergeable case is a BINFO, which are as-if DECLSs. */
9048 trees_out::tree_value (tree t
)
9050 /* We should never be writing a type by value. tree_type should
9051 have streamed it, or we're going via its TYPE_DECL. */
9052 gcc_checking_assert (!TYPE_P (t
));
9055 /* No template, type, var or function, except anonymous
9056 non-context vars. */
9057 gcc_checking_assert ((TREE_CODE (t
) != TEMPLATE_DECL
9058 && TREE_CODE (t
) != TYPE_DECL
9059 && (TREE_CODE (t
) != VAR_DECL
9060 || (!DECL_NAME (t
) && !DECL_CONTEXT (t
)))
9061 && TREE_CODE (t
) != FUNCTION_DECL
));
9065 /* A new node -> tt_node. */
9069 tree_node_bools (t
);
9072 if (TREE_CODE (t
) == TREE_BINFO
)
9073 /* Binfos are decl-like and need merging information. */
9074 binfo_mergeable (t
);
9076 int tag
= insert (t
, WK_value
);
9079 && dump ("Writing tree:%d %C:%N", tag
, TREE_CODE (t
), t
);
9084 dump (dumper::TREE
) && dump ("Written tree:%d %C:%N", tag
, TREE_CODE (t
), t
);
9088 trees_in::tree_value ()
9091 if (!t
|| !tree_node_bools (t
))
9095 if (TREE_CODE (t
) == TREE_BINFO
)
9098 unsigned ix
= binfo_mergeable (&type
);
9099 if (TYPE_BINFO (type
))
9101 /* We already have a definition, this must be a duplicate. */
9102 dump (dumper::MERGE
)
9103 && dump ("Deduping binfo %N[%u]", type
, ix
);
9104 existing
= TYPE_BINFO (type
);
9105 while (existing
&& ix
--)
9106 existing
= TREE_CHAIN (existing
);
9108 register_duplicate (t
, existing
);
9110 /* Error, mismatch -- diagnose in read_class_def's
9116 /* Insert into map. */
9117 int tag
= insert (existing
);
9119 && dump ("Reading tree:%d %C", tag
, TREE_CODE (t
));
9121 if (!tree_node_vals (t
))
9123 back_refs
[~tag
] = NULL_TREE
;
9129 dump (dumper::TREE
) && dump ("Read tree:%d %C:%N", tag
, TREE_CODE (t
), t
);
9131 if (TREE_CODE (existing
) == INTEGER_CST
&& !TREE_OVERFLOW (existing
))
9133 existing
= cache_integer_cst (t
, true);
9134 back_refs
[~tag
] = existing
;
9140 /* Stream out tree node T. We automatically create local back
9141 references, which is essentially a single pass lisp
9142 self-referential structure pretty-printer. */
9145 trees_out::tree_node (tree t
)
9148 walk_kind ref
= ref_node (t
);
9152 if (ref
!= WK_normal
)
9155 if (TREE_CODE (t
) == IDENTIFIER_NODE
)
9157 /* An identifier node -> tt_id, tt_conv_id, tt_anon_id, tt_lambda_id. */
9159 if (IDENTIFIER_ANON_P (t
))
9160 code
= IDENTIFIER_LAMBDA_P (t
) ? tt_lambda_id
: tt_anon_id
;
9161 else if (IDENTIFIER_CONV_OP_P (t
))
9167 if (code
== tt_conv_id
)
9169 tree type
= TREE_TYPE (t
);
9170 gcc_checking_assert (type
|| t
== conv_op_identifier
);
9173 else if (code
== tt_id
&& streaming_p ())
9174 str (IDENTIFIER_POINTER (t
), IDENTIFIER_LENGTH (t
));
9176 int tag
= insert (t
);
9179 /* We know the ordering of the 4 id tags. */
9180 static const char *const kinds
[] =
9181 {"", "conv_op ", "anon ", "lambda "};
9183 && dump ("Written:%d %sidentifier:%N", tag
,
9184 kinds
[code
- tt_id
],
9185 code
== tt_conv_id
? TREE_TYPE (t
) : t
);
9190 if (TREE_CODE (t
) == TREE_BINFO
)
9192 /* A BINFO -> tt_binfo.
9193 We must do this by reference. We stream the binfo tree
9194 itself when streaming its owning RECORD_TYPE. That we got
9195 here means the dominating type is not in this SCC. */
9198 binfo_mergeable (t
);
9199 gcc_checking_assert (!TREE_VISITED (t
));
9200 int tag
= insert (t
);
9202 dump (dumper::TREE
) && dump ("Inserting binfo:%d %N", tag
, t
);
9206 if (TREE_CODE (t
) == INTEGER_CST
9207 && !TREE_OVERFLOW (t
)
9208 && TREE_CODE (TREE_TYPE (t
)) == ENUMERAL_TYPE
)
9210 /* An integral constant of enumeral type. See if it matches one
9211 of the enumeration values. */
9212 for (tree values
= TYPE_VALUES (TREE_TYPE (t
));
9213 values
; values
= TREE_CHAIN (values
))
9215 tree decl
= TREE_VALUE (values
);
9216 if (tree_int_cst_equal (DECL_INITIAL (decl
), t
))
9221 dump (dumper::TREE
) && dump ("Written enum value %N", decl
);
9225 /* It didn't match. We'll write it a an explicit INTEGER_CST
9237 if (DECL_TEMPLATE_PARM_P (t
))
9243 if (!DECL_CONTEXT (t
))
9245 /* There are a few cases of decls with no context. We'll write
9246 these by value, but first assert they are cases we expect. */
9247 gcc_checking_assert (ref
== WK_normal
);
9248 switch (TREE_CODE (t
))
9250 default: gcc_unreachable ();
9253 /* CASE_LABEL_EXPRs contain uncontexted LABEL_DECLs. */
9254 gcc_checking_assert (!DECL_NAME (t
));
9258 /* AGGR_INIT_EXPRs cons up anonymous uncontexted VAR_DECLs. */
9259 gcc_checking_assert (!DECL_NAME (t
)
9260 && DECL_ARTIFICIAL (t
));
9264 /* REQUIRES_EXPRs have a tree list of uncontexted
9265 PARM_DECLS. It'd be nice if they had a
9266 distinguishing flag to double check. */
9274 if (DECL_P (t
) && !decl_node (t
, ref
))
9277 /* Otherwise by value */
9282 /* And, breath out. */
9286 /* Stream in a tree node. */
9289 trees_in::tree_node (bool is_use
)
9296 tree res
= NULL_TREE
;
9300 /* backref, pull it out of the map. */
9301 res
= back_ref (tag
);
9309 /* A fixed ref, find it in the fixed_ref array. */
9311 unsigned fix
= u ();
9312 if (fix
< (*fixed_trees
).length ())
9314 res
= (*fixed_trees
)[fix
];
9315 dump (dumper::TREE
) && dump ("Read fixed:%u %C:%N%S", fix
,
9316 TREE_CODE (res
), res
, res
);
9326 tree fn
= tree_node ();
9327 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
9331 && dump ("Read %s reference %N",
9332 TREE_CODE (res
) == PARM_DECL
? "parameter" : "result",
9338 /* A new node. Stream it in. */
9339 res
= tree_value ();
9343 /* A new decl. Stream it in. */
9344 res
= decl_value ();
9348 /* A template parameter. Stream it in. */
9349 res
= tpl_parm_value ();
9353 /* An identifier node. */
9356 const char *chars
= str (&l
);
9357 res
= get_identifier_with_length (chars
, l
);
9358 int tag
= insert (res
);
9360 && dump ("Read identifier:%d %N", tag
, res
);
9365 /* A conversion operator. Get the type and recreate the
9368 tree type
= tree_node ();
9369 if (!get_overrun ())
9371 res
= type
? make_conv_op_name (type
) : conv_op_identifier
;
9372 int tag
= insert (res
);
9374 && dump ("Created conv_op:%d %S for %N", tag
, res
, type
);
9381 /* An anonymous or lambda id. */
9383 res
= make_anon_name ();
9384 if (tag
== tt_lambda_id
)
9385 IDENTIFIER_LAMBDA_P (res
) = true;
9386 int tag
= insert (res
);
9388 && dump ("Read %s identifier:%d %N",
9389 IDENTIFIER_LAMBDA_P (res
) ? "lambda" : "anon", tag
, res
);
9393 case tt_typedef_type
:
9398 && dump ("Read %stypedef %C:%N",
9399 DECL_IMPLICIT_TYPEDEF_P (res
) ? "implicit " : "",
9400 TREE_CODE (res
), res
);
9401 res
= TREE_TYPE (res
);
9405 case tt_derived_type
:
9406 /* A type derived from some other type. */
9408 enum tree_code code
= tree_code (u ());
9419 tree domain
= tree_node ();
9421 if (!get_overrun ())
9422 res
= build_cplus_array_type (res
, domain
, dep
);
9427 if (!get_overrun ())
9428 res
= build_complex_type (res
);
9433 unsigned precision
= u ();
9434 if (!get_overrun ())
9435 res
= build_nonstandard_boolean_type (precision
);
9442 /* A range type (representing an array domain). */
9443 tree min
= tree_node ();
9444 tree max
= tree_node ();
9446 if (!get_overrun ())
9447 res
= build_range_type (res
, min
, max
);
9451 /* A new integral type (representing a bitfield). */
9452 unsigned enc
= u ();
9453 if (!get_overrun ())
9454 res
= build_nonstandard_integer_type (enc
>> 1, enc
& 1);
9461 tree klass
= code
== METHOD_TYPE
? tree_node () : NULL_TREE
;
9462 tree args
= tree_node ();
9463 if (!get_overrun ())
9466 res
= build_method_type_directly (klass
, res
, args
);
9468 res
= build_function_type (res
, args
);
9475 tree base
= tree_node ();
9476 if (!get_overrun ())
9477 res
= build_offset_type (base
, res
);
9482 if (!get_overrun ())
9483 res
= build_pointer_type (res
);
9486 case REFERENCE_TYPE
:
9488 bool rval
= bool (u ());
9489 if (!get_overrun ())
9490 res
= cp_build_reference_type (res
, rval
);
9496 case DEPENDENT_OPERATOR_TYPE
:
9498 tree expr
= tree_node ();
9499 if (!get_overrun ())
9501 res
= cxx_make_type (code
);
9502 TYPE_VALUES_RAW (res
) = expr
;
9503 if (code
== DECLTYPE_TYPE
)
9504 tree_node_bools (res
);
9505 SET_TYPE_STRUCTURAL_EQUALITY (res
);
9512 tree kind
= tree_node ();
9513 tree type1
= tree_node ();
9514 tree type2
= tree_node ();
9515 if (!get_overrun ())
9517 res
= cxx_make_type (TRAIT_TYPE
);
9518 TRAIT_TYPE_KIND_RAW (res
) = kind
;
9519 TRAIT_TYPE_TYPE1 (res
) = type1
;
9520 TRAIT_TYPE_TYPE2 (res
) = type2
;
9521 SET_TYPE_STRUCTURAL_EQUALITY (res
);
9526 case TYPE_ARGUMENT_PACK
:
9527 if (!get_overrun ())
9529 tree pack
= cxx_make_type (TYPE_ARGUMENT_PACK
);
9530 ARGUMENT_PACK_ARGS (pack
) = res
;
9535 case TYPE_PACK_EXPANSION
:
9538 tree param_packs
= tree_node ();
9539 tree extra_args
= tree_node ();
9540 if (!get_overrun ())
9542 tree expn
= cxx_make_type (TYPE_PACK_EXPANSION
);
9543 SET_TYPE_STRUCTURAL_EQUALITY (expn
);
9544 PACK_EXPANSION_PATTERN (expn
) = res
;
9545 PACK_EXPANSION_PARAMETER_PACKS (expn
) = param_packs
;
9546 PACK_EXPANSION_EXTRA_ARGS (expn
) = extra_args
;
9547 PACK_EXPANSION_LOCAL_P (expn
) = local
;
9555 tree ctx
= tree_node ();
9556 tree name
= tree_node ();
9557 tree fullname
= tree_node ();
9558 enum tag_types tag_type
= tag_types (u ());
9560 if (!get_overrun ())
9561 res
= build_typename_type (ctx
, name
, fullname
, tag_type
);
9565 case UNBOUND_CLASS_TEMPLATE
:
9567 tree ctx
= tree_node ();
9568 tree name
= tree_node ();
9569 tree parms
= tree_node ();
9571 if (!get_overrun ())
9572 res
= make_unbound_class_template_raw (ctx
, name
, parms
);
9578 unsigned HOST_WIDE_INT nunits
= wu ();
9579 if (!get_overrun ())
9580 res
= build_vector_type (res
, static_cast<poly_int64
> (nunits
));
9591 && dump ("Created:%d derived type %C", tag
, code
);
9594 res
= back_ref (tag
);
9598 case tt_variant_type
:
9599 /* Variant of some type. */
9607 else if (TREE_CODE (res
) == FUNCTION_TYPE
9608 || TREE_CODE (res
) == METHOD_TYPE
)
9610 cp_ref_qualifier rqual
= cp_ref_qualifier (flags
& 3);
9611 bool late
= (flags
>> 2) & 1;
9612 cp_cv_quals quals
= cp_cv_quals (flags
>> 3);
9614 tree raises
= tree_node ();
9615 if (raises
== error_mark_node
)
9616 raises
= TYPE_RAISES_EXCEPTIONS (res
);
9618 res
= build_cp_fntype_variant (res
, rqual
, raises
, late
);
9619 if (TREE_CODE (res
) == FUNCTION_TYPE
)
9620 res
= apply_memfn_quals (res
, quals
, rqual
);
9624 res
= build_aligned_type (res
, (1u << flags
) >> 1);
9625 TYPE_USER_ALIGN (res
) = true;
9628 if (tree attribs
= tree_node ())
9629 res
= cp_build_type_attribute_variant (res
, attribs
);
9632 if (quals
>= 0 && !get_overrun ())
9633 res
= cp_build_qualified_type (res
, quals
);
9641 && dump ("Created:%d variant type %C", tag
, TREE_CODE (res
));
9644 res
= back_ref (tag
);
9649 case tt_tinfo_typedef
:
9650 /* A tinfo var or typedef. */
9652 bool is_var
= tag
== tt_tinfo_var
;
9654 tree type
= NULL_TREE
;
9658 tree name
= tree_node ();
9659 type
= tree_node ();
9661 if (!get_overrun ())
9662 res
= get_tinfo_decl_direct (type
, name
, int (ix
));
9666 if (!get_overrun ())
9668 type
= get_pseudo_tinfo_type (ix
);
9669 res
= TYPE_NAME (type
);
9674 int tag
= insert (res
);
9676 && dump ("Created tinfo_%s:%d %S:%u for %N",
9677 is_var
? "var" : "decl", tag
, res
, ix
, type
);
9680 tag
= insert (type
);
9682 && dump ("Created tinfo_type:%d %u %N", tag
, ix
, type
);
9688 case tt_ptrmem_type
:
9689 /* A pointer to member function. */
9691 tree type
= tree_node ();
9692 if (type
&& TREE_CODE (type
) == POINTER_TYPE
9693 && TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
)
9695 res
= build_ptrmemfunc_type (type
);
9696 int tag
= insert (res
);
9697 dump (dumper::TREE
) && dump ("Created:%d ptrmem type", tag
);
9705 /* An NTTP object. */
9707 tree init
= tree_node ();
9708 tree name
= tree_node ();
9709 if (!get_overrun ())
9711 res
= get_template_parm_object (init
, name
);
9712 int tag
= insert (res
);
9714 && dump ("Created nttp object:%d %N", tag
, name
);
9720 /* An enum const value. */
9722 if (tree decl
= tree_node ())
9724 dump (dumper::TREE
) && dump ("Read enum value %N", decl
);
9725 res
= DECL_INITIAL (decl
);
9736 tree ctx
= tree_node ();
9737 tree name
= tree_node ();
9740 && TREE_CODE (ctx
) == ENUMERAL_TYPE
)
9741 res
= find_enum_member (ctx
, name
);
9747 int tag
= insert (res
);
9749 && dump ("Read enum decl:%d %C:%N", tag
, TREE_CODE (res
), res
);
9754 case tt_data_member
:
9755 /* A data member. */
9757 tree ctx
= tree_node ();
9758 tree name
= tree_node ();
9761 && RECORD_OR_UNION_TYPE_P (ctx
))
9764 res
= lookup_class_binding (ctx
, name
);
9766 res
= lookup_field_ident (ctx
, u ());
9769 || TREE_CODE (res
) != FIELD_DECL
9770 || DECL_CONTEXT (res
) != ctx
)
9778 int tag
= insert (res
);
9780 && dump ("Read member:%d %C:%N", tag
, TREE_CODE (res
), res
);
9786 /* A BINFO. Walk the tree of the dominating type. */
9789 unsigned ix
= binfo_mergeable (&type
);
9792 res
= TYPE_BINFO (type
);
9793 for (; ix
&& res
; res
= TREE_CHAIN (res
))
9802 /* Insert binfo into backreferences. */
9804 dump (dumper::TREE
) && dump ("Read binfo:%d %N", tag
, res
);
9811 tree ctx
= tree_node ();
9812 dump (dumper::TREE
) && dump ("Reading vtable %N[%u]", ctx
, ix
);
9813 if (TREE_CODE (ctx
) == RECORD_TYPE
&& TYPE_LANG_SPECIFIC (ctx
))
9814 for (res
= CLASSTYPE_VTABLES (ctx
); res
; res
= DECL_CHAIN (res
))
9825 tree target
= tree_node ();
9826 tree virt
= tree_node ();
9828 for (tree thunk
= DECL_THUNKS (target
);
9829 thunk
; thunk
= DECL_CHAIN (thunk
))
9830 if (THUNK_FIXED_OFFSET (thunk
) == fixed
9831 && !THUNK_VIRTUAL_OFFSET (thunk
) == !virt
9833 || tree_int_cst_equal (virt
, THUNK_VIRTUAL_OFFSET (thunk
))))
9839 int tag
= insert (res
);
9842 && dump ("Read:%d thunk %N to %N", tag
, DECL_NAME (res
), target
);
9850 tree target
= tree_node ();
9851 tree name
= tree_node ();
9853 if (DECL_P (target
) && DECL_MAYBE_IN_CHARGE_CDTOR_P (target
))
9856 FOR_EVERY_CLONE (clone
, target
)
9857 if (DECL_NAME (clone
) == name
)
9866 int tag
= insert (res
);
9869 && dump ("Read:%d clone %N of %N", tag
, DECL_NAME (res
), target
);
9876 /* Index into the entity table. Perhaps not loaded yet! */
9878 unsigned origin
= state
->slurp
->remap_module (u ());
9879 unsigned ident
= u ();
9880 module_state
*from
= (*modules
)[origin
];
9882 if (!origin
|| ident
>= from
->entity_num
)
9884 if (!get_overrun ())
9886 binding_slot
*slot
= &(*entity_ary
)[from
->entity_lwm
+ ident
];
9887 if (slot
->is_lazy ())
9888 if (!from
->lazy_load (ident
, slot
))
9895 const char *kind
= (origin
!= state
->mod
? "Imported" : "Named");
9896 int tag
= insert (res
);
9898 && dump ("%s:%d %C:%N@%M", kind
, tag
, TREE_CODE (res
),
9899 res
, (*modules
)[origin
]);
9901 if (!add_indirects (res
))
9912 if (tree tpl
= tree_node ())
9914 res
= DECL_TEMPLATE_RESULT (tpl
);
9916 && dump ("Read template %C:%N", TREE_CODE (res
), res
);
9921 if (is_use
&& !unused
&& res
&& DECL_P (res
) && !TREE_USED (res
))
9923 /* Mark decl used as mark_used does -- we cannot call
9924 mark_used in the middle of streaming, we only need a subset
9925 of its functionality. */
9926 TREE_USED (res
) = true;
9928 /* And for structured bindings also the underlying decl. */
9929 if (DECL_DECOMPOSITION_P (res
) && DECL_DECOMP_BASE (res
))
9930 TREE_USED (DECL_DECOMP_BASE (res
)) = true;
9932 if (DECL_CLONED_FUNCTION_P (res
))
9933 TREE_USED (DECL_CLONED_FUNCTION (res
)) = true;
9941 trees_out::tpl_parms (tree parms
, unsigned &tpl_levels
)
9946 if (TREE_VISITED (parms
))
9952 tpl_parms (TREE_CHAIN (parms
), tpl_levels
);
9954 tree vec
= TREE_VALUE (parms
);
9955 unsigned len
= TREE_VEC_LENGTH (vec
);
9957 int tag
= insert (parms
);
9962 && dump ("Writing template parms:%d level:%N length:%d",
9963 tag
, TREE_PURPOSE (parms
), len
);
9965 tree_node (TREE_PURPOSE (parms
));
9967 for (unsigned ix
= 0; ix
!= len
; ix
++)
9969 tree parm
= TREE_VEC_ELT (vec
, ix
);
9970 tree decl
= TREE_VALUE (parm
);
9972 gcc_checking_assert (DECL_TEMPLATE_PARM_P (decl
));
9974 switch (TREE_CODE (decl
))
9976 default: gcc_unreachable ();
9979 gcc_assert ((TREE_CODE (TREE_TYPE (decl
)) == TEMPLATE_TEMPLATE_PARM
)
9980 && (TREE_CODE (DECL_TEMPLATE_RESULT (decl
)) == TYPE_DECL
)
9981 && (TYPE_NAME (TREE_TYPE (decl
)) == decl
));
9985 gcc_assert ((TREE_CODE (TREE_TYPE (decl
)) == TEMPLATE_TYPE_PARM
)
9986 && (TYPE_NAME (TREE_TYPE (decl
)) == decl
));
9990 gcc_assert ((TREE_CODE (DECL_INITIAL (decl
)) == TEMPLATE_PARM_INDEX
)
9991 && (TREE_CODE (TEMPLATE_PARM_DECL (DECL_INITIAL (decl
)))
9993 && (DECL_TEMPLATE_PARM_P
9994 (TEMPLATE_PARM_DECL (DECL_INITIAL (decl
)))));
9999 tree_node (TEMPLATE_PARM_CONSTRAINTS (parm
));
10006 trees_in::tpl_parms (unsigned &tpl_levels
)
10008 tree parms
= NULL_TREE
;
10010 while (int len
= i ())
10014 parms
= back_ref (len
);
10019 parms
= tree_cons (NULL_TREE
, NULL_TREE
, parms
);
10020 int tag
= insert (parms
);
10021 TREE_PURPOSE (parms
) = tree_node ();
10023 dump (dumper::TREE
)
10024 && dump ("Reading template parms:%d level:%N length:%d",
10025 tag
, TREE_PURPOSE (parms
), len
);
10027 tree vec
= make_tree_vec (len
);
10028 for (int ix
= 0; ix
!= len
; ix
++)
10030 tree decl
= tree_node ();
10034 tree parm
= build_tree_list (NULL
, decl
);
10035 TEMPLATE_PARM_CONSTRAINTS (parm
) = tree_node ();
10037 TREE_VEC_ELT (vec
, ix
) = parm
;
10040 TREE_VALUE (parms
) = vec
;
10048 trees_out::tpl_parms_fini (tree tmpl
, unsigned tpl_levels
)
10050 for (tree parms
= DECL_TEMPLATE_PARMS (tmpl
);
10051 tpl_levels
--; parms
= TREE_CHAIN (parms
))
10053 tree vec
= TREE_VALUE (parms
);
10055 tree_node (TREE_TYPE (vec
));
10056 for (unsigned ix
= TREE_VEC_LENGTH (vec
); ix
--;)
10058 tree parm
= TREE_VEC_ELT (vec
, ix
);
10059 tree dflt
= TREE_PURPOSE (parm
);
10062 if (streaming_p ())
10064 tree decl
= TREE_VALUE (parm
);
10065 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
10067 tree ctx
= DECL_CONTEXT (decl
);
10068 tree inner
= DECL_TEMPLATE_RESULT (decl
);
10069 tree tpi
= (TREE_CODE (inner
) == TYPE_DECL
10070 ? TEMPLATE_TYPE_PARM_INDEX (TREE_TYPE (decl
))
10071 : DECL_INITIAL (inner
));
10072 bool original
= (TEMPLATE_PARM_LEVEL (tpi
)
10073 == TEMPLATE_PARM_ORIG_LEVEL (tpi
));
10074 /* Original template template parms have a context
10075 of their owning template. Reduced ones do not. */
10076 gcc_checking_assert (original
? ctx
== tmpl
: !ctx
);
10084 trees_in::tpl_parms_fini (tree tmpl
, unsigned tpl_levels
)
10086 for (tree parms
= DECL_TEMPLATE_PARMS (tmpl
);
10087 tpl_levels
--; parms
= TREE_CHAIN (parms
))
10089 tree vec
= TREE_VALUE (parms
);
10091 TREE_TYPE (vec
) = tree_node ();
10092 for (unsigned ix
= TREE_VEC_LENGTH (vec
); ix
--;)
10094 tree parm
= TREE_VEC_ELT (vec
, ix
);
10095 tree dflt
= tree_node ();
10096 if (get_overrun ())
10098 TREE_PURPOSE (parm
) = dflt
;
10100 tree decl
= TREE_VALUE (parm
);
10101 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
10103 tree inner
= DECL_TEMPLATE_RESULT (decl
);
10104 tree tpi
= (TREE_CODE (inner
) == TYPE_DECL
10105 ? TEMPLATE_TYPE_PARM_INDEX (TREE_TYPE (decl
))
10106 : DECL_INITIAL (inner
));
10107 bool original
= (TEMPLATE_PARM_LEVEL (tpi
)
10108 == TEMPLATE_PARM_ORIG_LEVEL (tpi
));
10109 /* Original template template parms have a context
10110 of their owning template. Reduced ones do not. */
10112 DECL_CONTEXT (decl
) = tmpl
;
10119 /* PARMS is a LIST, one node per level.
10120 TREE_VALUE is a TREE_VEC of parm info for that level.
10121 each ELT is a TREE_LIST
10122 TREE_VALUE is PARM_DECL, TYPE_DECL or TEMPLATE_DECL
10123 TREE_PURPOSE is the default value. */
10126 trees_out::tpl_header (tree tpl
, unsigned *tpl_levels
)
10128 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
10129 tpl_parms (parms
, *tpl_levels
);
10132 if (streaming_p ())
10136 tree_node (TEMPLATE_PARMS_CONSTRAINTS (parms
));
10140 trees_in::tpl_header (tree tpl
, unsigned *tpl_levels
)
10142 tree parms
= tpl_parms (*tpl_levels
);
10146 DECL_TEMPLATE_PARMS (tpl
) = parms
;
10149 TEMPLATE_PARMS_CONSTRAINTS (parms
) = tree_node ();
10154 /* Stream skeleton parm nodes, with their flags, type & parm indices.
10155 All the parms will have consecutive tags. */
10158 trees_out::fn_parms_init (tree fn
)
10160 /* First init them. */
10161 int base_tag
= ref_num
- 1;
10163 for (tree parm
= DECL_ARGUMENTS (fn
);
10164 parm
; parm
= DECL_CHAIN (parm
), ix
++)
10166 if (streaming_p ())
10169 tree_node_bools (parm
);
10171 int tag
= insert (parm
);
10172 gcc_checking_assert (base_tag
- ix
== tag
);
10174 /* Mark the end. */
10175 if (streaming_p ())
10178 /* Now stream their contents. */
10180 for (tree parm
= DECL_ARGUMENTS (fn
);
10181 parm
; parm
= DECL_CHAIN (parm
), ix
++)
10183 if (streaming_p ())
10184 dump (dumper::TREE
)
10185 && dump ("Writing parm:%d %u (%N) of %N",
10186 base_tag
- ix
, ix
, parm
, fn
);
10187 tree_node_vals (parm
);
10190 if (!streaming_p ())
10192 /* We must walk contract attrs so the dependency graph is complete. */
10193 for (tree contract
= DECL_CONTRACTS (fn
);
10195 contract
= CONTRACT_CHAIN (contract
))
10196 tree_node (contract
);
10199 /* Write a reference to contracts pre/post functions, if any, to avoid
10200 regenerating them in importers. */
10201 tree_node (DECL_PRE_FN (fn
));
10202 tree_node (DECL_POST_FN (fn
));
10205 /* Build skeleton parm nodes, read their flags, type & parm indices. */
10208 trees_in::fn_parms_init (tree fn
)
10210 int base_tag
= ~(int)back_refs
.length ();
10212 tree
*parm_ptr
= &DECL_ARGUMENTS (fn
);
10214 for (; int code
= u (); ix
++)
10216 tree parm
= start (code
);
10217 if (!tree_node_bools (parm
))
10220 int tag
= insert (parm
);
10221 gcc_checking_assert (base_tag
- ix
== tag
);
10223 parm_ptr
= &DECL_CHAIN (parm
);
10227 for (tree parm
= DECL_ARGUMENTS (fn
);
10228 parm
; parm
= DECL_CHAIN (parm
), ix
++)
10230 dump (dumper::TREE
)
10231 && dump ("Reading parm:%d %u (%N) of %N",
10232 base_tag
- ix
, ix
, parm
, fn
);
10233 if (!tree_node_vals (parm
))
10237 /* Reload references to contract functions, if any. */
10238 tree pre_fn
= tree_node ();
10239 tree post_fn
= tree_node ();
10240 set_contract_functions (fn
, pre_fn
, post_fn
);
10245 /* Read the remaining parm node data. Replace with existing (if
10246 non-null) in the map. */
10249 trees_in::fn_parms_fini (int tag
, tree fn
, tree existing
, bool is_defn
)
10251 tree existing_parm
= existing
? DECL_ARGUMENTS (existing
) : NULL_TREE
;
10252 tree parms
= DECL_ARGUMENTS (fn
);
10254 for (tree parm
= parms
; parm
; parm
= DECL_CHAIN (parm
), ix
++)
10258 if (is_defn
&& !DECL_SAVED_TREE (existing
))
10260 /* If we're about to become the definition, set the
10261 names of the parms from us. */
10262 DECL_NAME (existing_parm
) = DECL_NAME (parm
);
10263 DECL_SOURCE_LOCATION (existing_parm
) = DECL_SOURCE_LOCATION (parm
);
10266 back_refs
[~tag
] = existing_parm
;
10267 existing_parm
= DECL_CHAIN (existing_parm
);
10273 /* DEP is the depset of some decl we're streaming by value. Determine
10274 the merging behaviour. */
10277 trees_out::get_merge_kind (tree decl
, depset
*dep
)
10281 if (VAR_OR_FUNCTION_DECL_P (decl
))
10283 /* Any var or function with template info should have DEP. */
10284 gcc_checking_assert (!DECL_LANG_SPECIFIC (decl
)
10285 || !DECL_TEMPLATE_INFO (decl
));
10286 if (DECL_LOCAL_DECL_P (decl
))
10290 /* Either unique, or some member of a class that cannot have an
10291 out-of-class definition. For instance a FIELD_DECL. */
10292 tree ctx
= CP_DECL_CONTEXT (decl
);
10293 if (TREE_CODE (ctx
) == FUNCTION_DECL
)
10295 /* USING_DECLs and NAMESPACE_DECLs cannot have DECL_TEMPLATE_INFO --
10296 this isn't permitting them to have one. */
10297 gcc_checking_assert (TREE_CODE (decl
) == USING_DECL
10298 || TREE_CODE (decl
) == NAMESPACE_DECL
10299 || !DECL_LANG_SPECIFIC (decl
)
10300 || !DECL_TEMPLATE_INFO (decl
));
10305 if (TREE_CODE (decl
) == TEMPLATE_DECL
10306 && DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (decl
))
10307 return MK_local_friend
;
10309 gcc_checking_assert (TYPE_P (ctx
));
10310 if (TREE_CODE (decl
) == USING_DECL
)
10313 if (TREE_CODE (decl
) == FIELD_DECL
)
10315 if (DECL_NAME (decl
))
10317 /* Anonymous FIELD_DECLs have a NULL name. */
10318 gcc_checking_assert (!IDENTIFIER_ANON_P (DECL_NAME (decl
)));
10322 if (!DECL_NAME (decl
)
10323 && !RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl
))
10324 && !DECL_BIT_FIELD_REPRESENTATIVE (decl
))
10326 /* The underlying storage unit for a bitfield. We do not
10327 need to dedup it, because it's only reachable through
10328 the bitfields it represents. And those are deduped. */
10329 // FIXME: Is that assertion correct -- do we ever fish it
10330 // out and put it in an expr?
10331 gcc_checking_assert ((TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
10332 ? TREE_CODE (TREE_TYPE (TREE_TYPE (decl
)))
10333 : TREE_CODE (TREE_TYPE (decl
)))
10341 if (TREE_CODE (decl
) == CONST_DECL
)
10344 if (TREE_CODE (decl
) == VAR_DECL
10345 && DECL_VTABLE_OR_VTT_P (decl
))
10348 if (DECL_THUNK_P (decl
))
10349 /* Thunks are unique-enough, because they're only referenced
10350 from the vtable. And that's either new (so we want the
10351 thunks), or it's a duplicate (so it will be dropped). */
10354 /* There should be no other cases. */
10355 gcc_unreachable ();
10358 gcc_checking_assert (TREE_CODE (decl
) != FIELD_DECL
10359 && TREE_CODE (decl
) != USING_DECL
10360 && TREE_CODE (decl
) != CONST_DECL
);
10362 if (is_key_order ())
10364 /* When doing the mergeablilty graph, there's an indirection to
10365 the actual depset. */
10366 gcc_assert (dep
->is_special ());
10367 dep
= dep
->deps
[0];
10370 gcc_checking_assert (decl
== dep
->get_entity ());
10372 merge_kind mk
= MK_named
;
10373 switch (dep
->get_entity_kind ())
10376 gcc_unreachable ();
10378 case depset::EK_PARTIAL
:
10382 case depset::EK_DECL
:
10384 tree ctx
= CP_DECL_CONTEXT (decl
);
10386 switch (TREE_CODE (ctx
))
10389 gcc_unreachable ();
10391 case FUNCTION_DECL
:
10392 // FIXME: This can occur for (a) voldemorty TYPE_DECLS
10393 // (which are returned from a function), or (b)
10394 // block-scope class definitions in template functions.
10395 // These are as unique as the containing function. While
10396 // on read-back we can discover if the CTX was a
10397 // duplicate, we don't have a mechanism to get from the
10398 // existing CTX to the existing version of this decl.
10399 gcc_checking_assert
10400 (DECL_IMPLICIT_TYPEDEF_P (STRIP_TEMPLATE (decl
)));
10407 if (DECL_NAME (decl
) == as_base_identifier
)
10409 else if (IDENTIFIER_ANON_P (DECL_NAME (decl
)))
10413 case NAMESPACE_DECL
:
10414 if (DECL_IMPLICIT_TYPEDEF_P (STRIP_TEMPLATE (decl
))
10415 && LAMBDA_TYPE_P (TREE_TYPE (decl
)))
10417 = LAMBDA_EXPR_EXTRA_SCOPE (CLASSTYPE_LAMBDA_EXPR
10418 (TREE_TYPE (decl
))))
10419 if (TREE_CODE (scope
) == VAR_DECL
10420 && DECL_MODULE_KEYED_DECLS_P (scope
))
10426 if (TREE_CODE (decl
) == TEMPLATE_DECL
10427 && DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (decl
))
10428 mk
= MK_local_friend
;
10429 else if (IDENTIFIER_ANON_P (DECL_NAME (decl
)))
10431 if (DECL_IMPLICIT_TYPEDEF_P (decl
)
10432 && UNSCOPED_ENUM_P (TREE_TYPE (decl
))
10433 && TYPE_VALUES (TREE_TYPE (decl
)))
10434 /* Keyed by first enum value, and underlying type. */
10437 /* No way to merge it, it is an ODR land-mine. */
10444 case depset::EK_SPECIALIZATION
:
10446 gcc_checking_assert (dep
->is_special ());
10448 if (TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
10449 /* An block-scope classes of templates are themselves
10451 gcc_checking_assert (DECL_IMPLICIT_TYPEDEF_P (decl
));
10453 if (dep
->is_friend_spec ())
10454 mk
= MK_friend_spec
;
10455 else if (dep
->is_type_spec ())
10457 else if (dep
->is_alias ())
10458 mk
= MK_alias_spec
;
10462 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
10464 spec_entry
*entry
= reinterpret_cast <spec_entry
*> (dep
->deps
[0]);
10465 if (TREE_CODE (entry
->spec
) != TEMPLATE_DECL
)
10466 mk
= merge_kind (mk
| MK_tmpl_tmpl_mask
);
10476 /* The container of DECL -- not necessarily its context! */
10479 trees_out::decl_container (tree decl
)
10482 tree tpl
= NULL_TREE
;
10483 if (tree template_info
= node_template_info (decl
, use_tpl
))
10484 tpl
= TI_TEMPLATE (template_info
);
10488 /* Stream the template we're instantiated from. */
10491 tree container
= NULL_TREE
;
10492 if (TREE_CODE (decl
) == TEMPLATE_DECL
10493 && DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (decl
))
10494 container
= DECL_CHAIN (decl
);
10496 container
= CP_DECL_CONTEXT (decl
);
10498 if (TYPE_P (container
))
10499 container
= TYPE_NAME (container
);
10501 tree_node (container
);
10507 trees_in::decl_container ()
10509 /* The maybe-template. */
10510 (void)tree_node ();
10512 tree container
= tree_node ();
10517 /* Write out key information about a mergeable DEP. Does not write
10518 the contents of DEP itself. The context has already been
10519 written. The container has already been streamed. */
10522 trees_out::key_mergeable (int tag
, merge_kind mk
, tree decl
, tree inner
,
10523 tree container
, depset
*dep
)
10525 if (dep
&& is_key_order ())
10527 gcc_checking_assert (dep
->is_special ());
10528 dep
= dep
->deps
[0];
10531 if (streaming_p ())
10532 dump (dumper::MERGE
)
10533 && dump ("Writing:%d's %s merge key (%s) %C:%N", tag
, merge_kind_name
[mk
],
10534 dep
? dep
->entity_kind_name () : "contained",
10535 TREE_CODE (decl
), decl
);
10537 /* Now write the locating information. */
10538 if (mk
& MK_template_mask
)
10540 /* Specializations are located via their originating template,
10541 and the set of template args they specialize. */
10542 gcc_checking_assert (dep
&& dep
->is_special ());
10543 spec_entry
*entry
= reinterpret_cast <spec_entry
*> (dep
->deps
[0]);
10545 tree_node (entry
->tmpl
);
10546 tree_node (entry
->args
);
10547 if (mk
& MK_tmpl_decl_mask
)
10548 if (flag_concepts
&& TREE_CODE (inner
) == VAR_DECL
)
10550 /* Variable template partial specializations might need
10551 constraints (see spec_hasher::equal). It's simpler to
10552 write NULL when we don't need them. */
10553 tree constraints
= NULL_TREE
;
10555 if (uses_template_parms (entry
->args
))
10556 constraints
= get_constraints (inner
);
10557 tree_node (constraints
);
10562 /* Make sure we can locate the decl. */
10563 tree existing
= match_mergeable_specialization
10564 (bool (mk
& MK_tmpl_decl_mask
), entry
);
10566 gcc_assert (existing
);
10567 if (mk
& MK_tmpl_decl_mask
)
10569 if (mk
& MK_tmpl_alias_mask
)
10570 /* It should be in both tables. */
10571 gcc_checking_assert
10572 (same_type_p (match_mergeable_specialization (false, entry
),
10573 TREE_TYPE (existing
)));
10574 if (mk
& MK_tmpl_tmpl_mask
)
10575 existing
= DECL_TI_TEMPLATE (existing
);
10579 if (mk
& MK_tmpl_tmpl_mask
)
10580 existing
= CLASSTYPE_TI_TEMPLATE (existing
);
10582 existing
= TYPE_NAME (existing
);
10585 /* The walkabout should have found ourselves. */
10586 gcc_checking_assert (TREE_CODE (decl
) == TYPE_DECL
10587 ? same_type_p (TREE_TYPE (decl
),
10588 TREE_TYPE (existing
))
10589 : existing
== decl
);
10592 else if (mk
!= MK_unique
)
10595 tree name
= DECL_NAME (decl
);
10600 gcc_unreachable ();
10603 case MK_friend_spec
:
10604 if (IDENTIFIER_CONV_OP_P (name
))
10605 name
= conv_op_identifier
;
10607 if (TREE_CODE (inner
) == FUNCTION_DECL
)
10609 /* Functions are distinguished by parameter types. */
10610 tree fn_type
= TREE_TYPE (inner
);
10612 key
.ref_q
= type_memfn_rqual (fn_type
);
10613 key
.args
= TYPE_ARG_TYPES (fn_type
);
10615 if (tree reqs
= get_constraints (inner
))
10617 if (cxx_dialect
< cxx20
)
10618 reqs
= CI_ASSOCIATED_CONSTRAINTS (reqs
);
10620 reqs
= CI_DECLARATOR_REQS (reqs
);
10621 key
.constraints
= reqs
;
10624 if (IDENTIFIER_CONV_OP_P (name
)
10626 && !(name
== fun_identifier
10627 /* In case the user names something _FUN */
10628 && LAMBDA_TYPE_P (DECL_CONTEXT (inner
)))))
10629 /* And a function template, or conversion operator needs
10630 the return type. Except for the _FUN thunk of a
10631 generic lambda, which has a recursive decl_type'd
10633 // FIXME: What if the return type is a voldemort?
10634 key
.ret
= fndecl_declared_return_type (inner
);
10641 if (TREE_CODE (inner
) != FIELD_DECL
)
10644 gcc_checking_assert (!name
|| !IDENTIFIER_ANON_P (name
));
10646 for (tree field
= TYPE_FIELDS (TREE_TYPE (container
));
10647 ; field
= DECL_CHAIN (field
))
10649 tree finner
= STRIP_TEMPLATE (field
);
10650 if (TREE_CODE (finner
) == TREE_CODE (inner
))
10652 if (finner
== inner
)
10663 tree vtable
= CLASSTYPE_VTABLES (TREE_TYPE (container
));
10664 for (unsigned ix
= 0; ; vtable
= DECL_CHAIN (vtable
), ix
++)
10665 if (vtable
== decl
)
10675 gcc_checking_assert
10676 (decl
== TYPE_NAME (CLASSTYPE_AS_BASE (TREE_TYPE (container
))));
10679 case MK_local_friend
:
10681 /* Find by index on the class's DECL_LIST */
10683 for (tree decls
= CLASSTYPE_DECL_LIST (TREE_CHAIN (decl
));
10684 decls
; decls
= TREE_CHAIN (decls
))
10685 if (!TREE_PURPOSE (decls
))
10687 tree frnd
= friend_from_decl_list (TREE_VALUE (decls
));
10699 /* Anonymous enums are located by their first identifier,
10700 and underlying type. */
10701 tree type
= TREE_TYPE (decl
);
10703 gcc_checking_assert (UNSCOPED_ENUM_P (type
));
10704 /* Using the type name drops the bit precision we might
10705 have been using on the enum. */
10706 key
.ret
= TYPE_NAME (ENUM_UNDERLYING_TYPE (type
));
10707 if (tree values
= TYPE_VALUES (type
))
10708 name
= DECL_NAME (TREE_VALUE (values
));
10714 gcc_checking_assert (LAMBDA_TYPE_P (TREE_TYPE (inner
)));
10715 tree scope
= LAMBDA_EXPR_EXTRA_SCOPE (CLASSTYPE_LAMBDA_EXPR
10716 (TREE_TYPE (inner
)));
10717 gcc_checking_assert (TREE_CODE (scope
) == VAR_DECL
);
10718 auto *root
= keyed_table
->get (scope
);
10719 unsigned ix
= root
->length ();
10720 /* If we don't find it, we'll write a really big number
10721 that the reader will ignore. */
10723 if ((*root
)[ix
] == inner
)
10726 /* Use the keyed-to decl as the 'name'. */
10734 tree ti
= get_template_info (inner
);
10735 key
.constraints
= get_constraints (inner
);
10736 key
.ret
= TI_TEMPLATE (ti
);
10737 key
.args
= TI_ARGS (ti
);
10743 if (streaming_p ())
10745 unsigned code
= (key
.ref_q
<< 0) | (key
.index
<< 2);
10750 tree_node (key
.ret
);
10751 else if (mk
== MK_partial
10752 || (mk
== MK_named
&& inner
10753 && TREE_CODE (inner
) == FUNCTION_DECL
))
10755 tree_node (key
.ret
);
10756 tree arg
= key
.args
;
10757 if (mk
== MK_named
)
10758 while (arg
&& arg
!= void_list_node
)
10760 tree_node (TREE_VALUE (arg
));
10761 arg
= TREE_CHAIN (arg
);
10764 tree_node (key
.constraints
);
10769 /* DECL is a new declaration that may be duplicated in OVL. Use RET &
10770 ARGS to find its clone, or NULL. If DECL's DECL_NAME is NULL, this
10771 has been found by a proxy. It will be an enum type located by its
10774 We're conservative with matches, so ambiguous decls will be
10775 registered as different, then lead to a lookup error if the two
10776 modules are both visible. Perhaps we want to do something similar
10777 to duplicate decls to get ODR errors on loading? We already have
10778 some special casing for namespaces. */
10781 check_mergeable_decl (merge_kind mk
, tree decl
, tree ovl
, merge_key
const &key
)
10783 tree found
= NULL_TREE
;
10784 for (ovl_iterator
iter (ovl
); !found
&& iter
; ++iter
)
10786 tree match
= *iter
;
10788 tree d_inner
= decl
;
10789 tree m_inner
= match
;
10792 if (TREE_CODE (d_inner
) != TREE_CODE (m_inner
))
10794 if (TREE_CODE (match
) == NAMESPACE_DECL
10795 && !DECL_NAMESPACE_ALIAS (match
))
10796 /* Namespaces are never overloaded. */
10802 switch (TREE_CODE (d_inner
))
10804 case TEMPLATE_DECL
:
10805 if (template_heads_equivalent_p (d_inner
, m_inner
))
10807 d_inner
= DECL_TEMPLATE_RESULT (d_inner
);
10808 m_inner
= DECL_TEMPLATE_RESULT (m_inner
);
10809 if (d_inner
== error_mark_node
10810 && TYPE_DECL_ALIAS_P (m_inner
))
10819 case FUNCTION_DECL
:
10820 if (tree m_type
= TREE_TYPE (m_inner
))
10822 || same_type_p (key
.ret
, fndecl_declared_return_type (m_inner
)))
10823 && type_memfn_rqual (m_type
) == key
.ref_q
10824 && compparms (key
.args
, TYPE_ARG_TYPES (m_type
))
10825 /* Reject if old is a "C" builtin and new is not "C".
10826 Matches decls_match behaviour. */
10827 && (!DECL_IS_UNDECLARED_BUILTIN (m_inner
)
10828 || !DECL_EXTERN_C_P (m_inner
)
10829 || DECL_EXTERN_C_P (d_inner
))
10830 /* Reject if one is a different member of a
10831 guarded/pre/post fn set. */
10832 && (!flag_contracts
10833 || (DECL_IS_PRE_FN_P (d_inner
)
10834 == DECL_IS_PRE_FN_P (m_inner
)))
10835 && (!flag_contracts
10836 || (DECL_IS_POST_FN_P (d_inner
)
10837 == DECL_IS_POST_FN_P (m_inner
))))
10839 tree m_reqs
= get_constraints (m_inner
);
10842 if (cxx_dialect
< cxx20
)
10843 m_reqs
= CI_ASSOCIATED_CONSTRAINTS (m_reqs
);
10845 m_reqs
= CI_DECLARATOR_REQS (m_reqs
);
10848 if (cp_tree_equal (key
.constraints
, m_reqs
))
10854 if (DECL_IMPLICIT_TYPEDEF_P (d_inner
)
10855 == DECL_IMPLICIT_TYPEDEF_P (m_inner
))
10857 if (!IDENTIFIER_ANON_P (DECL_NAME (m_inner
)))
10859 else if (mk
== MK_enum
10860 && (TYPE_NAME (ENUM_UNDERLYING_TYPE (TREE_TYPE (m_inner
)))
10875 /* DECL, INNER & TYPE are a skeleton set of nodes for a decl. Only
10876 the bools have been filled in. Read its merging key and merge it.
10877 Returns the existing decl if there is one. */
10880 trees_in::key_mergeable (int tag
, merge_kind mk
, tree decl
, tree inner
,
10881 tree type
, tree container
, bool is_attached
)
10883 const char *kind
= "new";
10884 tree existing
= NULL_TREE
;
10886 if (mk
& MK_template_mask
)
10888 // FIXME: We could stream the specialization hash?
10890 spec
.tmpl
= tree_node ();
10891 spec
.args
= tree_node ();
10893 if (get_overrun ())
10894 return error_mark_node
;
10896 DECL_NAME (decl
) = DECL_NAME (spec
.tmpl
);
10897 DECL_CONTEXT (decl
) = DECL_CONTEXT (spec
.tmpl
);
10898 DECL_NAME (inner
) = DECL_NAME (decl
);
10899 DECL_CONTEXT (inner
) = DECL_CONTEXT (decl
);
10901 tree constr
= NULL_TREE
;
10902 bool is_decl
= mk
& MK_tmpl_decl_mask
;
10905 if (flag_concepts
&& TREE_CODE (inner
) == VAR_DECL
)
10907 constr
= tree_node ();
10909 set_constraints (inner
, constr
);
10911 spec
.spec
= (mk
& MK_tmpl_tmpl_mask
) ? inner
: decl
;
10915 existing
= match_mergeable_specialization (is_decl
, &spec
);
10917 /* We'll add these back later, if this is the new decl. */
10918 remove_constraints (inner
);
10921 ; /* We'll add to the table once read. */
10922 else if (mk
& MK_tmpl_decl_mask
)
10924 /* A declaration specialization. */
10925 if (mk
& MK_tmpl_tmpl_mask
)
10926 existing
= DECL_TI_TEMPLATE (existing
);
10930 /* A type specialization. */
10931 if (mk
& MK_tmpl_tmpl_mask
)
10932 existing
= CLASSTYPE_TI_TEMPLATE (existing
);
10934 existing
= TYPE_NAME (existing
);
10937 else if (mk
== MK_unique
)
10941 tree name
= tree_node ();
10944 unsigned code
= u ();
10945 key
.ref_q
= cp_ref_qualifier ((code
>> 0) & 3);
10946 key
.index
= code
>> 2;
10949 key
.ret
= tree_node ();
10950 else if (mk
== MK_partial
10951 || ((mk
== MK_named
|| mk
== MK_friend_spec
)
10952 && TREE_CODE (inner
) == FUNCTION_DECL
))
10954 key
.ret
= tree_node ();
10955 tree arg
, *arg_ptr
= &key
.args
;
10956 while ((arg
= tree_node ())
10957 && arg
!= void_list_node
10958 && mk
!= MK_partial
)
10960 *arg_ptr
= tree_cons (NULL_TREE
, arg
, NULL_TREE
);
10961 arg_ptr
= &TREE_CHAIN (*arg_ptr
);
10964 key
.constraints
= tree_node ();
10967 if (get_overrun ())
10968 return error_mark_node
;
10970 if (mk
< MK_indirect_lwm
)
10972 DECL_NAME (decl
) = name
;
10973 DECL_CONTEXT (decl
) = FROB_CONTEXT (container
);
10975 DECL_NAME (inner
) = DECL_NAME (decl
);
10976 DECL_CONTEXT (inner
) = DECL_CONTEXT (decl
);
10978 if (mk
== MK_partial
)
10980 for (tree spec
= DECL_TEMPLATE_SPECIALIZATIONS (key
.ret
);
10981 spec
; spec
= TREE_CHAIN (spec
))
10983 tree tmpl
= TREE_VALUE (spec
);
10984 tree ti
= get_template_info (tmpl
);
10985 if (template_args_equal (key
.args
, TI_ARGS (ti
))
10986 && cp_tree_equal (key
.constraints
,
10988 (DECL_TEMPLATE_RESULT (tmpl
))))
10996 switch (TREE_CODE (container
))
10999 gcc_unreachable ();
11001 case NAMESPACE_DECL
:
11002 if (mk
== MK_keyed
)
11004 if (DECL_LANG_SPECIFIC (name
)
11005 && VAR_OR_FUNCTION_DECL_P (name
)
11006 && DECL_MODULE_KEYED_DECLS_P (name
))
11007 if (auto *set
= keyed_table
->get (name
))
11008 if (key
.index
< set
->length ())
11010 existing
= (*set
)[key
.index
];
11013 gcc_checking_assert
11014 (DECL_IMPLICIT_TYPEDEF_P (existing
));
11017 = CLASSTYPE_TI_TEMPLATE (TREE_TYPE (existing
));
11021 else if (is_attached
11022 && !(state
->is_module () || state
->is_partition ()))
11026 gcc_checking_assert (mk
== MK_named
|| mk
== MK_enum
);
11028 tree
*vslot
= mergeable_namespace_slots (container
, name
,
11029 is_attached
, &mvec
);
11030 existing
= check_mergeable_decl (mk
, decl
, *vslot
, key
);
11032 add_mergeable_namespace_entity (vslot
, decl
);
11035 /* Note that we now have duplicates to deal with in
11038 BINDING_VECTOR_PARTITION_DUPS_P (mvec
) = true;
11040 BINDING_VECTOR_GLOBAL_DUPS_P (mvec
) = true;
11045 case FUNCTION_DECL
:
11046 // FIXME: What about a voldemort? how do we find what it
11047 // duplicates? Do we have to number vmorts relative to
11048 // their containing function? But how would that work
11049 // when matching an in-TU declaration?
11054 if (is_attached
&& !(state
->is_module () || state
->is_partition ())
11055 /* Implicit member functions can come from
11057 && !(DECL_ARTIFICIAL (decl
)
11058 && TREE_CODE (decl
) == FUNCTION_DECL
11059 && !DECL_THUNK_P (decl
)))
11063 tree ctx
= TREE_TYPE (container
);
11065 /* For some reason templated enumeral types are not marked
11066 as COMPLETE_TYPE_P, even though they have members.
11067 This may well be a bug elsewhere. */
11068 if (TREE_CODE (ctx
) == ENUMERAL_TYPE
)
11069 existing
= find_enum_member (ctx
, name
);
11070 else if (COMPLETE_TYPE_P (ctx
))
11075 gcc_unreachable ();
11078 existing
= lookup_class_binding (ctx
, name
);
11082 if (TREE_CODE (inner
) == TEMPLATE_DECL
11083 && !DECL_MEMBER_TEMPLATE_P (inner
))
11084 inner
= DECL_TEMPLATE_RESULT (inner
);
11086 existing
= check_mergeable_decl
11087 (mk
, inner
, existing
, key
);
11089 if (!existing
&& DECL_ALIAS_TEMPLATE_P (decl
))
11090 {} // FIXME: Insert into specialization
11091 // tables, we'll need the arguments for that!
11097 unsigned ix
= key
.index
;
11098 for (tree field
= TYPE_FIELDS (ctx
);
11099 field
; field
= DECL_CHAIN (field
))
11101 tree finner
= STRIP_TEMPLATE (field
);
11102 if (TREE_CODE (finner
) == TREE_CODE (inner
))
11114 unsigned ix
= key
.index
;
11115 for (tree vtable
= CLASSTYPE_VTABLES (ctx
);
11116 vtable
; vtable
= DECL_CHAIN (vtable
))
11127 tree as_base
= CLASSTYPE_AS_BASE (ctx
);
11128 if (as_base
&& as_base
!= ctx
)
11129 existing
= TYPE_NAME (as_base
);
11133 case MK_local_friend
:
11135 unsigned ix
= key
.index
;
11136 for (tree decls
= CLASSTYPE_DECL_LIST (ctx
);
11137 decls
; decls
= TREE_CHAIN (decls
))
11138 if (!TREE_PURPOSE (decls
) && !ix
--)
11141 = friend_from_decl_list (TREE_VALUE (decls
));
11148 if (existing
&& mk
< MK_indirect_lwm
&& mk
!= MK_partial
11149 && TREE_CODE (decl
) == TEMPLATE_DECL
11150 && !DECL_MEMBER_TEMPLATE_P (decl
))
11153 if (DECL_IMPLICIT_TYPEDEF_P (existing
))
11154 ti
= TYPE_TEMPLATE_INFO (TREE_TYPE (existing
));
11156 ti
= DECL_TEMPLATE_INFO (existing
);
11157 existing
= TI_TEMPLATE (ti
);
11164 dump (dumper::MERGE
)
11165 && dump ("Read:%d's %s merge key (%s) %C:%N", tag
, merge_kind_name
[mk
],
11166 existing
? "matched" : kind
, TREE_CODE (decl
), decl
);
11172 trees_out::binfo_mergeable (tree binfo
)
11175 while (tree parent
= BINFO_INHERITANCE_CHAIN (dom
))
11177 tree type
= BINFO_TYPE (dom
);
11178 gcc_checking_assert (TYPE_BINFO (type
) == dom
);
11180 if (streaming_p ())
11183 for (; dom
!= binfo
; dom
= TREE_CHAIN (dom
))
11190 trees_in::binfo_mergeable (tree
*type
)
11192 *type
= tree_node ();
11196 /* DECL is a just streamed mergeable decl that should match EXISTING. Check
11197 it does and issue an appropriate diagnostic if not. Merge any
11198 bits from DECL to EXISTING. This is stricter matching than
11199 decls_match, because we can rely on ODR-sameness, and we cannot use
11200 decls_match because it can cause instantiations of constraints. */
11203 trees_in::is_matching_decl (tree existing
, tree decl
, bool is_typedef
)
11205 // FIXME: We should probably do some duplicate decl-like stuff here
11206 // (beware, default parms should be the same?) Can we just call
11207 // duplicate_decls and teach it how to handle the module-specific
11208 // permitted/required duplications?
11210 // We know at this point that the decls have matched by key, so we
11211 // can elide some of the checking
11212 gcc_checking_assert (TREE_CODE (existing
) == TREE_CODE (decl
));
11214 tree d_inner
= decl
;
11215 tree e_inner
= existing
;
11216 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
11218 d_inner
= DECL_TEMPLATE_RESULT (d_inner
);
11219 e_inner
= DECL_TEMPLATE_RESULT (e_inner
);
11220 gcc_checking_assert (TREE_CODE (e_inner
) == TREE_CODE (d_inner
));
11223 if (TREE_CODE (d_inner
) == FUNCTION_DECL
)
11225 tree e_ret
= fndecl_declared_return_type (existing
);
11226 tree d_ret
= fndecl_declared_return_type (decl
);
11228 if (decl
!= d_inner
&& DECL_NAME (d_inner
) == fun_identifier
11229 && LAMBDA_TYPE_P (DECL_CONTEXT (d_inner
)))
11230 /* This has a recursive type that will compare different. */;
11231 else if (!same_type_p (d_ret
, e_ret
))
11234 tree e_type
= TREE_TYPE (e_inner
);
11235 tree d_type
= TREE_TYPE (d_inner
);
11237 if (DECL_EXTERN_C_P (d_inner
) != DECL_EXTERN_C_P (e_inner
))
11240 for (tree e_args
= TYPE_ARG_TYPES (e_type
),
11241 d_args
= TYPE_ARG_TYPES (d_type
);
11242 e_args
!= d_args
&& (e_args
|| d_args
);
11243 e_args
= TREE_CHAIN (e_args
), d_args
= TREE_CHAIN (d_args
))
11245 if (!(e_args
&& d_args
))
11248 if (!same_type_p (TREE_VALUE (d_args
), TREE_VALUE (e_args
)))
11251 // FIXME: Check default values
11254 /* If EXISTING has an undeduced or uninstantiated exception
11255 specification, but DECL does not, propagate the exception
11256 specification. Otherwise we end up asserting or trying to
11257 instantiate it in the middle of loading. */
11258 tree e_spec
= TYPE_RAISES_EXCEPTIONS (e_type
);
11259 tree d_spec
= TYPE_RAISES_EXCEPTIONS (d_type
);
11260 if (DEFERRED_NOEXCEPT_SPEC_P (e_spec
))
11262 if (!DEFERRED_NOEXCEPT_SPEC_P (d_spec
)
11263 || (UNEVALUATED_NOEXCEPT_SPEC_P (e_spec
)
11264 && !UNEVALUATED_NOEXCEPT_SPEC_P (d_spec
)))
11266 dump (dumper::MERGE
)
11267 && dump ("Propagating instantiated noexcept to %N", existing
);
11268 TREE_TYPE (existing
) = d_type
;
11270 /* Propagate to existing clones. */
11272 FOR_EACH_CLONE (clone
, existing
)
11274 if (TREE_TYPE (clone
) == e_type
)
11275 TREE_TYPE (clone
) = d_type
;
11278 = build_exception_variant (TREE_TYPE (clone
), d_spec
);
11282 else if (!DEFERRED_NOEXCEPT_SPEC_P (d_spec
)
11283 && !comp_except_specs (d_spec
, e_spec
, ce_type
))
11286 else if (is_typedef
)
11288 if (!DECL_ORIGINAL_TYPE (e_inner
)
11289 || !same_type_p (DECL_ORIGINAL_TYPE (d_inner
),
11290 DECL_ORIGINAL_TYPE (e_inner
)))
11293 /* Using cp_tree_equal because we can meet TYPE_ARGUMENT_PACKs
11294 here. I suspect the entities that directly do that are things
11295 that shouldn't go to duplicate_decls (FIELD_DECLs etc). */
11296 else if (!cp_tree_equal (TREE_TYPE (decl
), TREE_TYPE (existing
)))
11299 if (DECL_IS_UNDECLARED_BUILTIN (existing
))
11300 /* Just like duplicate_decls, presum the user knows what
11301 they're doing in overriding a builtin. */
11302 TREE_TYPE (existing
) = TREE_TYPE (decl
);
11305 // FIXME:QOI Might be template specialization from a module,
11306 // not necessarily global module
11307 error_at (DECL_SOURCE_LOCATION (decl
),
11308 "conflicting global module declaration %#qD", decl
);
11309 inform (DECL_SOURCE_LOCATION (existing
),
11310 "existing declaration %#qD", existing
);
11315 if (DECL_IS_UNDECLARED_BUILTIN (existing
)
11316 && !DECL_IS_UNDECLARED_BUILTIN (decl
))
11318 /* We're matching a builtin that the user has yet to declare.
11319 We are the one! This is very much duplicate-decl
11321 DECL_SOURCE_LOCATION (existing
) = DECL_SOURCE_LOCATION (decl
);
11322 if (TREE_CODE (decl
) != TYPE_DECL
)
11324 /* Propagate exceptions etc. */
11325 TREE_TYPE (existing
) = TREE_TYPE (decl
);
11326 TREE_NOTHROW (existing
) = TREE_NOTHROW (decl
);
11328 /* This is actually an import! */
11329 DECL_MODULE_IMPORT_P (existing
) = true;
11332 existing
->base
= decl
->base
;
11334 if (TREE_CODE (decl
) == FUNCTION_DECL
)
11337 memcpy (&existing
->decl_common
.size
,
11338 &decl
->decl_common
.size
,
11339 (offsetof (tree_decl_common
, pt_uid
)
11340 - offsetof (tree_decl_common
, size
)));
11341 auto bltin_class
= DECL_BUILT_IN_CLASS (decl
);
11342 existing
->function_decl
.built_in_class
= bltin_class
;
11343 auto fncode
= DECL_UNCHECKED_FUNCTION_CODE (decl
);
11344 DECL_UNCHECKED_FUNCTION_CODE (existing
) = fncode
;
11345 if (existing
->function_decl
.built_in_class
== BUILT_IN_NORMAL
)
11347 if (builtin_decl_explicit_p (built_in_function (fncode
)))
11350 case BUILT_IN_STPCPY
:
11351 set_builtin_decl_implicit_p
11352 (built_in_function (fncode
), true);
11355 set_builtin_decl_declared_p
11356 (built_in_function (fncode
), true);
11359 copy_attributes_to_builtin (decl
);
11364 if (VAR_OR_FUNCTION_DECL_P (decl
)
11365 && DECL_TEMPLATE_INSTANTIATED (decl
))
11366 /* Don't instantiate again! */
11367 DECL_TEMPLATE_INSTANTIATED (existing
) = true;
11369 if (TREE_CODE (d_inner
) == FUNCTION_DECL
11370 && DECL_DECLARED_INLINE_P (d_inner
))
11371 DECL_DECLARED_INLINE_P (e_inner
) = true;
11372 if (!DECL_EXTERNAL (d_inner
))
11373 DECL_EXTERNAL (e_inner
) = false;
11375 // FIXME: Check default tmpl and fn parms here
11380 /* FN is an implicit member function that we've discovered is new to
11381 the class. Add it to the TYPE_FIELDS chain and the method vector.
11382 Reset the appropriate classtype lazy flag. */
11385 trees_in::install_implicit_member (tree fn
)
11387 tree ctx
= DECL_CONTEXT (fn
);
11388 tree name
= DECL_NAME (fn
);
11389 /* We know these are synthesized, so the set of expected prototypes
11390 is quite restricted. We're not validating correctness, just
11391 distinguishing beteeen the small set of possibilities. */
11392 tree parm_type
= TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (fn
));
11393 if (IDENTIFIER_CTOR_P (name
))
11395 if (CLASSTYPE_LAZY_DEFAULT_CTOR (ctx
)
11396 && VOID_TYPE_P (parm_type
))
11397 CLASSTYPE_LAZY_DEFAULT_CTOR (ctx
) = false;
11398 else if (!TYPE_REF_P (parm_type
))
11400 else if (CLASSTYPE_LAZY_COPY_CTOR (ctx
)
11401 && !TYPE_REF_IS_RVALUE (parm_type
))
11402 CLASSTYPE_LAZY_COPY_CTOR (ctx
) = false;
11403 else if (CLASSTYPE_LAZY_MOVE_CTOR (ctx
))
11404 CLASSTYPE_LAZY_MOVE_CTOR (ctx
) = false;
11408 else if (IDENTIFIER_DTOR_P (name
))
11410 if (CLASSTYPE_LAZY_DESTRUCTOR (ctx
))
11411 CLASSTYPE_LAZY_DESTRUCTOR (ctx
) = false;
11414 if (DECL_VIRTUAL_P (fn
))
11415 /* A virtual dtor should have been created when the class
11416 became complete. */
11419 else if (name
== assign_op_identifier
)
11421 if (!TYPE_REF_P (parm_type
))
11423 else if (CLASSTYPE_LAZY_COPY_ASSIGN (ctx
)
11424 && !TYPE_REF_IS_RVALUE (parm_type
))
11425 CLASSTYPE_LAZY_COPY_ASSIGN (ctx
) = false;
11426 else if (CLASSTYPE_LAZY_MOVE_ASSIGN (ctx
))
11427 CLASSTYPE_LAZY_MOVE_ASSIGN (ctx
) = false;
11434 dump (dumper::MERGE
) && dump ("Adding implicit member %N", fn
);
11436 DECL_CHAIN (fn
) = TYPE_FIELDS (ctx
);
11437 TYPE_FIELDS (ctx
) = fn
;
11439 add_method (ctx
, fn
, false);
11441 /* Propagate TYPE_FIELDS. */
11442 fixup_type_variants (ctx
);
11447 /* Return non-zero if DECL has a definition that would be interesting to
11451 has_definition (tree decl
)
11453 bool is_tmpl
= TREE_CODE (decl
) == TEMPLATE_DECL
;
11455 decl
= DECL_TEMPLATE_RESULT (decl
);
11457 switch (TREE_CODE (decl
))
11462 case FUNCTION_DECL
:
11463 if (!DECL_SAVED_TREE (decl
))
11467 if (DECL_DECLARED_INLINE_P (decl
))
11470 if (DECL_THIS_STATIC (decl
)
11471 && (header_module_p ()
11472 || (!DECL_LANG_SPECIFIC (decl
) || !DECL_MODULE_PURVIEW_P (decl
))))
11473 /* GM static function. */
11476 if (DECL_TEMPLATE_INFO (decl
))
11478 int use_tpl
= DECL_USE_TEMPLATE (decl
);
11480 // FIXME: Partial specializations have definitions too.
11488 tree type
= TREE_TYPE (decl
);
11489 if (type
== TYPE_MAIN_VARIANT (type
)
11490 && decl
== TYPE_NAME (type
)
11491 && (TREE_CODE (type
) == ENUMERAL_TYPE
11492 ? TYPE_VALUES (type
) : TYPE_FIELDS (type
)))
11498 if (DECL_LANG_SPECIFIC (decl
)
11499 && DECL_TEMPLATE_INFO (decl
))
11500 return DECL_INITIAL (decl
);
11503 if (!DECL_INITIALIZED_P (decl
))
11506 if (header_module_p ()
11507 || (!DECL_LANG_SPECIFIC (decl
) || !DECL_MODULE_PURVIEW_P (decl
)))
11508 /* GM static variable. */
11511 if (!TREE_CONSTANT (decl
))
11519 if (DECL_INITIAL (decl
))
11529 trees_in::find_duplicate (tree existing
)
11534 return duplicates
->get (existing
);
11537 /* We're starting to read a duplicate DECL. EXISTING is the already
11541 trees_in::register_duplicate (tree decl
, tree existing
)
11544 duplicates
= new duplicate_hash_map (40);
11547 uintptr_t &slot
= duplicates
->get_or_insert (existing
, &existed
);
11548 gcc_checking_assert (!existed
);
11549 slot
= reinterpret_cast<uintptr_t> (decl
);
11552 /* We've read a definition of MAYBE_EXISTING. If not a duplicate,
11553 return MAYBE_EXISTING (into which the definition should be
11554 installed). Otherwise return NULL if already known bad, or the
11555 duplicate we read (for ODR checking, or extracting additional merge
11559 trees_in::odr_duplicate (tree maybe_existing
, bool has_defn
)
11561 tree res
= NULL_TREE
;
11563 if (uintptr_t *dup
= find_duplicate (maybe_existing
))
11566 res
= reinterpret_cast<tree
> (*dup
);
11569 res
= maybe_existing
;
11571 assert_definition (maybe_existing
, res
&& !has_defn
);
11573 // FIXME: We probably need to return the template, so that the
11574 // template header can be checked?
11575 return res
? STRIP_TEMPLATE (res
) : NULL_TREE
;
11578 /* The following writer functions rely on the current behaviour of
11579 depset::hash::add_dependency making the decl and defn depset nodes
11580 depend on eachother. That way we don't have to worry about seeding
11581 the tree map with named decls that cannot be looked up by name (I.e
11582 template and function parms). We know the decl and definition will
11583 be in the same cluster, which is what we want. */
11586 trees_out::write_function_def (tree decl
)
11588 tree_node (DECL_RESULT (decl
));
11589 tree_node (DECL_INITIAL (decl
));
11590 tree_node (DECL_SAVED_TREE (decl
));
11591 tree_node (DECL_FRIEND_CONTEXT (decl
));
11593 constexpr_fundef
*cexpr
= retrieve_constexpr_fundef (decl
);
11595 if (streaming_p ())
11596 u (cexpr
!= nullptr);
11599 chained_decls (cexpr
->parms
);
11600 tree_node (cexpr
->result
);
11601 tree_node (cexpr
->body
);
11604 if (streaming_p ())
11606 unsigned flags
= 0;
11608 if (DECL_NOT_REALLY_EXTERN (decl
))
11616 trees_out::mark_function_def (tree
)
11621 trees_in::read_function_def (tree decl
, tree maybe_template
)
11623 dump () && dump ("Reading function definition %N", decl
);
11624 tree result
= tree_node ();
11625 tree initial
= tree_node ();
11626 tree saved
= tree_node ();
11627 tree context
= tree_node ();
11628 constexpr_fundef cexpr
;
11630 tree maybe_dup
= odr_duplicate (maybe_template
, DECL_SAVED_TREE (decl
));
11631 bool installing
= maybe_dup
&& !DECL_SAVED_TREE (decl
);
11635 cexpr
.parms
= chained_decls ();
11636 cexpr
.result
= tree_node ();
11637 cexpr
.body
= tree_node ();
11641 cexpr
.decl
= NULL_TREE
;
11643 unsigned flags
= u ();
11645 if (get_overrun ())
11650 DECL_NOT_REALLY_EXTERN (decl
) = flags
& 1;
11651 DECL_RESULT (decl
) = result
;
11652 DECL_INITIAL (decl
) = initial
;
11653 DECL_SAVED_TREE (decl
) = saved
;
11655 DECL_ARGUMENTS (decl
) = DECL_ARGUMENTS (maybe_dup
);
11658 SET_DECL_FRIEND_CONTEXT (decl
, context
);
11660 register_constexpr_fundef (cexpr
);
11661 post_process (maybe_template
);
11663 else if (maybe_dup
)
11665 // FIXME:QOI Check matching defn
11671 /* Also for CONCEPT_DECLs. */
11674 trees_out::write_var_def (tree decl
)
11676 tree init
= DECL_INITIAL (decl
);
11680 tree dyn_init
= NULL_TREE
;
11682 if (DECL_NONTRIVIALLY_INITIALIZED_P (decl
))
11684 dyn_init
= value_member (decl
,
11685 CP_DECL_THREAD_LOCAL_P (decl
)
11686 ? tls_aggregates
: static_aggregates
);
11687 gcc_checking_assert (dyn_init
);
11688 /* Mark it so write_inits knows this is needed. */
11689 TREE_LANG_FLAG_0 (dyn_init
) = true;
11690 dyn_init
= TREE_PURPOSE (dyn_init
);
11692 tree_node (dyn_init
);
11697 trees_out::mark_var_def (tree
)
11702 trees_in::read_var_def (tree decl
, tree maybe_template
)
11704 /* Do not mark the virtual table entries as used. */
11705 bool vtable
= TREE_CODE (decl
) == VAR_DECL
&& DECL_VTABLE_OR_VTT_P (decl
);
11707 tree init
= tree_node ();
11708 tree dyn_init
= init
? NULL_TREE
: tree_node ();
11711 if (get_overrun ())
11714 bool initialized
= (VAR_P (decl
) ? bool (DECL_INITIALIZED_P (decl
))
11715 : bool (DECL_INITIAL (decl
)));
11716 tree maybe_dup
= odr_duplicate (maybe_template
, initialized
);
11717 bool installing
= maybe_dup
&& !initialized
;
11720 if (DECL_EXTERNAL (decl
))
11721 DECL_NOT_REALLY_EXTERN (decl
) = true;
11724 DECL_INITIALIZED_P (decl
) = true;
11725 if (maybe_dup
&& DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (maybe_dup
))
11726 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
11728 DECL_INITIAL (decl
) = init
;
11731 else if (CP_DECL_THREAD_LOCAL_P (decl
))
11732 tls_aggregates
= tree_cons (dyn_init
, decl
, tls_aggregates
);
11734 static_aggregates
= tree_cons (dyn_init
, decl
, static_aggregates
);
11736 else if (maybe_dup
)
11738 // FIXME:QOI Check matching defn
11744 /* If MEMBER doesn't have an independent life outside the class,
11745 return it (or its TEMPLATE_DECL). Otherwise NULL. */
11748 member_owned_by_class (tree member
)
11750 gcc_assert (DECL_P (member
));
11752 /* Clones are owned by their origin. */
11753 if (DECL_CLONED_FUNCTION_P (member
))
11756 if (TREE_CODE (member
) == FIELD_DECL
)
11757 /* FIELD_DECLS can have template info in some cases. We always
11758 want the FIELD_DECL though, as there's never a TEMPLATE_DECL
11763 if (tree ti
= node_template_info (member
, use_tpl
))
11765 // FIXME: Don't bail on things that CANNOT have their own
11766 // template header. No, make sure they're in the same cluster.
11770 if (DECL_TEMPLATE_RESULT (TI_TEMPLATE (ti
)) == member
)
11771 member
= TI_TEMPLATE (ti
);
11777 trees_out::write_class_def (tree defn
)
11779 gcc_assert (DECL_P (defn
));
11780 if (streaming_p ())
11781 dump () && dump ("Writing class definition %N", defn
);
11783 tree type
= TREE_TYPE (defn
);
11784 tree_node (TYPE_SIZE (type
));
11785 tree_node (TYPE_SIZE_UNIT (type
));
11786 tree_node (TYPE_VFIELD (type
));
11787 tree_node (TYPE_BINFO (type
));
11789 vec_chained_decls (TYPE_FIELDS (type
));
11791 /* Every class but __as_base has a type-specific. */
11792 gcc_checking_assert (!TYPE_LANG_SPECIFIC (type
) == IS_FAKE_BASE_TYPE (type
));
11794 if (TYPE_LANG_SPECIFIC (type
))
11797 vec
<tree
, va_gc
> *v
= CLASSTYPE_MEMBER_VEC (type
);
11800 gcc_checking_assert (!streaming_p ());
11801 /* Force a class vector. */
11802 v
= set_class_bindings (type
, -1);
11803 gcc_checking_assert (v
);
11806 unsigned len
= v
->length ();
11807 if (streaming_p ())
11809 for (unsigned ix
= 0; ix
!= len
; ix
++)
11812 if (TREE_CODE (m
) == TYPE_DECL
11813 && DECL_ARTIFICIAL (m
)
11814 && TYPE_STUB_DECL (TREE_TYPE (m
)) == m
)
11815 /* This is a using-decl for a type, or an anonymous
11816 struct (maybe with a typedef name). Write the type. */
11821 tree_node (CLASSTYPE_LAMBDA_EXPR (type
));
11823 /* TYPE_CONTAINS_VPTR_P looks at the vbase vector, which the
11824 reader won't know at this point. */
11825 int has_vptr
= TYPE_CONTAINS_VPTR_P (type
);
11827 if (streaming_p ())
11829 unsigned nvbases
= vec_safe_length (CLASSTYPE_VBASECLASSES (type
));
11836 tree_vec (CLASSTYPE_PURE_VIRTUALS (type
));
11837 tree_pair_vec (CLASSTYPE_VCALL_INDICES (type
));
11838 tree_node (CLASSTYPE_KEY_METHOD (type
));
11842 if (TYPE_LANG_SPECIFIC (type
))
11844 tree_node (CLASSTYPE_PRIMARY_BINFO (type
));
11846 tree as_base
= CLASSTYPE_AS_BASE (type
);
11848 as_base
= TYPE_NAME (as_base
);
11849 tree_node (as_base
);
11851 /* Write the vtables. */
11852 tree vtables
= CLASSTYPE_VTABLES (type
);
11853 vec_chained_decls (vtables
);
11854 for (; vtables
; vtables
= TREE_CHAIN (vtables
))
11855 write_definition (vtables
);
11857 /* Write the friend classes. */
11858 tree_list (CLASSTYPE_FRIEND_CLASSES (type
), false);
11860 /* Write the friend functions. */
11861 for (tree friends
= DECL_FRIENDLIST (defn
);
11862 friends
; friends
= TREE_CHAIN (friends
))
11864 /* Name of these friends. */
11865 tree_node (TREE_PURPOSE (friends
));
11866 tree_list (TREE_VALUE (friends
), false);
11868 /* End of friend fns. */
11869 tree_node (NULL_TREE
);
11871 /* Write the decl list. */
11872 tree_list (CLASSTYPE_DECL_LIST (type
), true);
11874 if (TYPE_CONTAINS_VPTR_P (type
))
11876 /* Write the thunks. */
11877 for (tree decls
= TYPE_FIELDS (type
);
11878 decls
; decls
= DECL_CHAIN (decls
))
11879 if (TREE_CODE (decls
) == FUNCTION_DECL
11880 && DECL_VIRTUAL_P (decls
)
11881 && DECL_THUNKS (decls
))
11884 /* Thunks are always unique, so chaining is ok. */
11885 chained_decls (DECL_THUNKS (decls
));
11887 tree_node (NULL_TREE
);
11893 trees_out::mark_class_member (tree member
, bool do_defn
)
11895 gcc_assert (DECL_P (member
));
11897 member
= member_owned_by_class (member
);
11899 mark_declaration (member
, do_defn
&& has_definition (member
));
11903 trees_out::mark_class_def (tree defn
)
11905 gcc_assert (DECL_P (defn
));
11906 tree type
= TREE_TYPE (defn
);
11907 /* Mark the class members that are not type-decls and cannot have
11908 independent definitions. */
11909 for (tree member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
11910 if (TREE_CODE (member
) == FIELD_DECL
11911 || TREE_CODE (member
) == USING_DECL
11912 /* A cloned enum-decl from 'using enum unrelated;' */
11913 || (TREE_CODE (member
) == CONST_DECL
11914 && DECL_CONTEXT (member
) == type
))
11916 mark_class_member (member
);
11917 if (TREE_CODE (member
) == FIELD_DECL
)
11918 if (tree repr
= DECL_BIT_FIELD_REPRESENTATIVE (member
))
11919 /* If we're marking a class template definition, then
11920 this'll contain the width (as set by grokbitfield)
11921 instead of a decl. */
11923 mark_declaration (repr
, false);
11926 /* Mark the binfo hierarchy. */
11927 for (tree child
= TYPE_BINFO (type
); child
; child
= TREE_CHAIN (child
))
11928 mark_by_value (child
);
11930 if (TYPE_LANG_SPECIFIC (type
))
11932 for (tree vtable
= CLASSTYPE_VTABLES (type
);
11933 vtable
; vtable
= TREE_CHAIN (vtable
))
11934 mark_declaration (vtable
, true);
11936 if (TYPE_CONTAINS_VPTR_P (type
))
11937 /* Mark the thunks, they belong to the class definition,
11938 /not/ the thunked-to function. */
11939 for (tree decls
= TYPE_FIELDS (type
);
11940 decls
; decls
= DECL_CHAIN (decls
))
11941 if (TREE_CODE (decls
) == FUNCTION_DECL
)
11942 for (tree thunks
= DECL_THUNKS (decls
);
11943 thunks
; thunks
= DECL_CHAIN (thunks
))
11944 mark_declaration (thunks
, false);
11948 /* Nop sorting, needed for resorting the member vec. */
11951 nop (void *, void *, void *)
11956 trees_in::read_class_def (tree defn
, tree maybe_template
)
11958 gcc_assert (DECL_P (defn
));
11959 dump () && dump ("Reading class definition %N", defn
);
11960 tree type
= TREE_TYPE (defn
);
11961 tree size
= tree_node ();
11962 tree size_unit
= tree_node ();
11963 tree vfield
= tree_node ();
11964 tree binfo
= tree_node ();
11965 vec
<tree
, va_gc
> *vbase_vec
= NULL
;
11966 vec
<tree
, va_gc
> *member_vec
= NULL
;
11967 vec
<tree
, va_gc
> *pure_virts
= NULL
;
11968 vec
<tree_pair_s
, va_gc
> *vcall_indices
= NULL
;
11969 tree key_method
= NULL_TREE
;
11970 tree lambda
= NULL_TREE
;
11972 /* Read the fields. */
11973 vec
<tree
, va_heap
> *fields
= vec_chained_decls ();
11975 if (TYPE_LANG_SPECIFIC (type
))
11977 if (unsigned len
= u ())
11979 vec_alloc (member_vec
, len
);
11980 for (unsigned ix
= 0; ix
!= len
; ix
++)
11982 tree m
= tree_node ();
11983 if (get_overrun ())
11986 m
= TYPE_STUB_DECL (m
);
11987 member_vec
->quick_push (m
);
11990 lambda
= tree_node ();
11992 if (!get_overrun ())
11994 unsigned nvbases
= u ();
11997 vec_alloc (vbase_vec
, nvbases
);
11998 for (tree child
= binfo
; child
; child
= TREE_CHAIN (child
))
11999 if (BINFO_VIRTUAL_P (child
))
12000 vbase_vec
->quick_push (child
);
12004 if (!get_overrun ())
12006 int has_vptr
= i ();
12009 pure_virts
= tree_vec ();
12010 vcall_indices
= tree_pair_vec ();
12011 key_method
= tree_node ();
12016 tree maybe_dup
= odr_duplicate (maybe_template
, TYPE_SIZE (type
));
12017 bool installing
= maybe_dup
&& !TYPE_SIZE (type
);
12020 if (DECL_EXTERNAL (defn
) && TYPE_LANG_SPECIFIC (type
))
12022 /* We don't deal with not-really-extern, because, for a
12023 module you want the import to be the interface, and for a
12024 header-unit, you're doing it wrong. */
12025 CLASSTYPE_INTERFACE_UNKNOWN (type
) = false;
12026 CLASSTYPE_INTERFACE_ONLY (type
) = true;
12029 if (maybe_dup
!= defn
)
12031 // FIXME: This is needed on other defns too, almost
12032 // duplicate-decl like? See is_matching_decl too.
12033 /* Copy flags from the duplicate. */
12034 tree type_dup
= TREE_TYPE (maybe_dup
);
12037 TYPE_MODE_RAW (type
) = TYPE_MODE_RAW (type_dup
);
12038 SET_DECL_MODE (defn
, DECL_MODE (maybe_dup
));
12039 TREE_ADDRESSABLE (type
) = TREE_ADDRESSABLE (type_dup
);
12040 DECL_SIZE (defn
) = DECL_SIZE (maybe_dup
);
12041 DECL_SIZE_UNIT (defn
) = DECL_SIZE_UNIT (maybe_dup
);
12042 DECL_ALIGN_RAW (defn
) = DECL_ALIGN_RAW (maybe_dup
);
12043 DECL_WARN_IF_NOT_ALIGN_RAW (defn
)
12044 = DECL_WARN_IF_NOT_ALIGN_RAW (maybe_dup
);
12045 DECL_USER_ALIGN (defn
) = DECL_USER_ALIGN (maybe_dup
);
12048 TYPE_POLYMORPHIC_P (type
) = TYPE_POLYMORPHIC_P (type_dup
);
12049 TYPE_HAS_USER_CONSTRUCTOR (type
)
12050 = TYPE_HAS_USER_CONSTRUCTOR (type_dup
);
12051 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
12052 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type_dup
);
12054 if (auto ls
= TYPE_LANG_SPECIFIC (type_dup
))
12056 if (TYPE_LANG_SPECIFIC (type
))
12058 CLASSTYPE_BEFRIENDING_CLASSES (type_dup
)
12059 = CLASSTYPE_BEFRIENDING_CLASSES (type
);
12060 if (!ANON_AGGR_TYPE_P (type
))
12061 CLASSTYPE_TYPEINFO_VAR (type_dup
)
12062 = CLASSTYPE_TYPEINFO_VAR (type
);
12064 for (tree v
= type
; v
; v
= TYPE_NEXT_VARIANT (v
))
12065 TYPE_LANG_SPECIFIC (v
) = ls
;
12069 TYPE_SIZE (type
) = size
;
12070 TYPE_SIZE_UNIT (type
) = size_unit
;
12074 tree
*chain
= &TYPE_FIELDS (type
);
12075 unsigned len
= fields
->length ();
12076 for (unsigned ix
= 0; ix
!= len
; ix
++)
12078 tree decl
= (*fields
)[ix
];
12082 /* An anonymous struct with typedef name. */
12083 tree tdef
= (*fields
)[ix
+1];
12084 decl
= TYPE_STUB_DECL (TREE_TYPE (tdef
));
12085 gcc_checking_assert (IDENTIFIER_ANON_P (DECL_NAME (decl
))
12089 gcc_checking_assert (!*chain
== !DECL_CLONED_FUNCTION_P (decl
));
12091 chain
= &DECL_CHAIN (decl
);
12093 if (TREE_CODE (decl
) == FIELD_DECL
12094 && ANON_AGGR_TYPE_P (TREE_TYPE (decl
)))
12095 ANON_AGGR_TYPE_FIELD
12096 (TYPE_MAIN_VARIANT (TREE_TYPE (decl
))) = decl
;
12098 if (TREE_CODE (decl
) == USING_DECL
12099 && TREE_CODE (USING_DECL_SCOPE (decl
)) == RECORD_TYPE
)
12101 /* Reconstruct DECL_ACCESS. */
12102 tree decls
= USING_DECL_DECLS (decl
);
12103 tree access
= declared_access (decl
);
12105 for (ovl_iterator
iter (decls
); iter
; ++iter
)
12109 retrofit_lang_decl (d
);
12110 tree list
= DECL_ACCESS (d
);
12112 if (!purpose_member (type
, list
))
12113 DECL_ACCESS (d
) = tree_cons (type
, access
, list
);
12119 TYPE_VFIELD (type
) = vfield
;
12120 TYPE_BINFO (type
) = binfo
;
12122 if (TYPE_LANG_SPECIFIC (type
))
12124 CLASSTYPE_LAMBDA_EXPR (type
) = lambda
;
12126 CLASSTYPE_MEMBER_VEC (type
) = member_vec
;
12127 CLASSTYPE_PURE_VIRTUALS (type
) = pure_virts
;
12128 CLASSTYPE_VCALL_INDICES (type
) = vcall_indices
;
12130 CLASSTYPE_KEY_METHOD (type
) = key_method
;
12132 CLASSTYPE_VBASECLASSES (type
) = vbase_vec
;
12134 /* Resort the member vector. */
12135 resort_type_member_vec (member_vec
, NULL
, nop
, NULL
);
12138 else if (maybe_dup
)
12140 // FIXME:QOI Check matching defn
12143 if (TYPE_LANG_SPECIFIC (type
))
12145 tree primary
= tree_node ();
12146 tree as_base
= tree_node ();
12149 as_base
= TREE_TYPE (as_base
);
12151 /* Read the vtables. */
12152 vec
<tree
, va_heap
> *vtables
= vec_chained_decls ();
12155 unsigned len
= vtables
->length ();
12156 for (unsigned ix
= 0; ix
!= len
; ix
++)
12158 tree vtable
= (*vtables
)[ix
];
12159 read_var_def (vtable
, vtable
);
12163 tree friend_classes
= tree_list (false);
12164 tree friend_functions
= NULL_TREE
;
12165 for (tree
*chain
= &friend_functions
;
12166 tree name
= tree_node (); chain
= &TREE_CHAIN (*chain
))
12168 tree val
= tree_list (false);
12169 *chain
= build_tree_list (name
, val
);
12171 tree decl_list
= tree_list (true);
12175 CLASSTYPE_PRIMARY_BINFO (type
) = primary
;
12176 CLASSTYPE_AS_BASE (type
) = as_base
;
12180 if (!CLASSTYPE_KEY_METHOD (type
)
12181 /* Sneaky user may have defined it inline
12183 || DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (type
)))
12184 vec_safe_push (keyed_classes
, type
);
12185 unsigned len
= vtables
->length ();
12186 tree
*chain
= &CLASSTYPE_VTABLES (type
);
12187 for (unsigned ix
= 0; ix
!= len
; ix
++)
12189 tree vtable
= (*vtables
)[ix
];
12190 gcc_checking_assert (!*chain
);
12192 chain
= &DECL_CHAIN (vtable
);
12195 CLASSTYPE_FRIEND_CLASSES (type
) = friend_classes
;
12196 DECL_FRIENDLIST (defn
) = friend_functions
;
12197 CLASSTYPE_DECL_LIST (type
) = decl_list
;
12199 for (; friend_classes
; friend_classes
= TREE_CHAIN (friend_classes
))
12201 tree f
= TREE_VALUE (friend_classes
);
12203 if (CLASS_TYPE_P (f
))
12205 CLASSTYPE_BEFRIENDING_CLASSES (f
)
12206 = tree_cons (NULL_TREE
, type
,
12207 CLASSTYPE_BEFRIENDING_CLASSES (f
));
12208 dump () && dump ("Class %N befriending %C:%N",
12209 type
, TREE_CODE (f
), f
);
12213 for (; friend_functions
;
12214 friend_functions
= TREE_CHAIN (friend_functions
))
12215 for (tree friend_decls
= TREE_VALUE (friend_functions
);
12216 friend_decls
; friend_decls
= TREE_CHAIN (friend_decls
))
12218 tree f
= TREE_VALUE (friend_decls
);
12220 DECL_BEFRIENDING_CLASSES (f
)
12221 = tree_cons (NULL_TREE
, type
, DECL_BEFRIENDING_CLASSES (f
));
12222 dump () && dump ("Class %N befriending %C:%N",
12223 type
, TREE_CODE (f
), f
);
12227 if (TYPE_CONTAINS_VPTR_P (type
))
12228 /* Read and install the thunks. */
12229 while (tree vfunc
= tree_node ())
12231 tree thunks
= chained_decls ();
12233 SET_DECL_THUNKS (vfunc
, thunks
);
12236 vec_free (vtables
);
12239 /* Propagate to all variants. */
12241 fixup_type_variants (type
);
12243 /* IS_FAKE_BASE_TYPE is inaccurate at this point, because if this is
12244 the fake base, we've not hooked it into the containing class's
12245 data structure yet. Fortunately it has a unique name. */
12247 && DECL_NAME (defn
) != as_base_identifier
12248 && (!CLASSTYPE_TEMPLATE_INFO (type
)
12249 || !uses_template_parms (TI_ARGS (CLASSTYPE_TEMPLATE_INFO (type
)))))
12250 /* Emit debug info. It'd be nice to know if the interface TU
12251 already emitted this. */
12252 rest_of_type_compilation (type
, !LOCAL_CLASS_P (type
));
12256 return !get_overrun ();
12260 trees_out::write_enum_def (tree decl
)
12262 tree type
= TREE_TYPE (decl
);
12264 tree_node (TYPE_VALUES (type
));
12265 /* Note that we stream TYPE_MIN/MAX_VALUE directly as part of the
12270 trees_out::mark_enum_def (tree decl
)
12272 tree type
= TREE_TYPE (decl
);
12274 for (tree values
= TYPE_VALUES (type
); values
; values
= TREE_CHAIN (values
))
12276 tree cst
= TREE_VALUE (values
);
12277 mark_by_value (cst
);
12278 /* We must mark the init to avoid circularity in tt_enum_int. */
12279 if (tree init
= DECL_INITIAL (cst
))
12280 if (TREE_CODE (init
) == INTEGER_CST
)
12281 mark_by_value (init
);
12286 trees_in::read_enum_def (tree defn
, tree maybe_template
)
12288 tree type
= TREE_TYPE (defn
);
12289 tree values
= tree_node ();
12291 if (get_overrun ())
12294 tree maybe_dup
= odr_duplicate (maybe_template
, TYPE_VALUES (type
));
12295 bool installing
= maybe_dup
&& !TYPE_VALUES (type
);
12299 TYPE_VALUES (type
) = values
;
12300 /* Note that we stream TYPE_MIN/MAX_VALUE directly as part of the
12303 rest_of_type_compilation (type
, DECL_NAMESPACE_SCOPE_P (defn
));
12305 else if (maybe_dup
)
12307 tree known
= TYPE_VALUES (type
);
12308 for (; known
&& values
;
12309 known
= TREE_CHAIN (known
), values
= TREE_CHAIN (values
))
12311 tree known_decl
= TREE_VALUE (known
);
12312 tree new_decl
= TREE_VALUE (values
);
12314 if (DECL_NAME (known_decl
) != DECL_NAME (new_decl
))
12317 new_decl
= maybe_duplicate (new_decl
);
12319 if (!cp_tree_equal (DECL_INITIAL (known_decl
),
12320 DECL_INITIAL (new_decl
)))
12324 if (known
|| values
)
12326 error_at (DECL_SOURCE_LOCATION (maybe_dup
),
12327 "definition of %qD does not match", maybe_dup
);
12328 inform (DECL_SOURCE_LOCATION (defn
),
12329 "existing definition %qD", defn
);
12331 tree known_decl
= NULL_TREE
, new_decl
= NULL_TREE
;
12334 known_decl
= TREE_VALUE (known
);
12336 new_decl
= maybe_duplicate (TREE_VALUE (values
));
12338 if (known_decl
&& new_decl
)
12340 inform (DECL_SOURCE_LOCATION (new_decl
),
12341 "... this enumerator %qD", new_decl
);
12342 inform (DECL_SOURCE_LOCATION (known_decl
),
12343 "enumerator %qD does not match ...", known_decl
);
12345 else if (known_decl
|| new_decl
)
12347 tree extra
= known_decl
? known_decl
: new_decl
;
12348 inform (DECL_SOURCE_LOCATION (extra
),
12349 "additional enumerators beginning with %qD", extra
);
12352 inform (DECL_SOURCE_LOCATION (maybe_dup
),
12353 "enumeration range differs");
12356 unmatched_duplicate (maybe_template
);
12363 /* Write out the body of DECL. See above circularity note. */
12366 trees_out::write_definition (tree decl
)
12368 if (streaming_p ())
12370 assert_definition (decl
);
12372 && dump ("Writing definition %C:%N", TREE_CODE (decl
), decl
);
12375 dump (dumper::DEPEND
)
12376 && dump ("Depending definition %C:%N", TREE_CODE (decl
), decl
);
12379 switch (TREE_CODE (decl
))
12382 gcc_unreachable ();
12384 case TEMPLATE_DECL
:
12385 decl
= DECL_TEMPLATE_RESULT (decl
);
12388 case FUNCTION_DECL
:
12389 write_function_def (decl
);
12394 tree type
= TREE_TYPE (decl
);
12395 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
12396 && TYPE_NAME (type
) == decl
);
12397 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
12398 write_enum_def (decl
);
12400 write_class_def (decl
);
12406 write_var_def (decl
);
12411 /* Mark a declaration for by-value walking. If DO_DEFN is true, mark
12415 trees_out::mark_declaration (tree decl
, bool do_defn
)
12417 mark_by_value (decl
);
12419 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
12420 decl
= DECL_TEMPLATE_RESULT (decl
);
12425 switch (TREE_CODE (decl
))
12428 gcc_unreachable ();
12430 case FUNCTION_DECL
:
12431 mark_function_def (decl
);
12436 tree type
= TREE_TYPE (decl
);
12437 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
12438 && TYPE_NAME (type
) == decl
);
12439 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
12440 mark_enum_def (decl
);
12442 mark_class_def (decl
);
12448 mark_var_def (decl
);
12453 /* Read in the body of DECL. See above circularity note. */
12456 trees_in::read_definition (tree decl
)
12458 dump () && dump ("Reading definition %C %N", TREE_CODE (decl
), decl
);
12460 tree maybe_template
= decl
;
12463 switch (TREE_CODE (decl
))
12468 case TEMPLATE_DECL
:
12469 decl
= DECL_TEMPLATE_RESULT (decl
);
12472 case FUNCTION_DECL
:
12473 return read_function_def (decl
, maybe_template
);
12477 tree type
= TREE_TYPE (decl
);
12478 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
12479 && TYPE_NAME (type
) == decl
);
12480 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
12481 return read_enum_def (decl
, maybe_template
);
12483 return read_class_def (decl
, maybe_template
);
12489 return read_var_def (decl
, maybe_template
);
12495 /* Lookup an maybe insert a slot for depset for KEY. */
12498 depset::hash::entity_slot (tree entity
, bool insert
)
12500 traits::compare_type
key (entity
, NULL
);
12501 depset
**slot
= find_slot_with_hash (key
, traits::hash (key
),
12502 insert
? INSERT
: NO_INSERT
);
12508 depset::hash::binding_slot (tree ctx
, tree name
, bool insert
)
12510 traits::compare_type
key (ctx
, name
);
12511 depset
**slot
= find_slot_with_hash (key
, traits::hash (key
),
12512 insert
? INSERT
: NO_INSERT
);
12518 depset::hash::find_dependency (tree decl
)
12520 depset
**slot
= entity_slot (decl
, false);
12522 return slot
? *slot
: NULL
;
12526 depset::hash::find_binding (tree ctx
, tree name
)
12528 depset
**slot
= binding_slot (ctx
, name
, false);
12530 return slot
? *slot
: NULL
;
12533 /* DECL is a newly discovered dependency. Create the depset, if it
12534 doesn't already exist. Add it to the worklist if so.
12536 DECL will be an OVL_USING_P OVERLOAD, if it's from a binding that's
12539 We do not have to worry about adding the same dependency more than
12540 once. First it's harmless, but secondly the TREE_VISITED marking
12541 prevents us wanting to do it anyway. */
12544 depset::hash::make_dependency (tree decl
, entity_kind ek
)
12546 /* Make sure we're being told consistent information. */
12547 gcc_checking_assert ((ek
== EK_NAMESPACE
)
12548 == (TREE_CODE (decl
) == NAMESPACE_DECL
12549 && !DECL_NAMESPACE_ALIAS (decl
)));
12550 gcc_checking_assert (ek
!= EK_BINDING
&& ek
!= EK_REDIRECT
);
12551 gcc_checking_assert (TREE_CODE (decl
) != FIELD_DECL
12552 && (TREE_CODE (decl
) != USING_DECL
12553 || TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
));
12554 gcc_checking_assert (!is_key_order ());
12555 if (ek
== EK_USING
)
12556 gcc_checking_assert (TREE_CODE (decl
) == OVERLOAD
);
12558 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
12559 /* The template should have copied these from its result decl. */
12560 gcc_checking_assert (DECL_MODULE_EXPORT_P (decl
)
12561 == DECL_MODULE_EXPORT_P (DECL_TEMPLATE_RESULT (decl
)));
12563 depset
**slot
= entity_slot (decl
, true);
12564 depset
*dep
= *slot
;
12565 bool for_binding
= ek
== EK_FOR_BINDING
;
12569 if ((DECL_IMPLICIT_TYPEDEF_P (decl
)
12570 /* ... not an enum, for instance. */
12571 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl
))
12572 && TYPE_LANG_SPECIFIC (TREE_TYPE (decl
))
12573 && CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl
)) == 2)
12575 && DECL_LANG_SPECIFIC (decl
)
12576 && DECL_USE_TEMPLATE (decl
) == 2))
12578 /* A partial or explicit specialization. Partial
12579 specializations might not be in the hash table, because
12580 there can be multiple differently-constrained variants.
12582 template<typename T> class silly;
12583 template<typename T> requires true class silly {};
12585 We need to find them, insert their TEMPLATE_DECL in the
12586 dep_hash, and then convert the dep we just found into a
12589 tree ti
= get_template_info (decl
);
12590 tree tmpl
= TI_TEMPLATE (ti
);
12591 tree partial
= NULL_TREE
;
12592 for (tree spec
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
12593 spec
; spec
= TREE_CHAIN (spec
))
12594 if (DECL_TEMPLATE_RESULT (TREE_VALUE (spec
)) == decl
)
12596 partial
= TREE_VALUE (spec
);
12602 /* Eagerly create an empty redirect. The following
12603 make_dependency call could cause hash reallocation,
12604 and invalidate slot's value. */
12605 depset
*redirect
= make_entity (decl
, EK_REDIRECT
);
12607 /* Redirects are never reached -- always snap to their target. */
12608 redirect
->set_flag_bit
<DB_UNREACHED_BIT
> ();
12612 depset
*tmpl_dep
= make_dependency (partial
, EK_PARTIAL
);
12613 gcc_checking_assert (tmpl_dep
->get_entity_kind () == EK_PARTIAL
);
12615 redirect
->deps
.safe_push (tmpl_dep
);
12621 bool has_def
= ek
!= EK_USING
&& has_definition (decl
);
12622 if (ek
> EK_BINDING
)
12625 /* The only OVERLOADS we should see are USING decls from
12627 *slot
= dep
= make_entity (decl
, ek
, has_def
);
12629 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
12631 if (DECL_ALIAS_TEMPLATE_P (decl
) && DECL_TEMPLATE_INFO (decl
))
12632 dep
->set_flag_bit
<DB_ALIAS_TMPL_INST_BIT
> ();
12633 else if (CHECKING_P
)
12634 /* The template_result should otherwise not be in the
12635 table, or be an empty redirect (created above). */
12636 if (auto *eslot
= entity_slot (DECL_TEMPLATE_RESULT (decl
), false))
12637 gcc_checking_assert ((*eslot
)->get_entity_kind () == EK_REDIRECT
12638 && !(*eslot
)->deps
.length ());
12641 if (ek
!= EK_USING
)
12643 tree not_tmpl
= STRIP_TEMPLATE (decl
);
12645 if (DECL_LANG_SPECIFIC (not_tmpl
)
12646 && DECL_MODULE_IMPORT_P (not_tmpl
))
12648 /* Store the module number and index in cluster/section,
12649 so we don't have to look them up again. */
12650 unsigned index
= import_entity_index (decl
);
12651 module_state
*from
= import_entity_module (index
);
12652 /* Remap will be zero for imports from partitions, which
12653 we want to treat as-if declared in this TU. */
12656 dep
->cluster
= index
- from
->entity_lwm
;
12657 dep
->section
= from
->remap
;
12658 dep
->set_flag_bit
<DB_IMPORTED_BIT
> ();
12663 && !dep
->is_import ()
12664 && TREE_CODE (CP_DECL_CONTEXT (decl
)) == NAMESPACE_DECL
12665 && !(TREE_CODE (decl
) == TEMPLATE_DECL
12666 && DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (decl
)))
12668 tree ctx
= CP_DECL_CONTEXT (decl
);
12670 if (!TREE_PUBLIC (ctx
))
12671 /* Member of internal namespace. */
12672 dep
->set_flag_bit
<DB_IS_INTERNAL_BIT
> ();
12673 else if (VAR_OR_FUNCTION_DECL_P (not_tmpl
)
12674 && DECL_THIS_STATIC (not_tmpl
))
12676 /* An internal decl. This is ok in a GM entity. */
12677 if (!(header_module_p ()
12678 || !DECL_LANG_SPECIFIC (not_tmpl
)
12679 || !DECL_MODULE_PURVIEW_P (not_tmpl
)))
12680 dep
->set_flag_bit
<DB_IS_INTERNAL_BIT
> ();
12685 if (!dep
->is_import ())
12686 worklist
.safe_push (dep
);
12689 dump (dumper::DEPEND
)
12690 && dump ("%s on %s %C:%N found",
12691 ek
== EK_REDIRECT
? "Redirect"
12692 : for_binding
? "Binding" : "Dependency",
12693 dep
->entity_kind_name (), TREE_CODE (decl
), decl
);
12698 /* DEP is a newly discovered dependency. Append it to current's
12702 depset::hash::add_dependency (depset
*dep
)
12704 gcc_checking_assert (current
&& !is_key_order ());
12705 current
->deps
.safe_push (dep
);
12707 if (dep
->is_internal () && !current
->is_internal ())
12708 current
->set_flag_bit
<DB_REFS_INTERNAL_BIT
> ();
12710 if (current
->get_entity_kind () == EK_USING
12711 && DECL_IMPLICIT_TYPEDEF_P (dep
->get_entity ())
12712 && TREE_CODE (TREE_TYPE (dep
->get_entity ())) == ENUMERAL_TYPE
)
12714 /* CURRENT is an unwrapped using-decl and DECL is an enum's
12715 implicit typedef. Is CURRENT a member of the enum? */
12716 tree c_decl
= OVL_FUNCTION (current
->get_entity ());
12718 if (TREE_CODE (c_decl
) == CONST_DECL
12719 && (current
->deps
[0]->get_entity ()
12720 == CP_DECL_CONTEXT (dep
->get_entity ())))
12721 /* Make DECL depend on CURRENT. */
12722 dep
->deps
.safe_push (current
);
12725 if (dep
->is_unreached ())
12727 /* The dependency is reachable now. */
12728 reached_unreached
= true;
12729 dep
->clear_flag_bit
<DB_UNREACHED_BIT
> ();
12730 dump (dumper::DEPEND
)
12731 && dump ("Reaching unreached %s %C:%N", dep
->entity_kind_name (),
12732 TREE_CODE (dep
->get_entity ()), dep
->get_entity ());
12737 depset::hash::add_dependency (tree decl
, entity_kind ek
)
12741 if (is_key_order ())
12743 dep
= find_dependency (decl
);
12746 current
->deps
.safe_push (dep
);
12747 dump (dumper::MERGE
)
12748 && dump ("Key dependency on %s %C:%N found",
12749 dep
->entity_kind_name (), TREE_CODE (decl
), decl
);
12753 /* It's not a mergeable decl, look for it in the original
12755 dep
= chain
->find_dependency (decl
);
12756 gcc_checking_assert (dep
);
12761 dep
= make_dependency (decl
, ek
);
12762 if (dep
->get_entity_kind () != EK_REDIRECT
)
12763 add_dependency (dep
);
12770 depset::hash::add_namespace_context (depset
*dep
, tree ns
)
12772 depset
*ns_dep
= make_dependency (ns
, depset::EK_NAMESPACE
);
12773 dep
->deps
.safe_push (ns_dep
);
12775 /* Mark it as special if imported so we don't walk connect when
12777 if (!dep
->is_binding () && ns_dep
->is_import ())
12778 dep
->set_special ();
12781 struct add_binding_data
12786 depset::hash
*hash
;
12787 bool met_namespace
;
12790 /* Return true if we are, or contain something that is exported. */
12793 depset::hash::add_binding_entity (tree decl
, WMB_Flags flags
, void *data_
)
12795 auto data
= static_cast <add_binding_data
*> (data_
);
12797 if (!(TREE_CODE (decl
) == NAMESPACE_DECL
&& !DECL_NAMESPACE_ALIAS (decl
)))
12801 if (TREE_CODE (inner
) == CONST_DECL
12802 && TREE_CODE (DECL_CONTEXT (inner
)) == ENUMERAL_TYPE
)
12803 inner
= TYPE_NAME (DECL_CONTEXT (inner
));
12804 else if (TREE_CODE (inner
) == TEMPLATE_DECL
)
12805 inner
= DECL_TEMPLATE_RESULT (inner
);
12807 if (!DECL_LANG_SPECIFIC (inner
) || !DECL_MODULE_PURVIEW_P (inner
))
12808 /* Ignore global module fragment entities. */
12811 if (VAR_OR_FUNCTION_DECL_P (inner
)
12812 && DECL_THIS_STATIC (inner
))
12814 if (!header_module_p ())
12815 /* Ignore internal-linkage entitites. */
12819 if ((TREE_CODE (decl
) == VAR_DECL
12820 || TREE_CODE (decl
) == TYPE_DECL
)
12821 && DECL_TINFO_P (decl
))
12822 /* Ignore TINFO things. */
12825 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_NTTP_OBJECT_P (decl
))
12826 /* Ignore NTTP objects. */
12829 if (!(flags
& WMB_Using
) && CP_DECL_CONTEXT (decl
) != data
->ns
)
12831 /* A using that lost its wrapper or an unscoped enum
12833 flags
= WMB_Flags (flags
| WMB_Using
);
12834 if (DECL_MODULE_EXPORT_P (TREE_CODE (decl
) == CONST_DECL
12835 ? TYPE_NAME (TREE_TYPE (decl
))
12836 : STRIP_TEMPLATE (decl
)))
12837 flags
= WMB_Flags (flags
| WMB_Export
);
12840 if (!data
->binding
)
12841 /* No binding to check. */;
12842 else if (flags
& WMB_Using
)
12844 /* Look in the binding to see if we already have this
12846 for (unsigned ix
= data
->binding
->deps
.length (); --ix
;)
12848 depset
*d
= data
->binding
->deps
[ix
];
12849 if (d
->get_entity_kind () == EK_USING
12850 && OVL_FUNCTION (d
->get_entity ()) == decl
)
12852 if (!(flags
& WMB_Hidden
))
12853 d
->clear_hidden_binding ();
12854 if (flags
& WMB_Export
)
12855 OVL_EXPORT_P (d
->get_entity ()) = true;
12856 return bool (flags
& WMB_Export
);
12860 else if (flags
& WMB_Dups
)
12862 /* Look in the binding to see if we already have this decl. */
12863 for (unsigned ix
= data
->binding
->deps
.length (); --ix
;)
12865 depset
*d
= data
->binding
->deps
[ix
];
12866 if (d
->get_entity () == decl
)
12868 if (!(flags
& WMB_Hidden
))
12869 d
->clear_hidden_binding ();
12875 /* We're adding something. */
12876 if (!data
->binding
)
12878 data
->binding
= make_binding (data
->ns
, DECL_NAME (decl
));
12879 data
->hash
->add_namespace_context (data
->binding
, data
->ns
);
12881 depset
**slot
= data
->hash
->binding_slot (data
->ns
,
12882 DECL_NAME (decl
), true);
12883 gcc_checking_assert (!*slot
);
12884 *slot
= data
->binding
;
12887 /* Make sure nobody left a tree visited lying about. */
12888 gcc_checking_assert (!TREE_VISITED (decl
));
12890 if (flags
& WMB_Using
)
12892 decl
= ovl_make (decl
, NULL_TREE
);
12893 if (flags
& WMB_Export
)
12894 OVL_EXPORT_P (decl
) = true;
12897 depset
*dep
= data
->hash
->make_dependency
12898 (decl
, flags
& WMB_Using
? EK_USING
: EK_FOR_BINDING
);
12899 if (flags
& WMB_Hidden
)
12900 dep
->set_hidden_binding ();
12901 data
->binding
->deps
.safe_push (dep
);
12902 /* Binding and contents are mutually dependent. */
12903 dep
->deps
.safe_push (data
->binding
);
12905 return (flags
& WMB_Using
12906 ? flags
& WMB_Export
: DECL_MODULE_EXPORT_P (decl
));
12908 else if (DECL_NAME (decl
) && !data
->met_namespace
)
12910 /* Namespace, walk exactly once. */
12911 gcc_checking_assert (TREE_PUBLIC (decl
));
12912 data
->met_namespace
= true;
12913 if (data
->hash
->add_namespace_entities (decl
, data
->partitions
))
12915 /* It contains an exported thing, so it is exported. */
12916 gcc_checking_assert (DECL_MODULE_PURVIEW_P (decl
));
12917 DECL_MODULE_EXPORT_P (decl
) = true;
12920 if (DECL_MODULE_PURVIEW_P (decl
))
12922 data
->hash
->make_dependency (decl
, depset::EK_NAMESPACE
);
12924 return DECL_MODULE_EXPORT_P (decl
);
12931 /* Recursively find all the namespace bindings of NS. Add a depset
12932 for every binding that contains an export or module-linkage entity.
12933 Add a defining depset for every such decl that we need to write a
12934 definition. Such defining depsets depend on the binding depset.
12935 Returns true if we contain something exported. */
12938 depset::hash::add_namespace_entities (tree ns
, bitmap partitions
)
12940 dump () && dump ("Looking for writables in %N", ns
);
12943 unsigned count
= 0;
12944 add_binding_data data
;
12946 data
.partitions
= partitions
;
12949 hash_table
<named_decl_hash
>::iterator end
12950 (DECL_NAMESPACE_BINDINGS (ns
)->end ());
12951 for (hash_table
<named_decl_hash
>::iterator iter
12952 (DECL_NAMESPACE_BINDINGS (ns
)->begin ()); iter
!= end
; ++iter
)
12954 data
.binding
= nullptr;
12955 data
.met_namespace
= false;
12956 if (walk_module_binding (*iter
, partitions
, add_binding_entity
, &data
))
12961 dump () && dump ("Found %u entries", count
);
12968 depset::hash::add_partial_entities (vec
<tree
, va_gc
> *partial_classes
)
12970 for (unsigned ix
= 0; ix
!= partial_classes
->length (); ix
++)
12972 tree inner
= (*partial_classes
)[ix
];
12974 depset
*dep
= make_dependency (inner
, depset::EK_DECL
);
12976 if (dep
->get_entity_kind () == depset::EK_REDIRECT
)
12977 /* We should have recorded the template as a partial
12979 gcc_checking_assert (dep
->deps
[0]->get_entity_kind ()
12980 == depset::EK_PARTIAL
);
12982 /* It was an explicit specialization, not a partial one. */
12983 gcc_checking_assert (dep
->get_entity_kind ()
12984 == depset::EK_SPECIALIZATION
);
12988 /* Add the members of imported classes that we defined in this TU.
12989 This will also include lazily created implicit member function
12990 declarations. (All others will be definitions.) */
12993 depset::hash::add_class_entities (vec
<tree
, va_gc
> *class_members
)
12995 for (unsigned ix
= 0; ix
!= class_members
->length (); ix
++)
12997 tree defn
= (*class_members
)[ix
];
12998 depset
*dep
= make_dependency (defn
, EK_INNER_DECL
);
13000 if (dep
->get_entity_kind () == EK_REDIRECT
)
13001 dep
= dep
->deps
[0];
13003 /* Only non-instantiations need marking as members. */
13004 if (dep
->get_entity_kind () == EK_DECL
)
13005 dep
->set_flag_bit
<DB_IS_MEMBER_BIT
> ();
13009 /* We add the partial & explicit specializations, and the explicit
13013 specialization_add (bool decl_p
, spec_entry
*entry
, void *data_
)
13015 vec
<spec_entry
*> *data
= reinterpret_cast <vec
<spec_entry
*> *> (data_
);
13019 /* We exclusively use decls to locate things. Make sure there's
13020 no mismatch between the two specialization tables we keep.
13021 pt.cc optimizes instantiation lookup using a complicated
13022 heuristic. We don't attempt to replicate that algorithm, but
13023 observe its behaviour and reproduce it upon read back. */
13025 gcc_checking_assert (DECL_ALIAS_TEMPLATE_P (entry
->tmpl
)
13026 || TREE_CODE (entry
->spec
) == ENUMERAL_TYPE
13027 || DECL_CLASS_TEMPLATE_P (entry
->tmpl
));
13029 /* Only alias templates can appear in both tables (and
13030 if they're in the type table they must also be in the decl
13032 gcc_checking_assert
13033 (!match_mergeable_specialization (true, entry
)
13034 == !DECL_ALIAS_TEMPLATE_P (entry
->tmpl
));
13036 else if (VAR_OR_FUNCTION_DECL_P (entry
->spec
))
13037 gcc_checking_assert (!DECL_LOCAL_DECL_P (entry
->spec
));
13039 data
->safe_push (entry
);
13042 /* Arbitrary stable comparison. */
13045 specialization_cmp (const void *a_
, const void *b_
)
13047 const spec_entry
*ea
= *reinterpret_cast<const spec_entry
*const *> (a_
);
13048 const spec_entry
*eb
= *reinterpret_cast<const spec_entry
*const *> (b_
);
13062 /* This can happen with friend specializations. Just order by
13063 entry address. See note in depset_cmp. */
13064 return ea
< eb
? -1 : +1;
13066 return DECL_UID (a
) < DECL_UID (b
) ? -1 : +1;
13069 /* We add all kinds of specialializations. Implicit specializations
13070 should only streamed and walked if they are reachable from
13071 elsewhere. Hence the UNREACHED flag. This is making the
13072 assumption that it is cheaper to reinstantiate them on demand
13073 elsewhere, rather than stream them in when we instantiate their
13074 general template. Also, if we do stream them, we can only do that
13075 if they are not internal (which they can become if they themselves
13076 touch an internal entity?). */
13079 depset::hash::add_specializations (bool decl_p
)
13081 vec
<spec_entry
*> data
;
13083 walk_specializations (decl_p
, specialization_add
, &data
);
13084 data
.qsort (specialization_cmp
);
13085 while (data
.length ())
13087 spec_entry
*entry
= data
.pop ();
13088 tree spec
= entry
->spec
;
13090 bool is_alias
= false;
13091 bool is_friend
= false;
13093 if (decl_p
&& DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (entry
->tmpl
))
13094 /* A friend of a template. This is keyed to the
13098 if (!decl_p
&& DECL_ALIAS_TEMPLATE_P (entry
->tmpl
))
13100 spec
= TYPE_NAME (spec
);
13104 if (decl_p
|| is_alias
)
13106 if (tree ti
= DECL_TEMPLATE_INFO (spec
))
13108 tree tmpl
= TI_TEMPLATE (ti
);
13110 use_tpl
= DECL_USE_TEMPLATE (spec
);
13111 if (spec
== DECL_TEMPLATE_RESULT (tmpl
))
13114 gcc_checking_assert (DECL_USE_TEMPLATE (spec
) == use_tpl
);
13116 else if (is_friend
)
13118 if (TI_TEMPLATE (ti
) != entry
->tmpl
13119 || !template_args_equal (TI_ARGS (ti
), entry
->tmpl
))
13120 goto template_friend
;
13126 gcc_checking_assert (is_friend
);
13127 /* This is a friend of a template class, but not the one
13128 that generated entry->spec itself (i.e. it's an
13129 equivalent clone). We do not need to record
13136 if (TREE_CODE (spec
) == ENUMERAL_TYPE
)
13138 tree ctx
= DECL_CONTEXT (TYPE_NAME (spec
));
13141 use_tpl
= CLASSTYPE_USE_TEMPLATE (ctx
);
13143 use_tpl
= DECL_USE_TEMPLATE (ctx
);
13146 use_tpl
= CLASSTYPE_USE_TEMPLATE (spec
);
13148 tree ti
= TYPE_TEMPLATE_INFO (spec
);
13149 tree tmpl
= TI_TEMPLATE (ti
);
13151 spec
= TYPE_NAME (spec
);
13152 if (spec
== DECL_TEMPLATE_RESULT (tmpl
))
13155 use_tpl
= DECL_USE_TEMPLATE (spec
);
13159 bool needs_reaching
= false;
13161 /* Implicit instantiations only walked if we reach them. */
13162 needs_reaching
= true;
13163 else if (!DECL_LANG_SPECIFIC (spec
)
13164 || !DECL_MODULE_PURVIEW_P (STRIP_TEMPLATE (spec
)))
13165 /* Likewise, GMF explicit or partial specializations. */
13166 needs_reaching
= true;
13168 #if false && CHECKING_P
13169 /* The instantiation isn't always on
13170 DECL_TEMPLATE_INSTANTIATIONS, */
13171 // FIXME: we probably need to remember this information?
13172 /* Verify the specialization is on the
13173 DECL_TEMPLATE_INSTANTIATIONS of the template. */
13174 for (tree cons
= DECL_TEMPLATE_INSTANTIATIONS (entry
->tmpl
);
13175 cons
; cons
= TREE_CHAIN (cons
))
13176 if (TREE_VALUE (cons
) == entry
->spec
)
13178 gcc_assert (entry
->args
== TREE_PURPOSE (cons
));
13181 gcc_unreachable ();
13185 /* Make sure nobody left a tree visited lying about. */
13186 gcc_checking_assert (!TREE_VISITED (spec
));
13187 depset
*dep
= make_dependency (spec
, depset::EK_SPECIALIZATION
);
13188 if (dep
->is_special ())
13190 /* An already located specialization, this must be the TYPE
13191 corresponding to an alias_decl we found in the decl
13193 spec_entry
*other
= reinterpret_cast <spec_entry
*> (dep
->deps
[0]);
13194 gcc_checking_assert (!decl_p
&& is_alias
&& !dep
->is_type_spec ());
13195 gcc_checking_assert (other
->tmpl
== entry
->tmpl
13196 && template_args_equal (other
->args
, entry
->args
)
13197 && TREE_TYPE (other
->spec
) == entry
->spec
);
13198 dep
->set_flag_bit
<DB_ALIAS_SPEC_BIT
> ();
13202 gcc_checking_assert (decl_p
|| !is_alias
);
13203 if (dep
->get_entity_kind () == depset::EK_REDIRECT
)
13204 dep
= dep
->deps
[0];
13205 else if (dep
->get_entity_kind () == depset::EK_SPECIALIZATION
)
13207 dep
->set_special ();
13208 dep
->deps
.safe_push (reinterpret_cast<depset
*> (entry
));
13210 dep
->set_flag_bit
<DB_TYPE_SPEC_BIT
> ();
13213 if (needs_reaching
)
13214 dep
->set_flag_bit
<DB_UNREACHED_BIT
> ();
13216 dep
->set_flag_bit
<DB_FRIEND_SPEC_BIT
> ();
13222 /* Add a depset into the mergeable hash. */
13225 depset::hash::add_mergeable (depset
*mergeable
)
13227 gcc_checking_assert (is_key_order ());
13228 entity_kind ek
= mergeable
->get_entity_kind ();
13229 tree decl
= mergeable
->get_entity ();
13230 gcc_checking_assert (ek
< EK_DIRECT_HWM
);
13232 depset
**slot
= entity_slot (decl
, true);
13233 gcc_checking_assert (!*slot
);
13234 depset
*dep
= make_entity (decl
, ek
);
13237 worklist
.safe_push (dep
);
13239 /* So we can locate the mergeable depset this depset refers to,
13240 mark the first dep. */
13241 dep
->set_special ();
13242 dep
->deps
.safe_push (mergeable
);
13245 /* Find the innermost-namespace scope of DECL, and that
13246 namespace-scope decl. */
13249 find_pending_key (tree decl
, tree
*decl_p
= nullptr)
13255 ns
= CP_DECL_CONTEXT (ns
);
13257 ns
= TYPE_NAME (ns
);
13259 while (TREE_CODE (ns
) != NAMESPACE_DECL
);
13267 /* Iteratively find dependencies. During the walk we may find more
13268 entries on the same binding that need walking. */
13271 depset::hash::find_dependencies (module_state
*module
)
13273 trees_out
walker (NULL
, module
, *this);
13274 vec
<depset
*> unreached
;
13275 unreached
.create (worklist
.length ());
13279 reached_unreached
= false;
13280 while (worklist
.length ())
13282 depset
*item
= worklist
.pop ();
13284 gcc_checking_assert (!item
->is_binding ());
13285 if (item
->is_unreached ())
13286 unreached
.quick_push (item
);
13290 tree decl
= current
->get_entity ();
13291 dump (is_key_order () ? dumper::MERGE
: dumper::DEPEND
)
13292 && dump ("Dependencies of %s %C:%N",
13293 is_key_order () ? "key-order"
13294 : current
->entity_kind_name (), TREE_CODE (decl
), decl
);
13297 if (current
->get_entity_kind () == EK_USING
)
13298 walker
.tree_node (OVL_FUNCTION (decl
));
13299 else if (TREE_VISITED (decl
))
13300 /* A global tree. */;
13301 else if (item
->get_entity_kind () == EK_NAMESPACE
)
13303 module
->note_location (DECL_SOURCE_LOCATION (decl
));
13304 add_namespace_context (current
, CP_DECL_CONTEXT (decl
));
13308 walker
.mark_declaration (decl
, current
->has_defn ());
13310 if (!walker
.is_key_order ()
13311 && (item
->get_entity_kind () == EK_SPECIALIZATION
13312 || item
->get_entity_kind () == EK_PARTIAL
13313 || (item
->get_entity_kind () == EK_DECL
13314 && item
->is_member ())))
13316 tree ns
= find_pending_key (decl
, nullptr);
13317 add_namespace_context (item
, ns
);
13320 // FIXME: Perhaps p1815 makes this redundant? Or at
13321 // least simplifies it. Voldemort types are only
13322 // ever emissable when containing (inline) function
13323 // definition is emitted?
13324 /* Turn the Sneakoscope on when depending the decl. */
13325 sneakoscope
= true;
13326 walker
.decl_value (decl
, current
);
13327 sneakoscope
= false;
13328 if (current
->has_defn ())
13329 walker
.write_definition (decl
);
13333 if (!walker
.is_key_order ()
13334 && TREE_CODE (decl
) == TEMPLATE_DECL
13335 && !DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (decl
))
13336 /* Mark all the explicit & partial specializations as
13338 for (tree cons
= DECL_TEMPLATE_INSTANTIATIONS (decl
);
13339 cons
; cons
= TREE_CHAIN (cons
))
13341 tree spec
= TREE_VALUE (cons
);
13343 spec
= TYPE_NAME (spec
);
13345 node_template_info (spec
, use_tpl
);
13348 depset
*spec_dep
= find_dependency (spec
);
13349 if (spec_dep
->get_entity_kind () == EK_REDIRECT
)
13350 spec_dep
= spec_dep
->deps
[0];
13351 if (spec_dep
->is_unreached ())
13353 reached_unreached
= true;
13354 spec_dep
->clear_flag_bit
<DB_UNREACHED_BIT
> ();
13355 dump (dumper::DEPEND
)
13356 && dump ("Reaching unreached specialization"
13357 " %C:%N", TREE_CODE (spec
), spec
);
13367 if (!reached_unreached
)
13370 /* It's possible the we reached the unreached before we
13371 processed it in the above loop, so we'll be doing this an
13372 extra time. However, to avoid that we have to do some
13373 bit shuffling that also involves a scan of the list.
13374 Swings & roundabouts I guess. */
13375 std::swap (worklist
, unreached
);
13378 unreached
.release ();
13381 /* Compare two entries of a single binding. TYPE_DECL before
13382 non-exported before exported. */
13385 binding_cmp (const void *a_
, const void *b_
)
13387 depset
*a
= *(depset
*const *)a_
;
13388 depset
*b
= *(depset
*const *)b_
;
13390 tree a_ent
= a
->get_entity ();
13391 tree b_ent
= b
->get_entity ();
13392 gcc_checking_assert (a_ent
!= b_ent
13393 && !a
->is_binding ()
13394 && !b
->is_binding ());
13396 /* Implicit typedefs come first. */
13397 bool a_implicit
= DECL_IMPLICIT_TYPEDEF_P (a_ent
);
13398 bool b_implicit
= DECL_IMPLICIT_TYPEDEF_P (b_ent
);
13399 if (a_implicit
|| b_implicit
)
13401 /* A binding with two implicit type decls? That's unpossible! */
13402 gcc_checking_assert (!(a_implicit
&& b_implicit
));
13403 return a_implicit
? -1 : +1; /* Implicit first. */
13406 /* Hidden before non-hidden. */
13407 bool a_hidden
= a
->is_hidden ();
13408 bool b_hidden
= b
->is_hidden ();
13409 if (a_hidden
!= b_hidden
)
13410 return a_hidden
? -1 : +1;
13412 bool a_using
= a
->get_entity_kind () == depset::EK_USING
;
13416 a_export
= OVL_EXPORT_P (a_ent
);
13417 a_ent
= OVL_FUNCTION (a_ent
);
13420 a_export
= DECL_MODULE_EXPORT_P (TREE_CODE (a_ent
) == CONST_DECL
13421 ? TYPE_NAME (TREE_TYPE (a_ent
))
13422 : STRIP_TEMPLATE (a_ent
));
13424 bool b_using
= b
->get_entity_kind () == depset::EK_USING
;
13428 b_export
= OVL_EXPORT_P (b_ent
);
13429 b_ent
= OVL_FUNCTION (b_ent
);
13432 b_export
= DECL_MODULE_EXPORT_P (TREE_CODE (b_ent
) == CONST_DECL
13433 ? TYPE_NAME (TREE_TYPE (b_ent
))
13434 : STRIP_TEMPLATE (b_ent
));
13436 /* Non-exports before exports. */
13437 if (a_export
!= b_export
)
13438 return a_export
? +1 : -1;
13440 /* At this point we don't care, but want a stable sort. */
13442 if (a_using
!= b_using
)
13444 return a_using
? -1 : +1;
13446 return DECL_UID (a_ent
) < DECL_UID (b_ent
) ? -1 : +1;
13449 /* Sort the bindings, issue errors about bad internal refs. */
13452 depset::hash::finalize_dependencies ()
13455 depset::hash::iterator
end (this->end ());
13456 for (depset::hash::iterator
iter (begin ()); iter
!= end
; ++iter
)
13458 depset
*dep
= *iter
;
13459 if (dep
->is_binding ())
13461 /* Keep the containing namespace dep first. */
13462 gcc_checking_assert (dep
->deps
.length () > 1
13463 && (dep
->deps
[0]->get_entity_kind ()
13465 && (dep
->deps
[0]->get_entity ()
13466 == dep
->get_entity ()));
13467 if (dep
->deps
.length () > 2)
13468 gcc_qsort (&dep
->deps
[1], dep
->deps
.length () - 1,
13469 sizeof (dep
->deps
[1]), binding_cmp
);
13471 else if (dep
->refs_internal ())
13473 for (unsigned ix
= dep
->deps
.length (); ix
--;)
13475 depset
*rdep
= dep
->deps
[ix
];
13476 if (rdep
->is_internal ())
13478 // FIXME:QOI Better location information? We're
13479 // losing, so it doesn't matter about efficiency
13480 tree decl
= dep
->get_entity ();
13481 error_at (DECL_SOURCE_LOCATION (decl
),
13482 "%q#D references internal linkage entity %q#D",
13483 decl
, rdep
->get_entity ());
13494 /* Core of TARJAN's algorithm to find Strongly Connected Components
13495 within a graph. See https://en.wikipedia.org/wiki/
13496 Tarjan%27s_strongly_connected_components_algorithm for details.
13498 We use depset::section as lowlink. Completed nodes have
13499 depset::cluster containing the cluster number, with the top
13502 A useful property is that the output vector is a reverse
13503 topological sort of the resulting DAG. In our case that means
13504 dependent SCCs are found before their dependers. We make use of
13508 depset::tarjan::connect (depset
*v
)
13510 gcc_checking_assert (v
->is_binding ()
13511 || !(v
->is_unreached () || v
->is_import ()));
13513 v
->cluster
= v
->section
= ++index
;
13514 stack
.safe_push (v
);
13516 /* Walk all our dependencies, ignore a first marked slot */
13517 for (unsigned ix
= v
->is_special (); ix
!= v
->deps
.length (); ix
++)
13519 depset
*dep
= v
->deps
[ix
];
13521 if (dep
->is_binding () || !dep
->is_import ())
13523 unsigned lwm
= dep
->cluster
;
13527 /* A new node. Connect it. */
13529 lwm
= dep
->section
;
13532 if (dep
->section
&& v
->section
> lwm
)
13537 if (v
->section
== v
->cluster
)
13539 /* Root of a new SCC. Push all the members onto the result list. */
13540 unsigned num
= v
->cluster
;
13547 result
.quick_push (p
);
13553 /* Compare two depsets. The specific ordering is unimportant, we're
13554 just trying to get consistency. */
13557 depset_cmp (const void *a_
, const void *b_
)
13559 depset
*a
= *(depset
*const *)a_
;
13560 depset
*b
= *(depset
*const *)b_
;
13562 depset::entity_kind a_kind
= a
->get_entity_kind ();
13563 depset::entity_kind b_kind
= b
->get_entity_kind ();
13565 if (a_kind
!= b_kind
)
13566 /* Different entity kinds, order by that. */
13567 return a_kind
< b_kind
? -1 : +1;
13569 tree a_decl
= a
->get_entity ();
13570 tree b_decl
= b
->get_entity ();
13571 if (a_kind
== depset::EK_USING
)
13573 /* If one is a using, the other must be too. */
13574 a_decl
= OVL_FUNCTION (a_decl
);
13575 b_decl
= OVL_FUNCTION (b_decl
);
13578 if (a_decl
!= b_decl
)
13579 /* Different entities, order by their UID. */
13580 return DECL_UID (a_decl
) < DECL_UID (b_decl
) ? -1 : +1;
13582 if (a_kind
== depset::EK_BINDING
)
13584 /* Both are bindings. Order by identifier hash. */
13585 gcc_checking_assert (a
->get_name () != b
->get_name ());
13586 return (IDENTIFIER_HASH_VALUE (a
->get_name ())
13587 < IDENTIFIER_HASH_VALUE (b
->get_name ())
13591 /* They are the same decl. This can happen with two using decls
13592 pointing to the same target. The best we can aim for is
13593 consistently telling qsort how to order them. Hopefully we'll
13594 never have to debug a case that depends on this. Oh, who am I
13595 kidding? Good luck. */
13596 gcc_checking_assert (a_kind
== depset::EK_USING
);
13598 /* Order by depset address. Not the best, but it is something. */
13599 return a
< b
? -1 : +1;
13602 /* Sort the clusters in SCC such that those that depend on one another
13603 are placed later. */
13605 // FIXME: I am not convinced this is needed and, if needed,
13606 // sufficient. We emit the decls in this order but that emission
13607 // could walk into later decls (from the body of the decl, or default
13608 // arg-like things). Why doesn't that walk do the right thing? And
13609 // if it DTRT why do we need to sort here -- won't things naturally
13610 // work? I think part of the issue is that when we're going to refer
13611 // to an entity by name, and that entity is in the same cluster as us,
13612 // we need to actually walk that entity, if we've not already walked
13615 sort_cluster (depset::hash
*original
, depset
*scc
[], unsigned size
)
13617 depset::hash
table (size
, original
);
13621 /* Place bindings last, usings before that. It's not strictly
13622 necessary, but it does make things neater. Says Mr OCD. */
13623 unsigned bind_lwm
= size
;
13624 unsigned use_lwm
= size
;
13625 for (unsigned ix
= 0; ix
!= use_lwm
;)
13627 depset
*dep
= scc
[ix
];
13628 switch (dep
->get_entity_kind ())
13630 case depset::EK_BINDING
:
13631 /* Move to end. No increment. Notice this could be moving
13632 a using decl, which we'll then move again. */
13633 if (--bind_lwm
!= ix
)
13635 scc
[ix
] = scc
[bind_lwm
];
13636 scc
[bind_lwm
] = dep
;
13638 if (use_lwm
> bind_lwm
)
13643 /* We must have copied a using, so move it too. */
13645 gcc_checking_assert (dep
->get_entity_kind () == depset::EK_USING
);
13648 case depset::EK_USING
:
13649 if (--use_lwm
!= ix
)
13651 scc
[ix
] = scc
[use_lwm
];
13652 scc
[use_lwm
] = dep
;
13656 case depset::EK_DECL
:
13657 case depset::EK_SPECIALIZATION
:
13658 case depset::EK_PARTIAL
:
13659 table
.add_mergeable (dep
);
13664 gcc_unreachable ();
13668 gcc_checking_assert (use_lwm
<= bind_lwm
);
13669 dump (dumper::MERGE
) && dump ("Ordering %u/%u depsets", use_lwm
, size
);
13671 table
.find_dependencies (nullptr);
13673 vec
<depset
*> order
= table
.connect ();
13674 gcc_checking_assert (order
.length () == use_lwm
);
13676 /* Now rewrite entries [0,lwm), in the dependency order we
13677 discovered. Usually each entity is in its own cluster. Rarely,
13678 we can get multi-entity clusters, in which case all but one must
13679 only be reached from within the cluster. This happens for
13682 template<typename T>
13683 auto Foo (const T &arg) -> TPL<decltype (arg)>;
13685 The instantiation of TPL will be in the specialization table, and
13686 refer to Foo via arg. But we can only get to that specialization
13687 from Foo's declaration, so we only need to treat Foo as mergable
13688 (We'll do structural comparison of TPL<decltype (arg)>).
13690 Finding the single cluster entry dep is very tricky and
13691 expensive. Let's just not do that. It's harmless in this case
13694 unsigned cluster
= ~0u;
13695 for (unsigned ix
= 0; ix
!= order
.length (); ix
++)
13697 gcc_checking_assert (order
[ix
]->is_special ());
13698 depset
*dep
= order
[ix
]->deps
[0];
13700 dump (dumper::MERGE
)
13701 && dump ("Mergeable %u is %N%s", ix
, dep
->get_entity (),
13702 order
[ix
]->cluster
== cluster
? " (tight)" : "");
13703 cluster
= order
[ix
]->cluster
;
13706 gcc_checking_assert (pos
== use_lwm
);
13709 dump (dumper::MERGE
) && dump ("Ordered %u keys", pos
);
13713 /* Reduce graph to SCCS clusters. SCCS will be populated with the
13714 depsets in dependency order. Each depset's CLUSTER field contains
13715 its cluster number. Each SCC has a unique cluster number, and are
13716 contiguous in SCCS. Cluster numbers are otherwise arbitrary. */
13719 depset::hash::connect ()
13721 tarjan
connector (size ());
13722 vec
<depset
*> deps
;
13723 deps
.create (size ());
13724 iterator
end (this->end ());
13725 for (iterator
iter (begin ()); iter
!= end
; ++iter
)
13727 depset
*item
= *iter
;
13729 entity_kind kind
= item
->get_entity_kind ();
13730 if (kind
== EK_BINDING
13731 || !(kind
== EK_REDIRECT
13732 || item
->is_unreached ()
13733 || item
->is_import ()))
13734 deps
.quick_push (item
);
13737 /* Iteration over the hash table is an unspecified ordering. While
13738 that has advantages, it causes 2 problems. Firstly repeatable
13739 builds are tricky. Secondly creating testcases that check
13740 dependencies are correct by making sure a bad ordering would
13741 happen if that was wrong. */
13742 deps
.qsort (depset_cmp
);
13744 while (deps
.length ())
13746 depset
*v
= deps
.pop ();
13747 dump (dumper::CLUSTER
) &&
13749 ? dump ("Connecting binding %P", v
->get_entity (), v
->get_name ())
13750 : dump ("Connecting %s %s %C:%N",
13751 is_key_order () ? "key-order"
13752 : !v
->has_defn () ? "declaration" : "definition",
13753 v
->entity_kind_name (), TREE_CODE (v
->get_entity ()),
13754 v
->get_entity ()));
13756 connector
.connect (v
);
13760 return connector
.result
;
13763 /* Initialize location spans. */
13766 loc_spans::init (const line_maps
*lmaps
, const line_map_ordinary
*map
)
13768 gcc_checking_assert (!init_p ());
13769 spans
= new vec
<span
> ();
13770 spans
->reserve (20);
13773 interval
.ordinary
.first
= 0;
13774 interval
.macro
.second
= MAX_LOCATION_T
+ 1;
13775 interval
.ordinary_delta
= interval
.macro_delta
= 0;
13777 /* A span for reserved fixed locs. */
13778 interval
.ordinary
.second
13779 = MAP_START_LOCATION (LINEMAPS_ORDINARY_MAP_AT (line_table
, 0));
13780 interval
.macro
.first
= interval
.macro
.second
;
13781 dump (dumper::LOCATION
)
13782 && dump ("Fixed span %u ordinary:[%u,%u) macro:[%u,%u)", spans
->length (),
13783 interval
.ordinary
.first
, interval
.ordinary
.second
,
13784 interval
.macro
.first
, interval
.macro
.second
);
13785 spans
->quick_push (interval
);
13787 /* A span for command line & forced headers. */
13788 interval
.ordinary
.first
= interval
.ordinary
.second
;
13789 interval
.macro
.second
= interval
.macro
.first
;
13792 interval
.ordinary
.second
= map
->start_location
;
13793 interval
.macro
.first
= LINEMAPS_MACRO_LOWEST_LOCATION (lmaps
);
13795 dump (dumper::LOCATION
)
13796 && dump ("Pre span %u ordinary:[%u,%u) macro:[%u,%u)", spans
->length (),
13797 interval
.ordinary
.first
, interval
.ordinary
.second
,
13798 interval
.macro
.first
, interval
.macro
.second
);
13799 spans
->quick_push (interval
);
13801 /* Start an interval for the main file. */
13802 interval
.ordinary
.first
= interval
.ordinary
.second
;
13803 interval
.macro
.second
= interval
.macro
.first
;
13804 dump (dumper::LOCATION
)
13805 && dump ("Main span %u ordinary:[%u,*) macro:[*,%u)", spans
->length (),
13806 interval
.ordinary
.first
, interval
.macro
.second
);
13807 spans
->quick_push (interval
);
13810 /* Reopen the span, if we want the about-to-be-inserted set of maps to
13811 be propagated in our own location table. I.e. we are the primary
13812 interface and we're importing a partition. */
13815 loc_spans::maybe_propagate (module_state
*import
, location_t hwm
)
13817 bool opened
= (module_interface_p () && !module_partition_p ()
13818 && import
->is_partition ());
13824 /* Open a new linemap interval. The just-created ordinary map is the
13825 first map of the interval. */
13828 loc_spans::open (location_t hwm
)
13831 interval
.ordinary
.first
= interval
.ordinary
.second
= hwm
;
13832 interval
.macro
.first
= interval
.macro
.second
13833 = LINEMAPS_MACRO_LOWEST_LOCATION (line_table
);
13834 interval
.ordinary_delta
= interval
.macro_delta
= 0;
13835 dump (dumper::LOCATION
)
13836 && dump ("Opening span %u ordinary:[%u,... macro:...,%u)",
13837 spans
->length (), interval
.ordinary
.first
,
13838 interval
.macro
.second
);
13839 if (spans
->length ())
13841 /* No overlapping! */
13842 auto &last
= spans
->last ();
13843 gcc_checking_assert (interval
.ordinary
.first
>= last
.ordinary
.second
);
13844 gcc_checking_assert (interval
.macro
.second
<= last
.macro
.first
);
13846 spans
->safe_push (interval
);
13849 /* Close out the current linemap interval. The last maps are within
13853 loc_spans::close ()
13855 span
&interval
= spans
->last ();
13857 interval
.ordinary
.second
13858 = ((line_table
->highest_location
+ (1 << line_table
->default_range_bits
))
13859 & ~((1u << line_table
->default_range_bits
) - 1));
13860 interval
.macro
.first
= LINEMAPS_MACRO_LOWEST_LOCATION (line_table
);
13861 dump (dumper::LOCATION
)
13862 && dump ("Closing span %u ordinary:[%u,%u) macro:[%u,%u)",
13863 spans
->length () - 1,
13864 interval
.ordinary
.first
,interval
.ordinary
.second
,
13865 interval
.macro
.first
, interval
.macro
.second
);
13868 /* Given an ordinary location LOC, return the lmap_interval it resides
13869 in. NULL if it is not in an interval. */
13871 const loc_spans::span
*
13872 loc_spans::ordinary (location_t loc
)
13874 unsigned len
= spans
->length ();
13878 unsigned half
= len
/ 2;
13879 const span
&probe
= (*spans
)[pos
+ half
];
13880 if (loc
< probe
.ordinary
.first
)
13882 else if (loc
< probe
.ordinary
.second
)
13887 len
= len
- (half
+ 1);
13893 /* Likewise, given a macro location LOC, return the lmap interval it
13896 const loc_spans::span
*
13897 loc_spans::macro (location_t loc
)
13899 unsigned len
= spans
->length ();
13903 unsigned half
= len
/ 2;
13904 const span
&probe
= (*spans
)[pos
+ half
];
13905 if (loc
>= probe
.macro
.second
)
13907 else if (loc
>= probe
.macro
.first
)
13912 len
= len
- (half
+ 1);
13918 /* Return the ordinary location closest to FROM. */
13921 ordinary_loc_of (line_maps
*lmaps
, location_t from
)
13923 while (!IS_ORDINARY_LOC (from
))
13925 if (IS_ADHOC_LOC (from
))
13926 from
= get_location_from_adhoc_loc (lmaps
, from
);
13927 if (from
>= LINEMAPS_MACRO_LOWEST_LOCATION (lmaps
))
13929 /* Find the ordinary location nearest FROM. */
13930 const line_map
*map
= linemap_lookup (lmaps
, from
);
13931 const line_map_macro
*mac_map
= linemap_check_macro (map
);
13932 from
= MACRO_MAP_EXPANSION_POINT_LOCATION (mac_map
);
13938 static module_state
**
13939 get_module_slot (tree name
, module_state
*parent
, bool partition
, bool insert
)
13941 module_state_hash::compare_type
ct (name
, uintptr_t (parent
) | partition
);
13942 hashval_t hv
= module_state_hash::hash (ct
);
13944 return modules_hash
->find_slot_with_hash (ct
, hv
, insert
? INSERT
: NO_INSERT
);
13947 static module_state
*
13948 get_primary (module_state
*parent
)
13950 while (parent
->is_partition ())
13951 parent
= parent
->parent
;
13954 // Implementation unit has null name
13955 parent
= parent
->parent
;
13960 /* Find or create module NAME & PARENT in the hash table. */
13963 get_module (tree name
, module_state
*parent
, bool partition
)
13968 parent
= get_primary ((*modules
)[0]);
13970 if (!parent
->is_partition () && !parent
->flatname
)
13971 parent
->set_flatname ();
13974 module_state
**slot
= get_module_slot (name
, parent
, partition
, true);
13975 module_state
*state
= *slot
;
13978 state
= (new (ggc_alloc
<module_state
> ())
13979 module_state (name
, parent
, partition
));
13985 /* Process string name PTR into a module_state. */
13987 static module_state
*
13988 get_module (const char *ptr
)
13990 /* On DOS based file systems, there is an ambiguity with A:B which can be
13991 interpreted as a module Module:Partition or Drive:PATH. Interpret strings
13992 which clearly starts as pathnames as header-names and everything else is
13993 treated as a (possibly malformed) named moduled. */
13994 if (IS_DIR_SEPARATOR (ptr
[ptr
[0] == '.']) // ./FOO or /FOO
13995 #if HAVE_DOS_BASED_FILE_SYSTEM
13996 || (HAS_DRIVE_SPEC (ptr
) && IS_DIR_SEPARATOR (ptr
[2])) // A:/FOO
13999 /* A header name. */
14000 return get_module (build_string (strlen (ptr
), ptr
));
14002 bool partition
= false;
14003 module_state
*mod
= NULL
;
14005 for (const char *probe
= ptr
;; probe
++)
14006 if (!*probe
|| *probe
== '.' || *probe
== ':')
14011 mod
= get_module (get_identifier_with_length (ptr
, probe
- ptr
),
14024 else if (!(ISALPHA (*probe
) || *probe
== '_'
14025 || (probe
!= ptr
&& ISDIGIT (*probe
))))
14031 /* Create a new mapper connecting to OPTION. */
14034 make_mapper (location_t loc
)
14036 timevar_start (TV_MODULE_MAPPER
);
14037 const char *option
= module_mapper_name
;
14039 option
= getenv ("CXX_MODULE_MAPPER");
14041 mapper
= module_client::open_module_client
14042 (loc
, option
, &set_cmi_repo
,
14043 (save_decoded_options
[0].opt_index
== OPT_SPECIAL_program_name
)
14044 && save_decoded_options
[0].arg
!= progname
14045 ? save_decoded_options
[0].arg
: nullptr);
14047 timevar_stop (TV_MODULE_MAPPER
);
14052 static unsigned lazy_snum
;
14055 recursive_lazy (unsigned snum
= ~0u)
14059 error_at (input_location
, "recursive lazy load");
14067 /* If THIS is the current purview, issue an import error and return false. */
14070 module_state::check_not_purview (location_t from
)
14072 module_state
*imp
= (*modules
)[0];
14073 if (imp
&& !imp
->name
)
14077 /* Cannot import the current module. */
14078 error_at (from
, "cannot import module in its own purview");
14079 inform (loc
, "module %qs declared here", get_flatname ());
14085 /* Module name substitutions. */
14086 static vec
<module_state
*,va_heap
> substs
;
14089 module_state::mangle (bool include_partition
)
14092 mangle_module_substitution (subst
);
14096 parent
->mangle (include_partition
);
14097 if (include_partition
|| !is_partition ())
14099 // Partitions are significant for global initializer
14101 bool partition
= is_partition () && !parent
->is_partition ();
14102 subst
= mangle_module_component (name
, partition
);
14103 substs
.safe_push (this);
14109 mangle_module (int mod
, bool include_partition
)
14111 module_state
*imp
= (*modules
)[mod
];
14113 gcc_checking_assert (!imp
->is_header ());
14116 /* Set when importing the primary module interface. */
14119 imp
->mangle (include_partition
);
14122 /* Clean up substitutions. */
14124 mangle_module_fini ()
14126 while (substs
.length ())
14127 substs
.pop ()->subst
= 0;
14130 /* Announce WHAT about the module. */
14133 module_state::announce (const char *what
) const
14137 fprintf (stderr
, " %s:%s", what
, get_flatname ());
14142 /* A human-readable README section. The contents of this section to
14143 not contribute to the CRC, so the contents can change per
14144 compilation. That allows us to embed CWD, hostname, build time and
14145 what not. It is a STRTAB that may be extracted with:
14146 readelf -pgnu.c++.README $(module).gcm */
14149 module_state::write_readme (elf_out
*to
, cpp_reader
*reader
, const char *dialect
)
14151 bytes_out
readme (to
);
14153 readme
.begin (false);
14155 readme
.printf ("GNU C++ %s",
14156 is_header () ? "header unit"
14157 : !is_partition () ? "primary interface"
14158 : is_interface () ? "interface partition"
14159 : "internal partition");
14161 /* Compiler's version. */
14162 readme
.printf ("compiler: %s", version_string
);
14164 /* Module format version. */
14166 version2string (MODULE_VERSION
, string
);
14167 readme
.printf ("version: %s", string
);
14169 /* Module information. */
14170 readme
.printf ("module: %s", get_flatname ());
14171 readme
.printf ("source: %s", main_input_filename
);
14172 readme
.printf ("dialect: %s", dialect
);
14174 readme
.printf ("extensions: %s",
14175 extensions
& SE_OPENMP
? "-fopenmp" : "");
14177 /* The following fields could be expected to change between
14178 otherwise identical compilations. Consider a distributed build
14179 system. We should have a way of overriding that. */
14180 if (char *cwd
= getcwd (NULL
, 0))
14182 readme
.printf ("cwd: %s", cwd
);
14185 readme
.printf ("repository: %s", cmi_repo
? cmi_repo
: ".");
14189 if (!gethostname (hostname
, sizeof (hostname
)))
14190 readme
.printf ("host: %s", hostname
);
14194 /* This of course will change! */
14196 auto kind
= cpp_get_date (reader
, &stampy
);
14197 if (kind
!= CPP_time_kind::UNKNOWN
)
14201 time
= gmtime (&stampy
);
14202 readme
.print_time ("build", time
, "UTC");
14204 if (kind
== CPP_time_kind::DYNAMIC
)
14206 time
= localtime (&stampy
);
14207 readme
.print_time ("local", time
,
14208 #if defined (__USE_MISC) || defined (__USE_BSD) /* Is there a better way? */
14218 /* Its direct imports. */
14219 for (unsigned ix
= 1; ix
< modules
->length (); ix
++)
14221 module_state
*state
= (*modules
)[ix
];
14223 if (state
->is_direct ())
14224 readme
.printf ("%s: %s %s", state
->exported_p
? "export" : "import",
14225 state
->get_flatname (), state
->filename
);
14228 readme
.end (to
, to
->name (MOD_SNAME_PFX
".README"), NULL
);
14231 /* Sort environment var names in reverse order. */
14234 env_var_cmp (const void *a_
, const void *b_
)
14236 const unsigned char *a
= *(const unsigned char *const *)a_
;
14237 const unsigned char *b
= *(const unsigned char *const *)b_
;
14239 for (unsigned ix
= 0; ; ix
++)
14241 bool a_end
= !a
[ix
] || a
[ix
] == '=';
14242 if (a
[ix
] == b
[ix
])
14249 bool b_end
= !b
[ix
] || b
[ix
] == '=';
14251 if (!a_end
&& !b_end
)
14252 return a
[ix
] < b
[ix
] ? +1 : -1;
14253 if (a_end
&& b_end
)
14255 return a_end
? +1 : -1;
14262 /* Write the environment. It is a STRTAB that may be extracted with:
14263 readelf -pgnu.c++.ENV $(module).gcm */
14266 module_state::write_env (elf_out
*to
)
14268 vec
<const char *> vars
;
14271 extern char **environ
;
14272 while (const char *var
= environ
[vars
.length ()])
14273 vars
.safe_push (var
);
14274 vars
.qsort (env_var_cmp
);
14276 bytes_out
env (to
);
14278 while (vars
.length ())
14279 env
.printf ("%s", vars
.pop ());
14280 env
.end (to
, to
->name (MOD_SNAME_PFX
".ENV"), NULL
);
14285 /* Write the direct or indirect imports.
14291 s:filename (direct)
14292 u:exported (direct)
14297 module_state::write_imports (bytes_out
&sec
, bool direct
)
14299 unsigned count
= 0;
14301 for (unsigned ix
= 1; ix
< modules
->length (); ix
++)
14303 module_state
*imp
= (*modules
)[ix
];
14305 if (imp
->remap
&& imp
->is_direct () == direct
)
14309 gcc_assert (!direct
|| count
);
14312 for (unsigned ix
= 1; ix
< modules
->length (); ix
++)
14314 module_state
*imp
= (*modules
)[ix
];
14316 if (imp
->remap
&& imp
->is_direct () == direct
)
14318 dump () && dump ("Writing %simport:%u->%u %M (crc=%x)",
14319 !direct
? "indirect "
14320 : imp
->exported_p
? "exported " : "",
14321 ix
, imp
->remap
, imp
, imp
->crc
);
14322 sec
.u (imp
->remap
);
14323 sec
.str (imp
->get_flatname ());
14324 sec
.u32 (imp
->crc
);
14327 write_location (sec
, imp
->imported_from ());
14328 sec
.str (imp
->filename
);
14329 int exportedness
= 0;
14330 if (imp
->exported_p
)
14332 else if (!imp
->is_purview_direct ())
14334 sec
.i (exportedness
);
14340 /* READER, LMAPS != NULL == direct imports,
14341 == NUL == indirect imports. */
14344 module_state::read_imports (bytes_in
&sec
, cpp_reader
*reader
, line_maps
*lmaps
)
14346 unsigned count
= sec
.u ();
14347 unsigned loaded
= 0;
14351 unsigned ix
= sec
.u ();
14352 if (ix
>= slurp
->remap
->length () || !ix
|| (*slurp
->remap
)[ix
])
14354 sec
.set_overrun ();
14358 const char *name
= sec
.str (NULL
);
14359 module_state
*imp
= get_module (name
);
14360 unsigned crc
= sec
.u32 ();
14361 int exportedness
= 0;
14363 /* If the import is a partition, it must be the same primary
14364 module as this TU. */
14365 if (imp
&& imp
->is_partition () &&
14366 (!named_module_p ()
14367 || (get_primary ((*modules
)[0]) != get_primary (imp
))))
14371 sec
.set_overrun ();
14372 if (sec
.get_overrun ())
14377 /* A direct import, maybe load it. */
14378 location_t floc
= read_location (sec
);
14379 const char *fname
= sec
.str (NULL
);
14380 exportedness
= sec
.i ();
14382 if (sec
.get_overrun ())
14385 if (!imp
->check_not_purview (loc
))
14388 if (imp
->loadedness
== ML_NONE
)
14392 if (!imp
->get_flatname ())
14393 imp
->set_flatname ();
14395 unsigned n
= dump
.push (imp
);
14397 if (!imp
->filename
&& fname
)
14398 imp
->filename
= xstrdup (fname
);
14400 if (imp
->is_partition ())
14401 dump () && dump ("Importing elided partition %M", imp
);
14403 if (!imp
->do_import (reader
, false))
14410 if (is_partition ())
14412 if (!imp
->is_direct ())
14413 imp
->directness
= MD_PARTITION_DIRECT
;
14414 if (exportedness
> 0)
14415 imp
->exported_p
= true;
14420 /* An indirect import, find it, it should already be here. */
14421 if (imp
->loadedness
== ML_NONE
)
14423 error_at (loc
, "indirect import %qs is not already loaded", name
);
14428 if (imp
->crc
!= crc
)
14429 error_at (loc
, "import %qs has CRC mismatch", imp
->get_flatname ());
14431 (*slurp
->remap
)[ix
] = (imp
->mod
<< 1) | (lmaps
!= NULL
);
14433 if (lmaps
&& exportedness
>= 0)
14434 set_import (imp
, bool (exportedness
));
14435 dump () && dump ("Found %simport:%u %M->%u", !lmaps
? "indirect "
14436 : exportedness
> 0 ? "exported "
14437 : exportedness
< 0 ? "gmf" : "", ix
, imp
,
14445 /* Write the import table to MOD_SNAME_PFX.imp. */
14448 module_state::write_imports (elf_out
*to
, unsigned *crc_ptr
)
14450 dump () && dump ("Writing imports");
14453 bytes_out
sec (to
);
14456 write_imports (sec
, true);
14457 write_imports (sec
, false);
14459 sec
.end (to
, to
->name (MOD_SNAME_PFX
".imp"), crc_ptr
);
14464 module_state::read_imports (cpp_reader
*reader
, line_maps
*lmaps
)
14468 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".imp"))
14471 dump () && dump ("Reading %u imports", slurp
->remap
->length () - 1);
14474 /* Read the imports. */
14475 unsigned direct
= read_imports (sec
, reader
, lmaps
);
14476 unsigned indirect
= read_imports (sec
, NULL
, NULL
);
14477 if (direct
+ indirect
+ 1 != slurp
->remap
->length ())
14478 from ()->set_error (elf::E_BAD_IMPORT
);
14481 if (!sec
.end (from ()))
14486 /* We're the primary module interface, but have partitions. Document
14487 them so that non-partition module implementation units know which
14488 have already been loaded. */
14491 module_state::write_partitions (elf_out
*to
, unsigned count
, unsigned *crc_ptr
)
14493 dump () && dump ("Writing %u elided partitions", count
);
14496 bytes_out
sec (to
);
14499 for (unsigned ix
= 1; ix
!= modules
->length (); ix
++)
14501 module_state
*imp
= (*modules
)[ix
];
14502 if (imp
->is_partition ())
14504 dump () && dump ("Writing elided partition %M (crc=%x)",
14506 sec
.str (imp
->get_flatname ());
14507 sec
.u32 (imp
->crc
);
14508 write_location (sec
, imp
->is_direct ()
14509 ? imp
->imported_from () : UNKNOWN_LOCATION
);
14510 sec
.str (imp
->filename
);
14514 sec
.end (to
, to
->name (MOD_SNAME_PFX
".prt"), crc_ptr
);
14519 module_state::read_partitions (unsigned count
)
14522 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".prt"))
14525 dump () && dump ("Reading %u elided partitions", count
);
14530 const char *name
= sec
.str (NULL
);
14531 unsigned crc
= sec
.u32 ();
14532 location_t floc
= read_location (sec
);
14533 const char *fname
= sec
.str (NULL
);
14535 if (sec
.get_overrun ())
14538 dump () && dump ("Reading elided partition %s (crc=%x)", name
, crc
);
14540 module_state
*imp
= get_module (name
);
14541 if (!imp
/* Partition should be ... */
14542 || !imp
->is_partition () /* a partition ... */
14543 || imp
->loadedness
!= ML_NONE
/* that is not yet loaded ... */
14544 || get_primary (imp
) != this) /* whose primary is this. */
14546 sec
.set_overrun ();
14550 if (!imp
->has_location ())
14553 if (!imp
->filename
&& fname
[0])
14554 imp
->filename
= xstrdup (fname
);
14558 if (!sec
.end (from ()))
14563 /* Data for config reading and writing. */
14564 struct module_state_config
{
14565 const char *dialect_str
;
14566 unsigned num_imports
;
14567 unsigned num_partitions
;
14568 unsigned num_entities
;
14569 unsigned ordinary_locs
;
14570 unsigned macro_locs
;
14571 unsigned loc_range_bits
;
14572 unsigned active_init
;
14575 module_state_config ()
14576 :dialect_str (get_dialect ()),
14577 num_imports (0), num_partitions (0), num_entities (0),
14578 ordinary_locs (0), macro_locs (0), loc_range_bits (0),
14583 static void release ()
14585 XDELETEVEC (dialect
);
14590 static const char *get_dialect ();
14591 static char *dialect
;
14594 char *module_state_config::dialect
;
14596 /* Generate a string of the significant compilation options.
14597 Generally assume the user knows what they're doing, in the same way
14598 that object files can be mixed. */
14601 module_state_config::get_dialect ()
14604 dialect
= concat (get_cxx_dialect_name (cxx_dialect
),
14605 /* C++ implies these, only show if disabled. */
14606 flag_exceptions
? "" : "/no-exceptions",
14607 flag_rtti
? "" : "/no-rtti",
14608 flag_new_inheriting_ctors
? "" : "/old-inheriting-ctors",
14609 /* C++ 20 implies concepts. */
14610 cxx_dialect
< cxx20
&& flag_concepts
? "/concepts" : "",
14611 flag_coroutines
? "/coroutines" : "",
14612 flag_module_implicit_inline
? "/implicit-inline" : "",
14613 flag_contracts
? "/contracts" : "",
14619 /* Contents of a cluster. */
14621 ct_decl
, /* A decl. */
14622 ct_defn
, /* A definition. */
14623 ct_bind
, /* A binding. */
14627 /* Binding modifiers. */
14630 cbf_export
= 0x1, /* An exported decl. */
14631 cbf_hidden
= 0x2, /* A hidden (friend) decl. */
14632 cbf_using
= 0x4, /* A using decl. */
14633 cbf_wrapped
= 0x8, /* ... that is wrapped. */
14636 /* DEP belongs to a different cluster, seed it to prevent
14637 unfortunately timed duplicate import. */
14638 // FIXME: QOI For inter-cluster references we could just only pick
14639 // one entity from an earlier cluster. Even better track
14640 // dependencies between earlier clusters
14643 module_state::intercluster_seed (trees_out
&sec
, unsigned index_hwm
, depset
*dep
)
14645 if (dep
->is_import ()
14646 || dep
->cluster
< index_hwm
)
14648 tree ent
= dep
->get_entity ();
14649 if (!TREE_VISITED (ent
))
14651 sec
.tree_node (ent
);
14652 dump (dumper::CLUSTER
)
14653 && dump ("Seeded %s %N",
14654 dep
->is_import () ? "import" : "intercluster", ent
);
14659 /* Write the cluster of depsets in SCC[0-SIZE).
14660 dep->section -> section number
14661 dep->cluster -> entity number
14665 module_state::write_cluster (elf_out
*to
, depset
*scc
[], unsigned size
,
14666 depset::hash
&table
, unsigned *counts
,
14669 dump () && dump ("Writing section:%u %u depsets", table
.section
, size
);
14672 trees_out
sec (to
, this, table
, table
.section
);
14674 unsigned index_lwm
= counts
[MSC_entities
];
14676 /* Determine entity numbers, mark for writing. */
14677 dump (dumper::CLUSTER
) && dump ("Cluster members:") && (dump
.indent (), true);
14678 for (unsigned ix
= 0; ix
!= size
; ix
++)
14680 depset
*b
= scc
[ix
];
14682 switch (b
->get_entity_kind ())
14685 gcc_unreachable ();
14687 case depset::EK_BINDING
:
14689 dump (dumper::CLUSTER
)
14690 && dump ("[%u]=%s %P", ix
, b
->entity_kind_name (),
14691 b
->get_entity (), b
->get_name ());
14692 depset
*ns_dep
= b
->deps
[0];
14693 gcc_checking_assert (ns_dep
->get_entity_kind ()
14694 == depset::EK_NAMESPACE
14695 && ns_dep
->get_entity () == b
->get_entity ());
14696 for (unsigned jx
= b
->deps
.length (); --jx
;)
14698 depset
*dep
= b
->deps
[jx
];
14699 // We could be declaring something that is also a
14701 gcc_checking_assert (dep
->is_import ()
14702 || TREE_VISITED (dep
->get_entity ())
14703 || (dep
->get_entity_kind ()
14704 == depset::EK_USING
));
14709 case depset::EK_DECL
:
14710 case depset::EK_SPECIALIZATION
:
14711 case depset::EK_PARTIAL
:
14712 b
->cluster
= counts
[MSC_entities
]++;
14713 sec
.mark_declaration (b
->get_entity (), b
->has_defn ());
14716 case depset::EK_USING
:
14717 gcc_checking_assert (!b
->is_import ()
14718 && !b
->is_unreached ());
14719 dump (dumper::CLUSTER
)
14720 && dump ("[%u]=%s %s %N", ix
, b
->entity_kind_name (),
14721 b
->has_defn () ? "definition" : "declaration",
14726 dump (dumper::CLUSTER
) && (dump
.outdent (), true);
14728 /* Ensure every out-of-cluster decl is referenced before we start
14729 streaming. We must do both imports *and* earlier clusters,
14730 because the latter could reach into the former and cause a
14732 sec
.set_importing (+1);
14733 for (unsigned ix
= 0; ix
!= size
; ix
++)
14735 depset
*b
= scc
[ix
];
14736 for (unsigned jx
= (b
->get_entity_kind () == depset::EK_BINDING
14737 || b
->is_special ()) ? 1 : 0;
14738 jx
!= b
->deps
.length (); jx
++)
14740 depset
*dep
= b
->deps
[jx
];
14742 if (dep
->is_binding ())
14744 for (unsigned ix
= dep
->deps
.length (); --ix
;)
14746 depset
*bind
= dep
->deps
[ix
];
14747 if (bind
->get_entity_kind () == depset::EK_USING
)
14748 bind
= bind
->deps
[1];
14750 intercluster_seed (sec
, index_lwm
, bind
);
14752 /* Also check the namespace itself. */
14753 dep
= dep
->deps
[0];
14756 intercluster_seed (sec
, index_lwm
, dep
);
14759 sec
.tree_node (NULL_TREE
);
14760 /* We're done importing now. */
14761 sec
.set_importing (-1);
14763 /* Write non-definitions. */
14764 for (unsigned ix
= 0; ix
!= size
; ix
++)
14766 depset
*b
= scc
[ix
];
14767 tree decl
= b
->get_entity ();
14768 switch (b
->get_entity_kind ())
14771 gcc_unreachable ();
14774 case depset::EK_BINDING
:
14776 gcc_assert (TREE_CODE (decl
) == NAMESPACE_DECL
);
14777 dump () && dump ("Depset:%u binding %C:%P", ix
, TREE_CODE (decl
),
14778 decl
, b
->get_name ());
14780 sec
.tree_node (decl
);
14781 sec
.tree_node (b
->get_name ());
14783 /* Write in reverse order, so reading will see the exports
14784 first, thus building the overload chain will be
14786 for (unsigned jx
= b
->deps
.length (); --jx
;)
14788 depset
*dep
= b
->deps
[jx
];
14789 tree bound
= dep
->get_entity ();
14790 unsigned flags
= 0;
14791 if (dep
->get_entity_kind () == depset::EK_USING
)
14794 bound
= OVL_FUNCTION (bound
);
14795 if (!(TREE_CODE (bound
) == CONST_DECL
14796 && UNSCOPED_ENUM_P (TREE_TYPE (bound
))
14797 && decl
== TYPE_NAME (TREE_TYPE (bound
))))
14799 /* An unscope enumerator in its enumeration's
14800 scope is not a using. */
14801 flags
|= cbf_using
;
14802 if (OVL_USING_P (ovl
))
14803 flags
|= cbf_wrapped
;
14805 if (OVL_EXPORT_P (ovl
))
14806 flags
|= cbf_export
;
14810 /* An implicit typedef must be at one. */
14811 gcc_assert (!DECL_IMPLICIT_TYPEDEF_P (bound
) || jx
== 1);
14812 if (dep
->is_hidden ())
14813 flags
|= cbf_hidden
;
14814 else if (DECL_MODULE_EXPORT_P (STRIP_TEMPLATE (bound
)))
14815 flags
|= cbf_export
;
14818 gcc_checking_assert (DECL_P (bound
));
14821 sec
.tree_node (bound
);
14824 /* Terminate the list. */
14829 case depset::EK_USING
:
14830 dump () && dump ("Depset:%u %s %C:%N", ix
, b
->entity_kind_name (),
14831 TREE_CODE (decl
), decl
);
14834 case depset::EK_SPECIALIZATION
:
14835 case depset::EK_PARTIAL
:
14836 case depset::EK_DECL
:
14837 dump () && dump ("Depset:%u %s entity:%u %C:%N", ix
,
14838 b
->entity_kind_name (), b
->cluster
,
14839 TREE_CODE (decl
), decl
);
14842 sec
.tree_node (decl
);
14844 dump () && dump ("Wrote declaration entity:%u %C:%N",
14845 b
->cluster
, TREE_CODE (decl
), decl
);
14850 depset
*namer
= NULL
;
14852 /* Write out definitions */
14853 for (unsigned ix
= 0; ix
!= size
; ix
++)
14855 depset
*b
= scc
[ix
];
14856 tree decl
= b
->get_entity ();
14857 switch (b
->get_entity_kind ())
14862 case depset::EK_SPECIALIZATION
:
14863 case depset::EK_PARTIAL
:
14864 case depset::EK_DECL
:
14868 if (b
->has_defn ())
14871 sec
.tree_node (decl
);
14872 dump () && dump ("Writing definition %N", decl
);
14873 sec
.write_definition (decl
);
14875 if (!namer
->has_defn ())
14882 /* We don't find the section by name. Use depset's decl's name for
14883 human friendliness. */
14885 tree naming_decl
= NULL_TREE
;
14888 naming_decl
= namer
->get_entity ();
14889 if (namer
->get_entity_kind () == depset::EK_USING
)
14890 /* This unfortunately names the section from the target of the
14891 using decl. But the name is only a guide, so Do Not Care. */
14892 naming_decl
= OVL_FUNCTION (naming_decl
);
14893 if (DECL_IMPLICIT_TYPEDEF_P (naming_decl
))
14894 /* Lose any anonymousness. */
14895 naming_decl
= TYPE_NAME (TREE_TYPE (naming_decl
));
14896 name
= to
->qualified_name (naming_decl
, namer
->has_defn ());
14899 unsigned bytes
= sec
.pos
;
14900 unsigned snum
= sec
.end (to
, name
, crc_ptr
);
14902 for (unsigned ix
= size
; ix
--;)
14903 gcc_checking_assert (scc
[ix
]->section
== snum
);
14906 dump () && dump ("Wrote section:%u named-by:%N", table
.section
, naming_decl
);
14911 /* Read a cluster from section SNUM. */
14914 module_state::read_cluster (unsigned snum
)
14916 trees_in
sec (this);
14918 if (!sec
.begin (loc
, from (), snum
))
14921 dump () && dump ("Reading section:%u", snum
);
14924 /* We care about structural equality. */
14925 comparing_dependent_aliases
++;
14927 /* First seed the imports. */
14928 while (tree import
= sec
.tree_node ())
14929 dump (dumper::CLUSTER
) && dump ("Seeded import %N", import
);
14931 while (!sec
.get_overrun () && sec
.more_p ())
14933 unsigned ct
= sec
.u ();
14937 sec
.set_overrun ();
14941 /* A set of namespace bindings. */
14943 tree ns
= sec
.tree_node ();
14944 tree name
= sec
.tree_node ();
14945 tree decls
= NULL_TREE
;
14946 tree visible
= NULL_TREE
;
14947 tree type
= NULL_TREE
;
14948 bool dedup
= false;
14950 /* We rely on the bindings being in the reverse order of
14951 the resulting overload set. */
14954 int flags
= sec
.i ();
14958 if ((flags
& cbf_hidden
)
14959 && (flags
& (cbf_using
| cbf_export
)))
14960 sec
.set_overrun ();
14962 tree decl
= sec
.tree_node ();
14963 if (sec
.get_overrun ())
14966 if (decls
&& TREE_CODE (decl
) == TYPE_DECL
)
14969 if (type
|| !DECL_IMPLICIT_TYPEDEF_P (decl
))
14970 sec
.set_overrun ();
14976 || (flags
& (cbf_hidden
| cbf_wrapped
))
14977 || DECL_FUNCTION_TEMPLATE_P (decl
))
14979 decls
= ovl_make (decl
, decls
);
14980 if (flags
& cbf_using
)
14983 OVL_USING_P (decls
) = true;
14984 if (flags
& cbf_export
)
14985 OVL_EXPORT_P (decls
) = true;
14988 if (flags
& cbf_hidden
)
14989 OVL_HIDDEN_P (decls
) = true;
14991 OVL_DEDUP_P (decls
) = true;
14996 if (flags
& cbf_export
14997 || (!(flags
& cbf_hidden
)
14998 && (is_module () || is_partition ())))
15004 sec
.set_overrun ();
15006 if (sec
.get_overrun ())
15009 dump () && dump ("Binding of %P", ns
, name
);
15010 if (!set_module_binding (ns
, name
, mod
,
15012 : is_module () || is_partition () ? 1
15014 decls
, type
, visible
))
15015 sec
.set_overrun ();
15022 tree decl
= sec
.tree_node ();
15023 dump () && dump ("Read declaration of %N", decl
);
15029 tree decl
= sec
.tree_node ();
15030 dump () && dump ("Reading definition of %N", decl
);
15031 sec
.read_definition (decl
);
15037 /* When lazy loading is in effect, we can be in the middle of
15038 parsing or instantiating a function. Save it away.
15039 push_function_context does too much work. */
15040 tree old_cfd
= current_function_decl
;
15041 struct function
*old_cfun
= cfun
;
15042 while (tree decl
= sec
.post_process ())
15044 bool abstract
= false;
15045 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
15048 decl
= DECL_TEMPLATE_RESULT (decl
);
15051 current_function_decl
= decl
;
15052 allocate_struct_function (decl
, abstract
);
15053 cfun
->language
= ggc_cleared_alloc
<language_function
> ();
15054 cfun
->language
->base
.x_stmt_tree
.stmts_are_full_exprs_p
= 1;
15058 else if (DECL_ABSTRACT_P (decl
))
15059 vec_safe_push (post_load_decls
, decl
);
15062 bool aggr
= aggregate_value_p (DECL_RESULT (decl
), decl
);
15063 #ifdef PCC_STATIC_STRUCT_RETURN
15064 cfun
->returns_pcc_struct
= aggr
;
15066 cfun
->returns_struct
= aggr
;
15068 if (DECL_COMDAT (decl
))
15069 // FIXME: Comdat grouping?
15070 comdat_linkage (decl
);
15071 note_vague_linkage_fn (decl
);
15072 cgraph_node::finalize_function (decl
, true);
15076 /* Look, function.cc's interface to cfun does too much for us, we
15077 just need to restore the old value. I do not want to go
15078 redesigning that API right now. */
15081 current_function_decl
= old_cfd
;
15082 comparing_dependent_aliases
--;
15085 dump () && dump ("Read section:%u", snum
);
15089 if (!sec
.end (from ()))
15096 module_state::write_namespace (bytes_out
&sec
, depset
*dep
)
15098 unsigned ns_num
= dep
->cluster
;
15099 unsigned ns_import
= 0;
15101 if (dep
->is_import ())
15102 ns_import
= dep
->section
;
15103 else if (dep
->get_entity () != global_namespace
)
15111 module_state::read_namespace (bytes_in
&sec
)
15113 unsigned ns_import
= sec
.u ();
15114 unsigned ns_num
= sec
.u ();
15115 tree ns
= NULL_TREE
;
15117 if (ns_import
|| ns_num
)
15122 if (unsigned origin
= slurp
->remap_module (ns_import
))
15124 module_state
*from
= (*modules
)[origin
];
15125 if (ns_num
< from
->entity_num
)
15127 binding_slot
&slot
= (*entity_ary
)[from
->entity_lwm
+ ns_num
];
15129 if (!slot
.is_lazy ())
15134 sec
.set_overrun ();
15137 ns
= global_namespace
;
15142 /* SPACES is a sorted vector of namespaces. Write out the namespaces
15143 to MOD_SNAME_PFX.nms section. */
15146 module_state::write_namespaces (elf_out
*to
, vec
<depset
*> spaces
,
15147 unsigned num
, unsigned *crc_p
)
15149 dump () && dump ("Writing namespaces");
15152 bytes_out
sec (to
);
15155 for (unsigned ix
= 0; ix
!= num
; ix
++)
15157 depset
*b
= spaces
[ix
];
15158 tree ns
= b
->get_entity ();
15160 gcc_checking_assert (TREE_CODE (ns
) == NAMESPACE_DECL
);
15161 /* P1815 may have something to say about this. */
15162 gcc_checking_assert (TREE_PUBLIC (ns
));
15164 unsigned flags
= 0;
15165 if (TREE_PUBLIC (ns
))
15167 if (DECL_NAMESPACE_INLINE_P (ns
))
15169 if (DECL_MODULE_PURVIEW_P (ns
))
15171 if (DECL_MODULE_EXPORT_P (ns
))
15174 dump () && dump ("Writing namespace:%u %N%s%s%s%s",
15176 flags
& 1 ? ", public" : "",
15177 flags
& 2 ? ", inline" : "",
15178 flags
& 4 ? ", purview" : "",
15179 flags
& 8 ? ", export" : "");
15180 sec
.u (b
->cluster
);
15181 sec
.u (to
->name (DECL_NAME (ns
)));
15182 write_namespace (sec
, b
->deps
[0]);
15185 write_location (sec
, DECL_SOURCE_LOCATION (ns
));
15188 sec
.end (to
, to
->name (MOD_SNAME_PFX
".nms"), crc_p
);
15192 /* Read the namespace hierarchy from MOD_SNAME_PFX.namespace. Fill in
15193 SPACES from that data. */
15196 module_state::read_namespaces (unsigned num
)
15200 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".nms"))
15203 dump () && dump ("Reading namespaces");
15206 for (unsigned ix
= 0; ix
!= num
; ix
++)
15208 unsigned entity_index
= sec
.u ();
15209 unsigned name
= sec
.u ();
15211 tree parent
= read_namespace (sec
);
15213 /* See comment in write_namespace about why not bits. */
15214 unsigned flags
= sec
.u ();
15215 location_t src_loc
= read_location (sec
);
15217 if (entity_index
>= entity_num
15219 || (flags
& 0xc) == 0x8)
15220 sec
.set_overrun ();
15221 if (sec
.get_overrun ())
15224 tree id
= name
? get_identifier (from ()->name (name
)) : NULL_TREE
;
15226 dump () && dump ("Read namespace:%u %P%s%s%s%s",
15227 entity_index
, parent
, id
,
15228 flags
& 1 ? ", public" : "",
15229 flags
& 2 ? ", inline" : "",
15230 flags
& 4 ? ", purview" : "",
15231 flags
& 8 ? ", export" : "");
15232 bool visible_p
= ((flags
& 8)
15235 && (is_partition () || is_module ())));
15236 tree inner
= add_imported_namespace (parent
, id
, src_loc
, mod
,
15237 bool (flags
& 2), visible_p
);
15240 sec
.set_overrun ();
15244 if (is_partition ())
15247 DECL_MODULE_PURVIEW_P (inner
) = true;
15249 DECL_MODULE_EXPORT_P (inner
) = true;
15252 /* Install the namespace. */
15253 (*entity_ary
)[entity_lwm
+ entity_index
] = inner
;
15254 if (DECL_MODULE_IMPORT_P (inner
))
15257 unsigned *slot
= &entity_map
->get_or_insert
15258 (DECL_UID (inner
), &existed
);
15260 /* If it existed, it should match. */
15261 gcc_checking_assert (inner
== (*entity_ary
)[*slot
]);
15263 *slot
= entity_lwm
+ entity_index
;
15267 if (!sec
.end (from ()))
15272 /* Write the binding TABLE to MOD_SNAME_PFX.bnd */
15275 module_state::write_bindings (elf_out
*to
, vec
<depset
*> sccs
, unsigned *crc_p
)
15277 dump () && dump ("Writing binding table");
15281 bytes_out
sec (to
);
15284 for (unsigned ix
= 0; ix
!= sccs
.length (); ix
++)
15286 depset
*b
= sccs
[ix
];
15287 if (b
->is_binding ())
15289 tree ns
= b
->get_entity ();
15290 dump () && dump ("Bindings %P section:%u", ns
, b
->get_name (),
15292 sec
.u (to
->name (b
->get_name ()));
15293 write_namespace (sec
, b
->deps
[0]);
15294 sec
.u (b
->section
);
15299 sec
.end (to
, to
->name (MOD_SNAME_PFX
".bnd"), crc_p
);
15305 /* Read the binding table from MOD_SNAME_PFX.bind. */
15308 module_state::read_bindings (unsigned num
, unsigned lwm
, unsigned hwm
)
15312 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".bnd"))
15315 dump () && dump ("Reading binding table");
15317 for (; !sec
.get_overrun () && num
--;)
15319 const char *name
= from ()->name (sec
.u ());
15320 tree ns
= read_namespace (sec
);
15321 unsigned snum
= sec
.u ();
15323 if (!ns
|| !name
|| (snum
- lwm
) >= (hwm
- lwm
))
15324 sec
.set_overrun ();
15325 if (!sec
.get_overrun ())
15327 tree id
= get_identifier (name
);
15328 dump () && dump ("Bindings %P section:%u", ns
, id
, snum
);
15329 if (mod
&& !import_module_binding (ns
, id
, mod
, snum
))
15335 if (!sec
.end (from ()))
15340 /* Write the entity table to MOD_SNAME_PFX.ent
15342 Each entry is a section number. */
15345 module_state::write_entities (elf_out
*to
, vec
<depset
*> depsets
,
15346 unsigned count
, unsigned *crc_p
)
15348 dump () && dump ("Writing entities");
15351 bytes_out
sec (to
);
15354 unsigned current
= 0;
15355 for (unsigned ix
= 0; ix
< depsets
.length (); ix
++)
15357 depset
*d
= depsets
[ix
];
15359 switch (d
->get_entity_kind ())
15364 case depset::EK_NAMESPACE
:
15365 if (!d
->is_import () && d
->get_entity () != global_namespace
)
15367 gcc_checking_assert (d
->cluster
== current
);
15373 case depset::EK_DECL
:
15374 case depset::EK_SPECIALIZATION
:
15375 case depset::EK_PARTIAL
:
15376 gcc_checking_assert (!d
->is_unreached ()
15377 && !d
->is_import ()
15378 && d
->cluster
== current
15381 sec
.u (d
->section
);
15385 gcc_assert (count
== current
);
15386 sec
.end (to
, to
->name (MOD_SNAME_PFX
".ent"), crc_p
);
15391 module_state::read_entities (unsigned count
, unsigned lwm
, unsigned hwm
)
15393 trees_in
sec (this);
15395 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".ent"))
15398 dump () && dump ("Reading entities");
15401 for (binding_slot
*slot
= entity_ary
->begin () + entity_lwm
; count
--; slot
++)
15403 unsigned snum
= sec
.u ();
15404 if (snum
&& (snum
- lwm
) >= (hwm
- lwm
))
15405 sec
.set_overrun ();
15406 if (sec
.get_overrun ())
15410 slot
->set_lazy (snum
<< 2);
15414 if (!sec
.end (from ()))
15419 /* Write the pending table to MOD_SNAME_PFX.pnd
15421 The pending table holds information about clusters that need to be
15422 loaded because they contain information about something that is not
15423 found by namespace-scope lookup.
15425 The three cases are:
15427 (a) Template (maybe-partial) specializations that we have
15428 instantiated or defined. When an importer needs to instantiate
15429 that template, they /must have/ the partial, explicit & extern
15430 specializations available. If they have the other specializations
15431 available, they'll have less work to do. Thus, when we're about to
15432 instantiate FOO, we have to be able to ask 'are there any
15433 specialization of FOO in our imports?'.
15435 (b) (Maybe-implicit) member functions definitions. A class could
15436 be defined in one header, and an inline member defined in a
15437 different header (this occurs in the STL). Similarly, like the
15438 specialization case, an implicit member function could have been
15439 'instantiated' in one module, and it'd be nice to not have to
15440 reinstantiate it in another.
15442 (c) A member classes completed elsewhere. A member class could be
15443 declared in one header and defined in another. We need to know to
15444 load the class definition before looking in it. This turns out to
15445 be a specific case of #b, so we can treat these the same. But it
15446 does highlight an issue -- there could be an intermediate import
15447 between the outermost containing namespace-scope class and the
15448 innermost being-defined member class. This is actually possible
15449 with all of these cases, so be aware -- we're not just talking of
15450 one level of import to get to the innermost namespace.
15452 This gets complicated fast, it took me multiple attempts to even
15453 get something remotely working. Partially because I focussed on
15454 optimizing what I think turns out to be a smaller problem, given
15455 the known need to do the more general case *anyway*. I document
15456 the smaller problem, because it does appear to be the natural way
15457 to do it. It's trap!
15461 Let's refer to the primary template or the containing class as the
15462 KEY. And the specialization or member as the PENDING-ENTITY. (To
15463 avoid having to say those mouthfuls all the time.)
15465 In either case, we have an entity and we need some way of mapping
15466 that to a set of entities that need to be loaded before we can
15467 proceed with whatever processing of the entity we were going to do.
15469 We need to link the key to the pending-entity in some way. Given a
15470 key, tell me the pending-entities I need to have loaded. However
15471 we tie the key to the pending-entity must not rely on the key being
15472 loaded -- that'd defeat the lazy loading scheme.
15474 As the key will be an import in we know its entity number (either
15475 because we imported it, or we're writing it out too). Thus we can
15476 generate a map of key-indices to pending-entities. The
15477 pending-entity indices will be into our span of the entity table,
15478 and thus allow them to be lazily loaded. The key index will be
15479 into another slot of the entity table. Notice that this checking
15480 could be expensive, we don't want to iterate over a bunch of
15481 pending-entity indices (across multiple imports), every time we're
15482 about do to the thing with the key. We need to quickly determine
15483 'definitely nothing needed'.
15485 That's almost good enough, except that key indices are not unique
15486 in a couple of cases :( Specifically the Global Module or a module
15487 partition can result in multiple modules assigning an entity index
15488 for the key. The decl-merging on loading will detect that so we
15489 only have one Key loaded, and in the entity hash it'll indicate the
15490 entity index of first load. Which might be different to how we
15491 know it. Notice this is restricted to GM entities or this-module
15492 entities. Foreign imports cannot have this.
15494 We can simply resolve this in the direction of how this module
15495 referred to the key to how the importer knows it. Look in the
15496 entity table slot that we nominate, maybe lazy load it, and then
15497 lookup the resultant entity in the entity hash to learn how the
15500 But we need to go in the other direction :( Given the key, find all
15501 the index-aliases of that key. We can partially solve that by
15502 adding an alias hash table. Whenever we load a merged decl, add or
15503 augment a mapping from the entity (or its entity-index) to the
15504 newly-discovered index. Then when we look for pending entities of
15505 a key, we also iterate over this aliases this mapping provides.
15507 But that requires the alias to be loaded. And that's not
15510 *** THE SIMPLER WAY
15512 The remaining fixed thing we have is the innermost namespace
15513 containing the ultimate namespace-scope container of the key and
15514 the name of that container (which might be the key itself). I.e. a
15515 namespace-decl/identifier/module tuple. Let's call this the
15516 top-key. We'll discover that the module is not important here,
15517 because of cross-module possibilities mentioned in case #c above.
15518 We can't markup namespace-binding slots. The best we can do is
15519 mark the binding vector with 'there's something here', and have
15520 another map from namespace/identifier pairs to a vector of pending
15523 Maintain a pending-entity map. This is keyed by top-key, and
15524 maps to a vector of pending-entity indices. On the binding vector
15525 have flags saying whether the pending-name-entity map has contents.
15526 (We might want to further extend the key to be GM-vs-Partition and
15527 specialization-vs-member, but let's not get ahead of ourselves.)
15529 For every key-like entity, find the outermost namespace-scope
15530 name. Use that to lookup in the pending-entity map and then make
15531 sure the specified entities are loaded.
15533 An optimization might be to have a flag in each key-entity saying
15534 that its top key might be in the entity table. It's not clear to
15535 me how to set that flag cheaply -- cheaper than just looking.
15537 FIXME: It'd be nice to have a bit in decls to tell us whether to
15538 even try this. We can have a 'already done' flag, that we set when
15539 we've done KLASS's lazy pendings. When we import a module that
15540 registers pendings on the same top-key as KLASS we need to clear
15541 the flag. A recursive walk of the top-key clearing the bit will
15542 suffice. Plus we only need to recurse on classes that have the bit
15543 set. (That means we need to set the bit on parents of KLASS here,
15544 don't forget.) However, first: correctness, second: efficiency. */
15547 module_state::write_pendings (elf_out
*to
, vec
<depset
*> depsets
,
15548 depset::hash
&table
, unsigned *crc_p
)
15550 dump () && dump ("Writing pending-entities");
15553 trees_out
sec (to
, this, table
);
15556 unsigned count
= 0;
15557 tree cache_ns
= NULL_TREE
;
15558 tree cache_id
= NULL_TREE
;
15559 unsigned cache_section
= ~0;
15560 for (unsigned ix
= 0; ix
< depsets
.length (); ix
++)
15562 depset
*d
= depsets
[ix
];
15564 if (d
->is_binding ())
15567 if (d
->is_import ())
15570 if (!(d
->get_entity_kind () == depset::EK_SPECIALIZATION
15571 || d
->get_entity_kind () == depset::EK_PARTIAL
15572 || (d
->get_entity_kind () == depset::EK_DECL
&& d
->is_member ())))
15575 tree key_decl
= nullptr;
15576 tree key_ns
= find_pending_key (d
->get_entity (), &key_decl
);
15577 tree key_name
= DECL_NAME (key_decl
);
15579 if (IDENTIFIER_ANON_P (key_name
))
15581 gcc_checking_assert (IDENTIFIER_LAMBDA_P (key_name
));
15582 if (tree attached
= LAMBDA_TYPE_EXTRA_SCOPE (TREE_TYPE (key_decl
)))
15583 key_name
= DECL_NAME (attached
);
15586 /* There's nothing to attach it to. Must
15587 always reinstantiate. */
15589 && dump ("Unattached lambda %N[%u] section:%u",
15590 d
->get_entity_kind () == depset::EK_DECL
15591 ? "Member" : "Specialization", d
->get_entity (),
15592 d
->cluster
, d
->section
);
15597 char const *also
= "";
15598 if (d
->section
== cache_section
15599 && key_ns
== cache_ns
15600 && key_name
== cache_id
)
15601 /* Same section & key as previous, no need to repeat ourselves. */
15606 cache_id
= key_name
;
15607 cache_section
= d
->section
;
15608 gcc_checking_assert (table
.find_dependency (cache_ns
));
15609 sec
.tree_node (cache_ns
);
15610 sec
.tree_node (cache_id
);
15611 sec
.u (d
->cluster
);
15614 dump () && dump ("Pending %s %N entity:%u section:%u %skeyed to %P",
15615 d
->get_entity_kind () == depset::EK_DECL
15616 ? "member" : "specialization", d
->get_entity (),
15617 d
->cluster
, cache_section
, also
, cache_ns
, cache_id
);
15619 sec
.end (to
, to
->name (MOD_SNAME_PFX
".pnd"), crc_p
);
15626 module_state::read_pendings (unsigned count
)
15628 trees_in
sec (this);
15630 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".pnd"))
15633 dump () && dump ("Reading %u pendings", count
);
15636 for (unsigned ix
= 0; ix
!= count
; ix
++)
15641 key
.ns
= sec
.tree_node ();
15642 key
.id
= sec
.tree_node ();
15645 if (!key
.ns
|| !key
.id
15646 || !(TREE_CODE (key
.ns
) == NAMESPACE_DECL
15647 && !DECL_NAMESPACE_ALIAS (key
.ns
))
15648 || !identifier_p (key
.id
)
15649 || index
>= entity_num
)
15650 sec
.set_overrun ();
15652 if (sec
.get_overrun ())
15655 dump () && dump ("Pending:%u keyed to %P", index
, key
.ns
, key
.id
);
15657 index
+= entity_lwm
;
15658 auto &vec
= pending_table
->get_or_insert (key
);
15659 vec
.safe_push (index
);
15663 if (!sec
.end (from ()))
15668 /* Read & write locations. */
15672 LK_IMPORT_ORDINARY
,
15678 static const module_state
*
15679 module_for_ordinary_loc (location_t loc
)
15682 unsigned len
= ool
->length () - pos
;
15686 unsigned half
= len
/ 2;
15687 module_state
*probe
= (*ool
)[pos
+ half
];
15688 if (loc
< probe
->ordinary_locs
.first
)
15690 else if (loc
< probe
->ordinary_locs
.first
+ probe
->ordinary_locs
.second
)
15695 len
= len
- (half
+ 1);
15702 static const module_state
*
15703 module_for_macro_loc (location_t loc
)
15706 unsigned len
= modules
->length () - pos
;
15710 unsigned half
= len
/ 2;
15711 module_state
*probe
= (*modules
)[pos
+ half
];
15712 if (loc
< probe
->macro_locs
.first
)
15715 len
= len
- (half
+ 1);
15717 else if (loc
>= probe
->macro_locs
.first
+ probe
->macro_locs
.second
)
15727 module_state::imported_from () const
15729 location_t from
= loc
;
15730 line_map_ordinary
const *fmap
15731 = linemap_check_ordinary (linemap_lookup (line_table
, from
));
15733 if (MAP_MODULE_P (fmap
))
15734 from
= linemap_included_from (fmap
);
15739 /* Note that LOC will need writing. This allows us to prune locations
15740 that are not needed. */
15743 module_state::note_location (location_t loc
)
15745 bool added
= false;
15746 if (!macro_loc_table
&& !ord_loc_table
)
15748 else if (loc
< RESERVED_LOCATION_COUNT
)
15750 else if (IS_ADHOC_LOC (loc
))
15752 location_t locus
= get_location_from_adhoc_loc (line_table
, loc
);
15753 note_location (locus
);
15754 source_range range
= get_range_from_loc (line_table
, loc
);
15755 if (range
.m_start
!= locus
)
15756 note_location (range
.m_start
);
15757 note_location (range
.m_finish
);
15759 else if (loc
>= LINEMAPS_MACRO_LOWEST_LOCATION (line_table
))
15761 if (spans
.macro (loc
))
15763 const line_map
*map
= linemap_lookup (line_table
, loc
);
15764 const line_map_macro
*mac_map
= linemap_check_macro (map
);
15765 hashval_t hv
= macro_loc_traits::hash (mac_map
);
15766 macro_loc_info
*slot
15767 = macro_loc_table
->find_slot_with_hash (mac_map
, hv
, INSERT
);
15770 slot
->src
= mac_map
;
15772 // Expansion locations could themselves be from a
15773 // macro, we need to note them all.
15774 note_location (mac_map
->expansion
);
15775 gcc_checking_assert (mac_map
->n_tokens
);
15776 location_t tloc
= UNKNOWN_LOCATION
;
15777 for (unsigned ix
= mac_map
->n_tokens
* 2; ix
--;)
15778 if (mac_map
->macro_locations
[ix
] != tloc
)
15780 tloc
= mac_map
->macro_locations
[ix
];
15781 note_location (tloc
);
15787 else if (IS_ORDINARY_LOC (loc
))
15789 if (spans
.ordinary (loc
))
15791 const line_map
*map
= linemap_lookup (line_table
, loc
);
15792 const line_map_ordinary
*ord_map
= linemap_check_ordinary (map
);
15794 lkup
.src
= ord_map
;
15795 lkup
.span
= 1 << ord_map
->m_column_and_range_bits
;
15796 lkup
.offset
= (loc
- MAP_START_LOCATION (ord_map
)) & ~(lkup
.span
- 1);
15798 ord_loc_info
*slot
= (ord_loc_table
->find_slot_with_hash
15799 (lkup
, ord_loc_traits::hash (lkup
), INSERT
));
15808 gcc_unreachable ();
15812 /* If we're not streaming, record that we need location LOC.
15813 Otherwise stream it. */
15816 module_state::write_location (bytes_out
&sec
, location_t loc
)
15818 if (!sec
.streaming_p ())
15820 note_location (loc
);
15824 if (loc
< RESERVED_LOCATION_COUNT
)
15826 dump (dumper::LOCATION
) && dump ("Reserved location %u", unsigned (loc
));
15827 sec
.u (LK_RESERVED
+ loc
);
15829 else if (IS_ADHOC_LOC (loc
))
15831 dump (dumper::LOCATION
) && dump ("Adhoc location");
15833 location_t locus
= get_location_from_adhoc_loc (line_table
, loc
);
15834 write_location (sec
, locus
);
15835 source_range range
= get_range_from_loc (line_table
, loc
);
15836 if (range
.m_start
== locus
)
15838 range
.m_start
= UNKNOWN_LOCATION
;
15839 write_location (sec
, range
.m_start
);
15840 write_location (sec
, range
.m_finish
);
15841 unsigned discriminator
= get_discriminator_from_adhoc_loc (line_table
, loc
);
15842 sec
.u (discriminator
);
15844 else if (loc
>= LINEMAPS_MACRO_LOWEST_LOCATION (line_table
))
15846 const macro_loc_info
*info
= nullptr;
15847 unsigned offset
= 0;
15848 if (unsigned hwm
= macro_loc_remap
->length ())
15850 info
= macro_loc_remap
->begin ();
15853 unsigned mid
= hwm
/ 2;
15854 if (MAP_START_LOCATION (info
[mid
].src
) <= loc
)
15862 offset
= loc
- MAP_START_LOCATION (info
->src
);
15863 if (offset
> info
->src
->n_tokens
)
15867 gcc_checking_assert (bool (info
) == bool (spans
.macro (loc
)));
15871 offset
+= info
->remap
;
15874 dump (dumper::LOCATION
)
15875 && dump ("Macro location %u output %u", loc
, offset
);
15877 else if (const module_state
*import
= module_for_macro_loc (loc
))
15879 unsigned off
= loc
- import
->macro_locs
.first
;
15880 sec
.u (LK_IMPORT_MACRO
);
15881 sec
.u (import
->remap
);
15883 dump (dumper::LOCATION
)
15884 && dump ("Imported macro location %u output %u:%u",
15885 loc
, import
->remap
, off
);
15888 gcc_unreachable ();
15890 else if (IS_ORDINARY_LOC (loc
))
15892 const ord_loc_info
*info
= nullptr;
15893 unsigned offset
= 0;
15894 if (unsigned hwm
= ord_loc_remap
->length ())
15896 info
= ord_loc_remap
->begin ();
15899 unsigned mid
= hwm
/ 2;
15900 if (MAP_START_LOCATION (info
[mid
].src
) + info
[mid
].offset
<= loc
)
15908 offset
= loc
- MAP_START_LOCATION (info
->src
) - info
->offset
;
15909 if (offset
> info
->span
)
15913 gcc_checking_assert (bool (info
) == bool (spans
.ordinary (loc
)));
15917 offset
+= info
->remap
;
15918 sec
.u (LK_ORDINARY
);
15921 dump (dumper::LOCATION
)
15922 && dump ("Ordinary location %u output %u", loc
, offset
);
15924 else if (const module_state
*import
= module_for_ordinary_loc (loc
))
15926 unsigned off
= loc
- import
->ordinary_locs
.first
;
15927 sec
.u (LK_IMPORT_ORDINARY
);
15928 sec
.u (import
->remap
);
15930 dump (dumper::LOCATION
)
15931 && dump ("Imported ordinary location %u output %u:%u",
15932 import
->remap
, import
->remap
, off
);
15935 gcc_unreachable ();
15938 gcc_unreachable ();
15942 module_state::read_location (bytes_in
&sec
) const
15944 location_t locus
= UNKNOWN_LOCATION
;
15945 unsigned kind
= sec
.u ();
15950 if (kind
< LK_RESERVED
+ RESERVED_LOCATION_COUNT
)
15951 locus
= location_t (kind
- LK_RESERVED
);
15953 sec
.set_overrun ();
15954 dump (dumper::LOCATION
)
15955 && dump ("Reserved location %u", unsigned (locus
));
15961 dump (dumper::LOCATION
) && dump ("Adhoc location");
15962 locus
= read_location (sec
);
15963 source_range range
;
15964 range
.m_start
= read_location (sec
);
15965 if (range
.m_start
== UNKNOWN_LOCATION
)
15966 range
.m_start
= locus
;
15967 range
.m_finish
= read_location (sec
);
15968 unsigned discriminator
= sec
.u ();
15969 if (locus
!= loc
&& range
.m_start
!= loc
&& range
.m_finish
!= loc
)
15970 locus
= get_combined_adhoc_loc (line_table
, locus
, range
, NULL
, discriminator
);
15976 unsigned off
= sec
.u ();
15978 if (macro_locs
.second
)
15980 if (off
< macro_locs
.second
)
15981 locus
= off
+ macro_locs
.first
;
15983 sec
.set_overrun ();
15987 dump (dumper::LOCATION
)
15988 && dump ("Macro %u becoming %u", off
, locus
);
15994 unsigned off
= sec
.u ();
15995 if (ordinary_locs
.second
)
15997 if (off
< ordinary_locs
.second
)
15998 locus
= off
+ ordinary_locs
.first
;
16000 sec
.set_overrun ();
16005 dump (dumper::LOCATION
)
16006 && dump ("Ordinary location %u becoming %u", off
, locus
);
16010 case LK_IMPORT_MACRO
:
16011 case LK_IMPORT_ORDINARY
:
16013 unsigned mod
= sec
.u ();
16014 unsigned off
= sec
.u ();
16015 const module_state
*import
= NULL
;
16017 if (!mod
&& !slurp
->remap
)
16018 /* This is an early read of a partition location during the
16019 read of our ordinary location map. */
16023 mod
= slurp
->remap_module (mod
);
16025 sec
.set_overrun ();
16027 import
= (*modules
)[mod
];
16032 if (kind
== LK_IMPORT_MACRO
)
16034 if (!import
->macro_locs
.second
)
16035 locus
= import
->loc
;
16036 else if (off
< import
->macro_locs
.second
)
16037 locus
= off
+ import
->macro_locs
.first
;
16039 sec
.set_overrun ();
16043 if (!import
->ordinary_locs
.second
)
16044 locus
= import
->loc
;
16045 else if (off
< import
->ordinary_locs
.second
)
16046 locus
= import
->ordinary_locs
.first
+ off
;
16048 sec
.set_overrun ();
16058 /* Allocate hash tables to record needed locations. */
16061 module_state::write_init_maps ()
16063 macro_loc_table
= new hash_table
<macro_loc_traits
> (EXPERIMENT (1, 400));
16064 ord_loc_table
= new hash_table
<ord_loc_traits
> (EXPERIMENT (1, 400));
16067 /* Prepare the span adjustments. We prune unneeded locations -- at
16068 this point every needed location must have been seen by
16072 module_state::write_prepare_maps (module_state_config
*cfg
, bool has_partitions
)
16074 dump () && dump ("Preparing locations");
16077 dump () && dump ("Reserved locations [%u,%u) macro [%u,%u)",
16078 spans
[loc_spans::SPAN_RESERVED
].ordinary
.first
,
16079 spans
[loc_spans::SPAN_RESERVED
].ordinary
.second
,
16080 spans
[loc_spans::SPAN_RESERVED
].macro
.first
,
16081 spans
[loc_spans::SPAN_RESERVED
].macro
.second
);
16083 range_t info
{0, 0};
16085 // Sort the noted lines.
16086 vec_alloc (ord_loc_remap
, ord_loc_table
->size ());
16087 for (auto iter
= ord_loc_table
->begin (), end
= ord_loc_table
->end ();
16088 iter
!= end
; ++iter
)
16089 ord_loc_remap
->quick_push (*iter
);
16090 ord_loc_remap
->qsort (&ord_loc_info::compare
);
16092 // Note included-from maps.
16093 bool added
= false;
16094 const line_map_ordinary
*current
= nullptr;
16095 for (auto iter
= ord_loc_remap
->begin (), end
= ord_loc_remap
->end ();
16096 iter
!= end
; ++iter
)
16097 if (iter
->src
!= current
)
16099 current
= iter
->src
;
16100 for (auto probe
= current
;
16101 auto from
= linemap_included_from (probe
);
16102 probe
= linemap_check_ordinary (linemap_lookup (line_table
, from
)))
16104 if (has_partitions
)
16106 // Partition locations need to elide their module map
16109 = linemap_check_ordinary (linemap_lookup (line_table
, from
));
16110 if (MAP_MODULE_P (probe
))
16111 from
= linemap_included_from (probe
);
16114 if (!note_location (from
))
16121 // Reconstruct the line array as we added items to the hash table.
16122 vec_free (ord_loc_remap
);
16123 vec_alloc (ord_loc_remap
, ord_loc_table
->size ());
16124 for (auto iter
= ord_loc_table
->begin (), end
= ord_loc_table
->end ();
16125 iter
!= end
; ++iter
)
16126 ord_loc_remap
->quick_push (*iter
);
16127 ord_loc_remap
->qsort (&ord_loc_info::compare
);
16129 delete ord_loc_table
;
16130 ord_loc_table
= nullptr;
16132 // Merge (sufficiently) adjacent spans, and calculate remapping.
16133 constexpr unsigned adjacency
= 2; // Allow 2 missing lines.
16134 auto begin
= ord_loc_remap
->begin (), end
= ord_loc_remap
->end ();
16136 unsigned offset
= 0, range_bits
= 0;
16137 ord_loc_info
*base
= nullptr;
16138 for (auto iter
= begin
; iter
!= end
; ++iter
)
16140 if (base
&& iter
->src
== base
->src
)
16142 if (base
->offset
+ base
->span
+
16143 ((adjacency
<< base
->src
->m_column_and_range_bits
)
16144 // If there are few c&r bits, allow further separation.
16145 | (adjacency
<< 4))
16149 offset
-= base
->span
;
16150 base
->span
= iter
->offset
+ iter
->span
- base
->offset
;
16151 offset
+= base
->span
;
16155 else if (range_bits
< iter
->src
->m_range_bits
)
16156 range_bits
= iter
->src
->m_range_bits
;
16158 offset
+= ((1u << iter
->src
->m_range_bits
) - 1);
16159 offset
&= ~((1u << iter
->src
->m_range_bits
) - 1);
16160 iter
->remap
= offset
;
16161 offset
+= iter
->span
;
16165 ord_loc_remap
->truncate (dst
- begin
);
16167 info
.first
= ord_loc_remap
->length ();
16168 cfg
->ordinary_locs
= offset
;
16169 cfg
->loc_range_bits
= range_bits
;
16170 dump () && dump ("Ordinary maps:%u locs:%u range_bits:%u",
16171 info
.first
, cfg
->ordinary_locs
,
16172 cfg
->loc_range_bits
);
16174 // Remap the macro locations.
16175 vec_alloc (macro_loc_remap
, macro_loc_table
->size ());
16176 for (auto iter
= macro_loc_table
->begin (), end
= macro_loc_table
->end ();
16177 iter
!= end
; ++iter
)
16178 macro_loc_remap
->quick_push (*iter
);
16179 delete macro_loc_table
;
16180 macro_loc_table
= nullptr;
16182 macro_loc_remap
->qsort (¯o_loc_info::compare
);
16184 for (auto iter
= macro_loc_remap
->begin (), end
= macro_loc_remap
->end ();
16185 iter
!= end
; ++iter
)
16187 auto mac
= iter
->src
;
16188 iter
->remap
= offset
;
16189 offset
+= mac
->n_tokens
;
16191 info
.second
= macro_loc_remap
->length ();
16192 cfg
->macro_locs
= offset
;
16194 dump () && dump ("Macro maps:%u locs:%u", info
.second
, cfg
->macro_locs
);
16198 // If we have no ordinary locs, we must also have no macro locs.
16199 gcc_checking_assert (cfg
->ordinary_locs
|| !cfg
->macro_locs
);
16205 module_state::read_prepare_maps (const module_state_config
*cfg
)
16207 location_t ordinary
= line_table
->highest_location
+ 1;
16208 ordinary
+= cfg
->ordinary_locs
;
16210 location_t macro
= LINEMAPS_MACRO_LOWEST_LOCATION (line_table
);
16211 macro
-= cfg
->macro_locs
;
16213 if (ordinary
< LINE_MAP_MAX_LOCATION_WITH_COLS
16214 && macro
>= LINE_MAP_MAX_LOCATION
)
16215 /* OK, we have enough locations. */
16218 ordinary_locs
.first
= ordinary_locs
.second
= 0;
16219 macro_locs
.first
= macro_locs
.second
= 0;
16221 static bool informed
= false;
16224 /* Just give the notice once. */
16226 inform (loc
, "unable to represent further imported source locations");
16232 /* Write & read the location maps. Not called if there are no
16236 module_state::write_ordinary_maps (elf_out
*to
, range_t
&info
,
16237 bool has_partitions
, unsigned *crc_p
)
16239 dump () && dump ("Writing ordinary location maps");
16242 vec
<const char *> filenames
;
16243 filenames
.create (20);
16245 /* Determine the unique filenames. */
16246 const line_map_ordinary
*current
= nullptr;
16247 for (auto iter
= ord_loc_remap
->begin (), end
= ord_loc_remap
->end ();
16248 iter
!= end
; ++iter
)
16249 if (iter
->src
!= current
)
16251 current
= iter
->src
;
16252 const char *fname
= ORDINARY_MAP_FILE_NAME (iter
->src
);
16254 /* We should never find a module linemap in an interval. */
16255 gcc_checking_assert (!MAP_MODULE_P (iter
->src
));
16257 /* We expect very few filenames, so just an array.
16258 (Not true when headers are still in play :() */
16259 for (unsigned jx
= filenames
.length (); jx
--;)
16261 const char *name
= filenames
[jx
];
16262 if (0 == strcmp (name
, fname
))
16264 /* Reset the linemap's name, because for things like
16265 preprocessed input we could have multiple instances
16266 of the same name, and we'd rather not percolate
16268 const_cast<line_map_ordinary
*> (iter
->src
)->to_file
= name
;
16274 filenames
.safe_push (fname
);
16277 bytes_out
sec (to
);
16280 /* Write the filenames. */
16281 unsigned len
= filenames
.length ();
16283 dump () && dump ("%u source file names", len
);
16284 for (unsigned ix
= 0; ix
!= len
; ix
++)
16286 const char *fname
= filenames
[ix
];
16287 dump (dumper::LOCATION
) && dump ("Source file[%u]=%s", ix
, fname
);
16291 sec
.u (info
.first
); /* Num maps. */
16292 const ord_loc_info
*base
= nullptr;
16293 for (auto iter
= ord_loc_remap
->begin (), end
= ord_loc_remap
->end ();
16294 iter
!= end
; ++iter
)
16296 dump (dumper::LOCATION
)
16297 && dump ("Span:%u ordinary [%u+%u,+%u)->[%u,+%u)",
16298 iter
- ord_loc_remap
->begin (),
16299 MAP_START_LOCATION (iter
->src
), iter
->offset
, iter
->span
,
16300 iter
->remap
, iter
->span
);
16302 if (!base
|| iter
->src
!= base
->src
)
16304 sec
.u (iter
->offset
- base
->offset
);
16307 sec
.u (iter
->src
->sysp
);
16308 sec
.u (iter
->src
->m_range_bits
);
16309 sec
.u (iter
->src
->m_column_and_range_bits
- iter
->src
->m_range_bits
);
16311 const char *fname
= ORDINARY_MAP_FILE_NAME (iter
->src
);
16312 for (unsigned ix
= 0; ix
!= filenames
.length (); ix
++)
16313 if (filenames
[ix
] == fname
)
16318 unsigned line
= ORDINARY_MAP_STARTING_LINE_NUMBER (iter
->src
);
16319 line
+= iter
->offset
>> iter
->src
->m_column_and_range_bits
;
16322 sec
.u (iter
->remap
);
16325 /* Write the included from location, which means reading it
16326 while reading in the ordinary maps. So we'd better not
16327 be getting ahead of ourselves. */
16328 location_t from
= linemap_included_from (iter
->src
);
16329 gcc_checking_assert (from
< MAP_START_LOCATION (iter
->src
));
16330 if (from
!= UNKNOWN_LOCATION
&& has_partitions
)
16332 /* A partition's span will have a from pointing at a
16333 MODULE_INC. Find that map's from. */
16334 line_map_ordinary
const *fmap
16335 = linemap_check_ordinary (linemap_lookup (line_table
, from
));
16336 if (MAP_MODULE_P (fmap
))
16337 from
= linemap_included_from (fmap
);
16339 write_location (sec
, from
);
16343 filenames
.release ();
16345 sec
.end (to
, to
->name (MOD_SNAME_PFX
".olm"), crc_p
);
16350 module_state::write_macro_maps (elf_out
*to
, range_t
&info
, unsigned *crc_p
)
16352 dump () && dump ("Writing macro location maps");
16355 bytes_out
sec (to
);
16358 dump () && dump ("Macro maps:%u", info
.second
);
16359 sec
.u (info
.second
);
16361 unsigned macro_num
= 0;
16362 for (auto iter
= macro_loc_remap
->end (), begin
= macro_loc_remap
->begin ();
16365 auto mac
= iter
->src
;
16366 sec
.u (iter
->remap
);
16367 sec
.u (mac
->n_tokens
);
16368 sec
.cpp_node (mac
->macro
);
16369 write_location (sec
, mac
->expansion
);
16370 const location_t
*locs
= mac
->macro_locations
;
16371 /* There are lots of identical runs. */
16372 location_t prev
= UNKNOWN_LOCATION
;
16373 unsigned count
= 0;
16375 for (unsigned jx
= mac
->n_tokens
* 2; jx
--;)
16377 location_t tok_loc
= locs
[jx
];
16378 if (tok_loc
== prev
)
16387 write_location (sec
, tok_loc
);
16390 dump (dumper::LOCATION
)
16391 && dump ("Macro:%u %I %u/%u*2 locations [%u,%u)->%u",
16392 macro_num
, identifier (mac
->macro
),
16393 runs
, mac
->n_tokens
,
16394 MAP_START_LOCATION (mac
),
16395 MAP_START_LOCATION (mac
) + mac
->n_tokens
,
16399 gcc_assert (macro_num
== info
.second
);
16401 sec
.end (to
, to
->name (MOD_SNAME_PFX
".mlm"), crc_p
);
16406 module_state::read_ordinary_maps (unsigned num_ord_locs
, unsigned range_bits
)
16410 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".olm"))
16412 dump () && dump ("Reading ordinary location maps");
16415 /* Read the filename table. */
16416 unsigned len
= sec
.u ();
16417 dump () && dump ("%u source file names", len
);
16418 vec
<const char *> filenames
;
16419 filenames
.create (len
);
16420 for (unsigned ix
= 0; ix
!= len
; ix
++)
16423 const char *buf
= sec
.str (&l
);
16424 char *fname
= XNEWVEC (char, l
+ 1);
16425 memcpy (fname
, buf
, l
+ 1);
16426 dump (dumper::LOCATION
) && dump ("Source file[%u]=%s", ix
, fname
);
16427 /* We leak these names into the line-map table. But it
16428 doesn't own them. */
16429 filenames
.quick_push (fname
);
16432 unsigned num_ordinary
= sec
.u ();
16433 dump () && dump ("Ordinary maps:%u, range_bits:%u", num_ordinary
, range_bits
);
16435 location_t offset
= line_table
->highest_location
+ 1;
16436 offset
+= ((1u << range_bits
) - 1);
16437 offset
&= ~((1u << range_bits
) - 1);
16438 ordinary_locs
.first
= offset
;
16440 bool propagated
= spans
.maybe_propagate (this, offset
);
16441 line_map_ordinary
*maps
= static_cast<line_map_ordinary
*>
16442 (line_map_new_raw (line_table
, false, num_ordinary
));
16444 const line_map_ordinary
*base
= nullptr;
16445 for (unsigned ix
= 0; ix
!= num_ordinary
&& !sec
.get_overrun (); ix
++)
16447 line_map_ordinary
*map
= &maps
[ix
];
16449 unsigned offset
= sec
.u ();
16452 map
->reason
= LC_RENAME
;
16453 map
->sysp
= sec
.u ();
16454 map
->m_range_bits
= sec
.u ();
16455 map
->m_column_and_range_bits
= sec
.u () + map
->m_range_bits
;
16456 unsigned fnum
= sec
.u ();
16457 map
->to_file
= (fnum
< filenames
.length () ? filenames
[fnum
] : "");
16458 map
->to_line
= sec
.u ();
16464 map
->to_line
+= offset
>> map
->m_column_and_range_bits
;
16466 unsigned remap
= sec
.u ();
16467 map
->start_location
= remap
+ ordinary_locs
.first
;
16470 /* Root the outermost map at our location. */
16471 ordinary_locs
.second
= remap
;
16472 location_t from
= read_location (sec
);
16473 map
->included_from
= from
!= UNKNOWN_LOCATION
? from
: loc
;
16477 ordinary_locs
.second
= num_ord_locs
;
16478 /* highest_location is the one handed out, not the next one to
16480 line_table
->highest_location
= ordinary_locs
.first
+ ordinary_locs
.second
- 1;
16482 if (line_table
->highest_location
>= LINE_MAP_MAX_LOCATION_WITH_COLS
)
16483 /* We shouldn't run out of locations, as we checked before
16485 sec
.set_overrun ();
16486 dump () && dump ("Ordinary location [%u,+%u)",
16487 ordinary_locs
.first
, ordinary_locs
.second
);
16492 filenames
.release ();
16495 if (!sec
.end (from ()))
16502 module_state::read_macro_maps (unsigned num_macro_locs
)
16506 if (!sec
.begin (loc
, from (), MOD_SNAME_PFX
".mlm"))
16508 dump () && dump ("Reading macro location maps");
16511 unsigned num_macros
= sec
.u ();
16512 dump () && dump ("Macro maps:%u locs:%u", num_macros
, num_macro_locs
);
16514 bool propagated
= spans
.maybe_propagate (this,
16515 line_table
->highest_location
+ 1);
16517 location_t offset
= LINEMAPS_MACRO_LOWEST_LOCATION (line_table
);
16518 macro_locs
.second
= num_macro_locs
;
16519 macro_locs
.first
= offset
- num_macro_locs
;
16521 dump () && dump ("Macro loc delta %d", offset
);
16522 dump () && dump ("Macro locations [%u,%u)",
16523 macro_locs
.first
, macro_locs
.second
);
16525 for (unsigned ix
= 0; ix
!= num_macros
&& !sec
.get_overrun (); ix
++)
16527 unsigned offset
= sec
.u ();
16528 unsigned n_tokens
= sec
.u ();
16529 cpp_hashnode
*node
= sec
.cpp_node ();
16530 location_t exp_loc
= read_location (sec
);
16532 const line_map_macro
*macro
16533 = linemap_enter_macro (line_table
, node
, exp_loc
, n_tokens
);
16535 /* We shouldn't run out of locations, as we checked that we
16536 had enough before starting. */
16538 gcc_checking_assert (MAP_START_LOCATION (macro
)
16539 == offset
+ macro_locs
.first
);
16541 location_t
*locs
= macro
->macro_locations
;
16542 location_t tok_loc
= UNKNOWN_LOCATION
;
16543 unsigned count
= sec
.u ();
16545 for (unsigned jx
= macro
->n_tokens
* 2; jx
-- && !sec
.get_overrun ();)
16547 while (!count
-- && !sec
.get_overrun ())
16550 tok_loc
= read_location (sec
);
16553 locs
[jx
] = tok_loc
;
16556 sec
.set_overrun ();
16557 dump (dumper::LOCATION
)
16558 && dump ("Macro:%u %I %u/%u*2 locations [%u,%u)",
16559 ix
, identifier (node
), runs
, n_tokens
,
16560 MAP_START_LOCATION (macro
),
16561 MAP_START_LOCATION (macro
) + n_tokens
);
16564 dump () && dump ("Macro location lwm:%u", macro_locs
.first
);
16569 if (!sec
.end (from ()))
16575 /* Serialize the definition of MACRO. */
16578 module_state::write_define (bytes_out
&sec
, const cpp_macro
*macro
)
16580 sec
.u (macro
->count
);
16582 sec
.b (macro
->fun_like
);
16583 sec
.b (macro
->variadic
);
16584 sec
.b (macro
->syshdr
);
16587 write_location (sec
, macro
->line
);
16588 if (macro
->fun_like
)
16590 sec
.u (macro
->paramc
);
16591 const cpp_hashnode
*const *parms
= macro
->parm
.params
;
16592 for (unsigned ix
= 0; ix
!= macro
->paramc
; ix
++)
16593 sec
.cpp_node (parms
[ix
]);
16597 for (unsigned ix
= 0; ix
!= macro
->count
; ix
++)
16599 const cpp_token
*token
= ¯o
->exp
.tokens
[ix
];
16600 write_location (sec
, token
->src_loc
);
16601 sec
.u (token
->type
);
16602 sec
.u (token
->flags
);
16603 switch (cpp_token_val_index (token
))
16606 gcc_unreachable ();
16608 case CPP_TOKEN_FLD_ARG_NO
:
16609 /* An argument reference. */
16610 sec
.u (token
->val
.macro_arg
.arg_no
);
16611 sec
.cpp_node (token
->val
.macro_arg
.spelling
);
16614 case CPP_TOKEN_FLD_NODE
:
16615 /* An identifier. */
16616 sec
.cpp_node (token
->val
.node
.node
);
16617 if (token
->val
.node
.spelling
== token
->val
.node
.node
)
16618 /* The spelling will usually be the same. so optimize
16622 sec
.cpp_node (token
->val
.node
.spelling
);
16625 case CPP_TOKEN_FLD_NONE
:
16628 case CPP_TOKEN_FLD_STR
:
16629 /* A string, number or comment. Not always NUL terminated,
16630 we stream out in a single contatenation with embedded
16631 NULs as that's a safe default. */
16632 len
+= token
->val
.str
.len
+ 1;
16633 sec
.u (token
->val
.str
.len
);
16636 case CPP_TOKEN_FLD_SOURCE
:
16637 case CPP_TOKEN_FLD_TOKEN_NO
:
16638 case CPP_TOKEN_FLD_PRAGMA
:
16639 /* These do not occur inside a macro itself. */
16640 gcc_unreachable ();
16646 char *ptr
= reinterpret_cast<char *> (sec
.buf (len
));
16648 for (unsigned ix
= 0; ix
!= macro
->count
; ix
++)
16650 const cpp_token
*token
= ¯o
->exp
.tokens
[ix
];
16651 if (cpp_token_val_index (token
) == CPP_TOKEN_FLD_STR
)
16653 memcpy (ptr
+ len
, token
->val
.str
.text
,
16654 token
->val
.str
.len
);
16655 len
+= token
->val
.str
.len
;
16662 /* Read a macro definition. */
16665 module_state::read_define (bytes_in
&sec
, cpp_reader
*reader
) const
16667 unsigned count
= sec
.u ();
16668 /* We rely on knowing cpp_reader's hash table is ident_hash, and
16669 its subobject allocator is stringpool_ggc_alloc and that is just
16670 a wrapper for ggc_alloc_atomic. */
16672 = (cpp_macro
*)ggc_alloc_atomic (sizeof (cpp_macro
)
16673 + sizeof (cpp_token
) * (count
- !!count
));
16674 memset (macro
, 0, sizeof (cpp_macro
) + sizeof (cpp_token
) * (count
- !!count
));
16676 macro
->count
= count
;
16677 macro
->kind
= cmk_macro
;
16678 macro
->imported_p
= true;
16680 macro
->fun_like
= sec
.b ();
16681 macro
->variadic
= sec
.b ();
16682 macro
->syshdr
= sec
.b ();
16685 macro
->line
= read_location (sec
);
16687 if (macro
->fun_like
)
16689 unsigned paramc
= sec
.u ();
16690 cpp_hashnode
**params
16691 = (cpp_hashnode
**)ggc_alloc_atomic (sizeof (cpp_hashnode
*) * paramc
);
16692 macro
->paramc
= paramc
;
16693 macro
->parm
.params
= params
;
16694 for (unsigned ix
= 0; ix
!= paramc
; ix
++)
16695 params
[ix
] = sec
.cpp_node ();
16699 for (unsigned ix
= 0; ix
!= count
&& !sec
.get_overrun (); ix
++)
16701 cpp_token
*token
= ¯o
->exp
.tokens
[ix
];
16702 token
->src_loc
= read_location (sec
);
16703 token
->type
= cpp_ttype (sec
.u ());
16704 token
->flags
= sec
.u ();
16705 switch (cpp_token_val_index (token
))
16708 sec
.set_overrun ();
16711 case CPP_TOKEN_FLD_ARG_NO
:
16712 /* An argument reference. */
16714 unsigned arg_no
= sec
.u ();
16715 if (arg_no
- 1 >= macro
->paramc
)
16716 sec
.set_overrun ();
16717 token
->val
.macro_arg
.arg_no
= arg_no
;
16718 token
->val
.macro_arg
.spelling
= sec
.cpp_node ();
16722 case CPP_TOKEN_FLD_NODE
:
16723 /* An identifier. */
16724 token
->val
.node
.node
= sec
.cpp_node ();
16725 token
->val
.node
.spelling
= sec
.cpp_node ();
16726 if (!token
->val
.node
.spelling
)
16727 token
->val
.node
.spelling
= token
->val
.node
.node
;
16730 case CPP_TOKEN_FLD_NONE
:
16733 case CPP_TOKEN_FLD_STR
:
16734 /* A string, number or comment. */
16735 token
->val
.str
.len
= sec
.u ();
16736 len
+= token
->val
.str
.len
+ 1;
16742 if (const char *ptr
= reinterpret_cast<const char *> (sec
.buf (len
)))
16744 /* There should be a final NUL. */
16746 sec
.set_overrun ();
16747 /* cpp_alloc_token_string will add a final NUL. */
16748 const unsigned char *buf
16749 = cpp_alloc_token_string (reader
, (const unsigned char *)ptr
, len
- 1);
16751 for (unsigned ix
= 0; ix
!= count
&& !sec
.get_overrun (); ix
++)
16753 cpp_token
*token
= ¯o
->exp
.tokens
[ix
];
16754 if (cpp_token_val_index (token
) == CPP_TOKEN_FLD_STR
)
16756 token
->val
.str
.text
= buf
+ len
;
16757 len
+= token
->val
.str
.len
;
16759 sec
.set_overrun ();
16764 if (sec
.get_overrun ())
16769 /* Exported macro data. */
16770 struct GTY(()) macro_export
{
16772 location_t undef_loc
;
16775 :def (NULL
), undef_loc (UNKNOWN_LOCATION
)
16780 /* Imported macro data. */
16781 class macro_import
{
16784 #if defined (WORDS_BIGENDIAN) && SIZEOF_VOID_P == 8
16787 /* We need to ensure we don't use the LSB for representation, as
16788 that's the union discriminator below. */
16791 #if !(defined (WORDS_BIGENDIAN) && SIZEOF_VOID_P == 8)
16804 /* Not a regular ctor, because we put it in a union, and that's
16805 not allowed in C++ 98. */
16806 static slot
ctor (unsigned module
, unsigned defness
)
16808 gcc_checking_assert (defness
);
16810 s
.bits
= defness
| (module
<< L_MODULE_SHIFT
);
16816 unsigned get_defness () const
16818 return bits
& L_BOTH
;
16820 unsigned get_module () const
16822 return bits
>> L_MODULE_SHIFT
;
16824 void become_undef ()
16826 bits
&= ~unsigned (L_DEF
);
16827 bits
|= unsigned (L_UNDEF
);
16832 typedef vec
<slot
, va_heap
, vl_embed
> ary_t
;
16834 /* Discriminated by bits 0|1 != 0. The expected case is that
16835 there will be exactly one slot per macro, hence the effort of
16848 bool single_p () const
16850 return u
.single
.bits
& slot::L_BOTH
;
16852 bool occupied_p () const
16854 return u
.ary
!= NULL
;
16858 unsigned length () const
16860 gcc_checking_assert (occupied_p ());
16861 return single_p () ? 1 : u
.ary
->length ();
16863 slot
&operator[] (unsigned ix
)
16865 gcc_checking_assert (occupied_p ());
16868 gcc_checking_assert (!ix
);
16872 return (*u
.ary
)[ix
];
16877 slot
&append (unsigned module
, unsigned defness
);
16880 /* O is a new import to append to the list for. If we're an empty
16881 set, initialize us. */
16883 macro_import::slot
&
16884 macro_import::append (unsigned module
, unsigned defness
)
16886 if (!occupied_p ())
16888 u
.single
= slot::ctor (module
, defness
);
16893 bool single
= single_p ();
16894 ary_t
*m
= single
? NULL
: u
.ary
;
16895 vec_safe_reserve (m
, 1 + single
);
16897 m
->quick_push (u
.single
);
16899 return *u
.ary
->quick_push (slot::ctor (module
, defness
));
16903 /* We're going to export something. Make sure the first import slot
16906 macro_import::slot
&
16907 macro_import::exported ()
16909 if (occupied_p () && !(*this)[0].get_module ())
16911 slot
&res
= (*this)[0];
16912 res
.bits
|= slot::L_DEF
;
16916 slot
*a
= &append (0, slot::L_DEF
);
16919 slot
&f
= (*this)[0];
16926 /* The import (&exported) macros. cpp_hasnode's deferred field
16927 indexes this array (offset by 1, so zero means 'not present'. */
16929 static vec
<macro_import
, va_heap
, vl_embed
> *macro_imports
;
16931 /* The exported macros. A macro_import slot's zeroth element's offset
16932 indexes this array. If the zeroth slot is not for module zero,
16933 there is no export. */
16935 static GTY(()) vec
<macro_export
, va_gc
> *macro_exports
;
16937 /* The reachable set of header imports from this TU. */
16939 static GTY(()) bitmap headers
;
16941 /* Get the (possibly empty) macro imports for NODE. */
16943 static macro_import
&
16944 get_macro_imports (cpp_hashnode
*node
)
16946 if (node
->deferred
)
16947 return (*macro_imports
)[node
->deferred
- 1];
16949 vec_safe_reserve (macro_imports
, 1);
16950 node
->deferred
= macro_imports
->length () + 1;
16951 return *vec_safe_push (macro_imports
, macro_import ());
16954 /* Get the macro export for export EXP of NODE. */
16956 static macro_export
&
16957 get_macro_export (macro_import::slot
&slot
)
16959 if (slot
.offset
>= 0)
16960 return (*macro_exports
)[slot
.offset
];
16962 vec_safe_reserve (macro_exports
, 1);
16963 slot
.offset
= macro_exports
->length ();
16964 return *macro_exports
->quick_push (macro_export ());
16967 /* If NODE is an exportable macro, add it to the export set. */
16970 maybe_add_macro (cpp_reader
*, cpp_hashnode
*node
, void *data_
)
16972 bool exporting
= false;
16974 if (cpp_user_macro_p (node
))
16975 if (cpp_macro
*macro
= node
->value
.macro
)
16976 /* Ignore imported, builtins, command line and forced header macros. */
16977 if (!macro
->imported_p
16978 && !macro
->lazy
&& macro
->line
>= spans
.main_start ())
16980 gcc_checking_assert (macro
->kind
== cmk_macro
);
16981 /* I don't want to deal with this corner case, that I suspect is
16982 a devil's advocate reading of the standard. */
16983 gcc_checking_assert (!macro
->extra_tokens
);
16985 macro_import::slot
&slot
= get_macro_imports (node
).exported ();
16986 macro_export
&exp
= get_macro_export (slot
);
16991 if (!exporting
&& node
->deferred
)
16993 macro_import
&imports
= (*macro_imports
)[node
->deferred
- 1];
16994 macro_import::slot
&slot
= imports
[0];
16995 if (!slot
.get_module ())
16997 gcc_checking_assert (slot
.get_defness ());
17003 static_cast<vec
<cpp_hashnode
*> *> (data_
)->safe_push (node
);
17005 return 1; /* Don't stop. */
17008 /* Order cpp_hashnodes A_ and B_ by their exported macro locations. */
17011 macro_loc_cmp (const void *a_
, const void *b_
)
17013 const cpp_hashnode
*node_a
= *(const cpp_hashnode
*const *)a_
;
17014 macro_import
&import_a
= (*macro_imports
)[node_a
->deferred
- 1];
17015 const macro_export
&export_a
= (*macro_exports
)[import_a
[0].offset
];
17016 location_t loc_a
= export_a
.def
? export_a
.def
->line
: export_a
.undef_loc
;
17018 const cpp_hashnode
*node_b
= *(const cpp_hashnode
*const *)b_
;
17019 macro_import
&import_b
= (*macro_imports
)[node_b
->deferred
- 1];
17020 const macro_export
&export_b
= (*macro_exports
)[import_b
[0].offset
];
17021 location_t loc_b
= export_b
.def
? export_b
.def
->line
: export_b
.undef_loc
;
17025 else if (loc_a
> loc_b
)
17031 /* Gather the macro definitions and undefinitions that we will need to
17034 vec
<cpp_hashnode
*> *
17035 module_state::prepare_macros (cpp_reader
*reader
)
17037 vec
<cpp_hashnode
*> *macros
;
17038 vec_alloc (macros
, 100);
17040 cpp_forall_identifiers (reader
, maybe_add_macro
, macros
);
17042 dump (dumper::MACRO
) && dump ("No more than %u macros", macros
->length ());
17044 macros
->qsort (macro_loc_cmp
);
17046 // Note the locations.
17047 for (unsigned ix
= macros
->length (); ix
--;)
17049 cpp_hashnode
*node
= (*macros
)[ix
];
17050 macro_import::slot
&slot
= (*macro_imports
)[node
->deferred
- 1][0];
17051 macro_export
&mac
= (*macro_exports
)[slot
.offset
];
17053 if (IDENTIFIER_KEYWORD_P (identifier (node
)))
17056 if (mac
.undef_loc
!= UNKNOWN_LOCATION
)
17057 note_location (mac
.undef_loc
);
17060 note_location (mac
.def
->line
);
17061 for (unsigned ix
= 0; ix
!= mac
.def
->count
; ix
++)
17062 note_location (mac
.def
->exp
.tokens
[ix
].src_loc
);
17069 /* Write out the exported defines. This is two sections, one
17070 containing the definitions, the other a table of node names. */
17073 module_state::write_macros (elf_out
*to
, vec
<cpp_hashnode
*> *macros
,
17076 dump () && dump ("Writing macros");
17079 /* Write the defs */
17080 bytes_out
sec (to
);
17083 unsigned count
= 0;
17084 for (unsigned ix
= macros
->length (); ix
--;)
17086 cpp_hashnode
*node
= (*macros
)[ix
];
17087 macro_import::slot
&slot
= (*macro_imports
)[node
->deferred
- 1][0];
17088 gcc_assert (!slot
.get_module () && slot
.get_defness ());
17090 macro_export
&mac
= (*macro_exports
)[slot
.offset
];
17091 gcc_assert (!!(slot
.get_defness () & macro_import::slot::L_UNDEF
)
17092 == (mac
.undef_loc
!= UNKNOWN_LOCATION
)
17093 && !!(slot
.get_defness () & macro_import::slot::L_DEF
)
17094 == (mac
.def
!= NULL
));
17096 if (IDENTIFIER_KEYWORD_P (identifier (node
)))
17098 warning_at (mac
.def
->line
, 0,
17099 "not exporting %<#define %E%> as it is a keyword",
17100 identifier (node
));
17106 slot
.offset
= sec
.pos
;
17107 dump (dumper::MACRO
)
17108 && dump ("Writing macro %s%s%s %I at %u",
17109 slot
.get_defness () & macro_import::slot::L_UNDEF
17111 slot
.get_defness () == macro_import::slot::L_BOTH
17113 slot
.get_defness () & macro_import::slot::L_DEF
17115 identifier (node
), slot
.offset
);
17116 if (mac
.undef_loc
!= UNKNOWN_LOCATION
)
17117 write_location (sec
, mac
.undef_loc
);
17119 write_define (sec
, mac
.def
);
17122 // We may have ended on a tokenless macro with a very short
17123 // location, that will cause problems reading its bit flags.
17125 sec
.end (to
, to
->name (MOD_SNAME_PFX
".def"), crc_p
);
17129 /* Write the table. */
17130 bytes_out
sec (to
);
17134 for (unsigned ix
= macros
->length (); ix
--;)
17136 const cpp_hashnode
*node
= (*macros
)[ix
];
17137 macro_import::slot
&slot
= (*macro_imports
)[node
->deferred
- 1][0];
17141 sec
.cpp_node (node
);
17142 sec
.u (slot
.get_defness ());
17143 sec
.u (slot
.offset
);
17146 sec
.end (to
, to
->name (MOD_SNAME_PFX
".mac"), crc_p
);
17154 module_state::read_macros ()
17156 /* Get the def section. */
17157 if (!slurp
->macro_defs
.begin (loc
, from (), MOD_SNAME_PFX
".def"))
17160 /* Get the tbl section, if there are defs. */
17161 if (slurp
->macro_defs
.more_p ()
17162 && !slurp
->macro_tbl
.begin (loc
, from (), MOD_SNAME_PFX
".mac"))
17168 /* Install the macro name table. */
17171 module_state::install_macros ()
17173 bytes_in
&sec
= slurp
->macro_tbl
;
17177 dump () && dump ("Reading macro table %M", this);
17180 unsigned count
= sec
.u ();
17181 dump () && dump ("%u macros", count
);
17184 cpp_hashnode
*node
= sec
.cpp_node ();
17185 macro_import
&imp
= get_macro_imports (node
);
17186 unsigned flags
= sec
.u () & macro_import::slot::L_BOTH
;
17188 sec
.set_overrun ();
17190 if (sec
.get_overrun ())
17193 macro_import::slot
&slot
= imp
.append (mod
, flags
);
17194 slot
.offset
= sec
.u ();
17196 dump (dumper::MACRO
)
17197 && dump ("Read %s macro %s%s%s %I at %u",
17198 imp
.length () > 1 ? "add" : "new",
17199 flags
& macro_import::slot::L_UNDEF
? "#undef" : "",
17200 flags
== macro_import::slot::L_BOTH
? " & " : "",
17201 flags
& macro_import::slot::L_DEF
? "#define" : "",
17202 identifier (node
), slot
.offset
);
17204 /* We'll leak an imported definition's TOKEN_FLD_STR's data
17205 here. But that only happens when we've had to resolve the
17206 deferred macro before this import -- why are you doing
17208 if (cpp_macro
*cur
= cpp_set_deferred_macro (node
))
17209 if (!cur
->imported_p
)
17211 macro_import::slot
&slot
= imp
.exported ();
17212 macro_export
&exp
= get_macro_export (slot
);
17214 dump (dumper::MACRO
)
17215 && dump ("Saving current #define %I", identifier (node
));
17219 /* We're now done with the table. */
17220 elf_in::release (slurp
->from
, sec
);
17225 /* Import the transitive macros. */
17228 module_state::import_macros ()
17230 bitmap_ior_into (headers
, slurp
->headers
);
17232 bitmap_iterator bititer
;
17234 EXECUTE_IF_SET_IN_BITMAP (slurp
->headers
, 0, bitnum
, bititer
)
17235 (*modules
)[bitnum
]->install_macros ();
17238 /* NODE is being undefined at LOC. Record it in the export table, if
17242 module_state::undef_macro (cpp_reader
*, location_t loc
, cpp_hashnode
*node
)
17244 if (!node
->deferred
)
17245 /* The macro is not imported, so our undef is irrelevant. */
17248 unsigned n
= dump
.push (NULL
);
17250 macro_import::slot
&slot
= (*macro_imports
)[node
->deferred
- 1].exported ();
17251 macro_export
&exp
= get_macro_export (slot
);
17253 exp
.undef_loc
= loc
;
17254 slot
.become_undef ();
17257 dump (dumper::MACRO
) && dump ("Recording macro #undef %I", identifier (node
));
17262 /* NODE is a deferred macro node. Determine the definition and return
17263 it, with NULL if undefined. May issue diagnostics.
17265 This can leak memory, when merging declarations -- the string
17266 contents (TOKEN_FLD_STR) of each definition are allocated in
17267 unreclaimable cpp objstack. Only one will win. However, I do not
17268 expect this to be common -- mostly macros have a single point of
17269 definition. Perhaps we could restore the objstack to its position
17270 after the first imported definition (if that wins)? The macros
17271 themselves are GC'd. */
17274 module_state::deferred_macro (cpp_reader
*reader
, location_t loc
,
17275 cpp_hashnode
*node
)
17277 macro_import
&imports
= (*macro_imports
)[node
->deferred
- 1];
17279 unsigned n
= dump
.push (NULL
);
17280 dump (dumper::MACRO
) && dump ("Deferred macro %I", identifier (node
));
17282 bitmap
visible (BITMAP_GGC_ALLOC ());
17284 if (!((imports
[0].get_defness () & macro_import::slot::L_UNDEF
)
17285 && !imports
[0].get_module ()))
17287 /* Calculate the set of visible header imports. */
17288 bitmap_copy (visible
, headers
);
17289 for (unsigned ix
= imports
.length (); ix
--;)
17291 const macro_import::slot
&slot
= imports
[ix
];
17292 unsigned mod
= slot
.get_module ();
17293 if ((slot
.get_defness () & macro_import::slot::L_UNDEF
)
17294 && bitmap_bit_p (visible
, mod
))
17296 bitmap arg
= mod
? (*modules
)[mod
]->slurp
->headers
: headers
;
17297 bitmap_and_compl_into (visible
, arg
);
17298 bitmap_set_bit (visible
, mod
);
17302 bitmap_set_bit (visible
, 0);
17304 /* Now find the macros that are still visible. */
17305 bool failed
= false;
17306 cpp_macro
*def
= NULL
;
17307 vec
<macro_export
> defs
;
17308 defs
.create (imports
.length ());
17309 for (unsigned ix
= imports
.length (); ix
--;)
17311 const macro_import::slot
&slot
= imports
[ix
];
17312 unsigned mod
= slot
.get_module ();
17313 if (bitmap_bit_p (visible
, mod
))
17315 macro_export
*pushed
= NULL
;
17318 const module_state
*imp
= (*modules
)[mod
];
17319 bytes_in
&sec
= imp
->slurp
->macro_defs
;
17320 if (!sec
.get_overrun ())
17322 dump (dumper::MACRO
)
17323 && dump ("Reading macro %s%s%s %I module %M at %u",
17324 slot
.get_defness () & macro_import::slot::L_UNDEF
17326 slot
.get_defness () == macro_import::slot::L_BOTH
17328 slot
.get_defness () & macro_import::slot::L_DEF
17330 identifier (node
), imp
, slot
.offset
);
17331 sec
.random_access (slot
.offset
);
17334 if (slot
.get_defness () & macro_import::slot::L_UNDEF
)
17335 exp
.undef_loc
= imp
->read_location (sec
);
17336 if (slot
.get_defness () & macro_import::slot::L_DEF
)
17337 exp
.def
= imp
->read_define (sec
, reader
);
17338 if (sec
.get_overrun ())
17339 error_at (loc
, "macro definitions of %qE corrupted",
17342 pushed
= defs
.quick_push (exp
);
17346 pushed
= defs
.quick_push ((*macro_exports
)[slot
.offset
]);
17347 if (pushed
&& pushed
->def
)
17351 else if (cpp_compare_macros (def
, pushed
->def
))
17359 /* If LOC is the first loc, this is the end of file check, which
17361 if (loc
== MAP_START_LOCATION (LINEMAPS_ORDINARY_MAP_AT (line_table
, 0)))
17362 warning_at (loc
, OPT_Winvalid_imported_macros
,
17363 "inconsistent imported macro definition %qE",
17364 identifier (node
));
17366 error_at (loc
, "inconsistent imported macro definition %qE",
17367 identifier (node
));
17368 for (unsigned ix
= defs
.length (); ix
--;)
17370 macro_export
&exp
= defs
[ix
];
17372 inform (exp
.undef_loc
, "%<#undef %E%>", identifier (node
));
17374 inform (exp
.def
->line
, "%<#define %s%>",
17375 cpp_macro_definition (reader
, node
, exp
.def
));
17387 /* Stream the static aggregates. Sadly some headers (ahem:
17388 iostream) contain static vars, and rely on them to run global
17391 module_state::write_inits (elf_out
*to
, depset::hash
&table
, unsigned *crc_ptr
)
17393 if (!static_aggregates
&& !tls_aggregates
)
17396 dump () && dump ("Writing initializers");
17399 static_aggregates
= nreverse (static_aggregates
);
17400 tls_aggregates
= nreverse (tls_aggregates
);
17402 unsigned count
= 0;
17403 trees_out
sec (to
, this, table
, ~0u);
17406 tree list
= static_aggregates
;
17407 for (int passes
= 0; passes
!= 2; passes
++)
17409 for (tree init
= list
; init
; init
= TREE_CHAIN (init
), count
++)
17410 if (TREE_LANG_FLAG_0 (init
))
17412 tree decl
= TREE_VALUE (init
);
17414 dump ("Initializer:%u for %N", count
, decl
);
17415 sec
.tree_node (decl
);
17418 list
= tls_aggregates
;
17421 sec
.end (to
, to
->name (MOD_SNAME_PFX
".ini"), crc_ptr
);
17427 /* We have to defer some post-load processing until we've completed
17428 reading, because they can cause more reading. */
17431 post_load_processing ()
17433 /* We mustn't cause a GC, our caller should have arranged for that
17435 gcc_checking_assert (function_depth
);
17437 if (!post_load_decls
)
17440 tree old_cfd
= current_function_decl
;
17441 struct function
*old_cfun
= cfun
;
17442 while (post_load_decls
->length ())
17444 tree decl
= post_load_decls
->pop ();
17446 dump () && dump ("Post-load processing of %N", decl
);
17448 gcc_checking_assert (DECL_ABSTRACT_P (decl
));
17449 /* Cloning can cause loading -- specifically operator delete for
17450 the deleting dtor. */
17451 maybe_clone_body (decl
);
17455 current_function_decl
= old_cfd
;
17459 module_state::read_inits (unsigned count
)
17461 trees_in
sec (this);
17462 if (!sec
.begin (loc
, from (), from ()->find (MOD_SNAME_PFX
".ini")))
17464 dump () && dump ("Reading %u initializers", count
);
17468 for (unsigned ix
= 0; ix
!= count
; ix
++)
17470 /* Merely referencing the decl causes its initializer to be read
17471 and added to the correct list. */
17472 tree decl
= sec
.tree_node ();
17474 if (sec
.get_overrun ())
17477 dump ("Initializer:%u for %N", count
, decl
);
17480 post_load_processing ();
17482 if (!sec
.end (from ()))
17488 module_state::write_counts (elf_out
*to
, unsigned counts
[MSC_HWM
],
17491 bytes_out
cfg (to
);
17495 for (unsigned ix
= MSC_HWM
; ix
--;)
17496 cfg
.u (counts
[ix
]);
17500 dump ("Cluster sections are [%u,%u)",
17501 counts
[MSC_sec_lwm
], counts
[MSC_sec_hwm
]);
17502 dump ("Bindings %u", counts
[MSC_bindings
]);
17503 dump ("Pendings %u", counts
[MSC_pendings
]);
17504 dump ("Entities %u", counts
[MSC_entities
]);
17505 dump ("Namespaces %u", counts
[MSC_namespaces
]);
17506 dump ("Macros %u", counts
[MSC_macros
]);
17507 dump ("Initializers %u", counts
[MSC_inits
]);
17510 cfg
.end (to
, to
->name (MOD_SNAME_PFX
".cnt"), crc_ptr
);
17514 module_state::read_counts (unsigned counts
[MSC_HWM
])
17518 if (!cfg
.begin (loc
, from (), MOD_SNAME_PFX
".cnt"))
17521 for (unsigned ix
= MSC_HWM
; ix
--;)
17522 counts
[ix
] = cfg
.u ();
17526 dump ("Declaration sections are [%u,%u)",
17527 counts
[MSC_sec_lwm
], counts
[MSC_sec_hwm
]);
17528 dump ("Bindings %u", counts
[MSC_bindings
]);
17529 dump ("Pendings %u", counts
[MSC_pendings
]);
17530 dump ("Entities %u", counts
[MSC_entities
]);
17531 dump ("Namespaces %u", counts
[MSC_namespaces
]);
17532 dump ("Macros %u", counts
[MSC_macros
]);
17533 dump ("Initializers %u", counts
[MSC_inits
]);
17536 return cfg
.end (from ());
17539 /* Tool configuration: MOD_SNAME_PFX .config
17541 This is data that confirms current state (or fails). */
17544 module_state::write_config (elf_out
*to
, module_state_config
&config
,
17545 unsigned inner_crc
)
17547 bytes_out
cfg (to
);
17551 /* Write version and inner crc as u32 values, for easier
17552 debug inspection. */
17553 dump () && dump ("Writing version=%V, inner_crc=%x",
17554 MODULE_VERSION
, inner_crc
);
17555 cfg
.u32 (unsigned (MODULE_VERSION
));
17556 cfg
.u32 (inner_crc
);
17558 cfg
.u (to
->name (is_header () ? "" : get_flatname ()));
17560 /* Configuration. */
17561 dump () && dump ("Writing target='%s', host='%s'",
17562 TARGET_MACHINE
, HOST_MACHINE
);
17563 unsigned target
= to
->name (TARGET_MACHINE
);
17564 unsigned host
= (!strcmp (TARGET_MACHINE
, HOST_MACHINE
)
17565 ? target
: to
->name (HOST_MACHINE
));
17569 cfg
.str (config
.dialect_str
);
17570 cfg
.u (extensions
);
17572 /* Global tree information. We write the globals crc separately,
17573 rather than mix it directly into the overall crc, as it is used
17574 to ensure data match between instances of the compiler, not
17575 integrity of the file. */
17576 dump () && dump ("Writing globals=%u, crc=%x",
17577 fixed_trees
->length (), global_crc
);
17578 cfg
.u (fixed_trees
->length ());
17579 cfg
.u32 (global_crc
);
17581 if (is_partition ())
17582 cfg
.u (is_interface ());
17584 cfg
.u (config
.num_imports
);
17585 cfg
.u (config
.num_partitions
);
17586 cfg
.u (config
.num_entities
);
17588 cfg
.u (config
.ordinary_locs
);
17589 cfg
.u (config
.macro_locs
);
17590 cfg
.u (config
.loc_range_bits
);
17592 cfg
.u (config
.active_init
);
17594 /* Now generate CRC, we'll have incorporated the inner CRC because
17595 of its serialization above. */
17596 cfg
.end (to
, to
->name (MOD_SNAME_PFX
".cfg"), &crc
);
17597 dump () && dump ("Writing CRC=%x", crc
);
17601 module_state::note_cmi_name ()
17603 if (!cmi_noted_p
&& filename
)
17605 cmi_noted_p
= true;
17606 inform (loc
, "compiled module file is %qs",
17607 maybe_add_cmi_prefix (filename
));
17612 module_state::read_config (module_state_config
&config
)
17616 if (!cfg
.begin (loc
, from (), MOD_SNAME_PFX
".cfg"))
17619 /* Check version. */
17620 unsigned my_ver
= MODULE_VERSION
;
17621 unsigned their_ver
= cfg
.u32 ();
17622 dump () && dump (my_ver
== their_ver
? "Version %V"
17623 : "Expecting %V found %V", my_ver
, their_ver
);
17624 if (their_ver
!= my_ver
)
17626 /* The compiler versions differ. Close enough? */
17627 verstr_t my_string
, their_string
;
17629 version2string (my_ver
, my_string
);
17630 version2string (their_ver
, their_string
);
17632 /* Reject when either is non-experimental or when experimental
17633 major versions differ. */
17634 bool reject_p
= ((!IS_EXPERIMENTAL (my_ver
)
17635 || !IS_EXPERIMENTAL (their_ver
)
17636 || MODULE_MAJOR (my_ver
) != MODULE_MAJOR (their_ver
))
17637 /* The 'I know what I'm doing' switch. */
17638 && !flag_module_version_ignore
);
17639 bool inform_p
= true;
17642 cfg
.set_overrun ();
17643 error_at (loc
, "compiled module is %sversion %s",
17644 IS_EXPERIMENTAL (their_ver
) ? "experimental " : "",
17648 inform_p
= warning_at (loc
, 0, "compiled module is %sversion %s",
17649 IS_EXPERIMENTAL (their_ver
) ? "experimental " : "",
17654 inform (loc
, "compiler is %sversion %s%s%s",
17655 IS_EXPERIMENTAL (my_ver
) ? "experimental " : "",
17657 reject_p
? "" : flag_module_version_ignore
17658 ? ", be it on your own head!" : ", close enough?",
17659 reject_p
? "" : " \xc2\xaf\\_(\xe3\x83\x84)_/\xc2\xaf");
17667 /* We wrote the inner crc merely to merge it, so simply read it
17668 back and forget it. */
17671 /* Check module name. */
17673 const char *their_name
= from ()->name (cfg
.u ());
17674 const char *our_name
= "";
17677 our_name
= get_flatname ();
17679 /* Header units can be aliased, so name checking is
17681 if (0 != strcmp (their_name
, our_name
))
17684 their_name
[0] && our_name
[0] ? G_("module %qs found")
17686 ? G_("header module expected, module %qs found")
17687 : G_("module %qs expected, header module found"),
17688 their_name
[0] ? their_name
: our_name
);
17689 cfg
.set_overrun ();
17694 /* Check the CRC after the above sanity checks, so that the user is
17697 unsigned e_crc
= crc
;
17698 crc
= cfg
.get_crc ();
17699 dump () && dump ("Reading CRC=%x", crc
);
17700 if (!is_direct () && crc
!= e_crc
)
17702 error_at (loc
, "module %qs CRC mismatch", get_flatname ());
17703 cfg
.set_overrun ();
17708 /* Check target & host. */
17710 const char *their_target
= from ()->name (cfg
.u ());
17711 const char *their_host
= from ()->name (cfg
.u ());
17712 dump () && dump ("Read target='%s', host='%s'", their_target
, their_host
);
17713 if (strcmp (their_target
, TARGET_MACHINE
)
17714 || strcmp (their_host
, HOST_MACHINE
))
17716 error_at (loc
, "target & host is %qs:%qs, expected %qs:%qs",
17717 their_target
, TARGET_MACHINE
, their_host
, HOST_MACHINE
);
17718 cfg
.set_overrun ();
17723 /* Check compilation dialect. This must match. */
17725 const char *their_dialect
= cfg
.str ();
17726 if (strcmp (their_dialect
, config
.dialect_str
))
17728 error_at (loc
, "language dialect differs %qs, expected %qs",
17729 their_dialect
, config
.dialect_str
);
17730 cfg
.set_overrun ();
17735 /* Check for extensions. If they set any, we must have them set
17738 unsigned ext
= cfg
.u ();
17739 unsigned allowed
= (flag_openmp
? SE_OPENMP
: 0);
17741 if (unsigned bad
= ext
& ~allowed
)
17743 if (bad
& SE_OPENMP
)
17744 error_at (loc
, "module contains OpenMP, use %<-fopenmp%> to enable");
17745 cfg
.set_overrun ();
17751 /* Check global trees. */
17753 unsigned their_fixed_length
= cfg
.u ();
17754 unsigned their_fixed_crc
= cfg
.u32 ();
17755 dump () && dump ("Read globals=%u, crc=%x",
17756 their_fixed_length
, their_fixed_crc
);
17757 if (!flag_preprocess_only
17758 && (their_fixed_length
!= fixed_trees
->length ()
17759 || their_fixed_crc
!= global_crc
))
17761 error_at (loc
, "fixed tree mismatch");
17762 cfg
.set_overrun ();
17767 /* All non-partitions are interfaces. */
17768 interface_p
= !is_partition () || cfg
.u ();
17770 config
.num_imports
= cfg
.u ();
17771 config
.num_partitions
= cfg
.u ();
17772 config
.num_entities
= cfg
.u ();
17774 config
.ordinary_locs
= cfg
.u ();
17775 config
.macro_locs
= cfg
.u ();
17776 config
.loc_range_bits
= cfg
.u ();
17778 config
.active_init
= cfg
.u ();
17781 return cfg
.end (from ());
17784 /* Comparator for ordering the Ordered Ordinary Location array. */
17787 ool_cmp (const void *a_
, const void *b_
)
17789 auto *a
= *static_cast<const module_state
*const *> (a_
);
17790 auto *b
= *static_cast<const module_state
*const *> (b_
);
17793 else if (a
->ordinary_locs
.first
< b
->ordinary_locs
.first
)
17799 /* Use ELROND format to record the following sections:
17800 qualified-names : binding value(s)
17801 MOD_SNAME_PFX.README : human readable, strings
17802 MOD_SNAME_PFX.ENV : environment strings, strings
17803 MOD_SNAME_PFX.nms : namespace hierarchy
17804 MOD_SNAME_PFX.bnd : binding table
17805 MOD_SNAME_PFX.spc : specialization table
17806 MOD_SNAME_PFX.imp : import table
17807 MOD_SNAME_PFX.ent : entity table
17808 MOD_SNAME_PFX.prt : partitions table
17809 MOD_SNAME_PFX.olm : ordinary line maps
17810 MOD_SNAME_PFX.mlm : macro line maps
17811 MOD_SNAME_PFX.def : macro definitions
17812 MOD_SNAME_PFX.mac : macro index
17813 MOD_SNAME_PFX.ini : inits
17814 MOD_SNAME_PFX.cnt : counts
17815 MOD_SNAME_PFX.cfg : config data
17819 module_state::write_begin (elf_out
*to
, cpp_reader
*reader
,
17820 module_state_config
&config
, unsigned &crc
)
17822 /* Figure out remapped module numbers, which might elide
17824 bitmap partitions
= NULL
;
17825 if (!is_header () && !is_partition ())
17826 partitions
= BITMAP_GGC_ALLOC ();
17827 write_init_maps ();
17829 unsigned mod_hwm
= 1;
17830 for (unsigned ix
= 1; ix
!= modules
->length (); ix
++)
17832 module_state
*imp
= (*modules
)[ix
];
17834 /* Promote any non-partition direct import from a partition, unless
17835 we're a partition. */
17836 if (!is_partition () && !imp
->is_partition ()
17837 && imp
->is_partition_direct ())
17838 imp
->directness
= MD_PURVIEW_DIRECT
;
17840 /* Write any import that is not a partition, unless we're a
17842 if (!partitions
|| !imp
->is_partition ())
17843 imp
->remap
= mod_hwm
++;
17846 dump () && dump ("Partition %M %u", imp
, ix
);
17847 bitmap_set_bit (partitions
, ix
);
17849 /* All interface partitions must be exported. */
17850 if (imp
->is_interface () && !bitmap_bit_p (exports
, imp
->mod
))
17852 error_at (imp
->loc
, "interface partition is not exported");
17853 bitmap_set_bit (exports
, imp
->mod
);
17856 /* All the partition entities should have been loaded when
17857 loading the partition. */
17859 for (unsigned jx
= 0; jx
!= imp
->entity_num
; jx
++)
17861 binding_slot
*slot
= &(*entity_ary
)[imp
->entity_lwm
+ jx
];
17862 gcc_checking_assert (!slot
->is_lazy ());
17866 if (imp
->is_direct () && (imp
->remap
|| imp
->is_partition ()))
17867 note_location (imp
->imported_from ());
17870 if (partitions
&& bitmap_empty_p (partitions
))
17871 /* No partitions present. */
17872 partitions
= nullptr;
17874 /* Find the set of decls we must write out. */
17875 depset::hash
table (DECL_NAMESPACE_BINDINGS (global_namespace
)->size () * 8);
17876 /* Add the specializations before the writables, so that we can
17877 detect injected friend specializations. */
17878 table
.add_specializations (true);
17879 table
.add_specializations (false);
17880 if (partial_specializations
)
17882 table
.add_partial_entities (partial_specializations
);
17883 partial_specializations
= NULL
;
17885 table
.add_namespace_entities (global_namespace
, partitions
);
17888 table
.add_class_entities (class_members
);
17889 class_members
= NULL
;
17892 /* Now join everything up. */
17893 table
.find_dependencies (this);
17895 if (!table
.finalize_dependencies ())
17902 /* We're done verifying at-most once reading, reset to verify
17903 at-most once writing. */
17904 note_defs
= note_defs_table_t::create_ggc (1000);
17907 /* Determine Strongy Connected Components. */
17908 vec
<depset
*> sccs
= table
.connect ();
17910 vec_alloc (ool
, modules
->length ());
17911 for (unsigned ix
= modules
->length (); --ix
;)
17913 auto *import
= (*modules
)[ix
];
17914 if (import
->loadedness
> ML_NONE
17915 && !(partitions
&& bitmap_bit_p (partitions
, import
->mod
)))
17916 ool
->quick_push (import
);
17918 ool
->qsort (ool_cmp
);
17920 vec
<cpp_hashnode
*> *macros
= nullptr;
17922 macros
= prepare_macros (reader
);
17924 config
.num_imports
= mod_hwm
;
17925 config
.num_partitions
= modules
->length () - mod_hwm
;
17926 auto map_info
= write_prepare_maps (&config
, bool (config
.num_partitions
));
17927 unsigned counts
[MSC_HWM
];
17928 memset (counts
, 0, sizeof (counts
));
17930 /* depset::cluster is the cluster number,
17931 depset::section is unspecified scratch value.
17933 The following loops make use of the tarjan property that
17934 dependencies will be earlier in the SCCS array. */
17936 /* This first loop determines the number of depsets in each SCC, and
17937 also the number of namespaces we're dealing with. During the
17938 loop, the meaning of a couple of depset fields now change:
17940 depset::cluster -> size_of cluster, if first of cluster & !namespace
17941 depset::section -> section number of cluster (if !namespace). */
17943 unsigned n_spaces
= 0;
17944 counts
[MSC_sec_lwm
] = counts
[MSC_sec_hwm
] = to
->get_section_limit ();
17945 for (unsigned size
, ix
= 0; ix
< sccs
.length (); ix
+= size
)
17947 depset
**base
= &sccs
[ix
];
17949 if (base
[0]->get_entity_kind () == depset::EK_NAMESPACE
)
17956 /* Count the members in this cluster. */
17957 for (size
= 1; ix
+ size
< sccs
.length (); size
++)
17958 if (base
[size
]->cluster
!= base
[0]->cluster
)
17961 for (unsigned jx
= 0; jx
!= size
; jx
++)
17963 /* Set the section number. */
17964 base
[jx
]->cluster
= ~(~0u >> 1); /* A bad value. */
17965 base
[jx
]->section
= counts
[MSC_sec_hwm
];
17968 /* Save the size in the first member's cluster slot. */
17969 base
[0]->cluster
= size
;
17971 counts
[MSC_sec_hwm
]++;
17975 /* Write the clusters. Namespace decls are put in the spaces array.
17976 The meaning of depset::cluster changes to provide the
17977 unnamed-decl count of the depset's decl (and remains zero for
17978 non-decls and non-unnamed). */
17979 unsigned bytes
= 0;
17980 vec
<depset
*> spaces
;
17981 spaces
.create (n_spaces
);
17983 for (unsigned size
, ix
= 0; ix
< sccs
.length (); ix
+= size
)
17985 depset
**base
= &sccs
[ix
];
17987 if (base
[0]->get_entity_kind () == depset::EK_NAMESPACE
)
17989 tree decl
= base
[0]->get_entity ();
17990 if (decl
== global_namespace
)
17991 base
[0]->cluster
= 0;
17992 else if (!base
[0]->is_import ())
17994 base
[0]->cluster
= counts
[MSC_entities
]++;
17995 spaces
.quick_push (base
[0]);
17996 counts
[MSC_namespaces
]++;
17999 /* Add it to the entity map, such that we can tell it is
18002 unsigned *slot
= &entity_map
->get_or_insert
18003 (DECL_UID (decl
), &existed
);
18005 /* It must have come from a partition. */
18006 gcc_checking_assert
18007 (import_entity_module (*slot
)->is_partition ());
18008 *slot
= ~base
[0]->cluster
;
18010 dump (dumper::CLUSTER
) && dump ("Cluster namespace %N", decl
);
18016 size
= base
[0]->cluster
;
18018 /* Cluster is now used to number entities. */
18019 base
[0]->cluster
= ~(~0u >> 1); /* A bad value. */
18021 sort_cluster (&table
, base
, size
);
18023 /* Record the section for consistency checking during stream
18024 out -- we don't want to start writing decls in different
18026 table
.section
= base
[0]->section
;
18027 bytes
+= write_cluster (to
, base
, size
, table
, counts
, &crc
);
18032 /* depset::cluster - entity number (on entities)
18033 depset::section - cluster number */
18034 /* We'd better have written as many sections and found as many
18035 namespaces as we predicted. */
18036 gcc_assert (counts
[MSC_sec_hwm
] == to
->get_section_limit ()
18037 && spaces
.length () == counts
[MSC_namespaces
]);
18039 /* Write the entitites. None happens if we contain namespaces or
18041 config
.num_entities
= counts
[MSC_entities
];
18042 if (counts
[MSC_entities
])
18043 write_entities (to
, sccs
, counts
[MSC_entities
], &crc
);
18045 /* Write the namespaces. */
18046 if (counts
[MSC_namespaces
])
18047 write_namespaces (to
, spaces
, counts
[MSC_namespaces
], &crc
);
18049 /* Write the bindings themselves. */
18050 counts
[MSC_bindings
] = write_bindings (to
, sccs
, &crc
);
18052 /* Write the unnamed. */
18053 counts
[MSC_pendings
] = write_pendings (to
, sccs
, table
, &crc
);
18055 /* Write the import table. */
18056 if (config
.num_imports
> 1)
18057 write_imports (to
, &crc
);
18059 /* Write elided partition table. */
18060 if (config
.num_partitions
)
18061 write_partitions (to
, config
.num_partitions
, &crc
);
18063 /* Write the line maps. */
18064 if (config
.ordinary_locs
)
18065 write_ordinary_maps (to
, map_info
, bool (config
.num_partitions
), &crc
);
18066 if (config
.macro_locs
)
18067 write_macro_maps (to
, map_info
, &crc
);
18071 counts
[MSC_macros
] = write_macros (to
, macros
, &crc
);
18072 counts
[MSC_inits
] = write_inits (to
, table
, &crc
);
18076 unsigned clusters
= counts
[MSC_sec_hwm
] - counts
[MSC_sec_lwm
];
18077 dump () && dump ("Wrote %u clusters, average %u bytes/cluster",
18078 clusters
, (bytes
+ clusters
/ 2) / (clusters
+ !clusters
));
18079 trees_out::instrument ();
18081 write_counts (to
, counts
, &crc
);
18086 vec_free (macro_loc_remap
);
18087 vec_free (ord_loc_remap
);
18090 // FIXME:QOI: Have a command line switch to control more detailed
18091 // information (which might leak data you do not want to leak).
18092 // Perhaps (some of) the write_readme contents should also be
18098 // Finish module writing after we've emitted all dynamic initializers.
18101 module_state::write_end (elf_out
*to
, cpp_reader
*reader
,
18102 module_state_config
&config
, unsigned &crc
)
18104 /* And finish up. */
18105 write_config (to
, config
, crc
);
18107 /* Human-readable info. */
18108 write_readme (to
, reader
, config
.dialect_str
);
18110 dump () && dump ("Wrote %u sections", to
->get_section_limit ());
18113 /* Initial read of a CMI. Checks config, loads up imports and line
18117 module_state::read_initial (cpp_reader
*reader
)
18119 module_state_config config
;
18122 if (ok
&& !from ()->begin (loc
))
18125 if (ok
&& !read_config (config
))
18128 bool have_locs
= ok
&& read_prepare_maps (&config
);
18130 /* Ordinary maps before the imports. */
18131 if (!(have_locs
&& config
.ordinary_locs
))
18132 ordinary_locs
.first
= line_table
->highest_location
+ 1;
18133 else if (!read_ordinary_maps (config
.ordinary_locs
, config
.loc_range_bits
))
18136 /* Allocate the REMAP vector. */
18137 slurp
->alloc_remap (config
.num_imports
);
18141 /* Read the import table. Decrement current to stop this CMI
18142 from being evicted during the import. */
18144 if (config
.num_imports
> 1 && !read_imports (reader
, line_table
))
18149 /* Read the elided partition table, if we're the primary partition. */
18150 if (ok
&& config
.num_partitions
&& is_module ()
18151 && !read_partitions (config
.num_partitions
))
18154 /* Determine the module's number. */
18155 gcc_checking_assert (mod
== MODULE_UNKNOWN
);
18156 gcc_checking_assert (this != (*modules
)[0]);
18159 /* Allocate space in the entities array now -- that array must be
18160 monotonically in step with the modules array. */
18161 entity_lwm
= vec_safe_length (entity_ary
);
18162 entity_num
= config
.num_entities
;
18163 gcc_checking_assert (modules
->length () == 1
18164 || modules
->last ()->entity_lwm
<= entity_lwm
);
18165 vec_safe_reserve (entity_ary
, config
.num_entities
);
18168 slot
.u
.binding
= NULL_TREE
;
18169 for (unsigned count
= config
.num_entities
; count
--;)
18170 entity_ary
->quick_push (slot
);
18173 /* We'll run out of other resources before we run out of module
18175 mod
= modules
->length ();
18176 vec_safe_push (modules
, this);
18178 /* We always import and export ourselves. */
18179 bitmap_set_bit (imports
, mod
);
18180 bitmap_set_bit (exports
, mod
);
18183 (*slurp
->remap
)[0] = mod
<< 1;
18184 dump () && dump ("Assigning %M module number %u", this, mod
);
18186 /* We should not have been frozen during the importing done by
18188 gcc_assert (!from ()->is_frozen ());
18190 /* Macro maps after the imports. */
18191 if (!(ok
&& have_locs
&& config
.macro_locs
))
18192 macro_locs
.first
= LINEMAPS_MACRO_LOWEST_LOCATION (line_table
);
18193 else if (!read_macro_maps (config
.macro_locs
))
18196 /* Note whether there's an active initializer. */
18197 active_init_p
= !is_header () && bool (config
.active_init
);
18199 gcc_assert (slurp
->current
== ~0u);
18203 /* Read a preprocessor state. */
18206 module_state::read_preprocessor (bool outermost
)
18208 gcc_checking_assert (is_header () && slurp
18209 && slurp
->remap_module (0) == mod
);
18211 if (loadedness
== ML_PREPROCESSOR
)
18212 return !(from () && from ()->get_error ());
18216 /* Read direct header imports. */
18217 unsigned len
= slurp
->remap
->length ();
18218 for (unsigned ix
= 1; ok
&& ix
!= len
; ix
++)
18220 unsigned map
= (*slurp
->remap
)[ix
];
18223 module_state
*import
= (*modules
)[map
>> 1];
18224 if (import
->is_header ())
18226 ok
= import
->read_preprocessor (false);
18227 bitmap_ior_into (slurp
->headers
, import
->slurp
->headers
);
18232 /* Record as a direct header. */
18234 bitmap_set_bit (slurp
->headers
, mod
);
18236 if (ok
&& !read_macros ())
18239 loadedness
= ML_PREPROCESSOR
;
18240 announce ("macros");
18242 if (flag_preprocess_only
)
18243 /* We're done with the string table. */
18244 from ()->release ();
18246 return check_read (outermost
, ok
);
18249 /* Read language state. */
18252 module_state::read_language (bool outermost
)
18254 gcc_checking_assert (!lazy_snum
);
18256 if (loadedness
== ML_LANGUAGE
)
18257 return !(slurp
&& from () && from ()->get_error ());
18259 gcc_checking_assert (slurp
&& slurp
->current
== ~0u
18260 && slurp
->remap_module (0) == mod
);
18264 /* Read direct imports. */
18265 unsigned len
= slurp
->remap
->length ();
18266 for (unsigned ix
= 1; ok
&& ix
!= len
; ix
++)
18268 unsigned map
= (*slurp
->remap
)[ix
];
18271 module_state
*import
= (*modules
)[map
>> 1];
18272 if (!import
->read_language (false))
18277 unsigned counts
[MSC_HWM
];
18279 if (ok
&& !read_counts (counts
))
18282 function_depth
++; /* Prevent unexpected GCs. */
18284 if (ok
&& counts
[MSC_entities
] != entity_num
)
18286 if (ok
&& counts
[MSC_entities
]
18287 && !read_entities (counts
[MSC_entities
],
18288 counts
[MSC_sec_lwm
], counts
[MSC_sec_hwm
]))
18291 /* Read the namespace hierarchy. */
18292 if (ok
&& counts
[MSC_namespaces
]
18293 && !read_namespaces (counts
[MSC_namespaces
]))
18296 if (ok
&& !read_bindings (counts
[MSC_bindings
],
18297 counts
[MSC_sec_lwm
], counts
[MSC_sec_hwm
]))
18301 if (ok
&& counts
[MSC_pendings
] && !read_pendings (counts
[MSC_pendings
]))
18306 slurp
->remaining
= counts
[MSC_sec_hwm
] - counts
[MSC_sec_lwm
];
18307 available_clusters
+= counts
[MSC_sec_hwm
] - counts
[MSC_sec_lwm
];
18310 if (!flag_module_lazy
18311 || (is_partition ()
18312 && module_interface_p ()
18313 && !module_partition_p ()))
18315 /* Read the sections in forward order, so that dependencies are read
18316 first. See note about tarjan_connect. */
18321 unsigned hwm
= counts
[MSC_sec_hwm
];
18322 for (unsigned ix
= counts
[MSC_sec_lwm
]; ok
&& ix
!= hwm
; ix
++)
18323 if (!load_section (ix
, NULL
))
18329 post_load_processing ();
18333 if (ok
&& CHECKING_P
)
18334 for (unsigned ix
= 0; ix
!= entity_num
; ix
++)
18335 gcc_assert (!(*entity_ary
)[ix
+ entity_lwm
].is_lazy ());
18338 // If the import is a header-unit, we need to register initializers
18339 // of any static objects it contains (looking at you _Ioinit).
18340 // Notice, the ordering of these initializers will be that of a
18341 // dynamic initializer at this point in the current TU. (Other
18342 // instances of these objects in other TUs will be initialized as
18343 // part of that TU's global initializers.)
18344 if (ok
&& counts
[MSC_inits
] && !read_inits (counts
[MSC_inits
]))
18349 announce (flag_module_lazy
? "lazy" : "imported");
18350 loadedness
= ML_LANGUAGE
;
18352 gcc_assert (slurp
->current
== ~0u);
18354 /* We're done with the string table. */
18355 from ()->release ();
18357 return check_read (outermost
, ok
);
18361 module_state::maybe_defrost ()
18364 if (from ()->is_frozen ())
18366 if (lazy_open
>= lazy_limit
)
18368 dump () && dump ("Defrosting '%s'", filename
);
18369 ok
= from ()->defrost (maybe_add_cmi_prefix (filename
));
18376 /* Load section SNUM, dealing with laziness. It doesn't matter if we
18377 have multiple concurrent loads, because we do not use TREE_VISITED
18378 when reading back in. */
18381 module_state::load_section (unsigned snum
, binding_slot
*mslot
)
18383 if (from ()->get_error ())
18386 if (snum
>= slurp
->current
)
18387 from ()->set_error (elf::E_BAD_LAZY
);
18388 else if (maybe_defrost ())
18390 unsigned old_current
= slurp
->current
;
18391 slurp
->current
= snum
;
18392 slurp
->lru
= 0; /* Do not swap out. */
18393 slurp
->remaining
--;
18394 read_cluster (snum
);
18395 slurp
->lru
= ++lazy_lru
;
18396 slurp
->current
= old_current
;
18399 if (mslot
&& mslot
->is_lazy ())
18401 /* Oops, the section didn't set this slot. */
18402 from ()->set_error (elf::E_BAD_DATA
);
18403 *mslot
= NULL_TREE
;
18406 bool ok
= !from ()->get_error ();
18409 error_at (loc
, "failed to read compiled module cluster %u: %s",
18410 snum
, from ()->get_error (filename
));
18414 maybe_completed_reading ();
18420 module_state::maybe_completed_reading ()
18422 if (loadedness
== ML_LANGUAGE
&& slurp
->current
== ~0u && !slurp
->remaining
)
18425 /* We no longer need the macros, all tokenizing has been done. */
18426 slurp
->release_macros ();
18434 /* After a reading operation, make sure things are still ok. If not,
18435 emit an error and clean up. */
18438 module_state::check_read (bool outermost
, bool ok
)
18440 gcc_checking_assert (!outermost
|| slurp
->current
== ~0u);
18443 from ()->set_error ();
18445 if (int e
= from ()->get_error ())
18447 error_at (loc
, "failed to read compiled module: %s",
18448 from ()->get_error (filename
));
18457 inform (loc
, "consider using %<-fno-module-lazy%>,"
18458 " increasing %<-param-lazy-modules=%u%> value,"
18459 " or increasing the per-process file descriptor limit",
18460 param_lazy_modules
);
18461 else if (e
== ENOENT
)
18462 inform (loc
, "imports must be built before being imported");
18465 fatal_error (loc
, "returning to the gate for a mechanical issue");
18470 maybe_completed_reading ();
18475 /* Return the IDENTIFIER_NODE naming module IX. This is the name
18479 module_name (unsigned ix
, bool header_ok
)
18483 module_state
*imp
= (*modules
)[ix
];
18485 if (ix
&& !imp
->name
)
18488 if (header_ok
|| !imp
->is_header ())
18489 return imp
->get_flatname ();
18495 /* Return the bitmap describing what modules are imported. Remember,
18496 we always import ourselves. */
18499 get_import_bitmap ()
18501 return (*modules
)[0]->imports
;
18504 /* Return the visible imports and path of instantiation for an
18505 instantiation at TINST. If TINST is nullptr, we're not in an
18506 instantiation, and thus will return the visible imports of the
18507 current TU (and NULL *PATH_MAP_P). We cache the information on
18508 the tinst level itself. */
18511 path_of_instantiation (tinst_level
*tinst
, bitmap
*path_map_p
)
18513 gcc_checking_assert (modules_p ());
18517 /* Not inside an instantiation, just the regular case. */
18518 *path_map_p
= nullptr;
18519 return get_import_bitmap ();
18525 bitmap visible
= path_of_instantiation (tinst
->next
, path_map_p
);
18526 bitmap path_map
= *path_map_p
;
18530 path_map
= BITMAP_GGC_ALLOC ();
18531 bitmap_set_bit (path_map
, 0);
18534 tree decl
= tinst
->tldcl
;
18535 if (TREE_CODE (decl
) == TREE_LIST
)
18536 decl
= TREE_PURPOSE (decl
);
18538 decl
= TYPE_NAME (decl
);
18540 if (unsigned mod
= get_originating_module (decl
))
18541 if (!bitmap_bit_p (path_map
, mod
))
18543 /* This is brand new information! */
18544 bitmap new_path
= BITMAP_GGC_ALLOC ();
18545 bitmap_copy (new_path
, path_map
);
18546 bitmap_set_bit (new_path
, mod
);
18547 path_map
= new_path
;
18549 bitmap imports
= (*modules
)[mod
]->imports
;
18550 if (bitmap_intersect_compl_p (imports
, visible
))
18552 /* IMPORTS contains additional modules to VISIBLE. */
18553 bitmap new_visible
= BITMAP_GGC_ALLOC ();
18555 bitmap_ior (new_visible
, visible
, imports
);
18556 visible
= new_visible
;
18560 tinst
->path
= path_map
;
18561 tinst
->visible
= visible
;
18564 *path_map_p
= tinst
->path
;
18565 return tinst
->visible
;
18568 /* Return the bitmap describing what modules are visible along the
18569 path of instantiation. If we're not an instantiation, this will be
18570 the visible imports of the TU. *PATH_MAP_P is filled in with the
18571 modules owning the instantiation path -- we see the module-linkage
18572 entities of those modules. */
18575 visible_instantiation_path (bitmap
*path_map_p
)
18580 return path_of_instantiation (current_instantiation (), path_map_p
);
18583 /* We've just directly imported IMPORT. Update our import/export
18584 bitmaps. IS_EXPORT is true if we're reexporting the OTHER. */
18587 module_state::set_import (module_state
const *import
, bool is_export
)
18589 gcc_checking_assert (this != import
);
18591 /* We see IMPORT's exports (which includes IMPORT). If IMPORT is
18592 the primary interface or a partition we'll see its imports. */
18593 bitmap_ior_into (imports
, import
->is_module () || import
->is_partition ()
18594 ? import
->imports
: import
->exports
);
18597 /* We'll export OTHER's exports. */
18598 bitmap_ior_into (exports
, import
->exports
);
18601 /* Return the declaring entity of DECL. That is the decl determining
18602 how to decorate DECL with module information. Returns NULL_TREE if
18603 it's the global module. */
18606 get_originating_module_decl (tree decl
)
18608 /* An enumeration constant. */
18609 if (TREE_CODE (decl
) == CONST_DECL
18610 && DECL_CONTEXT (decl
)
18611 && (TREE_CODE (DECL_CONTEXT (decl
)) == ENUMERAL_TYPE
))
18612 decl
= TYPE_NAME (DECL_CONTEXT (decl
));
18613 else if (TREE_CODE (decl
) == FIELD_DECL
18614 || TREE_CODE (decl
) == USING_DECL
)
18616 decl
= DECL_CONTEXT (decl
);
18617 if (TREE_CODE (decl
) != FUNCTION_DECL
)
18618 decl
= TYPE_NAME (decl
);
18621 gcc_checking_assert (TREE_CODE (decl
) == TEMPLATE_DECL
18622 || TREE_CODE (decl
) == FUNCTION_DECL
18623 || TREE_CODE (decl
) == TYPE_DECL
18624 || TREE_CODE (decl
) == VAR_DECL
18625 || TREE_CODE (decl
) == CONCEPT_DECL
18626 || TREE_CODE (decl
) == NAMESPACE_DECL
);
18630 /* Uninstantiated template friends are owned by the befriending
18631 class -- not their context. */
18632 if (TREE_CODE (decl
) == TEMPLATE_DECL
18633 && DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (decl
))
18634 decl
= TYPE_NAME (DECL_CHAIN (decl
));
18637 if (tree ti
= node_template_info (decl
, use
))
18639 decl
= TI_TEMPLATE (ti
);
18640 if (TREE_CODE (decl
) != TEMPLATE_DECL
)
18642 /* A friend template specialization. */
18643 gcc_checking_assert (OVL_P (decl
));
18644 return global_namespace
;
18649 tree ctx
= CP_DECL_CONTEXT (decl
);
18650 if (TREE_CODE (ctx
) == NAMESPACE_DECL
)
18655 ctx
= TYPE_NAME (ctx
);
18658 /* Some kind of internal type. */
18659 gcc_checking_assert (DECL_ARTIFICIAL (decl
));
18660 return global_namespace
;
18671 get_originating_module (tree decl
, bool for_mangle
)
18673 tree owner
= get_originating_module_decl (decl
);
18674 tree not_tmpl
= STRIP_TEMPLATE (owner
);
18676 if (!DECL_LANG_SPECIFIC (not_tmpl
))
18677 return for_mangle
? -1 : 0;
18679 if (for_mangle
&& !DECL_MODULE_ATTACH_P (not_tmpl
))
18682 int mod
= !DECL_MODULE_IMPORT_P (not_tmpl
) ? 0 : get_importing_module (owner
);
18683 gcc_checking_assert (!for_mangle
|| !(*modules
)[mod
]->is_header ());
18688 get_importing_module (tree decl
, bool flexible
)
18690 unsigned index
= import_entity_index (decl
, flexible
);
18691 if (index
== ~(~0u >> 1))
18693 module_state
*module
= import_entity_module (index
);
18695 return module
->mod
;
18698 /* Is it permissible to redeclare DECL. */
18701 module_may_redeclare (tree decl
)
18705 tree ctx
= CP_DECL_CONTEXT (decl
);
18706 if (TREE_CODE (ctx
) == NAMESPACE_DECL
)
18707 // Found the namespace-scope decl.
18709 if (!CLASS_TYPE_P (ctx
))
18710 // We've met a non-class scope. Such a thing is not
18711 // reopenable, so we must be ok.
18713 decl
= TYPE_NAME (ctx
);
18716 tree not_tmpl
= STRIP_TEMPLATE (decl
);
18719 if (node_template_info (not_tmpl
, use_tpl
) && use_tpl
)
18720 // Specializations of any kind can be redeclared anywhere.
18721 // FIXME: Should we be checking this in more places on the scope chain?
18724 if (!DECL_LANG_SPECIFIC (not_tmpl
) || !DECL_MODULE_ATTACH_P (not_tmpl
))
18725 // Decl is attached to global module. Current scope needs to be too.
18726 return !module_attach_p ();
18728 module_state
*me
= (*modules
)[0];
18729 module_state
*them
= me
;
18731 if (DECL_LANG_SPECIFIC (not_tmpl
) && DECL_MODULE_IMPORT_P (not_tmpl
))
18733 /* We can be given the TEMPLATE_RESULT. We want the
18736 if (tree ti
= node_template_info (decl
, use_tpl
))
18738 tree tmpl
= TI_TEMPLATE (ti
);
18741 /* A partial specialization. Find that specialization's
18743 for (tree list
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
18744 list
; list
= TREE_CHAIN (list
))
18745 if (DECL_TEMPLATE_RESULT (TREE_VALUE (list
)) == decl
)
18747 decl
= TREE_VALUE (list
);
18751 else if (DECL_TEMPLATE_RESULT (tmpl
) == decl
)
18754 unsigned index
= import_entity_index (decl
);
18755 them
= import_entity_module (index
);
18758 // Decl is attached to named module. Current scope needs to be
18759 // attaching to the same module.
18760 if (!module_attach_p ())
18763 // Both attached to named module.
18767 return me
&& get_primary (them
) == get_primary (me
);
18770 /* DECL is being created by this TU. Record it came from here. We
18771 record module purview, so we can see if partial or explicit
18772 specialization needs to be written out, even though its purviewness
18773 comes from the most general template. */
18776 set_instantiating_module (tree decl
)
18778 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
18779 || TREE_CODE (decl
) == VAR_DECL
18780 || TREE_CODE (decl
) == TYPE_DECL
18781 || TREE_CODE (decl
) == CONCEPT_DECL
18782 || TREE_CODE (decl
) == TEMPLATE_DECL
18783 || (TREE_CODE (decl
) == NAMESPACE_DECL
18784 && DECL_NAMESPACE_ALIAS (decl
)));
18789 decl
= STRIP_TEMPLATE (decl
);
18791 if (!DECL_LANG_SPECIFIC (decl
) && module_purview_p ())
18792 retrofit_lang_decl (decl
);
18794 if (DECL_LANG_SPECIFIC (decl
))
18796 DECL_MODULE_PURVIEW_P (decl
) = module_purview_p ();
18797 /* If this was imported, we'll still be in the entity_hash. */
18798 DECL_MODULE_IMPORT_P (decl
) = false;
18802 /* If DECL is a class member, whose class is not defined in this TU
18803 (it was imported), remember this decl. */
18806 set_defining_module (tree decl
)
18808 gcc_checking_assert (!DECL_LANG_SPECIFIC (decl
)
18809 || !DECL_MODULE_IMPORT_P (decl
));
18811 if (module_has_cmi_p ())
18813 tree ctx
= DECL_CONTEXT (decl
);
18815 && (TREE_CODE (ctx
) == RECORD_TYPE
|| TREE_CODE (ctx
) == UNION_TYPE
)
18816 && DECL_LANG_SPECIFIC (TYPE_NAME (ctx
))
18817 && DECL_MODULE_IMPORT_P (TYPE_NAME (ctx
)))
18819 /* This entity's context is from an import. We may need to
18820 record this entity to make sure we emit it in the CMI.
18821 Template specializations are in the template hash tables,
18822 so we don't need to record them here as well. */
18824 tree ti
= node_template_info (decl
, use_tpl
);
18829 gcc_checking_assert (!use_tpl
);
18830 /* Get to the TEMPLATE_DECL. */
18831 decl
= TI_TEMPLATE (ti
);
18834 /* Record it on the class_members list. */
18835 vec_safe_push (class_members
, decl
);
18838 else if (DECL_IMPLICIT_TYPEDEF_P (decl
)
18839 && CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (decl
)))
18840 /* This is a partial or explicit specialization. */
18841 vec_safe_push (partial_specializations
, decl
);
18846 set_originating_module (tree decl
, bool friend_p ATTRIBUTE_UNUSED
)
18848 set_instantiating_module (decl
);
18850 if (!DECL_NAMESPACE_SCOPE_P (decl
))
18853 gcc_checking_assert (friend_p
|| decl
== get_originating_module_decl (decl
));
18855 if (module_attach_p ())
18857 retrofit_lang_decl (decl
);
18858 DECL_MODULE_ATTACH_P (decl
) = true;
18861 if (!module_exporting_p ())
18864 // FIXME: Check ill-formed linkage
18865 DECL_MODULE_EXPORT_P (decl
) = true;
18868 /* DECL is keyed to CTX for odr purposes. */
18871 maybe_key_decl (tree ctx
, tree decl
)
18876 // FIXME: For now just deal with lambdas attached to var decls.
18877 // This might be sufficient?
18878 if (TREE_CODE (ctx
) != VAR_DECL
)
18881 gcc_checking_assert (DECL_NAMESPACE_SCOPE_P (ctx
));
18884 keyed_table
= new keyed_map_t (EXPERIMENT (1, 400));
18886 auto &vec
= keyed_table
->get_or_insert (ctx
);
18887 if (!vec
.length ())
18889 retrofit_lang_decl (ctx
);
18890 DECL_MODULE_KEYED_DECLS_P (ctx
) = true;
18892 vec
.safe_push (decl
);
18895 /* Create the flat name string. It is simplest to have it handy. */
18898 module_state::set_flatname ()
18900 gcc_checking_assert (!flatname
);
18903 auto_vec
<tree
,5> ids
;
18905 char const *primary
= NULL
;
18906 size_t pfx_len
= 0;
18908 for (module_state
*probe
= this;
18910 probe
= probe
->parent
)
18911 if (is_partition () && !probe
->is_partition ())
18913 primary
= probe
->get_flatname ();
18914 pfx_len
= strlen (primary
);
18919 ids
.safe_push (probe
->name
);
18920 len
+= IDENTIFIER_LENGTH (probe
->name
) + 1;
18923 char *flat
= XNEWVEC (char, pfx_len
+ len
+ is_partition ());
18928 memcpy (flat
, primary
, pfx_len
);
18933 for (unsigned len
= 0; ids
.length ();)
18937 tree elt
= ids
.pop ();
18938 unsigned l
= IDENTIFIER_LENGTH (elt
);
18939 memcpy (flat
+ len
, IDENTIFIER_POINTER (elt
), l
+ 1);
18943 else if (is_header ())
18944 flatname
= TREE_STRING_POINTER (name
);
18946 flatname
= IDENTIFIER_POINTER (name
);
18949 /* Read the CMI file for a module. */
18952 module_state::do_import (cpp_reader
*reader
, bool outermost
)
18954 gcc_assert (global_namespace
== current_scope () && loadedness
== ML_NONE
);
18956 loc
= linemap_module_loc (line_table
, loc
, get_flatname ());
18958 if (lazy_open
>= lazy_limit
)
18965 const char *file
= maybe_add_cmi_prefix (filename
);
18966 dump () && dump ("CMI is %s", file
);
18967 if (note_module_cmi_yes
|| inform_cmi_p
)
18968 inform (loc
, "reading CMI %qs", file
);
18969 fd
= open (file
, O_RDONLY
| O_CLOEXEC
| O_BINARY
);
18973 gcc_checking_assert (!slurp
);
18974 slurp
= new slurping (new elf_in (fd
, e
));
18977 if (!from ()->get_error ())
18979 announce ("importing");
18980 loadedness
= ML_CONFIG
;
18982 ok
= read_initial (reader
);
18983 slurp
->lru
= ++lazy_lru
;
18986 gcc_assert (slurp
->current
== ~0u);
18988 return check_read (outermost
, ok
);
18991 /* Attempt to increase the file descriptor limit. */
18994 try_increase_lazy (unsigned want
)
18996 gcc_checking_assert (lazy_open
>= lazy_limit
);
18998 /* If we're increasing, saturate at hard limit. */
18999 if (want
> lazy_hard_limit
&& lazy_limit
< lazy_hard_limit
)
19000 want
= lazy_hard_limit
;
19003 if ((!lazy_limit
|| !param_lazy_modules
)
19005 && want
<= lazy_hard_limit
)
19007 struct rlimit rlimit
;
19008 rlimit
.rlim_cur
= want
+ LAZY_HEADROOM
;
19009 rlimit
.rlim_max
= lazy_hard_limit
+ LAZY_HEADROOM
;
19010 if (!setrlimit (RLIMIT_NOFILE
, &rlimit
))
19015 return lazy_open
< lazy_limit
;
19018 /* Pick a victim module to freeze its reader. */
19021 module_state::freeze_an_elf ()
19023 if (try_increase_lazy (lazy_open
* 2))
19026 module_state
*victim
= NULL
;
19027 for (unsigned ix
= modules
->length (); ix
--;)
19029 module_state
*candidate
= (*modules
)[ix
];
19030 if (candidate
&& candidate
->slurp
&& candidate
->slurp
->lru
19031 && candidate
->from ()->is_freezable ()
19032 && (!victim
|| victim
->slurp
->lru
> candidate
->slurp
->lru
))
19033 victim
= candidate
;
19038 dump () && dump ("Freezing '%s'", victim
->filename
);
19039 if (victim
->slurp
->macro_defs
.size
)
19040 /* Save the macro definitions to a buffer. */
19041 victim
->from ()->preserve (victim
->slurp
->macro_defs
);
19042 if (victim
->slurp
->macro_tbl
.size
)
19043 /* Save the macro definitions to a buffer. */
19044 victim
->from ()->preserve (victim
->slurp
->macro_tbl
);
19045 victim
->from ()->freeze ();
19049 dump () && dump ("No module available for freezing");
19052 /* Load the lazy slot *MSLOT, INDEX'th slot of the module. */
19055 module_state::lazy_load (unsigned index
, binding_slot
*mslot
)
19057 unsigned n
= dump
.push (this);
19059 gcc_checking_assert (function_depth
);
19061 unsigned cookie
= mslot
->get_lazy ();
19062 unsigned snum
= cookie
>> 2;
19063 dump () && dump ("Loading entity %M[%u] section:%u", this, index
, snum
);
19065 bool ok
= load_section (snum
, mslot
);
19072 /* Load MOD's binding for NS::ID into *MSLOT. *MSLOT contains the
19073 lazy cookie. OUTER is true if this is the outermost lazy, (used
19074 for diagnostics). */
19077 lazy_load_binding (unsigned mod
, tree ns
, tree id
, binding_slot
*mslot
)
19079 int count
= errorcount
+ warningcount
;
19081 timevar_start (TV_MODULE_IMPORT
);
19083 /* Make sure lazy loading from a template context behaves as if
19084 from a non-template context. */
19085 processing_template_decl_sentinel ptds
;
19087 /* Stop GC happening, even in outermost loads (because our caller
19088 could well be building up a lookup set). */
19091 gcc_checking_assert (mod
);
19092 module_state
*module
= (*modules
)[mod
];
19093 unsigned n
= dump
.push (module
);
19095 unsigned snum
= mslot
->get_lazy ();
19096 dump () && dump ("Lazily binding %P@%N section:%u", ns
, id
,
19097 module
->name
, snum
);
19099 bool ok
= !recursive_lazy (snum
);
19102 ok
= module
->load_section (snum
, mslot
);
19104 post_load_processing ();
19111 timevar_stop (TV_MODULE_IMPORT
);
19114 fatal_error (input_location
,
19115 module
->is_header ()
19116 ? G_("failed to load binding %<%E%s%E%>")
19117 : G_("failed to load binding %<%E%s%E@%s%>"),
19118 ns
, &"::"[ns
== global_namespace
? 2 : 0], id
,
19119 module
->get_flatname ());
19121 if (count
!= errorcount
+ warningcount
)
19122 inform (input_location
,
19123 module
->is_header ()
19124 ? G_("during load of binding %<%E%s%E%>")
19125 : G_("during load of binding %<%E%s%E@%s%>"),
19126 ns
, &"::"[ns
== global_namespace
? 2 : 0], id
,
19127 module
->get_flatname ());
19130 /* Load any pending entities keyed to the top-key of DECL. */
19133 lazy_load_pendings (tree decl
)
19135 /* Make sure lazy loading from a template context behaves as if
19136 from a non-template context. */
19137 processing_template_decl_sentinel ptds
;
19141 key
.ns
= find_pending_key (decl
, &key_decl
);
19142 key
.id
= DECL_NAME (key_decl
);
19144 auto *pending_vec
= pending_table
? pending_table
->get (key
) : nullptr;
19148 int count
= errorcount
+ warningcount
;
19150 timevar_start (TV_MODULE_IMPORT
);
19151 bool ok
= !recursive_lazy ();
19154 function_depth
++; /* Prevent GC */
19155 unsigned n
= dump
.push (NULL
);
19156 dump () && dump ("Reading %u pending entities keyed to %P",
19157 pending_vec
->length (), key
.ns
, key
.id
);
19158 for (unsigned ix
= pending_vec
->length (); ix
--;)
19160 unsigned index
= (*pending_vec
)[ix
];
19161 binding_slot
*slot
= &(*entity_ary
)[index
];
19163 if (slot
->is_lazy ())
19165 module_state
*import
= import_entity_module (index
);
19166 if (!import
->lazy_load (index
- import
->entity_lwm
, slot
))
19171 module_state
*import
= import_entity_module (index
);
19172 dump () && dump ("Entity %M[%u] already loaded",
19173 import
, index
- import
->entity_lwm
);
19177 pending_table
->remove (key
);
19180 post_load_processing ();
19184 timevar_stop (TV_MODULE_IMPORT
);
19187 fatal_error (input_location
, "failed to load pendings for %<%E%s%E%>",
19188 key
.ns
, &"::"[key
.ns
== global_namespace
? 2 : 0], key
.id
);
19190 if (count
!= errorcount
+ warningcount
)
19191 inform (input_location
, "during load of pendings for %<%E%s%E%>",
19192 key
.ns
, &"::"[key
.ns
== global_namespace
? 2 : 0], key
.id
);
19196 direct_import (module_state
*import
, cpp_reader
*reader
)
19198 timevar_start (TV_MODULE_IMPORT
);
19199 unsigned n
= dump
.push (import
);
19201 gcc_checking_assert (import
->is_direct () && import
->has_location ());
19202 if (import
->loadedness
== ML_NONE
)
19203 if (!import
->do_import (reader
, true))
19204 gcc_unreachable ();
19206 if (import
->loadedness
< ML_LANGUAGE
)
19209 keyed_table
= new keyed_map_t (EXPERIMENT (1, 400));
19210 import
->read_language (true);
19213 (*modules
)[0]->set_import (import
, import
->exported_p
);
19216 timevar_stop (TV_MODULE_IMPORT
);
19219 /* Import module IMPORT. */
19222 import_module (module_state
*import
, location_t from_loc
, bool exporting_p
,
19223 tree
, cpp_reader
*reader
)
19225 if (!import
->check_not_purview (from_loc
))
19228 if (!import
->is_header () && current_lang_depth ())
19229 /* Only header units should appear inside language
19230 specifications. The std doesn't specify this, but I think
19231 that's an error in resolving US 033, because language linkage
19232 is also our escape clause to getting things into the global
19233 module, so we don't want to confuse things by having to think
19234 about whether 'extern "C++" { import foo; }' puts foo's
19235 contents into the global module all of a sudden. */
19236 warning (0, "import of named module %qs inside language-linkage block",
19237 import
->get_flatname ());
19239 if (exporting_p
|| module_exporting_p ())
19240 import
->exported_p
= true;
19242 if (import
->loadedness
!= ML_NONE
)
19244 from_loc
= ordinary_loc_of (line_table
, from_loc
);
19245 linemap_module_reparent (line_table
, import
->loc
, from_loc
);
19247 gcc_checking_assert (!import
->module_p
);
19248 gcc_checking_assert (import
->is_direct () && import
->has_location ());
19250 direct_import (import
, reader
);
19253 /* Declare the name of the current module to be NAME. EXPORTING_p is
19254 true if this TU is the exporting module unit. */
19257 declare_module (module_state
*module
, location_t from_loc
, bool exporting_p
,
19258 tree
, cpp_reader
*reader
)
19260 gcc_assert (global_namespace
== current_scope ());
19262 module_state
*current
= (*modules
)[0];
19263 if (module_purview_p () || module
->loadedness
> ML_CONFIG
)
19265 error_at (from_loc
, module_purview_p ()
19266 ? G_("module already declared")
19267 : G_("module already imported"));
19268 if (module_purview_p ())
19270 inform (module
->loc
, module_purview_p ()
19271 ? G_("module %qs declared here")
19272 : G_("module %qs imported here"),
19273 module
->get_flatname ());
19277 gcc_checking_assert (module
->module_p
);
19278 gcc_checking_assert (module
->is_direct () && module
->has_location ());
19280 /* Yer a module, 'arry. */
19281 module_kind
= module
->is_header () ? MK_HEADER
: MK_NAMED
| MK_ATTACH
;
19283 // Even in header units, we consider the decls to be purview
19284 module_kind
|= MK_PURVIEW
;
19286 if (module
->is_partition ())
19287 module_kind
|= MK_PARTITION
;
19290 module
->interface_p
= true;
19291 module_kind
|= MK_INTERFACE
;
19294 if (module_has_cmi_p ())
19296 /* Copy the importing information we may have already done. We
19297 do not need to separate out the imports that only happen in
19298 the GMF, inspite of what the literal wording of the std
19299 might imply. See p2191, the core list had a discussion
19300 where the module implementors agreed that the GMF of a named
19301 module is invisible to importers. */
19302 module
->imports
= current
->imports
;
19305 (*modules
)[0] = module
;
19309 module
->interface_p
= true;
19310 current
->parent
= module
; /* So mangler knows module identity. */
19311 direct_import (module
, reader
);
19315 /* Return true IFF we must emit a module global initializer function
19316 (which will be called by importers' init code). */
19319 module_global_init_needed ()
19321 return module_has_cmi_p () && !header_module_p ();
19324 /* Calculate which, if any, import initializers need calling. */
19327 module_determine_import_inits ()
19329 if (!modules
|| header_module_p ())
19332 /* Prune active_init_p. We need the same bitmap allocation
19333 scheme as for the imports member. */
19334 function_depth
++; /* Disable GC. */
19335 bitmap
covered_imports (BITMAP_GGC_ALLOC ());
19339 /* Because indirect imports are before their direct import, and
19340 we're scanning the array backwards, we only need one pass! */
19341 for (unsigned ix
= modules
->length (); --ix
;)
19343 module_state
*import
= (*modules
)[ix
];
19345 if (!import
->active_init_p
)
19347 else if (bitmap_bit_p (covered_imports
, ix
))
19348 import
->active_init_p
= false;
19351 /* Everything this imports is therefore handled by its
19352 initializer, so doesn't need initializing by us. */
19353 bitmap_ior_into (covered_imports
, import
->imports
);
19362 /* Emit calls to each direct import's global initializer. Including
19363 direct imports of directly imported header units. The initializers
19364 of (static) entities in header units will be called by their
19365 importing modules (for the instance contained within that), or by
19366 the current TU (for the instances we've brought in). Of course
19367 such header unit behaviour is evil, but iostream went through that
19368 door some time ago. */
19371 module_add_import_initializers ()
19373 if (!modules
|| header_module_p ())
19376 tree fntype
= build_function_type (void_type_node
, void_list_node
);
19377 releasing_vec args
; // There are no args
19379 for (unsigned ix
= modules
->length (); --ix
;)
19381 module_state
*import
= (*modules
)[ix
];
19382 if (import
->active_init_p
)
19384 tree name
= mangle_module_global_init (ix
);
19385 tree fndecl
= build_lang_decl (FUNCTION_DECL
, name
, fntype
);
19387 DECL_CONTEXT (fndecl
) = FROB_CONTEXT (global_namespace
);
19388 SET_DECL_ASSEMBLER_NAME (fndecl
, name
);
19389 TREE_PUBLIC (fndecl
) = true;
19390 determine_visibility (fndecl
);
19392 tree call
= cp_build_function_call_vec (fndecl
, &args
,
19393 tf_warning_or_error
);
19394 finish_expr_stmt (call
);
19399 /* NAME & LEN are a preprocessed header name, possibly including the
19400 surrounding "" or <> characters. Return the raw string name of the
19401 module to which it refers. This will be an absolute path, or begin
19402 with ./, so it is immediately distinguishable from a (non-header
19403 unit) module name. If READER is non-null, ask the preprocessor to
19404 locate the header to which it refers using the appropriate include
19405 path. Note that we do never do \ processing of the string, as that
19406 matches the preprocessor's behaviour. */
19408 static const char *
19409 canonicalize_header_name (cpp_reader
*reader
, location_t loc
, bool unquoted
,
19410 const char *str
, size_t &len_r
)
19412 size_t len
= len_r
;
19413 static char *buf
= 0;
19414 static size_t alloc
= 0;
19418 gcc_checking_assert (len
>= 2
19419 && ((reader
&& str
[0] == '<' && str
[len
-1] == '>')
19420 || (str
[0] == '"' && str
[len
-1] == '"')));
19427 gcc_assert (!unquoted
);
19432 buf
= XRESIZEVEC (char, buf
, alloc
);
19434 memcpy (buf
, str
, len
);
19437 if (const char *hdr
19438 = cpp_probe_header_unit (reader
, buf
, str
[-1] == '<', loc
))
19440 len
= strlen (hdr
);
19447 if (!(str
[0] == '.' ? IS_DIR_SEPARATOR (str
[1]) : IS_ABSOLUTE_PATH (str
)))
19450 if (len
+ 3 > alloc
)
19453 buf
= XRESIZEVEC (char, buf
, alloc
);
19457 buf
[1] = DIR_SEPARATOR
;
19458 memmove (buf
+ 2, str
, len
);
19468 /* Set the CMI name from a cody packet. Issue an error if
19471 void module_state::set_filename (const Cody::Packet
&packet
)
19473 gcc_checking_assert (!filename
);
19474 if (packet
.GetCode () == Cody::Client::PC_PATHNAME
)
19475 filename
= xstrdup (packet
.GetString ().c_str ());
19478 gcc_checking_assert (packet
.GetCode () == Cody::Client::PC_ERROR
);
19479 error_at (loc
, "unknown Compiled Module Interface: %s",
19480 packet
.GetString ().c_str ());
19484 /* Figure out whether to treat HEADER as an include or an import. */
19487 maybe_translate_include (cpp_reader
*reader
, line_maps
*lmaps
, location_t loc
,
19493 cpp_get_callbacks (reader
)->translate_include
= NULL
;
19497 if (!spans
.init_p ())
19498 /* Before the main file, don't divert. */
19503 dump () && dump ("Checking include translation '%s'", path
);
19504 auto *mapper
= get_mapper (cpp_main_loc (reader
));
19506 size_t len
= strlen (path
);
19507 path
= canonicalize_header_name (NULL
, loc
, true, path
, len
);
19508 auto packet
= mapper
->IncludeTranslate (path
, Cody::Flags::None
, len
);
19510 if (packet
.GetCode () == Cody::Client::PC_BOOL
)
19511 xlate
= -int (packet
.GetInteger ());
19512 else if (packet
.GetCode () == Cody::Client::PC_PATHNAME
)
19514 /* Record the CMI name for when we do the import. */
19515 module_state
*import
= get_module (build_string (len
, path
));
19516 import
->set_filename (packet
);
19521 gcc_checking_assert (packet
.GetCode () == Cody::Client::PC_ERROR
);
19522 error_at (loc
, "cannot determine %<#include%> translation of %s: %s",
19523 path
, packet
.GetString ().c_str ());
19527 if (note_include_translate_yes
&& xlate
> 1)
19529 else if (note_include_translate_no
&& xlate
== 0)
19531 else if (note_includes
)
19532 /* We do not expect the note_includes vector to be large, so O(N)
19534 for (unsigned ix
= note_includes
->length (); !note
&& ix
--;)
19535 if (!strcmp ((*note_includes
)[ix
], path
))
19540 ? G_("include %qs translated to import")
19541 : G_("include %qs processed textually") , path
);
19543 dump () && dump (xlate
? "Translating include to import"
19544 : "Keeping include as include");
19550 /* Create the translation text. */
19551 loc
= ordinary_loc_of (lmaps
, loc
);
19552 const line_map_ordinary
*map
19553 = linemap_check_ordinary (linemap_lookup (lmaps
, loc
));
19554 unsigned col
= SOURCE_COLUMN (map
, loc
);
19555 col
-= (col
!= 0); /* Columns are 1-based. */
19557 unsigned alloc
= len
+ col
+ 60;
19558 char *res
= XNEWVEC (char, alloc
);
19560 strcpy (res
, "__import");
19561 unsigned actual
= 8;
19564 /* Pad out so the filename appears at the same position. */
19565 memset (res
+ actual
, ' ', col
- actual
);
19568 /* No need to encode characters, that's not how header names are
19570 actual
+= snprintf (res
+ actual
, alloc
- actual
,
19571 "\"%s\" [[__translated]];\n", path
);
19572 gcc_checking_assert (actual
< alloc
);
19574 /* cpplib will delete the buffer. */
19579 begin_header_unit (cpp_reader
*reader
)
19581 /* Set the module header name from the main_input_filename. */
19582 const char *main
= main_input_filename
;
19583 size_t len
= strlen (main
);
19584 main
= canonicalize_header_name (NULL
, 0, true, main
, len
);
19585 module_state
*module
= get_module (build_string (len
, main
));
19587 preprocess_module (module
, cpp_main_loc (reader
), false, false, true, reader
);
19590 /* We've just properly entered the main source file. I.e. after the
19591 command line, builtins and forced headers. Record the line map and
19592 location of this map. Note we may be called more than once. The
19593 first call sticks. */
19596 module_begin_main_file (cpp_reader
*reader
, line_maps
*lmaps
,
19597 const line_map_ordinary
*map
)
19599 gcc_checking_assert (lmaps
== line_table
);
19600 if (modules_p () && !spans
.init_p ())
19602 unsigned n
= dump
.push (NULL
);
19603 spans
.init (lmaps
, map
);
19605 if (flag_header_unit
&& !cpp_get_options (reader
)->preprocessed
)
19607 /* Tell the preprocessor this is an include file. */
19608 cpp_retrofit_as_include (reader
);
19609 begin_header_unit (reader
);
19614 /* Process the pending_import queue, making sure we know the
19618 name_pending_imports (cpp_reader
*reader
)
19620 auto *mapper
= get_mapper (cpp_main_loc (reader
));
19622 if (!vec_safe_length (pending_imports
))
19623 /* Not doing anything. */
19626 timevar_start (TV_MODULE_MAPPER
);
19628 auto n
= dump
.push (NULL
);
19629 dump () && dump ("Resolving direct import names");
19630 bool want_deps
= (bool (mapper
->get_flags () & Cody::Flags::NameOnly
)
19631 || cpp_get_deps (reader
));
19634 for (unsigned ix
= 0; ix
!= pending_imports
->length (); ix
++)
19636 module_state
*module
= (*pending_imports
)[ix
];
19637 gcc_checking_assert (module
->is_direct ());
19638 if (!module
->filename
&& !module
->visited_p
)
19640 bool export_p
= (module
->module_p
19641 && (module
->is_partition () || module
->exported_p
));
19643 Cody::Flags flags
= Cody::Flags::None
;
19644 if (flag_preprocess_only
19645 && !(module
->is_header () && !export_p
))
19649 flags
= Cody::Flags::NameOnly
;
19658 mapper
->ModuleExport (module
->get_flatname (), flags
);
19660 mapper
->ModuleImport (module
->get_flatname (), flags
);
19661 module
->visited_p
= true;
19667 auto response
= mapper
->Uncork ();
19668 auto r_iter
= response
.begin ();
19669 for (unsigned ix
= 0; ix
!= pending_imports
->length (); ix
++)
19671 module_state
*module
= (*pending_imports
)[ix
];
19672 if (module
->visited_p
)
19674 module
->visited_p
= false;
19675 gcc_checking_assert (!module
->filename
);
19677 module
->set_filename (*r_iter
);
19685 timevar_stop (TV_MODULE_MAPPER
);
19688 /* We've just lexed a module-specific control line for MODULE. Mark
19689 the module as a direct import, and possibly load up its macro
19690 state. Returns the primary module, if this is a module
19692 /* Perhaps we should offer a preprocessing mode where we read the
19693 directives from the header unit, rather than require the header's
19697 preprocess_module (module_state
*module
, location_t from_loc
,
19698 bool in_purview
, bool is_import
, bool is_export
,
19699 cpp_reader
*reader
)
19704 /* It's already been mentioned, so ignore its module-ness. */
19708 /* Record it is the module. */
19709 module
->module_p
= true;
19712 module
->exported_p
= true;
19713 module
->interface_p
= true;
19718 if (module
->directness
< MD_DIRECT
+ in_purview
)
19720 /* Mark as a direct import. */
19721 module
->directness
= module_directness (MD_DIRECT
+ in_purview
);
19723 /* Set the location to be most informative for users. */
19724 from_loc
= ordinary_loc_of (line_table
, from_loc
);
19725 if (module
->loadedness
!= ML_NONE
)
19726 linemap_module_reparent (line_table
, module
->loc
, from_loc
);
19729 module
->loc
= from_loc
;
19730 if (!module
->flatname
)
19731 module
->set_flatname ();
19735 auto desired
= ML_CONFIG
;
19737 && module
->is_header ()
19738 && (!cpp_get_options (reader
)->preprocessed
19739 || cpp_get_options (reader
)->directives_only
))
19740 /* We need preprocessor state now. */
19741 desired
= ML_PREPROCESSOR
;
19743 if (!is_import
|| module
->loadedness
< desired
)
19745 vec_safe_push (pending_imports
, module
);
19747 if (desired
== ML_PREPROCESSOR
)
19749 unsigned n
= dump
.push (NULL
);
19751 dump () && dump ("Reading %M preprocessor state", module
);
19752 name_pending_imports (reader
);
19754 /* Preserve the state of the line-map. */
19755 unsigned pre_hwm
= LINEMAPS_ORDINARY_USED (line_table
);
19757 /* We only need to close the span, if we're going to emit a
19758 CMI. But that's a little tricky -- our token scanner
19759 needs to be smarter -- and this isn't much state.
19760 Remember, we've not parsed anything at this point, so
19761 our module state flags are inadequate. */
19762 spans
.maybe_init ();
19765 timevar_start (TV_MODULE_IMPORT
);
19767 /* Load the config of each pending import -- we must assign
19768 module numbers monotonically. */
19769 for (unsigned ix
= 0; ix
!= pending_imports
->length (); ix
++)
19771 auto *import
= (*pending_imports
)[ix
];
19772 if (!(import
->module_p
19773 && (import
->is_partition () || import
->exported_p
))
19774 && import
->loadedness
== ML_NONE
19775 && (import
->is_header () || !flag_preprocess_only
))
19777 unsigned n
= dump
.push (import
);
19778 import
->do_import (reader
, true);
19782 vec_free (pending_imports
);
19784 /* Restore the line-map state. */
19785 spans
.open (linemap_module_restore (line_table
, pre_hwm
));
19787 /* Now read the preprocessor state of this particular
19789 if (module
->loadedness
== ML_CONFIG
19790 && module
->read_preprocessor (true))
19791 module
->import_macros ();
19793 timevar_stop (TV_MODULE_IMPORT
);
19799 return is_import
? NULL
: get_primary (module
);
19802 /* We've completed phase-4 translation. Emit any dependency
19803 information for the not-yet-loaded direct imports, and fill in
19804 their file names. We'll have already loaded up the direct header
19808 preprocessed_module (cpp_reader
*reader
)
19810 unsigned n
= dump
.push (NULL
);
19812 dump () && dump ("Completed phase-4 (tokenization) processing");
19814 name_pending_imports (reader
);
19815 vec_free (pending_imports
);
19817 spans
.maybe_init ();
19820 using iterator
= hash_table
<module_state_hash
>::iterator
;
19821 if (mkdeps
*deps
= cpp_get_deps (reader
))
19823 /* Walk the module hash, informing the dependency machinery. */
19824 iterator end
= modules_hash
->end ();
19825 for (iterator iter
= modules_hash
->begin (); iter
!= end
; ++iter
)
19827 module_state
*module
= *iter
;
19829 if (module
->is_direct ())
19831 if (module
->is_module ()
19832 && (module
->is_interface () || module
->is_partition ()))
19833 deps_add_module_target (deps
, module
->get_flatname (),
19834 maybe_add_cmi_prefix (module
->filename
),
19835 module
->is_header());
19837 deps_add_module_dep (deps
, module
->get_flatname ());
19842 if (flag_header_unit
&& !flag_preprocess_only
)
19844 /* Find the main module -- remember, it's not yet in the module
19846 iterator end
= modules_hash
->end ();
19847 for (iterator iter
= modules_hash
->begin (); iter
!= end
; ++iter
)
19849 module_state
*module
= *iter
;
19850 if (module
->is_module ())
19852 declare_module (module
, cpp_main_loc (reader
), true, NULL
, reader
);
19853 module_kind
|= MK_EXPORTING
;
19862 /* VAL is a global tree, add it to the global vec if it is
19863 interesting. Add some of its targets, if they too are
19864 interesting. We do not add identifiers, as they can be re-found
19865 via the identifier hash table. There is a cost to the number of
19869 maybe_add_global (tree val
, unsigned &crc
)
19873 if (val
&& !(identifier_p (val
) || TREE_VISITED (val
)))
19875 TREE_VISITED (val
) = true;
19876 crc
= crc32_unsigned (crc
, fixed_trees
->length ());
19877 vec_safe_push (fixed_trees
, val
);
19880 if (CODE_CONTAINS_STRUCT (TREE_CODE (val
), TS_TYPED
))
19881 v
+= maybe_add_global (TREE_TYPE (val
), crc
);
19882 if (CODE_CONTAINS_STRUCT (TREE_CODE (val
), TS_TYPE_COMMON
))
19883 v
+= maybe_add_global (TYPE_NAME (val
), crc
);
19889 /* Initialize module state. Create the hash table, determine the
19890 global trees. Create the module for current TU. */
19893 init_modules (cpp_reader
*reader
)
19895 /* PCH should not be reachable because of lang-specs, but the
19896 user could have overriden that. */
19898 fatal_error (input_location
,
19899 "C++ modules are incompatible with precompiled headers");
19901 if (cpp_get_options (reader
)->traditional
)
19902 fatal_error (input_location
,
19903 "C++ modules are incompatible with traditional preprocessing");
19905 if (flag_preprocess_only
)
19907 cpp_options
*cpp_opts
= cpp_get_options (reader
);
19909 || (cpp_opts
->deps
.style
!= DEPS_NONE
19910 && !cpp_opts
->deps
.need_preprocessor_output
))
19912 warning (0, flag_dump_macros
== 'M'
19913 ? G_("macro debug output may be incomplete with modules")
19914 : G_("module dependencies require preprocessing"));
19915 if (cpp_opts
->deps
.style
!= DEPS_NONE
)
19916 inform (input_location
, "you should use the %<-%s%> option",
19917 cpp_opts
->deps
.style
== DEPS_SYSTEM
? "MD" : "MMD");
19921 /* :: is always exported. */
19922 DECL_MODULE_EXPORT_P (global_namespace
) = true;
19924 modules_hash
= hash_table
<module_state_hash
>::create_ggc (31);
19925 vec_safe_reserve (modules
, 20);
19927 /* Create module for current TU. */
19928 module_state
*current
19929 = new (ggc_alloc
<module_state
> ()) module_state (NULL_TREE
, NULL
, false);
19931 bitmap_set_bit (current
->imports
, 0);
19932 modules
->quick_push (current
);
19934 gcc_checking_assert (!fixed_trees
);
19936 headers
= BITMAP_GGC_ALLOC ();
19939 /* Canonicalize header names. */
19940 for (unsigned ix
= 0; ix
!= note_includes
->length (); ix
++)
19942 const char *hdr
= (*note_includes
)[ix
];
19943 size_t len
= strlen (hdr
);
19945 bool system
= hdr
[0] == '<';
19946 bool user
= hdr
[0] == '"';
19947 bool delimed
= system
|| user
;
19949 if (len
<= (delimed
? 2 : 0)
19950 || (delimed
&& hdr
[len
-1] != (system
? '>' : '"')))
19951 error ("invalid header name %qs", hdr
);
19953 hdr
= canonicalize_header_name (delimed
? reader
: NULL
,
19954 0, !delimed
, hdr
, len
);
19955 char *path
= XNEWVEC (char, len
+ 1);
19956 memcpy (path
, hdr
, len
);
19959 (*note_includes
)[ix
] = path
;
19963 /* Canonicalize & mark module names. */
19964 for (unsigned ix
= 0; ix
!= note_cmis
->length (); ix
++)
19966 const char *name
= (*note_cmis
)[ix
];
19967 size_t len
= strlen (name
);
19969 bool is_system
= name
[0] == '<';
19970 bool is_user
= name
[0] == '"';
19971 bool is_pathname
= false;
19972 if (!(is_system
|| is_user
))
19973 for (unsigned ix
= len
; !is_pathname
&& ix
--;)
19974 is_pathname
= IS_DIR_SEPARATOR (name
[ix
]);
19975 if (is_system
|| is_user
|| is_pathname
)
19977 if (len
<= (is_pathname
? 0 : 2)
19978 || (!is_pathname
&& name
[len
-1] != (is_system
? '>' : '"')))
19980 error ("invalid header name %qs", name
);
19984 name
= canonicalize_header_name (is_pathname
? nullptr : reader
,
19985 0, is_pathname
, name
, len
);
19987 if (auto module
= get_module (name
))
19988 module
->inform_cmi_p
= 1;
19990 error ("invalid module name %qs", name
);
19995 /* Determine lazy handle bound. */
19997 unsigned limit
= 1000;
19999 struct rlimit rlimit
;
20000 if (!getrlimit (RLIMIT_NOFILE
, &rlimit
))
20002 lazy_hard_limit
= (rlimit
.rlim_max
< 1000000
20003 ? unsigned (rlimit
.rlim_max
) : 1000000);
20004 lazy_hard_limit
= (lazy_hard_limit
> LAZY_HEADROOM
20005 ? lazy_hard_limit
- LAZY_HEADROOM
: 0);
20006 if (rlimit
.rlim_cur
< limit
)
20007 limit
= unsigned (rlimit
.rlim_cur
);
20010 limit
= limit
> LAZY_HEADROOM
? limit
- LAZY_HEADROOM
: 1;
20012 if (unsigned parm
= param_lazy_modules
)
20014 if (parm
<= limit
|| !lazy_hard_limit
|| !try_increase_lazy (parm
))
20018 lazy_limit
= limit
;
20024 version2string (MODULE_VERSION
, ver
);
20025 dump ("Source: %s", main_input_filename
);
20026 dump ("Compiler: %s", version_string
);
20027 dump ("Modules: %s", ver
);
20028 dump ("Checking: %s",
20031 #elif ENABLE_ASSERT_CHECKING
20037 dump ("Compiled by: "
20039 "GCC %d.%d, %s", __GNUC__
, __GNUC_MINOR__
,
20040 #ifdef __OPTIMIZE__
20049 dump ("Reading: %s", MAPPED_READING
? "mmap" : "fileio");
20050 dump ("Writing: %s", MAPPED_WRITING
? "mmap" : "fileio");
20051 dump ("Lazy limit: %u", lazy_limit
);
20052 dump ("Lazy hard limit: %u", lazy_hard_limit
);
20056 /* Construct the global tree array. This is an array of unique
20057 global trees (& types). Do this now, rather than lazily, as
20058 some global trees are lazily created and we don't want that to
20059 mess with our syndrome of fixed trees. */
20061 vec_alloc (fixed_trees
, 200);
20063 dump () && dump ("+Creating globals");
20064 /* Insert the TRANSLATION_UNIT_DECL. */
20065 TREE_VISITED (DECL_CONTEXT (global_namespace
)) = true;
20066 fixed_trees
->quick_push (DECL_CONTEXT (global_namespace
));
20067 for (unsigned jx
= 0; global_tree_arys
[jx
].first
; jx
++)
20069 const tree
*ptr
= global_tree_arys
[jx
].first
;
20070 unsigned limit
= global_tree_arys
[jx
].second
;
20072 for (unsigned ix
= 0; ix
!= limit
; ix
++, ptr
++)
20074 !(ix
& 31) && dump ("") && dump ("+\t%u:%u:", jx
, ix
);
20075 unsigned v
= maybe_add_global (*ptr
, crc
);
20076 dump () && dump ("+%u", v
);
20079 global_crc
= crc32_unsigned (crc
, fixed_trees
->length ());
20080 dump ("") && dump ("Created %u unique globals, crc=%x",
20081 fixed_trees
->length (), global_crc
);
20082 for (unsigned ix
= fixed_trees
->length (); ix
--;)
20083 TREE_VISITED ((*fixed_trees
)[ix
]) = false;
20087 if (!flag_module_lazy
)
20088 /* Get the mapper now, if we're not being lazy. */
20089 get_mapper (cpp_main_loc (reader
));
20091 if (!flag_preprocess_only
)
20093 pending_table
= new pending_map_t (EXPERIMENT (1, 400));
20094 entity_map
= new entity_map_t (EXPERIMENT (1, 400));
20095 vec_safe_reserve (entity_ary
, EXPERIMENT (1, 400));
20099 note_defs
= note_defs_table_t::create_ggc (1000);
20102 if (flag_header_unit
&& cpp_get_options (reader
)->preprocessed
)
20103 begin_header_unit (reader
);
20105 /* Collect here to make sure things are tagged correctly (when
20106 aggressively GC'd). */
20110 /* If NODE is a deferred macro, load it. */
20113 load_macros (cpp_reader
*reader
, cpp_hashnode
*node
, void *)
20115 location_t main_loc
20116 = MAP_START_LOCATION (LINEMAPS_ORDINARY_MAP_AT (line_table
, 0));
20118 if (cpp_user_macro_p (node
)
20119 && !node
->value
.macro
)
20121 cpp_macro
*macro
= cpp_get_deferred_macro (reader
, node
, main_loc
);
20122 dump () && dump ("Loaded macro #%s %I",
20123 macro
? "define" : "undef", identifier (node
));
20129 /* At the end of tokenizing, we no longer need the macro tables of
20130 imports. But the user might have requested some checking. */
20133 maybe_check_all_macros (cpp_reader
*reader
)
20135 if (!warn_imported_macros
)
20138 /* Force loading of any remaining deferred macros. This will
20139 produce diagnostics if they are ill-formed. */
20140 unsigned n
= dump
.push (NULL
);
20141 cpp_forall_identifiers (reader
, load_macros
, NULL
);
20145 // State propagated from finish_module_processing to fini_modules
20147 struct module_processing_cookie
20150 module_state_config config
;
20156 module_processing_cookie (char *cmi
, char *tmp
, int fd
, int e
)
20157 : out (fd
, e
), cmi_name (cmi
), tmp_name (tmp
), crc (0), began (false)
20160 ~module_processing_cookie ()
20162 XDELETEVEC (tmp_name
);
20163 XDELETEVEC (cmi_name
);
20167 /* Write the CMI, if we're a module interface. */
20170 finish_module_processing (cpp_reader
*reader
)
20172 module_processing_cookie
*cookie
= nullptr;
20174 if (header_module_p ())
20175 module_kind
&= ~MK_EXPORTING
;
20177 if (!modules
|| !(*modules
)[0]->name
)
20179 if (flag_module_only
)
20180 warning (0, "%<-fmodule-only%> used for non-interface");
20182 else if (!flag_syntax_only
)
20187 timevar_start (TV_MODULE_EXPORT
);
20189 /* Force a valid but empty line map at the end. This simplifies
20190 the line table preparation and writing logic. */
20191 linemap_add (line_table
, LC_ENTER
, false, "", 0);
20193 /* We write to a tmpname, and then atomically rename. */
20194 char *cmi_name
= NULL
;
20195 char *tmp_name
= NULL
;
20196 module_state
*state
= (*modules
)[0];
20198 unsigned n
= dump
.push (state
);
20199 state
->announce ("creating");
20200 if (state
->filename
)
20203 cmi_name
= xstrdup (maybe_add_cmi_prefix (state
->filename
, &len
));
20204 tmp_name
= XNEWVEC (char, len
+ 3);
20205 memcpy (tmp_name
, cmi_name
, len
);
20206 strcpy (&tmp_name
[len
], "~");
20209 for (unsigned again
= 2; ; again
--)
20211 fd
= open (tmp_name
,
20212 O_RDWR
| O_CREAT
| O_TRUNC
| O_CLOEXEC
| O_BINARY
,
20213 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IWGRP
|S_IROTH
|S_IWOTH
);
20215 if (fd
>= 0 || !again
|| e
!= ENOENT
)
20217 create_dirs (tmp_name
);
20219 if (note_module_cmi_yes
|| state
->inform_cmi_p
)
20220 inform (state
->loc
, "writing CMI %qs", cmi_name
);
20221 dump () && dump ("CMI is %s", cmi_name
);
20224 cookie
= new module_processing_cookie (cmi_name
, tmp_name
, fd
, e
);
20227 warning_at (state
->loc
, 0, "not writing module %qs due to errors",
20228 state
->get_flatname ());
20229 else if (cookie
->out
.begin ())
20231 cookie
->began
= true;
20232 auto loc
= input_location
;
20233 /* So crashes finger-point the module decl. */
20234 input_location
= state
->loc
;
20235 state
->write_begin (&cookie
->out
, reader
, cookie
->config
, cookie
->crc
);
20236 input_location
= loc
;
20240 timevar_stop (TV_MODULE_EXPORT
);
20247 unsigned n
= dump
.push (NULL
);
20248 dump () && dump ("Imported %u modules", modules
->length () - 1);
20249 dump () && dump ("Containing %u clusters", available_clusters
);
20250 dump () && dump ("Loaded %u clusters (%u%%)", loaded_clusters
,
20251 (loaded_clusters
* 100 + available_clusters
/ 2) /
20252 (available_clusters
+ !available_clusters
));
20259 // Do the final emission of a module. At this point we know whether
20260 // the module static initializer is a NOP or not.
20263 late_finish_module (cpp_reader
*reader
, module_processing_cookie
*cookie
,
20264 bool init_fn_non_empty
)
20266 timevar_start (TV_MODULE_EXPORT
);
20268 module_state
*state
= (*modules
)[0];
20269 unsigned n
= dump
.push (state
);
20270 state
->announce ("finishing");
20272 cookie
->config
.active_init
= init_fn_non_empty
;
20274 state
->write_end (&cookie
->out
, reader
, cookie
->config
, cookie
->crc
);
20276 if (cookie
->out
.end () && cookie
->cmi_name
)
20278 /* Some OS's do not replace NEWNAME if it already exists.
20279 This'll have a race condition in erroneous concurrent
20281 unlink (cookie
->cmi_name
);
20282 if (rename (cookie
->tmp_name
, cookie
->cmi_name
))
20284 dump () && dump ("Rename ('%s','%s') errno=%u",
20285 cookie
->tmp_name
, cookie
->cmi_name
, errno
);
20286 cookie
->out
.set_error (errno
);
20290 if (cookie
->out
.get_error () && cookie
->began
)
20292 error_at (state
->loc
, "failed to write compiled module: %s",
20293 cookie
->out
.get_error (state
->filename
));
20294 state
->note_cmi_name ();
20299 auto *mapper
= get_mapper (cpp_main_loc (reader
));
20300 mapper
->ModuleCompiled (state
->get_flatname ());
20302 else if (cookie
->cmi_name
)
20304 /* We failed, attempt to erase all evidence we even tried. */
20305 unlink (cookie
->tmp_name
);
20306 unlink (cookie
->cmi_name
);
20311 timevar_stop (TV_MODULE_EXPORT
);
20315 fini_modules (cpp_reader
*reader
, void *cookie
, bool has_inits
)
20318 late_finish_module (reader
,
20319 static_cast<module_processing_cookie
*> (cookie
),
20322 /* We're done with the macro tables now. */
20323 vec_free (macro_exports
);
20324 vec_free (macro_imports
);
20327 /* We're now done with everything but the module names. */
20328 set_cmi_repo (NULL
);
20331 timevar_start (TV_MODULE_MAPPER
);
20332 module_client::close_module_client (0, mapper
);
20334 timevar_stop (TV_MODULE_MAPPER
);
20336 module_state_config::release ();
20343 for (unsigned ix
= modules
->length (); --ix
;)
20344 if (module_state
*state
= (*modules
)[ix
])
20347 /* No need to lookup modules anymore. */
20348 modules_hash
= NULL
;
20350 /* Or entity array. We still need the entity map to find import numbers. */
20351 vec_free (entity_ary
);
20354 /* Or remember any pending entities. */
20355 delete pending_table
;
20356 pending_table
= NULL
;
20358 /* Or any keys -- Let it go! */
20359 delete keyed_table
;
20360 keyed_table
= NULL
;
20362 /* Allow a GC, we've possibly made much data unreachable. */
20366 /* If CODE is a module option, handle it & return true. Otherwise
20367 return false. For unknown reasons I cannot get the option
20368 generation machinery to set fmodule-mapper or -fmodule-header to
20369 make a string type option variable. */
20372 handle_module_option (unsigned code
, const char *str
, int)
20374 auto hdr
= CMS_header
;
20376 switch (opt_code (code
))
20378 case OPT_fmodule_mapper_
:
20379 module_mapper_name
= str
;
20382 case OPT_fmodule_header_
:
20384 if (!strcmp (str
, "user"))
20386 else if (!strcmp (str
, "system"))
20389 error ("unknown header kind %qs", str
);
20393 case OPT_fmodule_header
:
20394 flag_header_unit
= hdr
;
20398 case OPT_flang_info_include_translate_
:
20399 vec_safe_push (note_includes
, str
);
20402 case OPT_flang_info_module_cmi_
:
20403 vec_safe_push (note_cmis
, str
);
20411 /* Set preprocessor callbacks and options for modules. */
20414 module_preprocess_options (cpp_reader
*reader
)
20416 gcc_checking_assert (!lang_hooks
.preprocess_undef
);
20419 auto *cb
= cpp_get_callbacks (reader
);
20421 cb
->translate_include
= maybe_translate_include
;
20422 cb
->user_deferred_macro
= module_state::deferred_macro
;
20423 if (flag_header_unit
)
20425 /* If the preprocessor hook is already in use, that
20426 implementation will call the undef langhook. */
20428 lang_hooks
.preprocess_undef
= module_state::undef_macro
;
20430 cb
->undef
= module_state::undef_macro
;
20432 auto *opt
= cpp_get_options (reader
);
20433 opt
->module_directives
= true;
20434 opt
->main_search
= cpp_main_search (flag_header_unit
);
20438 #include "gt-cp-module.h"