730d3129f808ac097ab1e1cf17d8c88ce75d81a6
1 /* Producer string parsers for GDB.
3 Copyright (C) 2012-2020 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "gdbsupport/selftest.h"
27 producer_is_gcc_ge_4 (const char *producer
)
31 if (! producer_is_gcc (producer
, &major
, &minor
))
43 producer_is_gcc (const char *producer
, int *major
, int *minor
)
47 if (producer
!= NULL
&& startswith (producer
, "GNU "))
56 /* Skip any identifier after "GNU " - such as "C11" "C++" or "Java".
57 A full producer string might look like:
59 "GNU Fortran 4.8.2 20140120 (Red Hat 4.8.2-16) -mtune=generic ..."
60 "GNU C++14 5.0.0 20150123 (experimental)"
62 cs
= &producer
[strlen ("GNU ")];
63 while (*cs
&& !isspace (*cs
))
65 if (*cs
&& isspace (*cs
))
67 if (sscanf (cs
, "%d.%d", major
, minor
) == 2)
71 /* Not recognized as GCC. */
79 producer_is_icc (const char *producer
, int *major
, int *minor
)
81 if (producer
== NULL
|| !startswith (producer
, "Intel(R)"))
84 /* Prepare the used fields. */
94 /* Consumes the string till a "Version" is found. */
95 const char *cs
= strstr (producer
, "Version");
98 cs
= skip_to_space (cs
);
100 int intermediate
= 0;
101 int nof
= sscanf (cs
, "%d.%d.%d.%*d", major
, &intermediate
, minor
);
103 /* Internal versions are represented only as MAJOR.MINOR, where
105 Public versions have 3 fields as described with the command
112 *minor
= intermediate
;
117 static bool warning_printed
= false;
118 /* Not recognized as Intel, let the user know. */
119 if (!warning_printed
)
121 warning (_("Could not recognize version of Intel Compiler in: \"%s\""),
123 warning_printed
= true;
128 /* See producer.h. */
131 producer_is_llvm (const char *producer
)
133 return ((producer
!= NULL
) && (startswith (producer
, "clang ")
134 || startswith (producer
, " F90 Flang ")));
137 #if defined GDB_SELF_TEST
138 namespace selftests
{
142 producer_parsing_tests ()
145 /* Check that we don't crash if "Version" is not found in what
146 looks like an ICC producer string. */
147 static const char icc_no_version
[] = "Intel(R) foo bar";
149 int major
= 0, minor
= 0;
150 SELF_CHECK (!producer_is_icc (icc_no_version
, &major
, &minor
));
151 SELF_CHECK (!producer_is_gcc (icc_no_version
, &major
, &minor
));
155 static const char extern_f_14_1
[] = "\
156 Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on \
158 Version 14.0.1.074 Build 20130716";
160 int major
= 0, minor
= 0;
161 SELF_CHECK (producer_is_icc (extern_f_14_1
, &major
, &minor
)
162 && major
== 14 && minor
== 1);
163 SELF_CHECK (!producer_is_gcc (extern_f_14_1
, &major
, &minor
));
167 static const char intern_f_14
[] = "\
168 Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on \
172 int major
= 0, minor
= 0;
173 SELF_CHECK (producer_is_icc (intern_f_14
, &major
, &minor
)
174 && major
== 14 && minor
== 0);
175 SELF_CHECK (!producer_is_gcc (intern_f_14
, &major
, &minor
));
179 static const char intern_c_14
[] = "\
180 Intel(R) C++ Intel(R) 64 Compiler XE for applications running on \
183 int major
= 0, minor
= 0;
184 SELF_CHECK (producer_is_icc (intern_c_14
, &major
, &minor
)
185 && major
== 14 && minor
== 0);
186 SELF_CHECK (!producer_is_gcc (intern_c_14
, &major
, &minor
));
190 static const char intern_c_18
[] = "\
191 Intel(R) C++ Intel(R) 64 Compiler for applications running on \
194 int major
= 0, minor
= 0;
195 SELF_CHECK (producer_is_icc (intern_c_18
, &major
, &minor
)
196 && major
== 18 && minor
== 0);
200 static const char gnu
[] = "GNU C 4.7.2";
201 SELF_CHECK (!producer_is_icc (gnu
, NULL
, NULL
));
203 int major
= 0, minor
= 0;
204 SELF_CHECK (producer_is_gcc (gnu
, &major
, &minor
)
205 && major
== 4 && minor
== 7);
209 static const char gnu_exp
[] = "GNU C++14 5.0.0 20150123 (experimental)";
210 int major
= 0, minor
= 0;
211 SELF_CHECK (!producer_is_icc (gnu_exp
, NULL
, NULL
));
212 SELF_CHECK (producer_is_gcc (gnu_exp
, &major
, &minor
)
213 && major
== 5 && minor
== 0);
217 static const char clang_llvm_exp
[] = "clang version 12.0.0 (CLANG: bld#8)";
218 int major
= 0, minor
= 0;
219 SELF_CHECK (!producer_is_icc (clang_llvm_exp
, NULL
, NULL
));
220 SELF_CHECK (!producer_is_gcc (clang_llvm_exp
, &major
, &minor
));
221 SELF_CHECK (producer_is_llvm (clang_llvm_exp
));
225 static const char flang_llvm_exp
[] = " F90 Flang - 1.5 2017-05-01";
226 int major
= 0, minor
= 0;
227 SELF_CHECK (!producer_is_icc (flang_llvm_exp
, NULL
, NULL
));
228 SELF_CHECK (!producer_is_gcc (flang_llvm_exp
, &major
, &minor
));
229 SELF_CHECK (producer_is_llvm (flang_llvm_exp
));
236 void _initialize_producer ();
238 _initialize_producer ()
240 #if defined GDB_SELF_TEST
241 selftests::register_test
242 ("producer-parser", selftests::producer::producer_parsing_tests
);