PA30 is the hosted source/header compatibility assignment. Its job is to make
cppgm preprocess and compile the hosted standard-library and vendor
extension environment needed by later bootstrap-style builds.
This milestone is intentionally distinct from the previous host-toolchain assignments:
- PA27 is about ordinary host-linkable object files.
- PA28 is about host C++ ABI/runtime correctness after host link.
- PA30 is about preprocessing, parsing, semantic analysis, and lowering compatibility for hosted source/header inputs.
To complete PA30, implement these goals:
- hosted preprocessor compatibility
- GNU/Clang parser concessions used by the selected hosted headers
- GNU builtin type and literal forms used by the selected hosted environment
- builtin traits, transforms, and intrinsics used by that hosted environment
- hosted-header/source compile compatibility for the lighter hosted workload covered by the PA30 tests, including C-wrapper headers and selected vendor/header forms
Complete PA29 before starting this assignment.
You will want to reuse:
- the full earlier language, template, and lowering stack
- the PA27/PA28
cppgm -chost-object path - the PA28 host-ABI-compatible output path
- the earlier preprocessor pipeline, now with hosted-driver controls
The GNU/Clang concessions this assignment owns include several the selected hosted headers depend on:
-
GNU anonymous structs expose their fields as members of the enclosing class; these field names remain values when distinguishing casts from calls
-
hosted GNU source may define, expand, paste and undefine
newanddeletemacros. Alternative operator names such asandremain operators, and PA1 retains its original preprocessing-token categories -
GNU
constructorandconstructor(priority)attributes retain a namespace-scopevoid()function and run it once before program entry. Priorities range from 0 through 65535, with smaller values running first; the omitted priority is 65535. Preserve the priority through ordinary LowIR function-address tables and object startup records. For host-linked Mach-O, preserve priority within each object and use the linker's order between objects. Reject conflicting priorities and unsupported function signatures. -
GNU
destructoranddestructor(priority)attributes retain a namespace-scopevoid()function for normal program termination. Larger priorities run first and the omitted priority is 65535. Preserve attributes on an earlier declaration, merge repeated declarations with the same priority, and diagnose conflicting priorities. A function can carry both attributes. -
hosted source-file comments may contain opaque legacy 8-bit bytes; line splicing, trigraphs and comment delimiters retain their usual behavior. This does not relax UTF-8 diagnostics for tokens or literals, or the strict PA1 tokenizer's input contract
-
hosted source lines may end in CRLF: a splice deletes the carriage return with the backslash and new-line, after a trigraph
??/too. PA1'snew-linestays LF alone -
parenthesized parameter declarators introduce their names normally, including array parameters; a known type name still participates in the usual function-type disambiguation
-
a quote with no partner on its line is a token of its own, so
#if 0text may saydon't. PA1 rejects one -
the
alignedattribute takes a constant expression, not only a literal, and inside a class template that expression may name the template's own parameters, so it is not knowable until instantiation; it is accepted in the[[gnu::aligned]]spelling too, and before a block-scope declaration or after a declarator it aligns the declared object -
GNU attributes before and among declaration specifiers remain attached to their declaration, including constructors, destructors and conversions
-
a hosted type specifier such as
__uint128_tor__float128spells itself as an identifier rather than a keyword, and introduces a functional cast the same way a fundamental type keyword does -
GNU
mode(identifier)selects the complete declared scalar's machine representation, including the 64-bitword,pointerandunwind_wordmodes used by the hosted unwinder; it preserves qualifiers and signedness and validates the declaration's category. Dependent declared modes retain an interned type transform until substitution; GNU ignores an unassociated dependent alias RHS's mode, while an alias-name attribute still applies. The complex modesSC,DC,XCandTCselect float, double, extended and binary128 complex representations while retaining the complex category, qualifiers and dependent transform identity -
GCC's
__constinitrequires static or thread storage and static initialization, without addingconstor requiring a literal class type; dependent definitions are checked when instantiated -
Hosted declarations also accept the plain
constinitspelling as a contextual extension with the same semantic checks. In the supported C++11--17 modes, existing names calledconstinitretain their meaning. This does not select or claim full support for C++20 or C++23. -
Clang's
__builtin_bitreverse8/16/32/64converts its argument to the corresponding unsigned integer type and reverses all of its bits. The result has that same type; the builtins work in constant expressions and are advertised through__has_builtin -
_Atomicis notvolatile: a class with an_Atomicmember is still a literal type and may have aconstexprconstructor -
__builtin_frame_address(level)takes a nonnegative constant frame level and returns avoid*to the physical activation frame. On x86-64, level zero reads a retained RBP frame even in optimized leaf functions. A nonzero level follows saved caller frame pointers and requires a valid caller chain; callers that omit frame pointers cannot be traversed reliably. Inlining uses the containing activation's frame. The query is not a C++ constant expression, and__has_builtinadvertises it through the builtin registry -
__builtin_return_address(level)reads the return address for the selected native activation. It uses the same constant level and frame chain as__builtin_frame_address. Level zero reports the continuation in the caller of the physical activation.__builtin_extract_return_addr(pointer)converts its argument tovoid*, evaluates it once and returns that address on the supported targets. -
__builtin_alloca_with_align(size, alignment)allocates stack storage with the requested alignment. Evaluatesizeonce. The alignment is a power of two in bits and must be an integral constant expression of at least eight. The allocated object is usable within the block that calls the builtin. GCC stack allocation builtins -
Accept the fortified memory and formatted-output builtins used by hosted headers. Use their typed signatures and forward the buffer size and flags to the corresponding checked libc functions.
-
Expose
__builtin_source_location()through__has_builtin. Read the four named fields of the record in the builtin contract. Honor#lineand evaluate location-sensitive immediate calls in default arguments and default member initializers at the point of use. See[support.srcloc.cons]in the C++20 draft and CWG2631. In the source location function name, a subobject pointer template argument includes the declaring class of each named field. For example,(& record.Record::counter)ends with the qualified member name. -
In C++20 hosted mode,
__builtin_coro_resume,__builtin_coro_destroy,__builtin_coro_done, and__builtin_coro_promiseoperate on a suspended coroutine handle. Use the two entry pointers at the start of the frame. A null resume entry marks completion. The promise starts after the entry pointers, rounded up to the requested constant alignment. The constant direction operand selects handle-to-promise or promise-to-handle. Resume and destroy calls participate in ordinary exception unwinding.__builtin_coro_noop()yields a handle that stays suspended and whose resume and destroy operations have no effect. See[coroutine.handle]for the library contract. C++20 draft
The tests assume a Linux shell environment with make, bash, perl, and a
working host C++ compiler with hosted C++ headers installed.
You may override the compiler with CXX=.... CPPGM_HOST_CXX selects the host
compiler used for builtin macro/include probing. If it is not set, it defaults
to CXX.
The hosted tests rely on the host compiler's target, predefined macros, standard
library include paths, and standard-library selection flags. When you use a
non-default standard library, pass the same choice through CPPGM_STDLIB_FLAGS
so the course compiler and host compiler agree.
Library traits use their declared template definitions and specializations. A familiar standard-library name does not define an incomplete primary or replace its member declarations and values.
Those answers are discovered once, when cppgm is built, and baked into
it. The compiler does not probe the host toolchain at run time to find its
include paths: a compiler that decided where the standard library lives each
time it ran would give different answers on different machines and would make
its own output depend on whatever compiler happened to be installed. A
consequence students see directly is that -stdlib= on the command line cannot
change the choice. It is checked against the selection the compiler was built
with, so it may agree, and a flag that disagrees is refused rather than
honoured -- honouring it would compile against one library's headers while
claiming another.
The course solution adds one case for its released binaries, which run on
machines other than the build machine. When the baked C++ library directory
is not there, it reads the directories of a GCC installation on that machine
(--gcc-install-dir=<dir> names one). It runs no program, and the predefined
macros stay the baked ones. Your compiler does not need this.
The starter kit provides:
- your cumulative
dev/cppgm.cppcompiler entry point - the shared implementation you built under
dev/src/ pa30/cppgm.cpp, a link to../dev/cppgm.cpppa30/Makefilepa30/scripts/, the hosted preprocessor/compile test harnesspa30/tests/preproc/, hosted preprocessor tests and referencespa30/tests/compile/, hosted compile-only tests and referencespa30/tests/lowir/, LowIR tests of hosted builtins, such as the branch predictions of__builtin_expectpa30/tests/run/, small host-link/run smokes for hosted C-wrapper headers and builtin/runtime interop
Put your code changes in dev/, especially dev/cppgm.cpp and the
shared implementation files it calls. Do not edit generated .my files. Preserve supplied test inputs.
Corrections to reference outputs follow the
reference policy.
Use cppgm-ref to inspect example output.
Tests run your implementation against the checked-in contract fixtures.
Previously required:
- the PA25 compile/link surface:
-c, default link mode,-I,-L,-l, and--target - the PA27/PA28 host-compatible behavior for the relevant compile-mode subset
New or newly required in PA30:
- hosted preprocess mode:
-E-E -Pwrites expanded preprocessing tokens as source text without line markers. Preserve token boundaries and use-o -for standard output.-E -x assembler-with-cppalso writes source text. In this mode a paste such as. ## textmay leave separate preprocessing tokens that appear adjacent in the resulting assembly.-E -dMwrites the active object-like and function-like definitions after reading the input, including command-line and header definitions. It omits computed builtins such as__LINE__. Use-as the input to read source from standard input.-E -Hreports included file paths on standard error, with one dot for each level of inclusion
- make dependency generation
-Mand-MMpreprocess and write dependency rules without compiling. The default output is standard output. Use-MF <file>to select a file.-MDand-MMDalso write a make rule during compilation. The default depfile is named for the output, with a.dsuffix.-Wp,-MD,<file>and-Wp,-MMD,<file>select the corresponding mode and dependency file together.-Mand-MDinclude system headers.-MMand-MMDomit system headers and headers reached solely through them. A system-header pragma also excludes subsequent includes from that file. The file itself keeps the status it had when it was included.-MT <target>supplies a make target as written.-MQ <target>quotes make-special characters.-MPadds an empty rule for each header so a removed header does not break an older dependency file.- The active include search determines the rule's physical source paths, including forced headers. When reading from standard input, list the headers and omit the standard input stream from the prerequisites. Preprocessing should run once in each route.
- hosted preprocessor-control flags:
-D <macro>and-D<macro>-U <macro>and-U<macro>-include <file>-isystem <dir>and-isystem<dir>
-nostdinc++removes the default C++ library directories. Keep the compiler and platform C headers and all explicit include directories.-nostdincremoves both sets of default directories.__GNUG__matches__GNUC__on the GNU C++ target profiles. Advertise supported C++11 features through the SD-6 macros. Exception and RTTI macros follow-fno-exceptionsand-fno-rtti. In hosted mode,__FLT_EVAL_METHOD__describes the target's evaluation precision.- source views (
--emit-ast,--emit-types,--emit-semantics, and--emit-lowir) honor the same-include,-nostdinc, and-nostdinc++controls as object compilation. Forced headers are read in order after all-Dand-Uoptions, even when those options follow-includeon the command line - direct driver query forms:
--version-v-dumpmachine-dumpversion-print-search-dirs
- compatibility handling for common build-system flags that should either be honored or harmlessly accepted when they do not affect the tested output
-mno-red-zonedisables use of the x86-64 SysV red zone for local storage;-mred-zoneenables it, and the last of these options wins-ffunction-sectionsgives each function of an ELF object a.textsection of its own, so the linker can discard a function that nothing refers to (--gc-sections);-fno-function-sectionsrestores the shared section, and the last of these options wins
PA30 continues extending the same cppgm frontend used in PA25–PA29.
Required preprocess forms:
cppgm -E -o <outfile> <srcfile>
cppgm -E <srcfile1> <srcfile2> ...
cppgm -E -D <macro> -U <macro> -include <file> -isystem <dir> <srcfile>Required compile forms:
cppgm -c -o <objfile> <srcfile>
cppgm -c <srcfile1> <srcfile2> ...
cppgm -c -D <macro> -U <macro> -include <file> -isystem <dir> -o <objfile> <srcfile>Query flags are required only as direct driver queries. For example:
cppgm --version
cppgm -dumpmachine
cppgm -print-search-dirscppgm -E shall write the same structured posttoken/preprocessor stream
format used by the PA4 preproc frontend. When -o <outfile> is present, that
stream is written to <outfile>.
cppgm -c shall continue to write host-linker-compatible relocatable object
files as in PA27/PA28.
The new PA30 requirement is not a new object format. It is the ability to
preprocess and compile hosted source/header inputs successfully through the
cppgm path.
Hosted compatibility should use the same source-to-LowIR-to-object pipeline as
ordinary compilation. Hosted include search, predefined macros, and builtin
probes can affect the source program being compiled, but --emit-lowir should
remain representative of the LowIR that object emission consumes: the object
cppgm -c writes must be the object the serialized LowIR produces (PA33's
object round trip checks it), so the facts hosted code needs in the backend
are LowIR facts; how they travel in memory is yours.
If preprocessing, parsing, semantic analysis, lowering, object emission, or
output writing fails, cppgm shall exit with failure.
For compile-only tests, exact diagnostics are not the grading contract. The harness compares exit status and any checked output sidecars. If the reference run fails, stdout and stderr are diagnostic side effects rather than required output.
Run the PA30 suite with:
make testTo run one test through the shared check target:
make check TEST=tests/preproc/300-has-include.t
make check TEST=tests/compile/600-builtin-transforms-and-traits.t
make check TEST=tests/lowir/500-builtin-expect-predictions.t
make check TEST=tests/run/800-hosted-cmath-ceil-run.tPA30 has four test directories:
tests/preproc/: hosted preprocessor compatibility. The oracle is the PA4-style structured preprocessor stream plus exit status.tests/compile/: hosted compile-only compatibility. The oracle is successful object emission, compile exit status, and any stdout/reference sidecars used by the harness.tests/lowir/: the LowIR thatcppgm --emit-lowir -O0writes for hosted builtins, such as the branch predictions of__builtin_expectand the order branches of atomic stores and fences. The oracle is the relaxed LowIR comparison of the source-to-LowIR assignments (../pa8/lowir.md, What The Comparison Absorbs And What It Enforces).tests/run/: narrow host-link/run compatibility smokes. These tests cover hosted builtins, C library entry points, and lightweight hosted C-wrapper headers such as<cassert>,<cmath>,<cstdarg>,<cstddef>,<cstdio>,<cstdlib>,<cstring>, and<csignal>. They do not require broad template-heavy C++ standard-library headers or general hosted header-generated runtime support.
The checked-in tests are hosted/vendor compatibility cases, standard-library sentinels, reducers, and bootstrap-facing compile smokes rather than direct N3485 clause tests.
Optional sidecars include:
x.env: environment variables for one test, such as additional standard include pathsx.no-exceptions: compile atests/compileinput with-fno-exceptionsx.cxx-standard: select the required language mode belowx.flags: additional compiler flags fortests/runor for atests/compileinput with a language mode sidecarx.ref.impl.exit_status,x.ref.program.exit_status, andx.ref.program.stdout: implementation and program-result references fortests/runhost-link/run smokes
The default preprocessor references are intentionally host-agnostic. The test harness checks that checked-in PA30 preprocessor refs do not accidentally pin local host macro values such as platform-specific integer or floating-point limits.
In GNU C++ modes, q and Q floating suffixes denote __float128 in
compilation and in the typed cppgm -E stream. Emit binary128 bytes for
these literals. ISO C++ modes leave those suffixes to the ordinary
user-defined literal rules. The standard l and L suffixes denote
long double. GCC floating-type extensions
If the host probe defines __SIZEOF_FLOAT128__ for the native target, preserve
it in the hosted environment. Libraries use it to discover the GNU
__float128 type even in ISO C++ mode, where the GNU literal suffixes are
disabled.
Support GNU __builtin_classify_type with both a type-name and an
expression. Report the type-name's category directly and adjust array and
function expressions to pointers. A single expression has no effects during
ordinary execution. In C++ constant evaluation, check the expression as
required by the GNU builtin. The legacy form with several expression
arguments evaluates each for effects and reports the category of the first.
GCC builtin reference
Honor Clang's overloadable attribute on a function with C language
linkage. Give that function an Itanium signature-specific symbol, while
an unmarked function in the same overload set keeps its C name.
Clang overloadable declarations
Support -fconstexpr-ops-limit=<n> when compiling hosted C++. It sets the
work limit for one constant evaluation. Use a finite default and reset the
work counter between evaluations. A required evaluation that exceeds the
selected limit must issue a diagnostic.
GCC dialect options
In constant expressions, support the GNU builtins __builtin_fmaf,
__builtin_fma, and __builtin_fmal for finite operands. Evaluate the
product and sum with one rounding to the result type. An overflow or an
inexact underflow cannot produce a constant expression.
Fold __builtin_strcmp and __builtin_strncmp when both strings and any
length argument are literals. Compare unsigned bytes through the first
terminator or the length bound. A folded result supplies the sign of the
comparison and needs no library call.
Support __builtin_sinf, __builtin_sin, and __builtin_sinl in constant
expressions for finite operands. Compute the sine in the target floating-point
format when the host math library supplies the needed precision. Preserve a
signed zero. Infinite and NaN operands require a diagnostic in a required
constant expression. Apply the same evaluation to the C-linkage sine
declarations from system math headers, including declarations imported into
std by <cmath>. Preserve user definitions and other signatures.
Constant evaluation of binary128 values must use their target precision and range, including arithmetic, comparisons, casts and static initialization. Preserve signed zero, subnormals and the bits of supported NaN builtins; diagnose constant arithmetic overflow and out-of-range integer conversions. List-initialization applies the same representability rules as other arithmetic types, including integer constants wider than 64 bits.
Support __builtin_signbitf and __builtin_signbitl for hosted headers
that use the GNU floating-point builtins. Convert the argument once to
float or long double, respectively. Return a nonzero int if the sign
bit is set, including for negative zero and negative NaNs. Advertise the
typed builtins through __has_builtin.
Runtime checks that require libgcc's binary128 or bfloat16 helpers run on
Linux; the Darwin runtime does not supply those interfaces. Binary16 checks
run on both hosts. Calls to conversion helpers must follow the target runtime's
ABI, which can differ from the calling convention of an ordinary _Float16
function.
Hosted -Wno-narrowing suppresses list-initialization narrowing diagnostics,
as described in GCC's C++ dialect options.
The actual scalar conversions still occur, and narrowing remains a failure in
SFINAE contexts. -Wnarrowing or -Werror=narrowing restores the diagnostic;
the last of these specific options wins. Without suppression, the compiler
continues to reject narrowing conversions.
The language profile is taught and tested in the
owning earlier assignments. Hosted headers consume those same type, deduction,
constant-evaluation and closure rules. A language-only reducer belongs in its
earlier lesson; host include/builtin/ABI consumers stay here or in PA32.
The supplied .cxx-standard sidecars select required modes in normal tests.
An edition extension such as if constexpr, conditional explicit(bool) or __VA_OPT__
can appear in a system header under an earlier mode. Preserve the translation
unit's edition and feature macros when suppressing its extension diagnostic.
System status follows -isystem, nested includes from system headers, and
#pragma GCC system_header or #pragma clang system_header from the pragma
onward. -Wsystem-headers restores the default diagnostics for these locations.
Honor scoped diagnostic push, diagnostic ignored, and diagnostic pop
for the edition warning groups, including through _Pragma. Use
-pedantic-errors to require rejection for active extension diagnostics.
Ordinary language errors still diagnose inside a suppressed scope.
A constexpr try statement or function-try-block follows the C++20
extension group in C++14 and C++17. Evaluate an admitted protected block
using the PA21 constant-expression rules.
In C++20 mode, expose __cpp_concepts. PA31 exercises the hosted <concepts>
declarations through the course's constraint and overload rules.
PA30 is mostly about accepting hosted headers, but compile-only hosted tests can
still expose symbol-spelling problems through emitted objects and unresolved
references. The cppgm -c path should continue producing host ABI names that
PA27 and PA28 already made observable.
A recommended implementation style is to keep the PA9 mangler in the compile-mode path while adding hosted parser, semantic, builtin, and lowering support. That style works best when hosted standard-library entities, inline namespaces, ABI-tagged declarations, dependent template names, local entities, and function template specializations keep the semantic information needed to name them.
For compile-only tests, the immediate oracle may be successful object emission, but the object must carry host ABI names that PA32 can link and run without a separate hosted-only naming scheme.
To complete PA30, implement hosted compatibility for:
- GNU
__PRETTY_FUNCTION__names the specialization in a function template. Evaluate constant expressions that read the string with the specialization's arguments, including when the result determines an array bound. A C++20 argument that designates a named member includes the member's name in the string. -E -Cretains active-source comments in preprocessed text. Comments in directives and skipped groups remain absent. Use the retained comments as tokens when determining whether a directive or a function-like macro starts.- predefined macro import,
__COUNTER__, the GNU comma paste,_Pragma, and__BASE_FILE__. The latter expands to the primary input file name from both the primary file and its includes, regardless of#line.__has_*,#include_next,#warning, ignored unknown pragmas, and hosted hex-float preprocessing forms such as0x1p+4. Hosted preprocessing also executes conditional and macro-definition directives encountered while collecting a function-like macro's arguments, as GNU CPP does. A redefinition affects argument prescan, while the open call retains its original replacement list;__COUNTER__remains one sequence per translation unit. A system header may replace a macro's previous definition, as GNU CPP does with system-header redefinition diagnostics suppressed; ordinary source redefinitions still require identical definitions. Hosted rescanning follows GNU CPP's active replacement contexts: a macro stays disabled while its replacement is read, and tokens rejected for that reason remain unavailable on later rescans. PA4's non-hosted interface retains the course-defined nesting rules in PA4's macro guide. PA4's non-hosted text-sequence boundaries are unchanged.#warninglets translation continue, like an ignored pragma; anything it prints goes to standard error, which the tests do not check.__COUNTER__expands to0at its first use in a translation unit and to one more at each later use. In a variadic macro's replacement list, the GNU form, ## __VA_ARGS__removes the comma when the variable arguments are empty as written; otherwise the comma stays and the arguments follow it, pasting nothing. A probe answers for its whole family or not at all: a name the preprocessor treats as defined but does not substitute leaves the header's own fallback macro unused and the probe call sitting in the controlling expression.__has_cpp_attributetakes an attribute-token, which N4868 15.2/2 spells as an identifier or a scopedidentifier :: identifier, and__has_warningtakes a string literal; the rest take a single identifier.__has_cpp_attributeanswers nonzero only for an attribute the compiler implements, here the standardno_unique_address, also spelled__no_unique_address__, and0for any other name, scoped ones included;__has_attributelikewise answers nonzero for the GNU and Clang attributes the compiler implements (always_inline,noinline,noreturn,deprecated,pure,const,used,weak,alias,packed,aligned,section,vector_size,mode,gnu_inline,abi_tag,may_alias,using_if_existsandexclude_from_explicit_instantiation, each also spelled__name__) and0for any other. GNUalignedon a bit-field may follow its width. Preserve the field's placement and its contribution to the record alignment, including when the alignment depends on a template argument. Keep reads and writes of a packed union bit-field within its storage. An enumeration markedpackedwithout a fixed base uses the smallest integer type that can represent its members. Use a signed type if a member is negative and an unsigned type otherwise. Directories added with-iquoteare searched for quoted includes after the including file's directory and before-I. Angle-bracket lookups start at the ordinary include chain.#include_nextcontinues from the directory that found the current header. PA37 adds the Wasm-specific import/export binding attributes and probes; native profiles continue to report no support for those target attributes. GNUalias("object-name")declares another name for a function or global defined in the same translation unit. Preserve its address and independent strong or weak binding. Resolve the literal as an ABI object name, including mangled C++ names and asm labels; reject cycles, undefined targets and separate definitions of the alias. A function alias uses its target's actual calling ABI even when its declaration has another prototype; calling through it requires a compatible function pointer type. This hosted extension is supported for ELF and PA37's Wasm objects; Mach-O rejects it. GNUdeprecated/__deprecated__is recognized with no argument, an empty argument list, or one string-literal message (also as agnu::attribute). It does not change program behavior, type, or ABI. Deprecation warning emission is optional and is not implemented by this course tool; an invalid message type or more than one argument is still rejected. A conditional whose condition is__builtin_constant_p, optionally parenthesized or explicitly converted, permits folding reference reinterpretations in its selected expression. The reference retains the original storage identity: an unrelated view cannot read that storage. Called function bodies use their own constant-expression rules; ordinary conditionals and the non-hosted query keep their existing rules.__has_builtinanswers from the registries that hold the builtins rather than from a list beside them: claiming not to have one that is implemented is worse than lacking it, because the header then takes a fallback written in later-standard machinery that has to be supported instead of the builtin already there. Probes for guarantees the compiler does not make, such as__has_declspec_attribute, answer no rather than failing - GNU
always_inlinedirect calls in host objects substitute the available body at every optimization level, including constructors and destructors. An assembly operand that needs a constant or symbol address can use a parameter if substitution provides a valid operand for its constraint, including through a chain ofalways_inlinecalls. Discard private copies used only for substitution after their direct calls are expanded. A defaulted member of a class template still follows the rules for the location of its original= default. Instantiating a call preserves the special-member semantics of an in-class default. A bounded constant stack request outside every control-flow cycle can use fixed local storage before substitution. Preserve distinct allocations in loops; a dynamic request still needs its own stack lifetime. Determine recursion from reachable calls after constant branch cleanup; an unreachable self call must not block substitution. Substitution preserves cleanup, noexcept termination, local-static identity and source locations. An ineligible required call is diagnosed. The course LowIR view and its optionalforce_inlineprofitability flag retain their existing contract; the object LowIR view includes source-required substitution. - GNU/Clang parser concessions commonly exercised by the selected hosted
headers, including dependent nested-angle disambiguation, nested qualified
template-ids used as outer template arguments, builtin-trait identifiers
referenced as ordinary names, GNU
__decltype, parenthesized throw-expressions emitted by hosted helper macros, and GNU builtin float type specifiers such as__float128/_Float128, plus GNU complex component operators__real__and__imag__, and the C++20 conditional explicit-specifierexplicit(constant-expression), which both host compilers accept in C++11 mode as an extension and libc++ writes unconditionally outside its C++03 branch. Its condition decides whether the constructor takes part in copy initialization, so a parse that accepts the form and discards the condition silently mis-ranks overloads. Attributes interleave with the specifiers around it rather than preceding them all - hosted assembly consumers use the shared assembly boundary from PA29. Preserve the user instructions, declared operands/effects and module ordering; do not replace selected strings with arithmetic or runtime-query operations
- builtin traits, transforms, intrinsics, and builtin families used during
hosted compile acceptance, including lowering
__builtin_abortas a non-returning call to the host C runtime; fixed-arity hosted integer intrinsics reject calls with the wrong number of operands. This includes the type-shape traits a hosted library may spell directly rather than derive from partial specializations:__is_const,__is_volatile,__is_void,__is_array,__is_bounded_array,__is_unbounded_array,__is_lvalue_reference,__is_rvalue_reference,__is_object,__is_arithmetic,__is_fundamental,__is_compound,__is_referenceableand__is_unsigned. Note that cv-qualification belongs to the type, so__is_constis false for a reference to const however it was written.__is_base_ofrelates two class types, so it is false when either operand is a reference even though the reference names a class; a hosted library turns on that answer to remove an rvalue-stream overload when the stream deduces to an lvalue reference. It also includes the libm intrinsic family a hosted<cmath>forwards to, in itsfloat/double/long doublespellings. Most take their own result type in every operand, so the arity is the whole signature; the rest name their own shape, reading an exponent back through a pointer (frexp), taking one in (ldexp,scalbn,scalbln), writing a whole part (modf), writing a quotient (remquo), taking along doublesecond operand (nexttoward), or returning an integral type rather than the operand's (ilogb,lrint,lround,llrint,llround). They lower to a call to the C function of the same name, except__builtin_fabsfand__builtin_fabs, which clear only the sign bit inline, preserving NaN payloads and evaluating the converted argument once.__builtin_fabslretains the C-library call. Report the active native rounding mode from__builtin_flt_rounds(). Its result is 0 for toward zero, 1 for nearest, 2 for upward, and 3 for downward. A builtin is a global-namespace name, so::__builtin_xnames the same one as__builtin_x, which is how a hosted library keeps a user's macro from intercepting the call; any deeper qualification names something else. It also includes the variadic builtins<cstdarg>expands to: beside__builtin_va_startand__builtin_va_arg, which lower to theva_startandva_argof../pa8/lowir.md,__builtin_va_copycopies the argument-list object and__builtin_va_enddoes nothing.__builtin_expect(e, c)is the value ofeconverted tolong. A conditional branch that tests the call,can integer, character or boolean literal, is predicted:branch likelywhencis nonzero,branch unlikelywhen it is zero. That is a branch on the call as anif,while,forordocondition, as an operand of&&or||(in a condition or as a value) or as the condition of?:, also when the condition's temporaries are destroyed on each edge. No other branch is predicted: not a branch insidee(__builtin_expect(a && b, 1)predicts only the branch on the call), not one on!__builtin_expect(e, c)or on a variable a condition declares, and not one whosecis no literal. What an expectation implies for other branches is the optimizer's to derive. A prediction is advisory (../pa8/lowir.md, Terminators): an incorrect one must not change behavior.tests/lowir/checks the rule.__builtin_unreachable()lowers tounreachable, as in PA11.__builtin_assumeis not required; without it__has_builtin(__builtin_assume)answers 0 and a header takes its fallback - hosted compiler intrinsics lowered directly to typed LowIR operations do not
unwind; an explicit
noexceptwrapper containing only such operations shall not acquire a terminate landing - a force-inline function that does not return ends its caller's block: nothing follows the call, so there is no continuation to split off. Inlining it must still place the callee's body, and the block the callee's returns would have landed in is simply not reachable. A hosted library declares its throw helpers this way, so refusing the shape rejects the header
- semantic and lowering compatibility for hosted source patterns used by those
headers, including post-declarator parameter
attributes, explicit specializations of primary-template member functions,
placeholder-return declarations without a body, such as a deleted overload
declared
autoin C++14 or later, the default GNU C++11 course return-deduction extension from PA20, and GNU hexadecimal floating literals on ordinary floating types, and[[no_unique_address]]empty-member layout through generated copy operations - the standard
[[noreturn]]attribute takes no argument and appertains only to the declarator-id of a function declaration (7.6.3p1): a variable, including a block-scope one, a data member, a parameter, a typedef or alias-declaration, a class or enumeration head, a statement, and the position after a parameter list (where it would appertain to the function type) are rejected. Leading attributes of a block item appertain to the declaration it introduces - a function declared
[[noreturn]]or GNUnoreturnon any declaration statesreturn=noreturnon its declarations and definition and on the call signature of a virtual call (../pa8/lowir.md, "Facts The C++ Lowering States"; a direct call has no signature to carry it), and so do a function template's specializations, while an explicit specialization keeps only its own declarations'; a call through a pointer states none, and a call of such a function does not end its block. PA33's-O0driver lane compares the fact - default visibility for unannotated imports whose GNU inline body is
available only for inlining, even when the compilation uses
-fvisibility=hiddenor-fvisibility-inlines-hidden. - semantic validation of primary-source GNU inline function bodies even when emission is deferred; an unimplemented reserved compiler builtin may defer its wrapper, but ordinary lookup and type errors in an unused wrapper must still be diagnosed
- typed retention of a scalar GNU
vector_sizetypedef's byte width for compile-time layout queries and semantic validation of unused inline wrapper literals; runtime vector operations and vector-expression lowering are not required - lightweight hosted C-wrapper header and C runtime interop smokes where the
header surface is mostly builtin macros/functions or ordinary C declarations
(
<cassert>,<cmath>,<cstdarg>,<cstddef>,<cstdio>,<cstdlib>,<cstring>,<csignal>)
If a failing PA30 test exposes a bug in syntax, semantic analysis, template handling, lowering, or object emission that is shared with earlier language features, fix the shared compiler behavior rather than adding a PA30-only path.
The PA30 tests do not require:
- host object/link/runtime behavior beyond the PA27/PA28 host-compatible path
- compiling broad template-heavy C++ standard-library headers such as
<vector>,<tuple>,<functional>,<iostream>,<string>, or container and stream headers - general hosted C++ header-emitted link/runtime behavior
- full build-system emulation beyond the documented query and compatibility flags
- recursive hosted-header coverage reporting
- bootstrap or self-host builds
On x86-64 with POPCNT, -mpopcnt enables population-count lowering and
defines __POPCNT__; -mno-popcnt restores the portable default. The last
option wins, and explicit -D/-U macro overrides still apply. Run
make test-target-features to check this optional extension, including zero,
operand widths and evaluating an argument once. It is separate from the
required C++11 report and does not prescribe an instruction sequence.
The GNU __builtin_ia32_punpck*128 family interleaves the low or high
half of two 128-bit vectors with 8-, 16-, 32-, or 64-bit lanes. Preserve
all lane bits and evaluate each operand once. The provided-builtin registry
reports the implemented family, and semantic facts retain the selected half
and lane type for the existing vector lowering path.
The GNU SSE2 psll*, psrl* and psra* immediate-form builtins shift
16-, 32- and 64-bit lanes (arithmetic right for 16 and 32 bits). Their int
count may be a runtime value. Oversized and negative counts yield zero for
left/logical right and sign-fill for arithmetic right. Evaluate both operands
once and bound the count before forming a LowIR shift.
__builtin_ia32_pshufd selects four 32-bit lanes using the low 8 bits of a constant int;
__builtin_ia32_shufpd selects one double lane from each of two sources using
the low 2 bits of a constant int. GCC masks constant selectors to those
widths, including negative values. Preserve every lane bit, including NaN payloads and signed
zero, and evaluate operands once. Record selector/type facts during analysis;
a selector in an always-inline wrapper or template can remain deferred.
__builtin_ia32_shufps selects two float lanes from each of two sources
using an 8-bit immediate, preserving all payload bits.
__builtin_ia32_pshuflw and __builtin_ia32_pshufhw select four 16-bit
lanes within the low or high 64-bit half using an 8-bit immediate. Preserve
the other four lanes bit for bit, and retain the same single-evaluation and
deferred-selector rules.
After mandatory inlining substitutes a wrapper call, a deferred shuffle selector must be constant. A runtime selector through the public intrinsic wrapper remains an error. This check uses typed LowIR facts and leaves ordinary generated code and named debug storage unchanged.
Vector construction and wrapper substitution should retain whole-vector facts. Preserve lane bits and evaluation order when building narrow integer vectors; constant selectors exposed by required inlining can select native operations without first expanding into per-lane memory work. A still-variable selector must keep the operation's specified runtime behavior or diagnostic. No exact instruction sequence is required.
__builtin_ia32_pmovmskb128, __builtin_ia32_movmskps and
__builtin_ia32_movmskpd collect the sign bits of 16 byte, 4 float or
2 double lanes into the low bits of an int. Read floating representations
as integer bits, preserving signed zero and NaN signs without floating
exceptions. Evaluate the input once and leave unused result bits zero.
A memory order of the __atomic and __c11_atomic builtins that is not a
constant is seq_cst, as GCC takes it, except at an inline store or thread fence
(__atomic_store_n, __atomic_store, __atomic_clear,
__atomic_thread_fence, __c11_atomic_store and
__c11_atomic_thread_fence). There the lowering branches on cmp ult of
the order and 5 to two copies of the operation: below 5 the store is
release and the fence acq_rel, otherwise both are seq_cst. An inlined
caller's constant order, such as one a std::atomic member passes on, then
decides the branch. tests/lowir/ checks the rule.
The pointer-based __atomic_load, __atomic_store, __atomic_exchange and
__atomic_compare_exchange support complete objects beyond the inline
1-, 2-, 4- and 8-byte forms. Record this requirement in the existing typed
call facts and use the generic runtime ABI in host object mode: prepend
the object byte size; pass pointers and integer memory orders; omit the
compare-exchange weak parameter while evaluating its expression once.
Keep const-destination and operand-size checks. Clang's by-value
__c11_atomic_load, __c11_atomic_store, __c11_atomic_exchange and
compare-exchange forms also support complete objects. Only the atomic
object has the size and alignment of _Atomic(T). Read desired values and
write results using the ordinary size of T. When these sizes differ,
initialize the added padding in the atomic representation and copy the
observed ordinary value to the caller's expected object only when
compare-exchange fails. Use an inline operation where the atomic storage
width allows it. The generic runtime receives the atomic storage width
and needs a compatible provider such as Linux's libatomic, supplied by
the host link command. The modern GNU scalar builtins and Clang's
arithmetic builtins also accept 128-bit integers. Use the same runtime
protocol for their loads, stores, exchange, and compare-exchange.
For arithmetic, evaluate the operands once and use a compare-exchange
loop with the requested success order. The failure order drops any
release component. Integer arithmetic wraps at the object's width,
and the builtin spelling selects the old or new value.
The weak argument's value does not change the runtime ABI. cppgm preserves its expression's side effects once, as Clang does; GCC 15 discards that expression in the generic form. The required evaluation control records this host-oracle difference separately from the common ABI protocol.
__atomic_always_lock_free takes a constant size and reports the
target's inline instruction support. Use natural alignment for a
null pointer argument. An ordinary __atomic_is_lock_free query can
take a runtime size and address. Keep a constant result for a proven
inline case. For dynamic cases on Linux, retain the size and address
and call the runtime's bool __atomic_is_lock_free(size_t, const void *).
The size-only __c11_atomic_is_lock_free query uses a null address in
that ABI. Evaluate runtime operands once.
__builtin_shuffle(vector, mask) and __builtin_shuffle(first, second, mask)
permute lanes of one or two matching vectors. The integral mask has the
same width and lane count. Mask lanes select modulo N or 2N, including
negative and runtime values; the second input follows the first in memory
lane order. Preserve all lane bits, including floating NaNs and signed zero,
and evaluate each operand once. Use typed vector/mask facts and linear lane
lowering. The existing limit of 64 lanes also applies here.
The GCC/Clang __builtin_shufflevector(first, second, index...) form uses
constant indexes into two matching inputs. Its result has one lane per
index. With one index per lane it has the inputs' type; otherwise it is a
vector of the inputs' kind, GNU or Clang extended, so a shuffle of shuffles
can widen a vector. An index of -1 leaves that lane unspecified; choosing
zero is valid. Validate and retain these constants in typed facts. Both
public GCC and Clang SSE wrappers can then use the same permutation lowering.
__builtin_nondeterministic_value(x) returns an unspecified value of x's
type, which is a fundamental or vector type, and does not evaluate x.
Clang's headers pass it to a shuffle to widen a vector; any value, such as
zero, is valid.
An explicit arithmetic scalar cast to a Clang ext_vector_type converts to the
lane type and broadcasts the result to every lane. Evaluate the scalar once.
Keep this distinct from GNU vector_size casts, which reinterpret equal-sized
representations. Preserve the vector kind through template substitution.
A single same-type vector operand in braces initializes the whole vector, including in a member initializer and constant initialization. Distinguish this from a scalar lane list: preserve every lane, evaluate the operand once, and retain volatile reads. A vector of a different size cannot initialize a lane implicitly.
__builtin_ia32_pclmulqdq128 selects a 64-bit lane from each 128-bit input
using immediate bits 0 and 4 and returns their 128-bit carryless polynomial
product. __builtin_ia32_permti256 independently selects each 128-bit half
of a 256-bit result: each selector nibble chooses one of four source halves;
its bit 3 zeros the result half and bit 2 is ignored. Preserve operand bits
and evaluate inputs once. Selectors are immediate bytes; Clang's public
carryless-multiply macro passes that byte as char. A deferred selector in a
template or always-inline wrapper must become constant after substitution.
Use typed operation facts; wider vector objects retain their existing ABI.
__builtin_ia32_packuswb128 clamps signed 16-bit lanes to [0,255], then
packs them into bytes. __builtin_ia32_packsswb128 clamps to [-128,127];
__builtin_ia32_packssdw128 clamps signed 32-bit lanes to [-32768,32767]
and packs them into words. The SSE4.1 __builtin_ia32_packusdw128 clamps
signed 32-bit lanes to [0,65535] before packing them into unsigned words.
The first input fills the low half of the
128-bit result and the second fills the high half. Evaluate both once.
Use the recorded input/output lane types and signed comparisons before
narrowing; truncating first loses the saturation behavior.
__builtin_ia32_pandn128 takes two vectors of two signed 64-bit lanes and
returns the bitwise complement of the first input masked by the second.
Preserve all 128 bits and evaluate each operand once. The public
_mm_andnot_si128 wrapper has the same behavior.
__builtin_ia32_pmaxub128 chooses the unsigned maximum in each of sixteen
byte lanes. It shares the byte-minimum signature and typed lane lowering;
evaluate both operands once and compare byte bits as unsigned regardless
of the vector element type's signedness.
A GNU vector of 16 bytes is a LowIR v128 value, and an SSE builtin with an SSE
instruction is a LowIR vector instruction. This applies at every optimization
level. lowir.md defines v128, vector, the
list of operations and the call boundary. Extend the LowIR reader, writer and
validator and lowir2native to match. Each operation encodes as its legacy SSE
form. A vector of another size, a vector of bool lanes and an operation with no
vector form stay lane by lane, except that the
AVX2 and AVX-512 builtins may compute
128-bit pieces with vector operations.
Unsigned 32-bit lanes have the same packed bit representation as signed lanes.
Preserve those bits during construction, scalar broadcasts and constant-index
extraction, including values above INT_MAX. Keep scalar evaluation order and
volatile reads. On later targets, choose direct packed operations using the
selected target's capabilities: the native SSE2 baseline does not limit a
target that provides packed 32-bit multiplication. Equivalent lane lowering
remains valid when the target has no suitable operation.
GCC's and Clang's AVX2, AVX-512F, AVX-512BW and AVX-512VBMI2 headers use
these __builtin_ia32_ builtins on 32- and 64-byte GNU vectors. Each returns
its instruction's result:
- byte and word lanes:
paddusb256,psubusb256,pmaxsb256,pmaxub256,pminsb256,pminub256,pshufb256andpshufb512, the 512-bit_maskforms of these andpabsb512_mask, andpsllwiandpsrlwiof both widths with_maskforms; andnotsi256andpandnd512_mask, the complement of the first operand ANDed with the second;ptestz256, 1 when the operands' AND is zero;- masks, one bit per lane with lane i at bit i:
pmovmskb256andcvtb2mask512collect sign bits;pcmpeqb512_mask,pcmpgtb512_mask,ptestmb512andcmpb512_maskcompare signed bytes and AND the result with their last operand.cmpb512_mask's predicates 0 to 7 are equal, less, less or equal, false, not equal, not less, greater and true; blendmb_512_mask(a, b, m)takesb's lane wherem's bit is set, elsea's;selectb_512(m, a, b)takesa's lane where it is set, elseb's;compressqi512_mask(a, passthrough, m)packs the lanes ofawhose mask bits are set into the low lanes in order, and the other lanes are the passthrough's;compressstoreqi512_maskandcompressstoreuqi512_maskstore only the packed bytes, at any alignment;loaddquqi512_mask(address, passthrough, m)reads bytes at their original offsets where the corresponding mask bits are set and keeps the passthrough's other lanes. The address may be unaligned. A masked-off lane must never read memory, including when the access would cross into an inaccessible page or the mask is zero;vpermt2varq512_mask(index, a, b, m)andvpermi2varq512(a, index, b)select each lane froma's eight lanes followed byb's by the index lane's low four bits; wherem's bit is clear, the lane isa's;vextractf128_si256,extracti32x4_mask,vinsertf128_si256andpmovzxbd512_maskmove or widen 128-bit pieces;si_si256is the low piece andsi256_siplaces one, its other lanes unspecified;palignr256andpalignr512: GCC's count is in bits on 64-bit lanes and Clang's in bytes on byte lanes, as forpalignr128.
pshufb, palignr and the shifts work within each 128-bit piece. The
512-bit _mask lane forms, pandnd512_mask, pmovzxbd512_mask and
extracti32x4_mask end with a passthrough vector and a mask: a lane whose
mask bit is clear takes the passthrough lane. Selectors and predicates are
constant after substitution. Evaluate each operand once. Compute the results
with 128-bit operations, so programs run without AVX.
__builtin_ia32_lzcnt_u16, _u32 and _u64 count leading zero bits and
__builtin_ia32_tzcnt_u16, _u32 and _u64 trailing zero bits. The result
has the operand type of the builtin's width, and a zero operand gives that
width. The operand converts to that type and is evaluated once.
The _addcarry_u32, _addcarry_u64, _subborrow_u32 and _subborrow_u64
header functions use builtins with an unsigned byte input flag, two unsigned
operands of the indicated width and a pointer to an output of that width.
A nonzero input flag supplies one more unit to add or subtract. Evaluate
each argument once, store the wrapped result and return an unsigned byte
equal to zero or one according to whether the operation carried or borrowed.
Accept GCC's sbb and Clang's subborrow builtin spellings.
The signed and unsigned forms of the overflow-checking builtins use the
integer type selected by their names. For example, both operands of
__builtin_uaddll_overflow convert to unsigned long long, and its third
argument points to that type. Apply the argument conversions before
computing the exact result. Store the result converted to the destination
type and return whether the conversion changed its value.
GCC integer overflow builtins
Hosted compatibility is easiest to approach as a sequence of small compatibility surfaces: preprocessor probes, parser concessions, builtin traits/types, and then semantic/lowering cases. Keep fixes tied to the source pattern being exercised. Avoid making broad source-text special cases when an earlier semantic or template representation can carry the information directly.
The typed intrinsic kind can also serve exception-boundary analysis directly. Keeping that fact on the semantic call avoids treating a lowered atomic, vector, or compiler operation as an unknown indirect call.
That same preference applies to hosted ABI names: keep type structure, template arguments, ABI tags, and local context available until the ABI naming layer can consume them. Reconstructing those facts later from pretty-printed strings tends to create fragile library-version-specific behavior.
Later hosted tests keep the same hosted source/header environment while adding larger template-heavy standard-library headers and then link/run behavior for code emitted from hosted headers.
Clang's __builtin_ia32_pslldqi128_byteshift and
__builtin_ia32_psrldqi128_byteshift take a byte count in [0,255].
Normalize their constant count into the existing typed whole-register shift
facts. Counts of 16 or more produce zero; these Clang forms require a constant
immediate even in an always_inline function, while template arguments defer
until instantiation. The GNU forms retain their bit-count interface.
__builtin_elementwise_min and __builtin_elementwise_max operate on two
matching arithmetic scalars or vectors. Preserve the operand type without
integer promotions, order signed and unsigned lanes correctly, and evaluate
each operand once. Floating operations follow LLVM maxNum/minNum: one NaN
yields the numeric operand, two NaNs yield NaN, and equal zeros may retain
either sign. Consume typed operands and lower through existing scalar
comparisons and selection; integer scalar constant evaluation uses the same operation.
Clang's __builtin_elementwise_sqrt preserves float and double scalar
types as well as their vector forms. Evaluate the operand once, preserve IEEE
square-root results (including signed zero and NaNs), and leave errno alone.
__fp16 is a distinct two-byte floating storage type. Scalar arithmetic and
unary +/- promote it to float; variadic arguments promote it to double.
Preserve binary16 conversions, vector lanes and its distinct Itanium Dh
encoding. A declared scalar __fp16 parameter or return type is rejected;
pointers and references remain valid.
Required inlining preserves dynamic stack allocation lifetimes. Constant-sized, on-repeating requests may use fixed frame storage; runtime-sized or repeated requests retain dynamic storage and release it when the substituted call returns.
The optional test-target-features lane also checks ordered SSE feature flags
(-msse3, -mssse3, -msse4.1, -msse4.2 and their -mno- forms), implied
feature macros, and SSE4.1 dot-product, insertion and rounding builtins. Native
checks must guard execution on CPUs that lack the requested instruction set.
The SSE control builtins behind _mm_getcsr and _mm_setcsr access actual CPU
state. Preserve argument evaluation, mode bits and instruction ordering; restore
the original state in tests that change it.
Clang headers may declare _mm_getcsr and _mm_setcsr directly as compiler
intrinsics rather than define inline wrappers. Those global declarations use
the same semantics and must not require external runtime symbols.
GNU source accepts \e and \E for the escape character (value 27),
including wide literals. Preserve their source spelling during preprocessing
and stringification; raw strings retain their backslashes.
-fno-exceptions rejects throw and try/catch constructs in checked function
bodies, including instantiated templates, and omits unwind cleanup regions.
Unused template bodies may contain those constructs. Normal scope-exit
destruction, temporary lifetimes and array destruction still run. The opposite
flag restores exception handling.