[Committed] RISC-V: Fix bug of vlds attribute
This issue is noticed when support strided load/store auto-vectorization. Commit it as it is obvious. gcc/ChangeLog: * config/riscv/vector.md: Fix bug. --- gcc/config/riscv/vector.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md index ce5c5be8e42..c47bc77ab7c 100644 --- a/gcc/config/riscv/vector.md +++ b/gcc/config/riscv/vector.md @@ -840,7 +840,7 @@ ;; wheras it is pred_strided_load if operands[3] is vector mode. (eq_attr "type" "vlds") (if_then_else (match_test "VECTOR_MODE_P (GET_MODE (operands[3]))") -(const_int INVALID_ATTRIBUTE) +(const_int 8) (const_int 7)) (eq_attr "type" "vldux,vldox,vialu,vshift,viminmax,vimul,vidiv,vsalu,\ -- 2.36.3
Re: [PATCH] Fix PR ada/111909 On Darwin, determine filesystem case sensitivity at runtime
Hi Folks > On 4 Nov 2023, at 17:02, Simon Wright wrote: > > On 3 Nov 2023, at 08:39, Arnaud Charlet wrote: >> So without changing fundamentally the model, you can't decide dynamically >> for the whole >> system. Making the choice based on the current directory is pretty random, >> since the current >> directory isn't well defined at program's start up and could be pretty much >> any filesystem. > > I’d imagine that projects spread over more than one > differently-case-sensitive filesystem would > be rare. As to the current directory at compiler startup, with GPRbuild it’s > the object directory, so > likely to be somewhere near the project’s source tree. It’s likely much less rare to find a CS external disk or an NFS mount, or secondary FS with a non-CS system partition, (since the default for the system install is that way). I am suspicious of second-guessing any of this; my opinion is that if we have an automated recognition of CS, then it needs to work in the general circumstance (that would certainly be in the spirit of macOS “it just works”). If we cannot achieve that, the advantage of the current scenario (GNAT_FILE_NAME_CASE_SENSITIVE=..) is that it is explicit on the part of the user, and therefore puts the onus on the user to get it right. >> Note that the current setting on arm is actually for iOS, which we did >> support at AdaCore >> at some point (and could revive in the future, who knows). > > Wouldn’t it be more natural to go via LLVM? I understand from Iain that iOS > isn’t currently > supported by GCC. Historically, we had no support for Arm or AArch64, so the missing support of iOS as a concept was not important - now we have an AArch64 port, it is feasible and potentially relevant to update this. Having said that, I’m not sure how a a GCC-developed iOS app would be distributed - but of course libraries are a different story. > >> So it would be fine to refine the test to differentiate between macOS and >> embedded iOS and co, >> that would be a better change here. > > There didn’t seem to be a way to do that. We should be able to do that at runtime (sysctl calls for example) > So, Iain, do we want to pursue this? Right now, I have no spare resources to tackle this, (I suspect that the issues I see on earlier systems are due to the syscall not finding the right root FS from paths like /foo/bar so it remains to be see how to deal with it). I have no objection from a Darwin perspective to folks finding a mutually agreeable solution that works without the user specifying the env. var - but I’m not going to be able to contribute much to the work in the near future. thanks Iain
Re: [PATCH] tree-optimization: Add register pressure heuristics
Hello Richard: Below are the performance numbers on CPU 2017 benchmarks with and without register pressure changes for code sinking. INT Benchmarks: With register pressure code sinking changes: Estimated Estimated Base BaseBasePeak PeakPeak Benchmarks Copies Run Time RateCopies Run Time Rate --- --- - ---- - - 500.perlbench_r 1363 4.39 * 502.gcc_r 1225 6.30 * 505.mcf_r 1289 5.59 * 520.omnetpp_r 1315 4.17 * 523.xalancbmk_r 1238 4.43 * 525.x264_r1180 9.75 * 531.deepsjeng_r 1291 3.94 * 541.leela_r 1463 3.58 * 548.exchange2_r 1222 11.8 * 557.xz_r 1323 3.34 * Est. SPECrate(R)2017_int_base 5.24 Trunk without any register pressure code sinking changes: 500.perlbench_r 1358 4.44 * 502.gcc_r 1225 6.28 * 505.mcf_r 1286 5.64 * 520.omnetpp_r 1310 4.24 * 523.xalancbmk_r 1235 4.50 * 525.x264_r1181 9.69 * 531.deepsjeng_r 1291 3.94 * 541.leela_r 1465 3.56 * 548.exchange2_r 1219 11.9 * 557.xz_r 1325 3.32 * Est. SPECrate(R)2017_int_base 5.26 FP benchmarks: With register pressure code sinking changes: 503.bwaves_r 1187 53.5 * 507.cactuBSSN_r 1235 5.39 * 508.namd_r1216 4.40 * 510.parest_r 1340 7.69 * 511.povray_r 1488 4.78 * 519.lbm_r 1128 8.21 * 521.wrf_r 1269 8.34 * 526.blender_r 1311 4.89 * 527.cam4_r1314 5.56 * 538.imagick_r 1228 10.9 * 544.nab_r 1293 5.74 * 549.fotonik3d_r 1237 16.4 * 554.roms_r1269 5.90 * Est. SPECrate(R)2017_fp_base7.97 Trunk Without register pressure changes for code sinking: 503.bwaves_r 1188 53.4 * 507.cactuBSSN_r 1242 5.24 * 508.namd_r1215 4.42 * 510.parest_r 1333 7.86 * 511.povray_r 1481 4.85 * 519.lbm_r 1128 8.22 * 521.wrf_r 1269 8.34 * 526.blender_r 1309 4.93 * 527.cam4_r1313 5.58 * 538.imagick_r 1227 11.0 * 544.nab_r 1291 5.79 * 549.fotonik3d_r 1235 16.6 * 554.roms_r1268 5.92 * Est. SPECrate(R)2017_fp_base8.00 Thanks & Regards Ajit On 03/11/23 8:24 pm, Ajit Agarwal wrote: > Hello Richard: > > > On 03/11/23 7:06 pm, Richard Biener wrote: >> On Fri, Nov 3, 2023 at 11:20 AM Ajit Agarwal wrote: >>> >>> Hello Richard: >>> >>> On 03/11/23 12:51 pm, Richard Biener wrote: On Thu, Nov 2, 2023 at 9:50 PM Ajit Agarwal wrote: > > Hello All: > >> [...] > > High register pressure region is the region where there are live-in of > early blocks that has been modified by the early block. If there are > modification of the variables in best block that are live-in in early > block that are live-out of best block. ?! Parse error. >>> >>> I didnt understand what you meant here. Please suggest. >> >> I can't even guess what that paragraph means. It fails at a >> parsing level already, I can't even start to reason about what >> the sentences mean. > > Sorry for that I will modify. > >> > Bootstrapped and regtested on powerpc64-linux-gnu. What's the effect on code generation? Note that live is a quadratic problem while sinking was not. You are effectively making the pass unfit for -O1. You are computing "liveness" on GIMPLE where within EBBs there isn't really any particular order of stmts, so it's kind of a garbage heuristic. Likewise you are not computing the effect that moving a stmt has on liveness as far as I can see but you are just identifying some odd metrics (I don't really understand them) to rank blocks, not even taking the register file size into account. >>> >>> >>> if the live out of best_bb <= live out of early_bb, that shows >>> that there are modification in best_bb. >> >> Hm? Do you maybe want to say that if live_out (bb) < live_in (bb) >> then some variables die during the execution of bb? > > live_out (bb) < live_in(bb) means in
Re: [PATCH] diagnostics: fix gcc-urlifier.cc bootstrap failure [PR112379]
On Sat, 2023-11-04 at 16:23 +, Sergei Trofimovich wrote: > From: Sergei Trofimovich > > Without the change `./configure --enable-checking=release` bootstrap > fails as: > > gcc/gcc-urlifier.cc:100:1: error: > 'get_url_suffix_for_quoted_text()' > defined but not used [-Werror=unused-function] > > This happens because the helper is used only in `ASSERT` macros which > don't always get expanded to executable code. > > The fix marks helper function with `ATTRIBUTE_UNUSED`. Sorry for the breakage. Patch looks good to me; thanks Dave > > gcc/ > PR bootstrap/112379 > * gcc-urlifier.cc (get_url_suffix_for_quoted_text): Mark as > ATTRIBUTE_UNUSED. > --- > gcc/gcc-urlifier.cc | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/gcc/gcc-urlifier.cc b/gcc/gcc-urlifier.cc > index 269246bc703..0dbff985313 100644 > --- a/gcc/gcc-urlifier.cc > +++ b/gcc/gcc-urlifier.cc > @@ -37,7 +37,8 @@ public: > char *get_url_for_quoted_text (const char *p, size_t sz) const > final override; > > const char *get_url_suffix_for_quoted_text (const char *p, size_t > sz) const; > - const char *get_url_suffix_for_quoted_text (const char *p) const; > + /* We use ATTRIBUTE_UNUSED as this helper is called only from > ASSERTs. */ > + const char *get_url_suffix_for_quoted_text (const char *p) const > ATTRIBUTE_UNUSED; > > private: > static char *
Re: [PATCH] Fix PR ada/111909 On Darwin, determine filesystem case sensitivity at runtime
On 3 Nov 2023, at 08:39, Arnaud Charlet wrote: > In addition to the non portable issues already mentioned, this change isn't > OK also > for other reasons. > > Basically this function is global and decides once for all on the case > sensitivity, while > the case sensitiviy is on a per filsystem basis as you noted. Well, the current code does exactly what you describe, with less relationship to the actual environment than this proposal. > So without changing fundamentally the model, you can't decide dynamically for > the whole > system. Making the choice based on the current directory is pretty random, > since the current > directory isn't well defined at program's start up and could be pretty much > any filesystem. I’d imagine that projects spread over more than one differently-case-sensitive filesystem would be rare. As to the current directory at compiler startup, with GPRbuild it’s the object directory, so likely to be somewhere near the project’s source tree. > Note that the current setting on arm is actually for iOS, which we did > support at AdaCore > at some point (and could revive in the future, who knows). Wouldn’t it be more natural to go via LLVM? I understand from Iain that iOS isn’t currently supported by GCC. > So it would be fine to refine the test to differentiate between macOS and > embedded iOS and co, > that would be a better change here. There didn’t seem to be a way to do that. But anyway, I find myself puzzled by the casing issue. It seems to me that on a CS filesystem users would be well advised to stick to lower-case filenames, or the compiler won’t be able to resolve 'with' statements; whereas on a non-CS system, there’d be no such constraint. Indeed, when compiling a file with a mixed-case name in a CS environment, the compiler warns: $ GNAT_FILE_NAME_CASE_SENSITIVE=1 gcc -c -u -f WTF.adb WTF.adb:1:11: warning: file name does not match unit name, should be "wtf.adb" [enabled by default] Also, there’ve been about 80 downloads of GCC 13.1.0 for aarch64-apple-darwin, and no case-sensitivity issues have been reported. So, Iain, do we want to pursue this? > >> This change affects only Ada. >> >> In gcc/ada/adaint.c(__gnat_get_file_names_case_sensitive), the >> assumption for __APPLE__ is that file names are case-insensitive >> unless __arm__ or __arm64__ are defined, in which case file names >> are declared case-sensitive. >> >> The associated comment is >> "By default, we suppose filesystems aren't case sensitive on >> Windows and Darwin (but they are on arm-darwin)." >> >> This means that on aarch64-apple-darwin, file names are declared >> case-sensitive, which is not normally the case (but users can set >> up case-sensitive volumes). >> >> It's understood that GCC does not currently support iOS/tvOS/watchOS, >> so we assume macOS. >> >> Bootstrapped on x86_64-apple-darwin with languages c,c++,ada and regression >> tested (check-gnat). >> Also, tested with the example from PR ada/81114, extracted into 4 volumes >> (APFS, APFS-case-sensitive, >> HFS, HFS-case-sensitive; the example code built successfully on the >> case-sensitive volumes. >> Setting GNAT_FILE_NAME_CASE_SENSITIVE successfully overrode the choices made >> by the >> new code. >> >> gcc/ada/Changelog: >> >> 2023-10-29 Simon Wright >> >> PR ada/111909 >> >> * gcc/ada/adaint.c >> (__gnat_get_file_names_case_sensitive): Remove the checks for >> __arm__, __arm64__. >> Split out the check for __APPLE__; remove the checks for __arm__, >> __arm64__, and use getattrlist(2) to determine whether the current >> working directory is on a case-sensitive filesystem. >> >> Signed-off-by: Simon Wright
[PATCH] diagnostics: fix gcc-urlifier.cc bootstrap failure [PR112379]
From: Sergei Trofimovich Without the change `./configure --enable-checking=release` bootstrap fails as: gcc/gcc-urlifier.cc:100:1: error: 'get_url_suffix_for_quoted_text()' defined but not used [-Werror=unused-function] This happens because the helper is used only in `ASSERT` macros which don't always get expanded to executable code. The fix marks helper function with `ATTRIBUTE_UNUSED`. gcc/ PR bootstrap/112379 * gcc-urlifier.cc (get_url_suffix_for_quoted_text): Mark as ATTRIBUTE_UNUSED. --- gcc/gcc-urlifier.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/gcc-urlifier.cc b/gcc/gcc-urlifier.cc index 269246bc703..0dbff985313 100644 --- a/gcc/gcc-urlifier.cc +++ b/gcc/gcc-urlifier.cc @@ -37,7 +37,8 @@ public: char *get_url_for_quoted_text (const char *p, size_t sz) const final override; const char *get_url_suffix_for_quoted_text (const char *p, size_t sz) const; - const char *get_url_suffix_for_quoted_text (const char *p) const; + /* We use ATTRIBUTE_UNUSED as this helper is called only from ASSERTs. */ + const char *get_url_suffix_for_quoted_text (const char *p) const ATTRIBUTE_UNUSED; private: static char * -- 2.42.0
Re: Remove redundant partial specialization in _Nth_type
On Sat, 28 Oct 2023 at 14:15, Feng Jisen wrote: > > This patch remove a redundant partial specialization in class _Nth_type. Thanks for the patch, I've pushed it to trunk now. > > For the original metafunction _Nth_type code, > # 0 > template > struct _Nth_type<0, _Tp0, _Rest...> > { using type = _Tp0; }; > # 1 > template > struct _Nth_type<0, _Tp0, _Tp1, _Rest...> > { using type = _Tp0; }; > # 2 > template > struct _Nth_type<0, _Tp0, _Tp1, _Tp2, _Rest...> > { using type = _Tp0; }; > # 3 > template typename... _Rest> > #if __cpp_concepts > requires (_Np >= 3) > #endif > struct _Nth_type<_Np, _Tp0, _Tp1, _Tp2, _Rest...> > : _Nth_type<_Np - 3, _Rest...> > { }; > > we need partial specialization # 2 to deal with template argument <0, Tp0, > Tp1, Tp2, ...>. > Because without concepts, both # 0 and # 3 is legal and there is no partial > order relationship between them. > However, # 1 is redundant. For template argument <0, Tp0, Tp1>, #0 is > instantiated and that's enough. > > libstdc++-v3/ChangeLog: > > * include/bits/utility.h:(_Nth_type) Remove redundant partial specialization. > > > diff --git a/libstdc++-v3/include/bits/utility.h > b/libstdc++-v3/include/bits/utility.h > index bed94525642..8766dfbc15f 100644 > --- a/libstdc++-v3/include/bits/utility.h > +++ b/libstdc++-v3/include/bits/utility.h > @@ -258,10 +258,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > { }; > > #if ! __cpp_concepts // Need additional specializations to avoid ambiguities. > - template > -struct _Nth_type<0, _Tp0, _Tp1, _Rest...> > -{ using type = _Tp0; }; > - >template > struct _Nth_type<0, _Tp0, _Tp1, _Tp2, _Rest...> > { using type = _Tp0; }; > -- > >
[committed] libstdc++: Use strerror_r in std::generic_category()::message(int) [PR110133]
Tested x86_64-linux. Pushed to trunk. Probably worth backporting after some time on trunk. -- >8 -- Use strerror_r instead of strerror when available, due to the latter not being thread-safe. This is complicated by Glibc providing a GNU-specific strerror_r which is not compatible with POSIX strerror_r, so we need to dispatch on the return type. We can use the recently-added std::string::__resize_and_overwrite to write directly into the string buffer when possible. Because we estimate the initial buffer size we might end up with excess capacity in the returned std::string. We can slightly tweak the std::system_error constructors to make use of that excess capacity, so that in some cases we require fewer allocations to construct the std::system_error::what() string. libstdc++-v3/ChangeLog: PR libstdc++/110133 * include/std/system_error (system_error::system_error): Group arguments so that concatenation can reuse rvalue's capacity. * src/c++11/system_error.cc (strerror_string): New function. [_GLIBCXX_HAVE_STRERROR_R] (use_strerror_result): New functions. (generic_error_category::message): Use strerror_string. (system_error_category::message): Likewise. --- libstdc++-v3/include/std/system_error | 4 +- libstdc++-v3/src/c++11/system_error.cc | 78 +++--- 2 files changed, 72 insertions(+), 10 deletions(-) diff --git a/libstdc++-v3/include/std/system_error b/libstdc++-v3/include/std/system_error index d71abc9766b..e26472bb0bf 100644 --- a/libstdc++-v3/include/std/system_error +++ b/libstdc++-v3/include/std/system_error @@ -563,7 +563,7 @@ namespace __adl_only : runtime_error(__ec.message()), _M_code(__ec) { } system_error(error_code __ec, const string& __what) -: runtime_error(__what + ": " + __ec.message()), _M_code(__ec) { } +: runtime_error(__what + (": " + __ec.message())), _M_code(__ec) { } system_error(error_code __ec, const char* __what) : runtime_error(__what + (": " + __ec.message())), _M_code(__ec) { } @@ -576,7 +576,7 @@ namespace __adl_only _M_code(__v, __ecat) { } system_error(int __v, const error_category& __ecat, const string& __what) -: runtime_error(__what + ": " + error_code(__v, __ecat).message()), +: runtime_error(__what + (": " + error_code(__v, __ecat).message())), _M_code(__v, __ecat) { } #if __cplusplus >= 201103L diff --git a/libstdc++-v3/src/c++11/system_error.cc b/libstdc++-v3/src/c++11/system_error.cc index 748eee94168..876e2bb44fc 100644 --- a/libstdc++-v3/src/c++11/system_error.cc +++ b/libstdc++-v3/src/c++11/system_error.cc @@ -46,6 +46,74 @@ namespace { using std::string; +#if _GLIBCXX_HAVE_STRERROR_R + // Handle the result of POSIX strerror_r. + inline std::size_t + use_strerror_result(int res, char* buf, std::size_t bufsz, + std::size_t& nextbufsz) + { +if (res == 0) // Success. + return std::strlen(buf); + +if (res == ERANGE) // Buffer too small to hold result string. + { + nextbufsz = 2 * bufsz; + return 0; + } +// else res == EINVAL, unknown error. +if (*buf == '\0') // No result string written to buffer. + { + const char msg[] = "Unknown error"; + std::memcpy(buf, msg, sizeof(msg) - 1); + return sizeof(msg) - 1; + } +else // An "unknown error" string was already written to the buffer. + return std::strlen(buf); + } + + // Handle the result of GNU strerror_r. + inline std::size_t + use_strerror_result(char* res, char* buf, std::size_t bufsz, + std::size_t& nextbufsz) + { +if (res == buf) // Result string written to the buffer. + return std::strlen(res); + +// Static result string returned, must be copied to the buffer. +std::size_t len = std::strlen(res); +if (len <= bufsz) + { + std::strcpy(buf, res); + return len; + } + +// Reallocate and try again: +nextbufsz = len; +return 0; + } + + string strerror_string(int err) + { +// Estimate maximum length of strerror strings (including "Unknown error"). +// Any excess capacity here can be used by std::system_error constructors +// when concatenating strings. +std::size_t len = 60; +string s; +do + s.__resize_and_overwrite(len, [err, &len](char* p, std::size_t n) { + *p = '\0'; + return use_strerror_result(strerror_r(err, p, n), p, n, len); + }); +while (s.empty()); +return s; + } +#else + string strerror_string(int err) + { +return strerror(err); // XXX Not thread-safe. + } +#endif + template struct constant_init { @@ -66,11 +134,7 @@ namespace _GLIBCXX_DEFAULT_ABI_TAG string message(int i) const final -{ - // XXX locale issues: how does one get or set loc. - // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc) - return string(strerror(i)); -} +{ return strerror_string(i); }
[committed] libstdc++: Replace "_N" in examples of naming conventions
Pushed to trunk. -- >8 -- The name "_N" is listed as a reserved name on Solaris, so we shouldn't use it as an example of our naming conventions. libstdc++-v3/ChangeLog: * doc/xml/manual/appendix_contributing.xml: Replace example that uses a BADNAME. * doc/html/manual/source_code_style.html: Regenerate. --- libstdc++-v3/doc/html/manual/source_code_style.html | 4 ++-- libstdc++-v3/doc/xml/manual/appendix_contributing.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/doc/xml/manual/appendix_contributing.xml b/libstdc++-v3/doc/xml/manual/appendix_contributing.xml index 197c7d9fb40..a9196493adc 100644 --- a/libstdc++-v3/doc/xml/manual/appendix_contributing.xml +++ b/libstdc++-v3/doc/xml/manual/appendix_contributing.xml @@ -887,7 +887,7 @@ indicate a place that may require attention for multi-thread safety. Type names and template formal-argument names: _[A-Z][^_].* - Examples: _Helper _CharT _N + Examples: _Helper _CharT _Nm Member data and function names: _M_.* @@ -899,7 +899,7 @@ indicate a place that may require attention for multi-thread safety. Don't use names in the same scope that differ only in the prefix, e.g. _S_top and _M_top. See BADNAMES for a list of forbidden names. - (The most tempting of these seem to be and "_T" and "__sz".) + (The most tempting of these seem to be and "_T" and "_N".) Names must never have "__" internally; it would confuse name unmanglers on some targets. Also, never use "__[0-9]", same reason. -- 2.41.0
[committed] openmp: Add omp::decl support for C2X
Hi! This patch adds omp::decl support which has been added recently for C++ also to C. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2023-11-04 Jakub Jelinek * c-parser.h (c_maybe_parse_omp_decl): Declare. * c-parser.cc (struct c_parser): Add in_omp_decl_attribute member. (c_parser_std_attribute): Uncoment omp::decl handling. (c_parser_omp_var_list_parens): If parser->in_omp_decl_attribute don't expect any arguments, instead create clause or TREE_LIST for that decl. (c_maybe_parse_omp_decl): New function. (c_parser_omp_declare_target): If parser->in_omp_decl_attribute and first token isn't name or comma invoke c_parser_omp_var_list_parens. * c-decl.cc (c_decl_attributes): Uncomment omp::decl handling and use *node rather than non-existing *decl. * gcc.dg/gomp/attrs-19.c: New test. * gcc.dg/gomp/attrs-20.c: New test. * gcc.dg/gomp/attrs-21.c: New test. --- gcc/c/c-parser.h.jj 2023-11-03 14:45:30.884543778 +0100 +++ gcc/c/c-parser.h2023-11-03 15:24:44.859097248 +0100 @@ -204,5 +204,6 @@ extern void c_parser_declspecs (c_parser bool, bool, bool, bool, bool, enum c_lookahead_kind); extern struct c_type_name *c_parser_type_name (c_parser *, bool = false); +extern bool c_maybe_parse_omp_decl (tree, tree); #endif --- gcc/c/c-parser.cc.jj2023-11-03 14:45:30.903543539 +0100 +++ gcc/c/c-parser.cc 2023-11-03 16:18:30.593079455 +0100 @@ -262,6 +262,10 @@ struct GTY(()) c_parser { attributes turned into pragma, vector of tokens created from that, otherwise NULL. */ vec *in_omp_attribute_pragma; + + /* Set for omp::decl attribute parsing to the decl to which it + appertains. */ + tree in_omp_decl_attribute; }; /* Return a pointer to the Nth token in PARSERs tokens_buf. */ @@ -5797,14 +5801,14 @@ c_parser_std_attribute (c_parser *parser parens.skip_until_found_close (parser); return attribute; } -/* else if (is_attribute_p ("decl", name)) + else if (is_attribute_p ("decl", name)) { TREE_VALUE (TREE_PURPOSE (attribute)) = get_identifier ("directive"); c_parser_omp_directive_args (parser, attribute, true); parens.skip_until_found_close (parser); return attribute; - } */ + } else if (is_attribute_p ("sequence", name)) { TREE_VALUE (TREE_PURPOSE (attribute)) @@ -15147,6 +15151,19 @@ c_parser_omp_var_list_parens (c_parser * /* The clauses location. */ location_t loc = c_parser_peek_token (parser)->location; + if (parser->in_omp_decl_attribute) +{ + if (kind) + { + tree u = build_omp_clause (loc, kind); + OMP_CLAUSE_DECL (u) = parser->in_omp_decl_attribute; + OMP_CLAUSE_CHAIN (u) = list; + return u; + } + else + return tree_cons (parser->in_omp_decl_attribute, NULL_TREE, list); +} + matching_parens parens; if (parens.require_open (parser)) { @@ -24498,6 +24515,84 @@ c_finish_omp_declare_simd (c_parser *par clauses[0].type = CPP_PRAGMA; } +/* D should be C_TOKEN_VEC from omp::decl attribute. If it contains + a threadprivate, groupprivate, allocate or declare target directive, + return true and parse it for DECL. */ + +bool +c_maybe_parse_omp_decl (tree decl, tree d) +{ + gcc_assert (TREE_CODE (d) == C_TOKEN_VEC); + vec *toks = C_TOKEN_VEC_TOKENS (d); + c_token *first = toks->address (); + c_token *last = first + toks->length (); + const char *directive[3] = {}; + for (int j = 0; j < 3; j++) +{ + tree id = NULL_TREE; + if (first + j == last) + break; + if (first[j].type == CPP_NAME) + id = first[j].value; + else if (first[j].type == CPP_KEYWORD) + id = ridpointers[(int) first[j].keyword]; + else + break; + directive[j] = IDENTIFIER_POINTER (id); +} + const c_omp_directive *dir = NULL; + if (directive[0]) +dir = c_omp_categorize_directive (directive[0], directive[1], + directive[2]); + if (dir == NULL) +{ + error_at (first->location, + "unknown OpenMP directive name in " + "%qs attribute argument", "omp::decl"); + return false; +} + if (dir->id != PRAGMA_OMP_THREADPRIVATE + /* && dir->id != PRAGMA_OMP_GROUPPRIVATE */ + && dir->id != PRAGMA_OMP_ALLOCATE + && (dir->id != PRAGMA_OMP_DECLARE + || strcmp (directive[1], "target") != 0)) +return false; + + if (!flag_openmp && !dir->simd) +return true; + + c_parser *parser = the_parser; + unsigned int tokens_avail = parser->tokens_avail; + gcc_assert (parser->tokens == &parser->tokens_buf[0]); + toks = NULL; + vec_safe
[committed] openmp: Add support for omp::directive and omp::sequence attributes in C2X
Hi! The following patch adds support for attribute syntax which we have in C++11 and above since GCC 12 also for C, where OpenMP standard is going to add it in OpenMP 6.0. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2023-11-04 Jakub Jelinek gcc/c/ * c-tree.def: New file. * c-tree.h (struct c_tree_token_vec): Forward declare. (c_tree_size): Declare. * c-lang.h (struct c_omp_declare_target_attr): Add attr_syntax member. (struct c_omp_begin_assumes_data): New type. (current_omp_begin_assumes): Change type from int to vec *. * c-lang.cc: Include c-family/c-pragma.h and c-parser.h. * c-parser.h (struct c_tree_token_vec_struct): New type. (C_TOKEN_VEC_TOKENS): New macro. * c-parser.cc (struct c_parser): Add omp_attrs_forbidden_p and in_omp_attribute_pragma members. (c_parser_skip_until_found): Handle CPP_PRAGMA_EOL when parser->in_omp_attribute_pragma. (c_parser_skip_to_pragma_eol): Likewise. (c_parser_translation_unit): Adjust for current_omp_begin_assumes being a vector rather than counter. (c_parser_declaration_or_fndef): Handle omp::directive and omp::sequence attributes on attribute declaration and declare simd or declare variant directives in those on function declarations. (c_parser_check_balanced_raw_token_sequence): Forward declare. (c_parser_omp_directive_args, c_parser_omp_sequence_args): New functions. (c_parser_std_attribute): Handle omp::directive and omp::sequence attributes. (struct c_omp_attribute_data): New type. (c_parser_handle_statement_omp_attributes, c_parser_handle_directive_omp_attributes): New functions. (c_parser_compound_statement_nostart): Handle omp::directive and omp::sequence attributes on statements. Formatting fix. (c_parser_all_labels): Handle omp::directive and omp::sequence attributes on statements. (c_parser_statement): Clear parser->omp_attrs_forbidden_p. (c_parser_omp_variable_list): Handle parser->tokens != &parser->tokens_buf[0] by saving/restoring it. (c_parser_omp_structured_block): Set parser->omp_attrs_forbidden_p. (c_parser_omp_section_scan): New function. (c_parser_omp_structured_block_sequence, c_parser_omp_sections_scope): Use it. (c_parser_omp_parallel): Set parser->omp_attrs_forbidden_p. (c_parser_omp_task): Likewise. (c_parser_omp_declare_simd): Handle function declaration after std attributes. (c_finish_omp_declare_simd): Don't assert all kinds are the same. (c_parser_omp_declare_target): Also push attr_syntax flag. (c_parser_omp_begin): Likewise. Adjust for current_omp_begin_assumes type change. (c_parser_omp_end): Adjust for current_omp_begin_assumes type change. Diagnose mixing of attribute vs. pragma syntax on end assumes or end declare target. (c_parser_omp_declare_reduction): Handle parser->tokens != &parser->tokens_buf[0] by saving/restoring it. * c-decl.cc: Include c-parser.h. (current_omp_begin_assumes): Change type from int to vec *. (struct c_tree_token_vec): New type. Add static assertions for sizeof and offsetof. (union lang_tree_node): Add c_token_vec member and adjust GTY desc for it. (c_tree_size): New function. (c_decl_attributes): Diagnose invalid omp::directive attribute uses. * c-objc-common.h (LANG_HOOKS_TREE_SIZE): Redefine. gcc/cp/ * parser.h (struct cp_parser): Adjust comment on omp_attrs_forbidden_p member. * parser.cc (cp_parser_omp_section_scan): Allow __directive__ spelling. gcc/objc/ * objc-act.h (objc_common_tree_size): Remove. * objc-act.cc (objc_common_tree_size): Remove. * objc-lang.cc (LANG_HOOKS_TREE_SIZE): Remove. gcc/testsuite/ * gcc.dg/gomp/attrs-1.c: New test. * gcc.dg/gomp/attrs-2.c: New test. * gcc.dg/gomp/attrs-3.c: New test. * gcc.dg/gomp/attrs-4.c: New test. * gcc.dg/gomp/attrs-5.c: New test. * gcc.dg/gomp/attrs-6.c: New test. * gcc.dg/gomp/attrs-7.c: New test. * gcc.dg/gomp/attrs-8.c: New test. * gcc.dg/gomp/attrs-9.c: New test. * gcc.dg/gomp/attrs-10.c: New test. * gcc.dg/gomp/attrs-11.c: New test. * gcc.dg/gomp/attrs-12.c: New test. * gcc.dg/gomp/attrs-13.c: New test. * gcc.dg/gomp/attrs-14.c: New test. * gcc.dg/gomp/attrs-15.c: New test. * gcc.dg/gomp/attrs-16.c: New test. * gcc.dg/gomp/attrs-17.c: New test. * gcc.dg/gomp/attrs-18.c: New test. * g++.dg/gomp/attrs-2.C: Enable for c++11 rather than just c++17. Avoid using omp : syntax for c++11, c++14 and c. --- gcc/c/c-tr
Re: [PATCH] Fortran: Fix generate_error library function fnspec
Hi Martin, This looks to be 'obvious' and is certainly OK for mainline. Backport if you wish. Thanks Paul On Fri, 3 Nov 2023 at 12:54, Martin Jambor wrote: > Hi, > > when developing an otherwise unrelated patch I've discovered that the > fnspec for the Fortran library function generate_error is wrong. It is > currently ". R . R " where the first R describes the first parameter > and means that it "is only read and does not escape." The function > itself, however, with signature: > > bool > generate_error_common (st_parameter_common *cmp, int family, const char > *message) > > contains the following: > > /* Report status back to the compiler. */ > cmp->flags &= ~IOPARM_LIBRETURN_MASK; > > which does not correspond to the fnspec and breaks testcase > gfortran.dg/large_unit_2.f90 when my patch is applied, since it tries > to re-use the flags from before the call. > > This patch replaces the "R" with "W" which stands for "specifies that > the memory pointed to by the parameter does not escape." > > Bootstrapped and tested on x86_64-linux. OK for master? > > > 2023-11-02 Martin Jambor > > * trans-decl.cc (gfc_build_builtin_function_decls): Fix fnspec of > generate_error. > > --- > gcc/fortran/trans-decl.cc | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc > index a3f037bd07b..b86cfec7d49 100644 > --- a/gcc/fortran/trans-decl.cc > +++ b/gcc/fortran/trans-decl.cc > @@ -3821,7 +3821,7 @@ gfc_build_builtin_function_decls (void) > void_type_node, -2, pchar_type_node, pchar_type_node); > >gfor_fndecl_generate_error = gfc_build_library_function_decl_with_spec ( > - get_identifier (PREFIX("generate_error")), ". R . R ", > + get_identifier (PREFIX("generate_error")), ". W . R ", > void_type_node, 3, pvoid_type_node, integer_type_node, > pchar_type_node); > > -- > 2.42.0 > >