Skip to content

Commit 7e5f968

Browse files
committed
libgccjit: Accept more flags
1 parent dfbee71 commit 7e5f968

4 files changed

Lines changed: 150 additions & 11 deletions

File tree

gcc/jit/dummy-frontend.cc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,46 @@ jit_langhook_type_promotes_to (tree type)
20292029
return type;
20302030
}
20312031

2032+
/* Implementation of LANG_HOOKS_OPTION_LANG_MASK.
2033+
2034+
Without this, libgccjit has no language mask at all, so only Common and
2035+
Target options are accepted: everything else is rejected with
2036+
"command-line option '...' is valid for <languages> but not for
2037+
<nothing>". The options that make sense for a client of libgccjit are
2038+
marked with the LibGCCJIT language in the relevant lang.opt. */
2039+
2040+
static unsigned int
2041+
jit_langhook_option_lang_mask (void)
2042+
{
2043+
return CL_LibGCCJIT;
2044+
}
2045+
2046+
#undef LANG_HOOKS_OPTION_LANG_MASK
2047+
#define LANG_HOOKS_OPTION_LANG_MASK jit_langhook_option_lang_mask
2048+
2049+
/* Implementation of LANG_HOOKS_HANDLE_OPTION.
2050+
2051+
Every option libgccjit accepts has a Var(...) in the .opt file, so by the
2052+
time this is called handle_option has already stored the value and there is
2053+
nothing language-specific left to do. The hook still has to exist and
2054+
return true: the default lhd_handle_option returns false, which would make
2055+
read_cmdline_option report the option as unrecognized. */
2056+
2057+
static bool
2058+
jit_langhook_handle_option (
2059+
size_t code ATTRIBUTE_UNUSED,
2060+
const char *arg ATTRIBUTE_UNUSED,
2061+
HOST_WIDE_INT value ATTRIBUTE_UNUSED,
2062+
int kind ATTRIBUTE_UNUSED,
2063+
location_t loc ATTRIBUTE_UNUSED,
2064+
const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
2065+
{
2066+
return true;
2067+
}
2068+
2069+
#undef LANG_HOOKS_HANDLE_OPTION
2070+
#define LANG_HOOKS_HANDLE_OPTION jit_langhook_handle_option
2071+
20322072
#undef LANG_HOOKS_EH_PERSONALITY
20332073
#define LANG_HOOKS_EH_PERSONALITY jit_langhook_eh_personality
20342074

gcc/jit/lang.opt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
; Options for libgccjit.
2+
; Copyright (C) 2026 Free Software Foundation, Inc.
3+
;
4+
; This file is part of GCC.
5+
;
6+
; GCC is free software; you can redistribute it and/or modify it under
7+
; the terms of the GNU General Public License as published by the Free
8+
; Software Foundation; either version 3, or (at your option) any later
9+
; version.
10+
;
11+
; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12+
; WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
; for more details.
15+
;
16+
; You should have received a copy of the GNU General Public License
17+
; along with GCC; see the file COPYING3. If not see
18+
; <http://www.gnu.org/licenses/>.
19+
20+
; See the GCC internals manual for a description of this file's format.
21+
22+
; Please try to keep this file in ASCII collating order.
23+
24+
; libgccjit has no source language of its own, so the options listed here are
25+
; not front end options: they are the language-specific options that a client
26+
; of libgccjit can meaningfully pass to
27+
; gcc_jit_context_add_command_line_option. They are all warnings that are
28+
; enabled by default and that can be emitted from language-independent
29+
; middle-end or target code, so libgccjit can trigger them; without a record
30+
; here there is no way for a client to turn them off.
31+
32+
Language
33+
LibGCCJIT
34+
35+
Wif-not-aligned
36+
LibGCCJIT
37+
; Documented in C
38+
39+
Wpsabi
40+
LibGCCJIT
41+
; Documented in C
42+
43+
Wstringop-overflow=
44+
LibGCCJIT
45+
; Documented in C
46+
47+
Wstringop-overread
48+
LibGCCJIT
49+
; Documented in C
50+
51+
Wstringop-truncation
52+
LibGCCJIT
53+
; Documented in C
54+
55+
Wsync-nand
56+
LibGCCJIT
57+
; Documented in C
58+
59+
Wunused-result
60+
LibGCCJIT
61+
; Documented in C

gcc/jit/lang.opt.urls

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; Autogenerated by regenerate-opt-urls.py from gcc/jit/lang.opt and generated HTML
2+
3+
Wif-not-aligned
4+
UrlSuffix(gcc/Warning-Options.html#index-Wif-not-aligned)
5+
6+
Wpsabi
7+
UrlSuffix(gcc/Warning-Options.html#index-Wno-psabi)
8+
9+
Wstringop-overflow=
10+
UrlSuffix(gcc/Warning-Options.html#index-Wno-stringop-overflow)
11+
12+
Wstringop-overread
13+
UrlSuffix(gcc/Warning-Options.html#index-Wno-stringop-overread)
14+
15+
Wstringop-truncation
16+
UrlSuffix(gcc/Warning-Options.html#index-Wno-stringop-truncation)
17+
18+
Wsync-nand
19+
UrlSuffix(gcc/Warning-Options.html#index-Wno-sync-nand)
20+
21+
Wunused-result
22+
UrlSuffix(gcc/Warning-Options.html#index-Wno-unused-result)

gcc/opts.h

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,17 @@ extern const struct cl_var cl_vars[];
164164
extern const char *const lang_names[];
165165
extern const unsigned int cl_lang_count;
166166

167-
#define CL_PARAMS (1U << 16) /* Fake entry. Used to display --param info with --help. */
168-
#define CL_WARNING (1U << 17) /* Enables an (optional) warning message. */
169-
#define CL_OPTIMIZATION (1U << 18) /* Enables an (optional) optimization. */
170-
#define CL_DRIVER (1U << 19) /* Driver option. */
171-
#define CL_TARGET (1U << 20) /* Target-specific option. */
172-
#define CL_COMMON (1U << 21) /* Language-independent. */
167+
/* Bits 0 to cl_lang_count - 1 are reserved for the languages declared by the
168+
Language records in the .opt files; see CL_LANG_ALL in options.h. When a
169+
front end is added, every macro below has to be shifted up by one bit to
170+
make room for it. */
171+
172+
#define CL_PARAMS (1U << 17) /* Fake entry. Used to display --param info with --help. */
173+
#define CL_WARNING (1U << 18) /* Enables an (optional) warning message. */
174+
#define CL_OPTIMIZATION (1U << 19) /* Enables an (optional) optimization. */
175+
#define CL_DRIVER (1U << 20) /* Driver option. */
176+
#define CL_TARGET (1U << 21) /* Target-specific option. */
177+
#define CL_COMMON (1U << 22) /* Language-independent. */
173178

174179
#define CL_MIN_OPTION_CLASS CL_PARAMS
175180
#define CL_MAX_OPTION_CLASS CL_COMMON
@@ -179,11 +184,22 @@ extern const unsigned int cl_lang_count;
179184
This distinction is important because --help will not list options
180185
which only have these higher bits set. */
181186

182-
#define CL_JOINED (1U << 22) /* If takes joined argument. */
183-
#define CL_SEPARATE (1U << 23) /* If takes a separate argument. */
184-
#define CL_UNDOCUMENTED (1U << 24) /* Do not output with --help. */
185-
#define CL_NO_DWARF_RECORD (1U << 25) /* Do not add to producer string. */
186-
#define CL_PCH_IGNORE (1U << 26) /* Do compare state for pch. */
187+
#define CL_JOINED (1U << 23) /* If takes joined argument. */
188+
#define CL_SEPARATE (1U << 24) /* If takes a separate argument. */
189+
#define CL_UNDOCUMENTED (1U << 25) /* Do not output with --help. */
190+
#define CL_NO_DWARF_RECORD (1U << 26) /* Do not add to producer string. */
191+
#define CL_PCH_IGNORE (1U << 27) /* Do compare state for pch. */
192+
193+
/* The language bits must not collide with the option class and attribute bits
194+
defined above; adding a Language record to a .opt file without shifting
195+
those macros up would give a language the same bit as CL_PARAMS.
196+
optc-gen.awk emits an equivalent #error into options.cc, but that only
197+
covers the one generated file, so state the invariant here too, where the
198+
bits are actually laid out. CL_LANG_ALL comes from the generated
199+
options.h, which a few users of this header include only afterwards. */
200+
#ifdef CL_LANG_ALL
201+
STATIC_ASSERT ((CL_LANG_ALL & CL_MIN_OPTION_CLASS) == 0);
202+
#endif
187203

188204
/* Flags for an enumerated option argument. */
189205
#define CL_ENUM_CANONICAL (1 << 0) /* Canonical for this value. */

0 commit comments

Comments
 (0)