From 08a261e497412d744706ef0948bfb32dcc9a0242 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Tue, 25 Apr 2023 21:41:24 +0100 Subject: [PATCH 01/12] A26-5-1: Address compiler compatibility Move "rand" definition to the global namespace and import into std with "using", to better reflect "real" compilers. --- cpp/common/test/includes/standard-library/cstdlib.h | 2 +- cpp/common/test/includes/standard-library/stdlib.h | 2 ++ .../DoNotUseRandForGeneratingPseudorandomNumbers.expected | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp/common/test/includes/standard-library/cstdlib.h b/cpp/common/test/includes/standard-library/cstdlib.h index b2c87ada66..4a2d0cd9ee 100644 --- a/cpp/common/test/includes/standard-library/cstdlib.h +++ b/cpp/common/test/includes/standard-library/cstdlib.h @@ -7,10 +7,10 @@ namespace std { [[noreturn]] void quick_exit(int status) noexcept; extern "C++" int atexit(void (*f)(void)) noexcept; extern "C++" int at_quick_exit(void (*f)(void)) noexcept; -extern "C++" long rand() noexcept; using ::atof; using ::atoi; using ::atol; using ::atoll; +using ::rand; } // namespace std #endif // _GHLIBCPP_CSTDLIB \ No newline at end of file diff --git a/cpp/common/test/includes/standard-library/stdlib.h b/cpp/common/test/includes/standard-library/stdlib.h index 37902b52bb..c8ff7a7592 100644 --- a/cpp/common/test/includes/standard-library/stdlib.h +++ b/cpp/common/test/includes/standard-library/stdlib.h @@ -20,4 +20,6 @@ long int atol(const char *str); long long int atoll(const char *str); double atof(const char *str); +int rand(void); + #endif // _GHLIBCPP_STDLIB \ No newline at end of file diff --git a/cpp/common/test/rules/donotuserandforgeneratingpseudorandomnumbers/DoNotUseRandForGeneratingPseudorandomNumbers.expected b/cpp/common/test/rules/donotuserandforgeneratingpseudorandomnumbers/DoNotUseRandForGeneratingPseudorandomNumbers.expected index 2b4bcde88a..eaefe65ca3 100644 --- a/cpp/common/test/rules/donotuserandforgeneratingpseudorandomnumbers/DoNotUseRandForGeneratingPseudorandomNumbers.expected +++ b/cpp/common/test/rules/donotuserandforgeneratingpseudorandomnumbers/DoNotUseRandForGeneratingPseudorandomNumbers.expected @@ -1 +1 @@ -| test.cpp:5:47:5:55 | call to rand | Use of banned function std::rand. | +| test.cpp:5:47:5:55 | call to rand | Use of banned function rand. | From b9f8bdecd12473f0c6130345e1d96af03e96defe Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Tue, 25 Apr 2023 21:45:03 +0100 Subject: [PATCH 02/12] A15-1-5: Expect no results for real compilers Our compiler testing only uses a single compiler and cannot replicate execution boundaries, so we simply ignore this test by expecting no results. --- .../ExceptionsThrownAcrossExecutionBoundaries.clang.expected | 0 .../ExceptionsThrownAcrossExecutionBoundaries.gcc.expected | 0 .../ExceptionsThrownAcrossExecutionBoundaries.qcc.expected | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.clang.expected create mode 100644 cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.gcc.expected create mode 100644 cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.qcc.expected diff --git a/cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.clang.expected b/cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.clang.expected new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.gcc.expected b/cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.gcc.expected new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.qcc.expected b/cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.qcc.expected new file mode 100644 index 0000000000..e69de29bb2 From 96b85e01074b2edf6c37ff821d9a11a0564312ff Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Tue, 25 Apr 2023 22:00:26 +0100 Subject: [PATCH 03/12] A18-0-3: Address compiler compatibility Move global locale definitions to locale.h, and import them into std with "using" to better reflect real compilers. --- .../rules/A18-0-3/LocaleFunctionsUsed.expected | 14 +++++++------- .../rules/A18-0-3/LocaleTypeLConvUsed.expected | 2 +- cpp/common/test/includes/standard-library/clocale | 13 +++++-------- cpp/common/test/includes/standard-library/locale.h | 8 ++++++++ 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/cpp/autosar/test/rules/A18-0-3/LocaleFunctionsUsed.expected b/cpp/autosar/test/rules/A18-0-3/LocaleFunctionsUsed.expected index f6bfa5f4d9..1521b1a9f4 100644 --- a/cpp/autosar/test/rules/A18-0-3/LocaleFunctionsUsed.expected +++ b/cpp/autosar/test/rules/A18-0-3/LocaleFunctionsUsed.expected @@ -1,10 +1,10 @@ -| test.cpp:4:3:4:16 | call to setlocale | Use of function 'std::setlocale'. | -| test.cpp:5:3:5:16 | call to setlocale | Use of function 'std::setlocale'. | -| test.cpp:6:3:6:16 | call to setlocale | Use of function 'std::setlocale'. | -| test.cpp:7:3:7:16 | call to setlocale | Use of function 'std::setlocale'. | -| test.cpp:8:3:8:16 | call to setlocale | Use of function 'std::setlocale'. | -| test.cpp:9:3:9:16 | call to setlocale | Use of function 'std::setlocale'. | -| test.cpp:10:20:10:34 | call to localeconv | Use of function 'std::localeconv'. | +| test.cpp:4:3:4:16 | call to setlocale | Use of function 'setlocale'. | +| test.cpp:5:3:5:16 | call to setlocale | Use of function 'setlocale'. | +| test.cpp:6:3:6:16 | call to setlocale | Use of function 'setlocale'. | +| test.cpp:7:3:7:16 | call to setlocale | Use of function 'setlocale'. | +| test.cpp:8:3:8:16 | call to setlocale | Use of function 'setlocale'. | +| test.cpp:9:3:9:16 | call to setlocale | Use of function 'setlocale'. | +| test.cpp:10:20:10:34 | call to localeconv | Use of function 'localeconv'. | | test.cpp:12:3:12:11 | call to setlocale | Use of function 'setlocale'. | | test.cpp:13:3:13:11 | call to setlocale | Use of function 'setlocale'. | | test.cpp:14:3:14:11 | call to setlocale | Use of function 'setlocale'. | diff --git a/cpp/autosar/test/rules/A18-0-3/LocaleTypeLConvUsed.expected b/cpp/autosar/test/rules/A18-0-3/LocaleTypeLConvUsed.expected index 4e93c94f9b..c83be2cb1c 100644 --- a/cpp/autosar/test/rules/A18-0-3/LocaleTypeLConvUsed.expected +++ b/cpp/autosar/test/rules/A18-0-3/LocaleTypeLConvUsed.expected @@ -1,2 +1,2 @@ -| test.cpp:10:8:10:12 | type mention | Use of type 'std::lconv'. | +| test.cpp:10:8:10:12 | type mention | Use of type 'lconv'. | | test.cpp:18:3:18:7 | type mention | Use of type 'lconv'. | diff --git a/cpp/common/test/includes/standard-library/clocale b/cpp/common/test/includes/standard-library/clocale index da05144f67..430c36daa0 100644 --- a/cpp/common/test/includes/standard-library/clocale +++ b/cpp/common/test/includes/standard-library/clocale @@ -8,13 +8,10 @@ #define LC_NUMERIC 0 #define LC_TIME 0 +#include + namespace std { -struct lconv; -char *setlocale(int, const char *); -lconv *localeconv(); +using ::lconv; +using ::localeconv; +using ::setlocale; } // namespace std - -// global namespace -struct lconv; -char *setlocale(int, const char *); -lconv *localeconv(); \ No newline at end of file diff --git a/cpp/common/test/includes/standard-library/locale.h b/cpp/common/test/includes/standard-library/locale.h index e69de29bb2..346c4eeef5 100644 --- a/cpp/common/test/includes/standard-library/locale.h +++ b/cpp/common/test/includes/standard-library/locale.h @@ -0,0 +1,8 @@ +#ifndef _GHLIBCPP_LOCALE +#define _GHLIBCPP_LOCALE + +struct lconv; +char *setlocale(int, const char *); +lconv *localeconv(); + +#endif // _GHLIBCPP_LOCALE \ No newline at end of file From 7cb92193a7c6f54f0a8766ed266e5de04296717b Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 27 Apr 2023 19:30:45 +0100 Subject: [PATCH 04/12] ERR59-CPP: Expect no results for real compilers Our compiler testing only uses a single compiler and cannot replicate execution boundaries, so we simply ignore this test by expecting no results. --- .../DoNotThrowAnExceptionAcrossExecutionBoundaries.clang.expected | 0 .../DoNotThrowAnExceptionAcrossExecutionBoundaries.gcc.expected | 0 .../DoNotThrowAnExceptionAcrossExecutionBoundaries.qcc.expected | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.clang.expected create mode 100644 cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.gcc.expected create mode 100644 cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.qcc.expected diff --git a/cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.clang.expected b/cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.clang.expected new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.gcc.expected b/cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.gcc.expected new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.qcc.expected b/cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.qcc.expected new file mode 100644 index 0000000000..e69de29bb2 From 353de74cac6c362a0aac4061a9448f4d13f6873c Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 27 Apr 2023 22:27:14 +0100 Subject: [PATCH 05/12] M18-2-1: Update compiler expected results Macro parameter names vary by compiler. --- cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.gcc.expected | 1 + cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qcc.expected | 1 + 2 files changed, 2 insertions(+) create mode 100644 cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.gcc.expected create mode 100644 cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qcc.expected diff --git a/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.gcc.expected b/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.gcc.expected new file mode 100644 index 0000000000..f09fafd410 --- /dev/null +++ b/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.gcc.expected @@ -0,0 +1 @@ +| test.cpp:9:32:9:51 | offsetof(__typ,__id) | Use of banned macro offsetof. | diff --git a/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qcc.expected b/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qcc.expected new file mode 100644 index 0000000000..88647b9f36 --- /dev/null +++ b/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qcc.expected @@ -0,0 +1 @@ +| test.cpp:9:32:9:51 | offsetof(t,d) | Use of banned macro offsetof. | From 070579a0c467216db2368756dec892213a4b4903 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 27 Apr 2023 22:49:09 +0100 Subject: [PATCH 06/12] M18-7-1: Address signal.h compiler compat Better reflect how real compilers implement csignal. --- .../rules/M18-7-1/CsignalFunctionsUsed.expected | 4 ++-- .../test/rules/M18-7-1/CsignalTypesUsed.expected | 2 +- cpp/common/test/includes/standard-library/csignal | 15 ++++++--------- .../test/includes/standard-library/signal.h | 8 ++++++++ 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cpp/autosar/test/rules/M18-7-1/CsignalFunctionsUsed.expected b/cpp/autosar/test/rules/M18-7-1/CsignalFunctionsUsed.expected index 8806bacfe7..2cc8431463 100644 --- a/cpp/autosar/test/rules/M18-7-1/CsignalFunctionsUsed.expected +++ b/cpp/autosar/test/rules/M18-7-1/CsignalFunctionsUsed.expected @@ -1,4 +1,4 @@ -| test.cpp:7:3:7:13 | call to signal | Use of function 'std::signal'. | -| test.cpp:8:3:8:12 | call to raise | Use of function 'std::raise'. | +| test.cpp:7:3:7:13 | call to signal | Use of function 'signal'. | +| test.cpp:8:3:8:12 | call to raise | Use of function 'raise'. | | test.cpp:11:3:11:8 | call to signal | Use of function 'signal'. | | test.cpp:12:3:12:7 | call to raise | Use of function 'raise'. | diff --git a/cpp/autosar/test/rules/M18-7-1/CsignalTypesUsed.expected b/cpp/autosar/test/rules/M18-7-1/CsignalTypesUsed.expected index fda560380f..0ec502c3ac 100644 --- a/cpp/autosar/test/rules/M18-7-1/CsignalTypesUsed.expected +++ b/cpp/autosar/test/rules/M18-7-1/CsignalTypesUsed.expected @@ -1,2 +1,2 @@ -| test.cpp:6:8:6:19 | type mention | Use of type 'std::sig_atomic_t'. | +| test.cpp:6:8:6:19 | type mention | Use of type 'sig_atomic_t'. | | test.cpp:10:3:10:14 | type mention | Use of type 'sig_atomic_t'. | diff --git a/cpp/common/test/includes/standard-library/csignal b/cpp/common/test/includes/standard-library/csignal index 0cded25e15..4c3b565256 100644 --- a/cpp/common/test/includes/standard-library/csignal +++ b/cpp/common/test/includes/standard-library/csignal @@ -10,13 +10,10 @@ #define SIG_IGN 7 #define SIG_ERR 8 -namespace std { -typedef int sig_atomic_t; -void (*signal(int, void (*func)(int)))(int); -int raise(int sig); -} // namespace std +#include -// global namespace -typedef int sig_atomic_t; -void (*signal(int, void (*func)(int)))(int); -int raise(int); \ No newline at end of file +namespace std { +using ::raise; +using ::sig_atomic_t; +using ::signal; +} // namespace std \ No newline at end of file diff --git a/cpp/common/test/includes/standard-library/signal.h b/cpp/common/test/includes/standard-library/signal.h index e69de29bb2..b9ac81919a 100644 --- a/cpp/common/test/includes/standard-library/signal.h +++ b/cpp/common/test/includes/standard-library/signal.h @@ -0,0 +1,8 @@ +#ifndef _GHLIBCPP_SIGNAL +#define _GHLIBCPP_SIGNAL + +typedef int sig_atomic_t; +void (*signal(int, void (*func)(int)))(int); +int raise(int); + +#endif // _GHLIBCPP_SIGNAL \ No newline at end of file From ae7461affb5a7c4f81990290900cb0b31d5fd7b9 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 27 Apr 2023 23:06:17 +0100 Subject: [PATCH 07/12] M27-0-1: Address compiler compatibility Modify cstdio to more closely match real compilers. --- .../M27-0-1/CstdioFunctionsUsed.expected | 34 ++-- .../rules/M27-0-1/CstdioTypesUsed.expected | 4 +- .../test/includes/standard-library/cstdio | 182 +++++------------- .../test/includes/standard-library/stdio.h | 85 +++++++- 4 files changed, 152 insertions(+), 153 deletions(-) diff --git a/cpp/autosar/test/rules/M27-0-1/CstdioFunctionsUsed.expected b/cpp/autosar/test/rules/M27-0-1/CstdioFunctionsUsed.expected index 241d2281ef..54f341887a 100644 --- a/cpp/autosar/test/rules/M27-0-1/CstdioFunctionsUsed.expected +++ b/cpp/autosar/test/rules/M27-0-1/CstdioFunctionsUsed.expected @@ -1,20 +1,20 @@ -| test.cpp:4:18:4:27 | call to fopen | Use of function 'std::fopen'. | -| test.cpp:7:3:7:14 | call to fgetpos | Use of function 'std::fgetpos'. | -| test.cpp:9:11:9:19 | call to feof | Use of function 'std::feof'. | -| test.cpp:10:14:10:23 | call to fgetc | Use of function 'std::fgetc'. | -| test.cpp:12:7:12:17 | call to rewind | Use of function 'std::rewind'. | -| test.cpp:14:7:14:17 | call to ferror | Use of function 'std::ferror'. | -| test.cpp:15:5:15:17 | call to clearerr | Use of function 'std::clearerr'. | -| test.cpp:16:5:16:15 | call to fclose | Use of function 'std::fclose'. | -| test.cpp:17:5:17:15 | call to perror | Use of function 'std::perror'. | -| test.cpp:20:3:20:12 | call to fseek | Use of function 'std::fseek'. | -| test.cpp:21:3:21:12 | call to fseek | Use of function 'std::fseek'. | -| test.cpp:23:3:23:12 | call to fread | Use of function 'std::fread'. | -| test.cpp:25:3:25:14 | call to fsetpos | Use of function 'std::fsetpos'. | -| test.cpp:26:3:26:13 | call to fflush | Use of function 'std::fflush'. | -| test.cpp:27:3:27:13 | call to fclose | Use of function 'std::fclose'. | -| test.cpp:29:3:29:13 | call to printf | Use of function 'std::printf'. | -| test.cpp:31:3:31:11 | call to puts | Use of function 'std::puts'. | +| test.cpp:4:18:4:27 | call to fopen | Use of function 'fopen'. | +| test.cpp:7:3:7:14 | call to fgetpos | Use of function 'fgetpos'. | +| test.cpp:9:11:9:19 | call to feof | Use of function 'feof'. | +| test.cpp:10:14:10:23 | call to fgetc | Use of function 'fgetc'. | +| test.cpp:12:7:12:17 | call to rewind | Use of function 'rewind'. | +| test.cpp:14:7:14:17 | call to ferror | Use of function 'ferror'. | +| test.cpp:15:5:15:17 | call to clearerr | Use of function 'clearerr'. | +| test.cpp:16:5:16:15 | call to fclose | Use of function 'fclose'. | +| test.cpp:17:5:17:15 | call to perror | Use of function 'perror'. | +| test.cpp:20:3:20:12 | call to fseek | Use of function 'fseek'. | +| test.cpp:21:3:21:12 | call to fseek | Use of function 'fseek'. | +| test.cpp:23:3:23:12 | call to fread | Use of function 'fread'. | +| test.cpp:25:3:25:14 | call to fsetpos | Use of function 'fsetpos'. | +| test.cpp:26:3:26:13 | call to fflush | Use of function 'fflush'. | +| test.cpp:27:3:27:13 | call to fclose | Use of function 'fclose'. | +| test.cpp:29:3:29:13 | call to printf | Use of function 'printf'. | +| test.cpp:31:3:31:11 | call to puts | Use of function 'puts'. | | test.cpp:34:14:34:18 | call to fopen | Use of function 'fopen'. | | test.cpp:37:3:37:9 | call to fgetpos | Use of function 'fgetpos'. | | test.cpp:39:11:39:14 | call to feof | Use of function 'feof'. | diff --git a/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.expected b/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.expected index 037f54c05e..ed5a448ace 100644 --- a/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.expected +++ b/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.expected @@ -1,4 +1,4 @@ -| test.cpp:4:8:4:11 | type mention | Use of type 'std::FILE'. | -| test.cpp:6:8:6:13 | type mention | Use of type 'std::fpos_t'. | +| test.cpp:4:8:4:11 | type mention | Use of type 'FILE'. | +| test.cpp:6:8:6:13 | type mention | Use of type 'fpos_t'. | | test.cpp:34:3:34:6 | type mention | Use of type 'FILE'. | | test.cpp:36:3:36:8 | type mention | Use of type 'fpos_t'. | diff --git a/cpp/common/test/includes/standard-library/cstdio b/cpp/common/test/includes/standard-library/cstdio index 65dde7279d..e40fc5458c 100644 --- a/cpp/common/test/includes/standard-library/cstdio +++ b/cpp/common/test/includes/standard-library/cstdio @@ -16,135 +16,55 @@ #define SEEK_END -1 #define stderr 0 -namespace std { -struct FILE; -typedef int fpos_t; - -// Operations on files -int remove(const char *filename); -int rename(const char *oldname, const char *newname); -FILE *tmpfile(void); -char *tmpnam(char *str); - -// File access -int fclose(FILE *stream); -int fflush(FILE *stream); -FILE *fopen(const char *filename, const char *mode); -FILE *freopen(const char *filename, const char *mode, FILE *stream); -void setbuf(FILE *stream, char *buffer); -int setvbuf(FILE *stream, char *buffer, int mode, size_t size); - -// Formatted input/output -int fprintf(FILE *stream, const char *format, ...); -int fscanf(FILE *stream, const char *format, ...); -int printf(const char *format, ...); -int scanf(const char *format, ...); -int snprintf(char *s, size_t n, const char *format, ...); -int sprintf(char *str, const char *format, ...); -int sscanf(const char *s, const char *format, ...); -/* -int vfprintf ( FILE * stream, const char * format, va_list arg ); -int vfscanf ( FILE * stream, const char * format, va_list arg ); -int vprintf ( const char * format, va_list arg ); -int vscanf ( const char * format, va_list arg ); -int vsnprintf (char * s, size_t n, const char * format, va_list arg ); -int vsprintf (char * s, const char * format, va_list arg ); -int vsscanf ( const char * s, const char * format, va_list arg ); -*/ - -// Character input/output -int fgetc(FILE *stream); -char *fgets(char *str, int num, FILE *stream); -int fputc(int character, FILE *stream); -int fputs(const char *str, FILE *stream); -int getc(FILE *stream); -int getchar(void); -char *gets(char *str); -int putc(int character, FILE *stream); -int putchar(int character); -int puts(const char *str); -int ungetc(int character, FILE *stream); - -// Direct input/output -size_t fread(void *ptr, size_t size, size_t count, FILE *stream); -size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream); - -// File positioning -int fgetpos(FILE *stream, fpos_t *pos); -int fseek(FILE *stream, long int offset, int origin); -int fsetpos(FILE *stream, const fpos_t *pos); -long int ftell(FILE *stream); -void rewind(FILE *stream); - -// Error-handling -void clearerr(FILE *stream); -int feof(FILE *stream); -int ferror(FILE *stream); -void perror(const char *str); -} // namespace std +#include -// global namespace -struct FILE; -typedef int fpos_t; - -// Operations on files -int remove(const char *filename); -int rename(const char *oldname, const char *newname); -FILE *tmpfile(void); -char *tmpnam(char *str); - -// File access -int fclose(FILE *stream); -int fflush(FILE *stream); -FILE *fopen(const char *filename, const char *mode); -FILE *freopen(const char *filename, const char *mode, FILE *stream); -void setbuf(FILE *stream, char *buffer); -int setvbuf(FILE *stream, char *buffer, int mode, size_t size); - -// Formatted input/output -int fprintf(FILE *stream, const char *format, ...); -int fscanf(FILE *stream, const char *format, ...); -int printf(const char *format, ...); -int scanf(const char *format, ...); -int snprintf(char *s, size_t n, const char *format, ...); -int sprintf(char *str, const char *format, ...); -int sscanf(const char *s, const char *format, ...); -/* -int vfprintf ( FILE * stream, const char * format, va_list arg ); -int vfscanf ( FILE * stream, const char * format, va_list arg ); -int vprintf ( const char * format, va_list arg ); -int vscanf ( const char * format, va_list arg ); -int vsnprintf (char * s, size_t n, const char * format, va_list arg ); -int vsprintf (char * s, const char * format, va_list arg ); -int vsscanf ( const char * s, const char * format, va_list arg ); -*/ - -// Character input/output -int fgetc(FILE *stream); -char *fgets(char *str, int num, FILE *stream); -int fputc(int character, FILE *stream); -int fputs(const char *str, FILE *stream); -int getc(FILE *stream); -int getchar(void); -char *gets(char *str); -int putc(int character, FILE *stream); -int putchar(int character); -int puts(const char *str); -int ungetc(int character, FILE *stream); - -// Direct input/output -size_t fread(void *ptr, size_t size, size_t count, FILE *stream); -size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream); - -// File positioning -int fgetpos(FILE *stream, fpos_t *pos); -int fseek(FILE *stream, long int offset, int origin); -int fsetpos(FILE *stream, const fpos_t *pos); -long int ftell(FILE *stream); -void rewind(FILE *stream); - -// Error-handling -void clearerr(FILE *stream); -int feof(FILE *stream); -int ferror(FILE *stream); -void perror(const char *str); \ No newline at end of file +namespace std { +using ::FILE; +using ::fpos_t; + +using ::remove; +using ::rename; +using ::tmpfile; +using ::tmpnam; + +using ::fclose; +using ::fflush; +using ::fopen; +using ::freopen; +using ::setbuf; +using ::setvbuf; + +using ::fprintf; +using ::fscanf; +using ::printf; +using ::scanf; +using ::snprintf; +using ::sprintf; +using ::sscanf; + +using ::fgetc; +using ::fgets; +using ::fputc; +using ::fputs; +using ::getc; +using ::getchar; +using ::gets; +using ::putc; +using ::putchar; +using ::puts; +using ::ungetc; + +using ::fread; +using ::fwrite; + +using ::fgetpos; +using ::fseek; +using ::fsetpos; +using ::ftell; +using ::rewind; + +using ::clearerr; +using ::feof; +using ::ferror; +using ::perror; +} // namespace std \ No newline at end of file diff --git a/cpp/common/test/includes/standard-library/stdio.h b/cpp/common/test/includes/standard-library/stdio.h index b1a36a4af0..30ca17bcaf 100644 --- a/cpp/common/test/includes/standard-library/stdio.h +++ b/cpp/common/test/includes/standard-library/stdio.h @@ -1,5 +1,84 @@ +#ifndef _GHLIBCPP_STDIO +#define _GHLIBCPP_STDIO + +#include + typedef void FILE; +typedef int fpos_t; + +// Operations on files +int remove(const char *filename); +int rename(const char *oldname, const char *newname); +FILE *tmpfile(void); +char *tmpnam(char *str); + +// File access +int fclose(FILE *stream); +int fflush(FILE *stream); +FILE *fopen(const char *filename, const char *mode); +FILE *freopen(const char *filename, const char *mode, FILE *stream); +void setbuf(FILE *stream, char *buffer); +int setvbuf(FILE *stream, char *buffer, int mode, size_t size); + +// Formatted input/output +int fprintf(FILE *stream, const char *format, ...); +int fscanf(FILE *stream, const char *format, ...); +int printf(const char *format, ...); +int scanf(const char *format, ...); +int snprintf(char *s, size_t n, const char *format, ...); +int sprintf(char *str, const char *format, ...); +int sscanf(const char *s, const char *format, ...); +/* +int vfprintf ( FILE * stream, const char * format, va_list arg ); +int vfscanf ( FILE * stream, const char * format, va_list arg ); +int vprintf ( const char * format, va_list arg ); +int vscanf ( const char * format, va_list arg ); +int vsnprintf (char * s, size_t n, const char * format, va_list arg ); +int vsprintf (char * s, const char * format, va_list arg ); +int vsscanf ( const char * s, const char * format, va_list arg ); +*/ + +// Character input/output +int fgetc(FILE *stream); +char *fgets(char *str, int num, FILE *stream); +int fputc(int character, FILE *stream); +int fputs(const char *str, FILE *stream); +int getc(FILE *stream); +int getchar(void); +char *gets(char *str); +int putc(int character, FILE *stream); +int putchar(int character); +int puts(const char *str); +int ungetc(int character, FILE *stream); + +// Character input/output +int fgetc(FILE *stream); +char *fgets(char *str, int num, FILE *stream); +int fputc(int character, FILE *stream); +int fputs(const char *str, FILE *stream); +int getc(FILE *stream); +int getchar(void); +char *gets(char *str); +int putc(int character, FILE *stream); +int putchar(int character); +int puts(const char *str); +int ungetc(int character, FILE *stream); + +// Direct input/output +size_t fread(void *ptr, size_t size, size_t count, FILE *stream); +size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream); + +// File positioning +int fgetpos(FILE *stream, fpos_t *pos); +int fseek(FILE *stream, long int offset, int origin); +int fsetpos(FILE *stream, const fpos_t *pos); +long int ftell(FILE *stream); +void rewind(FILE *stream); + +// Error-handling +void clearerr(FILE *stream); +int feof(FILE *stream); +int ferror(FILE *stream); +void perror(const char *str); -FILE *fopen(const char *, const char *); -int fclose(FILE *); -int remove(const char *); \ No newline at end of file +#endif // _GHLIBCPP_STDIO \ No newline at end of file From 521c9972df822741011e519ec4ff0db7ba333436 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 27 Apr 2023 23:13:49 +0100 Subject: [PATCH 08/12] A14-7-2: Just report base name The source location is different between compiler testing and qltest, leading to spurious differences. This simplifies the query, reporting only the base name of the file but still reporting the link. --- .../TemplateSpecializationNotDeclaredInTheSameFile.ql | 2 +- .../TemplateSpecializationNotDeclaredInTheSameFile.expected | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cpp/autosar/src/rules/A14-7-2/TemplateSpecializationNotDeclaredInTheSameFile.ql b/cpp/autosar/src/rules/A14-7-2/TemplateSpecializationNotDeclaredInTheSameFile.ql index b583c9cc14..94214e8992 100644 --- a/cpp/autosar/src/rules/A14-7-2/TemplateSpecializationNotDeclaredInTheSameFile.ql +++ b/cpp/autosar/src/rules/A14-7-2/TemplateSpecializationNotDeclaredInTheSameFile.ql @@ -58,4 +58,4 @@ where not spec.getFile() = spec.getPrimary().getFile() and not extraExclude(spec) select spec, "Specialization found in file $@ where primary template is outside that file.", - spec.getFile(), spec.getFile().getRelativePath() + spec.getFile(), spec.getFile().getBaseName() diff --git a/cpp/autosar/test/rules/A14-7-2/TemplateSpecializationNotDeclaredInTheSameFile.expected b/cpp/autosar/test/rules/A14-7-2/TemplateSpecializationNotDeclaredInTheSameFile.expected index 1ec607ca49..e697056580 100644 --- a/cpp/autosar/test/rules/A14-7-2/TemplateSpecializationNotDeclaredInTheSameFile.expected +++ b/cpp/autosar/test/rules/A14-7-2/TemplateSpecializationNotDeclaredInTheSameFile.expected @@ -1,3 +1,3 @@ -| test.cpp:5:20:5:25 | s | Specialization found in file $@ where primary template is outside that file. | test.cpp:0:0:0:0 | test.cpp | rules/A14-7-2/test.cpp | -| test.cpp:7:18:7:24 | f | Specialization found in file $@ where primary template is outside that file. | test.cpp:0:0:0:0 | test.cpp | rules/A14-7-2/test.cpp | -| test.cpp:13:19:13:28 | vector> | Specialization found in file $@ where primary template is outside that file. | test.cpp:0:0:0:0 | test.cpp | rules/A14-7-2/test.cpp | +| test.cpp:5:20:5:25 | s | Specialization found in file $@ where primary template is outside that file. | test.cpp:0:0:0:0 | test.cpp | test.cpp | +| test.cpp:7:18:7:24 | f | Specialization found in file $@ where primary template is outside that file. | test.cpp:0:0:0:0 | test.cpp | test.cpp | +| test.cpp:13:19:13:28 | vector> | Specialization found in file $@ where primary template is outside that file. | test.cpp:0:0:0:0 | test.cpp | test.cpp | From aaf57886d489192647a7a19a98923ac2b08235ef Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Fri, 28 Apr 2023 14:59:58 +0100 Subject: [PATCH 09/12] Add change note. --- change_notes/2023-04-28-a14-7-2.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 change_notes/2023-04-28-a14-7-2.md diff --git a/change_notes/2023-04-28-a14-7-2.md b/change_notes/2023-04-28-a14-7-2.md new file mode 100644 index 0000000000..b74b95449f --- /dev/null +++ b/change_notes/2023-04-28-a14-7-2.md @@ -0,0 +1 @@ + * `A14-7-2` - alert messages have been slightly adjusted to refer only to the base name of a file, not the full relative path. \ No newline at end of file From 14f0f354e4a536002db18656438deb3c5a2550d1 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Tue, 9 May 2023 23:53:43 +0200 Subject: [PATCH 10/12] Update M18-2-1 .expected file --- cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qcc.expected | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qcc.expected b/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qcc.expected index 88647b9f36..f09fafd410 100644 --- a/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qcc.expected +++ b/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qcc.expected @@ -1 +1 @@ -| test.cpp:9:32:9:51 | offsetof(t,d) | Use of banned macro offsetof. | +| test.cpp:9:32:9:51 | offsetof(__typ,__id) | Use of banned macro offsetof. | From e34f38227abcfd6f14def5eb3fa05f0578973951 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Wed, 10 May 2023 00:06:56 +0200 Subject: [PATCH 11/12] matrix testing mutex --- scripts/matrix_testing/CreateMatrixTestReport.ps1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/matrix_testing/CreateMatrixTestReport.ps1 b/scripts/matrix_testing/CreateMatrixTestReport.ps1 index d80e87e426..0cf48ac36c 100644 --- a/scripts/matrix_testing/CreateMatrixTestReport.ps1 +++ b/scripts/matrix_testing/CreateMatrixTestReport.ps1 @@ -299,6 +299,11 @@ $jobRows = $queriesToCheck | ForEach-Object -ThrottleLimit $NumThreads -Parallel foreach($testDirectory in $testDirs){ + Write-Host "Acquiring lock for $testDirectory" + $Mutex = New-Object -TypeName System.Threading.Mutex -ArgumentList $false, ("__Matrix_" + $testDirectory.Replace([IO.Path]::DirectorySeparatorChar,"_")); + $Mutex.WaitOne() | Out-Null; + Write-Host "Locked $testDirectory" + # for the report $row = @{ "SUITE" = $CurrentSuiteName; @@ -412,6 +417,8 @@ $jobRows = $queriesToCheck | ForEach-Object -ThrottleLimit $NumThreads -Parallel # output current row state $row + # release any held mutexes + $Mutex.ReleaseMutex(); ########################################################### ########################################################### @@ -449,4 +456,4 @@ if (-not $SkipSummaryReport){ # write out a summary Write-Host "Writing summary report to $summaryReportOutputFile" Create-Summary-Report -DataFile $reportOutputFile -OutputFile $summaryReportOutputFile -} \ No newline at end of file +} From 2847322bfe78ef3c66ed73c8d4757b093c4dcaba Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Wed, 10 May 2023 17:00:46 +0200 Subject: [PATCH 12/12] Fix expected files names --- ...d => ExceptionsThrownAcrossExecutionBoundaries.expected.clang} | 0 ...ted => ExceptionsThrownAcrossExecutionBoundaries.expected.gcc} | 0 ...ted => ExceptionsThrownAcrossExecutionBoundaries.expected.qcc} | 0 ...roOffsetofUsed.gcc.expected => MacroOffsetofUsed.expected.gcc} | 0 ...roOffsetofUsed.qcc.expected => MacroOffsetofUsed.expected.qcc} | 0 ...DoNotThrowAnExceptionAcrossExecutionBoundaries.expected.clang} | 0 ...> DoNotThrowAnExceptionAcrossExecutionBoundaries.expected.gcc} | 0 ...> DoNotThrowAnExceptionAcrossExecutionBoundaries.expected.qcc} | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename cpp/autosar/test/rules/A15-1-5/{ExceptionsThrownAcrossExecutionBoundaries.clang.expected => ExceptionsThrownAcrossExecutionBoundaries.expected.clang} (100%) rename cpp/autosar/test/rules/A15-1-5/{ExceptionsThrownAcrossExecutionBoundaries.gcc.expected => ExceptionsThrownAcrossExecutionBoundaries.expected.gcc} (100%) rename cpp/autosar/test/rules/A15-1-5/{ExceptionsThrownAcrossExecutionBoundaries.qcc.expected => ExceptionsThrownAcrossExecutionBoundaries.expected.qcc} (100%) rename cpp/autosar/test/rules/M18-2-1/{MacroOffsetofUsed.gcc.expected => MacroOffsetofUsed.expected.gcc} (100%) rename cpp/autosar/test/rules/M18-2-1/{MacroOffsetofUsed.qcc.expected => MacroOffsetofUsed.expected.qcc} (100%) rename cpp/cert/test/rules/ERR59-CPP/{DoNotThrowAnExceptionAcrossExecutionBoundaries.clang.expected => DoNotThrowAnExceptionAcrossExecutionBoundaries.expected.clang} (100%) rename cpp/cert/test/rules/ERR59-CPP/{DoNotThrowAnExceptionAcrossExecutionBoundaries.gcc.expected => DoNotThrowAnExceptionAcrossExecutionBoundaries.expected.gcc} (100%) rename cpp/cert/test/rules/ERR59-CPP/{DoNotThrowAnExceptionAcrossExecutionBoundaries.qcc.expected => DoNotThrowAnExceptionAcrossExecutionBoundaries.expected.qcc} (100%) diff --git a/cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.clang.expected b/cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.expected.clang similarity index 100% rename from cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.clang.expected rename to cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.expected.clang diff --git a/cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.gcc.expected b/cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.expected.gcc similarity index 100% rename from cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.gcc.expected rename to cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.expected.gcc diff --git a/cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.qcc.expected b/cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.expected.qcc similarity index 100% rename from cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.qcc.expected rename to cpp/autosar/test/rules/A15-1-5/ExceptionsThrownAcrossExecutionBoundaries.expected.qcc diff --git a/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.gcc.expected b/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.expected.gcc similarity index 100% rename from cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.gcc.expected rename to cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.expected.gcc diff --git a/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qcc.expected b/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.expected.qcc similarity index 100% rename from cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qcc.expected rename to cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.expected.qcc diff --git a/cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.clang.expected b/cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.expected.clang similarity index 100% rename from cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.clang.expected rename to cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.expected.clang diff --git a/cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.gcc.expected b/cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.expected.gcc similarity index 100% rename from cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.gcc.expected rename to cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.expected.gcc diff --git a/cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.qcc.expected b/cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.expected.qcc similarity index 100% rename from cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.qcc.expected rename to cpp/cert/test/rules/ERR59-CPP/DoNotThrowAnExceptionAcrossExecutionBoundaries.expected.qcc