/* Producer string parsers for GDB.
- Copyright (C) 2012-2019 Free Software Foundation, Inc.
+ Copyright (C) 2012-2022 Free Software Foundation, Inc.
This file is part of GDB.
#include "defs.h"
#include "producer.h"
-#include "selftest.h"
+#include "gdbsupport/selftest.h"
+#include "gdbsupport/gdb_regex.h"
/* See producer.h. */
*/
cs = &producer[strlen ("GNU ")];
while (*cs && !isspace (*cs))
- cs++;
+ cs++;
if (*cs && isspace (*cs))
- cs++;
+ cs++;
if (sscanf (cs, "%d.%d", major, minor) == 2)
return 1;
}
return 0;
}
+/* See producer.h. */
+
+bool
+producer_is_icc_ge_19 (const char *producer)
+{
+ int major, minor;
+
+ if (! producer_is_icc (producer, &major, &minor))
+ return false;
+
+ return major >= 19;
+}
/* See producer.h. */
bool
producer_is_icc (const char *producer, int *major, int *minor)
{
- if (producer == NULL || !startswith (producer, "Intel(R)"))
+ compiled_regex i_re ("Intel(R)", 0, "producer_is_icc");
+ if (producer == nullptr || i_re.exec (producer, 0, nullptr, 0) != 0)
return false;
/* Prepare the used fields. */
int maj, min;
- if (major == NULL)
+ if (major == nullptr)
major = &maj;
- if (minor == NULL)
+ if (minor == nullptr)
minor = &min;
*minor = 0;
*major = 0;
- /* Consumes the string till a "Version" is found. */
- const char *cs = strstr (producer, "Version");
- if (cs != NULL)
+ compiled_regex re ("[0-9]+\\.[0-9]+", REG_EXTENDED, "producer_is_icc");
+ regmatch_t version[1];
+ if (re.exec (producer, ARRAY_SIZE (version), version, 0) == 0
+ && version[0].rm_so != -1)
{
- cs = skip_to_space (cs);
-
- int intermediate = 0;
- int nof = sscanf (cs, "%d.%d.%d.%*d", major, &intermediate, minor);
-
- /* Internal versions are represented only as MAJOR.MINOR, where
- minor is usually 0.
- Public versions have 3 fields as described with the command
- above. */
- if (nof == 3)
- return true;
-
- if (nof == 2)
- {
- *minor = intermediate;
- return true;
- }
+ const char *version_str = producer + version[0].rm_so;
+ sscanf (version_str, "%d.%d", major, minor);
+ return true;
}
- static bool warning_printed = false;
- /* Not recognized as Intel, let the user know. */
- if (!warning_printed)
- {
- warning (_("Could not recognize version of Intel Compiler in: \"%s\""),
- producer);
- warning_printed = true;
- }
return false;
}
+/* See producer.h. */
+
+bool
+producer_is_llvm (const char *producer)
+{
+ return ((producer != NULL) && (startswith (producer, "clang ")
+ || startswith (producer, " F90 Flang ")));
+}
+
#if defined GDB_SELF_TEST
namespace selftests {
namespace producer {
}
{
- static const char extern_f_14_1[] = "\
+ static const char extern_f_14_0[] = "\
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on \
Intel(R) 64, \
Version 14.0.1.074 Build 20130716";
int major = 0, minor = 0;
- SELF_CHECK (producer_is_icc (extern_f_14_1, &major, &minor)
- && major == 14 && minor == 1);
- SELF_CHECK (!producer_is_gcc (extern_f_14_1, &major, &minor));
+ SELF_CHECK (producer_is_icc (extern_f_14_0, &major, &minor)
+ && major == 14 && minor == 0);
+ SELF_CHECK (!producer_is_gcc (extern_f_14_0, &major, &minor));
}
{
SELF_CHECK (producer_is_gcc (gnu_exp, &major, &minor)
&& major == 5 && minor == 0);
}
+
+ {
+ static const char clang_llvm_exp[] = "clang version 12.0.0 (CLANG: bld#8)";
+ int major = 0, minor = 0;
+ SELF_CHECK (!producer_is_icc (clang_llvm_exp, NULL, NULL));
+ SELF_CHECK (!producer_is_gcc (clang_llvm_exp, &major, &minor));
+ SELF_CHECK (producer_is_llvm (clang_llvm_exp));
+ }
+
+ {
+ static const char flang_llvm_exp[] = " F90 Flang - 1.5 2017-05-01";
+ int major = 0, minor = 0;
+ SELF_CHECK (!producer_is_icc (flang_llvm_exp, NULL, NULL));
+ SELF_CHECK (!producer_is_gcc (flang_llvm_exp, &major, &minor));
+ SELF_CHECK (producer_is_llvm (flang_llvm_exp));
+ }
}
}
}
#endif
+void _initialize_producer ();
void
_initialize_producer ()
{